批量创建房屋改为多线程方式 --renpc
This commit is contained in:
parent
451f13aff7
commit
2f4995963f
@ -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<PopulationVO> 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<PopulationVO> 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<HouseVO> 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<HouseVO> subList = houseVOList.subList(i, end);
|
||||
executorService.submit(new saveHouse(subList, userInfoBO));
|
||||
}
|
||||
|
||||
executorService.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
public class saveHouse implements Runnable {
|
||||
private List<HouseVO> dataList;
|
||||
private UserInfoBO userInfoBO;
|
||||
|
||||
public saveHouse(List<HouseVO> dataList, UserInfoBO userInfoBO) {
|
||||
this.dataList = dataList;
|
||||
this.userInfoBO = userInfoBO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (HouseVO houseVO : dataList) {
|
||||
String houseId = UUIDUtil.getUUID();
|
||||
Map<String, Object> 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<String, Object> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -795,6 +795,7 @@
|
||||
hp.population_info_id = #{populationInfoId}
|
||||
)
|
||||
</if>
|
||||
ORDER BY house_num ASC
|
||||
</select>
|
||||
|
||||
<!-- 房院管理列表 -->
|
||||
|
Loading…
Reference in New Issue
Block a user