AdministerServiceImpl.java
12.9 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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
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.administer.AddAdministerDTO;
import com.subsidy.dto.company.OperatorsDTO;
import com.subsidy.mapper.AdministerCompanyMappingMapper;
import com.subsidy.mapper.ServiceAdministerMappingMapper;
import com.subsidy.model.AdministerCompanyMappingDO;
import com.subsidy.model.AdministerDO;
import com.subsidy.mapper.AdministerMapper;
import com.subsidy.model.ServiceAdministerMappingDO;
import com.subsidy.service.AdministerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.util.ConstantUtils;
import com.subsidy.util.JwtUtil;
import com.subsidy.util.Localstorage;
import com.subsidy.vo.administer.AdministerPermissionVO;
import com.subsidy.vo.administer.AdministerVO;
import com.subsidy.vo.administer.LoginVO;
import com.subsidy.vo.administer.PermissionsVO;
import com.subsidy.vo.company.GetAllCompanyVO;
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.ArrayList;
import java.util.List;
/**
* <p>
* 管理平台用户 服务实现类
* </p>
*
* @author Tuyp
* @since 2024-01-11
*/
@Service
public class AdministerServiceImpl extends ServiceImpl<AdministerMapper, AdministerDO> implements AdministerService {
@Autowired
private ServiceAdministerMappingMapper serviceAdministerMappingMapper;
@Autowired
private AdministerCompanyMappingMapper administerCompanyMappingMapper;
public LoginVO centerLogin(AdministerDO administerDO) {
LoginVO loginVO = new LoginVO();
AdministerDO administerDO1 = this.baseMapper.selectOne(new QueryWrapper<AdministerDO>()
.lambda()
.eq(AdministerDO::getAccountName, administerDO.getAccountName())
.eq(AdministerDO::getRole, 2));
if (null == administerDO1) {
throw new HttpException(10012);
}
if ("0".equals(administerDO1.getStatus())) {
throw new HttpException(10013);
}
if (administerDO1.getPassword().equals(administerDO.getPassword())) {
String token = JwtUtil.generateToken(administerDO1.getId(), ConstantUtils.ADMINISTER_TERMINATE);
loginVO.setToken(token);
return loginVO;
} else {
throw new HttpException(10029);
}
}
public AdministerPermissionVO getPermissions() {
AdministerPermissionVO administerPermissionVO = new AdministerPermissionVO();
AdministerDO administerDO = (AdministerDO) Localstorage.getUser();
if (administerDO == null) {
throw new HttpException(10012);
}
BeanUtils.copyProperties(administerDO, administerPermissionVO);
List<PermissionsVO> list = this.baseMapper.getPermissions(administerDO.getId());
List<PermissionsVO> treeList = new ArrayList();
if (list != null) {
list.forEach(permission -> {
if (permission.getParentId() == null) {
treeList.add(permission);
}
list.forEach(p -> {
if (null != p.getParentId() && p.getParentId().equals(permission.getId())) {
if (permission.getChildren() == null) {
permission.setChildren(new ArrayList<>());
}
permission.getChildren().add(p);
}
});
});
}
administerPermissionVO.setPermissions(treeList);
// //查询角色
// RoleAdministerMappingDO roleAdministerMappingDO = roleAdministerMappingMapper.selectOne(new QueryWrapper<RoleAdministerMappingDO>()
// .lambda()
// .eq(RoleAdministerMappingDO::getAdministerId, administerDO.getId()));
// administerPermissionVO.setRole(roleAdministerMappingDO.getRoleId());
// CompanyDictDO companyDictDO = companyDictMapper.selectById(administerDO.getCompanyId());
// administerPermissionVO.setCompanyName(companyDictDO.getCompanyName());
// administerPermissionVO.setShortName(companyDictDO.getShortName());
/**
* 所在公司
*/
List<GetAllCompanyVO> getAllCompanyVOS = this.baseMapper.administerCompanys(administerDO.getId());
administerPermissionVO.setGetAllCompanyVOS(getAllCompanyVOS);
return administerPermissionVO;
}
public IPage<AdministerVO> operators(OperatorsDTO operatorsDTO) {
Page pager = new Page(operatorsDTO.getPageNum(), operatorsDTO.getPageSize());
IPage<AdministerVO> administerVOIPage = this.baseMapper.operators(pager, operatorsDTO.getUserName(), operatorsDTO.getCompanyName());
List<AdministerVO> administerVOS = administerVOIPage.getRecords();
for (AdministerVO administerVO : administerVOS) {
if (0 == administerVO.getRole()) {
//所有服务
administerVO.setServiceDictDOS(serviceAdministerMappingMapper.administerService(administerVO.getId()));
}
}
return administerVOIPage;
}
public IPage<AdministerVO> appOperators(OperatorsDTO operatorsDTO) {
Page pager = new Page(operatorsDTO.getPageNum(), operatorsDTO.getPageSize());
IPage<AdministerVO> administerVOIPage = this.baseMapper.appOperators(pager, operatorsDTO.getUserName(), operatorsDTO.getCompanyName());
List<AdministerVO> administerVOS = administerVOIPage.getRecords();
for (AdministerVO administerVO : administerVOS) {
if (0 == administerVO.getRole()) {
//所有服务
administerVO.setServiceDictDOS(serviceAdministerMappingMapper.administerService(administerVO.getId()));
}
}
return administerVOIPage;
}
public IPage<AdministerVO> clientOperators(OperatorsDTO operatorsDTO) {
Page pager = new Page(operatorsDTO.getPageNum(), operatorsDTO.getPageSize());
IPage<AdministerVO> administerVOIPage = this.baseMapper.clientOperators(pager, operatorsDTO.getUserName(), operatorsDTO.getCompanyName());
List<AdministerVO> administerVOS = administerVOIPage.getRecords();
for (AdministerVO administerVO : administerVOS) {
administerVO.setGetAllCompanyVOS(this.baseMapper.administerCompanys(administerVO.getId()));
if (0 == administerVO.getRole()) {
//所有服务
administerVO.setServiceDictDOS(serviceAdministerMappingMapper.administerService(administerVO.getId()));
}
}
return administerVOIPage;
}
public String addAdminister(AddAdministerDTO addAdministerDTO) {
int count = this.baseMapper.selectCount(new QueryWrapper<AdministerDO>()
.lambda()
.eq(AdministerDO::getAccountName, addAdministerDTO.getAccountName()));
int count1 = this.baseMapper.selectCount(new QueryWrapper<AdministerDO>()
.lambda()
.eq(AdministerDO::getTelephone, addAdministerDTO.getTelephone()));
if (count + count1 > 0) {
throw new HttpException(20002);
}
AdministerDO administerDO = new AdministerDO();
BeanUtils.copyProperties(addAdministerDTO, administerDO);
this.baseMapper.insert(administerDO);
if (null != addAdministerDTO.getCompanyIds()) {
List<Long> companyIds = addAdministerDTO.getCompanyIds();
for (Long companyId : companyIds) {
AdministerCompanyMappingDO administerCompanyMappingDO = new AdministerCompanyMappingDO();
administerCompanyMappingDO.setAdministerId(administerDO.getId());
administerCompanyMappingDO.setCompanyId(companyId);
administerCompanyMappingMapper.insert(administerCompanyMappingDO);
}
}
if (null != addAdministerDTO.getServiceIds()) {
List<Long> serviceIds = addAdministerDTO.getServiceIds();
for (Long service : serviceIds) {
ServiceAdministerMappingDO serviceAdministerMappingDO = new ServiceAdministerMappingDO();
serviceAdministerMappingDO.setAdministerId(administerDO.getId());
serviceAdministerMappingDO.setServiceId(service);
serviceAdministerMappingMapper.insert(serviceAdministerMappingDO);
}
}
return ConstantUtils.ADD_SUCCESS;
}
@Transactional(rollbackFor = Exception.class)
public String deleteAdminister(AdministerDO administerDO) {
this.baseMapper.deleteById(administerDO.getId());
administerCompanyMappingMapper.delete(new QueryWrapper<AdministerCompanyMappingDO>()
.lambda()
.eq(AdministerCompanyMappingDO::getAdministerId, administerDO.getId()));
serviceAdministerMappingMapper.delete(new QueryWrapper<ServiceAdministerMappingDO>()
.lambda()
.eq(ServiceAdministerMappingDO::getAdministerId, administerDO.getId()));
return ConstantUtils.DELETE_SUCCESS;
}
public String updateAdminister(AddAdministerDTO addAdministerDTO) {
int count = this.baseMapper.selectCount(new QueryWrapper<AdministerDO>()
.lambda()
.eq(AdministerDO::getAccountName, addAdministerDTO.getAccountName())
.ne(AdministerDO::getId, addAdministerDTO.getId()));
int count1 = this.baseMapper.selectCount(new QueryWrapper<AdministerDO>()
.lambda()
.eq(AdministerDO::getTelephone, addAdministerDTO.getTelephone())
.ne(AdministerDO::getId, addAdministerDTO.getId()));
if (count + count1 > 0) {
throw new HttpException(20002);
}
AdministerDO administerDO = this.baseMapper.selectById(addAdministerDTO.getId());
BeanUtils.copyProperties(addAdministerDTO, administerDO);
this.baseMapper.updateById(administerDO);
if (null != addAdministerDTO.getCompanyIds()) {
//
List<Long> oldIds = this.baseMapper.administerCompanyIds(addAdministerDTO.getId());
List<Long> newIds = addAdministerDTO.getCompanyIds();
List<Long> newCompanyIds2 = new ArrayList<>();
for (Long lg : newIds) {
newCompanyIds2.add(lg);
}
newIds.removeAll(oldIds); //
if (newIds.size() > 0) {
for (Long lg : newIds) {
AdministerCompanyMappingDO administerCompanyMappingDO = new AdministerCompanyMappingDO();
administerCompanyMappingDO.setAdministerId(addAdministerDTO.getId());
administerCompanyMappingDO.setCompanyId(lg);
administerCompanyMappingMapper.insert(administerCompanyMappingDO);
}
}
oldIds.removeAll(newCompanyIds2);
if (oldIds.size() > 0) {
for (Long lg : oldIds) {
administerCompanyMappingMapper.delete(new QueryWrapper<AdministerCompanyMappingDO>()
.lambda()
.eq(AdministerCompanyMappingDO::getAdministerId, addAdministerDTO.getId())
.eq(AdministerCompanyMappingDO::getCompanyId, lg));
}
}
}
if (null != addAdministerDTO.getServiceIds()) {
//
List<Long> oldIds = this.baseMapper.administerServiceIds(addAdministerDTO.getId());
List<Long> newIds = addAdministerDTO.getServiceIds();
List<Long> newServices2 = new ArrayList<>();
for (Long lg : newIds) {
newServices2.add(lg);
}
newIds.removeAll(oldIds); //
if (newIds.size() > 0) {
for (Long lg : newIds) {
ServiceAdministerMappingDO serviceAdministerMappingDO = new ServiceAdministerMappingDO();
serviceAdministerMappingDO.setAdministerId(addAdministerDTO.getId());
serviceAdministerMappingDO.setServiceId(lg);
serviceAdministerMappingMapper.insert(serviceAdministerMappingDO);
}
}
oldIds.removeAll(newServices2);
if (oldIds.size() > 0) {
for (Long lg : oldIds) {
serviceAdministerMappingMapper.delete(new QueryWrapper<ServiceAdministerMappingDO>()
.lambda()
.eq(ServiceAdministerMappingDO::getAdministerId, addAdministerDTO.getId())
.eq(ServiceAdministerMappingDO::getServiceId, lg));
}
}
}
return ConstantUtils.SET_SUCCESS;
}
}