From 81465e5dd6680bf2a4749152efc8a51aea4d2ac3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=A3=E5=9C=A3=E5=8D=8E?= <752718920@qq.com> Date: Fri, 20 Aug 2021 00:33:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=95=86=E5=93=81=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jsh/erp/constants/ExceptionConstants.java | 3 + .../erp/service/material/MaterialService.java | 162 +++++++++--------- .../com/jsh/erp/service/unit/UnitService.java | 2 +- 3 files changed, 89 insertions(+), 78 deletions(-) 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 f4047466..d36eab33 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 @@ -287,6 +287,9 @@ public class ExceptionConstants { //商品条码重复 public static final int MATERIAL_BARCODE_EXISTS_CODE = 8000005; public static final String MATERIAL_BARCODE_EXISTS_MSG = "商品条码:%s重复"; + //商品-单位匹配不上 + public static final int MATERIAL_UNIT_MATE_CODE = 8000006; + public static final String MATERIAL_UNIT_MATE_MSG = "抱歉,单位匹配不上,请完善计量单位信息!"; /** * 单据信息 * type = 85 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 5e07d7f0..a412d8a3 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 @@ -441,88 +441,93 @@ public class MaterialService { @Transactional(value = "transactionManager", rollbackFor = Exception.class) public BaseResponseInfo importExcel(Sheet src, HttpServletRequest request) throws Exception { - List depotList= depotService.getDepot(); - int depotCount = depotList.size(); - List mList = new ArrayList<>(); - for (int i = 2; i < src.getRows(); i++) { - String name = ExcelUtils.getContent(src, i, 0); //名称 - String standard = ExcelUtils.getContent(src, i, 1); //规格 - String model = ExcelUtils.getContent(src, i, 2); //型号 - String color = ExcelUtils.getContent(src, i, 3); //颜色 - String categoryName = ExcelUtils.getContent(src, i, 4); //类别 - String safetyStock = ExcelUtils.getContent(src, i, 5); //安全存量 - String unit = ExcelUtils.getContent(src, i, 6); //基础单位 - //校验名称、单位是否为空 - if(StringUtil.isNotEmpty(name) && StringUtil.isNotEmpty(unit)) { - MaterialWithInitStock m = new MaterialWithInitStock(); - m.setName(name); - m.setStandard(standard); - m.setModel(model); - m.setColor(color); - Long categoryId = materialCategoryService.getCategoryIdByName(categoryName); - if(null!=categoryId){ - m.setCategoryId(categoryId); - } - m.setSafetyStock(parseBigDecimalEx(safetyStock)); - String manyUnit = ExcelUtils.getContent(src, i, 7); //副单位 - String barCode = ExcelUtils.getContent(src, i, 8); //基础条码 - String manyBarCode = ExcelUtils.getContent(src, i, 9); //副条码 - String ratio = ExcelUtils.getContent(src, i, 10); //比例 - String purchaseDecimal = ExcelUtils.getContent(src, i, 11); //采购价 - String commodityDecimal = ExcelUtils.getContent(src, i, 12); //零售价 - String wholesaleDecimal = ExcelUtils.getContent(src, i, 13); //销售价 - String lowDecimal = ExcelUtils.getContent(src, i, 14); //最低售价 - JSONObject materialExObj = new JSONObject(); - JSONObject basicObj = new JSONObject(); - basicObj.put("barCode", barCode); - basicObj.put("commodityUnit", unit); - basicObj.put("purchaseDecimal", purchaseDecimal); - basicObj.put("commodityDecimal", commodityDecimal); - basicObj.put("wholesaleDecimal", wholesaleDecimal); - basicObj.put("lowDecimal", lowDecimal); - materialExObj.put("basic", basicObj); - if(StringUtil.isNotEmpty(manyUnit.trim())){ //多单位 - String manyUnitAll = unit + "," + manyUnit + "(1:" + ratio + ")"; - Long unitId = unitService.getUnitIdByName(manyUnitAll); - m.setUnitId(unitId); - JSONObject otherObj = new JSONObject(); - otherObj.put("barCode", manyBarCode); - otherObj.put("commodityUnit", manyUnit); - otherObj.put("purchaseDecimal", parsePrice(purchaseDecimal,ratio)); - otherObj.put("commodityDecimal", parsePrice(commodityDecimal,ratio)); - otherObj.put("wholesaleDecimal", parsePrice(wholesaleDecimal,ratio)); - otherObj.put("lowDecimal", parsePrice(lowDecimal,ratio)); - materialExObj.put("other", otherObj); - } else { - m.setUnit(unit); - } - m.setMaterialExObj(materialExObj); - String enabled = ExcelUtils.getContent(src, i, 15); //状态 - m.setEnabled(enabled.equals("1")? true: false); - //缓存各个仓库的库存信息 - Map stockMap = new HashMap(); - for(int j=1; j<=depotCount;j++) { - int col = 15+j; - if(col < src.getColumns()){ - String depotName = ExcelUtils.getContent(src, 1, col); //获取仓库名称 - Long depotId = depotService.getIdByName(depotName); - if(depotId!=0L){ - String stockStr = ExcelUtils.getContent(src, i, col); - if(StringUtil.isNotEmpty(stockStr)) { - stockMap.put(depotId, parseBigDecimalEx(stockStr)); + BaseResponseInfo info = new BaseResponseInfo(); + try { + List depotList= depotService.getDepot(); + int depotCount = depotList.size(); + List mList = new ArrayList<>(); + for (int i = 2; i < src.getRows(); i++) { + String name = ExcelUtils.getContent(src, i, 0); //名称 + String standard = ExcelUtils.getContent(src, i, 1); //规格 + String model = ExcelUtils.getContent(src, i, 2); //型号 + String color = ExcelUtils.getContent(src, i, 3); //颜色 + String categoryName = ExcelUtils.getContent(src, i, 4); //类别 + String safetyStock = ExcelUtils.getContent(src, i, 5); //安全存量 + String unit = ExcelUtils.getContent(src, i, 6); //基础单位 + //校验名称、单位是否为空 + if(StringUtil.isNotEmpty(name) && StringUtil.isNotEmpty(unit)) { + MaterialWithInitStock m = new MaterialWithInitStock(); + m.setName(name); + m.setStandard(standard); + m.setModel(model); + m.setColor(color); + Long categoryId = materialCategoryService.getCategoryIdByName(categoryName); + if(null!=categoryId){ + m.setCategoryId(categoryId); + } + m.setSafetyStock(parseBigDecimalEx(safetyStock)); + String manyUnit = ExcelUtils.getContent(src, i, 7); //副单位 + String barCode = ExcelUtils.getContent(src, i, 8); //基础条码 + String manyBarCode = ExcelUtils.getContent(src, i, 9); //副条码 + String ratio = ExcelUtils.getContent(src, i, 10); //比例 + String purchaseDecimal = ExcelUtils.getContent(src, i, 11); //采购价 + String commodityDecimal = ExcelUtils.getContent(src, i, 12); //零售价 + String wholesaleDecimal = ExcelUtils.getContent(src, i, 13); //销售价 + String lowDecimal = ExcelUtils.getContent(src, i, 14); //最低售价 + JSONObject materialExObj = new JSONObject(); + JSONObject basicObj = new JSONObject(); + basicObj.put("barCode", barCode); + basicObj.put("commodityUnit", unit); + basicObj.put("purchaseDecimal", purchaseDecimal); + basicObj.put("commodityDecimal", commodityDecimal); + basicObj.put("wholesaleDecimal", wholesaleDecimal); + basicObj.put("lowDecimal", lowDecimal); + materialExObj.put("basic", basicObj); + if(StringUtil.isNotEmpty(manyUnit.trim())){ //多单位 + String manyUnitAll = unit + "," + manyUnit + "(1:" + ratio + ")"; + Long unitId = unitService.getUnitIdByName(manyUnitAll); + if(unitId != null) { + m.setUnitId(unitId); + } else { + throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_UNIT_MATE_CODE, + String.format(ExceptionConstants.MATERIAL_UNIT_MATE_MSG)); + } + JSONObject otherObj = new JSONObject(); + otherObj.put("barCode", manyBarCode); + otherObj.put("commodityUnit", manyUnit); + otherObj.put("purchaseDecimal", parsePrice(purchaseDecimal,ratio)); + otherObj.put("commodityDecimal", parsePrice(commodityDecimal,ratio)); + otherObj.put("wholesaleDecimal", parsePrice(wholesaleDecimal,ratio)); + otherObj.put("lowDecimal", parsePrice(lowDecimal,ratio)); + materialExObj.put("other", otherObj); + } else { + m.setUnit(unit); + } + m.setMaterialExObj(materialExObj); + String enabled = ExcelUtils.getContent(src, i, 15); //状态 + m.setEnabled(enabled.equals("1")? true: false); + //缓存各个仓库的库存信息 + Map stockMap = new HashMap(); + for(int j=1; j<=depotCount;j++) { + int col = 15+j; + if(col < src.getColumns()){ + String depotName = ExcelUtils.getContent(src, 1, col); //获取仓库名称 + Long depotId = depotService.getIdByName(depotName); + if(depotId!=0L){ + String stockStr = ExcelUtils.getContent(src, i, col); + if(StringUtil.isNotEmpty(stockStr)) { + stockMap.put(depotId, parseBigDecimalEx(stockStr)); + } } } } + m.setStockMap(stockMap); + mList.add(m); } - m.setStockMap(stockMap); - mList.add(m); } - } - logService.insertLog("商品", - new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_IMPORT).append(mList.size()).append(BusinessConstants.LOG_DATA_UNIT).toString(), - ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()); - BaseResponseInfo info = new BaseResponseInfo(); - try { + logService.insertLog("商品", + new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_IMPORT).append(mList.size()).append(BusinessConstants.LOG_DATA_UNIT).toString(), + ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()); Long mId = 0L; for(MaterialWithInitStock m: mList) { //判断该商品是否存在,如果不存在就新增,如果存在就更新 @@ -598,6 +603,9 @@ public class MaterialService { } info.code = 200; info.data = "导入成功"; + } catch (BusinessRunTimeException e) { + info.code = e.getCode(); + info.data = e.getData().get("message"); } catch (Exception e) { e.printStackTrace(); info.code = 500; diff --git a/jshERP-boot/src/main/java/com/jsh/erp/service/unit/UnitService.java b/jshERP-boot/src/main/java/com/jsh/erp/service/unit/UnitService.java index bb0d7804..15b9029e 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/service/unit/UnitService.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/service/unit/UnitService.java @@ -190,7 +190,7 @@ public class UnitService { * @param name */ public Long getUnitIdByName(String name){ - Long unitId = 0L; + Long unitId = null; UnitExample example = new UnitExample(); example.createCriteria().andNameEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED); List list = unitMapper.selectByExample(example);