diff --git a/kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/pojo/dict/SimpleDict.java b/kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/pojo/dict/SimpleDict.java index b1e83f3ba..903d21841 100644 --- a/kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/pojo/dict/SimpleDict.java +++ b/kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/pojo/dict/SimpleDict.java @@ -60,4 +60,12 @@ public class SimpleDict { @ChineseDescription("编码") private String code; + public SimpleDict() { + } + + public SimpleDict(Long id, String name, String code) { + this.id = id; + this.name = name; + this.code = code; + } } diff --git a/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/service/SysConfigService.java b/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/service/SysConfigService.java index 50b0ae752..6317470ed 100644 --- a/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/service/SysConfigService.java +++ b/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/service/SysConfigService.java @@ -103,4 +103,14 @@ public interface SysConfigService extends IService, InitConfigApi { */ InitConfigResponse getInitConfigs(); + /** + * 更新所有config所属的字典类型编码 + * + * @param originTypeCode 原有的typeCode + * @param destTypeCode 更新后的typeCode + * @author fengshuonan + * @since 2023/6/28 18:02 + */ + void updateSysConfigTypeCode(String originTypeCode, String destTypeCode); + } diff --git a/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/service/SysConfigTypeService.java b/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/service/SysConfigTypeService.java index 531e010af..45cf70a7c 100644 --- a/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/service/SysConfigTypeService.java +++ b/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/service/SysConfigTypeService.java @@ -7,6 +7,7 @@ import cn.stylefeng.roses.kernel.dict.api.DictTypeApi; import cn.stylefeng.roses.kernel.dict.api.pojo.SimpleDictUpdateParam; import cn.stylefeng.roses.kernel.rule.pojo.dict.SimpleDict; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.List; @@ -49,6 +50,7 @@ public class SysConfigTypeService { * @author fengshuonan * @since 2023/6/28 17:07 */ + @Transactional(rollbackFor = Exception.class) public void add(SysConfigTypeParam sysConfigTypeParam) { // 查询字典类型 @@ -66,13 +68,19 @@ public class SysConfigTypeService { } /** - * 更新字典类型 + * 新增系统配置类型 + *

+ * 针对字典类型编码为config_group的字典修改一个条目 * * @author fengshuonan * @since 2023/6/28 17:32 */ + @Transactional(rollbackFor = Exception.class) public void edit(SysConfigTypeParam sysConfigTypeParam) { + // 查询旧的字典编码 + SimpleDict originDictInfo = dictApi.getDictByDictId(sysConfigTypeParam.getConfigTypeId()); + // 查询字典类型 Long dictTypeId = dictTypeApi.getDictTypeIdByDictTypeCode(ConfigConstants.CONFIG_GROUP_DICT_TYPE_CODE); @@ -86,6 +94,12 @@ public class SysConfigTypeService { // 编辑字典 dictApi.simpleEditDict(simpleDictAddParam); + + // 如果更新了字典的编码,则属于该类型下的字典配置编码也都修改 + if (!originDictInfo.getCode().equals(sysConfigTypeParam.getConfigTypeCode())) { + sysConfigService.updateSysConfigTypeCode(originDictInfo.getCode(), sysConfigTypeParam.getConfigTypeCode()); + } + } } diff --git a/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/service/impl/SysConfigServiceImpl.java b/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/service/impl/SysConfigServiceImpl.java index bcb135db9..4084e6413 100644 --- a/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/service/impl/SysConfigServiceImpl.java +++ b/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/service/impl/SysConfigServiceImpl.java @@ -251,6 +251,14 @@ public class SysConfigServiceImpl extends ServiceImpl sysConfigLambdaUpdateWrapper = new LambdaUpdateWrapper<>(); + sysConfigLambdaUpdateWrapper.eq(SysConfig::getGroupCode, originTypeCode); + sysConfigLambdaUpdateWrapper.set(SysConfig::getGroupCode, destTypeCode); + this.update(sysConfigLambdaUpdateWrapper); + } + /** * 获取系统参数配置 * diff --git a/kernel-s-dict/dict-api/src/main/java/cn/stylefeng/roses/kernel/dict/api/DictApi.java b/kernel-s-dict/dict-api/src/main/java/cn/stylefeng/roses/kernel/dict/api/DictApi.java index eb47fc2d0..7b7d037b6 100644 --- a/kernel-s-dict/dict-api/src/main/java/cn/stylefeng/roses/kernel/dict/api/DictApi.java +++ b/kernel-s-dict/dict-api/src/main/java/cn/stylefeng/roses/kernel/dict/api/DictApi.java @@ -68,6 +68,14 @@ public interface DictApi { */ void deleteByDictId(Long dictId); + /** + * 通过字典id获取字典的名称和编码信息 + * + * @author fengshuonan + * @since 2023/5/4 21:25 + */ + SimpleDict getDictByDictId(Long dictId); + /** * 通过字典id获取字典的名称 * diff --git a/kernel-s-dict/dict-business/src/main/java/cn/stylefeng/roses/kernel/dict/modular/service/impl/DictServiceImpl.java b/kernel-s-dict/dict-business/src/main/java/cn/stylefeng/roses/kernel/dict/modular/service/impl/DictServiceImpl.java index c9c6ec808..8a6c24cd9 100644 --- a/kernel-s-dict/dict-business/src/main/java/cn/stylefeng/roses/kernel/dict/modular/service/impl/DictServiceImpl.java +++ b/kernel-s-dict/dict-business/src/main/java/cn/stylefeng/roses/kernel/dict/modular/service/impl/DictServiceImpl.java @@ -259,6 +259,24 @@ public class DictServiceImpl extends ServiceImpl implements this.removeById(dictId); } + @Override + public SimpleDict getDictByDictId(Long dictId) { + if (dictId == null) { + return new SimpleDict(); + } + + LambdaQueryWrapper sysDictLambdaQueryWrapper = new LambdaQueryWrapper<>(); + sysDictLambdaQueryWrapper.eq(SysDict::getDictId, dictId); + sysDictLambdaQueryWrapper.select(SysDict::getDictName, SysDict::getDictCode, SysDict::getDictId); + SysDict sysDict = this.getOne(sysDictLambdaQueryWrapper, false); + + if (sysDict == null) { + return new SimpleDict(); + } else { + return new SimpleDict(sysDict.getDictId(), sysDict.getDictName(), sysDict.getDictCode()); + } + } + @Override public String getDictNameByDictId(Long dictId) { if (dictId == null) {