ソースを参照

物料资料增加禁用前校验

chenw 7 年 前
コミット
aec5f8b256

+ 4 - 0
applications/commons/commons-dto/src/main/java/com/usoftchina/saas/commons/exception/BizExceptionCode.java

@@ -41,6 +41,10 @@ public enum BizExceptionCode implements BaseExceptionCode {
 
     NO_OPRATIONDATA(79400,"无可操作单据"),
     NULL_DATA(23232,"无数据"),
+    PRODUCT_HASSTOCK(79401, "当前物料库存大于0,不允许禁用"),
+    PRODUCT_EXISTS_PRODIO(79402, "存在未审核出入库单据使用了当前物料"),
+    PRODUCT_EXISTS_SALE(79403, "存在未关闭且状态非已出库销售订单使用了当前物料"),
+    PRODUCT_EXISTS_PURCHASE(79404, "存在未关闭且状态非已入库采购订单使用了当前物料"),
 
     BOM_SAVE(79401, "产品编号+版本号已存在"),
     BOM_CODE_REPEAT(74002, "组合件和子件不允许相同"),

+ 8 - 0
applications/document/document-server/src/main/java/com/usoftchina/saas/document/mapper/ProductMapper.java

@@ -54,4 +54,12 @@ public interface ProductMapper extends CommonBaseMapper<Product> {
     List<ProductReserveCostDTO> selectReserveCostByIgnoreWarehouse(@Param("con") String con, @Param("companyId") Long companyId);
 
     String selectCalculateFields(@Param("fields") String fields, @Param("con") String con, @Param("companyId") Long companyId);
+
+    int selectStockById(Long id);
+
+    int selectProdIOCount(Long id);
+
+    int selectSale(Long id);
+
+    int selectPurchase(Long id);
 }

+ 28 - 0
applications/document/document-server/src/main/java/com/usoftchina/saas/document/service/impl/ProductServiceImpl.java

@@ -336,6 +336,7 @@ public class ProductServiceImpl extends CommonBaseServiceImpl<ProductMapper, Pro
             if (!Status.ENABLE.getDisplay().equals(product.getPr_status())){
                 throw new BizException(BizExceptionCode.BIZ_BANNED);
             }
+            beforeClose(id);
             product.setPr_status(Status.BANNED.getDisplay());
             product.setPr_statuscode(Status.BANNED.name());
             product.setUpdaterId(BaseContextHolder.getUserId());
@@ -350,6 +351,33 @@ public class ProductServiceImpl extends CommonBaseServiceImpl<ProductMapper, Pro
         }
     }
 
+    /**
+     * 物料禁用前校验
+     * @param id
+     */
+    private void beforeClose(Long id){
+        //1.库存大于0
+        int count = getMapper().selectStockById(id);
+        if (count > 0){
+            throw new BizException(BizExceptionCode.PRODUCT_HASSTOCK);
+        }
+        //2.存在未审核出入库单据
+        count = getMapper().selectProdIOCount(id);
+        if (count > 0){
+            throw new BizException(BizExceptionCode.PRODUCT_EXISTS_PRODIO);
+        }
+        //3.存在未关闭且状态非已出库销售订单
+        count = getMapper().selectSale(id);
+        if (count > 0){
+            throw new BizException(BizExceptionCode.PRODUCT_EXISTS_SALE);
+        }
+        //4.存在未关闭且状态非已入库采购订单
+        count = getMapper().selectPurchase(id);
+        if (count > 0){
+            throw new BizException(BizExceptionCode.PRODUCT_EXISTS_PURCHASE);
+        }
+    }
+
     @Override
     public DocBaseDTO open(Long id) {
         DocBaseDTO docBaseDTO = null;

+ 12 - 0
applications/document/document-server/src/main/resources/mapper/ProductMapper.xml

@@ -934,5 +934,17 @@
     <select id="selectIdByCode" resultType="long">
         select pr_id from product where pr_code=#{code} and companyId=#{companyId}
     </select>
+    <select id="selectStockById" resultType="int">
+        SELECT COUNT(*) FROM PRODUCTONHAND WHERE PO_PRODID = #{id}
+    </select>
+    <select id="selectProdIOCount" resultType="int">
+        SELECT COUNT(*) FROM PRODIODETAIL WHERE PD_STATUS != 99 AND PD_PRODID = #{id}
+    </select>
+    <select id="selectSale" resultType="int">
+        SELECT COUNT(*) FROM SALE LEFT JOIN SALEDETAIL ON SA_ID = SD_SAID WHERE SA_SENDSTATUS != '已出库' AND SA_SENDSTATUS != '已关闭' AND IFNULL(SD_PRODID,0) = #{id}
+    </select>
+    <select id="selectPurchase" resultType="int">
+        SELECT COUNT(*) FROM PURCHASE LEFT JOIN PURCHASEDETAIL ON PU_ID = PD_PUID WHERE PU_ACCEPTSTATUS != '已出库' AND PU_ACCEPTSTATUSCODE != '已关闭' AND IFNULL(PD_PRODID,0) = #{id}
+    </select>
 </mapper>