增加字典tag类型
This commit is contained in:
parent
7eb5d18d87
commit
51bd733444
|
@ -27,6 +27,10 @@ public class SysDictDataEntity extends BaseEntity {
|
||||||
*/
|
*/
|
||||||
private String dictValue;
|
private String dictValue;
|
||||||
/**
|
/**
|
||||||
|
* 字典tag类型
|
||||||
|
*/
|
||||||
|
private String tagType;
|
||||||
|
/**
|
||||||
* 备注
|
* 备注
|
||||||
*/
|
*/
|
||||||
private String remark;
|
private String remark;
|
||||||
|
|
|
@ -39,115 +39,115 @@ import java.util.stream.Collectors;
|
||||||
@Service
|
@Service
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class SysDictTypeServiceImpl extends BaseServiceImpl<SysDictTypeDao, SysDictTypeEntity> implements SysDictTypeService, InitializingBean {
|
public class SysDictTypeServiceImpl extends BaseServiceImpl<SysDictTypeDao, SysDictTypeEntity> implements SysDictTypeService, InitializingBean {
|
||||||
private final SysDictDataDao sysDictDataDao;
|
private final SysDictDataDao sysDictDataDao;
|
||||||
private final DictionaryTransService dictionaryTransService;
|
private final DictionaryTransService dictionaryTransService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<SysDictTypeVO> page(SysDictTypeQuery query) {
|
public PageResult<SysDictTypeVO> page (SysDictTypeQuery query) {
|
||||||
IPage<SysDictTypeEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));
|
IPage<SysDictTypeEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));
|
||||||
return new PageResult<>(SysDictTypeConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
|
return new PageResult<>(SysDictTypeConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Wrapper<SysDictTypeEntity> getWrapper(SysDictTypeQuery query) {
|
private Wrapper<SysDictTypeEntity> getWrapper (SysDictTypeQuery query) {
|
||||||
LambdaQueryWrapper<SysDictTypeEntity> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<SysDictTypeEntity> wrapper = new LambdaQueryWrapper<>();
|
||||||
wrapper.like(StrUtil.isNotBlank(query.getDictType()), SysDictTypeEntity::getDictType, query.getDictType());
|
wrapper.like(StrUtil.isNotBlank(query.getDictType()), SysDictTypeEntity::getDictType, query.getDictType());
|
||||||
wrapper.like(StrUtil.isNotBlank(query.getDictName()), SysDictTypeEntity::getDictName, query.getDictName());
|
wrapper.like(StrUtil.isNotBlank(query.getDictName()), SysDictTypeEntity::getDictName, query.getDictName());
|
||||||
wrapper.orderByAsc(SysDictTypeEntity::getSort);
|
wrapper.orderByAsc(SysDictTypeEntity::getSort);
|
||||||
|
|
||||||
return wrapper;
|
return wrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void save(SysDictTypeVO vo) {
|
public void save (SysDictTypeVO vo) {
|
||||||
SysDictTypeEntity entity = SysDictTypeConvert.INSTANCE.convert(vo);
|
SysDictTypeEntity entity = SysDictTypeConvert.INSTANCE.convert(vo);
|
||||||
|
|
||||||
baseMapper.insert(entity);
|
baseMapper.insert(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void update(SysDictTypeVO vo) {
|
public void update (SysDictTypeVO vo) {
|
||||||
SysDictTypeEntity entity = SysDictTypeConvert.INSTANCE.convert(vo);
|
SysDictTypeEntity entity = SysDictTypeConvert.INSTANCE.convert(vo);
|
||||||
|
|
||||||
updateById(entity);
|
updateById(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void delete(List<Long> idList) {
|
public void delete (List<Long> idList) {
|
||||||
removeByIds(idList);
|
removeByIds(idList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SysDictVO.DictData> getDictSql(Long id) {
|
public List<SysDictVO.DictData> getDictSql (Long id) {
|
||||||
SysDictTypeEntity entity = this.getById(id);
|
SysDictTypeEntity entity = this.getById(id);
|
||||||
try {
|
try {
|
||||||
return sysDictDataDao.getListForSql(entity.getDictSql());
|
return sysDictDataDao.getListForSql(entity.getDictSql());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ServerException("动态SQL执行失败,请检查SQL是否正确!");
|
throw new ServerException("动态SQL执行失败,请检查SQL是否正确!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SysDictVO> getDictList() {
|
public List<SysDictVO> getDictList () {
|
||||||
// 全部字典类型列表
|
// 全部字典类型列表
|
||||||
List<SysDictTypeEntity> typeList = this.list(Wrappers.emptyWrapper());
|
List<SysDictTypeEntity> typeList = this.list(Wrappers.emptyWrapper());
|
||||||
|
|
||||||
// 全部字典数据列表
|
// 全部字典数据列表
|
||||||
QueryWrapper<SysDictDataEntity> query = new QueryWrapper<SysDictDataEntity>().orderByAsc("sort");
|
QueryWrapper<SysDictDataEntity> query = new QueryWrapper<SysDictDataEntity>().orderByAsc("sort");
|
||||||
List<SysDictDataEntity> dataList = sysDictDataDao.selectList(query);
|
List<SysDictDataEntity> dataList = sysDictDataDao.selectList(query);
|
||||||
|
|
||||||
// 全部字典列表
|
// 全部字典列表
|
||||||
List<SysDictVO> dictList = new ArrayList<>(typeList.size());
|
List<SysDictVO> dictList = new ArrayList<>(typeList.size());
|
||||||
for (SysDictTypeEntity type : typeList) {
|
for (SysDictTypeEntity type : typeList) {
|
||||||
SysDictVO dict = new SysDictVO();
|
SysDictVO dict = new SysDictVO();
|
||||||
dict.setDictType(type.getDictType());
|
dict.setDictType(type.getDictType());
|
||||||
|
|
||||||
for (SysDictDataEntity data : dataList) {
|
for (SysDictDataEntity data : dataList) {
|
||||||
if (type.getId().equals(data.getDictTypeId())) {
|
if (type.getId().equals(data.getDictTypeId())) {
|
||||||
dict.getDataList().add(new SysDictVO.DictData(data.getDictLabel(), data.getDictValue()));
|
dict.getDataList().add(new SysDictVO.DictData(data.getDictLabel(), data.getDictValue(), data.getTagType()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 数据来源动态SQL
|
// 数据来源动态SQL
|
||||||
if (type.getDictSource() == DictSourceEnum.SQL.getValue()) {
|
if (type.getDictSource() == DictSourceEnum.SQL.getValue()) {
|
||||||
// 增加动态列表
|
// 增加动态列表
|
||||||
String sql = type.getDictSql();
|
String sql = type.getDictSql();
|
||||||
try {
|
try {
|
||||||
dict.setDataList(sysDictDataDao.getListForSql(sql));
|
dict.setDataList(sysDictDataDao.getListForSql(sql));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("增加动态字典异常: type=" + type, e);
|
log.error("增加动态字典异常: type=" + type, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dictList.add(dict);
|
dictList.add(dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
return dictList;
|
return dictList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterPropertiesSet() {
|
public void afterPropertiesSet () {
|
||||||
refreshTransCache();
|
refreshTransCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refreshTransCache() {
|
public void refreshTransCache () {
|
||||||
// 异步不阻塞主线程,不会 增加启动用时
|
// 异步不阻塞主线程,不会 增加启动用时
|
||||||
CompletableFuture.supplyAsync(() -> {
|
CompletableFuture.supplyAsync(() -> {
|
||||||
// 获取所有的字典项数据
|
// 获取所有的字典项数据
|
||||||
List<SysDictDataEntity> dataList = sysDictDataDao.selectList(new LambdaQueryWrapper<>());
|
List<SysDictDataEntity> dataList = sysDictDataDao.selectList(new LambdaQueryWrapper<>());
|
||||||
// 根据类型分组
|
// 根据类型分组
|
||||||
Map<Long, List<SysDictDataEntity>> dictTypeDataMap = dataList.stream().collect(Collectors
|
Map<Long, List<SysDictDataEntity>> dictTypeDataMap = dataList.stream().collect(Collectors
|
||||||
.groupingBy(SysDictDataEntity::getDictTypeId));
|
.groupingBy(SysDictDataEntity::getDictTypeId));
|
||||||
List<SysDictTypeEntity> dictTypeEntities = super.list();
|
List<SysDictTypeEntity> dictTypeEntities = super.list();
|
||||||
for (SysDictTypeEntity dictTypeEntity : dictTypeEntities) {
|
for (SysDictTypeEntity dictTypeEntity : dictTypeEntities) {
|
||||||
if (dictTypeDataMap.containsKey(dictTypeEntity.getId())) {
|
if (dictTypeDataMap.containsKey(dictTypeEntity.getId())) {
|
||||||
dictionaryTransService.refreshCache(dictTypeEntity.getDictType(), dictTypeDataMap.get(dictTypeEntity.getId())
|
dictionaryTransService.refreshCache(dictTypeEntity.getDictType(), dictTypeDataMap.get(dictTypeEntity.getId())
|
||||||
.stream().collect(Collectors.toMap(SysDictDataEntity::getDictValue, SysDictDataEntity::getDictLabel)));
|
.stream().collect(Collectors.toMap(SysDictDataEntity::getDictValue, SysDictDataEntity::getDictLabel)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -32,6 +32,9 @@ public class SysDictDataVO implements Serializable {
|
||||||
@NotBlank(message = "字典标签不能为空")
|
@NotBlank(message = "字典标签不能为空")
|
||||||
private String dictLabel;
|
private String dictLabel;
|
||||||
|
|
||||||
|
@Schema(description = "字典tag类型")
|
||||||
|
private String tagType;
|
||||||
|
|
||||||
@Schema(description = "字典值")
|
@Schema(description = "字典值")
|
||||||
private String dictValue;
|
private String dictValue;
|
||||||
|
|
||||||
|
|
|
@ -30,5 +30,8 @@ public class SysDictVO {
|
||||||
|
|
||||||
@Schema(description = "字典值")
|
@Schema(description = "字典值")
|
||||||
private String dictValue;
|
private String dictValue;
|
||||||
|
|
||||||
|
@Schema(description = "字典tag类型")
|
||||||
|
private String tagType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user