|
|
|
@ -147,7 +147,7 @@ public class SplitUnitServiceImpl implements SplitUnitService { |
|
|
|
// 如果当前入库的数量大于拆单规定的进制数量
|
|
|
|
|
|
|
|
// 计算要进的数目
|
|
|
|
int quantity_in = (realQuantity / scale) ; |
|
|
|
int quantity_in = (realQuantity / scale); |
|
|
|
// 更新处理数量
|
|
|
|
disposeQuantity += quantity_in; |
|
|
|
// 拆单库存实际入库的数量
|
|
|
|
@ -176,17 +176,16 @@ public class SplitUnitServiceImpl implements SplitUnitService { |
|
|
|
map.put("realQuantity", quantity.toString()); |
|
|
|
if (splitInfoForUnit.getParentId() != null) { |
|
|
|
SplitInfo parentSplitInfo = splitUnitMapper.findSplitInfoById(splitInfoForUnit.getParentId()); |
|
|
|
updateSplitInfoSaveQuantity(parentSplitInfo, disposeQuantity, inventory.getId(), map,quantity.intValue()); |
|
|
|
updateSplitInfoSaveQuantity(parentSplitInfo, disposeQuantity, inventory.getId(), map, quantity.intValue()); |
|
|
|
} else { |
|
|
|
Double price = Double.parseDouble((String) map.get("price")); |
|
|
|
price = price * findSplitInfoQuantity(splitInfoForUnit); |
|
|
|
map.put("price",price.toString()); |
|
|
|
price = price * findSplitInfoScaleQuantity(splitInfoForUnit, -1); |
|
|
|
map.put("price", price.toString()); |
|
|
|
depositoryRecordService.applicationInPlace(map); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
else { |
|
|
|
} else { |
|
|
|
// 如果没有记录
|
|
|
|
|
|
|
|
// 获取当前拆单记录的父级
|
|
|
|
@ -211,18 +210,18 @@ public class SplitUnitServiceImpl implements SplitUnitService { |
|
|
|
|
|
|
|
SplitInfo parentSplitInfo = splitUnitMapper.findSplitInfoById(parentId); |
|
|
|
if (inventory != null) { |
|
|
|
updateSplitInfoSaveQuantity(parentSplitInfo, ObjectFormatUtil.toInteger(String.valueOf(saveQuantity)), inventory.getId(), map,quantity.intValue()); |
|
|
|
updateSplitInfoSaveQuantity(parentSplitInfo, ObjectFormatUtil.toInteger(String.valueOf(saveQuantity)), inventory.getId(), map, quantity.intValue()); |
|
|
|
} else { |
|
|
|
Double price = Double.parseDouble((String) map.get("price")); |
|
|
|
price = price * findSplitInfoQuantity(splitInfoForUnit); |
|
|
|
map.put("price",price.toString()); |
|
|
|
price = price * findSplitInfoScaleQuantity(splitInfoForUnit, -1); |
|
|
|
map.put("price", price.toString()); |
|
|
|
result += depositoryRecordService.applicationInPlace(map); |
|
|
|
updateSplitInfoSaveQuantity(parentSplitInfo, ObjectFormatUtil.toInteger(String.valueOf(saveQuantity)), ObjectFormatUtil.toInteger(map.get("newInMid")), map,quantity.intValue()); |
|
|
|
updateSplitInfoSaveQuantity(parentSplitInfo, ObjectFormatUtil.toInteger(String.valueOf(saveQuantity)), ObjectFormatUtil.toInteger(map.get("newInMid")), map, quantity.intValue()); |
|
|
|
} |
|
|
|
} else { |
|
|
|
Double price = Double.parseDouble((String) map.get("price")); |
|
|
|
price = price * findSplitInfoQuantity(splitInfoForUnit); |
|
|
|
map.put("price",price.toString()); |
|
|
|
price = price * findSplitInfoScaleQuantity(splitInfoForUnit, -1); |
|
|
|
map.put("price", price.toString()); |
|
|
|
result += depositoryRecordService.applicationInPlace(map); |
|
|
|
} |
|
|
|
} else { |
|
|
|
@ -240,19 +239,18 @@ public class SplitUnitServiceImpl implements SplitUnitService { |
|
|
|
|
|
|
|
// 插入一条库存记录
|
|
|
|
Double price = Double.parseDouble((String) map.get("price")); |
|
|
|
price = price * findSplitInfoQuantity(splitInfoForUnit); |
|
|
|
map.put("price",price.toString()); |
|
|
|
price = price * findSplitInfoScaleQuantity(splitInfoForUnit, -1); |
|
|
|
map.put("price", price.toString()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(parentId != null){ |
|
|
|
if (parentId != null) { |
|
|
|
// 如果有父级
|
|
|
|
|
|
|
|
// 先插入一条库存记录用于后续操作
|
|
|
|
map.put("quantity","0"); |
|
|
|
map.put("quantity", "0"); |
|
|
|
result += depositoryRecordService.applicationInPlace(map); |
|
|
|
|
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
// 如果没有父级
|
|
|
|
result += depositoryRecordService.applicationInPlace(map); |
|
|
|
} |
|
|
|
@ -261,10 +259,10 @@ public class SplitUnitServiceImpl implements SplitUnitService { |
|
|
|
} |
|
|
|
|
|
|
|
splitUnitMapper.addSplitInventory(paramForInsertSplitInventory); |
|
|
|
if(parentId != null){ |
|
|
|
if (parentId != null) { |
|
|
|
// 获取父级
|
|
|
|
SplitInfo parentSplitInfo = splitUnitMapper.findSplitInfoById(splitInfoForUnit.getParentId()); |
|
|
|
updateSplitInfoSaveQuantity(parentSplitInfo,disposeQuantity,ObjectFormatUtil.toInteger(map.get("newInMid")),map,quantity.intValue()); |
|
|
|
updateSplitInfoSaveQuantity(parentSplitInfo, disposeQuantity, ObjectFormatUtil.toInteger(map.get("newInMid")), map, quantity.intValue()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -278,39 +276,171 @@ public class SplitUnitServiceImpl implements SplitUnitService { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 用于计算当前拆单单位与基础单位之间的进率 |
|
|
|
* |
|
|
|
* 用于计算当前拆单单位与目标拆单单位之间的进率 |
|
|
|
* @param splitInfo 待查询拆单记录 |
|
|
|
* @param parentSplitInfoId 目标拆单单位 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public int findSplitInfoQuantity(SplitInfo splitInfo) { |
|
|
|
int quantity = 1; |
|
|
|
public int findSplitInfoScaleQuantity(SplitInfo splitInfo, Integer parentSplitInfoId) { |
|
|
|
int quantity = 1; // 定义进制
|
|
|
|
quantity *= splitInfo.getQuantity(); |
|
|
|
if(parentSplitInfoId != null && Integer.compare(-1,parentSplitInfoId) != 0){ |
|
|
|
// 如果待查询的父级不是顶级
|
|
|
|
if(Integer.compare(splitInfo.getId(),parentSplitInfoId) == 0){ |
|
|
|
// 如果当前拆单记录是目标拆单单位
|
|
|
|
return quantity; |
|
|
|
}else{ |
|
|
|
SplitInfo splitInfoById = splitUnitMapper.findSplitInfoById(splitInfo.getParentId()); |
|
|
|
return quantity * findSplitInfoScaleQuantity(splitInfoById,parentSplitInfoId); |
|
|
|
} |
|
|
|
}else { |
|
|
|
if (splitInfo.getParentId() != null) { |
|
|
|
SplitInfo splitInfoById = splitUnitMapper.findSplitInfoById(splitInfo.getParentId()); |
|
|
|
return quantity * findSplitInfoQuantity(splitInfoById); |
|
|
|
return quantity * findSplitInfoScaleQuantity(splitInfoById, parentSplitInfoId); |
|
|
|
} else { |
|
|
|
return quantity; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 获取当前拆单与基础拆单之间的库存总额(当前拆单记录为-1是全部库存是使用) |
|
|
|
* |
|
|
|
* @param splitInfoId 当前拆单记录Id |
|
|
|
* @param inventory 库存记录 |
|
|
|
* @param baseSplitInfoId 基础拆单记录Id |
|
|
|
* @param saveQuantity 最终返回值 |
|
|
|
* @param allQuantityFlag 用于标志是否获取全部库存 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public int findAllInventoryForSplitInfo(Integer splitInfoId, Inventory inventory, Integer baseSplitInfoId, int saveQuantity, boolean allQuantityFlag) { |
|
|
|
if (allQuantityFlag) { |
|
|
|
|
|
|
|
// 用于标志是否第一次计算
|
|
|
|
boolean flag = false; |
|
|
|
|
|
|
|
// 获取当前基础单位
|
|
|
|
SplitInfo baseSplitInfo = splitUnitMapper.findSplitInfoById(baseSplitInfoId); |
|
|
|
|
|
|
|
// 获取当前基础单位的库存
|
|
|
|
Map<String, Object> paramForSplitInventory = new HashMap<>(); |
|
|
|
paramForSplitInventory.put("iid", inventory.getId()); |
|
|
|
|
|
|
|
// 如果当前获取的为对应基础单位的所有库存
|
|
|
|
// 如果是第一次计算
|
|
|
|
|
|
|
|
if (Integer.compare(saveQuantity, 0) == 0) { |
|
|
|
// 如果是第一次计算
|
|
|
|
|
|
|
|
|
|
|
|
paramForSplitInventory.put("sid", baseSplitInfoId); |
|
|
|
|
|
|
|
// 当前基础单位的库存
|
|
|
|
SplitInventory baseSplitInventory = splitUnitMapper.findSplitInventoryByIidAndSid(paramForSplitInventory); |
|
|
|
if(baseSplitInventory != null) { |
|
|
|
saveQuantity += baseSplitInventory.getSaveQuantity(); |
|
|
|
} |
|
|
|
} |
|
|
|
if(Integer.compare(-1,splitInfoId) != 0){ |
|
|
|
flag = true; |
|
|
|
// 获取当前记录的子记录
|
|
|
|
SplitInfo splitInfoByParentId = splitUnitMapper.findSplitInfoByParentId(splitInfoId); |
|
|
|
paramForSplitInventory.put("sid",splitInfoId); |
|
|
|
SplitInventory splitInventoryByIidAndSid = splitUnitMapper.findSplitInventoryByIidAndSid(paramForSplitInventory); |
|
|
|
if(splitInventoryByIidAndSid != null){ |
|
|
|
saveQuantity += splitInventoryByIidAndSid.getSaveQuantity() * splitInfoByParentId.getQuantity(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(baseSplitInfo.getParentId() != null && !flag){ |
|
|
|
// 如果有父级且是第一次
|
|
|
|
|
|
|
|
// 获取其父级
|
|
|
|
SplitInfo parentSplitInfo = splitUnitMapper.findSplitInfoById(baseSplitInfo.getParentId()); |
|
|
|
return findAllInventoryForSplitInfo(parentSplitInfo.getId(),inventory,baseSplitInfoId,saveQuantity,allQuantityFlag); |
|
|
|
}else{ |
|
|
|
if(flag){ |
|
|
|
// 如果不是第一次
|
|
|
|
|
|
|
|
// 获取当前的拆单记录
|
|
|
|
SplitInfo splitInfo = splitUnitMapper.findSplitInfoById(splitInfoId); |
|
|
|
if(splitInfo.getParentId() != null){ |
|
|
|
SplitInfo parentSplitInfo = splitUnitMapper.findSplitInfoById(splitInfo.getParentId()); |
|
|
|
return findAllInventoryForSplitInfo(parentSplitInfo.getId(),inventory,baseSplitInfoId,saveQuantity,allQuantityFlag); |
|
|
|
}else{ |
|
|
|
int splitInfoScaleQuantity = findSplitInfoScaleQuantity(baseSplitInfo, -1); |
|
|
|
return saveQuantity + inventory.getQuantity() * splitInfoScaleQuantity; |
|
|
|
} |
|
|
|
|
|
|
|
}else{ |
|
|
|
int splitInfoScaleQuantity = findSplitInfoScaleQuantity(baseSplitInfo, -1); |
|
|
|
return saveQuantity + inventory.getQuantity() * splitInfoScaleQuantity; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
else { |
|
|
|
// 如果不是获取所有库存
|
|
|
|
// 获取当前基础单位
|
|
|
|
SplitInfo baseSplitInfo = splitUnitMapper.findSplitInfoById(baseSplitInfoId); |
|
|
|
|
|
|
|
// 获取当前基础单位的库存
|
|
|
|
Map<String, Object> paramForSplitInventory = new HashMap<>(); |
|
|
|
paramForSplitInventory.put("iid", inventory.getId()); |
|
|
|
|
|
|
|
// 如果当前获取的为对应基础单位的所有库存
|
|
|
|
if (Integer.compare(saveQuantity, 0) == 0) { |
|
|
|
// 如果是第一次计算
|
|
|
|
|
|
|
|
paramForSplitInventory.put("sid", baseSplitInfoId); |
|
|
|
|
|
|
|
// 当前基础单位的库存
|
|
|
|
SplitInventory baseSplitInventory = splitUnitMapper.findSplitInventoryByIidAndSid(paramForSplitInventory); |
|
|
|
saveQuantity += baseSplitInventory.getSaveQuantity(); |
|
|
|
} |
|
|
|
// 获取当前拆单记录与基础拆单记录之间的进制
|
|
|
|
|
|
|
|
int splitInfoScaleQuantity = findSplitInfoScaleQuantity(baseSplitInfo, splitInfoId); |
|
|
|
paramForSplitInventory.put("sid", splitInfoId); |
|
|
|
// 获取当前拆单记录的库存
|
|
|
|
SplitInventory splitInventory = splitUnitMapper.findSplitInventoryByIidAndSid(paramForSplitInventory); |
|
|
|
saveQuantity += splitInventory.getSaveQuantity() * splitInfoScaleQuantity; |
|
|
|
|
|
|
|
// 获取当前的子类
|
|
|
|
SplitInfo splitInfoByParentId = splitUnitMapper.findSplitInfoByParentId(splitInfoId); |
|
|
|
if (splitInfoByParentId != null && Integer.compare(splitInfoByParentId.getId(),baseSplitInfoId) != 0) { |
|
|
|
// 如果有子类
|
|
|
|
return findAllInventoryForSplitInfo(splitInfoByParentId.getId(), inventory, baseSplitInfoId, saveQuantity, allQuantityFlag); |
|
|
|
} else { |
|
|
|
// 如果没有
|
|
|
|
return saveQuantity; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据库存id与拆单记录id获取对应拆单库存处理记录 |
|
|
|
* |
|
|
|
* @param Iid 待查询库存id |
|
|
|
* @param sid 待查询拆单id |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public SplitInventory findSplitInventoryByIidAndSid(Integer Iid, Integer sid) { |
|
|
|
Map<String,Object> param = new HashMap<>(); |
|
|
|
param.put("iid",Iid); |
|
|
|
param.put("sid",sid); |
|
|
|
Map<String, Object> param = new HashMap<>(); |
|
|
|
param.put("iid", Iid); |
|
|
|
param.put("sid", sid); |
|
|
|
|
|
|
|
return splitUnitMapper.findSplitInventoryByIidAndSid(param); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据父级查询拆单记录 |
|
|
|
* |
|
|
|
* @param parentId 待查询父级 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@ -321,12 +451,13 @@ public class SplitUnitServiceImpl implements SplitUnitService { |
|
|
|
|
|
|
|
/** |
|
|
|
* 用于拆单库存处理记录的修改 |
|
|
|
* |
|
|
|
* @param splitInfo 对应拆单记录 |
|
|
|
* @param quantity 修改数目 |
|
|
|
* @param map 入库条件 |
|
|
|
* @param inQuantity 最终入库数量 |
|
|
|
*/ |
|
|
|
private void updateSplitInfoSaveQuantity(SplitInfo splitInfo, int quantity, int iid, Map<String, Object> map,int inQuantity) { |
|
|
|
private void updateSplitInfoSaveQuantity(SplitInfo splitInfo, int quantity, int iid, Map<String, Object> map, int inQuantity) { |
|
|
|
|
|
|
|
int result = 0; |
|
|
|
|
|
|
|
@ -374,33 +505,31 @@ public class SplitUnitServiceImpl implements SplitUnitService { |
|
|
|
// 获取具体父级
|
|
|
|
SplitInfo splitInfoForParent = splitUnitMapper.findSplitInfoById(parentId); |
|
|
|
|
|
|
|
updateSplitInfoSaveQuantity(splitInfoForParent, disposeQuantity, splitInventory.getIid(), map,inQuantity); |
|
|
|
updateSplitInfoSaveQuantity(splitInfoForParent, disposeQuantity, splitInventory.getIid(), map, inQuantity); |
|
|
|
} else { |
|
|
|
// 如果为空
|
|
|
|
Double price = Double.parseDouble((String) map.get("price")); |
|
|
|
price = price * findSplitInfoQuantity(splitInfo); |
|
|
|
map.put("price",price.toString()); |
|
|
|
price = price * findSplitInfoScaleQuantity(splitInfo, -1); |
|
|
|
map.put("price", price.toString()); |
|
|
|
map.put("quantity", String.valueOf(disposeQuantity)); |
|
|
|
map.put("realQuantity", String.valueOf(inQuantity)); |
|
|
|
|
|
|
|
depositoryRecordService.applicationInPlace(map); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
} else { |
|
|
|
// 当前库存拆单记录与新入库的数目不大于预设的进制
|
|
|
|
splitInventory.setSaveQuantity(splitInventory.getSaveQuantity() + disposeQuantity); |
|
|
|
splitInventory.setInQuantity(splitInventory.getInQuantity() + disposeQuantity); |
|
|
|
splitUnitMapper.updateSplitInventory(splitInventory); |
|
|
|
|
|
|
|
Double price = Double.parseDouble((String) map.get("price")); |
|
|
|
price = price * findSplitInfoQuantity(splitInfo); |
|
|
|
map.put("price",price.toString()); |
|
|
|
price = price * findSplitInfoScaleQuantity(splitInfo, -1); |
|
|
|
map.put("price", price.toString()); |
|
|
|
map.put("quantity", "0"); |
|
|
|
map.put("realQuantity", String.valueOf(inQuantity)); |
|
|
|
depositoryRecordService.applicationInPlace(map); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
} else { |
|
|
|
|
|
|
|
// 如果为空
|
|
|
|
Map<String, Object> paramForInsertSplitInventory = new HashMap<>(); |
|
|
|
@ -425,11 +554,11 @@ public class SplitUnitServiceImpl implements SplitUnitService { |
|
|
|
// 获取当前拆单记录的父级
|
|
|
|
SplitInfo parentSplitInfo = splitUnitMapper.findSplitInfoById(parentId); |
|
|
|
|
|
|
|
updateSplitInfoSaveQuantity(parentSplitInfo, quantity_scale, iid, map,inQuantity); |
|
|
|
updateSplitInfoSaveQuantity(parentSplitInfo, quantity_scale, iid, map, inQuantity); |
|
|
|
} else { |
|
|
|
Double price = Double.parseDouble((String) map.get("price")); |
|
|
|
price = price * findSplitInfoQuantity(splitInfo); |
|
|
|
map.put("price",price.toString()); |
|
|
|
price = price * findSplitInfoScaleQuantity(splitInfo, -1); |
|
|
|
map.put("price", price.toString()); |
|
|
|
map.put("quantity", String.valueOf(quantity_scale)); |
|
|
|
map.put("realQuantity", String.valueOf(inQuantity)); |
|
|
|
depositoryRecordService.applicationInPlace(map); |
|
|
|
|