|
@@ -5,8 +5,8 @@ import cn.hutool.extra.spring.SpringUtil;
|
|
|
import cn.hutool.http.HttpRequest;
|
|
|
import cn.hutool.http.HttpResponse;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
+import cn.hutool.json.JSONException;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
-import com.sundata.admin.AdminUtil;
|
|
|
import com.sundata.common.exception.BusinessException;
|
|
|
import com.sundata.common.util.JsonUtil;
|
|
|
import com.sundata.internalevaluation.calc.calcUnit.interfaces.InterfaceRunning;
|
|
@@ -27,6 +27,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
/**
|
|
|
* Created by IntelliJ IDEA.
|
|
@@ -123,8 +124,9 @@ public class InterfaceCalcUnit extends CalcUnit {
|
|
|
Map<CalcUnit, CalcResult<String, Object>> sourceResults) {
|
|
|
|
|
|
log.debug("计算{}:编号:{},名称:{},流水号:{}", getCalcType().getName(), getCalcCode(), getCalcName(), calculateInstanceNumber);
|
|
|
- // 获取新流水号,每次请求接口必须不一样
|
|
|
- String globalReqNo = AdminUtil.getNextId("cretSeqno");
|
|
|
+ // 获取新流水号,每次请求接口必须不一样 TODO 根据实际情况生成全局流水号
|
|
|
+// String globalReqNo = AdminUtil.getNextId("cretSeqno");
|
|
|
+ String globalReqNo = UUID.randomUUID().toString();
|
|
|
context.put("globalReqNo",globalReqNo);
|
|
|
// creditSeqNo 查询征信的流水号 如果不存在就重新赋值 只有征信的请求才会用到
|
|
|
context.putIfAbsent("creditSeqNo",globalReqNo);
|
|
@@ -166,7 +168,7 @@ public class InterfaceCalcUnit extends CalcUnit {
|
|
|
// 拼接url 其中可能存在变量
|
|
|
String url = interfaceTypeCode + "://" +
|
|
|
interfaceModel.getInterfaceIp() + ":" +
|
|
|
- interfaceModel.getInterfacePort() +
|
|
|
+ interfaceModel.getInterfacePort() +"/"+
|
|
|
interfaceModel.getInterfaceUrl();
|
|
|
|
|
|
Map<String,Object> allMap = new HashMap<>(headersMap);
|
|
@@ -220,22 +222,29 @@ public class InterfaceCalcUnit extends CalcUnit {
|
|
|
try (HttpResponse httpResponse = httpRequest.execute()) {
|
|
|
responseStr = httpResponse.body();
|
|
|
log.debug("接口-[{}({})]-请求地址-[{}]-响应body报文:{}",getCalcName(),getCalcCode(),url,responseStr);
|
|
|
- String respParamTypeCode = interfaceModel.getRespParamTypeCode();
|
|
|
- if ("json".equals(respParamTypeCode)){
|
|
|
- responseStr = JSONUtil.toJsonPrettyStr(responseStr);
|
|
|
- }
|
|
|
- // TODO 可继续增加其他类型
|
|
|
- else
|
|
|
- {
|
|
|
- throw new RuntimeException("接口-目前只支持 json 返回报文");
|
|
|
- }
|
|
|
-
|
|
|
}catch (Exception e){
|
|
|
String errMsg = StrUtil.format("接口-[{}({})]-请求地址-[{}] - 请求出现异常:{}", getCalcName(), getCalcCode(), url, e.getMessage());
|
|
|
log.error(errMsg);
|
|
|
throw new BusinessException(errMsg, e);
|
|
|
}
|
|
|
|
|
|
+ // 判断返回值类型
|
|
|
+ String respParamTypeCode = interfaceModel.getRespParamTypeCode();
|
|
|
+ if ("json".equals(respParamTypeCode)){
|
|
|
+ try {
|
|
|
+ responseStr = JSONUtil.toJsonPrettyStr(responseStr);
|
|
|
+ } catch (JSONException e) {
|
|
|
+ log.error("接口-[{}({})]-请求地址-[{}] - 返回值不是程序能解析的json字符串,请检查!", getCalcName(), getCalcCode(), url);
|
|
|
+ throw new CalcException(calculateInstanceNumber, "返回值不是程序能解析的json字符串,请检查!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // TODO 可继续增加其他类型
|
|
|
+ else
|
|
|
+ {
|
|
|
+ throw new RuntimeException("接口-目前只支持 json 返回报文");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
// 解密逻辑
|
|
|
String decryptionLogic = interfaceModel.getDecryptionLogic();
|
|
@@ -258,14 +267,38 @@ public class InterfaceCalcUnit extends CalcUnit {
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
- responseStr 一定是如下结果,否则后期计算会报错
|
|
|
+ responseStr 一定是如下结果(键为字符串,值为数组的Json字符串),否则后期计算会报错
|
|
|
{
|
|
|
"propA":[
|
|
|
- ]
|
|
|
+ {
|
|
|
+ "propA1":"valueA1-1",
|
|
|
+ "propA2":"valueA1-2",
|
|
|
+ "propA3":"valueA1-3",
|
|
|
+ ...
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "propA1":"valueA2-1",
|
|
|
+ "propA2":"valueA2-2",
|
|
|
+ "propA3":"valueA2-3",
|
|
|
+ },
|
|
|
+ ...
|
|
|
+ ],
|
|
|
+ "propB":[
|
|
|
+ {
|
|
|
+ "propB1":"valueB1-1",
|
|
|
+ "propB2":"valueB1-2",
|
|
|
+ "propB3":"valueB1-3",
|
|
|
+ ...
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "propB1":"valueB2-1",
|
|
|
+ "propB2":"valueB2-2",
|
|
|
+ "propB3":"valueB2-3",
|
|
|
+ },
|
|
|
+ ...
|
|
|
+ ],
|
|
|
+ ...
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
*/
|
|
|
// 保存结果
|
|
|
thisResult.put(getCalcCode(), responseStr);
|