|
@@ -1,12 +1,26 @@
|
|
|
package com.qunzhixinxi.hnqz.admin.controller;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import cn.hutool.core.map.MapUtil;
|
|
|
+import cn.hutool.core.util.ArrayUtil;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.qunzhixinxi.hnqz.admin.api.constant.UpmsType;
|
|
|
import com.qunzhixinxi.hnqz.admin.api.entity.SysDept;
|
|
|
+import com.qunzhixinxi.hnqz.admin.api.entity.WmTaskSubmissionPercentRule;
|
|
|
import com.qunzhixinxi.hnqz.admin.api.entity.WmTaskSubmissionRule;
|
|
|
+import com.qunzhixinxi.hnqz.admin.entity.WmTaskType;
|
|
|
+import com.qunzhixinxi.hnqz.admin.entity.WmTaskTypeSubCate2;
|
|
|
+import com.qunzhixinxi.hnqz.admin.enums.DelEnum;
|
|
|
import com.qunzhixinxi.hnqz.admin.service.SysDeptService;
|
|
|
+import com.qunzhixinxi.hnqz.admin.service.WmTaskSubmissionPercentRuleService;
|
|
|
import com.qunzhixinxi.hnqz.admin.service.WmTaskSubmissionRuleService;
|
|
|
+import com.qunzhixinxi.hnqz.admin.service.WmTaskTypeService;
|
|
|
+import com.qunzhixinxi.hnqz.admin.service.WmTaskTypeSubCate2Service;
|
|
|
+import com.qunzhixinxi.hnqz.common.core.constant.enums.CommonFlag;
|
|
|
import com.qunzhixinxi.hnqz.common.core.util.R;
|
|
|
+import com.qunzhixinxi.hnqz.common.security.util.SecurityUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -18,6 +32,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import javax.validation.constraints.NotEmpty;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
@@ -37,6 +54,9 @@ public class WmTaskSubmissionRuleController {
|
|
|
|
|
|
private final WmTaskSubmissionRuleService taskSubmissionRuleService;
|
|
|
private final SysDeptService deptService;
|
|
|
+ private final WmTaskTypeSubCate2Service wmTaskTypeSubCate2Service;
|
|
|
+ private final WmTaskSubmissionPercentRuleService taskSubmissionPercentRuleService;
|
|
|
+ private final WmTaskTypeService wmTaskTypeService;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -50,6 +70,149 @@ public class WmTaskSubmissionRuleController {
|
|
|
return R.ok(taskSubmissionRuleService.listDeptTaskSubmissionRules(deptId));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取企业的任务类型
|
|
|
+ *
|
|
|
+ * @param deptId 企业id
|
|
|
+ * @return 任务类型列表
|
|
|
+ */
|
|
|
+ @GetMapping("/list-task-type")
|
|
|
+ public R<?> listTaskType(@RequestParam(value = "deptId") Integer deptId) {
|
|
|
+
|
|
|
+ // 查询基础任务类型
|
|
|
+ List<WmTaskType> taskTypeList = wmTaskTypeService.list(Wrappers.<WmTaskType>lambdaQuery()
|
|
|
+ .eq(WmTaskType::getTaskTypeLevel, "1")
|
|
|
+ .eq(WmTaskType::getDelFlag, DelEnum.NOT_DEL.val()));
|
|
|
+ Map<String, String> baseTaskTypeMap = taskTypeList.stream()
|
|
|
+ .collect(Collectors.toMap(WmTaskType::getTaskTypeName, WmTaskType::getId));
|
|
|
+
|
|
|
+ // 查询任务类型分类表
|
|
|
+ List<WmTaskTypeSubCate2> list = wmTaskTypeSubCate2Service.list();
|
|
|
+ // key-任务类型父类型, value-任务类型名称列表
|
|
|
+ Map<String, List<String>> listMap = list.stream()
|
|
|
+ .collect(
|
|
|
+ Collectors.groupingBy(
|
|
|
+ WmTaskTypeSubCate2::getSubCate, Collectors.mapping(WmTaskTypeSubCate2::getTypeName, Collectors.toList())
|
|
|
+ )
|
|
|
+ );
|
|
|
+
|
|
|
+ List<Map<String, Object>> resultList = new ArrayList<>();
|
|
|
+ if (CollectionUtil.isNotEmpty(taskTypeList)) {
|
|
|
+ // 根据任务类型分类表,给企业任务类型分类
|
|
|
+ listMap.forEach((key, val) -> {
|
|
|
+ List<Map<String, String>> childTypeList = taskTypeList.stream()
|
|
|
+ .filter(wmTaskType -> val.contains(wmTaskType.getTaskTypeName())).map(wmTaskType -> {
|
|
|
+ Map<String, String> typeMap = new HashMap<>();
|
|
|
+ typeMap.put("taskTypeName", wmTaskType.getTaskTypeName());
|
|
|
+ typeMap.put("taskTypeId", baseTaskTypeMap.get(wmTaskType.getTaskTypeName()));
|
|
|
+ return typeMap;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (CollectionUtil.isNotEmpty(childTypeList)) {
|
|
|
+ Map<String, Object> taskTypeMap = MapUtil.newHashMap(2);
|
|
|
+ taskTypeMap.put("category", key);
|
|
|
+ taskTypeMap.put("categoryName", UpmsType.TaskSubCategory2.valueOf(key).getDescription());
|
|
|
+ taskTypeMap.put("children", childTypeList);
|
|
|
+ resultList.add(taskTypeMap);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (CollectionUtil.isNotEmpty(resultList)) {
|
|
|
+ // 查询任务类型启用状态
|
|
|
+ List<WmTaskSubmissionPercentRule> rules = taskSubmissionPercentRuleService.list(Wrappers.<WmTaskSubmissionPercentRule>lambdaQuery()
|
|
|
+ .eq(WmTaskSubmissionPercentRule::getDeptId, deptId)
|
|
|
+ .eq(WmTaskSubmissionPercentRule::getSubCategory, UpmsType.TaskSubCategory2.TASK_TYPE_CONFIG));
|
|
|
+ String[] taskTypeIds;
|
|
|
+ if (CollUtil.isNotEmpty(rules)) {
|
|
|
+ taskTypeIds = rules.get(0).getRule().getTaskTypeIds();
|
|
|
+ } else {
|
|
|
+ taskTypeIds = new String[0];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置任务类型是否启用状态
|
|
|
+ resultList.forEach(map -> {
|
|
|
+ List<Map<String, Object>> children = (List<Map<String, Object>>) map.get("children");
|
|
|
+ if (CollUtil.isNotEmpty(children)) {
|
|
|
+ // child添加是否启用标记
|
|
|
+ children.forEach(childMap -> {
|
|
|
+ String taskTypeId = (String) childMap.get("taskTypeId");
|
|
|
+ childMap.put("enableFlag", ArrayUtil.contains(taskTypeIds, taskTypeId));
|
|
|
+ });
|
|
|
+ // 父级添加是否启用标记
|
|
|
+ map.put("enableFlag", children.stream().anyMatch(childMap -> Boolean.TRUE.equals(childMap.get("enableFlag"))));
|
|
|
+ } else {
|
|
|
+ map.put("enableFlag", Boolean.FALSE);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.ok(resultList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取企业的任务类型id
|
|
|
+ *
|
|
|
+ * @param deptId 企业id
|
|
|
+ * @return 任务类型列表
|
|
|
+ */
|
|
|
+ @GetMapping("/list-task-type-ids")
|
|
|
+ public R<?> listTaskTypeIds(@RequestParam(value = "deptId") Integer deptId) {
|
|
|
+ // 查询任务类型启用状态
|
|
|
+ List<WmTaskSubmissionPercentRule> rules = taskSubmissionPercentRuleService.list(Wrappers.<WmTaskSubmissionPercentRule>lambdaQuery()
|
|
|
+ .eq(WmTaskSubmissionPercentRule::getDeptId, deptId)
|
|
|
+ .eq(WmTaskSubmissionPercentRule::getSubCategory, UpmsType.TaskSubCategory2.TASK_TYPE_CONFIG));
|
|
|
+ String[] taskTypeIds;
|
|
|
+ if (CollUtil.isNotEmpty(rules)) {
|
|
|
+ taskTypeIds = rules.get(0).getRule().getTaskTypeIds();
|
|
|
+ } else {
|
|
|
+ taskTypeIds = new String[0];
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.ok(taskTypeIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新启用的任务类型
|
|
|
+ *
|
|
|
+ * @param requestMap 请求参数
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @PostMapping("/update-task-type")
|
|
|
+ public R<Boolean> updateEnableTaskType(@RequestBody Map<String, Object> requestMap) {
|
|
|
+ List<String> taskTypeIds = (List<String>) requestMap.get("taskTypeIds");
|
|
|
+ Integer deptId = (Integer) requestMap.get("deptId");
|
|
|
+ if (ArrayUtil.isEmpty(taskTypeIds) || deptId == null) {
|
|
|
+ return R.failed("必填参数为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ WmTaskSubmissionPercentRule.PercentRule rule = new WmTaskSubmissionPercentRule.PercentRule();
|
|
|
+ rule.setLimitPercent("");
|
|
|
+ rule.setStartScore(0);
|
|
|
+ rule.setTaskTypeIds(taskTypeIds.toArray(new String[0]));
|
|
|
+
|
|
|
+ // 查询待修改企业的规则
|
|
|
+ List<WmTaskSubmissionPercentRule> queryRules = taskSubmissionPercentRuleService.list(Wrappers.<WmTaskSubmissionPercentRule>lambdaQuery()
|
|
|
+ .eq(WmTaskSubmissionPercentRule::getDeptId, deptId)
|
|
|
+ .eq(WmTaskSubmissionPercentRule::getSubCategory, UpmsType.TaskSubCategory2.TASK_TYPE_CONFIG));
|
|
|
+ if (CollUtil.isEmpty(queryRules)) {
|
|
|
+ WmTaskSubmissionPercentRule percentRule = new WmTaskSubmissionPercentRule();
|
|
|
+ percentRule.setDeptId(deptId);
|
|
|
+ percentRule.setRule(rule);
|
|
|
+ percentRule.setSubCategory(UpmsType.TaskSubCategory2.TASK_TYPE_CONFIG);
|
|
|
+ percentRule.setOptFlag(CommonFlag.OptFlag.OK);
|
|
|
+ taskSubmissionPercentRuleService.save(percentRule);
|
|
|
+ } else {
|
|
|
+ taskSubmissionPercentRuleService.update(Wrappers.<WmTaskSubmissionPercentRule>lambdaUpdate()
|
|
|
+ .eq(WmTaskSubmissionPercentRule::getDeptId, deptId)
|
|
|
+ .eq(WmTaskSubmissionPercentRule::getSubCategory, UpmsType.TaskSubCategory2.TASK_TYPE_CONFIG)
|
|
|
+ .set(WmTaskSubmissionPercentRule::getRule, JSONUtil.toJsonStr(rule)));
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.ok(Boolean.TRUE);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 初始化企业限制
|
|
|
*
|