Skip to content

Commit

Permalink
Merge branch 'master-jdk17' of https://gitee.com/zhijiantianya/ruoyi-…
Browse files Browse the repository at this point in the history
  • Loading branch information
YunaiV committed Aug 31, 2024
2 parents 0955119 + 56ae450 commit ea75cf8
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.baomidou.mybatisplus.core.incrementer.IKeyGenerator;
import com.baomidou.mybatisplus.extension.incrementer.*;
import com.baomidou.mybatisplus.extension.parser.JsqlParserGlobal;
import com.baomidou.mybatisplus.extension.parser.cache.JdkSerialCaffeineJsqlParseCache;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.apache.ibatis.annotations.Mapper;
Expand All @@ -16,6 +18,8 @@
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.ConfigurableEnvironment;

import java.util.concurrent.TimeUnit;

/**
* MyBaits 配置类
*
Expand All @@ -26,6 +30,14 @@
lazyInitialization = "${mybatis.lazy-initialization:false}") // Mapper 懒加载,目前仅用于单元测试
public class YudaoMybatisAutoConfiguration {

static {
// 动态 SQL 智能优化支持本地缓存加速解析,更完善的租户复杂 XML 动态 SQL 支持,静态注入缓存
JsqlParserGlobal.setJsqlParseCache(new JdkSerialCaffeineJsqlParseCache(
(cache) -> cache.maximumSize(1024)
.expireAfterWrite(5, TimeUnit.SECONDS))
);
}

@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
Expand All @@ -34,7 +46,7 @@ public MybatisPlusInterceptor mybatisPlusInterceptor() {
}

@Bean
public MetaObjectHandler defaultMetaObjectHandler(){
public MetaObjectHandler defaultMetaObjectHandler() {
return new DefaultDBFieldHandler(); // 自动填充参数类
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public boolean verifySignature(ApiSignature signature, HttpServletRequest reques

// 3. 将 nonce 记入缓存,防止重复使用(重点二:此处需要将 ttl 设定为允许 timestamp 时间差的值 x 2 )
String nonce = request.getHeader(signature.nonce());
signatureRedisDAO.setNonce(nonce, signature.timeout() * 2, signature.timeUnit());
signatureRedisDAO.setNonce(appId, nonce, signature.timeout() * 2, signature.timeUnit());
return true;
}

Expand Down Expand Up @@ -113,7 +113,7 @@ private boolean verifyHeaders(ApiSignature signature, HttpServletRequest request
}

// 3. 检查 nonce 是否存在,有且仅能使用一次
return signatureRedisDAO.getNonce(nonce) == null;
return signatureRedisDAO.getNonce(appId, nonce) == null;
}

/**
Expand Down Expand Up @@ -165,5 +165,4 @@ private static SortedMap<String, String> getRequestParameterMap(HttpServletReque
return sortedMap;
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ApiSignatureRedisDAO {
* VALUE 格式:String
* 过期时间:不固定
*/
private static final String SIGNATURE_NONCE = "api_signature_nonce:%s";
private static final String SIGNATURE_NONCE = "api_signature_nonce:%s:%s";

