Commit 3fe37ca4 authored by duanruiming's avatar duanruiming

[update] 项目启动时自动加载静态数据

parent 3c93e6a1
...@@ -8,6 +8,7 @@ import net.wanji.databus.dao.mapper.ManufacturerInfoMapper; ...@@ -8,6 +8,7 @@ import net.wanji.databus.dao.mapper.ManufacturerInfoMapper;
import net.wanji.databus.po.CrossInfoPO; import net.wanji.databus.po.CrossInfoPO;
import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner; import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -19,6 +20,7 @@ import java.util.*; ...@@ -19,6 +20,7 @@ import java.util.*;
*/ */
@Slf4j @Slf4j
@Component @Component
@Order(1)
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public class CrossInfoCache implements ApplicationRunner { public class CrossInfoCache implements ApplicationRunner {
......
package net.wanji.utc.dt.cache;
import net.wanji.databus.dao.entity.CrossSchedulesPO;
import net.wanji.databus.dto.PlanSectionDTO;
import net.wanji.databus.dto.SchemePhaseLightsDTO;
import net.wanji.databus.po.CrossInfoPO;
import net.wanji.databus.vo.PlanSectionVO;
import net.wanji.databus.vo.SchemePhaseLightsVO;
import net.wanji.utc.dt.service.controller.StaticInfoService;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
/**
* @author duanruiming
* @date 2023/07/05 16:23
*/
@Component
@Order(2)
public class StartQueryStaticInfo implements CommandLineRunner {
@Resource(name = "commonThreadPoolExecutor")
ThreadPoolTaskExecutor commonThreadPoolExecutor;
@Resource
CrossInfoCache crossInfoCache;
@Resource
StaticInfoService staticInfoService;
@Override
public void run(String... args) throws Exception {
try {
Map<String, CrossInfoPO> crossInfoMap = crossInfoCache.getCrossInfoCache();
if (!crossInfoMap.isEmpty()) {
for (Map.Entry<String, CrossInfoPO> entry : crossInfoMap.entrySet()) {
commonThreadPoolExecutor.execute(() -> {
try {
String crossId = entry.getKey();
List<CrossSchedulesPO> crossSchedulesPOS = staticInfoService.crossSchedules(crossId);
SchemePhaseLightsDTO schemePhaseLightsDTO = new SchemePhaseLightsDTO();
schemePhaseLightsDTO.setCrossId(crossId);
SchemePhaseLightsVO schemePhaseLightsVO = staticInfoService.schemePhaseLights(schemePhaseLightsDTO);
PlanSectionDTO planSectionDTO = new PlanSectionDTO();
planSectionDTO.setCrossId(crossId);
List<PlanSectionVO> planSectionVOS = staticInfoService.planSection(planSectionDTO);
} catch (Exception e) {
throw new RuntimeException("开机启动自动加载静态信息失败", e);
}
});
}
}
} catch (Exception e) {
throw new Exception("开机启动自动加载静态信息失败", e);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment