Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dm_project
Project
Project
Details
Activity
Releases
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
姚本章
dm_project
Commits
6b616132
Commit
6b616132
authored
Jan 13, 2021
by
ysongq
Browse files
Options
Browse Files
Download
Plain Diff
commit
parents
7dc8a4e0
78e8094b
Changes
37
Show whitespace changes
Inline
Side-by-side
Showing
37 changed files
with
1159 additions
and
474 deletions
+1159
-474
api_gateway.sql
database/zc/api_gateway.sql
+5
-1
pom.xml
jz-dm-apigateway/pom.xml
+12
-1
LoggingConstants.java
...main/java/com/jz/dm/common/constant/LoggingConstants.java
+3
-0
GatewayResultCode.java
...c/main/java/com/jz/dm/common/enums/GatewayResultCode.java
+5
-0
AuthReqTypeEnum.java
...ain/java/com/jz/dm/common/enums/auth/AuthReqTypeEnum.java
+34
-0
DateUtil.java
...gateway/src/main/java/com/jz/dm/common/util/DateUtil.java
+40
-1
MapUtil.java
...igateway/src/main/java/com/jz/dm/common/util/MapUtil.java
+4
-3
HttpDownload.java
.../main/java/com/jz/dm/common/util/stream/HttpDownload.java
+192
-0
SentinelConfig.java
...ateway/src/main/java/com/jz/dm/config/SentinelConfig.java
+72
-0
AuthFilter.java
...apigateway/src/main/java/com/jz/dm/filter/AuthFilter.java
+39
-6
VerifySignFilter.java
...eway/src/main/java/com/jz/dm/filter/VerifySignFilter.java
+5
-3
ApiAuth.java
...ateway/src/main/java/com/jz/dm/models/domian/ApiAuth.java
+11
-0
ApiInterface.java
...y/src/main/java/com/jz/dm/models/domian/ApiInterface.java
+11
-0
ApiInterfaceFile.java
...c/main/java/com/jz/dm/models/domian/ApiInterfaceFile.java
+0
-1
ApiInterfaceReq.java
.../main/java/com/jz/dm/models/req/make/ApiInterfaceReq.java
+6
-0
MakeDataBankApiReq.java
...in/java/com/jz/dm/models/req/make/MakeDataBankApiReq.java
+14
-5
AuthService.java
...igateway/src/main/java/com/jz/dm/service/AuthService.java
+7
-0
ApiInterfaceServiceImpl.java
.../java/com/jz/dm/service/impl/ApiInterfaceServiceImpl.java
+2
-0
ApiLogServiceImpl.java
...c/main/java/com/jz/dm/service/impl/ApiLogServiceImpl.java
+17
-8
AuthServiceImpl.java
...src/main/java/com/jz/dm/service/impl/AuthServiceImpl.java
+16
-2
ProducerServiceImpl.java
...main/java/com/jz/dm/service/impl/ProducerServiceImpl.java
+16
-0
ApiParamVerify.java
...c/main/java/com/jz/dm/service/request/ApiParamVerify.java
+57
-0
ApiQueryService.java
.../main/java/com/jz/dm/service/request/ApiQueryService.java
+136
-85
SystemLogAspect.java
...y/src/main/java/com/jz/dm/web/aspect/SystemLogAspect.java
+14
-11
AccessLimitInterceptor.java
...ava/com/jz/dm/web/interceptor/AccessLimitInterceptor.java
+10
-8
application-test.yml
jz-dm-apigateway/src/main/resources/application-test.yml
+19
-3
application.yml
jz-dm-apigateway/src/main/resources/application.yml
+15
-1
ApiReqTest.java
...teway/src/test/java/com/jz/dm/gateway/api/ApiReqTest.java
+57
-0
TestOrganizationManage.java
...st/java/com/jz/dm/gateway/org/TestOrganizationManage.java
+4
-5
TestAmountCall.java
...rc/test/java/com/jz/dm/gateway/orther/TestAmountCall.java
+71
-0
TestHttpReq.java
...y/src/test/java/com/jz/dm/gateway/orther/TestHttpReq.java
+1
-1
TestMakeApi.java
...y/src/test/java/com/jz/dm/gateway/orther/TestMakeApi.java
+1
-1
TestRedisUserSave.java
...test/java/com/jz/dm/gateway/orther/TestRedisUserSave.java
+1
-1
TestStreamReq.java
...src/test/java/com/jz/dm/gateway/orther/TestStreamReq.java
+26
-0
HttpsUtils.java
...-common/src/main/java/com/jz/common/utils/HttpsUtils.java
+4
-3
manageApplicationTests.java
...e/src/test/java/com/jz/manage/manageApplicationTests.java
+0
-42
pom.xml
pom.xml
+232
-282
No files found.
database/zc/api_gateway.sql
View file @
6b616132
...
...
@@ -11,7 +11,7 @@ CREATE TABLE `t_api_interface` (
`api_type`
varchar
(
50
)
NULL
DEFAULT
''
COMMENT
'api类型:1 数据银行制作API 2 数据银行制作数据包, 3 API实时接入 6 标签查询 9自定义'
,
`api_function`
varchar
(
200
)
DEFAULT
NULL
COMMENT
'接口功能'
,
`join_type`
varchar
(
50
)
NULL
DEFAULT
NULL
COMMENT
'接入类型:字典表对应key值'
,
`test_example`
varchar
(
255
)
NULL
DEFAULT
NULL
COMMENT
'测试实例'
;
`test_example`
varchar
(
255
)
NULL
DEFAULT
NULL
COMMENT
'测试实例'
,
`status`
varchar
(
50
)
NOT
NULL
COMMENT
'状态(DRAFT-草稿 ISSUE-发布 OUTMODED-过时 4FREEZE-冻结 EXPIRY-失效)'
,
`output_type`
varchar
(
50
)
NULL
DEFAULT
'JSON'
COMMENT
'输出类型:flow 流形式输出, json格式输出'
,
`page`
tinyint
(
2
)
NULL
DEFAULT
'0'
COMMENT
'是否分页:0 false ,1 true'
,
...
...
@@ -19,6 +19,8 @@ CREATE TABLE `t_api_interface` (
`sign_type`
varchar
(
50
)
DEFAULT
NULL
COMMENT
'加密方式: MD5 RSA'
,
`timeout`
varchar
(
50
)
DEFAULT
NULL
COMMENT
'超时时间'
,
`file_id`
bigint
(
20
)
NOT
NULL
COMMENT
'文件夹id'
,
`req_type`
varchar
(
20
)
DEFAULT
NULL
COMMENT
'限制类型:DAY 按天,MONTH 按月, YEAR 按年'
,
`req_frequency`
bigint
(
20
)
DEFAULT
'100'
COMMENT
'限制次数'
,
`is_test`
tinyint
(
2
)
NOT
NULL
DEFAULT
'0'
COMMENT
'是否测试数据:0 否,1 是'
,
`remark`
varchar
(
500
)
DEFAULT
NULL
COMMENT
'备注'
,
`create_date`
datetime
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
COMMENT
'创建时间'
,
...
...
@@ -103,6 +105,8 @@ CREATE TABLE `t_api_auth` (
`api_interface_id`
bigint
(
20
)
NOT
NULL
COMMENT
'api信息表id'
,
`api_org_id`
bigint
(
20
)
NOT
NULL
COMMENT
'api组织id'
,
`auth_type`
varchar
(
20
)
DEFAULT
NULL
COMMENT
'授权类型:DATA_BANK_AUTH 数据银行购买 DMP_AUTH dmp授权'
,
`req_type`
varchar
(
20
)
DEFAULT
NULL
COMMENT
'限制类型:DAY 按天,MONTH 按月, YEAR 按年'
,
`req_frequency`
bigint
(
20
)
DEFAULT
'100'
COMMENT
'限制次数'
,
`auth_code`
varchar
(
100
)
DEFAULT
NULL
COMMENT
'授权码'
,
`salt`
varchar
(
200
)
DEFAULT
NULL
COMMENT
'盐值'
,
`auth_mode`
varchar
(
50
)
DEFAULT
NULL
COMMENT
'授权方式:POWER_CALL_MODE 按次调用 ,RECORD_TIME_MODE 按时间调用 PERMANENT_TIME_MODE 永久有效'
,
...
...
jz-dm-apigateway/pom.xml
View file @
6b616132
...
...
@@ -97,18 +97,29 @@
<artifactId>
spring-boot-starter-aop
</artifactId>
</dependency>
<!-- 校验-->
<!--
validation
校验-->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-validation
</artifactId>
</dependency>
<!--Sentinel 限流框架依赖-->
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-alibaba-sentinel
</artifactId>
<!-- <version>0.9.0.RELEASE</version>-->
</dependency>
<dependency>
<groupId>
net.sf.json-lib
</groupId>
<artifactId>
json-lib
</artifactId>
<version>
2.2.3
</version>
<classifier>
jdk15
</classifier>
<!-- jdk版本 -->
</dependency>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
</dependency>
</dependencies>
<build>
...
...
jz-dm-apigateway/src/main/java/com/jz/dm/common/constant/LoggingConstants.java
View file @
6b616132
...
...
@@ -48,4 +48,7 @@ public class LoggingConstants {
/** "&" 符号*/
public
static
final
String
AND_SPILT
=
"&"
;
/** "=" 符号*/
public
static
final
String
AND_EQUAL
=
"="
;
}
jz-dm-apigateway/src/main/java/com/jz/dm/common/enums/GatewayResultCode.java
View file @
6b616132
...
...
@@ -67,6 +67,11 @@ public enum GatewayResultCode implements ResultCode {
ORG_STATE_EXCEPTION
(
"ORG_STATE_EXCEPTION"
,
"请求组织状态异常"
),
/** 请求信息不存在 */
REQUEST_INFO_UNEXIST
(
"REQUEST_INFO_UNEXIST"
,
"请求信息不存在"
),
/** 远程请求异常 */
DISTANCE_REQUEST_EXCEPTION
(
"DISTANCE_REQUEST_EXCEPTION"
,
"流形式输出异常"
),
/** 单次调用金额不足 */
CALL_AMOUNT_NOT_ENOUGH
(
"CALL_AMOUNT_NOT_ENOUGH"
,
"单次调用金额不足"
),
/** 输出类型错误 */
OUTPUT_TYPE_EXCEPTION
(
"OUTPUT_TYPE_EXCEPTION"
,
"输出类型错误!"
);
...
...
jz-dm-apigateway/src/main/java/com/jz/dm/common/enums/auth/AuthReqTypeEnum.java
0 → 100644
View file @
6b616132
package
com
.
jz
.
dm
.
common
.
enums
.
auth
;
/**
* @author ZC
* @PACKAGE_NAME: com.jz.dm.common.enums.auth
* @PROJECT_NAME: jz-dm-parent
* @NAME: AuthReqTypeEnum
* @DATE: 2021-1-8/18:44
* @DAY_NAME_SHORT: 周五
* @Description:
**/
public
enum
AuthReqTypeEnum
{
DAY
(
"天"
),
MONTH
(
"月"
),
YEAR
(
"年"
);
private
String
text
;
AuthReqTypeEnum
(
String
text
)
{
this
.
text
=
text
;
}
public
String
getText
()
{
return
text
;
}
public
static
AuthReqTypeEnum
fromAuthReqTypeEnum
(
String
typeName
)
{
for
(
AuthReqTypeEnum
type
:
AuthReqTypeEnum
.
values
())
{
if
(
type
.
name
().
equals
(
typeName
))
{
return
type
;
}
}
return
null
;
}
}
jz-dm-apigateway/src/main/java/com/jz/dm/common/util/DateUtil.java
View file @
6b616132
package
com
.
jz
.
dm
.
common
.
util
;
import
java.text.SimpleDateFormat
;
import
java.util.Calendar
;
import
java.util.Date
;
/**
* @author ZC
...
...
@@ -27,7 +29,44 @@ public class DateUtil {
return
(
cal
.
getTimeInMillis
()
-
System
.
currentTimeMillis
())
/
1000
;
}
/**
* 计算当前距离下月一号剩余时间
* @return
*/
public
static
long
calculateNowMonthTime
(){
Calendar
c
=
Calendar
.
getInstance
();
//获取一个Calendar对象
c
.
setTime
(
new
Date
()
);
c
.
add
(
Calendar
.
MONTH
,
1
);
c
.
set
(
Calendar
.
DAY_OF_MONTH
,
0
);
c
.
set
(
Calendar
.
HOUR_OF_DAY
,
23
);
c
.
set
(
Calendar
.
MINUTE
,
59
);
c
.
set
(
Calendar
.
SECOND
,
59
);
return
(
c
.
getTimeInMillis
()
-
System
.
currentTimeMillis
())
/
1000
;
}
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
calculateNowResidueTime
());
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
//System.out.println(calculateNowResidueTime());
Calendar
c
=
Calendar
.
getInstance
();
//获取一个Calendar对象
c
.
setTime
(
new
Date
()
);
c
.
add
(
Calendar
.
MONTH
,
1
);
c
.
set
(
Calendar
.
DAY_OF_MONTH
,
0
);
c
.
set
(
Calendar
.
HOUR_OF_DAY
,
23
);
c
.
set
(
Calendar
.
MINUTE
,
59
);
c
.
set
(
Calendar
.
SECOND
,
59
);
Date
time
=
c
.
getTime
();
String
format
=
dateFormat
.
format
(
time
);
System
.
out
.
println
(
format
);
Calendar
cal
=
Calendar
.
getInstance
();
//获取一个Calendar对象
cal
.
setTime
(
new
Date
()
);
cal
.
add
(
Calendar
.
MONTH
,
0
);
//获取当前时间的下一个月
cal
.
set
(
Calendar
.
DAY_OF_MONTH
,
cal
.
getActualMaximum
(
Calendar
.
DAY_OF_MONTH
));
//获取下一个月的最后一天
Date
preMonth
=
cal
.
getTime
();
//得到下个月的最后一天
String
format1
=
dateFormat
.
format
(
preMonth
);
System
.
out
.
println
(
format1
);
System
.
out
.
println
(
calculateNowMonthTime
()/
60
/
60
/
24
);
}
}
jz-dm-apigateway/src/main/java/com/jz/dm/common/util/MapUtil.java
View file @
6b616132
package
com
.
jz
.
dm
.
common
.
util
;
import
com.alibaba.fastjson.JSON
;
import
com.jz.dm.common.constant.LoggingConstants
;
import
org.apache.commons.lang3.StringUtils
;
import
java.io.UnsupportedEncodingException
;
...
...
@@ -30,9 +31,9 @@ public class MapUtil {
*/
public
static
String
getSignValue
(
String
apiKey
,
String
method
,
String
signType
,
String
timestamp
){
StringBuilder
builder
=
new
StringBuilder
();
builder
.
append
(
"apiKey="
).
append
(
apiKey
).
append
(
"&"
)
.
append
(
"method="
).
append
(
method
).
append
(
"&"
)
.
append
(
"signType="
).
append
(
signType
).
append
(
"&"
)
builder
.
append
(
"apiKey="
).
append
(
apiKey
).
append
(
LoggingConstants
.
AND_SPILT
)
.
append
(
"method="
).
append
(
method
).
append
(
LoggingConstants
.
AND_SPILT
)
.
append
(
"signType="
).
append
(
signType
).
append
(
LoggingConstants
.
AND_SPILT
)
.
append
(
"timestamp="
).
append
(
timestamp
);
return
builder
.
toString
();
}
...
...
jz-dm-apigateway/src/main/java/com/jz/dm/common/util/stream/HttpDownload.java
0 → 100644
View file @
6b616132
package
com
.
jz
.
dm
.
common
.
util
.
stream
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.http.*
;
import
org.apache.http.client.methods.HttpGet
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.text.MessageFormat
;
import
static
com
.
jz
.
common
.
utils
.
HttpClientPool
.
getHttpClient
;
/**
* @author ZC
* @PACKAGE_NAME: com.sentinel.project.util
* @PROJECT_NAME: jz-dm-parent
* @NAME: HttpDownload
* @DATE: 2021-1-7/18:04
* @DAY_NAME_SHORT: 周四
* @Description:
**/
@Slf4j
public
class
HttpDownload
{
public
static
final
int
cache
=
10
*
1024
;
public
static
final
boolean
isWindows
;
public
static
final
String
splash
;
public
static
final
String
root
;
static
{
if
(
System
.
getProperty
(
"name"
)
!=
null
&&
System
.
getProperty
(
"name"
).
toLowerCase
().
contains
(
"windows"
))
{
isWindows
=
true
;
splash
=
"\\"
;
root
=
"D:"
;
}
else
{
isWindows
=
false
;
splash
=
"/"
;
root
=
"/search"
;
}
}
/**
* 根据url下载文件,文件名从response header头中获取
*
* @param url
* @return
*/
public
static
void
download
(
String
url
)
{
download
(
url
,
null
);
}
/**
* 根据url下载文件,保存到filepath中
*
* @param baseUrl
* @param filepath
* @return
*/
public
static
void
download
(
String
baseUrl
,
String
filepath
)
{
InputStream
is
=
null
;
FileOutputStream
fileOut
=
null
;
try
{
CloseableHttpClient
client
=
getHttpClient
();
HttpGet
httpGet
=
new
HttpGet
(
baseUrl
);
HttpResponse
response
=
client
.
execute
(
httpGet
);
//获取消息头
Header
[]
headers
=
response
.
getAllHeaders
();
for
(
Header
header
:
headers
)
{
System
.
out
.
println
(
MessageFormat
.
format
(
"header:{0}={1}"
,
header
.
getName
(),
header
.
getValue
()));
}
String
fileName
=
response
.
getHeaders
(
"Content-Disposition"
)[
0
].
getValue
().
split
(
"filename="
)[
1
];
System
.
out
.
println
(
"文件名为"
+
fileName
);
HttpEntity
entity
=
response
.
getEntity
();
is
=
entity
.
getContent
();
if
(
fileName
==
null
)
{
fileName
=
getFilePath
(
response
);
}
if
(
filepath
!=
null
)
{
fileName
=
filepath
+
splash
+
fileName
;
}
else
{
fileName
=
splash
+
fileName
;
}
File
file
=
new
File
(
fileName
);
file
.
getParentFile
().
mkdirs
();
fileOut
=
new
FileOutputStream
(
file
);
/**
* 根据实际运行效果 设置缓冲区大小
*/
byte
[]
buffer
=
new
byte
[
cache
];
int
ch
=
0
;
while
((
ch
=
is
.
read
(
buffer
))
!=
-
1
)
{
fileOut
.
write
(
buffer
,
0
,
ch
);
}
fileOut
.
flush
();
log
.
info
(
"文件下载成功!"
);
}
catch
(
Exception
e
)
{
log
.
info
(
"数据下载异常:{}"
,
e
.
getMessage
());
e
.
printStackTrace
();
}
finally
{
if
(
is
!=
null
)
{
try
{
is
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
if
(
null
!=
fileOut
)
{
try
{
fileOut
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
}
/**
* 获取response要下载的文件的默认路径
*
* @param response
* @return
*/
public
static
String
getFilePath
(
HttpResponse
response
)
{
String
filepath
=
root
+
splash
;
String
filename
=
getFileName
(
response
);
if
(
filename
!=
null
)
{
filepath
+=
filename
;
}
else
{
filepath
+=
getRandomFileName
();
}
return
filepath
;
}
/**
* 获取response header中Content-Disposition中的filename值
*
* @param response
* @return
*/
public
static
String
getFileName
(
HttpResponse
response
)
{
Header
contentHeader
=
response
.
getFirstHeader
(
"Content-Disposition"
);
String
filename
=
null
;
if
(
contentHeader
!=
null
)
{
HeaderElement
[]
values
=
contentHeader
.
getElements
();
if
(
values
.
length
==
1
)
{
NameValuePair
param
=
values
[
0
].
getParameterByName
(
"filename"
);
if
(
param
!=
null
)
{
try
{
//filename = new String(param.getValue().toString().getBytes(), "utf-8");
//filename=URLDecoder.decode(param.getValue(),"utf-8");
filename
=
param
.
getValue
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
}
return
filename
;
}
/**
* 获取随机文件名
*
* @return
*/
public
static
String
getRandomFileName
()
{
return
String
.
valueOf
(
System
.
currentTimeMillis
());
}
public
static
void
outHeaders
(
HttpResponse
response
)
{
Header
[]
headers
=
response
.
getAllHeaders
();
for
(
int
i
=
0
;
i
<
headers
.
length
;
i
++)
{
System
.
out
.
println
(
headers
[
i
]);
}
}
public
static
void
main
(
String
[]
args
)
{
String
zip
=
"http://192.168.1.140:8090/api/download/"
;
String
text
=
"http://192.168.1.140:8090/api/download/txt"
;
String
docx
=
"http://192.168.1.140:8090/api/download/docx"
;
String
pdf
=
"http://192.168.1.140:8090/api/download/pdf"
;
String
xlsx
=
"http://192.168.1.140:8090/api/download/xlsx"
;
String
filepath
=
"C:\\Users\\key\\Desktop\\ideaIU-2019.3.3"
;
HttpDownload
.
download
(
xlsx
,
filepath
);
}
}
jz-dm-apigateway/src/main/java/com/jz/dm/config/SentinelConfig.java
0 → 100644
View file @
6b616132
package
com
.
jz
.
dm
.
config
;
import
com.alibaba.csp.sentinel.annotation.aspectj.SentinelResourceAspect
;
import
com.alibaba.csp.sentinel.slots.block.RuleConstant
;
import
com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule
;
import
com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager
;
import
com.alibaba.csp.sentinel.slots.block.flow.FlowRule
;
import
com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
javax.annotation.PostConstruct
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* @author ZC
* @PACKAGE_NAME: com.jz.dm.config
* @PROJECT_NAME: jz-dm-parent
* @NAME: SentinelConfig
* @DATE: 2021-1-7/15:57
* @DAY_NAME_SHORT: 周四
* @Description: 限流熔断初始化配置
**/
@Configuration
public
class
SentinelConfig
{
@Bean
public
SentinelResourceAspect
sentinelResourceAspect
()
{
return
new
SentinelResourceAspect
();
}
/**
* 默认最大请求数
*/
@Value
(
"${sentinel.request.max}"
)
private
Integer
defaultMaxRequest
;
/**
* 限流/熔断资源配置
*/
@Value
(
"${sentinel.resource}"
)
private
String
limitSource
;
@PostConstruct
private
void
initFlowRules
()
{
List
<
FlowRule
>
rules
=
new
ArrayList
<>();
FlowRule
rule
=
new
FlowRule
();
rule
.
setResource
(
limitSource
);
rule
.
setGrade
(
RuleConstant
.
FLOW_GRADE_QPS
);
rule
.
setCount
(
defaultMaxRequest
);
//每秒中可以有多少个请求
rules
.
add
(
rule
);
FlowRuleManager
.
loadRules
(
rules
);
//降级规则,可以多个degradeRule rule
//DegradeRuleManager.getRules()可以获取到已经设置的降级规则
List
<
DegradeRule
>
degradeRules
=
new
ArrayList
<>();
DegradeRule
degradeRule
=
new
DegradeRule
();
//设置资源名称,sentinel降级都是以资源为单位进行
degradeRule
.
setResource
(
limitSource
);
//使用异常统计降级,分钟统计,滑动时间窗口
degradeRule
.
setGrade
(
RuleConstant
.
DEGRADE_GRADE_EXCEPTION_COUNT
);
//异常数达到的数量阈值
degradeRule
.
setCount
(
defaultMaxRequest
);
//秒级时间窗口,该值必须有且必须大于零,否则降级将无法生效
degradeRule
.
setTimeWindow
(
1
);
degradeRules
.
add
(
degradeRule
);
//重新加载限流规则,此处将覆盖原有的限流,所以如果想要不覆盖
//请使用DegradeRuleManager.getRules()获取到的加入到rules中
DegradeRuleManager
.
loadRules
(
degradeRules
);
}
}
jz-dm-apigateway/src/main/java/com/jz/dm/filter/AuthFilter.java
View file @
6b616132
package
com
.
jz
.
dm
.
filter
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jz.common.utils.HttpsUtils
;
import
com.jz.common.utils.RedisUtils
;
import
com.jz.dm.common.constant.Constants
;
import
com.jz.dm.common.constant.LoggingConstants
;
import
com.jz.dm.common.enums.GatewayResultCode
;
import
com.jz.dm.common.enums.apiInterface.ApiStatusEnum
;
import
com.jz.dm.common.enums.auth.AuthReqTypeEnum
;
import
com.jz.dm.common.enums.org.OrgStatusEnum
;
import
com.jz.dm.common.exception.GatewayException
;
import
com.jz.dm.common.util.DateUtil
;
...
...
@@ -51,9 +53,10 @@ public class AuthFilter extends AbstractFilter {
private
ApiInterfaceService
apiInterfaceService
;
@Autowired
private
RedisUtils
redisUtils
;
@Value
(
"${request.limit.max}"
)
private
Long
limit
;
@Autowired
private
HttpsUtils
httpUtils
;
@Value
(
"${data.bank.balanceUrl}"
)
private
String
balanceUrl
;
@Override
public
String
getFilterName
()
{
...
...
@@ -124,15 +127,23 @@ public class AuthFilter extends AbstractFilter {
throw
new
GatewayException
(
GatewayResultCode
.
ORG_STATE_EXCEPTION
);
}
//查询数据银行银行余额是否充足
getDataAmountResult
(
request
);
try
{
//记录请求次数(每天限制请求次数)
String
limitKey
=
request
.
getApiKey
()
+
LoggingConstants
.
AND_SPILT
+
authCode
;
String
reqKey
=
redisUtils
.
get
(
limitKey
);
long
timeOut
=
DateUtil
.
calculateNowResidueTime
();
long
timeOut
=
0
;
if
(
AuthReqTypeEnum
.
DAY
.
name
().
equals
(
authAuth
.
getReqType
())){
//按天
timeOut
=
DateUtil
.
calculateNowResidueTime
();
}
else
if
(
AuthReqTypeEnum
.
MONTH
.
name
().
equals
(
authAuth
.
getReqType
())){
//按月
timeOut
=
DateUtil
.
calculateNowMonthTime
();
}
else
if
(
AuthReqTypeEnum
.
YEAR
.
name
().
equals
(
authAuth
.
getReqType
())){
//按年
//暂时不支持年
}
if
(
null
!=
reqKey
)
{
Integer
value
=
Integer
.
valueOf
(
reqKey
);
if
(
value
>
limit
)
{
//超出最大请求次数
if
(
value
>
authAuth
.
getReqFrequency
()
)
{
//超出最大请求次数
throw
new
GatewayException
(
GatewayResultCode
.
REQUEST_LIMIT_EXCEPTION
);
}
else
if
(
value
<=
limit
)
{
}
else
if
(
value
<=
authAuth
.
getReqFrequency
()
)
{
redisUtils
.
delAndAdd
(
limitKey
,
limitKey
,
value
+
1
,
timeOut
);
}
}
else
{
...
...
@@ -160,4 +171,26 @@ public class AuthFilter extends AbstractFilter {
throw
new
GatewayException
(
GatewayResultCode
.
ILLEGAL_REQUEST
);
}
}
/**
* 按次调用检查余额是否充足
* @param request
*/
private
void
getDataAmountResult
(
GatewayRequest
request
)
{
JSONObject
params
=
JSONObject
.
parseObject
(
request
.
getParams
());
if
(
null
!=
params
){
JSONObject
pObject
=
new
JSONObject
();
pObject
.
put
(
"assetsId"
,
params
.
getInteger
(
"assetsId"
));
pObject
.
put
(
"userId"
,
params
.
getInteger
(
"userId"
));
pObject
.
put
(
"dataPrice"
,
params
.
getString
(
"dataPrice"
));
String
respResult
=
httpUtils
.
submitPost
(
balanceUrl
,
pObject
.
toString
());
JSONObject
result
=
JSONObject
.
parseObject
(
respResult
);
if
(
null
!=
result
){
if
(
200
!=
result
.
getInteger
(
"code"
)){
log
.
info
(
"~~~~~~~~~~~~~~~~~~异常信息为:{}"
,
result
.
getString
(
"message"
));
throw
new
GatewayException
(
GatewayResultCode
.
CALL_AMOUNT_NOT_ENOUGH
);
}
}
}
}
}
jz-dm-apigateway/src/main/java/com/jz/dm/filter/VerifySignFilter.java
View file @
6b616132
...
...
@@ -41,17 +41,19 @@ public class VerifySignFilter extends AbstractFilter {
protected
void
internalDoFilter
(
GatewayRequest
request
,
GatewayResponse
response
,
FilterChain
chain
)
{
try
{
//对签约参数进行字典排序
String
signParams
=
MapUtil
.
getSignValue
(
request
.
getApiKey
(),
request
.
getMethod
(),
request
.
getSignType
(),
String
.
valueOf
(
request
.
getTimestamp
()));
if
(
StringUtils
.
isNotBlank
(
signParams
)){
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
request
.
getParams
());
String
authCode
=
jsonObject
.
getString
(
"authCode"
);
//需要传入授权码
ApiAuth
apiAuthInfo
=
apiInterfaceService
.
getApiAuthInfo
(
request
.
getApiKey
(),
jsonObject
.
getString
(
"authCode"
)
);
ApiAuth
apiAuthInfo
=
apiInterfaceService
.
getApiAuthInfo
(
request
.
getApiKey
(),
authCode
);
if
(
null
==
apiAuthInfo
){
throw
new
GatewayException
(
GatewayResultCode
.
ILLEGAL_REQUEST
);
}
String
s
alt
=
Md5
.
encrypt
(
signParams
,
apiAuthInfo
.
getSalt
());
if
(!
request
.
getSign
().
equals
(
s
alt
)){
String
s
ign
=
Md5
.
encrypt
(
signParams
,
apiAuthInfo
.
getSalt
());
if
(!
request
.
getSign
().
equals
(
s
ign
)){
throw
new
GatewayException
(
GatewayResultCode
.
SIGN_ERROR
);
}
}
else
{
...
...
jz-dm-apigateway/src/main/java/com/jz/dm/models/domian/ApiAuth.java
View file @
6b616132
...
...
@@ -43,6 +43,17 @@ public class ApiAuth extends BaseObject implements Serializable {
*/
@TableField
(
"auth_type"
)
private
String
authType
;
/**
* 限制类型:DAY 按天,MONTH 按月, YEAR 按年
*/
@TableField
(
"req_type"
)
private
String
reqType
;
/**
* 限制次数
*/
@TableField
(
"req_frequency"
)
private
Long
reqFrequency
;
/**
* 授权码
...
...
jz-dm-apigateway/src/main/java/com/jz/dm/models/domian/ApiInterface.java
View file @
6b616132
...
...
@@ -108,6 +108,17 @@ public class ApiInterface extends BaseObject implements Serializable {
@TableField
(
"sign_type"
)
private
String
signType
;
/**
* 限制类型:DAY 按天,MONTH 按月, YEAR 按年
*/
@TableField
(
"req_type"
)
private
String
reqType
;
/**
* 限制次数
*/
@TableField
(
"req_frequency"
)
private
Long
reqFrequency
;
/**
* 超时时间
*/
...
...
jz-dm-apigateway/src/main/java/com/jz/dm/models/domian/ApiInterfaceFile.java
View file @
6b616132
...
...
@@ -64,5 +64,4 @@ public class ApiInterfaceFile extends BaseObject implements Serializable {
@TableField
(
"status"
)
private
String
status
;
}
jz-dm-apigateway/src/main/java/com/jz/dm/models/req/make/ApiInterfaceReq.java
View file @
6b616132
...
...
@@ -46,6 +46,12 @@ public class ApiInterfaceReq implements Serializable {
@NotNull
(
message
=
"超时时间不能为空"
)
public
String
timeout
;
@ApiModelProperty
(
value
=
"限制类型:DAY 按天,MONTH 按月, YEAR 按年"
,
required
=
true
)
@NotNull
(
message
=
"限制类型不能为空"
)
public
String
reqType
;
@ApiModelProperty
(
value
=
"限制次数"
,
required
=
true
)
public
Long
reqFrequency
;
@ApiModelProperty
(
value
=
"api描述"
,
required
=
false
)
public
String
apiFunction
;
...
...
jz-dm-apigateway/src/main/java/com/jz/dm/models/req/make/MakeDataBankApiReq.java
View file @
6b616132
...
...
@@ -40,10 +40,21 @@ public class MakeDataBankApiReq implements Serializable {
@NotNull
(
message
=
"输出类型不能为空"
)
public
String
outputType
;
@ApiModelProperty
(
value
=
"是否分页:"
,
required
=
fals
e
)
//
@NotNull(message = "是否分页不能为空")
@ApiModelProperty
(
value
=
"是否分页:"
,
required
=
tru
e
)
@NotNull
(
message
=
"是否分页不能为空"
)
public
Boolean
page
;
@ApiModelProperty
(
value
=
"限制类型:DAY 按天,MONTH 按月"
,
required
=
true
)
@NotNull
(
message
=
"限制类型不能为空"
)
public
String
reqType
;
@ApiModelProperty
(
value
=
"文件id"
,
required
=
true
)
@NotNull
(
message
=
"文件id不能为空"
)
public
Long
fileId
;
@ApiModelProperty
(
value
=
"限制次数"
,
required
=
true
)
public
Long
reqFrequency
;
@ApiModelProperty
(
value
=
"请求地址"
,
required
=
false
)
public
String
apiPath
;
...
...
@@ -74,9 +85,7 @@ public class MakeDataBankApiReq implements Serializable {
@ApiModelProperty
(
value
=
"api样例"
,
required
=
false
)
public
String
apiExample
;
@ApiModelProperty
(
value
=
"文件id"
,
required
=
false
)
//@NotNull(message = "文件id不能为空")
public
Long
fileId
;
//-------------------------前端无效传参----------------------
//@ApiModelProperty(value = "状态",hidden = true)
...
...
jz-dm-apigateway/src/main/java/com/jz/dm/service/AuthService.java
View file @
6b616132
...
...
@@ -63,4 +63,11 @@ public interface AuthService {
* @return
*/
ApiAuth
getAuthUser
(
String
authCode
,
Long
apiId
);
/**
* 获取API授权信息
* @param authCode
* @return
*/
ApiAuth
getAuthInfo
(
String
authCode
);
}
jz-dm-apigateway/src/main/java/com/jz/dm/service/impl/ApiInterfaceServiceImpl.java
View file @
6b616132
package
com
.
jz
.
dm
.
service
.
impl
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.jz.dm.common.enums.apiInterface.ApiStatusEnum
;
import
com.jz.dm.mapper.ApiAuthMapper
;
import
com.jz.dm.mapper.ApiInterfaceMapper
;
import
com.jz.dm.models.domian.ApiAuth
;
...
...
@@ -69,6 +70,7 @@ public class ApiInterfaceServiceImpl implements ApiInterfaceService {
public
ApiInterface
getReqTargetInfo
(
String
apiKey
)
{
QueryWrapper
<
ApiInterface
>
query
=
new
QueryWrapper
<>();
query
.
eq
(
"api_key"
,
apiKey
);
query
.
eq
(
"status"
,
ApiStatusEnum
.
ISSUE
.
name
());
query
.
eq
(
"is_deleted"
,
0
);
return
apiInterfaceMapper
.
selectOne
(
query
);
}
...
...
jz-dm-apigateway/src/main/java/com/jz/dm/service/impl/ApiLogServiceImpl.java
View file @
6b616132
package
com
.
jz
.
dm
.
service
.
impl
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.jz.common.utils.Result
;
import
com.jz.dm.common.enums.GeneralStatusTypeEnum
;
import
com.jz.dm.config.ReentrantRedisLock
;
import
com.jz.dm.mapper.ApiReqLogMapper
;
import
com.jz.dm.models.domian.ApiReqLog
;
...
...
@@ -78,16 +80,23 @@ public class ApiLogServiceImpl implements ApiLogService {
@Override
public
void
updateLog
(
Long
id
,
JSONObject
jsonObject
)
{
try
{
ApiReqLog
apiReqLog
=
apiReqLogMapper
.
maxId
(
id
);
/*ApiReqLog apiReqLog = apiReqLogMapper.maxId(id);*/
ApiReqLog
apiReqLog
=
apiReqLogMapper
.
selectById
(
id
);
if
(
null
!=
apiReqLog
){
ApiReqLog
reqLog
=
new
ApiReqLog
();
reqLog
.
setId
(
apiReqLog
.
getId
());
reqLog
.
setStatus
(
apiReqLog
.
getStatus
());
reqLog
.
setResponseParams
(
jsonObject
.
toString
());
reqLog
.
setUpdateDate
(
new
Date
());
apiReqLogMapper
.
updateById
(
reqLog
);
UpdateWrapper
<
ApiReqLog
>
update
=
new
UpdateWrapper
<>();
if
(
200
==
jsonObject
.
getInt
(
"code"
)){
update
.
set
(
"status"
,
GeneralStatusTypeEnum
.
SUCCEED
);
}
else
{
log
.
info
(
"id为:{}"
,
id
+
"-----------------日志信息不存在"
);
update
.
set
(
"status"
,
GeneralStatusTypeEnum
.
FAIL
);
}
update
.
set
(
"response_params"
,
jsonObject
.
toString
());
update
.
set
(
"update_date"
,
new
Date
());
update
.
eq
(
"id"
,
id
);
if
(
apiReqLogMapper
.
update
(
null
,
update
)
==
0
){
log
.
info
(
"~~~~~~~~~~~更新日志信息失败~~~~~~~~"
);
}
}
else
{
log
.
info
(
"id为:{}"
,
id
+
"--------------日志信息不存在"
);
}
}
catch
(
Exception
ex
){
log
.
error
(
"更新日志返回信息异常:{}"
,
ex
.
getMessage
());
...
...
jz-dm-apigateway/src/main/java/com/jz/dm/service/impl/AuthServiceImpl.java
View file @
6b616132
...
...
@@ -189,6 +189,8 @@ public class AuthServiceImpl implements AuthService {
ApiAuth
apiAuth
=
new
ApiAuth
();
apiAuth
.
setApiInterfaceId
(
apiInterface
.
getId
());
apiAuth
.
setApiOrgId
(
apiOrg
.
getId
());
apiAuth
.
setReqType
(
apiInterface
.
getReqType
());
apiAuth
.
setReqFrequency
(
apiInterface
.
getReqFrequency
());
BeanUtils
.
copyProperties
(
req
,
apiAuth
);
//商城只有外部授权
String
authCode
=
""
;
...
...
@@ -274,8 +276,8 @@ public class AuthServiceImpl implements AuthService {
String
salt
=
RandomUtil
.
getStringRandom
(
8
);
UpdateWrapper
<
ApiAuth
>
update
=
new
UpdateWrapper
<>();
update
.
set
(
"salt"
,
salt
);
update
.
set
(
"
cre
ate_date"
,
new
Date
());
update
.
set
(
"
cre
ate_user"
,
""
);
update
.
set
(
"
upd
ate_date"
,
new
Date
());
update
.
set
(
"
upd
ate_user"
,
""
);
update
.
eq
(
"id"
,
apiAuth
.
getId
());
if
(
apiAuthMapper
.
update
(
null
,
update
)
>
0
)
{
response
.
setSalt
(
salt
);
...
...
@@ -299,6 +301,18 @@ public class AuthServiceImpl implements AuthService {
query
.
eq
(
"is_deleted"
,
0
);
return
apiAuthMapper
.
selectOne
(
query
);
}
/**
* 获取API授权信息
* @param authCode
* @return
*/
@Override
public
ApiAuth
getAuthInfo
(
String
authCode
)
{
QueryWrapper
<
ApiAuth
>
query
=
new
QueryWrapper
<>();
query
.
eq
(
"auth_code"
,
authCode
);
query
.
eq
(
"is_deleted"
,
0
);
return
apiAuthMapper
.
selectOne
(
query
);
}
private
ApiInterface
getInterface
(
String
apiKey
)
{
QueryWrapper
<
ApiInterface
>
queryInface
=
new
QueryWrapper
<>();
...
...
jz-dm-apigateway/src/main/java/com/jz/dm/service/impl/ProducerServiceImpl.java
View file @
6b616132
...
...
@@ -38,6 +38,7 @@ import javax.annotation.Resource;
import
java.util.*
;
import
static
com
.
jz
.
dm
.
common
.
enums
.
apiInterface
.
ApiStatusEnum
.
fromApiStatusName
;
import
static
com
.
jz
.
dm
.
common
.
enums
.
auth
.
AuthReqTypeEnum
.
fromAuthReqTypeEnum
;
/**
* @author ZC
...
...
@@ -133,6 +134,11 @@ public class ProducerServiceImpl implements ProducerService {
!
req
.
getOutputType
().
contains
(
ApiInfoOutTypeEnum
.
FLOW
.
name
())
)){
return
Result
.
of_error
(
"输出类型不存在!"
);
}
if
(
StringUtils
.
isNotBlank
(
req
.
getReqType
())
){
if
(
null
==
fromAuthReqTypeEnum
(
req
.
getReqType
())){
return
Result
.
of_error
(
"限制类型不存在!"
);
}
}
String
apiKey
=
""
;
if
(
StringUtils
.
isNotBlank
(
req
.
getJoinType
())
&&
"10006"
.
equals
(
req
.
getJoinType
()))
{
//数据银行制作API
...
...
@@ -263,6 +269,11 @@ public class ProducerServiceImpl implements ProducerService {
if
(
null
==
currentUser
)
{
return
Result
.
of_error
(
"用户信息不存在"
);
}
if
(
StringUtils
.
isNotBlank
(
req
.
getReqType
())
){
if
(
null
==
fromAuthReqTypeEnum
(
req
.
getReqType
())){
return
Result
.
of_error
(
"限制类型不存在!"
);
}
}
QueryWrapper
<
ApiInterfaceFile
>
query
=
new
QueryWrapper
<>();
query
.
eq
(
"project_id"
,
req
.
getProjectId
());
query
.
eq
(
"parent_id"
,
req
.
getParentId
());
...
...
@@ -329,6 +340,11 @@ public class ProducerServiceImpl implements ProducerService {
if
(
StringUtils
.
isBlank
(
req
.
getSignType
())
||
"0"
.
equals
(
req
.
getSignType
()))
{
return
Result
.
of_error
(
"加密类型错误!"
);
}
if
(
StringUtils
.
isNotBlank
(
req
.
getReqType
())
){
if
(
null
==
fromAuthReqTypeEnum
(
req
.
getReqType
())){
return
Result
.
of_error
(
"限制类型不存在!"
);
}
}
apiInterface
.
setApiType
(
req
.
getApiType
());
apiInterface
.
setApiDesc
(
req
.
getApiDesc
());
apiInterface
.
setJoinType
(
req
.
getJoinType
());
...
...
jz-dm-apigateway/src/main/java/com/jz/dm/service/request/ApiParamVerify.java
0 → 100644
View file @
6b616132
package
com
.
jz
.
dm
.
service
.
request
;
import
com.jz.common.constant.ResultMsg
;
import
com.jz.common.utils.Result
;
import
com.jz.dm.common.enums.GeneralStatusTypeEnum
;
import
com.jz.dm.common.enums.apiInterface.ApiStatusEnum
;
import
com.jz.dm.common.exception.GatewayException
;
import
com.jz.dm.models.domian.ApiAuth
;
import
com.jz.dm.models.domian.ApiInterface
;
/**
* @author ZC
* @PACKAGE_NAME: com.jz.dm.service.request
* @PROJECT_NAME: jz-dm-parent
* @NAME: ApiParamVerify
* @DATE: 2021-1-9/15:53
* @DAY_NAME_SHORT: 周六
* @Description: api参数验证
**/
public
class
ApiParamVerify
{
/**
* 校验Api信息
* @param apiInterface
* @return
*/
public
Result
verifyApiInterface
(
ApiInterface
apiInterface
){
if
(
null
==
apiInterface
){
throw
new
GatewayException
(
"300"
,
ResultMsg
.
DATA_NOT_FOUND
.
getMsg
());
}
if
(!
ApiStatusEnum
.
ISSUE
.
name
().
equals
(
apiInterface
.
getStatus
())){
throw
new
GatewayException
(
"300"
,
"API未发布!"
);
}
if
(
1
==
apiInterface
.
getIsDeleted
()){
throw
new
GatewayException
(
"300"
,
"API不存在!"
);
}
return
Result
.
of_success
(
ResultMsg
.
SUCCESS
);
}
/**
* 校验授权
* @param apiAuth
* @return
*/
public
Result
verifyAuth
(
ApiAuth
apiAuth
){
if
(
null
==
apiAuth
){
throw
new
GatewayException
(
"300"
,
ResultMsg
.
DATA_NOT_FOUND
.
getMsg
());
}
if
(!
GeneralStatusTypeEnum
.
VALID
.
name
().
equals
(
apiAuth
.
getStatus
())){
throw
new
GatewayException
(
"300"
,
"无效授权!"
);
}
if
(
1
==
apiAuth
.
getIsDeleted
()){
throw
new
GatewayException
(
"300"
,
"授权信息无效!"
);
}
return
Result
.
of_success
(
ResultMsg
.
SUCCESS
);
}
}
jz-dm-apigateway/src/main/java/com/jz/dm/service/request/ApiQueryService.java
View file @
6b616132
package
com
.
jz
.
dm
.
service
.
request
;
import
com.alibaba.csp.sentinel.annotation.SentinelResource
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jz.common.utils.HttpsUtils
;
import
com.jz.common.utils.RedisUtils
;
import
com.jz.dm.common.constant.LoggingConstants
;
import
com.jz.dm.common.enums.GatewayResultCode
;
import
com.jz.dm.common.enums.apiInterface.ApiInfoOutTypeEnum
;
import
com.jz.dm.common.enums.auth.AuthModeEnum
;
import
com.jz.dm.common.exception.GatewayException
;
import
com.jz.dm.common.util.OpenApiRequest
;
import
com.jz.dm.common.util.OpenApiResponse
;
import
com.jz.dm.common.util.stream.HttpDownload
;
import
com.jz.dm.gateway.OpenApiService
;
import
com.jz.dm.models.domian.ApiAuth
;
import
com.jz.dm.models.domian.ApiInterface
;
import
com.jz.dm.service.ApiInterfaceService
;
import
com.jz.dm.service.AuthService
;
import
com.jz.dm.web.annotation.AccessLimit
;
import
com.jz.dm.web.annotation.ApiLogAspect
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
@@ -33,7 +40,8 @@ import java.util.Map;
**/
@Service
(
"apiQueryService"
)
@Slf4j
public
class
ApiQueryService
implements
OpenApiService
{
public
class
ApiQueryService
extends
ApiParamVerify
implements
OpenApiService
{
@Override
public
String
getOpenApiMethod
()
{
return
"query"
;
...
...
@@ -47,94 +55,66 @@ public class ApiQueryService implements OpenApiService {
@Autowired
private
ApiInterfaceService
apiInterfaceService
;
@Autowired
private
AuthService
authService
;
@Autowired
private
RedisUtils
redisUtils
;
@Autowired
private
HttpsUtils
httpsUtils
;
@Value
(
"${data.bank.withholdUrl}"
)
private
String
withholdUrl
;
/**
* API请求逻辑处理
*
* @param request
* @param response
*/
@Override
@ApiLogAspect
(
description
=
"API请求日志"
)
@AccessLimit
(
limit
=
10000
,
sec
=
1
)
@SentinelResource
(
value
=
"api.gateway"
,
fallback
=
"fallbackGateway"
)
@Transactional
(
rollbackFor
=
Exception
.
class
,
propagation
=
Propagation
.
REQUIRES_NEW
)
public
void
doService
(
OpenApiRequest
request
,
OpenApiResponse
response
)
{
JSONObject
parameter
=
JSONObject
.
parseObject
(
request
.
getOpenApiParams
());
String
selectType
=
parameter
.
getString
(
"selectType"
);
String
authCode
=
parameter
.
getString
(
"authCode"
);
if
(
StringUtils
.
isBlank
(
authCode
))
{
throw
new
GatewayException
(
GatewayResultCode
.
ILLEGAL_REQUEST
);
}
verifyApiInterface
(
apiInterfaceService
.
getApiInfo
(
request
.
getApiKey
()));
ApiAuth
apiAuth
=
authService
.
getAuthInfo
(
authCode
);
verifyAuth
(
apiAuth
);
String
reqParams
=
parameter
.
getString
(
"reqParams"
);
Map
paramMap
=
null
;
if
(
null
!=
reqParams
&&
reqParams
.
length
()
>
0
)
{
Map
paramMap
=
null
;
if
(
StringUtils
.
isNotBlank
(
reqParams
)
)
{
paramMap
=
(
Map
)
JSONObject
.
parseObject
(
reqParams
);
}
String
apiInterface
=
redisUtils
.
get
(
request
.
getApiKey
());
if
(
StringUtils
.
isNotBlank
(
selectType
))
{
//取出缓存数据
String
redisReqParam
=
redisUtils
.
get
(
request
.
getApiKey
());
boolean
bResult
=
false
;
try
{
switch
(
selectType
)
{
case
"10001"
:
//实时接入查询
break
;
case
"10003"
:
//标签查询
break
;
case
"10002"
:
//大数据查询
if
(
StringUtils
.
isNotBlank
(
apiInterface
)){
//redis中存在
JSONObject
jsonBigData
=
JSONObject
.
parseObject
(
apiInterface
);
String
targetUrl
=
jsonBigData
.
getString
(
"targetUrl"
);
rangRequestTarget
(
ApiInfoOutTypeEnum
.
JSON
.
name
(),
targetUrl
,
paramMap
,
response
);
}
else
{
//缓存中不存在 查询数据库
ApiInterface
apiInfo
=
apiInterfaceService
.
getApiInfo
(
request
.
getApiKey
());
if
(
apiInfo
==
null
){
throw
new
GatewayException
(
GatewayResultCode
.
REQUEST_INFO_UNEXIST
);
}
rangRequestTarget
(
ApiInfoOutTypeEnum
.
JSON
.
name
(),
apiInfo
.
getTargetUrl
(),
paramMap
,
response
);
}
break
;
case
"10004"
:
//自定义查询(三方查询)
if
(
StringUtils
.
isNotBlank
(
apiInterface
)){
//redis中存在
JSONObject
jsonCustom
=
JSONObject
.
parseObject
(
apiInterface
);
String
targetUrl
=
jsonCustom
.
getString
(
"targetUrl"
);
rangRequestTarget
(
ApiInfoOutTypeEnum
.
JSON
.
name
(),
targetUrl
,
null
,
response
);
}
else
{
//redis中不存在,查询数据库
ApiInterface
apiReqDto
=
apiInterfaceService
.
getReqTargetInfo
(
request
.
getApiKey
());
if
(
null
==
apiReqDto
)
{
throw
new
GatewayException
(
GatewayResultCode
.
REQUEST_INFO_UNEXIST
);
}
rangRequestTarget
(
ApiInfoOutTypeEnum
.
JSON
.
name
(),
apiReqDto
.
getTargetUrl
(),
null
,
response
);
}
break
;
case
"10006"
:
//数据银行查询
if
(
StringUtils
.
isNotBlank
(
apiInterface
))
{
//redis中存在
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
apiInterface
);
if
(
StringUtils
.
isNotBlank
(
redisReqParam
))
{
//redis中存在
//解析出API制作成功时的参数配置
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
redisReqParam
);
String
targetUrl
=
jsonObject
.
getString
(
"targetUrl"
);
String
outputType
=
jsonObject
.
getString
(
"outputType"
);
rangRequestTarget
(
outputType
,
targetUrl
,
paramMap
,
response
);
bResult
=
rangRequestTarget
(
outputType
,
targetUrl
,
paramMap
,
response
);
}
else
{
//不存在查询数据库
ApiInterface
apiReqDto
=
apiInterfaceService
.
getReqTargetInfo
(
request
.
getApiKey
());
if
(
null
==
apiReqDto
)
{
throw
new
GatewayException
(
GatewayResultCode
.
REQUEST_INFO_UNEXIST
);
}
rangRequestTarget
(
apiReqDto
.
getOutputType
(),
apiReqDto
.
getTargetUrl
(),
paramMap
,
response
);
}
break
;
case
"10007"
:
//数据银行数据包查询
if
(
StringUtils
.
isNotBlank
(
apiInterface
)){
//从redis中获取数据
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
apiInterface
);
String
targetUrl
=
jsonObject
.
getString
(
"targetUrl"
);
String
outputType
=
jsonObject
.
getString
(
"outputType"
);
rangRequestTarget
(
outputType
,
targetUrl
,
paramMap
,
response
);
}
else
{
//不存在查询数据库
ApiInterface
apiReqDto
=
ApiInterface
apiInterface
=
apiInterfaceService
.
getReqTargetInfo
(
request
.
getApiKey
());
if
(
null
==
apiReqDto
)
{
if
(
null
==
apiInterface
)
{
throw
new
GatewayException
(
GatewayResultCode
.
REQUEST_INFO_UNEXIST
);
}
rangRequestTarget
(
apiReqDto
.
getOutputType
(),
apiReqDto
.
getTargetUrl
(),
paramMap
,
response
);
bResult
=
rangRequestTarget
(
apiInterface
.
getOutputType
(),
apiInterface
.
getTargetUrl
(),
paramMap
,
response
);
}
break
;
default
:
throw
new
GatewayException
(
GatewayResultCode
.
ILLEGAL_REQUEST
);
//调用成功请求数据银行扣款
if
(
AuthModeEnum
.
POWER_CALL_MODE
.
name
().
equals
(
apiAuth
.
getAuthMode
())){
notifierMinusMoney
(
parameter
,
bResult
);
}
}
catch
(
Exception
ex
)
{
if
(
ex
instanceof
GatewayException
)
{
throw
(
GatewayException
)
ex
;
if
(
ex
instanceof
GatewayException
)
{
throw
(
GatewayException
)
ex
;
}
log
.
error
(
"~~~~~~~~~~~~~~~请求api信息异常~~~~~~~~~~~~~"
);
log
.
error
(
"异常信息:{}"
,
ex
.
getMessage
());
...
...
@@ -142,17 +122,88 @@ public class ApiQueryService implements OpenApiService {
response
.
setMsg
(
GatewayResultCode
.
ILLEGAL_REQUEST
.
getMsg
());
}
}
}
private
void
rangRequestTarget
(
String
outputType
,
String
targetUrl
,
Map
<
String
,
String
>
param
,
OpenApiResponse
response
)
{
/**
* 远程请求获取数据
*
* @param outputType
* @param targetUrl
* @param param
* @param response
*/
private
boolean
rangRequestTarget
(
String
outputType
,
String
targetUrl
,
Map
<
String
,
String
>
param
,
OpenApiResponse
response
)
{
if
(
StringUtils
.
isBlank
(
outputType
))
{
outputType
=
ApiInfoOutTypeEnum
.
JSON
.
name
();
}
if
(
StringUtils
.
isBlank
(
targetUrl
))
{
throw
new
GatewayException
(
GatewayResultCode
.
ILLEGAL_REQUEST
);
}
if
(
ApiInfoOutTypeEnum
.
FLOW
.
name
().
equals
(
outputType
))
{
//文件流形式请求
// httpsUtils.doGetImg()TODO 流形式未实现
}
else
if
(
ApiInfoOutTypeEnum
.
JSON
.
name
().
equals
(
outputType
))
{
StringBuilder
builder
=
new
StringBuilder
();
builder
.
append
(
targetUrl
).
append
(
"?"
);
for
(
Map
.
Entry
<
String
,
String
>
entry
:
param
.
entrySet
())
{
String
key
=
entry
.
getKey
();
String
value
=
entry
.
getValue
();
builder
.
append
(
key
).
append
(
LoggingConstants
.
AND_EQUAL
)
.
append
(
value
).
append
(
LoggingConstants
.
AND_SPILT
);
}
String
baseUrl
=
builder
.
substring
(
0
,
builder
.
length
()
-
1
);
HttpDownload
.
download
(
baseUrl
);
response
.
setCode
(
GatewayResultCode
.
SUCCESS
.
getCode
());
response
.
setMsg
(
GatewayResultCode
.
SUCCESS
.
getMsg
());
return
true
;
}
else
if
(
ApiInfoOutTypeEnum
.
JSON
.
name
().
equals
(
outputType
))
{
//json格式请求
response
.
setAttribute
(
"调用成功!"
);
/*String respResult = httpsUtils.doGet(targetUrl, param);
response.setAttribute(respResult);*/
String
respResult
=
httpsUtils
.
doGet
(
targetUrl
,
param
);
JSONObject
resp
=
JSONObject
.
parseObject
(
respResult
);
if
(
null
!=
resp
&&
200
==
resp
.
getInteger
(
"code"
))
{
response
.
setCode
(
GatewayResultCode
.
SUCCESS
.
getCode
());
response
.
setMsg
(
GatewayResultCode
.
SUCCESS
.
getMsg
());
response
.
setAttribute
(
resp
.
getString
(
"data"
));
return
true
;
}
else
{
log
.
error
(
"~~~~~~~~~~~~~~~~远程请求异常~~~~~~~~~~~~~~~~~"
);
throw
new
GatewayException
(
GatewayResultCode
.
DISTANCE_REQUEST_EXCEPTION
);
}
}
else
{
throw
new
GatewayException
(
GatewayResultCode
.
OUTPUT_TYPE_EXCEPTION
);
}
}
/**
* 通知扣款
* @param parameter
* @param bResult
*/
private
void
notifierMinusMoney
(
JSONObject
parameter
,
boolean
bResult
)
{
Integer
assetsId
=
parameter
.
getInteger
(
"assetsId"
);
Integer
userId
=
parameter
.
getInteger
(
"userId"
);
String
dataPrice
=
parameter
.
getString
(
"dataPrice"
);
JSONObject
jsonReq
=
new
JSONObject
();
jsonReq
.
put
(
"assetsId"
,
assetsId
);
jsonReq
.
put
(
"userId"
,
userId
);
jsonReq
.
put
(
"dataPrice"
,
dataPrice
);
jsonReq
.
put
(
"callStatus"
,
bResult
);
//调用成功 扣款 false 调用失败,解冻金额
String
responseResult
=
httpsUtils
.
submitPost
(
withholdUrl
,
jsonReq
.
toString
());
JSONObject
paramsResult
=
JSONObject
.
parseObject
(
responseResult
);
if
(
null
!=
paramsResult
){
if
(
200
!=
paramsResult
.
getInteger
(
"code"
)){
log
.
info
(
"~~~~~~~~~~~~~~~调用数据银行扣款失败~~~~~~~~~~~~~"
);
throw
new
GatewayException
(
GatewayResultCode
.
CALL_AMOUNT_NOT_ENOUGH
);
}
}
}
/**
* 限流返回方法
*
* @param request
* @param response
*/
public
void
fallbackGateway
(
OpenApiRequest
request
,
OpenApiResponse
response
)
{
log
.
info
(
"用户请求过于频繁触发限流接口:ApiKey为:{}"
+
request
.
getApiKey
());
throw
new
GatewayException
(
GatewayResultCode
.
RATE_LIMIT_EXCEEDED
);
}
}
jz-dm-apigateway/src/main/java/com/jz/dm/web/aspect/SystemLogAspect.java
View file @
6b616132
...
...
@@ -4,7 +4,6 @@ package com.jz.dm.web.aspect;
import
com.jz.common.utils.IpUtils
;
import
com.jz.common.utils.JsonUtils
;
import
com.jz.common.utils.UrlUtil
;
import
com.jz.dm.common.enums.SignType
;
import
com.jz.dm.mapper.ApiReqLogMapper
;
import
com.jz.dm.models.domian.ApiReqLog
;
import
com.jz.dm.service.ApiLogService
;
...
...
@@ -17,7 +16,9 @@ import lombok.extern.slf4j.Slf4j;
import
net.sf.json.JSONObject
;
import
org.aspectj.lang.JoinPoint
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.annotation.*
;
import
org.aspectj.lang.annotation.Around
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.annotation.Pointcut
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
...
...
@@ -36,7 +37,7 @@ import java.util.Map;
* @NAME: SystemLogAspect
* @DATE: 2020-12-25/16:03
* @DAY_NAME_SHORT: 周五
* @Description:
* @Description:
日志收集
**/
@Aspect
...
...
@@ -85,28 +86,30 @@ public class SystemLogAspect {
log
.
info
(
"around请求参数为{}"
,
joinPoint
.
getArgs
());
//动态修改其参数
//注意,如果调用joinPoint.proceed()方法,则修改的参数值不会生效,必须调用joinPoint.proceed(Object[] args)
com
.
alibaba
.
fastjson
.
JSONObject
jsonObject
=
com
.
alibaba
.
fastjson
.
JSONObject
.
parseObject
(
params
);
String
paramsList
=
jsonObject
.
getString
(
"params"
);
com
.
alibaba
.
fastjson
.
JSONObject
jsonParamsList
=
com
.
alibaba
.
fastjson
.
JSONObject
.
parseObject
(
paramsList
);
try
{
ApiReqLog
reqLog
=
new
ApiReqLog
();
reqLog
.
setRequestIp
(
ip
);
//
reqLog.setApiKey(jsonObject.getString("apiKey"));
reqLog
.
setApiKey
(
jsonObject
.
getString
(
"apiKey"
));
reqLog
.
setRequestParams
(
params
);
reqLog
.
setResponseParams
(
""
);
//响应参数
reqLog
.
setRequestUrl
(
url
);
reqLog
.
setRequestMethod
(
contextPath
);
reqLog
.
setEncryMode
(
SignType
.
MD5
.
name
(
));
//加密方式:MD5,RSA
reqLog
.
setEncryMode
(
jsonObject
.
getString
(
"signType"
));
//加密方式:MD5,RSA
reqLog
.
setTransMode
(
request
.
getMethod
());
//传输方式 GET POST
// reqLog.setRequestToken(token
);
reqLog
.
setRequestToken
(
jsonParamsList
.
getString
(
"authCode"
)
);
reqLog
.
setRequestTime
(
new
Date
());
reqLog
.
setRemark
(
getServiceMethodDescription
(
joinPoint
));
System
.
out
.
println
(
reqLog
);
log
.
info
(
"请求参数:"
,
reqLog
);
if
(
null
!=
reqLog
)
{
apiReqLogMapper
.
insert
(
reqLog
);
}
Object
result
=
joinPoint
.
proceed
(
joinPoint
.
getArgs
());
JSONObject
json
Objec
t
=
JSONObject
.
fromObject
(
result
);
log
.
info
(
"around响应结果为{}"
,
json
Objec
t
);
apiLogService
.
updateLog
(
reqLog
.
getId
(),
json
Objec
t
);
JSONObject
json
Resul
t
=
JSONObject
.
fromObject
(
result
);
log
.
info
(
"around响应结果为{}"
,
json
Resul
t
);
apiLogService
.
updateLog
(
reqLog
.
getId
(),
json
Resul
t
);
}
catch
(
Throwable
throwable
)
{
throwable
.
printStackTrace
();
}
...
...
jz-dm-apigateway/src/main/java/com/jz/dm/web/interceptor/AccessLimitInterceptor.java
View file @
6b616132
package
com
.
jz
.
dm
.
web
.
interceptor
;
import
com.jz.common.utils.IpUtils
;
import
com.jz.common.utils.RedisUtils
;
import
com.jz.dm.web.annotation.AccessLimit
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.method.HandlerMethod
;
import
org.springframework.web.servlet.HandlerInterceptor
;
import
org.springframework.web.servlet.ModelAndView
;
...
...
@@ -19,13 +21,12 @@ import java.lang.reflect.Method;
* @NAME: AccessLimitInterceptor
* @DATE: 2020-12-26/17:39
* @DAY_NAME_SHORT: 周六
* @Description:
* @Description:
使用redis限流
**/
public
class
AccessLimitInterceptor
implements
HandlerInterceptor
{
//使用RedisTemplate操作redis
/* @Autowired
private RedisTemplate<String, Integer> redisTemplate;*/
@Autowired
private
RedisUtils
redisUtils
;
@Override
public
boolean
preHandle
(
HttpServletRequest
request
,
...
...
@@ -44,16 +45,17 @@ public class AccessLimitInterceptor implements HandlerInterceptor {
int
limit
=
accessLimit
.
limit
();
int
sec
=
accessLimit
.
sec
();
String
key
=
IpUtils
.
getIpAddr
(
request
)
+
request
.
getRequestURI
();
/*Integer maxLimit = redisTemplate.opsForValue().get(key);
String
result
=
redisUtils
.
get
(
key
);
Integer
maxLimit
=
Integer
.
valueOf
(
result
);
if
(
maxLimit
==
null
)
{
//set时一定要加过期时间
redis
Template.opsForValue().set(key, 1, sec, TimeUnit.SECONDS
);
redis
Utils
.
set
(
key
,
1
,
sec
);
}
else
if
(
maxLimit
<
limit
)
{
redis
Template.opsForValue().set(key, maxLimit + 1, sec, TimeUnit.SECONDS
);
redis
Utils
.
set
(
key
,
maxLimit
+
1
,
sec
);
}
else
{
output
(
response
,
"请求太频繁~!"
);
return
false
;
}
*/
}
}
return
true
;
}
...
...
jz-dm-apigateway/src/main/resources/application-test.yml
View file @
6b616132
...
...
@@ -77,6 +77,22 @@ dmp:
timeout
:
default
:
5000
max
:
5000
request
:
#api请求次数
limit
:
max
:
10
#流处理配置
windows
:
#文件流输出地址设置
name
:
stream
isWindows
:
true
#sentinel限流配置
sentinel
:
#sentinel每秒中最大的请求个数
resource
:
api.gateway
request
:
max
:
100
#数据银行调用配置
data
:
bank
:
balanceUrl
:
http://localhost:8081/mall/financeCustomerAssets/findAssets
#余额信息url
withholdUrl
:
http://localhost:8081/mall/financeCustomerAssets/unfreezeMoney
#扣款信通知url
jz-dm-apigateway/src/main/resources/application.yml
View file @
6b616132
...
...
@@ -19,7 +19,21 @@ spring:
max-request-size
:
50MB
profiles
:
active
:
test
#默认使用的配置文件
cloud
:
sentinel
:
#sentinel 限流框架配置
transport
:
# 项目本地会启动一个服务的端口号,默认8719,用于与sentinel-dashboard通讯
port
:
8719
# sentinel-dashboard服务地址 # sentinel-dashboard-1.6.0 的访问路径 ,启动方式java -jar sentinel-dashboard-1.6.0.jar
dashboard
:
localhost:9090
filter
:
# 需要进行限流监控的接口,多个匹配用逗号隔开
url-patterns
:
/*
servlet
:
# 触发限流后重定向的页面
block-page
:
/sentinel/block
#取消Sentinel控制台懒加载
#eager: true
# ====================MybatisPlus====================
mybatis-plus
:
...
...
jz-dm-apigateway/src/test/java/com/jz/dm/gateway/api/ApiReqTest.java
0 → 100644
View file @
6b616132
package
com
.
jz
.
dm
.
gateway
.
api
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jz.common.utils.HttpsUtils
;
import
com.jz.dm.common.util.MapUtil
;
import
com.jz.dm.common.util.Md5
;
import
com.jz.dm.gateway.SpringTestCase
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
/**
* @author ZC
* @PACKAGE_NAME: com.jz.dm.gateway.api
* @PROJECT_NAME: jz-dm-parent
* @NAME: ApiReqTest
* @DATE: 2021-1-6/14:13
* @DAY_NAME_SHORT: 周三
* @Description:
**/
public
class
ApiReqTest
extends
SpringTestCase
{
public
static
final
String
url
=
""
;
@Autowired
private
HttpsUtils
httpsUtils
;
@Test
public
void
TestGatewayReq
()
{
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"apiKey"
,
"9jNA1W5Ydn7Stp12"
);
jsonObject
.
put
(
"method"
,
"query"
);
jsonObject
.
put
(
"signType"
,
"MD5"
);
long
time
=
System
.
currentTimeMillis
();
jsonObject
.
put
(
"timestamp"
,
"1609919983045"
);
JSONObject
params
=
new
JSONObject
();
params
.
put
(
"authCode"
,
"20200000000221231111455Jg8ug1621"
);
params
.
put
(
"selectType"
,
"10006"
);
params
.
put
(
"reqParams"
,
new
JSONObject
());
jsonObject
.
put
(
"params"
,
params
);
try
{
String
apiKey
=
jsonObject
.
getString
(
"apiKey"
);
String
method
=
jsonObject
.
getString
(
"method"
);
String
signType
=
jsonObject
.
getString
(
"signType"
);
String
timestamp
=
jsonObject
.
getString
(
"timestamp"
);
String
signature
=
MapUtil
.
getSignValue
(
apiKey
,
method
,
signType
,
timestamp
);
String
salt
=
Md5
.
encrypt
(
signature
,
"OOmeF1gh"
);
jsonObject
.
put
(
"sign"
,
salt
);
String
response
=
httpsUtils
.
submitPost
(
url
,
jsonObject
.
toString
());
System
.
out
.
println
(
response
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
jz-dm-apigateway/src/test/java/com/jz/dm/gateway/org/TestOrganizationManage.java
View file @
6b616132
...
...
@@ -10,7 +10,6 @@ import com.jz.dm.models.req.organizationManage.OrganizationManageDetailQueryReq;
import
com.jz.dm.models.req.organizationManage.OrganizationManageListQueryReq
;
import
com.jz.dm.models.req.organizationManage.OrganizationManageUpdateReq
;
import
com.jz.dm.service.OrganizationManageService
;
import
org.junit.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
/**
...
...
@@ -30,7 +29,7 @@ public class TestOrganizationManage extends SpringTestCase {
/**
* 查询类列表信息
*/
@Test
//
@Test
public
void
getOrgList
(){
OrganizationManageListQueryReq
req
=
new
OrganizationManageListQueryReq
();
req
.
setPageNum
(
1
);
...
...
@@ -41,7 +40,7 @@ public class TestOrganizationManage extends SpringTestCase {
/**
* 查询详情信息
*/
@Test
//
@Test
public
void
getOrgDetail
(){
OrganizationManageDetailQueryReq
req
=
new
OrganizationManageDetailQueryReq
();
req
.
setId
(
1L
);
...
...
@@ -52,7 +51,7 @@ public class TestOrganizationManage extends SpringTestCase {
/**
* 添加组织信息
*/
@Test
//
@Test
public
void
addOrg
(){
OrganizationManageAddReq
req
=
new
OrganizationManageAddReq
();
req
.
setOrgName
(
"数据银行"
);
...
...
@@ -69,7 +68,7 @@ public class TestOrganizationManage extends SpringTestCase {
/**
* 更新组织信息
*/
@Test
//
@Test
public
void
updateOrg
(){
OrganizationManageUpdateReq
req
=
new
OrganizationManageUpdateReq
();
req
.
setId
(
8L
);
...
...
jz-dm-apigateway/src/test/java/com/jz/dm/gateway/orther/TestAmountCall.java
0 → 100644
View file @
6b616132
package
com
.
jz
.
dm
.
gateway
.
orther
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jz.common.utils.HttpsUtils
;
import
com.jz.dm.common.enums.GatewayResultCode
;
import
com.jz.dm.common.exception.GatewayException
;
import
com.jz.dm.gateway.SpringTestCase
;
import
org.junit.jupiter.api.Test
;
/**
* @author ZC
* @PACKAGE_NAME: com.jz.dm.gateway.orther
* @PROJECT_NAME: jz-dm-parent
* @NAME: TestAmountCall
* @DATE: 2021-1-9/15:04
* @DAY_NAME_SHORT: 周六
* @Description:
**/
public
class
TestAmountCall
extends
SpringTestCase
{
private
static
final
String
baseUrl
=
"http://192.168.1.139:8081/mall/financeCustomerAssets/findAssets"
;
private
static
final
String
baseUrl2
=
"http://192.168.1.139:8081/mall/financeCustomerAssets/unfreezeMoney"
;
/* @Autowired
private HttpsUtils httpUtils;*/
@Test
public
void
TestDataBankReq
(){
HttpsUtils
utils
=
new
HttpsUtils
();
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"assetsId"
,
1
);
jsonObject
.
put
(
"userId"
,
1
);
jsonObject
.
put
(
"dataPrice"
,
"50"
);
String
respResult
=
utils
.
submitPost
(
baseUrl
,
jsonObject
.
toString
());
JSONObject
paramsResult
=
JSONObject
.
parseObject
(
respResult
);
if
(
null
!=
paramsResult
){
Integer
code
=
paramsResult
.
getInteger
(
"code"
);
if
(
200
!=
code
){
System
.
out
.
println
(
"~~~~~~~~~~~~~~~~~~单次调用金额不足~~~~~~~~~~~~~~~"
);
System
.
out
.
println
(
respResult
);
throw
new
GatewayException
(
GatewayResultCode
.
CALL_AMOUNT_NOT_ENOUGH
);
}
else
{
System
.
out
.
println
(
paramsResult
.
getString
(
"message"
));
}
}
}
/**
* 通知扣款
*/
@Test
public
void
notifierDataBankReq
(){
HttpsUtils
utils
=
new
HttpsUtils
();
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"assetsId"
,
1
);
jsonObject
.
put
(
"userId"
,
1
);
jsonObject
.
put
(
"dataPrice"
,
"50"
);
jsonObject
.
put
(
"callStatus"
,
true
);
//调用成功 扣款 false 调用失败,解冻金额
String
respResult
=
utils
.
submitPost
(
baseUrl2
,
jsonObject
.
toString
());
JSONObject
paramsResult
=
JSONObject
.
parseObject
(
respResult
);
if
(
null
!=
paramsResult
){
Integer
code
=
paramsResult
.
getInteger
(
"code"
);
if
(
200
!=
code
){
System
.
out
.
println
(
"~~~~~~~~~~~~~~~~~~操作失败~~~~~~~~~~~~~~~"
);
System
.
out
.
println
(
respResult
);
throw
new
GatewayException
(
GatewayResultCode
.
CALL_AMOUNT_NOT_ENOUGH
);
}
else
{
System
.
out
.
println
(
paramsResult
.
getString
(
"message"
));
}
}
}
}
jz-dm-apigateway/src/test/java/com/jz/dm/gateway/orther/TestHttpReq.java
View file @
6b616132
...
...
@@ -3,7 +3,7 @@ package com.jz.dm.gateway.orther;
import
com.alibaba.fastjson.JSONObject
;
import
com.jz.common.utils.HttpsUtils
;
import
com.jz.dm.gateway.SpringTestCase
;
import
org.junit.Test
;
import
org.junit.
jupiter.api.
Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
java.util.HashMap
;
...
...
jz-dm-apigateway/src/test/java/com/jz/dm/gateway/orther/TestMakeApi.java
View file @
6b616132
...
...
@@ -4,7 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import
com.jz.common.utils.HttpsUtils
;
import
com.jz.dm.gateway.SpringTestCase
;
import
com.jz.dm.service.ProducerService
;
import
org.junit.Test
;
import
org.junit.
jupiter.api.
Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
java.util.HashMap
;
...
...
jz-dm-apigateway/src/test/java/com/jz/dm/gateway/orther/TestRedisUserSave.java
View file @
6b616132
...
...
@@ -2,7 +2,7 @@ package com.jz.dm.gateway.orther;
import
com.jz.dm.common.base.BaseCurrentUserObject
;
import
com.jz.dm.gateway.SpringTestCase
;
import
org.junit.Test
;
import
org.junit.
jupiter.api.
Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.RedisTemplate
;
...
...
jz-dm-apigateway/src/test/java/com/jz/dm/gateway/orther/TestStreamReq.java
0 → 100644
View file @
6b616132
package
com
.
jz
.
dm
.
gateway
.
orther
;
import
com.jz.dm.gateway.SpringTestCase
;
import
lombok.extern.slf4j.Slf4j
;
import
static
com
.
jz
.
dm
.
common
.
util
.
stream
.
HttpDownload
.
download
;
/**
* @author ZC
* @PACKAGE_NAME: com.jz.dm.gateway.orther
* @PROJECT_NAME: jz-dm-parent
* @NAME: TestStreamReq
* @DATE: 2021-1-7/16:51
* @DAY_NAME_SHORT: 周四
* @Description:
**/
@Slf4j
public
class
TestStreamReq
extends
SpringTestCase
{
private
static
final
String
baseUrl
=
"http://192.168.1.140:8090/api/download"
;
//@Test
public
void
testStreamReq
()
{
download
(
baseUrl
);
}
}
jz-dm-common/src/main/java/com/jz/common/utils/HttpsUtils.java
View file @
6b616132
...
...
@@ -195,15 +195,16 @@ public class HttpsUtils {
* @param url
* @throws IOException
*/
public
CloseableHttp
Client
doGetImg
(
String
url
)
{
public
CloseableHttp
Response
doGetImg
(
String
url
)
{
CloseableHttpClient
httpClient
=
getHttpClient
();
CloseableHttpResponse
response
=
null
;
HttpGet
httpGet
=
new
HttpGet
(
url
);
try
{
httpClient
.
execute
(
httpGet
);
response
=
httpClient
.
execute
(
httpGet
);
}
catch
(
IOException
e
)
{
log
.
error
(
"发起http request异常:{}"
,
e
);
}
return
httpClient
;
return
response
;
}
/**
...
...
jz-dm-manage/src/test/java/com/jz/manage/manageApplicationTests.java
deleted
100644 → 0
View file @
7dc8a4e0
package
com
.
jz
.
manage
;
import
com.jz.common.utils.DateUtils
;
import
com.jz.manage.moduls.controller.goods.bean.request.DataApiUpReq
;
import
com.jz.manage.moduls.entity.DataGoodsApiParams
;
import
com.jz.manage.moduls.service.DataGoodsService
;
import
com.jz.manage.moduls.service.SysUserService
;
import
com.jz.manage.moduls.service.TestUserService
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
java.math.BigDecimal
;
import
java.util.ArrayList
;
import
java.util.List
;
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
public
class
manageApplicationTests
{
@Autowired
private
TestUserService
userService
;
@Autowired
private
SysUserService
sysUserService
;
@Autowired
private
DataGoodsService
dataGoodsService
;
@Test
public
void
contextLoads
()
{
}
@Test
public
void
aa
()
{
String
s
=
"2020-11-11-2020-11-12"
;
String
substring
=
s
.
substring
(
0
,
10
);
String
substring1
=
s
.
substring
(
11
,
21
);
System
.
out
.
println
(
substring
);
System
.
out
.
println
(
substring1
);
}
}
pom.xml
View file @
6b616132
...
...
@@ -46,7 +46,7 @@
<springfox-swagger2.version>
2.9.2
</springfox-swagger2.version>
<swagger-bootstrap-ui.version>
1.9.6
</swagger-bootstrap-ui.version>
<lombok.version>
1.18.16
</lombok.version>
<
commons-net.version>
3.6
</commons-net
.version>
<
spring-cloud.version>
Finchley.SR1
</spring-cloud
.version>
</properties>
<dependencyManagement>
...
...
@@ -67,6 +67,22 @@
<scope>
import
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-dependencies
</artifactId>
<version>
${spring-cloud.version}
</version>
<type>
pom
</type>
<scope>
import
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-alibaba-dependencies
</artifactId>
<version>
0.1.2.RELEASE
</version>
<type>
pom
</type>
<scope>
import
</scope>
</dependency>
<!-- fastjson -->
<dependency>
<groupId>
com.alibaba
</groupId>
...
...
@@ -111,17 +127,6 @@
<!-- ***************************************************************** -->
<!--<dependency>-->
<!--<groupId>org.apache.flume</groupId>-->
<!--<artifactId>flume-ng-core</artifactId>-->
<!--<version>1.5.0</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.apache.flume.flume-ng-clients</groupId>-->
<!--<artifactId>flume-ng-log4jappender</artifactId>-->
<!--<version>1.5.0</version>-->
<!--</dependency>-->
<!-- Netty -->
<dependency>
<groupId>
io.netty
</groupId>
...
...
@@ -211,11 +216,6 @@
<artifactId>
lombok
</artifactId>
<version>
${lombok.version}
</version>
</dependency>
<dependency>
<groupId>
commons-net
</groupId>
<artifactId>
commons-net
</artifactId>
<version>
${commons-net.version}
</version>
</dependency>
</dependencies>
</dependencyManagement>
...
...
@@ -226,58 +226,7 @@
<module>
jz-dm-apigateway
</module>
</modules>
<!-- <build>-->
<!-- <defaultGoal>compile</defaultGoal>-->
<!-- <finalName>${project.artifactId}</finalName>-->
<!-- <resources>-->
<!-- <resource>-->
<!-- <directory>src/main/resources</directory>-->
<!-- <filtering>true</filtering>-->
<!-- <excludes>-->
<!-- <exclude>disconf.properties</exclude>-->
<!-- </excludes>-->
<!-- </resource>-->
<!-- </resources>-->
<!-- <plugins>-->
<!-- <plugin>-->
<!-- <groupId>org.apache.maven.plugins</groupId>-->
<!-- <artifactId>maven-compiler-plugin</artifactId>-->
<!-- <version>2.3.2</version>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <id>default-compile</id>-->
<!-- <phase>compile</phase>-->
<!-- <goals>-->
<!-- <goal>compile</goal>-->
<!-- </goals>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- <configuration>-->
<!-- <source>1.8</source>-->
<!-- <target>1.8</target>-->
<!-- <encoding>UTF-8</encoding>-->
<!-- </configuration>-->
<!-- </plugin>-->
<!-- <plugin>-->
<!-- <groupId>org.apache.maven.plugins</groupId>-->
<!-- <artifactId>maven-resources-plugin</artifactId>-->
<!-- <version>2.5</version>-->
<!-- <configuration>-->
<!-- <encoding>UTF-8</encoding>-->
<!-- </configuration>-->
<!-- </plugin>-->
<!-- <plugin>-->
<!-- <groupId>org.apache.maven.plugins</groupId>-->
<!-- <artifactId>maven-eclipse-plugin</artifactId>-->
<!-- <version>2.8</version>-->
<!-- <configuration>-->
<!-- <downloadSources>true</downloadSources>-->
<!-- <downloadJavadocs>false</downloadJavadocs>-->
<!-- <wtpversion>2.0</wtpversion>-->
<!-- </configuration>-->
<!-- </plugin>-->
<!-- </plugins>-->
<!-- </build>-->
<build>
<finalName>
${project.artifactId}
</finalName>
<plugins>
...
...
@@ -292,4 +241,5 @@
</plugin>
</plugins>
</build>
</project>
\ 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