26 changed files with 473 additions and 144 deletions
@ -0,0 +1,147 @@ |
|||||
|
package com.dreamchaser.depository_manage; |
||||
|
|
||||
|
import com.dreamchaser.depository_manage.entity.*; |
||||
|
import com.dreamchaser.depository_manage.pojo.ApplicationInRecordP; |
||||
|
import com.dreamchaser.depository_manage.pojo.ApplicationOutRecordP; |
||||
|
import com.dreamchaser.depository_manage.pojo.DepositoryRecordP; |
||||
|
import com.dreamchaser.depository_manage.pojo.InventoryP; |
||||
|
import com.dreamchaser.depository_manage.service.DepositoryRecordService; |
||||
|
import com.dreamchaser.depository_manage.service.DepositoryService; |
||||
|
import com.dreamchaser.depository_manage.service.MaterialService; |
||||
|
import com.dreamchaser.depository_manage.service.StockTakingService; |
||||
|
import com.dreamchaser.depository_manage.utils.LinkInterfaceUtil; |
||||
|
import com.dreamchaser.depository_manage.utils.ObjectFormatUtil; |
||||
|
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 javax.servlet.http.HttpServletRequest; |
||||
|
import java.util.ArrayList; |
||||
|
import java.util.HashMap; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
@SpringBootTest |
||||
|
@RunWith(SpringRunner.class) |
||||
|
public class TestFoFindDepositoryMaterial { |
||||
|
|
||||
|
@Autowired |
||||
|
DepositoryService depositoryService; |
||||
|
|
||||
|
@Autowired |
||||
|
DepositoryRecordService depositoryRecordService; |
||||
|
|
||||
|
@Autowired |
||||
|
MaterialService materialService; |
||||
|
|
||||
|
@Autowired |
||||
|
StockTakingService stockTakingService; |
||||
|
|
||||
|
@Test |
||||
|
public void Test(){ |
||||
|
UserByPort userByPort = LinkInterfaceUtil.FindUserById(78, null); |
||||
|
Boolean allSonDepository = findAllSonDepositoryOfRelevancy("48",null); |
||||
|
System.out.println(allSonDepository); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 根据父级编号查询所有关联信息 |
||||
|
* |
||||
|
* @param did |
||||
|
* @return |
||||
|
*/ |
||||
|
public Boolean findAllSonDepositoryOfRelevancy(String did, HttpServletRequest request) { |
||||
|
// 判断当前仓库是否存在物料
|
||||
|
boolean materialByDepository = findMaterialByDepository(did); |
||||
|
// 判断当前仓库是否有相关订单
|
||||
|
boolean depositoryRecord = findDepositoryRecord(did, request); |
||||
|
if (materialByDepository || depositoryRecord) { |
||||
|
return true; |
||||
|
} |
||||
|
// 查询当前仓库
|
||||
|
Depository depositoryById = depositoryService.findDepositoryById(ObjectFormatUtil.toInteger(did)); |
||||
|
// 查询当前仓库及子仓库
|
||||
|
List<Integer> childForDepositoryByParent = findChildForDepositoryByParent(depositoryById); |
||||
|
List<Depository> depositories = depositoryService.selectDepositoryRecordByIds(childForDepositoryByParent); |
||||
|
for (Depository depository : depositories) { |
||||
|
String depositoryId = depository.getId().toString(); |
||||
|
if (findMaterialByDepository(depositoryId) || findDepositoryRecord(depositoryId, request)) { |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 根据仓库编号判断该仓库是否有物品 |
||||
|
* |
||||
|
* @param depositoryId 待查询仓库id |
||||
|
* @return |
||||
|
*/ |
||||
|
public boolean findMaterialByDepository(String depositoryId) { |
||||
|
Map<String, Object> param = new HashMap<>(); |
||||
|
param.put("state", 1); |
||||
|
param.put("depositoryId", depositoryId); |
||||
|
List<InventoryP> materialPByCondition = materialService.findInventory(param); |
||||
|
return materialPByCondition.size() > 0; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 根据仓库编号查询与其有关的订单信息 |
||||
|
* @param depositoryId 待查询仓库id |
||||
|
* @return |
||||
|
*/ |
||||
|
public Boolean findDepositoryRecord(String depositoryId, HttpServletRequest request) { |
||||
|
Map<String, Object> param = new HashMap<>(); |
||||
|
param.put("depositoryId", depositoryId); |
||||
|
List<ApplicationInRecordP> inRecordPList = depositoryRecordService.findApplicationInRecordPByCondition(param,request); |
||||
|
List<ApplicationOutRecordP> outRecordPList = depositoryRecordService.findApplicationOutRecordPByCondition(param, request); |
||||
|
List<StockTaking> stockTakingList = stockTakingService.findStockTakingByCondition(param); |
||||
|
return inRecordPList.size() > 0 || outRecordPList.size() > 0 || stockTakingList.size() > 0; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 用于获取当前仓库的所有子类 |
||||
|
* @param d 待查询仓库 |
||||
|
* @return |
||||
|
*/ |
||||
|
public List<Integer> findChildForDepositoryByParent(Depository d) { |
||||
|
// 用于存储最终返回结果
|
||||
|
List<Integer> result = new ArrayList<>(); |
||||
|
result.add(d.getId()); |
||||
|
// 父级
|
||||
|
List<Integer> parentId = new ArrayList<>(); |
||||
|
parentId.add(d.getId()); |
||||
|
// 查询所有仓库正常使用的仓库
|
||||
|
List<Depository> depositoryAll = depositoryService.findDepositoryAll(); |
||||
|
for (Depository depository : depositoryAll) { |
||||
|
if (isTrueForParent(parentId, depository.getParentId())) { |
||||
|
parentId.add(depository.getId()); |
||||
|
result.add(depository.getId()); |
||||
|
} |
||||
|
} |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 判断当前id是否在ids中 |
||||
|
* |
||||
|
* @param parentList 父级列表 |
||||
|
* @param id 待判断id |
||||
|
* @return |
||||
|
*/ |
||||
|
public Boolean isTrueForParent(List<Integer> parentList, Integer id) { |
||||
|
for (Integer aLong : parentList) { |
||||
|
if (Long.compare(aLong, id) == 0) { |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
} |
||||
Loading…
Reference in new issue