|
@@ -2,15 +2,24 @@ package com.qunzhixinxi.hnqz.admin.controller;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.qunzhixinxi.hnqz.admin.api.entity.WmTaskSubmissionPercentRule;
|
|
|
+import com.qunzhixinxi.hnqz.admin.entity.WmTaskType;
|
|
|
import com.qunzhixinxi.hnqz.admin.service.WmTaskSubmissionPercentRuleService;
|
|
|
+import com.qunzhixinxi.hnqz.admin.service.WmTaskTypeService;
|
|
|
import com.qunzhixinxi.hnqz.common.core.constant.enums.CommonFlag;
|
|
|
import com.qunzhixinxi.hnqz.common.core.util.R;
|
|
|
+import com.qunzhixinxi.hnqz.common.log.annotation.SysLog;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import org.apache.commons.lang3.RandomStringUtils;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 任务提交百分比规则
|
|
@@ -25,66 +34,131 @@ public class WmTaskSubmissionPercentRuleController {
|
|
|
|
|
|
private final WmTaskSubmissionPercentRuleService wmTaskSubmissionPercentRuleService;
|
|
|
|
|
|
+ private final WmTaskTypeService wmTaskTypeService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据batchId查询单个限制规则
|
|
|
+ *
|
|
|
+ * @param batchId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @GetMapping("/{batchId}")
|
|
|
+ public R<List<WmTaskSubmissionPercentRule>> listDeptRules(@PathVariable("batchId") String batchId) {
|
|
|
+
|
|
|
+ List<WmTaskSubmissionPercentRule> percentRules = wmTaskSubmissionPercentRuleService.list(Wrappers.<WmTaskSubmissionPercentRule>lambdaQuery()
|
|
|
+ .eq(WmTaskSubmissionPercentRule::getBatchId, batchId)
|
|
|
+ .eq(WmTaskSubmissionPercentRule::getOptFlag, CommonFlag.OptFlag.OK));
|
|
|
+
|
|
|
+ return R.ok(percentRules);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
- * 获取企业的限制规则
|
|
|
+ * 根据deptId查询企业的限制规则列表
|
|
|
*
|
|
|
* @param deptId
|
|
|
* @return
|
|
|
*/
|
|
|
- @GetMapping
|
|
|
- public R<List<WmTaskSubmissionPercentRule>> listDeptRules(@RequestParam(value = "deptId") Integer deptId) {
|
|
|
- return R.ok(wmTaskSubmissionPercentRuleService.list(Wrappers.<WmTaskSubmissionPercentRule>lambdaQuery()
|
|
|
+ @GetMapping("/list")
|
|
|
+ public R<List<Map<String, Object>>> listDeptBriefRule(@RequestParam(value = "deptId") Integer deptId) {
|
|
|
+ List<WmTaskSubmissionPercentRule> percentRules = wmTaskSubmissionPercentRuleService.list(Wrappers.<WmTaskSubmissionPercentRule>lambdaQuery()
|
|
|
.eq(WmTaskSubmissionPercentRule::getDeptId, deptId)
|
|
|
- .eq(WmTaskSubmissionPercentRule::getOptFlag, CommonFlag.OptFlag.OK)));
|
|
|
+ .eq(WmTaskSubmissionPercentRule::getOptFlag, CommonFlag.OptFlag.OK));
|
|
|
+
|
|
|
+ Map<String, List<WmTaskSubmissionPercentRule>> collect = 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));
|
|
|
+
|
|
|
+ List<Map<String, Object>> result = new ArrayList<>();
|
|
|
+
|
|
|
+ collect.forEach((batchId, rules) -> {
|
|
|
+ // 获取该分组下所有taskTypeId
|
|
|
+ List<String> allTaskTypeIds = rules.stream()
|
|
|
+ .flatMap(percentRule -> Arrays.stream(percentRule.getRule().getTaskTypeIds()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<String> allTaskTypeNames = allTaskTypeIds.stream().map(taskTypeIdMap::get).collect(Collectors.toList());
|
|
|
+
|
|
|
+ Map<String, Object> ruleMap = new HashMap<>();
|
|
|
+ ruleMap.put("taskTypeNames", allTaskTypeNames);
|
|
|
+ WmTaskSubmissionPercentRule.PercentRule rule = rules.get(0).getRule();
|
|
|
+ ruleMap.put("startScore", rule.getStartScore());
|
|
|
+ ruleMap.put("limitPercent", rule.getLimitPercent());
|
|
|
+ ruleMap.put("batchId", batchId);
|
|
|
+ result.add(ruleMap);
|
|
|
+ });
|
|
|
+
|
|
|
+ return R.ok(result);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 保存
|
|
|
*
|
|
|
- * @param rule
|
|
|
+ * @param rules
|
|
|
* @return
|
|
|
*/
|
|
|
+ @SysLog("保存百分比规则")
|
|
|
@PostMapping
|
|
|
- public R<Boolean> save(@Validated @RequestBody WmTaskSubmissionPercentRule rule) {
|
|
|
- // 默认正常
|
|
|
- rule.setOptFlag(CommonFlag.OptFlag.OK);
|
|
|
+ public R<Boolean> save(@Validated @RequestBody List<WmTaskSubmissionPercentRule> rules) {
|
|
|
+
|
|
|
+ String batchId = RandomStringUtils.randomAlphabetic(16);
|
|
|
+ rules.forEach(rule -> {
|
|
|
+ // 默认正常
|
|
|
+ rule.setOptFlag(CommonFlag.OptFlag.OK);
|
|
|
+ // 批量保存编号
|
|
|
+ rule.setBatchId(batchId);
|
|
|
+ });
|
|
|
|
|
|
- return R.ok(wmTaskSubmissionPercentRuleService.save(rule));
|
|
|
+ return R.ok(wmTaskSubmissionPercentRuleService.saveBatch(rules));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 更新
|
|
|
*
|
|
|
- * @param rule
|
|
|
+ * @param rules
|
|
|
* @return
|
|
|
*/
|
|
|
+ @SysLog("更新百分比规则")
|
|
|
@PutMapping
|
|
|
- public R<Boolean> update(@RequestBody WmTaskSubmissionPercentRule rule) {
|
|
|
- if (rule.getRuleId() == null) {
|
|
|
- return R.failed("ruleId不能为空");
|
|
|
- }
|
|
|
+ public R<Boolean> update(@RequestBody List<WmTaskSubmissionPercentRule> rules) {
|
|
|
|
|
|
- WmTaskSubmissionPercentRule updateRule = new WmTaskSubmissionPercentRule();
|
|
|
- updateRule.setRuleId(rule.getRuleId());
|
|
|
- updateRule.setRule(rule.getRule());
|
|
|
+ for (WmTaskSubmissionPercentRule rule : rules) {
|
|
|
+ if (rule.getBatchId() == null) {
|
|
|
+ return R.failed("batchId不能为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- return R.ok(wmTaskSubmissionPercentRuleService.updateById(rule));
|
|
|
+ return R.ok(wmTaskSubmissionPercentRuleService.updateRule(rules));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除规则(逻辑删除)
|
|
|
*
|
|
|
- * @param ruleId
|
|
|
+ * @param batchId
|
|
|
* @return
|
|
|
*/
|
|
|
- @DeleteMapping("/{ruleId}")
|
|
|
- public R<Boolean> delete(@PathVariable("ruleId") Integer ruleId) {
|
|
|
+ @SysLog("删除百分比规则")
|
|
|
+ @DeleteMapping("/{batchId}")
|
|
|
+ public R<Boolean> delete(@PathVariable("batchId") String batchId) {
|
|
|
+
|
|
|
+ List<WmTaskSubmissionPercentRule> rules = wmTaskSubmissionPercentRuleService.list(Wrappers.<WmTaskSubmissionPercentRule>lambdaQuery()
|
|
|
+ .eq(WmTaskSubmissionPercentRule::getBatchId, batchId));
|
|
|
|
|
|
- WmTaskSubmissionPercentRule rule = new WmTaskSubmissionPercentRule();
|
|
|
- rule.setRuleId(ruleId);
|
|
|
- rule.setOptFlag(CommonFlag.OptFlag.DELETED);
|
|
|
+ List<WmTaskSubmissionPercentRule> updateRules = new ArrayList<>();
|
|
|
+ rules.forEach(percentRule -> {
|
|
|
+ WmTaskSubmissionPercentRule rule = new WmTaskSubmissionPercentRule();
|
|
|
+ rule.setRuleId(percentRule.getRuleId());
|
|
|
+ rule.setOptFlag(CommonFlag.OptFlag.DELETED);
|
|
|
+ updateRules.add(rule);
|
|
|
+ });
|
|
|
|
|
|
- return R.ok(wmTaskSubmissionPercentRuleService.updateById(rule));
|
|
|
+ return R.ok(wmTaskSubmissionPercentRuleService.updateBatchById(updateRules));
|
|
|
}
|
|
|
|
|
|
}
|