11 changed files with 1772 additions and 93 deletions
File diff suppressed because it is too large
@ -0,0 +1,62 @@ |
|||
package com.dreamchaser.depository_manage; |
|||
|
|||
import com.dreamchaser.depository_manage.entity.Depository; |
|||
import com.dreamchaser.depository_manage.entity.MaterialType; |
|||
import com.dreamchaser.depository_manage.mapper.DepositoryMapper; |
|||
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.ArrayList; |
|||
import java.util.List; |
|||
|
|||
@RunWith(SpringRunner.class) |
|||
@SpringBootTest |
|||
public class TestForOther { |
|||
|
|||
|
|||
@Autowired |
|||
DepositoryMapper depositoryMapper; |
|||
|
|||
@Test |
|||
public void run() { |
|||
Depository depositoryById = depositoryMapper.findDepositoryById(9); |
|||
List<Integer> childForDepositoryByParent = findChildForDepositoryByParent(depositoryById); |
|||
System.out.println(childForDepositoryByParent); |
|||
} |
|||
|
|||
// 根据id获取子类
|
|||
public List<Integer> findChildForDepositoryByParent(Depository depository) { |
|||
List<Integer> result = new ArrayList<>(); |
|||
result.add(depository.getId()); |
|||
List<Integer> parentId = new ArrayList<>(); |
|||
parentId.add(depository.getId()); |
|||
List<Depository> depositoryAll = depositoryMapper.findDepositoryAll(); |
|||
for (Depository d : depositoryAll) { |
|||
if (parentId.contains(d.getParentId())) { |
|||
parentId.add(d.getId()); |
|||
result.add(d.getId()); |
|||
} |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 判断当前id是否在ids中 |
|||
* |
|||
* @param parentList |
|||
* @param id |
|||
* @return |
|||
*/ |
|||
public Boolean isTrueForParent(List<Integer> parentList, Integer id) { |
|||
for (Integer aLong : parentList) { |
|||
if (Integer.compare(aLong, id) == 0) { |
|||
return true; |
|||
} |
|||
} |
|||
return false; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue