AcademyDictServiceImpl.java
9.75 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
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.academy.AcademiesDTO;
import com.subsidy.dto.academy.AcademyAccountDTO;
import com.subsidy.dto.academy.AddAcademyAccountDTO;
import com.subsidy.dto.academy.AddAcademyDTO;
import com.subsidy.mapper.AdministerAcademyMappingMapper;
import com.subsidy.mapper.AdministerMapper;
import com.subsidy.model.AcademyDictDO;
import com.subsidy.mapper.AcademyDictMapper;
import com.subsidy.model.AdministerAcademyMappingDO;
import com.subsidy.model.AdministerCompanyMappingDO;
import com.subsidy.model.AdministerDO;
import com.subsidy.service.AcademyDictService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.util.ConstantUtils;
import com.subsidy.vo.academy.AcademiesVO;
import com.subsidy.vo.academy.AcademyAccountVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.xml.ws.Action;
import java.util.ArrayList;
import java.util.List;
/**
* <p>
* 院校字典表 服务实现类
* </p>
*
* @author Tuyp
* @since 2024-02-23
*/
@Service
public class AcademyDictServiceImpl extends ServiceImpl<AcademyDictMapper, AcademyDictDO> implements AcademyDictService {
@Autowired
private AdministerMapper administerMapper;
@Autowired
private AdministerAcademyMappingMapper administerAcademyMappingMapper;
public IPage<AcademiesVO> academies(AcademiesDTO academiesDTO) {
Page pager = new Page(academiesDTO.getPageNum(), academiesDTO.getPageSize());
return this.baseMapper.academies(pager, academiesDTO.getAcademyName());
}
@Transactional(rollbackFor = Exception.class)
public String addAcademy(AddAcademyDTO addAcademyDTO) {
int count = this.baseMapper.selectCount(new QueryWrapper<AcademyDictDO>()
.lambda()
.eq(AcademyDictDO::getAcademyName, addAcademyDTO.getAcademyName()));
if (count > 0) {
throw new HttpException(10030);
}
//院校
AcademyDictDO academyDictDO = new AcademyDictDO();
BeanUtils.copyProperties(addAcademyDTO, academyDictDO);
this.baseMapper.insert(academyDictDO);
//账号
int count1 = administerMapper.selectCount(new QueryWrapper<AdministerDO>()
.lambda()
.eq(AdministerDO::getAccountName, addAcademyDTO.getAccountName()));
if (count1 > 0) {
throw new HttpException(10014);
}
AdministerDO administerDO = new AdministerDO();
BeanUtils.copyProperties(addAcademyDTO, administerDO);
administerDO.setRole(4);
administerDO.setStatus("1");
administerDO.setPassword("admin321");
administerDO.setUserName(academyDictDO.getAcademyName());
administerMapper.insert(administerDO);
//关联
AdministerAcademyMappingDO administerAcademyMappingDO = new AdministerAcademyMappingDO();
administerAcademyMappingDO.setAdministerId(administerDO.getId());
administerAcademyMappingDO.setAcademyId(academyDictDO.getId());
administerAcademyMappingMapper.insert(administerAcademyMappingDO);
return ConstantUtils.ADD_SUCCESS;
}
public String deleteAcademy(AcademyDictDO academyDictDO) {
this.baseMapper.deleteById(academyDictDO.getId());
List<AdministerAcademyMappingDO> administerAcademyMappingDOS = administerAcademyMappingMapper.selectList(new QueryWrapper<AdministerAcademyMappingDO>()
.lambda()
.eq(AdministerAcademyMappingDO::getAcademyId, academyDictDO.getId()));
administerAcademyMappingDOS.forEach(x -> {
administerAcademyMappingMapper.deleteById(x.getId());
administerMapper.deleteById(x.getAdministerId());
});
return ConstantUtils.DELETE_SUCCESS;
}
public String updateAcademy(AddAcademyDTO addAcademyDTO) {
AcademyDictDO academyDictDO = new AcademyDictDO();
BeanUtils.copyProperties(addAcademyDTO, academyDictDO);
this.updateById(academyDictDO);
//查看院校主账号
//账号
int count1 = administerMapper.selectCount(new QueryWrapper<AdministerDO>()
.lambda()
.eq(AdministerDO::getAccountName, addAcademyDTO.getAccountName())
.ne(AdministerDO::getId, addAcademyDTO.getId()));
if (count1 > 0) {
throw new HttpException(10014);
}
AdministerDO administerDO = this.baseMapper.mainAccount(addAcademyDTO.getId());
if (null != addAcademyDTO.getAccountName()) {
administerDO.setAccountName(addAcademyDTO.getAccountName());
}
if (null != addAcademyDTO.getTelephone()) {
administerDO.setTelephone(addAcademyDTO.getTelephone());
}
if (null != addAcademyDTO.getPassword()) {
administerDO.setPassword(addAcademyDTO.getPassword());
}
if (null != addAcademyDTO.getUserName()) {
administerDO.setUserName(addAcademyDTO.getUserName());
}
administerMapper.updateById(administerDO);
return ConstantUtils.SUCCESS_UPDATE;
}
public IPage academyAccount(AcademyAccountDTO academyAccountDTO) {
Page pager = new Page(academyAccountDTO.getPageNum(), academyAccountDTO.getPageSize());
IPage<AcademyAccountVO> academyAccountVOIPage = this.baseMapper.academyAccount(pager, academyAccountDTO.getAcademyName());
List<AcademyAccountVO> academyAccountVOS = academyAccountVOIPage.getRecords();
for (AcademyAccountVO aav : academyAccountVOS) {
//账户关联的院校
List<AcademyDictDO> academyDictDOS = this.baseMapper.accountAcademies(aav.getId());
aav.setAcademyDictDOS(academyDictDOS);
}
return academyAccountVOIPage;
}
public String addAcademyAccount(AddAcademyAccountDTO addAcademyAccountDTO) {
//账户
int count1 = administerMapper.selectCount(new QueryWrapper<AdministerDO>()
.lambda()
.eq(AdministerDO::getAccountName, addAcademyAccountDTO.getAccountName()));
if (count1 > 0) {
throw new HttpException(10014);
}
AdministerDO administerDO = new AdministerDO();
BeanUtils.copyProperties(addAcademyAccountDTO, administerDO);
administerDO.setRole(5);
administerMapper.insert(administerDO);
//映射关系
List<Long> academyIds = addAcademyAccountDTO.getAcademyIds();
for (Long academyId : academyIds) {
AdministerAcademyMappingDO administerAcademyMappingDO = new AdministerAcademyMappingDO();
administerAcademyMappingDO.setAcademyId(academyId);
administerAcademyMappingDO.setAdministerId(administerDO.getId());
administerAcademyMappingMapper.insert(administerAcademyMappingDO);
}
return ConstantUtils.ADD_SUCCESS;
}
public String deleteAcademyAccount(AdministerDO administerDO) {
administerMapper.deleteById(administerDO.getId());
List<AdministerAcademyMappingDO> administerAcademyMappingDOS = administerAcademyMappingMapper.selectList(new QueryWrapper<AdministerAcademyMappingDO>()
.lambda()
.eq(AdministerAcademyMappingDO::getAdministerId, administerDO.getId()));
for (AdministerAcademyMappingDO administerAcademyMappingDO : administerAcademyMappingDOS) {
administerAcademyMappingMapper.deleteById(administerAcademyMappingDO.getId());
}
return ConstantUtils.DELETE_SUCCESS;
}
public String updateAcademyAccount(AddAcademyAccountDTO addAcademyAccountDTO) {
//编辑人员信息
//账号
int count1 = administerMapper.selectCount(new QueryWrapper<AdministerDO>()
.lambda()
.eq(AdministerDO::getAccountName, addAcademyAccountDTO.getAccountName())
.ne(AdministerDO::getId, addAcademyAccountDTO.getId()));
if (count1 > 0) {
throw new HttpException(10014);
}
AdministerDO administerDO = new AdministerDO();
BeanUtils.copyProperties(addAcademyAccountDTO, administerDO);
administerMapper.updateById(administerDO);
//已关联院校信息
List<Long> oldIds = this.baseMapper.accountAcademyIds(addAcademyAccountDTO.getId());
//去旧加新
List<Long> newIds = addAcademyAccountDTO.getAcademyIds();
List<Long> newAcademyIds2 = new ArrayList<>();
for (Long lg : newIds) {
newAcademyIds2.add(lg);
}
newIds.removeAll(oldIds); //
if (newIds.size() > 0) {
for (Long lg : newIds) {
AdministerAcademyMappingDO administerAcademyMappingDO = new AdministerAcademyMappingDO();
administerAcademyMappingDO.setAdministerId(addAcademyAccountDTO.getId());
administerAcademyMappingDO.setAcademyId(lg);
administerAcademyMappingMapper.insert(administerAcademyMappingDO);
}
}
oldIds.removeAll(newAcademyIds2);
if (oldIds.size() > 0) {
for (Long lg : oldIds) {
administerAcademyMappingMapper.delete(new QueryWrapper<AdministerAcademyMappingDO>()
.lambda()
.eq(AdministerAcademyMappingDO::getAdministerId, addAcademyAccountDTO.getId())
.eq(AdministerAcademyMappingDO::getAcademyId, lg));
}
}
return ConstantUtils.SUCCESS_UPDATE;
}
}