config缓存bug

This commit is contained in:
zy 2025-11-24 15:34:57 +08:00
parent 7b83871438
commit 0367d1ccc8
3 changed files with 23 additions and 1 deletions

View File

@ -8,6 +8,8 @@ import javax.servlet.http.HttpServletResponse;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CacheConstant;
import org.jeecg.common.constant.IotConstants;
import org.jeecg.common.system.query.QueryGenerator; import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.entity.SurvConfig; import org.jeecg.common.entity.SurvConfig;
import org.jeecg.common.vo.dict.DictVo; import org.jeecg.common.vo.dict.DictVo;
@ -20,6 +22,7 @@ import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.system.base.controller.JeecgController; import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@ -96,6 +99,7 @@ public class SurvConfigController extends JeecgController<SurvConfig, ISurvConfi
@ApiOperation(value="业务参数配置表-编辑", notes="业务参数配置表-编辑") @ApiOperation(value="业务参数配置表-编辑", notes="业务参数配置表-编辑")
@RequiresPermissions("appmana:surv_config:edit") @RequiresPermissions("appmana:surv_config:edit")
@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST}) @RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
@CacheEvict(value= {IotConstants.IOT_SURVCONFIG_CACHE}, allEntries=true)
public Result<String> edit(@RequestBody SurvConfig survConfig, HttpServletRequest request) { public Result<String> edit(@RequestBody SurvConfig survConfig, HttpServletRequest request) {
//创建更新时间不能编辑 //创建更新时间不能编辑
survConfig.setCreateTime(null); survConfig.setCreateTime(null);
@ -119,6 +123,7 @@ public class SurvConfigController extends JeecgController<SurvConfig, ISurvConfi
@ApiOperation(value="业务参数配置表-通过id删除", notes="业务参数配置表-通过id删除") @ApiOperation(value="业务参数配置表-通过id删除", notes="业务参数配置表-通过id删除")
@RequiresPermissions("appmana:surv_config:delete") @RequiresPermissions("appmana:surv_config:delete")
@DeleteMapping(value = "/delete") @DeleteMapping(value = "/delete")
@CacheEvict(value= {IotConstants.IOT_SURVCONFIG_CACHE}, allEntries=true)
public Result<String> delete(@RequestParam(name="id",required=true) String id) { public Result<String> delete(@RequestParam(name="id",required=true) String id) {
survConfigService.removeById(id); survConfigService.removeById(id);
return Result.OK("删除成功!"); return Result.OK("删除成功!");

View File

@ -13,6 +13,7 @@ import org.jeecg.modules.appmana.service.ISurvHisdataOrientwaterService;
import org.jeecg.modules.appmana.service.ISurvHisdataSoilService; import org.jeecg.modules.appmana.service.ISurvHisdataSoilService;
import org.jeecg.common.vo.VOHisResult; import org.jeecg.common.vo.VOHisResult;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@ -34,6 +35,7 @@ public class CommonServiceImpl {
@Autowired @Autowired
private ISurvHisdataLivestockwaterService hisdataLivestockwaterService; private ISurvHisdataLivestockwaterService hisdataLivestockwaterService;
@Autowired @Autowired
@Lazy
private SurvConfigServiceImpl configService; private SurvConfigServiceImpl configService;
/** /**
@ -146,4 +148,9 @@ public class CommonServiceImpl {
} }
return survConfig; return survConfig;
} }
public SurvConfig queryCacheSurvConfig(String tenantId,String configType){
return configService.getCacheConfig(tenantId, configType);
}
} }

View File

@ -10,7 +10,9 @@ import org.jeecg.common.entity.SurvConfig;
import org.jeecg.common.vo.dict.DictVo; import org.jeecg.common.vo.dict.DictVo;
import org.jeecg.modules.appmana.mapper.SurvConfigMapper; import org.jeecg.modules.appmana.mapper.SurvConfigMapper;
import org.jeecg.modules.appmana.service.ISurvConfigService; import org.jeecg.modules.appmana.service.ISurvConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@ -30,17 +32,25 @@ import java.util.stream.Collectors;
@Service @Service
public class SurvConfigServiceImpl extends ServiceImpl<SurvConfigMapper, SurvConfig> implements ISurvConfigService { public class SurvConfigServiceImpl extends ServiceImpl<SurvConfigMapper, SurvConfig> implements ISurvConfigService {
@Autowired
@Lazy
private CommonServiceImpl commonService;
@Override @Override
public String getValueByKey(String key) { public String getValueByKey(String key) {
return baseMapper.getValueByKey(key); return baseMapper.getValueByKey(key);
} }
@Override @Override
@Cacheable(value = IotConstants.IOT_SURVCONFIG_CACHE, key = "#tenantId+':'+#type", unless = "#result == null ")
public SurvConfig getOneByTypeWithTenant(String tenantId, String type) { public SurvConfig getOneByTypeWithTenant(String tenantId, String type) {
if(StringUtils.isBlank(tenantId)){ if(StringUtils.isBlank(tenantId)){
tenantId = "0"; tenantId = "0";
} }
return commonService.queryCacheSurvConfig(tenantId,type);
}
@Cacheable(value = IotConstants.IOT_SURVCONFIG_CACHE, key = "#tenantId+':'+#type", unless = "#result == null ")
public SurvConfig getCacheConfig(String tenantId, String type) {
return baseMapper.getOneByTypeWithTenant(tenantId, type); return baseMapper.getOneByTypeWithTenant(tenantId, type);
} }