|
@@ -22,6 +22,7 @@ import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.convert.Convert;
|
|
|
import cn.hutool.core.date.DatePattern;
|
|
|
import cn.hutool.core.lang.Validator;
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
@@ -90,6 +91,7 @@ import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
import java.util.concurrent.Future;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@@ -2663,6 +2665,7 @@ public class WmScorePackageController {
|
|
|
|
|
|
return R.ok();
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 批量导入积分包
|
|
|
*
|
|
@@ -2676,111 +2679,121 @@ public class WmScorePackageController {
|
|
|
public R<?> batchCreatePackage(@RequestExcel(fileName = "excel", ignoreEmptyRow = true) List<BatchPackageExcelModel> batchPackageExcelModels,
|
|
|
@RequestPart(value = "history") WmScorePackage scorePackage) {
|
|
|
|
|
|
- log.warn("==========================================批量导入积分包-插入redis:开始=====================================================");
|
|
|
- // 获取操作人
|
|
|
HnqzUser user = SecurityUtils.getUser();
|
|
|
- // 记录历史信息
|
|
|
- // 缓存记录key
|
|
|
- String key = String.format(CacheConstants.BATCH_PACKAGE_HISTORY, user.getDeptId(), user.getId());
|
|
|
- Map<String, Object> history = new HashMap<>(2);
|
|
|
- scorePackage.setCreateTime(null);
|
|
|
- scorePackage.setUpdateTime(null);
|
|
|
- JSONObject jsonObject = JSONUtil.parseObj(scorePackage);
|
|
|
- jsonObject.set("relatedService",Integer.parseInt(scorePackage.getRelatedService()));
|
|
|
- history.put("history", jsonObject);
|
|
|
- history.put("timestamp", DateTimeFormatter.ofPattern(DatePattern.CHINESE_DATE_TIME_PATTERN).format(LocalDateTime.now()));
|
|
|
- redisTemplate.opsForValue().set(key, JSONUtil.toJsonStr(history));
|
|
|
-
|
|
|
- log.warn("==========================================批量导入积分包-插入redis:结束=====================================================");
|
|
|
-
|
|
|
- log.warn("==========================================批量导入积分包:开始=====================================================");
|
|
|
-
|
|
|
|
|
|
+ // 加锁防止多处理
|
|
|
|
|
|
- Multimap<String, Object> errorMap = ArrayListMultimap.create();
|
|
|
+ String lock = "lock:package:batch:" + user.getDeptId();
|
|
|
|
|
|
- TargetType targetType = null;
|
|
|
-
|
|
|
- // 全职
|
|
|
- if (StrUtil.equals("3", scorePackage.getTypeid())) {
|
|
|
- targetType = TargetType.FULL_TIME;
|
|
|
- }
|
|
|
- // 兼职
|
|
|
- else if (StrUtil.equals("4", scorePackage.getTypeid())) {
|
|
|
- targetType = TargetType.PART_TIME;
|
|
|
+ if (!redisTemplate.opsForValue().setIfAbsent(lock, IdUtil.fastUUID())) {
|
|
|
+ return R.failed("有在途的操作,请稍后");
|
|
|
}
|
|
|
|
|
|
- // 重复的模型
|
|
|
- Map<String, List<BatchPackageExcelModel>> dupNameModel = batchPackageExcelModels.stream()
|
|
|
- .collect(Collectors.groupingBy(BatchPackageExcelModel::getScorePackageName));
|
|
|
- List<String> names = batchPackageExcelModels.stream().map(BatchPackageExcelModel::getScorePackageName).collect(Collectors.toList());
|
|
|
+ try {
|
|
|
+ log.warn("==========================================批量导入积分包-插入redis:开始=====================================================");
|
|
|
+ // 获取操作人
|
|
|
+ // 记录历史信息
|
|
|
+ // 缓存记录key
|
|
|
+ String key = String.format(CacheConstants.BATCH_PACKAGE_HISTORY, user.getDeptId(), user.getId());
|
|
|
+ Map<String, Object> history = new HashMap<>(2);
|
|
|
+ scorePackage.setCreateTime(null);
|
|
|
+ scorePackage.setUpdateTime(null);
|
|
|
+ JSONObject jsonObject = JSONUtil.parseObj(scorePackage);
|
|
|
+ jsonObject.set("relatedService", Integer.parseInt(scorePackage.getRelatedService()));
|
|
|
+ history.put("history", jsonObject);
|
|
|
+ history.put("timestamp", DateTimeFormatter.ofPattern(DatePattern.CHINESE_DATE_TIME_PATTERN).format(LocalDateTime.now()));
|
|
|
+ redisTemplate.opsForValue().set(key, JSONUtil.toJsonStr(history));
|
|
|
+
|
|
|
+ log.warn("==========================================批量导入积分包-插入redis:结束=====================================================");
|
|
|
+
|
|
|
+ log.warn("==========================================批量导入积分包:开始=====================================================");
|
|
|
+
|
|
|
+
|
|
|
+ Multimap<String, Object> errorMap = ArrayListMultimap.create();
|
|
|
+
|
|
|
+ TargetType targetType = null;
|
|
|
+
|
|
|
+ // 全职
|
|
|
+ if (StrUtil.equals("3", scorePackage.getTypeid())) {
|
|
|
+ targetType = TargetType.FULL_TIME;
|
|
|
+ }
|
|
|
+ // 兼职
|
|
|
+ else if (StrUtil.equals("4", scorePackage.getTypeid())) {
|
|
|
+ targetType = TargetType.PART_TIME;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 重复的模型
|
|
|
+ Map<String, List<BatchPackageExcelModel>> dupNameModel = batchPackageExcelModels.stream()
|
|
|
+ .collect(Collectors.groupingBy(BatchPackageExcelModel::getScorePackageName));
|
|
|
+ List<String> names = batchPackageExcelModels.stream().map(BatchPackageExcelModel::getScorePackageName).collect(Collectors.toList());
|
|
|
+
|
|
|
+ for (Map.Entry<String, List<BatchPackageExcelModel>> entry : dupNameModel.entrySet()) {
|
|
|
+ String name = entry.getKey();
|
|
|
+ int size = entry.getValue().size();
|
|
|
+ if (size > 1) {
|
|
|
+ List<Integer> index = new ArrayList<>(size);
|
|
|
+ List<String> temp = new ArrayList<>(names);
|
|
|
+ Iterator<String> iterator = temp.iterator();
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ int idx = temp.lastIndexOf(name);
|
|
|
+ if (idx != -1) {
|
|
|
+ index.add(idx + 1);
|
|
|
+ temp.remove(idx);
|
|
|
+ }
|
|
|
|
|
|
- for (Map.Entry<String, List<BatchPackageExcelModel>> entry : dupNameModel.entrySet()){
|
|
|
- String name = entry.getKey();
|
|
|
- int size = entry.getValue().size();
|
|
|
- if (size > 1){
|
|
|
- List<Integer> index = new ArrayList<>(size);
|
|
|
- List<String> temp = new ArrayList<>(names);
|
|
|
- Iterator<String> iterator = temp.iterator();
|
|
|
- while (iterator.hasNext()){
|
|
|
- int idx = temp.lastIndexOf(name);
|
|
|
- if(idx != -1){
|
|
|
- index.add(idx + 1);
|
|
|
- temp.remove(idx);
|
|
|
}
|
|
|
|
|
|
+ errorMap.put("模板内积分包名称重复", index.stream().sorted().collect(Collectors.toList()));
|
|
|
}
|
|
|
-
|
|
|
- errorMap.put("模板内积分包名称重复", index.stream().sorted().collect(Collectors.toList()));
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- // 业务校验
|
|
|
- for (int i = 0, batchScoreTotal = 0, rows = batchPackageExcelModels.size(); i < rows; i++) {
|
|
|
+ // 业务校验
|
|
|
+ for (int i = 0, batchScoreTotal = 0, rows = batchPackageExcelModels.size(); i < rows; i++) {
|
|
|
+
|
|
|
+ batchScoreTotal += checkColumn(batchPackageExcelModels.get(i), targetType, errorMap, i + 1, user.getDeptId());
|
|
|
|
|
|
- batchScoreTotal += checkColumn(batchPackageExcelModels.get(i), targetType, errorMap, i + 1, user.getDeptId());
|
|
|
+ // 额外校验可分配积分包
|
|
|
+ if (!"-1".equals(scorePackage.getRelationScoreId()) && batchScoreTotal > (scorePackage.getKfpjf() == null ? 0 : scorePackage.getKfpjf())) {
|
|
|
+ errorMap.put("批量下发总值大于可分配值", i + 1);
|
|
|
+ }
|
|
|
|
|
|
- // 额外校验可分配积分包
|
|
|
- if (!"-1".equals(scorePackage.getRelationScoreId()) && batchScoreTotal > (scorePackage.getKfpjf() == null ? 0 : scorePackage.getKfpjf())){
|
|
|
- errorMap.put("批量下发总值大于可分配值", i + 1);
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
+ // 存在错误全表打回
|
|
|
+ if (!errorMap.isEmpty()) {
|
|
|
|
|
|
- // 存在错误全表打回
|
|
|
- if (!errorMap.isEmpty()) {
|
|
|
+ List<Map<String, Object>> resultList = new ArrayList<>(errorMap.size());
|
|
|
+ Map<String, Collection<Object>> asMap = errorMap.asMap();
|
|
|
|
|
|
- List<Map<String, Object>> resultList = new ArrayList<>(errorMap.size());
|
|
|
- Map<String, Collection<Object>> asMap = errorMap.asMap();
|
|
|
+ for (Map.Entry<String, Collection<Object>> entry : asMap.entrySet()) {
|
|
|
|
|
|
- for (Map.Entry<String, Collection<Object>> entry : asMap.entrySet()) {
|
|
|
+ Map<String, Object> m = new HashMap<>(2);
|
|
|
|
|
|
- Map<String, Object> m = new HashMap<>(2);
|
|
|
+ m.put("reason", entry.getKey());
|
|
|
|
|
|
- m.put("reason", entry.getKey());
|
|
|
+ m.put("line", entry.getValue());
|
|
|
+ resultList.add(m);
|
|
|
+ }
|
|
|
|
|
|
- m.put("line", entry.getValue());
|
|
|
- resultList.add(m);
|
|
|
+ return R.ok(resultList);
|
|
|
}
|
|
|
|
|
|
- return R.ok(resultList);
|
|
|
- }
|
|
|
-
|
|
|
- for (BatchPackageExcelModel model : batchPackageExcelModels) {
|
|
|
+ for (BatchPackageExcelModel model : batchPackageExcelModels) {
|
|
|
|
|
|
- scorePackage.setScore(Integer.parseInt(model.getScore()));
|
|
|
- scorePackage.setScorePackageName(model.getScorePackageName());
|
|
|
- scorePackage.setDescription(model.getDescription());
|
|
|
- scorePackage.setUserList(StrUtil.isEmpty(model.getTargetId()) ? new ArrayList<>(1) :
|
|
|
- Collections.singletonList(model.getTargetId()));
|
|
|
+ scorePackage.setScore(Integer.parseInt(model.getScore()));
|
|
|
+ scorePackage.setScorePackageName(model.getScorePackageName());
|
|
|
+ scorePackage.setDescription(model.getDescription());
|
|
|
+ scorePackage.setUserList(StrUtil.isEmpty(model.getTargetId()) ? new ArrayList<>(1) :
|
|
|
+ Collections.singletonList(model.getTargetId()));
|
|
|
|
|
|
- wmScorePackageService.addWmScorePackage(scorePackage);
|
|
|
+ wmScorePackageService.addWmScorePackage(scorePackage);
|
|
|
|
|
|
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ log.warn("==========================================批量导入积分包:结束=====================================================");
|
|
|
+ redisTemplate.delete(lock);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- log.warn("==========================================批量导入积分包:结束=====================================================");
|
|
|
return R.ok();
|
|
|
}
|
|
|
|
|
@@ -2822,9 +2835,9 @@ public class WmScorePackageController {
|
|
|
errorMap.put("积分值未填", row);
|
|
|
} else {
|
|
|
// 校验是否是数字
|
|
|
- if (!Validator.isNumber(model.getScore())){
|
|
|
+ if (!Validator.isNumber(model.getScore())) {
|
|
|
errorMap.put("积分值不是数字", row);
|
|
|
- } else if (model.getScore().contains(StrUtil.DOT) || Integer.parseInt(model.getScore()) <= 0){
|
|
|
+ } else if (model.getScore().contains(StrUtil.DOT) || Integer.parseInt(model.getScore()) <= 0) {
|
|
|
errorMap.put("积分值必须是正整数", row);
|
|
|
}
|
|
|
}
|