Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-boot-biz
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
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
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
项目统一框架
amos-boot-biz
Commits
95bdca29
Commit
95bdca29
authored
Jun 16, 2023
by
caotao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
户用光伏数据采集初版提交
parent
5298a92d
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
125 additions
and
268 deletions
+125
-268
pom.xml
amos-boot-data/amos-boot-data-accessapi/pom.xml
+5
-3
HouseholdPvUtils.java
...yeejoin/amos/api/householdapi/Utils/HouseholdPvUtils.java
+40
-0
HttpUtils.java
...va/com/yeejoin/amos/api/householdapi/Utils/HttpUtils.java
+0
-244
HouseholdPvApiTestController.java
...householdapi/controller/HouseholdPvApiTestController.java
+35
-18
HouseholdPvProducerInfoDto.java
...i/householdapi/face/model/HouseholdPvProducerInfoDto.java
+5
-3
HouseholdPvProducerInfo.java
...householdapi/face/orm/entity/HouseholdPvProducerInfo.java
+5
-0
PVProducerInfoEnum.java
...va/com/yeejoin/amos/openapi/enums/PVProducerInfoEnum.java
+35
-0
No files found.
amos-boot-data/amos-boot-data-accessapi/pom.xml
View file @
95bdca29
...
...
@@ -141,9 +141,6 @@
<artifactId>
license-sdk
</artifactId>
<version>
1.0.0
</version>
</dependency>
<!-- druid -->
<dependency>
<groupId>
com.alibaba
</groupId>
...
...
@@ -167,6 +164,11 @@
<version>
1.2.16
</version>
<scope>
compile
</scope>
</dependency>
<dependency>
<groupId>
cn.hutool
</groupId>
<artifactId>
hutool-all
</artifactId>
<version>
5.7.22
</version>
</dependency>
</dependencies>
<build>
<plugins>
...
...
amos-boot-data/amos-boot-data-accessapi/src/main/java/com/yeejoin/amos/api/householdapi/Utils/HouseholdPvUtils.java
0 → 100644
View file @
95bdca29
package
com
.
yeejoin
.
amos
.
api
.
householdapi
.
Utils
;
import
cn.hutool.http.HttpUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.yeejoin.amos.openapi.enums.PVProducerInfoEnum
;
import
java.util.HashMap
;
public
class
HouseholdPvUtils
{
public
static
HashMap
<
String
,
String
>
getHeaderByProducerCode
(
PVProducerInfoEnum
producerInfoEnum
)
{
HashMap
<
String
,
String
>
hashMap
=
new
HashMap
<>();
if
(
PVProducerInfoEnum
.
GDW
.
equals
(
producerInfoEnum
))
{
HashMap
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"account"
,
"18679135705"
);
map
.
put
(
"pwd"
,
"Ljf5705@sems"
);
String
body
=
JSON
.
toJSONString
(
map
);
String
response
=
HttpUtil
.
createPost
(
"http://openapi.sems.com.cn/api/OpenApi/GetToken"
).
body
(
body
).
execute
().
body
();
JSONObject
jsonObject
=
JSON
.
parseObject
(
response
);
if
(
jsonObject
.
get
(
"data"
)
!=
null
)
{
JSONObject
jsonObject1
=
(
JSONObject
)
jsonObject
.
get
(
"data"
);
hashMap
.
put
(
"token"
,
(
String
)
jsonObject1
.
get
(
"token"
));
}
}
else
if
(
PVProducerInfoEnum
.
SH
.
equals
(
producerInfoEnum
))
{
HashMap
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"accountName"
,
"18120415291"
);
map
.
put
(
"appId"
,
447430219192733696
l
);
map
.
put
(
"appSecret"
,
"5881ee8c062817016a2b34425c45937d"
);
map
.
put
(
"corporationId"
,
"447430928264990720"
);
map
.
put
(
"accountType"
,
2
);
String
body
=
JSON
.
toJSONString
(
map
);
String
response
=
HttpUtil
.
createPost
(
"https://openapi.sofarsolarmonitor.com/account/auth/createToken"
).
body
(
body
).
execute
().
body
();
JSONObject
jsonObject
=
JSON
.
parseObject
(
response
);
hashMap
.
put
(
"Authorization"
,
(
String
)
jsonObject
.
get
(
"data"
));
}
return
hashMap
;
}
}
amos-boot-data/amos-boot-data-accessapi/src/main/java/com/yeejoin/amos/api/householdapi/Utils/HttpUtils.java
deleted
100644 → 0
View file @
5298a92d
package
com
.
yeejoin
.
amos
.
api
.
householdapi
.
Utils
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.NameValuePair
;
import
org.apache.http.client.HttpClient
;
import
org.apache.http.client.config.RequestConfig
;
import
org.apache.http.client.entity.UrlEncodedFormEntity
;
import
org.apache.http.client.methods.CloseableHttpResponse
;
import
org.apache.http.client.methods.HttpGet
;
import
org.apache.http.client.methods.HttpPost
;
import
org.apache.http.conn.ssl.SSLConnectionSocketFactory
;
import
org.apache.http.conn.ssl.TrustStrategy
;
import
org.apache.http.entity.StringEntity
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.HttpClients
;
import
org.apache.http.impl.conn.PoolingHttpClientConnectionManager
;
import
org.apache.http.message.BasicNameValuePair
;
import
org.apache.http.ssl.SSLContextBuilder
;
import
org.apache.http.util.EntityUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
javax.net.ssl.HostnameVerifier
;
import
javax.net.ssl.SSLContext
;
import
javax.net.ssl.SSLSession
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.nio.charset.Charset
;
import
java.security.GeneralSecurityException
;
import
java.security.cert.CertificateException
;
import
java.security.cert.X509Certificate
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
public
class
HttpUtils
{
private
static
PoolingHttpClientConnectionManager
connMgr
;
private
static
RequestConfig
requestConfig
;
private
static
final
int
MAX_TIMEOUT
=
50000
;
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
HttpUtils
.
class
);
static
{
// 设置连接池
connMgr
=
new
PoolingHttpClientConnectionManager
();
// 设置连接池大小
connMgr
.
setMaxTotal
(
100
);
connMgr
.
setDefaultMaxPerRoute
(
connMgr
.
getMaxTotal
());
// Validate connections after 1 sec of inactivity
connMgr
.
setValidateAfterInactivity
(
5000
);
RequestConfig
.
Builder
configBuilder
=
RequestConfig
.
custom
();
// 设置连接超时
configBuilder
.
setConnectTimeout
(
MAX_TIMEOUT
);
// 设置读取超时
configBuilder
.
setSocketTimeout
(
MAX_TIMEOUT
);
// 设置从连接池获取连接实例的超时
configBuilder
.
setConnectionRequestTimeout
(
MAX_TIMEOUT
);
requestConfig
=
configBuilder
.
build
();
}
/**
* 发送 GET 请求(HTTP),不带输入数据
*
* @param url
* @return
*/
public
static
String
doGet
(
String
url
)
{
return
doGet
(
url
,
new
HashMap
<
String
,
Object
>());
}
/**
* 发送 GET 请求(HTTP),K-V形式
*
* @param url
* @param params
* @return
*/
public
static
String
doGet
(
String
url
,
Map
<
String
,
Object
>
params
)
{
String
apiUrl
=
url
;
StringBuffer
param
=
new
StringBuffer
();
int
i
=
0
;
for
(
String
key
:
params
.
keySet
())
{
if
(
i
==
0
)
param
.
append
(
"?"
);
else
param
.
append
(
"&"
);
param
.
append
(
key
).
append
(
"="
).
append
(
params
.
get
(
key
));
i
++;
}
apiUrl
+=
param
;
String
result
=
null
;
HttpClient
httpClient
=
null
;
if
(
apiUrl
.
startsWith
(
"https"
))
{
httpClient
=
HttpClients
.
custom
().
setSSLSocketFactory
(
createSSLConnSocketFactory
())
.
setConnectionManager
(
connMgr
).
setDefaultRequestConfig
(
requestConfig
).
build
();
}
else
{
httpClient
=
HttpClients
.
createDefault
();
}
try
{
HttpGet
httpGet
=
new
HttpGet
(
apiUrl
);
HttpResponse
response
=
httpClient
.
execute
(
httpGet
);
HttpEntity
entity
=
response
.
getEntity
();
if
(
entity
!=
null
)
{
InputStream
instream
=
entity
.
getContent
();
result
=
IOUtils
.
toString
(
instream
,
"UTF-8"
);
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
result
;
}
/**
* 发送 POST 请求(HTTP),不带输入数据
*
* @param apiUrl
* @return
*/
public
static
String
doPost
(
String
apiUrl
)
{
return
doPost
(
apiUrl
,
new
HashMap
<
String
,
Object
>());
}
/**
* 发送 POST 请求,K-V形式
*
* @param apiUrl
* API接口URL
* @param params
* 参数map
* @return
*/
public
static
String
doPost
(
String
apiUrl
,
Map
<
String
,
Object
>
params
)
{
CloseableHttpClient
httpClient
=
null
;
if
(
apiUrl
.
startsWith
(
"https"
))
{
httpClient
=
HttpClients
.
custom
().
setSSLSocketFactory
(
createSSLConnSocketFactory
())
.
setConnectionManager
(
connMgr
).
setDefaultRequestConfig
(
requestConfig
).
build
();
}
else
{
httpClient
=
HttpClients
.
createDefault
();
}
String
httpStr
=
null
;
HttpPost
httpPost
=
new
HttpPost
(
apiUrl
);
CloseableHttpResponse
response
=
null
;
try
{
httpPost
.
setConfig
(
requestConfig
);
List
<
NameValuePair
>
pairList
=
new
ArrayList
<>(
params
.
size
());
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
params
.
entrySet
())
{
NameValuePair
pair
=
new
BasicNameValuePair
(
entry
.
getKey
(),
entry
.
getValue
()!=
null
?
entry
.
getValue
().
toString
():
""
);
pairList
.
add
(
pair
);
}
httpPost
.
setEntity
(
new
UrlEncodedFormEntity
(
pairList
,
Charset
.
forName
(
"UTF-8"
)));
response
=
httpClient
.
execute
(
httpPost
);
HttpEntity
entity
=
response
.
getEntity
();
httpStr
=
EntityUtils
.
toString
(
entity
,
"UTF-8"
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
response
!=
null
)
{
try
{
EntityUtils
.
consume
(
response
.
getEntity
());
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
return
httpStr
;
}
/**
* 发送 POST 请求,JSON形式,接收端需要支持json形式,否则取不到数据
*
* @param apiUrl
* @param json
* json对象
* @return
*/
public
static
String
doPost
(
String
apiUrl
,
String
json
)
{
CloseableHttpClient
httpClient
=
null
;
if
(
apiUrl
.
startsWith
(
"https"
))
{
httpClient
=
HttpClients
.
custom
().
setSSLSocketFactory
(
createSSLConnSocketFactory
()).
setConnectionManager
(
connMgr
).
setDefaultRequestConfig
(
requestConfig
).
build
();
}
else
{
httpClient
=
HttpClients
.
createDefault
();
}
String
httpStr
=
null
;
HttpPost
httpPost
=
new
HttpPost
(
apiUrl
);
CloseableHttpResponse
response
=
null
;
try
{
httpPost
.
setConfig
(
requestConfig
);
StringEntity
stringEntity
=
new
StringEntity
(
json
,
"UTF-8"
);
// 解决中文乱码问题
stringEntity
.
setContentEncoding
(
"UTF-8"
);
stringEntity
.
setContentType
(
"application/json"
);
httpPost
.
setEntity
(
stringEntity
);
response
=
httpClient
.
execute
(
httpPost
);
HttpEntity
entity
=
response
.
getEntity
();
httpStr
=
EntityUtils
.
toString
(
entity
,
"UTF-8"
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
response
!=
null
)
{
try
{
EntityUtils
.
consume
(
response
.
getEntity
());
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
return
httpStr
;
}
/**
* 创建SSL安全连接
*
* @return
*/
private
static
SSLConnectionSocketFactory
createSSLConnSocketFactory
()
{
SSLConnectionSocketFactory
sslsf
=
null
;
try
{
SSLContext
sslContext
=
new
SSLContextBuilder
().
loadTrustMaterial
(
null
,
new
TrustStrategy
()
{
public
boolean
isTrusted
(
X509Certificate
[]
chain
,
String
authType
)
throws
CertificateException
{
return
true
;
}
}).
build
();
sslsf
=
new
SSLConnectionSocketFactory
(
sslContext
,
new
HostnameVerifier
()
{
@Override
public
boolean
verify
(
String
arg0
,
SSLSession
arg1
)
{
return
true
;
}
});
}
catch
(
GeneralSecurityException
e
)
{
e
.
printStackTrace
();
}
return
sslsf
;
}
}
amos-boot-data/amos-boot-data-accessapi/src/main/java/com/yeejoin/amos/api/householdapi/controller/HouseholdPvApiTestController.java
View file @
95bdca29
package
com
.
yeejoin
.
amos
.
api
.
householdapi
.
controller
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.yeejoin.amos.api.householdapi.Utils.HttpUtils
;
import
com.yeejoin.amos.api.householdapi.face.model.HouseholdPvApiDto
;
import
com.yeejoin.amos.api.householdapi.Utils.HouseholdPvUtils
;
import
com.yeejoin.amos.api.householdapi.face.service.impl.HouseholdPvApiServiceImpl
;
import
com.yeejoin.amos.api.householdapi.face.service.impl.HouseholdPvProducerInfoServiceImpl
;
import
com.yeejoin.amos.openapi.enums.PVProducerInfoEnum
;
import
fastjson.JSON
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
cn.hutool.http.HttpUtil
;
import
org.apache.ibatis.jdbc.Null
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
org.typroject.tyboot.core.foundation.enumeration.UserType
;
import
org.typroject.tyboot.core.restful.doc.TycloudOperation
;
import
org.typroject.tyboot.core.restful.utils.ResponseHelper
;
import
org.typroject.tyboot.core.restful.utils.ResponseModel
;
import
rx.Producer
;
import
java
x.servlet.http.HttpServletRequest
;
import
java
.io.IOException
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* 户用光伏-厂商API haders
...
...
@@ -27,7 +27,7 @@ import java.util.List;
* @date 2023-06-07
*/
@RestController
@Api
(
tags
=
"
测试
"
)
@Api
(
tags
=
"
户用光伏三方厂商示例
"
)
@RequestMapping
(
value
=
"/household-pv-api-test"
)
public
class
HouseholdPvApiTestController
{
@Autowired
...
...
@@ -39,16 +39,33 @@ public class HouseholdPvApiTestController {
*
* @return
*/
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
)
@PostMapping
(
value
=
"/Test"
)
@ApiOperation
(
httpMethod
=
"get"
,
value
=
"新增户用光伏-厂商API haders"
,
notes
=
"新增户用光伏-厂商API haders"
)
public
ResponseModel
<
Null
>
save
(
@RequestParam
Long
seq
)
{
HouseholdPvApiDto
householdPvApiDto
=
householdPvApiServiceImpl
.
queryBySeq
(
seq
);
String
result
=
HttpUtils
.
doPost
(
householdPvApiDto
.
getApiUrl
(),
"1"
);
System
.
out
.
println
(
result
);
return
null
;
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
,
needAuth
=
false
)
@PostMapping
(
value
=
"/gdwdemo"
)
@ApiOperation
(
httpMethod
=
"get"
,
value
=
"固德威示例"
,
notes
=
"固德威示例"
)
public
String
save
()
throws
IOException
{
Map
<
String
,
String
>
stringObjectHashMap
=
HouseholdPvUtils
.
getHeaderByProducerCode
(
PVProducerInfoEnum
.
GDW
);
Map
<
String
,
Object
>
body
=
new
HashMap
<>();
body
.
put
(
"page_index"
,
1
);
body
.
put
(
"page_size"
,
20
);
String
stringbody
=
JSON
.
toJSONString
(
body
);
String
respone
=
HttpUtil
.
createPost
(
"http://openapi.sems.com.cn/api/OpenApi/GetUserPowerStation"
).
headerMap
(
stringObjectHashMap
,
true
).
body
(
stringbody
).
execute
().
body
();
return
respone
;
}
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
,
needAuth
=
false
)
@PostMapping
(
value
=
"/shdemo"
)
@ApiOperation
(
httpMethod
=
"get"
,
value
=
"首航示例"
,
notes
=
"首航示例"
)
public
String
save2
(
)
throws
IOException
{
Map
<
String
,
String
>
stringObjectHashMap
=
HouseholdPvUtils
.
getHeaderByProducerCode
(
PVProducerInfoEnum
.
SH
);
Map
<
String
,
Object
>
body
=
new
HashMap
<>();
body
.
put
(
"page"
,
1
);
body
.
put
(
"size"
,
10
);
String
stringbody
=
JSON
.
toJSONString
(
body
);
String
respone
=
HttpUtil
.
createPost
(
"https://openapi.sofarsolarmonitor.com/station/v1.0/list"
).
headerMap
(
stringObjectHashMap
,
true
).
body
(
stringbody
).
execute
().
body
();
return
respone
;
}
}
amos-boot-data/amos-boot-data-accessapi/src/main/java/com/yeejoin/amos/api/householdapi/face/model/HouseholdPvProducerInfoDto.java
View file @
95bdca29
...
...
@@ -16,10 +16,10 @@ import java.util.Date;
*/
@Data
@EqualsAndHashCode
(
callSuper
=
true
)
@ApiModel
(
value
=
"HouseholdPvProducerInfoDto"
,
description
=
"户用光伏-厂商信息表"
)
public
class
HouseholdPvProducerInfoDto
extends
BaseModel
{
@ApiModel
(
value
=
"HouseholdPvProducerInfoDto"
,
description
=
"户用光伏-厂商信息表"
)
public
class
HouseholdPvProducerInfoDto
extends
BaseModel
{
private
static
final
long
serialVersionUID
=
1L
;
private
static
final
long
serialVersionUID
=
1L
;
@ApiModelProperty
(
value
=
"厂商名称"
)
...
...
@@ -46,4 +46,6 @@ public class HouseholdPvProducerInfoDto extends BaseModel {
@ApiModelProperty
(
value
=
"公共header信息"
)
private
String
headerInfo
;
@ApiModelProperty
(
value
=
"厂商code"
)
private
String
code
;
}
amos-boot-data/amos-boot-data-accessapi/src/main/java/com/yeejoin/amos/api/householdapi/face/orm/entity/HouseholdPvProducerInfo.java
View file @
95bdca29
...
...
@@ -71,4 +71,9 @@ public class HouseholdPvProducerInfo extends BaseEntity {
@TableField
(
"header_info"
)
private
String
headerInfo
;
/**
* 公共header信息
*/
@TableField
(
"code"
)
private
String
code
;
}
amos-boot-data/amos-boot-data-accessapi/src/main/java/com/yeejoin/amos/openapi/enums/PVProducerInfoEnum.java
0 → 100644
View file @
95bdca29
package
com
.
yeejoin
.
amos
.
openapi
.
enums
;
public
enum
PVProducerInfoEnum
{
GDW
(
"固德威"
,
"GDW"
),
SH
(
"首航"
,
"SH"
),
JLY
(
"锦浪云"
,
"JLY"
);
private
String
name
;
private
String
code
;
public
String
getName
()
{
return
name
;
}
PVProducerInfoEnum
(
String
name
,
String
code
)
{
this
.
name
=
name
;
this
.
code
=
code
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getCode
()
{
return
code
;
}
public
void
setCode
(
String
code
)
{
this
.
code
=
code
;
}
}
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