|
|
|
@ -11,6 +11,7 @@ import com.dreamchaser.depository_manage.pojo.callBackXml.approvalCallBackXml.Ap |
|
|
|
import com.dreamchaser.depository_manage.pojo.callBackXml.callBackXml_button_templatecard.TemplateCard; |
|
|
|
import com.dreamchaser.depository_manage.service.DepositoryRecordService; |
|
|
|
import com.dreamchaser.depository_manage.service.RoleService; |
|
|
|
import com.dreamchaser.depository_manage.service.SplitUnitService; |
|
|
|
import com.dreamchaser.depository_manage.utils.*; |
|
|
|
import org.redisson.api.RLock; |
|
|
|
import org.redisson.api.RedissonClient; |
|
|
|
@ -61,6 +62,9 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
@Autowired |
|
|
|
private SplitUnitMapper splitUnitMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private SplitUnitService splitUnitService; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 提交申请,插入一条仓库调度记录 |
|
|
|
@ -889,9 +893,9 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
restResponse.setData(""); |
|
|
|
restResponse.setStatusInfo(new StatusInfo("出库失败", "出库失败,库存不足")); |
|
|
|
} |
|
|
|
} else { |
|
|
|
// 如果是拆单后的单位
|
|
|
|
|
|
|
|
} |
|
|
|
else { |
|
|
|
// 如果是拆单后的出库
|
|
|
|
|
|
|
|
// 用于获取对应的拆单记录
|
|
|
|
Map<String, Object> paramForSplitInfo = new HashMap<>(); |
|
|
|
@ -943,12 +947,36 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
// 获取剩余不足的数量
|
|
|
|
int surplus = trueOut - splitInventory.getSaveQuantity(); |
|
|
|
|
|
|
|
if (surplus < splitInfoById.getQuantity()) { |
|
|
|
if (splitInfoById.getParentId() != null) { |
|
|
|
// 如果当前拆单有父级
|
|
|
|
|
|
|
|
|
|
|
|
// 设置剩余拆单库存处理数量
|
|
|
|
|
|
|
|
|
|
|
|
// 设置当前拆单库存出库数量
|
|
|
|
splitInventory.setOutQuantity(splitInventory.getOutQuantity() + splitInventory.getSaveQuantity()); |
|
|
|
|
|
|
|
// 将当前库存设置为0
|
|
|
|
splitInventory.setSaveQuantity(0); |
|
|
|
// 修改库存数量
|
|
|
|
splitUnitMapper.updateSplitInventory(splitInventory); |
|
|
|
|
|
|
|
if (splitInfoById.getParentId() != null) { |
|
|
|
// 如果当前拆单没有父级
|
|
|
|
|
|
|
|
// 如果剩余不足的数量小于拆单单位对应的数量
|
|
|
|
// 获取当前父级拆单记录
|
|
|
|
SplitInfo parentSplitInfo = splitUnitMapper.findSplitInfoById(splitInfoById.getParentId()); |
|
|
|
|
|
|
|
restResponse = updateSplitInventoryInfo(parentSplitInfo, inventory, trueOut, surplus, splitInfo); |
|
|
|
|
|
|
|
updateApplicationMinOutInfo(id, applicationOutMinById, record, trueOut, userByPort, placeId, userAgent); |
|
|
|
} else { |
|
|
|
// 如果当前拆单没有父级
|
|
|
|
|
|
|
|
|
|
|
|
if (surplus < splitInfoById.getQuantity()) { |
|
|
|
|
|
|
|
// 如果当前未处理的数量小于当前拆单库存数量
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> params = new HashMap<>(); |
|
|
|
params.put("mid", inventory.getId()); |
|
|
|
@ -976,13 +1004,16 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
// 令库存-1
|
|
|
|
inventory.setQuantity(inventory.getQuantity() - 1); |
|
|
|
|
|
|
|
|
|
|
|
// 重新计算总额
|
|
|
|
inventory.setAmounts(inventory.getQuantity() * inventory.getPrice()); |
|
|
|
|
|
|
|
// 重新计算单价
|
|
|
|
BigDecimal decimal = new BigDecimal(inventory.getAmounts() / inventory.getQuantity()); |
|
|
|
Double price = decimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); |
|
|
|
inventory.setPrice(price); |
|
|
|
if (Integer.compare(inventory.getQuantity(), 0) != 0) { |
|
|
|
// 重新计算单价
|
|
|
|
BigDecimal decimal = BigDecimal.valueOf(inventory.getAmounts() / inventory.getQuantity()); |
|
|
|
Double price = decimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); |
|
|
|
inventory.setPrice(price); |
|
|
|
} |
|
|
|
|
|
|
|
// 修改库存记录
|
|
|
|
materialMapper.updateInventory(inventory); |
|
|
|
@ -1023,100 +1054,95 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
restResponse.setData(""); |
|
|
|
restResponse.setStatusInfo(new StatusInfo("出库失败", "出库失败,库存不足")); |
|
|
|
} |
|
|
|
}else{ |
|
|
|
//如果有父级
|
|
|
|
} else { |
|
|
|
// 如果大于
|
|
|
|
|
|
|
|
// 获取库存重要减少的数量
|
|
|
|
int surplus_redundant = surplus / splitInfoById.getQuantity(); |
|
|
|
// 获取拆单库存处理中要处理数量
|
|
|
|
int saveQuantity = surplus - surplus_redundant * splitInfoById.getQuantity(); |
|
|
|
|
|
|
|
if (saveQuantity > splitInventory.getSaveQuantity()) { |
|
|
|
// 如果要处理的数量大于剩余数量
|
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|
// 如果大于
|
|
|
|
|
|
|
|
// 获取库存重要减少的数量
|
|
|
|
int surplus_redundant = surplus / splitInfoById.getQuantity(); |
|
|
|
// 获取拆单库存处理中要处理数量
|
|
|
|
int saveQuantity = surplus - surplus_redundant * splitInfoById.getQuantity(); |
|
|
|
// 获取一个数量
|
|
|
|
surplus_redundant += 1; |
|
|
|
splitInventory.setSaveQuantity(splitInfoById.getQuantity() + splitInventory.getSaveQuantity() - saveQuantity); |
|
|
|
} else { |
|
|
|
// 如果不大于
|
|
|
|
splitInventory.setSaveQuantity(splitInventory.getSaveQuantity() - saveQuantity); |
|
|
|
} |
|
|
|
splitInventory.setOutQuantity(splitInventory.getOutQuantity() + saveQuantity); |
|
|
|
Map<String, Object> params = new HashMap<>(); |
|
|
|
params.put("mid", inventory.getId()); |
|
|
|
params.put("pid", placeId); |
|
|
|
|
|
|
|
if (saveQuantity > splitInventory.getSaveQuantity()) { |
|
|
|
// 如果要处理的数量大于剩余数量
|
|
|
|
// 获取当前物料在库位中的数量
|
|
|
|
placeAndMaterialByMidAndPid = placeMapper.findPlaceAndMaterialByMidAndPid(params); |
|
|
|
|
|
|
|
// 获取一个数量
|
|
|
|
surplus_redundant += 1; |
|
|
|
splitInventory.setSaveQuantity(splitInfoById.getQuantity() + splitInventory.getSaveQuantity() - saveQuantity); |
|
|
|
} else { |
|
|
|
// 如果不大于
|
|
|
|
splitInventory.setSaveQuantity(splitInventory.getSaveQuantity() - saveQuantity); |
|
|
|
} |
|
|
|
splitInventory.setOutQuantity(splitInventory.getOutQuantity() + saveQuantity); |
|
|
|
Map<String, Object> params = new HashMap<>(); |
|
|
|
params.put("mid", inventory.getId()); |
|
|
|
params.put("pid", placeId); |
|
|
|
|
|
|
|
// 获取当前物料在库位中的数量
|
|
|
|
placeAndMaterialByMidAndPid = placeMapper.findPlaceAndMaterialByMidAndPid(params); |
|
|
|
|
|
|
|
if (placeAndMaterialByMidAndPid != null) { |
|
|
|
// 如果当前库位存在该物料
|
|
|
|
if (placeAndMaterialByMidAndPid.getQuantity() < surplus_redundant) { |
|
|
|
// 如果当前库存中的物料库存不足以出库
|
|
|
|
flag = false; |
|
|
|
if (placeAndMaterialByMidAndPid != null) { |
|
|
|
// 如果当前库位存在该物料
|
|
|
|
if (placeAndMaterialByMidAndPid.getQuantity() < surplus_redundant) { |
|
|
|
// 如果当前库存中的物料库存不足以出库
|
|
|
|
flag = false; |
|
|
|
} |
|
|
|
} else { |
|
|
|
restResponse.setStatus(566); |
|
|
|
restResponse.setData(""); |
|
|
|
restResponse.setStatusInfo(new StatusInfo("出库失败", "当前位置未发现该物料")); |
|
|
|
return restResponse; |
|
|
|
} |
|
|
|
} else { |
|
|
|
restResponse.setStatus(566); |
|
|
|
restResponse.setData(""); |
|
|
|
restResponse.setStatusInfo(new StatusInfo("出库失败", "当前位置未发现该物料")); |
|
|
|
return restResponse; |
|
|
|
} |
|
|
|
|
|
|
|
if (inventory.getQuantity() >= surplus_redundant && flag) { |
|
|
|
// 如果能够出库
|
|
|
|
if (inventory.getQuantity() >= surplus_redundant && flag) { |
|
|
|
// 如果能够出库
|
|
|
|
|
|
|
|
// 令库存-1
|
|
|
|
inventory.setQuantity(inventory.getQuantity() - surplus_redundant); |
|
|
|
|
|
|
|
// 重新计算总额
|
|
|
|
inventory.setAmounts(inventory.getQuantity() * inventory.getPrice()); |
|
|
|
// 令库存-1
|
|
|
|
inventory.setQuantity(inventory.getQuantity() - surplus_redundant); |
|
|
|
|
|
|
|
// 重新计算单价
|
|
|
|
BigDecimal decimal = new BigDecimal(inventory.getAmounts() / inventory.getQuantity()); |
|
|
|
Double price = decimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); |
|
|
|
inventory.setPrice(price); |
|
|
|
// 重新计算总额
|
|
|
|
inventory.setAmounts(inventory.getQuantity() * inventory.getPrice()); |
|
|
|
|
|
|
|
// 修改库存记录
|
|
|
|
materialMapper.updateInventory(inventory); |
|
|
|
if (Integer.compare(inventory.getQuantity(), 0) != 0) { |
|
|
|
// 重新计算单价
|
|
|
|
BigDecimal decimal = BigDecimal.valueOf(inventory.getAmounts() / inventory.getQuantity()); |
|
|
|
Double price = decimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); |
|
|
|
inventory.setPrice(price); |
|
|
|
} |
|
|
|
// 修改库存记录
|
|
|
|
materialMapper.updateInventory(inventory); |
|
|
|
|
|
|
|
|
|
|
|
// 修改当前库位存放物料的数量
|
|
|
|
placeAndMaterialByMidAndPid.setQuantity(placeAndMaterialByMidAndPid.getQuantity() - surplus_redundant); |
|
|
|
placeMapper.updateMaterialAndPlace(placeAndMaterialByMidAndPid); |
|
|
|
// 修改当前库位存放物料的数量
|
|
|
|
placeAndMaterialByMidAndPid.setQuantity(placeAndMaterialByMidAndPid.getQuantity() - surplus_redundant); |
|
|
|
placeMapper.updateMaterialAndPlace(placeAndMaterialByMidAndPid); |
|
|
|
|
|
|
|
// 修改库位数量
|
|
|
|
Place placeById = placeMapper.findPlaceById(placeId); |
|
|
|
placeById.setQuantity(placeById.getQuantity() - surplus_redundant); |
|
|
|
placeMapper.UpdatePlace(placeById); |
|
|
|
// 修改库位数量
|
|
|
|
Place placeById = placeMapper.findPlaceById(placeId); |
|
|
|
placeById.setQuantity(placeById.getQuantity() - surplus_redundant); |
|
|
|
placeMapper.UpdatePlace(placeById); |
|
|
|
|
|
|
|
|
|
|
|
// 如果是库存转移订单
|
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
if (record.getIstransfer() == 1) { |
|
|
|
map.put("quantity", String.valueOf(surplus_redundant)); |
|
|
|
map.put("applicantId", record.getApplicantId()); |
|
|
|
map.put("minRecordId", applicationOutMinById.getId()); // 出库订单编号
|
|
|
|
transferMaterial(map); |
|
|
|
} |
|
|
|
// 如果是库存转移订单
|
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
if (record.getIstransfer() == 1) { |
|
|
|
map.put("quantity", String.valueOf(surplus_redundant)); |
|
|
|
map.put("applicantId", record.getApplicantId()); |
|
|
|
map.put("minRecordId", applicationOutMinById.getId()); // 出库订单编号
|
|
|
|
transferMaterial(map); |
|
|
|
} |
|
|
|
|
|
|
|
updateApplicationMinOutInfo(id, applicationOutMinById, record, trueOut, userByPort, placeId, userAgent); |
|
|
|
updateApplicationMinOutInfo(id, applicationOutMinById, record, trueOut, userByPort, placeId, userAgent); |
|
|
|
|
|
|
|
restResponse.setStatus(200); |
|
|
|
restResponse.setData(""); |
|
|
|
restResponse.setStatusInfo(new StatusInfo("出库成功", "出库成功")); |
|
|
|
} else { |
|
|
|
restResponse.setStatus(508); |
|
|
|
restResponse.setData(""); |
|
|
|
restResponse.setStatusInfo(new StatusInfo("出库失败", "出库失败,库存不足")); |
|
|
|
restResponse.setStatus(200); |
|
|
|
restResponse.setData(""); |
|
|
|
restResponse.setStatusInfo(new StatusInfo("出库成功", "出库成功")); |
|
|
|
} else { |
|
|
|
restResponse.setStatus(508); |
|
|
|
restResponse.setData(""); |
|
|
|
restResponse.setStatusInfo(new StatusInfo("出库失败", "出库失败,库存不足")); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
@ -1136,11 +1162,12 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
// 设置新库存
|
|
|
|
inventory.setQuantity(inventory.getQuantity() - residue - 1); |
|
|
|
|
|
|
|
// 重新计算单价
|
|
|
|
BigDecimal decimal = BigDecimal.valueOf(inventory.getAmounts() / inventory.getQuantity()); |
|
|
|
Double price = decimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); |
|
|
|
inventory.setPrice(price); |
|
|
|
|
|
|
|
if (Integer.compare(inventory.getQuantity(), 0) != 0) { |
|
|
|
// 重新计算单价
|
|
|
|
BigDecimal decimal = BigDecimal.valueOf(inventory.getAmounts() / inventory.getQuantity()); |
|
|
|
Double price = decimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); |
|
|
|
inventory.setPrice(price); |
|
|
|
} |
|
|
|
//更新库存
|
|
|
|
materialMapper.updateInventory(inventory); |
|
|
|
|
|
|
|
@ -1191,23 +1218,237 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
return restResponse; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 用于有父级拆单记录的出库处理 |
|
|
|
* @param splitInfo 当前拆单记录 |
|
|
|
* @param inventory 当前库存记录 |
|
|
|
* |
|
|
|
* @param splitInfo 父级拆单记录 |
|
|
|
* @param inventory 当前库存记录 |
|
|
|
* @param quantity 当前出库总量 |
|
|
|
* @param nowQuantity 当前未出库数量 |
|
|
|
* @param realSplitInfo 实际出库的拆单记录 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
RestResponse updateSplitInventoryInfo(SplitInfo splitInfo,Inventory inventory){ |
|
|
|
// 获取当前拆单的父级
|
|
|
|
SplitInfo parentSplitInfo = splitUnitMapper.findSplitInfoById(splitInfo.getParentId()); |
|
|
|
//
|
|
|
|
Map<String,Object> paramForSplitInventory = new HashMap<>(); |
|
|
|
paramForSplitInventory.put("sid",splitInfo.getId()); |
|
|
|
paramForSplitInventory.put("iid",inventory.getId()); |
|
|
|
splitUnitMapper.findSplitInventoryByIidAndSid(paramForSplitInventory); |
|
|
|
return null; |
|
|
|
} |
|
|
|
RestResponse updateSplitInventoryInfo(SplitInfo splitInfo, Inventory inventory, int quantity, int nowQuantity, SplitInfo realSplitInfo) { |
|
|
|
// 定义返回值
|
|
|
|
RestResponse restResponse = new RestResponse(); |
|
|
|
// 用于获取当前拆单记录对应的拆单库存记录
|
|
|
|
Map<String, Object> paramForSplitInventory = new HashMap<>(); |
|
|
|
paramForSplitInventory.put("sid", splitInfo.getId()); |
|
|
|
paramForSplitInventory.put("iid", inventory.getId()); |
|
|
|
SplitInventory splitInventoryForSplitInfo = splitUnitMapper.findSplitInventoryByIidAndSid(paramForSplitInventory); |
|
|
|
// 获取当前拆单记录与实际出库拆单之间的进制
|
|
|
|
int parentScale = splitUnitService.findSplitInfoScaleQuantity(realSplitInfo, splitInfo.getId()); |
|
|
|
if (splitInventoryForSplitInfo.getSaveQuantity() * parentScale >= nowQuantity) { |
|
|
|
// 如果当前库存拆单记录的库存可以满足需要
|
|
|
|
|
|
|
|
// 设置当前拆单库存
|
|
|
|
splitInventoryForSplitInfo.setSaveQuantity(splitInventoryForSplitInfo.getSaveQuantity() - nowQuantity); |
|
|
|
// 设置当前拆单出库库存数
|
|
|
|
splitInventoryForSplitInfo.setOutQuantity(splitInventoryForSplitInfo.getOutQuantity() + nowQuantity); |
|
|
|
// 修改库存记录
|
|
|
|
splitUnitMapper.updateSplitInventory(splitInventoryForSplitInfo); |
|
|
|
|
|
|
|
|
|
|
|
restResponse.setStatus(200); |
|
|
|
restResponse.setData(""); |
|
|
|
restResponse.setStatusInfo(new StatusInfo("出库成功", "出库成功")); |
|
|
|
} else { |
|
|
|
|
|
|
|
// 如果当前库存拆单记录的库存不能满足需要
|
|
|
|
|
|
|
|
// 获取当前物料的库存
|
|
|
|
int allInventoryForSplitInfo = splitUnitService.findAllInventoryForSplitInfo(-1, inventory, realSplitInfo.getId(), 0, true); |
|
|
|
// 判断当前所有库存是否可以满足需求
|
|
|
|
if (allInventoryForSplitInfo >= nowQuantity) { |
|
|
|
// 如果当前库存数可以满足需求
|
|
|
|
|
|
|
|
if (splitInfo.getParentId() != null) { |
|
|
|
// 如果还有父级
|
|
|
|
|
|
|
|
// 获取当前拆单的父级
|
|
|
|
SplitInfo parentSplitInfo = splitUnitMapper.findSplitInfoById(splitInfo.getParentId()); |
|
|
|
|
|
|
|
paramForSplitInventory.put("sid", parentSplitInfo.getId()); |
|
|
|
SplitInventory parentSplitInventoryForSplitInfo = splitUnitMapper.findSplitInventoryByIidAndSid(paramForSplitInventory); |
|
|
|
|
|
|
|
// 定义当前库存下的库存数量
|
|
|
|
|
|
|
|
// 获取当前物料的进制
|
|
|
|
int scaleQuantity = splitUnitService.findSplitInfoScaleQuantity(parentSplitInfo, realSplitInfo.getId()); |
|
|
|
|
|
|
|
int realQuantity = scaleQuantity * parentSplitInventoryForSplitInfo.getSaveQuantity(); |
|
|
|
|
|
|
|
if (realQuantity >= nowQuantity) { |
|
|
|
// 如果当前库存容量可以满足需求
|
|
|
|
|
|
|
|
if (nowQuantity >= splitInfo.getQuantity()) { |
|
|
|
//如果当前要出库的数量大于等于进制数量
|
|
|
|
|
|
|
|
// 当前库存不足的数量
|
|
|
|
Double remainderQuantity = (double) (nowQuantity - splitInventoryForSplitInfo.getSaveQuantity()); |
|
|
|
|
|
|
|
// 获取需要借位的数量
|
|
|
|
int scale = (int) Math.ceil(remainderQuantity / splitInfo.getQuantity()); |
|
|
|
|
|
|
|
// 令父级拆单库存减少对应数量
|
|
|
|
parentSplitInventoryForSplitInfo.setSaveQuantity(parentSplitInventoryForSplitInfo.getSaveQuantity() - scale); |
|
|
|
// 令父级拆单出库量添加对应数量
|
|
|
|
parentSplitInventoryForSplitInfo.setOutQuantity(parentSplitInventoryForSplitInfo.getOutQuantity() + scale); |
|
|
|
// 修改父级拆单库存处理记录
|
|
|
|
splitUnitMapper.updateSplitInventory(parentSplitInventoryForSplitInfo); |
|
|
|
|
|
|
|
// 设置当前库存数量
|
|
|
|
splitInventoryForSplitInfo.setSaveQuantity(scale * splitInfo.getQuantity() - splitInventoryForSplitInfo.getSaveQuantity()); |
|
|
|
// 设置当前出库数量
|
|
|
|
splitInventoryForSplitInfo.setOutQuantity(splitInventoryForSplitInfo.getOutQuantity() + ((quantity - splitInventoryForSplitInfo.getSaveQuantity()))); |
|
|
|
// 修改当前拆单库存处理记录
|
|
|
|
|
|
|
|
} else { |
|
|
|
// 如果当前出库数量不大于进制数量
|
|
|
|
|
|
|
|
// 令父级拆单库存减一
|
|
|
|
parentSplitInventoryForSplitInfo.setSaveQuantity(parentSplitInventoryForSplitInfo.getSaveQuantity() - 1); |
|
|
|
// 令父级拆单出库量加一
|
|
|
|
parentSplitInventoryForSplitInfo.setOutQuantity(parentSplitInventoryForSplitInfo.getOutQuantity() + 1); |
|
|
|
// 修改父级拆单库存处理记录
|
|
|
|
splitUnitMapper.updateSplitInventory(parentSplitInventoryForSplitInfo); |
|
|
|
|
|
|
|
// 设置当前拆单库存数
|
|
|
|
splitInventoryForSplitInfo.setSaveQuantity(splitInventoryForSplitInfo.getSaveQuantity() - quantity); |
|
|
|
// 设置当前拆单库存出库数
|
|
|
|
splitInventoryForSplitInfo.setOutQuantity(splitInventoryForSplitInfo.getOutQuantity() + quantity); |
|
|
|
// 修改当前拆单库存处理记录
|
|
|
|
|
|
|
|
} |
|
|
|
splitUnitMapper.updateSplitInventory(splitInventoryForSplitInfo); |
|
|
|
restResponse.setStatus(200); |
|
|
|
restResponse.setData(""); |
|
|
|
restResponse.setStatusInfo(new StatusInfo("出库成功", "出库成功")); |
|
|
|
|
|
|
|
} else { |
|
|
|
// 如果当前当前父级与其的库存数量不大于要出库的数量
|
|
|
|
|
|
|
|
if (parentSplitInfo.getParentId() != null) { |
|
|
|
|
|
|
|
nowQuantity = nowQuantity - realQuantity; |
|
|
|
|
|
|
|
parentSplitInventoryForSplitInfo.setOutQuantity(parentSplitInventoryForSplitInfo.getOutQuantity() + parentSplitInventoryForSplitInfo.getSaveQuantity()); |
|
|
|
parentSplitInventoryForSplitInfo.setSaveQuantity(0); |
|
|
|
|
|
|
|
splitUnitMapper.updateSplitInventory(parentSplitInventoryForSplitInfo); |
|
|
|
// 如果当前还有父级
|
|
|
|
|
|
|
|
// 进行递归
|
|
|
|
RestResponse restResponse1 = updateSplitInventoryInfo(parentSplitInfo, inventory, quantity, nowQuantity, splitInfo); |
|
|
|
// 获取其父级减少与实际出库的拆单记录的数量
|
|
|
|
Object data = restResponse1.getData(); |
|
|
|
// 计算当前与最底层的进制
|
|
|
|
double splitInfoScaleQuantity = 1; |
|
|
|
if (Integer.compare(realSplitInfo.getId(), parentSplitInfo.getId()) != 0) { |
|
|
|
// 如果当前不是最底层
|
|
|
|
splitInfoScaleQuantity *= splitUnitService.findSplitInfoScaleQuantity(realSplitInfo, parentSplitInfo.getId()); |
|
|
|
} |
|
|
|
if (data != null && !"".equals(data.toString())) { |
|
|
|
int surplus_redundant = ObjectFormatUtil.toInteger(data) * (int) splitInfoScaleQuantity; |
|
|
|
if (surplus_redundant - nowQuantity == 0) { |
|
|
|
// 如果刚好完成出库且没有剩余
|
|
|
|
restResponse.setStatus(200); |
|
|
|
restResponse.setData(""); |
|
|
|
restResponse.setStatusInfo(new StatusInfo("出库成功", "出库成功")); |
|
|
|
} else { |
|
|
|
// 如果还有剩余
|
|
|
|
|
|
|
|
// 计算当前针对于最底层的数量
|
|
|
|
surplus_redundant = surplus_redundant - nowQuantity; |
|
|
|
// 获取当前拆单单位要添加的库存
|
|
|
|
double floor = Math.floor(surplus_redundant / splitInfoScaleQuantity); |
|
|
|
parentSplitInventoryForSplitInfo.setSaveQuantity((int) floor); |
|
|
|
if (surplus_redundant - floor == 0) { |
|
|
|
restResponse.setStatus(200); |
|
|
|
restResponse.setData(""); |
|
|
|
restResponse.setStatusInfo(new StatusInfo("出库成功", "出库成功")); |
|
|
|
} else { |
|
|
|
restResponse.setData(surplus_redundant - floor); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
return restResponse1; |
|
|
|
} |
|
|
|
} else { |
|
|
|
// 如果没有父级
|
|
|
|
|
|
|
|
// 获取当前拆单单位与顶级之间的进制
|
|
|
|
int splitInfoQuantity = splitUnitService.findSplitInfoScaleQuantity(splitInfo, -1); |
|
|
|
// 获取所有当前单位的拆单库存
|
|
|
|
realQuantity = inventory.getQuantity() * splitInfoQuantity + realQuantity; |
|
|
|
if (realQuantity > nowQuantity) { |
|
|
|
// 如果可以出库
|
|
|
|
|
|
|
|
// 计算当前不足的数量
|
|
|
|
int residue_quantity = realQuantity - nowQuantity; |
|
|
|
|
|
|
|
// 计算库存需要减少的数量
|
|
|
|
int inventory_quantity = (int) Math.ceil((double) residue_quantity / splitInfoQuantity); |
|
|
|
|
|
|
|
// 重新设置库存数量
|
|
|
|
inventory.setQuantity(inventory.getQuantity() - inventory_quantity); |
|
|
|
|
|
|
|
// 重新设置总额
|
|
|
|
inventory.setAmounts(inventory.getAmounts() - inventory_quantity * inventory.getPrice()); |
|
|
|
|
|
|
|
if (Integer.compare(inventory.getQuantity(), 0) != 0) { |
|
|
|
// 重新计算单价
|
|
|
|
BigDecimal decimal = BigDecimal.valueOf(inventory.getAmounts() / inventory.getQuantity()); |
|
|
|
Double price = decimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); |
|
|
|
inventory.setPrice(price); |
|
|
|
} |
|
|
|
// 修改库存数量
|
|
|
|
materialMapper.updateInventory(inventory); |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
// 如果不可出库
|
|
|
|
restResponse.setStatus(508); |
|
|
|
restResponse.setData(""); |
|
|
|
restResponse.setStatusInfo(new StatusInfo("出库失败", "出库失败,库存不足")); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
// 如果已经没有父级
|
|
|
|
|
|
|
|
// 获取顶级与当前单位之间的进制
|
|
|
|
double splitInfoScaleQuantityForAll = splitUnitService.findSplitInfoScaleQuantity(splitInfo, -1); |
|
|
|
// 计算库存减少的数目
|
|
|
|
int surplus_redundant = (int) Math.ceil(nowQuantity / splitInfoScaleQuantityForAll); |
|
|
|
|
|
|
|
// 设置当前库存数量
|
|
|
|
inventory.setQuantity(inventory.getQuantity() - surplus_redundant); |
|
|
|
// 设置当前总额
|
|
|
|
inventory.setAmounts(inventory.getPrice() * inventory.getQuantity()); |
|
|
|
if(Integer.compare(inventory.getQuantity(),0) != 0) { |
|
|
|
// 设置当前单价
|
|
|
|
BigDecimal decimal = BigDecimal.valueOf(inventory.getAmounts() / inventory.getQuantity()); |
|
|
|
Double price = decimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); |
|
|
|
inventory.setPrice(price); |
|
|
|
} |
|
|
|
// 修改库存数量
|
|
|
|
materialMapper.updateInventory(inventory); |
|
|
|
|
|
|
|
restResponse.setData(surplus_redundant); |
|
|
|
} |
|
|
|
} else { |
|
|
|
// 如果不能满足需求
|
|
|
|
|
|
|
|
restResponse.setStatus(508); |
|
|
|
restResponse.setData(""); |
|
|
|
restResponse.setStatusInfo(new StatusInfo("出库失败", "出库失败,库存不足")); |
|
|
|
} |
|
|
|
} |
|
|
|
return restResponse; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|