From 11834d714f298174e0324bacf75c288f8f57e415 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=A3=E5=9C=A3=E5=8D=8E?= <752718920@qq.com> Date: Tue, 27 Sep 2022 22:09:40 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=99excel=E5=AF=BC=E5=85=A5=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=9D=A1=E7=A0=81=E9=87=8D=E5=A4=8D=E7=9A=84=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jsh/erp/constants/ExceptionConstants.java | 6 ++ .../erp/service/material/MaterialService.java | 66 ++++++++++++++++++- 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/jshERP-boot/src/main/java/com/jsh/erp/constants/ExceptionConstants.java b/jshERP-boot/src/main/java/com/jsh/erp/constants/ExceptionConstants.java index 7ad46d3a..251a0be3 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/constants/ExceptionConstants.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/constants/ExceptionConstants.java @@ -335,6 +335,12 @@ public class ExceptionConstants { //盘点业务不能选择批号或序列号商品 public static final int MATERIAL_STOCK_CHECK_ERROR_CODE = 80000019; public static final String MATERIAL_STOCK_CHECK_ERROR_MSG = "抱歉,盘点业务不能选择批号或序列号商品:%s,建议走其它入库和出库单"; + //EXCEL中存在重复的商品 + public static final int MATERIAL_EXCEL_IMPORT_EXIST_CODE = 80000020; + public static final String MATERIAL_EXCEL_IMPORT_EXIST_MSG = "抱歉,EXCEL中存在重复的商品,具体信息为:%s"; + //EXCEL中存在重复的条码 + public static final int MATERIAL_EXCEL_IMPORT_BARCODE_EXIST_CODE = 80000021; + public static final String MATERIAL_EXCEL_IMPORT_BARCODE_EXIST_MSG = "抱歉,EXCEL中存在重复的条码,具体条码为:%s"; /** * 单据信息 diff --git a/jshERP-boot/src/main/java/com/jsh/erp/service/material/MaterialService.java b/jshERP-boot/src/main/java/com/jsh/erp/service/material/MaterialService.java index bcea2e9c..1c2956bd 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/service/material/MaterialService.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/service/material/MaterialService.java @@ -499,6 +499,8 @@ public class MaterialService { throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_UNIT_EMPTY_CODE, String.format(ExceptionConstants.MATERIAL_UNIT_EMPTY_MSG, i+1)); } + // 批量校验excel中有无重复商品,是指名称、规格、型号、颜色、单位 + batchCheckExistMaterialListByParam(mList, name, standard, model, color, unit); MaterialWithInitStock m = new MaterialWithInitStock(); m.setName(name); m.setStandard(standard); @@ -550,6 +552,8 @@ public class MaterialService { throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_BARCODE_NOT_INTEGER_CODE, String.format(ExceptionConstants.MATERIAL_BARCODE_NOT_INTEGER_MSG, manyBarCode)); } + //批量校验excel中有无重复条码 + batchCheckExistBarCodeByParam(mList, barCode, manyBarCode); JSONObject materialExObj = new JSONObject(); JSONObject basicObj = new JSONObject(); basicObj.put("barCode", barCode); @@ -649,7 +653,17 @@ public class MaterialService { insertCurrentStockMaterialList.add(materialCurrentStock); } } else { - depotItemService.updateCurrentStockFun(mId, depotId); + BigDecimal initStock = getInitStock(mId, depotId); + BigDecimal currentNumber = getCurrentStockByMaterialIdAndDepotId(mId, depotId); + //当前库存的更新:减去初始库存,再加上导入的新初始库存 + if(currentNumber!=null && initStock!=null) { + currentNumber = currentNumber.subtract(initStock).add(stock); + } + MaterialCurrentStock materialCurrentStock = new MaterialCurrentStock(); + materialCurrentStock.setMaterialId(mId); + materialCurrentStock.setDepotId(depotId); + materialCurrentStock.setCurrentNumber(currentNumber); + insertCurrentStockMaterialList.add(materialCurrentStock); } } } @@ -717,6 +731,56 @@ public class MaterialService { return stockMap; } + /** + * 批量校验excel中有无重复商品,是指名称、规格、型号、颜色、单位 + * @param mList + */ + public void batchCheckExistMaterialListByParam(List mList, String name, String standard, + String model, String color, String unit) { + for(MaterialWithInitStock material: mList){ + if(name.equals(material.getName()) && + standard.equals(material.getStandard()) && + model.equals(material.getModel()) && + color.equals(material.getColor()) && + unit.equals(material.getUnit())){ + String info = name + "-" + standard + "-" + model + "-" + color + "-" + unit; + throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_EXCEL_IMPORT_EXIST_CODE, + String.format(ExceptionConstants.MATERIAL_EXCEL_IMPORT_EXIST_MSG, info)); + } + } + } + + /** + * 批量校验excel中有无重复条码 + * @param mList + */ + public void batchCheckExistBarCodeByParam(List mList, + String barCode, String manyBarCode) { + for(MaterialWithInitStock material: mList){ + JSONObject materialExObj = material.getMaterialExObj(); + String basicBarCode = ""; + String otherBarCode = ""; + if(materialExObj.get("basic")!=null) { + JSONObject basicObj = materialExObj.getJSONObject("basic"); + basicBarCode = basicObj.getString("barCode"); + } + if(materialExObj.get("other")!=null) { + JSONObject otherObj = materialExObj.getJSONObject("other"); + otherBarCode = otherObj.getString("barCode"); + } + if(barCode.equals(basicBarCode) || barCode.equals(otherBarCode)){ + throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_EXCEL_IMPORT_BARCODE_EXIST_CODE, + String.format(ExceptionConstants.MATERIAL_EXCEL_IMPORT_BARCODE_EXIST_MSG, barCode)); + } + if(StringUtil.isNotEmpty(manyBarCode)) { + if(manyBarCode.equals(basicBarCode) || manyBarCode.equals(otherBarCode)){ + throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_EXCEL_IMPORT_BARCODE_EXIST_CODE, + String.format(ExceptionConstants.MATERIAL_EXCEL_IMPORT_BARCODE_EXIST_MSG, manyBarCode)); + } + } + } + } + /** * 给商品新增或更新条码与价格相关信息 * @param materialExObj