|
|
|
@ -46,33 +46,35 @@ public class SplitUnitServiceImpl implements SplitUnitService { |
|
|
|
|
|
|
|
/** |
|
|
|
* 用于添加一条拆单记录 |
|
|
|
* |
|
|
|
* @param map 待添加数据 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public Integer addSplitInfo(Map<String, Object> map) { |
|
|
|
// 查询该物料拆单前是否存在该计量单位
|
|
|
|
Map<String,Object> paramForUnit = new HashMap<>(); |
|
|
|
Map<String, Object> paramForUnit = new HashMap<>(); |
|
|
|
// 获取物料id
|
|
|
|
paramForUnit.put("mid",map.get("mid")); |
|
|
|
paramForUnit.put("mid", map.get("mid")); |
|
|
|
// 获取拆单前的计量单位
|
|
|
|
paramForUnit.put("oldUnit",map.get("oldUnit")); |
|
|
|
paramForUnit.put("newUnit", map.get("oldUnit")); |
|
|
|
// 查询当前要拆单的记录是否已经是拆单过的
|
|
|
|
SplitInfo splitInfoForUnit = splitUnitMapper.findSplitInfoByMidAndUnit(paramForUnit); |
|
|
|
if(splitInfoForUnit != null){ |
|
|
|
if (splitInfoForUnit != null) { |
|
|
|
// 如果是拆单过
|
|
|
|
map.put("parentId",splitInfoForUnit.getId()); |
|
|
|
}else{ |
|
|
|
map.put("parentId", splitInfoForUnit.getId()); |
|
|
|
} else { |
|
|
|
// 如果没有
|
|
|
|
map.put("parentId",null); |
|
|
|
map.put("parentId", null); |
|
|
|
} |
|
|
|
// 插入
|
|
|
|
map.put("state",1); |
|
|
|
map.put("state", 1); |
|
|
|
return splitUnitMapper.addSplitInfo(map); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 用于添加一条拆单库存处理记录 |
|
|
|
* |
|
|
|
* @param map 待添加数据 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@ -80,15 +82,21 @@ public class SplitUnitServiceImpl implements SplitUnitService { |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Integer addSplitInventory(Map<String, Object> map) { |
|
|
|
|
|
|
|
Map<String,Object> paramForSplitInfo = new HashMap<>(); |
|
|
|
paramForSplitInfo.put("mid",map.get("mid")); |
|
|
|
paramForSplitInfo.put("newUnit",map.get("unit")); |
|
|
|
Map<String, Object> paramForSplitInfo = new HashMap<>(); |
|
|
|
paramForSplitInfo.put("mid", map.get("mid")); |
|
|
|
paramForSplitInfo.put("newUnit", map.get("unit")); |
|
|
|
// 查询当前拆单是否存在
|
|
|
|
SplitInfo splitInfoForUnit = splitUnitMapper.findSplitInfoByMidAndUnit(paramForSplitInfo); |
|
|
|
|
|
|
|
|
|
|
|
// 用于存储最终计算结果
|
|
|
|
Integer result = 0; |
|
|
|
if(splitInfoForUnit != null) { |
|
|
|
if (splitInfoForUnit != null) { |
|
|
|
|
|
|
|
// 获取当前进制
|
|
|
|
// Integer scale = findSplitInfoQuantity(splitInfoForUnit);
|
|
|
|
Integer scale = findSplitInfoQuantity(splitInfoForUnit); |
|
|
|
|
|
|
|
// 获取当前处理的类型
|
|
|
|
String type = (String) map.get("type"); |
|
|
|
|
|
|
|
@ -100,25 +108,26 @@ public class SplitUnitServiceImpl implements SplitUnitService { |
|
|
|
// 定义对应的库存记录
|
|
|
|
Inventory inventory = null; |
|
|
|
// 用于存储拆单库存处理操作的数据
|
|
|
|
Map<String,Object> paramForInsertSplitInventory = new HashMap<>(); |
|
|
|
paramForInsertSplitInventory.put("sid",splitInfoForUnit.getId()); |
|
|
|
if(iid != null){ |
|
|
|
paramForInsertSplitInventory.put("iid",iid); |
|
|
|
Map<String, Object> paramForInsertSplitInventory = new HashMap<>(); |
|
|
|
paramForInsertSplitInventory.put("sid", splitInfoForUnit.getId()); |
|
|
|
if (iid != null) { |
|
|
|
paramForInsertSplitInventory.put("iid", iid); |
|
|
|
// 查询当前库存是否有该拆单的处理记录
|
|
|
|
splitInventory = splitUnitMapper.findSplitInventoryByIidAndSid(paramForInsertSplitInventory); |
|
|
|
// 获取对应的库存记录
|
|
|
|
inventory = materialMapper.findInventoryById(iid); |
|
|
|
} |
|
|
|
else{ |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
Map<String, Object> param = new HashMap<>(); |
|
|
|
param.put("depositoryId", map.get("depositoryId")); |
|
|
|
param.put("mid", map.get("mid")); |
|
|
|
// 判断该仓库中有无该物物料
|
|
|
|
List<Inventory> materialByCondition = materialMapper.findInventory(param); |
|
|
|
if(materialByCondition.size() > 0){ |
|
|
|
if (materialByCondition.size() > 0) { |
|
|
|
inventory = materialByCondition.get(0); |
|
|
|
|
|
|
|
paramForInsertSplitInventory.put("iid",inventory.getId()); |
|
|
|
paramForInsertSplitInventory.put("iid", inventory.getId()); |
|
|
|
|
|
|
|
// 查询当前库存是否有该拆单的处理记录
|
|
|
|
splitInventory = splitUnitMapper.findSplitInventoryByIidAndSid(paramForInsertSplitInventory); |
|
|
|
@ -131,71 +140,89 @@ public class SplitUnitServiceImpl implements SplitUnitService { |
|
|
|
// 如果是入库操作
|
|
|
|
|
|
|
|
// 计算处理数量(下取整)
|
|
|
|
int disposeQuantity = (int) Math.round(Math.floor(quantity / splitInfoForUnit.getQuantity())); |
|
|
|
int disposeQuantity = (int) Math.round(Math.floor(quantity / scale)); |
|
|
|
|
|
|
|
// 最终存储到拆单处理的数量
|
|
|
|
double saveQuantity = quantity - disposeQuantity * splitInfoForUnit.getQuantity(); |
|
|
|
if(splitInventory != null){ |
|
|
|
double saveQuantity = quantity - disposeQuantity * scale; |
|
|
|
if (splitInventory != null) { |
|
|
|
// 如果有过记录
|
|
|
|
|
|
|
|
// 最终存储数量
|
|
|
|
int realQuantity = (int) Math.round(saveQuantity) + splitInventory.getSaveQuantity(); |
|
|
|
|
|
|
|
if(realQuantity > splitInfoForUnit.getQuantity()){ |
|
|
|
if (realQuantity > scale) { |
|
|
|
// 如果当前入库的数量大于拆单规定的进制数量
|
|
|
|
int quantity_in = realQuantity - (realQuantity / splitInfoForUnit.getQuantity()); |
|
|
|
disposeQuantity += quantity_in; |
|
|
|
realQuantity = realQuantity - quantity_in * splitInfoForUnit.getQuantity(); |
|
|
|
int quantity_in = realQuantity - (realQuantity / scale); |
|
|
|
disposeQuantity += quantity_in; |
|
|
|
realQuantity = realQuantity - quantity_in * scale; |
|
|
|
} |
|
|
|
// 设置当前计量单位的库存
|
|
|
|
splitInventory.setSaveQuantity(realQuantity); |
|
|
|
// 设置当前计量单位的入库数目
|
|
|
|
if(splitInventory.getInQuantity() != null){ |
|
|
|
|
|
|
|
splitInventory.setInQuantity((int) Math.round(splitInventory.getInQuantity() + quantity)); |
|
|
|
}else{ |
|
|
|
splitInventory.setInQuantity((int)Math.round(quantity)); |
|
|
|
if (splitInventory.getInQuantity() != null) { |
|
|
|
// 如果当前库存不为空
|
|
|
|
splitInventory.setInQuantity((int) Math.round(splitInventory.getInQuantity() + quantity)); |
|
|
|
} else { |
|
|
|
splitInventory.setInQuantity((int) Math.round(quantity)); |
|
|
|
|
|
|
|
} |
|
|
|
splitUnitMapper.updateSplitInventory(splitInventory); |
|
|
|
|
|
|
|
if(disposeQuantity != 0) { |
|
|
|
if (disposeQuantity != 0) { |
|
|
|
// 用于更改库存的数量
|
|
|
|
map.put("quantity", String.valueOf(disposeQuantity)); |
|
|
|
|
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
map.put("quantity", "0"); |
|
|
|
} |
|
|
|
// 实际入库数量
|
|
|
|
map.put("realQuantity", quantity.toString()); |
|
|
|
result += depositoryRecordService.applicationInPlace(map); |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
// 如果没有记录
|
|
|
|
|
|
|
|
if(disposeQuantity != 0) { |
|
|
|
if (disposeQuantity != 0) { |
|
|
|
// 用于更改库存的数量
|
|
|
|
map.put("quantity", String.valueOf(disposeQuantity)); |
|
|
|
} |
|
|
|
else{ |
|
|
|
} else { |
|
|
|
map.put("quantity", "0"); |
|
|
|
} |
|
|
|
// 实际入库数量
|
|
|
|
map.put("realQuantity", quantity.toString()); |
|
|
|
result += depositoryRecordService.applicationInPlace(map); |
|
|
|
|
|
|
|
paramForInsertSplitInventory.put("inQuantity",quantity); |
|
|
|
paramForInsertSplitInventory.put("outQuantity",0); |
|
|
|
paramForInsertSplitInventory.put("saveQuantity",saveQuantity); |
|
|
|
paramForInsertSplitInventory.put("iid",map.get("newInMid")); |
|
|
|
paramForInsertSplitInventory.put("inQuantity", quantity); |
|
|
|
paramForInsertSplitInventory.put("outQuantity", 0); |
|
|
|
paramForInsertSplitInventory.put("saveQuantity", saveQuantity); |
|
|
|
paramForInsertSplitInventory.put("iid", map.get("newInMid")); |
|
|
|
splitUnitMapper.addSplitInventory(paramForInsertSplitInventory); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 用于计算当前拆单单位与基础单位之间的进率 |
|
|
|
* |
|
|
|
* @param splitInfo 待查询拆单记录 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private int findSplitInfoQuantity(SplitInfo splitInfo) { |
|
|
|
int quantity = 1; |
|
|
|
quantity *= splitInfo.getQuantity(); |
|
|
|
if (splitInfo.getParentId() != null) { |
|
|
|
SplitInfo splitInfoById = splitUnitMapper.findSplitInfoById(splitInfo.getParentId()); |
|
|
|
return quantity * findSplitInfoQuantity(splitInfoById); |
|
|
|
} else { |
|
|
|
return quantity; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据条件查询对应拆单详细信息 |
|
|
|
* |
|
|
|
* @param map 查询条件 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@ -211,15 +238,16 @@ public class SplitUnitServiceImpl implements SplitUnitService { |
|
|
|
map.put("begin", (page - 1) * size); |
|
|
|
} |
|
|
|
Object state = 1; |
|
|
|
if(map.containsKey("sstate")){ |
|
|
|
if (map.containsKey("sstate")) { |
|
|
|
state = map.get("sstate"); |
|
|
|
} |
|
|
|
map.put("sstate",state); |
|
|
|
map.put("sstate", state); |
|
|
|
return splitUnitMapper.findSplitInfoPByCondition(map); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据条件查询对应拆单数量 |
|
|
|
* |
|
|
|
* @param map 查询条件 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@ -230,6 +258,7 @@ public class SplitUnitServiceImpl implements SplitUnitService { |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据主键删除拆单信息(软删除) |
|
|
|
* |
|
|
|
* @param id 待删除id |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@ -244,17 +273,17 @@ public class SplitUnitServiceImpl implements SplitUnitService { |
|
|
|
for (SplitInventory splitInventory : |
|
|
|
splitInventoryList) { |
|
|
|
Integer saveQuantity = splitInventory.getSaveQuantity(); |
|
|
|
if(Integer.compare(saveQuantity,0) != 0){ |
|
|
|
if (Integer.compare(saveQuantity, 0) != 0) { |
|
|
|
// 如果当前记录的剩余库存不为0
|
|
|
|
flag = false; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
if(flag){ |
|
|
|
if (flag) { |
|
|
|
// 如果可以删除
|
|
|
|
splitInfo.setState(3); |
|
|
|
return splitUnitMapper.updateSplitInfo(splitInfo); |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
// 如果不可以
|
|
|
|
return -1; |
|
|
|
} |
|
|
|
@ -262,6 +291,7 @@ public class SplitUnitServiceImpl implements SplitUnitService { |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据主键删除拆单信息(硬删除) |
|
|
|
* |
|
|
|
* @param id 待删除id |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@ -276,16 +306,16 @@ public class SplitUnitServiceImpl implements SplitUnitService { |
|
|
|
for (SplitInventory splitInventory : |
|
|
|
splitInventoryList) { |
|
|
|
Integer saveQuantity = splitInventory.getSaveQuantity(); |
|
|
|
if(Integer.compare(saveQuantity,0) != 0){ |
|
|
|
if (Integer.compare(saveQuantity, 0) != 0) { |
|
|
|
// 如果当前记录的剩余库存不为0
|
|
|
|
flag = false; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
if(flag){ |
|
|
|
if (flag) { |
|
|
|
// 如果可以删除
|
|
|
|
return splitUnitMapper.delSplitInfoById(splitInfo.getId()); |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
// 如果不可以
|
|
|
|
return -1; |
|
|
|
} |
|
|
|
@ -293,6 +323,7 @@ public class SplitUnitServiceImpl implements SplitUnitService { |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据条件修改拆单信息 |
|
|
|
* |
|
|
|
* @param map 待修改数据 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@ -304,6 +335,7 @@ public class SplitUnitServiceImpl implements SplitUnitService { |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据主键id获取拆单信息 |
|
|
|
* |
|
|
|
* @param id 待查询主键 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@ -314,6 +346,7 @@ public class SplitUnitServiceImpl implements SplitUnitService { |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据主键id获取拆单详细信息 |
|
|
|
* |
|
|
|
* @param id 待查询主键 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@ -324,6 +357,7 @@ public class SplitUnitServiceImpl implements SplitUnitService { |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据物料id查询对应的拆单记录 |
|
|
|
* |
|
|
|
* @param mid 待查询物料id |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@ -335,6 +369,7 @@ public class SplitUnitServiceImpl implements SplitUnitService { |
|
|
|
|
|
|
|
/** |
|
|
|
* 通过物料id与拆单前的计量单位获取对应拆单记录 |
|
|
|
* |
|
|
|
* @param map 查询条件 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@ -345,6 +380,7 @@ public class SplitUnitServiceImpl implements SplitUnitService { |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据库存id获取对应拆单库存处理记录 |
|
|
|
* |
|
|
|
* @param Iid 待查询库存id |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
|