diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/dict/SysDictDataService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/dict/SysDictDataService.java index 20457202db..6375615c08 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/dict/SysDictDataService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/dict/SysDictDataService.java @@ -37,6 +37,19 @@ public interface SysDictDataService extends DictDataFrameworkService { */ void updateDictData(SysDictDataUpdateReqVO reqVO); + /** + * 手动更新字典数据 + */ + + void refreshDictData(); + /** + * 更新字典类型 + * + * @param oldType 旧字典类型 + * @param newType 新字典类型 + */ + void updateDictDataType(String oldType, String newType); + /** * 删除字典数据 * diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/dict/impl/SysDictDataServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/dict/impl/SysDictDataServiceImpl.java index 4f23dac881..a386d1795f 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/dict/impl/SysDictDataServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/dict/impl/SysDictDataServiceImpl.java @@ -16,6 +16,7 @@ import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.dict.SysDictDataMap import cn.iocoder.yudao.adminserver.modules.system.mq.producer.dict.SysDictDataProducer; import cn.iocoder.yudao.adminserver.modules.system.service.dict.SysDictDataService; import cn.iocoder.yudao.adminserver.modules.system.service.dict.SysDictTypeService; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableTable; import lombok.extern.slf4j.Slf4j; @@ -177,6 +178,21 @@ public class SysDictDataServiceImpl implements SysDictDataService { dictDataProducer.sendDictDataRefreshMessage(); } + @Override + public void refreshDictData() { + initLocalCache(); + } + + @Override + public void updateDictDataType(String oldType, String newType) { + if (oldType == null || newType == null) { + return; + } + dictDataMapper.update(new SysDictDataDO(), new LambdaUpdateWrapper() + .set(SysDictDataDO::getDictType, newType) + .eq(SysDictDataDO::getDictType, oldType)); + } + @Override public void deleteDictData(Long id) { // 校验是否存在 diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/dict/impl/SysDictTypeServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/dict/impl/SysDictTypeServiceImpl.java index 36a14b4152..1acbdb87a9 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/dict/impl/SysDictTypeServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/dict/impl/SysDictTypeServiceImpl.java @@ -10,6 +10,7 @@ import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dict.SysDictTy import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.dict.SysDictTypeMapper; import cn.iocoder.yudao.adminserver.modules.system.service.dict.SysDictDataService; import cn.iocoder.yudao.adminserver.modules.system.service.dict.SysDictTypeService; +import cn.iocoder.yudao.framework.dict.core.util.DictFrameworkUtils; import com.google.common.annotations.VisibleForTesting; import org.springframework.stereotype.Service; @@ -66,10 +67,13 @@ public class SysDictTypeServiceImpl implements SysDictTypeService { @Override public void updateDictType(SysDictTypeUpdateReqVO reqVO) { // 校验正确性 - this.checkCreateOrUpdate(reqVO.getId(), reqVO.getName(), null); + SysDictTypeDO sysDictTypeDO = this.checkCreateOrUpdate(reqVO.getId(), reqVO.getName(), null); // 更新字典类型 SysDictTypeDO updateObj = SysDictTypeConvert.INSTANCE.convert(reqVO); dictTypeMapper.updateById(updateObj); + // 更新字典数据,并更新缓存中的字典值 + dictDataService.updateDictDataType(sysDictTypeDO.getType(), reqVO.getType()); + dictDataService.refreshDictData(); } @Override @@ -89,13 +93,14 @@ public class SysDictTypeServiceImpl implements SysDictTypeService { return dictTypeMapper.selectList(); } - private void checkCreateOrUpdate(Long id, String name, String type) { + private SysDictTypeDO checkCreateOrUpdate(Long id, String name, String type) { // 校验自己存在 - checkDictTypeExists(id); + SysDictTypeDO sysDictTypeDO = checkDictTypeExists(id); // 校验字典类型的名字的唯一性 checkDictTypeNameUnique(id, name); // 校验字典类型的类型的唯一性 checkDictTypeUnique(id, type); + return sysDictTypeDO; } @VisibleForTesting