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 2bb9850e
authored
Nov 15, 2023
by
zhouhaibao
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]充电桩对外接口
1 parent
d1e668fe
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
268 additions
and
6 deletions
platform-charging-api/src/main/java/cn/com/glsx/charging/api/PileControlFeignClient.java
platform-charging-api/src/main/java/cn/com/glsx/charging/modules/model/pilecontrol/EndBo.java
platform-charging-api/src/main/java/cn/com/glsx/charging/modules/model/pilecontrol/PileStartBo.java
platform-charging-api/src/main/java/cn/com/glsx/charging/modules/model/pilecontrol/StartBo.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/api/PileControlApiController.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/controller/PileControController.java
platform-charging/src/test/java/cn/com/glsx/charging/gbt/ocpp16/ClientSimulateTest.java
platform-charging/src/test/java/cn/com/glsx/charging/gbt/ocpp16/ModelValTest.java
platform-charging-api/src/main/java/cn/com/glsx/charging/api/PileControlFeignClient.java
0 → 100644
View file @
2bb9850
package
cn
.
com
.
glsx
.
charging
.
api
;
import
cn.com.glsx.charging.modules.model.UserDTO
;
import
cn.com.glsx.charging.modules.model.pilecontrol.EndBo
;
import
cn.com.glsx.charging.modules.model.pilecontrol.StartBo
;
import
com.glsx.plat.core.web.Result
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
/**
* @author payu
*/
@FeignClient
(
name
=
"platform-charging"
,
contextId
=
"pilecontrol"
,
path
=
"/api/user/"
,
decode404
=
true
)
public
interface
PileControlFeignClient
{
/**
* 一、FeignClients使用注意事项:
* 1. @EnableFeignClients 默认扫描 xxxxApplication启动入口 所在包路径下的 @FeignClient bean,若无法扫描到, 可以在使用Feign调用外部模块的api时候,
* 需要在引用服务中 xxxxApplication 中的 `@EnableFeignClients(basePackages = "cn.tendyron.customer")` 添加外部包需要扫描FeignClient的路径,否则无法注入bean
* 2. @FeignClient 声明的类,使用 spring.application.name 作为 name配置 @FeignClient(name="xxxx"),如果想保留 context-path , 则需要配置 path 属性 ,如:@FeignClient(name="xxxx" , path="xxxx(context-path)")
* 3. @FeignClient 接口对应的实现类,需要使用 @RestController注解 声明
* 4. mapper注解不支持 : @GetMapping,@PostMapping , 参数要加 @RequestParam(“xxx”)
* 5. FeignClient 调用,实质是httpClient调用 ,若我们暴露的接口api,声明了对应的 http mapper 信息,在调用方调用时候,通过代理 发起了 http请求,到服务提供方对应的http服务上去,所以在服务提供方的接口,可以使用 @RestController
* 来声明接口的 实现,否则调用方无法找到 http 对应的路径,会报404 ;
* 或者 根据 api 声明的http 信息,构建一个 Controller ,再来调用接口的实现类,但是这样不太方便;
* 6.FeignClient是一个“客户端”,它是用来发起请求的,不是提供服务的。
*
*
* 二、fallback 几种模式:
* 1.EchoCenterFeignServiceFallback.class 直接fallback,获取不到HTTP请求错误状态码和信息
* 2.EchoCenterFeignFactory.class 特定类型工厂模式
* 3.FunFallbackFactory 使用统一的工厂模式处理
*
*
* 三、性能问题
* 1.Feign是一个http请求调用的轻量级框架,基于http协议,性能不如rpc
* 2.可以为Feign配置连接池,配合使用okhttp等
*/
@PostMapping
(
"/start"
)
Result
<
Boolean
>
start
(
@RequestParam
StartBo
startBo
);
@PostMapping
(
"/end"
)
Result
<
Boolean
>
end
(
@RequestParam
EndBo
endBo
);
@PostMapping
(
"/pileStart"
)
Result
<
Boolean
>
pileStart
(
@RequestParam
StartBo
startBo
);
}
platform-charging-api/src/main/java/cn/com/glsx/charging/modules/model/pilecontrol/EndBo.java
0 → 100644
View file @
2bb9850
package
cn
.
com
.
glsx
.
charging
.
modules
.
model
.
pilecontrol
;
import
javax.validation.constraints.NotNull
;
import
lombok.Data
;
@Data
public
class
EndBo
{
/**
* 充电桩
*/
@NotNull
private
String
pileId
;
/**
* 充电枪
*/
@NotNull
private
Integer
gunNumber
;
}
platform-charging-api/src/main/java/cn/com/glsx/charging/modules/model/pilecontrol/PileStartBo.java
0 → 100644
View file @
2bb9850
package
cn
.
com
.
glsx
.
charging
.
modules
.
model
.
pilecontrol
;
import
javax.validation.constraints.NotNull
;
import
lombok.Data
;
@Data
public
class
PileStartBo
{
/**
* 交易流水号
*/
@NotNull
private
String
transactionSerialNumber
;
/**
* 充电桩
*/
@NotNull
private
String
pileId
;
/**
* 充电枪
*/
@NotNull
private
Integer
gunNumber
;
/**
* 逻辑卡号
*/
private
String
logicalCardNumber
;
/**
* 账户余额
*/
private
double
accountBalance
;
/**
* 成功标识
*/
private
Integer
successflag
;
/**
* 失败原因
*/
private
Integer
fail
;
}
platform-charging-api/src/main/java/cn/com/glsx/charging/modules/model/pilecontrol/StartBo.java
0 → 100644
View file @
2bb9850
package
cn
.
com
.
glsx
.
charging
.
modules
.
model
.
pilecontrol
;
import
javax.validation.constraints.NotNull
;
import
lombok.Data
;
@Data
public
class
StartBo
{
/**
* 交易流水号
*/
@NotNull
private
String
transactionSerialNumber
;
/**
* 充电桩
*/
@NotNull
private
String
pileId
;
/**
* 充电枪
*/
@NotNull
private
Integer
gunNumber
;
/**
*
*/
private
String
logicalCardNumber
;
/**
*
*/
private
String
physicalCardNumber
;
/**
*
*/
private
double
accountBalance
;
private
byte
succeedStatus
;
}
platform-charging/src/main/java/cn/com/glsx/charging/modules/api/PileControlApiController.java
0 → 100644
View file @
2bb9850
package
cn
.
com
.
glsx
.
charging
.
modules
.
api
;
import
cn.com.glsx.charging.api.PileControlFeignClient
;
import
cn.com.glsx.charging.api.UserCenterFeignClient
;
import
cn.com.glsx.charging.modules.converter.UserConverter
;
import
cn.com.glsx.charging.modules.entity.User
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.Ocpp16Helper
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.ServerMain
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpCallback
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpRsp
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.AdminSwipeConfirmRspData
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.ShutdownMachineReqData
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.StartMachineReqData
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.AdminSwipeConfirmRsp
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.ShutdownMachineReq
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.StartMachineReq
;
import
cn.com.glsx.charging.modules.model.UserDTO
;
import
cn.com.glsx.charging.modules.model.pilecontrol.EndBo
;
import
cn.com.glsx.charging.modules.model.pilecontrol.StartBo
;
import
cn.com.glsx.charging.modules.service.UserDemoService
;
import
com.glsx.plat.core.annotation.ResponseResultBody
;
import
com.glsx.plat.core.web.Result
;
import
io.swagger.v3.oas.annotations.Operation
;
import
io.swagger.v3.oas.annotations.tags.Tag
;
import
java.math.BigDecimal
;
import
javax.annotation.Resource
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
/**
* 微服务应用在网关中处理统一返回体
*
* @author payu
*/
@Slf4j
@Tag
(
name
=
"充电桩开放接口"
)
@RestController
@RequestMapping
(
value
=
"/pilecontro"
)
@ResponseResultBody
public
class
PileControlApiController
implements
PileControlFeignClient
{
@Resource
private
UserDemoService
userDemoService
;
@Override
public
Result
<
Boolean
>
start
(
StartBo
startBo
)
{
StartMachineReq
req
=
new
StartMachineReq
();
StartMachineReqData
data
=
new
StartMachineReqData
();
data
.
setTransactionSerialNumber
(
Ocpp16Helper
.
strToBcd
(
startBo
.
getTransactionSerialNumber
(),
data
.
getTransactionSerialNumber
()));
data
.
setPileId
(
Ocpp16Helper
.
strToBcd
(
startBo
.
getPileId
(),
data
.
getPileId
()));
data
.
setGunNumber
((
byte
)
1
);
data
.
setLogicalCardNumber
(
Ocpp16Helper
.
strToBcd
(
startBo
.
getTransactionSerialNumber
(),
data
.
getLogicalCardNumber
()));
byte
[]
bytes
=
Ocpp16Helper
.
binToBytes
(
Ocpp16Helper
.
hexToBinStr
(
startBo
.
getPhysicalCardNumber
()));
data
.
setPhysicalCardNumber
(
bytes
);
byte
[]
accountBytes
=
Ocpp16Helper
.
bigDecimalToByteArray
(
BigDecimal
.
valueOf
(
startBo
.
getAccountBalance
()),
2
);
data
.
setAccountBalance
(
accountBytes
);
req
.
setData
(
data
);
TcpCallback
<
TcpRsp
>
tcpRspTcpCallback
=
ServerMain
.
getServer
().
sendSync
(
req
);
TcpRsp
tcpRsp
=
tcpRspTcpCallback
.
get
();
return
Result
.
success
(
true
);
}
@Override
public
Result
<
Boolean
>
end
(
EndBo
endBo
)
{
ShutdownMachineReq
req
=
new
ShutdownMachineReq
();
ShutdownMachineReqData
data
=
new
ShutdownMachineReqData
();
data
.
setGunNumber
(
endBo
.
getGunNumber
().
byteValue
());
data
.
setPileId
(
Ocpp16Helper
.
strToBcd
(
endBo
.
getPileId
(),
data
.
getPileId
()));
req
.
setData
(
data
);
TcpCallback
<
TcpRsp
>
tcpRspTcpCallback
=
ServerMain
.
getServer
().
sendSync
(
req
);
TcpRsp
tcpRsp
=
tcpRspTcpCallback
.
get
();
return
Result
.
success
(
true
);
}
@Override
public
Result
<
Boolean
>
pileStart
(
StartBo
startBo
)
{
AdminSwipeConfirmRsp
rsp
=
new
AdminSwipeConfirmRsp
();
AdminSwipeConfirmRspData
data
=
new
AdminSwipeConfirmRspData
();
data
.
setPileId
(
Ocpp16Helper
.
strToBcd
(
startBo
.
getPileId
(),
data
.
getPileId
()));
data
.
setGunNumber
(
startBo
.
getGunNumber
().
byteValue
());
data
.
setSucceedStatus
(
startBo
.
getSucceedStatus
());
data
.
setAccountBalance
(
Ocpp16Helper
.
bigDecimalToByteArray
(
BigDecimal
.
valueOf
(
startBo
.
getAccountBalance
()),
4
));
data
.
setTransactionSerialNumber
(
Ocpp16Helper
.
strToBcd
(
startBo
.
getTransactionSerialNumber
(),
data
.
getTransactionSerialNumber
()));
data
.
setLogicalCardNumber
(
Ocpp16Helper
.
strToBcd
(
startBo
.
getLogicalCardNumber
(),
data
.
getTransactionSerialNumber
()));
rsp
.
setData
(
data
);
TcpCallback
<
TcpRsp
>
tcpRspTcpCallback
=
ServerMain
.
getServer
().
sendSync
(
rsp
);
TcpRsp
tcpRsp
=
tcpRspTcpCallback
.
get
();
return
Result
.
success
(
true
);
}
}
platform-charging/src/main/java/cn/com/glsx/charging/modules/controller/PileControController.java
View file @
2bb9850
...
...
@@ -101,7 +101,7 @@ public class PileControController extends BaseController {
ModelSetReqData
data
=
new
ModelSetReqData
();
data
.
setPileId
(
Ocpp16Helper
.
strToBcd
(
pileId
,
data
.
getPileId
()));
data
.
setModelCode
(
Ocpp16Helper
.
strToBcd
(
modelcode
,
data
.
getModelCode
()));
byte
[]
byteArray1
=
new
byte
[]{(
byte
)
0x8D
,
0x40
,
0x1
0
,
0x00
};
byte
[]
byteArray1
=
new
byte
[]{(
byte
)
0x9C
,
0x40
,
0x0
0
,
0x00
};
byte
[]
byteArray
=
new
byte
[]{(
byte
)
0x9C
,
0x40
,
0x01
,
0x00
};
data
.
setValleyDreRate
(
byteArray1
);
data
.
setValleyEleRate
(
byteArray1
);
...
...
@@ -168,8 +168,8 @@ public class PileControController extends BaseController {
}
public
static
void
main
(
String
[]
args
)
{
byte
[]
byteArray
=
new
byte
[]{(
byte
)
0x8D
,
0x40
,
0x1
0
,
0x00
};
BigDecimal
bigDecimal1
=
Ocpp16Helper
.
bytesBinToBigDecimal
(
byteArray
,
5
);
byte
[]
byteArray
1
=
new
byte
[]{(
byte
)
0x9C
,
0x40
,
0x0
0
,
0x00
};
BigDecimal
bigDecimal1
=
Ocpp16Helper
.
bytesBinToBigDecimal
(
byteArray
1
,
5
);
System
.
out
.
println
(
bigDecimal1
);
}
...
...
platform-charging/src/test/java/cn/com/glsx/charging/gbt/ocpp16/ClientSimulateTest.java
View file @
2bb9850
...
...
@@ -20,8 +20,8 @@ public class ClientSimulateTest {
Ocpp16Helper
.
scan
();
String
host
=
"1
21.199.192.223
"
;
int
port
=
8
76
8
;
String
host
=
"1
92.168.3.122
"
;
int
port
=
8
88
8
;
TcpClient
client
=
ClientMain
.
getInstance
(
host
,
port
);
Thread
.
sleep
(
3000
);
...
...
platform-charging/src/test/java/cn/com/glsx/charging/gbt/ocpp16/ModelValTest.java
View file @
2bb9850
...
...
@@ -18,7 +18,7 @@ public class ModelValTest {
Ocpp16Helper
.
scan
();
String
host
=
"
localhost
"
;
String
host
=
"
192.168.3.122
"
;
int
port
=
8888
;
TcpClient
client
=
ClientMain
.
getInstance
(
host
,
port
);
...
...
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