|
@ -1,5 +1,6 @@ |
|
|
package org.dromara.platform.service.impl; |
|
|
package org.dromara.platform.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import jakarta.annotation.Resource; |
|
|
import org.dromara.common.core.utils.MapstructUtils; |
|
|
import org.dromara.common.core.utils.MapstructUtils; |
|
|
import org.dromara.common.core.utils.StringUtils; |
|
|
import org.dromara.common.core.utils.StringUtils; |
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo; |
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo; |
|
@ -8,8 +9,13 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
|
|
import org.dromara.platform.domain.ProjectCategoryPoint; |
|
|
|
|
|
import org.dromara.platform.domain.bo.ProjectCategoryPointBo; |
|
|
import org.dromara.platform.domain.vo.DailyInspectionReportVo; |
|
|
import org.dromara.platform.domain.vo.DailyInspectionReportVo; |
|
|
import org.dromara.platform.domain.vo.PointSelectVo; |
|
|
import org.dromara.platform.domain.vo.PointSelectVo; |
|
|
|
|
|
import org.dromara.platform.domain.vo.ProjectCategoryPointVo; |
|
|
|
|
|
import org.dromara.platform.service.IProjectCategoryPointService; |
|
|
|
|
|
import org.dromara.platform.service.IProjectInfoService; |
|
|
import org.springframework.beans.BeanUtils; |
|
|
import org.springframework.beans.BeanUtils; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.dromara.platform.domain.bo.PointInfoBo; |
|
|
import org.dromara.platform.domain.bo.PointInfoBo; |
|
@ -19,6 +25,7 @@ import org.dromara.platform.mapper.PointInfoMapper; |
|
|
import org.dromara.platform.service.IPointInfoService; |
|
|
import org.dromara.platform.service.IPointInfoService; |
|
|
|
|
|
|
|
|
import java.util.*; |
|
|
import java.util.*; |
|
|
|
|
|
import java.util.concurrent.*; |
|
|
import java.util.stream.Collectors; |
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -32,6 +39,12 @@ import java.util.stream.Collectors; |
|
|
public class PointInfoServiceImpl implements IPointInfoService { |
|
|
public class PointInfoServiceImpl implements IPointInfoService { |
|
|
|
|
|
|
|
|
private final PointInfoMapper baseMapper; |
|
|
private final PointInfoMapper baseMapper; |
|
|
|
|
|
@Resource |
|
|
|
|
|
private IProjectCategoryPointService projectCategoryPointService; |
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
|
private IProjectInfoService projectInfoService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 查询点位信息 |
|
|
* 查询点位信息 |
|
@ -164,8 +177,54 @@ public class PointInfoServiceImpl implements IPointInfoService { |
|
|
return pointSelectVos; |
|
|
return pointSelectVos; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 自定义线程池
|
|
|
|
|
|
private static final int CORE_POOL_SIZE = Runtime.getRuntime().availableProcessors() * 2; |
|
|
|
|
|
private static final ExecutorService taskExecutor = new ThreadPoolExecutor( |
|
|
|
|
|
CORE_POOL_SIZE, // 核心线程数
|
|
|
|
|
|
CORE_POOL_SIZE * 2, // 最大线程数
|
|
|
|
|
|
60L, TimeUnit.SECONDS, // 空闲线程存活时间
|
|
|
|
|
|
new LinkedBlockingQueue<>(200), // 队列容量
|
|
|
|
|
|
new ThreadPoolExecutor.CallerRunsPolicy() // 拒绝策略
|
|
|
|
|
|
); |
|
|
@Override |
|
|
@Override |
|
|
public void addData(List<PointInfo> list) { |
|
|
public void addData(List<PointInfo> list) { |
|
|
|
|
|
// 1. 查询 projectMap
|
|
|
|
|
|
List<ProjectCategoryPointVo> categoryPointVos = projectCategoryPointService.queryList(new ProjectCategoryPointBo()); |
|
|
|
|
|
Map<String, String> projectMap = categoryPointVos.stream() |
|
|
|
|
|
.collect(Collectors.toMap( |
|
|
|
|
|
ProjectCategoryPointVo::getProjectName, |
|
|
|
|
|
ProjectCategoryPointVo::getProjectId, |
|
|
|
|
|
(a, b) -> a |
|
|
|
|
|
)); |
|
|
|
|
|
|
|
|
|
|
|
// 2. 并发处理每个 PointInfo 对象
|
|
|
|
|
|
List<CompletableFuture<Void>> futureList = list.stream().map(pointInfo -> |
|
|
|
|
|
CompletableFuture.runAsync(() -> { |
|
|
|
|
|
try { |
|
|
|
|
|
String organizationName = pointInfo.getOrganizationName(); |
|
|
|
|
|
String projectName = pointInfo.getProjectName(); |
|
|
|
|
|
|
|
|
|
|
|
// 设置 projectId
|
|
|
|
|
|
String projectId = projectMap.get(organizationName); |
|
|
|
|
|
if (projectId != null) { |
|
|
|
|
|
pointInfo.setProjectId(projectId); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 调用远程服务获取单位信息(耗时操作)
|
|
|
|
|
|
String unit = projectInfoService.getContractPartyBNameByProjectName(projectName); |
|
|
|
|
|
if (unit != null) { |
|
|
|
|
|
pointInfo.setMaintenanceUnit(unit); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
System.err.println("处理错误:Error processing PointInfo: " + e.getMessage()); |
|
|
|
|
|
} |
|
|
|
|
|
}, taskExecutor) |
|
|
|
|
|
).collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
|
|
// 3. 等待所有任务完成
|
|
|
|
|
|
CompletableFuture.allOf(futureList.toArray(new CompletableFuture[0])).join(); |
|
|
|
|
|
// 4. 插入数据到数据库
|
|
|
baseMapper.insert(list); |
|
|
baseMapper.insert(list); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|