| | |
| | | import com.ruoyi.basic.utils.FileUtil; |
| | | import com.ruoyi.common.enums.FileNameType; |
| | | import com.ruoyi.common.enums.StockOutQualifiedRecordTypeEnum; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.OrderUtils; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.framework.security.LoginUser; |
| | |
| | | import com.ruoyi.sales.mapper.SalesLedgerProductMapper; |
| | | import com.ruoyi.sales.mapper.ShippingInfoMapper; |
| | | import com.ruoyi.sales.mapper.ShippingProductDetailMapper; |
| | | import com.ruoyi.sales.pojo.SalesLedgerProduct; |
| | | import com.ruoyi.sales.pojo.ShippingInfo; |
| | | import com.ruoyi.sales.pojo.ShippingProductDetail; |
| | | import com.ruoyi.sales.service.ShippingInfoService; |
| | |
| | | |
| | | @Override |
| | | public boolean add(ShippingInfoDto req) { |
| | | String ledgerStockType = resolveLedgerStockType(req.getSalesLedgerProductId()); |
| | | this.save(req); |
| | | req.getBatchNoDetailList().forEach(item -> item.setShippingInfoId(req.getId())); |
| | | req.getBatchNoDetailList().forEach(item -> { |
| | | item.setShippingInfoId(req.getId()); |
| | | item.setStockType(ledgerStockType); |
| | | }); |
| | | shippingProductDetailMapper.insert(req.getBatchNoDetailList()); |
| | | // 保存文件 |
| | | fileUtil.saveStorageAttachment(ApplicationTypeEnum.IMAGE, RecordTypeEnum.SHIPPING_INFO, req.getId(), req.getStorageBlobDTOs()); |
| | |
| | | req.setStatus("待审核"); |
| | | boolean save = this.add(req); |
| | | // 发货审批 |
| | | ApprovalTemplate approvalTemplate = approvalTemplateMapper.selectOne(new LambdaQueryWrapper<ApprovalTemplate>() |
| | | .eq(ApprovalTemplate::getBusinessType, 7L) |
| | | .eq(ApprovalTemplate::getDeleted, 0) |
| | | .orderByDesc(ApprovalTemplate::getId) |
| | | .last("LIMIT 1")); |
| | | if (approvalTemplate == null) { |
| | | throw new ServiceException("请先配置发货审批模板"); |
| | | } |
| | | ApprovalInstanceDto approvalInstance = new ApprovalInstanceDto(); |
| | | approvalInstance.setTemplateId(approvalTemplateMapper.selectOne(new LambdaQueryWrapper<ApprovalTemplate>().eq(ApprovalTemplate::getBusinessType,7L).orderByDesc(ApprovalTemplate::getId).last("LIMIT 1")).getId()); |
| | | approvalInstance.setTemplateName(approvalTemplateMapper.selectOne(new LambdaQueryWrapper<ApprovalTemplate>().eq(ApprovalTemplate::getBusinessType,7L).orderByDesc(ApprovalTemplate::getId).last("LIMIT 1")).getTemplateName()); |
| | | approvalInstance.setTemplateId(approvalTemplate.getId()); |
| | | approvalInstance.setTemplateName(approvalTemplate.getTemplateName()); |
| | | approvalInstance.setBusinessId(req.getId()); |
| | | approvalInstance.setBusinessType(7L); |
| | | approvalInstance.setCurrentLevel(1); |
| | |
| | | } |
| | | |
| | | private void addShippingStockOutRecord(ShippingProductDetail shippingProductDetail, Long shippingInfoId) { |
| | | String stockType = shippingProductDetail.getStockType(); |
| | | if (stockType != null) { |
| | | stockType = stockType.trim().toLowerCase(); |
| | | ShippingInfo shippingInfo = this.getById(shippingInfoId); |
| | | String stockType = resolveLedgerStockType(shippingInfo != null ? shippingInfo.getSalesLedgerProductId() : null); |
| | | if (stockType == null) { |
| | | stockType = normalizeStockType(shippingProductDetail.getStockType()); |
| | | } |
| | | if ("waste".equals(stockType) || "unqualified".equals(stockType)) { |
| | | String detailStockType = normalizeStockType(shippingProductDetail.getStockType()); |
| | | if (detailStockType != null && stockType != null && !stockType.equals(detailStockType)) { |
| | | throw new RuntimeException("发货明细库存类型与销售台账产品库存类型不一致"); |
| | | } |
| | | if ("waste".equals(stockType)) { |
| | | StockUninventoryDto stockUninventoryDto = new StockUninventoryDto(); |
| | | stockUninventoryDto.setRecordId(shippingInfoId); |
| | | stockUninventoryDto.setRecordType(StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode()); |
| | |
| | | String normalized = batchNo.trim(); |
| | | return normalized.isEmpty() ? null : normalized; |
| | | } |
| | | |
| | | private String normalizeStockType(String stockType) { |
| | | if (stockType == null) { |
| | | return null; |
| | | } |
| | | String normalized = stockType.trim().toLowerCase(); |
| | | if (normalized.isEmpty()) { |
| | | return null; |
| | | } |
| | | if ("unqualified".equals(normalized)) { |
| | | return "waste"; |
| | | } |
| | | return normalized; |
| | | } |
| | | |
| | | private String resolveLedgerStockType(Long salesLedgerProductId) { |
| | | if (salesLedgerProductId == null) { |
| | | return null; |
| | | } |
| | | SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(salesLedgerProductId); |
| | | if (salesLedgerProduct == null) { |
| | | throw new RuntimeException("销售台账产品不存在"); |
| | | } |
| | | String stockType = normalizeStockType(salesLedgerProduct.getStockType()); |
| | | return stockType == null ? "qualified" : stockType; |
| | | } |
| | | } |