From 7df381ec9690d9615d16e506ab80c2be45f1e979 Mon Sep 17 00:00:00 2001 From: Parker Date: Fri, 27 Nov 2020 16:12:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E5=AD=97=E5=85=B8=E4=B8=BA=E7=A9=BA=E6=97=B6=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E5=AD=97=E5=85=B8=E5=8F=AF=E8=83=BD=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E8=A1=A5=E5=85=A8BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/DictDetailServiceImpl.java | 169 ++++++++++-------- 1 file changed, 94 insertions(+), 75 deletions(-) diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/service/impl/DictDetailServiceImpl.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/service/impl/DictDetailServiceImpl.java index b94ac45d..4f06baf3 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/service/impl/DictDetailServiceImpl.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/service/impl/DictDetailServiceImpl.java @@ -42,7 +42,9 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.Collection; +import java.util.HashSet; import java.util.List; +import java.util.Set; /** @@ -81,30 +83,23 @@ public class DictDetailServiceImpl extends CrudServiceImpl listByTypeCode = this.findListByTypeCode(ret.getTypeCode()); + if(listByTypeCode != null && listByTypeCode.size() > 0){ + List dictWrapperList = Lists.newArrayListWithCapacity(listByTypeCode.size()); + for (DictDetailModel dictDetailModel : listByTypeCode) { + DictWrapper dictWrapperModel = new DictWrapper(); + dictWrapperModel.setTypeCode(dictDetailModel.getTypeCode()); + dictWrapperModel.setDictName(dictDetailModel.getDictName()); + dictWrapperModel.setDictValue(dictDetailModel.getDictValue()); + dictWrapperList.add(dictWrapperModel); + } + // 删除缓存 + DictUtil.delAll(ret.getTypeCode()); + // 广播缓存数据 - 通知其他服务器同步数据 + redisPlugin.sendMessage( + DictMsgFactory.createMsg(dictWrapperList, CacheType.DELETE) + ); + } } return ret; @@ -132,29 +127,23 @@ public class DictDetailServiceImpl extends CrudServiceImpl listByTypeCode = this.findListByTypeCode(oldModel.getTypeCode()); + if(listByTypeCode != null && listByTypeCode.size() > 0){ + List dictWrapperList = Lists.newArrayListWithCapacity(listByTypeCode.size()); + for (DictDetailModel dictDetailModel : listByTypeCode) { + DictWrapper dictWrapperModel = new DictWrapper(); + dictWrapperModel.setTypeCode(dictDetailModel.getTypeCode()); + dictWrapperModel.setDictName(dictDetailModel.getDictName()); + dictWrapperModel.setDictValue(dictDetailModel.getDictValue()); + dictWrapperList.add(dictWrapperModel); + } + // 删除缓存 + DictUtil.delAll(oldModel.getTypeCode()); + // 广播缓存数据 - 通知其他服务器同步数据 + redisPlugin.sendMessage( + DictMsgFactory.createMsg(dictWrapperList, CacheType.DELETE) + ); + } } return ret; @@ -168,19 +157,26 @@ public class DictDetailServiceImpl extends CrudServiceImpl listByTypeCode = this.findListByTypeCode(dictModel.getTypeCode()); + if(listByTypeCode != null && listByTypeCode.size() > 0){ + List dictWrapperList = Lists.newArrayListWithCapacity(listByTypeCode.size()); + for (DictDetailModel dictDetailModel : listByTypeCode) { + DictWrapper dictWrapperModel = new DictWrapper(); + dictWrapperModel.setTypeCode(dictDetailModel.getTypeCode()); + dictWrapperModel.setDictName(dictDetailModel.getDictName()); + dictWrapperModel.setDictValue(dictDetailModel.getDictValue()); + dictWrapperList.add(dictWrapperModel); + } + // 删除缓存 + DictUtil.delAll(dictModel.getTypeCode()); + // 广播缓存数据 - 通知其他服务器同步数据 + redisPlugin.sendMessage( + DictMsgFactory.createMsg(dictWrapperList, CacheType.DELETE) + ); + } } return ret; } @@ -192,19 +188,26 @@ public class DictDetailServiceImpl extends CrudServiceImpl listByTypeCode = this.findListByTypeCode(dictModel.getTypeCode()); + if(listByTypeCode != null && listByTypeCode.size() > 0){ + List dictWrapperList = Lists.newArrayListWithCapacity(listByTypeCode.size()); + for (DictDetailModel dictDetailModel : listByTypeCode) { + DictWrapper dictWrapperModel = new DictWrapper(); + dictWrapperModel.setTypeCode(dictDetailModel.getTypeCode()); + dictWrapperModel.setDictName(dictDetailModel.getDictName()); + dictWrapperModel.setDictValue(dictDetailModel.getDictValue()); + dictWrapperList.add(dictWrapperModel); + } + // 删除缓存 + DictUtil.delAll(dictModel.getTypeCode()); + // 广播缓存数据 - 通知其他服务器同步数据 + redisPlugin.sendMessage( + DictMsgFactory.createMsg(dictWrapperList, CacheType.DELETE) + ); + } } return ret; } @@ -226,16 +229,24 @@ public class DictDetailServiceImpl extends CrudServiceImpl 0){ List dictWrapperModels = Lists.newArrayListWithCapacity(list.size()); - // 删除缓存 + Set typeCodes = new HashSet<>(); + // 封装数据 for (SysDictDetail sysDictDetail : list) { DictWrapper dictWrapperModel = new DictWrapper(); dictWrapperModel.setTypeCode(sysDictDetail.getTypeCode()); dictWrapperModel.setDictName(sysDictDetail.getDictName()); dictWrapperModel.setDictValue(sysDictDetail.getDictValue()); - // 删除缓存 - DictUtil.del(dictWrapperModel); + dictWrapperModels.add(dictWrapperModel); + + typeCodes.add(dictWrapperModel.getTypeCode()); } + + // 删除缓存 + for (String typeCode : typeCodes) { + DictUtil.delAll(typeCode); + } + // 广播缓存数据 - 通知其他服务器同步数据 redisPlugin.sendMessage( DictMsgFactory.createMsg(dictWrapperModels, CacheType.DELETE) @@ -270,16 +281,24 @@ public class DictDetailServiceImpl extends CrudServiceImpl 0){ List dictWrapperModels = Lists.newArrayListWithCapacity(list.size()); - // 删除缓存 + Set typeCodes = new HashSet<>(); + // 封装数据 for (SysDictDetail sysDictDetail : list) { DictWrapper dictWrapperModel = new DictWrapper(); dictWrapperModel.setTypeCode(sysDictDetail.getTypeCode()); dictWrapperModel.setDictName(sysDictDetail.getDictName()); dictWrapperModel.setDictValue(sysDictDetail.getDictValue()); - // 删除缓存 - DictUtil.del(dictWrapperModel); + dictWrapperModels.add(dictWrapperModel); + + typeCodes.add(dictWrapperModel.getTypeCode()); } + + // 删除缓存 + for (String typeCode : typeCodes) { + DictUtil.delAll(typeCode); + } + // 广播缓存数据 - 通知其他服务器同步数据 redisPlugin.sendMessage( DictMsgFactory.createMsg(dictWrapperModels, CacheType.DELETE)