Commit fe8b550d authored by mcb's avatar mcb

数据服务修改

parent 8146a9b3
...@@ -62,4 +62,8 @@ public class CommConstant { ...@@ -62,4 +62,8 @@ public class CommConstant {
//azkaban相关常量 //azkaban相关常量
public static final String AZKABAN_PROJECTNAME_PREFIX = "jz_workflow_new_"; //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";
} }
...@@ -80,9 +80,10 @@ public class GatewayApiConstant { ...@@ -80,9 +80,10 @@ public class GatewayApiConstant {
public static final String createProjectFolder = "/api/producer/createProjectFolder"; public static final String createProjectFolder = "/api/producer/createProjectFolder";
//授权--组织名称查询 //授权--组织名称查询
public static final String getOrgNameList = "/api/auth/get-org-list"; public static final String getOrgNameList = "/api/auth/get-org-list";
//API测试--下拉框
//授权--组织名称查询
public static final String listGetApiKey = "/api/interface/listGetApiKey"; public static final String listGetApiKey = "/api/interface/listGetApiKey";
//删除文件夹
public static final String delFolder = "/api/producer/delProjectFolder";
private static Logger logger = LoggerFactory.getLogger(GatewayApiConstant.class); private static Logger logger = LoggerFactory.getLogger(GatewayApiConstant.class);
......
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();
}
}
...@@ -159,7 +159,7 @@ public class HttpClientUtils { ...@@ -159,7 +159,7 @@ public class HttpClientUtils {
try { try {
httpClient = HttpClients.createDefault(); httpClient = HttpClients.createDefault();
httpPost = new HttpPost(url); httpPost = new HttpPost(url);
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(50000).setConnectTimeout(50000).build();//设置请求和传输超时时间 RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(5000).setConnectTimeout(5000).build();//设置请求和传输超时时间
httpPost.setConfig(requestConfig); httpPost.setConfig(requestConfig);
StringEntity se = new StringEntity(json, "UTF-8"); StringEntity se = new StringEntity(json, "UTF-8");
//StringEntity se = new StringEntity("UTF-8"); //StringEntity se = new StringEntity("UTF-8");
...@@ -199,7 +199,7 @@ public class HttpClientUtils { ...@@ -199,7 +199,7 @@ public class HttpClientUtils {
try { try {
httpClient = HttpClients.createDefault(); httpClient = HttpClients.createDefault();
httpPost = new HttpPost(url); httpPost = new HttpPost(url);
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(50000).setConnectTimeout(50000).build();//设置请求和传输超时时间 RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(10000).setConnectTimeout(10000).build();//设置请求和传输超时时间
httpPost.setConfig(requestConfig); httpPost.setConfig(requestConfig);
/* StringEntity se = new StringEntity(json, "UTF-8"); /* StringEntity se = new StringEntity(json, "UTF-8");
se.setContentType("application/x-www-form-urlencoded"); se.setContentType("application/x-www-form-urlencoded");
...@@ -495,7 +495,7 @@ public class HttpClientUtils { ...@@ -495,7 +495,7 @@ public class HttpClientUtils {
try { try {
httpClient = HttpClients.createDefault(); httpClient = HttpClients.createDefault();
httpPost = new HttpPost(url); httpPost = new HttpPost(url);
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(50000).setConnectTimeout(50000).build();//设置请求和传输超时时间 RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(5000).setConnectTimeout(5000).build();//设置请求和传输超时时间
httpPost.setConfig(requestConfig); httpPost.setConfig(requestConfig);
httpPost.setHeader("token", token); httpPost.setHeader("token", token);
StringEntity se = new StringEntity(json, "UTF-8"); StringEntity se = new StringEntity(json, "UTF-8");
...@@ -562,6 +562,8 @@ public class HttpClientUtils { ...@@ -562,6 +562,8 @@ public class HttpClientUtils {
try { try {
// 创建httpget. // 创建httpget.
HttpGet httpget = new HttpGet(requestUrl); 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()); System.out.println("get executing request " + httpget.getURI());
// 执行get请求. // 执行get请求.
CloseableHttpResponse response = httpclient.execute(httpget); CloseableHttpResponse response = httpclient.execute(httpget);
......
...@@ -179,10 +179,10 @@ public class DmpApiMangeController { ...@@ -179,10 +179,10 @@ public class DmpApiMangeController {
*/ */
@ApiOperation(value = "API测试", notes = "API测试") @ApiOperation(value = "API测试", notes = "API测试")
@PostMapping(value = "/apiTestInfo") @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(); JsonResult jsonResult = new JsonResult();
try { try {
jsonResult = dmpApiMangeService.apiTestInfo(params); jsonResult = dmpApiMangeService.apiTestInfo(apiKey);
} catch (Exception e) { } catch (Exception e) {
jsonResult.setMessage(e.getMessage()); jsonResult.setMessage(e.getMessage());
jsonResult.setCode(ResultCode.INTERNAL_SERVER_ERROR); jsonResult.setCode(ResultCode.INTERNAL_SERVER_ERROR);
...@@ -199,11 +199,11 @@ public class DmpApiMangeController { ...@@ -199,11 +199,11 @@ public class DmpApiMangeController {
*/ */
@ApiOperation(value = "API测试--下拉框", notes = "API测试--下拉框") @ApiOperation(value = "API测试--下拉框", notes = "API测试--下拉框")
@GetMapping(value = "/apiTestGetApiKey") @GetMapping(value = "/apiTestGetApiKey")
@ApiImplicitParam(name = "apiKey", value = "apiKey") @ApiImplicitParam(name = "apiName", value = "apiName")
public JsonResult getApiTestGetApiKey(@RequestParam(required = false) String apiKey, HttpServletRequest httpRequest) { public JsonResult getApiTestGetApiKey(@RequestParam(required = false) String apiName, HttpServletRequest httpRequest) {
JsonResult jsonResult = new JsonResult(); JsonResult jsonResult = new JsonResult();
try { try {
jsonResult = dmpApiMangeService.getApiTestGetApiKey(apiKey); jsonResult = dmpApiMangeService.getApiTestGetApiKey(apiName);
} catch (Exception e) { } catch (Exception e) {
jsonResult.setMessage(e.getMessage()); jsonResult.setMessage(e.getMessage());
jsonResult.setCode(ResultCode.INTERNAL_SERVER_ERROR); jsonResult.setCode(ResultCode.INTERNAL_SERVER_ERROR);
......
...@@ -311,6 +311,28 @@ public class DmpApiServiceMangeController { ...@@ -311,6 +311,28 @@ public class DmpApiServiceMangeController {
return jsonResult; 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 * 服务开发---获取ApiId
* *
...@@ -332,12 +354,12 @@ public class DmpApiServiceMangeController { ...@@ -332,12 +354,12 @@ public class DmpApiServiceMangeController {
} }
/** /**
* 创建项目文件夹 * 创建/编辑项目文件夹
* *
* @author Bellamy * @author Bellamy
* @since 2021-02-24 * @since 2021-02-24
*/ */
@ApiOperation(value = "创建项目文件夹", notes = "创建项目文件夹") @ApiOperation(value = "创建/编辑项目文件夹", notes = "创建/编辑项目文件夹")
@PostMapping(value = "/createProjectFolder") @PostMapping(value = "/createProjectFolder")
public JsonResult createProjectFolder(@RequestBody @Validated CreateFolderReq req, HttpServletRequest httpRequest) { public JsonResult createProjectFolder(@RequestBody @Validated CreateFolderReq req, HttpServletRequest httpRequest) {
JsonResult jsonResult = new JsonResult(); JsonResult jsonResult = new JsonResult();
......
...@@ -24,7 +24,7 @@ public class CreateFolderReq implements Serializable { ...@@ -24,7 +24,7 @@ public class CreateFolderReq implements Serializable {
@ApiModelProperty(value = "项目id", required = false) @ApiModelProperty(value = "项目id", required = false)
private Long projectId; private Long projectId;
@ApiModelProperty(value = "组织编码", required = false) @ApiModelProperty(value = "组织编码/编辑时不允许修改", required = false)
private String orgCode; private String orgCode;
@ApiModelProperty(value = "父类文件夹id ,创建同级不传", required = false) @ApiModelProperty(value = "父类文件夹id ,创建同级不传", required = false)
...@@ -40,8 +40,14 @@ public class CreateFolderReq implements Serializable { ...@@ -40,8 +40,14 @@ public class CreateFolderReq implements Serializable {
@NotNull(message = "文件来源不能为空") @NotNull(message = "文件来源不能为空")
private String fileSource; private String fileSource;
@ApiModelProperty(value = "创建用户", required = false) @ApiModelProperty(value = "创建用户", required = false)
private String createUser; private String createUser;
//---------------------------------更新时id必传------------------
@ApiModelProperty(value = "文件id", required = false)
private String id;
@ApiModelProperty(value = "更新用户", required = false)
private String updateUser;
} }
...@@ -68,7 +68,7 @@ public interface DmpApiMangeService { ...@@ -68,7 +68,7 @@ public interface DmpApiMangeService {
* @author Bellamy * @author Bellamy
* @since 2021-01-19 * @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 { ...@@ -147,5 +147,5 @@ public interface DmpApiMangeService {
* @author Bellamy * @author Bellamy
* @since 2021-03-03 * @since 2021-03-03
*/ */
JsonResult getApiTestGetApiKey(String apiKey) throws Exception; JsonResult getApiTestGetApiKey(String apiName) throws Exception;
} }
...@@ -122,4 +122,13 @@ public interface DmpApiServiceMangeService { ...@@ -122,4 +122,13 @@ public interface DmpApiServiceMangeService {
* @since 2021-02-24 * @since 2021-02-24
*/ */
JsonResult createProjectFolder(CreateFolderReq req) throws Exception; 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
...@@ -130,4 +130,5 @@ public interface OfflineSynchService { ...@@ -130,4 +130,5 @@ public interface OfflineSynchService {
* @since 2021-02-19 * @since 2021-02-19
*/ */
JsonResult getDataPreview(OfflineDataPreview req) throws Exception; JsonResult getDataPreview(OfflineDataPreview req) throws Exception;
} }
package com.jz.dmp.modules.service.impl; package com.jz.dmp.modules.service.impl;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.jz.common.constant.CommConstant;
import com.jz.common.constant.GatewayApiConstant; import com.jz.common.constant.GatewayApiConstant;
import com.jz.common.constant.JsonResult; import com.jz.common.constant.JsonResult;
import com.jz.common.constant.ResultCode; import com.jz.common.constant.ResultCode;
import com.jz.common.utils.FreeMarkerUtils;
import com.jz.common.utils.MD5SignUtils; import com.jz.common.utils.MD5SignUtils;
import com.jz.common.utils.MapUtil; import com.jz.common.utils.MapUtil;
import com.jz.common.utils.web.HttpClientUtils; import com.jz.common.utils.web.HttpClientUtils;
...@@ -12,8 +14,10 @@ import com.jz.dmp.modules.service.DmpApiMangeService; ...@@ -12,8 +14,10 @@ import com.jz.dmp.modules.service.DmpApiMangeService;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfig;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -33,6 +37,9 @@ public class DmpApiMangeServiceImpl implements DmpApiMangeService { ...@@ -33,6 +37,9 @@ public class DmpApiMangeServiceImpl implements DmpApiMangeService {
@Value("${spring.gateway-url}") @Value("${spring.gateway-url}")
private String gatewayUrl; private String gatewayUrl;
@Autowired
private FreeMarkerConfig freeMarkerConfig;
/** /**
* 授权给他人的API-列表分页查询 * 授权给他人的API-列表分页查询
* *
...@@ -195,16 +202,31 @@ public class DmpApiMangeServiceImpl implements DmpApiMangeService { ...@@ -195,16 +202,31 @@ public class DmpApiMangeServiceImpl implements DmpApiMangeService {
* @since 2021-01-19 * @since 2021-01-19
*/ */
@Override @Override
public JsonResult apiTestInfo(Map<String, Object> params) throws Exception { public JsonResult apiTestInfo(Map<String, String> params) throws Exception {
String url = gatewayUrl + GatewayApiConstant.testApi; 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)) { if (StringUtils.isNotEmpty(signParams)) {
String sign = MD5SignUtils.encrypt(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; return result;
} }
...@@ -454,10 +476,10 @@ public class DmpApiMangeServiceImpl implements DmpApiMangeService { ...@@ -454,10 +476,10 @@ public class DmpApiMangeServiceImpl implements DmpApiMangeService {
* @since 2021-03-03 * @since 2021-03-03
*/ */
@Override @Override
public JsonResult getApiTestGetApiKey(String apiKey) throws Exception { public JsonResult getApiTestGetApiKey(String apiName) throws Exception {
String url = gatewayUrl + GatewayApiConstant.listGetApiKey; String url = gatewayUrl + GatewayApiConstant.listGetApiKey;
Map params = new HashMap(); Map params = new HashMap();
params.put("apiKey", apiKey); params.put("apiName", apiName);
JsonResult result = GatewayApiConstant.getRequest2GetData(url, params); JsonResult result = GatewayApiConstant.getRequest2GetData(url, params);
return result; return result;
} }
......
...@@ -241,10 +241,30 @@ public class DmpApiServiceMangeServiceImpl implements DmpApiServiceMangeService ...@@ -241,10 +241,30 @@ public class DmpApiServiceMangeServiceImpl implements DmpApiServiceMangeService
public JsonResult createProjectFolder(CreateFolderReq req) throws Exception { public JsonResult createProjectFolder(CreateFolderReq req) throws Exception {
String url = gatewayUrl + GatewayApiConstant.createProjectFolder; String url = gatewayUrl + GatewayApiConstant.createProjectFolder;
req.setCreateUser(SessionUtils.getCurrentUserName()); req.setCreateUser(SessionUtils.getCurrentUserName());
if (StringUtils.isNotEmpty(req.getId())) {
req.setUpdateUser(SessionUtils.getCurrentUserName());
}
JsonResult result = GatewayApiConstant.postRequest2GetData(url, JSONObject.toJSONString(req)); JsonResult result = GatewayApiConstant.postRequest2GetData(url, JSONObject.toJSONString(req));
return result; 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列表 * 服务开发API列表
* *
......
<#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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment