修复初始化字典为空时 新增字典可能无法补全BUG

v1.4.1
Parker 4 years ago
parent a9048d40f8
commit 7df381ec96

@ -42,7 +42,9 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
/** /**
@ -81,30 +83,23 @@ public class DictDetailServiceImpl extends CrudServiceImpl<DictDetailMapper, Sys
DictDetailModel ret = super.insert(model); DictDetailModel ret = super.insert(model);
if(ret != null){ if(ret != null){
DictWrapper dictWrapperModel = new DictWrapper(); List<DictDetailModel> listByTypeCode = this.findListByTypeCode(ret.getTypeCode());
dictWrapperModel.setTypeCode(model.getTypeCode()); if(listByTypeCode != null && listByTypeCode.size() > 0){
dictWrapperModel.setDictName(model.getDictName()); List<DictWrapper> dictWrapperList = Lists.newArrayListWithCapacity(listByTypeCode.size());
dictWrapperModel.setDictValue(model.getDictValue()); for (DictDetailModel dictDetailModel : listByTypeCode) {
dictWrapperModel.setModel(ret); DictWrapper dictWrapperModel = new DictWrapper();
// 先删老缓存 dictWrapperModel.setTypeCode(dictDetailModel.getTypeCode());
DictUtil.del(dictWrapperModel); dictWrapperModel.setDictName(dictDetailModel.getDictName());
// 广播缓存数据 - 通知其他服务器同步数据 dictWrapperModel.setDictValue(dictDetailModel.getDictValue());
redisPlugin.sendMessage( dictWrapperList.add(dictWrapperModel);
DictMsgFactory.createMsg(dictWrapperModel, CacheType.DELETE) }
); // 删除缓存
DictUtil.delAll(ret.getTypeCode());
// 先删老缓存 // 广播缓存数据 - 通知其他服务器同步数据
DictWrapper currDictWrapperModel = new DictWrapper(); redisPlugin.sendMessage(
currDictWrapperModel.setTypeCode(ret.getTypeCode()); DictMsgFactory.createMsg(dictWrapperList, CacheType.DELETE)
currDictWrapperModel.setDictName(ret.getDictName()); );
currDictWrapperModel.setDictValue(ret.getDictValue()); }
currDictWrapperModel.setModel(ret);
// 增加缓存
DictUtil.put(currDictWrapperModel);
// 广播缓存数据 - 通知其他服务器同步数据
redisPlugin.sendMessage(
DictMsgFactory.createMsg(currDictWrapperModel, CacheType.UPDATE)
);
} }
return ret; return ret;
@ -132,29 +127,23 @@ public class DictDetailServiceImpl extends CrudServiceImpl<DictDetailMapper, Sys
DictDetailModel ret = super.update(model); DictDetailModel ret = super.update(model);
if(ret != null){ if(ret != null){
// 先删老缓存 List<DictDetailModel> listByTypeCode = this.findListByTypeCode(oldModel.getTypeCode());
DictWrapper oldDictWrapperModel = new DictWrapper(); if(listByTypeCode != null && listByTypeCode.size() > 0){
oldDictWrapperModel.setTypeCode(oldModel.getTypeCode()); List<DictWrapper> dictWrapperList = Lists.newArrayListWithCapacity(listByTypeCode.size());
oldDictWrapperModel.setDictName(oldModel.getDictName()); for (DictDetailModel dictDetailModel : listByTypeCode) {
oldDictWrapperModel.setDictValue(oldModel.getDictValue()); DictWrapper dictWrapperModel = new DictWrapper();
DictUtil.del(oldDictWrapperModel); dictWrapperModel.setTypeCode(dictDetailModel.getTypeCode());
// 广播缓存数据 - 通知其他服务器同步数据 dictWrapperModel.setDictName(dictDetailModel.getDictName());
redisPlugin.sendMessage( dictWrapperModel.setDictValue(dictDetailModel.getDictValue());
DictMsgFactory.createMsg(oldDictWrapperModel, CacheType.DELETE) dictWrapperList.add(dictWrapperModel);
); }
// 删除缓存
// 先删老缓存 DictUtil.delAll(oldModel.getTypeCode());
DictWrapper currDictWrapperModel = new DictWrapper(); // 广播缓存数据 - 通知其他服务器同步数据
currDictWrapperModel.setTypeCode(ret.getTypeCode()); redisPlugin.sendMessage(
currDictWrapperModel.setDictName(ret.getDictName()); DictMsgFactory.createMsg(dictWrapperList, CacheType.DELETE)
currDictWrapperModel.setDictValue(ret.getDictValue()); );
currDictWrapperModel.setModel(ret); }
// 增加缓存
DictUtil.put(currDictWrapperModel);
// 广播缓存数据 - 通知其他服务器同步数据
redisPlugin.sendMessage(
DictMsgFactory.createMsg(currDictWrapperModel, CacheType.UPDATE)
);
} }
return ret; return ret;
@ -168,19 +157,26 @@ public class DictDetailServiceImpl extends CrudServiceImpl<DictDetailMapper, Sys
*/ */
@Override @Override
public boolean delete(String id) { public boolean delete(String id) {
DictDetailModel dictDetailModel = this.get(id); DictDetailModel dictModel = this.get(id);
boolean ret = super.delete(id); boolean ret = super.delete(id);
if(ret){ if(ret){
DictWrapper dictWrapperModel = new DictWrapper(); List<DictDetailModel> listByTypeCode = this.findListByTypeCode(dictModel.getTypeCode());
dictWrapperModel.setTypeCode(dictDetailModel.getTypeCode()); if(listByTypeCode != null && listByTypeCode.size() > 0){
dictWrapperModel.setDictName(dictDetailModel.getDictName()); List<DictWrapper> dictWrapperList = Lists.newArrayListWithCapacity(listByTypeCode.size());
dictWrapperModel.setDictValue(dictDetailModel.getDictValue()); for (DictDetailModel dictDetailModel : listByTypeCode) {
// 删除缓存 DictWrapper dictWrapperModel = new DictWrapper();
DictUtil.del(dictWrapperModel); dictWrapperModel.setTypeCode(dictDetailModel.getTypeCode());
// 广播缓存数据 - 通知其他服务器同步数据 dictWrapperModel.setDictName(dictDetailModel.getDictName());
redisPlugin.sendMessage( dictWrapperModel.setDictValue(dictDetailModel.getDictValue());
DictMsgFactory.createMsg(dictWrapperModel, CacheType.DELETE) dictWrapperList.add(dictWrapperModel);
); }
// 删除缓存
DictUtil.delAll(dictModel.getTypeCode());
// 广播缓存数据 - 通知其他服务器同步数据
redisPlugin.sendMessage(
DictMsgFactory.createMsg(dictWrapperList, CacheType.DELETE)
);
}
} }
return ret; return ret;
} }
@ -192,19 +188,26 @@ public class DictDetailServiceImpl extends CrudServiceImpl<DictDetailMapper, Sys
*/ */
@Override @Override
public boolean delete(DictDetailModel model) { public boolean delete(DictDetailModel model) {
DictDetailModel dictDetailModel = this.get(model); DictDetailModel dictModel = this.get(model);
boolean ret = super.delete(model); boolean ret = super.delete(model);
if(ret){ if(ret){
DictWrapper dictWrapperModel = new DictWrapper(); List<DictDetailModel> listByTypeCode = this.findListByTypeCode(dictModel.getTypeCode());
dictWrapperModel.setTypeCode(dictDetailModel.getTypeCode()); if(listByTypeCode != null && listByTypeCode.size() > 0){
dictWrapperModel.setDictName(dictDetailModel.getDictName()); List<DictWrapper> dictWrapperList = Lists.newArrayListWithCapacity(listByTypeCode.size());
dictWrapperModel.setDictValue(dictDetailModel.getDictValue()); for (DictDetailModel dictDetailModel : listByTypeCode) {
// 删除缓存 DictWrapper dictWrapperModel = new DictWrapper();
DictUtil.del(dictWrapperModel); dictWrapperModel.setTypeCode(dictDetailModel.getTypeCode());
// 广播缓存数据 - 通知其他服务器同步数据 dictWrapperModel.setDictName(dictDetailModel.getDictName());
redisPlugin.sendMessage( dictWrapperModel.setDictValue(dictDetailModel.getDictValue());
DictMsgFactory.createMsg(dictWrapperModel, CacheType.DELETE) dictWrapperList.add(dictWrapperModel);
); }
// 删除缓存
DictUtil.delAll(dictModel.getTypeCode());
// 广播缓存数据 - 通知其他服务器同步数据
redisPlugin.sendMessage(
DictMsgFactory.createMsg(dictWrapperList, CacheType.DELETE)
);
}
} }
return ret; return ret;
} }
@ -226,16 +229,24 @@ public class DictDetailServiceImpl extends CrudServiceImpl<DictDetailMapper, Sys
if(ret){ if(ret){
if(list != null && list.size() > 0){ if(list != null && list.size() > 0){
List<DictWrapper> dictWrapperModels = Lists.newArrayListWithCapacity(list.size()); List<DictWrapper> dictWrapperModels = Lists.newArrayListWithCapacity(list.size());
// 删除缓存 Set<String> typeCodes = new HashSet<>();
// 封装数据
for (SysDictDetail sysDictDetail : list) { for (SysDictDetail sysDictDetail : list) {
DictWrapper dictWrapperModel = new DictWrapper(); DictWrapper dictWrapperModel = new DictWrapper();
dictWrapperModel.setTypeCode(sysDictDetail.getTypeCode()); dictWrapperModel.setTypeCode(sysDictDetail.getTypeCode());
dictWrapperModel.setDictName(sysDictDetail.getDictName()); dictWrapperModel.setDictName(sysDictDetail.getDictName());
dictWrapperModel.setDictValue(sysDictDetail.getDictValue()); dictWrapperModel.setDictValue(sysDictDetail.getDictValue());
// 删除缓存
DictUtil.del(dictWrapperModel);
dictWrapperModels.add(dictWrapperModel); dictWrapperModels.add(dictWrapperModel);
typeCodes.add(dictWrapperModel.getTypeCode());
} }
// 删除缓存
for (String typeCode : typeCodes) {
DictUtil.delAll(typeCode);
}
// 广播缓存数据 - 通知其他服务器同步数据 // 广播缓存数据 - 通知其他服务器同步数据
redisPlugin.sendMessage( redisPlugin.sendMessage(
DictMsgFactory.createMsg(dictWrapperModels, CacheType.DELETE) DictMsgFactory.createMsg(dictWrapperModels, CacheType.DELETE)
@ -270,16 +281,24 @@ public class DictDetailServiceImpl extends CrudServiceImpl<DictDetailMapper, Sys
if(ret){ if(ret){
if(list != null && list.size() > 0){ if(list != null && list.size() > 0){
List<DictWrapper> dictWrapperModels = Lists.newArrayListWithCapacity(list.size()); List<DictWrapper> dictWrapperModels = Lists.newArrayListWithCapacity(list.size());
// 删除缓存 Set<String> typeCodes = new HashSet<>();
// 封装数据
for (SysDictDetail sysDictDetail : list) { for (SysDictDetail sysDictDetail : list) {
DictWrapper dictWrapperModel = new DictWrapper(); DictWrapper dictWrapperModel = new DictWrapper();
dictWrapperModel.setTypeCode(sysDictDetail.getTypeCode()); dictWrapperModel.setTypeCode(sysDictDetail.getTypeCode());
dictWrapperModel.setDictName(sysDictDetail.getDictName()); dictWrapperModel.setDictName(sysDictDetail.getDictName());
dictWrapperModel.setDictValue(sysDictDetail.getDictValue()); dictWrapperModel.setDictValue(sysDictDetail.getDictValue());
// 删除缓存
DictUtil.del(dictWrapperModel);
dictWrapperModels.add(dictWrapperModel); dictWrapperModels.add(dictWrapperModel);
typeCodes.add(dictWrapperModel.getTypeCode());
} }
// 删除缓存
for (String typeCode : typeCodes) {
DictUtil.delAll(typeCode);
}
// 广播缓存数据 - 通知其他服务器同步数据 // 广播缓存数据 - 通知其他服务器同步数据
redisPlugin.sendMessage( redisPlugin.sendMessage(
DictMsgFactory.createMsg(dictWrapperModels, CacheType.DELETE) DictMsgFactory.createMsg(dictWrapperModels, CacheType.DELETE)

Loading…
Cancel
Save