|
@@ -6,11 +6,15 @@ import com.qunzhixinxi.hnqz.admin.service.WmTaskSubmissionPercentRuleService;
|
|
|
import com.qunzhixinxi.hnqz.common.core.constant.enums.CommonFlag;
|
|
|
import com.qunzhixinxi.hnqz.common.core.util.R;
|
|
|
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.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 任务提交百分比规则
|
|
@@ -32,59 +36,83 @@ public class WmTaskSubmissionPercentRuleController {
|
|
|
* @return
|
|
|
*/
|
|
|
@GetMapping
|
|
|
- public R<List<WmTaskSubmissionPercentRule>> listDeptRules(@RequestParam(value = "deptId") Integer deptId) {
|
|
|
- return R.ok(wmTaskSubmissionPercentRuleService.list(Wrappers.<WmTaskSubmissionPercentRule>lambdaQuery()
|
|
|
+ public R<Map<String, List<WmTaskSubmissionPercentRule>>> listDeptRules(@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));
|
|
|
+
|
|
|
+ return R.ok(collect);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 保存
|
|
|
*
|
|
|
- * @param rule
|
|
|
+ * @param rules
|
|
|
* @return
|
|
|
*/
|
|
|
@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
|
|
|
*/
|
|
|
@PutMapping
|
|
|
- public R<Boolean> update(@RequestBody WmTaskSubmissionPercentRule rule) {
|
|
|
- if (rule.getRuleId() == null) {
|
|
|
- return R.failed("ruleId不能为空");
|
|
|
+ public R<Boolean> update(@RequestBody List<WmTaskSubmissionPercentRule> rules) {
|
|
|
+
|
|
|
+ List<WmTaskSubmissionPercentRule> updateRules = new ArrayList<>();
|
|
|
+ for (WmTaskSubmissionPercentRule rule : rules) {
|
|
|
+ if (rule.getRuleId() == null) {
|
|
|
+ return R.failed("ruleId不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ WmTaskSubmissionPercentRule updateRule = new WmTaskSubmissionPercentRule();
|
|
|
+ updateRule.setRuleId(rule.getRuleId());
|
|
|
+ updateRule.setRule(rule.getRule());
|
|
|
+ updateRules.add(updateRule);
|
|
|
}
|
|
|
|
|
|
- WmTaskSubmissionPercentRule updateRule = new WmTaskSubmissionPercentRule();
|
|
|
- updateRule.setRuleId(rule.getRuleId());
|
|
|
- updateRule.setRule(rule.getRule());
|
|
|
|
|
|
- return R.ok(wmTaskSubmissionPercentRuleService.updateById(rule));
|
|
|
+ return R.ok(wmTaskSubmissionPercentRuleService.updateBatchById(updateRules));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除规则(逻辑删除)
|
|
|
*
|
|
|
- * @param ruleId
|
|
|
+ * @param batchId
|
|
|
* @return
|
|
|
*/
|
|
|
- @DeleteMapping("/{ruleId}")
|
|
|
- public R<Boolean> delete(@PathVariable("ruleId") Integer ruleId) {
|
|
|
+ @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));
|
|
|
}
|
|
|
|
|
|
}
|