mirror of
https://gitee.com/san-bing/JChargePointProtocol
synced 2026-05-05 02:19:56 +08:00
测试计费策略下发
This commit is contained in:
@@ -11,8 +11,10 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import sanbing.jcpp.app.service.PileProtocolService;
|
||||
import sanbing.jcpp.proto.gen.ProtocolProto.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @author baigod
|
||||
@@ -30,4 +32,116 @@ public class TestController {
|
||||
|
||||
return ResponseEntity.ok("success");
|
||||
}
|
||||
|
||||
@GetMapping("/api/setPricing")
|
||||
public ResponseEntity<String> setPricing() {
|
||||
|
||||
String pileCode = "20231212000010";
|
||||
|
||||
FlagPriceProto flagPriceTop = FlagPriceProto.newBuilder()
|
||||
.setFlag(PricingModelFlag.TOP)
|
||||
.setElec("1.5")
|
||||
.setServ("0.5")
|
||||
.build();
|
||||
|
||||
FlagPriceProto flagPricePeak = FlagPriceProto.newBuilder()
|
||||
.setFlag(PricingModelFlag.PEAK)
|
||||
.setElec("1.2")
|
||||
.setServ("0.4")
|
||||
.build();
|
||||
|
||||
FlagPriceProto flagPriceFlat = FlagPriceProto.newBuilder()
|
||||
.setFlag(PricingModelFlag.FLAT)
|
||||
.setElec("1.0")
|
||||
.setServ("0.3")
|
||||
.build();
|
||||
|
||||
FlagPriceProto flagPriceValley = FlagPriceProto.newBuilder()
|
||||
.setFlag(PricingModelFlag.VALLEY)
|
||||
.setElec("0.7")
|
||||
.setServ("0.2")
|
||||
.build();
|
||||
|
||||
// 构建 PeriodProto 对象
|
||||
PeriodProto topPeriod1 = PeriodProto.newBuilder()
|
||||
.setSn(1)
|
||||
.setBegin("10:00")
|
||||
.setEnd("15:00")
|
||||
.setFlag(PricingModelFlag.TOP)
|
||||
.build();
|
||||
|
||||
PeriodProto topPeriod2 = PeriodProto.newBuilder()
|
||||
.setSn(2)
|
||||
.setBegin("18:00")
|
||||
.setEnd("21:00")
|
||||
.setFlag(PricingModelFlag.TOP)
|
||||
.build();
|
||||
|
||||
PeriodProto peakPeriod1 = PeriodProto.newBuilder()
|
||||
.setSn(3)
|
||||
.setBegin("07:00")
|
||||
.setEnd("10:00")
|
||||
.setFlag(PricingModelFlag.PEAK)
|
||||
.build();
|
||||
|
||||
PeriodProto peakPeriod2 = PeriodProto.newBuilder()
|
||||
.setSn(4)
|
||||
.setBegin("15:00")
|
||||
.setEnd("18:00")
|
||||
.setFlag(PricingModelFlag.PEAK)
|
||||
.build();
|
||||
|
||||
PeriodProto flatPeriod1 = PeriodProto.newBuilder()
|
||||
.setSn(5)
|
||||
.setBegin("06:00")
|
||||
.setEnd("07:00")
|
||||
.setFlag(PricingModelFlag.FLAT)
|
||||
.build();
|
||||
|
||||
PeriodProto flatPeriod2 = PeriodProto.newBuilder()
|
||||
.setSn(6)
|
||||
.setBegin("21:00")
|
||||
.setEnd("23:00")
|
||||
.setFlag(PricingModelFlag.FLAT)
|
||||
.build();
|
||||
|
||||
PeriodProto valleyPeriod = PeriodProto.newBuilder()
|
||||
.setSn(7)
|
||||
.setBegin("23:00")
|
||||
.setEnd("06:00")
|
||||
.setFlag(PricingModelFlag.VALLEY)
|
||||
.build();
|
||||
|
||||
// 构建 flagPrice 映射
|
||||
HashMap<Integer, FlagPriceProto> flagPriceMap = new HashMap<>();
|
||||
flagPriceMap.put(PricingModelFlag.TOP_VALUE, flagPriceTop);
|
||||
flagPriceMap.put(PricingModelFlag.PEAK_VALUE, flagPricePeak);
|
||||
flagPriceMap.put(PricingModelFlag.FLAT_VALUE, flagPriceFlat);
|
||||
flagPriceMap.put(PricingModelFlag.VALLEY_VALUE, flagPriceValley);
|
||||
|
||||
// 构建 PricingModelProto 对象
|
||||
PricingModelProto pricingModel = PricingModelProto.newBuilder()
|
||||
.setType(PricingModelType.CHARGE) // 设置为充电计费模型
|
||||
.setRule(PricingModelRule.SPLIT_TIME) // 使用分时计费规则
|
||||
.setStandardElec("1.0") // 标准电费(默认值)
|
||||
.setStandardServ("0.3") // 标准服务费(默认值)
|
||||
.putAllFlagPrice(flagPriceMap) // 设置尖峰平谷对应的价格
|
||||
.addPeriod(topPeriod1) // 添加尖峰时段1
|
||||
.addPeriod(topPeriod2) // 添加尖峰时段2
|
||||
.addPeriod(peakPeriod1) // 添加峰时段1
|
||||
.addPeriod(peakPeriod2) // 添加峰时段2
|
||||
.addPeriod(flatPeriod1) // 添加平时段1
|
||||
.addPeriod(flatPeriod2) // 添加平时段2
|
||||
.addPeriod(valleyPeriod) // 添加谷时段
|
||||
.build();
|
||||
|
||||
pileProtocolService.setPricing(pileCode,
|
||||
SetPricingRequest.newBuilder()
|
||||
.setPileCode(pileCode)
|
||||
.setPricingId(1000L)
|
||||
.setPricingModel(pricingModel)
|
||||
.build());
|
||||
|
||||
return ResponseEntity.ok("success");
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
package sanbing.jcpp.app.service;
|
||||
|
||||
import sanbing.jcpp.infrastructure.queue.Callback;
|
||||
import sanbing.jcpp.proto.gen.ProtocolProto.SetPricingRequest;
|
||||
import sanbing.jcpp.proto.gen.ProtocolProto.UplinkQueueMessage;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@@ -72,4 +73,9 @@ public interface PileProtocolService {
|
||||
* 启动充电
|
||||
*/
|
||||
void startCharge(String pileCode, String gunCode, BigDecimal limitYuan, String orderNo);
|
||||
|
||||
/**
|
||||
* 下发计费
|
||||
*/
|
||||
void setPricing(String pileCode, SetPricingRequest setPricingRequest);
|
||||
}
|
||||
@@ -226,7 +226,7 @@ public class DefaultPileProtocolService implements PileProtocolService {
|
||||
|
||||
@Override
|
||||
public void onSetPricingResponse(UplinkQueueMessage uplinkQueueMessage, Callback callback) {
|
||||
log.info("接收到充电桩上费率下发反馈 {}", uplinkQueueMessage);
|
||||
log.info("接收到充电桩上报费率下发反馈 {}", uplinkQueueMessage);
|
||||
|
||||
// TODO 处理相关业务逻辑
|
||||
|
||||
@@ -277,7 +277,6 @@ public class DefaultPileProtocolService implements PileProtocolService {
|
||||
@Override
|
||||
public void startCharge(String pileCode, String gunCode, BigDecimal limitYuan, String orderNo) {
|
||||
|
||||
|
||||
UUID messageId = UUID.randomUUID();
|
||||
UUID requestId = UUID.randomUUID();
|
||||
|
||||
@@ -295,6 +294,22 @@ public class DefaultPileProtocolService implements PileProtocolService {
|
||||
.setTradeNo(orderNo)
|
||||
.build());
|
||||
|
||||
downlinkCallService.sendDownlinkMessage(downlinkRequestMessageBuilder, pileCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPricing(String pileCode, SetPricingRequest setPricingRequest) {
|
||||
UUID messageId = UUID.randomUUID();
|
||||
UUID requestId = UUID.randomUUID();
|
||||
|
||||
DownlinkRequestMessage.Builder downlinkRequestMessageBuilder = DownlinkRequestMessage.newBuilder()
|
||||
.setMessageIdMSB(messageId.getMostSignificantBits())
|
||||
.setMessageIdLSB(messageId.getLeastSignificantBits())
|
||||
.setPileCode(pileCode)
|
||||
.setRequestIdMSB(requestId.getMostSignificantBits())
|
||||
.setRequestIdLSB(requestId.getLeastSignificantBits())
|
||||
.setDownlinkCmd(DownlinkCmdEnum.SET_PRICING.name())
|
||||
.setSetPricingRequest(setPricingRequest);
|
||||
|
||||
downlinkCallService.sendDownlinkMessage(downlinkRequestMessageBuilder, pileCode);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user