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] =?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 --- .../net/maku/system/entity/SysDictDataEntity.java | 6 +- .../service/impl/SysDictTypeServiceImpl.java | 188 ++++++++++----------- .../java/net/maku/system/vo/SysDictDataVO.java | 5 +- .../main/java/net/maku/system/vo/SysDictVO.java | 3 + 4 files changed, 106 insertions(+), 96 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 @@ -27,6 +27,10 @@ public class SysDictDataEntity extends BaseEntity { */ private String dictValue; /** + * 字典tag类型 + */ + private String tagType; + /** * 备注 */ private String remark; @@ -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; + 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()); - } + @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); + 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; - } + return wrapper; + } - @Override - @Transactional(rollbackFor = Exception.class) - public void save(SysDictTypeVO vo) { - SysDictTypeEntity entity = SysDictTypeConvert.INSTANCE.convert(vo); + @Override + @Transactional(rollbackFor = Exception.class) + public void save (SysDictTypeVO vo) { + SysDictTypeEntity entity = SysDictTypeConvert.INSTANCE.convert(vo); - baseMapper.insert(entity); - } + baseMapper.insert(entity); + } - @Override - @Transactional(rollbackFor = Exception.class) - public void update(SysDictTypeVO vo) { - SysDictTypeEntity entity = SysDictTypeConvert.INSTANCE.convert(vo); + @Override + @Transactional(rollbackFor = Exception.class) + public void update (SysDictTypeVO vo) { + SysDictTypeEntity entity = SysDictTypeConvert.INSTANCE.convert(vo); - updateById(entity); - } + updateById(entity); + } - @Override - @Transactional(rollbackFor = Exception.class) - public void delete(List idList) { - removeByIds(idList); - } + @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 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()); + @Override + public List getDictList () { + // 全部字典类型列表 + List typeList = this.list(Wrappers.emptyWrapper()); - // 全部字典数据列表 - QueryWrapper query = new QueryWrapper().orderByAsc("sort"); - List dataList = sysDictDataDao.selectList(query); + // 全部字典数据列表 + 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()); + // 全部字典列表 + 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())); - } - } + 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); - } - } + // 数据来源动态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); - } + dictList.add(dict); + } - return dictList; - } + return dictList; + } - @Override - public void afterPropertiesSet() { - refreshTransCache(); - } + @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 + 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; } }