|
@@ -1,5 +1,6 @@
|
|
|
package com.zjugis.business.service.impl;
|
|
|
|
|
|
+import com.alibaba.excel.util.StringUtils;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.zjugis.business.bean.dto.ContractDto;
|
|
@@ -26,6 +27,8 @@ import org.springframework.stereotype.Service;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.zjugis.business.constants.ResponseStatusEnum.MAIN_CONTRACT_NOT_EXIST;
|
|
|
import static com.zjugis.business.constants.ResponseStatusEnum.PROJECT_CONTRACT_RELATED;
|
|
@@ -77,23 +80,31 @@ public class ContractServiceImpl implements ContractService{
|
|
|
return contractMapper.deleteBatchIds(idList);
|
|
|
}
|
|
|
|
|
|
- public ContractResponse selectWithChildren(String projectId) {
|
|
|
+ public List<ContractResponse> selectWithChildren(String projectId) {
|
|
|
List<Contract> contracts = contractMapper.selectWithChildren(projectId);
|
|
|
if(contracts.isEmpty()){
|
|
|
return null;
|
|
|
}
|
|
|
- Contract dbParent = contracts.get(0);
|
|
|
- ContractResponse parent = new ContractResponse();
|
|
|
- BeanUtils.copyProperties(dbParent,parent);
|
|
|
- contracts.remove(0);
|
|
|
- List<ContractChildResponse> children = new ArrayList<>();
|
|
|
- for (Contract dbChild : contracts) {
|
|
|
- ContractChildResponse child = new ContractChildResponse();
|
|
|
- BeanUtils.copyProperties(dbChild,child);
|
|
|
- children.add(child);
|
|
|
+ List<Contract> dbParents = contracts.stream().filter(item -> StringUtils.isBlank(item.getParentId())).collect(Collectors.toList());
|
|
|
+ List<ContractResponse> parents = new ArrayList<>();
|
|
|
+ contracts.removeAll(dbParents);
|
|
|
+ Map<String, List<Contract>> map = contracts.stream().collect(Collectors.groupingBy(Contract::getParentId));
|
|
|
+ for (Contract dbParent : dbParents) {
|
|
|
+ ContractResponse r = new ContractResponse();
|
|
|
+ BeanUtils.copyProperties(dbParent, r);
|
|
|
+ if(!map.isEmpty()) {
|
|
|
+ List<Contract> children = map.get(r.getId());
|
|
|
+ if(!children.isEmpty()){
|
|
|
+ r.setChildren(children.stream().map((contract) -> {
|
|
|
+ ContractChildResponse child = new ContractChildResponse();
|
|
|
+ BeanUtils.copyProperties(contract, child);
|
|
|
+ return child;
|
|
|
+ }).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ parents.add(r);
|
|
|
}
|
|
|
- parent.setChildren(children);
|
|
|
- return parent;
|
|
|
+ return parents;
|
|
|
}
|
|
|
|
|
|
/**
|