liyong
5 小时以前 1cf91e355038837f30f2d727507b2229263d7de7
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package com.ruoyi.sales.controller;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.math.LongMath;
import com.ruoyi.common.enums.StockQualifiedRecordTypeEnum;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.procurementrecord.dto.ProcurementAddDto;
import com.ruoyi.procurementrecord.dto.ProcurementRecordOutAdd;
import com.ruoyi.procurementrecord.pojo.ProcurementRecordOut;
import com.ruoyi.procurementrecord.pojo.ProcurementRecordStorage;
import com.ruoyi.procurementrecord.service.ProcurementRecordOutService;
import com.ruoyi.procurementrecord.service.ProcurementRecordService;
import com.ruoyi.procurementrecord.utils.StockUtils;
import com.ruoyi.sales.mapper.ShipmentApprovalMapper;
import com.ruoyi.sales.mapper.ShippingInfoMapper;
import com.ruoyi.sales.pojo.SalesLedgerProduct;
import com.ruoyi.sales.pojo.ShipmentApproval;
import com.ruoyi.sales.pojo.ShippingInfo;
import com.ruoyi.sales.service.ISalesLedgerProductService;
import com.ruoyi.sales.service.ShipmentApprovalService;
import com.ruoyi.sales.service.ShippingInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
 
@RestController
@RequestMapping("/shipmentApproval")
@Api(tags = "发货审批管理")
public class ShipmentApprovalController extends BaseController {
 
    @Autowired
    private ShipmentApprovalService shipmentApprovalService;
    @Autowired
    private ShipmentApprovalMapper shipmentApprovalMapper;
 
    @Autowired
    private ISalesLedgerProductService salesLedgerProductService;
    @Autowired
    private StockUtils stockUtils;
 
    @GetMapping("/listPage")
    @ApiOperation("发货审批列表")
    public AjaxResult listPage(Page page, ShipmentApproval req) {
        IPage<ShipmentApproval> listPage = shipmentApprovalService.listPage(page,req);
        return AjaxResult.success(listPage);
    }
 
    @PostMapping("/update")
    @ApiOperation("发货审批,更新发货审批状态")
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult update(@RequestBody ShipmentApproval req) {
 
        //  查询发货审批
        ShipmentApproval shipmentApproval = shipmentApprovalMapper.selectById(req.getId());
        if (shipmentApproval == null) {
            return AjaxResult.error("发货审批不存在");
        }
 
        //  更新发货审批状态
        shipmentApproval.setApproveStatus(req.getApproveStatus());
        boolean update = shipmentApprovalService.updateById(shipmentApproval);
        if (!update) {
            //  事务回滚
            throw new ServiceException("发货审批更新失败");
        }
        //  查询关联的销售台账产品
        SalesLedgerProduct salesLedgerProduct = salesLedgerProductService.getById(shipmentApproval.getSalesLedgerProductId());
        if (salesLedgerProduct == null) {
            //  抛异常事务回滚
            throw new ServiceException("销售台账不存在,审批回滚");
        }
 
        //  同步更新销售台账产品的审批状态
        salesLedgerProduct.setApproveStatus(req.getApproveStatus());
        salesLedgerProductService.updateById(salesLedgerProduct);
 
        //  审批通过
        if (req.getApproveStatus() == 3) {
//            // 查询采购入库记录
//            LambdaQueryWrapper<ProcurementRecordStorage> lambdaQueryWrapper = new LambdaQueryWrapper<ProcurementRecordStorage>()
//                    .eq(ProcurementRecordStorage::getSalesLedgerProductId, req.getSalesLedgerProductId());
//            ProcurementRecordStorage procurementRecordStorage = procurementRecordStorageService.getOne(lambdaQueryWrapper);
//
//            if (procurementRecordStorage == null) {
//                // 保证前面的修改全部回滚
//                throw new ServiceException("采购记录不存在,审批回滚");
//            }
 
 
            //出库
            stockUtils.addStock(salesLedgerProduct.getProductModelId(), salesLedgerProduct.getQuantity(), StockQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode(), req.getId());
        }
 
        return AjaxResult.success();
    }
 
 
 
    /**
     * 导出发货信息管理
     */
    @PostMapping("/export")
    @ApiOperation("导出发货审批")
    public void export(HttpServletResponse response) {
        List<ShipmentApproval> list = shipmentApprovalService.list(null);
        ExcelUtil<ShipmentApproval> util = new ExcelUtil<ShipmentApproval>(ShipmentApproval.class);
        util.exportExcel(response, list, "发货审批");
    }
 
}