Skip to content

Commit

Permalink
refactor(open): 优化应用管理代码
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed Nov 18, 2024
1 parent ff3f23d commit 4454daa
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ const options: Options = {
btns: { hide: true },
}
const { form, resetForm } = useForm({
// todo 待补充
})
const columns: Columns = reactive([
<#list fieldConfigs as fieldConfig>
<#if fieldConfig.showInForm>
Expand Down Expand Up @@ -81,10 +85,6 @@ const columns: Columns = reactive([
</#list>
])
const { form, resetForm } = useForm({
// todo 待补充
})
// 重置
const reset = () => {
formRef.value?.formRef?.resetFields()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public Class<SaCheckPermission> getHandlerAnnotationClass() {

@Override
public void checkMethod(SaCheckPermission at, Method method) {
if (!ApiSignCheckUtils.isExistSignParam()) {
if (!ApiSignCheckUtils.isSignParamExists()) {
_checkMethod(at.type(), at.value(), at.mode(), at.orRole());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,26 @@

package top.continew.admin.open.mapper;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import top.continew.starter.data.mp.base.BaseMapper;
import top.continew.admin.open.model.entity.AppDO;
import top.continew.starter.security.crypto.annotation.FieldEncrypt;

/**
* 应用 Mapper
*
* @author chengzi
* @since 2024/10/17 16:03
*/
public interface AppMapper extends BaseMapper<AppDO> {}
public interface AppMapper extends BaseMapper<AppDO> {

/**
* 根据 Access Key 查询
*
* @param accessKey Access Key
* @return 应用信息
*/
@Select("select * from sys_app where access_key = #{accessKey}")
AppDO selectByAccessKey(@FieldEncrypt @Param("accessKey") String accessKey);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import top.continew.starter.core.constant.StringConstants;
import top.continew.starter.extension.crud.service.impl.BaseServiceImpl;

import java.time.LocalDateTime;
import java.util.Optional;

/**
* 应用业务实现
Expand Down Expand Up @@ -74,31 +74,22 @@ public void resetSecret(Long id) {

@Override
public String getSecretKeyByAccessKey(String accessKey) {
return baseMapper.lambdaQuery()
.select(AppDO::getSecretKey)
.eq(AppDO::getAccessKey, accessKey)
.oneOpt()
.map(AppDO::getSecretKey)
.orElse(null);
return Optional.ofNullable(baseMapper.selectByAccessKey(accessKey)).map(AppDO::getSecretKey).orElse(null);
}

@Override
public boolean isAppExists(String accessKey) {
return baseMapper.lambdaQuery().eq(AppDO::getAccessKey, accessKey).exists();
return baseMapper.selectByAccessKey(accessKey) != null;
}

@Override
public boolean isAppSecretExpired(String accessKey) {
LocalDateTime expireTime = baseMapper.lambdaQuery()
.select(AppDO::getExpireTime)
.eq(AppDO::getAccessKey, accessKey)
.oneOpt()
.map(AppDO::getExpireTime)
.orElse(null);
if (expireTime == null) {
AppDO app = baseMapper.selectByAccessKey(accessKey);
ValidationUtils.throwIfNull(app, "应用不存在");
if (app.getExpireTime() == null) {
return false;
}
return expireTime.isBefore(DateUtil.date().toLocalDateTime());
return app.getExpireTime().isBefore(DateUtil.date().toLocalDateTime());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import cn.dev33.satoken.context.SaHolder;
import cn.dev33.satoken.context.model.SaRequest;
import cn.dev33.satoken.sign.SaSignTemplate;

import java.util.List;

Expand All @@ -37,10 +38,9 @@ private ApiSignCheckUtils() {
*
* @return 是否包含sign参数(true:包含;false:不包含)
*/
public static boolean isExistSignParam() {
public static boolean isSignParamExists() {
SaRequest saRequest = SaHolder.getRequest();
List<String> paramNames = saRequest.getParamNames();
return paramNames.stream().anyMatch(paramName -> paramName.equals("sign"));
return paramNames.stream().anyMatch(SaSignTemplate.sign::equals);
}

}

0 comments on commit 4454daa

Please sign in to comment.