Commit 1dfee283 by yuwei

2.0.0项目初始化

parent c044641a
......@@ -47,7 +47,7 @@ public class MD5Util {
public static void main(String[] args) {
try {
String value = "1214835832967581698";
String value = "1246656415670484994";
MD5Util mt = new MD5Util();
System.out.println("加密前的字符:" + value);
System.out.println("加密后的字符:" + mt.encode(value));
......
......@@ -6,9 +6,11 @@ import cn.datax.common.utils.HttpUtil;
import cn.datax.common.utils.IPUtil;
import cn.datax.common.utils.MD5Util;
import cn.datax.common.utils.ResponseUtil;
import cn.datax.service.data.market.api.call.service.ApiLogService;
import cn.datax.service.data.market.api.call.utils.ThreadUtil;
import cn.datax.service.data.market.api.dto.ApiLogDto;
import cn.datax.service.data.market.api.entity.DataApiEntity;
import cn.datax.service.data.market.api.enums.DataType;
import cn.datax.service.data.market.api.feign.DataApiServiceFeign;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
......@@ -39,6 +41,9 @@ public class ApiInterceptor implements HandlerInterceptor {
@Autowired
private DataApiServiceFeign dataApiServiceFeign;
@Autowired
private ApiLogService apiLogService;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
System.out.println("************ApiInterceptor preHandle executed**********");
......@@ -91,7 +96,8 @@ public class ApiInterceptor implements HandlerInterceptor {
dataApiEntity.getReqParams().stream().forEach(param -> {
if (params.containsKey(param.getParamName())) {
Integer dataType = param.getDataType();
// 数据类型转换
// 数据类型是否正确
DataType.parse(DataType.getDataType(dataType), params.get(param.getParamName()));
}
});
String apiName = dataApiEntity.getApiName();
......@@ -143,8 +149,9 @@ public class ApiInterceptor implements HandlerInterceptor {
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
ThreadUtil.getInstance().get().setTime(System.currentTimeMillis() - ThreadUtil.getInstance().get().getTime());
log.info("调用消耗时间:" + ThreadUtil.getInstance().get().getTime());
log.info("调用耗时:" + ThreadUtil.getInstance().get().getTime());
log.info("调用日志:" + ThreadUtil.getInstance().get());
apiLogService.saveApiLog(ThreadUtil.getInstance().get());
ThreadUtil.getInstance().remove();
}
}
......@@ -40,8 +40,6 @@ public class ApiCallServiceImpl implements ApiCallService {
@Override
public PageResult<Map<String, Object>> v1() {
// 缓存取数据
// redisTemplate.opsForValue().get("myCache::userName")
R apiResult = dataApiServiceFeign.getDataApiById(ThreadUtil.getInstance().get().getApiId());
if(apiResult == null || !apiResult.isSuccess() || ObjectUtil.isEmpty(apiResult.getData())){
ThreadUtil.getInstance().get().setStatus(0);
......
......@@ -45,7 +45,7 @@ public class ApiLogEntity implements Serializable {
*/
private String callerParams;
/**
* 调用返回数据量
* 调用数据量
*/
private Integer callerSize;
/**
......
package cn.datax.service.data.market.api.enums;
import cn.datax.common.exception.DataException;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import java.math.BigDecimal;
public enum DataType {
String(1, "字符串"),
......@@ -25,10 +31,55 @@ public enum DataType {
return val;
}
// public Object parse(Object obj) {
// if (obj == null) return null;
// switch (this) {
//
// }
// }
public static Object parse(DataType dataType, Object obj) {
if (ObjectUtil.isEmpty(obj)) {
return null;
}
switch (dataType) {
case String:
try {
return (java.lang.String)obj;
} catch (Exception e) {
throw new DataException("参数值[" + obj + "]不是" + String.getVal() + "数据类型]");
}
case Float:
try {
return new BigDecimal(obj.toString()).doubleValue();
} catch (Exception e) {
throw new DataException("参数值[" + obj + "]不是" + Float.getVal() + "数据类型]");
}
case Integer:
try {
return (java.lang.Integer)obj;
} catch (Exception e) {
throw new DataException("参数值[" + obj + "]不是" + Integer.getVal() + "数据类型]");
}
case List:
try {
return (java.util.List<?>)obj;
} catch (Exception e) {
throw new DataException("参数值[" + obj + "]不是" + List.getVal() + "数据类型]");
}
case Date:
try {
return DateUtil.parse(obj.toString(), "yyyy-MM-dd HH:mm:ss");
} catch (Exception e) {
try {
return DateUtil.parse(obj.toString(), "yyyy-MM-dd");
} catch (Exception ex) {
throw new DataException("参数值[" + obj + "]不是" + Date.getVal() + "数据类型]");
}
}
}
return null;
}
public static DataType getDataType(Integer dataType) {
for (DataType type : DataType.values()) {
if (type.key == dataType) {
return type;
}
}
return String;
}
}
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