|
@@ -114,6 +114,138 @@ public class InformationQueryServiceImpl implements InformationQueryService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public CommonResponseObject queryList(String keyWord, String type) {
|
|
|
+ String requestId = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date())
|
|
|
+ + UUID.randomUUID().toString();
|
|
|
+ log.info("keyWord:{}, type:{}, requestId:{}", keyWord, type, requestId);
|
|
|
+ long startTime = System.currentTimeMillis();
|
|
|
+ String cookie = CookieUtil.getAuthenticationCookie();
|
|
|
+ if (StringUtils.isBlank(cookie)) {
|
|
|
+ CommonResponseObject result = CommonResponseObject.failed("查询失败",
|
|
|
+ CommonConstant.NETWORK_DISABLED, getLocalHost(), requestId);
|
|
|
+ log.info("keyWord:{}, type:{}, requestId:{}, result:{}, costTime:{}"
|
|
|
+ , keyWord, type, requestId, JSON.toJSONString(result), (System.currentTimeMillis() - startTime));
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ Map<String, JSONObject> catalogIdMap = CatalogConcurrentHashMapUtil.getInstance();
|
|
|
+ if (catalogIdMap.size() == 0) {
|
|
|
+ // 查询节点id
|
|
|
+ FormBody formBody = new FormBody.Builder()
|
|
|
+ .add("pinyin", "false")
|
|
|
+ .add("keyWord", keyWord)
|
|
|
+ .build();
|
|
|
+ String catalogContent = HttpUtil.doPost(catalogUrl, formBody, cookie);
|
|
|
+ catalogIdMap = getCatalogIds(catalogContent);
|
|
|
+ CatalogConcurrentHashMapUtil.getInstance().putAll(catalogIdMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ String id = "";
|
|
|
+ String queryId = "";
|
|
|
+ for (Map.Entry<String, JSONObject> entry : catalogIdMap.entrySet()) {
|
|
|
+ String catalogName = entry.getKey();
|
|
|
+ if (type.equals(catalogName)) {
|
|
|
+ JSONObject catalogIdObject = entry.getValue();
|
|
|
+ queryId = catalogIdObject.getString("queryId");
|
|
|
+ id = catalogIdObject.getString("id");
|
|
|
+ } else {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String encodeKeyWord = "";
|
|
|
+ try {
|
|
|
+ encodeKeyWord = URLEncoder.encode(keyWord, "utf-8");
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ StringBuffer stringBuffer = new StringBuffer(queryResultUrl);
|
|
|
+ stringBuffer.append("?pinyin=false");
|
|
|
+ stringBuffer.append("&keyWord=").append(encodeKeyWord);
|
|
|
+ stringBuffer.append("&reportQuery.id=").append(queryId);
|
|
|
+ stringBuffer.append("&resource.id=").append(id);
|
|
|
+ String resultContent = HttpUtil.doGet(stringBuffer.toString(), cookie);
|
|
|
+ List<Map<String, String>> listInfo = getListInfo(type, resultContent);
|
|
|
+
|
|
|
+ if (listInfo.size() != 0) {
|
|
|
+ CommonResponseObject result = CommonResponseObject.success(listInfo, getLocalHost(), requestId);
|
|
|
+ log.info("keyWord:{}, type:{}, requestId:{}, result:{}, costTime:{}"
|
|
|
+ , keyWord, type, requestId, JSON.toJSONString(result), (System.currentTimeMillis() - startTime));
|
|
|
+ return result;
|
|
|
+ } else {
|
|
|
+ CommonResponseObject result = CommonResponseObject.noResult(getLocalHost(), requestId);
|
|
|
+ log.info("keyWord:{}, type:{}, requestId:{}, result:{}, costTime:{}"
|
|
|
+ , keyWord, type, requestId, JSON.toJSONString(result), (System.currentTimeMillis() - startTime));
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CommonResponseObject queryDetail(String path) {
|
|
|
+ long startTime = System.currentTimeMillis();
|
|
|
+ String requestId = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date())
|
|
|
+ + UUID.randomUUID().toString();
|
|
|
+ log.info("path:{}, requestId:{}", path, requestId);
|
|
|
+ if (!path.contains("../")) {
|
|
|
+ CommonResponseObject result = CommonResponseObject.noResult(getLocalHost(), requestId);
|
|
|
+ log.info("path:{}, requestId:{}, result:{}, costTime:{}"
|
|
|
+ , path, requestId, JSON.toJSONString(result), (System.currentTimeMillis() - startTime));
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ List<Map<String, String>> results = getDetail(path);
|
|
|
+ if (results.size() != 0) {
|
|
|
+ CommonResponseObject result = CommonResponseObject.success(results, getLocalHost(), requestId);
|
|
|
+ log.info("path:{}, requestId:{}, result:{}, costTime:{}"
|
|
|
+ , path, requestId, JSON.toJSONString(result), (System.currentTimeMillis() - startTime));
|
|
|
+ return result;
|
|
|
+ } else {
|
|
|
+ CommonResponseObject result = CommonResponseObject.noResult(getLocalHost(), requestId);
|
|
|
+ log.info("path:{}, requestId:{}, result:{}, costTime:{}"
|
|
|
+ , path, requestId, JSON.toJSONString(result), (System.currentTimeMillis() - startTime));
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Map<String, String>> getListInfo(String type, String content) {
|
|
|
+ List<Map<String, String>> results = new ArrayList<>();
|
|
|
+
|
|
|
+ Document doc = Jsoup.parse(content);
|
|
|
+ Elements elementList = doc.select("td").select(".column");
|
|
|
+ for (Element element : elementList) {
|
|
|
+ Elements tdList = element.select(".kyfuse-form-value");
|
|
|
+ Map<String, String> tdMap = new HashMap<>();
|
|
|
+ for (Element td : tdList) {
|
|
|
+ String dataName = td.attr("data-name");
|
|
|
+ String dataValue = td.attr("data-value");
|
|
|
+ tdMap.put(dataName, dataValue);
|
|
|
+ }
|
|
|
+ results.add(tdMap);
|
|
|
+ if (type.equals("stolenVehicleInfo")) {
|
|
|
+ tdMap.put("detailPath", element.select("a").eachAttr("url").get(1));
|
|
|
+ } else {
|
|
|
+ tdMap.put("detailPath", element.select("a").attr("url"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return results;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Map<String, String>> getDetail(String path) {
|
|
|
+ List<Map<String, String>> results = new ArrayList<>();
|
|
|
+ String url = path.replace("../", hostUrl).replace("amp;", "");
|
|
|
+ String detailInfoContent = HttpUtil.doGet(url, CookieUtil.getAuthenticationCookie());
|
|
|
+ Document detailDoc = Jsoup.parse(detailInfoContent);
|
|
|
+ Elements elements = detailDoc.select(".detail-info-list");
|
|
|
+ Map<String, String> detailMap = new HashMap<>();
|
|
|
+ for (int i = 0; i < elements.size(); i++) {
|
|
|
+ String dataName = detailDoc.select(".detail-info-list").get(i).select("span").get(1).attr("data-name");
|
|
|
+ String dataValue = detailDoc.select(".detail-info-list").get(i).select("span").get(1).text();
|
|
|
+ detailMap.put(dataName, dataValue);
|
|
|
+ }
|
|
|
+ if (detailMap.size() != 0) {
|
|
|
+ results.add(detailMap);
|
|
|
+ }
|
|
|
+ return results;
|
|
|
+ }
|
|
|
+
|
|
|
// 处理列表多条返回的情况
|
|
|
private List<Map<String, String>> getDetailInfo(String content) {
|
|
|
List<Map<String, String>> results = new ArrayList<>();
|