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
860a7d9e
Commit
860a7d9e
authored
Sep 25, 2023
by
caotao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
户用光伏新增科士达信息
parent
798be0cc
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
735 additions
and
18 deletions
+735
-18
AESUtils.java
...ava/com/yeejoin/amos/api/householdapi/Utils/AESUtils.java
+94
-0
GolangRequestUtil.java
...eejoin/amos/api/householdapi/Utils/GolangRequestUtil.java
+0
-10
GoodWeRequestUtil.java
...eejoin/amos/api/householdapi/Utils/GoodWeRequestUtil.java
+163
-0
KSolarRequestUtil.java
...eejoin/amos/api/householdapi/Utils/KSolarRequestUtil.java
+165
-0
SofarRequestUtil.java
...yeejoin/amos/api/householdapi/Utils/SofarRequestUtil.java
+155
-0
GoLangConstant.java
...eejoin/amos/api/householdapi/constant/GoLangConstant.java
+3
-0
GoodWeConstant.java
...eejoin/amos/api/householdapi/constant/GoodWeConstant.java
+8
-0
KSolarConstant.java
...eejoin/amos/api/householdapi/constant/KSolarConstant.java
+11
-0
SoFarConstant.java
...yeejoin/amos/api/householdapi/constant/SoFarConstant.java
+8
-0
HouseholdTestController.java
.../api/householdapi/controller/HouseholdTestController.java
+60
-4
GoodWeDataAcquisitionService.java
...useholdapi/face/service/GoodWeDataAcquisitionService.java
+32
-0
SofarDataAcquisitionService.java
...ouseholdapi/face/service/SofarDataAcquisitionService.java
+32
-0
GoLangDataAcquisitionServiceImpl.java
...i/face/service/impl/GoLangDataAcquisitionServiceImpl.java
+1
-3
PVProducerInfoEnum.java
...va/com/yeejoin/amos/openapi/enums/PVProducerInfoEnum.java
+3
-1
No files found.
amos-boot-data/amos-boot-data-housepvapi/src/main/java/com/yeejoin/amos/api/householdapi/Utils/AESUtils.java
0 → 100644
View file @
860a7d9e
package
com
.
yeejoin
.
amos
.
api
.
householdapi
.
Utils
;
import
org.apache.commons.codec.binary.Base64
;
import
org.springframework.stereotype.Component
;
import
javax.crypto.Cipher
;
import
javax.crypto.spec.SecretKeySpec
;
@Component
/**
* Created by jhb on 2022-08-03 14:16
*/
public
class
AESUtils
{
public
static
final
String
DEFAULT_SECRET_KEY
=
"kstar_ase_keysfo"
;
/**
* 加密
* @param sSrc 需要加密的字符串
* @param sKey 此处使用AES-128-ECB加密模式,key需要为16位。
* @return
* @throws Exception
*/
public
static
String
Encrypt
(
String
sSrc
,
String
sKey
)
throws
Exception
{
// 判断Key是否为16位
if
(
sKey
.
length
()
!=
16
)
{
System
.
out
.
print
(
"Key长度不是16位"
);
return
null
;
}
byte
[]
raw
=
sKey
.
getBytes
(
"utf-8"
);
SecretKeySpec
skeySpec
=
new
SecretKeySpec
(
raw
,
"AES"
);
Cipher
cipher
=
Cipher
.
getInstance
(
"AES/ECB/PKCS5Padding"
);
//"算法/模式/补码方式"
cipher
.
init
(
Cipher
.
ENCRYPT_MODE
,
skeySpec
);
byte
[]
encrypted
=
cipher
.
doFinal
(
sSrc
.
getBytes
(
"utf-8"
));
return
new
Base64
().
encodeToString
(
encrypted
);
//此处使用BASE64做转码功能,同时能起到2次加密的作用。
}
/**
* 解密
* @param sSrc 需要解密的字符串
* @param sKey 此处使用AES-128-ECB加密模式,key需要为16位。
* @return
* @throws Exception
*/
public
static
String
Decrypt
(
String
sSrc
,
String
sKey
)
throws
Exception
{
try
{
// 判断Key是否正确
if
(
sKey
==
null
)
{
System
.
out
.
print
(
"Key为空null"
);
return
null
;
}
// 判断Key是否为16位
if
(
sKey
.
length
()
!=
16
)
{
System
.
out
.
print
(
"Key长度不是16位"
);
return
null
;
}
byte
[]
raw
=
sKey
.
getBytes
(
"utf-8"
);
SecretKeySpec
skeySpec
=
new
SecretKeySpec
(
raw
,
"AES"
);
Cipher
cipher
=
Cipher
.
getInstance
(
"AES/ECB/PKCS5Padding"
);
cipher
.
init
(
Cipher
.
DECRYPT_MODE
,
skeySpec
);
byte
[]
encrypted1
=
new
Base64
().
decode
(
sSrc
);
//先用base64解密
try
{
byte
[]
original
=
cipher
.
doFinal
(
encrypted1
);
String
originalString
=
new
String
(
original
,
"utf-8"
);
return
originalString
;
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
.
toString
());
return
null
;
}
}
catch
(
Exception
ex
)
{
System
.
out
.
println
(
ex
.
toString
());
return
null
;
}
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
/*
* 此处使用AES-128-ECB加密模式,key需要为16位。
*/
String
cKey
=
"kstar_ase_keysfo"
;
// 需要加密的字串
String
cSrc
=
"sygn2022"
;
System
.
out
.
println
(
cSrc
);
// 加密
String
enString
=
AESUtils
.
Encrypt
(
cSrc
,
cKey
);
System
.
out
.
println
(
"加密后的字串是:"
+
enString
);
// 解密
String
DeString
=
AESUtils
.
Decrypt
(
enString
,
cKey
);
System
.
out
.
println
(
"解密后的字串是:"
+
DeString
);
}
}
amos-boot-data/amos-boot-data-housepvapi/src/main/java/com/yeejoin/amos/api/householdapi/Utils/GolangRequestUtil.java
View file @
860a7d9e
...
...
@@ -5,13 +5,8 @@ import cn.hutool.http.HttpUtil;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.yeejoin.amos.api.householdapi.constant.GoLangConstant
;
import
com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.tdeingine.GolangStationList
;
import
com.yeejoin.amos.api.householdapi.face.orm.mapper.tdengine.GolangStationMapper
;
import
com.yeejoin.amos.api.householdapi.face.service.impl.HouseholdPvProducerInfoServiceImpl
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.ObjectUtils
;
import
org.typroject.tyboot.component.cache.Redis
;
import
java.util.*
;
...
...
@@ -19,11 +14,6 @@ import java.util.*;
public
class
GolangRequestUtil
{
@Autowired
private
HouseholdPvProducerInfoServiceImpl
householdPvProducerInfoServiceImpl
;
@Autowired
private
GolangStationMapper
golangStationMapper
;
/**
* @return HashMap<String, Object> 发送请求前的准备 准备header信息
...
...
amos-boot-data/amos-boot-data-housepvapi/src/main/java/com/yeejoin/amos/api/householdapi/Utils/GoodWeRequestUtil.java
0 → 100644
View file @
860a7d9e
package
com
.
yeejoin
.
amos
.
api
.
householdapi
.
Utils
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.http.HttpUtil
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.yeejoin.amos.api.householdapi.constant.GoLangConstant
;
import
com.yeejoin.amos.api.householdapi.face.orm.mapper.tdengine.GolangStationMapper
;
import
com.yeejoin.amos.api.householdapi.face.service.impl.HouseholdPvProducerInfoServiceImpl
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.ObjectUtils
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
@Component
public
class
GoodWeRequestUtil
{
@Autowired
private
HouseholdPvProducerInfoServiceImpl
householdPvProducerInfoServiceImpl
;
@Autowired
private
GolangStationMapper
golangStationMapper
;
/**
* @return HashMap<String, Object> 发送请求前的准备 准备header信息
* @deprecated 根据厂商编码获取厂商的hearer
*/
public
HashMap
<
String
,
Object
>
getHeaderOfGolang
()
{
HashMap
<
String
,
Object
>
hashMap
=
new
HashMap
<>();
HashMap
<
String
,
String
>
hashMaphead
=
new
HashMap
<>();
String
url
=
GoLangConstant
.
baseurl
+
GoLangConstant
.
tokenurl
;
hashMap
.
put
(
"apiurl"
,
GoLangConstant
.
baseurl
);
hashMaphead
.
put
(
"Content-type"
,
"application/json;charset=UTF-8"
);
hashMaphead
.
put
(
"Authorization"
,
"API "
+
GoLangConstant
.
prodcerappid
);
hashMaphead
.
put
(
"Content-MD5"
,
null
);
hashMaphead
.
put
(
"Date"
,
GoLangHeaderUtils
.
getGMTTime
());
hashMap
.
put
(
"header"
,
hashMaphead
);
hashMap
.
put
(
"appsecret"
,
GoLangConstant
.
prodcerappsecret
);
return
hashMap
;
}
/**
* @param apiurl 请求url
* @param requestMethod 请求方式
* @param requestParmInfo 请求参数mapper
* @param ResultResolveRule 请求的解析
* @param tClass 需要转换成的bean
* @param <T> 泛型数据
* @return List<T> list<Result>
* @desc 根据请求参数发送http请求并且对于返回的数据进行处理
*/
public
<
T
>
List
<
T
>
getResPonse
(
String
apiurl
,
String
requestMethod
,
String
requestParmInfo
,
String
ResultResolveRule
,
Class
<
T
>
tClass
)
{
String
respone
=
""
;
String
params
=
""
;
JSONArray
jsonArray
=
null
;
List
<
T
>
result
=
new
ArrayList
<>();
try
{
HashMap
<
String
,
Object
>
producerInfo
=
getHeaderOfGolang
();
String
baseurl
=
(
String
)
producerInfo
.
get
(
"apiurl"
);
HashMap
<
String
,
String
>
headMap
=
(
HashMap
<
String
,
String
>)
producerInfo
.
get
(
"header"
);
String
orginalAuthorization
=
headMap
.
get
(
"Authorization"
)
+
":"
;
String
url
=
baseurl
+
apiurl
;
String
appsecret
=
(
String
)
producerInfo
.
get
(
"appsecret"
);
JLYHeaderMapHandler
(
params
,
headMap
,
orginalAuthorization
,
appsecret
,
apiurl
);
respone
=
sendRequest
(
requestMethod
,
url
,
requestParmInfo
,
headMap
);
jsonArray
=
handlerResponseByResultResolverule
(
ResultResolveRule
,
respone
);
if
(!
ObjectUtils
.
isEmpty
(
jsonArray
))
{
result
=
JSONArray
.
parseArray
(
jsonArray
.
toJSONString
(),
tClass
);
}
}
catch
(
Exception
exception
)
{
return
result
;
}
return
result
;
}
/**
* @param resultResovle 请求返回的解析规则 来源与数据库
* @param response 请求返回的字符串
* @return 解析后的数据
* @desc 根据解析规则解析请求返回数据
*/
public
JSONArray
handlerResponseByResultResolverule
(
String
resultResovle
,
String
response
)
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
response
);
JSONArray
jsonArray
=
new
JSONArray
();
if
(
ObjectUtil
.
isNotEmpty
(
resultResovle
))
{
String
[]
rules
=
resultResovle
.
split
(
","
);
if
(
rules
.
length
>
0
)
{
for
(
int
i
=
0
;
i
<
rules
.
length
;
i
++)
{
try
{
jsonObject
=
(
JSONObject
)
jsonObject
.
get
(
rules
[
i
]);
if
(
jsonObject
==
null
)
{
jsonArray
=
(
JSONArray
)
jsonObject
.
get
(
rules
[
i
]);
}
}
catch
(
Exception
exception
)
{
jsonArray
=
(
JSONArray
)
jsonObject
.
get
(
rules
[
i
]);
}
}
}
if
(
jsonArray
.
size
()
==
0
)
{
jsonArray
.
add
(
jsonObject
);
}
}
return
jsonArray
;
}
public
String
sendRequest
(
String
requestMethod
,
String
url
,
String
params
,
HashMap
<
String
,
String
>
headMap
)
{
String
respone
=
""
;
if
(
requestMethod
.
equals
(
"POST"
))
{
respone
=
HttpUtil
.
createPost
(
url
).
headerMap
(
headMap
,
false
).
body
(
params
).
execute
().
body
();
}
if
(
requestMethod
.
equals
(
"GET"
))
{
respone
=
HttpUtil
.
createGet
(
url
).
headerMap
(
headMap
,
true
).
body
(
params
).
execute
().
body
();
}
return
respone
;
}
/***
*
* @param params 参数字符窜
* @param headMap header头
* @param orginalAuthorization 原始的orginalAuthorization
* @param appsecret appsecret
* @desc 锦浪云请求参数及head头处理
*/
public
void
JLYHeaderMapHandler
(
String
params
,
HashMap
<
String
,
String
>
headMap
,
String
orginalAuthorization
,
String
appsecret
,
String
apiurl
)
{
String
contentMD5
=
GoLangHeaderUtils
.
getDigest
(
params
);
headMap
.
put
(
"Date"
,
GoLangHeaderUtils
.
getGMTTime
());
String
param
=
"POST"
+
"\n"
+
contentMD5
+
"\n"
+
"application/json"
+
"\n"
+
headMap
.
get
(
"Date"
)
+
"\n"
+
apiurl
;
String
sign
=
""
;
try
{
sign
=
GoLangHeaderUtils
.
HmacSHA1Encrypt
(
param
,
appsecret
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
headMap
.
put
(
"Content-MD5"
,
contentMD5
);
headMap
.
put
(
"Authorization"
,
orginalAuthorization
+
sign
);
}
/**
* @param pageSizeResovle
* @param response
* @return
* @desc 根据分页规则 获取分页数
*/
public
Integer
getPagesize
(
String
pageSizeResovle
,
String
response
)
{
Integer
pageSize
=
0
;
String
[]
rules
=
pageSizeResovle
.
split
(
","
);
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
response
);
if
(
rules
.
length
>
0
)
{
for
(
int
i
=
0
;
i
<
rules
.
length
-
1
;
i
++)
{
jsonObject
=
(
JSONObject
)
jsonObject
.
get
(
rules
[
i
]);
}
}
pageSize
=
(
Integer
)
jsonObject
.
get
(
rules
[
rules
.
length
-
1
]);
return
pageSize
;
}
}
amos-boot-data/amos-boot-data-housepvapi/src/main/java/com/yeejoin/amos/api/householdapi/Utils/KSolarRequestUtil.java
0 → 100644
View file @
860a7d9e
package
com
.
yeejoin
.
amos
.
api
.
householdapi
.
Utils
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.http.HttpUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.yeejoin.amos.api.householdapi.constant.GoLangConstant
;
import
com.yeejoin.amos.api.householdapi.constant.KSolarConstant
;
import
org.bouncycastle.jcajce.provider.symmetric.AES
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.ObjectUtils
;
import
java.nio.charset.StandardCharsets
;
import
java.util.ArrayList
;
import
java.util.Base64
;
import
java.util.HashMap
;
import
java.util.List
;
@Component
public
class
KSolarRequestUtil
{
@Autowired
private
AESUtils
aesUtils
;
/**
* @return HashMap<String, Object> 发送请求前的准备 准备header信息
* @deprecated 根据厂商编码获取厂商的hearer
*/
public
HashMap
<
String
,
Object
>
getHeader
()
{
HashMap
<
String
,
Object
>
hashMap
=
new
HashMap
<>();
HashMap
<
String
,
Object
>
requsetParams
=
new
HashMap
<>();
HashMap
<
String
,
String
>
hashMaphead
=
new
HashMap
<>();
requsetParams
.
put
(
"username"
,
KSolarConstant
.
account
);
try
{
requsetParams
.
put
(
"password"
,
AESUtils
.
Encrypt
(
KSolarConstant
.
password
,
AESUtils
.
DEFAULT_SECRET_KEY
));
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
String
url
=
KSolarConstant
.
baseurl
+
KSolarConstant
.
tokenUrl
;
hashMaphead
.
put
(
"Authorization"
,
"Basic "
+
Base64
.
getUrlEncoder
().
encodeToString
((
KSolarConstant
.
authUsername
+
":"
+
KSolarConstant
.
authPassword
).
getBytes
(
StandardCharsets
.
UTF_8
)));
String
ResPonse
=
HttpUtil
.
createPost
(
url
).
headerMap
(
hashMaphead
,
false
).
body
(
JSONObject
.
toJSONString
(
requsetParams
)).
execute
().
body
();
return
hashMap
;
}
/**
* @param apiurl 请求url
* @param requestMethod 请求方式
* @param requestParmInfo 请求参数mapper
* @param ResultResolveRule 请求的解析
* @param tClass 需要转换成的bean
* @param <T> 泛型数据
* @return List<T> list<Result>
* @desc 根据请求参数发送http请求并且对于返回的数据进行处理
*/
public
<
T
>
List
<
T
>
getResPonse
(
String
apiurl
,
String
requestMethod
,
String
requestParmInfo
,
String
ResultResolveRule
,
Class
<
T
>
tClass
)
{
String
respone
=
""
;
String
params
=
""
;
JSONArray
jsonArray
=
null
;
List
<
T
>
result
=
new
ArrayList
<>();
try
{
HashMap
<
String
,
Object
>
producerInfo
=
getHeader
();
String
baseurl
=
(
String
)
producerInfo
.
get
(
"apiurl"
);
HashMap
<
String
,
String
>
headMap
=
(
HashMap
<
String
,
String
>)
producerInfo
.
get
(
"header"
);
String
orginalAuthorization
=
headMap
.
get
(
"Authorization"
)
+
":"
;
String
url
=
baseurl
+
apiurl
;
String
appsecret
=
(
String
)
producerInfo
.
get
(
"appsecret"
);
JLYHeaderMapHandler
(
params
,
headMap
,
orginalAuthorization
,
appsecret
,
apiurl
);
respone
=
sendRequest
(
requestMethod
,
url
,
requestParmInfo
,
headMap
);
jsonArray
=
handlerResponseByResultResolverule
(
ResultResolveRule
,
respone
);
if
(!
ObjectUtils
.
isEmpty
(
jsonArray
))
{
result
=
JSONArray
.
parseArray
(
jsonArray
.
toJSONString
(),
tClass
);
}
}
catch
(
Exception
exception
)
{
return
result
;
}
return
result
;
}
/**
* @param resultResovle 请求返回的解析规则 来源与数据库
* @param response 请求返回的字符串
* @return 解析后的数据
* @desc 根据解析规则解析请求返回数据
*/
public
JSONArray
handlerResponseByResultResolverule
(
String
resultResovle
,
String
response
)
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
response
);
JSONArray
jsonArray
=
new
JSONArray
();
if
(
ObjectUtil
.
isNotEmpty
(
resultResovle
))
{
String
[]
rules
=
resultResovle
.
split
(
","
);
if
(
rules
.
length
>
0
)
{
for
(
int
i
=
0
;
i
<
rules
.
length
;
i
++)
{
try
{
jsonObject
=
(
JSONObject
)
jsonObject
.
get
(
rules
[
i
]);
if
(
jsonObject
==
null
)
{
jsonArray
=
(
JSONArray
)
jsonObject
.
get
(
rules
[
i
]);
}
}
catch
(
Exception
exception
)
{
jsonArray
=
(
JSONArray
)
jsonObject
.
get
(
rules
[
i
]);
}
}
}
if
(
jsonArray
.
size
()
==
0
)
{
jsonArray
.
add
(
jsonObject
);
}
}
return
jsonArray
;
}
public
String
sendRequest
(
String
requestMethod
,
String
url
,
String
params
,
HashMap
<
String
,
String
>
headMap
)
{
String
respone
=
""
;
if
(
requestMethod
.
equals
(
"POST"
))
{
respone
=
HttpUtil
.
createPost
(
url
).
headerMap
(
headMap
,
false
).
body
(
params
).
execute
().
body
();
}
if
(
requestMethod
.
equals
(
"GET"
))
{
respone
=
HttpUtil
.
createGet
(
url
).
headerMap
(
headMap
,
true
).
body
(
params
).
execute
().
body
();
}
return
respone
;
}
/***
*
* @param params 参数字符窜
* @param headMap header头
* @param orginalAuthorization 原始的orginalAuthorization
* @param appsecret appsecret
* @desc 锦浪云请求参数及head头处理
*/
public
void
JLYHeaderMapHandler
(
String
params
,
HashMap
<
String
,
String
>
headMap
,
String
orginalAuthorization
,
String
appsecret
,
String
apiurl
)
{
String
contentMD5
=
GoLangHeaderUtils
.
getDigest
(
params
);
headMap
.
put
(
"Date"
,
GoLangHeaderUtils
.
getGMTTime
());
String
param
=
"POST"
+
"\n"
+
contentMD5
+
"\n"
+
"application/json"
+
"\n"
+
headMap
.
get
(
"Date"
)
+
"\n"
+
apiurl
;
String
sign
=
""
;
try
{
sign
=
GoLangHeaderUtils
.
HmacSHA1Encrypt
(
param
,
appsecret
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
headMap
.
put
(
"Content-MD5"
,
contentMD5
);
headMap
.
put
(
"Authorization"
,
orginalAuthorization
+
sign
);
}
/**
* @param pageSizeResovle
* @param response
* @return
* @desc 根据分页规则 获取分页数
*/
public
Integer
getPagesize
(
String
pageSizeResovle
,
String
response
)
{
Integer
pageSize
=
0
;
String
[]
rules
=
pageSizeResovle
.
split
(
","
);
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
response
);
if
(
rules
.
length
>
0
)
{
for
(
int
i
=
0
;
i
<
rules
.
length
-
1
;
i
++)
{
jsonObject
=
(
JSONObject
)
jsonObject
.
get
(
rules
[
i
]);
}
}
pageSize
=
(
Integer
)
jsonObject
.
get
(
rules
[
rules
.
length
-
1
]);
return
pageSize
;
}
}
amos-boot-data/amos-boot-data-housepvapi/src/main/java/com/yeejoin/amos/api/householdapi/Utils/SofarRequestUtil.java
0 → 100644
View file @
860a7d9e
package
com
.
yeejoin
.
amos
.
api
.
householdapi
.
Utils
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.http.HttpUtil
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.yeejoin.amos.api.householdapi.constant.GoLangConstant
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.ObjectUtils
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
@Component
public
class
SofarRequestUtil
{
/**
* @return HashMap<String, Object> 发送请求前的准备 准备header信息
* @deprecated 根据厂商编码获取厂商的hearer
*/
public
HashMap
<
String
,
Object
>
getHeaderOfGolang
()
{
HashMap
<
String
,
Object
>
hashMap
=
new
HashMap
<>();
HashMap
<
String
,
String
>
hashMaphead
=
new
HashMap
<>();
String
url
=
GoLangConstant
.
baseurl
+
GoLangConstant
.
tokenurl
;
hashMap
.
put
(
"apiurl"
,
GoLangConstant
.
baseurl
);
hashMaphead
.
put
(
"Content-type"
,
"application/json;charset=UTF-8"
);
hashMaphead
.
put
(
"Authorization"
,
"API "
+
GoLangConstant
.
prodcerappid
);
hashMaphead
.
put
(
"Content-MD5"
,
null
);
hashMaphead
.
put
(
"Date"
,
GoLangHeaderUtils
.
getGMTTime
());
hashMap
.
put
(
"header"
,
hashMaphead
);
hashMap
.
put
(
"appsecret"
,
GoLangConstant
.
prodcerappsecret
);
return
hashMap
;
}
/**
* @param apiurl 请求url
* @param requestMethod 请求方式
* @param requestParmInfo 请求参数mapper
* @param ResultResolveRule 请求的解析
* @param tClass 需要转换成的bean
* @param <T> 泛型数据
* @return List<T> list<Result>
* @desc 根据请求参数发送http请求并且对于返回的数据进行处理
*/
public
<
T
>
List
<
T
>
getResPonse
(
String
apiurl
,
String
requestMethod
,
String
requestParmInfo
,
String
ResultResolveRule
,
Class
<
T
>
tClass
)
{
String
respone
=
""
;
String
params
=
""
;
JSONArray
jsonArray
=
null
;
List
<
T
>
result
=
new
ArrayList
<>();
try
{
HashMap
<
String
,
Object
>
producerInfo
=
getHeaderOfGolang
();
String
baseurl
=
(
String
)
producerInfo
.
get
(
"apiurl"
);
HashMap
<
String
,
String
>
headMap
=
(
HashMap
<
String
,
String
>)
producerInfo
.
get
(
"header"
);
String
orginalAuthorization
=
headMap
.
get
(
"Authorization"
)
+
":"
;
String
url
=
baseurl
+
apiurl
;
String
appsecret
=
(
String
)
producerInfo
.
get
(
"appsecret"
);
JLYHeaderMapHandler
(
params
,
headMap
,
orginalAuthorization
,
appsecret
,
apiurl
);
respone
=
sendRequest
(
requestMethod
,
url
,
requestParmInfo
,
headMap
);
jsonArray
=
handlerResponseByResultResolverule
(
ResultResolveRule
,
respone
);
if
(!
ObjectUtils
.
isEmpty
(
jsonArray
))
{
result
=
JSONArray
.
parseArray
(
jsonArray
.
toJSONString
(),
tClass
);
}
}
catch
(
Exception
exception
)
{
return
result
;
}
return
result
;
}
/**
* @param resultResovle 请求返回的解析规则 来源与数据库
* @param response 请求返回的字符串
* @return 解析后的数据
* @desc 根据解析规则解析请求返回数据
*/
public
JSONArray
handlerResponseByResultResolverule
(
String
resultResovle
,
String
response
)
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
response
);
JSONArray
jsonArray
=
new
JSONArray
();
if
(
ObjectUtil
.
isNotEmpty
(
resultResovle
))
{
String
[]
rules
=
resultResovle
.
split
(
","
);
if
(
rules
.
length
>
0
)
{
for
(
int
i
=
0
;
i
<
rules
.
length
;
i
++)
{
try
{
jsonObject
=
(
JSONObject
)
jsonObject
.
get
(
rules
[
i
]);
if
(
jsonObject
==
null
)
{
jsonArray
=
(
JSONArray
)
jsonObject
.
get
(
rules
[
i
]);
}
}
catch
(
Exception
exception
)
{
jsonArray
=
(
JSONArray
)
jsonObject
.
get
(
rules
[
i
]);
}
}
}
if
(
jsonArray
.
size
()
==
0
)
{
jsonArray
.
add
(
jsonObject
);
}
}
return
jsonArray
;
}
public
String
sendRequest
(
String
requestMethod
,
String
url
,
String
params
,
HashMap
<
String
,
String
>
headMap
)
{
String
respone
=
""
;
if
(
requestMethod
.
equals
(
"POST"
))
{
respone
=
HttpUtil
.
createPost
(
url
).
headerMap
(
headMap
,
false
).
body
(
params
).
execute
().
body
();
}
if
(
requestMethod
.
equals
(
"GET"
))
{
respone
=
HttpUtil
.
createGet
(
url
).
headerMap
(
headMap
,
true
).
body
(
params
).
execute
().
body
();
}
return
respone
;
}
/***
*
* @param params 参数字符窜
* @param headMap header头
* @param orginalAuthorization 原始的orginalAuthorization
* @param appsecret appsecret
* @desc 锦浪云请求参数及head头处理
*/
public
void
JLYHeaderMapHandler
(
String
params
,
HashMap
<
String
,
String
>
headMap
,
String
orginalAuthorization
,
String
appsecret
,
String
apiurl
)
{
String
contentMD5
=
GoLangHeaderUtils
.
getDigest
(
params
);
headMap
.
put
(
"Date"
,
GoLangHeaderUtils
.
getGMTTime
());
String
param
=
"POST"
+
"\n"
+
contentMD5
+
"\n"
+
"application/json"
+
"\n"
+
headMap
.
get
(
"Date"
)
+
"\n"
+
apiurl
;
String
sign
=
""
;
try
{
sign
=
GoLangHeaderUtils
.
HmacSHA1Encrypt
(
param
,
appsecret
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
headMap
.
put
(
"Content-MD5"
,
contentMD5
);
headMap
.
put
(
"Authorization"
,
orginalAuthorization
+
sign
);
}
/**
* @param pageSizeResovle
* @param response
* @return
* @desc 根据分页规则 获取分页数
*/
public
Integer
getPagesize
(
String
pageSizeResovle
,
String
response
)
{
Integer
pageSize
=
0
;
String
[]
rules
=
pageSizeResovle
.
split
(
","
);
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
response
);
if
(
rules
.
length
>
0
)
{
for
(
int
i
=
0
;
i
<
rules
.
length
-
1
;
i
++)
{
jsonObject
=
(
JSONObject
)
jsonObject
.
get
(
rules
[
i
]);
}
}
pageSize
=
(
Integer
)
jsonObject
.
get
(
rules
[
rules
.
length
-
1
]);
return
pageSize
;
}
}
amos-boot-data/amos-boot-data-housepvapi/src/main/java/com/yeejoin/amos/api/householdapi/constant/GoLangConstant.java
View file @
860a7d9e
...
...
@@ -5,6 +5,9 @@ import org.apache.xmlbeans.impl.xb.xsdschema.Public;
import
java.time.format.DateTimeFormatter
;
import
java.util.HashMap
;
/**
* 锦浪云常量
*/
public
class
GoLangConstant
{
public
static
final
HashMap
<
String
,
String
>
stationStaus
=
new
HashMap
<
String
,
String
>()
{
{
...
...
amos-boot-data/amos-boot-data-housepvapi/src/main/java/com/yeejoin/amos/api/householdapi/constant/GoodWeConstant.java
0 → 100644
View file @
860a7d9e
package
com
.
yeejoin
.
amos
.
api
.
householdapi
.
constant
;
/**
* 固德威常量
*/
public
class
GoodWeConstant
{
}
amos-boot-data/amos-boot-data-housepvapi/src/main/java/com/yeejoin/amos/api/householdapi/constant/KSolarConstant.java
0 → 100644
View file @
860a7d9e
package
com
.
yeejoin
.
amos
.
api
.
householdapi
.
constant
;
public
class
KSolarConstant
{
public
static
String
baseurl
=
"http://111.230.136.62:8092"
;
public
static
String
account
=
"三一硅能"
;
public
static
String
password
=
"sygn2022"
;
public
static
String
tokenUrl
=
"/authentication/form"
;
public
static
String
authUsername
=
"kstar"
;
public
static
String
authPassword
=
"kstarSecret"
;
}
amos-boot-data/amos-boot-data-housepvapi/src/main/java/com/yeejoin/amos/api/householdapi/constant/SoFarConstant.java
0 → 100644
View file @
860a7d9e
package
com
.
yeejoin
.
amos
.
api
.
householdapi
.
constant
;
/**
* 首航常量
*/
public
class
SoFarConstant
{
}
amos-boot-data/amos-boot-data-housepvapi/src/main/java/com/yeejoin/amos/api/householdapi/controller/HouseholdTestController.java
View file @
860a7d9e
package
com
.
yeejoin
.
amos
.
api
.
householdapi
.
controller
;
import
com.yeejoin.amos.api.householdapi.Utils.GolangRequestUtil
;
import
com.yeejoin.amos.api.householdapi.Utils.HouseholdPvUtils
;
import
com.yeejoin.amos.api.householdapi.constant.GoLangConstant
;
import
com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.tdeingine.GolangStationList
;
import
com.yeejoin.amos.api.householdapi.Utils.KSolarRequestUtil
;
import
com.yeejoin.amos.api.householdapi.face.service.GoLangDataAcquisitionService
;
import
fastjson.JSON
;
import
io.swagger.annotations.Api
;
...
...
@@ -32,7 +30,9 @@ public class HouseholdTestController {
@Autowired
private
HouseholdPvUtils
householdPvUtils
;
@Autowired
private
GoLangDataAcquisitionService
goLangDataAcquisitionService
;
private
GoLangDataAcquisitionService
goLangDataAcquisitionService
;
@Autowired
private
KSolarRequestUtil
kSolarRequestUtil
;
/**
...
...
@@ -46,6 +46,7 @@ public class HouseholdTestController {
public
String
save
(
Long
seq
)
throws
IOException
{
return
householdPvUtils
.
gerResponseByAPiID
(
seq
);
}
/**
* 新增户用光伏-厂商API haders
*
...
...
@@ -60,7 +61,62 @@ public class HouseholdTestController {
// goLangDataAcquisitionService.collectorList();
//// goLangDataAcquisitionService.inverterList();
goLangDataAcquisitionService
.
collectorDetail
();
goLangDataAcquisitionService
.
inverterDetail
();
// goLangDataAcquisitionService.inverAlramInfo();
}
/**
* 新增户用光伏-厂商API haders
*
* @return
*/
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
,
needAuth
=
false
)
@PostMapping
(
value
=
"/sofarnew"
)
@ApiOperation
(
httpMethod
=
"POST"
,
value
=
"首航"
,
notes
=
"首航"
)
public
void
sofarnew
()
throws
IOException
{
// goLangDataAcquisitionService.stationList();
// goLangDataAcquisitionService.stationDetail();
// goLangDataAcquisitionService.collectorList();
//// goLangDataAcquisitionService.inverterList();
// goLangDataAcquisitionService.collectorDetail();
// goLangDataAcquisitionService.inverterDetail();
// goLangDataAcquisitionService.inverAlramInfo();
}
/**
* 新增户用光伏-厂商API haders
*
* @return
*/
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
,
needAuth
=
false
)
@PostMapping
(
value
=
"/goodWenew"
)
@ApiOperation
(
httpMethod
=
"POST"
,
value
=
"固德威"
,
notes
=
"固德威"
)
public
void
goodWenew
()
throws
IOException
{
// goLangDataAcquisitionService.stationList();
// goLangDataAcquisitionService.stationDetail();
// goLangDataAcquisitionService.collectorList();
//// goLangDataAcquisitionService.inverterList();
// goLangDataAcquisitionService.collectorDetail();
// goLangDataAcquisitionService.inverterDetail();
// goLangDataAcquisitionService.inverAlramInfo();
}
/**
* 新增户用光伏-厂商API haders
*
* @return
*/
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
,
needAuth
=
false
)
@PostMapping
(
value
=
"/ksolarnew"
)
@ApiOperation
(
httpMethod
=
"POST"
,
value
=
"科士达"
,
notes
=
"科士达"
)
public
void
ksolarnew
()
throws
IOException
{
// goLangDataAcquisitionService.stationList();
// goLangDataAcquisitionService.stationDetail();
// goLangDataAcquisitionService.collectorList();
//// goLangDataAcquisitionService.inverterList();
// goLangDataAcquisitionService.collectorDetail();
// goLangDataAcquisitionService.inverterDetail();
// goLangDataAcquisitionService.inverAlramInfo();
kSolarRequestUtil
.
getHeader
();
}
}
amos-boot-data/amos-boot-data-housepvapi/src/main/java/com/yeejoin/amos/api/householdapi/face/service/GoodWeDataAcquisitionService.java
0 → 100644
View file @
860a7d9e
package
com
.
yeejoin
.
amos
.
api
.
householdapi
.
face
.
service
;
public
interface
GoodWeDataAcquisitionService
{
/**
* @descrption 场站列表数据入库
*/
void
stationList
();
/**
* @descrption 场站详情数据入库
*/
void
stationDetail
();
/**
* @descrption 采集器列表数据入库
*/
void
collectorList
();
/**
* @descrption 采集器详情数据入库
*/
void
collectorDetail
();
/**
* @descrption 逆变器列表数据入库
*/
void
inverterList
();
/**
* @descrption 逆变器详情数据入库
*/
void
inverterDetail
();
/**
* @descrption 采集器告警列表数据入库
*/
void
inverAlramInfo
();
}
amos-boot-data/amos-boot-data-housepvapi/src/main/java/com/yeejoin/amos/api/householdapi/face/service/SofarDataAcquisitionService.java
0 → 100644
View file @
860a7d9e
package
com
.
yeejoin
.
amos
.
api
.
householdapi
.
face
.
service
;
public
interface
SofarDataAcquisitionService
{
/**
* @descrption 场站列表数据入库
*/
void
stationList
();
/**
* @descrption 场站详情数据入库
*/
void
stationDetail
();
/**
* @descrption 采集器列表数据入库
*/
void
collectorList
();
/**
* @descrption 采集器详情数据入库
*/
void
collectorDetail
();
/**
* @descrption 逆变器列表数据入库
*/
void
inverterList
();
/**
* @descrption 逆变器详情数据入库
*/
void
inverterDetail
();
/**
* @descrption 采集器告警列表数据入库
*/
void
inverAlramInfo
();
}
amos-boot-data/amos-boot-data-housepvapi/src/main/java/com/yeejoin/amos/api/householdapi/face/service/impl/GoLangDataAcquisitionServiceImpl.java
View file @
860a7d9e
...
...
@@ -2,9 +2,7 @@ package com.yeejoin.amos.api.householdapi.face.service.impl;
import
cn.hutool.core.date.DateTime
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.util.StrUtil
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.fasterxml.jackson.core.JsonParser
;
import
com.yeejoin.amos.api.householdapi.Utils.GolangRequestUtil
;
import
com.yeejoin.amos.api.householdapi.constant.GoLangConstant
;
import
com.yeejoin.amos.api.householdapi.face.dto.AlarmDto
;
...
...
@@ -39,7 +37,7 @@ import java.util.concurrent.TimeUnit;
@Service
public
class
GoLangDataAcquisitionServiceImpl
implements
GoLangDataAcquisitionService
{
//定时任务执行频率 当前为10分钟一次
private
final
String
dataRequstScheduled
=
"0 0/
1
0 * * * *"
;
private
final
String
dataRequstScheduled
=
"0 0/
6
0 * * * *"
;
//锦浪云请求工具封装
@Autowired
...
...
amos-boot-data/amos-boot-data-housepvapi/src/main/java/com/yeejoin/amos/openapi/enums/PVProducerInfoEnum.java
View file @
860a7d9e
...
...
@@ -6,7 +6,9 @@ public enum PVProducerInfoEnum {
GDW
(
"固德威"
,
"GDW"
),
SH
(
"首航"
,
"SH"
),
JLY
(
"锦浪云"
,
"JLY"
);
JLY
(
"锦浪云"
,
"JLY"
),
KSOLAR
(
"科士达"
,
"KSD"
),
HUAWEI
(
"华为"
,
"HW"
);
private
String
name
;
...
...
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