|
|
|
@ -2,6 +2,7 @@ package com.gaotao.modules.inspection.service.impl; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.gaotao.modules.inspection.entity.QualifiedInspectionDto; |
|
|
|
import com.gaotao.modules.inspection.entity.UnqualifiedInspectionDto; |
|
|
|
import com.gaotao.modules.inspection.entity.InboundConfirmDto; |
|
|
|
import com.gaotao.modules.inspection.service.InspectionInboundService; |
|
|
|
import com.gaotao.modules.po.entity.PoReceipt; |
|
|
|
@ -27,10 +28,14 @@ import java.math.BigDecimal; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
@Service |
|
|
|
public class InspectionInboundServiceImpl implements InspectionInboundService { |
|
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(InspectionInboundServiceImpl.class); |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private TransHeaderService transHeaderService; |
|
|
|
|
|
|
|
@ -323,4 +328,164 @@ public class InspectionInboundServiceImpl implements InspectionInboundService { |
|
|
|
.update(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<UnqualifiedInspectionDto> getUnqualifiedInspectionList(UnqualifiedInspectionDto unqualifiedInspectionDto) { |
|
|
|
// 查询po_receipt_detail表中所有不合格状态的记录 |
|
|
|
QueryWrapper<PoReceiptDetail> detailWrapper = new QueryWrapper<>(); |
|
|
|
|
|
|
|
// 查询所有不合格状态 |
|
|
|
detailWrapper.in("status", "RETCREDIT", "RETWORK", "INVSCRAP", "SCPCREDIT", "EXCHANGE", "REWORK"); |
|
|
|
|
|
|
|
if (unqualifiedInspectionDto.getSite() != null) { |
|
|
|
detailWrapper.eq("site", unqualifiedInspectionDto.getSite()); |
|
|
|
} |
|
|
|
|
|
|
|
// 支持根据接收单号或采购单号查找 |
|
|
|
if (unqualifiedInspectionDto.getTransNo() != null) { |
|
|
|
detailWrapper.and(wrapper -> wrapper |
|
|
|
.eq("receipt_no", unqualifiedInspectionDto.getTransNo()) // 接收单号 |
|
|
|
.or() |
|
|
|
.eq("order_no", unqualifiedInspectionDto.getTransNo()) // 采购单号 |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
detailWrapper.orderByDesc("receipt_no"); |
|
|
|
|
|
|
|
List<PoReceiptDetail> details = poReceiptDetailService.list(detailWrapper); |
|
|
|
List<UnqualifiedInspectionDto> result = new ArrayList<>(); |
|
|
|
|
|
|
|
for (PoReceiptDetail detail : details) { |
|
|
|
// 获取对应的接收单主记录 |
|
|
|
QueryWrapper<PoReceipt> receiptWrapper = new QueryWrapper<>(); |
|
|
|
receiptWrapper.eq("site", detail.getSite()); |
|
|
|
receiptWrapper.eq("receipt_no", detail.getReceiptNo()); |
|
|
|
PoReceipt receipt = poReceiptService.getOne(receiptWrapper); |
|
|
|
|
|
|
|
if (receipt != null) { |
|
|
|
String status = detail.getStatus(); |
|
|
|
String processType = mapStatusToProcessType(status); |
|
|
|
BigDecimal unqualifiedQty = getUnqualifiedQtyByStatus(detail, status); |
|
|
|
|
|
|
|
// 只有数量大于0的记录才添加到结果中 |
|
|
|
if (unqualifiedQty != null && unqualifiedQty.compareTo(BigDecimal.ZERO) > 0) { |
|
|
|
UnqualifiedInspectionDto dto = new UnqualifiedInspectionDto(); |
|
|
|
dto.setSite(detail.getSite()); |
|
|
|
dto.setTransNo(detail.getReceiptNo()); // 使用接收单号作为事务号 |
|
|
|
dto.setItemNo(String.valueOf(detail.getItemNo())); |
|
|
|
dto.setPartNo(detail.getPartNo()); |
|
|
|
dto.setPartDesc(detail.getPartDesc()); |
|
|
|
dto.setTransQty(detail.getArriveQty()); |
|
|
|
dto.setUnqualifiedQty(unqualifiedQty); // 根据状态获取对应的数量 |
|
|
|
dto.setBatchNo(detail.getBatchNo()); |
|
|
|
dto.setLocationId(detail.getLocationId()); |
|
|
|
dto.setWarehouseId(receipt.getWarehouseId()); |
|
|
|
dto.setOrderRef1(detail.getOrderNo()); // 采购单号 |
|
|
|
dto.setOrderRef2(""); |
|
|
|
dto.setOrderRef3(""); |
|
|
|
dto.setTransDate(receipt.getReceiveDate()); |
|
|
|
dto.setInspectionDate(detail.getInspectionTime()); |
|
|
|
dto.setInspectionUser(detail.getInspector()); |
|
|
|
dto.setStatus(status); // 原始状态 |
|
|
|
dto.setUserName(receipt.getReceiver()); |
|
|
|
dto.setRemark(receipt.getRemark()); |
|
|
|
dto.setProcessType(processType); // 处理类型 |
|
|
|
|
|
|
|
result.add(dto); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据状态获取对应的不合格数量 |
|
|
|
*/ |
|
|
|
private BigDecimal getUnqualifiedQtyByStatus(PoReceiptDetail detail, String status) { |
|
|
|
if (status == null) { |
|
|
|
return BigDecimal.ZERO; |
|
|
|
} |
|
|
|
|
|
|
|
switch (status) { |
|
|
|
case "RETCREDIT": |
|
|
|
case "RETWORK": |
|
|
|
// 退货数量 |
|
|
|
return detail.getQtyReturned() != null ? detail.getQtyReturned() : BigDecimal.ZERO; |
|
|
|
case "INVSCRAP": |
|
|
|
case "SCPCREDIT": |
|
|
|
// 报废数量 |
|
|
|
return detail.getQtyScrapt()!= null ? detail.getQtyScrapt() : BigDecimal.ZERO; |
|
|
|
case "EXCHANGE": |
|
|
|
case "REWORK": |
|
|
|
// 换货/返工数量 - 可能需要根据实际字段调整 |
|
|
|
return detail.getQtyReplace() != null ? detail.getQtyReplace() : BigDecimal.ZERO; |
|
|
|
default: |
|
|
|
return BigDecimal.ZERO; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据状态映射处理类型 |
|
|
|
*/ |
|
|
|
private String mapStatusToProcessType(String status) { |
|
|
|
if (status == null) { |
|
|
|
return "UNKNOWN"; |
|
|
|
} |
|
|
|
|
|
|
|
switch (status) { |
|
|
|
case "RETWORK": |
|
|
|
return "RETURN"; // 退货 |
|
|
|
case "INVSCRAP": |
|
|
|
case "SCPCREDIT": |
|
|
|
return "SCRAP"; // 报废 |
|
|
|
case "EXCHANGE": |
|
|
|
case "REWORK": |
|
|
|
case "RETCREDIT": |
|
|
|
return "EXCHANGE"; // 换货 |
|
|
|
default: |
|
|
|
return "UNKNOWN"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public void confirmUnqualifiedProcess(String transNo, String processType, List<String> handlingUnitIds) { |
|
|
|
try { |
|
|
|
// 1. 更新HandlingUnit状态为失效 |
|
|
|
if (handlingUnitIds != null && !handlingUnitIds.isEmpty()) { |
|
|
|
QueryWrapper<HandlingUnit> huWrapper = new QueryWrapper<>(); |
|
|
|
huWrapper.in("unit_id", handlingUnitIds); |
|
|
|
|
|
|
|
HandlingUnit huUpdate = new HandlingUnit(); |
|
|
|
huUpdate.setStatus("INVALID"); // 设置为失效状态 |
|
|
|
huUpdate.setModifiedDate(new Date()); |
|
|
|
|
|
|
|
boolean huResult = handlingUnitService.update(huUpdate, huWrapper); |
|
|
|
if (!huResult) { |
|
|
|
throw new RuntimeException("更新HandlingUnit状态失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 2. 更新PoReceiptDetail状态为已处理 |
|
|
|
QueryWrapper<PoReceiptDetail> detailWrapper = new QueryWrapper<>(); |
|
|
|
detailWrapper.eq("receipt_no", transNo); |
|
|
|
|
|
|
|
PoReceiptDetail detailUpdate = new PoReceiptDetail(); |
|
|
|
detailUpdate.setStatus("PROCESSED"); // 设置为已处理状态 |
|
|
|
//detailUpdate.setUpdateTime(new Date()); |
|
|
|
|
|
|
|
boolean detailResult = poReceiptDetailService.update(detailUpdate, detailWrapper); |
|
|
|
if (!detailResult) { |
|
|
|
throw new RuntimeException("更新接收单详情状态失败"); |
|
|
|
} |
|
|
|
|
|
|
|
log.info("不合格处理确认成功 - 单据号: {}, 处理类型: {}, HandlingUnit数量: {}", |
|
|
|
transNo, processType, handlingUnitIds != null ? handlingUnitIds.size() : 0); |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
log.error("确认不合格处理失败 - 单据号: {}, 错误: {}", transNo, e.getMessage(), e); |
|
|
|
throw new RuntimeException("确认不合格处理失败: " + e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |