fix 完善报文解析
parent
c16028c96f
commit
e4bcdeefe2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,73 @@
|
|||
package com.muyu.iotdb.model;
|
||||
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
|
||||
/**
|
||||
* @author 牧鱼
|
||||
* @Classname VehicleData
|
||||
* @Description 车辆模拟数据对象
|
||||
* @Date 2021/8/5
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class VehicleData {
|
||||
private String vin; // 车辆识别号
|
||||
private long timestamp; // 时间戳
|
||||
private double longitude; // 经度
|
||||
private double latitude; // 纬度
|
||||
private int speed; // 速度
|
||||
private int mileage; // 里程
|
||||
private Double voltage; // 电压,默认为Double而非String以支持数值操作
|
||||
private Double current; // 电流
|
||||
private Double resistance; // 电阻
|
||||
private String gear; // 档位
|
||||
private String accelerationPedal; // 加速踏板位置
|
||||
private String brakePedal; // 刹车踏板状态
|
||||
private String fuelConsumptionRate; // 燃油消耗率
|
||||
private String motorControllerTemperature; // 电机控制器温度
|
||||
private String motorSpeed; // 电机转速
|
||||
private String motorTorque; // 电机扭矩
|
||||
private String motorTemperature; // 电机温度
|
||||
private String motorVoltage; // 电机电压
|
||||
private String motorCurrent; // 电机电流
|
||||
private int remainingBattery; // 剩余电池电量百分比
|
||||
private int batteryLevel; // 电池等级
|
||||
private String maximumFeedbackPower; // 最大回馈功率
|
||||
private String maximumDischargePower; // 最大放电功率
|
||||
private String selfCheckCounter; // 自检计数器
|
||||
private String totalBatteryCurrent; // 总电池电流
|
||||
private String totalBatteryVoltage; // 总电池电压
|
||||
private String singleBatteryMaxVoltage; // 单体电池最高电压
|
||||
private String singleBatteryMinVoltage; // 单体电池最低电压
|
||||
private String singleBatteryMaxTemperature; // 单体电池最高温度
|
||||
private String singleBatteryMinTemperature; // 单体电池最低温度
|
||||
private String availableBatteryCapacity; // 可用电池容量
|
||||
private int vehicleStatus; // 车辆状态
|
||||
private int chargingStatus; // 充电状态
|
||||
private int operatingStatus; // 运行状态
|
||||
private int socStatus; // SOC状态
|
||||
private int chargingEnergyStorageStatus; // 充电储能状态
|
||||
private int driveMotorStatus; // 驱动电机状态
|
||||
private int positionStatus; // 位置状态
|
||||
private int easStatus; // EAS状态(假设EAS为某种系统状态)
|
||||
private int ptcStatus; // PTC状态
|
||||
private int epsStatus; // EPS状态
|
||||
private int absStatus; // ABS状态
|
||||
private int mcuStatus; // MCU状态
|
||||
private int heatingStatus; // 加热状态
|
||||
private int batteryStatus; // 电池状态
|
||||
private int batteryInsulationStatus; // 电池绝缘状态
|
||||
private int dcdcStatus; // DC/DC转换器状态
|
||||
private int chgStatus; // 充电状态(可能与chargingStatus有区别,具体看实际业务)
|
||||
private String vehicleStatusMsg; // 车辆状态信息
|
||||
private String smartHardwareMsg; // 智能硬件信息
|
||||
private String batteryMsg; // 电池信息
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.muyu.iotdb.model.param;
|
||||
|
||||
import lombok.Data;
|
||||
/**
|
||||
* description: 入参
|
||||
* date: 2022/8/15 21:53
|
||||
* author: YangLe
|
||||
*/
|
||||
@Data
|
||||
public class IotDbParam {
|
||||
|
||||
|
||||
|
||||
private String vin;
|
||||
/***
|
||||
* 查询开始时间
|
||||
*/
|
||||
private String startTime;
|
||||
/***
|
||||
* 查询结束时间
|
||||
*/
|
||||
private String endTime;
|
||||
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.muyu.iotdb.model.result;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* description: 返回结果
|
||||
* date: 2022/8/15 21:56
|
||||
* author: YangLe
|
||||
*/
|
||||
@Data
|
||||
public class IotDbResult {
|
||||
/***
|
||||
* 时间
|
||||
*/
|
||||
private String time;
|
||||
/***
|
||||
* 产品PK
|
||||
*/
|
||||
private String pk;
|
||||
/***
|
||||
* 设备号
|
||||
*/
|
||||
private String sn;
|
||||
/***
|
||||
* 实时呼吸
|
||||
*/
|
||||
private String breath;
|
||||
/***
|
||||
* 实时心率
|
||||
*/
|
||||
private String heart;
|
||||
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
package com.muyu.iotdb.respone;
|
||||
|
||||
/**
|
||||
* description: 错误返回封装
|
||||
* date: 2022/8/15 21:30
|
||||
* author: YangLe
|
||||
*/
|
||||
public class ErrorResponseData extends ResponseData {
|
||||
private String exceptionClazz;
|
||||
|
||||
ErrorResponseData(String message) {
|
||||
super(false, DEFAULT_ERROR_CODE, message, message, (Object)null);
|
||||
}
|
||||
|
||||
public ErrorResponseData(Integer code, String message) {
|
||||
super(false, code, message, message, (Object)null);
|
||||
}
|
||||
|
||||
ErrorResponseData(Integer code, String message, Object object) {
|
||||
super(false, code, message, object);
|
||||
}
|
||||
|
||||
ErrorResponseData(Integer code, String message, String localizedMsg, Object object) {
|
||||
super(false, code, message, localizedMsg, object);
|
||||
}
|
||||
|
||||
public boolean equals(final Object o) {
|
||||
if (o == this) {
|
||||
return true;
|
||||
} else if (!(o instanceof ErrorResponseData)) {
|
||||
return false;
|
||||
} else {
|
||||
ErrorResponseData other = (ErrorResponseData)o;
|
||||
if (!other.canEqual(this)) {
|
||||
return false;
|
||||
} else if (!super.equals(o)) {
|
||||
return false;
|
||||
} else {
|
||||
Object this$exceptionClazz = this.getExceptionClazz();
|
||||
Object other$exceptionClazz = other.getExceptionClazz();
|
||||
if (this$exceptionClazz == null) {
|
||||
if (other$exceptionClazz != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!this$exceptionClazz.equals(other$exceptionClazz)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean canEqual(final Object other) {
|
||||
return other instanceof ErrorResponseData;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int result = super.hashCode();
|
||||
Object $exceptionClazz = this.getExceptionClazz();
|
||||
result = result * 59 + ($exceptionClazz == null ? 43 : $exceptionClazz.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getExceptionClazz() {
|
||||
return this.exceptionClazz;
|
||||
}
|
||||
|
||||
public void setExceptionClazz(final String exceptionClazz) {
|
||||
this.exceptionClazz = exceptionClazz;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "ErrorResponseData(exceptionClazz=" + this.getExceptionClazz() + ")";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,214 @@
|
|||
package com.muyu.iotdb.respone;
|
||||
|
||||
/**
|
||||
* description: 返回结果封装
|
||||
* date: 2022/8/15 21:32
|
||||
* author: YangLe
|
||||
*/
|
||||
public class ResponseData {
|
||||
public static final String DEFAULT_SUCCESS_MESSAGE = "请求成功";
|
||||
public static final String DEFAULT_ERROR_MESSAGE = "网络异常";
|
||||
public static final Integer DEFAULT_SUCCESS_CODE = 200;
|
||||
public static final Integer DEFAULT_ERROR_CODE = 500;
|
||||
private Boolean success;
|
||||
private Integer code;
|
||||
private String message;
|
||||
private String localizedMsg;
|
||||
private Object data;
|
||||
|
||||
public ResponseData() {
|
||||
}
|
||||
|
||||
public ResponseData(Boolean success, Integer code, String message, Object data) {
|
||||
this.success = success;
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public ResponseData(Boolean success, Integer code, String message, String localizedMsg, Object data) {
|
||||
this.success = success;
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
this.localizedMsg = localizedMsg;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public ResponseData(Boolean success, Integer code, String message) {
|
||||
this.success = success;
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public static SuccessResponseData success() {
|
||||
return new SuccessResponseData();
|
||||
}
|
||||
|
||||
public static SuccessResponseData success(Object object) {
|
||||
return new SuccessResponseData(object);
|
||||
}
|
||||
|
||||
public static SuccessResponseData success(Integer code, String message, Object object) {
|
||||
return new SuccessResponseData(code, message, object);
|
||||
}
|
||||
|
||||
public static SuccessResponseData success(Integer code, String message) {
|
||||
return new SuccessResponseData(code, message);
|
||||
}
|
||||
|
||||
public static SuccessResponseData success(Integer code, String message, String localizedMsg, Object object) {
|
||||
return new SuccessResponseData(code, message, localizedMsg, object);
|
||||
}
|
||||
|
||||
public static ErrorResponseData error(String message) {
|
||||
return new ErrorResponseData(message);
|
||||
}
|
||||
|
||||
public static ErrorResponseData error(Integer code, String message) {
|
||||
return new ErrorResponseData(code, message);
|
||||
}
|
||||
|
||||
public static ErrorResponseData error(Integer code, String message, Object object) {
|
||||
return new ErrorResponseData(code, message, object);
|
||||
}
|
||||
|
||||
public static ErrorResponseData error(Integer code, String message, String localizedMsg, Object object) {
|
||||
return new ErrorResponseData(code, message, localizedMsg, object);
|
||||
}
|
||||
|
||||
public Boolean getSuccess() {
|
||||
return this.success;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
public String getLocalizedMsg() {
|
||||
return this.localizedMsg;
|
||||
}
|
||||
|
||||
public Object getData() {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
public void setSuccess(final Boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
public void setCode(final Integer code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public void setMessage(final String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public void setLocalizedMsg(final String localizedMsg) {
|
||||
this.localizedMsg = localizedMsg;
|
||||
}
|
||||
|
||||
public void setData(final Object data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public boolean equals(final Object o) {
|
||||
if (o == this) {
|
||||
return true;
|
||||
} else if (!(o instanceof ResponseData)) {
|
||||
return false;
|
||||
} else {
|
||||
ResponseData other = (ResponseData)o;
|
||||
if (!other.canEqual(this)) {
|
||||
return false;
|
||||
} else {
|
||||
label71: {
|
||||
Object this$success = this.getSuccess();
|
||||
Object other$success = other.getSuccess();
|
||||
if (this$success == null) {
|
||||
if (other$success == null) {
|
||||
break label71;
|
||||
}
|
||||
} else if (this$success.equals(other$success)) {
|
||||
break label71;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Object this$code = this.getCode();
|
||||
Object other$code = other.getCode();
|
||||
if (this$code == null) {
|
||||
if (other$code != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!this$code.equals(other$code)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
label57: {
|
||||
Object this$message = this.getMessage();
|
||||
Object other$message = other.getMessage();
|
||||
if (this$message == null) {
|
||||
if (other$message == null) {
|
||||
break label57;
|
||||
}
|
||||
} else if (this$message.equals(other$message)) {
|
||||
break label57;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Object this$localizedMsg = this.getLocalizedMsg();
|
||||
Object other$localizedMsg = other.getLocalizedMsg();
|
||||
if (this$localizedMsg == null) {
|
||||
if (other$localizedMsg != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!this$localizedMsg.equals(other$localizedMsg)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Object this$data = this.getData();
|
||||
Object other$data = other.getData();
|
||||
if (this$data == null) {
|
||||
if (other$data == null) {
|
||||
return true;
|
||||
}
|
||||
} else if (this$data.equals(other$data)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean canEqual(final Object other) {
|
||||
return other instanceof ResponseData;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int result1 = 1;
|
||||
Object $success = this.getSuccess();
|
||||
int result = result1 * 59 + ($success == null ? 43 : $success.hashCode());
|
||||
Object $code = this.getCode();
|
||||
result = result * 59 + ($code == null ? 43 : $code.hashCode());
|
||||
Object $message = this.getMessage();
|
||||
result = result * 59 + ($message == null ? 43 : $message.hashCode());
|
||||
Object $localizedMsg = this.getLocalizedMsg();
|
||||
result = result * 59 + ($localizedMsg == null ? 43 : $localizedMsg.hashCode());
|
||||
Object $data = this.getData();
|
||||
result = result * 59 + ($data == null ? 43 : $data.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "ResponseData(success=" + this.getSuccess() + ", code=" + this.getCode() + ", message=" + this.getMessage() + ", localizedMsg=" + this.getLocalizedMsg() + ", data=" + this.getData() + ")";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.muyu.iotdb.respone;
|
||||
/**
|
||||
* description: 正确返回结果封装
|
||||
* date: 2022/8/15 21:40
|
||||
* author: YangLe
|
||||
*/
|
||||
|
||||
public class SuccessResponseData extends ResponseData {
|
||||
public SuccessResponseData() {
|
||||
super(true, DEFAULT_SUCCESS_CODE, "请求成功", "请求成功", (Object)null);
|
||||
}
|
||||
|
||||
public SuccessResponseData(Object object) {
|
||||
super(true, DEFAULT_SUCCESS_CODE, "请求成功", "请求成功", object);
|
||||
}
|
||||
|
||||
public SuccessResponseData(Integer code, String message, Object object) {
|
||||
super(true, code, message, message, object);
|
||||
}
|
||||
|
||||
public SuccessResponseData(Integer code, String message, String localizedMsg, Object object) {
|
||||
super(true, code, message, localizedMsg, object);
|
||||
}
|
||||
|
||||
public SuccessResponseData(Integer code, String message) {
|
||||
super(true, code, message);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.muyu.iotdb.server;
|
||||
|
||||
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.muyu.iotdb.model.VehicleData;
|
||||
import org.apache.iotdb.rpc.IoTDBConnectionException;
|
||||
import org.apache.iotdb.rpc.StatementExecutionException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.rmi.ServerException;
|
||||
|
||||
/**
|
||||
* description: iot服务类
|
||||
* date: 2022/8/15 21:41
|
||||
* author: YangLe
|
||||
*/
|
||||
@Service
|
||||
public interface IotDbServer {
|
||||
/**
|
||||
* 添加数据
|
||||
*/
|
||||
void insertData(JSONObject vehicleData) throws StatementExecutionException, ServerException, IoTDBConnectionException;
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package com.muyu.iotdb.server.impl;
|
||||
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
|
||||
import com.muyu.iotdb.config.IotDBSessionConfig;
|
||||
import com.muyu.iotdb.model.VehicleData;
|
||||
import com.muyu.iotdb.server.IotDbServer;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.apache.iotdb.rpc.IoTDBConnectionException;
|
||||
import org.apache.iotdb.rpc.StatementExecutionException;
|
||||
import org.apache.iotdb.session.SessionDataSet;
|
||||
import org.apache.iotdb.tsfile.read.common.Field;
|
||||
import org.apache.iotdb.tsfile.read.common.RowRecord;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.rmi.ServerException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* description: iot服务实现类
|
||||
* date: 2022/8/15 9:43
|
||||
* author: yangle
|
||||
*/
|
||||
|
||||
@Log4j2
|
||||
@Service
|
||||
public class IotDbServerImpl implements IotDbServer {
|
||||
|
||||
@Resource
|
||||
private IotDBSessionConfig iotDBSessionConfig;
|
||||
|
||||
@Override
|
||||
public void insertData(JSONObject vehicleData) throws StatementExecutionException, ServerException, IoTDBConnectionException {
|
||||
// iotDbParam: 模拟设备上报消息
|
||||
// bizkey: 业务唯一key PK :产品唯一编码 SN:设备唯一编码
|
||||
String deviceId = "root.test." + vehicleData.getString("vin");
|
||||
// 将设备上报的数据存入数据库(时序数据库)
|
||||
List<String> measurementsList = new ArrayList<>();
|
||||
measurementsList.add("vehicleStatusMsg");
|
||||
List<String> valuesList = new ArrayList<>();
|
||||
valuesList.add(vehicleData.toString());
|
||||
log.info("vehicleData:{}", vehicleData);
|
||||
log.info("valuesList:{}",valuesList);
|
||||
iotDBSessionConfig.insertRecord(deviceId, vehicleData.getLong("timestamp"), measurementsList, valuesList);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.muyu.mqtt.dao;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.apache.iotdb.tsfile.read.filter.operator.In;
|
||||
import org.checkerframework.checker.units.qual.N;
|
||||
|
||||
/**
|
||||
* 解析完成对象
|
||||
*
|
||||
* @author Yangle
|
||||
* Date 2024/6/26 22:30
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@SuperBuilder
|
||||
public class MessageDa {
|
||||
private Integer id;
|
||||
private String analyzeKey;
|
||||
private Integer analyzeStart;
|
||||
private Integer ent;
|
||||
private String lable;
|
||||
private String value;
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.muyu.redis;
|
||||
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* Redis启动类 RedisApplication
|
||||
*
|
||||
* @author Yangle
|
||||
* Date 2024/6/26 16:45
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class RedisApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.muyu.redis.controller;
|
||||
|
||||
import com.muyu.redis.demo.RedisData;
|
||||
import com.muyu.redis.service.RedisService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* RedisController
|
||||
*
|
||||
* @author Yangle
|
||||
* Date 2024/6/26 16:48
|
||||
*/
|
||||
@RestController
|
||||
public class RedisController {
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
|
||||
@PostMapping("/redis/set")
|
||||
public String set(@RequestBody RedisData redisData) {
|
||||
redisService.set(redisData);
|
||||
return "success";
|
||||
}
|
||||
|
||||
@PostMapping("/redis/get")
|
||||
public String get(@RequestBody RedisData redisData) {
|
||||
return redisService.get(redisData);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.muyu.redis.service;
|
||||
|
||||
import com.muyu.redis.demo.RedisData;
|
||||
|
||||
/**
|
||||
* RedisService
|
||||
*
|
||||
* @author Yangle
|
||||
* Date 2024/6/26 16:49
|
||||
*/
|
||||
public interface RedisService {
|
||||
void set(RedisData redisData);
|
||||
|
||||
String get(RedisData redisData);
|
||||
}
|
|
@ -0,0 +1,117 @@
|
|||
package com.muyu.redis.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.muyu.mqtt.dao.MessageDa;
|
||||
import com.muyu.redis.demo.RedisData;
|
||||
import com.muyu.redis.service.RedisService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* RedisServiceImpl
|
||||
*
|
||||
* @author Yangle
|
||||
* Date 2024/6/26 16:49
|
||||
*/
|
||||
@Service
|
||||
@Log4j2
|
||||
public class RedisServiceImpl implements RedisService {
|
||||
@Autowired
|
||||
private RedisTemplate<String,String> redisTemplate;
|
||||
|
||||
@Override
|
||||
public void set(RedisData redisData) {
|
||||
|
||||
|
||||
List<MessageDa> messageDas = new ArrayList<>();
|
||||
messageDas.add(
|
||||
new MessageDa(
|
||||
1,
|
||||
"vin",
|
||||
0,
|
||||
17,
|
||||
"vIN",
|
||||
"基础信息"
|
||||
)
|
||||
);
|
||||
|
||||
messageDas.add(
|
||||
new MessageDa(
|
||||
2,
|
||||
"timestamp",
|
||||
17,
|
||||
30,
|
||||
"时间戳",
|
||||
"基础信息"
|
||||
)
|
||||
);
|
||||
messageDas.add(
|
||||
new MessageDa(
|
||||
3,
|
||||
"longitude",
|
||||
38,
|
||||
41,
|
||||
"经度",
|
||||
"基础信息"
|
||||
)
|
||||
);
|
||||
redisTemplate.opsForList().set(redisData.getVin(), 0, JSON.toJSONString(messageDas));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(RedisData redisData) {
|
||||
|
||||
String string = redisTemplate.opsForValue().get(redisData.getVin());
|
||||
log.error("string:{}", string);
|
||||
return null;
|
||||
// String index = redisTemplate.opsForList().index(redisData.getVin(), 0);
|
||||
// log.error("index:{}",index);
|
||||
// // 解析JSON字符串
|
||||
// JSONArray objects = JSON.parseArray(index);
|
||||
// log.error("objects:{}",objects);
|
||||
// for (Object object : objects) {
|
||||
// JSONObject jsonObject = JSONObject.parseObject(object.toString());
|
||||
// String typeIdentification = jsonObject.getString("typeIdentification");
|
||||
// String initiationPosition = jsonObject.getString("initiationPosition");
|
||||
// String terminatePosition = jsonObject.getString("terminatePosition");
|
||||
// String messageLabel = jsonObject.getString("messageLabel");
|
||||
//
|
||||
// log.error("typeIdentification:{}",typeIdentification);
|
||||
// log.error("initiationPosition:{}",initiationPosition);
|
||||
// log.error("terminatePosition:{}",terminatePosition);
|
||||
// log.error("messageLabel:{}",messageLabel);
|
||||
// }
|
||||
//
|
||||
// // 遍历JSON数组
|
||||
//// for (int i = 0; i < jsonArray.length(); i++) {
|
||||
//// // 获取当前项
|
||||
//// JSONObject jsonObject = jsonArray.getJSONObject(i);
|
||||
////
|
||||
//// // 提取initiationPosition的值
|
||||
//// String initiationPosition = jsonObject.getString("initiationPosition");
|
||||
////
|
||||
//// // 打印结果
|
||||
//// System.out.println("initiationPosition at index " + i + " is: " + initiationPosition);
|
||||
//// }
|
||||
// return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 本地缓存
|
||||
*/
|
||||
Cache<String, String> localCache = Caffeine.newBuilder()
|
||||
.initialCapacity(5)
|
||||
.maximumSize(10)
|
||||
//过期时间3秒钟
|
||||
.expireAfterWrite(5, TimeUnit.SECONDS)
|
||||
.build();
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.muyu.test;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
@RequiredArgsConstructor
|
||||
public class Application implements CommandLineRunner {
|
||||
|
||||
private final UserRegistrationService userRegistrationService;
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication app = new SpringApplication(Application.class);
|
||||
app.setWebApplicationType(WebApplicationType.NONE);
|
||||
app.run(args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(String... args) {
|
||||
// 在启动时注册新用户
|
||||
userRegistrationService.registerUser("小猪猪");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.muyu.test;
|
||||
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class UserNotificationService {
|
||||
|
||||
@EventListener
|
||||
public void handleUserRegisteredEvent(UserRegisteredEvent event) {
|
||||
// 处理用户注册事件,例如发送通知
|
||||
String username = event.getUsername();
|
||||
System.out.println("Notification sent for user: " + username);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package com.muyu.test;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
public class UserRegisteredEvent extends ApplicationEvent {
|
||||
private final String username;
|
||||
|
||||
public UserRegisteredEvent(Object source, String username) {
|
||||
super(source);
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package com.muyu.test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class UserRegistrationService {
|
||||
|
||||
@Autowired
|
||||
private ApplicationEventPublisher eventPublisher;
|
||||
|
||||
public void registerUser(String username) {
|
||||
// 注册新用户逻辑
|
||||
// ...
|
||||
|
||||
// 发布用户注册事件,这里使用 eventPublisher 将 预先定义好的事件交由 Spring 的Event Channel 管理
|
||||
eventPublisher.publishEvent(new UserRegisteredEvent(this, username));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue