中控上报信息存储优化

This commit is contained in:
attiya 2025-12-03 10:50:13 +08:00
parent a907d7891b
commit cef25e8180
5 changed files with 47 additions and 7 deletions

View File

@ -321,7 +321,7 @@ public class EbikeBikeInfoServiceImpl extends ServiceImpl<EbikeBikeInfoMapper, E
}
EbikeEcuInfo ebikeEcuInfo = ebikeEcuInfoService.getEcu(bikeCode);
ResGPSDto resGPSDto = (ResGPSDto)redisUtil.get(RedisUtil.Database.DB2, ebikeEcuInfo.getEcuSn());
ResGPSDto resGPSDto = (ResGPSDto)redisUtil.getEcu(ebikeEcuInfo.getEcuSn());
if (resGPSDto.getSoc() < 20){
throw new EbikeException("该车辆电量低,暂不能骑行");
@ -382,7 +382,7 @@ public class EbikeBikeInfoServiceImpl extends ServiceImpl<EbikeBikeInfoMapper, E
EbikeEcuInfo ecuInfo = ebikeEcuInfoService.getOne(query);
int soc = 0;
if (ecuInfo != null) {
ResGPSDto resGPSDto = (ResGPSDto) redisUtil.get(RedisUtil.Database.DB2,ecuInfo.getEcuSn());
ResGPSDto resGPSDto = (ResGPSDto) redisUtil.getEcu(ecuInfo.getEcuSn());
soc = resGPSDto.getSoc();
}
if (specialBillingConfiguration == null || specialBillingConfiguration.getType() == SpecialBillingConfigurationType.CLOSED) {

View File

@ -185,7 +185,7 @@ public class EbikeBikeOrderServiceImpl extends ServiceImpl<EbikeBikeOrderMapper,
.leftJoin(EBIKE_BIKE_INFO).on(EBIKE_BIKE_INFO.BIKE_CODE.eq(EBIKE_BIKE_ORDER.BIKE_CODE))
.leftJoin(EBIKE_ECU_INFO).on(EBIKE_ECU_INFO.ECU_ID.eq(EBIKE_BIKE_INFO.ECU_ID));
EbikeBikeOrderInfoDto infoDto = this.mapper.selectOneWithRelationsByQueryAs(queryWrapper, EbikeBikeOrderInfoDto.class);
ResGPSDto resGPSDto = (ResGPSDto) redisUtil.get(RedisUtil.Database.DB2, infoDto.getEcuSn());
ResGPSDto resGPSDto = (ResGPSDto) redisUtil.getEcu(infoDto.getEcuSn());
if (Objects.nonNull(resGPSDto)) {
infoDto.setSoc(resGPSDto.getSoc());
}
@ -315,6 +315,13 @@ public class EbikeBikeOrderServiceImpl extends ServiceImpl<EbikeBikeOrderMapper,
@Override
public void batteryChange(EbikeBatteryChangeVo changeVo) {
String bikeCode = changeVo.getBikeCode();
QueryWrapper queryWrapper = QueryWrapper.create()
.where(EBIKE_BIKE_INFO.BIKE_CODE.eq(bikeCode));
EbikeBikeInfo bikeInfo = bikeInfoMapper.selectOneByQuery(queryWrapper);
if (bikeInfo == null) {
throw new EbikeException("车辆编号错误");
}
}
EbikeBikeInfo checkBikeCode(String bikeCode) {

View File

@ -39,6 +39,9 @@ public class RedisUtil {
// 调度工单相关
public static final String BIKE_DISPATCH_ORDER_PREFIX = "bike:dispatch:order:";
// 车辆信息相关
public static final String BIKE_ECU_PREFIX = "bike:ecu:";
/**
* 错误消息常量
@ -473,4 +476,18 @@ public class RedisUtil {
public Boolean releaseDispatchLock(String lockKey) {
return delete(Database.DB2, lockKey);
}
/**
* 数据库2专用存储中控信息
*/
public void saveEcu(String ecuSn, Object ecuData) {
set(Database.DB2, BIKE_ECU_PREFIX + ecuSn, ecuData);
}
/**
* 数据库2专用获取中控信息
*/
public Object getEcu(String ecuSn) {
return get(Database.DB2, BIKE_ECU_PREFIX + ecuSn);
}
}

View File

@ -79,7 +79,7 @@ public class ReoprtHandler {
resGpsDto.setIsHelmetLocked(isHelmetLocked);
resGpsDto.setIsWheelSpin(isWheelSpin);
resGpsDto.setIsMoving(isMoving);
redisUtil.set(deviceId, resGpsDto);
redisUtil.saveEcu(deviceId, resGpsDto);
double[] doubles = CoordinateUtil.WGS84ToGCJ02(resGpsDto.getLongitude(), resGpsDto.getLatitude());
boolean outOfChina = CoordinateUtil.outOfChina(doubles[0], doubles[1]);
if (!outOfChina) {
@ -90,12 +90,11 @@ public class ReoprtHandler {
}
public void bmsMsgHandler(JsonNode param, String deviceId) {
ResGPSDto resGpsDto = (ResGPSDto) redisUtil.get(deviceId);
ResGPSDto resGpsDto = (ResGPSDto) redisUtil.getEcu(deviceId);
if (resGpsDto != null) {
Integer mosState = param.get("MOSState").asInt();
resGpsDto.setMosState(mosState);
redisUtil.delete(deviceId);
redisUtil.set(deviceId, resGpsDto);
redisUtil.saveEcu(deviceId, resGpsDto);
}
}

View File

@ -18,6 +18,9 @@ public class RedisUtil {
private final RedisTemplate<String, Object> redisTemplate;
// 车辆信息相关
public static final String BIKE_ECU_PREFIX = "bike:ecu:";
@Autowired
public RedisUtil(RedisTemplate<String, Object> redisTemplate) {
@ -252,4 +255,18 @@ public class RedisUtil {
public Boolean releaseLock(String key) {
return redisTemplate.delete(key);
}
/**
* 数据库2专用存储中控信息
*/
public void saveEcu(String ecuSn, Object ecuData) {
set( BIKE_ECU_PREFIX + ecuSn, ecuData);
}
/**
* 数据库2专用获取中控信息
*/
public Object getEcu(String ecuSn) {
return get( BIKE_ECU_PREFIX + ecuSn);
}
}