添加缓存注解以优化性能

- 在 MaterialLeaseInfoServiceImpl 类中的 getUseTypeTree、getTeamByNameCached 和 getAgreementInfoCached 方法上添加 Cacheable 注解
-通过缓存结果减少数据库查询次数,提高系统响应速度
-优化了与项目 ID、班组名称和协议 ID 相关的数据查询
This commit is contained in:
syruan 2025-09-06 17:40:21 +08:00
parent 0f3582ab4c
commit 9361352ee1
1 changed files with 7 additions and 2 deletions

View File

@ -46,6 +46,7 @@ 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;
@ -1338,6 +1339,8 @@ public class MaterialLeaseInfoServiceImpl implements MaterialLeaseInfoService {
* @return * @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={}",
@ -1504,7 +1507,8 @@ public class MaterialLeaseInfoServiceImpl implements MaterialLeaseInfoService {
* @param teamName 班组名称 * @param teamName 班组名称
* @return 班组信息 * @return 班组信息
*/ */
private BmTeam getTeamByNameCached(String teamName) { @Cacheable(value = "teamCache", key = "#teamName", unless = "#result == null")
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);
@ -1515,7 +1519,8 @@ public class MaterialLeaseInfoServiceImpl implements MaterialLeaseInfoService {
* @param bean 查询参数 * @param bean 查询参数
* @return 协议信息 * @return 协议信息
*/ */
private BmAgreementInfo getAgreementInfoCached(MaterialLeaseApplyInfo bean) { @Cacheable(value = "agreementCache", key = "#bean.proId + '_' + #bean.teamId", unless = "#result == null")
public BmAgreementInfo getAgreementInfoCached(MaterialLeaseApplyInfo bean) {
return materialLeaseInfoMapper.getAgreeId(bean); return materialLeaseInfoMapper.getAgreeId(bean);
} }