提交 | 用户 | 时间
|
1ac2bc
|
1 |
package cn.stylefeng.guns.sys.modular.rest.service; |
懒 |
2 |
|
|
3 |
import cn.stylefeng.guns.base.pojo.node.TreeviewNode; |
|
4 |
import cn.stylefeng.guns.base.pojo.node.ZTreeNode; |
|
5 |
import cn.stylefeng.guns.sys.core.exception.enums.BizExceptionEnum; |
|
6 |
import cn.stylefeng.guns.sys.modular.rest.entity.RestDept; |
|
7 |
import cn.stylefeng.guns.sys.modular.rest.mapper.RestDeptMapper; |
|
8 |
import cn.stylefeng.roses.core.util.ToolUtil; |
|
9 |
import cn.stylefeng.roses.kernel.model.exception.ServiceException; |
|
10 |
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
11 |
import org.springframework.stereotype.Service; |
|
12 |
import org.springframework.transaction.annotation.Transactional; |
|
13 |
|
|
14 |
import javax.annotation.Resource; |
|
15 |
import java.util.List; |
|
16 |
import java.util.Map; |
|
17 |
|
|
18 |
/** |
|
19 |
* <p> |
|
20 |
* 部门表 服务实现类 |
|
21 |
* </p> |
|
22 |
* |
|
23 |
* @author stylefeng |
|
24 |
* @since 2018-12-07 |
|
25 |
*/ |
|
26 |
@Service |
|
27 |
public class RestDeptService extends ServiceImpl<RestDeptMapper, RestDept> { |
|
28 |
|
|
29 |
@Resource |
|
30 |
private RestDeptMapper restDeptMapper; |
|
31 |
|
|
32 |
/** |
|
33 |
* 新增部门 |
|
34 |
* |
|
35 |
* @author fengshuonan |
|
36 |
* @Date 2018/12/23 5:00 PM |
|
37 |
*/ |
|
38 |
@Transactional(rollbackFor = Exception.class) |
|
39 |
public void addDept(RestDept dept) { |
|
40 |
|
|
41 |
if (ToolUtil.isOneEmpty(dept, dept.getSimpleName(), dept.getFullName(), dept.getPid(), dept.getDescription())) { |
|
42 |
throw new ServiceException(BizExceptionEnum.REQUEST_NULL); |
|
43 |
} |
|
44 |
|
|
45 |
//完善pids,根据pid拿到pid的pids |
|
46 |
this.deptSetPids(dept); |
|
47 |
|
|
48 |
this.save(dept); |
|
49 |
} |
|
50 |
|
|
51 |
/** |
|
52 |
* 修改部门 |
|
53 |
* |
|
54 |
* @author fengshuonan |
|
55 |
* @Date 2018/12/23 5:00 PM |
|
56 |
*/ |
|
57 |
@Transactional(rollbackFor = Exception.class) |
|
58 |
public void editDept(RestDept dept) { |
|
59 |
|
|
60 |
if (ToolUtil.isOneEmpty(dept, dept.getDeptId(), dept.getSimpleName(), dept.getFullName(), dept.getPid(), dept.getDescription())) { |
|
61 |
throw new ServiceException(BizExceptionEnum.REQUEST_NULL); |
|
62 |
} |
|
63 |
|
|
64 |
//完善pids,根据pid拿到pid的pids |
|
65 |
this.deptSetPids(dept); |
|
66 |
|
|
67 |
this.updateById(dept); |
|
68 |
} |
|
69 |
|
|
70 |
/** |
|
71 |
* 删除部门 |
|
72 |
* |
|
73 |
* @author fengshuonan |
|
74 |
* @Date 2018/12/23 5:16 PM |
|
75 |
*/ |
|
76 |
@Transactional |
|
77 |
public void deleteDept(Long deptId) { |
|
78 |
RestDept dept = restDeptMapper.selectById(deptId); |
|
79 |
|
|
80 |
//根据like查询删除所有级联的部门 |
|
81 |
List<RestDept> subDepts = restDeptMapper.likePids(dept.getDeptId()); |
|
82 |
|
|
83 |
for (RestDept temp : subDepts) { |
|
84 |
this.removeById(temp.getDeptId()); |
|
85 |
} |
|
86 |
|
|
87 |
this.removeById(dept.getDeptId()); |
|
88 |
} |
|
89 |
|
|
90 |
/** |
|
91 |
* 获取ztree的节点列表 |
|
92 |
* |
|
93 |
* @author fengshuonan |
|
94 |
* @Date 2018/12/23 5:16 PM |
|
95 |
*/ |
|
96 |
public List<ZTreeNode> tree() { |
|
97 |
return this.baseMapper.tree(); |
|
98 |
} |
|
99 |
|
|
100 |
/** |
|
101 |
* 获取ztree的节点列表 |
|
102 |
* |
|
103 |
* @author fengshuonan |
|
104 |
* @Date 2018/12/23 5:16 PM |
|
105 |
*/ |
|
106 |
public List<TreeviewNode> treeviewNodes() { |
|
107 |
return this.baseMapper.treeviewNodes(); |
|
108 |
} |
|
109 |
|
|
110 |
/** |
|
111 |
* 获取所有部门列表 |
|
112 |
* |
|
113 |
* @author fengshuonan |
|
114 |
* @Date 2018/12/23 5:16 PM |
|
115 |
*/ |
|
116 |
public List<Map<String, Object>> list(String condition, Long deptId) { |
|
117 |
return this.baseMapper.listNotPage(condition, deptId); |
|
118 |
} |
|
119 |
|
|
120 |
/** |
|
121 |
* 设置部门的父级ids |
|
122 |
* |
|
123 |
* @author fengshuonan |
|
124 |
* @Date 2018/12/23 4:58 PM |
|
125 |
*/ |
|
126 |
private void deptSetPids(RestDept dept) { |
|
127 |
if (ToolUtil.isEmpty(dept.getPid()) || dept.getPid().equals(0L)) { |
|
128 |
dept.setPid(0L); |
|
129 |
dept.setPids("[0],"); |
|
130 |
} else { |
|
131 |
Long pid = dept.getPid(); |
|
132 |
RestDept temp = this.getById(pid); |
|
133 |
String pids = temp.getPids(); |
|
134 |
dept.setPid(pid); |
|
135 |
dept.setPids(pids + "[" + pid + "],"); |
|
136 |
} |
|
137 |
} |
|
138 |
} |