master
tianxinlei 2026-05-27 08:38:40 +08:00
parent 33bfe31895
commit 9dfb999323
3 changed files with 73 additions and 22 deletions

View File

@ -0,0 +1,52 @@
package com.zcloud.safetyDutyList.command.tasklist;
import com.alibaba.cola.exception.BizException;
import com.zcloud.safetyDutyList.domain.gateway.tasklist.TaskDetailGateway;
import com.zcloud.safetyDutyList.domain.model.tasklist.TaskDetailE;
import com.zcloud.safetyDutyList.dto.clientobject.tasklist.TaskDetailCO;
import com.zcloud.safetyDutyList.dto.tasklist.TaskDetailEditCmd;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.List;
@Component
@AllArgsConstructor
public class TaskDetailEditExe {
private final TaskDetailGateway taskDetailGateway;
public TaskDetailCO execute(TaskDetailEditCmd cmd) {
TaskDetailE existDetail = taskDetailGateway.getByTaskDetailId(cmd.getTaskDetailId());
if (existDetail == null) {
throw new BizException("任务详情不存在");
}
List<TaskDetailE> existDetails = taskDetailGateway.listByTaskListId(existDetail.getTaskListId());
BigDecimal otherTotalScore = existDetails.stream()
.filter(d -> !d.getTaskDetailId().equals(cmd.getTaskDetailId()))
.map(TaskDetailE::getTaskScore)
.filter(s -> s != null)
.reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal newScore = cmd.getTaskScore() != null ? cmd.getTaskScore() : BigDecimal.ZERO;
BigDecimal totalScore = otherTotalScore.add(newScore);
if (totalScore.compareTo(new BigDecimal("100")) > 0) {
BigDecimal diff = new BigDecimal("100").subtract(otherTotalScore);
throw new BizException("当前清单总分不能超过100,当前任务可设最大分值:" + diff);
}
existDetail.setExecuteContent(cmd.getExecuteContent());
existDetail.setFeedbackCycleType(cmd.getFeedbackCycleType());
existDetail.setTaskScore(cmd.getTaskScore());
boolean res = taskDetailGateway.update(existDetail);
if (!res) {
throw new BizException("编辑失败");
}
TaskDetailCO co = new TaskDetailCO();
BeanUtils.copyProperties(existDetail, co);
return co;
}
}

View File

@ -38,26 +38,29 @@ public class TaskDetailSaveBatchExe {
// 获取当前已有列表
List<TaskDetailE> existDetails = taskDetailGateway.listByTaskListId(cmds.get(0).getTaskListId());
if (existDetails == null || existDetails.isEmpty()) {
throw new BizException("清单不存在");
}
// 当前的分值
BigDecimal totalScore = existDetails.stream()
.map(TaskDetailE::getTaskScore)
.filter(s -> s != null)
.reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal cmdScore = cmds.stream()
.map(TaskDetailSaveCmd::getTaskScore)
.filter(s -> s != null)
.reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal diff = new BigDecimal("100").subtract(totalScore);
if (cmdScore != null) {
totalScore = totalScore.add(cmdScore);
}
if (totalScore.compareTo(new BigDecimal("100")) > 0) {
throw new BizException("当前清单总分不能超过100,任务可设最大分值:" + diff);
}
// BigDecimal totalScore = existDetails.stream()
// .map(TaskDetailE::getTaskScore)
// .filter(s -> s != null)
// .reduce(BigDecimal.ZERO, BigDecimal::add);
//
// BigDecimal cmdScore = cmds.stream()
// .map(TaskDetailSaveCmd::getTaskScore)
// .filter(s -> s != null)
// .reduce(BigDecimal.ZERO, BigDecimal::add);
//
// BigDecimal diff = new BigDecimal("100").subtract(totalScore);
//
// if (cmdScore != null) {
// totalScore = totalScore.add(cmdScore);
// }
// if (totalScore.compareTo(new BigDecimal("100")) > 0) {
// throw new BizException("当前清单总分不能超过100,任务可设最大分值:" + diff);
// }
List<TaskDetailE> detailEList = new ArrayList <>();
for (TaskDetailSaveCmd cmd : cmds) {

View File

@ -18,10 +18,6 @@ public class TaskDetailEditCmd implements Serializable {
@NotEmpty(message = "任务详情ID不能为空")
private String taskDetailId;
@ApiModelProperty(value = "清单表主键ID", required = true)
@NotEmpty(message = "清单ID不能为空")
private String taskListId;
@ApiModelProperty(value = "执行内容")
private String executeContent;