| | |
| | | import com.ruoyi.approve.pojo.ApproveNode; |
| | | import com.ruoyi.approve.pojo.ApproveProcess; |
| | | import com.ruoyi.approve.service.IApproveNodeService; |
| | | import com.ruoyi.approve.vo.ApproveProcessVO; |
| | | import com.ruoyi.common.enums.FileNameType; |
| | | import com.ruoyi.common.enums.StockQualifiedRecordTypeEnum; |
| | | import com.ruoyi.common.enums.StockInQualifiedRecordTypeEnum; |
| | | import com.ruoyi.common.enums.StockOutQualifiedRecordTypeEnum; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.device.mapper.DeviceRepairMapper; |
| | | import com.ruoyi.device.pojo.DeviceRepair; |
| | |
| | | import com.ruoyi.purchase.service.impl.PurchaseLedgerServiceImpl; |
| | | import com.ruoyi.sales.mapper.*; |
| | | import com.ruoyi.sales.pojo.CommonFile; |
| | | import com.ruoyi.sales.pojo.SalesLedger; |
| | | import com.ruoyi.sales.pojo.SalesLedgerProduct; |
| | | import com.ruoyi.sales.pojo.SalesQuotation; |
| | | import com.ruoyi.sales.pojo.ShippingInfo; |
| | | import com.ruoyi.sales.service.ShippingInfoService; |
| | | import com.ruoyi.sales.service.impl.CommonFileServiceImpl; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | |
| | | |
| | | @Autowired |
| | | private PurchaseLedgerServiceImpl purchaseLedgerServiceImpl; |
| | | |
| | | @Autowired |
| | | private SalesLedgerMapper salesLedgerMapper; |
| | | |
| | | @Autowired |
| | | @Lazy |
| | | private ShippingInfoService shippingInfoService; |
| | | |
| | | |
| | | public ApproveProcess getApproveById(String id) { |
| | |
| | | LambdaQueryWrapper<ApproveProcess> approveProcessLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | approveProcessLambdaQueryWrapper.eq(ApproveProcess::getApproveId, approveNode.getApproveProcessId()) |
| | | .eq(ApproveProcess::getApproveDelete, 0) |
| | | .eq(ApproveProcess::getApproveStatus, 0) |
| | | .last("limit 1"); |
| | | ApproveProcess approveProcess = approveProcessMapper.selectOne(approveProcessLambdaQueryWrapper); |
| | | if(approveProcess == null) throw new RuntimeException("审批不存在"); |
| | |
| | | purchaseLedgerServiceImpl.addQualityInspect(purchaseLedger, salesLedgerProduct); |
| | | }else { |
| | | //直接入库 |
| | | stockUtils.addStock(salesLedgerProduct.getProductModelId(), salesLedgerProduct.getQuantity(), StockQualifiedRecordTypeEnum.PURCHASE_STOCK_IN.getCode(), purchaseLedger.getId()); |
| | | stockUtils.addStock(salesLedgerProduct.getProductModelId(), salesLedgerProduct.getQuantity(), StockInQualifiedRecordTypeEnum.PURCHASE_STOCK_IN.getCode(), purchaseLedger.getId()); |
| | | } |
| | | } |
| | | } else if (status.equals(3)) { |
| | |
| | | } |
| | | salesQuotationMapper.updateById(salesQuote); |
| | | } |
| | | // 出库审批修改 |
| | | // 出库审批修改 (订单级别) |
| | | if(approveProcess.getApproveType().equals(7)){ |
| | | String[] split = approveProcess.getApproveReason().split(":"); |
| | | ShippingInfo shippingInfo = shippingInfoMapper.selectOne(new LambdaQueryWrapper<ShippingInfo>() |
| | | .eq(ShippingInfo::getShippingNo, split[1]) |
| | | .orderByDesc(ShippingInfo::getCreateTime) |
| | | .last("limit 1")); |
| | | if(shippingInfo != null){ |
| | | if(status.equals(2)){ |
| | | shippingInfo.setStatus("审核通过"); |
| | | }else if(status.equals(3)){ |
| | | shippingInfo.setStatus("审核拒绝"); |
| | | }else if(status.equals(1)){ |
| | | shippingInfo.setStatus("审核中"); |
| | | if (split.length > 1) { |
| | | String identifier = split[1]; |
| | | // 查找销售台账 |
| | | SalesLedger salesLedger = salesLedgerMapper.selectOne(new LambdaQueryWrapper<SalesLedger>() |
| | | .eq(SalesLedger::getSalesContractNo, identifier) |
| | | .last("limit 1")); |
| | | |
| | | if (salesLedger != null) { |
| | | if(status.equals(2)){ |
| | | // 审批完成 -> 自动扣除库存 |
| | | try { |
| | | shippingInfoService.deductStockByOrder(salesLedger.getId(), null); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException("自动扣除库存失败: " + e.getMessage()); |
| | | } |
| | | } else if(status.equals(3)){ |
| | | updateSalesLedgerDeliveryStatus(salesLedger.getId(), 3); |
| | | // 更新关联的发货记录为审核拒绝 |
| | | updateShippingInfoStatusByOrder(salesLedger.getId(), "审核拒绝"); |
| | | } else if(status.equals(1)){ |
| | | updateSalesLedgerDeliveryStatus(salesLedger.getId(), 2); |
| | | updateShippingInfoStatusByOrder(salesLedger.getId(), "审核中"); |
| | | } |
| | | } |
| | | shippingInfoMapper.updateById(shippingInfo); |
| | | } |
| | | |
| | | } |
| | | // 绑定附件 |
| | | if(!CollectionUtils.isEmpty(approveNode.getTempFileIds()) && approveNode.getApproveNodeStatus() == 1){ |
| | |
| | | } |
| | | } |
| | | |
| | | private void updateShippingInfoStatusByOrder(Long salesLedgerId, String statusText) { |
| | | if (salesLedgerId == null) return; |
| | | shippingInfoMapper.update(null, new UpdateWrapper<ShippingInfo>() |
| | | .lambda() |
| | | .set(ShippingInfo::getStatus, statusText) |
| | | .eq(ShippingInfo::getSalesLedgerId, salesLedgerId)); |
| | | } |
| | | |
| | | private void updateSalesLedgerDeliveryStatus(Long salesLedgerId, Integer status) { |
| | | if (salesLedgerId == null) return; |
| | | SalesLedger salesLedger = salesLedgerMapper.selectById(salesLedgerId); |
| | | if (salesLedger != null) { |
| | | salesLedger.setDeliveryStatus(status); |
| | | salesLedgerMapper.updateById(salesLedger); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void updateApproveNode(ApproveNode approveNode) throws IOException { |
| | | // 审批节点状态:1同意,2拒绝,0尚未审核 |