doc/ºÓÄϺױÚÌìãå¸Ö»¯²£Á§³§.sql
@@ -139,3 +139,19 @@ ALTER TABLE `sales_ledger_product` ADD COLUMN `unqualified_stocked_quantity` decimal(18, 2) DEFAULT '0.00' COMMENT 'ä¸åæ ¼å ¥åºæ°é' AFTER `stocked_quantity`, ADD COLUMN `unqualified_shipped_quantity` decimal(18, 2) DEFAULT '0.00' COMMENT 'ä¸åæ ¼åºåºæ°é' AFTER `shipped_quantity`; ALTER TABLE `product-inventory-management-hbtmblc`.`purchase_ledger` ADD COLUMN `stock_status` tinyint(1) NULL DEFAULT 0 COMMENT 'å ¥åºç¶æï¼0-æªå ¥åºï¼1-é¨åå ¥åºï¼2-å·²å ¥åº' AFTER `approve_user_ids`; ALTER TABLE `product-inventory-management-hbtmblc`.`sales_ledger_product` MODIFY COLUMN `actual_piece_area` decimal(20, 4) NULL DEFAULT NULL COMMENT 'å®é åçé¢ç§¯(ã¡)' AFTER `is_checked`, MODIFY COLUMN `actual_total_area` decimal(20, 4) NULL DEFAULT NULL COMMENT 'å®é æ»é¢ç§¯(ã¡)' AFTER `actual_piece_area`, MODIFY COLUMN `settle_piece_area` decimal(20, 4) NULL DEFAULT NULL COMMENT 'ç»ç®åçé¢ç§¯(ã¡)' AFTER `actual_total_area`, MODIFY COLUMN `settle_total_area` decimal(20, 4) NULL DEFAULT NULL COMMENT 'ç»ç®æ»é¢ç§¯(ã¡)' AFTER `settle_piece_area`, MODIFY COLUMN `width` decimal(20, 4) NULL DEFAULT NULL COMMENT '宽' AFTER `settle_total_area`, MODIFY COLUMN `height` decimal(20, 4) NULL DEFAULT NULL COMMENT 'é«' AFTER `width`, MODIFY COLUMN `perimeter` decimal(20, 4) NULL DEFAULT NULL COMMENT 'å¨é¿' AFTER `remark`, MODIFY COLUMN `heavy_box` decimal(20, 4) NULL DEFAULT NULL COMMENT 'éç®±' AFTER `perimeter`; ALTER TABLE `product-inventory-management-hbtmblc`.`quality_unqualified` ADD COLUMN `product_model_id` bigint NULL COMMENT '产åè§æ ¼ID' AFTER `inspect_id`; src/main/java/com/ruoyi/approve/service/impl/ApproveNodeServiceImpl.java
@@ -13,7 +13,6 @@ import com.ruoyi.approve.service.IApproveNodeService; 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.device.pojo.DeviceRepair; @@ -39,6 +38,7 @@ import org.springframework.util.CollectionUtils; import java.io.IOException; import java.math.BigDecimal; import java.time.LocalDateTime; import java.util.Arrays; import java.util.Comparator; @@ -208,16 +208,26 @@ purchaseLedger.setApprovalStatus(3); List<SalesLedgerProduct> salesLedgerProducts = salesLedgerProductMapper.selectList(new QueryWrapper<SalesLedgerProduct>() .lambda().eq(SalesLedgerProduct::getSalesLedgerId, purchaseLedger.getId()).eq(SalesLedgerProduct::getType, 2)); boolean hasCheckedProduct = false; for (SalesLedgerProduct salesLedgerProduct : salesLedgerProducts) { // è´¨æ£ if (salesLedgerProduct.getIsChecked()) { hasCheckedProduct = true; purchaseLedgerServiceImpl.addQualityInspect(purchaseLedger, salesLedgerProduct); }else { //ç´æ¥å ¥åº stockUtils.addStock(null, salesLedgerProduct.getId(), salesLedgerProduct.getProductModelId(), salesLedgerProduct.getQuantity(), StockInQualifiedRecordTypeEnum.PURCHASE_STOCK_IN.getCode(), salesLedgerProduct.getId()); BigDecimal oldStocked = salesLedgerProduct.getStockedQuantity() == null ? BigDecimal.ZERO : salesLedgerProduct.getStockedQuantity(); BigDecimal orderQty = salesLedgerProduct.getQuantity() == null ? BigDecimal.ZERO : salesLedgerProduct.getQuantity(); BigDecimal newStocked = oldStocked.add(orderQty); salesLedgerProduct.setStockedQuantity(newStocked); salesLedgerProduct.setProductStockStatus(2); salesLedgerProduct.fillRemainingQuantity(); salesLedgerProductMapper.updateById(salesLedgerProduct); } } purchaseLedger.setStockStatus(hasCheckedProduct ? 0 : 2); } else if (status.equals(3)) { // æç» purchaseLedger.setApprovalStatus(4); src/main/java/com/ruoyi/common/enums/StockInQualifiedRecordTypeEnum.java
@@ -7,14 +7,13 @@ public enum StockInQualifiedRecordTypeEnum implements BaseEnum<String> { CUSTOMIZATION_STOCK_IN("0", "åæ ¼èªå®ä¹å ¥åº"), PRODUCTION_REPORT_STOCK_IN("2", "ç产æ¥å·¥-å ¥åº"), PURCHASE_STOCK_IN("7", "éè´-å ¥åº"), QUALITYINSPECT_STOCK_IN("6", "è´¨æ£-åæ ¼å ¥åº"), DEFECTIVE_PASS("11", "ä¸åæ ¼-è®©æ¥æ¾è¡"), RETURN_HE_IN("14", "éå®éè´§-åæ ¼å ¥åº"), SALE_STOCK_IN("15", "éå®è®¢å-åæ ¼å ¥åº"), SALE_SCAN_STOCK_IN("17", "éå®è®¢åæ«ç -åæ ¼å ¥åº"), PURCHASE_SCAN_STOCK_IN("18", "éè´è®¢åæ«ç -åæ ¼å ¥åº"); PURCHASE_SCAN_STOCK_IN("18", "éè´è®¢åæ«ç -åæ ¼å ¥åº"), PURCHASE_SCAN_QUALITY_STOCK_IN("19", "æ«ç å ¥åºè´¨æ£-åæ ¼å ¥åº"); private final String code; src/main/java/com/ruoyi/common/enums/StockInUnQualifiedRecordTypeEnum.java
@@ -11,9 +11,9 @@ PRODUCTION_SCRAP("5", "ç产æ¥å·¥-æ¥åº"), CUSTOMIZATION_UNSTOCK_IN("9", "ä¸åæ ¼èªå®ä¹å ¥åº"), QUALITYINSPECT_UNSTOCK_IN("12", "è´¨æ£-ä¸åæ ¼å ¥åº"), RETURN_UNSTOCK_IN("15", "éå®éè´§-ä¸åæ ¼å ¥åº"), SALES_SCAN_UNSTOCK_IN("16", "éå®è®¢åæ«ç -ä¸åæ ¼å ¥åº"), PURCHASE_SCAN_UNSTOCK_IN("19", "éè´è®¢åæ«ç -ä¸åæ ¼å ¥åº"); PURCHASE_SCAN_UNSTOCK_IN("19", "éè´è®¢åæ«ç -ä¸åæ ¼å ¥åº"), PURCHASE_SCAN_QUALITY_UNSTOCK_IN("20", "æ«ç å ¥åºè´¨æ£-ä¸åæ ¼å ¥åº"); private final String code; src/main/java/com/ruoyi/purchase/dto/PurchaseLedgerDto.java
@@ -193,6 +193,13 @@ private String paymentMethod; @ApiModelProperty("审æ¹ç¶æ") private Integer approvalStatus; @ApiModelProperty("éè´è®¢åå ¥åºç¶æï¼0-æªå ¥åºï¼1-é¨åå ¥åºï¼2-å·²å ¥åº") private Integer stockStatus; @ApiModelProperty("éè´è®¢å产åå ¥åºç¶æï¼0-æªå ¥åºï¼1-é¨åå ¥åºï¼2-å·²å ¥åº") private Integer productStockStatus; @ApiModelProperty(value = "模æ¿åç§°") private String templateName; @ApiModelProperty(value = "审æ¹äººid") src/main/java/com/ruoyi/purchase/pojo/PurchaseLedger.java
@@ -159,4 +159,9 @@ @ApiModelProperty(value = "审æ¹äººid") private String approveUserIds; /** * å ¥åºç¶æï¼0-æªå ¥åºï¼1-é¨åå ¥åºï¼2-å·²å ¥åº */ private Integer stockStatus; } src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java
@@ -141,6 +141,8 @@ @Autowired private QualityInspectMapper qualityInspectMapper; @Autowired private QualityUnqualifiedMapper qualityUnqualifiedMapper; @Autowired private CommonFileServiceImpl commonFileService; @Autowired private QualityTestStandardBindingMapper qualityTestStandardBindingMapper; @@ -212,6 +214,7 @@ purchaseLedger.setRecorderName(sysUser.getNickName()); purchaseLedger.setPhoneNumber(sysUser.getPhonenumber()); purchaseLedger.setApprovalStatus(1); purchaseLedger.setStockStatus(0); // 3. æ°å¢ææ´æ°ä¸»è¡¨ if (purchaseLedger.getId() == null) { purchaseLedgerMapper.insert(purchaseLedger); @@ -336,6 +339,7 @@ if (!updateList.isEmpty()) { for (SalesLedgerProduct product : updateList) { product.setType(type); product.setProductStockStatus(calculateProductStockStatus(product)); product.fillRemainingQuantity(); salesLedgerProductMapper.updateById(product); } @@ -351,6 +355,7 @@ salesLedgerProduct.setFutureTickets(salesLedgerProduct.getQuantity()); salesLedgerProduct.setFutureTicketsAmount(salesLedgerProduct.getTaxInclusiveTotalPrice()); salesLedgerProduct.setPendingTicketsTotal(salesLedgerProduct.getTaxInclusiveTotalPrice()); salesLedgerProduct.setProductStockStatus(calculateProductStockStatus(salesLedgerProduct)); salesLedgerProduct.fillRemainingQuantity(); salesLedgerProductMapper.insert(salesLedgerProduct); } @@ -481,7 +486,8 @@ .in(StockInRecord::getSalesLedgerProductId, productIds) .or(q -> q.in(StockInRecord::getRecordId, productIds) .in(StockInRecord::getRecordType, Arrays.asList( StockInUnQualifiedRecordTypeEnum.PURCHASE_SCAN_UNSTOCK_IN.getCode() StockInUnQualifiedRecordTypeEnum.PURCHASE_SCAN_UNSTOCK_IN.getCode(), StockInUnQualifiedRecordTypeEnum.PURCHASE_SCAN_QUALITY_UNSTOCK_IN.getCode() )))) .select(StockInRecord::getId)) .stream().map(StockInRecord::getId).collect(Collectors.toList()); @@ -567,7 +573,7 @@ productWrapper.eq(SalesLedgerProduct::getSalesLedgerId, purchaseLedger.getId()) .eq(SalesLedgerProduct::getType, purchaseLedgerDto.getType()); List<SalesLedgerProduct> products = salesLedgerProductMapper.selectList(productWrapper); products.forEach(SalesLedgerProduct::fillRemainingQuantity); applyQualityInboundToProducts(purchaseLedger.getId(), products); // 3.æ¥è¯¢ä¸ä¼ æä»¶ LambdaQueryWrapper<CommonFile> salesLedgerFileWrapper = new LambdaQueryWrapper<>(); @@ -837,7 +843,7 @@ productWrapper.eq(SalesLedgerProduct::getSalesLedgerId, purchaseLedger.getId()) .eq(SalesLedgerProduct::getType, 2); List<SalesLedgerProduct> products = salesLedgerProductMapper.selectList(productWrapper); products.forEach(SalesLedgerProduct::fillRemainingQuantity); applyQualityInboundToProducts(purchaseLedger.getId(), products); // 4. è½¬æ¢ DTO PurchaseLedgerDto resultDto = new PurchaseLedgerDto(); @@ -908,7 +914,57 @@ if (dbProduct.getProductModelId() == null) { throw new ServiceException("å ¥åºå¤±è´¥,产åè§æ ¼æªç»´æ¤,æ æ³å ¥åº"); } BigDecimal orderQty = dbProduct.getQuantity() == null ? BigDecimal.ZERO : dbProduct.getQuantity(); if (orderQty.compareTo(BigDecimal.ZERO) <= 0) { throw new ServiceException("å ¥åºå¤±è´¥,éè´äº§åæ°éå¼å¸¸"); } // éè¦è´¨æ£ï¼æ«ç å ¥åºè¿å ¥åæææ£éªï¼ä¸ç´æ¥å ¥åæ ¼åºå if (Boolean.TRUE.equals(dbProduct.getIsChecked())) { // å卿ªéè¿/æªå¤ççåæææ£éªåï¼åç¦æ¢ç»§ç»æ«ç å ¥åº Long pendingInspectCount = qualityInspectMapper.selectCount(new LambdaQueryWrapper<QualityInspect>() .eq(QualityInspect::getInspectType, 0) .eq(QualityInspect::getPurchaseLedgerId, purchaseId) .eq(QualityInspect::getProductModelId, dbProduct.getProductModelId()) .and(w -> w .isNull(QualityInspect::getInspectState) .or(q0 -> q0.eq(QualityInspect::getInspectState, 0)) // inspect_state=1 ä¹è§ä¸ºâæªå¤çâ .or(q1 -> q1.eq(QualityInspect::getInspectState, 1) .isNull(QualityInspect::getCheckResult)))); if (pendingInspectCount != null && pendingInspectCount > 0) { throw new ServiceException("å ¥åºå¤±è´¥,å卿ªéè¿ææªå¤ççè´¨æ£è®°å½,请å å¤çååæ«ç å ¥åº"); } // éè¦è´¨æ£æ¶ï¼æâå¾ æ£/å·²åæ ¼âçæ£éªæ°éæ§å¶æ«ç ä¸é BigDecimal inspectQty = qualityInspectMapper.selectList(new LambdaQueryWrapper<QualityInspect>() .eq(QualityInspect::getInspectType, 0) .eq(QualityInspect::getPurchaseLedgerId, purchaseId) .eq(QualityInspect::getProductModelId, dbProduct.getProductModelId()) .and(w -> w .isNull(QualityInspect::getInspectState) .or(q0 -> q0.eq(QualityInspect::getInspectState, 0)) .or(q1 -> q1.eq(QualityInspect::getInspectState, 1) .and(r -> r.isNull(QualityInspect::getCheckResult) .or() .eq(QualityInspect::getCheckResult, "åæ ¼"))))) .stream() .map(QualityInspect::getQuantity) .filter(Objects::nonNull) .reduce(BigDecimal.ZERO, BigDecimal::add); if (inspectQty.add(inboundThisLine).compareTo(orderQty) > 0) { throw new ServiceException("å ¥åºå¤±è´¥,æ«ç åæ ¼å ¥åºæ°éä¸è½è¶ è¿éè´äº§åæ°é"); } SalesLedgerProduct scanInspectProduct = new SalesLedgerProduct(); BeanUtils.copyProperties(dbProduct, scanInspectProduct); scanInspectProduct.setQuantity(inboundThisLine); addQualityInspect(purchaseLedger, scanInspectProduct); continue; } // ä¸éè¦è´¨æ£ï¼æ«ç ç´æ¥å ¥åºï¼å 许å¤å ¥åºï¼ä¸åä¸ééå¶ï¼ BigDecimal oldStocked = dbProduct.getStockedQuantity() == null ? BigDecimal.ZERO : dbProduct.getStockedQuantity(); if (oldStocked.add(inboundThisLine).compareTo(orderQty) > 0) { throw new ServiceException("å ¥åºå¤±è´¥,æ«ç åæ ¼å ¥åºæ°éä¸è½è¶ è¿éè´äº§åæ°é"); } BigDecimal newStocked = oldStocked.add(inboundThisLine); StockInventoryDto stockInventoryDto = new StockInventoryDto(); @@ -920,7 +976,6 @@ stockInventoryDto.setSalesLedgerProductId(dbProduct.getId()); stockInventoryService.addstockInventory(stockInventoryDto); BigDecimal orderQty = dbProduct.getQuantity() == null ? BigDecimal.ZERO : dbProduct.getQuantity(); int lineStockStatus; if (newStocked.compareTo(BigDecimal.ZERO) <= 0) { lineStockStatus = 0; @@ -934,6 +989,7 @@ dbProduct.fillRemainingQuantity(); salesLedgerProductMapper.updateById(dbProduct); } refreshPurchaseLedgerStockStatus(purchaseLedger.getId()); } @Override @@ -1051,7 +1107,28 @@ throw new ServiceException("ä¸åæ ¼å ¥åºå¤±è´¥,产åè§æ ¼æªç»´æ¤,æ æ³å ¥åº"); } stockUtils.addUnStock(null, null, dbProduct.getProductModelId(), inboundThisLine, StockInUnQualifiedRecordTypeEnum.PURCHASE_SCAN_UNSTOCK_IN.getCode(), dbProduct.getId()); Boolean.TRUE.equals(dbProduct.getIsChecked()) ? StockInUnQualifiedRecordTypeEnum.PURCHASE_SCAN_QUALITY_UNSTOCK_IN.getCode() : StockInUnQualifiedRecordTypeEnum.PURCHASE_SCAN_UNSTOCK_IN.getCode(), dbProduct.getId()); // éè´ä¸åæ ¼å ¥åºåï¼èªå¨è¿å ¥ä¸åæ ¼ç®¡çï¼çå¾ ç¨æ·å¤ç QualityUnqualified qualityUnqualified = new QualityUnqualified(); qualityUnqualified.setInspectType(0); // åææä¸åæ ¼ qualityUnqualified.setInspectState(0); // å¾ å¤ç qualityUnqualified.setCheckTime(new Date()); LoginUser loginUser = SecurityUtils.getLoginUser(); if (loginUser != null && loginUser.getUser() != null) { qualityUnqualified.setCheckName(loginUser.getUser().getNickName()); } qualityUnqualified.setProductId(dbProduct.getProductId()); qualityUnqualified.setProductModelId(dbProduct.getProductModelId()); qualityUnqualified.setProductName(dbProduct.getProductCategory()); qualityUnqualified.setModel(dbProduct.getSpecificationModel()); qualityUnqualified.setUnit(dbProduct.getUnit()); qualityUnqualified.setQuantity(inboundThisLine); qualityUnqualified.setDefectivePhenomena("éè´è®¢åæ«ç ä¸åæ ¼å ¥åºï¼å¾ å¤ç"); qualityUnqualifiedMapper.insert(qualityUnqualified); BigDecimal oldUnStocked = dbProduct.getUnqualifiedStockedQuantity() == null ? BigDecimal.ZERO : dbProduct.getUnqualifiedStockedQuantity(); dbProduct.setUnqualifiedStockedQuantity(oldUnStocked.add(inboundThisLine)); @@ -1124,6 +1201,105 @@ } } private void applyQualityInboundToProducts(Long purchaseLedgerId, List<SalesLedgerProduct> products) { if (CollectionUtils.isEmpty(products)) { return; } Map<Long, BigDecimal> qualityInboundQtyByLine = getQualifiedInspectInboundQtyByLine(purchaseLedgerId); for (SalesLedgerProduct product : products) { product.fillRemainingQuantity(); if (!Boolean.TRUE.equals(product.getIsChecked())) { continue; } BigDecimal orderQty = product.getQuantity() == null ? BigDecimal.ZERO : product.getQuantity(); BigDecimal scanInboundQty = product.getStockedQuantity() == null ? BigDecimal.ZERO : product.getStockedQuantity(); BigDecimal qualityInboundQty = qualityInboundQtyByLine.getOrDefault(product.getId(), BigDecimal.ZERO); BigDecimal totalQualifiedInbound = qualityInboundQty.add(scanInboundQty); BigDecimal remainingInbound = orderQty.subtract(totalQualifiedInbound); product.setRemainingQuantity(remainingInbound.compareTo(BigDecimal.ZERO) < 0 ? BigDecimal.ZERO : remainingInbound); BigDecimal shippedQty = product.getShippedQuantity() == null ? BigDecimal.ZERO : product.getShippedQuantity(); BigDecimal remainingShipped = totalQualifiedInbound.subtract(shippedQty); product.setRemainingShippedQuantity(remainingShipped.compareTo(BigDecimal.ZERO) < 0 ? BigDecimal.ZERO : remainingShipped); } } private Map<Long, BigDecimal> getQualifiedInspectInboundQtyByLine(Long purchaseLedgerId) { Map<Long, BigDecimal> qualityInboundByModel = qualityInspectMapper.selectList(new LambdaQueryWrapper<QualityInspect>() .eq(QualityInspect::getInspectType, 0) .eq(QualityInspect::getPurchaseLedgerId, purchaseLedgerId) .eq(QualityInspect::getInspectState, 1) .eq(QualityInspect::getCheckResult, "åæ ¼")) .stream() .filter(qualityInspect -> qualityInspect.getProductModelId() != null && qualityInspect.getQuantity() != null) .collect(Collectors.groupingBy(QualityInspect::getProductModelId, Collectors.reducing(BigDecimal.ZERO, QualityInspect::getQuantity, BigDecimal::add))); if (qualityInboundByModel.isEmpty()) { return Collections.emptyMap(); } List<SalesLedgerProduct> purchaseProducts = salesLedgerProductMapper.selectList(new LambdaQueryWrapper<SalesLedgerProduct>() .eq(SalesLedgerProduct::getSalesLedgerId, purchaseLedgerId) .eq(SalesLedgerProduct::getType, PURCHASE.getCode())); Map<Long, BigDecimal> qualityInboundByLine = new HashMap<>(); for (SalesLedgerProduct product : purchaseProducts) { if (product.getId() == null || product.getProductModelId() == null) { continue; } qualityInboundByLine.put(product.getId(), qualityInboundByModel.getOrDefault(product.getProductModelId(), BigDecimal.ZERO)); } return qualityInboundByLine; } private void refreshPurchaseLedgerStockStatus(Long purchaseLedgerId) { if (purchaseLedgerId == null) { return; } List<SalesLedgerProduct> products = salesLedgerProductMapper.selectList(new LambdaQueryWrapper<SalesLedgerProduct>() .eq(SalesLedgerProduct::getSalesLedgerId, purchaseLedgerId) .eq(SalesLedgerProduct::getType, PURCHASE.getCode())); if (CollectionUtils.isEmpty(products)) { return; } Map<Long, BigDecimal> qualityInboundQtyByLine = getQualifiedInspectInboundQtyByLine(purchaseLedgerId); boolean allInbound = true; boolean anyInbound = false; for (SalesLedgerProduct product : products) { BigDecimal orderQty = product.getQuantity() == null ? BigDecimal.ZERO : product.getQuantity(); BigDecimal scanInboundQty = product.getStockedQuantity() == null ? BigDecimal.ZERO : product.getStockedQuantity(); BigDecimal qualityInboundQty = qualityInboundQtyByLine.getOrDefault(product.getId(), BigDecimal.ZERO); BigDecimal totalInboundQty = scanInboundQty.add(qualityInboundQty); if (totalInboundQty.compareTo(BigDecimal.ZERO) > 0) { anyInbound = true; } if (totalInboundQty.compareTo(orderQty) < 0) { allInbound = false; } } PurchaseLedger purchaseLedger = purchaseLedgerMapper.selectById(purchaseLedgerId); if (purchaseLedger == null) { return; } int targetStockStatus = allInbound ? 2 : (anyInbound ? 1 : 0); if (!Objects.equals(purchaseLedger.getStockStatus(), targetStockStatus)) { purchaseLedger.setStockStatus(targetStockStatus); purchaseLedgerMapper.updateById(purchaseLedger); } } private Integer calculateProductStockStatus(SalesLedgerProduct product) { if (product == null) { return 0; } BigDecimal orderQty = product.getQuantity() == null ? BigDecimal.ZERO : product.getQuantity(); BigDecimal stockedQty = product.getStockedQuantity() == null ? BigDecimal.ZERO : product.getStockedQuantity(); if (stockedQty.compareTo(BigDecimal.ZERO) <= 0) { return 0; } if (orderQty.compareTo(BigDecimal.ZERO) > 0 && stockedQty.compareTo(orderQty) < 0) { return 1; } return 2; } /** * ä¸å线å½å转驼峰å½å */ src/main/java/com/ruoyi/quality/pojo/QualityUnqualified.java
@@ -63,6 +63,11 @@ private Long productId; /** * 产åè§æ ¼ID */ private Long productModelId; /** * 产ååç§° */ @Excel(name = "产ååç§°") src/main/java/com/ruoyi/quality/service/impl/QualityInspectServiceImpl.java
@@ -2,6 +2,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -9,7 +10,6 @@ import com.deepoove.poi.XWPFTemplate; import com.deepoove.poi.config.Configure; import com.ruoyi.common.enums.StockInQualifiedRecordTypeEnum; import com.ruoyi.common.enums.StockOutQualifiedRecordTypeEnum; import com.ruoyi.common.utils.HackLoopTableRenderPolicy; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.procurementrecord.service.ProcurementRecordService; @@ -23,7 +23,10 @@ import com.ruoyi.quality.pojo.QualityUnqualified; import com.ruoyi.quality.service.IQualityInspectParamService; import com.ruoyi.quality.service.IQualityInspectService; import com.ruoyi.purchase.mapper.PurchaseLedgerMapper; import com.ruoyi.purchase.pojo.PurchaseLedger; import com.ruoyi.sales.mapper.SalesLedgerProductMapper; import com.ruoyi.sales.pojo.SalesLedgerProduct; import lombok.AllArgsConstructor; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; @@ -32,9 +35,11 @@ import javax.servlet.http.HttpServletResponse; import java.io.InputStream; import java.io.OutputStream; import java.math.BigDecimal; import java.net.URLEncoder; import java.util.HashMap; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @AllArgsConstructor @@ -52,6 +57,8 @@ private QualityUnqualifiedMapper qualityUnqualifiedMapper; private SalesLedgerProductMapper salesLedgerProductMapper; private PurchaseLedgerMapper purchaseLedgerMapper; private ProcurementRecordService procurementRecordService; @@ -99,9 +106,13 @@ } else { //åæ ¼ç´æ¥å ¥åº stockUtils.addStock(qualityInspect.getProductModelId(), qualityInspect.getQuantity(), StockInQualifiedRecordTypeEnum.QUALITYINSPECT_STOCK_IN.getCode(), qualityInspect.getId()); // éè´åæææ£éªï¼åæ ¼å ¥åºå忥å°éè´äº§åâå·²å ¥åºæ°éâï¼ä¸æ«ç å ¥åºå ±ç¨ä¸ä»½æ°æ®å£å¾ syncQualifiedInboundToPurchaseProducts(qualityInspect); } qualityInspect.setInspectState(1);//å·²æäº¤ return qualityInspectMapper.updateById(qualityInspect); int updated = qualityInspectMapper.updateById(qualityInspect); refreshPurchaseLedgerStockStatusByInspect(qualityInspect.getPurchaseLedgerId()); return updated; } /*çææ£éªæ¥å*/ @@ -193,5 +204,114 @@ } private void refreshPurchaseLedgerStockStatusByInspect(Long purchaseLedgerId) { if (purchaseLedgerId == null) { return; } List<SalesLedgerProduct> products = salesLedgerProductMapper.selectList(new LambdaQueryWrapper<SalesLedgerProduct>() .eq(SalesLedgerProduct::getSalesLedgerId, purchaseLedgerId) .eq(SalesLedgerProduct::getType, 2)); if (products == null || products.isEmpty()) { return; } boolean allInbound = true; boolean anyInbound = false; for (SalesLedgerProduct product : products) { BigDecimal orderQty = product.getQuantity() == null ? BigDecimal.ZERO : product.getQuantity(); BigDecimal totalInboundQty = product.getStockedQuantity() == null ? BigDecimal.ZERO : product.getStockedQuantity(); if (totalInboundQty.compareTo(BigDecimal.ZERO) > 0) { anyInbound = true; } if (totalInboundQty.compareTo(orderQty) < 0) { allInbound = false; } } PurchaseLedger purchaseLedger = purchaseLedgerMapper.selectById(purchaseLedgerId); if (purchaseLedger == null) { return; } int targetStockStatus = allInbound ? 2 : (anyInbound ? 1 : 0); if (!Objects.equals(purchaseLedger.getStockStatus(), targetStockStatus)) { purchaseLedger.setStockStatus(targetStockStatus); purchaseLedgerMapper.updateById(purchaseLedger); } } private void syncQualifiedInboundToPurchaseProducts(QualityInspect qualityInspect) { if (qualityInspect == null) { return; } if (!Objects.equals(qualityInspect.getInspectType(), 0) || qualityInspect.getPurchaseLedgerId() == null) { return; } if (qualityInspect.getProductModelId() == null || qualityInspect.getQuantity() == null) { return; } BigDecimal inboundQty = qualityInspect.getQuantity(); if (inboundQty.compareTo(BigDecimal.ZERO) <= 0) { return; } List<SalesLedgerProduct> lines = salesLedgerProductMapper.selectList(new LambdaQueryWrapper<SalesLedgerProduct>() .eq(SalesLedgerProduct::getSalesLedgerId, qualityInspect.getPurchaseLedgerId()) .eq(SalesLedgerProduct::getType, 2) .eq(SalesLedgerProduct::getProductModelId, qualityInspect.getProductModelId()) .eq(SalesLedgerProduct::getIsChecked, true) .orderByAsc(SalesLedgerProduct::getId)); if (lines == null || lines.isEmpty()) { return; } BigDecimal remaining = inboundQty; SalesLedgerProduct fallbackLine = null; for (SalesLedgerProduct line : lines) { if (remaining.compareTo(BigDecimal.ZERO) <= 0) { break; } BigDecimal orderQty = line.getQuantity() == null ? BigDecimal.ZERO : line.getQuantity(); BigDecimal stocked = line.getStockedQuantity() == null ? BigDecimal.ZERO : line.getStockedQuantity(); BigDecimal canFill = orderQty.subtract(stocked); if (canFill.compareTo(BigDecimal.ZERO) <= 0) { fallbackLine = line; continue; } BigDecimal add = canFill.min(remaining); BigDecimal newStocked = stocked.add(add); int status; if (newStocked.compareTo(BigDecimal.ZERO) <= 0) { status = 0; } else if (orderQty.compareTo(BigDecimal.ZERO) > 0 && newStocked.compareTo(orderQty) < 0) { status = 1; } else { status = 2; } line.setStockedQuantity(newStocked); line.setProductStockStatus(status); line.fillRemainingQuantity(); salesLedgerProductMapper.updateById(line); remaining = remaining.subtract(add); fallbackLine = line; } // å 许å¤å ¥åºï¼è¥ä»æå©ä½ï¼ç´¯è®¡å°æåä¸è¡ï¼ç¡®ä¿ remaining_shipped_quantity è½åæ¥å¢é¿ if (remaining.compareTo(BigDecimal.ZERO) > 0 && fallbackLine != null) { BigDecimal orderQty = fallbackLine.getQuantity() == null ? BigDecimal.ZERO : fallbackLine.getQuantity(); BigDecimal stocked = fallbackLine.getStockedQuantity() == null ? BigDecimal.ZERO : fallbackLine.getStockedQuantity(); BigDecimal newStocked = stocked.add(remaining); int status; if (newStocked.compareTo(BigDecimal.ZERO) <= 0) { status = 0; } else if (orderQty.compareTo(BigDecimal.ZERO) > 0 && newStocked.compareTo(orderQty) < 0) { status = 1; } else { status = 2; } fallbackLine.setStockedQuantity(newStocked); fallbackLine.setProductStockStatus(status); fallbackLine.fillRemainingQuantity(); salesLedgerProductMapper.updateById(fallbackLine); } } } src/main/java/com/ruoyi/quality/service/impl/QualityUnqualifiedServiceImpl.java
@@ -63,8 +63,16 @@ @Override public int deal(QualityUnqualified qualityUnqualified) { QualityUnqualified unqualified = qualityUnqualifiedMapper.selectById(qualityUnqualified.getId()); QualityInspect qualityInspect = qualityInspectService.getById(unqualified.getInspectId()); if (ObjectUtils.isNotNull(qualityInspect) && qualityInspect.getInspectType() != 0) { if (ObjectUtils.isNull(unqualified)) { throw new RuntimeException("ä¸åæ ¼è®°å½ä¸åå¨"); } QualityInspect qualityInspect = null; if (ObjectUtils.isNotNull(unqualified.getInspectId())) { qualityInspect = qualityInspectService.getById(unqualified.getInspectId()); } if (ObjectUtils.isNotNull(unqualified.getInspectId()) && ObjectUtils.isNotNull(qualityInspect) && qualityInspect.getInspectType() != 0) { switch (qualityUnqualified.getDealResult()) { case "è¿ä¿®": case "è¿å·¥": @@ -137,8 +145,14 @@ break; } } else { //æ¥è¯¢å¯¹åºçè§æ ¼åå·id Long modelId = qualityUnqualifiedMapper.getModelId(qualityUnqualified.getProductName(), qualityUnqualified.getModel()); // æ«ç ä¸åæ ¼ä¼å ä½¿ç¨ productModelId Long modelId = unqualified.getProductModelId(); if (ObjectUtils.isNull(modelId)) { modelId = qualityUnqualifiedMapper.getModelId(qualityUnqualified.getProductName(), qualityUnqualified.getModel()); } if (ObjectUtils.isNull(modelId)) { throw new RuntimeException("å¤ç失败,æªæ¾å°å¯¹åºäº§åè§æ ¼,è¯·æ£æ¥äº§ååç§°åè§æ ¼åå·"); } switch (qualityUnqualified.getDealResult()) { case "æ¥åº": //è°ç¨ä¸åæ ¼åºåæ¥å£ å ¥ä¸åæ ¼åº src/main/java/com/ruoyi/sales/controller/ShippingInfoController.java
@@ -28,7 +28,6 @@ import com.ruoyi.sales.pojo.SalesLedgerProduct; // import com.ruoyi.sales.pojo.ShipmentApproval; import com.ruoyi.sales.pojo.ShippingInfo; import com.ruoyi.sales.service.ISalesLedgerProductService; import com.ruoyi.sales.service.ISalesLedgerService; import com.ruoyi.sales.service.ShippingInfoService; // import com.ruoyi.sales.service.impl.CommonFileServiceImpl; @@ -67,9 +66,6 @@ // private StockUtils stockUtils; @Autowired private ISalesLedgerProductService salesLedgerProductService; @Autowired private ISalesLedgerService salesLedgerService; @Autowired @@ -99,6 +95,15 @@ return AjaxResult.error("å ³è订åä¸åå¨"); } // åè´§åå¿ é¡»ä¿è¯è¯¥è®¢åææäº§åå·²å ¥åº List<SalesLedgerProduct> notStocked = salesLedgerProductMapper.selectList(new LambdaQueryWrapper<SalesLedgerProduct>() .eq(SalesLedgerProduct::getSalesLedgerId, salesLedger.getId()) .eq(SalesLedgerProduct::getType, 1) .ne(SalesLedgerProduct::getProductStockStatus, 2)); if (CollectionUtils.isNotEmpty(notStocked)) { return AjaxResult.error("å货失败,该éå®è®¢åå卿ªå ¥åºäº§å,请å å®æå ¨é¨å ¥åºåååè´§"); } // æ£æ¥æ¯å¦å·²ç»å¨å®¡æ¹ä¸æå·²åè´§ if (salesLedger.getDeliveryStatus() != null && salesLedger.getDeliveryStatus() >= 2 && !salesLedger.getDeliveryStatus().equals(3)) { return AjaxResult.error("该订åå·²å¨å®¡æ¹ä¸æå·²åè´§ï¼æ æ³éå¤åèµ·"); src/main/java/com/ruoyi/sales/pojo/SalesLedgerProduct.java
@@ -340,6 +340,10 @@ @TableField(exist = false) private Integer hasSufficientStock; @TableField(exist = false) @ApiModelProperty("éè´è®¢åå ¥åºç¶æï¼0-æªå ¥åºï¼1-é¨åå ¥åºï¼2-å·²å ¥åº") private Integer purchaseStockStatus; // éè´§æ°é @TableField(exist = false) private BigDecimal returnQuality; src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java
@@ -9,6 +9,7 @@ import com.ruoyi.basic.mapper.ProductModelMapper; import com.ruoyi.basic.pojo.ProductModel; import com.ruoyi.common.enums.StockOutQualifiedRecordTypeEnum; import com.ruoyi.common.enums.StockInQualifiedRecordTypeEnum; import com.ruoyi.common.enums.StockInUnQualifiedRecordTypeEnum; import com.ruoyi.framework.web.domain.R; import com.ruoyi.procurementrecord.utils.StockUtils; @@ -32,6 +33,9 @@ import com.ruoyi.sales.service.ISalesLedgerProductProcessBindService; import com.ruoyi.sales.service.ISalesLedgerProductService; import com.ruoyi.stock.mapper.StockInventoryMapper; import com.ruoyi.stock.mapper.StockInRecordMapper; import com.ruoyi.stock.dto.StockInventoryDto; import com.ruoyi.stock.pojo.StockInRecord; import com.ruoyi.stock.pojo.StockInventory; import lombok.AllArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; @@ -88,6 +92,8 @@ private ShippingInfoServiceImpl shippingInfoService; private StockUtils stockUtils; private StockInRecordMapper stockInRecordMapper; private final ISalesLedgerProductProcessBindService salesLedgerProductProcessBindService; @@ -294,9 +300,32 @@ result = salesLedgerProductMapper.insert(salesLedgerProduct); addProductionData(salesLedgerProduct); } else { SalesLedgerProduct dbBefore = salesLedgerProductMapper.selectById(salesLedgerProduct.getId()); if (dbBefore == null) { throw new RuntimeException("éå®äº§åä¸åå¨ï¼æ æ³ç¼è¾"); } // ä¸è½æè®¢åæ°éæ¹å°å°äºå·²åè´§æ°éï¼å¦åè´¦å®ä¸ä¸è´ BigDecimal shipped = dbBefore.getShippedQuantity() == null ? BigDecimal.ZERO : dbBefore.getShippedQuantity(); BigDecimal newOrderQty = salesLedgerProduct.getQuantity() == null ? BigDecimal.ZERO : salesLedgerProduct.getQuantity(); if (newOrderQty.compareTo(shipped) < 0) { throw new RuntimeException("ç¼è¾å¤±è´¥,è®¢åæ°éä¸è½å°äºå·²åè´§æ°é"); } //æ¥è¯¢åæ¬ç产ååå·id salesLedgerProduct.setFutureTickets(salesLedgerProduct.getQuantity()); result = salesLedgerProductMapper.updateById(salesLedgerProduct); // å 许âå¤å ¥åºâï¼å½è®¢åæ°é被ä¸è°æ¶ï¼åªåéâä¸è°å·®é¢â对åºçå ¥åºæ°é // ä¾ï¼å订å100ï¼å·²å ¥åº120ï¼æ¹ä¸º50 -> åªåé50ï¼æç»å·²å ¥åº70ï¼ä¸å¼ºåå°50ï¼ BigDecimal oldOrderQty = dbBefore.getQuantity() == null ? BigDecimal.ZERO : dbBefore.getQuantity(); BigDecimal stocked = dbBefore.getStockedQuantity() == null ? BigDecimal.ZERO : dbBefore.getStockedQuantity(); BigDecimal reduced = oldOrderQty.subtract(newOrderQty); if (reduced.compareTo(BigDecimal.ZERO) > 0) { BigDecimal rollbackQty = stocked.min(reduced); if (rollbackQty.compareTo(BigDecimal.ZERO) > 0) { rollbackExcessStockIn(dbBefore, rollbackQty); } } /*å é¤å¯¹åºççäº§æ°æ®å¹¶éæ°æ°å¢*/ deleteProductionData(Arrays.asList(salesLedgerProduct.getId())); // å é¤çäº§æ ¸ç®æ°æ® @@ -333,10 +362,108 @@ // æ¸ ç©ºéå®äº§åç»å®çå å·¥ salesLedgerProductProcessBindService.updateProductProcessBind(salesLedgerProduct.getSalesProductProcessList(), salesLedgerProduct.getId()); // æ°å¢/ç¼è¾äº§ååï¼å·æ°éå®ä¸»åå ¥åºç¶æï¼é¿å å æ°å¢æªå ¥åºè¡å¯¼è´ç¶æä¸åï¼ refreshSalesLedgerStockStatus(salesLedgerId); } return result; } private void rollbackExcessStockIn(SalesLedgerProduct dbBefore, BigDecimal rollbackQtyTotal) { if (dbBefore == null || rollbackQtyTotal == null || rollbackQtyTotal.compareTo(BigDecimal.ZERO) <= 0) { return; } if (dbBefore.getProductModelId() == null) { throw new RuntimeException("åéå ¥åºå¤±è´¥,产åè§æ ¼æªç»´æ¤"); } Long productId = dbBefore.getId(); // ååºåéï¼ä¼å åéâæ«ç å ¥åºâï¼ååéâæå¨å ¥åºâ List<String> recordTypes = Arrays.asList( StockInQualifiedRecordTypeEnum.SALE_SCAN_STOCK_IN.getCode(), StockInQualifiedRecordTypeEnum.SALE_STOCK_IN.getCode() ); List<StockInRecord> records = stockInRecordMapper.selectList(new LambdaQueryWrapper<StockInRecord>() .eq(StockInRecord::getSalesLedgerProductId, productId) .eq(StockInRecord::getType, "0") .in(StockInRecord::getRecordType, recordTypes) .orderByDesc(StockInRecord::getCreateTime)); BigDecimal remaining = rollbackQtyTotal; for (StockInRecord r : records) { if (remaining.compareTo(BigDecimal.ZERO) <= 0) { break; } BigDecimal inNum = r.getStockInNum() == null ? BigDecimal.ZERO : r.getStockInNum(); if (inNum.compareTo(BigDecimal.ZERO) <= 0) { continue; } BigDecimal rollbackQty = inNum.min(remaining); StockInventoryDto stockInventoryDto = new StockInventoryDto(); stockInventoryDto.setProductModelId(dbBefore.getProductModelId()); stockInventoryDto.setQualitity(rollbackQty); int affectRows = stockInventoryMapper.updateSubtractStockInventory(stockInventoryDto); if (affectRows <= 0) { throw new RuntimeException("åéå ¥åºå¤±è´¥,å½ååºåä¸è¶³,æ æ³æ£åè¶ å ¥åºæ°é"); } BigDecimal newInNum = inNum.subtract(rollbackQty); if (newInNum.compareTo(BigDecimal.ZERO) <= 0) { stockInRecordMapper.deleteById(r.getId()); } else { r.setStockInNum(newInNum); stockInRecordMapper.updateById(r); } remaining = remaining.subtract(rollbackQty); } if (remaining.compareTo(BigDecimal.ZERO) > 0) { throw new RuntimeException("åéå ¥åºå¤±è´¥,æªæ¾å°è¶³å¤çå ¥åºè®°å½ç¨äºæ£åè¶ å ¥åºæ°é"); } // åå产åè¡å·²å ¥åºæ°éä¸ç¶æ SalesLedgerProduct fresh = salesLedgerProductMapper.selectById(dbBefore.getId()); if (fresh == null) { return; } BigDecimal newStocked = (fresh.getStockedQuantity() == null ? BigDecimal.ZERO : fresh.getStockedQuantity()).subtract(rollbackQtyTotal); if (newStocked.compareTo(BigDecimal.ZERO) < 0) { newStocked = BigDecimal.ZERO; } BigDecimal orderQty = fresh.getQuantity() == null ? BigDecimal.ZERO : fresh.getQuantity(); int stockStatus; if (newStocked.compareTo(BigDecimal.ZERO) <= 0) stockStatus = 0; else if (orderQty.compareTo(BigDecimal.ZERO) > 0 && newStocked.compareTo(orderQty) < 0) stockStatus = 1; else stockStatus = 2; fresh.setStockedQuantity(newStocked); fresh.setProductStockStatus(stockStatus); fresh.fillRemainingQuantity(); salesLedgerProductMapper.updateById(fresh); } private void refreshSalesLedgerStockStatus(Long salesLedgerId) { if (salesLedgerId == null) { return; } SalesLedger ledger = salesLedgerMapper.selectById(salesLedgerId); if (ledger == null) { return; } List<SalesLedgerProduct> allProducts = salesLedgerProductMapper.selectList(new LambdaQueryWrapper<SalesLedgerProduct>() .eq(SalesLedgerProduct::getSalesLedgerId, salesLedgerId) .eq(SalesLedgerProduct::getType, 1)); if (CollectionUtils.isEmpty(allProducts)) { ledger.setStockStatus(0); salesLedgerMapper.updateById(ledger); return; } boolean anyInbound = allProducts.stream().anyMatch(p -> { BigDecimal sq = p.getStockedQuantity(); return sq != null && sq.compareTo(BigDecimal.ZERO) > 0; }); boolean allFull = allProducts.stream().allMatch(p -> Objects.equals(p.getProductStockStatus(), 2)); ledger.setStockStatus(allFull ? 2 : (anyInbound ? 1 : 0)); salesLedgerMapper.updateById(ledger); } /** * æ°å¢çäº§æ°æ® */ src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
@@ -1006,7 +1006,15 @@ if (!updateList.isEmpty()) { for (SalesLedgerProduct product : updateList) { product.setType(type.getCode()); SalesLedgerProduct db = salesLedgerProductMapper.selectById(product.getId()); if (db != null) { BigDecimal stockedQty = product.getStockedQuantity() != null ? product.getStockedQuantity() : db.getStockedQuantity(); BigDecimal orderQty = product.getQuantity() != null ? product.getQuantity() : db.getQuantity(); product.setStockedQuantity(stockedQty); product.setProductStockStatus(calculateProductStockStatus(stockedQty, orderQty)); } else { product.setProductStockStatus(0); } product.fillRemainingQuantity(); salesLedgerProductMapper.updateById(product); // æ¸ ç©ºéå®äº§åç»å®çå å·¥ @@ -1020,7 +1028,9 @@ salesLedgerProduct.setNoInvoiceNum(salesLedgerProduct.getQuantity()); salesLedgerProduct.setNoInvoiceAmount(salesLedgerProduct.getTaxInclusiveTotalPrice()); salesLedgerProduct.setPendingInvoiceTotal(salesLedgerProduct.getTaxInclusiveTotalPrice()); salesLedgerProduct.setProductStockStatus(0); BigDecimal stockedQty = salesLedgerProduct.getStockedQuantity(); BigDecimal orderQty = salesLedgerProduct.getQuantity(); salesLedgerProduct.setProductStockStatus(calculateProductStockStatus(stockedQty, orderQty)); salesLedgerProduct.fillRemainingQuantity(); salesLedgerProductMapper.insert(salesLedgerProduct); // ç»å®äº§åé¢å¤å å·¥ @@ -1030,6 +1040,41 @@ // salesLedgerProductServiceImpl.addProductionData(salesLedgerProduct); } } refreshSalesLedgerStockStatus(salesLedgerId); } private int calculateProductStockStatus(BigDecimal stockedQty, BigDecimal orderQty) { BigDecimal stocked = stockedQty == null ? BigDecimal.ZERO : stockedQty; BigDecimal order = orderQty == null ? BigDecimal.ZERO : orderQty; if (stocked.compareTo(BigDecimal.ZERO) <= 0) { return 0; } if (order.compareTo(BigDecimal.ZERO) > 0 && stocked.compareTo(order) < 0) { return 1; } return 2; } private void refreshSalesLedgerStockStatus(Long salesLedgerId) { if (salesLedgerId == null) return; SalesLedger ledger = baseMapper.selectById(salesLedgerId); if (ledger == null) return; List<SalesLedgerProduct> allProducts = salesLedgerProductMapper.selectList( Wrappers.<SalesLedgerProduct>lambdaQuery() .eq(SalesLedgerProduct::getSalesLedgerId, salesLedgerId) .eq(SalesLedgerProduct::getType, SaleEnum.SALE.getCode())); if (CollectionUtils.isEmpty(allProducts)) { ledger.setStockStatus(0); baseMapper.updateById(ledger); return; } boolean anyInbound = allProducts.stream().anyMatch(p -> { BigDecimal sq = p.getStockedQuantity(); return sq != null && sq.compareTo(BigDecimal.ZERO) > 0; }); boolean allFull = allProducts.stream().allMatch(p -> Objects.equals(p.getProductStockStatus(), 2)); ledger.setStockStatus(allFull ? 2 : (anyInbound ? 1 : 0)); baseMapper.updateById(ledger); } private SalesLedger convertToEntity(SalesLedgerDto dto) { src/main/java/com/ruoyi/sales/service/impl/ShippingInfoServiceImpl.java
@@ -19,15 +19,9 @@ import com.ruoyi.sales.pojo.ShippingInfo; import com.ruoyi.sales.service.ShippingInfoService; import com.ruoyi.sales.mapper.SalesLedgerMapper; import com.ruoyi.stock.mapper.StockInventoryMapper; import com.ruoyi.stock.pojo.StockInventory; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; import java.util.HashMap; import java.util.Map; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; @@ -64,9 +58,6 @@ @Autowired private SalesLedgerMapper salesLedgerMapper; @Autowired private StockInventoryMapper stockInventoryMapper; @Override public IPage<ShippingInfoDto> listPage(Page page, ShippingInfo req) { IPage<ShippingInfoDto> listPage = shippingInfoMapper.listPage(page, req); @@ -83,6 +74,14 @@ if (byId == null) { throw new RuntimeException("åè´§ä¿¡æ¯ä¸åå¨"); } // åè´§æ£åºååå¿ é¡»ä¿è¯è¯¥è®¢åææäº§åå·²å ¥åº List<SalesLedgerProduct> notStocked = salesLedgerProductMapper.selectList(new LambdaQueryWrapper<SalesLedgerProduct>() .eq(SalesLedgerProduct::getSalesLedgerId, byId.getSalesLedgerId()) .eq(SalesLedgerProduct::getType, 1) .ne(SalesLedgerProduct::getProductStockStatus, 2)); if (CollectionUtils.isNotEmpty(notStocked)) { throw new RuntimeException("å货失败,该éå®è®¢åå卿ªå ¥åºäº§å,请å å®æå ¨é¨å ¥åºåååè´§"); } //æ£ååºå if (!"å·²åè´§".equals(byId.getStatus())) { SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(byId.getSalesLedgerProductId()); src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java
@@ -79,7 +79,10 @@ stockInRecordService.add(stockInRecordDto); //åè¿è¡æ°å¢åºåæ°éåºå //å æ¥è¯¢åºå表ä¸çäº§åæ¯å¦åå¨ï¼ä¸å卿°å¢ï¼å卿´æ° StockInventory oldStockInventory = stockInventoryMapper.selectOne(new QueryWrapper<StockInventory>().lambda().eq(StockInventory::getProductModelId, stockInventoryDto.getProductModelId())); List<StockInventory> stockInventories = stockInventoryMapper.selectList(new QueryWrapper<StockInventory>().lambda() .eq(StockInventory::getProductModelId, stockInventoryDto.getProductModelId()) .orderByDesc(StockInventory::getId)); StockInventory oldStockInventory = (stockInventories == null || stockInventories.isEmpty()) ? null : stockInventories.get(0); if (ObjectUtils.isEmpty(oldStockInventory)) { StockInventory newStockInventory = new StockInventory(); newStockInventory.setProductModelId(stockInventoryDto.getProductModelId()); @@ -109,7 +112,10 @@ stockOutRecordDto.setSalesLedgerId(stockInventoryDto.getSalesLedgerId()); stockOutRecordDto.setSalesLedgerProductId(stockInventoryDto.getSalesLedgerProductId()); stockOutRecordService.add(stockOutRecordDto); StockInventory oldStockInventory = stockInventoryMapper.selectOne(new QueryWrapper<StockInventory>().lambda().eq(StockInventory::getProductModelId, stockInventoryDto.getProductModelId())); List<StockInventory> stockInventories = stockInventoryMapper.selectList(new QueryWrapper<StockInventory>().lambda() .eq(StockInventory::getProductModelId, stockInventoryDto.getProductModelId()) .orderByDesc(StockInventory::getId)); StockInventory oldStockInventory = (stockInventories == null || stockInventories.isEmpty()) ? null : stockInventories.get(0); if (ObjectUtils.isEmpty(oldStockInventory)) { throw new RuntimeException("产ååºåä¸åå¨"); } src/main/java/com/ruoyi/stock/service/impl/StockUninventoryServiceImpl.java
@@ -59,7 +59,10 @@ stockInRecordService.add(stockInRecordDto); //åè¿è¡æ°å¢åºåæ°éåºå //å æ¥è¯¢åºå表ä¸çäº§åæ¯å¦åå¨ï¼ä¸å卿°å¢ï¼å卿´æ° StockUninventory oldStockUnInventory = stockUninventoryMapper.selectOne(new QueryWrapper<StockUninventory>().lambda().eq(StockUninventory::getProductModelId, stockUninventoryDto.getProductModelId())); List<StockUninventory> stockUninventories = stockUninventoryMapper.selectList(new QueryWrapper<StockUninventory>().lambda() .eq(StockUninventory::getProductModelId, stockUninventoryDto.getProductModelId()) .orderByDesc(StockUninventory::getId)); StockUninventory oldStockUnInventory = (stockUninventories == null || stockUninventories.isEmpty()) ? null : stockUninventories.get(0); if (ObjectUtils.isEmpty(oldStockUnInventory)) { StockUninventory newStockUnInventory = new StockUninventory(); newStockUnInventory.setProductModelId(stockUninventoryDto.getProductModelId()); @@ -87,7 +90,10 @@ stockOutRecordDto.setSalesLedgerId(stockUninventoryDto.getSalesLedgerId()); stockOutRecordDto.setSalesLedgerProductId(stockUninventoryDto.getSalesLedgerProductId()); stockOutRecordService.add(stockOutRecordDto); StockUninventory oldStockInventory = stockUninventoryMapper.selectOne(new QueryWrapper<StockUninventory>().lambda().eq(StockUninventory::getProductModelId, stockUninventoryDto.getProductModelId())); List<StockUninventory> stockUninventories = stockUninventoryMapper.selectList(new QueryWrapper<StockUninventory>().lambda() .eq(StockUninventory::getProductModelId, stockUninventoryDto.getProductModelId()) .orderByDesc(StockUninventory::getId)); StockUninventory oldStockInventory = (stockUninventories == null || stockUninventories.isEmpty()) ? null : stockUninventories.get(0); if (ObjectUtils.isEmpty(oldStockInventory)) { throw new RuntimeException("产ååºåä¸åå¨"); }else { src/main/resources/mapper/purchase/PurchaseLedgerMapper.xml
@@ -29,6 +29,8 @@ pl.approve_user_ids, sm.is_white, pl.approval_status, pl.stock_status, IFNULL(ps.product_stock_status, 0) AS product_stock_status, pl.payment_method, pl.remarks FROM purchase_ledger pl @@ -40,6 +42,19 @@ GROUP BY purchase_ledger_id ) tr_sum ON pl.id = tr_sum.purchase_ledger_id LEFT JOIN supplier_manage sm ON pl.supplier_id = sm.id LEFT JOIN ( SELECT sales_ledger_id, CASE WHEN COUNT(1) = 0 THEN 0 WHEN SUM(CASE WHEN IFNULL(product_stock_status, 0) = 2 THEN 1 ELSE 0 END) = COUNT(1) THEN 2 WHEN SUM(CASE WHEN IFNULL(product_stock_status, 0) > 0 THEN 1 ELSE 0 END) > 0 THEN 1 ELSE 0 END AS product_stock_status FROM sales_ledger_product WHERE type = 2 GROUP BY sales_ledger_id ) ps ON pl.id = ps.sales_ledger_id <where> <if test="c.purchaseContractNumber != null and c.purchaseContractNumber != ''"> AND pl.purchase_contract_number LIKE CONCAT('%', #{c.purchaseContractNumber}, '%') src/main/resources/mapper/quality/QualityInspectMapper.xml
@@ -47,7 +47,7 @@ <if test="qualityInspect.entryDateEnd != null and qualityInspect.entryDateEnd != '' "> AND qi.check_time <= DATE_FORMAT(#{qualityInspect.entryDateEnd},'%Y-%m-%d') </if> ORDER BY qi.check_time DESC ORDER BY qi.id DESC </select> <select id="qualityInspectExport" resultType="com.ruoyi.quality.pojo.QualityInspect"> src/main/resources/mapper/sales/SalesLedgerProductMapper.xml
@@ -7,6 +7,7 @@ <select id="selectSalesLedgerProductList" resultType="com.ruoyi.sales.pojo.SalesLedgerProduct"> SELECT T1.*, pl.stock_status AS purchase_stock_status, CASE WHEN (IFNULL(t2.qualitity, 0) - IFNULL(t2.locked_quantity, 0)) >= IFNULL(T1.quantity, 0) THEN 1 ELSE 0 @@ -14,6 +15,7 @@ FROM sales_ledger_product T1 LEFT JOIN stock_inventory t2 ON T1.product_model_id = t2.product_model_id LEFT JOIN purchase_ledger pl ON T1.sales_ledger_id = pl.id AND T1.type = 2 <where> <if test="salesLedgerProduct.salesLedgerId != null"> AND T1.sales_ledger_id = #{salesLedgerProduct.salesLedgerId}