From e166a470bed371810cefa09aa64063f7b4b46984 Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Wed, 24 Jan 2024 14:22:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=B0=E7=AB=99=E8=BF=90=E8=A1=8C=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=90=AF=E5=8A=A8=E6=97=B6=E5=A2=9E=E5=8A=A0=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=89=80=E6=9C=89=E7=94=A8=E6=88=B7=E6=9C=80=E5=A4=A7?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E6=97=B6=E9=97=B4=E7=9A=84=E6=96=B9=E6=B3=95?= =?UTF-8?q?=20=E5=8F=B0=E7=AB=99=E8=BF=90=E8=A1=8C=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E5=8F=B0=E7=AB=99=E7=9A=84=E8=BF=90=E8=A1=8C?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E6=8E=A5=E5=8F=A3=E6=A0=B9=E6=8D=AE=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E8=AE=BE=E7=BD=AE=E7=9A=84=E7=BC=93=E5=AD=98=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E8=BF=9B=E8=A1=8C=E7=BB=93=E6=9E=9C=E5=88=87=E5=89=B2?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=20=E7=B3=BB=E7=BB=9F=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E7=B1=BB=E6=96=B0=E5=A2=9E=E5=8A=A0=E7=BC=93=E5=AD=98=E5=8F=B0?= =?UTF-8?q?=E7=AB=99id=E5=8F=8A=E5=8F=B0=E7=AB=99id=E5=85=B3=E8=81=94?= =?UTF-8?q?=E7=9A=84=E6=8E=A2=E6=B5=8B=E5=99=A8=E6=95=B0=E7=BB=84=E6=96=B9?= =?UTF-8?q?=E6=B3=95=20=E5=8F=B0=E7=AB=99=E8=BF=90=E8=A1=8C=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E6=95=B0=E6=8D=AE=E7=8A=B6=E6=80=81=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E5=90=91redis=E7=BC=93=E5=AD=98=E8=BF=87=E4=BA=8E=E9=A2=91?= =?UTF-8?q?=E7=B9=81=E5=AF=BC=E8=87=B4=E8=A7=A6=E5=8F=91redis=E5=BA=8F?= =?UTF-8?q?=E5=88=97=E5=8C=96=E9=94=99=E8=AF=AF=E9=97=AE=E9=A2=98=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jeecg/DataReceivingStatusManager.java | 31 +-- .../jeecg/common/CalculateDataRateThread.java | 10 +- .../jeecg/common/CalculateStationData.java | 78 +----- .../mapper/StationReceivingConfigMapper.java | 7 + .../xml/stationReceivingConfigMapper.xml | 12 + .../modules/service/ICacheTimeService.java | 3 - .../service/IStationOperationService.java | 2 +- .../service/ISysUserFocusStationService.java | 5 + .../impl/StationOperationServiceImpl.java | 258 +++++------------- .../impl/SysUserFocusStationServiceImpl.java | 11 + .../controller/GardsDetectorsController.java | 5 - .../service/IGardsDetectorsService.java | 7 - .../impl/GardsDetectorsServiceImpl.java | 33 +-- .../JeecgStationOperationApplication.java | 3 + 14 files changed, 137 insertions(+), 328 deletions(-) create mode 100644 jeecg-module-station-operation/src/main/java/org/jeecg/modules/mapper/xml/stationReceivingConfigMapper.xml diff --git a/jeecg-module-station-operation/src/main/java/org/jeecg/DataReceivingStatusManager.java b/jeecg-module-station-operation/src/main/java/org/jeecg/DataReceivingStatusManager.java index 39ee71b5..af035bdd 100644 --- a/jeecg-module-station-operation/src/main/java/org/jeecg/DataReceivingStatusManager.java +++ b/jeecg-module-station-operation/src/main/java/org/jeecg/DataReceivingStatusManager.java @@ -15,8 +15,10 @@ 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.enums.DetectorStatus; +import org.jeecg.modules.entity.StationReceivingConfigStation; import org.jeecg.modules.entity.data.*; import org.jeecg.modules.mapper.StationMetDataMapper; +import org.jeecg.modules.mapper.StationReceivingConfigMapper; import org.jeecg.modules.mapper.StationSampleDataMapper; import org.jeecg.modules.mapper.StationSohDataMapper; import org.jeecg.modules.service.ICacheTimeService; @@ -42,8 +44,6 @@ public class DataReceivingStatusManager { private final RedisUtil redisUtil; - private final ICacheTimeService cacheTimeService; - private final StationMetDataMapper stationMetDataMapper; private final StationSampleDataMapper stationSampleDataMapper; @@ -69,7 +69,7 @@ public class DataReceivingStatusManager { //获取机器可用核心数 int systemCores = maximumPoolSizeProperties.getStation();//Runtime.getRuntime().availableProcessors(); //初始化线程池 - ThreadFactory threadFactory = new CustomizableThreadFactory("undeal-file-parsing-"); + ThreadFactory threadFactory = new CustomizableThreadFactory("data-receiving-status-"); poolExecutor = new ThreadPoolExecutor(systemCores-1,systemCores,5, TimeUnit.SECONDS, new LinkedBlockingQueue<>(),threadFactory); } @@ -77,18 +77,8 @@ public class DataReceivingStatusManager { public void run() { for(;;){ long start = System.currentTimeMillis(); - // start:生成临时Token到线程中 - UserTokenContext.setToken(getTempToken()); - //获取四项缓存数据的对应内容 - List> cacheList = cacheTimeService.findCacheTime(); - //缓存时间 - String cacheTime = ""; - for (int i=0; i< cacheList.size(); i++) { - if ( StringUtils.isNotBlank(cacheList.get(i).get(CacheName.cacheTime)) ) { - cacheTime = cacheList.get(i).get(CacheName.cacheTime); - break; - } - } + //读取缓存 + String cacheTime = (String) redisUtil.get("maxCacheTime"); //从redis中获取台站信息 Map stationInfoMap = (HashMap) redisUtil.get("stationInfoMap"); List stationIds = new LinkedList<>(); @@ -100,6 +90,7 @@ public class DataReceivingStatusManager { } //从redis中获取探测器信息 Map detectorInfoMap = (Map)redisUtil.get("detectorsMap"); + Map> stationDetectorMap = (Map>) redisUtil.get("stationDetectorMap"); //声明存储所有台站id对应的数据信息的集合 Map stationDataMap = Objects.nonNull(redisUtil.get("stationDataMap"))?(Map) redisUtil.get("stationDataMap"):new HashMap<>(); //遍历台站id @@ -112,21 +103,21 @@ public class DataReceivingStatusManager { //根据台站id,开始时间查询出台站下的气象数据 List metDataList = stationMetDataMapper.findMetDataList(stationIds, startDateTime); //根据台站id查询出当前台站下处于运行状态的数据 - Map> stationDetectors = cacheTimeService.findStationDetectors(stationIds); +// Map> stationDetectors = cacheTimeService.findStationDetectors(stationIds); //遍历台站id 获取台站下的探测器数据 - if (CollectionUtils.isNotEmpty(stationDetectors)) { + if (CollectionUtils.isNotEmpty(stationDetectorMap)) { for (String stationId : stationIds) { Map>> stationMap = new HashMap<>(); //获取台站下对应的探测器数据 - List detectors = stationDetectors.get(stationId); + List detectors = stationDetectorMap.get(stationId); if (CollectionUtils.isNotEmpty(detectors)) { StationData stationData = new StationData(); //stream流获取探测器id List detectorIds = detectors.stream().map(GardsDetectorsSystem::getDetectorId).collect(Collectors.toList()); - //探测器加上NA 无效探测器id - detectorIds.add(1); //根据探测器id 开始时间查询样品基础数据 List sampleDataList = stationSampleDataMapper.findSampleDataList(detectorIds, startDateTime); + //探测器加上NA 无效探测器id + detectorIds.add(1); //根据台站id,探测器id,开始时间 List sohDataList = stationSohDataMapper.findSohDataList(stationId, detectorIds, startDateTime); //移除掉最后一个探测器 diff --git a/jeecg-module-station-operation/src/main/java/org/jeecg/common/CalculateDataRateThread.java b/jeecg-module-station-operation/src/main/java/org/jeecg/common/CalculateDataRateThread.java index 417e0ff0..af396cb8 100644 --- a/jeecg-module-station-operation/src/main/java/org/jeecg/common/CalculateDataRateThread.java +++ b/jeecg-module-station-operation/src/main/java/org/jeecg/common/CalculateDataRateThread.java @@ -20,11 +20,9 @@ public class CalculateDataRateThread implements Runnable{ private ICalCulStationDataService calCulStationDataService = ApplicationContextUtil.getContext().getBean(ICalCulStationDataService.class); - private RedisUtil redisUtil = ApplicationContextUtil.getContext().getBean(RedisUtil.class); + private GetStationinfoAndDataRate stationinfoAndDataRate; - private final GetStationinfoAndDataRate stationinfoAndDataRate; - - private final Map finallySta; + private Map finallySta; private CountDownLatch countDownLatch; @@ -64,10 +62,8 @@ public class CalculateDataRateThread implements Runnable{ CalculateDataRate calculateDataRate = new CalculateDataRate(); calculateDataRate.setParameter(mRateparam); //根据台站编码 查询 台站信息 -// StationInfo stationInfo = calCulStationDataService.getStationInfo(originalstationsinfo.getStationCode()); StationInfo stationInfo = new StationInfo(); BeanUtils.copyProperties(originalstationsinfo, stationInfo); -// stationInfo.setUsed(calCulStationDataService.getUsed(Integer.valueOf(stationInfo.getId()))); //赋值台站信息 calculateDataRate.setMStationId(stationInfo.getId()); calculateDataRate.setMStationCode(stationInfo.getStationCode()); @@ -88,7 +84,7 @@ public class CalculateDataRateThread implements Runnable{ } //赋值最后的结果 finallySta.put(stationInfo.getStationCode(), stationInfo); - redisUtil.set("dataStationInfoList", finallySta); +// redisUtil.set("dataStationInfoList", finallySta); } } diff --git a/jeecg-module-station-operation/src/main/java/org/jeecg/common/CalculateStationData.java b/jeecg-module-station-operation/src/main/java/org/jeecg/common/CalculateStationData.java index 4ed0a2d3..41cce466 100644 --- a/jeecg-module-station-operation/src/main/java/org/jeecg/common/CalculateStationData.java +++ b/jeecg-module-station-operation/src/main/java/org/jeecg/common/CalculateStationData.java @@ -825,18 +825,9 @@ public class CalculateStationData { CountDownLatch countDownLatch = null; //初始化线程数量=0 int threadNum = 0; -// //获取当前设备的理想线程数 -// int idealnum = Runtime.getRuntime().availableProcessors(); //获取需要处理的台站信息数量 int works = stationInfos.size(); -// // 如果需要工作处理的数量 小于 理想线程数 -// if(works < idealnum) { - //将需要处理的工作数量赋值给线程数,按照需要处理的工作数量处理数据 - threadNum = works; -// } else { -// //否则按照理想线程数 处理数据 -// threadNum = idealnum; -// } + threadNum = works; // 如果线程数不等于0 if (threadNum != 0){ //获取机器可用核心数 @@ -852,12 +843,7 @@ public class CalculateStationData { } }; poolExecutor = new ThreadPoolExecutor(15,maximumPoolSize,10, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(),threadFactory); - //初始化线程池 -// poolExecutor = new ThreadPoolExecutor(16, 32, 1, TimeUnit.SECONDS, new LinkedBlockingQueue<>()); } -// else { -// return finallySta; -// } // 线程数 等于 需要处理的台站数量 if( threadNum == works ){ countDownLatch = new CountDownLatch(threadNum); @@ -883,67 +869,7 @@ public class CalculateStationData { poolExecutor.shutdownNow(); } } + redisUtil.set("dataStationInfoList", finallySta); } -// else { // 线程数 不等于 需要处理的台站数量时 -// //将台站数组按照线程数分成多组 -// //声明一个变量 看当前台站信息需要分为多少组 -// int Tworks = 0; -// //如果当前需要处理的台站数量是线程数量的整数倍 -// if(works % threadNum == 0){ -// //变量值 等于 需要处理的台站数量与线程数的商 -// Tworks = works / threadNum; // 300 30 10 -// } else { -// // 变量值 等于 需要处理的台站数量与线程数的商 +1 -// Tworks = works / threadNum + 1; // 301 30 11 -// } -// //遍历需要查询的组数 -// for (int i = 0; i < Tworks; i++){ -// long start = System.currentTimeMillis(); -// //根据每组的台站大小 分割台站数组 -// List infos = new ArrayList<>(); -// int startIndex = i * threadNum; -// int endIndex = ((i + 1) * threadNum); -// //判断当前结束下标是否超出台站数量 没有超出说明还在范围内 正常截取数组 -// if (endIndex <= works){ -// infos = stationInfos.subList(startIndex, endIndex); -// }else {//如果超出台站数量 则从截取开始下标 截取到台站数组长度 -// infos = stationInfos.subList(startIndex, works); -// } -// countDownLatch = new CountDownLatch(infos.size()); -// //遍历当前组的台站并进行计算 -// for (int j = 0; j < infos.size(); j++){ -// //获取台站信息 -// StationInfo stationInfo = infos.get(j); -// //声明一个实体类 -// GetStationinfoAndDataRate stationinfoAndDataRate = new GetStationinfoAndDataRate(); -// stationinfoAndDataRate.setMOriginalstationsinfo(stationInfo); -// stationinfoAndDataRate.setMRateparam(mRateParam); -// CalculateDataRateThread calculateDataRateThread = new CalculateDataRateThread(finallySta, stationinfoAndDataRate, countDownLatch); -// //调用线程计算率值 -// poolExecutor.execute(calculateDataRateThread); -// } -// if (i == Tworks - 1){ -// try { -// countDownLatch.await(); -// } catch (InterruptedException e) { -// throw new RuntimeException(e); -// } finally { -// //关闭线程池 -// if(poolExecutor != null) { -// poolExecutor.shutdownNow(); -// } -// } -// }else { -// try { -// countDownLatch.await(); -// } catch (InterruptedException e) { -// throw new RuntimeException(e); -// } -// } -// long end = System.currentTimeMillis(); -// System.out.println("单次线程执行总时长:"+ (end-start)); -// } -// } -// return finallySta; } } diff --git a/jeecg-module-station-operation/src/main/java/org/jeecg/modules/mapper/StationReceivingConfigMapper.java b/jeecg-module-station-operation/src/main/java/org/jeecg/modules/mapper/StationReceivingConfigMapper.java index a89adf78..7ed275ca 100644 --- a/jeecg-module-station-operation/src/main/java/org/jeecg/modules/mapper/StationReceivingConfigMapper.java +++ b/jeecg-module-station-operation/src/main/java/org/jeecg/modules/mapper/StationReceivingConfigMapper.java @@ -1,7 +1,14 @@ package org.jeecg.modules.mapper; +import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; import org.jeecg.modules.entity.StationReceivingConfigStation; +@Mapper +@DS("master") public interface StationReceivingConfigMapper extends BaseMapper { + + String findMaxCacheTime(); + } diff --git a/jeecg-module-station-operation/src/main/java/org/jeecg/modules/mapper/xml/stationReceivingConfigMapper.xml b/jeecg-module-station-operation/src/main/java/org/jeecg/modules/mapper/xml/stationReceivingConfigMapper.xml new file mode 100644 index 00000000..b39ef042 --- /dev/null +++ b/jeecg-module-station-operation/src/main/java/org/jeecg/modules/mapper/xml/stationReceivingConfigMapper.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file diff --git a/jeecg-module-station-operation/src/main/java/org/jeecg/modules/service/ICacheTimeService.java b/jeecg-module-station-operation/src/main/java/org/jeecg/modules/service/ICacheTimeService.java index 65657c2e..ee98e075 100644 --- a/jeecg-module-station-operation/src/main/java/org/jeecg/modules/service/ICacheTimeService.java +++ b/jeecg-module-station-operation/src/main/java/org/jeecg/modules/service/ICacheTimeService.java @@ -19,9 +19,6 @@ public interface ICacheTimeService { @RequestMapping("/sys/dictItem/findCacheTime") List> findCacheTime(); - @RequestMapping("/gardsDetectors/findStationDetectors") - Map> findStationDetectors(@RequestBody List stationIds); - @RequestMapping("/sys/user/findUserByName") SysUser findUserByName(@RequestParam String userName); diff --git a/jeecg-module-station-operation/src/main/java/org/jeecg/modules/service/IStationOperationService.java b/jeecg-module-station-operation/src/main/java/org/jeecg/modules/service/IStationOperationService.java index 9d7c5768..058df0d8 100644 --- a/jeecg-module-station-operation/src/main/java/org/jeecg/modules/service/IStationOperationService.java +++ b/jeecg-module-station-operation/src/main/java/org/jeecg/modules/service/IStationOperationService.java @@ -46,7 +46,7 @@ public interface IStationOperationService extends IService { /** * 查询台站监测数据 * @param userId - * @param stationId + * @param oneStationId * @return */ Result getDataReceivingStatus(String userId, String oneStationId); diff --git a/jeecg-module-station-operation/src/main/java/org/jeecg/modules/service/ISysUserFocusStationService.java b/jeecg-module-station-operation/src/main/java/org/jeecg/modules/service/ISysUserFocusStationService.java index 1e3ab12c..309f9ea3 100644 --- a/jeecg-module-station-operation/src/main/java/org/jeecg/modules/service/ISysUserFocusStationService.java +++ b/jeecg-module-station-operation/src/main/java/org/jeecg/modules/service/ISysUserFocusStationService.java @@ -34,4 +34,9 @@ public interface ISysUserFocusStationService extends IService stationDataMap = (Map) redisUtil.get("stationDataMap"); -// //获取四项缓存数据的对应内容 -// List> cacheList = cacheTimeService.findCacheTime(); -// //缓存时间 -// String cacheTime = ""; -// for (int i=0; i< cacheList.size(); i++) { -// if ( StringUtils.isNotBlank(cacheList.get(i).get(CacheName.cacheTime)) ) { -// cacheTime = cacheList.get(i).get(CacheName.cacheTime); -// break; -// } -// } -// if (StringUtils.isBlank(cacheTime)) { -// result.error500("The cache time cannot be empty"); -// return result; -// } + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(StationReceivingConfig::getUserId, userId); + StationReceivingConfigStation configStation = stationReceivingConfigMapper.selectOne(queryWrapper); + Double cacheTime = configStation.getCacheTime(); + //获取当前日期时间 作为结束查询时间 + LocalDateTime endDate = LocalDateTime.now(); + //根据缓存日期 得到开始查询时间 + LocalDateTime startDate = endDate.minusDays(cacheTime.intValue()); + //获取到开始时间的秒数 + long startMill = startDate.toInstant(ZoneOffset.UTC).toEpochMilli(); //过滤出当前用户关注的台站信息 List stationDataList = new LinkedList<>(); - if (StringUtils.isNotBlank(oneStationId)) { - StationData stationData = stationDataMap.get(oneStationId); - stationDataList.add(stationData); - } else { - //根据用户id查询出当前用户关注的台站信息 - LambdaQueryWrapper userFocusStationQueryWrapper = new LambdaQueryWrapper<>(); - userFocusStationQueryWrapper.eq(SysUserFocusStationStation::getUserId, userId); - List userFocusStations = sysUserFocusStationMapper.selectList(userFocusStationQueryWrapper); - List stationIds = userFocusStations.stream().map(SysUserFocusStation::getStationId).collect(Collectors.toList()); - for (String stationId:stationIds) { - if (Objects.nonNull(stationDataMap.get(stationId))) { - stationDataList.add(stationDataMap.get(stationId)); + if (CollectionUtils.isNotEmpty(stationDataMap)) { + if (StringUtils.isNotBlank(oneStationId)) { + StationData stationData = stationDataMap.get(oneStationId); + if (Objects.nonNull(stationData)) { + //读取探测器的数据集合 + Map>> detectors = stationData.getDetectors(); + //遍历探测器的集合 + for (Map.Entry>> detector:detectors.entrySet()) { + //获取探测器对应的数组 + List> detectorValue = detector.getValue(); + //遍历探测器数组 + for (Map detectorDataMap:detectorValue) { + for (String key :detectorDataMap.keySet()) { + DetectorData detectorData = detectorDataMap.get(key); + //通过流过滤出数据的开始时间戳在用户统计的开始时间戳之后的数据 + detectorData.getDataList().stream().filter(item -> item.getBeginTime() >= startMill).collect(Collectors.toList()); + } + } + } + } + stationDataList.add(stationData); + } else { + //根据用户id查询出当前用户关注的台站信息 + LambdaQueryWrapper userFocusStationQueryWrapper = new LambdaQueryWrapper<>(); + userFocusStationQueryWrapper.eq(SysUserFocusStationStation::getUserId, userId); + List userFocusStations = sysUserFocusStationMapper.selectList(userFocusStationQueryWrapper); + List stationIds = userFocusStations.stream().map(SysUserFocusStation::getStationId).collect(Collectors.toList()); + for (String stationId:stationIds) { + StationData stationData = stationDataMap.get(stationId); + if (Objects.nonNull(stationData)) { + //读取探测器的数据集合 + Map>> detectors = stationData.getDetectors(); + //遍历探测器的集合 + for (Map.Entry>> detector:detectors.entrySet()) { + //获取探测器对应的数组 + List> detectorValue = detector.getValue(); + //遍历探测器数组 + for (Map detectorDataMap:detectorValue) { + for (String key :detectorDataMap.keySet()) { + DetectorData detectorData = detectorDataMap.get(key); + //通过流过滤出数据的开始时间戳在用户统计的开始时间戳之后的数据 + detectorData.getDataList().stream().filter(item -> item.getBeginTime() >= startMill).collect(Collectors.toList()); + } + } + } + stationDataList.add(stationData); + } } } } - -// //从redis中获取台站信息 -// Map stationInfoMap = (Map)redisUtil.get("stationMap"); -// //从redis中获取探测器信息 -// Map detectorInfoMap = (Map)redisUtil.get("detectorsMap"); -// //遍历台站id -// if (CollectionUtils.isNotEmpty(stationIds)) { -// //获取当前日期时间 作为结束查询时间 -// LocalDateTime endDate = LocalDateTime.now(); -// //根据缓存日期 得到开始查询时间 -// LocalDateTime startDate = endDate.minusDays(Integer.valueOf(cacheTime)); -// String startDateTime = startDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); -// //根据台站id,开始时间查询出台站下的气象数据 -// List metDataList = stationMetDataMapper.findMetDataList(stationIds, startDateTime); -// //根据台站id查询出当前台站下处于运行状态的数据 -// Map> stationDetectors = cacheTimeService.findStationDetectors(stationIds); -// //声明存储所有台站id对应的数据信息的集合 -// List stationDataList = new LinkedList<>(); -// //遍历台站id 获取台站下的探测器数据 -// if (CollectionUtils.isNotEmpty(stationDetectors)) { -// for (String stationId:stationIds) { -// Map>> stationMap = new HashMap<>(); -// //获取台站下对应的探测器数据 -// List detectors = stationDetectors.get(stationId); -// if (CollectionUtils.isNotEmpty(detectors)) { -// StationData stationData = new StationData(); -// //stream流获取探测器id -// List detectorIds = detectors.stream().map(GardsDetectorsSystem::getDetectorId).collect(Collectors.toList()); -// //根据探测器id 开始时间查询样品基础数据 -// List sampleDataList = stationSampleDataMapper.findSampleDataList(detectorIds, startDateTime); -// //根据台站id,探测器id,开始时间 -// List sohDataList = stationSohDataMapper.findSohDataList(stationId, detectorIds, startDateTime); -// //用于接收当前台站下所有探测器及探测器所有的样品数据,气体数据,状态数据集合 -// List> detectorDataList = new LinkedList<>(); -// -// for (Integer detectorId:detectorIds) { -// Map detectorMap = new HashMap<>(); -// DetectorData detectorData = new DetectorData(); -// detectorData.setDetectorId(detectorId); -// //声明数据实体实体类 根据参数存储 样品基础数据对应的数据 气体数据 状态数据 -// List dataInfoList = new LinkedList<>(); -// if (CollectionUtils.isNotEmpty(sampleDataList)) { -// //根据探测器id过滤出对应的样品数据 并进行遍历封装进dataInfo -// List dataListSample = sampleDataList.stream().filter(item -> item.getDetectorId().equals(detectorId)).collect(Collectors.toList()); -// if (CollectionUtils.isNotEmpty(dataListSample)) { -// for (GardsSampleData sampleData:dataListSample) { -// DataInfoVo dataInfo = new DataInfoVo(); -// //根据样品数据类型判断 数据类型 根据不同的样品数据状态 -// String dataType = sampleData.getDataType(); -// String spectralQualifie = sampleData.getSpectralQualifie(); -// if (StrUtil.equals(dataType,"S")){ -// dataInfo.setType("PHD"); -// if (StrUtil.equals(spectralQualifie,"PREL")){ -// dataInfo.setStatus("SPREL"); -// } else if (StrUtil.equals(spectralQualifie,"FULL")) { -// dataInfo.setStatus("SFULL"); -// } -// } else if (StrUtil.equals(dataType,"Q")){ -// dataInfo.setType("QC"); -// dataInfo.setStatus("QC"); -// } else if (StrUtil.equals(dataType,"G")){ -// dataInfo.setType("PHD"); -// if (StrUtil.equals(spectralQualifie,"PREL")){ -// dataInfo.setStatus("GPREL"); -// } else if (StrUtil.equals(spectralQualifie,"FULL")) { -// dataInfo.setStatus("GFULL"); -// } -// } else { -// continue; -// } -// //处理开始时间 -// Date acquisitionStart = sampleData.getAcquisitionStart(); -// dataInfo.setBeginTime(Double.valueOf(acquisitionStart.getTime()/1000)); -// //处理结束时间 -// Date acquisitionStop = sampleData.getAcquisitionStop(); -// dataInfo.setEndTime(Double.valueOf(acquisitionStop.getTime()/1000)); -// //时间间隔 -// Double span = Double.valueOf(acquisitionStop.getTime()/1000) - Double.valueOf(acquisitionStart.getTime()/1000); -// dataInfo.setSpanTime(span); -// dataInfoList.add(dataInfo); -// } -// } -// } -// if (CollectionUtils.isNotEmpty(sohDataList)) { -// List dataListSoh = sohDataList.stream().filter(item -> item.getDetectorId().equals(detectorId)).collect(Collectors.toList()); -// //根据探测器id 台站id 开始时间查询状态数据 -// if (CollectionUtils.isNotEmpty(dataListSoh)) { -// for (GardsSohData sohData:dataListSoh) { -// DataInfoVo dataInfo = new DataInfoVo(); -// dataInfo.setType("SOH"); -// dataInfo.setStatus("SOH"); -// Date startTime = sohData.getStartTime(); -// dataInfo.setBeginTime(Double.valueOf(startTime.getTime()/1000)); -// dataInfo.setSpanTime(Double.valueOf(sohData.getTime())); -// dataInfoList.add(dataInfo); -// } -// } -// } -// if (CollectionUtils.isNotEmpty(metDataList)) { -// List dataListMet = metDataList.stream().filter(item -> item.getStationId().equals(stationId)).collect(Collectors.toList()); -// if (CollectionUtils.isNotEmpty(dataListMet)) { -// for (GardsMetData metData:dataListMet) { -// DataInfoVo dataInfo = new DataInfoVo(); -// dataInfo.setType("MET"); -// dataInfo.setStatus("MET"); -// Date startTime = metData.getStartTime(); -// dataInfo.setBeginTime(Double.valueOf(startTime.getTime()/1000)); -// Date endTime = metData.getEndTime(); -// dataInfo.setEndTime(Double.valueOf(endTime.getTime()/1000)); -// Double span = Double.valueOf(startTime.getTime() / 1000) - Double.valueOf(endTime.getTime() / 1000); -// dataInfo.setSpanTime(span); -// dataInfoList.add(dataInfo); -// } -// } -// } -// detectorData.setDataList(dataInfoList); -// if (CollectionUtils.isNotEmpty(detectorInfoMap)) { -// if (StringUtils.isNotBlank(detectorInfoMap.get(detectorId.toString()))) { -// detectorData.setDetectorCode(detectorInfoMap.get(detectorId.toString())); -// } -// } -// detectorMap.put(String.valueOf(detectorId), detectorData); -// detectorDataList.add(detectorMap); -// } -// -// 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); -// } -// } -// } - result.setSuccess(true); - result.setResult(stationDataList); -// } + result.setSuccess(true); + result.setResult(stationDataList); return result; } @@ -565,33 +464,6 @@ public class StationOperationServiceImpl extends ServiceImpl stationInfoMap = (HashMap) redisUtil.get("stationInfoMap"); -// List detectorsUsedList = (List) redisUtil.get("detectorsUsedList"); -// // 获取所有的台站信息 -// List stations = stationInfoMap.values().stream().sorted(Comparator.comparing(GardsStations::getStationId)).collect(Collectors.toList()); -// List stationInfos = new ArrayList<>(); -// for (GardsStations gardsStations : stations) { -// StationInfo stationInfo = new StationInfo(); -// stationInfo.setId(gardsStations.getStationId().toString()); -// stationInfo.setStationCode(gardsStations.getStationCode()); -// stationInfo.setCountryCode(gardsStations.getCountryCode()); -// stationInfo.setLon(gardsStations.getLon().toString()); -// stationInfo.setLat(gardsStations.getLat().toString()); -// stationInfo.setType(gardsStations.getType()); -// stationInfo.setDescription(gardsStations.getDescription()); -// stationInfo.setStatus(gardsStations.getStatus()); -// boolean contains = detectorsUsedList.contains(gardsStations.getStationId()); -// if (contains) { -// stationInfo.setUsed("YES"); -// } else { -// stationInfo.setUsed("NO"); -// } -// stationInfos.add(stationInfo); -// } -// RateParam mRateParam = calCulateStationData.initParameter(); -// List stationInfoList = calCulateStationData.mutiThreadGetStationInfo(stationInfos,mRateParam); return Result.OK(stationInfoList); } diff --git a/jeecg-module-station-operation/src/main/java/org/jeecg/modules/service/impl/SysUserFocusStationServiceImpl.java b/jeecg-module-station-operation/src/main/java/org/jeecg/modules/service/impl/SysUserFocusStationServiceImpl.java index 7ee0251a..b11356de 100644 --- a/jeecg-module-station-operation/src/main/java/org/jeecg/modules/service/impl/SysUserFocusStationServiceImpl.java +++ b/jeecg-module-station-operation/src/main/java/org/jeecg/modules/service/impl/SysUserFocusStationServiceImpl.java @@ -12,6 +12,7 @@ import org.jeecg.common.system.util.JwtUtil; import org.jeecg.common.util.RedisUtil; import org.jeecg.common.util.SpringContextUtils; import org.jeecg.modules.base.entity.configuration.GardsStations; +import org.jeecg.modules.base.entity.postgre.StationReceivingConfig; import org.jeecg.modules.base.entity.postgre.SysUser; import org.jeecg.modules.entity.StationReceivingConfigStation; import org.jeecg.modules.entity.SysUserFocusStationStation; @@ -27,6 +28,7 @@ import org.springframework.transaction.annotation.Transactional; import javax.servlet.http.HttpServletRequest; import java.time.LocalDateTime; import java.util.*; +import java.util.stream.Collectors; @Service("sysUserFocusStationService") public class SysUserFocusStationServiceImpl extends ServiceImpl implements ISysUserFocusStationService { @@ -134,6 +136,8 @@ public class SysUserFocusStationServiceImpl extends ServiceImpl> findStationDetectors(@RequestBody List stationIds){ - return gardsDetectorsService.findStationDetectors(stationIds); - } } diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/IGardsDetectorsService.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/IGardsDetectorsService.java index 05a0bf87..23df9ae4 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/IGardsDetectorsService.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/IGardsDetectorsService.java @@ -57,11 +57,4 @@ public interface IGardsDetectorsService extends IService { * @return */ void findDetectors(); - - /** - * 根据台站id查询对应的探测器数据信息 - * @param stationIds - * @return - */ - Map> findStationDetectors(List stationIds); } diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/GardsDetectorsServiceImpl.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/GardsDetectorsServiceImpl.java index 806b63f3..ef654a99 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/GardsDetectorsServiceImpl.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/GardsDetectorsServiceImpl.java @@ -27,6 +27,7 @@ import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import java.util.*; +import java.util.function.Function; import java.util.stream.Collectors; @Service("gardsDetectorsService") @@ -147,26 +148,26 @@ public class GardsDetectorsServiceImpl extends ServiceImpl gardsDetectors = this.baseMapper.selectList(new LambdaQueryWrapper<>()); + //根据台站id获取对应的探测集合 + Map> stationDetectorMap = new HashMap<>(); + for (GardsDetectorsSystem detectorsSystem: gardsDetectors) { + if (detectorsSystem.getStationId() != null) { + List systemList = CollectionUtils.isNotEmpty(stationDetectorMap.get(detectorsSystem.getStationId()))?stationDetectorMap.get(detectorsSystem.getStationId()):new LinkedList<>(); + if (detectorsSystem.getStatus() != null && detectorsSystem.getStatus().trim().equals(DetectorStatus.ON.getValue())) { + systemList.add(detectorsSystem); + stationDetectorMap.put(detectorsSystem.getStationId(), systemList); + } + } + } + //生成一个探测器id,探测器编码的map进行缓存 Map detectorsMap = gardsDetectors.stream().collect(Collectors.toMap(GardsDetectorsSystem::getDetectorId, GardsDetectorsSystem::getDetectorCode)); + //过滤出使用状态的探测器相关的台站信息 List detectorsUsedList = gardsDetectors.stream().filter(item -> item.getStatus()!=null && DetectorStatus.ON.getValue().equals(item.getStatus().trim())).map(GardsDetectorsSystem::getStationId).collect(Collectors.toList()); redisUtil.set("detectorsMap",detectorsMap); redisUtil.set("detectorsUsedList", detectorsUsedList); - } - - @Override - public Map> findStationDetectors(List stationIds) { - Map> map = new HashMap<>(); - if (CollectionUtils.isNotEmpty(stationIds)){ - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.in(GardsDetectorsSystem::getStationId, stationIds); - List detectorsList = this.baseMapper.selectList(queryWrapper); - for (String stationId:stationIds) { - List detectors = detectorsList.stream().filter(item -> item.getStationId()!=null && item.getStationId().equals(Integer.valueOf(stationId)) && item.getStatus()!=null && item.getStatus().trim().equals(DetectorStatus.ON.getValue())).collect(Collectors.toList()); - map.put(stationId, detectors); - } - } - return map; + redisUtil.set("stationDetectorMap", stationDetectorMap); } } diff --git a/jeecg-server-cloud/armd-station-operation-start/src/main/java/org/jeecg/JeecgStationOperationApplication.java b/jeecg-server-cloud/armd-station-operation-start/src/main/java/org/jeecg/JeecgStationOperationApplication.java index 444da5cc..8c3db501 100644 --- a/jeecg-server-cloud/armd-station-operation-start/src/main/java/org/jeecg/JeecgStationOperationApplication.java +++ b/jeecg-server-cloud/armd-station-operation-start/src/main/java/org/jeecg/JeecgStationOperationApplication.java @@ -3,6 +3,7 @@ package org.jeecg; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.jeecg.common.util.oConvertUtils; +import org.jeecg.modules.service.ISysUserFocusStationService; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -23,6 +24,7 @@ import java.net.UnknownHostException; @RequiredArgsConstructor public class JeecgStationOperationApplication extends SpringBootServletInitializer implements CommandLineRunner { + private final ISysUserFocusStationService sysUserFocusStationService; private final DataProvisionEfficiencyManager dataProvisionEfficiencyManager; private final DataReceivingStatusManager dataReceivingStatusManager; @@ -48,6 +50,7 @@ public class JeecgStationOperationApplication extends SpringBootServletInitializ @Override public void run(String... args) throws Exception { + sysUserFocusStationService.cacheStationReceivingConfig(); dataProvisionEfficiencyManager.start(); dataReceivingStatusManager.start(); }