From fcb1dbf7f54d4fcd50b63a96c4e1a2bf9f064215 Mon Sep 17 00:00:00 2001 From: shusir <497819738@qq.com> Date: Fri, 27 Feb 2026 10:08:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E7=B3=BB=E7=BB=9F=E6=95=B0=E9=87=8F?= =?UTF-8?q?=E9=99=90=E5=88=B6=EF=BC=8C=E7=89=A9=E6=96=99=E5=85=A5=E5=BA=93?= =?UTF-8?q?=E6=95=B0=E9=87=8F=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../qms/core/constant/CommonConstant.java | 14 ++++++++++ .../material/constant/MaterialConstants.java | 3 ++- .../MaterialInventoryInboundServiceImpl.java | 26 +++++++++++++++++-- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/core/constant/CommonConstant.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/core/constant/CommonConstant.java index fc354922..a19b8ef3 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/core/constant/CommonConstant.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/core/constant/CommonConstant.java @@ -1,5 +1,7 @@ package com.zt.plat.module.qms.core.constant; +import java.math.BigDecimal; + public class CommonConstant { @@ -75,4 +77,16 @@ public class CommonConstant { //================数据库常量====================== public static final String SQL_WHERE = "where"; + //================数量限制======================== + /** + * 单次最大生成数量(防止系统资源耗尽) + */ + public static final BigDecimal MAX_GENERATE_QUANTITY = new BigDecimal("10000"); + + /** + * 单次最大响应数量(防止响应数据过大) + */ + public static final BigDecimal MAX_RESPONSE_QUANTITY = new BigDecimal("1000"); + + } diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/constant/MaterialConstants.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/constant/MaterialConstants.java index d32f488c..2f2045fd 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/constant/MaterialConstants.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/constant/MaterialConstants.java @@ -4,8 +4,9 @@ package com.zt.plat.module.qms.resource.material.constant; * 物料常量 */ public class MaterialConstants { - // 字典 类型 + // 字典 public static final String DICT_MATERIAL_FLOW_TYPE = "jy_material_lifecycle_bsn_type"; + public static final String DICT_MATERIAL_INBOUND_QUANTITY_LIMIT = "materialInboundQuantityLimit"; // 序列号 public static final String SEQUENCE_INF_KEY = "QMS_MATERIAL_INF_NO"; diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInventoryInboundServiceImpl.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInventoryInboundServiceImpl.java index a89835a2..9c5daa40 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInventoryInboundServiceImpl.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInventoryInboundServiceImpl.java @@ -1,13 +1,18 @@ package com.zt.plat.module.qms.resource.material.service; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.NumberUtil; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.zt.plat.framework.common.exception.ServiceException; +import com.zt.plat.framework.common.pojo.CommonResult; import com.zt.plat.framework.common.pojo.PageResult; import com.zt.plat.framework.common.util.object.BeanUtils; import com.zt.plat.framework.security.core.LoginUser; import com.zt.plat.framework.security.core.util.SecurityFrameworkUtils; +import com.zt.plat.module.qms.common.dic.controller.vo.DictionaryBusinessRespVO; +import com.zt.plat.module.qms.common.dic.service.DictionaryBusinessService; import com.zt.plat.module.qms.core.code.SequenceUtil; +import com.zt.plat.module.qms.core.constant.CommonConstant; import com.zt.plat.module.qms.core.constant.DataTypeConstant; import com.zt.plat.module.qms.resource.material.constant.MaterialConstants; import com.zt.plat.module.qms.resource.material.controller.vo.MaterialInventoryInboundDetailRespVO; @@ -55,6 +60,8 @@ public class MaterialInventoryInboundServiceImpl implements MaterialInventoryInb private MaterialInfomationService materialInfomationService; @Autowired private MaterialInventoryInboundDetailService materialInventoryInboundDetailService; + @Autowired + private DictionaryBusinessService dictionaryBusinessService; @Transactional @@ -63,6 +70,19 @@ public class MaterialInventoryInboundServiceImpl implements MaterialInventoryInb Long gongduanId = createReqVO.getGongduanId(); BigDecimal reqQuantity = createReqVO.getQuantity(); if (reqQuantity.compareTo(BigDecimal.ZERO) <= 0) throw new ServiceException(1_032_160_000, "入库数量不能小于等于0"); + CommonResult inboundQuantityLimitResult = dictionaryBusinessService.getDataByDataKey(MaterialConstants.DICT_MATERIAL_INBOUND_QUANTITY_LIMIT); + DictionaryBusinessRespVO inboundQuantityLimit = inboundQuantityLimitResult.getData(); + if (reqQuantity.compareTo(CommonConstant.MAX_GENERATE_QUANTITY) > 0 + || reqQuantity.compareTo(CommonConstant.MAX_RESPONSE_QUANTITY) > 0) + throw new ServiceException(1_032_160_000, + String.format("入库数量不能超过系统限制数量:%s", Math.min(CommonConstant.MAX_GENERATE_QUANTITY.doubleValue(), CommonConstant.MAX_RESPONSE_QUANTITY.doubleValue()))); + if (inboundQuantityLimit != null) { + BigDecimal inbQtyLimit = new BigDecimal(inboundQuantityLimit.getValue()); + if (reqQuantity.compareTo(inbQtyLimit) > 0) { + throw new ServiceException(1_032_160_000, + String.format("入库数量超出配置限制:%s,当前请求数量:%s", inbQtyLimit, reqQuantity)); + } + } MaterialBatchDO gongDO = materialBatchService.getMaterialBatch(gongduanId); if (gongDO == null) throw exception(MATERIAL_BATCH_GONG_NOT_EXISTS); // 1.检查工段是否已经验收 @@ -70,7 +90,6 @@ public class MaterialInventoryInboundServiceImpl implements MaterialInventoryInb throw new ServiceException(1_032_160_000, "工段未验收,不能入库"); // 2.入库数量不大于批次工段数量 - if (reqQuantity.compareTo(gongDO.getInboundQuantity()) > 0) throw new ServiceException(1_032_160_000, "入库数量不能大于批次工段数量"); // TODO 这儿应该调整为去物料实例统计出此工段的入库数量 List inboundDOS = materialInventoryInboundMapper.selectList(Wrappers.lambdaQuery(MaterialInventoryInboundDO.class) .eq(MaterialInventoryInboundDO::getGongduanId, gongduanId)); @@ -79,7 +98,10 @@ public class MaterialInventoryInboundServiceImpl implements MaterialInventoryInb for (MaterialInventoryInboundDO inboundDO : inboundDOS) { totalQuantity = totalQuantity.add(inboundDO.getQuantity()); } - if (totalQuantity.compareTo(gongDO.getInboundQuantity()) > 0) throw new ServiceException(1_032_160_000, "入库数量不能大于批次工段数量"); + if (totalQuantity.compareTo(gongDO.getInboundQuantity()) > 0) + throw new ServiceException(1_032_160_000, "入库数量不能大于批次工段未入库数量"); + } else if (reqQuantity.compareTo(gongDO.getInboundQuantity()) > 0) { + throw new ServiceException(1_032_160_000, "入库数量不能大于批次工段数量"); } // 3.保存入库记录 MaterialInventoryInboundDO inbound = saveInbound(createReqVO, gongDO);