新增 0x17、0x23报文解析

This commit is contained in:
Lemon
2024-12-10 14:32:09 +08:00
parent fa578f31e4
commit 19f8aeb07a
8 changed files with 493 additions and 39 deletions

View File

@@ -1,5 +1,6 @@
package com.jsowell.pile.service;
import com.jsowell.common.core.domain.ykc.BMSDemandAndChargerOutputData;
import com.jsowell.common.core.domain.ykc.RealTimeMonitorData;
import com.jsowell.pile.domain.PileBasicInfo;
import com.jsowell.pile.domain.ebike.deviceupload.EBikeMessageCmd20;
@@ -151,6 +152,19 @@ public interface PileBasicInfoService {
*/
void saveRealTimeMonitorData2Redis(RealTimeMonitorData realTimeMonitorData);
/**
* 0x23数据保存到redis
* @param bmsDemandAndChargerOutputData
*/
void saveBMSDemandAndChargerOutputInfo2Redis(BMSDemandAndChargerOutputData bmsDemandAndChargerOutputData);
/**
* 根据交易流水号查询0x23数据时间倒序
* @param transactionCode
* @return
*/
List<BMSDemandAndChargerOutputData> getBMSDemandAndChargerOutputInfoList(String transactionCode);
PileConnectorDetailVO queryPileConnectorDetail(String pileConnectorCode);
String getPileQrCodeUrl(String pileSn);

View File

@@ -1,11 +1,13 @@
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.YouDianUtils;
import com.jsowell.common.constant.CacheConstants;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.domain.vo.AuthorizedDeptVO;
import com.jsowell.common.core.domain.ykc.BMSDemandAndChargerOutputData;
import com.jsowell.common.core.domain.ykc.GroundLockData;
import com.jsowell.common.core.domain.ykc.RealTimeMonitorData;
import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode;
@@ -663,6 +665,66 @@ public class PileBasicInfoServiceImpl implements PileBasicInfoService {
redisCache.setCacheObject(pileIsChargingKey, realTimeMonitorData.getTransactionCode(), 20);
}
/**
* 0x23信息设置缓存 (缓存时间3天)
* @param data
*/
public void saveBMSDemandAndChargerOutputInfo2Redis(BMSDemandAndChargerOutputData data) {
if (StringUtils.equals(data.getTransactionCode(), Constants.ILLEGAL_TRANSACTION_CODE)) {
return;
}
// 保存到redis
String redisKey = CacheConstants.BMS_CHARGE_INFO_BY_TRANSACTION_CODE + data.getTransactionCode();
// 设置接收到实时数据的时间
Date now = new Date();
data.setDateTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, now));
// 计算功率,后面查询要用
String power = new BigDecimal(data.getPileVoltageOutput())
.multiply(new BigDecimal(data.getPileCurrentOutput())).setScale(2, RoundingMode.HALF_UP).toString();
data.setOutputPower(power);
// 保存json字符串
String jsonMsg = JSON.toJSONString(data);
// 0x23数据20秒发送一次1分钟3次在同一分钟内只保留最后一条实时数据
redisCache.hset(redisKey, DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:00", now), jsonMsg);
// 设置过期时间
try {
redisCache.expire(redisKey, CacheConstants.cache_expire_time_3d);
// if (redisCache.getExpire(redisKey) < 0) {
// }
} catch (Exception e) {
log.info("0x23存入缓存设置过期时间error", e);
}
}
/**
* 根据交易流水号查询0x23数据时间倒序
* @param transactionCode
* @return
*/
@Override
public List<BMSDemandAndChargerOutputData> getBMSDemandAndChargerOutputInfoList(String transactionCode) {
List<BMSDemandAndChargerOutputData> resultList = Lists.newArrayList();
if (StringUtils.isBlank(transactionCode)) {
return resultList;
}
String redisKey = CacheConstants.BMS_CHARGE_INFO_BY_TRANSACTION_CODE + transactionCode;
// 拿到所有数据
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());
for (String s : keyList) {
Object o = map.get(s);
BMSDemandAndChargerOutputData data = JSONObject.parseObject((String) o, BMSDemandAndChargerOutputData.class);
resultList.add(data);
}
}
return resultList;
}
@Override
public PileConnectorDetailVO queryPileConnectorDetail(String pileConnectorCode) {
return pileBasicInfoMapper.queryPileConnectorDetail(pileConnectorCode);