mirror of
https://gitee.com/san-bing/JChargePointProtocol
synced 2026-05-06 02:49:57 +08:00
云快充1.5.0 初始化
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user