DepInfoServiceImpl.java
5.39 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
package com.chinagas.modules.system.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chinagas.api.system.domain.DepInfo;
import com.chinagas.api.system.domain.SysDept;
import com.chinagas.common.core.constants.UserConstants;
import com.chinagas.common.core.utils.StringUtils;
import com.chinagas.modules.system.mapper.DepInfoMapper;
import com.chinagas.modules.system.service.IDepInfoService;
import com.chinagas.modules.system.service.ISysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
* <p>
* 组织机构表 服务实现类
* </p>
*
* @author lidwd
* @since 2022-10-14
*/
@Service
public class DepInfoServiceImpl extends ServiceImpl<DepInfoMapper, DepInfo> implements IDepInfoService {
@Autowired
private DepInfoMapper depInfoMapper;
@Autowired
private ISysDeptService deptService;
// @Transactional(rollbackFor = Exception.class)
// @Override
// public int insertDepInfo(DepInfo depInfo) {
// QueryWrapper<DepInfo> queryWrapper = new QueryWrapper<>();
// queryWrapper.eq("dept_id",depInfo.getDeptId());
// DepInfo depInfo_old = depInfoMapper.selectOne(queryWrapper);
// if(StringUtils.isNotNull(depInfo_old)){
// queryWrapper.clear();
// queryWrapper.eq("dept_id",depInfo_old.getDeptId());
// depInfo.setLstupdtDate(new Date());
// copyToSysDept(depInfo,BusinessType.UPDATE);
// return depInfoMapper.update(depInfo,queryWrapper);
// }
// copyToSysDept(depInfo,BusinessType.INSERT);
// return depInfoMapper.insertDepInfo(depInfo);
// }
@Override
// @Transactional(rollbackFor = Exception.class)
public int insertDepInfoBach(List<DepInfo> depList){
int rows = 0;
SysDept sysDept = null;
List<SysDept> deptList = new ArrayList<>();
for(DepInfo depInfo:depList){
sysDept = new SysDept();
sysDept.setDeptId(Long.parseLong(depInfo.getDeptId()));
if(StringUtils.isNotNull(depInfo.getDepName())){
sysDept.setDeptName(depInfo.getDepName());
}else {
sysDept.setDeptName("");
}
if(StringUtils.isNotEmpty(depInfo.getCgDeptParent())){
sysDept.setParentId(Long.parseLong(depInfo.getCgDeptParent()));
}
sysDept.setAncestors(getAncestors(depInfo.getDeptId(), depList));
sysDept.setDeptPath(depInfo.getCgDeptPath());
sysDept.setCreateBy("定时任务同步");
if(StringUtils.equals(depInfo.getDeptId(),"100000")){
sysDept.setParentId(0L);
}
if("A".equals(depInfo.getEffStatus())){
sysDept.setStatus(UserConstants.DEPT_NORMAL);
}else{
sysDept.setStatus(UserConstants.DEPT_DISABLE);
}
if(StringUtils.isNotEmpty(depInfo.getCgDeptSort())){
sysDept.setOrderNum(Integer.parseInt(depInfo.getCgDeptSort()));
}
sysDept.setIsCompany(depInfo.getCgIsCompany());
rows += deptService.insertOrUpdateDept(sysDept);
// deptList.add(sysDept);
// if (deptList.size()%100==0){
// rows += deptService.insertOrUpdateDeptBatch(deptList);
// deptList.clear();
// }
}
// rows += deptService.insertOrUpdateDeptBatch(deptList);
return rows;
}
/**
* 根据机构ID,获取该部门所有上级机构
* @param deptId
* @param depList
* @return
*/
public String getAncestors(String deptId, List<DepInfo> depList){
if (StringUtils.isEmpty(deptId)) {//异常数据
return "";
}
if (StringUtils.equals(deptId,"100000")) {
return "100000";
}else {
String ancestors = deptId;
for(DepInfo depInfo:depList){
if(StringUtils.equals(depInfo.getDeptId(), deptId)) {
ancestors = getAncestors(depInfo.getCgDeptParent(), depList) + "," + ancestors;
}
}
return ancestors;
}
}
// private int copyToSysDept(DepInfo depInfo, BusinessType opreation){
// int rows = 0;
// SysDept sysDept = new SysDept();
// sysDept.setDeptId(Long.parseLong(depInfo.getDeptId()));
// if(StringUtils.isNotNull(depInfo.getDepName())){
// sysDept.setDeptName(depInfo.getDepName());
// }else {
// sysDept.setDeptName("");
// }
// sysDept.setParentId(Long.parseLong(depInfo.getCgDeptParent()));
// sysDept.setDeptPath(depInfo.getCgDeptPath());
// sysDept.setCreateBy("定时任务同步");
// if("A".equals(depInfo.getEffStatus())){
// sysDept.setStatus(UserConstants.DEPT_NORMAL);
// }else{
// sysDept.setStatus(UserConstants.DEPT_DISABLE);
// }
// if(StringUtils.isNotEmpty(depInfo.getCgDeptSort())){
// sysDept.setOrderNum(Integer.parseInt(depInfo.getCgDeptSort()));
// }
// if(BusinessType.INSERT.equals(opreation)){
// rows += deptService.insertDept(sysDept);
// }
// if (BusinessType.UPDATE.equals(opreation)){
// rows += deptService.updateDept(sysDept);
// }
// return rows;
// }
}