Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-boot-zx-biz
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Jobs
Commits
Open sidebar
项目统一框架
一体化_户用光伏项目代码
amos-boot-zx-biz
Commits
1dff0a2b
Commit
1dff0a2b
authored
Jul 17, 2024
by
yangyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
对接 碳银电站接口
parent
c671dc3b
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
121 additions
and
28 deletions
+121
-28
TanYinApiUtils.java
...m/yeejoin/amos/api/householdapi/Utils/TanYinApiUtils.java
+10
-9
TanYinConstant.java
...eejoin/amos/api/householdapi/constant/TanYinConstant.java
+16
-0
BusinessException.java
...in/amos/api/householdapi/exception/BusinessException.java
+10
-1
TanYinInveterInfo.java
...face/orm/houseapi/entity/tdeingine/TanYinInveterInfo.java
+78
-18
TanYinDataAcquisitionServiceImpl.java
...i/face/service/impl/TanYinDataAcquisitionServiceImpl.java
+0
-0
application-dev.properties
...-housepvapi/src/main/resources/application-dev.properties
+7
-0
No files found.
amos-boot-data/amos-boot-data-housepvapi/src/main/java/com/yeejoin/amos/api/householdapi/Utils/TanYinApiUtils.java
View file @
1dff0a2b
...
...
@@ -162,19 +162,23 @@ public class TanYinApiUtils {
// 记录请求日志。
log
.
debug
(
"请求 => 碳银{}接口,url:{},参数:{},headers:{}"
,
desc
,
url
,
paramsJsonStr
,
JSON
.
toJSONString
(
headers
));
HttpResponse
response
;
HttpResponse
response
=
null
;
try
{
// 发送POST请求,带上参数和headers,并执行。
response
=
HttpUtil
.
createPost
(
url
).
body
(
paramsJsonStr
,
MediaType
.
APPLICATION_JSON_UTF8_VALUE
).
headerMap
(
headers
,
true
).
execute
();
// 解析响应并返回。
return
parseResponse
(
desc
,
response
,
resultClass
);
}
catch
(
BusinessException
businessException
)
{
if
(
businessException
.
isTokenError
())
{
// 在业务异常情况下,尝试刷新令牌并重试请求。
// 刷新 Access_token
headers
.
put
(
"Authorization"
,
"Bearer "
+
refreshAccessToken
(
clientKey
,
clientSecret
));
response
=
HttpUtil
.
createPost
(
url
).
body
(
paramsJsonStr
,
MediaType
.
APPLICATION_JSON_UTF8_VALUE
).
headerMap
(
headers
,
true
).
execute
();
// 解析刷新令牌后的响应并返回。
return
parseResponse
(
desc
,
response
,
resultClass
);
}
log
.
warn
(
String
.
format
(
"异常 => 碳银%s接口,参数: %s,响应: %s"
,
desc
,
paramsJsonStr
,
response
!=
null
?
response
.
body
()
:
businessException
.
getMessage
()));
return
null
;
}
catch
(
Exception
e
)
{
// 记录未预期的异常日志。
log
.
warn
(
String
.
format
(
"异常 => 碳银%s接口,参数: %s"
,
desc
,
paramsJsonStr
),
e
);
...
...
@@ -208,24 +212,25 @@ public class TanYinApiUtils {
// 记录请求日志
log
.
info
(
"请求 => 碳银{}接口,url:{},参数:{},headers:{}"
,
desc
,
url
,
paramsJsonStr
,
JSON
.
toJSONString
(
headers
));
HttpResponse
response
;
HttpResponse
response
=
null
;
try
{
// 发送POST请求,设置请求体和请求头
response
=
HttpUtil
.
createPost
(
url
).
body
(
paramsJsonStr
,
MediaType
.
APPLICATION_JSON_UTF8_VALUE
).
headerMap
(
headers
,
true
).
execute
();
// 记录响应日志
log
.
info
(
"响应 => 碳银{}接口,参数:{},httpCode:{}, response:{}"
,
desc
,
paramsJsonStr
,
response
.
getStatus
(),
response
.
body
());
// 解析响应,返回分页信息和请求结果
return
parsePageResponse
(
desc
,
response
,
resultClass
);
}
catch
(
BusinessException
businessException
)
{
if
(
businessException
.
isTokenError
())
{
// 在业务异常情况下,尝试刷新令牌并重试请求。
// 刷新 Access_token
headers
.
put
(
"Authorization"
,
"Bearer "
+
refreshAccessToken
(
clientKey
,
clientSecret
));
// 重新发送请求并解析响应
response
=
HttpUtil
.
createPost
(
url
).
body
(
paramsJsonStr
,
MediaType
.
APPLICATION_JSON_UTF8_VALUE
).
headerMap
(
headers
,
true
).
execute
();
return
parsePageResponse
(
desc
,
response
,
resultClass
);
}
log
.
warn
(
String
.
format
(
"异常 => 碳银%s接口,参数: %s,响应: %s"
,
desc
,
paramsJsonStr
,
response
!=
null
?
response
.
body
()
:
businessException
.
getMessage
()));
return
null
;
}
catch
(
Exception
e
)
{
// 记录异常日志
log
.
warn
(
String
.
format
(
"异常 => 碳银%s接口,参数: %s"
,
desc
,
paramsJsonStr
),
e
);
...
...
@@ -261,12 +266,8 @@ public class TanYinApiUtils {
// 检查响应是否成功并存在有效数据,如果不成功且错误码为401,则抛出业务异常;其他情况返回null。
if
(!
baseResult
.
getSuccess
()
||
Objects
.
isNull
(
baseResult
.
getData
()))
{
if
(
"401"
.
equals
(
baseResult
.
getCode
()))
{
// Token 过期
throw
new
BusinessException
(
baseResult
.
getCode
().
toString
(),
baseResult
.
getMsg
());
}
return
null
;
}
// 解析响应数据部分,根据其类型进行相应的处理和转换。
JSON
result
=
(
JSON
)
baseResult
.
getData
();
...
...
amos-boot-data/amos-boot-data-housepvapi/src/main/java/com/yeejoin/amos/api/householdapi/constant/TanYinConstant.java
View file @
1dff0a2b
package
com
.
yeejoin
.
amos
.
api
.
householdapi
.
constant
;
import
java.util.HashMap
;
/**
* 碳银常量类
* <p>
...
...
@@ -35,4 +37,18 @@ public class TanYinConstant {
*/
public
static
String
refreshAccessTokenUrl
=
"/v1/auth/refreshAccessToken"
;
public
static
final
HashMap
<
String
,
String
>
stationStatus
=
new
HashMap
<
String
,
String
>()
{
{
put
(
"0"
,
"在线"
);
put
(
"1"
,
"离线"
);
put
(
"2"
,
"异常"
);
}
};
public
static
final
HashMap
<
String
,
String
>
intoNetWorkStatus
=
new
HashMap
<
String
,
String
>()
{
{
put
(
"0"
,
"普通并网"
);
}
};
}
amos-boot-data/amos-boot-data-housepvapi/src/main/java/com/yeejoin/amos/api/householdapi/exception/BusinessException.java
View file @
1dff0a2b
...
...
@@ -12,18 +12,27 @@ import org.typroject.tyboot.core.foundation.exception.BaseException;
*/
public
class
BusinessException
extends
BaseException
{
private
String
code
=
""
;
public
BusinessException
(
String
message
)
{
super
(
message
,
BusinessException
.
class
.
getSimpleName
(),
"错误的请求."
);
this
.
code
=
"-1"
;
this
.
httpStatus
=
500
;
}
public
BusinessException
(
String
message
,
String
errorCod
e
)
{
public
BusinessException
(
String
errorCode
,
String
messag
e
)
{
super
(
message
,
BusinessException
.
class
.
getSimpleName
(),
message
);
if
(
StringUtils
.
isBlank
(
errorCode
))
{
this
.
httpStatus
=
500
;
this
.
code
=
errorCode
;
}
else
{
this
.
httpStatus
=
Integer
.
parseInt
(
errorCode
);
this
.
code
=
errorCode
;
}
}
public
boolean
isTokenError
()
{
return
"401"
.
equals
(
this
.
code
);
}
}
amos-boot-data/amos-boot-data-housepvapi/src/main/java/com/yeejoin/amos/api/householdapi/face/orm/houseapi/entity/tdeingine/TanYinInveterInfo.java
View file @
1dff0a2b
...
...
@@ -37,6 +37,10 @@ public class TanYinInveterInfo {
@TableField
(
"gmt_create"
)
private
String
gmtCreate
;
@ApiModelProperty
(
"ID"
)
@TableField
(
"idString"
)
private
String
idString
;
@ApiModelProperty
(
"功率"
)
@TableField
(
"watt"
)
private
String
watt
;
...
...
@@ -81,10 +85,50 @@ public class TanYinInveterInfo {
@TableField
(
"vol4"
)
private
String
vol4
;
@ApiModelProperty
(
"输出电压 1"
)
@TableField
(
"vol5"
)
private
String
vol5
;
@ApiModelProperty
(
"输出电压 2"
)
@TableField
(
"vol6"
)
private
String
vol6
;
@ApiModelProperty
(
"输出电压 3"
)
@TableField
(
"vol7"
)
private
String
vol7
;
@ApiModelProperty
(
"输出电压 3"
)
@TableField
(
"vol8"
)
private
String
vol8
;
@ApiModelProperty
(
"输出电压 3"
)
@TableField
(
"vol9"
)
private
String
vol9
;
@ApiModelProperty
(
"输入电压 6"
)
@TableField
(
"vol10"
)
private
String
vol10
;
@ApiModelProperty
(
"输出电压 3"
)
@TableField
(
"vol11"
)
private
String
vol11
;
@ApiModelProperty
(
"输出电压 3"
)
@TableField
(
"vol12"
)
private
String
vol12
;
@ApiModelProperty
(
"输出电压 3"
)
@TableField
(
"vol13"
)
private
String
vol13
;
@ApiModelProperty
(
"输出电压 3"
)
@TableField
(
"vol14"
)
private
String
vol14
;
@ApiModelProperty
(
"输出电压 3"
)
@TableField
(
"vol15"
)
private
String
vol15
;
@ApiModelProperty
(
"输入电流 1"
)
@TableField
(
"amp0"
)
private
String
amp0
;
...
...
@@ -106,33 +150,49 @@ public class TanYinInveterInfo {
private
String
amp4
;
@ApiModelProperty
(
"输入电流 6"
)
@TableField
(
"amp10"
)
private
String
amp10
;
@ApiModelProperty
(
"输出电压 1"
)
@TableField
(
"vol5"
)
private
String
vol5
;
@ApiModelProperty
(
"输出电压 2"
)
@TableField
(
"vol6"
)
private
String
vol6
;
@ApiModelProperty
(
"输出电压 3"
)
@TableField
(
"vol7"
)
private
String
vol7
;
@ApiModelProperty
(
"输出电流 1"
)
@TableField
(
"amp5"
)
private
String
amp5
;
@ApiModelProperty
(
"输
出电流 2
"
)
@ApiModelProperty
(
"输
入电流 7
"
)
@TableField
(
"amp6"
)
private
String
amp6
;
@ApiModelProperty
(
"输
出电流 3
"
)
@ApiModelProperty
(
"输
入电流 8
"
)
@TableField
(
"amp7"
)
private
String
amp7
;
@ApiModelProperty
(
"输入电流 9"
)
@TableField
(
"amp8"
)
private
String
amp8
;
@ApiModelProperty
(
"输入电流 10"
)
@TableField
(
"amp9"
)
private
String
amp9
;
@ApiModelProperty
(
"输入电流 11"
)
@TableField
(
"amp10"
)
private
String
amp10
;
@ApiModelProperty
(
"输入电流 12"
)
@TableField
(
"amp11"
)
private
String
amp11
;
@ApiModelProperty
(
"输入电流 13"
)
@TableField
(
"amp12"
)
private
String
amp12
;
@ApiModelProperty
(
"输入电流 14"
)
@TableField
(
"amp13"
)
private
String
amp13
;
@ApiModelProperty
(
"输入电流 15"
)
@TableField
(
"amp14"
)
private
String
amp14
;
@ApiModelProperty
(
"输入电流 16"
)
@TableField
(
"amp15"
)
private
String
amp15
;
@ApiModelProperty
(
"温度(单位:摄氏度)"
)
@TableField
(
"temperature"
)
private
String
temperature
;
...
...
amos-boot-data/amos-boot-data-housepvapi/src/main/java/com/yeejoin/amos/api/householdapi/face/service/impl/TanYinDataAcquisitionServiceImpl.java
View file @
1dff0a2b
This diff is collapsed.
Click to expand it.
amos-boot-data/amos-boot-data-housepvapi/src/main/resources/application-dev.properties
View file @
1dff0a2b
...
...
@@ -73,3 +73,9 @@ dataRequstScheduled.Sunlight=0 0/50 * * * *
dataRequstScheduled.GoodWe
=
0 0/3 * * * *
dataRequstScheduled.Sofar
=
0 0/50 * * * *
# 碳银
tanYin.api.apiUrl
=
https://userauth.tanwin.cn
tanYin.api.clientSecret
=
rKrWVa2sXsSZeNAOW43v
tanYin.api.clientKey
=
yx10001
dataRequestScheduled.tanYin
=
0 0/10 * * * *
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment