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
d88a8293
Commit
d88a8293
authored
Jun 19, 2023
by
caotao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新户用光伏相关代码
parent
87cf8b25
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
117 additions
and
34 deletions
+117
-34
HouseholdPvUtils.java
...yeejoin/amos/api/householdapi/Utils/HouseholdPvUtils.java
+87
-31
HouseholdPvApiDto.java
...n/amos/api/householdapi/face/model/HouseholdPvApiDto.java
+30
-3
No files found.
amos-boot-data/amos-boot-data-accessapi/src/main/java/com/yeejoin/amos/api/householdapi/Utils/HouseholdPvUtils.java
View file @
d88a8293
package
com
.
yeejoin
.
amos
.
api
.
householdapi
.
Utils
;
package
com
.
yeejoin
.
amos
.
api
.
householdapi
.
Utils
;
import
cn.hutool.Hutool
;
import
cn.hutool.http.HttpUtil
;
import
cn.hutool.http.HttpUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.qiniu.util.Json
;
import
com.yeejoin.amos.api.householdapi.face.model.HouseholdPvApiDto
;
import
com.yeejoin.amos.api.householdapi.face.model.HouseholdPvApiDto
;
import
com.yeejoin.amos.api.householdapi.face.model.HouseholdPvProducerInfoDto
;
import
com.yeejoin.amos.api.householdapi.face.model.HouseholdPvProducerInfoDto
;
import
com.yeejoin.amos.api.householdapi.face.orm.entity.HouseholdPvProducerInfo
;
import
com.yeejoin.amos.api.householdapi.face.orm.entity.HouseholdPvProducerInfo
;
import
com.yeejoin.amos.api.householdapi.face.service.impl.HouseholdPvApiServiceImpl
;
import
com.yeejoin.amos.api.householdapi.face.service.impl.HouseholdPvApiServiceImpl
;
import
com.yeejoin.amos.api.householdapi.face.service.impl.HouseholdPvProducerInfoServiceImpl
;
import
com.yeejoin.amos.api.householdapi.face.service.impl.HouseholdPvProducerInfoServiceImpl
;
import
com.yeejoin.amos.component.influxdb.InfluxDbConnection
;
import
com.yeejoin.amos.openapi.enums.PVProducerInfoEnum
;
import
com.yeejoin.amos.openapi.enums.PVProducerInfoEnum
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.
springframework.web.bind.annotation.ResponseBody
;
import
org.
typroject.tyboot.component.cache.Redis
;
import
java.util.Date
;
import
java.util.*
;
import
java.util.HashMap
;
@Component
@Component
public
class
HouseholdPvUtils
{
public
class
HouseholdPvUtils
{
@Autowired
@Autowired
private
HouseholdPvProducerInfoServiceImpl
householdPvProducerInfoServiceImpl
;
private
HouseholdPvProducerInfoServiceImpl
householdPvProducerInfoServiceImpl
;
@Autowired
@Autowired
private
HouseholdPvApiServiceImpl
householdPvApiServiceImpl
;
private
HouseholdPvApiServiceImpl
householdPvApiServiceImpl
;
@Autowired
InfluxDbConnection
influxDbConnection
;
private
final
static
String
API_REDIS_PREFIX
=
"HOUSEHOLD_API_CACHE_"
+
""
;
/**
/**
* @deprecated 根据厂商编码获取厂商的hearer
* @param code 厂商code
* @param code 厂商code
* @return HashMap<String, Object> 发送请求前的准备 准备header信息
* @return HashMap<String, Object> 发送请求前的准备 准备header信息
* @deprecated 根据厂商编码获取厂商的hearer
*/
*/
public
HashMap
<
String
,
Object
>
getHeaderByProducerCode
(
String
code
)
{
public
HashMap
<
String
,
Object
>
getHeaderByProducerCode
(
String
code
)
{
HashMap
<
String
,
Object
>
hashMap
=
new
HashMap
<>();
HashMap
<
String
,
Object
>
hashMap
=
new
HashMap
<>();
HashMap
<
String
,
String
>
hashMaphead
=
new
HashMap
<>();
HashMap
<
String
,
String
>
hashMaphead
=
new
HashMap
<>();
HouseholdPvProducerInfo
householdPvProducerInfo
=
this
.
householdPvProducerInfoServiceImpl
.
queryForHouseholdPvProducerInfoByCode
(
code
);
HouseholdPvProducerInfo
householdPvProducerInfo
=
this
.
householdPvProducerInfoServiceImpl
.
queryForHouseholdPvProducerInfoByCode
(
code
);
String
url
=
householdPvProducerInfo
.
getProdcerUrl
()
+
householdPvProducerInfo
.
getTokenUrl
();
String
url
=
householdPvProducerInfo
.
getProdcerUrl
()
+
householdPvProducerInfo
.
getTokenUrl
();
hashMap
.
put
(
"apiurl"
,
householdPvProducerInfo
.
getProdcerUrl
());
hashMap
.
put
(
"apiurl"
,
householdPvProducerInfo
.
getProdcerUrl
());
if
(
PVProducerInfoEnum
.
GDW
.
getCode
().
equals
(
code
))
{
if
(
PVProducerInfoEnum
.
GDW
.
getCode
().
equals
(
code
))
{
...
@@ -59,45 +67,93 @@ public class HouseholdPvUtils {
...
@@ -59,45 +67,93 @@ public class HouseholdPvUtils {
String
response
=
HttpUtil
.
createPost
(
url
).
body
(
body
).
execute
().
body
();
String
response
=
HttpUtil
.
createPost
(
url
).
body
(
body
).
execute
().
body
();
JSONObject
jsonObject
=
JSON
.
parseObject
(
response
);
JSONObject
jsonObject
=
JSON
.
parseObject
(
response
);
hashMaphead
.
put
(
"Authorization"
,
(
String
)
jsonObject
.
get
(
"data"
));
hashMaphead
.
put
(
"Authorization"
,
(
String
)
jsonObject
.
get
(
"data"
));
hashMap
.
put
(
"header"
,
hashMaphead
);
hashMap
.
put
(
"header"
,
hashMaphead
);
}
else
if
(
PVProducerInfoEnum
.
JLY
.
getCode
().
equals
(
code
))
{
}
else
if
(
PVProducerInfoEnum
.
JLY
.
getCode
().
equals
(
code
))
{
hashMaphead
.
put
(
"Content-type"
,
"application/json;charset=UTF-8"
);
hashMaphead
.
put
(
"Content-type"
,
"application/json;charset=UTF-8"
);
hashMaphead
.
put
(
"Authorization"
,
"API "
+
householdPvProducerInfo
.
getProdcerAppid
());
hashMaphead
.
put
(
"Authorization"
,
"API "
+
householdPvProducerInfo
.
getProdcerAppid
());
hashMaphead
.
put
(
"Content-MD5"
,
null
);
hashMaphead
.
put
(
"Content-MD5"
,
null
);
hashMaphead
.
put
(
"Date"
,
GoLangHeaderUtils
.
getGMTTime
());
hashMaphead
.
put
(
"Date"
,
GoLangHeaderUtils
.
getGMTTime
());
hashMap
.
put
(
"header"
,
hashMaphead
);
hashMap
.
put
(
"header"
,
hashMaphead
);
hashMap
.
put
(
"appsecret"
,
householdPvProducerInfo
.
getProdcerAppsecret
());
hashMap
.
put
(
"appsecret"
,
householdPvProducerInfo
.
getProdcerAppsecret
());
}
}
return
hashMap
;
return
hashMap
;
}
}
/** @return String 请求返回的response字符串
/**
* @param seq apiId 数据库中维护的的apiId
* @param seq apiId 数据库中维护的的apiId
* */
* @return String 请求返回的response字符串
public
String
gerResponseByAPiID
(
Long
seq
){
*/
public
String
gerResponseByAPiID
(
Long
seq
)
{
HouseholdPvApiDto
householdPvApiDto
=
this
.
householdPvApiServiceImpl
.
queryBySeq
(
seq
);
HouseholdPvApiDto
householdPvApiDto
=
this
.
householdPvApiServiceImpl
.
queryBySeq
(
seq
);
HashMap
<
String
,
Object
>
producerInfo
=
this
.
getHeaderByProducerCode
(
householdPvApiDto
.
getProducerId
());
HashMap
<
String
,
Object
>
producerInfo
=
this
.
getHeaderByProducerCode
(
householdPvApiDto
.
getProducerId
());
HashMap
<
String
,
String
>
headMap
=
(
HashMap
<
String
,
String
>)
producerInfo
.
get
(
"header"
);
HashMap
<
String
,
String
>
headMap
=
(
HashMap
<
String
,
String
>)
producerInfo
.
get
(
"header"
);
if
(
PVProducerInfoEnum
.
JLY
.
getCode
().
equals
(
householdPvApiDto
.
getProducerId
()))
{
if
(
PVProducerInfoEnum
.
JLY
.
getCode
().
equals
(
householdPvApiDto
.
getProducerId
()))
{
String
contentMD5
=
GoLangHeaderUtils
.
getDigest
(
householdPvApiDto
.
getParamInfo
());
String
contentMD5
=
GoLangHeaderUtils
.
getDigest
(
householdPvApiDto
.
getParamInfo
());
String
param
=
"POST"
+
"\n"
+
contentMD5
+
"\n"
+
"application/json"
+
"\n"
+
headMap
.
get
(
"Date"
)+
"\n"
+
householdPvApiDto
.
getApiUrl
();
String
param
=
"POST"
+
"\n"
+
contentMD5
+
"\n"
+
"application/json"
+
"\n"
+
headMap
.
get
(
"Date"
)
+
"\n"
+
householdPvApiDto
.
getApiUrl
();
String
sign
=
""
;
String
sign
=
""
;
try
{
try
{
sign
=
GoLangHeaderUtils
.
HmacSHA1Encrypt
(
param
,
(
String
)
producerInfo
.
get
(
"appsecret"
));
sign
=
GoLangHeaderUtils
.
HmacSHA1Encrypt
(
param
,
(
String
)
producerInfo
.
get
(
"appsecret"
));
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
throw
new
RuntimeException
(
e
);
}
}
headMap
.
put
(
"Content-MD5"
,
contentMD5
);
headMap
.
put
(
"Content-MD5"
,
contentMD5
);
headMap
.
put
(
"Authorization"
,
headMap
.
get
(
"Authorization"
)+
":"
+
sign
);
headMap
.
put
(
"Authorization"
,
headMap
.
get
(
"Authorization"
)
+
":"
+
sign
);
}
}
String
respone
=
""
;
String
respone
=
""
;
if
(
householdPvApiDto
.
getRequestMethod
().
equals
(
"POST"
))
{
if
(
householdPvApiDto
.
getRequestMethod
().
equals
(
"POST"
))
{
respone
=
HttpUtil
.
createPost
(
producerInfo
.
get
(
"apiurl"
)
+
householdPvApiDto
.
getApiUrl
()).
headerMap
(
headMap
,
false
).
respone
=
HttpUtil
.
createPost
(
producerInfo
.
get
(
"apiurl"
)
+
householdPvApiDto
.
getApiUrl
()).
headerMap
(
headMap
,
false
).
body
(
householdPvApiDto
.
getParamInfo
()).
execute
().
body
();
body
(
householdPvApiDto
.
getParamInfo
()).
execute
().
body
();
}
}
if
(
householdPvApiDto
.
getRequestMethod
().
equals
(
"GET"
))
{
if
(
householdPvApiDto
.
getRequestMethod
().
equals
(
"GET"
))
{
respone
=
HttpUtil
.
createGet
(
producerInfo
.
get
(
"apiurl"
)
+
householdPvApiDto
.
getApiUrl
()).
headerMap
(
headMap
,
true
).
respone
=
HttpUtil
.
createGet
(
producerInfo
.
get
(
"apiurl"
)
+
householdPvApiDto
.
getApiUrl
()).
headerMap
(
headMap
,
true
).
body
(
householdPvApiDto
.
getParamInfo
()).
execute
().
body
();
body
(
householdPvApiDto
.
getParamInfo
()).
execute
().
body
();
}
}
JSONArray
jsonArray
=
handlerResponseByResultResolverule
(
householdPvApiDto
.
getResultResolveRule
(),
respone
);
handleResponseAndCacheData
(
String
.
valueOf
(
seq
),
householdPvApiDto
.
getCacheField
(),
jsonArray
);
return
respone
;
return
respone
;
}
}
public
JSONArray
handlerResponseByResultResolverule
(
String
resultResovle
,
String
response
)
{
String
[]
rules
=
resultResovle
.
split
(
","
);
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
response
);
JSONArray
jsonArray
=
new
JSONArray
();
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
]);
}
}
}
return
jsonArray
;
}
public
void
handleResponseAndCacheData
(
String
seq
,
String
cacheField
,
JSONArray
jsonArray
)
{
String
apiID
=
API_REDIS_PREFIX
+
seq
;
List
list
=
new
ArrayList
();
List
saveList
=
new
ArrayList
();
if
(
jsonArray
.
size
()
>
0
)
{
for
(
Object
o
:
jsonArray
)
{
Map
<
String
,
Object
>
maps1
=
(
Map
<
String
,
Object
>)
o
;
list
.
add
(
maps1
.
get
(
cacheField
));
Map
<
String
,
String
>
maps2
=
new
HashMap
<>();
maps2
.
put
(
"key"
,
UUID
.
randomUUID
().
toString
());
// influxDbConnection.insert("SH_DZ",maps2,maps1);
}
}
saveList
=
Redis
.
getRedisTemplate
().
opsForList
().
range
(
apiID
,
0
,
-
1
);
if
(
saveList
.
size
()
==
0
)
{
Redis
.
getRedisTemplate
().
opsForList
().
leftPushAll
(
apiID
,
list
);
}
// saveList = Redis.getRedisTemplate().opsForList().range(apiID,0,-1);
if
(
saveList
.
size
()
!=
list
.
size
())
{
Redis
.
getRedisTemplate
().
delete
(
apiID
);
Redis
.
getRedisTemplate
().
opsForList
().
leftPushAll
(
apiID
,
list
);
}
list
=
Redis
.
getRedisTemplate
().
opsForList
().
range
(
apiID
,
0
,
-
1
);
}
}
}
amos-boot-data/amos-boot-data-accessapi/src/main/java/com/yeejoin/amos/api/householdapi/face/model/HouseholdPvApiDto.java
View file @
d88a8293
package
com
.
yeejoin
.
amos
.
api
.
householdapi
.
face
.
model
;
package
com
.
yeejoin
.
amos
.
api
.
householdapi
.
face
.
model
;
import
com.baomidou.mybatisplus.annotation.TableField
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
lombok.Data
;
...
@@ -16,10 +17,10 @@ import java.util.Date;
...
@@ -16,10 +17,10 @@ import java.util.Date;
*/
*/
@Data
@Data
@EqualsAndHashCode
(
callSuper
=
true
)
@EqualsAndHashCode
(
callSuper
=
true
)
@ApiModel
(
value
=
"HouseholdPvApiDto"
,
description
=
"户用光伏-厂商API haders"
)
@ApiModel
(
value
=
"HouseholdPvApiDto"
,
description
=
"户用光伏-厂商API haders"
)
public
class
HouseholdPvApiDto
extends
BaseModel
{
public
class
HouseholdPvApiDto
extends
BaseModel
{
private
static
final
long
serialVersionUID
=
1L
;
private
static
final
long
serialVersionUID
=
1L
;
@ApiModelProperty
(
value
=
"厂商id"
)
@ApiModelProperty
(
value
=
"厂商id"
)
...
@@ -40,4 +41,30 @@ public class HouseholdPvApiDto extends BaseModel {
...
@@ -40,4 +41,30 @@ public class HouseholdPvApiDto extends BaseModel {
@ApiModelProperty
(
value
=
"参数信息"
)
@ApiModelProperty
(
value
=
"参数信息"
)
private
String
paramInfo
;
private
String
paramInfo
;
/**
* 依赖的apiId
*/
@ApiModelProperty
(
value
=
"依赖的apiId"
)
private
String
dependecyApiId
;
/**
* 缓存的属性
*/
@ApiModelProperty
(
value
=
"缓存的属性"
)
private
String
cacheField
;
/**
* 依赖的api属性
*/
@ApiModelProperty
(
value
=
"依赖的api属性"
)
private
String
dependApiParamKey
;
/**
* result解析结果
*/
@ApiModelProperty
(
value
=
"result解析结果"
)
private
String
resultResolveRule
;
/**
* 是否分页
*/
@ApiModelProperty
(
value
=
"是否分页"
)
private
Integer
isPage
;
}
}
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