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

This commit is contained in:
2024-05-07 12:04:14 +08:00
parent 902d9b98e7
commit 7e1990c2c1

View File

@@ -1,12 +1,9 @@
package com.jsowell.pile.service.impl; package com.jsowell.pile.service.impl;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.jsowell.common.constant.CacheConstants; import com.jsowell.common.constant.CacheConstants;
import com.jsowell.common.constant.Constants; import com.jsowell.common.constant.Constants;
import com.jsowell.pile.thirdparty.ConnectorInfo;
import com.jsowell.pile.thirdparty.EquipmentInfo;
import com.jsowell.common.core.domain.vo.AuthorizedDeptVO; import com.jsowell.common.core.domain.vo.AuthorizedDeptVO;
import com.jsowell.common.core.domain.ykc.GroundLockData; import com.jsowell.common.core.domain.ykc.GroundLockData;
import com.jsowell.common.core.domain.ykc.RealTimeMonitorData; import com.jsowell.common.core.domain.ykc.RealTimeMonitorData;
@@ -20,7 +17,10 @@ import com.jsowell.common.enums.ykc.PileStatusEnum;
import com.jsowell.common.enums.ykc.ReturnCodeEnum; import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.exception.BusinessException; import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.util.*; import com.jsowell.common.util.*;
import com.jsowell.pile.domain.*; import com.jsowell.pile.domain.PileBasicInfo;
import com.jsowell.pile.domain.PileConnectorInfo;
import com.jsowell.pile.domain.PileModelInfo;
import com.jsowell.pile.domain.PileSimInfo;
import com.jsowell.pile.dto.IndexQueryDTO; import com.jsowell.pile.dto.IndexQueryDTO;
import com.jsowell.pile.dto.QueryPileDTO; import com.jsowell.pile.dto.QueryPileDTO;
import com.jsowell.pile.dto.ReplaceMerchantStationDTO; import com.jsowell.pile.dto.ReplaceMerchantStationDTO;
@@ -28,6 +28,8 @@ import com.jsowell.pile.mapper.PileBasicInfoMapper;
import com.jsowell.pile.mapper.PileMerchantInfoMapper; import com.jsowell.pile.mapper.PileMerchantInfoMapper;
import com.jsowell.pile.mapper.PileSimInfoMapper; import com.jsowell.pile.mapper.PileSimInfoMapper;
import com.jsowell.pile.service.*; import com.jsowell.pile.service.*;
import com.jsowell.pile.thirdparty.ConnectorInfo;
import com.jsowell.pile.thirdparty.EquipmentInfo;
import com.jsowell.pile.thirdparty.ZDLConnectorInfo; import com.jsowell.pile.thirdparty.ZDLConnectorInfo;
import com.jsowell.pile.thirdparty.ZDLEquipmentInfo; import com.jsowell.pile.thirdparty.ZDLEquipmentInfo;
import com.jsowell.pile.util.UserUtils; import com.jsowell.pile.util.UserUtils;
@@ -560,36 +562,27 @@ public class PileBasicInfoServiceImpl implements PileBasicInfoService {
// 保存到redis // 保存到redis
String redisKey = CacheConstants.PILE_REAL_TIME_MONITOR_DATA + realTimeMonitorData.getPileConnectorCode() + "_" + realTimeMonitorData.getTransactionCode(); String redisKey = CacheConstants.PILE_REAL_TIME_MONITOR_DATA + realTimeMonitorData.getPileConnectorCode() + "_" + realTimeMonitorData.getTransactionCode();
// 设置过期时间
try {
if (redisCache.getExpire(redisKey) < 0) {
redisCache.expire(redisKey, CacheConstants.cache_expire_time_1d);
}
} catch (Exception e) {
log.info("设置过期时间error", e);
}
// 拿到所有数据取出最后一条数据,对比数据变化 // 拿到所有数据取出最后一条数据,对比数据变化
Map<Object, Object> map = redisCache.hmget(redisKey); // Map<Object, Object> map = redisCache.hmget(redisKey);
if (map != null && !map.isEmpty()) { // if (map != null && !map.isEmpty()) {
List<String> keyList = map.keySet().stream() // List<String> keyList = map.keySet().stream()
.map(x -> (String) x) // .map(x -> (String) x)
.sorted(Comparator.reverseOrder()) // 对keyList排序 时间倒序 // .sorted(Comparator.reverseOrder()) // 对keyList排序 时间倒序
.collect(Collectors.toList()); // .collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(keyList)) { // if (CollectionUtils.isNotEmpty(keyList)) {
// index为0是最新的时间 // // index为0是最新的时间
String lastTime = keyList.get(0); // String lastTime = keyList.get(0);
// 取出最新的数据 // // 取出最新的数据
Object lastData = map.get(lastTime); // Object lastData = map.get(lastTime);
RealTimeMonitorData data = JSONObject.parseObject((String) lastData, RealTimeMonitorData.class); // RealTimeMonitorData data = JSONObject.parseObject((String) lastData, RealTimeMonitorData.class);
if (Objects.nonNull(data)) { // if (Objects.nonNull(data)) {
// 如果已充金额相同则return // // 如果已充金额相同则return
if (StringUtils.equals(data.getChargingAmount(), realTimeMonitorData.getChargingAmount())) { // if (StringUtils.equals(data.getChargingAmount(), realTimeMonitorData.getChargingAmount())) {
return; // return;
} // }
} // }
} // }
} // }
// 设置接收到实时数据的时间 // 设置接收到实时数据的时间
Date now = new Date(); Date now = new Date();
@@ -603,6 +596,15 @@ public class PileBasicInfoServiceImpl implements PileBasicInfoService {
// 上传实时数据每10秒发送一次1分钟6次在同一分钟内只保留最后一条实时数据 // 上传实时数据每10秒发送一次1分钟6次在同一分钟内只保留最后一条实时数据
redisCache.hset(redisKey, DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:00", now), jsonMsg); redisCache.hset(redisKey, DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:00", now), jsonMsg);
// 设置过期时间
try {
if (redisCache.getExpire(redisKey) < 0) {
redisCache.expire(redisKey, CacheConstants.cache_expire_time_1d);
}
} catch (Exception e) {
log.info("设置过期时间error", e);
}
// 把充电桩正在充电中的状态存到redis // 把充电桩正在充电中的状态存到redis
String pileIsChargingKey = CacheConstants.PILE_IS_CHARGING + realTimeMonitorData.getPileConnectorCode(); String pileIsChargingKey = CacheConstants.PILE_IS_CHARGING + realTimeMonitorData.getPileConnectorCode();
redisCache.setCacheObject(pileIsChargingKey, realTimeMonitorData.getTransactionCode(), 20); redisCache.setCacheObject(pileIsChargingKey, realTimeMonitorData.getTransactionCode(), 20);