Commit 8146a9b3 authored by mcb's avatar mcb

数据服务代码修改

parent ccb56a80
......@@ -81,6 +81,9 @@ public class GatewayApiConstant {
//授权--组织名称查询
public static final String getOrgNameList = "/api/auth/get-org-list";
//授权--组织名称查询
public static final String listGetApiKey = "/api/interface/listGetApiKey";
private static Logger logger = LoggerFactory.getLogger(GatewayApiConstant.class);
/*
......
package com.jz.common.utils;
import com.jz.dmp.modules.controller.dataService.DmpApiMangeController;
import org.apache.commons.codec.digest.DigestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
/**
*
......@@ -16,7 +20,10 @@ import java.io.UnsupportedEncodingException;
*/
public class MD5SignUtils {
private static Logger logger = LoggerFactory.getLogger(MD5SignUtils.class);
private static final String DEFAULT_CHARSET = "UTF-8";
private static final String SIGN_TYPE = "MD5";
/**
* 签名
......@@ -74,4 +81,37 @@ public class MD5SignUtils {
throw new RuntimeException("MD5签名过程中出现错误,指定的编码集不对,您目前指定的编码集是:" + charset);
}
}
/**
* MD5加盐加密
*
* @param str
* @param salt
* @return
*/
public static String encrypt(String str, String salt) {
try {
MessageDigest md5 = MessageDigest.getInstance(SIGN_TYPE);
md5.update((str + salt).getBytes(DEFAULT_CHARSET));
return byte2hex(md5.digest());
} catch (Exception e) {
if (logger.isDebugEnabled()) {
logger.debug("md5 加密异常", e);
}
}
return "";
}
public static String byte2hex(byte[] bytes) {
StringBuilder sign = new StringBuilder();
for (int i = 0; i < bytes.length; i++) {
String hex = Integer.toHexString(bytes[i] & 0xFF);
if (hex.length() == 1) {
sign.append("0");
}
sign.append(hex.toUpperCase());
}
return sign.toString();
}
}
package com.jz.common.utils;
import com.alibaba.fastjson.JSON;
import org.apache.commons.lang3.StringUtils;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.net.URLEncoder;
import java.util.*;
/**
* @author ZC
* @PACKAGE_NAME: com.jz.dm.common.util
* @PROJECT_NAME: jz-dm-parent
* @NAME: MapUtil
* @DATE: 2021-1-2/14:02
* @DAY_NAME_SHORT: 周六
* @Description:
**/
public class MapUtil {
/**
* 获取签名参数
*
* @param apiKey
* @param method
* @param signType
* @return
*/
//public static String getSignValue(String apiKey, String method, String signType) {
// StringBuilder builder = new StringBuilder();
// builder.append("apiKey=").append(apiKey).append(LoggingConstants.AND_SPILT)
// .append("method=").append(method).append(LoggingConstants.AND_SPILT)
// .append("signType=").append(signType);
// return builder.toString();
//}
/**
* 将对象转成TreeMap,属性名为key,属性值为value
*
* @param object 对象
* @return
* @throws IllegalAccessException
*/
public static TreeMap<String, String> objToMap(Object object) throws IllegalAccessException {
Class clazz = object.getClass();
TreeMap<String, String> treeMap = new TreeMap<String, String>();
while (null != clazz.getSuperclass()) {
Field[] declaredFields1 = clazz.getDeclaredFields();
for (Field field : declaredFields1) {
String name = field.getName();
// 获取原来的访问控制权限
boolean accessFlag = field.isAccessible();
// 修改访问控制权限
field.setAccessible(true);
Object value = field.get(object);
// 恢复访问控制权限
field.setAccessible(accessFlag);
if (null != value && StringUtils.isNotBlank(value.toString())) {
//如果是List,将List转换为json字符串
if (value instanceof List) {
value = JSON.toJSONString(value);
}
treeMap.put(name, String.valueOf(value));
}
}
clazz = clazz.getSuperclass();
}
return treeMap;
}
/**
* 按照指定的分割符将list转换为String
*
* @param list
* @param separator
* @return
*/
public static String listToString(List list, String separator) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < list.size(); i++) {
if (i == list.size() - 1) {
sb.append(list.get(i));
} else {
sb.append(list.get(i));
sb.append(separator);
}
}
return sb.toString();
}
/**
* * 把数组元素按照按照字典倒序排序,并按照“参数=参数值”的模式用“&”字符拼接成字符串
* @param params 需要排序并参与字符拼接的参数组
* @return 拼接后字符串
*/
public static String stringInvertSort(Map<String, String> params) {
List<String> keys = new ArrayList<String>(params.keySet());
Collections.reverse(keys);
String prestr = "";
for (int i = 0; i < keys.size(); i++) {
String key = keys.get(i);
String value = params.get(key);
try {
value = URLEncoder.encode(value, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
if (i == keys.size() - 1) {//拼接时,不包括最后一个&字符
prestr = prestr + key + "=" + value;
} else {
prestr = prestr + key + "=" + value + "&";
}
}
return prestr;
}
/**
*   * 把数组所有元素字典排序,并按照“参数=参数值”的模式用“&”字符拼接成字符串
*   * @param params 需要排序并参与字符拼接的参数组
*   * @return 拼接后字符串 
*/
public static String stringNormalSort(Map<String, String> params) {
List<String> keys = new ArrayList<String>(params.keySet());
Collections.sort(keys);
String prestr = "";
for (int i = 0; i < keys.size(); i++) {
String key = keys.get(i);
String value = params.get(key);
try {
value = URLEncoder.encode(value, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
if (i == keys.size() - 1) {//拼接时,不包括最后一个&字符
prestr = prestr + key + "=" + value;
} else {
prestr = prestr + key + "=" + value + "&";
}
}
return prestr;
}
class SpellComparatorUtils implements Comparator {
@Override
public int compare(Object o1, Object o2) {
try {
// 取得比较对象的汉字编码,并将其转换成字符串
String s1 = new String(o1.toString().getBytes("GB2312"), "ISO-8859-1");
String s2 = new String(o2.toString().getBytes("GB2312"), "ISO-8859-1");
// 运用String类的 compareTo()方法对两对象进行比较
return s1.compareTo(s2);
} catch (Exception e) {
e.printStackTrace();
}
return 0;
}
}
public static void main(String[] args) {
//Map<String, String> map = new HashMap();
//map.put("name", "hello");
//map.put("value", "world");
//System.out.println(createLinkStringByGet(map));
StringJoiner joiner = new StringJoiner(",","[","]");
joiner.add("123");
joiner.add("456");
joiner.add("789");
System.out.println(joiner);
}
}
......@@ -37,7 +37,7 @@ public class DmpApiMangeController {
@Autowired
private DmpApiMangeService dmpApiMangeService;
/* *//**
/* *//**
* 授权给他人的API-列表分页查询
*
* @return
......@@ -178,8 +178,8 @@ public class DmpApiMangeController {
* @since 2021-01-19
*/
@ApiOperation(value = "API测试", notes = "API测试")
@GetMapping(value = "/apiTestInfo")
public JsonResult getApiTestInfo(@RequestBody Map<String,Object> params, HttpServletRequest httpRequest) {
@PostMapping(value = "/apiTestInfo")
public JsonResult getApiTestInfo(@RequestBody Map<String, Object> params, HttpServletRequest httpRequest) {
JsonResult jsonResult = new JsonResult();
try {
jsonResult = dmpApiMangeService.apiTestInfo(params);
......@@ -191,6 +191,27 @@ public class DmpApiMangeController {
return jsonResult;
}
/**
* API测试--下拉框
*
* @author Bellamy
* @since 2021-03-03
*/
@ApiOperation(value = "API测试--下拉框", notes = "API测试--下拉框")
@GetMapping(value = "/apiTestGetApiKey")
@ApiImplicitParam(name = "apiKey", value = "apiKey")
public JsonResult getApiTestGetApiKey(@RequestParam(required = false) String apiKey, HttpServletRequest httpRequest) {
JsonResult jsonResult = new JsonResult();
try {
jsonResult = dmpApiMangeService.getApiTestGetApiKey(apiKey);
} catch (Exception e) {
jsonResult.setMessage(e.getMessage());
jsonResult.setCode(ResultCode.INTERNAL_SERVER_ERROR);
e.printStackTrace();
}
return jsonResult;
}
/**
* API日志列表
*
......
......@@ -24,9 +24,20 @@ public class LogInfoListReq extends BasePageBean implements Serializable {
@ApiModelProperty(value = "客户请求token")
private String requestToken;
@ApiModelProperty(value = "开始时间")
private String startDate;
@ApiModelProperty(value = "结束时间")
private String endDate;
@ApiModelProperty(value = "状态:SUCCEED 请求成功, FAIL 请求失败")
private String status;
@ApiModelProperty(value = "创建时间")
private String createDate;
@ApiModelProperty(value = "历史查询-数据银行")
private String historyQuery;
}
......@@ -140,4 +140,12 @@ public interface DmpApiMangeService {
* @since 2021-03-02
*/
JsonResult getAuthOrgName(String orgName) throws Exception;
/**
* API测试--下拉框
*
* @author Bellamy
* @since 2021-03-03
*/
JsonResult getApiTestGetApiKey(String apiKey) throws Exception;
}
......@@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSONObject;
import com.jz.common.constant.GatewayApiConstant;
import com.jz.common.constant.JsonResult;
import com.jz.common.constant.ResultCode;
import com.jz.common.utils.MD5SignUtils;
import com.jz.common.utils.MapUtil;
import com.jz.common.utils.web.HttpClientUtils;
import com.jz.dmp.modules.controller.dataService.bean.*;
import com.jz.dmp.modules.service.DmpApiMangeService;
......@@ -195,10 +197,32 @@ public class DmpApiMangeServiceImpl implements DmpApiMangeService {
@Override
public JsonResult apiTestInfo(Map<String, Object> params) throws Exception {
String url = gatewayUrl + GatewayApiConstant.testApi;
params.put("timestamp", System.currentTimeMillis());
//对签约参数进行字典排序
String signParams = MapUtil.stringNormalSort(assembleSignMap(params));
if (StringUtils.isNotEmpty(signParams)) {
String sign = MD5SignUtils.encrypt(signParams, "");
params.put("sign", sign);
}
JsonResult result = GatewayApiConstant.postRequest2GetData(url, JSONObject.toJSONString(params));
return result;
}
/**
* 组装签名参数
*
* @param params
* @return
*/
private Map assembleSignMap(Map<String, Object> params) {
Map<String, String> paramsMap = new HashMap<>();
paramsMap.put("apiKey", (String) params.get("apiKey"));
paramsMap.put("method", (String) params.get("method"));
paramsMap.put("signType", (String) params.get("signType"));
paramsMap.put("params", JSONObject.toJSONString(params.get("params")));
return paramsMap;
}
/**
* 查看日志
*
......@@ -207,26 +231,8 @@ public class DmpApiMangeServiceImpl implements DmpApiMangeService {
*/
@Override
public JsonResult checkApiLogInfo(LogInfoListReq req) throws Exception {
JsonResult result = new JsonResult();
String url = gatewayUrl + GatewayApiConstant.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("msg")) {
logger.info(jsonObject.get("msg").toString());
result.setCode(ResultCode.INTERNAL_SERVER_ERROR);
result.setMessage(jsonObject.get("msg").toString());
}
JsonResult result = GatewayApiConstant.postRequest2GetData(url, JSONObject.toJSONString(req));
return result;
}
......@@ -437,7 +443,22 @@ public class DmpApiMangeServiceImpl implements DmpApiMangeService {
String url = gatewayUrl + GatewayApiConstant.getOrgNameList;
Map params = new HashMap();
params.put("orgName", orgName);
JsonResult result = GatewayApiConstant.getRequest2GetData(url,params);
JsonResult result = GatewayApiConstant.getRequest2GetData(url, params);
return result;
}
/**
* API测试--下拉框
*
* @author Bellamy
* @since 2021-03-03
*/
@Override
public JsonResult getApiTestGetApiKey(String apiKey) throws Exception {
String url = gatewayUrl + GatewayApiConstant.listGetApiKey;
Map params = new HashMap();
params.put("apiKey", apiKey);
JsonResult result = GatewayApiConstant.getRequest2GetData(url, params);
return result;
}
......
{
"projectId":"35",
"treeId":755,
"taskId":"212",
"srcDataSourceId":"239",
"srcDatasourceTypeId":1,
"targetDataSourceId":"202",
"targetDataSourceTypeId":10,
"regularExpression":"21312312",
"tables":[
{
"sourceTableName":"dmp_table",
"targetTableName":"dmp_table",
"fieldInfo":[
{
"desensitizationField":"is_show",
"arithmetic":"HmacSHA256"
},
{
"desensitizationField":"cn_name",
"arithmetic":"HmacSHA256"
}
]
},
{
"sourceTableName":"dmp_table_column",
"targetTableName":"dmp_table_column",
"fieldInfo":[
]
},
{
"sourceTableName":"dmp_table_field_mapping",
"targetTableName":"dmp_table_field_mapping",
"fieldInfo":[
]
},
{
"sourceTableName":"dmp_table_field_schema",
"targetTableName":"dmp_table_field_schema",
"fieldInfo":[
]
}
]
}
/*{
"projectId":31,
"treeId": 1,
"taskId":181,
......@@ -21,22 +66,4 @@
"pkName":"source_database_name,source_table_name,stat_date"
}
]
}
/*{
"projectId":31,
"treeId": 1,
"taskId":181, //任务id编辑时 需要
"srcDataSourceId":205, //来源数据源id
"targetDataSourceId":202, //目标数据源id
"tables":[
{
"sourceTableName":"dmp_data_contrast", //选择的 来源表
"targetTableName":"dmp_data_contrast", //目标表
"desensitizationField":"target_database_name", //脱敏字段
"arithmetic":"HmacSHA256" //算法
}
]
}*/
\ No newline at end of file
......@@ -108,14 +108,14 @@
"registerTableName": "dmp_azkaban_exector_server_config",
"sourceHdfsPath": "", //HDFS存储目录
"sourceHdfsFile": "",
"sourceFtpDir": "", //文件所在目录
"sourceFtpDir": "", //Ftp文件所在目录
"fileType": "", //文件类型
"sourceCsvDelimiter": "", //分隔符
"sourceCsvCharset": "", //字符集编码
"sourceCsvHeader": "", //是否含有表头
"null值":"",
"compressedFormat":"", //压缩格式
"sourceFtpFile": "", //文件名
"sourceFtpFile": "", //Ftp文件名
"sourceSkipFtpFile": "", //没有数据文件是否跳过
"sourceCsvQuote": "",
"sourceFtpLoadDate": "", //加载数据日期
......
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