28 changed files with 502 additions and 464 deletions
@ -0,0 +1,174 @@ |
|||||
|
package com.dreamchaser.depository_manage; |
||||
|
|
||||
|
import com.dreamchaser.depository_manage.entity.MaterialAndPlace; |
||||
|
import com.dreamchaser.depository_manage.entity.SplitInfo; |
||||
|
import com.dreamchaser.depository_manage.entity.SplitInventory; |
||||
|
import com.dreamchaser.depository_manage.mapper.PlaceMapper; |
||||
|
import com.dreamchaser.depository_manage.mapper.SplitUnitMapper; |
||||
|
import com.dreamchaser.depository_manage.service.SplitUnitService; |
||||
|
import org.junit.Test; |
||||
|
import org.junit.runner.RunWith; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.boot.test.context.SpringBootTest; |
||||
|
import org.springframework.test.context.junit4.SpringRunner; |
||||
|
|
||||
|
import java.util.HashMap; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
@SpringBootTest |
||||
|
@RunWith(SpringRunner.class) |
||||
|
public class TestQywxSplitInventoryAll { |
||||
|
|
||||
|
@Autowired |
||||
|
SplitUnitMapper splitUnitMapper; |
||||
|
|
||||
|
@Autowired |
||||
|
PlaceMapper placeMapper; |
||||
|
|
||||
|
|
||||
|
@Test |
||||
|
public void Test(){ |
||||
|
Map<String,Object> map = new HashMap<>(); |
||||
|
map.put("mid","6"); |
||||
|
map.put("pid","8"); |
||||
|
MaterialAndPlace placeAndMaterialByMidAndPid = placeMapper.findPlaceAndMaterialByMidAndPid(map); |
||||
|
int allInventoryForSplitInfo = findAllInventoryForSplitInfo(-1, placeAndMaterialByMidAndPid, 4, 0, true); |
||||
|
System.out.println(allInventoryForSplitInfo); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public int findAllInventoryForSplitInfo(Integer splitInfoId, MaterialAndPlace materialAndPlace, 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", materialAndPlace.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(), materialAndPlace, 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(), materialAndPlace, baseSplitInfoId, saveQuantity, allQuantityFlag); |
||||
|
} else { |
||||
|
int splitInfoScaleQuantity = findSplitInfoScaleQuantity(baseSplitInfo, -1); |
||||
|
return saveQuantity + materialAndPlace.getQuantity() * splitInfoScaleQuantity; |
||||
|
} |
||||
|
|
||||
|
} else { |
||||
|
int splitInfoScaleQuantity = findSplitInfoScaleQuantity(baseSplitInfo, -1); |
||||
|
return saveQuantity + materialAndPlace.getQuantity() * splitInfoScaleQuantity; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
|
else { |
||||
|
// 如果不是获取所有库存
|
||||
|
// 获取当前基础单位
|
||||
|
SplitInfo baseSplitInfo = splitUnitMapper.findSplitInfoById(baseSplitInfoId); |
||||
|
|
||||
|
// 获取当前基础单位的库存
|
||||
|
Map<String, Object> paramForSplitInventory = new HashMap<>(); |
||||
|
paramForSplitInventory.put("iid", materialAndPlace.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(), materialAndPlace, baseSplitInfoId, saveQuantity, allQuantityFlag); |
||||
|
} else { |
||||
|
// 如果没有
|
||||
|
return saveQuantity; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
public int findSplitInfoScaleQuantity(SplitInfo splitInfo, Integer parentSplitInfoId) { |
||||
|
int quantity = 1; // 定义进制
|
||||
|
if (parentSplitInfoId != null && Integer.compare(-1, parentSplitInfoId) != 0) { |
||||
|
// 如果待查询的父级不是顶级
|
||||
|
if (Integer.compare(splitInfo.getParentId(), parentSplitInfoId) == 0) { |
||||
|
// 如果当前拆单记录是目标拆单单位
|
||||
|
quantity *= splitInfo.getQuantity(); |
||||
|
|
||||
|
return quantity; |
||||
|
} else { |
||||
|
SplitInfo splitInfoById = splitUnitMapper.findSplitInfoById(splitInfo.getParentId()); |
||||
|
return quantity * findSplitInfoScaleQuantity(splitInfoById, parentSplitInfoId); |
||||
|
} |
||||
|
} else { |
||||
|
quantity *= splitInfo.getQuantity(); |
||||
|
if (splitInfo.getParentId() != null) { |
||||
|
SplitInfo splitInfoById = splitUnitMapper.findSplitInfoById(splitInfo.getParentId()); |
||||
|
return quantity * findSplitInfoScaleQuantity(splitInfoById, parentSplitInfoId); |
||||
|
} else { |
||||
|
return quantity; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
Loading…
Reference in new issue