|
@@ -1730,13 +1730,6 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
|
|
|
return vo;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 导入表格
|
|
|
- * @param file
|
|
|
- * @param request
|
|
|
- * @return
|
|
|
- * @throws Exception
|
|
|
- */
|
|
|
@Override
|
|
|
public BaseResponseInfo importExcelTwo(MultipartFile file, HttpServletRequest request) throws Exception {
|
|
|
BaseResponseInfo info = new BaseResponseInfo();
|
|
@@ -1755,6 +1748,7 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
|
|
|
Sheet src = workbook.getSheet(0);
|
|
|
//获取真实的行数,剔除掉空白行
|
|
|
int rightRows = ExcelUtils.getRightRows(src);
|
|
|
+ //获取所有仓库
|
|
|
List<Depot> depotList= depotService.getDepot();
|
|
|
int depotCount = depotList.size();
|
|
|
Map<String, Long> depotMap = parseDepotToMap(depotList);
|
|
@@ -1767,33 +1761,6 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
|
|
|
}
|
|
|
for (int i = 2; i < rightRows; 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 brand = ExcelUtils.getContent(src, i, 4); //品牌
|
|
|
- String categoryName = ExcelUtils.getContent(src, i, 5); //类别
|
|
|
- String weight = ExcelUtils.getContent(src, i, 6); //基础重量(kg)
|
|
|
- String unit = ExcelUtils.getContent(src, i, 7); //基本单位
|
|
|
- String manyUnit = ExcelUtils.getContent(src, i, 8); //副单位
|
|
|
- String ratio = ExcelUtils.getContent(src, i, 9); //比例
|
|
|
- String sku = 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); //最低售价
|
|
|
- String enabled = ExcelUtils.getContent(src, i, 15); //状态
|
|
|
- String enableSerialNumber = ExcelUtils.getContent(src, i, 16); //序列号
|
|
|
- String productionDate = ExcelUtils.getContent(src, i, 17); //生产日期
|
|
|
- String expiryNum = ExcelUtils.getContent(src, i, 18); //保质期天数
|
|
|
- String supplier = ExcelUtils.getContent(src, i, 19); //供应商
|
|
|
- String barCode = ExcelUtils.getContent(src, i, 20); //商品条码
|
|
|
- String depotName = ExcelUtils.getContent(src, i, 21); //仓库名称
|
|
|
- String position = ExcelUtils.getContent(src, i, 22); //仓位货架
|
|
|
- String inventory = ExcelUtils.getContent(src,i,23);//库存
|
|
|
- String otherField1 = ExcelUtils.getContent(src, i, 24); //自定义1
|
|
|
- String otherField2 = ExcelUtils.getContent(src, i, 25); //自定义2
|
|
|
- String otherField3 = ExcelUtils.getContent(src, i, 26); //自定义3
|
|
|
- String remark = ExcelUtils.getContent(src, i, 27); //备注
|
|
|
//名称为空
|
|
|
if(StringUtil.isEmpty(name)) {
|
|
|
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_NAME_EMPTY_CODE,
|
|
@@ -1804,21 +1771,21 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
|
|
|
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_NAME_OVER_CODE,
|
|
|
String.format(ExceptionConstants.MATERIAL_NAME_OVER_MSG, i+1));
|
|
|
}
|
|
|
+ String standard = ExcelUtils.getContent(src, i, 1); //规格
|
|
|
//规格长度超出
|
|
|
if(StringUtil.isNotEmpty(standard) && standard.length()>100) {
|
|
|
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_STANDARD_OVER_CODE,
|
|
|
String.format(ExceptionConstants.MATERIAL_STANDARD_OVER_MSG, i+1));
|
|
|
}
|
|
|
+ String model = ExcelUtils.getContent(src, i, 2); //型号
|
|
|
//型号长度超出
|
|
|
if(StringUtil.isNotEmpty(model) && model.length()>100) {
|
|
|
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_MODEL_OVER_CODE,
|
|
|
String.format(ExceptionConstants.MATERIAL_MODEL_OVER_MSG, i+1));
|
|
|
}
|
|
|
- //基本单位为空
|
|
|
- if(StringUtil.isEmpty(unit)) {
|
|
|
- throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_UNIT_EMPTY_CODE,
|
|
|
- String.format(ExceptionConstants.MATERIAL_UNIT_EMPTY_MSG, i+1));
|
|
|
- }
|
|
|
+ String color = ExcelUtils.getContent(src, i, 3); //颜色
|
|
|
+ String brand = ExcelUtils.getContent(src, i, 4); //品牌
|
|
|
+ String categoryName = ExcelUtils.getContent(src, i, 5); //类别
|
|
|
//类别为空
|
|
|
if(StringUtil.isEmpty(categoryName)) {
|
|
|
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_Category_Name_EMPTY_CODE,
|
|
@@ -1831,8 +1798,46 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
|
|
|
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_TYPE_NOT_DECIMAL_CODE,
|
|
|
String.format(ExceptionConstants.MATERIAL_TYPE_NOT_DECIMAL_MSG, i+1));
|
|
|
}
|
|
|
+ String weight = ExcelUtils.getContent(src, i, 6); //基础重量(kg)
|
|
|
+ if(StringUtil.isNotEmpty(weight)) {
|
|
|
+ //校验基础重量是否是数字(含小数)
|
|
|
+ if(!StringUtil.isPositiveBigDecimal(weight)) {
|
|
|
+ throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_WEIGHT_NOT_DECIMAL_CODE,
|
|
|
+ String.format(ExceptionConstants.MATERIAL_WEIGHT_NOT_DECIMAL_MSG, i+1));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String unit = ExcelUtils.getContent(src, i, 7); //基本单位
|
|
|
+ //基本单位为空
|
|
|
+ if(StringUtil.isEmpty(unit)) {
|
|
|
+ throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_UNIT_EMPTY_CODE,
|
|
|
+ String.format(ExceptionConstants.MATERIAL_UNIT_EMPTY_MSG, i+1));
|
|
|
+ }
|
|
|
+ String manyUnit = ExcelUtils.getContent(src, i, 8); //副单位
|
|
|
+ String ratio = ExcelUtils.getContent(src, i, 9); //比例
|
|
|
+ String sku = 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); //最低售价
|
|
|
+ String enabled = ExcelUtils.getContent(src, i, 15); //状态
|
|
|
+ //状态格式错误
|
|
|
+ if(!"1".equals(enabled) && !"0".equals(enabled)) {
|
|
|
+ throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_ENABLED_ERROR_CODE,
|
|
|
+ String.format(ExceptionConstants.MATERIAL_ENABLED_ERROR_MSG, i+1));
|
|
|
+ }
|
|
|
+ String enableSerialNumber = ExcelUtils.getContent(src, i, 16); //序列号
|
|
|
+ String productionDate = ExcelUtils.getContent(src, i, 17); //生产日期
|
|
|
+ String expiryNum = ExcelUtils.getContent(src, i, 18); //保质期天数
|
|
|
+ if(StringUtil.isNotEmpty(expiryNum)) {
|
|
|
+ //校验保质期是否是正整数
|
|
|
+ if(!StringUtil.isPositiveLong(expiryNum)) {
|
|
|
+ throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_EXPIRY_NUM_NOT_INTEGER_CODE,
|
|
|
+ String.format(ExceptionConstants.MATERIAL_EXPIRY_NUM_NOT_INTEGER_MSG, i+1));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String supplier = ExcelUtils.getContent(src, i, 19); //供应商
|
|
|
Long supplierId = null;
|
|
|
- if (supplier != null && !supplier.isEmpty()){
|
|
|
+ if(StringUtil.isNotEmpty(supplier)) {
|
|
|
//根据供应商查询供应商id
|
|
|
Supplier s = supplierService.getOne(new LambdaQueryWrapperX<Supplier>().eq(Supplier::getSupplier,supplier));
|
|
|
supplierId = s.getId();
|
|
@@ -1842,8 +1847,10 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
|
|
|
String.format(ExceptionConstants.MATERIAL_SUPPLIER_NOT_DECIMAL_MSG, i+1));
|
|
|
}
|
|
|
}
|
|
|
+ String barCode = ExcelUtils.getContent(src, i, 20); //商品条码
|
|
|
+ String depotName = ExcelUtils.getContent(src, i, 21); //仓库名称
|
|
|
Long depotId = null;
|
|
|
- if (depotName != null && !depotName.isEmpty()){
|
|
|
+ if(StringUtil.isNotEmpty(supplier)) {
|
|
|
//根据仓库名查询仓库id
|
|
|
depotId = depotMapperEx.selectByConditionDepot(depotName,null,null).get(0).getId();
|
|
|
if (depotId == null){
|
|
@@ -1852,6 +1859,12 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
|
|
|
String.format(ExceptionConstants.MATERIAL_DEPOT_NOT_DECIMAL_MSG, i+1));
|
|
|
}
|
|
|
}
|
|
|
+ String position = ExcelUtils.getContent(src, i, 22); //仓位货架
|
|
|
+ String inventory = ExcelUtils.getContent(src,i,23);//库存
|
|
|
+ String otherField1 = ExcelUtils.getContent(src, i, 24); //自定义1
|
|
|
+ String otherField2 = ExcelUtils.getContent(src, i, 25); //自定义2
|
|
|
+ String otherField3 = ExcelUtils.getContent(src, i, 26); //自定义3
|
|
|
+ String remark = ExcelUtils.getContent(src, i, 27); //备注
|
|
|
MaterialWithInitStock m = new MaterialWithInitStock();
|
|
|
//设置商品名字、规格、型号、颜色、品牌、类型id
|
|
|
m.setName(name);
|
|
@@ -1862,53 +1875,42 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
|
|
|
m.setCategoryId(categoryId);
|
|
|
//通过名称生成助记码
|
|
|
m.setMnemonic(PinYinUtil.getFirstLettersLo(name));
|
|
|
+ //设置单位、备注、基础重量
|
|
|
+ m.setUnit(unit);
|
|
|
+ m.setRemark(remark);
|
|
|
+ m.setWeight(new BigDecimal(weight));
|
|
|
+ //设置商品是否启用
|
|
|
+ m.setEnabled("1".equals(enabled));
|
|
|
+ //设置商品是否开启序列号
|
|
|
+ if(StringUtil.isNotEmpty(enableSerialNumber) && "1".equals(enableSerialNumber)) {
|
|
|
+ m.setEnableSerialNumber("1");
|
|
|
+ } else {
|
|
|
+ m.setEnableSerialNumber("0");
|
|
|
+ }
|
|
|
//获取类型编码
|
|
|
Long serial_no = categoryId == null ? null : materialCategoryService.getMaterialCategory(m.getCategoryId()).getSerialNo();
|
|
|
//设置系统sku
|
|
|
- m.setSystemSku(serial_no + DateUtils.dateTimeNow());
|
|
|
- if(StringUtil.isNotEmpty(weight)) {
|
|
|
- //校验基础重量是否是数字(含小数)
|
|
|
- if(!StringUtil.isPositiveBigDecimal(weight)) {
|
|
|
- throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_WEIGHT_NOT_DECIMAL_CODE,
|
|
|
- String.format(ExceptionConstants.MATERIAL_WEIGHT_NOT_DECIMAL_MSG, i+1));
|
|
|
- }
|
|
|
- m.setWeight(new BigDecimal(weight));
|
|
|
- }
|
|
|
- if(StringUtil.isNotEmpty(expiryNum)) {
|
|
|
- //校验保质期是否是正整数
|
|
|
- if(!StringUtil.isPositiveLong(expiryNum)) {
|
|
|
- throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_EXPIRY_NUM_NOT_INTEGER_CODE,
|
|
|
- String.format(ExceptionConstants.MATERIAL_EXPIRY_NUM_NOT_INTEGER_MSG, i+1));
|
|
|
- }
|
|
|
- //m.setExpiryNum(Integer.parseInt(expiryNum));
|
|
|
- }
|
|
|
+ m.setSystemSku(serial_no + DateUtils.dateTimeNow() + RandomHelper.getRandomStr(6));
|
|
|
m.setOtherField1(StringUtil.isNotEmpty(otherField1)?otherField1:null);
|
|
|
m.setOtherField2(StringUtil.isNotEmpty(otherField2)?otherField2:null);
|
|
|
m.setOtherField3(StringUtil.isNotEmpty(otherField3)?otherField3:null);
|
|
|
m.setRemark(remark);
|
|
|
- //状态格式错误
|
|
|
- if(!"1".equals(enabled) && !"0".equals(enabled)) {
|
|
|
- throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_ENABLED_ERROR_CODE,
|
|
|
- String.format(ExceptionConstants.MATERIAL_ENABLED_ERROR_MSG, i+1));
|
|
|
- }
|
|
|
- //批量校验excel中有无重复商品,是指名称、规格、型号、颜色、单位、多属性
|
|
|
- //batchCheckExistMaterialListByParam(mList, name, standard, model, color, unit, sku);
|
|
|
//设置商品拓展属性
|
|
|
JSONObject materialExObj = new JSONObject();
|
|
|
JSONObject basicObj = new JSONObject();
|
|
|
- basicObj.put("commodityUnit", unit);
|
|
|
- basicObj.put("sku", sku);
|
|
|
- basicObj.put("purchaseDecimal", purchaseDecimal);
|
|
|
- basicObj.put("commodityDecimal", commodityDecimal);
|
|
|
- basicObj.put("wholesaleDecimal", wholesaleDecimal);
|
|
|
- basicObj.put("lowDecimal", lowDecimal);
|
|
|
- basicObj.put("productionDate",productionDate);
|
|
|
- basicObj.put("expiryNum",expiryNum);
|
|
|
- basicObj.put("supplierId",supplierId);
|
|
|
- basicObj.put("barCode", barCode);
|
|
|
- basicObj.put("inventory",inventory);
|
|
|
- basicObj.put("depotId",depotId);
|
|
|
- basicObj.put("position",position);
|
|
|
+ basicObj.put("commodityUnit", unit); //商品单位
|
|
|
+ basicObj.put("sku", sku); //商品属性
|
|
|
+ basicObj.put("purchaseDecimal", purchaseDecimal); //采购价格
|
|
|
+ basicObj.put("commodityDecimal", commodityDecimal); //零售价格
|
|
|
+ basicObj.put("wholesaleDecimal", wholesaleDecimal); //销售价格
|
|
|
+ basicObj.put("lowDecimal", lowDecimal); //最低售价
|
|
|
+ basicObj.put("productionDate",productionDate); //生产日期
|
|
|
+ basicObj.put("expiryNum",expiryNum); //保质期天数
|
|
|
+ basicObj.put("supplierId",supplierId); //供应商id
|
|
|
+ basicObj.put("barCode", barCode); //商品条码
|
|
|
+ basicObj.put("inventory",inventory); //库存
|
|
|
+ basicObj.put("depotId",depotId); //仓库id
|
|
|
+ basicObj.put("position",position); //仓位货架
|
|
|
materialExObj.put("basic", basicObj);
|
|
|
if(StringUtil.isNotEmpty(manyUnit) && StringUtil.isNotEmpty(ratio)){ //多单位
|
|
|
//校验比例是否是数字(含小数)
|
|
@@ -1921,46 +1923,31 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
|
|
|
m.setUnitId(unitId);
|
|
|
m.setUnit("");
|
|
|
}
|
|
|
- JSONObject otherObj = new JSONObject();
|
|
|
- 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);
|
|
|
+// JSONObject otherObj = new JSONObject();
|
|
|
+// 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.setUnitId(null);
|
|
|
}
|
|
|
m.setMaterialExObj(materialExObj);
|
|
|
- //设置商品是否启用
|
|
|
- m.setEnabled("1".equals(enabled));
|
|
|
- //设置商品是否开启序列号
|
|
|
- if(StringUtil.isNotEmpty(enableSerialNumber) && "1".equals(enableSerialNumber)) {
|
|
|
- m.setEnableSerialNumber("1");
|
|
|
- } else {
|
|
|
- m.setEnableSerialNumber("0");
|
|
|
- }
|
|
|
//设置库存
|
|
|
m.setStockMap(getStockMapCache(src, depotCount, depotMap, i));
|
|
|
mList.add(m);
|
|
|
}
|
|
|
//处理表单信息,转为对象集合
|
|
|
List<Material> materialList = parseMapByExcelData(mList);
|
|
|
- List<Long> deleteInitialStockMaterialIdList = new ArrayList<>();
|
|
|
- List<Long> deleteCurrentStockMaterialIdList = new ArrayList<>();
|
|
|
- List<MaterialInitialStock> insertInitialStockMaterialList = new ArrayList<>();
|
|
|
- List<MaterialCurrentStock> insertCurrentStockMaterialList = new ArrayList<>();
|
|
|
- //防止初始库存和当前库存出现重复
|
|
|
- Map<String, String> materialDepotInitialMap = new HashMap<>();
|
|
|
- Map<String, String> materialDepotCurrentMap = new HashMap<>();
|
|
|
for (Material material : materialList) {
|
|
|
- //添加商品
|
|
|
+ //添加商品信息
|
|
|
materialMapperEx.insertSelectiveEx(material);
|
|
|
- //
|
|
|
- Long mId = material.getId();
|
|
|
+ //添加商品子信息
|
|
|
for (MaterialExtend materialExtend : material.getList()) {
|
|
|
- materialExtend.setMaterialId(mId);
|
|
|
+ //设置商品id
|
|
|
+ materialExtend.setMaterialId( material.getId());
|
|
|
materialExtendService.insertMaterialExtend(materialExtend);
|
|
|
}
|
|
|
}
|
|
@@ -2069,6 +2056,10 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
|
|
|
material.setUnit(m.getUnit());
|
|
|
//计量单位Id
|
|
|
material.setUnitId(m.getUnitId());
|
|
|
+ //备注
|
|
|
+ material.setRemark(m.getRemark());
|
|
|
+ //基础重量
|
|
|
+ material.setWeight(m.getWeight());
|
|
|
//启用 0-禁用 1-启用
|
|
|
material.setEnabled(m.getEnabled());
|
|
|
//自定义1
|
|
@@ -2114,6 +2105,7 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
|
|
|
materialExtend.setDepotId(basicObj.getLong("depotId"));
|
|
|
//仓位货架
|
|
|
materialExtend.setPosition(basicObj.getString("position"));
|
|
|
+ //库存
|
|
|
materialExtend.setInventory(basicObj.getBigDecimal("inventory"));
|
|
|
materialMap.get(str).getList().add(materialExtend);
|
|
|
}
|