tuqin
2026-11-03 9494075e6d9d2a4b2b884b4ed740dee0c434734c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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;
    }
 
}