package cn.iocoder.yudao.module.mes.api.productsales;
|
|
import cn.iocoder.yudao.module.mes.api.productsales.dto.MesWmProductSalesOutboundReqDTO;
|
import cn.iocoder.yudao.module.mes.controller.admin.wm.productsales.vo.MesWmProductSalesSaveReqVO;
|
import cn.iocoder.yudao.module.mes.controller.admin.wm.productsales.vo.MesWmProductSalesShippingReqVO;
|
import cn.iocoder.yudao.module.mes.controller.admin.wm.productsales.vo.detail.MesWmProductSalesDetailSaveReqVO;
|
import cn.iocoder.yudao.module.mes.controller.admin.wm.productsales.vo.line.MesWmProductSalesLineSaveReqVO;
|
import cn.iocoder.yudao.module.mes.service.wm.productsales.MesWmProductSalesDetailService;
|
import cn.iocoder.yudao.module.mes.service.wm.productsales.MesWmProductSalesLineService;
|
import cn.iocoder.yudao.module.mes.service.wm.productsales.MesWmProductSalesService;
|
import jakarta.annotation.Resource;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.validation.annotation.Validated;
|
|
/**
|
* MES 成品出库单 API 实现类
|
*
|
* @author mom
|
*/
|
@Service
|
@Validated
|
public class MesWmProductSalesApiImpl implements MesWmProductSalesApi {
|
|
@Resource
|
private MesWmProductSalesService productSalesService;
|
@Resource
|
private MesWmProductSalesLineService productSalesLineService;
|
@Resource
|
private MesWmProductSalesDetailService productSalesDetailService;
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public Long createAndFinishProductSales(MesWmProductSalesOutboundReqDTO reqDTO) {
|
// 1. 建单
|
MesWmProductSalesSaveReqVO createReqVO = new MesWmProductSalesSaveReqVO();
|
createReqVO.setCode(reqDTO.getCode());
|
createReqVO.setName(reqDTO.getName());
|
createReqVO.setClientId(reqDTO.getClientId());
|
createReqVO.setSalesDate(reqDTO.getSalesDate());
|
createReqVO.setCarrier(reqDTO.getCarrier());
|
createReqVO.setShippingNumber(reqDTO.getShippingNumber());
|
createReqVO.setRemark(reqDTO.getRemark());
|
Long salesId = productSalesService.createProductSales(createReqVO);
|
|
// 2. 逐条写入「行 + 明细」(oqcCheckFlag=false,避免进入待检验分支)
|
for (MesWmProductSalesOutboundReqDTO.Line line : reqDTO.getLines()) {
|
MesWmProductSalesLineSaveReqVO lineVO = new MesWmProductSalesLineSaveReqVO();
|
lineVO.setSalesId(salesId);
|
lineVO.setItemId(line.getItemId());
|
lineVO.setQuantity(line.getQuantity());
|
lineVO.setBatchId(line.getBatchId());
|
lineVO.setBatchCode(line.getBatchCode());
|
lineVO.setOqcCheckFlag(Boolean.FALSE);
|
Long lineId = productSalesLineService.createProductSalesLine(lineVO);
|
|
MesWmProductSalesDetailSaveReqVO detailVO = new MesWmProductSalesDetailSaveReqVO();
|
detailVO.setLineId(lineId);
|
detailVO.setSalesId(salesId);
|
detailVO.setItemId(line.getItemId());
|
detailVO.setQuantity(line.getQuantity());
|
detailVO.setMaterialStockId(line.getMaterialStockId());
|
detailVO.setWarehouseId(line.getWarehouseId());
|
detailVO.setBatchId(line.getBatchId());
|
detailVO.setBatchCode(line.getBatchCode());
|
detailVO.setLocationId(line.getLocationId());
|
detailVO.setAreaId(line.getAreaId());
|
productSalesDetailService.createProductSalesDetail(detailVO);
|
}
|
|
// 3. 状态机:提交 → 拣货 → 填写运单 → 执行出库(扣库存)
|
productSalesService.submitProductSales(salesId);
|
productSalesService.stockProductSales(salesId);
|
MesWmProductSalesShippingReqVO shippingVO = new MesWmProductSalesShippingReqVO();
|
shippingVO.setId(salesId);
|
shippingVO.setCarrier(reqDTO.getCarrier());
|
shippingVO.setShippingNumber(reqDTO.getShippingNumber());
|
productSalesService.shippingProductSales(shippingVO);
|
productSalesService.finishProductSales(salesId);
|
return salesId;
|
}
|
|
}
|