| ¶Ô±ÈÐÂÎļþ |
| | |
| | | ALTER TABLE shipping_product_detail |
| | | ADD COLUMN stock_type VARCHAR(20) NOT NULL DEFAULT 'qualified' COMMENT 'åºåç±»åï¼qualified/waste' AFTER product_model_id; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | ALTER TABLE stock_uninventory |
| | | ADD COLUMN type VARCHAR(20) NOT NULL DEFAULT 'unqualified' COMMENT 'åºåç±»åï¼unqualified/waste' AFTER qualitity; |
| | | |
| | | UPDATE stock_uninventory |
| | | SET type = 'unqualified' |
| | | WHERE type IS NULL OR type = ''; |
| | |
| | | stockUninventoryDto.setRecordType(String.valueOf(recordType)); |
| | | stockUninventoryDto.setQualitity(quantity); |
| | | stockUninventoryDto.setProductModelId(productModelId); |
| | | stockUninventoryDto.setType(resolveUninventoryType(recordType)); |
| | | stockUninventoryService.addStockInRecordOnly(stockUninventoryDto); |
| | | } |
| | | |
| | |
| | | stockUninventoryDto.setQualitity(quantity); |
| | | stockUninventoryDto.setProductModelId(productModelId); |
| | | stockUninventoryDto.setBatchNo(batchNo); |
| | | stockUninventoryDto.setType(resolveUninventoryType(recordType)); |
| | | stockUninventoryService.addStockInRecordOnly(stockUninventoryDto); |
| | | } |
| | | |
| | |
| | | stockUninventoryDto.setRecordType(String.valueOf(recordType)); |
| | | stockUninventoryDto.setQualitity(quantity); |
| | | stockUninventoryDto.setProductModelId(productModelId); |
| | | stockUninventoryDto.setType("unqualified"); |
| | | stockUninventoryService.subtractStockUninventory(stockUninventoryDto); |
| | | } |
| | | |
| | |
| | | |
| | | //å é¤åºåºè®°å½ |
| | | public void deleteStockOutRecord(Long recordId, String recordType) { |
| | | StockOutRecord one = stockOutRecordService.getOne(new QueryWrapper<StockOutRecord>() |
| | | java.util.List<StockOutRecord> list = stockOutRecordService.list(new QueryWrapper<StockOutRecord>() |
| | | .lambda().eq(StockOutRecord::getRecordId, recordId) |
| | | .eq(StockOutRecord::getRecordType, recordType), false); |
| | | if (ObjectUtils.isNotEmpty(one)) { |
| | | if (ReviewStatusEnum.APPROVED.getCode().equals(one.getApprovalStatus())) { |
| | | stockOutRecordService.batchDelete(Collections.singletonList(one.getId())); |
| | | } else { |
| | | stockOutRecordService.removeById(one.getId()); |
| | | .eq(StockOutRecord::getRecordType, recordType)); |
| | | if (ObjectUtils.isNotEmpty(list)) { |
| | | java.util.List<Long> approvedIds = new java.util.ArrayList<>(); |
| | | java.util.List<Long> pendingIds = new java.util.ArrayList<>(); |
| | | for (StockOutRecord stockOutRecord : list) { |
| | | if (ReviewStatusEnum.APPROVED.getCode().equals(stockOutRecord.getApprovalStatus())) { |
| | | approvedIds.add(stockOutRecord.getId()); |
| | | } else { |
| | | pendingIds.add(stockOutRecord.getId()); |
| | | } |
| | | } |
| | | if (!approvedIds.isEmpty()) { |
| | | stockOutRecordService.batchDelete(approvedIds); |
| | | } |
| | | if (!pendingIds.isEmpty()) { |
| | | stockOutRecordService.removeByIds(pendingIds); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | private String resolveUninventoryType(String recordType) { |
| | | if (com.ruoyi.common.enums.StockInQualifiedRecordTypeEnum.PRODUCTION_SCRAP.getCode().equals(recordType)) { |
| | | return "waste"; |
| | | } |
| | | return "unqualified"; |
| | | } |
| | | } |
| | |
| | | |
| | | @ApiModelProperty("产ååå·id") |
| | | private Long productModelId; |
| | | |
| | | @ApiModelProperty("åºåç±»åï¼qualified/waste") |
| | | private String stockType; |
| | | } |
| | |
| | | import com.ruoyi.sales.pojo.ShippingInfo; |
| | | import com.ruoyi.sales.pojo.ShippingProductDetail; |
| | | import com.ruoyi.sales.service.ShippingInfoService; |
| | | import com.ruoyi.stock.dto.StockInventoryDto; |
| | | import com.ruoyi.stock.dto.StockUninventoryDto; |
| | | import com.ruoyi.stock.service.StockInventoryService; |
| | | import com.ruoyi.stock.service.StockUninventoryService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | |
| | | private final ShippingProductDetailMapper shippingProductDetailMapper; |
| | | private final ApprovalTemplateMapper approvalTemplateMapper; |
| | | private final ApprovalInstanceService approvalInstanceService; |
| | | private final StockInventoryService stockInventoryService; |
| | | private final StockUninventoryService stockUninventoryService; |
| | | |
| | | @Override |
| | | public IPage<ShippingInfoDto> listPage(Page page, ShippingInfo req) { |
| | |
| | | throw new RuntimeException("åè´§ä¿¡æ¯ä¸åå¨"); |
| | | } |
| | | for (ShippingProductDetail shippingProductDetail : shippingProductDetails) { |
| | | stockUtils.substractStock(shippingProductDetail.getProductModelId(), shippingProductDetail.getQuantity(), StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode(), req.getId(), shippingProductDetail.getBatchNo()); |
| | | addShippingStockOutRecord(shippingProductDetail, req.getId()); |
| | | } |
| | | } |
| | | byId.setExpressNumber(req.getExpressNumber()); |
| | |
| | | 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; |
| | |
| | | approvalInstanceService.add(approvalInstance); |
| | | return true; |
| | | } |
| | | |
| | | private void addShippingStockOutRecord(ShippingProductDetail shippingProductDetail, Long shippingInfoId) { |
| | | String stockType = shippingProductDetail.getStockType(); |
| | | if (stockType != null) { |
| | | stockType = stockType.trim().toLowerCase(); |
| | | } |
| | | if ("waste".equals(stockType) || "unqualified".equals(stockType)) { |
| | | StockUninventoryDto stockUninventoryDto = new StockUninventoryDto(); |
| | | stockUninventoryDto.setRecordId(shippingInfoId); |
| | | stockUninventoryDto.setRecordType(StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode()); |
| | | stockUninventoryDto.setQualitity(shippingProductDetail.getQuantity()); |
| | | stockUninventoryDto.setProductModelId(shippingProductDetail.getProductModelId()); |
| | | stockUninventoryDto.setBatchNo(normalizeBatchNo(shippingProductDetail.getBatchNo())); |
| | | stockUninventoryDto.setType("waste"); |
| | | stockUninventoryService.addStockOutRecordOnly(stockUninventoryDto); |
| | | return; |
| | | } |
| | | if (!"qualified".equals(stockType)) { |
| | | throw new RuntimeException("åè´§æç»åºåç±»åæ æï¼åªæ¯æ qualified æ waste"); |
| | | } |
| | | StockInventoryDto stockInventoryDto = new StockInventoryDto(); |
| | | stockInventoryDto.setRecordId(shippingInfoId); |
| | | stockInventoryDto.setRecordType(StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode()); |
| | | stockInventoryDto.setQualitity(shippingProductDetail.getQuantity()); |
| | | stockInventoryDto.setProductModelId(shippingProductDetail.getProductModelId()); |
| | | stockInventoryDto.setBatchNo(normalizeBatchNo(shippingProductDetail.getBatchNo())); |
| | | stockInventoryService.addStockOutRecordOnly(stockInventoryDto); |
| | | } |
| | | |
| | | private String normalizeBatchNo(String batchNo) { |
| | | if (batchNo == null) { |
| | | return null; |
| | | } |
| | | String normalized = batchNo.trim(); |
| | | return normalized.isEmpty() ? null : normalized; |
| | | } |
| | | } |
| | |
| | | @GetMapping("/pagestockUninventory") |
| | | @Operation(summary = "å页æ¥è¯¢åºå") |
| | | public R pagestockUninventory(Page page, StockUninventoryDto stockUninventoryDto) { |
| | | stockUninventoryDto.setType("unqualified"); |
| | | IPage<StockUninventoryDto> stockUninventoryDtoIPage = stockUninventoryService.pageStockUninventory(page, stockUninventoryDto); |
| | | return R.ok(stockUninventoryDtoIPage); |
| | | } |
| | | |
| | | @GetMapping("/pageWasteQuery") |
| | | @Operation(summary = "åºåæ¥è¯¢é¡µé¢å页æ¥è¯¢") |
| | | public R pageWasteQuery(Page page, StockUninventoryDto stockUninventoryDto) { |
| | | IPage<StockUninventoryDto> stockUninventoryDtoIPage = stockUninventoryService.pageWasteQuery(page, stockUninventoryDto); |
| | | return R.ok(stockUninventoryDtoIPage); |
| | | } |
| | | |
| | |
| | | public R addstockUninventory(@RequestBody StockUninventoryDto stockUninventoryDto) { |
| | | stockUninventoryDto.setRecordType(String.valueOf(StockInQualifiedRecordTypeEnum.CUSTOMIZATION_UNSTOCK_IN.getCode())); |
| | | stockUninventoryDto.setRecordId(0L); |
| | | if (stockUninventoryDto.getType() == null || stockUninventoryDto.getType().trim().isEmpty()) { |
| | | stockUninventoryDto.setType("unqualified"); |
| | | } |
| | | return R.ok(stockUninventoryService.addStockUninventory(stockUninventoryDto)); |
| | | } |
| | | |
| | |
| | | public R subtractstockUninventory(@RequestBody StockUninventoryDto stockUninventoryDto) { |
| | | stockUninventoryDto.setRecordType(String.valueOf(StockOutQualifiedRecordTypeEnum.CUSTOMIZATION_UNSTOCK_OUT.getCode())); |
| | | stockUninventoryDto.setRecordId(0L); |
| | | if (stockUninventoryDto.getType() == null || stockUninventoryDto.getType().trim().isEmpty()) { |
| | | stockUninventoryDto.setType("unqualified"); |
| | | } |
| | | return R.ok(stockUninventoryService.subtractStockUninventory(stockUninventoryDto)); |
| | | } |
| | | |
| | |
| | | public R addStockInRecordOnly(@RequestBody StockUninventoryDto stockUninventoryDto) { |
| | | stockUninventoryDto.setRecordType(String.valueOf(StockInQualifiedRecordTypeEnum.CUSTOMIZATION_UNSTOCK_IN.getCode())); |
| | | stockUninventoryDto.setRecordId(0L); |
| | | if (stockUninventoryDto.getType() == null || stockUninventoryDto.getType().trim().isEmpty()) { |
| | | stockUninventoryDto.setType("unqualified"); |
| | | } |
| | | return R.ok(stockUninventoryService.addStockInRecordOnly(stockUninventoryDto)); |
| | | } |
| | | |
| | |
| | | public R addStockOutRecordOnly(@RequestBody StockUninventoryDto stockUninventoryDto) { |
| | | stockUninventoryDto.setRecordType(String.valueOf(StockOutQualifiedRecordTypeEnum.CUSTOMIZATION_UNSTOCK_OUT.getCode())); |
| | | stockUninventoryDto.setRecordId(0L); |
| | | if (stockUninventoryDto.getType() == null || stockUninventoryDto.getType().trim().isEmpty()) { |
| | | stockUninventoryDto.setType("unqualified"); |
| | | } |
| | | return R.ok(stockUninventoryService.addStockOutRecordOnly(stockUninventoryDto)); |
| | | } |
| | | |
| | | @PostMapping("/exportStockUninventory") |
| | | @Operation(summary = "导åºåºå") |
| | | public void exportStockUninventory(HttpServletResponse response, StockUninventoryDto stockUninventoryDto) { |
| | | stockUninventoryDto.setType("unqualified"); |
| | | stockUninventoryService.exportStockUninventory(response,stockUninventoryDto); |
| | | } |
| | | |
| | | @PostMapping("/exportWasteQuery") |
| | | @Operation(summary = "导åºåºåæ¥è¯¢é¡µé¢æ°æ®") |
| | | public void exportWasteQuery(HttpServletResponse response, StockUninventoryDto stockUninventoryDto) { |
| | | stockUninventoryService.exportWasteQuery(response, stockUninventoryDto); |
| | | } |
| | | |
| | | |
| | | @PostMapping("/frozenStock") |
| | | @Operation(summary = "å»ç»åºå") |
| | |
| | | private String productName; |
| | | private String model; |
| | | private String unit; |
| | | private Long topParentProductId; |
| | | |
| | | |
| | | //å
¥åºç±»å |
| | |
| | | import lombok.Data; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDateTime; |
| | | |
| | | @Data |
| | | public class StockUnInventoryExportData { |
| | |
| | | |
| | | @Excel(name = "æ¹å·") |
| | | private String batchNo; |
| | | |
| | | @Excel(name = "åºåç±»å") |
| | | private String type; |
| | | |
| | | @Excel(name = "åºåæ°é") |
| | | private BigDecimal qualitity; |
| | | |
| | | @Excel(name = "å»ç»æ°é") |
| | | private BigDecimal lockedQuantity; |
| | | |
| | | @Excel(name = "å¯ç¨æ°é") |
| | | private BigDecimal unLockedQuantity; |
| | | |
| | | @Excel(name = "夿³¨") |
| | | private String remark; |
| | | // |
| | | // @Excel(name = "ææ°æ´æ°æ¶é´") |
| | | // @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | // @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | // private LocalDateTime updateTime; |
| | | |
| | | @Excel(name = "ææ°æ´æ°æ¶é´", width = 20, dateFormat = "yyyy-MM-dd HH:mm:ss") |
| | | private LocalDateTime updateTime; |
| | | |
| | | } |
| | |
| | | |
| | | IPage<StockUninventoryDto> pageStockUninventory(Page page, @Param("ew") StockUninventoryDto stockUninventoryDto); |
| | | |
| | | IPage<StockUninventoryDto> pageWasteQuery(Page page, @Param("ew") StockUninventoryDto stockUninventoryDto); |
| | | |
| | | int updateSubtractStockUnInventory(@Param("ew") StockUninventoryDto stockUninventoryDto); |
| | | |
| | | BigDecimal selectPendingOutQuantity(@Param("productModelId") Long productModelId, @Param("batchNo") String batchNo, @Param("type") String type); |
| | |
| | | int updateAddStockUnInventory(@Param("ew") StockUninventoryDto stockUninventoryDto); |
| | | |
| | | List<StockUnInventoryExportData> listStockInventoryExportData(@Param("ew") StockUninventoryDto stockUninventoryDto); |
| | | |
| | | List<StockUnInventoryExportData> listWasteQueryExportData(@Param("ew") StockUninventoryDto stockUninventoryDto); |
| | | } |
| | |
| | | @Schema(description = "æ°é") |
| | | private BigDecimal qualitity; |
| | | |
| | | @Schema(description = "ç±»å unqualified ä¸åæ ¼ waste åºå") |
| | | private String type; |
| | | |
| | | @TableField(fill = FieldFill.INSERT) |
| | | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
| | |
| | | |
| | | IPage<StockUninventoryDto> pageStockUninventory(Page page, StockUninventoryDto stockUninventoryDto); |
| | | |
| | | IPage<StockUninventoryDto> pageWasteQuery(Page page, StockUninventoryDto stockUninventoryDto); |
| | | |
| | | Integer addStockUninventory(StockUninventoryDto stockUninventoryDto); |
| | | |
| | | Integer subtractStockUninventory(StockUninventoryDto stockUninventoryDto); |
| | |
| | | |
| | | void exportStockUninventory(HttpServletResponse response, StockUninventoryDto stockUninventoryDto); |
| | | |
| | | void exportWasteQuery(HttpServletResponse response, StockUninventoryDto stockUninventoryDto); |
| | | |
| | | Boolean frozenStock(StockInventoryDto stockInventoryDto); |
| | | |
| | | Boolean thawStock(StockInventoryDto stockInventoryDto); |
| | |
| | | @AllArgsConstructor |
| | | public class StockInRecordServiceImpl extends ServiceImpl<StockInRecordMapper, StockInRecord> implements StockInRecordService { |
| | | |
| | | private static final String UNQUALIFIED_TYPE = "unqualified"; |
| | | private static final String WASTE_TYPE = "waste"; |
| | | |
| | | private StockInRecordMapper stockInRecordMapper; |
| | | private StockInventoryMapper stockInventoryMapper; |
| | | private StockUninventoryMapper stockUninventoryMapper; |
| | |
| | | stockInventoryMapper.updateSubtractStockInventory(stockInRecordDto); |
| | | } |
| | | }else if (stockInRecord.getType().equals("1")) { |
| | | String uninventoryType = resolveUninventoryTypeByInRecordType(stockInRecord.getRecordType()); |
| | | LambdaQueryWrapper<StockUninventory> eq = new LambdaQueryWrapper<StockUninventory>() |
| | | .eq(StockUninventory::getProductModelId, stockInRecord.getProductModelId()); |
| | | .eq(StockUninventory::getProductModelId, stockInRecord.getProductModelId()) |
| | | .eq(StockUninventory::getType, uninventoryType); |
| | | if (StringUtils.isEmpty(stockInRecord.getBatchNo())) { |
| | | eq.isNull(StockUninventory::getBatchNo); |
| | | } else { |
| | |
| | | stockUninventoryDto.setProductModelId(stockUninventory.getProductModelId()); |
| | | stockUninventoryDto.setBatchNo(stockUninventory.getBatchNo()); |
| | | stockUninventoryDto.setQualitity(stockInRecord.getStockInNum()); |
| | | stockUninventoryDto.setType(uninventoryType); |
| | | stockUninventoryMapper.updateSubtractStockUnInventory(stockUninventoryDto); |
| | | } |
| | | } |
| | |
| | | return stockInventoryMapper.selectOne(eq); |
| | | } |
| | | |
| | | private StockUninventory getStockUninventory(Long productModelId, String batchNo) { |
| | | private StockUninventory getStockUninventory(Long productModelId, String batchNo, String uninventoryType) { |
| | | LambdaQueryWrapper<StockUninventory> eq = new LambdaQueryWrapper<>(); |
| | | eq.eq(StockUninventory::getProductModelId, productModelId); |
| | | if (StringUtils.isNotEmpty(uninventoryType)) { |
| | | eq.eq(StockUninventory::getType, uninventoryType); |
| | | } |
| | | if (StringUtils.isEmpty(batchNo)) { |
| | | eq.isNull(StockUninventory::getBatchNo); |
| | | } else { |
| | |
| | | } |
| | | } else if ("1".equals(stockInRecord.getType())) { |
| | | // ä¸åæ ¼å
¥åº -> å
æ¥åºåï¼åå¨åæ´æ°ï¼ä¸åå¨åæ°å¢ |
| | | StockUninventory stockUninventory = getStockUninventory(stockInRecord.getProductModelId(), stockInRecord.getBatchNo()); |
| | | String uninventoryType = resolveUninventoryTypeByInRecordType(stockInRecord.getRecordType()); |
| | | StockUninventory stockUninventory = getStockUninventory(stockInRecord.getProductModelId(), stockInRecord.getBatchNo(), uninventoryType); |
| | | StockUninventoryDto stockUninventoryDto = new StockUninventoryDto(); |
| | | stockUninventoryDto.setProductModelId(stockInRecord.getProductModelId()); |
| | | stockUninventoryDto.setBatchNo(stockInRecord.getBatchNo()); |
| | |
| | | stockUninventoryDto.setRemark(stockInRecord.getRemark()); |
| | | stockUninventoryDto.setManufacturerId(stockInRecord.getManufacturerId()); |
| | | stockUninventoryDto.setSource(stockInRecord.getSource()); |
| | | stockUninventoryDto.setType(uninventoryType); |
| | | if (stockUninventory == null) { |
| | | stockUninventoryMapper.insert(new StockUninventory() {{ |
| | | setProductModelId(stockInRecord.getProductModelId()); |
| | | setQualitity(finalStockInNum); |
| | | setBatchNo(stockInRecord.getBatchNo()); |
| | | setType(uninventoryType); |
| | | setRemark(stockInRecord.getRemark()); |
| | | setManufacturerId(stockInRecord.getManufacturerId()); |
| | | setSource(stockInRecord.getSource()); |
| | |
| | | return items.size(); |
| | | } |
| | | |
| | | private String resolveUninventoryTypeByInRecordType(String recordType) { |
| | | if (StockInQualifiedRecordTypeEnum.PRODUCTION_SCRAP.getCode().equals(recordType)) { |
| | | return WASTE_TYPE; |
| | | } |
| | | return UNQUALIFIED_TYPE; |
| | | } |
| | | |
| | | private void adjustPurchaseInboundAuditFields(StockInRecord stockInRecord, BigDecimal finalStockInNum) { |
| | | if (stockInRecord == null || finalStockInNum == null) { |
| | | return; |
| | |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class StockOutRecordServiceImpl extends ServiceImpl<StockOutRecordMapper, StockOutRecord> implements StockOutRecordService { |
| | | private static final String UNQUALIFIED_TYPE = "unqualified"; |
| | | private static final String WASTE_TYPE = "waste"; |
| | | |
| | | private final StockOutRecordMapper stockOutRecordMapper; |
| | | private final StockInventoryMapper stockInventoryMapper; |
| | | private final StockUninventoryMapper stockUninventoryMapper; |
| | |
| | | } |
| | | } |
| | | else if (stockOutRecord.getType().equals("1")) { |
| | | String uninventoryType = resolveUninventoryTypeByOutRecordType(stockOutRecord.getRecordType()); |
| | | LambdaQueryWrapper<StockUninventory> wrapper = new LambdaQueryWrapper<StockUninventory>() |
| | | .eq(StockUninventory::getProductModelId, stockOutRecord.getProductModelId()); |
| | | .eq(StockUninventory::getProductModelId, stockOutRecord.getProductModelId()) |
| | | .eq(StockUninventory::getType, uninventoryType); |
| | | if (StringUtils.isEmpty(stockOutRecord.getBatchNo())) { |
| | | wrapper.isNull(StockUninventory::getBatchNo); |
| | | } else { |
| | |
| | | stockUninventoryDto.setProductModelId(stockUninventory.getProductModelId()); |
| | | stockUninventoryDto.setQualitity(stockOutRecord.getStockOutNum()); |
| | | stockUninventoryDto.setBatchNo(stockUninventory.getBatchNo()); |
| | | stockUninventoryDto.setType(uninventoryType); |
| | | stockUninventoryMapper.updateAddStockUnInventory(stockUninventoryDto); |
| | | } |
| | | } |
| | |
| | | stockInventoryMapper.updateSubtractStockInventory(stockInventoryDto); |
| | | } else if ("1".equals(stockOutRecord.getType())) { |
| | | // ä¸åæ ¼åºåº -> å
æ¥åºåæ¯å¦åå¨ï¼å卿æ£å |
| | | StockUninventory stockUninventory = getStockUninventory(stockOutRecord.getProductModelId(), stockOutRecord.getBatchNo()); |
| | | String uninventoryType = resolveUninventoryTypeByOutRecordType(stockOutRecord.getRecordType()); |
| | | StockUninventory stockUninventory = getStockUninventory(stockOutRecord.getProductModelId(), stockOutRecord.getBatchNo(), uninventoryType); |
| | | if (stockUninventory == null) { |
| | | throw new BaseException("ä¸åæ ¼åºåè®°å½ä¸åå¨,åºåºæ¹æ¬¡:" + stockOutRecord.getOutboundBatches()); |
| | | } |
| | |
| | | stockUninventoryDto.setProductModelId(stockOutRecord.getProductModelId()); |
| | | stockUninventoryDto.setBatchNo(stockOutRecord.getBatchNo()); |
| | | stockUninventoryDto.setQualitity(stockOutRecord.getStockOutNum()); |
| | | stockUninventoryDto.setType(uninventoryType); |
| | | stockUninventoryMapper.updateSubtractStockUnInventory(stockUninventoryDto); |
| | | } |
| | | } |
| | |
| | | return stockInventoryMapper.selectOne(eq); |
| | | } |
| | | |
| | | private StockUninventory getStockUninventory(Long productModelId, String batchNo) { |
| | | private StockUninventory getStockUninventory(Long productModelId, String batchNo, String uninventoryType) { |
| | | LambdaQueryWrapper<StockUninventory> eq = new LambdaQueryWrapper<>(); |
| | | eq.eq(StockUninventory::getProductModelId, productModelId); |
| | | if (StringUtils.isNotEmpty(uninventoryType)) { |
| | | eq.eq(StockUninventory::getType, uninventoryType); |
| | | } |
| | | if (StringUtils.isEmpty(batchNo)) { |
| | | eq.isNull(StockUninventory::getBatchNo); |
| | | } else { |
| | |
| | | } |
| | | return stockUninventoryMapper.selectOne(eq); |
| | | } |
| | | |
| | | private String resolveUninventoryTypeByOutRecordType(String recordType) { |
| | | if (StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode().equals(recordType)) { |
| | | return WASTE_TYPE; |
| | | } |
| | | return UNQUALIFIED_TYPE; |
| | | } |
| | | } |
| | |
| | | @RequiredArgsConstructor |
| | | public class StockUninventoryServiceImpl extends ServiceImpl<StockUninventoryMapper, StockUninventory> implements StockUninventoryService { |
| | | |
| | | |
| | | private static final String UNQUALIFIED_TYPE = "unqualified"; |
| | | private final StockUninventoryMapper stockUninventoryMapper; |
| | | private final StockOutRecordService stockOutRecordService; |
| | | private final StockInRecordService stockInRecordService; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public IPage<StockUninventoryDto> pageWasteQuery(Page page, StockUninventoryDto stockUninventoryDto) { |
| | | return stockUninventoryMapper.pageWasteQuery(page, stockUninventoryDto); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Integer addStockUninventory(StockUninventoryDto stockUninventoryDto) { |
| | | String inventoryType = resolveInventoryType(stockUninventoryDto); |
| | | stockUninventoryDto.setType(inventoryType); |
| | | LambdaQueryWrapper<StockUninventory> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.eq(StockUninventory::getProductModelId, stockUninventoryDto.getProductModelId()); |
| | | wrapper.eq(StockUninventory::getType, inventoryType); |
| | | if (StringUtils.isEmpty(stockUninventoryDto.getBatchNo())) { |
| | | stockUninventoryDto.setBatchNo(null); |
| | | wrapper.isNull(StockUninventory::getBatchNo); |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Integer subtractStockUninventory(StockUninventoryDto stockUninventoryDto) { |
| | | String inventoryType = resolveInventoryType(stockUninventoryDto); |
| | | stockUninventoryDto.setType(inventoryType); |
| | | |
| | | // æ°å¢åºåºè®°å½ |
| | | StockOutRecordDto stockOutRecordDto = new StockOutRecordDto(); |
| | |
| | | stockOutRecordDto.setBatchNo(stockUninventoryDto.getBatchNo()); |
| | | stockOutRecordDto.setType("1"); |
| | | stockOutRecordService.add(stockOutRecordDto); |
| | | StockUninventory oldStockInventory = stockUninventoryMapper.selectOne(new QueryWrapper<StockUninventory>().lambda().eq(StockUninventory::getProductModelId, stockUninventoryDto.getProductModelId())); |
| | | StockUninventory oldStockInventory = stockUninventoryMapper.selectOne(new QueryWrapper<StockUninventory>().lambda() |
| | | .eq(StockUninventory::getProductModelId, stockUninventoryDto.getProductModelId()) |
| | | .eq(StockUninventory::getType, inventoryType)); |
| | | if (ObjectUtils.isEmpty(oldStockInventory)) { |
| | | throw new RuntimeException("产ååºåä¸åå¨"); |
| | | }else { |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Integer addStockInRecordOnly(StockUninventoryDto stockUninventoryDto) { |
| | | stockUninventoryDto.setType(resolveInventoryType(stockUninventoryDto)); |
| | | StockInRecordDto stockInRecordDto = new StockInRecordDto(); |
| | | stockInRecordDto.setRecordId(stockUninventoryDto.getRecordId()); |
| | | stockInRecordDto.setRecordType(stockUninventoryDto.getRecordType()); |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Integer addStockOutRecordOnly(StockUninventoryDto stockUninventoryDto) { |
| | | String inventoryType = resolveInventoryType(stockUninventoryDto); |
| | | stockUninventoryDto.setType(inventoryType); |
| | | LambdaQueryWrapper<StockUninventory> eq = new LambdaQueryWrapper<>(); |
| | | eq.eq(StockUninventory::getProductModelId, stockUninventoryDto.getProductModelId()); |
| | | eq.eq(StockUninventory::getType, inventoryType); |
| | | if (StringUtils.isEmpty(stockUninventoryDto.getBatchNo())) { |
| | | eq.isNull(StockUninventory::getBatchNo); |
| | | } else { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void exportWasteQuery(HttpServletResponse response, StockUninventoryDto stockUninventoryDto) { |
| | | List<StockUnInventoryExportData> list = stockUninventoryMapper.listWasteQueryExportData(stockUninventoryDto); |
| | | ExcelUtil<StockUnInventoryExportData> util = new ExcelUtil<>(StockUnInventoryExportData.class); |
| | | util.exportExcel(response, list, "åºåæ¥è¯¢ä¿¡æ¯"); |
| | | } |
| | | |
| | | @Override |
| | | public Boolean frozenStock(StockInventoryDto stockInventoryDto) { |
| | | StockUninventory stockUninventory = stockUninventoryMapper.selectById(stockInventoryDto.getId()); |
| | | if (stockUninventory.getQualitity().compareTo(stockInventoryDto.getLockedQuantity())<0) { |
| | |
| | | return this.updateById(stockUninventory); |
| | | } |
| | | |
| | | private String resolveInventoryType(StockUninventoryDto stockUninventoryDto) { |
| | | if (stockUninventoryDto != null && StringUtils.isNotEmpty(stockUninventoryDto.getType())) { |
| | | return stockUninventoryDto.getType().trim(); |
| | | } |
| | | return UNQUALIFIED_TYPE; |
| | | } |
| | | |
| | | //è§åçæï¼20260424-产åç¼å·-001 |
| | | private String generateAutoBatchNo(Long productModelId) { |
| | | if (productModelId == null) { |
| | |
| | | <result column="batch_no" property="batchNo" /> |
| | | <result column="quantity" property="quantity" /> |
| | | <result column="shipping_info_id" property="shippingInfoId" /> |
| | | <result column="product_model_id" property="productModelId" /> |
| | | <result column="stock_type" property="stockType" /> |
| | | </resultMap> |
| | | <select id="getDetail" resultType="com.ruoyi.sales.dto.ShippingProductDetailDto"> |
| | | select si.batch_no, pm.model as specification_model, p.product_name, spd.quantity as delivery_quantity |
| | | select spd.batch_no, pm.model as specification_model, p.product_name, spd.quantity as delivery_quantity |
| | | from shipping_product_detail spd |
| | | left join stock_inventory si on si.id = spd.stock_inventory_id |
| | | left join product_model pm on pm.id = si.product_model_id |
| | | left join product_model pm on pm.id = spd.product_model_id |
| | | left join product p on p.id = pm.product_id |
| | | where spd.shipping_info_id = #{id} |
| | | </select> |
| | | <select id="getDateilByShippingNo" resultType="com.ruoyi.sales.dto.ShippingProductDetailDto"> |
| | | select si.batch_no, pm.model as specification_model, p.product_name, spd.quantity as delivery_quantity |
| | | select spd.batch_no, pm.model as specification_model, p.product_name, spd.quantity as delivery_quantity |
| | | from shipping_product_detail spd |
| | | left join shipping_info sp on sp.id = spd.shipping_info_id |
| | | left join stock_inventory si on si.id = spd.stock_inventory_id |
| | | left join product_model pm on pm.id = si.product_model_id |
| | | left join product_model pm on pm.id = spd.product_model_id |
| | | left join product p on p.id = pm.product_id |
| | | where sp.shipping_no = #{shippingNo} |
| | | </select> |
| | |
| | | from stock_uninventory su |
| | | left join product_model pm on su.product_model_id = pm.id |
| | | left join product p on pm.product_id = p.id |
| | | where COALESCE(su.type, 'unqualified') != 'waste' |
| | | ) as combined |
| | | <where> |
| | | <if test="ew.productName != null and ew.productName !=''"> |
| | |
| | | from stock_uninventory su |
| | | left join product_model pm on su.product_model_id = pm.id |
| | | left join product p on pm.product_id = p.id |
| | | where COALESCE(su.type, 'unqualified') != 'waste' |
| | | ) as combined |
| | | <where> |
| | | <if test="ew.productName != null and ew.productName !=''"> |
| | |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.ruoyi.stock.mapper.StockUninventoryMapper"> |
| | | |
| | | <!-- éç¨æ¥è¯¢æ å°ç»æ --> |
| | | <resultMap id="BaseResultMap" type="com.ruoyi.stock.pojo.StockUninventory"> |
| | | <result column="id" property="id" /> |
| | | <result column="product_model_id" property="productModelId" /> |
| | | <result column="qualitity" property="qualitity" /> |
| | | <result column="type" property="type" /> |
| | | <result column="create_time" property="createTime" /> |
| | | <result column="update_time" property="updateTime" /> |
| | | <result column="version" property="version" /> |
| | | </resultMap> |
| | | |
| | | <sql id="WasteQueryRecursiveTree"> |
| | | WITH RECURSIVE product_tree AS ( |
| | | SELECT id |
| | | FROM product |
| | | WHERE id = #{ew.topParentProductId} |
| | | |
| | | UNION ALL |
| | | |
| | | SELECT p.id |
| | | FROM product p |
| | | INNER JOIN product_tree pt ON p.parent_id = pt.id |
| | | ) |
| | | </sql> |
| | | |
| | | <sql id="BaseWasteFromClause"> |
| | | from stock_uninventory su |
| | | left join product_model pm on su.product_model_id = pm.id |
| | | left join product p on pm.product_id = p.id |
| | | </sql> |
| | | |
| | | <sql id="WastePageColumns"> |
| | | su.id, |
| | | su.qualitity, |
| | | su.type, |
| | | COALESCE(su.locked_quantity, 0) as locked_quantity, |
| | | su.product_model_id, |
| | | su.create_time, |
| | | su.update_time, |
| | | su.version, |
| | | (su.qualitity - COALESCE(su.locked_quantity, 0)) as un_locked_quantity, |
| | | pm.model, |
| | | pm.unit, |
| | | p.product_name |
| | | </sql> |
| | | |
| | | <update id="updateSubtractStockUnInventory"> |
| | | update stock_uninventory |
| | | <set> |
| | |
| | | <if test="ew.version != null"> |
| | | version = version + 1, |
| | | </if> |
| | | <if test="ew.remark != null and ew.remark !=''"> |
| | | <if test="ew.remark != null and ew.remark != ''"> |
| | | remark = #{ew.remark}, |
| | | </if> |
| | | <if test="ew.type != null and ew.type != ''"> |
| | | type = #{ew.type}, |
| | | </if> |
| | | update_time = now() |
| | | </set> |
| | | where |
| | | product_model_id = #{ew.productModelId} and qualitity >= #{ew.qualitity} |
| | | where product_model_id = #{ew.productModelId} |
| | | and qualitity >= #{ew.qualitity} |
| | | <if test="ew.type != null and ew.type != ''"> |
| | | and type = #{ew.type} |
| | | </if> |
| | | <if test="ew.batchNo == null"> |
| | | and batch_no is null |
| | | </if> |
| | | <if test="ew.batchNo != null"> |
| | | and batch_no = #{ew.batchNo} |
| | | </if> |
| | | |
| | | </update> |
| | | |
| | | <update id="updateAddStockUnInventory"> |
| | | update stock_uninventory |
| | | <set> |
| | |
| | | <if test="ew.version != null"> |
| | | version = version + 1, |
| | | </if> |
| | | <if test="ew.remark != null and ew.remark !=''"> |
| | | <if test="ew.remark != null and ew.remark != ''"> |
| | | remark = #{ew.remark}, |
| | | </if> |
| | | <if test="ew.type != null and ew.type != ''"> |
| | | type = #{ew.type}, |
| | | </if> |
| | | update_time = now() |
| | | </set> |
| | | where product_model_id = #{ew.productModelId} |
| | | <if test="ew.type != null and ew.type != ''"> |
| | | and type = #{ew.type} |
| | | </if> |
| | | <if test="ew.batchNo == null"> |
| | | and batch_no is null |
| | | </if> |
| | |
| | | and batch_no = #{ew.batchNo} |
| | | </if> |
| | | </update> |
| | | |
| | | <select id="pageStockUninventory" resultType="com.ruoyi.stock.dto.StockUninventoryDto"> |
| | | select su.id, |
| | | select |
| | | su.id, |
| | | su.qualitity, |
| | | su.type, |
| | | COALESCE(su.locked_quantity, 0) as locked_quantity, |
| | | su.product_model_id, |
| | | su.create_time, |
| | |
| | | pm.model, |
| | | pm.unit, |
| | | p.product_name |
| | | from stock_uninventory su |
| | | left join product_model pm on su.product_model_id = pm.id |
| | | left join product p on pm.product_id = p.id |
| | | where 1 = 1 |
| | | <if test="ew.productName != null and ew.productName !=''"> |
| | | and p.product_name like concat('%',#{ew.productName},'%') |
| | | </if> |
| | | <include refid="BaseWasteFromClause" /> |
| | | <where> |
| | | <if test="ew.type != null and ew.type != ''"> |
| | | and su.type = #{ew.type} |
| | | </if> |
| | | <if test="ew.productName != null and ew.productName != ''"> |
| | | and p.product_name like concat('%', #{ew.productName}, '%') |
| | | </if> |
| | | </where> |
| | | </select> |
| | | |
| | | <select id="pageWasteQuery" resultType="com.ruoyi.stock.dto.StockUninventoryDto"> |
| | | <include refid="WasteQueryRecursiveTree" /> |
| | | select |
| | | <include refid="WastePageColumns" /> |
| | | <include refid="BaseWasteFromClause" /> |
| | | <where> |
| | | and su.type = 'waste' |
| | | <if test="ew.productName != null and ew.productName != ''"> |
| | | and p.product_name like concat('%', #{ew.productName}, '%') |
| | | </if> |
| | | <if test="ew.model != null and ew.model != ''"> |
| | | and pm.model like concat('%', #{ew.model}, '%') |
| | | </if> |
| | | <if test="ew.batchNo != null and ew.batchNo != ''"> |
| | | and su.batch_no like concat('%', #{ew.batchNo}, '%') |
| | | </if> |
| | | <if test="ew.topParentProductId != null and ew.topParentProductId > 0"> |
| | | and p.id in (select id from product_tree) |
| | | </if> |
| | | </where> |
| | | |
| | | order by su.update_time desc, su.id desc |
| | | </select> |
| | | |
| | | <select id="listStockInventoryExportData" resultType="com.ruoyi.stock.execl.StockUnInventoryExportData"> |
| | | select su.*, |
| | | select |
| | | su.*, |
| | | pm.model, |
| | | pm.unit, |
| | | p.product_name |
| | | from stock_uninventory su |
| | | left join product_model pm on su.product_model_id = pm.id |
| | | left join product p on pm.product_id = p.id |
| | | where 1 = 1 |
| | | <if test="ew.productName != null and ew.productName !=''"> |
| | | and p.product_name like concat('%',#{ew.productName},'%') |
| | | </if> |
| | | <include refid="BaseWasteFromClause" /> |
| | | <where> |
| | | <if test="ew.type != null and ew.type != ''"> |
| | | and su.type = #{ew.type} |
| | | </if> |
| | | <if test="ew.productName != null and ew.productName != ''"> |
| | | and p.product_name like concat('%', #{ew.productName}, '%') |
| | | </if> |
| | | </where> |
| | | </select> |
| | | |
| | | <select id="listWasteQueryExportData" resultType="com.ruoyi.stock.execl.StockUnInventoryExportData"> |
| | | <include refid="WasteQueryRecursiveTree" /> |
| | | select |
| | | su.*, |
| | | pm.model, |
| | | pm.unit, |
| | | p.product_name, |
| | | (su.qualitity - COALESCE(su.locked_quantity, 0)) as un_locked_quantity |
| | | <include refid="BaseWasteFromClause" /> |
| | | <where> |
| | | and su.type = 'waste' |
| | | <if test="ew.productName != null and ew.productName != ''"> |
| | | and p.product_name like concat('%', #{ew.productName}, '%') |
| | | </if> |
| | | <if test="ew.model != null and ew.model != ''"> |
| | | and pm.model like concat('%', #{ew.model}, '%') |
| | | </if> |
| | | <if test="ew.batchNo != null and ew.batchNo != ''"> |
| | | and su.batch_no like concat('%', #{ew.batchNo}, '%') |
| | | </if> |
| | | <if test="ew.topParentProductId != null and ew.topParentProductId > 0"> |
| | | and p.id in (select id from product_tree) |
| | | </if> |
| | | </where> |
| | | order by su.update_time desc, su.id desc |
| | | </select> |
| | | |
| | | <select id="selectPendingOutQuantity" resultType="java.math.BigDecimal"> |