From 3dc21e8893d17e2a25f50efeb7eec100c8e882ee Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期三, 26 四月 2023 13:32:17 +0800 Subject: [PATCH] 1 --- src/main/java/com/yssh/service/impl/WarningAnalyseServiceImpl.java | 30 ++++++++++++++ src/main/java/com/yssh/controller/WarningAnalyseController.java | 32 +++++++++++++++- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/yssh/controller/WarningAnalyseController.java b/src/main/java/com/yssh/controller/WarningAnalyseController.java index 00c7a19..7a63715 100644 --- a/src/main/java/com/yssh/controller/WarningAnalyseController.java +++ b/src/main/java/com/yssh/controller/WarningAnalyseController.java @@ -12,6 +12,12 @@ import com.yssh.service.IWarningAnalyseService; import com.yssh.utils.Result; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + @Api(tags="鍛婅鍒嗘瀽") @RequestMapping("/warning") @RestController @@ -20,6 +26,12 @@ @Autowired private IWarningAnalyseService warningService; + + private static ConcurrentHashMap<String, Object> cache = new ConcurrentHashMap<>(5); + + private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); + + public static final long CACHE_HOLD_TIME_24H = 24 * 60 * 60 * 1000L; //鎶ヨ鍒嗘瀽 /** @@ -62,8 +74,24 @@ @ApiOperationSupport(order = 4) @ApiOperation(value = "涓夊皬鏃剁洃娴嬬珯鐐规暟鎹彉鍖栬秼鍔�", notes = "杩斿洖鍊间负涓夊皬鏃剁洃娴嬬珯鐐圭洃娴嬫暟鎹紝杩斿洖鍊间负map闆嗗悎锛屽叾涓璳ey涓虹珯鐐瑰悕绉帮紝value涓簂ist闆嗗悎锛屼繚瀛樻瘡澶╃洃娴嬫暟鍊兼暟鎹�") @GetMapping("/locationDataChange") - public Result locationDataChange(){ - return Result.OK(warningService.selectEachLocationDataChange()); + public Result locationDataChange() { + //return Result.OK(warningService.selectEachLocationDataChange()); + + String key = dateFormat.format(new Date()); + Map<String, List<Double>> map = null; + if (cache.containsKey(key)) { + map = (Map<String, List<Double>>) cache.get(key); + } else { + map = warningService.selectEachLocationDataChange(); + if (null != map && map.size() > 0) { + if (cache.size() > 0) { + cache.clear(); + } + cache.put(key, map); + } + } + + return Result.ok(map); } @ApiOperationSupport(order = 4) diff --git a/src/main/java/com/yssh/service/impl/WarningAnalyseServiceImpl.java b/src/main/java/com/yssh/service/impl/WarningAnalyseServiceImpl.java index 02ca1d7..eccd472 100644 --- a/src/main/java/com/yssh/service/impl/WarningAnalyseServiceImpl.java +++ b/src/main/java/com/yssh/service/impl/WarningAnalyseServiceImpl.java @@ -229,7 +229,7 @@ @Override public Map<String, List<Double>> selectEachLocationDataChange() { - Map<String, List<Double>> result = new LinkedHashMap<>(); + /*Map<String, List<Double>> result = new LinkedHashMap<>(); List<MonitorPointPosition> checkPoints = commonService.getCheckPoints3d(); Date nowDate = DateUtils.getNowDate(); Long endTime = Long.parseLong(DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH, nowDate)); @@ -249,6 +249,34 @@ result.put(c.getName(), values); } }); + return result;*/ + + Map<String, List<Double>> result = new LinkedHashMap<>(); + List<MonitorPointPosition> checkPoints = commonService.getCheckPoints3d(); + + Date nowDate = DateUtils.getNowDate(); + Long endTime = Long.parseLong(DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH, nowDate)); + Long startTime = Long.parseLong(DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH, DateUtils.getAPeriodOfTime(nowDate, -3, Calendar.HOUR_OF_DAY))); + List<DictRecord> recordList = dictRecordMapper.selectByTimeDictRecordList(startTime, endTime); + + List<String> tableNames = new ArrayList<>(); + for(DictRecord dr : recordList){ + if (suYuanMapper.isTableExists(dr.getTableName())>0){ + tableNames.add(dr.getTableName()); + } + } + if (tableNames.isEmpty()){ + return result; + } + + for(MonitorPointPosition c : checkPoints){ + List<Double> values = new ArrayList<>(); + List<SuYuanMonitorData> data = suYuanMapper.getMonitorData(tableNames, c.getId()); + data.forEach(v -> { + values.add(v.getValue()); + }); + result.put(c.getName(), values); + } return result; } -- Gitblit v1.9.3