|
@@ -3,17 +3,19 @@ package com.hhwy.qbeqsjy.kafka.service;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
+import com.hhwy.qbeqsjy.common.CommonUtil;
|
|
|
+import com.hhwy.qbeqsjy.common.Constants;
|
|
|
import com.hhwy.qbeqsjy.common.HttpClient;
|
|
|
+import com.hhwy.qbeqsjy.common.TimeTool;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.http.NameValuePair;
|
|
|
import org.apache.http.message.BasicNameValuePair;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -39,16 +41,21 @@ public class SameTravelService {
|
|
|
private String fwkfptTokenUrl;
|
|
|
@Value("${fwkfpt.uniQuery.url}")
|
|
|
private String fwkfptUniQueryUrl;
|
|
|
+ @Value("${tx.query.max.count}")
|
|
|
+ private String maxReturnNum;
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 调用烽火同行类数据通查服务接口
|
|
|
+ * @param conditionFieldValue 条件查询的字段值
|
|
|
+ * @param resourceName 条件查询的数据资源标识符(烽火标准)
|
|
|
* @return
|
|
|
*/
|
|
|
- public List<Map<String, Object>> callFHUniQueryService(){
|
|
|
+ public List<Map<String, Object>> callFHUniQueryService(String conditionFieldValue, String resourceName){
|
|
|
List<Map<String, Object>> dataList = new ArrayList<>();
|
|
|
+ // ========== 获取烽火 - 服务开放平台token
|
|
|
Map<String, Object> tokenHeaderParamsMap = new HashMap<>();
|
|
|
- tokenHeaderParamsMap.put("Content-Type", "application/x-www-form-urlencoded");
|
|
|
+ tokenHeaderParamsMap.put("Content-Type", Constants.URLENCODED_RSP_TYPE);
|
|
|
Map<String, Object> userTokenMap = new HashMap<>();
|
|
|
userTokenMap.put("type", fwkfptType);
|
|
|
userTokenMap.put("policeNo", fwkfptPoliceNo);
|
|
@@ -76,17 +83,52 @@ public class SameTravelService {
|
|
|
userTokenId = JSON.parseObject(userTokenJSONStr).getString("userToken");
|
|
|
log.info("获取【烽火 - 服务开放平台 # 权限认证令牌】 令牌创建成功,响应消息:{}", content);
|
|
|
}
|
|
|
+
|
|
|
long start = System.currentTimeMillis();
|
|
|
+ // ========== 构造请求头
|
|
|
Map<String, Object> headerParamsMap = new HashMap<>();
|
|
|
- headerParamsMap.put("Content-Type", "application/json");
|
|
|
+ headerParamsMap.put("Content-Type", Constants.DEFAULT_RSP_TYPE);
|
|
|
headerParamsMap.put("app_token", appTokenId);
|
|
|
headerParamsMap.put("user_token", userTokenId);
|
|
|
headerParamsMap.put("userid", fwkfptUserId);
|
|
|
headerParamsMap.put("subid", fwkfptAppId);
|
|
|
headerParamsMap.put("serviceid", fwkfptServiceId);
|
|
|
headerParamsMap.put("SenderID", fwkfptSenderId);
|
|
|
- String reqBody = "{ \"From\":\"120000\", \"To\":\"120000\", \"MessageSequence\":\"2020030314141200001\", \"RequestParam\":{ \"Condition\":\"VEH_PLATE_NUM='津RVG959'\", \"OtherCondition\":{ \"AsyncBoolean\":\"0\", \"AsyncIdentity\":\"0\", \"AsyncOnceReturnNum\":\"100\", \"AsyncQuery\":\"\", \"CallbackID\":\"\", \"CodeMode\":\"0\", \"MaxReturnNum\":\"10\", \"SortResults\":\"ILLE_TIME+\" }, \"ResourceInfos\":[ { \"DataItems\":[ { \"Name\":\"VEH_PLATE_NUM\", \"Fmt\": \"\" }, { \"Name\":\"ILLE_TIME\", \"Fmt\": \"\" } ], \"ResourceName\":\"R-120000000001-00000170\" } ] } }";
|
|
|
- String rspStr = httpClient.postResource(fwkfptUniQueryUrl, reqBody, headerParamsMap);
|
|
|
+ // ========== 构造请求体
|
|
|
+ Map<String, Object> reqBody = new HashMap<>();
|
|
|
+ reqBody.put("From", Constants.AREA_CODE_TJ);
|
|
|
+ reqBody.put("To", Constants.AREA_CODE_TJ);
|
|
|
+ reqBody.put("MessageSequence", TimeTool.timeStampToDateString4(TimeTool.getNowTimeStamp()));
|
|
|
+ Map<String, Object> requestParam = new HashMap<>();
|
|
|
+ List<String> rspFieldNameList = Arrays.asList(CommonUtil.getConfValueByKey(resourceName).split(","));
|
|
|
+ requestParam.put("Condition", rspFieldNameList.get(0) + "='" + conditionFieldValue + "'");
|
|
|
+ Map<String, Object> otherCondition = new HashMap<>();
|
|
|
+ otherCondition.put("AsyncBoolean", Constants.STR_NUM_0);
|
|
|
+ otherCondition.put("AsyncIdentity", Constants.STR_NUM_0);
|
|
|
+ otherCondition.put("AsyncOnceReturnNum", maxReturnNum);
|
|
|
+ otherCondition.put("AsyncQuery", "");
|
|
|
+ otherCondition.put("CallbackID", "");
|
|
|
+ otherCondition.put("CodeMode", Constants.STR_NUM_0);
|
|
|
+ otherCondition.put("MaxReturnNum", maxReturnNum);
|
|
|
+ otherCondition.put("SortResults", "");
|
|
|
+ requestParam.put("OtherCondition", otherCondition);
|
|
|
+ List<Map<String, Object>> resourceInfosList = new ArrayList<>();
|
|
|
+ Map<String, Object> resourceInfoMap = new HashMap<>();
|
|
|
+ List<Map<String, Object>> dataItemsList = new ArrayList<>();
|
|
|
+ for (String fieldName : rspFieldNameList) {
|
|
|
+ Map<String, Object> dataItemMap = new HashMap<>();
|
|
|
+ dataItemMap.put("Fmt", "");
|
|
|
+ dataItemMap.put("Name", fieldName);
|
|
|
+ dataItemsList.add(dataItemMap);
|
|
|
+ }
|
|
|
+ resourceInfoMap.put("DataItems", dataItemsList);
|
|
|
+ resourceInfoMap.put("ResourceName", resourceName);
|
|
|
+ resourceInfosList.add(resourceInfoMap);
|
|
|
+ requestParam.put("ResourceInfos", resourceInfosList);
|
|
|
+ reqBody.put("RequestParam", requestParam);
|
|
|
+ log.info(JSON.toJSONString(reqBody, SerializerFeature.WriteMapNullValue));
|
|
|
+
|
|
|
+ String rspStr = httpClient.postResource(fwkfptUniQueryUrl, JSON.toJSONString(reqBody, SerializerFeature.WriteMapNullValue), headerParamsMap);
|
|
|
JSONObject rspJSONObj = JSON.parseObject(rspStr);
|
|
|
if(rspJSONObj != null){
|
|
|
String messageStatus = rspJSONObj.getString("MessageStatus");
|
|
@@ -96,7 +138,7 @@ public class SameTravelService {
|
|
|
JSONArray resourceInfos = responseParam.getJSONArray("ResourceInfos");
|
|
|
if(resourceInfos != null && resourceInfos.size() > 0){
|
|
|
JSONObject jsonObject = resourceInfos.getJSONObject(0);
|
|
|
- String resourceName = jsonObject.getString("ResourceName");
|
|
|
+ String resName = jsonObject.getString("ResourceName");
|
|
|
JSONArray dataInfo = jsonObject.getJSONArray("DataInfo");
|
|
|
if(dataInfo != null && dataInfo.size() > 0){ // 存在命中数据
|
|
|
JSONArray dataItems = jsonObject.getJSONArray("DataItems");
|
|
@@ -113,11 +155,17 @@ public class SameTravelService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- log.info("【烽火 - 服务开放平台 # 同行类数据通查服务接口 响应数据解析完成】 命中数据量:{}", dataList.size());
|
|
|
}
|
|
|
}
|
|
|
+ log.info("【烽火 - 服务开放平台 # 同行类数据通查服务接口 响应数据解析完成】 命中数据量:{}", dataList.size());
|
|
|
return dataList;
|
|
|
}
|
|
|
|
|
|
|
|
|
+ public static void main(String[] args) {
|
|
|
+ SameTravelService sameTravelService = new SameTravelService();
|
|
|
+ sameTravelService.callFHUniQueryService("120000xxxx", "R-120000000000-00000003");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|