From 51bd73344408f457ce48226de03496af0e13f9ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E7=A5=81?= <593401899@qq.com> Date: Thu, 8 Dec 2022 22:22:49 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AD=97=E5=85=B8tag?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../maku/system/entity/SysDictDataEntity.java | 6 +- .../service/impl/SysDictTypeServiceImpl.java | 224 +++++++++--------- .../net/maku/system/vo/SysDictDataVO.java | 5 +- .../java/net/maku/system/vo/SysDictVO.java | 3 + 4 files changed, 124 insertions(+), 114 deletions(-) diff --git a/maku-boot-system/src/main/java/net/maku/system/entity/SysDictDataEntity.java b/maku-boot-system/src/main/java/net/maku/system/entity/SysDictDataEntity.java index 2c8017b..a89fba7 100644 --- a/maku-boot-system/src/main/java/net/maku/system/entity/SysDictDataEntity.java +++ b/maku-boot-system/src/main/java/net/maku/system/entity/SysDictDataEntity.java @@ -26,6 +26,10 @@ public class SysDictDataEntity extends BaseEntity { * 字典值 */ private String dictValue; + /** + * 字典tag类型 + */ + private String tagType; /** * 备注 */ @@ -34,4 +38,4 @@ public class SysDictDataEntity extends BaseEntity { * 排序 */ private Integer sort; -} \ No newline at end of file +} diff --git a/maku-boot-system/src/main/java/net/maku/system/service/impl/SysDictTypeServiceImpl.java b/maku-boot-system/src/main/java/net/maku/system/service/impl/SysDictTypeServiceImpl.java index 871f619..c41a03b 100644 --- a/maku-boot-system/src/main/java/net/maku/system/service/impl/SysDictTypeServiceImpl.java +++ b/maku-boot-system/src/main/java/net/maku/system/service/impl/SysDictTypeServiceImpl.java @@ -39,115 +39,115 @@ import java.util.stream.Collectors; @Service @AllArgsConstructor public class SysDictTypeServiceImpl extends BaseServiceImpl implements SysDictTypeService, InitializingBean { - private final SysDictDataDao sysDictDataDao; - private final DictionaryTransService dictionaryTransService; - - @Override - public PageResult page(SysDictTypeQuery query) { - IPage page = baseMapper.selectPage(getPage(query), getWrapper(query)); - return new PageResult<>(SysDictTypeConvert.INSTANCE.convertList(page.getRecords()), page.getTotal()); - } - - private Wrapper getWrapper(SysDictTypeQuery query) { - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.like(StrUtil.isNotBlank(query.getDictType()), SysDictTypeEntity::getDictType, query.getDictType()); - wrapper.like(StrUtil.isNotBlank(query.getDictName()), SysDictTypeEntity::getDictName, query.getDictName()); - wrapper.orderByAsc(SysDictTypeEntity::getSort); - - return wrapper; - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void save(SysDictTypeVO vo) { - SysDictTypeEntity entity = SysDictTypeConvert.INSTANCE.convert(vo); - - baseMapper.insert(entity); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void update(SysDictTypeVO vo) { - SysDictTypeEntity entity = SysDictTypeConvert.INSTANCE.convert(vo); - - updateById(entity); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void delete(List idList) { - removeByIds(idList); - } - - @Override - public List getDictSql(Long id) { - SysDictTypeEntity entity = this.getById(id); - try { - return sysDictDataDao.getListForSql(entity.getDictSql()); - } catch (Exception e) { - throw new ServerException("动态SQL执行失败,请检查SQL是否正确!"); - } - } - - @Override - public List getDictList() { - // 全部字典类型列表 - List typeList = this.list(Wrappers.emptyWrapper()); - - // 全部字典数据列表 - QueryWrapper query = new QueryWrapper().orderByAsc("sort"); - List dataList = sysDictDataDao.selectList(query); - - // 全部字典列表 - List dictList = new ArrayList<>(typeList.size()); - for (SysDictTypeEntity type : typeList) { - SysDictVO dict = new SysDictVO(); - dict.setDictType(type.getDictType()); - - for (SysDictDataEntity data : dataList) { - if (type.getId().equals(data.getDictTypeId())) { - dict.getDataList().add(new SysDictVO.DictData(data.getDictLabel(), data.getDictValue())); - } - } - - // 数据来源动态SQL - if (type.getDictSource() == DictSourceEnum.SQL.getValue()) { - // 增加动态列表 - String sql = type.getDictSql(); - try { - dict.setDataList(sysDictDataDao.getListForSql(sql)); - } catch (Exception e) { - log.error("增加动态字典异常: type=" + type, e); - } - } - - dictList.add(dict); - } - - return dictList; - } - - @Override - public void afterPropertiesSet() { - refreshTransCache(); - } - - public void refreshTransCache() { - // 异步不阻塞主线程,不会 增加启动用时 - CompletableFuture.supplyAsync(() -> { - // 获取所有的字典项数据 - List dataList = sysDictDataDao.selectList(new LambdaQueryWrapper<>()); - // 根据类型分组 - Map> dictTypeDataMap = dataList.stream().collect(Collectors - .groupingBy(SysDictDataEntity::getDictTypeId)); - List dictTypeEntities = super.list(); - for (SysDictTypeEntity dictTypeEntity : dictTypeEntities) { - if (dictTypeDataMap.containsKey(dictTypeEntity.getId())) { - dictionaryTransService.refreshCache(dictTypeEntity.getDictType(), dictTypeDataMap.get(dictTypeEntity.getId()) - .stream().collect(Collectors.toMap(SysDictDataEntity::getDictValue, SysDictDataEntity::getDictLabel))); - } - } - return null; - }); - } -} \ No newline at end of file + private final SysDictDataDao sysDictDataDao; + private final DictionaryTransService dictionaryTransService; + + @Override + public PageResult page (SysDictTypeQuery query) { + IPage page = baseMapper.selectPage(getPage(query), getWrapper(query)); + return new PageResult<>(SysDictTypeConvert.INSTANCE.convertList(page.getRecords()), page.getTotal()); + } + + private Wrapper getWrapper (SysDictTypeQuery query) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.like(StrUtil.isNotBlank(query.getDictType()), SysDictTypeEntity::getDictType, query.getDictType()); + wrapper.like(StrUtil.isNotBlank(query.getDictName()), SysDictTypeEntity::getDictName, query.getDictName()); + wrapper.orderByAsc(SysDictTypeEntity::getSort); + + return wrapper; + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void save (SysDictTypeVO vo) { + SysDictTypeEntity entity = SysDictTypeConvert.INSTANCE.convert(vo); + + baseMapper.insert(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update (SysDictTypeVO vo) { + SysDictTypeEntity entity = SysDictTypeConvert.INSTANCE.convert(vo); + + updateById(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void delete (List idList) { + removeByIds(idList); + } + + @Override + public List getDictSql (Long id) { + SysDictTypeEntity entity = this.getById(id); + try { + return sysDictDataDao.getListForSql(entity.getDictSql()); + } catch (Exception e) { + throw new ServerException("动态SQL执行失败,请检查SQL是否正确!"); + } + } + + @Override + public List getDictList () { + // 全部字典类型列表 + List typeList = this.list(Wrappers.emptyWrapper()); + + // 全部字典数据列表 + QueryWrapper query = new QueryWrapper().orderByAsc("sort"); + List dataList = sysDictDataDao.selectList(query); + + // 全部字典列表 + List dictList = new ArrayList<>(typeList.size()); + for (SysDictTypeEntity type : typeList) { + SysDictVO dict = new SysDictVO(); + dict.setDictType(type.getDictType()); + + for (SysDictDataEntity data : dataList) { + if (type.getId().equals(data.getDictTypeId())) { + dict.getDataList().add(new SysDictVO.DictData(data.getDictLabel(), data.getDictValue(), data.getTagType())); + } + } + + // 数据来源动态SQL + if (type.getDictSource() == DictSourceEnum.SQL.getValue()) { + // 增加动态列表 + String sql = type.getDictSql(); + try { + dict.setDataList(sysDictDataDao.getListForSql(sql)); + } catch (Exception e) { + log.error("增加动态字典异常: type=" + type, e); + } + } + + dictList.add(dict); + } + + return dictList; + } + + @Override + public void afterPropertiesSet () { + refreshTransCache(); + } + + public void refreshTransCache () { + // 异步不阻塞主线程,不会 增加启动用时 + CompletableFuture.supplyAsync(() -> { + // 获取所有的字典项数据 + List dataList = sysDictDataDao.selectList(new LambdaQueryWrapper<>()); + // 根据类型分组 + Map> dictTypeDataMap = dataList.stream().collect(Collectors + .groupingBy(SysDictDataEntity::getDictTypeId)); + List dictTypeEntities = super.list(); + for (SysDictTypeEntity dictTypeEntity : dictTypeEntities) { + if (dictTypeDataMap.containsKey(dictTypeEntity.getId())) { + dictionaryTransService.refreshCache(dictTypeEntity.getDictType(), dictTypeDataMap.get(dictTypeEntity.getId()) + .stream().collect(Collectors.toMap(SysDictDataEntity::getDictValue, SysDictDataEntity::getDictLabel))); + } + } + return null; + }); + } +} diff --git a/maku-boot-system/src/main/java/net/maku/system/vo/SysDictDataVO.java b/maku-boot-system/src/main/java/net/maku/system/vo/SysDictDataVO.java index 7735789..aa0f6e4 100644 --- a/maku-boot-system/src/main/java/net/maku/system/vo/SysDictDataVO.java +++ b/maku-boot-system/src/main/java/net/maku/system/vo/SysDictDataVO.java @@ -32,6 +32,9 @@ public class SysDictDataVO implements Serializable { @NotBlank(message = "字典标签不能为空") private String dictLabel; + @Schema(description = "字典tag类型") + private String tagType; + @Schema(description = "字典值") private String dictValue; @@ -49,4 +52,4 @@ public class SysDictDataVO implements Serializable { @Schema(description = "更新时间") @JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN) private Date updateTime; -} \ No newline at end of file +} diff --git a/maku-boot-system/src/main/java/net/maku/system/vo/SysDictVO.java b/maku-boot-system/src/main/java/net/maku/system/vo/SysDictVO.java index 2615d96..f05f3d3 100644 --- a/maku-boot-system/src/main/java/net/maku/system/vo/SysDictVO.java +++ b/maku-boot-system/src/main/java/net/maku/system/vo/SysDictVO.java @@ -30,5 +30,8 @@ public class SysDictVO { @Schema(description = "字典值") private String dictValue; + + @Schema(description = "字典tag类型") + private String tagType; } } -- Gitee From 5b7dd840915a4b4307b54eeb8de647be9351072f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E7=A5=81?= <593401899@qq.com> Date: Thu, 8 Dec 2022 22:23:27 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9B=B4=E6=96=B0sql?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/mysql/maku.sql | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/db/mysql/maku.sql b/db/mysql/maku.sql index ffa7b55..226abad 100644 --- a/db/mysql/maku.sql +++ b/db/mysql/maku.sql @@ -291,6 +291,7 @@ INSERT INTO sys_dict_type (id, dict_type, dict_name, remark, sort, version, dele INSERT INTO sys_dict_type (id, dict_type, dict_name, remark, sort, version, deleted, creator, create_time, updater, update_time) VALUES (7, 'login_operation', '操作信息', '登录管理', 0, 0, 0, 10000, now(), 10000, now()); INSERT INTO sys_dict_type (id, dict_type, dict_name, remark, sort, version, deleted, creator, create_time, updater, update_time) VALUES (8, 'params_type', '系统参数', '参数管理', 0, 0, 0, 10000, now(), 10000, now()); INSERT INTO sys_dict_type (id, dict_type, dict_name, remark, sort, version, deleted, creator, create_time, updater, update_time) VALUES (9, 'user_super_admin', '用户是否是超管','用户是否是超管', 0, 0, 0, 10000, now(), 10000, now()); +INSERT INTO sys_dict_type (id, dict_type, dict_name, dict_source, dict_sql, remark, sort, version, deleted, creator, create_time, updater, update_time) VALUES (10, 'dict_tag', '字典类型', 0, '', '字典tag类型', 0, 0, 0, 10000, now(), 10000, now()); INSERT INTO sys_dict_data (id, dict_type_id, dict_label, dict_value, remark, sort, version, deleted, creator, create_time, updater, update_time) VALUES (1, 1, '停用', '0', '', 1, 0, 0, 10000, now(), 10000, now()); @@ -317,6 +318,11 @@ INSERT INTO sys_dict_data (id, dict_type_id, dict_label, dict_value, remark, sor INSERT INTO sys_dict_data (id, dict_type_id, dict_label, dict_value, remark, sort, version, deleted, creator, create_time, updater, update_time) VALUES (22, 8, '是', '1', '', 0, 0, 0, 10000, now(), 10000, now()); INSERT INTO sys_dict_data (id, dict_type_id, dict_label, dict_value, remark, sort, version, deleted, creator, create_time, updater, update_time) VALUES (23, 9, '是', '1', '', 1, 0, 0, 10000, now(), 10000, now()); INSERT INTO sys_dict_data (id, dict_type_id, dict_label, dict_value, remark, sort, version, deleted, creator, create_time, updater, update_time) VALUES (24, 9, '否', '0', '', 0, 0, 0, 10000, now(), 10000, now()); +INSERT INTO sys_dict_data (id, dict_type_id, dict_label, dict_value, tag_type, remark, sort, version, deleted, creator, create_time, updater, update_time) VALUES (25, 10, '成功', 'success', 'success', '', 0, 0, 0, 10000, now(), 10000, now()); +INSERT INTO sys_dict_data (id, dict_type_id, dict_label, dict_value, tag_type, remark, sort, version, deleted, creator, create_time, updater, update_time) VALUES (26, 10, '默认', '', '', '', 0, 0, 0, 10000, now(), 10000, now()); +INSERT INTO sys_dict_data (id, dict_type_id, dict_label, dict_value, tag_type, remark, sort, version, deleted, creator, create_time, updater, update_time) VALUES (27, 10, '提示', 'info', 'info', '', 0, 0, 0, 10000, now(), 10000, now()); +INSERT INTO sys_dict_data (id, dict_type_id, dict_label, dict_value, tag_type, remark, sort, version, deleted, creator, create_time, updater, update_time) VALUES (28, 10, '警告', 'warning', 'warning', '', 0, 0, 0, 10000, now(), 10000, now()); +INSERT INTO sys_dict_data (id, dict_type_id, dict_label, dict_value, tag_type, remark, sort, version, deleted, creator, create_time, updater, update_time) VALUES (29, 10, '错误', 'danger', 'danger', '', 0, 0, 0, 10000, now(), 10000, now()); INSERT INTO sys_params (param_name, param_type, param_key, param_value, remark, version, deleted, creator, create_time, updater, update_time) VALUES ('用户登录-验证码开关', 1, 'LOGIN_CAPTCHA', 'false', '是否开启验证码(true:开启,false:关闭)', 0, 0, 10000, now(), 10000, now()); -- Gitee