From 6beecb7c88e1d0ce8182bc5c833c5a5fa92e0e89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E6=B5=B7=E6=AF=93?= <378101239@qq.com> Date: Thu, 13 May 2021 17:25:40 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=201.=E5=AD=97=E5=85=B8=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E8=A3=85=E9=85=8D=E7=B1=BB=E9=94=99=E8=AF=AF=202.?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AD=97=E5=85=B8type=E6=97=A0=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/controller/dict/vo/type/SysDictTypeBaseVO.java | 5 +++++ .../system/service/dict/impl/SysDictTypeServiceImpl.java | 4 ++++ .../src/main/resources/META-INF/spring.factories | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/dict/vo/type/SysDictTypeBaseVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/dict/vo/type/SysDictTypeBaseVO.java index c4458cd26b..05d399e2f4 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/dict/vo/type/SysDictTypeBaseVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/dict/vo/type/SysDictTypeBaseVO.java @@ -23,6 +23,11 @@ public class SysDictTypeBaseVO { @NotNull(message = "状态不能为空") private Integer status; + @ApiModelProperty(value = "字典类型", required = true) + @NotNull(message = "字典类型不能为空") + @Size(max = 100, message = "字典类型长度不能超过100个字符") + private String type; + @ApiModelProperty(value = "备注", example = "快乐的备注") private String remark; 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 b054764532..36a14b4152 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 @@ -115,6 +115,10 @@ public class SysDictTypeServiceImpl implements SysDictTypeService { @VisibleForTesting public void checkDictTypeUnique(Long id, String type) { + // 判断type是否为空,减少一次查询数据库的操作 + if (type == null) { + return; + } SysDictTypeDO dictType = dictTypeMapper.selectByType(type); if (dictType == null) { return; diff --git a/yudao-framework/yudao-spring-boot-starter-biz-dict/src/main/resources/META-INF/spring.factories b/yudao-framework/yudao-spring-boot-starter-biz-dict/src/main/resources/META-INF/spring.factories index 529a476630..3986b1c2b2 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-dict/src/main/resources/META-INF/spring.factories +++ b/yudao-framework/yudao-spring-boot-starter-biz-dict/src/main/resources/META-INF/spring.factories @@ -1,2 +1,2 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ - cn.iocoder.yudao.framework.operatelog.config.YudaoOperateLogAutoConfiguration + cn.iocoder.yudao.framework.dict.config.YudaoDictAutoConfiguration From 3705f736bfa96c8e7077ddc4c83c6adba31c4e90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E6=B5=B7=E6=AF=93?= <378101239@qq.com> Date: Thu, 13 May 2021 17:56:59 +0800 Subject: [PATCH 2/3] =?UTF-8?q?optimize:=20=E4=BF=AE=E6=94=B9=E5=AD=97?= =?UTF-8?q?=E5=85=B8=E7=B1=BB=E5=9E=8B=E5=90=8C=E6=97=B6=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=AD=97=E5=85=B8=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/service/dict/SysDictDataService.java | 13 +++++++++++++ .../dict/impl/SysDictDataServiceImpl.java | 16 ++++++++++++++++ .../dict/impl/SysDictTypeServiceImpl.java | 11 ++++++++--- 3 files changed, 37 insertions(+), 3 deletions(-) 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 From 69e0b4f560536cce1647e483917ac22758cf4eea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E6=B5=B7=E6=AF=93?= <378101239@qq.com> Date: Thu, 13 May 2021 17:59:11 +0800 Subject: [PATCH 3/3] =?UTF-8?q?optimize:=20=E5=8E=BB=E6=8E=89=E6=97=A0?= =?UTF-8?q?=E7=94=A8=E5=BC=95=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/service/dict/impl/SysDictTypeServiceImpl.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 1acbdb87a9..ff648909f8 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 @@ -1,6 +1,5 @@ package cn.iocoder.yudao.adminserver.modules.system.service.dict.impl; -import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.type.SysDictTypeCreateReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.type.SysDictTypeExportReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.type.SysDictTypePageReqVO; @@ -10,15 +9,15 @@ 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 cn.iocoder.yudao.framework.common.pojo.PageResult; import com.google.common.annotations.VisibleForTesting; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.List; -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.*; +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; /** * 字典类型 Service 实现类