/**
* 签名密钥
Expand All @@ -36,16 +36,16 @@ public class ApiSignatureRedisDAO {

// ========== 验签随机数 ==========

public String getNonce(String nonce) {
return stringRedisTemplate.opsForValue().get(formatNonceKey(nonce));
public String getNonce(String appId, String nonce) {
return stringRedisTemplate.opsForValue().get(formatNonceKey(appId, nonce));
}

public void setNonce(String nonce, int time, TimeUnit timeUnit) {
stringRedisTemplate.opsForValue().set(formatNonceKey(nonce), "", time, timeUnit);
public void setNonce(String appId, String nonce, int time, TimeUnit timeUnit) {
stringRedisTemplate.opsForValue().set(formatNonceKey(appId, nonce), "", time, timeUnit);
}

private static String formatNonceKey(String key) {
return String.format(SIGNATURE_NONCE, key);
private static String formatNonceKey(String appId, String nonce) {
return String.format(SIGNATURE_NONCE, appId, nonce);
}

// ========== 签名密钥 ==========
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void testSignatureGet() throws IOException {
// 断言结果
assertTrue(result);
// 断言调用
verify(signatureRedisDAO).setNonce(eq(nonce), eq(120), eq(TimeUnit.SECONDS));
verify(signatureRedisDAO).setNonce(eq(appId), eq(nonce), eq(120), eq(TimeUnit.SECONDS));
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.mzt.logapi.beans.LogRecord;
import com.mzt.logapi.service.ILogRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
Expand All @@ -28,19 +29,24 @@ public class LogRecordServiceImpl implements ILogRecordService {
private OperateLogApi operateLogApi;

@Override
@Async
public void record(LogRecord logRecord) {
// 1. 补全通用字段
OperateLogCreateReqDTO reqDTO = new OperateLogCreateReqDTO();
reqDTO.setTraceId(TracerUtils.getTraceId());
// 补充用户信息
fillUserFields(reqDTO);
// 补全模块信息
fillModuleFields(reqDTO, logRecord);
// 补全请求信息
fillRequestFields(reqDTO);
try {
reqDTO.setTraceId(TracerUtils.getTraceId());
// 补充用户信息
fillUserFields(reqDTO);
// 补全模块信息
fillModuleFields(reqDTO, logRecord);
// 补全请求信息
fillRequestFields(reqDTO);

// 2. 异步记录日志
operateLogApi.createOperateLog(reqDTO);
// 2. 异步记录日志
operateLogApi.createOperateLog(reqDTO);
} catch (Throwable ex) {
// 由于 @Async 异步调用,这里打印下日志,更容易跟进
log.error("[record][url({}) log({}) 发生异常]", reqDTO.getRequestUrl(), reqDTO, ex);
}
}

private static void fillUserFields(OperateLogCreateReqDTO reqDTO) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public class BpmModelServiceImpl implements BpmModelService {
@Override
public PageResult<Model> getModelPage(BpmModelPageReqVO pageVO) {
ModelQuery modelQuery = repositoryService.createModelQuery();
modelQuery.modelTenantId(FlowableUtils.getTenantId());
if (StrUtil.isNotBlank(pageVO.getKey())) {
modelQuery.modelKey(pageVO.getKey());
}
Expand All @@ -78,7 +79,6 @@ public PageResult<Model> getModelPage(BpmModelPageReqVO pageVO) {
return PageResult.empty(count);
}
List<Model> models = modelQuery
.modelTenantId(FlowableUtils.getTenantId())
.orderByCreateTime().desc()
.listPage(PageUtils.getStart(pageVO), pageVO.getPageSize());
return new PageResult<>(models, count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public PageResult<Task> getTaskTodoPage(Long userId, BpmTaskPageReqVO pageVO) {
}
if (ArrayUtil.isNotEmpty(pageVO.getCreateTime())) {
taskQuery.taskCreatedAfter(DateUtils.of(pageVO.getCreateTime()[0]));
taskQuery.taskCreatedAfter(DateUtils.of(pageVO.getCreateTime()[1]));
taskQuery.taskCreatedBefore(DateUtils.of(pageVO.getCreateTime()[1]));
}
long count = taskQuery.count();
if (count == 0) {
Expand All @@ -119,7 +119,7 @@ public PageResult<HistoricTaskInstance> getTaskDonePage(Long userId, BpmTaskPage
}
if (ArrayUtil.isNotEmpty(pageVO.getCreateTime())) {
taskQuery.taskCreatedAfter(DateUtils.of(pageVO.getCreateTime()[0]));
taskQuery.taskCreatedAfter(DateUtils.of(pageVO.getCreateTime()[1]));
taskQuery.taskCreatedBefore(DateUtils.of(pageVO.getCreateTime()[1]));
}
// 执行查询
long count = taskQuery.count();
Expand All @@ -141,7 +141,7 @@ public PageResult<HistoricTaskInstance> getTaskPage(Long userId, BpmTaskPageReqV
}
if (ArrayUtil.isNotEmpty(pageVO.getCreateTime())) {
taskQuery.taskCreatedAfter(DateUtils.of(pageVO.getCreateTime()[0]));
taskQuery.taskCreatedAfter(DateUtils.of(pageVO.getCreateTime()[1]));
taskQuery.taskCreatedBefore(DateUtils.of(pageVO.getCreateTime()[1]));
}
// 执行查询
long count = taskQuery.count();
Expand Down

0 comments on commit ea75cf8

Please sign in to comment.