src/main/java/com/ruoyi/approve/service/impl/ApproveNodeServiceImpl.java
@@ -15,6 +15,7 @@ import com.ruoyi.basic.utils.FileUtil; import com.ruoyi.common.enums.FileNameType; 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.procurementrecord.utils.StockUtils; @@ -31,14 +32,8 @@ import com.ruoyi.quality.pojo.QualityInspectParam; import com.ruoyi.quality.pojo.QualityTestStandard; import com.ruoyi.quality.pojo.QualityTestStandardParam; import com.ruoyi.sales.mapper.CommonFileMapper; import com.ruoyi.sales.mapper.SalesLedgerProductMapper; import com.ruoyi.sales.mapper.SalesQuotationMapper; import com.ruoyi.sales.mapper.ShippingInfoMapper; import com.ruoyi.sales.pojo.CommonFile; import com.ruoyi.sales.pojo.SalesLedgerProduct; import com.ruoyi.sales.pojo.SalesQuotation; import com.ruoyi.sales.pojo.ShippingInfo; import com.ruoyi.sales.mapper.*; import com.ruoyi.sales.pojo.*; import com.ruoyi.sales.service.impl.CommonFileServiceImpl; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -64,6 +59,7 @@ private final PurchaseLedgerMapper purchaseLedgerMapper; private final SalesQuotationMapper salesQuotationMapper; private final ShippingInfoMapper shippingInfoMapper; private final ShippingProductDetailMapper shippingProductDetailMapper; private final CommonFileServiceImpl commonFileService; private final StockUtils stockUtils; private final SalesLedgerProductMapper salesLedgerProductMapper; @@ -183,7 +179,7 @@ addQualityInspect(purchaseLedger, salesLedgerProduct); } else { //直接入库 stockUtils.addStockWithBatchNo(salesLedgerProduct.getProductModelId(), salesLedgerProduct.getQuantity(), StockInQualifiedRecordTypeEnum.PURCHASE_STOCK_IN.getCode(), purchaseLedger.getId(),purchaseLedger.getPurchaseContractNumber()+"-"+salesLedgerProduct.getId()); stockUtils.addStockWithBatchNo(salesLedgerProduct.getProductModelId(), salesLedgerProduct.getQuantity(), StockInQualifiedRecordTypeEnum.PURCHASE_STOCK_IN.getCode(), purchaseLedger.getId(), purchaseLedger.getPurchaseContractNumber() + "-" + salesLedgerProduct.getId()); } } } else if (status.equals(3)) { @@ -220,6 +216,8 @@ if (shippingInfo != null) { if (status.equals(2)) { shippingInfo.setStatus("审核通过"); //更改出库审核状态(待确认改成待审核) stockUtils.shipmentStatus(StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode(), shippingInfo.getId()); } else if (status.equals(3)) { shippingInfo.setStatus("审核拒绝"); } else if (status.equals(1)) { @@ -227,7 +225,6 @@ } shippingInfoMapper.updateById(shippingInfo); } //库存扣减 } fileUtil.saveStorageAttachment(ApplicationTypeEnum.FILE, RecordTypeEnum.APPROVE_NODE, approveNode.getId(), approveNode.getStorageBlobDTOS()); src/main/java/com/ruoyi/procurementrecord/utils/StockUtils.java
@@ -1,5 +1,6 @@ package com.ruoyi.procurementrecord.utils; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.ruoyi.procurementrecord.mapper.ProcurementRecordMapper; @@ -66,8 +67,6 @@ /** * 合格入库 * @param productModelId * @param quantity * @param recordType * @param recordId */ @@ -105,15 +104,6 @@ * @param recordType * @param recordId */ public void substractStock(Long productModelId, BigDecimal quantity, String recordType, Long recordId) { StockInventoryDto stockInventoryDto = new StockInventoryDto(); stockInventoryDto.setRecordId(recordId); stockInventoryDto.setRecordType(String.valueOf(recordType)); stockInventoryDto.setQualitity(quantity); stockInventoryDto.setProductModelId(productModelId); stockInventoryService.subtractStockInventory(stockInventoryDto); } public void substractStock(Long productModelId, BigDecimal quantity, String recordType, Long recordId, String batchNo) { StockInventoryDto stockInventoryDto = new StockInventoryDto(); stockInventoryDto.setRecordId(recordId); @@ -121,7 +111,20 @@ stockInventoryDto.setQualitity(quantity); stockInventoryDto.setProductModelId(productModelId); stockInventoryDto.setBatchNo(batchNo); stockInventoryService.subtractStockInventory(stockInventoryDto); stockInventoryService.addStockOutRecordOnly(stockInventoryDto); } /** * 发货审批状态更改 * @param recordType * @param recordId */ public void shipmentStatus(String recordType, Long recordId) { LambdaQueryWrapper<StockOutRecord> queryWrapper = new LambdaQueryWrapper<StockOutRecord>().eq(StockOutRecord::getRecordType, recordType) .eq(StockOutRecord::getRecordId, recordId); StockOutRecord stockOutRecord = stockOutRecordService.getOne(queryWrapper); stockOutRecord.setApprovalStatus(0); stockOutRecordService.updateById(stockOutRecord); } //不合格库存删除 src/main/java/com/ruoyi/sales/service/impl/ShippingInfoServiceImpl.java
@@ -55,7 +55,7 @@ @Override public IPage<ShippingInfoDto> listPage(Page page, ShippingInfo req) { IPage<ShippingInfoDto> listPage = shippingInfoMapper.listPage(page, req); listPage.getRecords().forEach(item ->{ listPage.getRecords().forEach(item -> { item.setStorageBlobVOs(fileUtil.getStorageBlobVOsByApplicationAndRecordTypeAndRecordId(ApplicationTypeEnum.IMAGE, RecordTypeEnum.SHIPPING_INFO, item.getId())); }); return listPage; @@ -68,7 +68,7 @@ throw new RuntimeException("发货信息不存在"); } //扣减库存 if(!"已发货".equals(byId.getStatus())){ if (!"已发货".equals(byId.getStatus())) { List<ShippingProductDetail> shippingProductDetails = shippingProductDetailMapper.selectList(new LambdaQueryWrapper<ShippingProductDetail>().eq(ShippingProductDetail::getShippingInfoId, req.getId())); if (CollectionUtils.isEmpty(shippingProductDetails)) { throw new RuntimeException("发货信息不存在"); @@ -85,28 +85,28 @@ boolean update = this.updateById(byId); // 保存文件 fileUtil.saveStorageAttachment(ApplicationTypeEnum.IMAGE, RecordTypeEnum.SHIPPING_INFO, req.getId(), req.getStorageBlobDTOs()); return update ; return update; } @Override public boolean delete(List<Long> ids) { List<ShippingInfo> shippingInfos = shippingInfoMapper.selectList(new LambdaQueryWrapper<ShippingInfo>() .in(ShippingInfo::getId, ids)); if(CollectionUtils.isEmpty(shippingInfos)) return false; if (CollectionUtils.isEmpty(shippingInfos)) return false; // 删除附件 commonFileService.deleteByBusinessIds(ids, FileNameType.SHIP.getValue()); // 扣已发货库存 for (ShippingInfo shippingInfo : shippingInfos) { if("已发货".equals(shippingInfo.getStatus())) { if ("已发货".equals(shippingInfo.getStatus())) { stockUtils.deleteStockOutRecord(shippingInfo.getId(), StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode()); } } // 删除发货审批 if(CollectionUtils.isNotEmpty(shippingInfos)){ for (ShippingInfo shippingInfo : shippingInfos){ if (CollectionUtils.isNotEmpty(shippingInfos)) { for (ShippingInfo shippingInfo : shippingInfos) { List<ApproveProcess> one = approveProcessService.list(new LambdaQueryWrapper<ApproveProcess>() .like(ApproveProcess::getApproveReason, shippingInfo.getShippingNo())); if(one != null){ if (one != null) { List<Long> list = one.stream().map(ApproveProcess::getId).toList(); approveProcessService.delByIds(list); } @@ -120,7 +120,7 @@ @Override public List<SalesLedgerProductDto> getReturnManagementDtoById(Long shippingId) { return shippingInfoMapper.getReturnManagementDtoById(shippingId ); return shippingInfoMapper.getReturnManagementDtoById(shippingId); } @@ -131,9 +131,14 @@ @Override public boolean add(ShippingInfoDto req) { this.save( req); this.save(req); req.getBatchNoDetailList().forEach(item -> item.setShippingInfoId(req.getId())); shippingProductDetailMapper.insert(req.getBatchNoDetailList()); for (ShippingProductDetail shippingProductDetail : req.getBatchNoDetailList()) { stockUtils.substractStock(shippingProductDetail.getProductModelId(), shippingProductDetail.getQuantity(), StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode(), req.getId(), shippingProductDetail.getBatchNo()); } // 保存文件 fileUtil.saveStorageAttachment(ApplicationTypeEnum.IMAGE, RecordTypeEnum.SHIPPING_INFO, req.getId(), req.getStorageBlobDTOs()); return true; } @@ -147,7 +152,7 @@ ShippingApproveDto shippingApproveDto = new ShippingApproveDto(); ShippingInfo shippingInfo = new ShippingInfo(); shippingInfo.setShippingNo(shippingNo); shippingApproveDto.setShippingInfo(shippingInfoMapper.listPage(new Page(1, -1),shippingInfo).getRecords().get(0)); shippingApproveDto.setShippingInfo(shippingInfoMapper.listPage(new Page(1, -1), shippingInfo).getRecords().get(0)); List<ShippingProductDetailDto> dateilByShippingNo = shippingProductDetailMapper.getDateilByShippingNo(shippingNo); shippingApproveDto.setShippingProductDetailDtoList(dateilByShippingNo); return shippingApproveDto; src/main/java/com/ruoyi/stock/pojo/StockOutRecord.java
@@ -75,7 +75,7 @@ @Schema(description = "类型 0合格入库 1不合格入库") private String type; @Schema(description = "审批状态 0-待审批 1-通过 2-驳回", implementation = ReviewStatusEnum.class) @Schema(description = "审批状态 0-待审批 1-通过 2-驳回 3-销售出库待确认", implementation = ReviewStatusEnum.class) private Integer approvalStatus; @TableField(fill = FieldFill.INSERT) src/main/java/com/ruoyi/stock/service/impl/StockOutRecordServiceImpl.java
@@ -20,7 +20,6 @@ import com.ruoyi.stock.mapper.StockInventoryMapper; import com.ruoyi.stock.mapper.StockOutRecordMapper; import com.ruoyi.stock.mapper.StockUninventoryMapper; import com.ruoyi.stock.pojo.StockInRecord; import com.ruoyi.stock.pojo.StockInventory; import com.ruoyi.stock.pojo.StockOutRecord; import com.ruoyi.stock.pojo.StockUninventory; @@ -57,8 +56,9 @@ public int add(StockOutRecordDto stockOutRecordDto) { String no = OrderUtils.countTodayByCreateTime(stockOutRecordMapper, "CK","outbound_batches"); stockOutRecordDto.setOutboundBatches(no); StockInRecord stockInRecord = new StockInRecord(); BeanUtils.copyProperties(stockOutRecordDto, stockInRecord); if (StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode().equals(stockOutRecordDto.getRecordType())){ stockOutRecordDto.setApprovalStatus(3); } return stockOutRecordMapper.insert(stockOutRecordDto); } src/main/resources/mapper/stock/StockInventoryMapper.xml
@@ -436,7 +436,7 @@ WHERE sor.product_model_id = #{productModelId} AND (sor.batch_no = #{batchNo} OR (#{batchNo} IS NULL AND sor.batch_no IS NULL)) AND sor.type = #{type} AND sor.approval_status = 0 AND sor.approval_status IN (0, 3) </select> <select id="listSelectableBatchNoByProductModelIds" resultType="com.ruoyi.stock.pojo.StockInventory"> @@ -453,12 +453,24 @@ order by si.product_model_id, si.batch_no </select> <select id="getByModelId" resultType="com.ruoyi.stock.pojo.StockInventory"> select spd.id, spd.batch_no, spd.locked_quantity, (spd.qualitity - IFNULL(sd.qualitity, 0)) as qualitity from stock_inventory spd left join (select stock_inventory_id, sum(quantity) as qualitity from shipping_product_detail group by stock_inventory_id) as sd on sd.stock_inventory_id = spd.id where product_model_id = #{productModelId} select si.id, si.batch_no, si.locked_quantity, (si.qualitity - IFNULL(sd.qualitity, 0)) as qualitity from stock_inventory si left join ( select spd.stock_inventory_id, sum(spd.quantity) as qualitity from shipping_product_detail spd where exists ( select 1 from stock_out_record sor where sor.record_id = spd.shipping_info_id and sor.record_type = '13' and sor.type = '0' and sor.approval_status in (0, 3) and sor.product_model_id = spd.product_model_id and (sor.batch_no = spd.batch_no or (sor.batch_no is null and spd.batch_no is null)) ) group by spd.stock_inventory_id ) as sd on sd.stock_inventory_id = si.id where si.product_model_id = #{productModelId} </select> </mapper>