package jnpf.limsController; import cn.dev33.satoken.annotation.SaCheckLogin; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jnpf.exception.DataException; import jnpf.flowable.WorkFlowApi; import jnpf.flowable.entity.TaskEntity; import jnpf.limsEntity.LimsSxtFlowEventParam; import jnpf.limsService.LimsSxtJihuaService; import jnpf.util.R; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** * 工作流节点事件接口。站内数据接口会透传流程操作者令牌,故不允许匿名调用。 */ @Slf4j @Tag(name = "水系统计划流程事件", description = "") @RestController @SaCheckLogin @RequestMapping("/lims/biz/sxt/flow-status") public class LimsSxtFlowStatusController { @Autowired private LimsSxtJihuaService jihuaService; @Autowired private WorkFlowApi workFlowApi; @Operation(summary = "水系统计划流程发起事件") @PostMapping("/start") public R syncFlowStarted(@RequestBody LimsSxtFlowEventParam param) { String validationMessage = validateFlowEventParam(param); if (validationMessage != null) { return R.error(validationMessage); } try { jihuaService.syncFlowStarted(param.getFlowId(), param.getTaskId()); return R.success(); } catch (DataException e) { log.warn("水系统流程发起状态同步失败,flowId={}, taskId={}", param.getFlowId(), param.getTaskId(), e); return R.error(e.getMessage()); } } @Operation(summary = "水系统计划流程结束事件") @PostMapping("/end") public R syncFlowEnded(@RequestBody LimsSxtFlowEventParam param) { String validationMessage = validateFlowEventParam(param); if (validationMessage != null) { return R.error(validationMessage); } TaskEntity task = workFlowApi.getInfoSubmit(param.getTaskId()); if (task == null) { return R.error("未找到流程任务:" + param.getTaskId()); } if (!param.getTaskId().equals(task.getId())) { return R.error("流程任务与传入任务ID不匹配"); } try { jihuaService.syncFlowEnded(param.getFlowId(), param.getTaskId(), task.getStatus()); return R.success(); } catch (DataException e) { log.warn("水系统流程结束状态同步失败,flowId={}, taskId={}, status={}", param.getFlowId(), param.getTaskId(), task.getStatus(), e); return R.error(e.getMessage()); } } private String validateFlowEventParam(LimsSxtFlowEventParam param) { if (param == null) { return "请求参数不能为空"; } if (!StringUtils.hasText(param.getFlowId())) { return "流程id(flow_id)不能为空"; } if (!StringUtils.hasText(param.getTaskId())) { return "流程任务id(task_id)不能为空"; } return null; } }