台站运行管理查看台站数据提供率及有效率接口修改为redis启动时缓存方式

台站运行管理查询台站查询台站监测数据信息修改为redis启动时缓存方式
修改台站Map缓存格式
This commit is contained in:
qiaoqinzheng 2023-10-28 14:06:45 +08:00
parent d3e00b1660
commit 87fb378000
19 changed files with 50 additions and 47 deletions

View File

@ -2494,7 +2494,7 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService {
EnergySpectrumStruct struct = EnergySpectrumHandler.getSourceData(file.getAbsolutePath());
String stationName = struct.site_code;
//根据台站id查询台站名称
Map<Integer, String> stationMap = (Map<Integer, String>)redisUtil.get("stationMap");
Map<String, String> stationMap = (Map<String, String>)redisUtil.get("stationMap");
if (CollectionUtils.isEmpty(stationMap)){
result.error500("The station cache information is empty!");
return result;
@ -2505,7 +2505,7 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService {
result.error500("The station information does not exist!");
return result;
}
List<Integer> stationIds = stationMap.keySet().stream().collect(Collectors.toList());
List<String> stationIds = stationMap.keySet().stream().collect(Collectors.toList());
String stationId = String.valueOf(stationIds.get(index));
map.put("stationId", stationId);
map.put("stationName", stationName);
@ -2546,7 +2546,7 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService {
Result result = new Result();
Map<String, Object> map = new HashMap<>();
//根据台站id查询台站名称
Map<Integer, String> stationMap = (Map<Integer, String>)redisUtil.get("stationMap");
Map<String, String> stationMap = (Map<String, String>)redisUtil.get("stationMap");
if (CollectionUtils.isEmpty(stationMap)){
result.error500("The station cache information is empty!");
return result;
@ -2557,7 +2557,7 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService {
result.error500("The station information does not exist!");
return result;
}
List<Integer> stationIds = stationMap.keySet().stream().collect(Collectors.toList());
List<String> stationIds = stationMap.keySet().stream().collect(Collectors.toList());
String stationId = String.valueOf(stationIds.get(index));
map.put("stationId", stationId);
map.put("stationName", stationName);

View File

@ -46,7 +46,7 @@ public class DataProvisionEfficiencyManager {
//获取机器可用核心数
int systemCores = Runtime.getRuntime().availableProcessors();
//初始化线程池
ThreadFactory threadFactory = new CustomizableThreadFactory("undeal-file-parsing-");
ThreadFactory threadFactory = new CustomizableThreadFactory("provision-efficiency-");
poolExecutor = new ThreadPoolExecutor(systemCores-1,systemCores,5, TimeUnit.SECONDS, new LinkedBlockingQueue<>(),threadFactory);
}
@ -58,7 +58,7 @@ public class DataProvisionEfficiencyManager {
HashMap<String, GardsStations> stationInfoMap = (HashMap<String, GardsStations>) redisUtil.get("stationInfoMap");
List<Integer> detectorsUsedList = (List<Integer>) redisUtil.get("detectorsUsedList");
// 获取所有的台站信息
List<GardsStations> stations = stationInfoMap.values().stream().sorted(Comparator.comparing(GardsStations::getStationId)).collect(Collectors.toList());
List<GardsStations> stations = stationInfoMap.values().stream().filter(item-> item.getLon()!=null && item.getLat()!=null).sorted(Comparator.comparing(GardsStations::getStationId)).collect(Collectors.toList());
List<StationInfo> stationInfos = new ArrayList<>();
for (GardsStations gardsStations : stations) {
StationInfo stationInfo = new StationInfo();

View File

@ -1,19 +1,16 @@
package org.jeecg;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.CacheName;
import org.jeecg.common.config.mqtoken.UserTokenContext;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.modules.base.entity.configuration.GardsStations;
import org.jeecg.modules.base.entity.original.GardsMetData;
import org.jeecg.modules.base.entity.original.GardsSampleData;
import org.jeecg.modules.base.entity.original.GardsSohData;
import org.jeecg.modules.base.entity.postgre.SysUserFocusStation;
import org.jeecg.modules.entity.SysUserFocusStationStation;
import org.jeecg.modules.entity.data.*;
import org.jeecg.modules.mapper.StationMetDataMapper;
import org.jeecg.modules.mapper.StationSampleDataMapper;
@ -32,6 +29,8 @@ import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static org.jeecg.common.util.TokenUtils.getTempToken;
@Slf4j
@Component
@RequiredArgsConstructor
@ -72,7 +71,8 @@ public class DataReceivingStatusManager {
public void run() {
for(;;){
long start = System.currentTimeMillis();
// start:生成临时Token到线程中
UserTokenContext.setToken(getTempToken());
//获取四项缓存数据的对应内容
List<Map<String, String>> cacheList = cacheTimeService.findCacheTime();
//缓存时间
@ -84,12 +84,12 @@ public class DataReceivingStatusManager {
}
}
//从redis中获取台站信息
Map<Integer, String> stationInfoMap = (Map<Integer, String>)redisUtil.get("stationMap");
List<Integer> stationIds = stationInfoMap.keySet().stream().collect(Collectors.toList());
Map<String, String> stationInfoMap = (Map<String, String>)redisUtil.get("stationMap");
List<String> stationIds = stationInfoMap.keySet().stream().collect(Collectors.toList());
//从redis中获取探测器信息
Map<Integer, String> detectorInfoMap = (Map<Integer, String>)redisUtil.get("detectorsMap");
//声明存储所有台站id对应的数据信息的集合
List<StationData> stationDataList = Objects.nonNull(redisUtil.get("stationDataList"))? (List<StationData>) redisUtil.get("stationDataList") : new LinkedList<>();
Map<String, StationData> stationDataMap = Objects.nonNull(redisUtil.get("stationDataMap"))?(Map<String, StationData>) redisUtil.get("stationDataMap"):new HashMap<>();
//遍历台站id
if (CollectionUtils.isNotEmpty(stationIds)) {
//获取当前日期时间 作为结束查询时间
@ -103,10 +103,10 @@ public class DataReceivingStatusManager {
Map<String, List<GardsDetectorsSystem>> stationDetectors = cacheTimeService.findStationDetectors(stationIds);
//遍历台站id 获取台站下的探测器数据
if (CollectionUtils.isNotEmpty(stationDetectors)) {
for (Integer stationId : stationIds) {
for (String stationId : stationIds) {
Map<String, List<Map<String, DetectorData>>> stationMap = new HashMap<>();
//获取台站下对应的探测器数据
List<GardsDetectorsSystem> detectors = stationDetectors.get(String.valueOf(stationId));
List<GardsDetectorsSystem> detectors = stationDetectors.get(stationId);
if (CollectionUtils.isNotEmpty(detectors)) {
StationData stationData = new StationData();
//stream流获取探测器id
@ -207,17 +207,17 @@ public class DataReceivingStatusManager {
detectorDataList.add(detectorMap);
}
stationMap.put(String.valueOf(stationId), detectorDataList);
stationData.setStationId(String.valueOf(stationId));
stationMap.put(stationId, detectorDataList);
stationData.setStationId(stationId);
if (CollectionUtils.isNotEmpty(stationInfoMap)) {
if (StringUtils.isNotBlank(stationInfoMap.get(stationId))) {
stationData.setStationCode(stationInfoMap.get(stationId));
}
}
stationData.setDetectors(stationMap);
stationDataList.add(stationData);
redisUtil.set("stationDataList", stationDataList);
stationDataMap.put(stationData.getStationId(), stationData);
}
redisUtil.set("stationDataMap", stationDataMap);
}
}
}

View File

@ -36,14 +36,11 @@ public class CalculateDataRateThread implements Runnable{
@Override
public void run() {
long start = System.currentTimeMillis();
try {
this.calCulStationInfo();
}catch (Exception e){
e.printStackTrace();
} finally {
long end = System.currentTimeMillis();
System.out.println("单线程时长:"+(end-start));
// CountDownLatch 计数器减 1
countDownLatch.countDown();
}

View File

@ -13,6 +13,6 @@ import java.util.List;
@Mapper
public interface StationMetDataMapper extends BaseMapper<GardsMetData> {
List<GardsMetData> findMetDataList(@Param("stationIds") List<Integer> stationIds, @Param("startDate") String startDate);
List<GardsMetData> findMetDataList(@Param("stationIds") List<String> stationIds, @Param("startDate") String startDate);
}

View File

@ -13,5 +13,5 @@ import java.util.List;
@Mapper
public interface StationSohDataMapper extends BaseMapper<GardsSohData> {
List<GardsSohData> findSohDataList(@Param("stationId") Integer stationId, @Param("detectorIds") List<Integer> detectorIds, @Param("startDate") String startDate);
List<GardsSohData> findSohDataList(@Param("stationId") String stationId, @Param("detectorIds") List<Integer> detectorIds, @Param("startDate") String startDate);
}

View File

@ -20,7 +20,7 @@ public interface ICacheTimeService {
List<Map<String, String>> findCacheTime();
@RequestMapping("/gardsDetectors/findStationDetectors")
Map<String, List<GardsDetectorsSystem>> findStationDetectors(@RequestBody List<Integer> stationIds);
Map<String, List<GardsDetectorsSystem>> findStationDetectors(@RequestBody List<String> stationIds);
@RequestMapping("/sys/user/findUserByName")
SysUser findUserByName(@RequestParam String userName);

View File

@ -386,7 +386,7 @@ public class StationOperationServiceImpl extends ServiceImpl<StationOperationMap
@Override
public Result getDataReceivingStatus(String userId) {
Result result = new Result();
List<StationData> stationDataList = (List<StationData>) redisUtil.get("stationDataList");
Map<String, StationData> stationDataMap = (Map<String, StationData>) redisUtil.get("stationDataMap");
// //获取四项缓存数据的对应内容
// List<Map<String, String>> cacheList = cacheTimeService.findCacheTime();
// //缓存时间
@ -407,7 +407,12 @@ public class StationOperationServiceImpl extends ServiceImpl<StationOperationMap
List<SysUserFocusStationStation> userFocusStations = sysUserFocusStationMapper.selectList(userFocusStationQueryWrapper);
List<String> stationIds = userFocusStations.stream().map(SysUserFocusStation::getStationId).collect(Collectors.toList());
//过滤出当前用户关注的台站信息
stationDataList = stationDataList.stream().filter(item-> stationIds.equals(item.getStationId())).collect(Collectors.toList());
List<StationData> stationDataList = new LinkedList<>();
for (String stationId:stationIds) {
if (Objects.nonNull(stationDataMap.get(stationId))) {
stationDataList.add(stationDataMap.get(stationId));
}
}
// //从redis中获取台站信息
// Map<Integer, String> stationInfoMap = (Map<Integer, String>)redisUtil.get("stationMap");
// //从redis中获取探测器信息
@ -553,7 +558,7 @@ public class StationOperationServiceImpl extends ServiceImpl<StationOperationMap
@Override
public Result getDataProvisionEfficiency() {
Map<String, StationInfo> stationInfoMap = (Map<String, StationInfo>) redisUtil.get("dataStationInfoList");
List<StationInfo> stationInfoList = stationInfoMap.values().stream().collect(Collectors.toList());
List<StationInfo> stationInfoList = stationInfoMap.values().stream().filter(Objects::nonNull).collect(Collectors.toList());
// // 获取所有的台站信息
// HashMap<String, GardsStations> stationInfoMap = (HashMap<String, GardsStations>) redisUtil.get("stationInfoMap");
// List<Integer> detectorsUsedList = (List<Integer>) redisUtil.get("detectorsUsedList");

View File

@ -67,7 +67,7 @@ public class GardsDetectorsController {
}
@RequestMapping("findStationDetectors")
public Map<String, List<GardsDetectorsSystem>> findStationDetectors(@RequestBody List<Integer> stationIds){
public Map<String, List<GardsDetectorsSystem>> findStationDetectors(@RequestBody List<String> stationIds){
return gardsDetectorsService.findStationDetectors(stationIds);
}

View File

@ -35,8 +35,8 @@ public class GardsSampleDataController {
@GetMapping("findStations")
@ApiOperation(value = "查询台站相关信息", notes = "查询台站相关信息")
public Map<Integer, String> findStations(){
Map<Integer, String> stationMap = (Map<Integer, String>)redisUtil.get("stationMap");
public Map<String, String> findStations(){
Map<String, String> stationMap = (Map<String, String>)redisUtil.get("stationMap");
return stationMap;
}

View File

@ -63,6 +63,6 @@ public interface IGardsDetectorsService extends IService<GardsDetectorsSystem> {
* @param stationIds
* @return
*/
Map<String, List<GardsDetectorsSystem>> findStationDetectors(List<Integer> stationIds);
Map<String, List<GardsDetectorsSystem>> findStationDetectors(List<String> stationIds);
}

View File

@ -143,15 +143,15 @@ public class GardsDetectorsServiceImpl extends ServiceImpl<GardsDetectorsMapper,
}
@Override
public Map<String, List<GardsDetectorsSystem>> findStationDetectors(List<Integer> stationIds) {
public Map<String, List<GardsDetectorsSystem>> findStationDetectors(List<String> stationIds) {
Map<String, List<GardsDetectorsSystem>> map = new HashMap<>();
if (CollectionUtils.isNotEmpty(stationIds)){
LambdaQueryWrapper<GardsDetectorsSystem> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.in(GardsDetectorsSystem::getStationId, stationIds);
List<GardsDetectorsSystem> detectorsList = this.baseMapper.selectList(queryWrapper);
for (Integer stationId:stationIds) {
List<GardsDetectorsSystem> detectors = detectorsList.stream().filter(item -> item.getStationId()!=null && item.getStationId().equals(stationId) && item.getStatus()!=null && item.getStatus().trim().equals("Operating")).collect(Collectors.toList());
map.put(String.valueOf(stationId), detectors);
for (String stationId:stationIds) {
List<GardsDetectorsSystem> detectors = detectorsList.stream().filter(item -> item.getStationId()!=null && item.getStationId().equals(Integer.valueOf(stationId)) && item.getStatus()!=null && item.getStatus().trim().equals("Operating")).collect(Collectors.toList());
map.put(stationId, detectors);
}
}
return map;

View File

@ -29,7 +29,7 @@ public class GardsSampleDataServiceImpl extends ServiceImpl<GardsSampleDataMappe
@Override
public Result<IPage<GardsSampleDataSystem>> findPage(QueryRequest queryRequest, GardsSampleDataSystem gardsSampleData) {
//查询全部台站信息
HashMap<Integer, String> stationMap = (HashMap<Integer, String>) redisUtil.get("stationMap");
HashMap<String, String> stationMap = (HashMap<String, String>) redisUtil.get("stationMap");
//查询全部监测器信息
HashMap<Integer, String> detectorsMap = (HashMap<Integer, String>) redisUtil.get("detectorsMap");
Result<IPage<GardsSampleDataSystem>> result = new Result<>();

View File

@ -175,7 +175,8 @@ public class GardsStationsServiceImpl extends ServiceImpl<GardsStationsMapper, G
redisUtil.del("stationInfoMap");
}
List<GardsStations> gardsStations = this.baseMapper.selectList(new LambdaQueryWrapper<>());
Map<Integer, String> stationMap = gardsStations.stream().collect(Collectors.toMap(GardsStations::getStationId, GardsStations::getStationCode));
Map<String, String> stationMap = gardsStations.stream().collect(Collectors.toMap(GardsStations::getStationId, GardsStations::getStationCode)).entrySet().stream()
.collect(Collectors.toMap(entry -> entry.getKey().toString(), Map.Entry::getValue));;
HashMap<Integer, Object> stationInfoMap = new HashMap<>();
if (CollectionUtils.isNotEmpty(gardsStations)){
for (GardsStations station:gardsStations) {

View File

@ -62,7 +62,7 @@ public class SysTaskServiceImpl extends ServiceImpl<SysTaskMapper, SysTaskSystem
Result<Map<String, List<SysTaskVo>>> result = new Result();
Map<String, List<SysTaskVo>> map = new LinkedHashMap<>();
//获取全部台站信息
HashMap<Integer, String> stationMap = (HashMap<Integer, String>)redisUtil.get("stationMap");
HashMap<String, String> stationMap = (HashMap<String, String>)redisUtil.get("stationMap");
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String yearMonthStr = DateUtils.formatDate(yearMonth, "yyyy-MM");
@ -138,7 +138,7 @@ public class SysTaskServiceImpl extends ServiceImpl<SysTaskMapper, SysTaskSystem
public Result<List<SysTaskSystem>> findInfo(Date day) {
Result<List<SysTaskSystem>> result = new Result();
//获取全部台站信息
HashMap<Integer, String> stationMap = (HashMap<Integer, String>)redisUtil.get("stationMap");
HashMap<String, String> stationMap = (HashMap<String, String>)redisUtil.get("stationMap");
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal = Calendar.getInstance();

View File

@ -47,7 +47,7 @@ public class AutoServiceImpl extends ServiceImpl<GardsAnalysesAutoMapper, GardsA
public Result findAutoPage(QueryRequest queryRequest, Integer[] stationIds, Date startTime, Date endTime) {
Result result = new Result();
//获取redis中缓存的台站信息
Map<Integer, String> stationMap = (Map<Integer, String>)redisUtil.get("stationMap");
Map<String, String> stationMap = (Map<String, String>)redisUtil.get("stationMap");
if (Objects.isNull(startTime)){
result.error500("The start time cannot be empty");
return result;

View File

@ -72,7 +72,7 @@ public class GardsSampleDataWebServiceImpl extends ServiceImpl<GardsSampleDataWe
try {
Result result = new Result();
//获取redis中缓存的台站信息
Map<Integer, String> stationMap = (Map<Integer, String>)redisUtil.get("stationMap");
Map<String, String> stationMap = (Map<String, String>)redisUtil.get("stationMap");
if (StringUtils.isBlank(dataType)) {
result.error500("The data type cannot be empty");
return result;
@ -174,7 +174,7 @@ public class GardsSampleDataWebServiceImpl extends ServiceImpl<GardsSampleDataWe
Acquisition acquisition = null;
Calibration calibration = null;
//获取redis中缓存的台站信息
Map<Integer, String> stationMap = (Map<Integer, String>)redisUtil.get("stationMap");
Map<String, String> stationMap = (Map<String, String>)redisUtil.get("stationMap");
//根据sample_id查询sample_data内容
LambdaQueryWrapper<GardsSampleDataWeb> sampleDataQueryWrapper = new LambdaQueryWrapper<>();
sampleDataQueryWrapper.eq(GardsSampleDataWeb::getSampleId, sampleId);
@ -695,7 +695,7 @@ public class GardsSampleDataWebServiceImpl extends ServiceImpl<GardsSampleDataWe
List<GardsSampleDataWeb> sampleData = this.list(wrapper);
// 获取redis中缓存的台站信息
Map<Integer, String> stationMap = (Map<Integer, String>)redisUtil.get("stationMap");
Map<String, String> stationMap = (Map<String, String>)redisUtil.get("stationMap");
int no = 1;
boolean emptyMap = MapUtil.isEmpty(stationMap);
for (GardsSampleDataWeb sampleDatum : sampleData) {

View File

@ -47,7 +47,7 @@ public class ReviewedServiceImpl extends ServiceImpl<GardsAnalysesManMapper, Gar
public Result findReviewedPage(QueryRequest queryRequest, Integer[] stationIds, Date startTime, Date endTime) {
Result result = new Result();
//获取redis中缓存的台站信息
Map<Integer, String> stationMap = (Map<Integer, String>)redisUtil.get("stationMap");
Map<String, String> stationMap = (Map<String, String>)redisUtil.get("stationMap");
if (Objects.isNull(startTime)){
result.error500("The start time cannot be empty");
return result;

View File

@ -49,6 +49,6 @@ public class JeecgStationOperationApplication extends SpringBootServletInitializ
@Override
public void run(String... args) throws Exception {
dataProvisionEfficiencyManager.start();
// dataReceivingStatusManager.start();
dataReceivingStatusManager.start();
}
}