| | |
| | | import com.ruoyi.purchase.mapper.PurchaseLedgerMapper; |
| | | import com.ruoyi.purchase.pojo.PurchaseLedger; |
| | | import com.ruoyi.quality.utils.QualityInspectHelper; |
| | | import com.ruoyi.sales.mapper.SalesLedgerMapper; |
| | | import com.ruoyi.sales.mapper.SalesLedgerProductMapper; |
| | | import com.ruoyi.sales.mapper.SalesQuotationMapper; |
| | | import com.ruoyi.sales.mapper.ShippingInfoMapper; |
| | | import com.ruoyi.sales.mapper.ShippingProductDetailMapper; |
| | | import com.ruoyi.sales.pojo.SalesLedgerProduct; |
| | | import com.ruoyi.sales.pojo.SalesQuotation; |
| | | import com.ruoyi.sales.pojo.ShippingInfo; |
| | | import com.ruoyi.sales.pojo.ShippingProductDetail; |
| | | import com.ruoyi.staff.mapper.HolidayApplicationMapper; |
| | | import com.ruoyi.staff.pojo.HolidayApplication; |
| | | import lombok.RequiredArgsConstructor; |
| | |
| | | private final EnterpriseNewsMapper enterpriseNewsMapper; |
| | | private final EnterpriseNewsScopeDeptMapper enterpriseNewsScopeDeptMapper; |
| | | private final ApprovalTemplateNodeApproverMapper approvalTemplateNodeApproverMapper; |
| | | private final ShippingProductDetailMapper shippingProductDetailMapper; |
| | | private final SalesLedgerMapper salesLedgerMapper; |
| | | |
| | | @Override |
| | | public R listPage(Page<ApprovalInstanceVo> page, ApprovalInstanceDto approvalInstanceDto) { |
| | | // 注入当前用户ID,用于过滤只查看申请人和审核人是自己的数据 |
| | | approvalInstanceDto.setCurrentUserId(SecurityUtils.getUserId()); |
| | | IPage<ApprovalInstanceVo> approvalInstanceVoIPage = approvalInstanceMapper.listPage(page, approvalInstanceDto); |
| | | |
| | | List<ApprovalInstanceVo> records = approvalInstanceVoIPage.getRecords(); |
| | |
| | | ApprovalInstance instance = getPendingApprovalInstance(approvalInstanceDto.getId()); |
| | | if (instance == null) { |
| | | return R.fail("审批实例不存在"); |
| | | } |
| | | |
| | | // 如果前端传递了仓库信息,更新审批实例的仓库字段 |
| | | if (StringUtils.hasText(approvalInstanceDto.getWarehouse())) { |
| | | instance.setWarehouse(approvalInstanceDto.getWarehouse()); |
| | | this.updateById(instance); |
| | | } |
| | | |
| | | ApprovalInstanceNode currentNode = approveProcessConfigNodeUtils.getCurrentNode(instance.getId()); |
| | |
| | | salesLedgerProduct.getQuantity(), |
| | | StockInQualifiedRecordTypeEnum.PURCHASE_STOCK_IN.getCode(), |
| | | purchaseLedger.getId(), |
| | | purchaseLedger.getPurchaseContractNumber() + "-" + salesLedgerProduct.getId() |
| | | purchaseLedger.getPurchaseContractNumber() + "-" + salesLedgerProduct.getId(), |
| | | null, |
| | | instance.getWarehouse() |
| | | ); |
| | | } |
| | | } |
| | |
| | | private void handleShippingApprovalFinished(ApprovalInstance instance, String status) { |
| | | ShippingInfo shippingInfo = shippingInfoMapper.selectOne( |
| | | new LambdaQueryWrapper<ShippingInfo>() |
| | | .eq(ShippingInfo::getId, instance.getTitle()) |
| | | .orderByDesc(ShippingInfo::getCreateTime) |
| | | .eq(ShippingInfo::getId, instance.getBusinessId()) |
| | | .last("limit 1") |
| | | ); |
| | | if (shippingInfo == null) { |
| | |
| | | shippingInfo.setStatus(ShippingStatusEnum.APPROVED.getCode()); |
| | | shippingInfo.setShippingDate(new Date()); |
| | | stockUtils.shipmentStatus(StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode(), shippingInfo.getId()); |
| | | |
| | | // 发货审批通过后,自动生成出厂检验单 |
| | | createFactoryInspectForShipping(shippingInfo); |
| | | } else if ("REJECTED".equals(status)) { |
| | | stockUtils.deleteStockOutRecord(shippingInfo.getId(), StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode()); |
| | | shippingInfo.setStatus(ShippingStatusEnum.REJECTED.getCode()); |
| | |
| | | shippingInfoMapper.updateById(shippingInfo); |
| | | } |
| | | |
| | | /** |
| | | * 发货审批通过后,自动生成出厂检验单 |
| | | */ |
| | | private void createFactoryInspectForShipping(ShippingInfo shippingInfo) { |
| | | // 查询发货产品明细 |
| | | List<ShippingProductDetail> detailList = shippingProductDetailMapper.selectList( |
| | | new LambdaQueryWrapper<ShippingProductDetail>() |
| | | .eq(ShippingProductDetail::getShippingInfoId, shippingInfo.getId()) |
| | | ); |
| | | |
| | | if (detailList == null || detailList.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | // 获取客户名称 |
| | | String customerName = null; |
| | | if (shippingInfo.getSalesLedgerId() != null) { |
| | | com.ruoyi.sales.pojo.SalesLedger salesLedger = salesLedgerMapper.selectById(shippingInfo.getSalesLedgerId()); |
| | | if (salesLedger != null) { |
| | | customerName = salesLedger.getCustomerName(); |
| | | } |
| | | } |
| | | |
| | | // 为每个发货产品创建出厂检验单 |
| | | for (ShippingProductDetail detail : detailList) { |
| | | qualityInspectHelper.addFactoryInspect( |
| | | shippingInfo, |
| | | detail, |
| | | customerName, |
| | | shippingInfo.getSalesLedgerId() |
| | | ); |
| | | } |
| | | } |
| | | |
| | | private List<ApprovalTask> createNodeAndTasks(ApprovalInstance instance, ApprovalTemplateNode templateNode) { |
| | | List<ApprovalTemplateNodeApprover> approvers = approvalTemplateNodeApproverMapper.selectList( |
| | | new LambdaQueryWrapper<ApprovalTemplateNodeApprover>() |