DepartmentDictServiceImpl.java
12.1 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
package com.meishu.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.meishu.common.exception.HttpException;
import com.meishu.dto.department.BatchOprDTO;
import com.meishu.dto.department.GetAllDepartmentVO;
import com.meishu.dto.department.GetTeachersDTO;
import com.meishu.dto.subject.GetSubjectTreeDTO;
import com.meishu.mapper.AdministerDepartmentMappingMapper;
import com.meishu.mapper.AdministerMapper;
import com.meishu.model.*;
import com.meishu.mapper.DepartmentDictMapper;
import com.meishu.service.DepartmentDictService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.meishu.util.ConstantUtils;
import com.meishu.vo.administer.GetTeachersVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
* <p>
* 部门字典表 服务实现类
* </p>
*
* @author Tuyp
* @since 2021-04-25
*/
@Service
public class DepartmentDictServiceImpl extends ServiceImpl<DepartmentDictMapper, DepartmentDictDO> implements DepartmentDictService {
@Autowired
private AdministerMapper administerMapper;
@Autowired
private AdministerDepartmentMappingMapper administerDepartmentMappingMapper;
public List<GetAllDepartmentVO> getDepartmentInfo() {
//返回结果
List<GetAllDepartmentVO> getAllDepartmentVOS = new ArrayList<>();
//获取所有的父节点
List<DepartmentDictDO> parentNodes = this.baseMapper.selectList(new QueryWrapper<DepartmentDictDO>()
.lambda()
.isNull(DepartmentDictDO::getParentId));
//遍历父节点
for (DepartmentDictDO departmentDictDO : parentNodes) {
GetAllDepartmentVO getAllDepartmentVO = new GetAllDepartmentVO();
BeanUtils.copyProperties(departmentDictDO, getAllDepartmentVO);
if (null != departmentDictDO.getParentId()) {
DepartmentDictDO departmentDictDO1 = this.baseMapper.selectById(departmentDictDO.getParentId());
getAllDepartmentVO.setParentDepartmentName(departmentDictDO1.getDepartmentName());
}
getAllDepartmentVO.setChildren(getChildNodes(getAllDepartmentVO));
AdministerDO administerDO = administerMapper.selectById(getAllDepartmentVO.getDepartmentLeaderId());
if (null != administerDO) {
List<AdministerDepartmentMappingDO> administerDepartmentMappingDOS = administerDepartmentMappingMapper.selectList(new QueryWrapper<AdministerDepartmentMappingDO>()
.lambda()
.eq(AdministerDepartmentMappingDO::getAdministerId, administerDO.getId()));
getAllDepartmentVO.setAdministerDepartmentMappingDOS(administerDepartmentMappingDOS);
getAllDepartmentVO.setAdministerId(administerDO.getId());
getAllDepartmentVO.setUserName(administerDO.getUserName());
getAllDepartmentVO.setImg(administerDO.getImg());
}
Integer count = administerDepartmentMappingMapper.selectCount(new QueryWrapper<AdministerDepartmentMappingDO>()
.lambda()
.eq(AdministerDepartmentMappingDO::getDepartmentId, departmentDictDO.getId()));
getAllDepartmentVO.setCount(count);
//部门人员
List<AdministerDO> administerDOS = administerMapper.getAdministerByDepartmentId(departmentDictDO.getId());
getAllDepartmentVO.setAdministerDOS(administerDOS);
getAllDepartmentVOS.add(getAllDepartmentVO);
}
return getAllDepartmentVOS;
}
public List<DepartmentDictDO> getDepartmentList(GetSubjectTreeDTO getSubjectTreeDTO) {
//查看角色所在部门
List<DepartmentDictDO> departmentDictDOS = administerMapper.getDepartmentByAdministerId(getSubjectTreeDTO.getUserId());
List<Long> ids = new ArrayList<>();
for (DepartmentDictDO departmentDictDO : departmentDictDOS) {
ids.add(departmentDictDO.getId());
}
List<DepartmentDictDO> parentNodes = this.baseMapper.selectList(new QueryWrapper<DepartmentDictDO>()
.lambda()
.eq(DepartmentDictDO::getParentId, 1)
.in(DepartmentDictDO::getId, ids));
for (DepartmentDictDO departmentDictDO : parentNodes) {
departmentDictDO.setChildren(getChildNodes(departmentDictDO));
}
return parentNodes;
}
public String addDepartment(DepartmentDictDO departmentDictDO) {
Integer count = this.baseMapper.selectCount(new QueryWrapper<DepartmentDictDO>()
.lambda()
.eq(DepartmentDictDO::getDepartmentName, departmentDictDO.getDepartmentName()));
if (count > 0) {
throw new HttpException(20001);
}
this.baseMapper.insert(departmentDictDO);
return ConstantUtils.ADD_SUCCESS;
}
public IPage<GetTeachersVO> getTeachers(GetTeachersDTO getTeachersDTO) {
Page pager = new Page(getTeachersDTO.getPageNum(), getTeachersDTO.getPageSize());
List<Long> userIds = new ArrayList<>();
//查看该角色所在部门
if (null == getTeachersDTO.getDepartmentId()){
List<DepartmentDictDO> departmentDictDOS = administerMapper.getDepartmentByAdministerId(getTeachersDTO.getUserId());
for (DepartmentDictDO departmentDictDO : departmentDictDOS){
userIds.add(departmentDictDO.getId());
}
}
IPage<GetTeachersVO> getTeachersVOIPage = administerMapper.getDepartmentTeachers(pager, getTeachersDTO.getDepartmentId(), getTeachersDTO.getCampusId(), getTeachersDTO.getUserName(),userIds);
List<GetTeachersVO> getTeachersVOS = getTeachersVOIPage.getRecords();
for (GetTeachersVO getTeachersVO : getTeachersVOS) {
// List<CampusDictDO> campusDictDOS = administerMapper.getTeacherCampus(getTeachersVO.getId());
// getTeachersVO.setCampusDictDOS(campusDictDOS);
//部门
List<DepartmentDictDO> departmentDictDOS = administerMapper.getDepartmentByAdministerId(getTeachersVO.getId());
getTeachersVO.setDepartmentDictDOS(departmentDictDOS);
//科目
List<KnowledgeSubjectDictDO> knowledgeSubjectDicts = administerMapper.getTeacherSubjects(getTeachersVO.getId());
getTeachersVO.setKnowledgeSubjectDicts(knowledgeSubjectDicts);
//角色
List<RoleDictDO> roleDictDOS = administerMapper.getTeacherRoles(getTeachersVO.getId());
getTeachersVO.setRoleDictDOS(roleDictDOS);
//多个在读班级
List<SubjectDictDO> subjectDictDOS = administerMapper.getTeacherClasses(getTeachersVO.getId());
getTeachersVO.setSubjectDictDOS(subjectDictDOS);
}
return getTeachersVOIPage;
}
public String batchOpr(BatchOprDTO batchOprDTO) {
List<Long> longs = batchOprDTO.getIds();
for (Long lg : longs) {
DepartmentDictDO departmentDictDO = this.baseMapper.selectById(lg);
if (null != batchOprDTO.getDepartmentLeaderId()) {
departmentDictDO.setDepartmentLeaderId(batchOprDTO.getDepartmentLeaderId());
}
if (null != batchOprDTO.getParentId()) {
departmentDictDO.setParentId(batchOprDTO.getParentId());
}
this.baseMapper.updateById(departmentDictDO);
}
return ConstantUtils.SUCCESS_UPDATE;
}
public String deleteDepartment(BatchOprDTO batchOprDTO) {
List<Long> longs = batchOprDTO.getIds();
for (Long lg : longs) {
List<DepartmentDictDO> departmentDictDOS = this.baseMapper.selectList(new QueryWrapper<DepartmentDictDO>()
.lambda()
.eq(DepartmentDictDO::getParentId, lg)
);
for (DepartmentDictDO departmentDictDO1 : departmentDictDOS) {
deleteChildNode(departmentDictDO1);
}
this.baseMapper.deleteById(lg);
}
return ConstantUtils.DELETE_SUCCESS;
}
public String updateDepartment(DepartmentDictDO departmentDictDO) {
this.baseMapper.updateById(departmentDictDO);
return ConstantUtils.SUCCESS_UPDATE;
}
void deleteChildNode(DepartmentDictDO departmentDictDO) {
List<DepartmentDictDO> departmentDictDOS = this.baseMapper.selectList(new QueryWrapper<DepartmentDictDO>()
.lambda()
.eq(DepartmentDictDO::getParentId, departmentDictDO.getId()));
for (DepartmentDictDO departmentDictDO1 : departmentDictDOS) {
deleteChildNode(departmentDictDO1);
}
this.baseMapper.deleteById(departmentDictDO.getId());
}
/**
* 递归 带上部门总数,部门负责人等参数
*
* @param getAllDepartmentVO 父节点查找该节点的children
* @return 子节点
*/
public List<GetAllDepartmentVO> getChildNodes(GetAllDepartmentVO getAllDepartmentVO) {
List<GetAllDepartmentVO> getAllDepartmentVOS = new ArrayList<>();
//查询该节点的子节点
List<DepartmentDictDO> departmentDictDOS = this.baseMapper.selectList(new QueryWrapper<DepartmentDictDO>()
.lambda()
.eq(DepartmentDictDO::getParentId, getAllDepartmentVO.getId()));
//递归
for (DepartmentDictDO dd : departmentDictDOS) {
GetAllDepartmentVO getAllDepartmentVO1 = new GetAllDepartmentVO();
BeanUtils.copyProperties(dd, getAllDepartmentVO1);
if (null != dd.getParentId()) {
DepartmentDictDO departmentDictDO = this.baseMapper.selectById(dd.getParentId());
getAllDepartmentVO1.setParentDepartmentName(departmentDictDO.getDepartmentName());
}
getAllDepartmentVO1.setChildren(getChildNodes(getAllDepartmentVO1));
AdministerDO administerDO = administerMapper.selectById(getAllDepartmentVO1.getDepartmentLeaderId());
if (null != administerDO) {
List<AdministerDepartmentMappingDO> administerDepartmentMappingDOS = administerDepartmentMappingMapper.selectList(new QueryWrapper<AdministerDepartmentMappingDO>()
.lambda()
.eq(AdministerDepartmentMappingDO::getAdministerId, administerDO.getId()));
getAllDepartmentVO1.setAdministerDepartmentMappingDOS(administerDepartmentMappingDOS);
getAllDepartmentVO1.setUserName(administerDO.getUserName());
getAllDepartmentVO1.setImg(administerDO.getImg());
getAllDepartmentVO1.setAdministerId(administerDO.getId());
}
Integer count = administerDepartmentMappingMapper.selectCount(new QueryWrapper<AdministerDepartmentMappingDO>()
.lambda()
.eq(AdministerDepartmentMappingDO::getDepartmentId, dd.getId()));
getAllDepartmentVO1.setCount(count);
//部门人员
List<AdministerDO> administerDOS = administerMapper.getAdministerByDepartmentId(dd.getId());
getAllDepartmentVO1.setAdministerDOS(administerDOS);
getAllDepartmentVOS.add(getAllDepartmentVO1);
}
if (departmentDictDOS.size() == 0) {
return null;
}
return getAllDepartmentVOS;
}
/**
* 递归部门列表 不包含老师信息和人数信息
*
* @param departmentDictDO
* @return
*/
public List<DepartmentDictDO> getChildNodes(DepartmentDictDO departmentDictDO) {
List<DepartmentDictDO> departmentDictDOS = this.baseMapper.selectList(new QueryWrapper<DepartmentDictDO>()
.lambda()
.eq(DepartmentDictDO::getParentId, departmentDictDO.getId()));
for (DepartmentDictDO departmentDictDO1 : departmentDictDOS) {
departmentDictDO1.setChildren(getChildNodes(departmentDictDO1));
}
if (departmentDictDOS.size() == 0) {
return null;
}
return departmentDictDOS;
}
}