update 拿到所有数据取出最后一条数据,对比数据变化

This commit is contained in:
2024-05-06 14:17:08 +08:00
parent 3727199935
commit eb39a4d6c3
3 changed files with 28 additions and 1 deletions

View File

@@ -1646,7 +1646,7 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
if (insert > 0) {
// 删除redis中缓存
String pileConnectorCode = transactionCode.substring(0, 16);
String redisKey = CacheConstants.PILE_REAL_TIME_MONITOR_DATA + pileConnectorCode + "_" + transactionCode;
String redisKey = CacheConstants.PILE_REAL_TIME_MONITOR_DATA + pileConnectorCode + "_" + transactionCode; // 删除redis中缓存
redisCache.deleteObject(redisKey);
}
} catch (Exception e) {

View File

@@ -1,6 +1,7 @@
package com.jsowell.pile.service.impl;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.google.common.collect.Lists;
import com.jsowell.common.constant.CacheConstants;
import com.jsowell.common.constant.Constants;
@@ -559,6 +560,28 @@ public class PileBasicInfoServiceImpl implements PileBasicInfoService {
// 保存到redis
String redisKey = CacheConstants.PILE_REAL_TIME_MONITOR_DATA + realTimeMonitorData.getPileConnectorCode() + "_" + realTimeMonitorData.getTransactionCode();
// 拿到所有数据取出最后一条数据,对比数据变化
Map<Object, Object> map = redisCache.hmget(redisKey);
if (map != null && !map.isEmpty()) {
List<String> keyList = map.keySet().stream()
.map(x -> (String) x)
.sorted(Comparator.reverseOrder()) // 对keyList排序 时间倒序
.collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(keyList)) {
// index为0是最新的时间
String lastTime = keyList.get(0);
// 取出最新的数据
Object lastData = map.get(lastTime);
RealTimeMonitorData data = JSONObject.parseObject((String) lastData, RealTimeMonitorData.class);
if (Objects.nonNull(data)) {
// 如果已充金额相同则return
if (StringUtils.equals(data.getChargingAmount(), realTimeMonitorData.getChargingAmount())) {
return;
}
}
}
}
// 设置接收到实时数据的时间
Date now = new Date();
realTimeMonitorData.setDateTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, now));