SysEnumerationServiceImpl.java
3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package com.lego.system.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeNodeConfig;
import cn.hutool.core.lang.tree.TreeUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.lego.system.service.ISysEnumerationService;
import com.lego.common.constant.CacheNames;
import com.lego.common.constant.SystemConstants;
import com.lego.system.domain.SysEnumeration;
import com.lego.system.domain.bo.SysEnumerationQueryBo;
import com.lego.system.mapper.SysEnumerationMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 枚举Service业务层处理
*
* @author gyongyi
* @date 2024-07-19
*/
@RequiredArgsConstructor
@Service
public class SysEnumerationServiceImpl implements ISysEnumerationService {
private final SysEnumerationMapper baseMapper;
@Cacheable(cacheNames = CacheNames.SYS_ENUMERATION_TYPE, key = "#enumerationType")
@Override
public List<Tree<String>> queryEnumerationTreeList(String enumerationType) {
LambdaQueryWrapper<SysEnumeration> lqw = Wrappers.lambdaQuery();
lqw.eq(SysEnumeration::getType, enumerationType);
List<SysEnumeration> enumerationList = baseMapper.selectList(lqw);
return buildDeptTreeSelect(enumerationList);
}
@Override
public Tree<String> queryById(String id) {
SysEnumeration enumeration = baseMapper.selectById(id);
return new Tree<String>(){{
setId(StrUtil.toStringOrNull(enumeration.getEnumerationId()));
setParentId(StrUtil.toStringOrNull(enumeration.getParentId()));
// 扩展属性 ...
putExtra(SystemConstants.ENUMERATION_LABEL, enumeration.getLabel());
putExtra(SystemConstants.ENUMERATION_VALUE, enumeration.getValue());
}};
}
@Override
public List<Tree<String>> queryList(SysEnumerationQueryBo query) {
LambdaQueryWrapper<SysEnumeration> lqw = buildQueryWrapper(query);
List<SysEnumeration> enumerationList = baseMapper.selectList(lqw);
return buildDeptTreeSelect(enumerationList);
}
private LambdaQueryWrapper<SysEnumeration> buildQueryWrapper(SysEnumerationQueryBo bo) {
LambdaQueryWrapper<SysEnumeration> lqw = Wrappers.lambdaQuery();
lqw.eq(bo.getParentId() != null, SysEnumeration::getParentId, bo.getParentId());
return lqw;
}
/**
* 构建前端所需要下拉树结构
*
* @param enumerationList
* @return 下拉树结构列表
*/
private List<Tree<String>> buildDeptTreeSelect(List<SysEnumeration> enumerationList) {
if (CollUtil.isEmpty(enumerationList)) {
return CollUtil.newArrayList();
}
//配置
return TreeUtil.build(enumerationList, StrUtil.toStringOrNull(enumerationList.get(0).getParentId()), new TreeNodeConfig(),
(treeNode, tree) -> {
tree.setId(StrUtil.toStringOrNull(treeNode.getEnumerationId()));
tree.setParentId(StrUtil.toStringOrNull(treeNode.getParentId()));
// 扩展属性 ...
tree.putExtra(SystemConstants.ENUMERATION_LABEL, treeNode.getLabel());
tree.putExtra(SystemConstants.ENUMERATION_VALUE, treeNode.getValue());
});
}
}