Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jz-dmp-service
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
姚本章
jz-dmp-service
Commits
4bfc8b2e
Commit
4bfc8b2e
authored
Jan 19, 2021
by
mcb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
no message
parent
0b6d8222
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
358 additions
and
15 deletions
+358
-15
DmpApiMangeController.java
...modules/controller/dataService/DmpApiMangeController.java
+92
-0
AuthUserApiReq.java
...p/modules/controller/dataService/bean/AuthUserApiReq.java
+42
-0
LogInfoListReq.java
...p/modules/controller/dataService/bean/LogInfoListReq.java
+23
-0
DmpApiMangeService.java
...n/java/com/jz/dmp/modules/service/DmpApiMangeService.java
+33
-1
DmpApiMangeServiceImpl.java
...m/jz/dmp/modules/service/impl/DmpApiMangeServiceImpl.java
+168
-14
No files found.
src/main/java/com/jz/dmp/modules/controller/dataService/DmpApiMangeController.java
View file @
4bfc8b2e
...
...
@@ -125,4 +125,96 @@ public class DmpApiMangeController {
}
return
jsonResult
;
}
/**
* 根据apiid获取API详情
*
* @author Bellamy
* @since 2021-01-19
*/
@ApiOperation
(
value
=
"获取API详情"
,
notes
=
"获取API详情"
)
@GetMapping
(
value
=
"/getApiInfo"
)
@ApiImplicitParam
(
name
=
"id"
,
value
=
"ApiId"
,
required
=
true
)
public
JsonResult
getApiInfoByApiId
(
@RequestParam
String
id
,
HttpServletRequest
httpRequest
)
{
if
(
StringUtils
.
isEmpty
(
id
))
{
return
JsonResult
.
error
(
ResultCode
.
PARAMS_ERROR
,
"apiId不能为空!"
);
}
JsonResult
jsonResult
=
new
JsonResult
();
try
{
jsonResult
=
dmpApiMangeService
.
queryApiInfoByApiId
(
id
);
}
catch
(
Exception
e
)
{
jsonResult
.
setMessage
(
e
.
getMessage
());
jsonResult
.
setCode
(
ResultCode
.
INTERNAL_SERVER_ERROR
);
e
.
printStackTrace
();
}
return
jsonResult
;
}
/**
* 授权给组织-提交保存
*
* @author Bellamy
* @since 2021-01-19
*/
@ApiOperation
(
value
=
"授权给组织-提交保存"
,
notes
=
"授权给组织-提交保存"
)
@PostMapping
(
value
=
"/addApiAuthToOrg"
)
public
JsonResult
addApiAuthToOrg
(
@RequestBody
@Validated
AuthUserApiReq
req
,
HttpServletRequest
httpRequest
)
{
JsonResult
jsonResult
=
new
JsonResult
();
try
{
jsonResult
=
dmpApiMangeService
.
addApiAuthToOrg
(
req
);
}
catch
(
Exception
e
)
{
jsonResult
.
setMessage
(
e
.
getMessage
());
jsonResult
.
setCode
(
ResultCode
.
INTERNAL_SERVER_ERROR
);
e
.
printStackTrace
();
}
return
jsonResult
;
}
/**
* API测试
*
* @author Bellamy
* @since 2021-01-19
*/
@ApiOperation
(
value
=
"API测试"
,
notes
=
"API测试"
)
@GetMapping
(
value
=
"/apiTestInfo"
)
@ApiImplicitParam
(
name
=
"apiKey"
,
value
=
"apiKey"
,
required
=
true
)
public
JsonResult
getApiTestInfo
(
@RequestParam
String
apiKey
,
HttpServletRequest
httpRequest
)
{
if
(
StringUtils
.
isEmpty
(
apiKey
))
{
return
JsonResult
.
error
(
ResultCode
.
PARAMS_ERROR
,
"apiKey不能为空!"
);
}
JsonResult
jsonResult
=
new
JsonResult
();
try
{
jsonResult
=
dmpApiMangeService
.
apiTestInfo
(
apiKey
);
}
catch
(
Exception
e
)
{
jsonResult
.
setMessage
(
e
.
getMessage
());
jsonResult
.
setCode
(
ResultCode
.
INTERNAL_SERVER_ERROR
);
e
.
printStackTrace
();
}
return
jsonResult
;
}
/**
* 查看日志
*
* @author Bellamy
* @since 2021-01-19
*/
@ApiOperation
(
value
=
"查看日志"
,
notes
=
"查看日志"
)
@PostMapping
(
value
=
"/checkApiLogInfo"
)
public
JsonResult
checkApiLogInfo
(
@RequestBody
LogInfoListReq
req
,
HttpServletRequest
httpRequest
)
{
if
(
StringUtils
.
isEmpty
(
req
.
getApiKey
()))
{
return
JsonResult
.
error
(
ResultCode
.
PARAMS_ERROR
,
"apiKey不能为空!"
);
}
JsonResult
jsonResult
=
new
JsonResult
();
try
{
jsonResult
=
dmpApiMangeService
.
checkApiLogInfo
(
req
);
}
catch
(
Exception
e
)
{
jsonResult
.
setMessage
(
e
.
getMessage
());
jsonResult
.
setCode
(
ResultCode
.
INTERNAL_SERVER_ERROR
);
e
.
printStackTrace
();
}
return
jsonResult
;
}
}
\ No newline at end of file
src/main/java/com/jz/dmp/modules/controller/dataService/bean/AuthUserApiReq.java
0 → 100644
View file @
4bfc8b2e
package
com
.
jz
.
dmp
.
modules
.
controller
.
dataService
.
bean
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
org.springframework.format.annotation.DateTimeFormat
;
import
javax.validation.constraints.NotEmpty
;
import
javax.validation.constraints.NotNull
;
import
java.io.Serializable
;
import
java.util.Date
;
/**
* @ClassName: AuthUserApiReq
* @Description: API认证授权
* @Author: Bellamy
* @Date 2021/1/19
* @Version 1.0
*/
@Data
@ApiModel
(
"API认证授权"
)
public
class
AuthUserApiReq
implements
Serializable
{
@ApiModelProperty
(
value
=
"apiKey唯一标识"
,
required
=
true
)
@NotNull
(
message
=
"apiKey唯一标识不能为空"
)
@NotEmpty
(
message
=
"apiKey唯一标识不能为空"
)
private
String
apiKey
;
@ApiModelProperty
(
value
=
"组织编码"
,
required
=
true
)
@NotNull
(
message
=
"组织编码不能为空"
)
@NotEmpty
(
message
=
"组织编码不能为空"
)
private
String
orgCode
;
@ApiModelProperty
(
value
=
"授权方式:POWER_CALL_MODE 按次调用 ,RECORD_TIME_MODE 按时间调用,PERMANENT_TIME_MODE 永久有效"
,
required
=
true
)
@NotNull
(
message
=
"授权方式不能为空"
)
private
String
authMode
;
@ApiModelProperty
(
value
=
"创建用户"
,
required
=
false
)
private
String
createUser
;
}
src/main/java/com/jz/dmp/modules/controller/dataService/bean/LogInfoListReq.java
0 → 100644
View file @
4bfc8b2e
package
com
.
jz
.
dmp
.
modules
.
controller
.
dataService
.
bean
;
import
com.jz.common.bean.BasePageBean
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
java.io.Serializable
;
/**
* @ClassName: AuthListInfoReq
* @Description: 日志信息列表请求对象
* @Author: Bellamy
* @Date 2021/1/18
* @Version 1.0
*/
@Data
@ApiModel
(
"日志信息列表请求对象"
)
public
class
LogInfoListReq
extends
BasePageBean
implements
Serializable
{
@ApiModelProperty
(
value
=
"ApiKey"
)
private
String
apiKey
;
}
src/main/java/com/jz/dmp/modules/service/DmpApiMangeService.java
View file @
4bfc8b2e
...
...
@@ -42,5 +42,37 @@ public interface DmpApiMangeService {
* @author Bellamy
* @since 2021-01-18
*/
JsonResult
delApiInfo
(
String
apiKey
,
String
type
)
throws
Exception
;
JsonResult
delApiInfo
(
String
apiKey
,
String
type
)
throws
Exception
;
/**
* 根据apiid获取API详情
*
* @author Bellamy
* @since 2021-01-19
*/
JsonResult
queryApiInfoByApiId
(
String
id
)
throws
Exception
;
/**
* 授权给组织-提交保存
*
* @author Bellamy
* @since 2021-01-19
*/
JsonResult
addApiAuthToOrg
(
AuthUserApiReq
req
)
throws
Exception
;
/**
* API测试
*
* @author Bellamy
* @since 2021-01-19
*/
JsonResult
apiTestInfo
(
String
apiKey
)
throws
Exception
;
/**
* 查看日志
*
* @author Bellamy
* @since 2021-01-19
*/
JsonResult
checkApiLogInfo
(
LogInfoListReq
req
)
throws
Exception
;
}
src/main/java/com/jz/dmp/modules/service/impl/DmpApiMangeServiceImpl.java
View file @
4bfc8b2e
...
...
@@ -42,6 +42,18 @@ public class DmpApiMangeServiceImpl implements DmpApiMangeService {
//删除APIurl
private
static
final
String
delApi
=
"/api/interface/delDMPApiInterface"
;
//根据apiid获取API详情url
private
static
final
String
getApiInfo
=
"/api/interface/getApiInterfaceDetail"
;
//授权给组织url
private
static
final
String
apiAuthToOrg
=
"/api/auth/dmp-auth-api"
;
//测试url
private
static
final
String
testApi
=
"/api/interface/apiTestApiInterface"
;
//查看日志url
private
static
final
String
checkApiLog
=
"/api/logging/listApiLog"
;
@Value
(
"${spring.gateway-url}"
)
private
String
gatewayUrl
;
...
...
@@ -53,6 +65,7 @@ public class DmpApiMangeServiceImpl implements DmpApiMangeService {
*/
@Override
public
JsonResult
queryApiAuthListPage
(
AuthListInfoReq
req
)
throws
Exception
{
JsonResult
result
=
new
JsonResult
();
String
url
=
gatewayUrl
+
apiAuthListPage
;
String
resultData
=
HttpClientUtils
.
post
(
url
,
JSONObject
.
toJSONString
(
req
));
if
(
StringUtils
.
isEmpty
(
resultData
))
{
...
...
@@ -61,15 +74,17 @@ public class DmpApiMangeServiceImpl implements DmpApiMangeService {
logger
.
info
(
"#################响应结果数据{}"
+
resultData
);
Map
jsonObject
=
JSONObject
.
parseObject
(
resultData
);
if
(
StringUtils
.
isNotEmpty
(
jsonObject
.
get
(
"code"
).
toString
()
))
{
if
(
jsonObject
.
containsKey
(
"code"
))
{
if
(
"200"
.
equals
(
jsonObject
.
get
(
"code"
).
toString
()))
{
return
JsonResult
.
ok
(
jsonObject
.
get
(
"data"
));
}
}
if
(
StringUtils
.
isNotEmpty
(
jsonObject
.
get
(
"message"
).
toString
()
))
{
if
(
jsonObject
.
containsKey
(
"message"
))
{
logger
.
info
(
jsonObject
.
get
(
"message"
).
toString
());
result
.
setMessage
(
jsonObject
.
get
(
"message"
).
toString
());
result
.
setCode
(
ResultCode
.
INTERNAL_SERVER_ERROR
);
}
return
JsonResult
.
error
(
jsonObject
.
get
(
"message"
).
toString
())
;
return
result
;
}
/**
...
...
@@ -80,6 +95,7 @@ public class DmpApiMangeServiceImpl implements DmpApiMangeService {
*/
@Override
public
JsonResult
cancelApiAuth
(
String
id
)
throws
Exception
{
JsonResult
result
=
new
JsonResult
();
String
url
=
gatewayUrl
+
cancelApiAuth
;
Map
params
=
new
HashMap
();
params
.
put
(
"id"
,
id
);
...
...
@@ -90,13 +106,17 @@ public class DmpApiMangeServiceImpl implements DmpApiMangeService {
logger
.
info
(
"#################响应结果数据{}"
+
resultData
);
Map
jsonObject
=
JSONObject
.
parseObject
(
resultData
);
if
(
"200"
.
equals
(
jsonObject
.
get
(
"code"
).
toString
()))
{
return
JsonResult
.
ok
(
jsonObject
.
get
(
"data"
));
if
(
jsonObject
.
containsKey
(
"code"
))
{
if
(
"200"
.
equals
(
jsonObject
.
get
(
"code"
).
toString
()))
{
return
JsonResult
.
ok
(
jsonObject
.
get
(
"data"
));
}
}
if
(
StringUtils
.
isNotEmpty
(
jsonObject
.
get
(
"message"
).
toString
()
))
{
if
(
jsonObject
.
containsKey
(
"message"
))
{
logger
.
info
(
jsonObject
.
get
(
"message"
).
toString
());
result
.
setMessage
(
jsonObject
.
get
(
"message"
).
toString
());
result
.
setCode
(
ResultCode
.
INTERNAL_SERVER_ERROR
);
}
return
JsonResult
.
error
(
jsonObject
.
get
(
"message"
).
toString
())
;
return
result
;
}
/**
...
...
@@ -107,6 +127,7 @@ public class DmpApiMangeServiceImpl implements DmpApiMangeService {
*/
@Override
public
JsonResult
queryApiListPage
(
ApiInterfaceInfoListReq
req
)
throws
Exception
{
JsonResult
result
=
new
JsonResult
();
String
url
=
gatewayUrl
+
apiListPage
;
String
resultData
=
HttpClientUtils
.
post
(
url
,
JSONObject
.
toJSONString
(
req
));
if
(
StringUtils
.
isEmpty
(
resultData
))
{
...
...
@@ -115,13 +136,17 @@ public class DmpApiMangeServiceImpl implements DmpApiMangeService {
logger
.
info
(
"#################响应结果数据{}"
+
resultData
);
Map
jsonObject
=
JSONObject
.
parseObject
(
resultData
);
if
(
"200"
.
equals
(
jsonObject
.
get
(
"code"
).
toString
()))
{
return
JsonResult
.
ok
(
jsonObject
.
get
(
"data"
));
if
(
jsonObject
.
containsKey
(
"code"
))
{
if
(
"200"
.
equals
(
jsonObject
.
get
(
"code"
).
toString
()))
{
return
JsonResult
.
ok
(
jsonObject
.
get
(
"data"
));
}
}
if
(
StringUtils
.
isNotEmpty
(
jsonObject
.
get
(
"message"
).
toString
()
))
{
if
(
jsonObject
.
containsKey
(
"message"
))
{
logger
.
info
(
jsonObject
.
get
(
"message"
).
toString
());
result
.
setMessage
(
jsonObject
.
get
(
"message"
).
toString
());
result
.
setCode
(
ResultCode
.
INTERNAL_SERVER_ERROR
);
}
return
JsonResult
.
error
(
jsonObject
.
get
(
"message"
).
toString
())
;
return
result
;
}
/**
...
...
@@ -143,14 +168,143 @@ public class DmpApiMangeServiceImpl implements DmpApiMangeService {
}
logger
.
info
(
"#################响应结果{}"
+
returnData
);
Map
map
=
JSONObject
.
parseObject
(
returnData
);
if
(
"200"
.
equals
(
map
.
get
(
"code"
).
toString
()))
{
return
JsonResult
.
ok
();
if
(
map
.
containsKey
(
"code"
))
{
if
(
"200"
.
equals
(
map
.
get
(
"code"
).
toString
()))
{
return
JsonResult
.
ok
();
}
}
if
(
map
.
containsKey
(
"message"
))
{
logger
.
info
(
map
.
get
(
"message"
).
toString
());
result
.
setMessage
(
map
.
get
(
"message"
).
toString
());
result
.
setCode
(
ResultCode
.
INTERNAL_SERVER_ERROR
);
}
return
result
;
}
/**
* 根据apiid获取API详情
*
* @author Bellamy
* @since 2021-01-19
*/
@Override
public
JsonResult
queryApiInfoByApiId
(
String
id
)
throws
Exception
{
JsonResult
result
=
new
JsonResult
();
String
url
=
gatewayUrl
+
getApiInfo
;
Map
params
=
new
HashMap
();
params
.
put
(
"id"
,
id
);
String
resultData
=
HttpClientUtils
.
post
(
url
,
JSONObject
.
toJSONString
(
params
));
if
(
StringUtils
.
isEmpty
(
resultData
))
{
throw
new
RuntimeException
(
"查询失败!"
);
}
logger
.
info
(
"#################响应结果数据{}"
+
resultData
);
Map
jsonObject
=
JSONObject
.
parseObject
(
resultData
);
if
(
jsonObject
.
containsKey
(
"code"
))
{
if
(
"200"
.
equals
(
jsonObject
.
get
(
"code"
).
toString
()))
{
return
JsonResult
.
ok
(
jsonObject
.
get
(
"data"
));
}
}
if
(
jsonObject
.
containsKey
(
"message"
))
{
logger
.
info
(
jsonObject
.
get
(
"message"
).
toString
());
result
.
setCode
(
ResultCode
.
INTERNAL_SERVER_ERROR
);
result
.
setMessage
(
jsonObject
.
get
(
"message"
).
toString
());
}
return
result
;
}
/**
* 授权给组织-提交保存
*
* @author Bellamy
* @since 2021-01-19
*/
@Override
public
JsonResult
addApiAuthToOrg
(
AuthUserApiReq
req
)
throws
Exception
{
JsonResult
result
=
new
JsonResult
();
String
url
=
gatewayUrl
+
apiAuthToOrg
;
String
resultData
=
HttpClientUtils
.
post
(
url
,
JSONObject
.
toJSONString
(
req
));
if
(
StringUtils
.
isEmpty
(
resultData
))
{
throw
new
RuntimeException
(
"保存失败!"
);
}
logger
.
info
(
"#################响应结果数据{}"
+
resultData
);
Map
jsonObject
=
JSONObject
.
parseObject
(
resultData
);
if
(
jsonObject
.
containsKey
(
"code"
))
{
if
(
"200"
.
equals
(
jsonObject
.
get
(
"code"
).
toString
()))
{
result
.
setData
(
jsonObject
.
get
(
"data"
));
//授权码和盐值
return
result
;
}
}
if
(
jsonObject
.
containsKey
(
"message"
))
{
logger
.
info
(
jsonObject
.
get
(
"message"
).
toString
());
result
.
setCode
(
ResultCode
.
INTERNAL_SERVER_ERROR
);
result
.
setMessage
(
jsonObject
.
get
(
"message"
).
toString
());
}
return
result
;
}
/**
* API测试
*
* @author Bellamy
* @since 2021-01-19
*/
@Override
public
JsonResult
apiTestInfo
(
String
apiKey
)
throws
Exception
{
JsonResult
result
=
new
JsonResult
();
String
url
=
gatewayUrl
+
testApi
;
Map
params
=
new
HashMap
();
params
.
put
(
"apiKey"
,
apiKey
);
String
returnData
=
HttpClientUtils
.
getJsonForParam
(
url
,
params
);
if
(
StringUtils
.
isEmpty
(
returnData
))
{
throw
new
RuntimeException
(
"测试失败!"
);
}
logger
.
info
(
"#################响应结果{}"
+
returnData
);
Map
map
=
JSONObject
.
parseObject
(
returnData
);
if
(
map
.
containsKey
(
"code"
))
{
if
(
"200"
.
equals
(
map
.
get
(
"code"
).
toString
()))
{
return
JsonResult
.
ok
(
map
.
get
(
"data"
));
}
}
if
(
StringUtils
.
isNotEmpty
(
map
.
get
(
"message"
).
toString
()
))
{
if
(
map
.
containsKey
(
"message"
))
{
logger
.
info
(
map
.
get
(
"message"
).
toString
());
result
.
setMessage
(
map
.
get
(
"message"
).
toString
());
result
.
setCode
(
ResultCode
.
INTERNAL_SERVER_ERROR
);
}
return
result
;
}
/**
* 查看日志
*
* @author Bellamy
* @since 2021-01-19
*/
@Override
public
JsonResult
checkApiLogInfo
(
LogInfoListReq
req
)
throws
Exception
{
JsonResult
result
=
new
JsonResult
();
String
url
=
gatewayUrl
+
checkApiLog
;
String
resultData
=
HttpClientUtils
.
post
(
url
,
JSONObject
.
toJSONString
(
req
));
if
(
StringUtils
.
isEmpty
(
resultData
))
{
throw
new
RuntimeException
(
"查询失败!"
);
}
logger
.
info
(
"#################响应结果数据{}"
+
resultData
);
Map
jsonObject
=
JSONObject
.
parseObject
(
resultData
);
if
(
jsonObject
.
containsKey
(
"code"
))
{
if
(
"200"
.
equals
(
jsonObject
.
get
(
"code"
).
toString
()))
{
result
.
setData
(
jsonObject
.
get
(
"data"
));
return
result
;
}
}
if
(
jsonObject
.
containsKey
(
"message"
))
{
logger
.
info
(
jsonObject
.
get
(
"message"
).
toString
());
result
.
setCode
(
ResultCode
.
INTERNAL_SERVER_ERROR
);
result
.
setMessage
(
jsonObject
.
get
(
"message"
).
toString
());
}
return
result
;
}
}
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