package jnpf.limsService.impl;
|
|
import jnpf.audit.sdk.annotation.AuditLog;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import jnpf.exception.DataException;
|
import jnpf.limsEntity.LimsShebeiJiliangQijuEntity;
|
import jnpf.limsEntity.LimsShebeiYiqiQijuBaofeiEntity;
|
import jnpf.limsMapper.LimsShebeiJiliangQijuMapper;
|
import jnpf.limsMapper.LimsShebeiYiqiQijuBaofeiMapper;
|
import jnpf.limsService.LimsShebeiYiqiQijuBaofeiService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.List;
|
|
@Service
|
public class LimsShebeiYiqiQijuBaofeiServiceImpl implements LimsShebeiYiqiQijuBaofeiService {
|
|
private static final String BIZ_STATUS_YIBAOFEI = "yibaofei";
|
|
@Autowired
|
private LimsShebeiYiqiQijuBaofeiMapper qijuBaofeiMapper;
|
|
@Autowired
|
private LimsShebeiJiliangQijuMapper jiliangQijuMapper;
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
@AuditLog(action = "SCRAP", label = "器具报废", bizType = "SHEBEI_YIQI",
|
bizCodeExpr = "#flowId", bizCodeRequired = false, targetTable = "lims_shebei_yiqi_qiju",
|
targetIdExpr = "T(jnpf.limsService.support.LimsAuditTargetIds).qijuByScrapFlow(#flowId, #taskId)",
|
diff = true, entityClass = LimsShebeiJiliangQijuEntity.class)
|
public void baofeiQiju(String flowId, String taskId) throws DataException {
|
String resolvedFlowId = trimToEmpty(flowId);
|
String resolvedTaskId = trimToEmpty(taskId);
|
if (resolvedFlowId.isEmpty()) {
|
throw new DataException("流程ID(flow_id)不能为空");
|
}
|
if (resolvedTaskId.isEmpty()) {
|
throw new DataException("流程任务ID(task_id)不能为空");
|
}
|
|
LambdaQueryWrapper<LimsShebeiYiqiQijuBaofeiEntity> query = new LambdaQueryWrapper<>();
|
query.eq(LimsShebeiYiqiQijuBaofeiEntity::getFlowId, resolvedFlowId)
|
.eq(LimsShebeiYiqiQijuBaofeiEntity::getFlowTaskId, resolvedTaskId);
|
List<LimsShebeiYiqiQijuBaofeiEntity> baofeiList = qijuBaofeiMapper.selectList(query);
|
if (baofeiList.isEmpty()) {
|
throw new DataException("未找到关联的器具报废申请:flow_id=" + resolvedFlowId + ", task_id=" + resolvedTaskId);
|
}
|
if (baofeiList.size() > 1) {
|
throw new DataException("多个器具报废申请关联同一流程任务:task_id=" + resolvedTaskId);
|
}
|
|
String qijuId = trimToEmpty(baofeiList.get(0).getQijuId());
|
if (qijuId.isEmpty()) {
|
throw new DataException("器具报废申请未关联计量器具");
|
}
|
if (jiliangQijuMapper.selectById(qijuId) == null) {
|
throw new DataException("计量器具不存在:" + qijuId);
|
}
|
|
LambdaUpdateWrapper<LimsShebeiJiliangQijuEntity> update = new LambdaUpdateWrapper<>();
|
update.eq(LimsShebeiJiliangQijuEntity::getId, qijuId)
|
.set(LimsShebeiJiliangQijuEntity::getBizStatus, BIZ_STATUS_YIBAOFEI);
|
if (jiliangQijuMapper.update(null, update) != 1) {
|
throw new DataException("计量器具报废状态更新失败,请刷新后重试");
|
}
|
}
|
|
private String trimToEmpty(String value) {
|
return value == null ? "" : value.trim();
|
}
|
}
|