MemberServiceImpl.java
11.3 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
286
package com.subsidy.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.subsidy.common.exception.HttpException;
import com.subsidy.dto.company.AttendMembersDTO;
import com.subsidy.dto.member.*;
import com.subsidy.mapper.*;
import com.subsidy.model.*;
import com.subsidy.service.MemberService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.util.ConstantUtils;
import com.subsidy.util.excel.ExcelUtil;
import com.subsidy.vo.member.AttendMembersVO;
import com.subsidy.vo.member.DepartMembersVO;
import com.subsidy.vo.member.GetAllVO;
import com.subsidy.vo.member.MemberAttendInfoVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* <p>
* 学生表 服务实现类
* </p>
*
* @author Tuyp
* @since 2024-01-11
*/
@Service
public class MemberServiceImpl extends ServiceImpl<MemberMapper, MemberDO> implements MemberService {
@Autowired
private MemberDepartmentMappingMapper memberDepartmentMappingMapper;
@Autowired
private CompanyMemberMappingMapper companyMemberMappingMapper;
@Autowired
private DepartmentDictMapper departmentDictMapper;
@Autowired
private JobDictMapper jobDictMapper;
@Autowired
private ClassMemberMappingMapper classMemberMappingMapper;
@Autowired
private JobMemberMappingMapper jobMemberMappingMapper;
public IPage<DepartMembersVO> departMembers(DepartMembersDTO departMembersDTO) {
Page pager = new Page(departMembersDTO.getPageNum(), departMembersDTO.getPageSize());
return companyMemberMappingMapper.departMembers(pager, departMembersDTO.getCompanyId(), departMembersDTO.getUserName());
}
public void exportDepartMembers(DepartMembersDTO departMembersDTO) {
Page pager = new Page(1, -1);
IPage<DepartMembersVO> departMembersVOIPage = companyMemberMappingMapper.departMembers(pager, departMembersDTO.getCompanyId(), departMembersDTO.getUserName());
List<DepartMembersVO> departMembersVOS = departMembersVOIPage.getRecords();
ExcelUtil.writeExcel(departMembersVOS, DepartMembersVO.class);
}
public IPage<AttendMembersVO> attendMembers(AttendMembersDTO attendMembersDTO) {
Page pager = new Page(attendMembersDTO.getPageNum(), attendMembersDTO.getPageSize());
IPage<AttendMembersVO> attendMembersVOIPage = companyMemberMappingMapper.attendMembers(pager, attendMembersDTO.getCompanyId(), attendMembersDTO.getDepartmentId(), attendMembersDTO.getUserName());
List<AttendMembersVO> getAllVOS = attendMembersVOIPage.getRecords();
for (AttendMembersVO getAllVO : getAllVOS) {
//获取这个人所在的部门
List<DepartmentDictDO> departmentDictDOS = this.baseMapper.getDepartments(getAllVO.getId());
getAllVO.setDepartmentDictDOS(departmentDictDOS);
//获取这个人所在的岗位
List<JobDictDO> jobDictDOS = jobDictMapper.queryMemberJobs(getAllVO.getId());
getAllVO.setJobDictDOS(jobDictDOS);
}
return attendMembersVOIPage;
}
public List<MemberAttendInfoVO> memberAttendInfo(CompanyMemberMappingDO companyMemberMappingDO) {
return companyMemberMappingMapper.memberAttendInfo(companyMemberMappingDO.getMemberId(), companyMemberMappingDO.getCompanyId());
}
public IPage<GetAllVO> getAll(GetAllDTO getAllDTO) {
Page pager = new Page(getAllDTO.getPageNum(), getAllDTO.getPageSize());
DepartmentDictDO departmentDictDO = departmentDictMapper.selectById(getAllDTO.getDepartmentId());
IPage iPage = null;
if (null != departmentDictDO.getParentId()) {
iPage = this.baseMapper.getMembers(pager, getAllDTO.getDepartmentId(), getAllDTO.getUserName(), getAllDTO.getStatus(), getAllDTO.getStartDate(), getAllDTO.getEndDate());
} else {
iPage = this.baseMapper.getCompanyMember(pager, departmentDictDO.getCompanyId(), getAllDTO.getUserName(), getAllDTO.getStatus(), getAllDTO.getStartDate(), getAllDTO.getEndDate());
}
List<GetAllVO> getAllVOS = iPage.getRecords();
for (GetAllVO getAllVO : getAllVOS) {
//获取这个人所在的部门
List<DepartmentDictDO> departmentDictDOS = this.baseMapper.getDepartments(getAllVO.getId());
getAllVO.setDepartmentDictDOS(departmentDictDOS);
//获取这个人所在的岗位
List<JobDictDO> jobDictDOS = jobDictMapper.queryMemberJobs(getAllVO.getId());
getAllVO.setJobDictDOS(jobDictDOS);
}
return iPage;
}
@Transactional(rollbackFor = Exception.class)
public String deleteMember(MemberDO memberDO) {
this.baseMapper.deleteById(memberDO.getId());
classMemberMappingMapper.delete(new QueryWrapper<ClassMemberMappingDO>()
.lambda()
.eq(ClassMemberMappingDO::getMemberId, memberDO.getId()));
memberDepartmentMappingMapper.delete(new QueryWrapper<MemberDepartmentMappingDO>()
.lambda()
.eq(MemberDepartmentMappingDO::getMemberId, memberDO.getId()));
return ConstantUtils.DELETE_SUCCESS;
}
public String addMember(AddMemberDTO addMemberDTO) {
Integer count = this.baseMapper.selectCount(new QueryWrapper<MemberDO>()
.lambda()
.eq(MemberDO::getTelephone, addMemberDTO.getTelephone())
.eq(MemberDO::getMemberType, 2));
if (count > 0) {
throw new HttpException(20002);
}
Integer count2 = this.baseMapper.selectCount(new QueryWrapper<MemberDO>()
.lambda()
.eq(MemberDO::getIdCard, addMemberDTO.getIdCard())
.eq(MemberDO::getMemberType, 2));
if (count2 > 0) {
throw new HttpException(20002);
}
List<MemberDO> memberDOS = companyMemberMappingMapper.companyAccountMembers(addMemberDTO.getCompanyId(), addMemberDTO.getAccountName());
if (memberDOS.size() > 0) {
throw new HttpException(20002);
}
MemberDO memberDO = new MemberDO();
BeanUtils.copyProperties(addMemberDTO, memberDO);
memberDO.setPassword("Ykhl123456");
memberDO.setStatus("启用");
memberDO.setFirstLogin(0);
memberDO.setMemberType(2);
this.baseMapper.insert(memberDO);
//公司赋值
CompanyMemberMappingDO companyMemberMappingDO = new CompanyMemberMappingDO();
companyMemberMappingDO.setCompanyId(addMemberDTO.getCompanyId());
companyMemberMappingDO.setMemberId(memberDO.getId());
companyMemberMappingDO.setMemberStatus(1);
companyMemberMappingMapper.insert(companyMemberMappingDO);
if (null != addMemberDTO.getDepartmentIds()) {
//部门
List<Long> longs = addMemberDTO.getDepartmentIds();
for (Long lg : longs) {
MemberDepartmentMappingDO memberDepartmentMappingDO = new MemberDepartmentMappingDO();
memberDepartmentMappingDO.setMemberId(memberDO.getId());
memberDepartmentMappingDO.setDepartmentId(lg);
memberDepartmentMappingDO.setMemberStatus(1);
memberDepartmentMappingMapper.insert(memberDepartmentMappingDO);
}
}
if (null != addMemberDTO.getJobIds()) {
jobMemberMappingMapper.delete(new QueryWrapper<JobMemberMappingDO>()
.lambda()
.eq(JobMemberMappingDO::getMemberId, addMemberDTO.getId()));
//岗位
List<Long> longs = addMemberDTO.getJobIds();
for (Long lg : longs) {
JobMemberMappingDO jobMemberMappingDO = new JobMemberMappingDO();
jobMemberMappingDO.setMemberId(memberDO.getId());
jobMemberMappingDO.setJobId(lg);
jobMemberMappingMapper.insert(jobMemberMappingDO);
}
}
return ConstantUtils.ADD_SUCCESS;
}
public String updateMember(AddMemberDTO addMemberDTO) {
Integer count = this.baseMapper.selectCount(new QueryWrapper<MemberDO>()
.lambda()
.eq(MemberDO::getTelephone, addMemberDTO.getTelephone())
.ne(MemberDO::getId, addMemberDTO.getId()));
if (count > 0) {
throw new HttpException(20002);
}
Integer count1 = this.baseMapper.selectCount(new QueryWrapper<MemberDO>()
.lambda()
.eq(MemberDO::getIdCard, addMemberDTO.getIdCard())
.ne(MemberDO::getId, addMemberDTO.getId()));
if (count1 > 0) {
throw new HttpException(20002);
}
MemberDO memberDO = new MemberDO();
BeanUtils.copyProperties(addMemberDTO, memberDO);
this.baseMapper.updateById(memberDO);
if (null != addMemberDTO.getDepartmentIds()) {
memberDepartmentMappingMapper.delete(new QueryWrapper<MemberDepartmentMappingDO>()
.lambda()
.eq(MemberDepartmentMappingDO::getMemberId, addMemberDTO.getId()));
//部门
List<Long> longs = addMemberDTO.getDepartmentIds();
for (Long lg : longs) {
MemberDepartmentMappingDO memberDepartmentMappingDO = new MemberDepartmentMappingDO();
memberDepartmentMappingDO.setMemberId(memberDO.getId());
memberDepartmentMappingDO.setDepartmentId(lg);
memberDepartmentMappingDO.setMemberStatus(1);
memberDepartmentMappingMapper.insert(memberDepartmentMappingDO);
}
}
if (null != addMemberDTO.getJobIds()) {
jobMemberMappingMapper.delete(new QueryWrapper<JobMemberMappingDO>()
.lambda()
.eq(JobMemberMappingDO::getMemberId, addMemberDTO.getId()));
//岗位
List<Long> longs = addMemberDTO.getJobIds();
for (Long lg : longs) {
JobMemberMappingDO jobMemberMappingDO = new JobMemberMappingDO();
jobMemberMappingDO.setMemberId(memberDO.getId());
jobMemberMappingDO.setJobId(lg);
jobMemberMappingMapper.insert(jobMemberMappingDO);
}
}
return ConstantUtils.SET_SUCCESS;
}
public String changeDepartments(ChangeDepartmentsDTO changeDepartmentsDTO) {
List<Long> memberIds = changeDepartmentsDTO.getMemberIds();
//清掉以前的部门
for (Long lg : memberIds) {
memberDepartmentMappingMapper.cancelMember(lg);
}
//加入新的部门
List<Long> depIds = changeDepartmentsDTO.getDesDepId();
for (Long lg : memberIds) {
for (Long depId : depIds) {
MemberDepartmentMappingDO memberDepartmentMappingDO = new MemberDepartmentMappingDO();
memberDepartmentMappingDO.setMemberId(lg);
memberDepartmentMappingDO.setDepartmentId(depId);
memberDepartmentMappingDO.setMemberStatus(1);
memberDepartmentMappingMapper.insert(memberDepartmentMappingDO);
}
}
return ConstantUtils.SET_SUCCESS;
}
}