以房找人bug修改 --renpc
This commit is contained in:
parent
c884d12a85
commit
b520ff9905
@ -112,12 +112,12 @@ public class PopulationInfoBaseDTO {
|
||||
this.healthStatus = healthStatus;
|
||||
}
|
||||
|
||||
public String getIsMinority() {
|
||||
/*public String getIsMinority() {
|
||||
if (getAge() < 18) {
|
||||
return "是";
|
||||
}
|
||||
return "否";
|
||||
}
|
||||
}*/
|
||||
|
||||
public void setIsMinority(String isMinority) {
|
||||
this.isMinority = isMinority;
|
||||
@ -134,14 +134,14 @@ public class PopulationInfoBaseDTO {
|
||||
this.isSeriousIllness = isSeriousIllness;
|
||||
}
|
||||
|
||||
public Integer getAge() {
|
||||
/*public Integer getAge() {
|
||||
if (StringUtils.isBlank(this.getBirthday())) {
|
||||
return 0;
|
||||
}
|
||||
LocalDate birthDate = LocalDate.parse(this.birthday);
|
||||
Period period = Period.between(birthDate, LocalDate.now());
|
||||
return period.getYears();
|
||||
}
|
||||
}*/
|
||||
|
||||
public void setAge(Integer age) {
|
||||
this.age = age;
|
||||
|
@ -21,6 +21,7 @@ import com.cm.population.service.population.IPopulationService;
|
||||
import com.cm.population.service.populationinfo.IPopulationInfoService;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -470,27 +471,40 @@ public class PopulationServiceImpl extends AbstractService implements IPopulatio
|
||||
int size = populationInfoIds.size();
|
||||
int numThreads = size / 2 + (size % 2 == 0 ? 0 : 1); // 计算需要的线程数
|
||||
ExecutorService executorService = Executors.newFixedThreadPool(numThreads);
|
||||
List<Future<List<PopulationInfoBaseDTO>>> futures = new ArrayList<>();
|
||||
|
||||
Callable<List<PopulationInfoBaseDTO>> task = () -> {
|
||||
List<PopulationInfoBaseDTO> output = new ArrayList<>();
|
||||
for (String str : populationInfoIds) {
|
||||
PopulationInfoBaseDTO base = populationInfoService.getBase(str);
|
||||
output.add(base);
|
||||
}
|
||||
return output;
|
||||
};
|
||||
// 将populationInfoIds分割成多个子列表,每个子列表由一个任务处理
|
||||
int chunkSize = (int) Math.ceil((double) populationInfoIds.size() / numThreads);
|
||||
List<List<String>> chunks = Lists.partition(populationInfoIds, chunkSize);
|
||||
|
||||
Future<List<PopulationInfoBaseDTO>> futureResult = executorService.submit(task);
|
||||
try {
|
||||
List<PopulationInfoBaseDTO> result = futureResult.get();
|
||||
populationInfoBaseDTOs.addAll(result);
|
||||
executorService.shutdown();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
for (List<String> chunk : chunks) {
|
||||
Callable<List<PopulationInfoBaseDTO>> task = () -> {
|
||||
List<PopulationInfoBaseDTO> output = new ArrayList<>();
|
||||
for (String str : chunk) {
|
||||
try {
|
||||
PopulationInfoBaseDTO base = populationInfoService.getBase(str);
|
||||
output.add(base);
|
||||
} catch (Exception e) {
|
||||
// 处理或记录异常
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return output;
|
||||
};
|
||||
futures.add(executorService.submit(task));
|
||||
}
|
||||
|
||||
// 等待所有任务完成并合并结果
|
||||
for (Future<List<PopulationInfoBaseDTO>> future : futures) {
|
||||
try {
|
||||
populationInfoBaseDTOs.addAll(future.get());
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
// 处理或记录异常
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
executorService.shutdown(); // 关闭线程池
|
||||
|
||||
Map<String, HouseDTO> houseMap = null;
|
||||
Map<String, PopulationInfoBaseDTO> baseMap = null;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user