| | |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.arrivalnotice.vo.MesWmArrivalNoticeSaveReqVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.arrivalnotice.MesWmArrivalNoticeDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.arrivalnotice.MesWmArrivalNoticeLineDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.returnvendor.MesWmReturnVendorDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.returnvendor.MesWmReturnVendorLineDO; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.wm.arrivalnotice.MesWmArrivalNoticeMapper; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.wm.returnvendor.MesWmReturnVendorLineMapper; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.wm.returnvendor.MesWmReturnVendorMapper; |
| | | import cn.iocoder.yudao.module.mes.enums.wm.MesWmArrivalNoticeStatusEnum; |
| | | import cn.iocoder.yudao.module.erp.api.purchase.ErpPurchaseOrderApi; |
| | | import cn.iocoder.yudao.module.srm.api.supplier.SrmSupplierApi; |
| | |
| | | import java.math.BigDecimal; |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*; |
| | |
| | | |
| | | @Resource |
| | | private MesWmArrivalNoticeLineService arrivalNoticeLineService; |
| | | |
| | | @Resource |
| | | private MesWmReturnVendorMapper returnVendorMapper; |
| | | @Resource |
| | | private MesWmReturnVendorLineMapper returnVendorLineMapper; |
| | | |
| | | @Resource |
| | | private SrmSupplierApi srmSupplierApi; |
| | |
| | | return notice.getId(); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Long createReplacementArrivalNotice(Long returnVendorId) { |
| | | // 1. 校验退货单 |
| | | MesWmReturnVendorDO returnVendor = returnVendorMapper.selectById(returnVendorId); |
| | | if (returnVendor == null) { |
| | | throw exception(WM_RETURN_VENDOR_NOT_EXISTS); |
| | | } |
| | | if (returnVendor.getPurchaseOrderId() == null) { |
| | | throw exception(WM_RETURN_VENDOR_PURCHASE_ORDER_REQUIRED); |
| | | } |
| | | List<MesWmReturnVendorLineDO> returnLines = returnVendorLineMapper.selectListByReturnId(returnVendorId); |
| | | if (CollUtil.isEmpty(returnLines)) { |
| | | throw exception(WM_RETURN_VENDOR_NO_LINE); |
| | | } |
| | | |
| | | // 2. 获取采购订单明细,用于按物料匹配采购订单明细编号(保证入库后能回写入库/退货数量) |
| | | Map<Long, Long> purchaseOrderItemIdMap = new HashMap<>(); |
| | | List<ErpPurchaseOrderItemRespDTO> orderItems = purchaseOrderApi |
| | | .getPurchaseOrderItemList(returnVendor.getPurchaseOrderId()).getCheckedData(); |
| | | if (CollUtil.isNotEmpty(orderItems)) { |
| | | orderItems.stream() |
| | | .filter(item -> item.getProductId() != null) |
| | | .forEach(item -> purchaseOrderItemIdMap.putIfAbsent(item.getProductId(), item.getId())); |
| | | } |
| | | |
| | | // 3. 创建到货通知单主表,状态直接置为待质检 |
| | | MesWmArrivalNoticeDO notice = new MesWmArrivalNoticeDO(); |
| | | notice.setCode(generateArrivalNoticeCode()); |
| | | notice.setName(returnVendor.getCode() + "换货到货"); |
| | | notice.setPurchaseOrderId(returnVendor.getPurchaseOrderId()); |
| | | notice.setPurchaseOrderCode(returnVendor.getPurchaseOrderCode()); |
| | | notice.setVendorId(returnVendor.getVendorId()); |
| | | notice.setArrivalDate(java.time.LocalDateTime.now()); |
| | | notice.setStatus(MesWmArrivalNoticeStatusEnum.PENDING_QC.getStatus()); |
| | | notice.setRemark("供应商退货单[" + returnVendor.getCode() + "]换货重新入库,合同号[" |
| | | + returnVendor.getContractNo() + "]"); |
| | | arrivalNoticeMapper.insert(notice); |
| | | |
| | | // 4. 遍历退货行创建到货通知单行,全部标记需要质检 |
| | | for (MesWmReturnVendorLineDO returnLine : returnLines) { |
| | | MesWmArrivalNoticeLineDO line = new MesWmArrivalNoticeLineDO(); |
| | | line.setNoticeId(notice.getId()); |
| | | line.setPurchaseOrderItemId(purchaseOrderItemIdMap.get(returnLine.getItemId())); |
| | | line.setItemId(returnLine.getItemId()); |
| | | line.setArrivalQuantity(returnLine.getQuantity()); |
| | | line.setIqcCheckFlag(true); |
| | | arrivalNoticeLineService.createArrivalNoticeLineFromPurchaseOrderItem(line); |
| | | } |
| | | |
| | | // 5. 逐行自动创建 IQC 检验单 |
| | | List<MesWmArrivalNoticeLineDO> lines = arrivalNoticeLineService.getArrivalNoticeLineListByNoticeId(notice.getId()); |
| | | for (MesWmArrivalNoticeLineDO line : lines) { |
| | | Long iqcId = iqcService.createIqcFromArrivalNotice( |
| | | notice.getId(), line, notice.getCode(), notice.getVendorId()); |
| | | arrivalNoticeLineService.updateArrivalNoticeLineIqcId(line.getId(), iqcId); |
| | | log.info("[createReplacementArrivalNotice][换货到货通知单({}) 行({}) 自动创建 IQC 检验单({})]", |
| | | notice.getId(), line.getId(), iqcId); |
| | | } |
| | | return notice.getId(); |
| | | } |
| | | |
| | | /** |
| | | * 生成到货通知单编码 |
| | | */ |