From 2f4995963f43045e531a313f8bae4c099ce10e58 Mon Sep 17 00:00:00 2001 From: Renpc-kilig <308442850@qq.com> Date: Mon, 20 Nov 2023 11:52:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=B9=E9=87=8F=E5=88=9B=E5=BB=BA=E6=88=BF?= =?UTF-8?q?=E5=B1=8B=E6=94=B9=E4=B8=BA=E5=A4=9A=E7=BA=BF=E7=A8=8B=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=20=20--renpc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/house/impl/HouseServiceImpl.java | 104 ++++++++++++++---- .../com/cm/population/utils/AreaUtils.java | 4 +- .../mybatis/mapper/house/house-mapper.xml | 1 + 3 files changed, 87 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/cm/population/service/house/impl/HouseServiceImpl.java b/src/main/java/com/cm/population/service/house/impl/HouseServiceImpl.java index ece7c54..e4ed13c 100644 --- a/src/main/java/com/cm/population/service/house/impl/HouseServiceImpl.java +++ b/src/main/java/com/cm/population/service/house/impl/HouseServiceImpl.java @@ -4,6 +4,7 @@ import com.cm.common.base.AbstractService; import com.cm.common.pojo.ListPage; import com.cm.common.pojo.bos.UserInfoBO; import com.cm.common.result.SuccessResultList; +import com.cm.common.utils.DateUtil; import com.cm.common.utils.HashMapUtil; import com.cm.common.utils.UUIDUtil; import com.cm.population.dao.house.IHouseDao; @@ -30,9 +31,15 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; /** * @ClassName: HouseServiceImpl @@ -87,7 +94,7 @@ public class HouseServiceImpl extends AbstractService implements IHouseService { } houseDao.save(params); - if(!CollectionUtils.isEmpty(houseVO.getPopulationVOList())) { + if (!CollectionUtils.isEmpty(houseVO.getPopulationVOList())) { List populationVOList = houseVO.getPopulationVOList(); for (PopulationVO populationVO : populationVOList) { populationVO.setHouseId(houseId); @@ -144,17 +151,17 @@ public class HouseServiceImpl extends AbstractService implements IHouseService { // 1. 判断创建房屋时,是否有人员信息一起 // 2. 有的话,删除旧的人员信息,并录入新的人员信息 - if(!CollectionUtils.isEmpty(houseVO.getPopulationVOList())) { + if (!CollectionUtils.isEmpty(houseVO.getPopulationVOList())) { List populationVOList = houseVO.getPopulationVOList(); for (PopulationVO populationVO : populationVOList) { - if("1".equals(populationVO.getOutHouse())) { + if ("1".equals(populationVO.getOutHouse())) { populationService.update(populationVO.getPopulationId(), populationVO); } } populationdao.deleteByHouseId(houseId); for (PopulationVO populationVO : populationVOList) { - if(!"1".equals(populationVO.getOutHouse())) { + if (!"1".equals(populationVO.getOutHouse())) { populationVO.setHouseId(houseId); populationService.save(token, populationVO); } @@ -300,7 +307,7 @@ public class HouseServiceImpl extends AbstractService implements IHouseService { house.setHouseId(houseDTO.getHouseId()); house.setName(houseDTO.getHouseNum().toString()); house.setGmtCreate(houseDTO.getGmtCreate()); - if(userId.equals(houseDTO.getCreator()) || isAdmin()) { + if (userId.equals(houseDTO.getCreator()) || isAdmin()) { house.setIsCreator(1); // 获取当前房屋内的人数 params.put("houseId", houseDTO.getHouseId()); @@ -398,6 +405,10 @@ public class HouseServiceImpl extends AbstractService implements IHouseService { @Override public void saveAuto(String token, AutoHouseDTO autoHouseDTO) { + UserInfoBO userInfoBO = this.securityComponent.getCurrentUser(); + + List houseVOList = new ArrayList<>(); + String buildingId = autoHouseDTO.getBuildingId(); BuildingDTO buildingDTO = buildingService.get(buildingId); @@ -411,26 +422,79 @@ public class HouseServiceImpl extends AbstractService implements IHouseService { for (int unit = 1; unit <= unitNum; unit++) { for (int floor = 1; floor <= floorsNum; floor++) { - HouseVO houseVO = new HouseVO(); - // 基本信息:街道、社区、小区、楼栋 - houseVO.setStreet(buildingDTO.getStreet()); - houseVO.setStreetName(buildingDTO.getStreetName()); - houseVO.setCommunity(buildingDTO.getCommunity()); - houseVO.setCommunityName(buildingDTO.getCommunityName()); - houseVO.setResidentialId(buildingDTO.getResidentialId()); - houseVO.setResidentialName(buildingDTO.getResidentialName()); - houseVO.setBuildingId(buildingDTO.getBuildingId()); - houseVO.setBuildingName(buildingDTO.getName()); - - // 房屋信息:单元、楼层、房号 - houseVO.setAffiliationUnit("" + unit); - houseVO.setAffiliationFloors(String.valueOf(floor)); for (int house = 1; house <= houseCount; house++) { + HouseVO houseVO = new HouseVO(); + // 基本信息:街道、社区、小区、楼栋 + houseVO.setStreet(buildingDTO.getStreet()); + houseVO.setStreetName(buildingDTO.getStreetName()); + houseVO.setCommunity(buildingDTO.getCommunity()); + houseVO.setCommunityName(buildingDTO.getCommunityName()); + houseVO.setResidentialId(buildingDTO.getResidentialId()); + houseVO.setResidentialName(buildingDTO.getResidentialName()); + houseVO.setBuildingId(buildingDTO.getBuildingId()); + houseVO.setBuildingName(buildingDTO.getName()); + + // 房屋信息:单元、楼层、房号 + houseVO.setAffiliationUnit("" + unit); + houseVO.setAffiliationFloors(String.valueOf(floor)); houseVO.setHouseNum(floor + "0" + house); - save(token, houseVO); + System.out.println(floor + "0" + house); + houseVOList.add(houseVO); } } } + + int size = houseVOList.size(); + int numThreads = size / 5 + (size % 5 == 0 ? 0 : 1); // 计算需要的线程数 + + ExecutorService executorService = Executors.newFixedThreadPool(numThreads); + + for (int i = 0; i < size; i += 5) { + int end = Math.min(i + 5, size); + List subList = houseVOList.subList(i, end); + executorService.submit(new saveHouse(subList, userInfoBO)); + } + + executorService.shutdown(); + } + } + + public class saveHouse implements Runnable { + private List dataList; + private UserInfoBO userInfoBO; + + public saveHouse(List dataList, UserInfoBO userInfoBO) { + this.dataList = dataList; + this.userInfoBO = userInfoBO; + } + + @Override + public void run() { + for (HouseVO houseVO : dataList) { + String houseId = UUIDUtil.getUUID(); + Map params = null; + try { + params = HashMapUtil.beanToMap(houseVO); + } catch (Exception e) { + e.printStackTrace(); + } + params.put("houseId", houseId); + if (userInfoBO != null) { + this.setSave(userInfoBO.getUserId(), params); + } else { + this.setSave("1", params); + } + houseDao.save(params); + } + } + + private void setSave(String userId, Map params) { + String currentDate = DateUtil.getTime(); + params.put("creator", userId); + params.put("gmtCreate", currentDate); + params.put("modifier", userId); + params.put("gmtModified", currentDate); + params.put("isDelete", 0); } } diff --git a/src/main/java/com/cm/population/utils/AreaUtils.java b/src/main/java/com/cm/population/utils/AreaUtils.java index 130db51..6055ad3 100644 --- a/src/main/java/com/cm/population/utils/AreaUtils.java +++ b/src/main/java/com/cm/population/utils/AreaUtils.java @@ -32,11 +32,11 @@ public class AreaUtils { @PostConstruct public void init() { PopulationInfoStaticService = PopulationInfoService; - initArea0(); + /*initArea0(); initArea1(); initArea2(); initArea3(); - initArea4(); + initArea4();*/ aree.put(0, area0); aree.put(1, area1); aree.put(2, area2); diff --git a/src/main/resources/mybatis/mapper/house/house-mapper.xml b/src/main/resources/mybatis/mapper/house/house-mapper.xml index 734dfc3..54c18b4 100644 --- a/src/main/resources/mybatis/mapper/house/house-mapper.xml +++ b/src/main/resources/mybatis/mapper/house/house-mapper.xml @@ -795,6 +795,7 @@ hp.population_info_id = #{populationInfoId} ) + ORDER BY house_num ASC