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
fe8b550d
Commit
fe8b550d
authored
Mar 03, 2021
by
mcb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
数据服务修改
parent
8146a9b3
Changes
13
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
185 additions
and
23 deletions
+185
-23
CommConstant.java
src/main/java/com/jz/common/constant/CommConstant.java
+4
-0
GatewayApiConstant.java
src/main/java/com/jz/common/constant/GatewayApiConstant.java
+3
-2
FreeMarkerUtils.java
src/main/java/com/jz/common/utils/FreeMarkerUtils.java
+53
-0
HttpClientUtils.java
src/main/java/com/jz/common/utils/web/HttpClientUtils.java
+5
-3
DmpApiMangeController.java
...modules/controller/dataService/DmpApiMangeController.java
+5
-5
DmpApiServiceMangeController.java
.../controller/dataService/DmpApiServiceMangeController.java
+24
-2
CreateFolderReq.java
.../modules/controller/dataService/bean/CreateFolderReq.java
+8
-2
DmpApiMangeService.java
...n/java/com/jz/dmp/modules/service/DmpApiMangeService.java
+2
-2
DmpApiServiceMangeService.java
...com/jz/dmp/modules/service/DmpApiServiceMangeService.java
+9
-0
OfflineSynchService.java
.../java/com/jz/dmp/modules/service/OfflineSynchService.java
+1
-0
DmpApiMangeServiceImpl.java
...m/jz/dmp/modules/service/impl/DmpApiMangeServiceImpl.java
+29
-7
DmpApiServiceMangeServiceImpl.java
...p/modules/service/impl/DmpApiServiceMangeServiceImpl.java
+20
-0
api_test.ftl
src/main/resources/templates/api_test.ftl
+22
-0
No files found.
src/main/java/com/jz/common/constant/CommConstant.java
View file @
fe8b550d
...
...
@@ -62,4 +62,8 @@ public class CommConstant {
//azkaban相关常量
public
static
final
String
AZKABAN_PROJECTNAME_PREFIX
=
"jz_workflow_new_"
;
//azkaban项目名称前缀
/***************************************************/
//模板名称
public
static
final
String
API_TEST
=
"api_test.ftl"
;
public
static
final
String
realTimeTask
=
"source_connector.ftl"
;
}
src/main/java/com/jz/common/constant/GatewayApiConstant.java
View file @
fe8b550d
...
...
@@ -80,9 +80,10 @@ public class GatewayApiConstant {
public
static
final
String
createProjectFolder
=
"/api/producer/createProjectFolder"
;
//授权--组织名称查询
public
static
final
String
getOrgNameList
=
"/api/auth/get-org-list"
;
//授权--组织名称查询
//API测试--下拉框
public
static
final
String
listGetApiKey
=
"/api/interface/listGetApiKey"
;
//删除文件夹
public
static
final
String
delFolder
=
"/api/producer/delProjectFolder"
;
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
GatewayApiConstant
.
class
);
...
...
src/main/java/com/jz/common/utils/FreeMarkerUtils.java
0 → 100644
View file @
fe8b550d
package
com
.
jz
.
common
.
utils
;
import
freemarker.core.ParseException
;
import
freemarker.template.MalformedTemplateNameException
;
import
freemarker.template.Template
;
import
freemarker.template.TemplateException
;
import
freemarker.template.TemplateNotFoundException
;
import
org.springframework.web.servlet.view.freemarker.FreeMarkerConfig
;
import
java.io.IOException
;
import
java.io.StringWriter
;
import
java.util.Map
;
/**
* @ClassName: FreeMarkerUtils
* @Description: freeMarkerUtils
* @Author Bellamy
* @Date 2021/3/3
* @Version 1.0
*/
public
class
FreeMarkerUtils
{
/**
* 使用freemaker模板生成 kafka connector 请求参数
*
* @param type 模板类型
* @param dataModel 模板里定义的变量数据对象
* @return
* @author Bellamy
*/
public
static
String
freemakerJson
(
String
type
,
Map
<
String
,
String
>
dataModel
,
FreeMarkerConfig
freeMarkerConfig
)
{
StringWriter
stringWriter
=
new
StringWriter
();
try
{
Template
template
=
freeMarkerConfig
.
getConfiguration
().
getTemplate
(
type
);
if
(
template
!=
null
)
{
try
{
template
.
process
(
dataModel
,
stringWriter
);
}
catch
(
TemplateException
e
)
{
e
.
printStackTrace
();
}
}
}
catch
(
TemplateNotFoundException
e
)
{
e
.
printStackTrace
();
}
catch
(
MalformedTemplateNameException
e
)
{
e
.
printStackTrace
();
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
stringWriter
.
toString
();
}
}
src/main/java/com/jz/common/utils/web/HttpClientUtils.java
View file @
fe8b550d
...
...
@@ -159,7 +159,7 @@ public class HttpClientUtils {
try
{
httpClient
=
HttpClients
.
createDefault
();
httpPost
=
new
HttpPost
(
url
);
RequestConfig
requestConfig
=
RequestConfig
.
custom
().
setSocketTimeout
(
5000
0
).
setConnectTimeout
(
50
000
).
build
();
//设置请求和传输超时时间
RequestConfig
requestConfig
=
RequestConfig
.
custom
().
setSocketTimeout
(
5000
).
setConnectTimeout
(
5
000
).
build
();
//设置请求和传输超时时间
httpPost
.
setConfig
(
requestConfig
);
StringEntity
se
=
new
StringEntity
(
json
,
"UTF-8"
);
//StringEntity se = new StringEntity("UTF-8");
...
...
@@ -199,7 +199,7 @@ public class HttpClientUtils {
try
{
httpClient
=
HttpClients
.
createDefault
();
httpPost
=
new
HttpPost
(
url
);
RequestConfig
requestConfig
=
RequestConfig
.
custom
().
setSocketTimeout
(
50000
).
setConnectTimeout
(
5
0000
).
build
();
//设置请求和传输超时时间
RequestConfig
requestConfig
=
RequestConfig
.
custom
().
setSocketTimeout
(
10000
).
setConnectTimeout
(
1
0000
).
build
();
//设置请求和传输超时时间
httpPost
.
setConfig
(
requestConfig
);
/* StringEntity se = new StringEntity(json, "UTF-8");
se.setContentType("application/x-www-form-urlencoded");
...
...
@@ -495,7 +495,7 @@ public class HttpClientUtils {
try
{
httpClient
=
HttpClients
.
createDefault
();
httpPost
=
new
HttpPost
(
url
);
RequestConfig
requestConfig
=
RequestConfig
.
custom
().
setSocketTimeout
(
5000
0
).
setConnectTimeout
(
50
000
).
build
();
//设置请求和传输超时时间
RequestConfig
requestConfig
=
RequestConfig
.
custom
().
setSocketTimeout
(
5000
).
setConnectTimeout
(
5
000
).
build
();
//设置请求和传输超时时间
httpPost
.
setConfig
(
requestConfig
);
httpPost
.
setHeader
(
"token"
,
token
);
StringEntity
se
=
new
StringEntity
(
json
,
"UTF-8"
);
...
...
@@ -562,6 +562,8 @@ public class HttpClientUtils {
try
{
// 创建httpget.
HttpGet
httpget
=
new
HttpGet
(
requestUrl
);
RequestConfig
requestConfig
=
RequestConfig
.
custom
().
setSocketTimeout
(
5000
).
setConnectTimeout
(
5000
).
build
();
//设置请求和传输超时时间
httpget
.
setConfig
(
requestConfig
);
System
.
out
.
println
(
"get executing request "
+
httpget
.
getURI
());
// 执行get请求.
CloseableHttpResponse
response
=
httpclient
.
execute
(
httpget
);
...
...
src/main/java/com/jz/dmp/modules/controller/dataService/DmpApiMangeController.java
View file @
fe8b550d
...
...
@@ -179,10 +179,10 @@ public class DmpApiMangeController {
*/
@ApiOperation
(
value
=
"API测试"
,
notes
=
"API测试"
)
@PostMapping
(
value
=
"/apiTestInfo"
)
public
JsonResult
getApiTestInfo
(
@RequestBody
Map
<
String
,
Object
>
params
,
HttpServletRequest
httpRequest
)
{
public
JsonResult
getApiTestInfo
(
@RequestBody
Map
<
String
,
String
>
apiKey
,
HttpServletRequest
httpRequest
)
{
JsonResult
jsonResult
=
new
JsonResult
();
try
{
jsonResult
=
dmpApiMangeService
.
apiTestInfo
(
params
);
jsonResult
=
dmpApiMangeService
.
apiTestInfo
(
apiKey
);
}
catch
(
Exception
e
)
{
jsonResult
.
setMessage
(
e
.
getMessage
());
jsonResult
.
setCode
(
ResultCode
.
INTERNAL_SERVER_ERROR
);
...
...
@@ -199,11 +199,11 @@ public class DmpApiMangeController {
*/
@ApiOperation
(
value
=
"API测试--下拉框"
,
notes
=
"API测试--下拉框"
)
@GetMapping
(
value
=
"/apiTestGetApiKey"
)
@ApiImplicitParam
(
name
=
"api
Key"
,
value
=
"apiKey
"
)
public
JsonResult
getApiTestGetApiKey
(
@RequestParam
(
required
=
false
)
String
api
Key
,
HttpServletRequest
httpRequest
)
{
@ApiImplicitParam
(
name
=
"api
Name"
,
value
=
"apiName
"
)
public
JsonResult
getApiTestGetApiKey
(
@RequestParam
(
required
=
false
)
String
api
Name
,
HttpServletRequest
httpRequest
)
{
JsonResult
jsonResult
=
new
JsonResult
();
try
{
jsonResult
=
dmpApiMangeService
.
getApiTestGetApiKey
(
api
Key
);
jsonResult
=
dmpApiMangeService
.
getApiTestGetApiKey
(
api
Name
);
}
catch
(
Exception
e
)
{
jsonResult
.
setMessage
(
e
.
getMessage
());
jsonResult
.
setCode
(
ResultCode
.
INTERNAL_SERVER_ERROR
);
...
...
src/main/java/com/jz/dmp/modules/controller/dataService/DmpApiServiceMangeController.java
View file @
fe8b550d
...
...
@@ -311,6 +311,28 @@ public class DmpApiServiceMangeController {
return
jsonResult
;
}
/**
* 删除文件夹
*
* @return
* @author Bellamy
* @since 2021-03-3
*/
@ApiOperation
(
value
=
"删除文件夹"
,
notes
=
"删除文件夹"
)
@GetMapping
(
value
=
"/delFolder"
)
@ApiImplicitParam
(
name
=
"id"
,
value
=
"文件夹id"
,
required
=
true
)
public
JsonResult
delFolderById
(
@RequestParam
String
id
)
throws
Exception
{
JsonResult
jsonResult
=
new
JsonResult
();
try
{
jsonResult
=
dmpApiServiceMangeService
.
delFolderById
(
id
);
}
catch
(
Exception
e
)
{
jsonResult
.
setMessage
(
e
.
getMessage
());
jsonResult
.
setCode
(
ResultCode
.
INTERNAL_SERVER_ERROR
);
e
.
printStackTrace
();
}
return
jsonResult
;
}
/**
* 服务开发---获取ApiId
*
...
...
@@ -332,12 +354,12 @@ public class DmpApiServiceMangeController {
}
/**
* 创建项目文件夹
* 创建
/编辑
项目文件夹
*
* @author Bellamy
* @since 2021-02-24
*/
@ApiOperation
(
value
=
"创建
项目文件夹"
,
notes
=
"创建
项目文件夹"
)
@ApiOperation
(
value
=
"创建
/编辑项目文件夹"
,
notes
=
"创建/编辑
项目文件夹"
)
@PostMapping
(
value
=
"/createProjectFolder"
)
public
JsonResult
createProjectFolder
(
@RequestBody
@Validated
CreateFolderReq
req
,
HttpServletRequest
httpRequest
)
{
JsonResult
jsonResult
=
new
JsonResult
();
...
...
src/main/java/com/jz/dmp/modules/controller/dataService/bean/CreateFolderReq.java
View file @
fe8b550d
...
...
@@ -24,7 +24,7 @@ public class CreateFolderReq implements Serializable {
@ApiModelProperty
(
value
=
"项目id"
,
required
=
false
)
private
Long
projectId
;
@ApiModelProperty
(
value
=
"组织编码"
,
required
=
false
)
@ApiModelProperty
(
value
=
"组织编码
/编辑时不允许修改
"
,
required
=
false
)
private
String
orgCode
;
@ApiModelProperty
(
value
=
"父类文件夹id ,创建同级不传"
,
required
=
false
)
...
...
@@ -40,8 +40,14 @@ public class CreateFolderReq implements Serializable {
@NotNull
(
message
=
"文件来源不能为空"
)
private
String
fileSource
;
@ApiModelProperty
(
value
=
"创建用户"
,
required
=
false
)
private
String
createUser
;
//---------------------------------更新时id必传------------------
@ApiModelProperty
(
value
=
"文件id"
,
required
=
false
)
private
String
id
;
@ApiModelProperty
(
value
=
"更新用户"
,
required
=
false
)
private
String
updateUser
;
}
src/main/java/com/jz/dmp/modules/service/DmpApiMangeService.java
View file @
fe8b550d
...
...
@@ -68,7 +68,7 @@ public interface DmpApiMangeService {
* @author Bellamy
* @since 2021-01-19
*/
JsonResult
apiTestInfo
(
Map
<
String
,
Object
>
params
)
throws
Exception
;
JsonResult
apiTestInfo
(
Map
<
String
,
String
>
params
)
throws
Exception
;
/**
* 查看日志
...
...
@@ -147,5 +147,5 @@ public interface DmpApiMangeService {
* @author Bellamy
* @since 2021-03-03
*/
JsonResult
getApiTestGetApiKey
(
String
api
Key
)
throws
Exception
;
JsonResult
getApiTestGetApiKey
(
String
api
Name
)
throws
Exception
;
}
src/main/java/com/jz/dmp/modules/service/DmpApiServiceMangeService.java
View file @
fe8b550d
...
...
@@ -122,4 +122,13 @@ public interface DmpApiServiceMangeService {
* @since 2021-02-24
*/
JsonResult
createProjectFolder
(
CreateFolderReq
req
)
throws
Exception
;
/**
* 删除文件夹
*
* @return
* @author Bellamy
* @since 2021-03-3
*/
JsonResult
delFolderById
(
String
id
)
throws
Exception
;
}
\ No newline at end of file
src/main/java/com/jz/dmp/modules/service/OfflineSynchService.java
View file @
fe8b550d
...
...
@@ -130,4 +130,5 @@ public interface OfflineSynchService {
* @since 2021-02-19
*/
JsonResult
getDataPreview
(
OfflineDataPreview
req
)
throws
Exception
;
}
src/main/java/com/jz/dmp/modules/service/impl/DmpApiMangeServiceImpl.java
View file @
fe8b550d
package
com
.
jz
.
dmp
.
modules
.
service
.
impl
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jz.common.constant.CommConstant
;
import
com.jz.common.constant.GatewayApiConstant
;
import
com.jz.common.constant.JsonResult
;
import
com.jz.common.constant.ResultCode
;
import
com.jz.common.utils.FreeMarkerUtils
;
import
com.jz.common.utils.MD5SignUtils
;
import
com.jz.common.utils.MapUtil
;
import
com.jz.common.utils.web.HttpClientUtils
;
...
...
@@ -12,8 +14,10 @@ import com.jz.dmp.modules.service.DmpApiMangeService;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.servlet.view.freemarker.FreeMarkerConfig
;
import
java.util.HashMap
;
import
java.util.Map
;
...
...
@@ -33,6 +37,9 @@ public class DmpApiMangeServiceImpl implements DmpApiMangeService {
@Value
(
"${spring.gateway-url}"
)
private
String
gatewayUrl
;
@Autowired
private
FreeMarkerConfig
freeMarkerConfig
;
/**
* 授权给他人的API-列表分页查询
*
...
...
@@ -195,16 +202,31 @@ public class DmpApiMangeServiceImpl implements DmpApiMangeService {
* @since 2021-01-19
*/
@Override
public
JsonResult
apiTestInfo
(
Map
<
String
,
Object
>
params
)
throws
Exception
{
public
JsonResult
apiTestInfo
(
Map
<
String
,
String
>
params
)
throws
Exception
{
String
url
=
gatewayUrl
+
GatewayApiConstant
.
testApi
;
params
.
put
(
"timestamp"
,
System
.
currentTimeMillis
());
if
(
StringUtils
.
isEmpty
(
params
.
get
(
"apiKey"
)))
{
return
JsonResult
.
error
(
ResultCode
.
PARAMS_ERROR
,
"apiKey不能为空!"
);
}
params
.
put
(
"apiKey"
,
params
.
get
(
"apiKey"
));
params
.
put
(
"timestamp"
,
String
.
valueOf
(
System
.
currentTimeMillis
()));
//使用freemaker模板生成 请求参数
String
jsonStr
=
FreeMarkerUtils
.
freemakerJson
(
CommConstant
.
API_TEST
,
params
,
freeMarkerConfig
);
Map
<
String
,
Object
>
requestJson
=
(
Map
<
String
,
Object
>)
JSONObject
.
parse
(
jsonStr
);
//对签约参数进行字典排序
String
signParams
=
MapUtil
.
stringNormalSort
(
assembleSignMap
(
params
));
String
signParams
=
MapUtil
.
stringNormalSort
(
assembleSignMap
(
requestJson
));
if
(
StringUtils
.
isNotEmpty
(
signParams
))
{
String
sign
=
MD5SignUtils
.
encrypt
(
signParams
,
""
);
params
.
put
(
"sign"
,
sign
);
requestJson
.
put
(
"sign"
,
sign
);
}
JsonResult
result
=
GatewayApiConstant
.
postRequest2GetData
(
url
,
JSONObject
.
toJSONString
(
params
));
JsonResult
result
=
GatewayApiConstant
.
postRequest2GetData
(
url
,
JSONObject
.
toJSONString
(
requestJson
));
if
(
null
==
result
.
getData
())
{
throw
new
RuntimeException
(
"failed!"
);
}
Map
<
String
,
Object
>
data
=
(
Map
<
String
,
Object
>)
result
.
getData
();
result
.
setData
(
data
.
get
(
"response_result"
));
return
result
;
}
...
...
@@ -454,10 +476,10 @@ public class DmpApiMangeServiceImpl implements DmpApiMangeService {
* @since 2021-03-03
*/
@Override
public
JsonResult
getApiTestGetApiKey
(
String
api
Key
)
throws
Exception
{
public
JsonResult
getApiTestGetApiKey
(
String
api
Name
)
throws
Exception
{
String
url
=
gatewayUrl
+
GatewayApiConstant
.
listGetApiKey
;
Map
params
=
new
HashMap
();
params
.
put
(
"api
Key"
,
apiKey
);
params
.
put
(
"api
Name"
,
apiName
);
JsonResult
result
=
GatewayApiConstant
.
getRequest2GetData
(
url
,
params
);
return
result
;
}
...
...
src/main/java/com/jz/dmp/modules/service/impl/DmpApiServiceMangeServiceImpl.java
View file @
fe8b550d
...
...
@@ -241,10 +241,30 @@ public class DmpApiServiceMangeServiceImpl implements DmpApiServiceMangeService
public
JsonResult
createProjectFolder
(
CreateFolderReq
req
)
throws
Exception
{
String
url
=
gatewayUrl
+
GatewayApiConstant
.
createProjectFolder
;
req
.
setCreateUser
(
SessionUtils
.
getCurrentUserName
());
if
(
StringUtils
.
isNotEmpty
(
req
.
getId
()))
{
req
.
setUpdateUser
(
SessionUtils
.
getCurrentUserName
());
}
JsonResult
result
=
GatewayApiConstant
.
postRequest2GetData
(
url
,
JSONObject
.
toJSONString
(
req
));
return
result
;
}
/**
* 删除文件夹
*
* @param id
* @return
* @author Bellamy
* @since 2021-03-3
*/
@Override
public
JsonResult
delFolderById
(
String
id
)
throws
Exception
{
String
url
=
gatewayUrl
+
GatewayApiConstant
.
delFolder
;
Map
params
=
new
HashMap
();
params
.
put
(
"id"
,
id
);
JsonResult
result
=
GatewayApiConstant
.
getRequest2GetData
(
url
,
params
);
return
result
;
}
/**
* 服务开发API列表
*
...
...
src/main/resources/templates/api_test.ftl
0 → 100644
View file @
fe8b550d
<#if apiKey??>
{
"apiKey":"${apiKey!}",
"method":"request",
"signType":"MD5",
"sign":"${sign!}",
"timestamp":"${timestamp!}",
"params":{
"authCode":"",
"isTest":true,
"reqParams":{
"datasourceId": "1",
"query_database": "product",
"query_table": "table1",
"request_fileds": {"flelds1": "xxxxxx", "flelds2":"xxxxxx"},
"response_fields": "field1,field2,field3,field4",
"page_num": 1,
"page_size": 100
}
}
}
</#if>
\ 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