package jnpf.limsService.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import jnpf.audit.sdk.annotation.AuditLog;
|
import jnpf.exception.DataException;
|
import jnpf.limsEntity.LimsWendingxingXiaohuiShenqingEntity;
|
import jnpf.limsMapper.LimsWendingxingXiaohuiShenqingMapper;
|
import jnpf.limsService.LimsWendingxingXiaohuiShenqingService;
|
import jnpf.limsService.support.LimsWendingxingXiaohuiFlowStatusResolver;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.util.StringUtils;
|
|
import java.util.List;
|
import java.util.Objects;
|
|
@Service
|
public class LimsWendingxingXiaohuiShenqingServiceImpl
|
implements LimsWendingxingXiaohuiShenqingService {
|
|
@Autowired
|
private LimsWendingxingXiaohuiShenqingMapper xiaohuiShenqingMapper;
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
@AuditLog(action = "FLOW_START", label = "稳定性销毁流程发起", bizType = "WENDINGXING",
|
bizCodeExpr = "#flowId", bizCodeRequired = false,
|
targetTable = "lims_wendingxing_xiaohui_shenqing",
|
targetIdExpr = "T(jnpf.limsService.support.LimsAuditTargetIds).wendingxingDestroyByFlow(#flowId, #taskId)",
|
diff = true, entityClass = LimsWendingxingXiaohuiShenqingEntity.class)
|
public void syncFlowStarted(String flowId, String taskId) throws DataException {
|
LimsWendingxingXiaohuiShenqingEntity shenqing = findByFlow(flowId, taskId);
|
if (LimsWendingxingXiaohuiFlowStatusResolver.COMPLETED.equals(shenqing.getBizStatus())) {
|
return;
|
}
|
updateBizStatus(shenqing, LimsWendingxingXiaohuiFlowStatusResolver.PROCESSING);
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
@AuditLog(action = "FLOW_END", label = "稳定性销毁流程结束", bizType = "WENDINGXING",
|
bizCodeExpr = "#flowId", bizCodeRequired = false,
|
targetTable = "lims_wendingxing_xiaohui_shenqing",
|
targetIdExpr = "T(jnpf.limsService.support.LimsAuditTargetIds).wendingxingDestroyByFlow(#flowId, #taskId)",
|
diff = true, entityClass = LimsWendingxingXiaohuiShenqingEntity.class)
|
public void syncFlowEnded(String flowId, String taskId, Integer flowState) throws DataException {
|
if (!LimsWendingxingXiaohuiFlowStatusResolver.isTerminal(flowState)) {
|
throw new DataException("流程尚未结束,当前状态:" + flowState);
|
}
|
LimsWendingxingXiaohuiShenqingEntity shenqing = findByFlow(flowId, taskId);
|
updateBizStatus(shenqing, LimsWendingxingXiaohuiFlowStatusResolver.COMPLETED);
|
}
|
|
private LimsWendingxingXiaohuiShenqingEntity findByFlow(String flowId, String taskId)
|
throws DataException {
|
String resolvedFlowId = trimToEmpty(flowId);
|
String resolvedTaskId = trimToEmpty(taskId);
|
if (!StringUtils.hasText(resolvedFlowId)) {
|
throw new DataException("流程id(flow_id)不能为空");
|
}
|
if (!StringUtils.hasText(resolvedTaskId)) {
|
throw new DataException("流程任务id(task_id)不能为空");
|
}
|
|
LambdaQueryWrapper<LimsWendingxingXiaohuiShenqingEntity> query = new LambdaQueryWrapper<>();
|
query.eq(LimsWendingxingXiaohuiShenqingEntity::getFFlowId, resolvedFlowId)
|
.eq(LimsWendingxingXiaohuiShenqingEntity::getFFlowTaskId, resolvedTaskId)
|
.and(w -> w.isNull(LimsWendingxingXiaohuiShenqingEntity::getFDeleteMark)
|
.or()
|
.ne(LimsWendingxingXiaohuiShenqingEntity::getFDeleteMark, 1));
|
List<LimsWendingxingXiaohuiShenqingEntity> list = xiaohuiShenqingMapper.selectList(query);
|
if (list == null || list.isEmpty()) {
|
throw new DataException("稳定性销毁申请不存在:flow_id=" + resolvedFlowId
|
+ ", task_id=" + resolvedTaskId);
|
}
|
if (list.size() > 1) {
|
throw new DataException("多个稳定性销毁申请关联同一流程任务:task_id=" + resolvedTaskId);
|
}
|
return list.get(0);
|
}
|
|
private void updateBizStatus(LimsWendingxingXiaohuiShenqingEntity shenqing, String targetStatus)
|
throws DataException {
|
if (Objects.equals(shenqing.getBizStatus(), targetStatus)) {
|
return;
|
}
|
LambdaUpdateWrapper<LimsWendingxingXiaohuiShenqingEntity> update = new LambdaUpdateWrapper<>();
|
update.eq(LimsWendingxingXiaohuiShenqingEntity::getId, shenqing.getId())
|
.eq(LimsWendingxingXiaohuiShenqingEntity::getFTenantId, shenqing.getFTenantId())
|
.and(w -> w.isNull(LimsWendingxingXiaohuiShenqingEntity::getFDeleteMark)
|
.or()
|
.ne(LimsWendingxingXiaohuiShenqingEntity::getFDeleteMark, 1))
|
.set(LimsWendingxingXiaohuiShenqingEntity::getBizStatus, targetStatus);
|
if (xiaohuiShenqingMapper.update(null, update) != 1) {
|
throw new DataException("稳定性销毁申请状态更新失败,请刷新后重试");
|
}
|
}
|
|
private String trimToEmpty(String value) {
|
return value == null ? "" : value.trim();
|
}
|
}
|