|
@@ -1,6 +1,8 @@
|
|
|
package com.qunzhixinxi.hnqz.admin.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.qunzhixinxi.hnqz.admin.api.entity.WmTaskSubmissionPercentRule;
|
|
@@ -45,61 +47,79 @@ public class WmTaskSubmissionPercentRuleServiceImpl
|
|
|
/**
|
|
|
* 校验任务百分比限制规则(达到要求的积分包,【任务配置】-【百分比限制】所选的任务总完成积分值不得大于积分包值*百分比)
|
|
|
*
|
|
|
- * @param scorePackage
|
|
|
+ * @param scorePackage 积分包实体
|
|
|
+ * @param deptId 部门id
|
|
|
+ * @param taskUserId 任务承接人userId
|
|
|
+ * @param checkTaskTypeList 要校验的任务类型list
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public R<?> checkPercentRule(WmScorePackage scorePackage, Integer deptId) {
|
|
|
+ public R<?> checkPercentRule(WmScorePackage scorePackage, Integer deptId, Integer taskUserId, List<String> checkTaskTypeList) {
|
|
|
|
|
|
AtomicBoolean failFlag = new AtomicBoolean(false);
|
|
|
AtomicReference<String> message = new AtomicReference<>("");
|
|
|
|
|
|
// 查询配置的百分比规则
|
|
|
List<WmTaskSubmissionPercentRule> percentRules = this.list(Wrappers.<WmTaskSubmissionPercentRule>lambdaQuery()
|
|
|
- .eq(WmTaskSubmissionPercentRule::getDeptId, deptId)
|
|
|
+ .in(WmTaskSubmissionPercentRule::getDeptId, 1, deptId)
|
|
|
.eq(WmTaskSubmissionPercentRule::getOptFlag, CommonFlag.OptFlag.OK));
|
|
|
|
|
|
- // 根据batchId分组
|
|
|
- Map<String, List<WmTaskSubmissionPercentRule>> batchRules = percentRules.stream().collect(Collectors.groupingBy(WmTaskSubmissionPercentRule::getBatchId));
|
|
|
-
|
|
|
- // 查询taskType
|
|
|
- List<WmTaskType> taskTypeList = wmTaskTypeService.list(Wrappers.<WmTaskType>lambdaQuery()
|
|
|
- .eq(WmTaskType::getTaskTypeLevel, "1")
|
|
|
- .eq(WmTaskType::getDelFlag, "0")
|
|
|
- .eq(WmTaskType::getEnableFlag, "0"));
|
|
|
- // taskType通过id分组(key为parentId,value为taskTypeId的set)
|
|
|
- Map<String, String> taskTypeIdMap = taskTypeList.stream()
|
|
|
- .collect(Collectors.toMap(WmTaskType::getId, WmTaskType::getTaskTypeName));
|
|
|
-
|
|
|
- batchRules.forEach((batchId, rules) -> {
|
|
|
-
|
|
|
- // 获取该分组下所有taskTypeId
|
|
|
- List<String> allTaskTypeIds = rules.stream()
|
|
|
- .flatMap(percentRule -> Arrays.stream(percentRule.getRule().getTaskTypeIds()))
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
- WmTaskSubmissionPercentRule.PercentRule rule = rules.get(0).getRule();
|
|
|
-
|
|
|
- // 指定任务类型做的任务总积分不得大于积分包值的rule.limitPercent%(积分包值小于rule.startScore不做限制)
|
|
|
- if (scorePackage.getScore() > rule.getStartScore()) {
|
|
|
- List<WmTask> wmTaskList = wmTaskService.list(Wrappers.<WmTask>lambdaQuery()
|
|
|
- .eq(WmTask::getRealFlag, "0")
|
|
|
- .eq(WmTask::getDelFlag, DelEnum.NOT_DEL.val())
|
|
|
- .in(WmTask::getScorePackageId, scorePackage.getId())
|
|
|
- .in(WmTask::getTaskTypeId, allTaskTypeIds)
|
|
|
- .ne(WmTask::getTaskStatus, "4"));
|
|
|
-
|
|
|
- if (CollectionUtil.isNotEmpty(wmTaskList)) {
|
|
|
- int totalScore = scorePackage.getScore();
|
|
|
- int partScore = wmTaskList.stream().mapToInt(WmTask::getScore).sum();
|
|
|
- if (partScore * 100.0 / totalScore > Float.parseFloat(rule.getLimitPercent())) {
|
|
|
- failFlag.set(true);
|
|
|
-
|
|
|
- String taskTypeNames = allTaskTypeIds.stream().map(taskTypeIdMap::get).collect(Collectors.joining("、"));
|
|
|
- message.set(String.format("%s任务类型的任务总积分不得大于积分包值的%s%%", taskTypeNames, rule.getLimitPercent()));
|
|
|
+ // 根据deptId分组,再根据batchId分组
|
|
|
+ Map<Integer, Map<String, List<WmTaskSubmissionPercentRule>>> deptsMap = percentRules.stream()
|
|
|
+ .collect(Collectors.groupingBy(WmTaskSubmissionPercentRule::getDeptId, Collectors.groupingBy(WmTaskSubmissionPercentRule::getBatchId)));
|
|
|
+
|
|
|
+ deptsMap.forEach((dptId, batchRules) -> {
|
|
|
+ // 查询taskType
|
|
|
+ List<WmTaskType> taskTypeList = wmTaskTypeService.list(Wrappers.<WmTaskType>lambdaQuery()
|
|
|
+ .eq(WmTaskType::getTaskTypeLevel, "1")
|
|
|
+ .eq(WmTaskType::getDelFlag, "0")
|
|
|
+ .eq(WmTaskType::getEnableFlag, "0"));
|
|
|
+ // taskType通过id分组(key为parentId,value为taskTypeId的set)
|
|
|
+ Map<String, String> taskTypeIdMap = taskTypeList.stream()
|
|
|
+ .collect(Collectors.toMap(WmTaskType::getId, WmTaskType::getTaskTypeName));
|
|
|
+
|
|
|
+ batchRules.forEach((batchId, rules) -> {
|
|
|
+
|
|
|
+ // 获取该分组下所有taskTypeId
|
|
|
+ List<String> allTaskTypeIds = rules.stream()
|
|
|
+ .flatMap(percentRule -> Arrays.stream(percentRule.getRule().getTaskTypeIds()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<String> toCheckTaskTypes = null;
|
|
|
+ if (checkTaskTypeList != null) {
|
|
|
+ // 把要校验的任务 和 已配置的规则任务 做交集,得到实际需要校验的任务类型
|
|
|
+ toCheckTaskTypes = new ArrayList<>(CollUtil.intersection(allTaskTypeIds, checkTaskTypeList));
|
|
|
+ } else {
|
|
|
+ toCheckTaskTypes = allTaskTypeIds;
|
|
|
+ }
|
|
|
+
|
|
|
+ WmTaskSubmissionPercentRule.PercentRule rule = rules.get(0).getRule();
|
|
|
+
|
|
|
+ // 指定任务类型做的任务总积分不得大于积分包值的rule.limitPercent%(积分包值小于rule.startScore不做限制)
|
|
|
+ if (scorePackage.getScore() > rule.getStartScore()) {
|
|
|
+ LambdaQueryWrapper<WmTask> queryWrapper = Wrappers.<WmTask>lambdaQuery()
|
|
|
+ .eq(WmTask::getRealFlag, "0")
|
|
|
+ .eq(WmTask::getDelFlag, DelEnum.NOT_DEL.val())
|
|
|
+ .in(WmTask::getScorePackageId, scorePackage.getId())
|
|
|
+ .in(WmTask::getTaskTypeId, toCheckTaskTypes)
|
|
|
+ .ne(WmTask::getTaskStatus, "4");
|
|
|
+ if (taskUserId != null) {
|
|
|
+ queryWrapper.eq(WmTask::getTaskUserId, taskUserId);
|
|
|
+ }
|
|
|
+ List<WmTask> wmTaskList = wmTaskService.list(queryWrapper);
|
|
|
+
|
|
|
+ if (CollectionUtil.isNotEmpty(wmTaskList)) {
|
|
|
+ int totalScore = scorePackage.getScore();
|
|
|
+ int partScore = wmTaskList.stream().mapToInt(WmTask::getScore).sum();
|
|
|
+ if (partScore * 100.0 / totalScore > Float.parseFloat(rule.getLimitPercent())) {
|
|
|
+ failFlag.set(true);
|
|
|
+
|
|
|
+ String taskTypeNames = toCheckTaskTypes.stream().map(taskTypeIdMap::get).collect(Collectors.joining("、"));
|
|
|
+ message.set(String.format("%s任务类型的任务总积分不得大于积分包值的%s%%", taskTypeNames, rule.getLimitPercent()));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
return failFlag.get() ? R.failed(null, message.get()) : R.ok();
|