|
|
|
@ -1,16 +1,11 @@ |
|
|
|
package com.dreamchaser.depository_manage.service.impl; |
|
|
|
|
|
|
|
import com.dreamchaser.depository_manage.entity.Inventory; |
|
|
|
import com.dreamchaser.depository_manage.entity.SplitInfo; |
|
|
|
import com.dreamchaser.depository_manage.entity.SplitInventory; |
|
|
|
import com.dreamchaser.depository_manage.exception.MyException; |
|
|
|
import com.dreamchaser.depository_manage.entity.*; |
|
|
|
import com.dreamchaser.depository_manage.mapper.*; |
|
|
|
import com.dreamchaser.depository_manage.pojo.SplitInfoP; |
|
|
|
import com.dreamchaser.depository_manage.service.DepositoryRecordService; |
|
|
|
import com.dreamchaser.depository_manage.service.MaterialService; |
|
|
|
import com.dreamchaser.depository_manage.service.SplitUnitService; |
|
|
|
import com.dreamchaser.depository_manage.utils.ObjectFormatUtil; |
|
|
|
import com.sun.mail.imap.protocol.ID; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
@ -91,11 +86,10 @@ public class SplitUnitServiceImpl implements SplitUnitService { |
|
|
|
|
|
|
|
// 用于存储最终计算结果
|
|
|
|
Integer result = 0; |
|
|
|
if (splitInfoForUnit != null) { |
|
|
|
|
|
|
|
if (splitInfoForUnit != null) { |
|
|
|
// 获取当前进制
|
|
|
|
// Integer scale = findSplitInfoQuantity(splitInfoForUnit);
|
|
|
|
Integer scale = findSplitInfoQuantity(splitInfoForUnit); |
|
|
|
Integer scale = splitInfoForUnit.getQuantity(); |
|
|
|
|
|
|
|
// 获取当前处理的类型
|
|
|
|
String type = (String) map.get("type"); |
|
|
|
@ -117,15 +111,14 @@ public class SplitUnitServiceImpl implements SplitUnitService { |
|
|
|
// 获取对应的库存记录
|
|
|
|
inventory = materialMapper.findInventoryById(iid); |
|
|
|
|
|
|
|
|
|
|
|
} 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) { |
|
|
|
inventory = materialByCondition.get(0); |
|
|
|
List<Inventory> inventoryList = materialMapper.findInventory(param); |
|
|
|
if (inventoryList.size() > 0) { |
|
|
|
inventory = inventoryList.get(0); |
|
|
|
|
|
|
|
paramForInsertSplitInventory.put("iid", inventory.getId()); |
|
|
|
|
|
|
|
@ -144,15 +137,20 @@ public class SplitUnitServiceImpl implements SplitUnitService { |
|
|
|
|
|
|
|
// 最终存储到拆单处理的数量
|
|
|
|
double saveQuantity = quantity - disposeQuantity * scale; |
|
|
|
|
|
|
|
if (splitInventory != null) { |
|
|
|
// 如果有过记录
|
|
|
|
|
|
|
|
// 最终存储数量
|
|
|
|
int realQuantity = (int) Math.round(saveQuantity) + splitInventory.getSaveQuantity(); |
|
|
|
if (realQuantity > scale) { |
|
|
|
if (realQuantity >= scale) { |
|
|
|
// 如果当前入库的数量大于拆单规定的进制数量
|
|
|
|
int quantity_in = realQuantity - (realQuantity / scale); |
|
|
|
|
|
|
|
// 计算要进的数目
|
|
|
|
int quantity_in = (realQuantity / scale) ; |
|
|
|
// 更新处理数量
|
|
|
|
disposeQuantity += quantity_in; |
|
|
|
// 拆单库存实际入库的数量
|
|
|
|
realQuantity = realQuantity - quantity_in * scale; |
|
|
|
} |
|
|
|
// 设置当前计量单位的库存
|
|
|
|
@ -165,7 +163,7 @@ public class SplitUnitServiceImpl implements SplitUnitService { |
|
|
|
splitInventory.setInQuantity((int) Math.round(quantity)); |
|
|
|
|
|
|
|
} |
|
|
|
splitUnitMapper.updateSplitInventory(splitInventory); |
|
|
|
result += splitUnitMapper.updateSplitInventory(splitInventory); |
|
|
|
|
|
|
|
if (disposeQuantity != 0) { |
|
|
|
// 用于更改库存的数量
|
|
|
|
@ -176,25 +174,101 @@ public class SplitUnitServiceImpl implements SplitUnitService { |
|
|
|
} |
|
|
|
// 实际入库数量
|
|
|
|
map.put("realQuantity", quantity.toString()); |
|
|
|
result += depositoryRecordService.applicationInPlace(map); |
|
|
|
if (splitInfoForUnit.getParentId() != null) { |
|
|
|
SplitInfo parentSplitInfo = splitUnitMapper.findSplitInfoById(splitInfoForUnit.getParentId()); |
|
|
|
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()); |
|
|
|
depositoryRecordService.applicationInPlace(map); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
else { |
|
|
|
// 如果没有记录
|
|
|
|
|
|
|
|
// 获取当前拆单记录的父级
|
|
|
|
Integer parentId = splitInfoForUnit.getParentId(); |
|
|
|
|
|
|
|
if (disposeQuantity != 0) { |
|
|
|
// 用于更改库存的数量
|
|
|
|
map.put("quantity", String.valueOf(disposeQuantity)); |
|
|
|
} else { |
|
|
|
map.put("quantity", "0"); |
|
|
|
} |
|
|
|
|
|
|
|
if (disposeQuantity > splitInfoForUnit.getQuantity()) { |
|
|
|
//如果当前处理数量大于设置的进制数量
|
|
|
|
|
|
|
|
// 实际入库数量
|
|
|
|
map.put("realQuantity", quantity.toString()); |
|
|
|
|
|
|
|
|
|
|
|
if (parentId != null) { |
|
|
|
// 如果该记录有父级拆单
|
|
|
|
|
|
|
|
SplitInfo parentSplitInfo = splitUnitMapper.findSplitInfoById(parentId); |
|
|
|
if (inventory != null) { |
|
|
|
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()); |
|
|
|
result += depositoryRecordService.applicationInPlace(map); |
|
|
|
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()); |
|
|
|
result += depositoryRecordService.applicationInPlace(map); |
|
|
|
} |
|
|
|
} else { |
|
|
|
// 如果不大于设置的进制数量
|
|
|
|
|
|
|
|
paramForInsertSplitInventory.put("inQuantity", quantity); |
|
|
|
paramForInsertSplitInventory.put("outQuantity", 0); |
|
|
|
paramForInsertSplitInventory.put("saveQuantity", saveQuantity); |
|
|
|
|
|
|
|
if (inventory != null) { |
|
|
|
// 如果有库存记录
|
|
|
|
paramForInsertSplitInventory.put("iid", inventory.getId()); |
|
|
|
} else { |
|
|
|
// 如果没有库存记录
|
|
|
|
|
|
|
|
// 插入一条库存记录
|
|
|
|
Double price = Double.parseDouble((String) map.get("price")); |
|
|
|
price = price * findSplitInfoQuantity(splitInfoForUnit); |
|
|
|
map.put("price",price.toString()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(parentId != null){ |
|
|
|
// 如果有父级
|
|
|
|
|
|
|
|
// 先插入一条库存记录用于后续操作
|
|
|
|
map.put("quantity","0"); |
|
|
|
result += depositoryRecordService.applicationInPlace(map); |
|
|
|
|
|
|
|
}else{ |
|
|
|
// 如果没有父级
|
|
|
|
result += depositoryRecordService.applicationInPlace(map); |
|
|
|
} |
|
|
|
|
|
|
|
paramForInsertSplitInventory.put("iid", map.get("newInMid")); |
|
|
|
} |
|
|
|
|
|
|
|
splitUnitMapper.addSplitInventory(paramForInsertSplitInventory); |
|
|
|
if(parentId != null){ |
|
|
|
// 获取父级
|
|
|
|
SplitInfo parentSplitInfo = splitUnitMapper.findSplitInfoById(splitInfoForUnit.getParentId()); |
|
|
|
updateSplitInfoSaveQuantity(parentSplitInfo,disposeQuantity,ObjectFormatUtil.toInteger(map.get("newInMid")),map,quantity.intValue()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -209,7 +283,7 @@ public class SplitUnitServiceImpl implements SplitUnitService { |
|
|
|
* @param splitInfo 待查询拆单记录 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private int findSplitInfoQuantity(SplitInfo splitInfo) { |
|
|
|
public int findSplitInfoQuantity(SplitInfo splitInfo) { |
|
|
|
int quantity = 1; |
|
|
|
quantity *= splitInfo.getQuantity(); |
|
|
|
if (splitInfo.getParentId() != null) { |
|
|
|
@ -220,6 +294,158 @@ public class SplitUnitServiceImpl implements SplitUnitService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据库存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); |
|
|
|
|
|
|
|
return splitUnitMapper.findSplitInventoryByIidAndSid(param); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据父级查询拆单记录 |
|
|
|
* @param parentId 待查询父级 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public SplitInfo findSplitInfoByParentId(Integer parentId) { |
|
|
|
return splitUnitMapper.findSplitInfoByParentId(parentId); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 用于拆单库存处理记录的修改 |
|
|
|
* @param splitInfo 对应拆单记录 |
|
|
|
* @param quantity 修改数目 |
|
|
|
* @param map 入库条件 |
|
|
|
* @param inQuantity 最终入库数量 |
|
|
|
*/ |
|
|
|
private void updateSplitInfoSaveQuantity(SplitInfo splitInfo, int quantity, int iid, Map<String, Object> map,int inQuantity) { |
|
|
|
|
|
|
|
int result = 0; |
|
|
|
|
|
|
|
// 获取当前拆单记录的父级拆单记录
|
|
|
|
Integer parentId = splitInfo.getParentId(); |
|
|
|
|
|
|
|
// 获取当前拆单记录对应的拆开库存处理记录
|
|
|
|
Map<String, Object> paramForSplitInventory = new HashMap<>(); |
|
|
|
paramForSplitInventory.put("iid", iid); |
|
|
|
paramForSplitInventory.put("sid", splitInfo.getId()); |
|
|
|
SplitInventory splitInventory = splitUnitMapper.findSplitInventoryByIidAndSid(paramForSplitInventory); |
|
|
|
|
|
|
|
|
|
|
|
// 获取当前进制
|
|
|
|
int scale = splitInfo.getQuantity(); |
|
|
|
|
|
|
|
// 计算处理数量(下取整)
|
|
|
|
int disposeQuantity = (int) Math.round(Math.floor(quantity / scale)); |
|
|
|
|
|
|
|
// 最终存储到拆单处理的数量
|
|
|
|
double saveQuantity = quantity - disposeQuantity * scale; |
|
|
|
|
|
|
|
if (splitInventory != null) { |
|
|
|
// 如果拆单库存处理记录不为空
|
|
|
|
if (splitInventory.getSaveQuantity() + saveQuantity > splitInfo.getQuantity()) { |
|
|
|
// 当前库存拆单记录与新入库的数目大于预设的进制
|
|
|
|
|
|
|
|
|
|
|
|
// 定义当前实际修改数量
|
|
|
|
double new_saveQuantity = splitInventory.getSaveQuantity() + saveQuantity - splitInfo.getQuantity(); |
|
|
|
// 令计算处理数量+1
|
|
|
|
disposeQuantity += 1; |
|
|
|
|
|
|
|
// 定义保存数量
|
|
|
|
splitInventory.setSaveQuantity((int) (splitInventory.getSaveQuantity() + new_saveQuantity)); |
|
|
|
// 定义添加数量
|
|
|
|
splitInventory.setInQuantity((int) (splitInventory.getInQuantity() + new_saveQuantity)); |
|
|
|
|
|
|
|
// 修改库存拆单库存处理记录
|
|
|
|
splitUnitMapper.updateSplitInventory(splitInventory); |
|
|
|
|
|
|
|
if (parentId != null) { |
|
|
|
// 如果当前拆单的父级不为空
|
|
|
|
|
|
|
|
// 获取具体父级
|
|
|
|
SplitInfo splitInfoForParent = splitUnitMapper.findSplitInfoById(parentId); |
|
|
|
|
|
|
|
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()); |
|
|
|
map.put("quantity", String.valueOf(disposeQuantity)); |
|
|
|
map.put("realQuantity", String.valueOf(inQuantity)); |
|
|
|
|
|
|
|
depositoryRecordService.applicationInPlace(map); |
|
|
|
} |
|
|
|
} |
|
|
|
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()); |
|
|
|
map.put("quantity", "0"); |
|
|
|
map.put("realQuantity", String.valueOf(inQuantity)); |
|
|
|
depositoryRecordService.applicationInPlace(map); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
|
|
|
|
// 如果为空
|
|
|
|
Map<String, Object> paramForInsertSplitInventory = new HashMap<>(); |
|
|
|
|
|
|
|
paramForInsertSplitInventory.put("sid", splitInfo.getId()); |
|
|
|
paramForInsertSplitInventory.put("inQuantity", quantity); |
|
|
|
paramForInsertSplitInventory.put("outQuantity", 0); |
|
|
|
paramForInsertSplitInventory.put("iid", map.get("newInMid")); |
|
|
|
if (quantity > splitInfo.getQuantity()) { |
|
|
|
// 如果当前处理数量大于当前设置的进制数量
|
|
|
|
|
|
|
|
// 计算需要进位的数量
|
|
|
|
int quantity_scale = quantity / splitInfo.getQuantity(); |
|
|
|
// 计算剩余处理的数量
|
|
|
|
int quantity_residue = quantity - quantity_scale * splitInfo.getQuantity(); |
|
|
|
paramForInsertSplitInventory.put("saveQuantity", quantity_residue); |
|
|
|
splitUnitMapper.addSplitInventory(paramForInsertSplitInventory); |
|
|
|
|
|
|
|
if (parentId != null) { |
|
|
|
// 如果其有父级
|
|
|
|
|
|
|
|
// 获取当前拆单记录的父级
|
|
|
|
SplitInfo parentSplitInfo = splitUnitMapper.findSplitInfoById(parentId); |
|
|
|
|
|
|
|
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()); |
|
|
|
map.put("quantity", String.valueOf(quantity_scale)); |
|
|
|
map.put("realQuantity", String.valueOf(inQuantity)); |
|
|
|
depositoryRecordService.applicationInPlace(map); |
|
|
|
} |
|
|
|
} else { |
|
|
|
// 如果不大于
|
|
|
|
paramForInsertSplitInventory.put("saveQuantity", String.valueOf(inQuantity)); |
|
|
|
splitUnitMapper.addSplitInventory(paramForInsertSplitInventory); |
|
|
|
map.put("quantity", "0"); |
|
|
|
map.put("realQuantity", String.valueOf(inQuantity)); |
|
|
|
depositoryRecordService.applicationInPlace(map); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据条件查询对应拆单详细信息 |
|
|
|
* |
|
|
|
@ -385,7 +611,7 @@ public class SplitUnitServiceImpl implements SplitUnitService { |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public SplitInventory findSplitInventoryByIid(Integer Iid) { |
|
|
|
public List<SplitInventory> findSplitInventoryByIid(Integer Iid) { |
|
|
|
return splitUnitMapper.findSplitInventoryByIid(Iid); |
|
|
|
} |
|
|
|
|
|
|
|
|