移除缓存配置并调整相关代码

- 删除了 CacheConfig 类和 RedisCacheConfig 类
- 移除了 ComplexQueryController 中的缓存相关注解
- 调整了 MaterialLeaseInfoServiceImpl 中的缓存相关方法,改为私有方法
- 重命名了 ProjUsingRecordExports 类,修正了包结构
- 优化了 PreventRepeatSubmitAspect 中的日志记录和错误处理
This commit is contained in:
syruan 2025-09-06 18:34:32 +08:00
parent 40b9706aae
commit 1ac2534ff9
6 changed files with 17 additions and 135 deletions

View File

@ -1,110 +0,0 @@
package com.bonus.material.config;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.cache.interceptor.KeyGenerator;
import java.lang.reflect.Method;
import java.util.Arrays;
/**
* 缓存配置类
* 为getUseTypeTree方法优化提供缓存支持
*/
@Configuration
@EnableCaching
public class CacheConfig {
/**
* 缓存管理器配置
* 使用ConcurrentMapCacheManager作为简单的内存缓存
* 生产环境建议使用Redis等分布式缓存
*/
@Bean
public CacheManager cacheManager() {
ConcurrentMapCacheManager cacheManager = new ConcurrentMapCacheManager();
// 配置缓存名称
cacheManager.setCacheNames(Arrays.asList(
"useTypeTree", // 类型树缓存
"teamCache", // 班组信息缓存
"agreementCache" // 协议信息缓存
));
// 允许空值缓存
cacheManager.setAllowNullValues(false);
return cacheManager;
}
/**
* 自定义键生成器
* 用于生成更精确的缓存键
*/
@Bean("customKeyGenerator")
public KeyGenerator keyGenerator() {
return new KeyGenerator() {
@Override
public Object generate(Object target, Method method, Object... params) {
StringBuilder sb = new StringBuilder();
sb.append(target.getClass().getSimpleName()).append(".");
sb.append(method.getName()).append("(");
for (int i = 0; i < params.length; i++) {
if (i > 0) {
sb.append(",");
}
if (params[i] != null) {
sb.append(params[i].toString());
} else {
sb.append("null");
}
}
sb.append(")");
return sb.toString();
}
};
}
}
/**
* Redis缓存配置可选
* 如果需要使用Redis作为缓存可以启用以下配置
*/
/*
@Configuration
@EnableCaching
@ConditionalOnProperty(name = "spring.cache.type", havingValue = "redis")
public class RedisCacheConfig {
@Bean
public RedisCacheManager cacheManager(RedisConnectionFactory connectionFactory) {
RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig()
.entryTtl(Duration.ofMinutes(30)) // 缓存30分钟过期
.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer()))
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer()))
.disableCachingNullValues();
// 为不同的缓存设置不同的过期时间
Map<String, RedisCacheConfiguration> cacheConfigurations = new HashMap<>();
// 类型树缓存 - 30分钟过期
cacheConfigurations.put("useTypeTree", config.entryTtl(Duration.ofMinutes(30)));
// 班组缓存 - 1小时过期
cacheConfigurations.put("teamCache", config.entryTtl(Duration.ofHours(1)));
// 协议缓存 - 15分钟过期
cacheConfigurations.put("agreementCache", config.entryTtl(Duration.ofMinutes(15)));
return RedisCacheManager.builder(connectionFactory)
.cacheDefaults(config)
.withInitialCacheConfigurations(cacheConfigurations)
.build();
}
}
*/

View File

@ -9,12 +9,11 @@ import com.bonus.common.core.utils.poi.ExcelUtil;
import com.bonus.common.core.web.controller.BaseController; import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult; import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.security.utils.SecurityUtils; import com.bonus.common.security.utils.SecurityUtils;
import com.bonus.material.basic.ProjUsingRecordExports; import com.bonus.material.basic.domain.ProjUsingRecordExports;
import com.bonus.material.basic.domain.*; import com.bonus.material.basic.domain.*;
import com.bonus.material.basic.domain.vo.MaTypeSelectInfo; import com.bonus.material.basic.domain.vo.MaTypeSelectInfo;
import com.bonus.material.basic.service.ComplexQueryService; import com.bonus.material.basic.service.ComplexQueryService;
import com.bonus.material.ma.domain.Type; import com.bonus.material.ma.domain.Type;
import com.bonus.system.api.domain.SysUser;
import com.bonus.system.api.model.LoginUser; import com.bonus.system.api.model.LoginUser;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;

