From 7130d28d70a63767975c9c59e10cc555511976ce Mon Sep 17 00:00:00 2001
From: ‘liusuyi’ <1951119284@qq.com>
Date: 星期六, 16 九月 2023 16:21:06 +0800
Subject: [PATCH] 优化
---
ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java | 14 +++
ard-work/src/main/java/com/ruoyi/alarm/global/service/impl/GlobalAlarmServiceImpl.java | 165 ++++++++++++++++++++++++-----------------
ard-work/src/main/java/com/ruoyi/alarm/radar/mapper/ArdAlarmRadarMoveMapper.java | 5 -
ruoyi-common/src/main/java/com/ruoyi/common/core/redis/RedisCache.java | 27 ++++++
4 files changed, 138 insertions(+), 73 deletions(-)
diff --git a/ard-work/src/main/java/com/ruoyi/alarm/global/service/impl/GlobalAlarmServiceImpl.java b/ard-work/src/main/java/com/ruoyi/alarm/global/service/impl/GlobalAlarmServiceImpl.java
index f6b19e8..70a9e07 100644
--- a/ard-work/src/main/java/com/ruoyi/alarm/global/service/impl/GlobalAlarmServiceImpl.java
+++ b/ard-work/src/main/java/com/ruoyi/alarm/global/service/impl/GlobalAlarmServiceImpl.java
@@ -114,6 +114,7 @@
private Map<String, Integer> unGuideCountMapMove = new HashMap<>();
private Map<String, Integer> unGuideCountMapFire = new HashMap<>();
private Map<String, Integer> unGuideCountMapPump = new HashMap<>();
+
/**
* @鎻忚堪 鏌ヨ鎵�鏈夋姤璀︾殑褰撳墠鏁伴噺
* @鍙傛暟 []
@@ -309,6 +310,7 @@
return null;
}
}
+
/**
* 鑾峰彇鐑姏鍥炬暟鎹�
* 鍒樿嫃涔�
@@ -348,19 +350,38 @@
return globalAlarmData;
}).collect(Collectors.toList());
case 1003:
- List<ArdAlarmRadarMove> ardAlarmRadarMoves = ardAlarmRadarMoveMapper.selectListAllByCommand(refreshTime);
- return ardAlarmRadarMoves.stream()
- .map(ardAlarmRadarMove -> {
- GlobalAlarmData globalAlarmData = new GlobalAlarmData()
- .setId(ardAlarmRadarMove.getId())
- .setName(ardAlarmRadarMove.getName())
- .setAlarmTime(ardAlarmRadarMove.getAlarmTime())
- .setLongitude(ardAlarmRadarMove.getLongitude())
- .setLatitude(ardAlarmRadarMove.getLatitude())
- .setCount(ardAlarmRadarMove.getCount())
- .setTotal(ardAlarmRadarMove.getTotal());
- return globalAlarmData;
- }).collect(Collectors.toList());
+ //浠庣紦瀛樿幏鍙栨暟鎹�
+ //String key = "radar_alarm:" + DateUtils.getDate();
+ //List<ArdAlarmRadarMove> ardAlarmRadarMoves = redisCache.getCacheList(key);
+ //Map<String, List<ArdAlarmRadarMove>> groupedData = ardAlarmRadarMoves.stream()
+ // .collect(Collectors.groupingBy(ArdAlarmRadarMove::getName));
+ //List<GlobalAlarmData> globalAlarmDataList = new ArrayList<>();
+ //for (String name : groupedData.keySet()) {
+ // List<ArdAlarmRadarMove> ardAlarmRadarMove = groupedData.get(name);
+ // GlobalAlarmData globalAlarmData = new GlobalAlarmData()
+ // .setId(ardAlarmRadarMove.get(0).getId())
+ // .setName(name)
+ // .setAlarmTime(ardAlarmRadarMove.get(0).getAlarmTime())
+ // .setLongitude(ardAlarmRadarMove.get(0).getLongitude())
+ // .setLatitude(ardAlarmRadarMove.get(0).getLatitude())
+ // .setTotal(ardAlarmRadarMove.size());
+ // globalAlarmDataList.add(globalAlarmData);
+ //}
+ //return globalAlarmDataList;
+ //浠庢暟鎹簱鑾峰彇
+ List<ArdAlarmRadarMove> ardAlarmRadarMoves = ardAlarmRadarMoveMapper.selectListAllByCommand(refreshTime);
+ return ardAlarmRadarMoves.stream()
+ .map(ardAlarmRadarMove -> {
+ GlobalAlarmData globalAlarmData = new GlobalAlarmData()
+ .setId(ardAlarmRadarMove.getId())
+ .setName(ardAlarmRadarMove.getName())
+ .setAlarmTime(ardAlarmRadarMove.getAlarmTime())
+ .setLongitude(ardAlarmRadarMove.getLongitude())
+ .setLatitude(ardAlarmRadarMove.getLatitude())
+ .setCount(ardAlarmRadarMove.getCount())
+ .setTotal(ardAlarmRadarMove.getTotal());
+ return globalAlarmData;
+ }).collect(Collectors.toList());
case 1004:
List<ArdAlarmRadarFire> ardAlarmRadarFires = ardAlarmRadarFireMapper.selectListAllByCommand(refreshTime);
return ardAlarmRadarFires.stream()
@@ -484,12 +505,12 @@
.setAlarmType("1001");
return globalAlarmData;
}).collect(Collectors.toList());
- if(alarmData1001.size()>0) {
+ if (alarmData1001.size() > 0) {
GlobalAlarmDataList.addAll(alarmData1001);
}
List<ArdAlarmCamera> ardAlarmCameras = ardAlarmCameraMapper.selectListAllByCommand(refreshTime);
- List<GlobalAlarmData> alarmData1002= ardAlarmCameras.stream()
+ List<GlobalAlarmData> alarmData1002 = ardAlarmCameras.stream()
.map(ardAlarmCamera -> {
GlobalAlarmData globalAlarmData = new GlobalAlarmData()
.setId(ardAlarmCamera.getId())
@@ -502,12 +523,12 @@
.setAlarmType("1002");
return globalAlarmData;
}).collect(Collectors.toList());
- if(alarmData1002.size()>0) {
+ if (alarmData1002.size() > 0) {
GlobalAlarmDataList.addAll(alarmData1002);
}
List<ArdAlarmRadarMove> ardAlarmRadarMoves = ardAlarmRadarMoveMapper.selectListAllByCommand(refreshTime);
- List<GlobalAlarmData> alarmData1003= ardAlarmRadarMoves.stream()
+ List<GlobalAlarmData> alarmData1003 = ardAlarmRadarMoves.stream()
.map(ardAlarmRadarMove -> {
GlobalAlarmData globalAlarmData = new GlobalAlarmData()
.setId(ardAlarmRadarMove.getId())
@@ -520,12 +541,12 @@
.setAlarmType("1003");
return globalAlarmData;
}).collect(Collectors.toList());
- if(alarmData1003.size()>0) {
+ if (alarmData1003.size() > 0) {
GlobalAlarmDataList.addAll(alarmData1003);
}
List<ArdAlarmRadarFire> ardAlarmRadarFires = ardAlarmRadarFireMapper.selectListAllByCommand(refreshTime);
- List<GlobalAlarmData> alarmData1004= ardAlarmRadarFires.stream()
+ List<GlobalAlarmData> alarmData1004 = ardAlarmRadarFires.stream()
.map(ardAlarmRadarFire -> {
GlobalAlarmData globalAlarmData = new GlobalAlarmData()
.setId(ardAlarmRadarFire.getId())
@@ -538,12 +559,12 @@
.setAlarmType("1004");
return globalAlarmData;
}).collect(Collectors.toList());
- if(alarmData1004.size()>0) {
+ if (alarmData1004.size() > 0) {
GlobalAlarmDataList.addAll(alarmData1004);
}
List<ArdAlarmExternal> ardAlarmExternals = ardAlarmExternalMapper.selectListAllByCommand(refreshTime, "闃插尯鎶ヨ");
- List<GlobalAlarmData> alarmData1005= ardAlarmExternals.stream()
+ List<GlobalAlarmData> alarmData1005 = ardAlarmExternals.stream()
.map(ardAlarmExternal -> {
GlobalAlarmData globalAlarmData = new GlobalAlarmData()
.setId(ardAlarmExternal.getId())
@@ -556,12 +577,12 @@
.setAlarmType("1005");
return globalAlarmData;
}).collect(Collectors.toList());
- if(alarmData1005.size()>0) {
+ if (alarmData1005.size() > 0) {
GlobalAlarmDataList.addAll(alarmData1005);
}
List<ArdAlarmAccess> ardAlarmAccesses = ardAlarmAccessMapper.selectListAllByCommand(refreshTime);
- List<GlobalAlarmData> alarmData1006= ardAlarmAccesses.stream()
+ List<GlobalAlarmData> alarmData1006 = ardAlarmAccesses.stream()
.map(ardAlarmAccess -> {
GlobalAlarmData globalAlarmData = new GlobalAlarmData()
.setId(ardAlarmAccess.getId())
@@ -574,12 +595,12 @@
.setAlarmType("1006");
return globalAlarmData;
}).collect(Collectors.toList());
- if(alarmData1006.size()>0) {
+ if (alarmData1006.size() > 0) {
GlobalAlarmDataList.addAll(alarmData1006);
}
List<ArdAlarmRadarPump> ardAlarmRadarPumps = ardAlarmRadarPumpMapper.selectListAllByCommand(refreshTime);
- List<GlobalAlarmData> alarmData1007= ardAlarmRadarPumps.stream()
+ List<GlobalAlarmData> alarmData1007 = ardAlarmRadarPumps.stream()
.map(ardAlarmRadarPump -> {
GlobalAlarmData globalAlarmData = new GlobalAlarmData()
.setId(ardAlarmRadarPump.getId())
@@ -592,12 +613,12 @@
.setAlarmType("1007");
return globalAlarmData;
}).collect(Collectors.toList());
- if(alarmData1007.size()>0) {
+ if (alarmData1007.size() > 0) {
GlobalAlarmDataList.addAll(alarmData1007);
}
List<ArdAlarmApponekey> ardAlarmApponekeys = ardAlarmApponekeyMapper.selectListAllByCommand(refreshTime);
- List<GlobalAlarmData> alarmData1009= ardAlarmApponekeys.stream()
+ List<GlobalAlarmData> alarmData1009 = ardAlarmApponekeys.stream()
.map(ardAlarmApponekey -> {
GlobalAlarmData globalAlarmData = new GlobalAlarmData()
.setId(ardAlarmApponekey.getId())
@@ -610,12 +631,12 @@
.setAlarmType("1009");
return globalAlarmData;
}).collect(Collectors.toList());
- if(alarmData1009.size()>0) {
+ if (alarmData1009.size() > 0) {
GlobalAlarmDataList.addAll(alarmData1009);
}
List<ArdAlarmWall> ardAlarmWalls = ardAlarmWallMapper.selectListAllByCommand(refreshTime);
- List<GlobalAlarmData> alarmData1010= ardAlarmWalls.stream()
+ List<GlobalAlarmData> alarmData1010 = ardAlarmWalls.stream()
.map(ardAlarmWall -> {
GlobalAlarmData globalAlarmData = new GlobalAlarmData()
.setId(ardAlarmWall.getId())
@@ -628,12 +649,12 @@
.setAlarmType("1010");
return globalAlarmData;
}).collect(Collectors.toList());
- if(alarmData1010.size()>0) {
+ if (alarmData1010.size() > 0) {
GlobalAlarmDataList.addAll(alarmData1010);
}
List<ArdAlarmTube> ardAlarmTubes = ardAlarmTubeMapper.selectListAllByCommand(refreshTime);
- List<GlobalAlarmData> alarmData1014= ardAlarmTubes.stream()
+ List<GlobalAlarmData> alarmData1014 = ardAlarmTubes.stream()
.map(ardAlarmTube -> {
GlobalAlarmData globalAlarmData = new GlobalAlarmData()
.setId(ardAlarmTube.getId())
@@ -647,11 +668,11 @@
.setAlarmType("1014");
return globalAlarmData;
}).collect(Collectors.toList());
- if(alarmData1014.size()>0) {
+ if (alarmData1014.size() > 0) {
GlobalAlarmDataList.addAll(alarmData1014);
}
return GlobalAlarmDataList;
-}
+ }
/**
* @鎻忚堪 鍘嗗彶鎶ヨ鏌ヨ
@@ -915,18 +936,18 @@
//region 澶勭悊闆疯揪鎶ヨ
RadarAlarmData radarAlarmData = JSONObject.parseObject(message, RadarAlarmData.class);
List<ArdAlarmRadar> ardAlarmRadars = radarAlarmData.getArdAlarmRadars();
- List<ArdAlarmRadarMove>ardAlarmRadarMoves=new ArrayList<>();
- List<ArdAlarmRadarFire>ardAlarmRadarFires=new ArrayList<>();
- List<ArdAlarmRadarPump>ardAlarmRadarPumps=new ArrayList<>();
+ List<ArdAlarmRadarMove> ardAlarmRadarMoves = new ArrayList<>();
+ List<ArdAlarmRadarFire> ardAlarmRadarFires = new ArrayList<>();
+ List<ArdAlarmRadarPump> ardAlarmRadarPumps = new ArrayList<>();
for (ArdAlarmRadar ardAlarmRadar : ardAlarmRadars) {
String uuid = IdUtils.simpleUUID();
String alarmpointName = ardAlarmRadar.getName();//鍏磋叮鐐瑰悕绉�
Double longitude = ardAlarmRadar.getLongitude();
Double latitude = ardAlarmRadar.getLatitude();
- String targetId=ardAlarmRadar.getTargetId();
+ String targetId = ardAlarmRadar.getTargetId();
switch (ardAlarmRadar.getAlarmType()) {
case "杩愬姩鐩爣妫�娴�":
- ArdAlarmRadarMove ardAlarmRadarMove=new ArdAlarmRadarMove();
+ ArdAlarmRadarMove ardAlarmRadarMove = new ArdAlarmRadarMove();
ardAlarmRadarMove.setId(uuid);
ardAlarmRadarMove.setTargetId(targetId);
ardAlarmRadarMove.setAlarmTime(radarAlarmData.getAlarmTime());
@@ -938,10 +959,17 @@
//鍏ュ簱
ardAlarmRadarMoveMapper.insertArdAlarmRadarMove(ardAlarmRadarMove);
ardAlarmRadarMoves.add(ardAlarmRadarMove);
-
+ //鍏ョ紦瀛�
+ //String key = "radar_alarm:" + DateUtils.getDate();
+ //if (redisCache.hasKey(key)) {
+ // redisCache.setCacheList(key, ardAlarmRadarMove, -1, TimeUnit.HOURS);
+ //} else {
+ // Integer expiryTimeInSeconds = DateUtils.getDayRemainingTime(ardAlarmRadarMove.getCreateTime());
+ // redisCache.setCacheList(key, ardAlarmRadarMove, expiryTimeInSeconds, TimeUnit.SECONDS);
+ //}
break;
case "鐑簮妫�娴�":
- ArdAlarmRadarFire ardAlarmRadarFire=new ArdAlarmRadarFire();
+ ArdAlarmRadarFire ardAlarmRadarFire = new ArdAlarmRadarFire();
ardAlarmRadarFire.setId(uuid);
ardAlarmRadarFire.setTargetId(targetId);
ardAlarmRadarFire.setAlarmTime(radarAlarmData.getAlarmTime());
@@ -956,7 +984,7 @@
break;
case "闆疯揪鎶芥补鏈哄仠鏈�":
- ArdAlarmRadarPump ardAlarmRadarPump=new ArdAlarmRadarPump();
+ ArdAlarmRadarPump ardAlarmRadarPump = new ArdAlarmRadarPump();
ardAlarmRadarPump.setId(uuid);
ardAlarmRadarPump.setTargetId(targetId);
ardAlarmRadarPump.setAlarmTime(radarAlarmData.getAlarmTime());
@@ -975,9 +1003,9 @@
break;
}
}
- radarMoveGuide(ardAlarmRadarMoves,radarAlarmData);
- radarFireGuide(ardAlarmRadarFires,radarAlarmData);
- radarPumpGuide(ardAlarmRadarPumps,radarAlarmData);
+ radarMoveGuide(ardAlarmRadarMoves, radarAlarmData);
+ radarFireGuide(ardAlarmRadarFires, radarAlarmData);
+ radarPumpGuide(ardAlarmRadarPumps, radarAlarmData);
break;
case "external":
//region 澶勭悊澶栬仈鎶ヨ
@@ -1074,13 +1102,20 @@
//鐩告満ID
guideTask.setCameraId(cameraId);
//鎶ヨ绫诲瀷
- String aType="";
- switch (alarmType)
- {
- case "杩愬姩鐩爣妫�娴�": aType="sys_radar_move";break;
- case "鐑簮妫�娴�": aType="sys_radar_fire";break;
- case "闆疯揪鎶芥补鏈哄仠鏈�": aType="sys_radar_pump";break;
- default: aType=alarmType;break;
+ String aType = "";
+ switch (alarmType) {
+ case "杩愬姩鐩爣妫�娴�":
+ aType = "sys_radar_move";
+ break;
+ case "鐑簮妫�娴�":
+ aType = "sys_radar_fire";
+ break;
+ case "闆疯揪鎶芥补鏈哄仠鏈�":
+ aType = "sys_radar_pump";
+ break;
+ default:
+ aType = alarmType;
+ break;
}
guideTask.setAlarmType(aType);
//閫氶亾(閫氳繃鏃ュ鏃堕棿鐮斿垽)
@@ -1170,11 +1205,10 @@
return minDistanceCameraId;
}
-
/**
* 闆疯揪寮曞鍏ラ槦
*/
- private void radarGuideToQueue(String alarmId,String radarId, String name, String alarmType, Date createTime, double[] coordinate) {
+ private void radarGuideToQueue(String alarmId, String radarId, String name, String alarmType, Date createTime, double[] coordinate) {
int index = name.indexOf("(");
String alarmpointName = name.substring(0, index);
//鑾峰彇闆疯揪鎵�鍦ㄥ涓婄殑澶у厜鐢�
@@ -1183,9 +1217,7 @@
log.debug("鑾峰彇鍒伴浄杈惧涓婄殑鍏夌數:" + cameraIdWithTower);
//濡傛灉闆疯揪濉斾笂鏈夊厜鐢�
messagesEnqueued(cameraIdWithTower, alarmId, alarmType, createTime, 1, 1, coordinate);
- }
- else
- {
+ } else {
log.debug("鏈幏鍙栧埌闆疯揪濉斾笂鐨勫厜鐢�");
}
//鑾峰彇鎶ヨ鐐瑰叧鑱旂殑澶у厜鐢�
@@ -1198,20 +1230,17 @@
log.info("鑾峰彇鍒版姤璀︾偣鍏宠仈鐨勫厜鐢�:" + cameraId);
//濡傛灉鎶ヨ鐐瑰叧鑱斾簡鍏夌數
messagesEnqueued(cameraId, alarmId, alarmType, createTime, 1, 2, coordinate);
- }
- else
- {
+ } else {
log.debug("鏈幏鍙栧埌鎶ヨ鐐瑰叧鑱旂殑鍏夌數");
}
}
- private void radarMoveGuide(List<ArdAlarmRadarMove> ardAlarmRadarMoves,RadarAlarmData radarAlarmData)
- {
+ private void radarMoveGuide(List<ArdAlarmRadarMove> ardAlarmRadarMoves, RadarAlarmData radarAlarmData) {
//鎸夊叴瓒g偣鍘婚噸,鐒跺悗鎸夊紩瀵奸�昏緫杩涜寮曞鍏ラ槦
ardAlarmRadarMoves = ardAlarmRadarMoves.stream()
.collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new java.util.TreeSet<>(java.util.Comparator.comparing(ArdAlarmRadarMove::getName))), ArrayList::new));
- if(ardAlarmRadarMoves.size()>0) {
+ if (ardAlarmRadarMoves.size() > 0) {
for (ArdAlarmRadarMove ardAlarmRadarMove : ardAlarmRadarMoves) {
//閬嶅巻鎶ヨ鏁版嵁杩涜寮曞
if (StringUtils.isNull(ardAlarmRadarMove.getLongitude()) || StringUtils.isNull(ardAlarmRadarMove.getLatitude())) {
@@ -1259,12 +1288,12 @@
}
//endregion
}
- private void radarFireGuide(List<ArdAlarmRadarFire> ardAlarmRadarFires,RadarAlarmData radarAlarmData)
- {
+
+ private void radarFireGuide(List<ArdAlarmRadarFire> ardAlarmRadarFires, RadarAlarmData radarAlarmData) {
//鎸夊叴瓒g偣鍘婚噸,鐒跺悗鎸夊紩瀵奸�昏緫杩涜寮曞鍏ラ槦
ardAlarmRadarFires = ardAlarmRadarFires.stream()
.collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new java.util.TreeSet<>(java.util.Comparator.comparing(ArdAlarmRadarFire::getName))), ArrayList::new));
- if(ardAlarmRadarFires.size()>0) {
+ if (ardAlarmRadarFires.size() > 0) {
for (ArdAlarmRadarFire ardAlarmRadarFire : ardAlarmRadarFires) {
//閬嶅巻鎶ヨ鏁版嵁杩涜寮曞
if (StringUtils.isNull(ardAlarmRadarFire.getLongitude()) || StringUtils.isNull(ardAlarmRadarFire.getLatitude())) {
@@ -1311,12 +1340,12 @@
}
//endregion
}
- private void radarPumpGuide(List<ArdAlarmRadarPump> ardAlarmRadarPumps,RadarAlarmData radarAlarmData)
- {
+
+ private void radarPumpGuide(List<ArdAlarmRadarPump> ardAlarmRadarPumps, RadarAlarmData radarAlarmData) {
//鎸夊叴瓒g偣鍘婚噸,鐒跺悗鎸夊紩瀵奸�昏緫杩涜寮曞鍏ラ槦
ardAlarmRadarPumps = ardAlarmRadarPumps.stream()
.collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new java.util.TreeSet<>(java.util.Comparator.comparing(ArdAlarmRadarPump::getName))), ArrayList::new));
- if(ardAlarmRadarPumps.size()>0) {
+ if (ardAlarmRadarPumps.size() > 0) {
for (ArdAlarmRadarPump ardAlarmRadarPump : ardAlarmRadarPumps) {
//閬嶅巻鎶ヨ鏁版嵁杩涜寮曞
if (StringUtils.isNull(ardAlarmRadarPump.getLongitude()) || StringUtils.isNull(ardAlarmRadarPump.getLatitude())) {
diff --git a/ard-work/src/main/java/com/ruoyi/alarm/radar/mapper/ArdAlarmRadarMoveMapper.java b/ard-work/src/main/java/com/ruoyi/alarm/radar/mapper/ArdAlarmRadarMoveMapper.java
index 60dbd8c..6cd0d81 100644
--- a/ard-work/src/main/java/com/ruoyi/alarm/radar/mapper/ArdAlarmRadarMoveMapper.java
+++ b/ard-work/src/main/java/com/ruoyi/alarm/radar/mapper/ArdAlarmRadarMoveMapper.java
@@ -65,8 +65,5 @@
int selectCountByAlarmTime(@Param("refreshTime") String refreshTime);
List<ArdAlarmRadarMove> selectListAllByCommand(@Param("refreshTime") String refreshTime);
public int updateViewTimeByCondition(@Param("name")String name,@Param("alarmTime") String alarmTime,@Param("viewTime") String viewTime);
- /**
- * 閫氳繃闆疯揪id鎵惧埌鍏宠仈濉斾笂鐨勫ぇ鍏夌數id
- */
- String getCameraByRadar(String radarId);
+
}
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/redis/RedisCache.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/redis/RedisCache.java
index e035b3c..1d21301 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/core/redis/RedisCache.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/redis/RedisCache.java
@@ -138,6 +138,15 @@
return redisTemplate.opsForList().range(key, 0, -1);
}
+ public <T> void setCacheList(String key, T data, final Integer timeout, final TimeUnit timeUnit) {
+ // 灏嗘暟鎹彃鍏ist
+ redisTemplate.opsForList().leftPush(key, data);
+ // 璁剧疆杩囨湡鏃堕棿
+ if (timeout > 0) {
+ redisTemplate.expire(key,timeout, timeUnit);
+ }
+ }
+
/**
* 缂撳瓨Set
*
@@ -153,7 +162,23 @@
}
return setOperation;
}
-
+ /**
+ * 缂撳瓨Set
+ *
+ * @param key 缂撳瓨閿��
+ * @param data 缂撳瓨鐨勫��
+ * @param timeout 鏃堕棿
+ * @param timeUnit 鏃堕棿棰楃矑搴�
+ * @return 缂撳瓨鏁版嵁鐨勫璞�
+ */
+ public <T> void setCacheSet(String key, T data, final Integer timeout, final TimeUnit timeUnit) {
+ BoundSetOperations<String, String> setOperations = redisTemplate.boundSetOps(key);
+ setOperations.add(data.toString());
+ // 璁剧疆杩囨湡鏃堕棿
+ if (timeout > 0) {
+ setOperations.expire(timeout, timeUnit);
+ }
+ }
/**
* 鑾峰緱缂撳瓨鐨剆et
*
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java
index 4a46064..3ff67fb 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java
@@ -8,6 +8,7 @@
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
+import java.time.temporal.ChronoUnit;
import java.util.Date;
import org.apache.commons.lang3.time.DateFormatUtils;
@@ -207,4 +208,17 @@
long sec = diff/ ns;
return sec;
}
+
+ /**
+ * 鑾峰彇涓�澶╀腑鍓╀綑鐨勬椂闂达紙绉掓暟锛�
+ */
+ public static Integer getDayRemainingTime(Date currentDate) {
+ LocalDateTime midnight = LocalDateTime.ofInstant(currentDate.toInstant(),
+ ZoneId.systemDefault()).plusDays(1).withHour(0).withMinute(0)
+ .withSecond(0).withNano(0);
+ LocalDateTime currentDateTime = LocalDateTime.ofInstant(currentDate.toInstant(),
+ ZoneId.systemDefault());
+ long seconds = ChronoUnit.SECONDS.between(currentDateTime, midnight);
+ return (int) seconds;
+ }
}
--
Gitblit v1.9.3