From a61ad138416ad1df0875e6216e65ff5ade4f5b32 Mon Sep 17 00:00:00 2001 From: Renpc-kilig <308442850@qq.com> Date: Fri, 24 Nov 2023 17:44:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A5=E4=BA=BA=E6=89=BE?= =?UTF-8?q?=E6=88=BF=EF=BC=8C=E4=BB=A5=E6=88=BF=E6=89=BE=E4=BA=BA=20=20--r?= =?UTF-8?q?enpc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pojo/dtos/population/PopulationDTO.java | 23 ++--- .../impl/PopulationServiceImpl.java | 95 ++++++++++++++----- 2 files changed, 82 insertions(+), 36 deletions(-) diff --git a/src/main/java/com/cm/population/pojo/dtos/population/PopulationDTO.java b/src/main/java/com/cm/population/pojo/dtos/population/PopulationDTO.java index 7feddfd..5e928e6 100644 --- a/src/main/java/com/cm/population/pojo/dtos/population/PopulationDTO.java +++ b/src/main/java/com/cm/population/pojo/dtos/population/PopulationDTO.java @@ -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; + } } diff --git a/src/main/java/com/cm/population/service/population/impl/PopulationServiceImpl.java b/src/main/java/com/cm/population/service/population/impl/PopulationServiceImpl.java index 2a7378c..34d0926 100644 --- a/src/main/java/com/cm/population/service/population/impl/PopulationServiceImpl.java +++ b/src/main/java/com/cm/population/service/population/impl/PopulationServiceImpl.java @@ -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 listBatch(Map params) { List list = populationDao.listBatch(params); return list; @@ -462,9 +467,35 @@ public class PopulationServiceImpl extends AbstractService implements IPopulatio // 一次性获取所有的房屋信息 List houseDTOs = houseService.getBatch(houseIds); + // 获取base + List populationInfoBaseDTOs = new ArrayList<>(); + int size = populationInfoIds.size(); + int numThreads = size / 2 + (size % 2 == 0 ? 0 : 1); // 计算需要的线程数 + ExecutorService executorService = Executors.newFixedThreadPool(numThreads); + + Callable> task = () -> { + List output = new ArrayList<>(); + for (String str : populationInfoIds) { + PopulationInfoBaseDTO base = populationInfoService.getBase(str); + output.add(base); + } + return output; + }; + + Future> futureResult = executorService.submit(task); + try { + List result = futureResult.get(); + populationInfoBaseDTOs.addAll(result); + executorService.shutdown(); + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (ExecutionException e) { + e.printStackTrace(); + } Map populationInfoMap = null; Map houseMap = null; + Map 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)); } + if (!CollectionUtils.isEmpty(populationInfoBaseDTOs)) { + baseMap = populationInfoBaseDTOs.stream() + .collect(Collectors.toMap(PopulationInfoBaseDTO::getPopulationInfoId, + baseDTO -> baseDTO)); + } + for (PopulationDTO populationDTO : overList) { if (StringUtils.isNotEmpty(populationDTO.getPopulationInfoId())) { - PopulationInfoDTO populationInfoDTO; - if(null != populationInfoMap) { - populationInfoDTO = populationInfoMap.get(populationDTO.getPopulationInfoId()); - populationInfoService.getTuoMin(populationInfoDTO); + PopulationInfoBaseDTO populationInfoBaseDTO=null; + if (null != baseMap) { + // 获取人员 + populationInfoBaseDTO = baseMap.get(populationDTO.getPopulationInfoId()); }else { - populationInfoDTO = setPopulationInfo(populationDTO); + populationInfoBaseDTO = setPopulationBaseInfo(populationDTO); } - - PopulationInfoHouseDTO populationInfoHouseDTO = new PopulationInfoHouseDTO(); - BeanUtils.copyProperties(populationInfoDTO, populationInfoHouseDTO); - - - // 获取人员 - PopulationInfoBaseDTO base = populationInfoService.getBase(populationDTO.getPopulationInfoId()); - // populationInfoService.getTuoMin(base); - populationInfoHouseDTO.setPopulationInfoBaseDTO(base); - - populationDTO.setPopulationInfoHouseDTO(populationInfoHouseDTO); - populationDTO.setPopulationInfoDTO(populationInfoDTO); - }else { + 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 dataList; + private List baseDTOList; + + public getBase(List dataList, List baseDTOList) { + this.dataList = dataList; + this.baseDTOList = baseDTOList; + } + + @Override + public void run() { + for (String s : dataList) { + PopulationInfoBaseDTO base = populationInfoService.getBase(s); + baseDTOList.add(base); + } + } + } + } \ No newline at end of file