|
@@ -53,79 +53,89 @@ import static org.springblade.core.cache.constant.CacheConstant.DICT_CACHE;
|
|
@Service
|
|
@Service
|
|
public class DictServiceImpl extends ServiceImpl<DictMapper, Dict> implements IDictService {
|
|
public class DictServiceImpl extends ServiceImpl<DictMapper, Dict> implements IDictService {
|
|
|
|
|
|
- @Override
|
|
|
|
- public IPage<DictVO> selectDictPage(IPage<DictVO> page, DictVO dict) {
|
|
|
|
- return page.setRecords(baseMapper.selectDictPage(page, dict));
|
|
|
|
- }
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public IPage<DictVO> selectDictPage(IPage<DictVO> page, DictVO dict) {
|
|
|
|
+ return page.setRecords(baseMapper.selectDictPage(page, dict));
|
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
|
- public List<DictVO> tree() {
|
|
|
|
- return ForestNodeMerger.merge(baseMapper.tree());
|
|
|
|
- }
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public List<DictVO> tree() {
|
|
|
|
+ return ForestNodeMerger.merge(baseMapper.tree());
|
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
|
- public List<DictVO> parentTree() {
|
|
|
|
- return ForestNodeMerger.merge(baseMapper.parentTree());
|
|
|
|
- }
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public List<DictVO> parentTree() {
|
|
|
|
+ return ForestNodeMerger.merge(baseMapper.parentTree());
|
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
|
- public String getValue(String code, String dictKey) {
|
|
|
|
- return Func.toStr(baseMapper.getValue(code, dictKey), StringPool.EMPTY);
|
|
|
|
- }
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public String getValue(String code, String dictKey) {
|
|
|
|
+ if (dictKey.contains(",")) {
|
|
|
|
+ //liuYc 2023-01-05 userType字符串拼接
|
|
|
|
+ String[] split = dictKey.split(",");
|
|
|
|
+ List<String> str = new ArrayList<>();
|
|
|
|
+ for (String key : split) {
|
|
|
|
+ String result = Func.toStr(baseMapper.getValue(code, key), StringPool.EMPTY);
|
|
|
|
+ str.add(result);
|
|
|
|
+ }
|
|
|
|
+ return Func.toStr(str, StringPool.EMPTY);
|
|
|
|
+ }
|
|
|
|
+ return Func.toStr(baseMapper.getValue(code, dictKey), StringPool.EMPTY);
|
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
|
- public List<Dict> getList(String code) {
|
|
|
|
- return baseMapper.getList(code);
|
|
|
|
- }
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public List<Dict> getList(String code) {
|
|
|
|
+ return baseMapper.getList(code);
|
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
|
- public List<DictVO02> getList2(String code) {
|
|
|
|
- return baseMapper.getList2(code);
|
|
|
|
- }
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public List<DictVO02> getList2(String code) {
|
|
|
|
+ return baseMapper.getList2(code);
|
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
|
- public boolean submit(Dict dict) {
|
|
|
|
- LambdaQueryWrapper<Dict> lqw = Wrappers.<Dict>query().lambda().eq(Dict::getCode, dict.getCode()).eq(Dict::getDictKey, dict.getDictKey());
|
|
|
|
- Long cnt = baseMapper.selectCount((Func.isEmpty(dict.getId())) ? lqw : lqw.notIn(Dict::getId, dict.getId()));
|
|
|
|
- if (cnt > 0L) {
|
|
|
|
- throw new ServiceException("当前字典键值已存在!");
|
|
|
|
- }
|
|
|
|
- // 修改顶级字典后同步更新下属字典的编号
|
|
|
|
- if (Func.isNotEmpty(dict.getId()) && dict.getParentId().longValue() == BladeConstant.TOP_PARENT_ID) {
|
|
|
|
- Dict parent = DictCache.getById(dict.getId());
|
|
|
|
- this.update(Wrappers.<Dict>update().lambda().set(Dict::getCode, dict.getCode()).eq(Dict::getCode, parent.getCode()).ne(Dict::getParentId, BladeConstant.TOP_PARENT_ID));
|
|
|
|
- }
|
|
|
|
- if (Func.isEmpty(dict.getParentId())) {
|
|
|
|
- dict.setParentId(BladeConstant.TOP_PARENT_ID);
|
|
|
|
- }
|
|
|
|
- dict.setIsDeleted(BladeConstant.DB_NOT_DELETED);
|
|
|
|
- CacheUtil.clear(DICT_CACHE, Boolean.FALSE);
|
|
|
|
- return saveOrUpdate(dict);
|
|
|
|
- }
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public boolean submit(Dict dict) {
|
|
|
|
+ LambdaQueryWrapper<Dict> lqw = Wrappers.<Dict>query().lambda().eq(Dict::getCode, dict.getCode()).eq(Dict::getDictKey, dict.getDictKey());
|
|
|
|
+ Long cnt = baseMapper.selectCount((Func.isEmpty(dict.getId())) ? lqw : lqw.notIn(Dict::getId, dict.getId()));
|
|
|
|
+ if (cnt > 0L) {
|
|
|
|
+ throw new ServiceException("当前字典键值已存在!");
|
|
|
|
+ }
|
|
|
|
+ // 修改顶级字典后同步更新下属字典的编号
|
|
|
|
+ if (Func.isNotEmpty(dict.getId()) && dict.getParentId().longValue() == BladeConstant.TOP_PARENT_ID) {
|
|
|
|
+ Dict parent = DictCache.getById(dict.getId());
|
|
|
|
+ this.update(Wrappers.<Dict>update().lambda().set(Dict::getCode, dict.getCode()).eq(Dict::getCode, parent.getCode()).ne(Dict::getParentId, BladeConstant.TOP_PARENT_ID));
|
|
|
|
+ }
|
|
|
|
+ if (Func.isEmpty(dict.getParentId())) {
|
|
|
|
+ dict.setParentId(BladeConstant.TOP_PARENT_ID);
|
|
|
|
+ }
|
|
|
|
+ dict.setIsDeleted(BladeConstant.DB_NOT_DELETED);
|
|
|
|
+ CacheUtil.clear(DICT_CACHE, Boolean.FALSE);
|
|
|
|
+ return saveOrUpdate(dict);
|
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
|
- public boolean removeDict(String ids) {
|
|
|
|
- Long cnt = baseMapper.selectCount(Wrappers.<Dict>query().lambda().in(Dict::getParentId, Func.toLongList(ids)));
|
|
|
|
- if (cnt > 0L) {
|
|
|
|
- throw new ServiceException("请先删除子节点!");
|
|
|
|
- }
|
|
|
|
- return removeByIds(Func.toLongList(ids));
|
|
|
|
- }
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public boolean removeDict(String ids) {
|
|
|
|
+ Long cnt = baseMapper.selectCount(Wrappers.<Dict>query().lambda().in(Dict::getParentId, Func.toLongList(ids)));
|
|
|
|
+ if (cnt > 0L) {
|
|
|
|
+ throw new ServiceException("请先删除子节点!");
|
|
|
|
+ }
|
|
|
|
+ return removeByIds(Func.toLongList(ids));
|
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
|
- public IPage<DictVO> parentList(Map<String, Object> dict, Query query) {
|
|
|
|
- IPage<Dict> page = this.page(Condition.getPage(query), Condition.getQueryWrapper(dict, Dict.class).lambda().eq(Dict::getParentId, CommonConstant.TOP_PARENT_ID).orderByAsc(Dict::getSort));
|
|
|
|
- return DictWrapper.build().pageVO(page);
|
|
|
|
- }
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public IPage<DictVO> parentList(Map<String, Object> dict, Query query) {
|
|
|
|
+ IPage<Dict> page = this.page(Condition.getPage(query), Condition.getQueryWrapper(dict, Dict.class).lambda().eq(Dict::getParentId, CommonConstant.TOP_PARENT_ID).orderByAsc(Dict::getSort));
|
|
|
|
+ return DictWrapper.build().pageVO(page);
|
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
|
- public List<DictVO> childList(Map<String, Object> dict, Long parentId) {
|
|
|
|
- if (parentId < 0) {
|
|
|
|
- return new ArrayList<>();
|
|
|
|
- }
|
|
|
|
- dict.remove("parentId");
|
|
|
|
- Dict parentDict = DictCache.getById(parentId);
|
|
|
|
- List<Dict> list = this.list(Condition.getQueryWrapper(dict, Dict.class).lambda().ne(Dict::getId, parentId).eq(Dict::getCode, parentDict.getCode()).orderByAsc(Dict::getSort));
|
|
|
|
- return DictWrapper.build().listNodeVO(list);
|
|
|
|
- }
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public List<DictVO> childList(Map<String, Object> dict, Long parentId) {
|
|
|
|
+ if (parentId < 0) {
|
|
|
|
+ return new ArrayList<>();
|
|
|
|
+ }
|
|
|
|
+ dict.remove("parentId");
|
|
|
|
+ Dict parentDict = DictCache.getById(parentId);
|
|
|
|
+ List<Dict> list = this.list(Condition.getQueryWrapper(dict, Dict.class).lambda().ne(Dict::getId, parentId).eq(Dict::getCode, parentDict.getCode()).orderByAsc(Dict::getSort));
|
|
|
|
+ return DictWrapper.build().listNodeVO(list);
|
|
|
|
+ }
|
|
}
|
|
}
|