优化商品导入功能
This commit is contained in:
Binary file not shown.
@@ -1,5 +1,7 @@
|
|||||||
package com.jsh.erp.datasource.entities;
|
package com.jsh.erp.datasource.entities;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -7,6 +9,8 @@ public class MaterialWithInitStock extends Material {
|
|||||||
|
|
||||||
private Map<Long, BigDecimal> stockMap;
|
private Map<Long, BigDecimal> stockMap;
|
||||||
|
|
||||||
|
private JSONObject materialExObj;
|
||||||
|
|
||||||
public Map<Long, BigDecimal> getStockMap() {
|
public Map<Long, BigDecimal> getStockMap() {
|
||||||
return stockMap;
|
return stockMap;
|
||||||
}
|
}
|
||||||
@@ -14,4 +18,12 @@ public class MaterialWithInitStock extends Material {
|
|||||||
public void setStockMap(Map<Long, BigDecimal> stockMap) {
|
public void setStockMap(Map<Long, BigDecimal> stockMap) {
|
||||||
this.stockMap = stockMap;
|
this.stockMap = stockMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JSONObject getMaterialExObj() {
|
||||||
|
return materialExObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaterialExObj(JSONObject materialExObj) {
|
||||||
|
this.materialExObj = materialExObj;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -40,6 +40,8 @@ public class MaterialService {
|
|||||||
@Resource
|
@Resource
|
||||||
private MaterialMapper materialMapper;
|
private MaterialMapper materialMapper;
|
||||||
@Resource
|
@Resource
|
||||||
|
private MaterialExtendMapper materialExtendMapper;
|
||||||
|
@Resource
|
||||||
private MaterialMapperEx materialMapperEx;
|
private MaterialMapperEx materialMapperEx;
|
||||||
@Resource
|
@Resource
|
||||||
private MaterialExtendMapperEx materialExtendMapperEx;
|
private MaterialExtendMapperEx materialExtendMapperEx;
|
||||||
@@ -366,68 +368,63 @@ public class MaterialService {
|
|||||||
public BaseResponseInfo importExcel(Sheet src) throws Exception {
|
public BaseResponseInfo importExcel(Sheet src) throws Exception {
|
||||||
List<Depot> depotList= depotService.getDepot();
|
List<Depot> depotList= depotService.getDepot();
|
||||||
int depotCount = depotList.size();
|
int depotCount = depotList.size();
|
||||||
List<MaterialWithInitStock> mList = new ArrayList<MaterialWithInitStock>();
|
List<MaterialWithInitStock> mList = new ArrayList<>();
|
||||||
for (int i = 2; i < src.getRows(); i++) {
|
for (int i = 2; i < src.getRows(); i++) {
|
||||||
String name = ExcelUtils.getContent(src, i, 0); //名称
|
String name = ExcelUtils.getContent(src, i, 0); //名称
|
||||||
String model = ExcelUtils.getContent(src, i, 1); //型号
|
String standard = ExcelUtils.getContent(src, i, 1); //规格
|
||||||
String categoryName = ExcelUtils.getContent(src, i, 2); //类型
|
String model = ExcelUtils.getContent(src, i, 2); //型号
|
||||||
String safetyStock = ExcelUtils.getContent(src, i, 3); //安全存量
|
String color = ExcelUtils.getContent(src, i, 3); //颜色
|
||||||
String color = ExcelUtils.getContent(src, i, 4); //颜色
|
String categoryName = ExcelUtils.getContent(src, i, 4); //类别
|
||||||
String unit = ExcelUtils.getContent(src, i, 5); //单位
|
String safetyStock = ExcelUtils.getContent(src, i, 5); //安全存量
|
||||||
|
String unit = ExcelUtils.getContent(src, i, 6); //基础单位
|
||||||
//校验名称、型号、单位是否为空
|
//校验名称、型号、单位是否为空
|
||||||
if(StringUtil.isNotEmpty(name) && StringUtil.isNotEmpty(model) && StringUtil.isNotEmpty(unit)) {
|
if(StringUtil.isNotEmpty(name) && StringUtil.isNotEmpty(model) && StringUtil.isNotEmpty(unit)) {
|
||||||
MaterialWithInitStock m = new MaterialWithInitStock();
|
MaterialWithInitStock m = new MaterialWithInitStock();
|
||||||
m.setName(name);
|
m.setName(name);
|
||||||
|
m.setStandard(standard);
|
||||||
m.setModel(model);
|
m.setModel(model);
|
||||||
|
m.setColor(color);
|
||||||
Long categoryId = materialCategoryService.getCategoryIdByName(categoryName);
|
Long categoryId = materialCategoryService.getCategoryIdByName(categoryName);
|
||||||
m.setCategoryid(categoryId);
|
m.setCategoryid(categoryId);
|
||||||
m.setSafetystock(parseBigDecimalEx(safetyStock));
|
m.setSafetystock(parseBigDecimalEx(safetyStock));
|
||||||
m.setColor(color);
|
m.setUnit(unit);
|
||||||
String manyUnit = ExcelUtils.getContent(src, i, 6); //多单位
|
String manyUnit = ExcelUtils.getContent(src, i, 7); //副单位
|
||||||
String ratio = ExcelUtils.getContent(src, i, 7); //比例
|
String barCode = ExcelUtils.getContent(src, i, 8); //基础条码
|
||||||
String retailPrice = ExcelUtils.getContent(src, i, 8); //零售价
|
String manyBarCode = ExcelUtils.getContent(src, i, 9); //副条码
|
||||||
String lowPrice = ExcelUtils.getContent(src, i, 9); //最低售价
|
String ratio = ExcelUtils.getContent(src, i, 10); //比例
|
||||||
String presetpriceone = ExcelUtils.getContent(src, i, 10); //预计采购价
|
String purchaseDecimal = ExcelUtils.getContent(src, i, 11); //采购价
|
||||||
String presetpricetwo = 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())){ //多单位
|
if(StringUtil.isNotEmpty(manyUnit.trim())){ //多单位
|
||||||
String manyUnitAll = unit + "," + manyUnit + "(1:" + ratio + ")";
|
String manyUnitAll = unit + "," + manyUnit + "(1:" + ratio + ")";
|
||||||
Long unitId = unitService.getUnitIdByName(manyUnitAll);
|
Long unitId = unitService.getUnitIdByName(manyUnitAll);
|
||||||
m.setUnitid(unitId);
|
m.setUnitid(unitId);
|
||||||
//m.setFirstoutunit(unit); //首选出库单位
|
|
||||||
//m.setFirstinunit(manyUnit); //首选入库单位
|
|
||||||
JSONArray arr = new JSONArray();
|
|
||||||
JSONObject basicObj = new JSONObject();
|
|
||||||
basicObj.put("Unit", unit);
|
|
||||||
basicObj.put("RetailPrice", retailPrice);
|
|
||||||
basicObj.put("LowPrice", lowPrice);
|
|
||||||
basicObj.put("PresetPriceOne", presetpriceone);
|
|
||||||
basicObj.put("PresetPriceTwo", presetpricetwo);
|
|
||||||
JSONObject basicObjEx = new JSONObject();
|
|
||||||
basicObjEx.put("basic", basicObj);
|
|
||||||
JSONObject otherObj = new JSONObject();
|
JSONObject otherObj = new JSONObject();
|
||||||
otherObj.put("Unit", manyUnit);
|
otherObj.put("barCode", manyBarCode);
|
||||||
otherObj.put("RetailPrice", parsePrice(retailPrice,ratio));
|
otherObj.put("commodityUnit", manyUnit);
|
||||||
otherObj.put("LowPrice", parsePrice(lowPrice,ratio));
|
otherObj.put("purchaseDecimal", parsePrice(purchaseDecimal,ratio));
|
||||||
otherObj.put("PresetPriceOne", parsePrice(presetpriceone,ratio));
|
otherObj.put("commodityDecimal", parsePrice(commodityDecimal,ratio));
|
||||||
otherObj.put("PresetPriceTwo", parsePrice(presetpricetwo,ratio));
|
otherObj.put("wholesaleDecimal", parsePrice(wholesaleDecimal,ratio));
|
||||||
JSONObject otherObjEx = new JSONObject();
|
otherObj.put("lowDecimal", parsePrice(lowDecimal,ratio));
|
||||||
otherObjEx.put("other", otherObj);
|
materialExObj.put("other", otherObj);
|
||||||
arr.add(basicObjEx);
|
|
||||||
arr.add(otherObjEx);
|
|
||||||
//m.setPricestrategy(arr.toJSONString());
|
|
||||||
} else {
|
|
||||||
m.setUnit(unit);
|
|
||||||
//m.setRetailprice(parseBigDecimalEx(retailPrice));
|
|
||||||
//m.setLowprice(parseBigDecimalEx(lowPrice));
|
|
||||||
//m.setPresetpriceone(parseBigDecimalEx(presetpriceone));
|
|
||||||
//m.setPresetpricetwo(parseBigDecimalEx(presetpricetwo));
|
|
||||||
}
|
}
|
||||||
String enabled = ExcelUtils.getContent(src, i, 12); //状态
|
m.setMaterialExObj(materialExObj);
|
||||||
|
String enabled = ExcelUtils.getContent(src, i, 15); //状态
|
||||||
m.setEnabled(enabled.equals("1")? true: false);
|
m.setEnabled(enabled.equals("1")? true: false);
|
||||||
//缓存各个仓库的库存信息
|
//缓存各个仓库的库存信息
|
||||||
Map<Long, BigDecimal> stockMap = new HashMap<Long, BigDecimal>();
|
Map<Long, BigDecimal> stockMap = new HashMap<Long, BigDecimal>();
|
||||||
for(int j=1; j<=depotCount;j++) {
|
for(int j=1; j<=depotCount;j++) {
|
||||||
int col = 12+j;
|
int col = 15+j;
|
||||||
if(col <= src.getColumns()){
|
if(col <= src.getColumns()){
|
||||||
String depotName = ExcelUtils.getContent(src, 1, col); //获取仓库名称
|
String depotName = ExcelUtils.getContent(src, 1, col); //获取仓库名称
|
||||||
Long depotId = depotService.getIdByName(depotName);
|
Long depotId = depotService.getIdByName(depotName);
|
||||||
@@ -468,6 +465,31 @@ public class MaterialService {
|
|||||||
material.setId(mId);
|
material.setId(mId);
|
||||||
materialMapper.updateByPrimaryKeySelective(material);
|
materialMapper.updateByPrimaryKeySelective(material);
|
||||||
}
|
}
|
||||||
|
//给商品新增条码与价格相关信息
|
||||||
|
User user = userService.getCurrentUser();
|
||||||
|
JSONObject materialExObj = m.getMaterialExObj();
|
||||||
|
if(StringUtil.isExist(materialExObj.get("basic"))){
|
||||||
|
String basicStr = materialExObj.getString("basic");
|
||||||
|
MaterialExtend basicMaterialExtend = JSONObject.parseObject(basicStr, MaterialExtend.class);
|
||||||
|
basicMaterialExtend.setMaterialId(mId);
|
||||||
|
basicMaterialExtend.setDefaultFlag("1");
|
||||||
|
basicMaterialExtend.setCreateTime(new Date());
|
||||||
|
basicMaterialExtend.setUpdateTime(new Date().getTime());
|
||||||
|
basicMaterialExtend.setCreateSerial(user.getLoginName());
|
||||||
|
basicMaterialExtend.setUpdateSerial(user.getLoginName());
|
||||||
|
materialExtendMapper.insertSelective(basicMaterialExtend);
|
||||||
|
}
|
||||||
|
if(StringUtil.isExist(materialExObj.get("other"))) {
|
||||||
|
String otherStr = materialExObj.getString("other");
|
||||||
|
MaterialExtend otherMaterialExtend = JSONObject.parseObject(otherStr, MaterialExtend.class);
|
||||||
|
otherMaterialExtend.setMaterialId(mId);
|
||||||
|
otherMaterialExtend.setDefaultFlag("0");
|
||||||
|
otherMaterialExtend.setCreateTime(new Date());
|
||||||
|
otherMaterialExtend.setUpdateTime(new Date().getTime());
|
||||||
|
otherMaterialExtend.setCreateSerial(user.getLoginName());
|
||||||
|
otherMaterialExtend.setUpdateSerial(user.getLoginName());
|
||||||
|
materialExtendMapper.insertSelective(otherMaterialExtend);
|
||||||
|
}
|
||||||
//给商品初始化库存
|
//给商品初始化库存
|
||||||
Map<Long, BigDecimal> stockMap = m.getStockMap();
|
Map<Long, BigDecimal> stockMap = m.getStockMap();
|
||||||
Long depotId = null;
|
Long depotId = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user