From 0e152e2ac7595aad81e657160d88f1f422a7d43e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E6=B2=90?= Date: Sat, 10 Dec 2022 14:45:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/maku/system/entity/SysDictDataEntity.java | 48 +++--- .../service/impl/SysDictTypeServiceImpl.java | 186 ++++++++++----------- .../java/net/maku/system/vo/SysDictDataVO.java | 48 +++--- .../main/java/net/maku/system/vo/SysDictVO.java | 4 +- 4 files changed, 143 insertions(+), 143 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 a89fba7..a605e09 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 @@ -14,28 +14,28 @@ import net.maku.framework.common.entity.BaseEntity; @EqualsAndHashCode(callSuper = false) @TableName("sys_dict_data") public class SysDictDataEntity extends BaseEntity { - /** - * 字典类型ID - */ - private Long dictTypeId; - /** - * 字典标签 - */ - private String dictLabel; - /** - * 字典值 - */ - private String dictValue; - /** - * 字典tag类型 - */ - private String tagType; - /** - * 备注 - */ - private String remark; - /** - * 排序 - */ - private Integer sort; + /** + * 字典类型ID + */ + private Long dictTypeId; + /** + * 字典标签 + */ + private String dictLabel; + /** + * 字典值 + */ + private String dictValue; + /** + * 标签样式 + */ + private String labelClass; + /** + * 备注 + */ + private String remark; + /** + * 排序 + */ + private Integer sort; } 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 c41a03b..70ffcc3 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(), data.getTagType())); - } - } + for (SysDictDataEntity data : dataList) { + if (type.getId().equals(data.getDictTypeId())) { + dict.getDataList().add(new SysDictVO.DictData(data.getDictLabel(), data.getDictValue(), data.getLabelClass())); + } + } - // 数据来源动态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; - }); - } + 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 aa0f6e4..05161de 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 @@ -19,37 +19,37 @@ import java.util.Date; @Data @Schema(description = "字典数据") public class SysDictDataVO implements Serializable { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - @Schema(description = "id") - private Long id; + @Schema(description = "id") + private Long id; - @Schema(description = "字典类型ID", required = true) - @NotNull(message = "字典类型ID不能为空") - private Long dictTypeId; + @Schema(description = "字典类型ID", required = true) + @NotNull(message = "字典类型ID不能为空") + private Long dictTypeId; - @Schema(description = "字典标签", required = true) - @NotBlank(message = "字典标签不能为空") - private String dictLabel; + @Schema(description = "字典标签", required = true) + @NotBlank(message = "字典标签不能为空") + private String dictLabel; - @Schema(description = "字典tag类型") - private String tagType; + @Schema(description = "标签样式") + private String labelClass; - @Schema(description = "字典值") - private String dictValue; + @Schema(description = "字典值") + private String dictValue; - @Schema(description = "备注") - private String remark; + @Schema(description = "备注") + private String remark; - @Schema(description = "排序", required = true) - @Min(value = 0, message = "排序值不能小于0") - private Integer sort; + @Schema(description = "排序", required = true) + @Min(value = 0, message = "排序值不能小于0") + private Integer sort; - @Schema(description = "创建时间") - @JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN) - private Date createTime; + @Schema(description = "创建时间") + @JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN) + private Date createTime; - @Schema(description = "更新时间") - @JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN) - private Date updateTime; + @Schema(description = "更新时间") + @JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN) + private Date updateTime; } 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 f05f3d3..7ba88c7 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 @@ -31,7 +31,7 @@ public class SysDictVO { @Schema(description = "字典值") private String dictValue; - @Schema(description = "字典tag类型") - private String tagType; + @Schema(description = "标签样式") + private String labelClass; } }