|
|
@@ -3,6 +3,7 @@ package org.dromara.system.service.impl;
|
|
|
import cn.hutool.core.date.DateField;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.thread.ThreadUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import org.dromara.common.core.service.OssService;
|
|
|
@@ -58,6 +59,7 @@ public class TblDzbcPathSchedulingServiceImpl implements ITblDzbcPathSchedulingS
|
|
|
*/
|
|
|
@Override
|
|
|
public TblDzbcPathSchedulingVo queryById(Long id){
|
|
|
+ SysCache();
|
|
|
return baseMapper.selectVoById(id);
|
|
|
}
|
|
|
|
|
|
@@ -142,7 +144,7 @@ public class TblDzbcPathSchedulingServiceImpl implements ITblDzbcPathSchedulingS
|
|
|
boolean flag = baseMapper.insert(add) > 0;
|
|
|
if (flag) {
|
|
|
bo.setId(add.getId());
|
|
|
- SysCache(add.getId(),null);
|
|
|
+ SysCache();
|
|
|
}
|
|
|
return flag;
|
|
|
}
|
|
|
@@ -156,48 +158,41 @@ public class TblDzbcPathSchedulingServiceImpl implements ITblDzbcPathSchedulingS
|
|
|
validEntityBeforeSave(update);
|
|
|
int c = baseMapper.updateById(update) ;
|
|
|
if(c>0){
|
|
|
- SysCache(bo.getId(),null);
|
|
|
+ SysCache();
|
|
|
}
|
|
|
return c> 0;
|
|
|
}
|
|
|
|
|
|
|
|
|
- private void SysCache(Long id, Collection<Long> ids) {
|
|
|
- try {
|
|
|
|
|
|
- if(ids!=null){
|
|
|
- List<String> keys = RedisUtils.keys("dzbc_path_scheduling").stream().toList();
|
|
|
- for (String key : keys) {
|
|
|
- Map<String,TblDzbcPathSchedulingVo> boMap = RedisUtils.getCacheMap(key.toString());
|
|
|
- if(boMap == null){
|
|
|
- boMap = new HashMap<>();
|
|
|
- }
|
|
|
- for (Long id1 : ids) {
|
|
|
- boMap.remove(id1.toString());
|
|
|
- }
|
|
|
- RedisUtils.setCacheMap(key.toString(),boMap);
|
|
|
- String date = key.split("\\|")[1];
|
|
|
- long datetime = DateUtil.parseDate(date).getTime();
|
|
|
- long currentdatetime = DateUtil.parseDate(DateUtil.today()).getTime();
|
|
|
- if(datetime<currentdatetime){
|
|
|
- RedisUtils.deleteObject(key.toString());
|
|
|
+ @Override
|
|
|
+ public void SysCache() {
|
|
|
+ try {
|
|
|
+ ThreadUtil.execAsync(new Runnable() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ TblDzbcPathSchedulingBo bo = new TblDzbcPathSchedulingBo();
|
|
|
+ bo.getParams().put("mdate", DateUtil.today());
|
|
|
+ LambdaQueryWrapper<TblDzbcPathScheduling> lqw = buildQueryWrapper(bo);
|
|
|
+ List<TblDzbcPathSchedulingVo> list = baseMapper.selectVoList(lqw);
|
|
|
+ Map<String,Map<String,TblDzbcPathSchedulingVo> > map = new HashMap<>();
|
|
|
+ for (TblDzbcPathSchedulingVo tblDzbcPathSchedulingVo : list) {
|
|
|
+ if(tblDzbcPathSchedulingVo.getMdate()!=null){
|
|
|
+ if(map.containsKey(DateUtil.formatDate(tblDzbcPathSchedulingVo.getMdate()))){
|
|
|
+ map.get(DateUtil.formatDate(tblDzbcPathSchedulingVo.getMdate())).put(tblDzbcPathSchedulingVo.getId().toString(),tblDzbcPathSchedulingVo);
|
|
|
+ }else{
|
|
|
+ map.put(DateUtil.formatDate(tblDzbcPathSchedulingVo.getMdate()),Map.of(tblDzbcPathSchedulingVo.getId().toString(),tblDzbcPathSchedulingVo));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- RedisUtils.expire(key.toString(),DateUtil.parseDate(date).offset(DateField.HOUR_OF_DAY,24).getTime()-DateUtil.current() );
|
|
|
+ map.keySet().forEach(key ->{
|
|
|
+ RedisUtils.setCacheMap(StrUtil.format("dzbc_path_scheduling|{}", key), map.get(key));
|
|
|
+ RedisUtils.expire(StrUtil.format("dzbc_path_scheduling|{}", key), DateUtil.offset(DateUtil.parseDate(key), DateField.HOUR_OF_DAY, 24).getTime() - DateUtil.current());
|
|
|
+ });
|
|
|
}
|
|
|
- }else{
|
|
|
- TblDzbcPathSchedulingVo bo = baseMapper.selectVoById(id);
|
|
|
- if(bo == null||bo.getMdate()==null) return;
|
|
|
- {
|
|
|
- Map<String, TblDzbcPathSchedulingVo> boMap = RedisUtils.getCacheMap(StrUtil.format("dzbc_path_scheduling|{}", DateUtil.formatDate(bo.getMdate())));
|
|
|
- if (boMap == null||boMap.size() <1) {
|
|
|
- boMap = new HashMap<>();
|
|
|
- }
|
|
|
+ });
|
|
|
|
|
|
- boMap.put(id.toString(), bo);
|
|
|
- RedisUtils.setCacheMap(StrUtil.format("dzbc_path_scheduling|{}", DateUtil.formatDate(bo.getMdate())), boMap);
|
|
|
- RedisUtils.expire(StrUtil.format("dzbc_path_scheduling|{}", DateUtil.formatDate(bo.getMdate())), DateUtil.offset(bo.getMdate(), DateField.HOUR_OF_DAY, 24).getTime() - DateUtil.current());
|
|
|
- }
|
|
|
- }
|
|
|
}catch (Exception e){}
|
|
|
|
|
|
|
|
|
@@ -221,7 +216,7 @@ public class TblDzbcPathSchedulingServiceImpl implements ITblDzbcPathSchedulingS
|
|
|
}
|
|
|
int c = baseMapper.deleteBatchIds(ids) ;
|
|
|
if(c>0){
|
|
|
- SysCache(null,ids);
|
|
|
+ SysCache();
|
|
|
}
|
|
|
return c>0;
|
|
|
}
|