|
@@ -13,6 +13,7 @@ import com.jsh.erp.datasource.vo.MaterialVoSearch;
|
|
|
import com.jsh.erp.datasource.vo.MaterialWarnListVo;
|
|
|
import com.jsh.erp.exception.BusinessRunTimeException;
|
|
|
import com.jsh.erp.exception.JshException;
|
|
|
+import com.jsh.erp.query.LambdaQueryWrapperX;
|
|
|
import com.jsh.erp.service.*;
|
|
|
import com.jsh.erp.utils.*;
|
|
|
import jxl.Sheet;
|
|
@@ -76,6 +77,10 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
|
|
|
private SystemConfigService systemConfigService;
|
|
|
@Resource
|
|
|
private DepotHeadService depotHeadService;
|
|
|
+ @Resource
|
|
|
+ private SupplierService supplierService;
|
|
|
+ @Resource
|
|
|
+ private DepotMapperEx depotMapperEx;
|
|
|
|
|
|
@Value(value="${file.uploadType}")
|
|
|
private Long fileUploadType;
|
|
@@ -229,6 +234,7 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
|
|
|
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
|
|
public int updateMaterial(JSONObject obj, HttpServletRequest request) throws Exception{
|
|
|
Material material = JSONObject.parseObject(obj.toJSONString(), Material.class);
|
|
|
+
|
|
|
try{
|
|
|
//修改商品属性
|
|
|
materialMapper.updateByPrimaryKeySelective(material);
|
|
@@ -1649,7 +1655,7 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
|
|
|
materialExtendExample.createCriteria().andDeleteFlagEqualTo("0");
|
|
|
List<MaterialExtend> extendList = materialExtendMapper.selectByExample(materialExtendExample);
|
|
|
//无动销提醒
|
|
|
- materials.stream().filter( v -> v.getMovingPinReminderCycle() != null)
|
|
|
+ materials.stream().filter( v -> v.getMovingPinReminderCycle() != null && !"".equals(v.getMovingPinReminderCycle()))
|
|
|
.forEach(v -> {
|
|
|
//获取商品最后一条动销订单数据
|
|
|
DepotHead depotHead = depotHeadService.getDepotLastByMaterialId(v.getId());
|
|
@@ -1751,6 +1757,26 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
|
|
|
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,
|
|
@@ -1781,24 +1807,48 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
|
|
|
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_Category_Name_EMPTY_CODE,
|
|
|
String.format(ExceptionConstants.MATERIAL_Category_Name_EMPTY_MSG, i+1));
|
|
|
}
|
|
|
+ //通过类型名查询类型编号
|
|
|
+ Long categoryId = materialCategoryService.getCategoryIdByName(categoryName);
|
|
|
+ if(null == categoryId){
|
|
|
+ //类别不存在
|
|
|
+ throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_TYPE_NOT_DECIMAL_CODE,
|
|
|
+ String.format(ExceptionConstants.MATERIAL_TYPE_NOT_DECIMAL_MSG, i+1));
|
|
|
+ }
|
|
|
+ Long supplierId = null;
|
|
|
+ if (supplier != null && !supplier.isEmpty()){
|
|
|
+ //根据供应商查询供应商id
|
|
|
+ Supplier s = supplierService.getOne(new LambdaQueryWrapperX<Supplier>().eq(Supplier::getSupplier,supplier));
|
|
|
+ supplierId = s.getId();
|
|
|
+ if (supplierId == null){
|
|
|
+ //供应商不存在
|
|
|
+ throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_SUPPLIER_NOT_DECIMAL_CODE,
|
|
|
+ String.format(ExceptionConstants.MATERIAL_SUPPLIER_NOT_DECIMAL_MSG, i+1));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Long depotId = null;
|
|
|
+ if (depotName != null && !depotName.isEmpty()){
|
|
|
+ //根据仓库名查询仓库id
|
|
|
+ depotId = depotMapperEx.selectByConditionDepot(depotName,null,null).get(0).getId();
|
|
|
+ if (depotId == null){
|
|
|
+ //仓库不存在
|
|
|
+ throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_DEPOT_NOT_DECIMAL_CODE,
|
|
|
+ String.format(ExceptionConstants.MATERIAL_DEPOT_NOT_DECIMAL_MSG, i+1));
|
|
|
+ }
|
|
|
+ }
|
|
|
MaterialWithInitStock m = new MaterialWithInitStock();
|
|
|
- //设置商品名字、规格、型号、颜色、品牌
|
|
|
+ //设置商品名字、规格、型号、颜色、品牌、类型id
|
|
|
m.setName(name);
|
|
|
m.setStandard(standard);
|
|
|
m.setModel(model);
|
|
|
m.setColor(color);
|
|
|
m.setBrand(brand);
|
|
|
+ m.setCategoryId(categoryId);
|
|
|
//通过名称生成助记码
|
|
|
m.setMnemonic(PinYinUtil.getFirstLettersLo(name));
|
|
|
- //通过类型名查询类型编号
|
|
|
- Long categoryId = materialCategoryService.getCategoryIdByName(categoryName);
|
|
|
//获取类型编码
|
|
|
Long serial_no = categoryId == null ? null : materialCategoryService.getMaterialCategory(m.getCategoryId()).getSerialNo();
|
|
|
//设置系统sku
|
|
|
m.setSystemSku(serial_no + DateUtils.dateTimeNow());
|
|
|
- if(null!=categoryId){
|
|
|
- m.setCategoryId(categoryId);
|
|
|
- }
|
|
|
if(StringUtil.isNotEmpty(weight)) {
|
|
|
//校验基础重量是否是数字(含小数)
|
|
|
if(!StringUtil.isPositiveBigDecimal(weight)) {
|
|
@@ -1807,19 +1857,6 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
|
|
|
}
|
|
|
m.setWeight(new BigDecimal(weight));
|
|
|
}
|
|
|
- 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 enableBatchNumber = ExcelUtils.getContent(src, i, 17); //批号
|
|
|
- String systemSku = ExcelUtils.getContent(src, i, 18); //系统sku
|
|
|
- String productionDate = ExcelUtils.getContent(src, i, 19); //生产日期
|
|
|
- String expiryNum = ExcelUtils.getContent(src, i, 20); //保质期天数
|
|
|
if(StringUtil.isNotEmpty(expiryNum)) {
|
|
|
//校验保质期是否是正整数
|
|
|
if(!StringUtil.isPositiveLong(expiryNum)) {
|
|
@@ -1828,17 +1865,6 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
|
|
|
}
|
|
|
//m.setExpiryNum(Integer.parseInt(expiryNum));
|
|
|
}
|
|
|
- String supplier = ExcelUtils.getContent(src, i, 21); //供应商
|
|
|
- String barCode = ExcelUtils.getContent(src, i, 22); //商品条码
|
|
|
- String batchNumber = ExcelUtils.getContent(src, i, 23); //批次号
|
|
|
- String depotName = ExcelUtils.getContent(src, i, 24); //仓库名称
|
|
|
- String position = ExcelUtils.getContent(src, i, 25); //仓位货架
|
|
|
- String otherField1 = ExcelUtils.getContent(src, i, 26); //自定义1
|
|
|
- String otherField2 = ExcelUtils.getContent(src, i, 27); //自定义2
|
|
|
- String otherField3 = ExcelUtils.getContent(src, i, 28); //自定义3
|
|
|
- String remark = ExcelUtils.getContent(src, i, 29); //备注
|
|
|
- // m.setPosition(StringUtil.isNotEmpty(position)?position:null);
|
|
|
- //m.setMfrs(StringUtil.isNotEmpty(mfrs)?mfrs:null);
|
|
|
m.setOtherField1(StringUtil.isNotEmpty(otherField1)?otherField1:null);
|
|
|
m.setOtherField2(StringUtil.isNotEmpty(otherField2)?otherField2:null);
|
|
|
m.setOtherField3(StringUtil.isNotEmpty(otherField3)?otherField3:null);
|
|
@@ -1848,30 +1874,24 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
|
|
|
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_ENABLED_ERROR_CODE,
|
|
|
String.format(ExceptionConstants.MATERIAL_ENABLED_ERROR_MSG, i+1));
|
|
|
}
|
|
|
- //基本条码为空
|
|
|
- if(StringUtil.isEmpty(barCode)) {
|
|
|
- throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_BARCODE_EMPTY_CODE,
|
|
|
- String.format(ExceptionConstants.MATERIAL_BARCODE_EMPTY_MSG, i+1));
|
|
|
- }
|
|
|
- //校验基本条码长度为4到40位
|
|
|
- if(!StringUtil.checkBarCodeLength(barCode)) {
|
|
|
- throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_BARCODE_LENGTH_ERROR_CODE,
|
|
|
- String.format(ExceptionConstants.MATERIAL_BARCODE_LENGTH_ERROR_MSG, barCode));
|
|
|
- }
|
|
|
//批量校验excel中有无重复商品,是指名称、规格、型号、颜色、单位、多属性
|
|
|
- batchCheckExistMaterialListByParam(mList, name, standard, model, color, unit, sku);
|
|
|
- //批量校验excel中有无重复条码(1-文档自身校验,2-和数据库里面的商品校验)
|
|
|
- //batchCheckExistBarCodeByParam(mList, barCode, manyBarCode);
|
|
|
+ //batchCheckExistMaterialListByParam(mList, name, standard, model, color, unit, sku);
|
|
|
//设置商品拓展属性
|
|
|
JSONObject materialExObj = new JSONObject();
|
|
|
JSONObject basicObj = new JSONObject();
|
|
|
- basicObj.put("barCode", barCode);
|
|
|
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);
|
|
|
materialExObj.put("basic", basicObj);
|
|
|
if(StringUtil.isNotEmpty(manyUnit) && StringUtil.isNotEmpty(ratio)){ //多单位
|
|
|
//校验比例是否是数字(含小数)
|
|
@@ -1884,12 +1904,7 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
|
|
|
m.setUnitId(unitId);
|
|
|
m.setUnit("");
|
|
|
}
|
|
|
-// else {
|
|
|
-// throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_UNIT_MATE_CODE,
|
|
|
-// String.format(ExceptionConstants.MATERIAL_UNIT_MATE_MSG, manyBarCode));
|
|
|
-// }
|
|
|
JSONObject otherObj = new JSONObject();
|
|
|
- //otherObj.put("barCode", manyBarCode);
|
|
|
otherObj.put("commodityUnit", manyUnit);
|
|
|
otherObj.put("purchaseDecimal", parsePrice(purchaseDecimal,ratio));
|
|
|
otherObj.put("commodityDecimal", parsePrice(commodityDecimal,ratio));
|
|
@@ -1901,24 +1916,30 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
|
|
|
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");
|
|
|
}
|
|
|
- if(StringUtil.isNotEmpty(enableBatchNumber) && "1".equals(enableBatchNumber)) {
|
|
|
- m.setEnableBatchNumber("1");
|
|
|
- } else {
|
|
|
- m.setEnableBatchNumber("0");
|
|
|
- }
|
|
|
- if("1".equals(enableSerialNumber) && "1".equals(enableBatchNumber)) {
|
|
|
- throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_ENABLE_MUST_ONE_CODE,
|
|
|
- String.format(ExceptionConstants.MATERIAL_ENABLE_MUST_ONE_MSG, barCode));
|
|
|
- }
|
|
|
+ //批号去掉
|
|
|
+// if(StringUtil.isNotEmpty(enableBatchNumber) && "1".equals(enableBatchNumber)) {
|
|
|
+// m.setEnableBatchNumber("1");
|
|
|
+// } else {
|
|
|
+// m.setEnableBatchNumber("0");
|
|
|
+// }
|
|
|
+// if("1".equals(enableSerialNumber) && "1".equals(enableBatchNumber)) {
|
|
|
+// throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_ENABLE_MUST_ONE_CODE,
|
|
|
+// String.format(ExceptionConstants.MATERIAL_ENABLE_MUST_ONE_MSG, barCode));
|
|
|
+// }
|
|
|
+ //设置库存
|
|
|
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<>();
|
|
@@ -1926,86 +1947,25 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
|
|
|
//防止初始库存和当前库存出现重复
|
|
|
Map<String, String> materialDepotInitialMap = new HashMap<>();
|
|
|
Map<String, String> materialDepotCurrentMap = new HashMap<>();
|
|
|
- for(MaterialWithInitStock m: mList) {
|
|
|
- Long mId = 0L;
|
|
|
- //判断该商品是否存在,如果不存在就新增,如果存在就更新
|
|
|
- String basicBarCode = getBasicBarCode(m);
|
|
|
- //根据条件返回产品列表
|
|
|
- List<Material> materials = getMaterialListByParam(m.getName(),m.getStandard(),m.getModel(),m.getColor(),m.getUnit(),m.getUnitId(), basicBarCode);
|
|
|
- if(materials.size() == 0) { //产品列表为0,新增商品
|
|
|
- materialMapperEx.insertSelectiveEx(m);
|
|
|
- mId = m.getId();
|
|
|
- } else { //产品列表不为0,商品存在,修改商品属性
|
|
|
- mId = materials.get(0).getId();
|
|
|
- String materialJson = JSON.toJSONString(m);
|
|
|
- Material material = JSONObject.parseObject(materialJson, Material.class);
|
|
|
- material.setId(mId);
|
|
|
- materialMapper.updateByPrimaryKeySelective(material);
|
|
|
- //更新多单位
|
|
|
- if(material.getUnitId() == null) {
|
|
|
- materialMapperEx.setUnitIdToNull(material.getId());
|
|
|
- }
|
|
|
- //如果之前有保质期,则更新保质期
|
|
|
-// if(materials.get(0).getExpiryNum()!=null && material.getExpiryNum() == null) {
|
|
|
-// materialMapperEx.setExpiryNumToNull(material.getId());
|
|
|
-// }
|
|
|
- }
|
|
|
- //给商品新增或更新条码与价格相关信息
|
|
|
- JSONObject materialExObj = m.getMaterialExObj();
|
|
|
- insertOrUpdateMaterialExtend(materialExObj, "basic", "1", mId, user);
|
|
|
- insertOrUpdateMaterialExtend(materialExObj, "other", "0", mId, user);
|
|
|
- //给商品更新库存
|
|
|
- Map<Long, BigDecimal> stockMap = m.getStockMap();
|
|
|
- for(Depot depot: depotList){
|
|
|
- Long depotId = depot.getId();
|
|
|
- String materialDepotKey = mId + "_" + depotId;
|
|
|
- //获取初始库存
|
|
|
- BigDecimal initStock = getInitStock(mId, depotId);
|
|
|
- //excel里面的当前库存
|
|
|
- BigDecimal stock = stockMap.get(depot.getId());
|
|
|
- //新增或更新初始库存
|
|
|
- if(stock!=null && stock.compareTo(BigDecimal.ZERO)!=0) {
|
|
|
- String basicStr = materialExObj.getString("basic");
|
|
|
- MaterialExtend materialExtend = JSONObject.parseObject(basicStr, MaterialExtend.class);
|
|
|
- if(StringUtil.isNotEmpty(materialExtend.getSku())) {
|
|
|
- throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_SKU_BEGIN_STOCK_FAILED_CODE,
|
|
|
- String.format(ExceptionConstants.MATERIAL_SKU_BEGIN_STOCK_FAILED_MSG, materialExtend.getBarCode()));
|
|
|
- }
|
|
|
- buildChangeInitialStock(deleteInitialStockMaterialIdList, insertInitialStockMaterialList, materialDepotInitialMap, mId, depotId, materialDepotKey, stock);
|
|
|
- } else {
|
|
|
- if(initStock.compareTo(BigDecimal.ZERO)!=0) {
|
|
|
- buildChangeInitialStock(deleteInitialStockMaterialIdList, insertInitialStockMaterialList, materialDepotInitialMap, mId, depotId, materialDepotKey, stock);
|
|
|
- }
|
|
|
- }
|
|
|
- //新增或更新当前库存
|
|
|
- Long billCount = depotItemService.getCountByMaterialAndDepot(mId, depotId);
|
|
|
- if(billCount == 0) {
|
|
|
- if(stock!=null && stock.compareTo(BigDecimal.ZERO)!=0) {
|
|
|
- buildChangeCurrentStock(deleteCurrentStockMaterialIdList, insertCurrentStockMaterialList, materialDepotCurrentMap, mId, depotId, materialDepotKey, stock);
|
|
|
- } else {
|
|
|
- if(initStock.compareTo(BigDecimal.ZERO)!=0) {
|
|
|
- buildChangeCurrentStock(deleteCurrentStockMaterialIdList, insertCurrentStockMaterialList, materialDepotCurrentMap, mId, depotId, materialDepotKey, stock);
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- BigDecimal currentNumber = getCurrentStockByMaterialIdAndDepotId(mId, depotId);
|
|
|
- //当前库存的更新:减去初始库存,再加上导入的新初始库存
|
|
|
- if(currentNumber!=null && initStock!=null && stock!=null) {
|
|
|
- currentNumber = currentNumber.subtract(initStock).add(stock);
|
|
|
- }
|
|
|
- buildChangeCurrentStock(deleteCurrentStockMaterialIdList, insertCurrentStockMaterialList, materialDepotCurrentMap, mId, depotId, materialDepotKey, currentNumber);
|
|
|
- }
|
|
|
+ for (Material material : materialList) {
|
|
|
+ //添加商品
|
|
|
+ materialMapperEx.insertSelectiveEx(material);
|
|
|
+ //
|
|
|
+ Long mId = material.getId();
|
|
|
+ for (MaterialExtend materialExtend : material.getList()) {
|
|
|
+ materialExtend.setMaterialId(mId);
|
|
|
+ materialExtendService.insertMaterialExtend(materialExtend);
|
|
|
}
|
|
|
}
|
|
|
//批量更新库存,先删除后新增
|
|
|
- if(insertInitialStockMaterialList.size()>0) {
|
|
|
- batchDeleteInitialStockByMaterialList(deleteInitialStockMaterialIdList);
|
|
|
- materialInitialStockMapperEx.batchInsert(insertInitialStockMaterialList);
|
|
|
- }
|
|
|
- if(insertCurrentStockMaterialList.size()>0) {
|
|
|
- batchDeleteCurrentStockByMaterialList(deleteCurrentStockMaterialIdList);
|
|
|
- materialCurrentStockMapperEx.batchInsert(insertCurrentStockMaterialList);
|
|
|
- }
|
|
|
+// if(insertInitialStockMaterialList.size()>0) {
|
|
|
+// batchDeleteInitialStockByMaterialList(deleteInitialStockMaterialIdList);
|
|
|
+// materialInitialStockMapperEx.batchInsert(insertInitialStockMaterialList);
|
|
|
+// }
|
|
|
+// if(insertCurrentStockMaterialList.size()>0) {
|
|
|
+// batchDeleteCurrentStockByMaterialList(deleteCurrentStockMaterialIdList);
|
|
|
+// materialCurrentStockMapperEx.batchInsert(insertCurrentStockMaterialList);
|
|
|
+// }
|
|
|
//添加日志
|
|
|
logService.insertLog("商品",
|
|
|
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_IMPORT).append(mList.size()).append(BusinessConstants.LOG_DATA_UNIT).toString(),
|
|
@@ -2025,4 +1985,98 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
|
|
|
return info;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 解析excel表格数据为商品对象
|
|
|
+ */
|
|
|
+ public List<Material> parseMapByExcelData(List<MaterialWithInitStock> mList){
|
|
|
+ List<Material> materials = new ArrayList<>();
|
|
|
+ Map<String,Material> materialMap = new HashMap<>();
|
|
|
+ for (MaterialWithInitStock m : mList) {
|
|
|
+ String materialSku = "";
|
|
|
+ JSONObject materialExObj = m.getMaterialExObj();
|
|
|
+ JSONObject basicObj = materialExObj.getJSONObject("basic");
|
|
|
+ if(materialExObj!=null && materialExObj.get("basic")!=null) {
|
|
|
+ if(basicObj!=null && materialExObj.get("sku")!=null) {
|
|
|
+ materialSku = basicObj.getString("sku");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //名称,型号,品牌,规格,颜色,单位一样视为同一商品
|
|
|
+ String str = m.getName()
|
|
|
+ +"-" + m.getModel()
|
|
|
+ + "-" + m.getStandard()
|
|
|
+ + "-" + m.getBrand()
|
|
|
+ + "-" + m.getColor()
|
|
|
+ + "-" + m.getUnit()
|
|
|
+ + "-" + materialSku;
|
|
|
+ if (materialMap.get(str) == null) {
|
|
|
+ //商品主表不存在,创建商品主表
|
|
|
+ Material material = new Material();
|
|
|
+ //名称
|
|
|
+ material.setName(m.getName());
|
|
|
+ //型号
|
|
|
+ material.setModel(m.getModel());
|
|
|
+ //规格
|
|
|
+ material.setStandard(m.getStandard());
|
|
|
+ //品牌
|
|
|
+ material.setBrand(m.getBrand());
|
|
|
+ //助记码
|
|
|
+ material.setMnemonic(m.getMnemonic());
|
|
|
+ //颜色
|
|
|
+ material.setColor(m.getColor());
|
|
|
+ //单位-单个
|
|
|
+ material.setUnit(m.getUnit());
|
|
|
+ //计量单位Id
|
|
|
+ material.setUnitId(m.getUnitId());
|
|
|
+ //启用 0-禁用 1-启用
|
|
|
+ material.setEnabled(m.getEnabled());
|
|
|
+ //自定义1
|
|
|
+ material.setOtherField1(m.getOtherField1());
|
|
|
+ //自定义2
|
|
|
+ material.setOtherField2(m.getOtherField2());
|
|
|
+ //自定义3
|
|
|
+ material.setOtherField3(m.getOtherField3());
|
|
|
+ //是否开启序列号
|
|
|
+ material.setEnableSerialNumber(m.getEnableSerialNumber());
|
|
|
+ //系统sku
|
|
|
+ material.setSystemSku(m.getSystemSku());
|
|
|
+ List<MaterialExtend> list = new ArrayList<>();
|
|
|
+ material.setList(list);
|
|
|
+ materialMap.put(str,material);
|
|
|
+ }
|
|
|
+ //添加子表信息
|
|
|
+ MaterialExtend materialExtend = new MaterialExtend();
|
|
|
+ //商品单位
|
|
|
+ materialExtend.setCommodityUnit(m.getUnit());
|
|
|
+ //商品属性
|
|
|
+ materialExtend.setSku(materialSku);
|
|
|
+ //采购价格
|
|
|
+ materialExtend.setPurchaseDecimal(basicObj.getBigDecimal("purchaseDecimal"));
|
|
|
+ //零售价格
|
|
|
+ materialExtend.setCommodityDecimal(basicObj.getBigDecimal("commodityDecimal"));
|
|
|
+ //销售价格
|
|
|
+ materialExtend.setWholesaleDecimal(basicObj.getBigDecimal("wholesaleDecimal"));
|
|
|
+ //最低售价
|
|
|
+ materialExtend.setLowDecimal(basicObj.getBigDecimal("lowDecimal"));
|
|
|
+ //生产日期
|
|
|
+ materialExtend.setProductionDate(basicObj.getDate("productionDate"));
|
|
|
+ //保质期天数
|
|
|
+ materialExtend.setExpiryNum(basicObj.getInteger("expiryNum"));
|
|
|
+ //供应商id
|
|
|
+ materialExtend.setSupplierId(basicObj.getLong("supplierId"));
|
|
|
+ //商品条码
|
|
|
+ materialExtend.setBarCode(basicObj.getString("barCode"));
|
|
|
+ //设置批次号
|
|
|
+ String batchNumber = DateUtils.dateTimeNow("yyyyMMdd") + RandomHelper.getRandomStr(6);
|
|
|
+ materialExtend.setBatchNumber(batchNumber);
|
|
|
+ //仓库id
|
|
|
+ materialExtend.setDepotId(basicObj.getLong("depotId"));
|
|
|
+ //仓位货架
|
|
|
+ materialExtend.setPosition(basicObj.getString("position"));
|
|
|
+ materialExtend.setInventory(basicObj.getBigDecimal("inventory"));
|
|
|
+ materialMap.get(str).getList().add(materialExtend);
|
|
|
+ }
|
|
|
+ materialMap.values().forEach(v -> materials.add(v));
|
|
|
+ return materials;
|
|
|
+ }
|
|
|
+
|
|
|
}
|