| | |
| | | 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.enums.StockOutQualifiedRecordTypeEnum; |
| | | 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.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 io.swagger.v3.oas.annotations.tags.Tag; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.List; |
| | | |
| | | @RestController |
| | | @RequestMapping("/shipmentApproval") |
| | | @Api(tags = "发货审批管理") |
| | | @Tag(name = "发货审批管理") |
| | | @AllArgsConstructor |
| | | public class ShipmentApprovalController extends BaseController { |
| | | |
| | | @Autowired |
| | | private ShipmentApprovalService shipmentApprovalService; |
| | | @Autowired |
| | | private ShipmentApprovalMapper shipmentApprovalMapper; |
| | | |
| | | @Autowired |
| | | private ISalesLedgerProductService salesLedgerProductService; |
| | | private final ShipmentApprovalService shipmentApprovalService; |
| | | private final ShipmentApprovalMapper shipmentApprovalMapper; |
| | | private final ISalesLedgerProductService salesLedgerProductService; |
| | | private final StockUtils stockUtils; |
| | | |
| | | @GetMapping("/listPage") |
| | | @ApiOperation("发货审批列表") |
| | | @Operation(summary = "发货审批列表") |
| | | public AjaxResult listPage(Page page, ShipmentApproval req) { |
| | | IPage<ShipmentApproval> listPage = shipmentApprovalService.listPage(page,req); |
| | | return AjaxResult.success(listPage); |
| | | } |
| | | |
| | | @PostMapping("/update") |
| | | @ApiOperation("发货审批,更新发货审批状态") |
| | | @Operation(summary = "发货审批,更新发货审批状态") |
| | | @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){ |
| | | SalesLedgerProduct salesLedgerProduct = salesLedgerProductService.getById(shipmentApproval.getSalesLedgerProductId()); |
| | | salesLedgerProduct.setApproveStatus(req.getApproveStatus()); |
| | | salesLedgerProductService.updateById(salesLedgerProduct); |
| | | if (!update) { |
| | | // 事务回滚 |
| | | throw new ServiceException("发货审批更新失败"); |
| | | } |
| | | return update ? AjaxResult.success() : AjaxResult.error(); |
| | | // 查询关联的销售台账产品 |
| | | 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(), StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode(), req.getId()); |
| | | } |
| | | |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 导出发货信息管理 |
| | | */ |
| | | @PostMapping("/export") |
| | | @ApiOperation("导出发货审批") |
| | | @Operation(summary = "导出发货审批") |
| | | public void export(HttpServletResponse response) { |
| | | List<ShipmentApproval> list = shipmentApprovalService.list(null); |
| | | List<ShipmentApproval> list = shipmentApprovalService.list(); |
| | | ExcelUtil<ShipmentApproval> util = new ExcelUtil<ShipmentApproval>(ShipmentApproval.class); |
| | | util.exportExcel(response, list, "发货审批"); |
| | | } |