添加缓存注解以优化性能
- 在 MaterialLeaseInfoServiceImpl 类中的 getUseTypeTree、getTeamByNameCached 和 getAgreementInfoCached 方法上添加 Cacheable 注解 -通过缓存结果减少数据库查询次数,提高系统响应速度 -优化了与项目 ID、班组名称和协议 ID 相关的数据查询
This commit is contained in:
parent
0f3582ab4c
commit
9361352ee1
|
|
@ -46,6 +46,7 @@ import com.bonus.material.task.domain.TmTaskAgreement;
|
|||
import com.bonus.material.task.mapper.TmTaskAgreementMapper;
|
||||
import com.bonus.material.task.mapper.TmTaskMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
|
@ -1338,6 +1339,8 @@ public class MaterialLeaseInfoServiceImpl implements MaterialLeaseInfoService {
|
|||
* @return
|
||||
*/
|
||||
@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) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
log.info("开始执行getUseTypeTree方法,参数:proId={}, teamName={}, agreementIdList={}",
|
||||
|
|
@ -1504,7 +1507,8 @@ public class MaterialLeaseInfoServiceImpl implements MaterialLeaseInfoService {
|
|||
* @param teamName 班组名称
|
||||
* @return 班组信息
|
||||
*/
|
||||
private BmTeam getTeamByNameCached(String teamName) {
|
||||
@Cacheable(value = "teamCache", key = "#teamName", unless = "#result == null")
|
||||
public BmTeam getTeamByNameCached(String teamName) {
|
||||
BmTeam bmTeam = new BmTeam();
|
||||
bmTeam.setTeamName(teamName);
|
||||
return bmTeamMapper.selectByName(bmTeam);
|
||||
|
|
@ -1515,7 +1519,8 @@ public class MaterialLeaseInfoServiceImpl implements MaterialLeaseInfoService {
|
|||
* @param bean 查询参数
|
||||
* @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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue