Browse Source

更新拆单库存查询、拆单进制计算算法

lwx_dev
erdanergou 3 years ago
parent
commit
65cd73d772
  1. 3
      src/main/java/com/dreamchaser/depository_manage/controller/MaterialController.java
  2. 2
      src/main/java/com/dreamchaser/depository_manage/controller/SplitController.java
  3. 6
      src/main/java/com/dreamchaser/depository_manage/mapper/SplitUnitMapper.xml
  4. 20
      src/main/java/com/dreamchaser/depository_manage/service/SplitUnitService.java
  5. 289
      src/main/java/com/dreamchaser/depository_manage/service/impl/DepositoryRecordServiceImpl.java
  6. 167
      src/main/java/com/dreamchaser/depository_manage/service/impl/SplitUnitServiceImpl.java
  7. 56
      src/test/java/com/dreamchaser/depository_manage/TestForOther.java
  8. 6
      target/classes/com/dreamchaser/depository_manage/mapper/SplitUnitMapper.xml

3
src/main/java/com/dreamchaser/depository_manage/controller/MaterialController.java

@ -611,7 +611,7 @@ public class MaterialController {
SplitInfo splitInfo = splitUnitService.findSplitInfoByMidAndUnit(paramForSplitInfo); SplitInfo splitInfo = splitUnitService.findSplitInfoByMidAndUnit(paramForSplitInfo);
// 获取最高级对应当前单位的数量 // 获取最高级对应当前单位的数量
int saveQuantity = inventoryP.getQuantity() * splitUnitService.findSplitInfoQuantity(splitInfo); int saveQuantity = inventoryP.getQuantity() * splitUnitService.findSplitInfoScaleQuantity(splitInfo,-1);
SplitInventory splitInventory = splitUnitService.findSplitInventoryByIidAndSid(inventoryP.getId(), splitInfo.getId()); SplitInventory splitInventory = splitUnitService.findSplitInventoryByIidAndSid(inventoryP.getId(), splitInfo.getId());
saveQuantity += splitInventory.getSaveQuantity(); saveQuantity += splitInventory.getSaveQuantity();
@ -623,7 +623,6 @@ public class MaterialController {
saveQuantity += splitInventory.getSaveQuantity() * splitInfo.getQuantity(); saveQuantity += splitInventory.getSaveQuantity() * splitInfo.getQuantity();
parentSplitInfo = splitUnitService.findSplitInfoById(parentSplitInfo.getParentId()); parentSplitInfo = splitUnitService.findSplitInfoById(parentSplitInfo.getParentId());
} }
if (quantity <= saveQuantity) { // 如果当前数量合适则跳出循环 if (quantity <= saveQuantity) { // 如果当前数量合适则跳出循环
flag = true; flag = true;
break; break;

2
src/main/java/com/dreamchaser/depository_manage/controller/SplitController.java

@ -123,7 +123,7 @@ public class SplitController {
List<Inventory> inventoryByMid = materialService.findInventoryByMid(splitInfoByMidAndUnit.getMid()); List<Inventory> inventoryByMid = materialService.findInventoryByMid(splitInfoByMidAndUnit.getMid());
if(inventoryByMid.size() > 0){ if(inventoryByMid.size() > 0){
Inventory inventory = inventoryByMid.get(0); Inventory inventory = inventoryByMid.get(0);
return new RestResponse(inventory.getPrice() / splitUnitService.findSplitInfoQuantity(splitInfoByMidAndUnit)); return new RestResponse(inventory.getPrice() / splitUnitService.findSplitInfoScaleQuantity(splitInfoByMidAndUnit,-1));
} }
}else{ }else{
Integer mid = ObjectFormatUtil.toInteger(map.get("mid")); Integer mid = ObjectFormatUtil.toInteger(map.get("mid"));

6
src/main/java/com/dreamchaser/depository_manage/mapper/SplitUnitMapper.xml

@ -151,13 +151,13 @@
<if test="sid != null and sid != ''"> <if test="sid != null and sid != ''">
sid = #{sid}, sid = #{sid},
</if> </if>
<if test="outQuantity != null and outQuantity != ''"> <if test="outQuantity != null">
outQuantity = #{outQuantity}, outQuantity = #{outQuantity},
</if> </if>
<if test="inQuantity != null and inQuantity != ''"> <if test="inQuantity != null">
inQuantity = #{inQuantity}, inQuantity = #{inQuantity},
</if> </if>
<if test="saveQuantity != null and saveQuantity != ''"> <if test="saveQuantity != null">
saveQuantity = #{saveQuantity}, saveQuantity = #{saveQuantity},
</if> </if>
</set> </set>

20
src/main/java/com/dreamchaser/depository_manage/service/SplitUnitService.java

@ -1,5 +1,6 @@
package com.dreamchaser.depository_manage.service; package com.dreamchaser.depository_manage.service;
import com.dreamchaser.depository_manage.entity.Inventory;
import com.dreamchaser.depository_manage.entity.SplitInfo; import com.dreamchaser.depository_manage.entity.SplitInfo;
import com.dreamchaser.depository_manage.entity.SplitInventory; import com.dreamchaser.depository_manage.entity.SplitInventory;
import com.dreamchaser.depository_manage.pojo.SplitInfoP; import com.dreamchaser.depository_manage.pojo.SplitInfoP;
@ -101,12 +102,25 @@ public interface SplitUnitService {
List<SplitInventory> findSplitInventoryByIid(Integer Iid); List<SplitInventory> findSplitInventoryByIid(Integer Iid);
/** /**
* 用于计算当前拆单单位与基础单位之间的进率 * 用于计算当前拆单单位与目标拆单单位之间的进率
*
* @param splitInfo 待查询拆单记录 * @param splitInfo 待查询拆单记录
* @param parentSplitInfoId 目标拆单单位
* @return
*/
int findSplitInfoScaleQuantity(SplitInfo splitInfo, Integer parentSplitInfoId);
/**
* 获取当前拆单与基础拆单之间的库存总额(当前拆单记录为-1是全部库存是使用)
*
* @param splitInfoId 当前拆单记录Id
* @param inventory 库存记录
* @param baseSplitInfoId 基础拆单记录Id
* @param saveQuantity 最终返回值
* @param allQuantityFlag 用于标志是否获取全部库存
* @return * @return
*/ */
int findSplitInfoQuantity(SplitInfo splitInfo); int findAllInventoryForSplitInfo(Integer splitInfoId, Inventory inventory, Integer baseSplitInfoId, int saveQuantity, boolean allQuantityFlag);
/** /**
* 根据库存id与拆单记录id获取对应拆单库存处理记录 * 根据库存id与拆单记录id获取对应拆单库存处理记录

289
src/main/java/com/dreamchaser/depository_manage/service/impl/DepositoryRecordServiceImpl.java

@ -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.pojo.callBackXml.callBackXml_button_templatecard.TemplateCard;
import com.dreamchaser.depository_manage.service.DepositoryRecordService; import com.dreamchaser.depository_manage.service.DepositoryRecordService;
import com.dreamchaser.depository_manage.service.RoleService; import com.dreamchaser.depository_manage.service.RoleService;
import com.dreamchaser.depository_manage.service.SplitUnitService;
import com.dreamchaser.depository_manage.utils.*; import com.dreamchaser.depository_manage.utils.*;
import org.redisson.api.RLock; import org.redisson.api.RLock;
import org.redisson.api.RedissonClient; import org.redisson.api.RedissonClient;
@ -61,6 +62,9 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService {
@Autowired @Autowired
private SplitUnitMapper splitUnitMapper; private SplitUnitMapper splitUnitMapper;
@Autowired
private SplitUnitService splitUnitService;
/** /**
* 提交申请插入一条仓库调度记录 * 提交申请插入一条仓库调度记录
@ -889,9 +893,9 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService {
restResponse.setData(""); restResponse.setData("");
restResponse.setStatusInfo(new StatusInfo("出库失败", "出库失败,库存不足")); restResponse.setStatusInfo(new StatusInfo("出库失败", "出库失败,库存不足"));
} }
} else { }
// 如果是拆单后的单位 else {
// 如果是拆单后的出库
// 用于获取对应的拆单记录 // 用于获取对应的拆单记录
Map<String, Object> paramForSplitInfo = new HashMap<>(); Map<String, Object> paramForSplitInfo = new HashMap<>();
@ -943,12 +947,36 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService {
// 获取剩余不足的数量 // 获取剩余不足的数量
int surplus = trueOut - splitInventory.getSaveQuantity(); int surplus = trueOut - splitInventory.getSaveQuantity();
if (surplus < splitInfoById.getQuantity()) {
if (splitInfoById.getParentId() != null) { if (splitInfoById.getParentId() != null) {
// 如果当前拆单有父级
// 设置剩余拆单库存处理数量
// 设置当前拆单库存出库数量
splitInventory.setOutQuantity(splitInventory.getOutQuantity() + splitInventory.getSaveQuantity());
// 将当前库存设置为0
splitInventory.setSaveQuantity(0);
// 修改库存数量
splitUnitMapper.updateSplitInventory(splitInventory);
// 获取当前父级拆单记录
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<>(); Map<String, Object> params = new HashMap<>();
params.put("mid", inventory.getId()); params.put("mid", inventory.getId());
@ -976,13 +1004,16 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService {
// 令库存-1 // 令库存-1
inventory.setQuantity(inventory.getQuantity() - 1); inventory.setQuantity(inventory.getQuantity() - 1);
// 重新计算总额 // 重新计算总额
inventory.setAmounts(inventory.getQuantity() * inventory.getPrice()); inventory.setAmounts(inventory.getQuantity() * inventory.getPrice());
if (Integer.compare(inventory.getQuantity(), 0) != 0) {
// 重新计算单价 // 重新计算单价
BigDecimal decimal = new BigDecimal(inventory.getAmounts() / inventory.getQuantity()); BigDecimal decimal = BigDecimal.valueOf(inventory.getAmounts() / inventory.getQuantity());
Double price = decimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); Double price = decimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
inventory.setPrice(price); inventory.setPrice(price);
}
// 修改库存记录 // 修改库存记录
materialMapper.updateInventory(inventory); materialMapper.updateInventory(inventory);
@ -1022,12 +1053,6 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService {
restResponse.setStatus(508); restResponse.setStatus(508);
restResponse.setData(""); restResponse.setData("");
restResponse.setStatusInfo(new StatusInfo("出库失败", "出库失败,库存不足")); restResponse.setStatusInfo(new StatusInfo("出库失败", "出库失败,库存不足"));
}
}else{
//如果有父级
} }
} else { } else {
// 如果大于 // 如果大于
@ -1077,11 +1102,12 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService {
// 重新计算总额 // 重新计算总额
inventory.setAmounts(inventory.getQuantity() * inventory.getPrice()); inventory.setAmounts(inventory.getQuantity() * inventory.getPrice());
if (Integer.compare(inventory.getQuantity(), 0) != 0) {
// 重新计算单价 // 重新计算单价
BigDecimal decimal = new BigDecimal(inventory.getAmounts() / inventory.getQuantity()); BigDecimal decimal = BigDecimal.valueOf(inventory.getAmounts() / inventory.getQuantity());
Double price = decimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); Double price = decimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
inventory.setPrice(price); inventory.setPrice(price);
}
// 修改库存记录 // 修改库存记录
materialMapper.updateInventory(inventory); materialMapper.updateInventory(inventory);
@ -1116,7 +1142,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService {
restResponse.setStatusInfo(new StatusInfo("出库失败", "出库失败,库存不足")); restResponse.setStatusInfo(new StatusInfo("出库失败", "出库失败,库存不足"));
} }
} }
}
} }
} else { } else {
@ -1136,11 +1162,12 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService {
// 设置新库存 // 设置新库存
inventory.setQuantity(inventory.getQuantity() - residue - 1); inventory.setQuantity(inventory.getQuantity() - residue - 1);
if (Integer.compare(inventory.getQuantity(), 0) != 0) {
// 重新计算单价 // 重新计算单价
BigDecimal decimal = BigDecimal.valueOf(inventory.getAmounts() / inventory.getQuantity()); BigDecimal decimal = BigDecimal.valueOf(inventory.getAmounts() / inventory.getQuantity());
Double price = decimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); Double price = decimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
inventory.setPrice(price); inventory.setPrice(price);
}
//更新库存 //更新库存
materialMapper.updateInventory(inventory); materialMapper.updateInventory(inventory);
@ -1191,23 +1218,237 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService {
return restResponse; return restResponse;
} }
/** /**
* 用于有父级拆单记录的出库处理 * 用于有父级拆单记录的出库处理
* @param splitInfo 当前拆单记录 *
* @param splitInfo 父级拆单记录
* @param inventory 当前库存记录 * @param inventory 当前库存记录
* @param quantity 当前出库总量
* @param nowQuantity 当前未出库数量
* @param realSplitInfo 实际出库的拆单记录
* @return * @return
*/ */
RestResponse updateSplitInventoryInfo(SplitInfo splitInfo,Inventory inventory){ RestResponse updateSplitInventoryInfo(SplitInfo splitInfo, Inventory inventory, int quantity, int nowQuantity, SplitInfo realSplitInfo) {
// 获取当前拆单的父级 // 定义返回值
SplitInfo parentSplitInfo = splitUnitMapper.findSplitInfoById(splitInfo.getParentId()); RestResponse restResponse = new RestResponse();
// // 用于获取当前拆单记录对应的拆单库存记录
Map<String, Object> paramForSplitInventory = new HashMap<>(); Map<String, Object> paramForSplitInventory = new HashMap<>();
paramForSplitInventory.put("sid", splitInfo.getId()); paramForSplitInventory.put("sid", splitInfo.getId());
paramForSplitInventory.put("iid", inventory.getId()); paramForSplitInventory.put("iid", inventory.getId());
splitUnitMapper.findSplitInventoryByIidAndSid(paramForSplitInventory); SplitInventory splitInventoryForSplitInfo = splitUnitMapper.findSplitInventoryByIidAndSid(paramForSplitInventory);
return null; // 获取当前拆单记录与实际出库拆单之间的进制
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;
}
/** /**

167
src/main/java/com/dreamchaser/depository_manage/service/impl/SplitUnitServiceImpl.java

@ -179,14 +179,13 @@ public class SplitUnitServiceImpl implements SplitUnitService {
updateSplitInfoSaveQuantity(parentSplitInfo, disposeQuantity, inventory.getId(), map, quantity.intValue()); updateSplitInfoSaveQuantity(parentSplitInfo, disposeQuantity, inventory.getId(), map, quantity.intValue());
} else { } else {
Double price = Double.parseDouble((String) map.get("price")); Double price = Double.parseDouble((String) map.get("price"));
price = price * findSplitInfoQuantity(splitInfoForUnit); price = price * findSplitInfoScaleQuantity(splitInfoForUnit, -1);
map.put("price", price.toString()); map.put("price", price.toString());
depositoryRecordService.applicationInPlace(map); depositoryRecordService.applicationInPlace(map);
} }
} } else {
else {
// 如果没有记录 // 如果没有记录
// 获取当前拆单记录的父级 // 获取当前拆单记录的父级
@ -214,14 +213,14 @@ public class SplitUnitServiceImpl implements SplitUnitService {
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 { } else {
Double price = Double.parseDouble((String) map.get("price")); Double price = Double.parseDouble((String) map.get("price"));
price = price * findSplitInfoQuantity(splitInfoForUnit); price = price * findSplitInfoScaleQuantity(splitInfoForUnit, -1);
map.put("price", price.toString()); map.put("price", price.toString());
result += depositoryRecordService.applicationInPlace(map); 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 { } else {
Double price = Double.parseDouble((String) map.get("price")); Double price = Double.parseDouble((String) map.get("price"));
price = price * findSplitInfoQuantity(splitInfoForUnit); price = price * findSplitInfoScaleQuantity(splitInfoForUnit, -1);
map.put("price", price.toString()); map.put("price", price.toString());
result += depositoryRecordService.applicationInPlace(map); result += depositoryRecordService.applicationInPlace(map);
} }
@ -240,11 +239,10 @@ public class SplitUnitServiceImpl implements SplitUnitService {
// 插入一条库存记录 // 插入一条库存记录
Double price = Double.parseDouble((String) map.get("price")); Double price = Double.parseDouble((String) map.get("price"));
price = price * findSplitInfoQuantity(splitInfoForUnit); price = price * findSplitInfoScaleQuantity(splitInfoForUnit, -1);
map.put("price", price.toString()); map.put("price", price.toString());
if (parentId != null) { if (parentId != null) {
// 如果有父级 // 如果有父级
@ -278,24 +276,155 @@ public class SplitUnitServiceImpl implements SplitUnitService {
} }
/** /**
* 用于计算当前拆单单位与基础单位之间的进率 * 用于计算当前拆单单位与目标拆单单位之间的进率
*
* @param splitInfo 待查询拆单记录 * @param splitInfo 待查询拆单记录
* @param parentSplitInfoId 目标拆单单位
* @return * @return
*/ */
public int findSplitInfoQuantity(SplitInfo splitInfo) { public int findSplitInfoScaleQuantity(SplitInfo splitInfo, Integer parentSplitInfoId) {
int quantity = 1; int quantity = 1; // 定义进制
quantity *= splitInfo.getQuantity(); 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) { if (splitInfo.getParentId() != null) {
SplitInfo splitInfoById = splitUnitMapper.findSplitInfoById(splitInfo.getParentId()); SplitInfo splitInfoById = splitUnitMapper.findSplitInfoById(splitInfo.getParentId());
return quantity * findSplitInfoQuantity(splitInfoById); return quantity * findSplitInfoScaleQuantity(splitInfoById, parentSplitInfoId);
} else { } else {
return quantity; 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获取对应拆单库存处理记录 * 根据库存id与拆单记录id获取对应拆单库存处理记录
*
* @param Iid 待查询库存id * @param Iid 待查询库存id
* @param sid 待查询拆单id * @param sid 待查询拆单id
* @return * @return
@ -311,6 +440,7 @@ public class SplitUnitServiceImpl implements SplitUnitService {
/** /**
* 根据父级查询拆单记录 * 根据父级查询拆单记录
*
* @param parentId 待查询父级 * @param parentId 待查询父级
* @return * @return
*/ */
@ -321,6 +451,7 @@ public class SplitUnitServiceImpl implements SplitUnitService {
/** /**
* 用于拆单库存处理记录的修改 * 用于拆单库存处理记录的修改
*
* @param splitInfo 对应拆单记录 * @param splitInfo 对应拆单记录
* @param quantity 修改数目 * @param quantity 修改数目
* @param map 入库条件 * @param map 入库条件
@ -378,29 +509,27 @@ public class SplitUnitServiceImpl implements SplitUnitService {
} else { } else {
// 如果为空 // 如果为空
Double price = Double.parseDouble((String) map.get("price")); Double price = Double.parseDouble((String) map.get("price"));
price = price * findSplitInfoQuantity(splitInfo); price = price * findSplitInfoScaleQuantity(splitInfo, -1);
map.put("price", price.toString()); map.put("price", price.toString());
map.put("quantity", String.valueOf(disposeQuantity)); map.put("quantity", String.valueOf(disposeQuantity));
map.put("realQuantity", String.valueOf(inQuantity)); map.put("realQuantity", String.valueOf(inQuantity));
depositoryRecordService.applicationInPlace(map); depositoryRecordService.applicationInPlace(map);
} }
} } else {
else {
// 当前库存拆单记录与新入库的数目不大于预设的进制 // 当前库存拆单记录与新入库的数目不大于预设的进制
splitInventory.setSaveQuantity(splitInventory.getSaveQuantity() + disposeQuantity); splitInventory.setSaveQuantity(splitInventory.getSaveQuantity() + disposeQuantity);
splitInventory.setInQuantity(splitInventory.getInQuantity() + disposeQuantity); splitInventory.setInQuantity(splitInventory.getInQuantity() + disposeQuantity);
splitUnitMapper.updateSplitInventory(splitInventory); splitUnitMapper.updateSplitInventory(splitInventory);
Double price = Double.parseDouble((String) map.get("price")); Double price = Double.parseDouble((String) map.get("price"));
price = price * findSplitInfoQuantity(splitInfo); price = price * findSplitInfoScaleQuantity(splitInfo, -1);
map.put("price", price.toString()); map.put("price", price.toString());
map.put("quantity", "0"); map.put("quantity", "0");
map.put("realQuantity", String.valueOf(inQuantity)); map.put("realQuantity", String.valueOf(inQuantity));
depositoryRecordService.applicationInPlace(map); depositoryRecordService.applicationInPlace(map);
} }
} } else {
else {
// 如果为空 // 如果为空
Map<String, Object> paramForInsertSplitInventory = new HashMap<>(); Map<String, Object> paramForInsertSplitInventory = new HashMap<>();
@ -428,7 +557,7 @@ public class SplitUnitServiceImpl implements SplitUnitService {
updateSplitInfoSaveQuantity(parentSplitInfo, quantity_scale, iid, map, inQuantity); updateSplitInfoSaveQuantity(parentSplitInfo, quantity_scale, iid, map, inQuantity);
} else { } else {
Double price = Double.parseDouble((String) map.get("price")); Double price = Double.parseDouble((String) map.get("price"));
price = price * findSplitInfoQuantity(splitInfo); price = price * findSplitInfoScaleQuantity(splitInfo, -1);
map.put("price", price.toString()); map.put("price", price.toString());
map.put("quantity", String.valueOf(quantity_scale)); map.put("quantity", String.valueOf(quantity_scale));
map.put("realQuantity", String.valueOf(inQuantity)); map.put("realQuantity", String.valueOf(inQuantity));

56
src/test/java/com/dreamchaser/depository_manage/TestForOther.java

@ -1,23 +1,20 @@
package com.dreamchaser.depository_manage; package com.dreamchaser.depository_manage;
import com.dreamchaser.depository_manage.entity.Inventory;
import com.dreamchaser.depository_manage.entity.SplitInfo; import com.dreamchaser.depository_manage.entity.SplitInfo;
import com.dreamchaser.depository_manage.entity.SplitInventory; import com.dreamchaser.depository_manage.entity.SplitInventory;
import com.dreamchaser.depository_manage.mapper.MaterialMapper;
import com.dreamchaser.depository_manage.mapper.SplitUnitMapper; import com.dreamchaser.depository_manage.mapper.SplitUnitMapper;
import com.dreamchaser.depository_manage.pojo.InventoryP;
import com.dreamchaser.depository_manage.service.SplitUnitService; import com.dreamchaser.depository_manage.service.SplitUnitService;
import com.dreamchaser.depository_manage.utils.CreateQrCodeUtil;
import com.dreamchaser.depository_manage.utils.ObjectFormatUtil;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import sun.misc.BASE64Decoder;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.util.HashMap;
import java.util.Map;
/** /**
@ -28,13 +25,48 @@ import java.io.OutputStream;
public class TestForOther { public class TestForOther {
@Test @Autowired
public void Test() throws IOException { SplitUnitService splitUnitService;
Double a = 24.0;
System.out.println(a.intValue());
}
@Autowired
SplitUnitMapper splitUnitMapper;
@Autowired
MaterialMapper materialMapper;
@Test
public void Test() throws IOException {
SplitInfo splitInfoById = splitUnitMapper.findSplitInfoById(7);
double splitInfoScaleQuantity = findSplitInfoScaleQuantity(splitInfoById, 7);
System.out.println(splitInfoScaleQuantity);
}
/**
* 用于计算当前拆单单位与目标拆单单位之间的进率
* @param splitInfo 待查询拆单记录
* @param parentSplitInfoId 目标拆单单位
* @return
*/
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 * findSplitInfoScaleQuantity(splitInfoById, parentSplitInfoId);
} else {
return quantity;
}
}
}
} }

6
target/classes/com/dreamchaser/depository_manage/mapper/SplitUnitMapper.xml

@ -151,13 +151,13 @@
<if test="sid != null and sid != ''"> <if test="sid != null and sid != ''">
sid = #{sid}, sid = #{sid},
</if> </if>
<if test="outQuantity != null and outQuantity != ''"> <if test="outQuantity != null">
outQuantity = #{outQuantity}, outQuantity = #{outQuantity},
</if> </if>
<if test="inQuantity != null and inQuantity != ''"> <if test="inQuantity != null">
inQuantity = #{inQuantity}, inQuantity = #{inQuantity},
</if> </if>
<if test="saveQuantity != null and saveQuantity != ''"> <if test="saveQuantity != null">
saveQuantity = #{saveQuantity}, saveQuantity = #{saveQuantity},
</if> </if>
</set> </set>

Loading…
Cancel
Save