feat:启动时向redis中缓存台站,探测器信息

This commit is contained in:
qiaoqinzheng 2023-05-23 10:29:17 +08:00
parent bcb2b6b7ed
commit f404f4f365
4 changed files with 43 additions and 4 deletions

View File

@ -5,6 +5,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.jeecg.common.api.QueryRequest; import org.jeecg.common.api.QueryRequest;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.modules.system.entity.GardsSampleData; import org.jeecg.modules.system.entity.GardsSampleData;
import org.jeecg.modules.system.service.IGardsSampleDataService; import org.jeecg.modules.system.service.IGardsSampleDataService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -13,6 +14,8 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
@RestController @RestController
@RequestMapping("gardsSampleData") @RequestMapping("gardsSampleData")
@Api(value = "DATA BASE管理", tags = "DATA BASE管理") @Api(value = "DATA BASE管理", tags = "DATA BASE管理")
@ -20,6 +23,8 @@ public class GardsSampleDataController {
@Autowired @Autowired
private IGardsSampleDataService gardsSampleDataService; private IGardsSampleDataService gardsSampleDataService;
@Autowired
private RedisUtil redisUtil;
@GetMapping("findPage") @GetMapping("findPage")
@ApiOperation(value = "分页查询DATA_BASE数据", notes = "分页查询DATA_BASE数据") @ApiOperation(value = "分页查询DATA_BASE数据", notes = "分页查询DATA_BASE数据")
@ -28,6 +33,20 @@ public class GardsSampleDataController {
return result; return result;
} }
@GetMapping("findStations")
@ApiOperation(value = "查询台站相关信息", notes = "查询台站相关信息")
public Map<Integer, String> findStations(){
Map<Integer, String> stationMap = (Map<Integer, String>)redisUtil.get("stationMap");
return stationMap;
}
@GetMapping("findDetectors")
@ApiOperation(value = "查询台站相关信息", notes = "查询台站相关信息")
public Map<Integer, String> findDetectors(){
Map<Integer, String> detectorsMap = (Map<Integer, String>)redisUtil.get("detectorsMap");
return detectorsMap;
}
@DeleteMapping("deleteById") @DeleteMapping("deleteById")
@ApiOperation(value = "删除DATA_BASE数据", notes = "删除DATA_BASE数据") @ApiOperation(value = "删除DATA_BASE数据", notes = "删除DATA_BASE数据")
public Result deleteById(Integer sampleId){ public Result deleteById(Integer sampleId){

View File

@ -138,6 +138,13 @@ public class GardsDetectorsServiceImpl extends ServiceImpl<GardsDetectorsMapper,
@Transactional(propagation = Propagation.REQUIRES_NEW) @Transactional(propagation = Propagation.REQUIRES_NEW)
public List<GardsDetectors> findDetectors(){ public List<GardsDetectors> findDetectors(){
List<GardsDetectors> gardsDetectors = this.baseMapper.selectList(new LambdaQueryWrapper<>()); List<GardsDetectors> gardsDetectors = this.baseMapper.selectList(new LambdaQueryWrapper<>());
HashMap<Integer, String> map = new HashMap<>();
if (CollectionUtils.isNotEmpty(gardsDetectors)){
for (GardsDetectors detectors:gardsDetectors) {
map.put(detectors.getDetectorId(),detectors.getDetectorCode());
}
}
redisUtil.set("detectorsMap",map);
return gardsDetectors; return gardsDetectors;
} }
} }

View File

@ -3,6 +3,7 @@ package org.jeecg.modules.system.service.impl;
import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -155,11 +156,12 @@ public class GardsStationsServiceImpl extends ServiceImpl<GardsStationsMapper, G
@Override @Override
@Transactional(propagation = Propagation.REQUIRES_NEW) @Transactional(propagation = Propagation.REQUIRES_NEW)
public List<GardsStations> getGardsStations() { public List<GardsStations> getGardsStations() {
LambdaQueryWrapper<GardsStations> queryWrapper = new LambdaQueryWrapper<>(); List<GardsStations> gardsStations = this.baseMapper.selectList(new LambdaQueryWrapper<>());
List<GardsStations> gardsStations = this.baseMapper.selectList(queryWrapper);
HashMap<Integer, String> map = new HashMap<>(); HashMap<Integer, String> map = new HashMap<>();
for (GardsStations station:gardsStations) { if (CollectionUtils.isNotEmpty(gardsStations)){
map.put(station.getStationId(),station.getStationCode()); for (GardsStations station:gardsStations) {
map.put(station.getStationId(),station.getStationCode());
}
} }
redisUtil.set("stationMap",map); redisUtil.set("stationMap",map);
return gardsStations; return gardsStations;

View File

@ -4,6 +4,8 @@ import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.base.BaseMap; import org.jeecg.common.base.BaseMap;
import org.jeecg.common.constant.GlobalConstants; import org.jeecg.common.constant.GlobalConstants;
import org.jeecg.common.util.oConvertUtils; import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.system.service.IGardsDetectorsService;
import org.jeecg.modules.system.service.IGardsStationsService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner; import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
@ -33,6 +35,11 @@ public class JeecgSystemCloudApplication extends SpringBootServletInitializer im
@Autowired @Autowired
private RedisTemplate<String, Object> redisTemplate; private RedisTemplate<String, Object> redisTemplate;
@Autowired
private IGardsStationsService gardsStationsService;
@Autowired
private IGardsDetectorsService gardsDetectorsService;
@Override @Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(JeecgSystemCloudApplication.class); return application.sources(JeecgSystemCloudApplication.class);
@ -65,5 +72,9 @@ public class JeecgSystemCloudApplication extends SpringBootServletInitializer im
params.put(GlobalConstants.HANDLER_NAME, GlobalConstants.LODER_ROUDER_HANDLER); params.put(GlobalConstants.HANDLER_NAME, GlobalConstants.LODER_ROUDER_HANDLER);
//刷新网关 //刷新网关
redisTemplate.convertAndSend(GlobalConstants.REDIS_TOPIC_NAME, params); redisTemplate.convertAndSend(GlobalConstants.REDIS_TOPIC_NAME, params);
//触发缓存一下台站信息
gardsStationsService.getGardsStations();
//触发缓存一下探测器信息
gardsDetectorsService.findDetectors();
} }
} }