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