|
|
@@ -1,32 +1,41 @@
|
|
1
|
1
|
package com.sundot.airport.system.service.impl;
|
|
2
|
2
|
|
|
3
|
|
-import java.util.ArrayList;
|
|
4
|
|
-import java.util.HashMap;
|
|
5
|
3
|
import java.util.List;
|
|
6
|
4
|
import java.util.Map;
|
|
|
5
|
+import java.util.stream.Collectors;
|
|
7
|
6
|
|
|
8
|
|
-import cn.hutool.core.util.ObjectUtil;
|
|
|
7
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
8
|
+import cn.hutool.core.util.ObjUtil;
|
|
|
9
|
+import com.sundot.airport.common.core.domain.entity.SysDictData;
|
|
9
|
10
|
import com.sundot.airport.common.exception.ServiceException;
|
|
10
|
11
|
import com.sundot.airport.common.utils.DateUtils;
|
|
11
|
|
-import org.apache.commons.lang3.ObjectUtils;
|
|
|
12
|
+import com.sundot.airport.system.domain.BasePerformanceIndicatorCategory;
|
|
|
13
|
+import com.sundot.airport.system.service.IBasePerformanceIndicatorCategoryService;
|
|
|
14
|
+import com.sundot.airport.system.service.ISysDictDataService;
|
|
|
15
|
+import com.sundot.airport.system.utils.CodeGeneratorUtil;
|
|
12
|
16
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
13
|
17
|
import org.springframework.stereotype.Service;
|
|
14
|
18
|
import com.sundot.airport.system.mapper.BasePerformanceIndicatorMapper;
|
|
15
|
19
|
import com.sundot.airport.system.domain.BasePerformanceIndicator;
|
|
16
|
20
|
import com.sundot.airport.system.service.IBasePerformanceIndicatorService;
|
|
17
|
21
|
import org.springframework.transaction.annotation.Transactional;
|
|
18
|
|
-import org.springframework.util.CollectionUtils;
|
|
19
|
22
|
|
|
20
|
23
|
/**
|
|
21
|
24
|
* 考核指标Service业务层处理
|
|
22
|
25
|
*
|
|
23
|
26
|
* @author ruoyi
|
|
24
|
|
- * @date 2026-04-20
|
|
|
27
|
+ * @date 2026-04-28
|
|
25
|
28
|
*/
|
|
26
|
29
|
@Service
|
|
27
|
30
|
public class BasePerformanceIndicatorServiceImpl implements IBasePerformanceIndicatorService {
|
|
28
|
31
|
@Autowired
|
|
29
|
32
|
private BasePerformanceIndicatorMapper basePerformanceIndicatorMapper;
|
|
|
33
|
+ @Autowired
|
|
|
34
|
+ private IBasePerformanceIndicatorCategoryService basePerformanceIndicatorCategoryService;
|
|
|
35
|
+ @Autowired
|
|
|
36
|
+ private ISysDictDataService sysDictDataService;
|
|
|
37
|
+ @Autowired
|
|
|
38
|
+ private CodeGeneratorUtil codeGeneratorUtil;
|
|
30
|
39
|
|
|
31
|
40
|
/**
|
|
32
|
41
|
* 查询考核指标
|
|
|
@@ -58,19 +67,19 @@ public class BasePerformanceIndicatorServiceImpl implements IBasePerformanceIndi
|
|
58
|
67
|
*/
|
|
59
|
68
|
@Override
|
|
60
|
69
|
public int insertBasePerformanceIndicator(BasePerformanceIndicator basePerformanceIndicator) {
|
|
61
|
|
- basePerformanceIndicator.setCreateTime(DateUtils.getNowDate());
|
|
62
|
|
- if (ObjectUtil.isEmpty(basePerformanceIndicator.getParentId()) || basePerformanceIndicator.getParentId().equals(0L)) {
|
|
63
|
|
- basePerformanceIndicator.setAncestors("0");
|
|
64
|
|
- basePerformanceIndicator.setLevel(1);
|
|
|
70
|
+ BasePerformanceIndicator query = new BasePerformanceIndicator();
|
|
|
71
|
+ query.setCategoryCode(basePerformanceIndicator.getCategoryCode());
|
|
|
72
|
+ query.setName(basePerformanceIndicator.getName());
|
|
|
73
|
+ List<BasePerformanceIndicator> existingList = basePerformanceIndicatorMapper.selectBasePerformanceIndicatorList(query);
|
|
|
74
|
+ if (CollUtil.isNotEmpty(existingList)) {
|
|
|
75
|
+ basePerformanceIndicator.setUpdateTime(DateUtils.getNowDate());
|
|
|
76
|
+ basePerformanceIndicator.setId(existingList.get(0).getId());
|
|
|
77
|
+ return basePerformanceIndicatorMapper.updateBasePerformanceIndicator(basePerformanceIndicator);
|
|
65
|
78
|
} else {
|
|
66
|
|
- BasePerformanceIndicator info = basePerformanceIndicatorMapper.selectBasePerformanceIndicatorById(basePerformanceIndicator.getParentId());
|
|
67
|
|
- if (ObjectUtil.isEmpty(info)) {
|
|
68
|
|
- throw new ServiceException("父分类不存在,不允许新增");
|
|
69
|
|
- }
|
|
70
|
|
- basePerformanceIndicator.setAncestors(info.getAncestors() + "," + basePerformanceIndicator.getParentId());
|
|
71
|
|
- basePerformanceIndicator.setLevel(basePerformanceIndicator.getAncestors().split(",").length);
|
|
|
79
|
+ basePerformanceIndicator.setCreateTime(DateUtils.getNowDate());
|
|
|
80
|
+ basePerformanceIndicator.setCode(codeGeneratorUtil.getNextCodeGenerator());
|
|
|
81
|
+ return basePerformanceIndicatorMapper.insertBasePerformanceIndicator(basePerformanceIndicator);
|
|
72
|
82
|
}
|
|
73
|
|
- return basePerformanceIndicatorMapper.insertBasePerformanceIndicator(basePerformanceIndicator);
|
|
74
|
83
|
}
|
|
75
|
84
|
|
|
76
|
85
|
/**
|
|
|
@@ -79,41 +88,13 @@ public class BasePerformanceIndicatorServiceImpl implements IBasePerformanceIndi
|
|
79
|
88
|
* @param basePerformanceIndicator 考核指标
|
|
80
|
89
|
* @return 结果
|
|
81
|
90
|
*/
|
|
82
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
83
|
91
|
@Override
|
|
84
|
92
|
public int updateBasePerformanceIndicator(BasePerformanceIndicator basePerformanceIndicator) {
|
|
85
|
93
|
basePerformanceIndicator.setUpdateTime(DateUtils.getNowDate());
|
|
86
|
|
- BasePerformanceIndicator newParent = basePerformanceIndicatorMapper.selectBasePerformanceIndicatorById(basePerformanceIndicator.getParentId());
|
|
87
|
|
- BasePerformanceIndicator old = basePerformanceIndicatorMapper.selectBasePerformanceIndicatorById(basePerformanceIndicator.getId());
|
|
88
|
|
- if (ObjectUtils.isNotEmpty(newParent) && ObjectUtils.isNotEmpty(old)) {
|
|
89
|
|
- String newAncestors = newParent.getAncestors() + "," + newParent.getId();
|
|
90
|
|
- String oldAncestors = old.getAncestors();
|
|
91
|
|
- basePerformanceIndicator.setAncestors(newAncestors);
|
|
92
|
|
- basePerformanceIndicator.setLevel(basePerformanceIndicator.getAncestors().split(",").length);
|
|
93
|
|
- updateChildren(basePerformanceIndicator.getId(), newAncestors, oldAncestors);
|
|
94
|
|
- }
|
|
95
|
94
|
return basePerformanceIndicatorMapper.updateBasePerformanceIndicator(basePerformanceIndicator);
|
|
96
|
95
|
}
|
|
97
|
96
|
|
|
98
|
97
|
/**
|
|
99
|
|
- * 修改子元素关系
|
|
100
|
|
- *
|
|
101
|
|
- * @param id 被修改的元素ID
|
|
102
|
|
- * @param newAncestors 新的父ID集合
|
|
103
|
|
- * @param oldAncestors 旧的父ID集合
|
|
104
|
|
- */
|
|
105
|
|
- private void updateChildren(Long id, String newAncestors, String oldAncestors) {
|
|
106
|
|
- List<BasePerformanceIndicator> children = basePerformanceIndicatorMapper.selectChildrenById(id);
|
|
107
|
|
- for (BasePerformanceIndicator child : children) {
|
|
108
|
|
- child.setAncestors(child.getAncestors().replaceFirst(oldAncestors, newAncestors));
|
|
109
|
|
- child.setLevel(child.getAncestors().split(",").length);
|
|
110
|
|
- }
|
|
111
|
|
- if (!CollectionUtils.isEmpty(children)) {
|
|
112
|
|
- basePerformanceIndicatorMapper.updateChildren(children);
|
|
113
|
|
- }
|
|
114
|
|
- }
|
|
115
|
|
-
|
|
116
|
|
- /**
|
|
117
|
98
|
* 批量删除考核指标
|
|
118
|
99
|
*
|
|
119
|
100
|
* @param ids 需要删除的考核指标主键
|
|
|
@@ -136,57 +117,99 @@ public class BasePerformanceIndicatorServiceImpl implements IBasePerformanceIndi
|
|
136
|
117
|
}
|
|
137
|
118
|
|
|
138
|
119
|
/**
|
|
139
|
|
- * 查询考核指标列表树形结构
|
|
|
120
|
+ * 导入考核指标列表
|
|
140
|
121
|
*
|
|
141
|
|
- * @param basePerformanceIndicator 考核指标
|
|
142
|
|
- * @return 考核指标集合
|
|
|
122
|
+ * @param list 数据列表
|
|
|
123
|
+ * @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据
|
|
|
124
|
+ * @return 结果
|
|
143
|
125
|
*/
|
|
|
126
|
+ @Transactional(rollbackFor = Exception.class)
|
|
144
|
127
|
@Override
|
|
145
|
|
- public List<BasePerformanceIndicator> selectBasePerformanceIndicatorListTree(BasePerformanceIndicator basePerformanceIndicator) {
|
|
146
|
|
- List<BasePerformanceIndicator> list = selectBasePerformanceIndicatorList(basePerformanceIndicator);
|
|
147
|
|
- return buildTree(list);
|
|
|
128
|
+ public String importData(List<BasePerformanceIndicator> list, boolean isUpdateSupport) {
|
|
|
129
|
+ if (CollUtil.isEmpty(list)) {
|
|
|
130
|
+ throw new ServiceException("导入速率数据不能为空!");
|
|
|
131
|
+ }
|
|
|
132
|
+
|
|
|
133
|
+ SysDictData leaveTypeQueryParam = new SysDictData();
|
|
|
134
|
+ leaveTypeQueryParam.setDictType("base_performance_indicator_leave_type");
|
|
|
135
|
+ List<SysDictData> leaveTypeList = sysDictDataService.selectDictDataList(leaveTypeQueryParam);
|
|
|
136
|
+ Map<String, String> leaveTypeMap = leaveTypeList.stream().collect(Collectors.toMap(SysDictData::getDictLabel, SysDictData::getDictValue));
|
|
|
137
|
+
|
|
|
138
|
+ BasePerformanceIndicatorCategory categoryQueryParam = new BasePerformanceIndicatorCategory();
|
|
|
139
|
+ categoryQueryParam.setLevel(2);
|
|
|
140
|
+ List<BasePerformanceIndicatorCategory> categoryList = basePerformanceIndicatorCategoryService.selectBasePerformanceIndicatorCategoryList(categoryQueryParam);
|
|
|
141
|
+ Map<String, String> categoryMap = categoryList.stream().collect(Collectors.toMap(BasePerformanceIndicatorCategory::getName, BasePerformanceIndicatorCategory::getCode, (oldValue, newValue) -> newValue));
|
|
|
142
|
+
|
|
|
143
|
+ int successNum = 0;
|
|
|
144
|
+ int failureNum = 0;
|
|
|
145
|
+ StringBuilder successMsg = new StringBuilder();
|
|
|
146
|
+ StringBuilder failureMsg = new StringBuilder();
|
|
|
147
|
+
|
|
|
148
|
+ for (BasePerformanceIndicator data : list) {
|
|
|
149
|
+ // 根据名称填充ID字段
|
|
|
150
|
+ fillIdsByName(data, categoryMap, leaveTypeMap);
|
|
|
151
|
+ try {
|
|
|
152
|
+ if (ObjUtil.isNull(data.getCategoryCode()) || ObjUtil.isNull(data.getCategoryName())) {
|
|
|
153
|
+ failureNum++;
|
|
|
154
|
+ failureMsg.append("<br/>" + failureNum + "、所属分类不能为空");
|
|
|
155
|
+ continue;
|
|
|
156
|
+ }
|
|
|
157
|
+
|
|
|
158
|
+ // 查询是否已存在(根据【日期+当班大队+班次】唯一)
|
|
|
159
|
+ BasePerformanceIndicator queryParam = new BasePerformanceIndicator();
|
|
|
160
|
+ queryParam.setCategoryCode(data.getCategoryCode());
|
|
|
161
|
+ queryParam.setName(data.getName());
|
|
|
162
|
+ List<BasePerformanceIndicator> existingList = basePerformanceIndicatorMapper.selectBasePerformanceIndicatorList(queryParam);
|
|
|
163
|
+
|
|
|
164
|
+ if (CollUtil.isEmpty(existingList)) {
|
|
|
165
|
+ // 新增
|
|
|
166
|
+ data.setCode(codeGeneratorUtil.getNextCodeGenerator());
|
|
|
167
|
+ data.setCreateTime(DateUtils.getNowDate());
|
|
|
168
|
+ basePerformanceIndicatorMapper.insertBasePerformanceIndicator(data);
|
|
|
169
|
+ successNum++;
|
|
|
170
|
+ successMsg.append("<br/>" + successNum + "、所属分类名称【" + data.getCategoryName() + "】、指标名称【" + data.getName() + "】导入成功");
|
|
|
171
|
+ } else if (isUpdateSupport) {
|
|
|
172
|
+ // 更新
|
|
|
173
|
+ BasePerformanceIndicator old = existingList.get(0);
|
|
|
174
|
+ data.setId(old.getId());
|
|
|
175
|
+ data.setUpdateTime(DateUtils.getNowDate());
|
|
|
176
|
+ basePerformanceIndicatorMapper.updateBasePerformanceIndicator(data);
|
|
|
177
|
+ successNum++;
|
|
|
178
|
+ successMsg.append("<br/>" + successNum + "、所属分类名称【" + data.getCategoryName() + "】、指标名称【" + data.getName() + "】更新成功");
|
|
|
179
|
+ } else {
|
|
|
180
|
+ failureNum++;
|
|
|
181
|
+ failureMsg.append("<br/>" + failureNum + "、所属分类名称【" + data.getCategoryName() + "】、指标名称【" + data.getName() + "】已存在");
|
|
|
182
|
+ }
|
|
|
183
|
+ } catch (Exception e) {
|
|
|
184
|
+ failureNum++;
|
|
|
185
|
+ String msg = "<br/>" + failureNum + "、所属分类名称【" + data.getCategoryName() + "】、指标名称【" + data.getName() + "】导入失败:";
|
|
|
186
|
+ failureMsg.append(msg + e.getMessage());
|
|
|
187
|
+ }
|
|
|
188
|
+ }
|
|
|
189
|
+
|
|
|
190
|
+ if (failureNum > 0) {
|
|
|
191
|
+ failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
|
|
|
192
|
+ throw new ServiceException(failureMsg.toString());
|
|
|
193
|
+ } else {
|
|
|
194
|
+ successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
|
|
|
195
|
+ }
|
|
|
196
|
+ return successMsg.toString();
|
|
148
|
197
|
}
|
|
149
|
198
|
|
|
150
|
199
|
/**
|
|
151
|
|
- * 构建前端所需要树结构
|
|
|
200
|
+ * 根据名称填充ID字段
|
|
152
|
201
|
*
|
|
153
|
|
- * @param list 列表
|
|
154
|
|
- * @return 树结构列表
|
|
|
202
|
+ * @param data 速率数据
|
|
155
|
203
|
*/
|
|
156
|
|
- @Override
|
|
157
|
|
- public List<BasePerformanceIndicator> buildTree(List<BasePerformanceIndicator> list) {
|
|
158
|
|
- // 结果列表
|
|
159
|
|
- List<BasePerformanceIndicator> result = new ArrayList<>();
|
|
160
|
|
-
|
|
161
|
|
- // 临时Map,用于快速查找节点
|
|
162
|
|
- Map<Long, BasePerformanceIndicator> nodeMap = new HashMap<>();
|
|
163
|
|
-
|
|
164
|
|
- // 第一次遍历:将所有节点存入Map
|
|
165
|
|
- for (BasePerformanceIndicator node : list) {
|
|
166
|
|
- nodeMap.put(node.getId(), node);
|
|
|
204
|
+ private void fillIdsByName(BasePerformanceIndicator data, Map<String, String> categoryMap, Map<String, String> leaveTypeMap) {
|
|
|
205
|
+ // 分类编码
|
|
|
206
|
+ if (ObjUtil.isNotNull(data.getCategoryName())) {
|
|
|
207
|
+ data.setCategoryCode(categoryMap.get(data.getCategoryName()));
|
|
167
|
208
|
}
|
|
168
|
209
|
|
|
169
|
|
- // 第二次遍历:建立父子关系
|
|
170
|
|
- for (BasePerformanceIndicator node : list) {
|
|
171
|
|
- Long parentId = node.getParentId();
|
|
172
|
|
- if (parentId == null || parentId == 0L) {
|
|
173
|
|
- // 父ID为null或0,说明是根节点
|
|
174
|
|
- result.add(node);
|
|
175
|
|
- } else {
|
|
176
|
|
- // 查找父节点
|
|
177
|
|
- BasePerformanceIndicator parent = nodeMap.get(parentId);
|
|
178
|
|
- if (parent != null) {
|
|
179
|
|
- // 初始化子节点列表
|
|
180
|
|
- if (parent.getChildren() == null) {
|
|
181
|
|
- parent.setChildren(new ArrayList<>());
|
|
182
|
|
- }
|
|
183
|
|
- // 将当前节点添加到父节点的子列表中
|
|
184
|
|
- List<BasePerformanceIndicator> children = (List<BasePerformanceIndicator>) parent.getChildren();
|
|
185
|
|
- children.add(node);
|
|
186
|
|
- }
|
|
187
|
|
- }
|
|
|
210
|
+ // 事/病假
|
|
|
211
|
+ if (ObjUtil.isNotNull(data.getLeaveTypeDesc())) {
|
|
|
212
|
+ data.setLeaveType(leaveTypeMap.get(data.getLeaveTypeDesc()));
|
|
188
|
213
|
}
|
|
189
|
|
-
|
|
190
|
|
- return result;
|
|
191
|
214
|
}
|
|
192
|
215
|
}
|