批量创建房屋改为多线程方式 --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.ListPage;
|
||||||
import com.cm.common.pojo.bos.UserInfoBO;
|
import com.cm.common.pojo.bos.UserInfoBO;
|
||||||
import com.cm.common.result.SuccessResultList;
|
import com.cm.common.result.SuccessResultList;
|
||||||
|
import com.cm.common.utils.DateUtil;
|
||||||
import com.cm.common.utils.HashMapUtil;
|
import com.cm.common.utils.HashMapUtil;
|
||||||
import com.cm.common.utils.UUIDUtil;
|
import com.cm.common.utils.UUIDUtil;
|
||||||
import com.cm.population.dao.house.IHouseDao;
|
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.stereotype.Service;
|
||||||
import org.springframework.util.CollectionUtils;
|
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.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ClassName: HouseServiceImpl
|
* @ClassName: HouseServiceImpl
|
||||||
@ -398,6 +405,10 @@ public class HouseServiceImpl extends AbstractService implements IHouseService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveAuto(String token, AutoHouseDTO autoHouseDTO) {
|
public void saveAuto(String token, AutoHouseDTO autoHouseDTO) {
|
||||||
|
UserInfoBO userInfoBO = this.securityComponent.getCurrentUser();
|
||||||
|
|
||||||
|
List<HouseVO> houseVOList = new ArrayList<>();
|
||||||
|
|
||||||
String buildingId = autoHouseDTO.getBuildingId();
|
String buildingId = autoHouseDTO.getBuildingId();
|
||||||
|
|
||||||
BuildingDTO buildingDTO = buildingService.get(buildingId);
|
BuildingDTO buildingDTO = buildingService.get(buildingId);
|
||||||
@ -411,6 +422,7 @@ public class HouseServiceImpl extends AbstractService implements IHouseService {
|
|||||||
|
|
||||||
for (int unit = 1; unit <= unitNum; unit++) {
|
for (int unit = 1; unit <= unitNum; unit++) {
|
||||||
for (int floor = 1; floor <= floorsNum; floor++) {
|
for (int floor = 1; floor <= floorsNum; floor++) {
|
||||||
|
for (int house = 1; house <= houseCount; house++) {
|
||||||
HouseVO houseVO = new HouseVO();
|
HouseVO houseVO = new HouseVO();
|
||||||
// 基本信息:街道、社区、小区、楼栋
|
// 基本信息:街道、社区、小区、楼栋
|
||||||
houseVO.setStreet(buildingDTO.getStreet());
|
houseVO.setStreet(buildingDTO.getStreet());
|
||||||
@ -425,13 +437,65 @@ public class HouseServiceImpl extends AbstractService implements IHouseService {
|
|||||||
// 房屋信息:单元、楼层、房号
|
// 房屋信息:单元、楼层、房号
|
||||||
houseVO.setAffiliationUnit("" + unit);
|
houseVO.setAffiliationUnit("" + unit);
|
||||||
houseVO.setAffiliationFloors(String.valueOf(floor));
|
houseVO.setAffiliationFloors(String.valueOf(floor));
|
||||||
for (int house = 1; house <= houseCount; house++) {
|
|
||||||
houseVO.setHouseNum(floor + "0" + house);
|
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
|
@PostConstruct
|
||||||
public void init() {
|
public void init() {
|
||||||
PopulationInfoStaticService = PopulationInfoService;
|
PopulationInfoStaticService = PopulationInfoService;
|
||||||
initArea0();
|
/*initArea0();
|
||||||
initArea1();
|
initArea1();
|
||||||
initArea2();
|
initArea2();
|
||||||
initArea3();
|
initArea3();
|
||||||
initArea4();
|
initArea4();*/
|
||||||
aree.put(0, area0);
|
aree.put(0, area0);
|
||||||
aree.put(1, area1);
|
aree.put(1, area1);
|
||||||
aree.put(2, area2);
|
aree.put(2, area2);
|
||||||
|
@ -795,6 +795,7 @@
|
|||||||
hp.population_info_id = #{populationInfoId}
|
hp.population_info_id = #{populationInfoId}
|
||||||
)
|
)
|
||||||
</if>
|
</if>
|
||||||
|
ORDER BY house_num ASC
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<!-- 房院管理列表 -->
|
<!-- 房院管理列表 -->
|
||||||
|
Loading…
Reference in New Issue
Block a user