解决多单位商品导入的bug

This commit is contained in:
季圣华
2021-12-03 21:52:53 +08:00
parent 4bb9140426
commit 3e2bbd0a1b
7 changed files with 32 additions and 23 deletions

View File

@@ -382,7 +382,7 @@ public class DepotItemService {
Unit unitInfo = materialService.findUnit(materialExtend.getMaterialId()); //查询计量单位信息
if (StringUtil.isNotEmpty(unitInfo.getName())) {
String basicUnit = unitInfo.getBasicUnit(); //基本单位
if (unit.equals(basicUnit)) { //如果等于基单位
if (unit.equals(basicUnit)) { //如果等于基单位
depotItem.setBasicNumber(oNumber); //数量一致
} else if (unit.equals(unitInfo.getOtherUnit())) { //如果等于副单位
depotItem.setBasicNumber(oNumber.multiply(new BigDecimal(unitInfo.getRatio())) ); //数量乘以比例

View File

@@ -472,7 +472,7 @@ public class MaterialService {
String color = ExcelUtils.getContent(src, i, 3); //颜色
String categoryName = ExcelUtils.getContent(src, i, 4); //类别
String expiryNum = ExcelUtils.getContent(src, i, 5); //保质期
String unit = ExcelUtils.getContent(src, i, 6); //基单位
String unit = ExcelUtils.getContent(src, i, 6); //基单位
//校验名称、单位是否为空
if(StringUtil.isNotEmpty(name) && StringUtil.isNotEmpty(unit)) {
MaterialWithInitStock m = new MaterialWithInitStock();
@@ -516,14 +516,13 @@ public class MaterialService {
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(StringUtil.isNotEmpty(manyUnit) && StringUtil.isNotEmpty(ratio)){ //多单位
Long unitId = unitService.getUnitIdByParam(unit, manyUnit, Integer.parseInt(ratio.trim()));
if(unitId != null) {
m.setUnitId(unitId);
} else {
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_UNIT_MATE_CODE,
String.format(ExceptionConstants.MATERIAL_UNIT_MATE_MSG));
String.format(ExceptionConstants.MATERIAL_UNIT_MATE_MSG, manyBarCode));
}
JSONObject otherObj = new JSONObject();
otherObj.put("barCode", manyBarCode);
@@ -544,11 +543,13 @@ public class MaterialService {
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));
if(StringUtil.isNotEmpty(depotName)) {
Long depotId = depotService.getIdByName(depotName);
if(depotId!=0L){
String stockStr = ExcelUtils.getContent(src, i, col);
if(StringUtil.isNotEmpty(stockStr)) {
stockMap.put(depotId, parseBigDecimalEx(stockStr));
}
}
}
}

View File

@@ -192,7 +192,7 @@ public class MaterialExtendService {
this.updateMaterialExtend(materialExtend);
}
}
//处理条码的排序,基单位排第一个
//处理条码的排序,基单位排第一个
if (null != sortJson && sortJson.size()>0) {
//此处为更新的逻辑
for (int i = 0; i < sortJson.size(); i++) {
@@ -207,7 +207,7 @@ public class MaterialExtendService {
this.updateMaterialExtend(materialExtend);
}
} else {
//新增的时候将第一条记录设置为默认基单位
//新增的时候将第一条记录设置为默认基单位
MaterialExtendExample example = new MaterialExtendExample();
example.createCriteria().andMaterialIdEqualTo(materialId).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<MaterialExtend> meList = materialExtendMapper.selectByExample(example);

View File

@@ -208,13 +208,17 @@ public class UnitService {
}
/**
* 根据名称获取类型
* @param name
* 根据条件查询单位id
* @param basicUnit
* @param otherUnit
* @param ratio
* @return
*/
public Long getUnitIdByName(String name){
public Long getUnitIdByParam(String basicUnit, String otherUnit, Integer ratio){
Long unitId = null;
UnitExample example = new UnitExample();
example.createCriteria().andNameEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
example.createCriteria().andBasicUnitEqualTo(basicUnit).andOtherUnitEqualTo(otherUnit).andRatioEqualTo(ratio)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<Unit> list = unitMapper.selectByExample(example);
if(list!=null && list.size()>0) {
unitId = list.get(0).getId();