5-26 fix
parent
907ba840f3
commit
3bb41be81a
|
|
@ -14,6 +14,8 @@ import lombok.AllArgsConstructor;
|
|||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 任务详情控制器
|
||||
* <p>
|
||||
|
|
@ -40,6 +42,12 @@ public class TaskDetailController {
|
|||
return taskListService.addTaskDetail(cmd);
|
||||
}
|
||||
|
||||
@ApiOperation("新增任务")
|
||||
@PostMapping("/saveBatch")
|
||||
public SingleResponse add(@Validated @RequestBody List<TaskDetailSaveCmd> cmds) {
|
||||
return taskListService.addTaskDetailBatch(cmds);
|
||||
}
|
||||
|
||||
@ApiOperation("获取任务详情")
|
||||
@GetMapping("/{detailId}")
|
||||
public SingleResponse<TaskDetailInfoCO> getByDetailId(@PathVariable String detailId) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,80 @@
|
|||
package com.zcloud.safetyDutyList.command.tasklist;
|
||||
|
||||
import com.alibaba.cola.exception.BizException;
|
||||
import com.zcloud.safetyDutyList.domain.enums.TaskStatusEnum;
|
||||
import com.zcloud.safetyDutyList.domain.gateway.tasklist.TaskDetailGateway;
|
||||
import com.zcloud.safetyDutyList.domain.gateway.tasklist.TaskListGateway;
|
||||
import com.zcloud.safetyDutyList.domain.model.tasklist.TaskDetailE;
|
||||
import com.zcloud.safetyDutyList.dto.clientobject.tasklist.TaskDetailCO;
|
||||
import com.zcloud.safetyDutyList.dto.tasklist.TaskDetailSaveCmd;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 任务详情保存执行器
|
||||
* <p>
|
||||
* 处理新增任务详情的业务逻辑:
|
||||
* 1. 查询该清单下已有任务详情,计算总分
|
||||
* 2. 校验新增后清单总分不超过100分
|
||||
* 3. 创建任务详情实体并保存
|
||||
* 4. 返回新增后的任务详情信息
|
||||
*/
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class TaskDetailSaveBatchExe {
|
||||
private final TaskDetailGateway taskDetailGateway;
|
||||
private final TaskListGateway taskListGateway;
|
||||
|
||||
public Boolean execute(List<TaskDetailSaveCmd> cmds) {
|
||||
|
||||
if (cmds == null || cmds.isEmpty()) {
|
||||
throw new BizException("参数不能为空");
|
||||
}
|
||||
|
||||
// 获取当前已有列表
|
||||
List<TaskDetailE> existDetails = taskDetailGateway.listByTaskListId(cmds.get(0).getTaskListId());
|
||||
|
||||
// 当前的分值
|
||||
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) {
|
||||
TaskDetailE detailE = new TaskDetailE();
|
||||
BeanUtils.copyProperties(cmd, detailE);
|
||||
detailE.init();
|
||||
detailE.setTaskStatus(TaskStatusEnum.IN_PROGRESS.getCode());
|
||||
detailE.setFeedbackStatus(1);
|
||||
|
||||
detailEList.add(detailE);
|
||||
}
|
||||
|
||||
boolean res = taskDetailGateway.batchAdd(detailEList);
|
||||
if (!res) {
|
||||
throw new BizException("保存失败");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -12,6 +12,8 @@ import com.zcloud.safetyDutyList.dto.tasklist.*;
|
|||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 安全责任清单服务实现类
|
||||
* <p>
|
||||
|
|
@ -39,6 +41,8 @@ public class TaskListServiceImpl implements TaskListServiceI {
|
|||
private final TaskListIssueExe taskListIssueExe;
|
||||
/** 任务详情保存执行器 */
|
||||
private final TaskDetailSaveExe taskDetailSaveExe;
|
||||
/** 任务详情批量保存执行器 */
|
||||
private final TaskDetailSaveBatchExe taskDetailSaveBatchExe;
|
||||
/** 任务详情关闭执行器 */
|
||||
private final TaskDetailCloseExe taskDetailCloseExe;
|
||||
/** 任务评分更新执行器 */
|
||||
|
|
@ -118,6 +122,12 @@ public class TaskListServiceImpl implements TaskListServiceI {
|
|||
return SingleResponse.of(co);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SingleResponse addTaskDetailBatch(List <TaskDetailSaveCmd> cmds) {
|
||||
taskDetailSaveBatchExe.execute(cmds);
|
||||
return SingleResponse.buildSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SingleResponse<TaskDetailInfoCO> getByTaskDetailId(String detailId) {
|
||||
return taskDetailQueryExe.getByDetailId(detailId);
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import com.alibaba.cola.dto.SingleResponse;
|
|||
import com.zcloud.safetyDutyList.dto.clientobject.tasklist.*;
|
||||
import com.zcloud.safetyDutyList.dto.tasklist.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 安全责任清单服务接口
|
||||
* <p>
|
||||
|
|
@ -97,6 +99,14 @@ public interface TaskListServiceI {
|
|||
*/
|
||||
SingleResponse<TaskDetailCO> addTaskDetail(TaskDetailSaveCmd cmd);
|
||||
|
||||
/**
|
||||
* 新增任务详情(校验清单总分不超过100)
|
||||
*
|
||||
* @param cmds 任务保存命令
|
||||
* @return 新增后的任务详情
|
||||
*/
|
||||
SingleResponse<TaskDetailCO> addTaskDetailBatch(List<TaskDetailSaveCmd> cmds);
|
||||
|
||||
/**
|
||||
* 根据任务详情ID获取任务详情(含所属清单信息)
|
||||
*
|
||||
|
|
|
|||
|
|
@ -12,12 +12,13 @@
|
|||
fb_dept.name AS feedbackDepartmentName,
|
||||
fb_corp.corp_name AS feedbackCorpName
|
||||
FROM safety_accountability_feedback f
|
||||
LEFT JOIN safety_accountability_task_detail td ON f.task_detail_id = td.task_detail_id
|
||||
LEFT JOIN safety_accountability_task_list tl ON f.task_list_id = tl.task_list_id
|
||||
LEFT JOIN safety_accountability_task_detail td ON f.task_detail_id = td.task_detail_id and td.delete_enum = 'FALSE'
|
||||
LEFT JOIN safety_accountability_task_list tl ON f.task_list_id = tl.task_list_id and tl.delete_enum = 'FALSE'
|
||||
LEFT JOIN user fb_user ON f.feedback_user_id = fb_user.id
|
||||
LEFT JOIN department fb_dept ON f.feedback_department_id = fb_dept.id
|
||||
LEFT JOIN corp_info fb_corp ON f.feedback_corp_id = fb_corp.id
|
||||
<where>
|
||||
delete_enum = 'FALSE'
|
||||
<if test="params.feedbackCorpId != null">
|
||||
AND f.feedback_corp_id = #{params.feedbackCorpId}
|
||||
</if>
|
||||
|
|
@ -36,13 +37,13 @@
|
|||
|
||||
<select id="listByTaskListId" resultType="com.zcloud.safetyDutyList.persistence.dataobject.tasklist.FeedbackDO">
|
||||
SELECT * FROM safety_accountability_feedback
|
||||
WHERE task_list_id = #{taskListId}
|
||||
WHERE task_list_id = #{taskListId} AND delete_enum = 'FALSE'
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
<select id="listByTaskDetailId" resultType="com.zcloud.safetyDutyList.persistence.dataobject.tasklist.FeedbackDO">
|
||||
SELECT * FROM safety_accountability_feedback
|
||||
WHERE task_detail_id = #{taskDetailId}
|
||||
WHERE task_detail_id = #{taskDetailId} AND delete_enum = 'FALSE'
|
||||
ORDER BY feedback_time DESC
|
||||
</select>
|
||||
|
||||
|
|
@ -59,7 +60,7 @@
|
|||
LEFT JOIN user fb_user ON f.feedback_user_id = fb_user.id
|
||||
LEFT JOIN department fb_dept ON f.feedback_department_id = fb_dept.id
|
||||
LEFT JOIN corp_info fb_corp ON f.feedback_corp_id = fb_corp.id
|
||||
WHERE f.feedback_id = #{feedbackId}
|
||||
WHERE f.feedback_id = #{feedbackId} AND f.delete_enum = 'FALSE'
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
|
|
|||
Loading…
Reference in New Issue