From 3ed1f2cc27045591b3a54186b5fa5ff53d459ddc Mon Sep 17 00:00:00 2001 From: fengshuonan Date: Tue, 27 Jun 2023 17:27:23 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=907.6.0=E3=80=91=E3=80=90dict=E3=80=91?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=96=B0=E5=A2=9E=E5=AD=97=E5=85=B8=E7=9A=84?= =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modular/pojo/request/DictRequest.java | 3 +- .../modular/service/impl/DictServiceImpl.java | 74 ++++++++++-------- .../dict/modular/sqladapter/DictSql.java | 77 ------------------- .../dict/modular/sqladapter/DictTypeSql.java | 74 ------------------ 4 files changed, 42 insertions(+), 186 deletions(-) delete mode 100644 kernel-s-dict/dict-business/src/main/java/cn/stylefeng/roses/kernel/dict/modular/sqladapter/DictSql.java delete mode 100644 kernel-s-dict/dict-business/src/main/java/cn/stylefeng/roses/kernel/dict/modular/sqladapter/DictTypeSql.java diff --git a/kernel-s-dict/dict-business/src/main/java/cn/stylefeng/roses/kernel/dict/modular/pojo/request/DictRequest.java b/kernel-s-dict/dict-business/src/main/java/cn/stylefeng/roses/kernel/dict/modular/pojo/request/DictRequest.java index c2f0deae9..d85dbc316 100644 --- a/kernel-s-dict/dict-business/src/main/java/cn/stylefeng/roses/kernel/dict/modular/pojo/request/DictRequest.java +++ b/kernel-s-dict/dict-business/src/main/java/cn/stylefeng/roses/kernel/dict/modular/pojo/request/DictRequest.java @@ -104,6 +104,7 @@ public class DictRequest extends BaseRequest { * 如果没有上级字典id,则为-1 */ @ChineseDescription("上级字典的id") + @NotNull(message = "上级字典的id不能为空", groups = {edit.class, add.class}) private Long dictParentId; /** @@ -117,8 +118,8 @@ public class DictRequest extends BaseRequest { /** * 排序,带小数点 */ - @ChineseDescription("排序") @NotNull(message = "排序不能为空", groups = {add.class, edit.class}) + @ChineseDescription("排序") private BigDecimal dictSort; /** 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 9e9999e0f..f279f0a3e 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 @@ -27,11 +27,9 @@ package cn.stylefeng.roses.kernel.dict.modular.service.impl; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; -import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi; import cn.stylefeng.roses.kernel.db.api.factory.PageFactory; import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory; import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult; -import cn.stylefeng.roses.kernel.dict.api.constants.DictConstants; import cn.stylefeng.roses.kernel.dict.api.exception.DictException; import cn.stylefeng.roses.kernel.dict.api.exception.enums.DictExceptionEnum; import cn.stylefeng.roses.kernel.dict.modular.entity.SysDict; @@ -41,7 +39,8 @@ import cn.stylefeng.roses.kernel.dict.modular.pojo.request.DictRequest; import cn.stylefeng.roses.kernel.dict.modular.service.DictService; import cn.stylefeng.roses.kernel.dict.modular.service.DictTypeService; import cn.stylefeng.roses.kernel.pinyin.api.PinYinApi; -import cn.stylefeng.roses.kernel.rule.enums.StatusEnum; +import cn.stylefeng.roses.kernel.rule.constants.SymbolConstant; +import cn.stylefeng.roses.kernel.rule.constants.TreeConstants; import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum; import cn.stylefeng.roses.kernel.rule.pojo.dict.SimpleDict; import cn.stylefeng.roses.kernel.rule.tree.factory.DefaultTreeBuildFactory; @@ -73,11 +72,6 @@ public class DictServiceImpl extends ServiceImpl implements @Resource private DictTypeService dictTypeService; - @Resource(name = "defaultStringCacheOperator") - private CacheOperatorApi defaultStringCacheOperator; - - private static final String CACHE_PREFIX = "dict:"; - @Override public List getTreeDictList(DictRequest dictRequest) { @@ -107,26 +101,26 @@ public class DictServiceImpl extends ServiceImpl implements @Transactional(rollbackFor = Exception.class) public void add(DictRequest dictRequest) { - // 校验字典重复 + // 校验字典重复,同一个字典类型下不能有重复的字典编码或者字典名称 this.validateRepeat(dictRequest, false); SysDict sysDict = new SysDict(); BeanUtil.copyProperties(dictRequest, sysDict); - sysDict.setDictParentId(DictConstants.DEFAULT_DICT_PARENT_ID); - sysDict.setDictPids(StrUtil.BRACKET_START + DictConstants.DEFAULT_DICT_PARENT_ID + StrUtil.BRACKET_END + StrUtil.COMMA); - sysDict.setStatusFlag(StatusEnum.ENABLE.getCode()); + + // 填充字典的拼音 sysDict.setDictNamePinyin(pinYinApi.parseEveryPinyinFirstLetter(sysDict.getDictName())); + + // 填充字典的pids + String pids = this.createPids(sysDict.getDictParentId()); + sysDict.setDictPids(pids); + this.save(sysDict); } @Override public void del(DictRequest dictRequest) { - SysDict sysDict = this.querySysDict(dictRequest); - sysDict.setDelFlag(YesOrNotEnum.Y.getCode()); - this.updateById(sysDict); - - // 清除缓存中的字典值 - defaultStringCacheOperator.remove(CACHE_PREFIX + sysDict.getDictTypeId() + "|" + sysDict.getDictCode()); + // 删除字典 + this.removeById(dictRequest.getDictId()); } @Override @@ -145,9 +139,6 @@ public class DictServiceImpl extends ServiceImpl implements sysDict.setDictNamePinyin(pinYinApi.parseEveryPinyinFirstLetter(sysDict.getDictName())); this.updateById(sysDict); - - // 清除缓存中的字典值 - defaultStringCacheOperator.remove(CACHE_PREFIX + sysDict.getDictTypeId() + "|" + sysDict.getDictCode()); } @Override @@ -181,10 +172,6 @@ public class DictServiceImpl extends ServiceImpl implements @Override public String getDictName(String dictTypeCode, String dictCode) { - String dictName = defaultStringCacheOperator.get(CACHE_PREFIX + dictTypeCode + "|" + dictCode); - if (StrUtil.isNotEmpty(dictName)) { - return dictName; - } LambdaQueryWrapper sysDictLambdaQueryWrapper = new LambdaQueryWrapper<>(); sysDictLambdaQueryWrapper.eq(SysDict::getDictTypeId, dictTypeCode); sysDictLambdaQueryWrapper.eq(SysDict::getDictCode, dictCode); @@ -203,13 +190,7 @@ public class DictServiceImpl extends ServiceImpl implements return StrUtil.EMPTY; } - dictName = list.get(0).getDictName(); - defaultStringCacheOperator.put(CACHE_PREFIX + dictTypeCode + "|" + dictCode, dictName); - if (dictName != null) { - return dictName; - } else { - return StrUtil.EMPTY; - } + return list.get(0).getDictName(); } @Override @@ -298,7 +279,6 @@ public class DictServiceImpl extends ServiceImpl implements if (editFlag) { sysDictLambdaQueryWrapper.ne(SysDict::getDictId, dictRequest.getDictId()); } - sysDictLambdaQueryWrapper.ne(SysDict::getDelFlag, YesOrNotEnum.Y.getCode()); long count = this.count(sysDictLambdaQueryWrapper); if (count > 0) { throw new DictException(DictExceptionEnum.DICT_CODE_REPEAT, dictRequest.getDictTypeId(), dictRequest.getDictCode()); @@ -311,12 +291,38 @@ public class DictServiceImpl extends ServiceImpl implements if (editFlag) { dictNameWrapper.ne(SysDict::getDictId, dictRequest.getDictId()); } - dictNameWrapper.ne(SysDict::getDelFlag, YesOrNotEnum.Y.getCode()); long dictNameCount = this.count(dictNameWrapper); if (dictNameCount > 0) { throw new DictException(DictExceptionEnum.DICT_NAME_REPEAT, dictRequest.getDictTypeId(), dictRequest.getDictCode()); } + } + /** + * 创建字典的pids的值 + *

+ * 如果pid是顶级节点,pids = 【[-1],】 + *

+ * 如果pid不是顶级节点,pids = 【父菜单的pids,[pid],】 + * + * @author fengshuonan + * @since 2023/6/27 17:24 + */ + private String createPids(Long dictParentId) { + if (dictParentId.equals(TreeConstants.DEFAULT_PARENT_ID)) { + return SymbolConstant.LEFT_SQUARE_BRACKETS + TreeConstants.DEFAULT_PARENT_ID + SymbolConstant.RIGHT_SQUARE_BRACKETS + SymbolConstant.COMMA; + } else { + //获取父字典 + LambdaQueryWrapper dictWrapper = new LambdaQueryWrapper<>(); + dictWrapper.eq(SysDict::getDictId, dictParentId); + dictWrapper.select(SysDict::getDictPids); + SysDict parentDictInfo = this.getOne(dictWrapper, false); + if (parentDictInfo == null) { + return SymbolConstant.LEFT_SQUARE_BRACKETS + TreeConstants.DEFAULT_PARENT_ID + SymbolConstant.RIGHT_SQUARE_BRACKETS + SymbolConstant.COMMA; + } else { + // 组装pids + return parentDictInfo.getDictPids() + SymbolConstant.LEFT_SQUARE_BRACKETS + dictParentId + SymbolConstant.RIGHT_SQUARE_BRACKETS + SymbolConstant.COMMA; + } + } } } diff --git a/kernel-s-dict/dict-business/src/main/java/cn/stylefeng/roses/kernel/dict/modular/sqladapter/DictSql.java b/kernel-s-dict/dict-business/src/main/java/cn/stylefeng/roses/kernel/dict/modular/sqladapter/DictSql.java deleted file mode 100644 index e5d4af21a..000000000 --- a/kernel-s-dict/dict-business/src/main/java/cn/stylefeng/roses/kernel/dict/modular/sqladapter/DictSql.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright [2020-2030] [https://www.stylefeng.cn] - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: - * - * 1.请不要删除和修改根目录下的LICENSE文件。 - * 2.请不要删除和修改Guns源码头部的版权声明。 - * 3.请保留源码和相关描述文件的项目出处,作者声明等。 - * 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns - * 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns - * 6.若您的项目无法满足以上几点,可申请商业授权 - */ -package cn.stylefeng.roses.kernel.dict.modular.sqladapter; - -import cn.stylefeng.roses.kernel.db.api.sqladapter.AbstractSql; -import lombok.Getter; - -/** - * 创建数据库的sql,可用在租户的创建 - * - * @author fengshuonan - * @since 2019-07-16-13:06 - */ -@Getter -public class DictSql extends AbstractSql { - - @Override - protected String mysql() { - return "CREATE TABLE `sys_dict` (\n" + - " `dict_id` bigint(20) NOT NULL COMMENT '字典id',\n" + - " `dict_code` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '字典编码',\n" + - " `dict_name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '字典名称',\n" + - " `dict_name_pinyin` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '字典名称首字母',\n" + - " `dict_encode` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '字典编码',\n" + - " `dict_type_code` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '字典类型的编码',\n" + - " `dict_short_name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '字典简称',\n" + - " `dict_short_code` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '字典简称的编码',\n" + - " `dict_parent_id` bigint(20) NOT NULL COMMENT '上级字典的id(如果没有上级字典id,则为-1)',\n" + - " `status_flag` tinyint(4) NOT NULL COMMENT '状态:(1-启用,2-禁用),参考 StatusEnum',\n" + - " `dict_sort` decimal(10,2) DEFAULT NULL COMMENT '排序,带小数点',\n" + - " `dict_pids` varchar(1000) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '父id集合',\n" + - " `del_flag` char(1) CHARACTER SET utf8 NOT NULL DEFAULT 'N' COMMENT '是否删除,Y-被删除,N-未删除',\n" + - " `create_time` datetime DEFAULT NULL COMMENT '创建时间',\n" + - " `create_user` bigint(20) DEFAULT NULL COMMENT '创建用户id',\n" + - " `update_time` datetime DEFAULT NULL COMMENT '修改时间',\n" + - " `update_user` bigint(20) DEFAULT NULL COMMENT '修改用户id',\n" + - " PRIMARY KEY (`dict_id`) USING BTREE\n" + - ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='字典';"; - } - - @Override - protected String sqlServer() { - return ""; - } - - @Override - protected String pgSql() { - return ""; - } - - @Override - protected String oracle() { - return ""; - } -} diff --git a/kernel-s-dict/dict-business/src/main/java/cn/stylefeng/roses/kernel/dict/modular/sqladapter/DictTypeSql.java b/kernel-s-dict/dict-business/src/main/java/cn/stylefeng/roses/kernel/dict/modular/sqladapter/DictTypeSql.java deleted file mode 100644 index 8ae205dff..000000000 --- a/kernel-s-dict/dict-business/src/main/java/cn/stylefeng/roses/kernel/dict/modular/sqladapter/DictTypeSql.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright [2020-2030] [https://www.stylefeng.cn] - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: - * - * 1.请不要删除和修改根目录下的LICENSE文件。 - * 2.请不要删除和修改Guns源码头部的版权声明。 - * 3.请保留源码和相关描述文件的项目出处,作者声明等。 - * 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns - * 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns - * 6.若您的项目无法满足以上几点,可申请商业授权 - */ -package cn.stylefeng.roses.kernel.dict.modular.sqladapter; - -import cn.stylefeng.roses.kernel.db.api.sqladapter.AbstractSql; -import lombok.Getter; - -/** - * 创建数据库的sql,可用在租户的创建 - * - * @author fengshuonan - * @since 2019-07-16-13:06 - */ -@Getter -public class DictTypeSql extends AbstractSql { - - @Override - protected String mysql() { - return "CREATE TABLE `sys_dict_type` (\n" + - " `dict_type_id` bigint(20) NOT NULL COMMENT '字典类型id',\n" + - " `dict_type_class` int(11) DEFAULT NULL COMMENT '字典类型: 1-业务类型,2-系统类型,参考 DictTypeClassEnum',\n" + - " `dict_type_bus_code` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '字典类型业务编码',\n" + - " `dict_type_code` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '字典类型编码',\n" + - " `dict_type_name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '字典类型名称',\n" + - " `dict_type_name_pinyin` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '字典类型名称首字母拼音',\n" + - " `dict_type_desc` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '字典类型描述',\n" + - " `status_flag` tinyint(4) DEFAULT NULL COMMENT '字典类型的状态:1-启用,2-禁用,参考 StatusEnum',\n" + - " `dict_type_sort` decimal(10,2) DEFAULT NULL COMMENT '排序,带小数点',\n" + - " `del_flag` char(1) CHARACTER SET utf8 NOT NULL DEFAULT 'N' COMMENT '是否删除:Y-被删除,N-未删除',\n" + - " `create_time` datetime DEFAULT NULL COMMENT '创建时间',\n" + - " `create_user` bigint(20) DEFAULT NULL COMMENT '创建用户id',\n" + - " `update_time` datetime DEFAULT NULL COMMENT '修改时间',\n" + - " `update_user` bigint(20) DEFAULT NULL COMMENT '修改用户id',\n" + - " PRIMARY KEY (`dict_type_id`) USING BTREE\n" + - ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='字典类型';"; - } - - @Override - protected String sqlServer() { - return ""; - } - - @Override - protected String pgSql() { - return ""; - } - - @Override - protected String oracle() { - return ""; - } -}