View File

@ -5,6 +5,7 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
/** /**
@ -14,7 +15,7 @@ import java.math.BigDecimal;
*/ */
@ApiModel(description = "退料查询") @ApiModel(description = "退料查询")
@Data @Data
public class ProjUsingRecordExport { public class ProjUsingRecordExport implements Serializable {
private static final long serialVersionUID = 2227217051604273598L; private static final long serialVersionUID = 2227217051604273598L;

View File

@ -1,10 +1,11 @@
package com.bonus.material.basic; package com.bonus.material.basic.domain;
import com.bonus.common.core.annotation.Excel; import com.bonus.common.core.annotation.Excel;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
/** /**
@ -14,7 +15,7 @@ import java.math.BigDecimal;
*/ */
@ApiModel(description = "退料查询") @ApiModel(description = "退料查询")
@Data @Data
public class ProjUsingRecordExports { public class ProjUsingRecordExports implements Serializable {
private static final long serialVersionUID = 2227217051604273598L; private static final long serialVersionUID = 2227217051604273598L;

View File

@ -46,7 +46,6 @@ import com.bonus.material.task.domain.TmTaskAgreement;
import com.bonus.material.task.mapper.TmTaskAgreementMapper; import com.bonus.material.task.mapper.TmTaskAgreementMapper;
import com.bonus.material.task.mapper.TmTaskMapper; import com.bonus.material.task.mapper.TmTaskMapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -1335,16 +1334,11 @@ public class MaterialLeaseInfoServiceImpl implements MaterialLeaseInfoService {
/** /**
* 材料站在库设备类型树(即机具在用设备) * 材料站在库设备类型树(即机具在用设备)
* @param bean
* @return
*/ */
@Override @Override
@Cacheable(value = "useTypeTree", key = "#bean.proId + '_' + #bean.teamName + '_' + (#bean.agreementIdList != null ? #bean.agreementIdList.toString() : 'null')",
unless = "#result == null || #result.data == null", condition = "#bean.proId != null")
public AjaxResult getUseTypeTree(MaterialLeaseApplyInfo bean) { public AjaxResult getUseTypeTree(MaterialLeaseApplyInfo bean) {
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
log.info("开始执行getUseTypeTree方法参数proId={}, teamName={}, agreementIdList={}", log.info("开始执行getUseTypeTree方法参数proId={}, teamName={}, agreementIdList={}", bean.getProId(), bean.getTeamName(), bean.getAgreementIdList());
bean.getProId(), bean.getTeamName(), bean.getAgreementIdList());
List<TypeTreeNode> groupList = new ArrayList<>(); List<TypeTreeNode> groupList = new ArrayList<>();
List<TypeTreeNode> list = new ArrayList<>(); List<TypeTreeNode> list = new ArrayList<>();
@ -1507,8 +1501,7 @@ public class MaterialLeaseInfoServiceImpl implements MaterialLeaseInfoService {
* @param teamName 班组名称 * @param teamName 班组名称
* @return 班组信息 * @return 班组信息
*/ */
@Cacheable(value = "teamCache", key = "#teamName", unless = "#result == null") private BmTeam getTeamByNameCached(String teamName) {
public BmTeam getTeamByNameCached(String teamName) {
BmTeam bmTeam = new BmTeam(); BmTeam bmTeam = new BmTeam();
bmTeam.setTeamName(teamName); bmTeam.setTeamName(teamName);
return bmTeamMapper.selectByName(bmTeam); return bmTeamMapper.selectByName(bmTeam);
@ -1519,8 +1512,7 @@ public class MaterialLeaseInfoServiceImpl implements MaterialLeaseInfoService {
* @param bean 查询参数 * @param bean 查询参数
* @return 协议信息 * @return 协议信息
*/ */
@Cacheable(value = "agreementCache", key = "#bean.proId + '_' + #bean.teamId", unless = "#result == null") private BmAgreementInfo getAgreementInfoCached(MaterialLeaseApplyInfo bean) {
public BmAgreementInfo getAgreementInfoCached(MaterialLeaseApplyInfo bean) {
return materialLeaseInfoMapper.getAgreeId(bean); return materialLeaseInfoMapper.getAgreeId(bean);
} }

View File

@ -24,7 +24,7 @@ import java.util.concurrent.TimeUnit;
@Aspect @Aspect
@Component @Component
public class PreventRepeatSubmitAspect { public class PreventRepeatSubmitAspect {
private static final Logger LOG = LoggerFactory.getLogger(PreventRepeatSubmitAspect.class); private static final Logger log = LoggerFactory.getLogger(PreventRepeatSubmitAspect.class);
private static final String header = "Authorization"; private static final String header = "Authorization";
@Autowired @Autowired
@ -38,18 +38,17 @@ public class PreventRepeatSubmitAspect {
@Around("preventRepeatSubmit()") @Around("preventRepeatSubmit()")
public Object checkPrs(ProceedingJoinPoint pjp) throws Throwable { public Object checkPrs(ProceedingJoinPoint pjp) throws Throwable {
LOG.info("进入preventRepeatSubmit切面"); log.info("进入preventRepeatSubmit切面");
//得到request对象 //得到request对象
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
String requestURI = request.getRequestURI(); String requestURI = request.getRequestURI();
LOG.info("防重复提交的请求地址:{} ,请求方式:{}",requestURI,request.getMethod()); log.info("防重复提交的请求地址:{} ,请求方式:{}",requestURI,request.getMethod());
LOG.info("防重复提交拦截到的类名:{} ,方法:{}",pjp.getTarget().getClass().getSimpleName(),pjp.getSignature().getName()); log.info("防重复提交拦截到的类名:{} ,方法:{}",pjp.getTarget().getClass().getSimpleName(),pjp.getSignature().getName());
//获取请求参数 //获取请求参数
Object[] args = pjp.getArgs(); Object[] args = pjp.getArgs();
String argStr = ""; String argStr = "";
for (int i = 0; i < args.length; i++) { for (Object obj : args) {
Object obj = args[i];
try { try {
if (Objects.nonNull(obj)) { if (Objects.nonNull(obj)) {
//这里替换是为了在redis可视化工具中方便查看, argStr=argStr.replace(":","#"); //这里替换是为了在redis可视化工具中方便查看, argStr=argStr.replace(":","#");
@ -57,7 +56,7 @@ public class PreventRepeatSubmitAspect {
} }
break; break;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); log.error("获取参数异常", e);
} }
} }
@ -69,7 +68,7 @@ public class PreventRepeatSubmitAspect {
Method method=ms.getMethod(); Method method=ms.getMethod();
PreventRepeatSubmit preventRepeatSubmit=method.getAnnotation(PreventRepeatSubmit.class); PreventRepeatSubmit preventRepeatSubmit=method.getAnnotation(PreventRepeatSubmit.class);
int interval = preventRepeatSubmit.interval(); int interval = preventRepeatSubmit.interval();
LOG.info("获取到preventRepeatSubmit的有效期时间"+interval); log.info("获取到preventRepeatSubmit的有效期时间{}", interval);
//redis分布式锁 //redis分布式锁
Boolean aBoolean = redisCache.setNxCacheObject(cacheRepeatKey, 1, preventRepeatSubmit.interval(), TimeUnit.SECONDS); Boolean aBoolean = redisCache.setNxCacheObject(cacheRepeatKey, 1, preventRepeatSubmit.interval(), TimeUnit.SECONDS);
//aBoolean为true则证明没有重复提交 //aBoolean为true则证明没有重复提交