优化以人找房,以房找人 --renpc
This commit is contained in:
parent
f719b2f6f5
commit
a61ad13841
@ -1,6 +1,7 @@
|
||||
package com.cm.population.pojo.dtos.population;
|
||||
|
||||
import com.cm.population.pojo.dtos.house.HouseDTO;
|
||||
import com.cm.population.pojo.dtos.populationinfo.PopulationInfoBaseDTO;
|
||||
import com.cm.population.pojo.dtos.populationinfo.PopulationInfoDTO;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
@ -44,10 +45,10 @@ public class PopulationDTO {
|
||||
private Integer isDelete;
|
||||
@ApiModelProperty(name = "houseDTO", value = "房屋详情")
|
||||
private HouseDTO houseDTO;
|
||||
@ApiModelProperty(name = "populationInfoHouseDTO", value = "人口详情")
|
||||
private PopulationInfoHouseDTO populationInfoHouseDTO;
|
||||
@ApiModelProperty(name = "populationInfoDTO", value = "人口详情")
|
||||
@ApiModelProperty(name = "populationInfoDTO", value = "人员基本信息")
|
||||
private PopulationInfoDTO populationInfoDTO;
|
||||
@ApiModelProperty(name = "populationInfoBaseDTO", value = "人员基本信息")
|
||||
private PopulationInfoBaseDTO populationInfoBaseDTO;
|
||||
|
||||
public String getPopulationId() {
|
||||
return populationId == null ? "" : populationId.trim();
|
||||
@ -161,14 +162,6 @@ public class PopulationDTO {
|
||||
this.houseDTO = houseDTO;
|
||||
}
|
||||
|
||||
public PopulationInfoHouseDTO getPopulationInfoHouseDTO() {
|
||||
return populationInfoHouseDTO;
|
||||
}
|
||||
|
||||
public void setPopulationInfoHouseDTO(PopulationInfoHouseDTO populationInfoHouseDTO) {
|
||||
this.populationInfoHouseDTO = populationInfoHouseDTO;
|
||||
}
|
||||
|
||||
public PopulationInfoDTO getPopulationInfoDTO() {
|
||||
return populationInfoDTO;
|
||||
}
|
||||
@ -176,4 +169,12 @@ public class PopulationDTO {
|
||||
public void setPopulationInfoDTO(PopulationInfoDTO populationInfoDTO) {
|
||||
this.populationInfoDTO = populationInfoDTO;
|
||||
}
|
||||
|
||||
public PopulationInfoBaseDTO getPopulationInfoBaseDTO() {
|
||||
return populationInfoBaseDTO;
|
||||
}
|
||||
|
||||
public void setPopulationInfoBaseDTO(PopulationInfoBaseDTO populationInfoBaseDTO) {
|
||||
this.populationInfoBaseDTO = populationInfoBaseDTO;
|
||||
}
|
||||
}
|
||||
|
@ -10,18 +10,15 @@ import com.cm.population.dao.house.IHouseDao;
|
||||
import com.cm.population.dao.population.IPopulationDao;
|
||||
import com.cm.population.pojo.bos.population.PopulationBO;
|
||||
import com.cm.population.pojo.dtos.house.HouseDTO;
|
||||
import com.cm.population.pojo.dtos.population.HouseUserDTO;
|
||||
import com.cm.population.pojo.dtos.population.PopulationDTO;
|
||||
import com.cm.population.pojo.dtos.population.PopulationInfoHouseDTO;
|
||||
import com.cm.population.pojo.dtos.populationinfo.PopulationInfoBaseDTO;
|
||||
import com.cm.population.pojo.dtos.populationinfo.PopulationInfoDTO;
|
||||
import com.cm.population.pojo.pos.population.PopulationPO;
|
||||
import com.cm.population.pojo.vos.house.HouseVO;
|
||||
import com.cm.population.pojo.vos.population.PopulationVO;
|
||||
import com.cm.population.service.house.IHouseService;
|
||||
import com.cm.population.service.population.IPopulationService;
|
||||
import com.cm.population.service.populationinfo.IPopulationInfoService;
|
||||
import com.cm.population.service.populationinfo.impl.PopulationInfoServiceImpl;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -29,12 +26,10 @@ import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import sun.security.krb5.internal.PAData;
|
||||
|
||||
import javax.mail.search.SearchException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@ -436,6 +431,16 @@ public class PopulationServiceImpl extends AbstractService implements IPopulatio
|
||||
return populationInfoDTO;
|
||||
}
|
||||
|
||||
private PopulationInfoBaseDTO setPopulationBaseInfo(PopulationDTO populationDTO) {
|
||||
PopulationInfoBaseDTO populationInfoDTO = new PopulationInfoBaseDTO();
|
||||
populationInfoDTO.setIdcard(populationDTO.getCardNum());
|
||||
populationInfoDTO.setName(populationDTO.getName());
|
||||
populationInfoDTO.setPhone(populationDTO.getPhone());
|
||||
populationInfoDTO.setIdcardType("身份证");
|
||||
populationInfoService.getTuoMin(populationInfoDTO);
|
||||
return populationInfoDTO;
|
||||
}
|
||||
|
||||
private List<PopulationDTO> listBatch(Map<String, Object> params) {
|
||||
List<PopulationDTO> list = populationDao.listBatch(params);
|
||||
return list;
|
||||
@ -462,9 +467,35 @@ public class PopulationServiceImpl extends AbstractService implements IPopulatio
|
||||
// 一次性获取所有的房屋信息
|
||||
List<HouseDTO> houseDTOs = houseService.getBatch(houseIds);
|
||||
|
||||
// 获取base
|
||||
List<PopulationInfoBaseDTO> populationInfoBaseDTOs = new ArrayList<>();
|
||||
int size = populationInfoIds.size();
|
||||
int numThreads = size / 2 + (size % 2 == 0 ? 0 : 1); // 计算需要的线程数
|
||||
ExecutorService executorService = Executors.newFixedThreadPool(numThreads);
|
||||
|
||||
Callable<List<PopulationInfoBaseDTO>> task = () -> {
|
||||
List<PopulationInfoBaseDTO> output = new ArrayList<>();
|
||||
for (String str : populationInfoIds) {
|
||||
PopulationInfoBaseDTO base = populationInfoService.getBase(str);
|
||||
output.add(base);
|
||||
}
|
||||
return output;
|
||||
};
|
||||
|
||||
Future<List<PopulationInfoBaseDTO>> futureResult = executorService.submit(task);
|
||||
try {
|
||||
List<PopulationInfoBaseDTO> result = futureResult.get();
|
||||
populationInfoBaseDTOs.addAll(result);
|
||||
executorService.shutdown();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Map<String, PopulationInfoDTO> populationInfoMap = null;
|
||||
Map<String, HouseDTO> houseMap = null;
|
||||
Map<String, PopulationInfoBaseDTO> baseMap = null;
|
||||
if (!CollectionUtils.isEmpty(populationInfoDTOs)) {
|
||||
populationInfoMap = populationInfoDTOs.stream()
|
||||
.collect(Collectors.toMap(PopulationInfoDTO::getPopulationInfoId,
|
||||
@ -477,33 +508,29 @@ public class PopulationServiceImpl extends AbstractService implements IPopulatio
|
||||
houseDTO -> houseDTO));
|
||||
}
|
||||
|
||||
for (PopulationDTO populationDTO : overList) {
|
||||
if (StringUtils.isNotEmpty(populationDTO.getPopulationInfoId())) {
|
||||
PopulationInfoDTO populationInfoDTO;
|
||||
if(null != populationInfoMap) {
|
||||
populationInfoDTO = populationInfoMap.get(populationDTO.getPopulationInfoId());
|
||||
populationInfoService.getTuoMin(populationInfoDTO);
|
||||
}else {
|
||||
populationInfoDTO = setPopulationInfo(populationDTO);
|
||||
if (!CollectionUtils.isEmpty(populationInfoBaseDTOs)) {
|
||||
baseMap = populationInfoBaseDTOs.stream()
|
||||
.collect(Collectors.toMap(PopulationInfoBaseDTO::getPopulationInfoId,
|
||||
baseDTO -> baseDTO));
|
||||
}
|
||||
|
||||
PopulationInfoHouseDTO populationInfoHouseDTO = new PopulationInfoHouseDTO();
|
||||
BeanUtils.copyProperties(populationInfoDTO, populationInfoHouseDTO);
|
||||
|
||||
|
||||
for (PopulationDTO populationDTO : overList) {
|
||||
if (StringUtils.isNotEmpty(populationDTO.getPopulationInfoId())) {
|
||||
PopulationInfoBaseDTO populationInfoBaseDTO=null;
|
||||
if (null != baseMap) {
|
||||
// 获取人员
|
||||
PopulationInfoBaseDTO base = populationInfoService.getBase(populationDTO.getPopulationInfoId());
|
||||
// populationInfoService.getTuoMin(base);
|
||||
populationInfoHouseDTO.setPopulationInfoBaseDTO(base);
|
||||
|
||||
populationDTO.setPopulationInfoHouseDTO(populationInfoHouseDTO);
|
||||
populationDTO.setPopulationInfoDTO(populationInfoDTO);
|
||||
populationInfoBaseDTO = baseMap.get(populationDTO.getPopulationInfoId());
|
||||
}else {
|
||||
populationInfoBaseDTO = setPopulationBaseInfo(populationDTO);
|
||||
}
|
||||
populationInfoService.getTuoMin(populationInfoBaseDTO);
|
||||
populationDTO.setPopulationInfoBaseDTO(populationInfoBaseDTO);
|
||||
} else {
|
||||
PopulationInfoDTO populationInfoDTO = setPopulationInfo(populationDTO);
|
||||
populationDTO.setPopulationInfoDTO(populationInfoDTO);
|
||||
}
|
||||
|
||||
if(null != houseMap) {
|
||||
if (null != houseMap) {
|
||||
HouseDTO houseDTO = houseMap.get(populationDTO.getHouseId());
|
||||
populationDTO.setHouseDTO(houseDTO);
|
||||
}
|
||||
@ -555,4 +582,22 @@ public class PopulationServiceImpl extends AbstractService implements IPopulatio
|
||||
return new SuccessResultList<>(populationDTOs, pageInfo.getPageNum(), pageInfo.getTotal());
|
||||
}
|
||||
|
||||
public class getBase implements Runnable {
|
||||
private List<String> dataList;
|
||||
private List<PopulationInfoBaseDTO> baseDTOList;
|
||||
|
||||
public getBase(List<String> dataList, List<PopulationInfoBaseDTO> baseDTOList) {
|
||||
this.dataList = dataList;
|
||||
this.baseDTOList = baseDTOList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (String s : dataList) {
|
||||
PopulationInfoBaseDTO base = populationInfoService.getBase(s);
|
||||
baseDTOList.add(base);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user