Commit 528d6f7f by 杨卫

feat: 检测提交时校验检测师

1 parent bba25fb2
......@@ -89,10 +89,11 @@ public class InspectionRecordService {
* </pre>
*
* @param req 保存请求
* @param inspector 当前登录的检测师
* @return 检测记录 ID
*/
@Transactional(propagation = Propagation.REQUIRED)
public Long saveInspection(InspectionSaveVO req) {
public Long saveInspection(InspectionSaveVO req, Inspector inspector) {
Long taskId = req.getTaskId();
String lockKey = StringUtils.templateFormat(InspectConstants.INSPECTION_LOCK_KEY, taskId);
......@@ -110,6 +111,11 @@ public class InspectionRecordService {
throw new BusinessCodeException(ErrorCodeEnum.NOT_ABLE_INSPECT);
}
// 校验检测师
if (!inspector.getId().equals(Optional.ofNullable(inspectionWorkOrder.getInspector()).map(Inspector::getId).orElse(null))) {
throw new BusinessCodeException(ErrorCodeEnum.NOT_CURR_WORK_INSPECTOR);
}
boolean nextFlag = BooleanUtil.isTrue(req.getNextFlag());
log.info("保存检测数据,taskId: {}, nextFlag: {}", taskId, nextFlag);
......@@ -406,10 +412,11 @@ public class InspectionRecordService {
* </pre>
*
* @param req 完成检测请求
* @param inspector 当前登录的检测师
* @return 第一个未完成的根节点 id,全部完成返回 null
*/
@Transactional(propagation = Propagation.REQUIRED)
public CompleteInspectionRespVO completeInspection(CompleteInspectionVO req) {
public CompleteInspectionRespVO completeInspection(CompleteInspectionVO req, Inspector inspector) {
Long taskId = req.getTaskId();
log.info("检测师完成检测,taskId: {}", taskId);
......@@ -429,6 +436,11 @@ public class InspectionRecordService {
}
InspectionTemplateDTO inspectionTemplateDTO = inspectionTemplateService.getTemplateByIdAndVersion(inspectionWorkOrder.getTemplateId(), inspectionWorkOrder.getTemplateVersion());
// 校验检测师
if (!inspector.getId().equals(Optional.ofNullable(inspectionWorkOrder.getInspector()).map(Inspector::getId).orElse(null))) {
throw new BusinessCodeException(ErrorCodeEnum.NOT_CURR_WORK_INSPECTOR);
}
// 1. 查询检测记录,不存在则新建
InspectionRecord record;
Optional<InspectionRecord> inspectionRecordOptional = inspectionRecordRepository.findByTaskIdAndDeletedFlag(taskId, DeleteFlag.NOT_DELETED.getCode());
......
......@@ -45,6 +45,8 @@ public enum ErrorCodeEnum {
NOT_ABLE_INSPECT(1001104, "当前工单无法提交检测"),
NODE_CHECK_RULE_ERROR(1001105, "【{0}】校验规则解析异常"),
NOT_CURR_WORK_INSPECTOR(1001106, "您不是当前工单的检测师,无法提交!")
;
private final Integer code;
private final String message;
......
......@@ -2,6 +2,8 @@ package com.glsx.usedcar.controller;
import cn.hutool.core.map.MapUtil;
import com.glsx.usedcar.annotation.RequireLogin;
import com.glsx.usedcar.context.InspectorContext;
import com.glsx.usedcar.module.inspect.entity.Inspector;
import com.glsx.usedcar.module.inspect.service.InspectionRecordService;
import com.glsx.usedcar.module.inspect.vo.CompleteInspectionRespVO;
import com.glsx.usedcar.module.inspect.vo.CompleteInspectionVO;
......@@ -16,9 +18,12 @@ import lombok.RequiredArgsConstructor;
import lombok.Value;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.summerframework.core.enums.ErrorCodeEnum;
import org.summerframework.core.exception.BusinessCodeException;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/**
* 检测记录前端控制器
......@@ -46,14 +51,18 @@ public class InspectionRecordController {
@PostMapping("/save")
@Operation(summary = "保存/下一步", description = "分步保存同一级的所有叶子节点数据,包括检测记录主表和检测值明细")
public BaseResp<Long> saveInspection(@RequestBody @Valid InspectionSaveVO req) {
Long recordId = inspectionRecordService.saveInspection(req);
Inspector inspector = Optional.ofNullable(InspectorContext.getInspector())
.orElseThrow(() -> new BusinessCodeException(ErrorCodeEnum.LOGIN_ERROR));
Long recordId = inspectionRecordService.saveInspection(req, inspector);
return BaseResp.success(recordId, "保存成功");
}
@PostMapping("/completeInspection")
@Operation(summary = "完成检测", description = "完成检测,全量检查所有必填选项")
public BaseResp<CompleteInspectionRespVO> completeInspection(@RequestBody @Valid CompleteInspectionVO req) {
return BaseResp.success(inspectionRecordService.completeInspection(req), "完成检测");
Inspector inspector = Optional.ofNullable(InspectorContext.getInspector())
.orElseThrow(() -> new BusinessCodeException(ErrorCodeEnum.LOGIN_ERROR));
return BaseResp.success(inspectionRecordService.completeInspection(req, inspector), "完成检测");
}
/**
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!