FrontDeptServiceImpl.java
16.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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
package com.lhcredit.project.business.frontDept.service;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
import com.lhcredit.common.constant.UserConstants;
import com.lhcredit.common.utils.StringUtils;
import com.lhcredit.common.utils.security.ShiroUtils;
import com.lhcredit.framework.web.domain.Ztree;
import com.lhcredit.project.business.contractReportBusinessType.service.IContractReportBusinessTypeService;
import com.lhcredit.project.business.orgDept.domain.OrgDept;
import com.lhcredit.project.business.orgDept.mapper.OrgDeptMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.lhcredit.project.business.frontDept.mapper.FrontDeptMapper;
import com.lhcredit.project.business.frontDept.domain.FrontDept;
import com.lhcredit.common.utils.text.Convert;
/**
* 公司部门 服务层实现
*
* @author lhcredit
* @date 2024-05-08
*/
@Service
public class FrontDeptServiceImpl implements IFrontDeptService {
@Autowired
private FrontDeptMapper frontDeptMapper;
@Autowired
private OrgDeptMapper orgDeptMapper;
@Autowired
private IContractReportBusinessTypeService contractReportBusinessTypeService;
@Override
public List<FrontDept> likeByName(String name){
List<FrontDept> frontDept = frontDeptMapper.likeByName(name);
return frontDept;
}
@Override
public String getAllDeptNameForAdmin(Long id){
//查出当前
FrontDept frontDept = frontDeptMapper.selectFrontDeptByOrgId(id);
List<String> list=new ArrayList<>();
list.add(frontDept.getDeptName());
for (int i = 0; i <10 ; i++) {
//为0时,跳出循环
if (frontDept.getParentId()==0)break;
frontDept = frontDeptMapper.selectFrontDeptById(frontDept.getParentId());
list.add(frontDept.getDeptName());
}
return list.stream().sorted(Comparator.reverseOrder()).collect(Collectors.joining("-"));
}
@Override
public String getParentDeptName(Long id) {
//查出当前
FrontDept frontDept = frontDeptMapper.selectFrontDeptByOrgId(id);
List<String> list=new LinkedList<>();
list.add(frontDept.getDeptName());
for (int i = 0; i <4 ; i++) {
//为0时,跳出循环
if (frontDept.getParentId()==0)break;
frontDept = frontDeptMapper.selectFrontDeptById(frontDept.getParentId());
list.add(frontDept.getDeptName());
}
return list.stream().sorted(Comparator.reverseOrder()).collect(Collectors.joining("--"));
}
@Override
public FrontDept getParentDept(Long id) {
//查出当前
FrontDept frontDept = frontDeptMapper.selectFrontDeptByOrgId(id);
if (null==frontDept){
return frontDept;
}
for (int i = 0; i <4 ; i++) {
//为0时,跳出循环
if (frontDept.getParentId()==0)break;
frontDept = frontDeptMapper.selectFrontDeptById(frontDept.getParentId());
}
return frontDept;
}
/**
* 查询公司部门信息
*
* @param id 公司部门ID
* @return 公司部门信息
*/
@Override
public FrontDept selectFrontDeptById(Long id) {
return frontDeptMapper.selectFrontDeptById(id);
}
/**
* 查询公司部门列表
*
* @param frontDept 公司部门信息
* @return 公司部门集合
*/
@Override
public List<FrontDept> selectFrontDeptList(FrontDept frontDept) {
List<FrontDept> frontDepts = frontDeptMapper.selectFrontDeptList(frontDept);
if (frontDept.getDeptName() != null && !frontDept.getDeptName().isEmpty()) {
// 创建一个临时列表存储需要添加的元素
List<FrontDept> toAdd = new ArrayList<>();
frontDepts.forEach(fron -> {
if (null != fron.getParentId() && fron.getParentId() == 0) {
List<FrontDept> frontDeptList = frontDeptMapper.getparentId(fron.getId());
toAdd.addAll(frontDeptList);
List<FrontDept> toAdd1 = new ArrayList<>();
if (frontDeptList.size() > 0) {
frontDeptList.forEach(front -> {
// 修复:使用 front.getId() 而不是 fron.getId()
List<FrontDept> frontDepts1 = frontDeptMapper.getparentId(front.getId());
toAdd1.addAll(frontDepts1);
});
}
toAdd.addAll(toAdd1);
}
});
// 遍历结束后再统一添加
frontDepts.addAll(toAdd);
}
return frontDepts;
}
/**
* 字段转换
* @param frontDept 公司部门信息
* @return 公司部门信息
*/
@Override
public FrontDept changeModel(FrontDept frontDept) {
// //这里写各字段转换逻辑
// if(frontDept!=null){
// if(StringUtils.isNotEmpty(frontDept.getXXX())){
// frontDept.setXXX(frontDept.getXXX());
// }
// }
return frontDept;
}
/**
* 列表转换
*
* @param frontDeptList 公司部门集合
* @return 公司部门集合
*/
@Override
public List<FrontDept> changeModel(List<FrontDept> frontDeptList) {
List<FrontDept> result = new ArrayList<FrontDept>();
if (frontDeptList.size() > 0) {
for (FrontDept frontDept:frontDeptList){
result.add(changeModel(frontDept));
}
}
return result;
}
/**
* 新增公司部门
*
* @param frontDept 公司部门信息
* @return 结果
*/
@Override
public int insertFrontDept(FrontDept frontDept) {
return frontDeptMapper.insertFrontDept(frontDept);
}
/**
* 修改公司部门
*
* @param frontDept 公司部门信息
* @return 结果
*/
@Override
public int updateFrontDept(FrontDept frontDept) {
return frontDeptMapper.updateFrontDept(frontDept);
}
/**
* g根据 父id 更新对应对公司全部部门的 biz_types(有效报告类型)
*
* @param frontDept
* @return
*/
@Override
public int updateFrontDeptByAncestors(FrontDept frontDept) {
return frontDeptMapper.updateFrontDeptByAncestors(frontDept);
}
/**
* 根据 id 批量查询部门信息
*
* @param ids
* @return
*/
@Override
public List<FrontDept> getDeptListByIds(List<Long> ids) {
return frontDeptMapper.getDeptListByIds(ids);
}
/**
* 根据用户的orgid 查询对应的 org公司的父公司
*
* @param orgId
* @return
*/
@Override
public FrontDept getParentOrgInfoByOrgId(Long orgId) {
return frontDeptMapper.getParentOrgInfoByOrgId(orgId);
}
@Override
public FrontDept getFrontDeptByName(String orgName) {
return frontDeptMapper.getFrontDeptByName(orgName);
}
/**
* 删除部门管理信息
*
* @param id 部门ID
* @return 结果
*/
@Override
public int deleteFrontDeptById(Long id) {
return frontDeptMapper.deleteFrontDeptById(id);
}
/**
* 删除公司部门对象
*
* @param ids 需要删除的数据ID
* @return 结果
*/
@Override
public int deleteFrontDeptByIds(String ids) {
return frontDeptMapper.deleteFrontDeptByIds(Convert.toStrArray(ids));
}
@Override
public void addSave(String headOffice, String deptName, String branchOffices,String monitorBegin,String monitorEnd) throws Exception{
//总公司入库
FrontDept frontDept=new FrontDept();
frontDept.setParentId(0L);
frontDept.setAncestors("0");
frontDept.setDeptName(deptName);
frontDept.setDeptType("0");
frontDept.setIsEnable("1");
frontDept.setSigningMethod("0");
frontDept.setCreateTime(new Date());
frontDept.setCreateBy(ShiroUtils.getLoginName());
frontDept.setUpdateTime(new Date());
frontDept.setMonitorBegin(monitorBegin);
frontDept.setMonitorEnd(monitorEnd);
frontDeptMapper.insertFrontDept(frontDept);
Long cid=frontDept.getId();//总公司id
//总公司插入中间表
OrgDept zorg=new OrgDept();
zorg.setOrgId(Long.parseLong(cid+""));
zorg.setDeptId(Long.parseLong(cid+""));
orgDeptMapper.insertOrgDept(zorg);
//分公司
if(StringUtils.isNotBlank(headOffice)) {
String[] bos = branchOffices.split(",");
if (bos.length > 0) {
for (int i = 0; i < bos.length; i++) {
FrontDept front = new FrontDept();
front.setParentId(cid);
front.setAncestors(cid + "");
front.setDeptName(bos[i]);
front.setDeptType("1");
front.setIsEnable("1");
front.setSigningMethod("0");
front.setCreateTime(new Date());
front.setCreateBy(ShiroUtils.getLoginName());
front.setUpdateTime(new Date());
frontDeptMapper.insertFrontDept(front);
//插入中间表
OrgDept orgDept = new OrgDept();
orgDept.setOrgId(Long.parseLong(cid + ""));
orgDept.setDeptId(Long.parseLong(front.getId() + ""));//分公司id
orgDeptMapper.insertOrgDept(orgDept);
//自己插入数据库
OrgDept od = new OrgDept();
od.setOrgId(front.getId());
od.setDeptId(Long.parseLong(front.getId() + ""));
orgDeptMapper.insertOrgDept(od);
}
}
}
// //部门
// JSONArray arrayDept=obj.getJSONArray("dept");
// if(arrayDept.size()>0){
// for(int j=0;j<arrayDept.size();j++){
// JSONObject o=JSONObject.parseObject(arrayDept.getString(j).toString());
// //查询分公司id,根据名称
// FrontDept fd=frontDeptMapper.selectFrontDeptByName(o.get("clientName").toString());
// FrontDept front=new FrontDept();
// front.setParentId(Integer.parseInt(fd.getId().toString()));
// front.setAncestors(cid+","+fd.getId());
// front.setDeptName(o.get("deptName").toString());
// front.setDeptType("2");
// front.setIsEnable("1");
// front.setContractType(contract_type);
// front.setSigningMethod("0");
// front.setContractNum(map.get("contractId").toString());
// front.setCreateTime(new Date());
// front.setCreateBy(ShiroUtils.getLoginName());
// front.setUpdateTime(new Date());
// frontDeptMapper.insertFrontDept(front);
//
// //分公司部门插入中间表
// OrgDept orgDept=new OrgDept();
// orgDept.setOrgId(fd.getId());
// orgDept.setDeptId(Long.parseLong(front.getId()+""));
// orgDeptMapper.insertOrgDept(orgDept);
//
// //总公司部门插入中间表
// OrgDept orgCom=new OrgDept();
// orgCom.setOrgId(Long.parseLong(cid+""));
// orgCom.setDeptId(Long.parseLong(front.getId()+""));
// orgDeptMapper.insertOrgDept(orgCom);
//
// //自己插入数据库
// OrgDept od=new OrgDept();
// od.setOrgId(fd.getId());
// od.setDeptId(Long.parseLong(fd.getId()+""));
// orgDeptMapper.insertOrgDept(od);
// }
// }
}
@Override
public void addDept(Long parentId,String deptName,int sort) {
//根据父id查询部门
FrontDept fd=frontDeptMapper.selectFrontDeptByOrgId(parentId);
FrontDept front=new FrontDept();
front.setParentId(fd.getId());
front.setAncestors(fd.getParentId()+","+fd.getId());
front.setDeptName(deptName);
front.setDeptType("2");
front.setIsEnable("1");
front.setContractType(fd.getContractType());
front.setSigningMethod("0");
front.setContractNum(fd.getContractNum());
front.setCreateTime(new Date());
front.setCreateBy(ShiroUtils.getLoginName());
front.setUpdateTime(new Date());
front.setSort(sort);
front.setBizTypes(fd.getBizTypes());
frontDeptMapper.insertFrontDept(front);
//分公司部门插入中间表
OrgDept orgDept=new OrgDept();
orgDept.setOrgId(fd.getId());
orgDept.setDeptId(Long.parseLong(front.getId()+""));
orgDeptMapper.insertOrgDept(orgDept);
//总公司部门插入中间表
OrgDept orgCom=new OrgDept();
orgCom.setOrgId(Long.parseLong(fd.getParentId()+""));
orgCom.setDeptId(Long.parseLong(front.getId()+""));
orgDeptMapper.insertOrgDept(orgCom);
//自己插入数据库
OrgDept od=new OrgDept();
od.setOrgId(front.getId());
od.setDeptId(Long.parseLong(front.getId()+""));
orgDeptMapper.insertOrgDept(od);
}
@Override
public void addCompay(FrontDept fd,Long parentId, String deptName, int sort) {
FrontDept front=new FrontDept();
front.setParentId(parentId);
front.setAncestors(parentId+"");
front.setDeptName(deptName);
front.setDeptType("1");
front.setIsEnable("1");
front.setContractType(fd.getContractType());
front.setSigningMethod("0");
front.setContractNum(fd.getContractNum());
front.setCreateTime(new Date());
front.setCreateBy(ShiroUtils.getLoginName());
front.setUpdateTime(new Date());
front.setBizTypes(fd.getBizTypes());
front.setSort(sort);
frontDeptMapper.insertFrontDept(front);
//插入中间表
OrgDept orgDept=new OrgDept();
orgDept.setOrgId(Long.parseLong(parentId+""));
orgDept.setDeptId(Long.parseLong(front.getId()+""));//分公司id
orgDeptMapper.insertOrgDept(orgDept);
//自己关联自己
OrgDept od=new OrgDept();
od.setOrgId(Long.parseLong(front.getId()+""));
od.setDeptId(Long.parseLong(front.getId()+""));//分公司id
orgDeptMapper.insertOrgDept(od);
}
@Override
public List<Ztree> selectDeptTree(FrontDept frontDept) {
List<FrontDept> deptList = frontDeptMapper.selectFrontDeptList(frontDept);
List<Ztree> ztrees = initZtree(deptList);
return ztrees;
}
@Override
public List<FrontDept> findDeptTypeAll(String orgId) {
return frontDeptMapper.findDeptTypeAll(orgId);
}
/**
* 对象转部门树
*
* @param deptList 部门列表
* @return 树结构列表
*/
public List<Ztree> initZtree(List<FrontDept> deptList) {
return initZtree(deptList, null);
}
/**
* 对象转部门树
*
* @param deptList 部门列表
* @param roleDeptList 角色已存在菜单列表
* @return 树结构列表
*/
public List<Ztree> initZtree(List<FrontDept> deptList, List<String> roleDeptList) {
List<Ztree> ztrees = new ArrayList<Ztree>();
boolean isCheck = StringUtils.isNotNull(roleDeptList);
for (FrontDept dept : deptList) {
if (dept.getIsEnable().equals("1")) {//启用
Ztree ztree = new Ztree();
ztree.setId(dept.getId());
ztree.setpId(Long.parseLong(dept.getParentId()+""));
ztree.setName(dept.getDeptName());
ztree.setTitle(dept.getDeptName());
if (isCheck) {
ztree.setChecked(roleDeptList.contains(dept.getId() + dept.getDeptName()));
}
ztrees.add(ztree);
}
}
return ztrees;
}
/**
* 校验部门名称是否唯一
*
* @param frontDept 部门信息
* @return 结果
*/
@Override
public String checkDeptNameUnique(FrontDept frontDept) {
Long deptId = StringUtils.isNull(frontDept.getId()) ? -1L : frontDept.getId();
FrontDept info = frontDeptMapper.checkDeptNameUnique(frontDept.getDeptName(), frontDept.getParentId());
if (StringUtils.isNotNull(info) && info.getId().longValue() != deptId.longValue()) {
return UserConstants.DEPT_NAME_NOT_UNIQUE;
}
return UserConstants.DEPT_NAME_UNIQUE;
}
@Override
public List<Ztree> selectDeptTreeByOrgId(Long orgId) {
List<FrontDept> deptList=frontDeptMapper.selectDeptTreeByOrgId(orgId);
return initZtree(deptList, null);
}
/**
* 根据id 查询FrontDept
*
* @param id
* @return
*/
@Override
public FrontDept getFrontDeptById(Long id) {
return frontDeptMapper.getFrontDeptById(id);
}
}