Explorar el Código

feat: 任务类型百分比限制-查询列表接口、单个接口

李学松 hace 2 años
padre
commit
5e0b4e13e5

+ 55 - 5
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/controller/WmTaskSubmissionPercentRuleController.java

@@ -2,7 +2,9 @@ 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 lombok.AllArgsConstructor;
@@ -11,7 +13,10 @@ import org.springframework.http.MediaType;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
+import javax.validation.constraints.NotEmpty;
 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;
@@ -29,22 +34,67 @@ public class WmTaskSubmissionPercentRuleController {
 
 	private final WmTaskSubmissionPercentRuleService wmTaskSubmissionPercentRuleService;
 
+	private final WmTaskTypeService wmTaskTypeService;
+
 	/**
-	 * 获取企业的限制规则
+	 * 根据batchId查询单个限制规则
 	 *
-	 * @param deptId
+	 * @param batchId
 	 * @return
 	 */
-	@GetMapping
-	public R<Map<String, List<WmTaskSubmissionPercentRule>>> listDeptRules(@RequestParam(value = "deptId") Integer deptId) {
+	@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("/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));
 
 		Map<String, List<WmTaskSubmissionPercentRule>> collect = percentRules.stream().collect(Collectors.groupingBy(WmTaskSubmissionPercentRule::getBatchId));
 
-		return R.ok(collect);
+		// 查询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);
 	}
 
 	/**