Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
platform
/
platform-charging-server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 973314e7
authored
Nov 14, 2023
by
叶立庆
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+] 交易记录/实时监测数据上报到业务
1 parent
d9c21f76
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
112 additions
and
49 deletions
platform-charging-api/pom.xml
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/handler/TransactionRecordsReqHandler.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/handler/UploadRealTimeRspHandler.java
platform-charging-api/pom.xml
View file @
973314e
...
...
@@ -22,6 +22,11 @@
<groupId>
com.glsx
</groupId>
<artifactId>
rest-admin-feign
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-loadbalancer
</artifactId>
<version>
3.1.0
</version>
</dependency>
</dependencies>
</project>
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/handler/TransactionRecordsReqHandler.java
View file @
973314e
...
...
@@ -6,60 +6,116 @@ import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.TransactionRecordsReqDat
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.TransactionRecordsRespData
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.TransactionRecordsReq
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.TransactionRecordsResp
;
import
cn.com.glsx.charging.modules.service.DataInteractionService
;
import
cn.com.glsx.charging.util.ByteUtils
;
import
cn.com.glsx.charging.util.SpringContextUtil
;
import
cn.com.glsx.evbusiness.api.DataInteractionFeignClient
;
import
cn.com.glsx.evbusiness.modules.model.ocpp16.TransactionRecordsData
;
import
com.glsx.plat.core.web.Result
;
import
io.netty.channel.Channel
;
/**
* @Description 运营平台接收到结算账单上传后,都需回复此确认信息。若桩未收到回复帧,则 5 分钟后继续
*
上送一次交易记录,此情况下无论平台是否成功回复都停止上送。这一帧仅是报文交互使用,
*
意指平台成功接收到交易记录报文,并不代表交易订单成功结算
* 上送一次交易记录,此情况下无论平台是否成功回复都停止上送。这一帧仅是报文交互使用,
* 意指平台成功接收到交易记录报文,并不代表交易订单成功结算
* @Author yelq
* @Date 2023/11/7-17:37
* @Version 1.0
*/
public
class
TransactionRecordsReqHandler
implements
TcpHandler
<
TransactionRecordsReq
,
TransactionRecordsResp
>
{
@Override
public
TransactionRecordsResp
handle
(
Channel
channel
,
TransactionRecordsReq
transactionRecordsReq
)
{
TransactionRecordsReqData
data
=
transactionRecordsReq
.
getData
();
/** 解析参数日志打印 */
log
.
info
(
"交易流水号:{}"
,
Ocpp16Helper
.
bcdToStr
(
data
.
getTransactionSerialNumber
()));
log
.
info
(
"桩编号:{}"
,
Ocpp16Helper
.
bcdToStr
(
data
.
getPileId
()));
log
.
info
(
"枪号:{}"
,
data
.
getGunNumber
());
log
.
info
(
"开始时间:{}"
,
ByteUtils
.
toHex
(
data
.
getStartTime
()));
log
.
info
(
"结束时间:{}"
,
ByteUtils
.
toHex
(
data
.
getEndTime
()));
log
.
info
(
"尖单价:{}"
,
ByteUtils
.
toHex
(
data
.
getPeakUnitPrice
()));
log
.
info
(
"尖电量:{}"
,
ByteUtils
.
toHex
(
data
.
getPeakElectricity
()));
log
.
info
(
"计损尖电量:{}"
,
ByteUtils
.
toHex
(
data
.
getPeakElectricityLoss
()));
log
.
info
(
"尖金额:{}"
,
ByteUtils
.
toHex
(
data
.
getPeakAmount
()));
log
.
info
(
"峰单价:{}"
,
ByteUtils
.
toHex
(
data
.
getTopUnitPrice
()));
log
.
info
(
"峰电量:{}"
,
ByteUtils
.
toHex
(
data
.
getTopElectricity
()));
log
.
info
(
"计损峰电量:{}"
,
ByteUtils
.
toHex
(
data
.
getTopElectricityLoss
()));
log
.
info
(
"峰金额:{}"
,
ByteUtils
.
toHex
(
data
.
getTopAmount
()));
log
.
info
(
"平单价:{}"
,
ByteUtils
.
toHex
(
data
.
getFlatUnitPrice
()));
log
.
info
(
"平电量:{}"
,
ByteUtils
.
toHex
(
data
.
getFlatElectricity
()));
log
.
info
(
"计损平电量:{}"
,
ByteUtils
.
toHex
(
data
.
getFlatElectricityLoss
()));
log
.
info
(
"平金额:{}"
,
ByteUtils
.
toHex
(
data
.
getFlatAmount
()));
log
.
info
(
"谷单价:{}"
,
ByteUtils
.
toHex
(
data
.
getValleyUnitPrice
()));
log
.
info
(
"谷电量:{}"
,
ByteUtils
.
toHex
(
data
.
getValleyElectricity
()));
log
.
info
(
"计损谷电量:{}"
,
ByteUtils
.
toHex
(
data
.
getValleyElectricityLoss
()));
log
.
info
(
"谷金额:{}"
,
ByteUtils
.
toHex
(
data
.
getValleyAmount
()));
log
.
info
(
"电表总起值:{}"
,
ByteUtils
.
toHex
(
data
.
getTotalStartValue
()));
log
.
info
(
"电表总止值:{}"
,
ByteUtils
.
toHex
(
data
.
getTotalEndValue
()));
log
.
info
(
"总电量:{}"
,
ByteUtils
.
toHex
(
data
.
getTotalElectricity
()));
log
.
info
(
"计损总电量:{}"
,
ByteUtils
.
toHex
(
data
.
getTotalElectricityLoss
()));
log
.
info
(
"消费金额:{}"
,
ByteUtils
.
toHex
(
data
.
getTotalAmount
()));
log
.
info
(
"电动汽车唯一标识:{}"
,
ByteUtils
.
toHex
(
data
.
getVehicleIdentifier
()));
log
.
info
(
"交易标识:{}"
,
data
.
getTransactionIdentifier
());
log
.
info
(
"交易日期、时间:{}"
,
ByteUtils
.
toHex
(
data
.
getTransactionDateTime
()));
log
.
info
(
"停止原因:{}"
,
data
.
getStopReason
());
log
.
info
(
"物理卡号:{}"
,
ByteUtils
.
toHex
(
data
.
getPhysicalCardNumber
()));
/** 解析参数日志打印 */
TransactionRecordsResp
resp
=
new
TransactionRecordsResp
();
TransactionRecordsRespData
respData
=
new
TransactionRecordsRespData
();
respData
.
setTransactionSerialNumber
(
data
.
getTransactionSerialNumber
());
respData
.
setConfirmResult
((
byte
)
0
);
@Override
public
TransactionRecordsResp
handle
(
Channel
channel
,
TransactionRecordsReq
transactionRecordsReq
)
{
TransactionRecordsReqData
data
=
transactionRecordsReq
.
getData
();
/** 解析参数日志打印 */
log
.
info
(
"交易流水号:{}"
,
Ocpp16Helper
.
bcdToStr
(
data
.
getTransactionSerialNumber
()));
log
.
info
(
"桩编号:{}"
,
Ocpp16Helper
.
bcdToStr
(
data
.
getPileId
()));
log
.
info
(
"枪号:{}"
,
data
.
getGunNumber
());
log
.
info
(
"开始时间:{}"
,
ByteUtils
.
toHex
(
data
.
getStartTime
()));
log
.
info
(
"结束时间:{}"
,
ByteUtils
.
toHex
(
data
.
getEndTime
()));
log
.
info
(
"尖单价:{}"
,
ByteUtils
.
toHex
(
data
.
getPeakUnitPrice
()));
log
.
info
(
"尖电量:{}"
,
ByteUtils
.
toHex
(
data
.
getPeakElectricity
()));
log
.
info
(
"计损尖电量:{}"
,
ByteUtils
.
toHex
(
data
.
getPeakElectricityLoss
()));
log
.
info
(
"尖金额:{}"
,
ByteUtils
.
toHex
(
data
.
getPeakAmount
()));
log
.
info
(
"峰单价:{}"
,
ByteUtils
.
toHex
(
data
.
getTopUnitPrice
()));
log
.
info
(
"峰电量:{}"
,
ByteUtils
.
toHex
(
data
.
getTopElectricity
()));
log
.
info
(
"计损峰电量:{}"
,
ByteUtils
.
toHex
(
data
.
getTopElectricityLoss
()));
log
.
info
(
"峰金额:{}"
,
ByteUtils
.
toHex
(
data
.
getTopAmount
()));
log
.
info
(
"平单价:{}"
,
ByteUtils
.
toHex
(
data
.
getFlatUnitPrice
()));
log
.
info
(
"平电量:{}"
,
ByteUtils
.
toHex
(
data
.
getFlatElectricity
()));
log
.
info
(
"计损平电量:{}"
,
ByteUtils
.
toHex
(
data
.
getFlatElectricityLoss
()));
log
.
info
(
"平金额:{}"
,
ByteUtils
.
toHex
(
data
.
getFlatAmount
()));
log
.
info
(
"谷单价:{}"
,
ByteUtils
.
toHex
(
data
.
getValleyUnitPrice
()));
log
.
info
(
"谷电量:{}"
,
ByteUtils
.
toHex
(
data
.
getValleyElectricity
()));
log
.
info
(
"计损谷电量:{}"
,
ByteUtils
.
toHex
(
data
.
getValleyElectricityLoss
()));
log
.
info
(
"谷金额:{}"
,
ByteUtils
.
toHex
(
data
.
getValleyAmount
()));
log
.
info
(
"电表总起值:{}"
,
ByteUtils
.
toHex
(
data
.
getTotalStartValue
()));
log
.
info
(
"电表总止值:{}"
,
ByteUtils
.
toHex
(
data
.
getTotalEndValue
()));
log
.
info
(
"总电量:{}"
,
ByteUtils
.
toHex
(
data
.
getTotalElectricity
()));
log
.
info
(
"计损总电量:{}"
,
ByteUtils
.
toHex
(
data
.
getTotalElectricityLoss
()));
log
.
info
(
"消费金额:{}"
,
ByteUtils
.
toHex
(
data
.
getTotalAmount
()));
log
.
info
(
"电动汽车唯一标识:{}"
,
ByteUtils
.
toHex
(
data
.
getVehicleIdentifier
()));
log
.
info
(
"交易标识:{}"
,
data
.
getTransactionIdentifier
());
log
.
info
(
"交易日期、时间:{}"
,
ByteUtils
.
toHex
(
data
.
getTransactionDateTime
()));
log
.
info
(
"停止原因:{}"
,
data
.
getStopReason
());
log
.
info
(
"物理卡号:{}"
,
ByteUtils
.
toHex
(
data
.
getPhysicalCardNumber
()));
/** 解析参数日志打印 */
Boolean
b
=
syncData
(
data
);
TransactionRecordsResp
resp
=
new
TransactionRecordsResp
();
TransactionRecordsRespData
respData
=
new
TransactionRecordsRespData
();
respData
.
setTransactionSerialNumber
(
data
.
getTransactionSerialNumber
());
respData
.
setConfirmResult
((
byte
)
0
);
resp
.
setData
(
respData
);
return
resp
;
}
resp
.
setData
(
respData
);
return
resp
;
}
/**
* 调业务侧接口
*
* @param data
*/
private
Boolean
syncData
(
TransactionRecordsReqData
data
)
{
TransactionRecordsData
respData
=
new
TransactionRecordsData
();
respData
.
setTransactionSerialNumber
(
Ocpp16Helper
.
bcdToStr
(
data
.
getTransactionSerialNumber
()));
respData
.
setPileId
(
Ocpp16Helper
.
bcdToStr
(
data
.
getPileId
()));
respData
.
setGunNumber
(
data
.
getGunNumber
());
respData
.
setStartTime
(
ByteUtils
.
parseCp56Time2a
(
data
.
getStartTime
()));
respData
.
setEndTime
(
ByteUtils
.
parseCp56Time2a
(
data
.
getEndTime
()));
respData
.
setPeakUnitPrice
(
Ocpp16Helper
.
bytesBinToBigDecimal
(
data
.
getPeakUnitPrice
(),
5
));
respData
.
setPeakElectricity
(
Ocpp16Helper
.
bytesBinToBigDecimal
(
data
.
getPeakElectricity
(),
4
));
respData
.
setPeakElectricityLoss
(
Ocpp16Helper
.
bytesBinToBigDecimal
(
data
.
getPeakElectricityLoss
(),
4
));
respData
.
setPeakAmount
(
Ocpp16Helper
.
bytesBinToBigDecimal
(
data
.
getPeakAmount
(),
4
));
respData
.
setTopUnitPrice
(
Ocpp16Helper
.
bytesBinToBigDecimal
(
data
.
getTopUnitPrice
(),
4
));
respData
.
setTopElectricity
(
Ocpp16Helper
.
bytesBinToBigDecimal
(
data
.
getTopElectricity
(),
4
));
respData
.
setTopElectricityLoss
(
Ocpp16Helper
.
bytesBinToBigDecimal
(
data
.
getTopElectricityLoss
(),
4
));
respData
.
setTopAmount
(
Ocpp16Helper
.
bytesBinToBigDecimal
(
data
.
getTopAmount
(),
4
));
respData
.
setFlatUnitPrice
(
Ocpp16Helper
.
bytesBinToBigDecimal
(
data
.
getFlatUnitPrice
(),
4
));
respData
.
setFlatElectricity
(
Ocpp16Helper
.
bytesBinToBigDecimal
(
data
.
getFlatElectricity
(),
4
));
respData
.
setFlatElectricityLoss
(
Ocpp16Helper
.
bytesBinToBigDecimal
(
data
.
getFlatElectricityLoss
(),
4
));
respData
.
setFlatAmount
(
Ocpp16Helper
.
bytesBinToBigDecimal
(
data
.
getFlatAmount
(),
4
));
respData
.
setValleyUnitPrice
(
Ocpp16Helper
.
bytesBinToBigDecimal
(
data
.
getValleyUnitPrice
(),
4
));
respData
.
setValleyElectricity
(
Ocpp16Helper
.
bytesBinToBigDecimal
(
data
.
getValleyElectricity
(),
4
));
respData
.
setValleyElectricityLoss
(
Ocpp16Helper
.
bytesBinToBigDecimal
(
data
.
getValleyElectricityLoss
(),
4
));
respData
.
setValleyAmount
(
Ocpp16Helper
.
bytesBinToBigDecimal
(
data
.
getValleyAmount
(),
4
));
respData
.
setTotalStartValue
(
Ocpp16Helper
.
bytesBinToBigDecimal
(
data
.
getTotalStartValue
(),
4
));
respData
.
setTotalEndValue
(
Ocpp16Helper
.
bytesBinToBigDecimal
(
data
.
getTotalEndValue
(),
4
));
respData
.
setTotalElectricity
(
Ocpp16Helper
.
bytesBinToBigDecimal
(
data
.
getTotalElectricity
(),
4
));
respData
.
setTotalElectricityLoss
(
Ocpp16Helper
.
bytesBinToBigDecimal
(
data
.
getTotalElectricityLoss
(),
4
));
respData
.
setTotalAmount
(
Ocpp16Helper
.
bytesBinToBigDecimal
(
data
.
getTotalAmount
(),
4
));
respData
.
setVehicleIdentifier
(
ByteUtils
.
toHex
(
data
.
getVehicleIdentifier
()));
respData
.
setTransactionIdentifier
(
data
.
getTransactionIdentifier
());
respData
.
setTransactionDateTime
(
ByteUtils
.
parseCp56Time2a
(
data
.
getTransactionDateTime
()));
respData
.
setStopReason
(
data
.
getStopReason
());
respData
.
setPhysicalCardNumber
(
ByteUtils
.
toHex
(
data
.
getPhysicalCardNumber
()));
DataInteractionFeignClient
feignClient
=
SpringContextUtil
.
getBean
(
DataInteractionFeignClient
.
class
);
Result
<
Boolean
>
result
=
feignClient
.
uploadTransactionRecordsData
(
respData
);
log
.
info
(
"feign调用结果:{}"
,
result
);
return
result
.
getData
();
}
}
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/handler/UploadRealTimeRspHandler.java
View file @
973314e
...
...
@@ -7,7 +7,9 @@ import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.UploadRealtimeDataRs
import
cn.com.glsx.charging.modules.service.DataInteractionService
;
import
cn.com.glsx.charging.util.ByteUtils
;
import
cn.com.glsx.charging.util.SpringContextUtil
;
import
cn.com.glsx.evbusiness.api.DataInteractionFeignClient
;
import
cn.com.glsx.evbusiness.modules.model.ocpp16.RealTimeUploadData
;
import
com.glsx.plat.core.web.Result
;
import
io.netty.channel.Channel
;
import
java.util.Objects
;
...
...
@@ -52,10 +54,10 @@ public class UploadRealTimeRspHandler implements TcpHandler<UploadRealtimeDataRs
upData
.
setLossChargingDegree
(
Ocpp16Helper
.
bytesBinToBigDecimal
(
data
.
getLossChargingDegree
(),
4
));
upData
.
setChargingMoney
(
Ocpp16Helper
.
bytesBinToBigDecimal
(
data
.
getChargingMoney
(),
4
));
upData
.
setHardwareMalfunction
(
Ocpp16Helper
.
bytesBinToBigDecimal
(
data
.
getHardwareMalfunction
(),
0
).
shortValue
());
// TODO: 2023/11/13 调用业务侧接口、把数据传给业务侧
DataInteractionService
dataInteractionService
=
SpringContextUtil
.
getBean
(
DataInteractionService
.
class
);
dataInteractionService
.
test
(
upData
);
return
true
;
DataInteractionFeignClient
feignClient
=
SpringContextUtil
.
getBean
(
DataInteractionFeignClient
.
class
);
Result
<
Boolean
>
result
=
feignClient
.
uploadRealTimeData
(
upData
);
log
.
info
(
"feign调用结果:{}"
,
result
);
return
result
.
getData
()
;
}
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment