From 27df6462b390be991320fc1dafea0a81e078bbb9 Mon Sep 17 00:00:00 2001 From: Renpc-kilig <308442850@qq.com> Date: Mon, 15 Jan 2024 18:03:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B2=A1=E6=9C=89=E6=88=BF=E4=B8=BB=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E7=9A=84=E6=88=BF=E5=B1=8B=EF=BC=8C=E5=B0=86=E5=90=8C?= =?UTF-8?q?=E4=BD=8F=E4=BA=BA=E7=AC=AC=E4=B8=80=E6=9D=A1=E5=A1=AB=E5=85=85?= =?UTF-8?q?=E4=B8=BA=E6=88=BF=E4=B8=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/population/PopulationController.java | 8 + .../cm/population/dao/house/IHouseDao.java | 4 + .../population/IPopulationService.java | 4 +- .../impl/PopulationServiceImpl.java | 84 +++++++ .../mybatis/mapper/house/house-mapper.xml | 232 ++++++++++++++++++ 5 files changed, 331 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/cm/population/controller/api/population/PopulationController.java b/src/main/java/com/cm/population/controller/api/population/PopulationController.java index 232a3ad..c2149ba 100644 --- a/src/main/java/com/cm/population/controller/api/population/PopulationController.java +++ b/src/main/java/com/cm/population/controller/api/population/PopulationController.java @@ -159,4 +159,12 @@ public class PopulationController extends AbstractController { return populationService.findPopulation(page); } + @ApiOperation(value = "房屋列表(房主)", notes = "房屋列表(房主)接口") + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("houseOwner") + public List houseOwner() { + Map params = requestParams(); + return populationService.houseOwner(params); + } + } \ No newline at end of file diff --git a/src/main/java/com/cm/population/dao/house/IHouseDao.java b/src/main/java/com/cm/population/dao/house/IHouseDao.java index 80b06d2..bd45d89 100644 --- a/src/main/java/com/cm/population/dao/house/IHouseDao.java +++ b/src/main/java/com/cm/population/dao/house/IHouseDao.java @@ -131,4 +131,8 @@ public interface IHouseDao { List getBatch(Map params); List getUserHouse(HashMap objectObjectHashMap); + + List getNoOwnerList(Map params); + + List getHasOwnerList(Map params); } \ No newline at end of file diff --git a/src/main/java/com/cm/population/service/population/IPopulationService.java b/src/main/java/com/cm/population/service/population/IPopulationService.java index bc26fe3..bb2c29d 100644 --- a/src/main/java/com/cm/population/service/population/IPopulationService.java +++ b/src/main/java/com/cm/population/service/population/IPopulationService.java @@ -212,7 +212,7 @@ public interface IPopulationService { * @param page * @return */ - SuccessResultList> findPopulation(ListPage pag); + SuccessResultList> findPopulation(ListPage page); /** * 搬离房屋 @@ -220,4 +220,6 @@ public interface IPopulationService { void updateOuthouseTrue(String token, List populationIds) ; SuccessResultList> listPageAll(ListPage page); + + List houseOwner(Map params); } \ No newline at end of file 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 99b795b..b31c6d3 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 @@ -30,6 +30,7 @@ import org.springframework.util.CollectionUtils; import javax.mail.search.SearchException; import java.util.*; import java.util.concurrent.*; +import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; /** @@ -640,4 +641,87 @@ public class PopulationServiceImpl extends AbstractService implements IPopulatio return new SuccessResultList<>(populationDTOs, pageInfo.getPageNum(), pageInfo.getTotal()); } + @Override + public List houseOwner(Map params) { + // 获取没有房主的房屋 + List noHomeOwner = houseDao.getNoOwnerList(params); + // 获取有房主的房屋 + List hasHomeOwner = houseDao.getHasOwnerList(params); + + this.setHomeOwner(noHomeOwner, params); + + List houseDTOs = new ArrayList<>(); + houseDTOs.addAll(noHomeOwner); + houseDTOs.addAll(hasHomeOwner); + + System.out.println(houseDTOs.size()); + + return houseDTOs; + } + + /** + * 遍历房屋信息 + * 存在房主信息,不做处理 + * 不存在房主信息,则查找房屋同住人,将第一个人填充成为房主 + * + * @param houseDTOList + * @param params + */ + private void setHomeOwner(List houseDTOList, Map params) { + // 遍历房屋信息 + // 存在房主信息,不做处理 + // 不存在房主信息,则查找房屋同住人,将第一个人填充成为房主 + int size = houseDTOList.size(); + // 计算需要的线程数 + int numThreads = size / 2500 + (size % 2500 == 0 ? 0 : 1); + numThreads = numThreads == 0 ? 1 : numThreads; + ExecutorService executorService = Executors.newFixedThreadPool(numThreads); + // 获取base + List> futures = new ArrayList<>(); + + // 将houseDTOs分割成多个子列表,每个子列表由一个任务处理 + int chunkSize = (int) Math.ceil((double) houseDTOList.size() / numThreads); + chunkSize = chunkSize == 0 ? 1 : chunkSize; + List> chunks = Lists.partition(houseDTOList, chunkSize); + + for (List chunk : chunks) { + Future future = executorService.submit(() -> { + for (HouseDTO houseDTO : chunk) { + params.put("houseId", houseDTO.getHouseId()); + try { + if (StringUtils.isEmpty(houseDTO.getHomeowner())) { + // 获取同住人 + List populationDTOList = list(params); + if (!CollectionUtils.isEmpty(populationDTOList)) { + PopulationDTO populationDTO = populationDTOList.get(0); + houseDTO.setHomeowner(populationDTO.getName()); + houseDTO.setOwnerPopulationId(populationDTO.getPopulationInfoId()); + houseDTO.setDocumentNum(populationDTO.getCardNum()); + houseDTO.setPhone(populationDTO.getPhone()); + } + } + } catch (Exception e) { + // 处理或记录异常 + e.printStackTrace(); + } + } + return null; + }); + futures.add(future); + } + + // 等待所有异步任务完成 + for (Future future : futures) { + try { + future.get(); + } catch (Exception e) { + // 处理异常 + e.printStackTrace(); + } + } + + // 关闭线程池 + executorService.shutdown(); + } + } \ No newline at end of file diff --git a/src/main/resources/mybatis/mapper/house/house-mapper.xml b/src/main/resources/mybatis/mapper/house/house-mapper.xml index 5c4299d..d7176e0 100644 --- a/src/main/resources/mybatis/mapper/house/house-mapper.xml +++ b/src/main/resources/mybatis/mapper/house/house-mapper.xml @@ -1266,4 +1266,236 @@ OR (t1.custodian_document_num IS NOT NULL AND t1.custodian_document_num <> '') + + + + \ No newline at end of file