mirror of
https://gitee.com/san-bing/JChargePointProtocol
synced 2026-05-04 09:59:55 +08:00
云快充1.5.0 初始化
This commit is contained in:
50
jcpp-infrastructure-proto/pom.xml
Normal file
50
jcpp-infrastructure-proto/pom.xml
Normal file
@@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
抖音关注:程序员三丙
|
||||
知识星球:https://t.zsxq.com/j9b21
|
||||
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>sanbing</groupId>
|
||||
<artifactId>jcpp-parent</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>jcpp-infrastructure-proto</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>JChargePointProtocol Infrastructure Proto Module</name>
|
||||
<description>基础Protobuf模块</description>
|
||||
|
||||
<properties>
|
||||
<main.dir>${basedir}/..</main.dir>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.google.protobuf</groupId>
|
||||
<artifactId>protobuf-java</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.protobuf</groupId>
|
||||
<artifactId>protobuf-java-util</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.xolstice.maven.plugins</groupId>
|
||||
<artifactId>protobuf-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* 抖音关注:程序员三丙
|
||||
* 知识星球:https://t.zsxq.com/j9b21
|
||||
*/
|
||||
package sanbing.jcpp.infrastructure.proto;
|
||||
|
||||
|
||||
import sanbing.jcpp.infrastructure.proto.model.PricingModel;
|
||||
import sanbing.jcpp.infrastructure.proto.model.PricingModel.FlagPrice;
|
||||
import sanbing.jcpp.infrastructure.proto.model.PricingModel.Period;
|
||||
import sanbing.jcpp.proto.gen.ProtocolProto.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author baigod
|
||||
*/
|
||||
public class ProtoConverter {
|
||||
|
||||
public static PricingModelProto toPricingModel(PricingModel pricingModel) {
|
||||
// 创建 PricingModelProto 实例
|
||||
PricingModelProto.Builder builder = PricingModelProto.newBuilder();
|
||||
|
||||
// 设置字段
|
||||
builder.setType(PricingModelType.valueOf(pricingModel.getType().name()));
|
||||
builder.setRule(PricingModelRule.valueOf(pricingModel.getRule().name()));
|
||||
builder.setStandardElec(pricingModel.getStandardElec());
|
||||
builder.setStandardServ(pricingModel.getStandardServ());
|
||||
|
||||
// 转换 flagPriceList
|
||||
for (Map.Entry<PricingModelFlag, FlagPrice> entry : pricingModel.getFlagPriceList().entrySet()) {
|
||||
PricingModelFlag flag = entry.getKey();
|
||||
FlagPrice flagPrice = entry.getValue();
|
||||
|
||||
FlagPriceProto flagPriceProto = FlagPriceProto.newBuilder()
|
||||
.setFlag(PricingModelFlag.valueOf(flag.name())) // 枚举转换
|
||||
.setElec(flagPrice.getElec())
|
||||
.setServ(flagPrice.getServ())
|
||||
.build();
|
||||
|
||||
builder.putFlagPrice(flag.ordinal(), flagPriceProto); // 按 ordinal 值作为 key 存入
|
||||
}
|
||||
|
||||
// 转换 PeriodsList
|
||||
for (Period period : pricingModel.getPeriodsList()) {
|
||||
PeriodProto periodProto = PeriodProto.newBuilder()
|
||||
.setSn(period.getSn())
|
||||
.setBegin(period.getBegin().toString()) // 假设 begin 是 LocalTime, 转换为字符串
|
||||
.setEnd(period.getEnd().toString()) // 假设 end 是 LocalTime, 转换为字符串
|
||||
.setFlag(PricingModelFlag.valueOf(period.getFlag().name()))
|
||||
.build();
|
||||
builder.addPeriod(periodProto);
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* 抖音关注:程序员三丙
|
||||
* 知识星球:https://t.zsxq.com/j9b21
|
||||
*/
|
||||
package sanbing.jcpp.infrastructure.proto.model;
|
||||
|
||||
import lombok.*;
|
||||
import sanbing.jcpp.proto.gen.ProtocolProto.PricingModelFlag;
|
||||
import sanbing.jcpp.proto.gen.ProtocolProto.PricingModelRule;
|
||||
import sanbing.jcpp.proto.gen.ProtocolProto.PricingModelType;
|
||||
|
||||
import java.time.LocalTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@Data
|
||||
public class PricingModel {
|
||||
|
||||
private UUID id;
|
||||
|
||||
// 计数器,供充电桩协议使用
|
||||
private int sequenceNumber;
|
||||
|
||||
private String pileCode;
|
||||
|
||||
private PricingModelType type;
|
||||
|
||||
private PricingModelRule rule;
|
||||
|
||||
/**
|
||||
* 标准电价(单位分)
|
||||
*/
|
||||
private int standardElec;
|
||||
|
||||
/**
|
||||
* 标准服务费(单位分)
|
||||
*/
|
||||
private int standardServ;
|
||||
|
||||
/**
|
||||
* 分时电价
|
||||
*/
|
||||
private Map<PricingModelFlag, FlagPrice> flagPriceList;
|
||||
|
||||
/**
|
||||
* 分时时段
|
||||
*/
|
||||
private List<Period> periodsList;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
public static class Period {
|
||||
private int sn;
|
||||
|
||||
// 起始时间
|
||||
private LocalTime begin;
|
||||
|
||||
// 结束时间
|
||||
private LocalTime end;
|
||||
|
||||
// 尖峰平谷标识
|
||||
private PricingModelFlag flag;
|
||||
}
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public static class FlagPrice {
|
||||
|
||||
// 分时电价,单位分
|
||||
private int elec;
|
||||
|
||||
// 分时服务费,单位分
|
||||
private int serv;
|
||||
}
|
||||
|
||||
}
|
||||
25
jcpp-infrastructure-proto/src/main/proto/cluster.proto
Normal file
25
jcpp-infrastructure-proto/src/main/proto/cluster.proto
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* 抖音关注:程序员三丙
|
||||
* 知识星球:https://t.zsxq.com/j9b21
|
||||
*/
|
||||
syntax = "proto3";
|
||||
|
||||
package infrastructureProto;
|
||||
|
||||
option java_package = "sanbing.jcpp.proto.gen";
|
||||
option java_outer_classname = "ClusterProto";
|
||||
|
||||
message ServiceInfo {
|
||||
string serviceId = 1;
|
||||
repeated string serviceTypes = 2;
|
||||
SystemInfoProto systemInfo = 10;
|
||||
}
|
||||
|
||||
message SystemInfoProto {
|
||||
int64 cpuUsage = 1;
|
||||
int64 cpuCount = 2;
|
||||
int64 memoryUsage = 3;
|
||||
int64 totalMemory = 4;
|
||||
int64 diskUsage = 5;
|
||||
int64 totalDiscSpace = 6;
|
||||
}
|
||||
242
jcpp-infrastructure-proto/src/main/proto/protocol.proto
Normal file
242
jcpp-infrastructure-proto/src/main/proto/protocol.proto
Normal file
@@ -0,0 +1,242 @@
|
||||
/**
|
||||
* 抖音关注:程序员三丙
|
||||
* 知识星球:https://t.zsxq.com/j9b21
|
||||
*/
|
||||
syntax = "proto3";
|
||||
|
||||
package infrastructureProto;
|
||||
|
||||
option java_package = "sanbing.jcpp.proto.gen";
|
||||
option java_outer_classname = "ProtocolProto";
|
||||
|
||||
message UplinkQueueMessage {
|
||||
int64 messageIdMSB = 1;
|
||||
int64 messageIdLSB = 2;
|
||||
int64 sessionIdMSB = 3;
|
||||
int64 sessionIdLSB = 4;
|
||||
string messageKey = 5;
|
||||
string protocolName = 6;
|
||||
bytes requestData = 10;
|
||||
LoginRequest loginRequest = 21;
|
||||
HeartBeatRequest heartBeatRequest = 22;
|
||||
VerifyPricingRequest verifyPricingRequest = 23;
|
||||
QueryPricingRequest queryPricingRequest = 24;
|
||||
GunRunStatusProto gunRunStatusProto = 25;
|
||||
ChargingProgressProto chargingProgressProto = 26;
|
||||
SetPricingResponse setPricingResponse = 27;
|
||||
RemoteStartChargingResponse remoteStartChargingResponse = 28;
|
||||
RemoteStopChargingResponse remoteStopChargingResponse = 29;
|
||||
TransactionRecord transactionRecord = 30;
|
||||
}
|
||||
|
||||
message DownlinkRestMessage {
|
||||
int64 messageIdMSB = 1;
|
||||
int64 messageIdLSB = 2;
|
||||
int64 sessionIdMSB = 3;
|
||||
int64 sessionIdLSB = 4;
|
||||
string protocolName = 6;
|
||||
string pileCode = 7;
|
||||
optional int64 requestIdMSB = 8;
|
||||
optional int64 requestIdLSB = 9;
|
||||
optional bytes requestData = 10;
|
||||
string downlinkCmd = 11;
|
||||
LoginResponse loginResponse = 20;
|
||||
VerifyPricingResponse verifyPricingResponse = 21;
|
||||
QueryPricingResponse queryPricingResponse = 22;
|
||||
SetPricingRequest setPricingRequest = 23;
|
||||
RemoteStartChargingRequest remoteStartChargingRequest = 24;
|
||||
RemoteStopChargingRequest remoteStopChargingRequest = 25;
|
||||
TransactionRecordAck transactionRecordAck = 26;
|
||||
}
|
||||
|
||||
message LoginRequest {
|
||||
string pileCode = 3;
|
||||
string remoteAddress = 4;
|
||||
string nodeId = 10;
|
||||
string nodeWebapiIpPort = 11;
|
||||
optional string additionalInfo = 20;
|
||||
}
|
||||
|
||||
message LoginResponse {
|
||||
bool success = 1;
|
||||
string pileCode = 2;
|
||||
}
|
||||
|
||||
message HeartBeatRequest {
|
||||
string pileCode = 3;
|
||||
string remoteAddress = 4;
|
||||
string nodeId = 10;
|
||||
string nodeWebapiIpPort = 11;
|
||||
optional string additionalInfo = 20;
|
||||
}
|
||||
|
||||
message VerifyPricingRequest {
|
||||
string pileCode = 4;
|
||||
int64 pricingId = 30;
|
||||
optional string pricingModel = 31;
|
||||
optional string additionalInfo = 20;
|
||||
}
|
||||
|
||||
message VerifyPricingResponse {
|
||||
bool success = 1;
|
||||
int64 pricingId = 30;
|
||||
}
|
||||
|
||||
message QueryPricingRequest {
|
||||
string pileCode = 4;
|
||||
optional string additionalInfo = 20;
|
||||
}
|
||||
|
||||
message QueryPricingResponse {
|
||||
string pileCode = 4;
|
||||
int64 pricingId = 30;
|
||||
PricingModelProto pricingModel = 1;
|
||||
}
|
||||
|
||||
message PricingModelProto {
|
||||
PricingModelType type = 3;
|
||||
PricingModelRule rule = 4;
|
||||
int32 standardElec = 5;
|
||||
int32 standardServ = 6;
|
||||
map<int32, FlagPriceProto> flagPrice = 8;
|
||||
repeated PeriodProto period = 9;
|
||||
}
|
||||
|
||||
message PeriodProto {
|
||||
int32 sn = 1;
|
||||
string begin = 2;
|
||||
string end = 3;
|
||||
PricingModelFlag flag = 4;
|
||||
}
|
||||
|
||||
message FlagPriceProto {
|
||||
PricingModelFlag flag = 1;
|
||||
int32 elec = 2;
|
||||
int32 serv = 3;
|
||||
}
|
||||
|
||||
enum PricingModelType {
|
||||
CHARGE = 0; // 充电费率模型
|
||||
DISCHARGE = 1; // 放电费率模型
|
||||
}
|
||||
|
||||
enum PricingModelRule {
|
||||
STANDARD = 0;
|
||||
SPLIT_TIME = 1;
|
||||
}
|
||||
|
||||
enum PricingModelFlag {
|
||||
TOP = 0; // 尖峰
|
||||
PEAK = 1; // 峰
|
||||
FLAT = 2; // 平
|
||||
VALLEY = 3; // 谷
|
||||
DEEP = 4; // 深谷
|
||||
}
|
||||
|
||||
enum GunRunStatus {
|
||||
IDLE = 0; // 空闲
|
||||
INSERTED = 1; // 已插枪
|
||||
CHARGING = 2; // 充电中
|
||||
CHARGE_COMPLETE = 3; // 充电完成
|
||||
DISCHARGE_READY = 4; // 放电准备
|
||||
DISCHARGING = 5; // 放电中
|
||||
DISCHARGE_COMPLETE = 6; // 放电完成
|
||||
RESERVED = 7; // 预约
|
||||
FAULT = 8; // 故障
|
||||
UNKNOWN = 9; // 未知
|
||||
}
|
||||
|
||||
message GunRunStatusProto {
|
||||
int64 ts = 1;
|
||||
string pileCode = 4;
|
||||
string gunCode = 5;
|
||||
GunRunStatus GunRunStatus = 41;
|
||||
repeated string faultMessages = 6;
|
||||
optional string additionalInfo = 20;
|
||||
}
|
||||
|
||||
message ChargingProgressProto {
|
||||
int64 ts = 1;
|
||||
string pileCode = 4;
|
||||
string gunCode = 5;
|
||||
string tradeNo = 6;
|
||||
float outputVoltage = 7;
|
||||
float outputCurrent = 8;
|
||||
float soc = 9;
|
||||
int32 totalChargingDurationMin = 10;
|
||||
float totalChargingEnergyKWh = 11;
|
||||
int64 totalChargingCostCent = 12;
|
||||
optional string additionalInfo = 20;
|
||||
}
|
||||
|
||||
message SetPricingRequest {
|
||||
string pileCode = 4;
|
||||
int64 pricingId = 30;
|
||||
PricingModelProto pricingModel = 1;
|
||||
}
|
||||
|
||||
message SetPricingResponse {
|
||||
bool success = 1;
|
||||
string pileCode = 4;
|
||||
int64 pricingId = 30;
|
||||
}
|
||||
|
||||
message RemoteStartChargingRequest {
|
||||
string pileCode = 4;
|
||||
string gunCode = 5;
|
||||
string tradeNo = 6;
|
||||
int32 limitCent = 7;
|
||||
optional string additionalInfo = 20;
|
||||
}
|
||||
|
||||
message RemoteStartChargingResponse {
|
||||
int64 ts = 1;
|
||||
string pileCode = 4;
|
||||
string gunCode = 5;
|
||||
string tradeNo = 6;
|
||||
bool success = 7;
|
||||
string failReason = 8;
|
||||
optional string additionalInfo = 20;
|
||||
}
|
||||
|
||||
message RemoteStopChargingRequest {
|
||||
string pileCode = 4;
|
||||
string gunCode = 5;
|
||||
}
|
||||
|
||||
message RemoteStopChargingResponse {
|
||||
int64 ts = 1;
|
||||
string pileCode = 4;
|
||||
string gunCode = 5;
|
||||
bool success = 7;
|
||||
string failReason = 8;
|
||||
optional string additionalInfo = 20;
|
||||
}
|
||||
|
||||
message TransactionRecord {
|
||||
string pileCode = 4;
|
||||
string gunCode = 5;
|
||||
string tradeNo = 6;
|
||||
int64 startTs = 51;
|
||||
int64 endTs = 52;
|
||||
float topEnergyKWh = 53;
|
||||
int64 topAmountCent = 54;
|
||||
float peakEnergyKWh = 55;
|
||||
int64 peakAmountCent = 56;
|
||||
float flatEnergyKWh = 57;
|
||||
int64 flatAmountCent = 58;
|
||||
float valleyEnergyKWh = 59;
|
||||
int64 valleyAmountCent = 60;
|
||||
float deepEnergyKWh = 61;
|
||||
int64 deepAmountCent = 62;
|
||||
float totalEnergyKWh = 63;
|
||||
int64 totalAmountCent = 64;
|
||||
int64 tradeTs = 65;
|
||||
string stopReason = 66;
|
||||
optional string additionalInfo = 20;
|
||||
}
|
||||
|
||||
message TransactionRecordAck {
|
||||
string tradeNo = 6;
|
||||
bool success = 7;
|
||||
}
|
||||
Reference in New Issue
Block a user