src/main/java/com/ruoyi/sales/controller/ShippingInfoController.java
@@ -1,5 +1,6 @@
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.ruoyi.common.utils.poi.ExcelUtil;
@@ -7,13 +8,19 @@
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.sales.mapper.ShipmentApprovalMapper;
import com.ruoyi.sales.mapper.ShippingInfoMapper;
import com.ruoyi.sales.pojo.SalesLedger;
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.ISalesLedgerService;
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;
@@ -30,6 +37,10 @@
    @Autowired
    private ShippingInfoService shippingInfoService;
    @Autowired
    private ShipmentApprovalMapper shipmentApprovalMapper;
    @Autowired
    private ISalesLedgerProductService salesLedgerProductService;
    @GetMapping("/listPage")
@@ -41,8 +52,32 @@
    @PostMapping("/add")
    @ApiOperation("添加发货信息")
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult add(@RequestBody ShippingInfo req) {
        boolean save = shippingInfoService.save(req);
        if(save){
            LambdaQueryWrapper<ShippingInfo> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(ShippingInfo::getSalesLedgerId, req.getSalesLedgerId());
            wrapper.eq(ShippingInfo::getSalesLedgerProductId, req.getSalesLedgerProductId());
            ShippingInfo shippingInfo = shippingInfoService.getOne(wrapper);
            if(shippingInfo == null){
                return AjaxResult.error("发货信息不存在");
            }
            ShipmentApproval shipmentApproval = new ShipmentApproval();
            shipmentApproval.setSalesLedgerId(req.getSalesLedgerId());
            shipmentApproval.setSalesLedgerProductId(req.getSalesLedgerProductId());
            shipmentApproval.setApproveUserId(req.getApproverId());
            shipmentApproval.setApproveStatus(2);
            shipmentApproval.setShippingInfoId(shippingInfo.getId());
            shipmentApprovalMapper.insert(shipmentApproval);
            SalesLedgerProduct salesLedgerProduct = salesLedgerProductService.getById(req.getSalesLedgerProductId());
            if(salesLedgerProduct != null){
                salesLedgerProduct.setApproveStatus(2);
                salesLedgerProductService.updateById(salesLedgerProduct);
            }
        }
        return save ? AjaxResult.success() : AjaxResult.error();
    }