| | |
| | | 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.exception.ServiceException; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.framework.web.controller.BaseController; |
| | | import com.ruoyi.framework.web.domain.AjaxResult; |
| | |
| | | @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){ |
| | | SalesLedgerProduct salesLedgerProduct = salesLedgerProductService.getById(shipmentApproval.getSalesLedgerProductId()); |
| | | salesLedgerProduct.setApproveStatus(req.getApproveStatus()); |
| | | salesLedgerProductService.updateById(salesLedgerProduct); |
| | | |
| | | if(req.getApproveStatus()==3){ |
| | | ProcurementRecordStorage procurementRecordStorage = procurementRecordStorageService.getOne(new LambdaQueryWrapper<ProcurementRecordStorage>() |
| | | .eq(ProcurementRecordStorage::getSalesLedgerProductId, req.getSalesLedgerProductId())); |
| | | if(procurementRecordStorage==null){ |
| | | return AjaxResult.error("采购记录不存在"); |
| | | } |
| | | //发货审批通过,生产该订单出库记录 |
| | | ProcurementRecordOutAdd procurementRecordOutAdd = new ProcurementRecordOutAdd(); |
| | | procurementRecordOutAdd.setId(procurementRecordStorage.getId()); |
| | | procurementRecordOutAdd.setSalesLedgerProductId(Math.toIntExact(salesLedgerProduct.getId())); |
| | | procurementRecordOutAdd.setType(2); |
| | | procurementRecordOutAdd.setUserId(Math.toIntExact(getUserId())); |
| | | procurementRecordOutAdd.setQuantity(String.valueOf(salesLedgerProduct.getQuantity())); |
| | | //获取当前时间 |
| | | LocalDate now = LocalDate.now(); |
| | | procurementRecordOutAdd.setTime(now.toString()); |
| | | procurementRecordOutService.stockout(procurementRecordOutAdd); |
| | | } |
| | | 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("采购记录不存在,审批回滚"); |
| | | } |
| | | |
| | | // 生成出库记录 |
| | | ProcurementRecordOutAdd procurementRecordOutAdd = new ProcurementRecordOutAdd(); |
| | | procurementRecordOutAdd.setId(procurementRecordStorage.getId()); |
| | | procurementRecordOutAdd.setSalesLedgerProductId(Math.toIntExact(salesLedgerProduct.getId())); |
| | | procurementRecordOutAdd.setType(2); |
| | | procurementRecordOutAdd.setUserId(Math.toIntExact(getUserId())); |
| | | procurementRecordOutAdd.setQuantity(salesLedgerProduct.getQuantity().toPlainString()); |
| | | procurementRecordOutAdd.setTime(LocalDate.now().toString()); |
| | | |
| | | procurementRecordOutService.stockout(procurementRecordOutAdd); |
| | | } |
| | | |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 导出发货信息管理 |
| | | */ |