|
|
|
@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import com.xujie.common.exception.XJException; |
|
|
|
import com.xujie.common.utils.*; |
|
|
|
import com.xujie.modules.inspection.data.MyInspectionListVO; |
|
|
|
import com.xujie.modules.inspection.entity.InspectionRequestDetail; |
|
|
|
import com.xujie.modules.inspection.mapper.InspectionRequestDetailMapper; |
|
|
|
import com.xujie.modules.inspection.mapper.InspectionRequestHeaderMapper; |
|
|
|
import com.xujie.modules.qms.data.PartData; |
|
|
|
@ -3675,41 +3676,80 @@ public class QcServiceImpl implements QcService { |
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public void iqcRecordDelete(QcFAIRecordData data) { |
|
|
|
String state = data.getSubmitList().get(0).getState(); |
|
|
|
// 判断状态是否一致 |
|
|
|
boolean bool = data.getSubmitList().stream().anyMatch(a -> !state.equals(a.getState())); |
|
|
|
if (bool) { |
|
|
|
|
|
|
|
List<QcFAIRecordData> list = data.getSubmitList(); |
|
|
|
if (list == null || list.isEmpty()) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// 1. 校验状态一致性 |
|
|
|
String firstState = list.get(0).getState(); |
|
|
|
boolean inconsistent = list.stream() |
|
|
|
.anyMatch(a -> !Objects.equals(firstState, a.getState())); |
|
|
|
|
|
|
|
if (inconsistent) { |
|
|
|
throw new RuntimeException("所选检验单状态不一致,请确认!"); |
|
|
|
} |
|
|
|
for (QcFAIRecordData qcData : data.getSubmitList()){ |
|
|
|
// 判断状态 |
|
|
|
|
|
|
|
// 2. 循环处理删除 |
|
|
|
for (QcFAIRecordData qcData : list) { |
|
|
|
|
|
|
|
// 状态校验 |
|
|
|
if ("已完成".equals(qcData.getState())) { |
|
|
|
throw new RuntimeException("检验单已完成,不允许删除!"); |
|
|
|
} |
|
|
|
|
|
|
|
// 回滚验货申请明细:清空inspect_no并更新状态为已排程 |
|
|
|
|
|
|
|
// ===== 回滚逻辑 ===== |
|
|
|
if (qcData.getPoOrderNo() != null && qcData.getPoItemNo() != null) { |
|
|
|
|
|
|
|
try { |
|
|
|
Integer poItemNo = Integer.parseInt(qcData.getPoItemNo()); |
|
|
|
Integer poItemNo = Integer.valueOf(qcData.getPoItemNo()); |
|
|
|
// 回滚明细 |
|
|
|
inspectionRequestDetailMapper.rollbackInspectRequestDetail( |
|
|
|
qcData.getSite(), |
|
|
|
qcData.getPoOrderNo(), |
|
|
|
poItemNo |
|
|
|
); |
|
|
|
|
|
|
|
// 查询明细 |
|
|
|
List<InspectionRequestDetail> detailList = |
|
|
|
inspectionRequestDetailMapper.selectList( |
|
|
|
new LambdaQueryWrapper<InspectionRequestDetail>() |
|
|
|
.eq(InspectionRequestDetail::getSite, qcData.getSite()) |
|
|
|
.eq(InspectionRequestDetail::getRequestNo, qcData.getPoOrderNo()) |
|
|
|
); |
|
|
|
|
|
|
|
// 判断是否全部 Scheduled |
|
|
|
boolean allScheduled = detailList.stream() |
|
|
|
.allMatch(d -> "Scheduled".equals(d.getStatusDb())); |
|
|
|
|
|
|
|
// 更新主表 |
|
|
|
if (allScheduled) { |
|
|
|
log.info("所有明细已回滚为Scheduled,更新主单: {}", qcData.getPoOrderNo()); |
|
|
|
|
|
|
|
int count = inspectionRequestHeaderMapper.rollbackHeaderToScheduled( |
|
|
|
qcData.getSite(), |
|
|
|
qcData.getPoOrderNo() |
|
|
|
); |
|
|
|
|
|
|
|
if (count == 0) { |
|
|
|
throw new RuntimeException("更新主记录状态失败"); |
|
|
|
} |
|
|
|
} else { |
|
|
|
log.info("存在未回滚明细,不更新主单: {}, size={}", |
|
|
|
qcData.getPoOrderNo(), detailList.size()); |
|
|
|
} |
|
|
|
|
|
|
|
} catch (NumberFormatException e) { |
|
|
|
// poItemNo格式错误时忽略,继续执行删除逻辑 |
|
|
|
throw new RuntimeException("PO行号格式错误: " + qcData.getPoItemNo(), e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 删除检验记录 |
|
|
|
|
|
|
|
// ===== 删除业务数据 ===== |
|
|
|
qcMapper.deleteIQCRecord(qcData); |
|
|
|
// 删除明细记录信息 |
|
|
|
qcMapper.deleteIQCDetailedRecord(qcData); |
|
|
|
// 删除子明细记录信息 |
|
|
|
qcMapper.deleteIQCSubDetailedRecord(qcData); |
|
|
|
// 删除数据采集的数据 |
|
|
|
qcMapper.deleteEquipmentDataAcquisition(qcData); |
|
|
|
// 删除文件 |
|
|
|
qcMapper.deleteInspectionFiles(qcData); |
|
|
|
} |
|
|
|
} |
|
|
|
|