|
@@ -8,6 +8,7 @@ import com.jkcredit.info.query.enums.CatalogEnum;
|
|
import com.jkcredit.info.query.service.InformationQueryService;
|
|
import com.jkcredit.info.query.service.InformationQueryService;
|
|
import com.jkcredit.info.query.task.AsyncQuery;
|
|
import com.jkcredit.info.query.task.AsyncQuery;
|
|
import com.jkcredit.info.query.util.CatalogConcurrentHashMapUtil;
|
|
import com.jkcredit.info.query.util.CatalogConcurrentHashMapUtil;
|
|
|
|
+import com.jkcredit.info.query.util.CookieTaskConcurrentHashMapUtil;
|
|
import com.jkcredit.info.query.util.CookieUtil;
|
|
import com.jkcredit.info.query.util.CookieUtil;
|
|
import com.jkcredit.info.query.util.HttpUtil;
|
|
import com.jkcredit.info.query.util.HttpUtil;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -22,7 +23,9 @@ import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
import java.io.UnsupportedEncodingException;
|
|
-import java.net.*;
|
|
|
|
|
|
+import java.net.InetAddress;
|
|
|
|
+import java.net.URLEncoder;
|
|
|
|
+import java.net.UnknownHostException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.concurrent.CountDownLatch;
|
|
import java.util.concurrent.CountDownLatch;
|
|
@@ -55,7 +58,7 @@ public class InformationQueryServiceImpl implements InformationQueryService {
|
|
+ UUID.randomUUID().toString();
|
|
+ UUID.randomUUID().toString();
|
|
log.info("keyWord:{}, type:{}, requestId:{}", keyWord, type, requestId);
|
|
log.info("keyWord:{}, type:{}, requestId:{}", keyWord, type, requestId);
|
|
long startTime = System.currentTimeMillis();
|
|
long startTime = System.currentTimeMillis();
|
|
- String cookie = CookieUtil.getAuthenticationCookie();
|
|
|
|
|
|
+ String cookie = getCookie();
|
|
if (StringUtils.isBlank(cookie)) {
|
|
if (StringUtils.isBlank(cookie)) {
|
|
CommonResponseObject result = CommonResponseObject.failed("查询失败",
|
|
CommonResponseObject result = CommonResponseObject.failed("查询失败",
|
|
CommonConstant.NETWORK_DISABLED, getLocalHost(), requestId);
|
|
CommonConstant.NETWORK_DISABLED, getLocalHost(), requestId);
|
|
@@ -114,13 +117,40 @@ public class InformationQueryServiceImpl implements InformationQueryService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private String getCookie() {
|
|
|
|
+ Map<String, Long> cookieTaskMap = CookieTaskConcurrentHashMapUtil.getInstance();
|
|
|
|
+ if (cookieTaskMap.size() == 0) {
|
|
|
|
+ String cookie = CookieUtil.getNewCookie();
|
|
|
|
+ if (StringUtils.isNotBlank(cookie)) {
|
|
|
|
+ log.info("firstGetCookie:{}", cookie);
|
|
|
|
+ CookieTaskConcurrentHashMapUtil.getInstance().put("cookie", System.currentTimeMillis());
|
|
|
|
+ log.info("InformationQueryServiceImpl.getCookie:{}", cookie);
|
|
|
|
+ }
|
|
|
|
+ return cookie;
|
|
|
|
+ } else {
|
|
|
|
+ long cookieTime = cookieTaskMap.get("cookie");
|
|
|
|
+ if (System.currentTimeMillis() - cookieTime >= 1620000) {
|
|
|
|
+ String cookie = CookieUtil.getNewCookie();
|
|
|
|
+ if (StringUtils.isNotBlank(cookie)) {
|
|
|
|
+ log.info("reloadCookie:{}", cookie);
|
|
|
|
+ CookieTaskConcurrentHashMapUtil.getInstance().put("cookie", System.currentTimeMillis());
|
|
|
|
+ log.info("InformationQueryServiceImpl.getCookie:{}", cookie);
|
|
|
|
+ }
|
|
|
|
+ return cookie;
|
|
|
|
+ } else {
|
|
|
|
+ log.info("usefulCookie:{}", CookieUtil.getAuthenticationCookie());
|
|
|
|
+ return CookieUtil.getAuthenticationCookie();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public CommonResponseObject queryList(String keyWord, String type) {
|
|
public CommonResponseObject queryList(String keyWord, String type) {
|
|
String requestId = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date())
|
|
String requestId = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date())
|
|
+ UUID.randomUUID().toString();
|
|
+ UUID.randomUUID().toString();
|
|
log.info("keyWord:{}, type:{}, requestId:{}", keyWord, type, requestId);
|
|
log.info("keyWord:{}, type:{}, requestId:{}", keyWord, type, requestId);
|
|
long startTime = System.currentTimeMillis();
|
|
long startTime = System.currentTimeMillis();
|
|
- String cookie = CookieUtil.getAuthenticationCookie();
|
|
|
|
|
|
+ String cookie = getCookie();
|
|
if (StringUtils.isBlank(cookie)) {
|
|
if (StringUtils.isBlank(cookie)) {
|
|
CommonResponseObject result = CommonResponseObject.failed("查询失败",
|
|
CommonResponseObject result = CommonResponseObject.failed("查询失败",
|
|
CommonConstant.NETWORK_DISABLED, getLocalHost(), requestId);
|
|
CommonConstant.NETWORK_DISABLED, getLocalHost(), requestId);
|
|
@@ -184,6 +214,15 @@ public class InformationQueryServiceImpl implements InformationQueryService {
|
|
long startTime = System.currentTimeMillis();
|
|
long startTime = System.currentTimeMillis();
|
|
String requestId = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date())
|
|
String requestId = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date())
|
|
+ UUID.randomUUID().toString();
|
|
+ UUID.randomUUID().toString();
|
|
|
|
+ String cookie = getCookie();
|
|
|
|
+ if (StringUtils.isBlank(cookie)) {
|
|
|
|
+ CommonResponseObject result = CommonResponseObject.failed("查询失败",
|
|
|
|
+ CommonConstant.NETWORK_DISABLED, getLocalHost(), requestId);
|
|
|
|
+ log.info("path:{}, requestId:{}, result:{}, costTime:{}"
|
|
|
|
+ , path, requestId, JSON.toJSONString(result), (System.currentTimeMillis() - startTime));
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
log.info("path:{}, requestId:{}", path, requestId);
|
|
log.info("path:{}, requestId:{}", path, requestId);
|
|
if (!path.contains("../")) {
|
|
if (!path.contains("../")) {
|
|
CommonResponseObject result = CommonResponseObject.noResult(getLocalHost(), requestId);
|
|
CommonResponseObject result = CommonResponseObject.noResult(getLocalHost(), requestId);
|
|
@@ -191,7 +230,7 @@ public class InformationQueryServiceImpl implements InformationQueryService {
|
|
, path, requestId, JSON.toJSONString(result), (System.currentTimeMillis() - startTime));
|
|
, path, requestId, JSON.toJSONString(result), (System.currentTimeMillis() - startTime));
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
- List<Map<String, String>> results = getDetail(path);
|
|
|
|
|
|
+ List<Map<String, String>> results = getDetail(path, cookie);
|
|
if (results.size() != 0) {
|
|
if (results.size() != 0) {
|
|
CommonResponseObject result = CommonResponseObject.success(results, getLocalHost(), requestId);
|
|
CommonResponseObject result = CommonResponseObject.success(results, getLocalHost(), requestId);
|
|
log.info("path:{}, requestId:{}, result:{}, costTime:{}"
|
|
log.info("path:{}, requestId:{}, result:{}, costTime:{}"
|
|
@@ -211,6 +250,16 @@ public class InformationQueryServiceImpl implements InformationQueryService {
|
|
Document doc = Jsoup.parse(content);
|
|
Document doc = Jsoup.parse(content);
|
|
Elements elementList = doc.select("td").select(".column");
|
|
Elements elementList = doc.select("td").select(".column");
|
|
for (Element element : elementList) {
|
|
for (Element element : elementList) {
|
|
|
|
+ String imageUrl = "";
|
|
|
|
+ String url = element.select(".detailImage").attr("data-url");
|
|
|
|
+ if (url.contains("/photoSearch/singlePhotoSearch.action")) {
|
|
|
|
+ imageUrl = url.replace("../photoSearch/singlePhotoSearch.action",
|
|
|
|
+ "http://51.1.0.67:80/info-query/getImage");
|
|
|
|
+ } else if (url.contains("/crjPhotoSearch/singlePhotoSearch.action")) {
|
|
|
|
+ imageUrl = url.replace("../crjPhotoSearch/singlePhotoSearch.action",
|
|
|
|
+ "http://51.1.0.67:80/info-query/getCrjImage");
|
|
|
|
+ }
|
|
|
|
+
|
|
Elements tdList = element.select(".kyfuse-form-value");
|
|
Elements tdList = element.select(".kyfuse-form-value");
|
|
Map<String, String> tdMap = new HashMap<>();
|
|
Map<String, String> tdMap = new HashMap<>();
|
|
for (Element td : tdList) {
|
|
for (Element td : tdList) {
|
|
@@ -224,21 +273,34 @@ public class InformationQueryServiceImpl implements InformationQueryService {
|
|
} else {
|
|
} else {
|
|
tdMap.put("detailPath", element.select("a").attr("url"));
|
|
tdMap.put("detailPath", element.select("a").attr("url"));
|
|
}
|
|
}
|
|
|
|
+ tdMap.put("imageUrl", imageUrl);
|
|
}
|
|
}
|
|
return results;
|
|
return results;
|
|
}
|
|
}
|
|
|
|
|
|
- private List<Map<String, String>> getDetail(String path) {
|
|
|
|
|
|
+ private List<Map<String, String>> getDetail(String path, String cookie) {
|
|
List<Map<String, String>> results = new ArrayList<>();
|
|
List<Map<String, String>> results = new ArrayList<>();
|
|
String url = path.replace("../", hostUrl).replace("amp;", "");
|
|
String url = path.replace("../", hostUrl).replace("amp;", "");
|
|
- String detailInfoContent = HttpUtil.doGet(url, CookieUtil.getAuthenticationCookie());
|
|
|
|
|
|
+ String detailInfoContent = HttpUtil.doGet(url, cookie);
|
|
Document detailDoc = Jsoup.parse(detailInfoContent);
|
|
Document detailDoc = Jsoup.parse(detailInfoContent);
|
|
Elements elements = detailDoc.select(".detail-info-list");
|
|
Elements elements = detailDoc.select(".detail-info-list");
|
|
|
|
+
|
|
|
|
+ String imageUrl = "";
|
|
|
|
+ String srcUrl = detailDoc.select(".detail-phone").attr("src");
|
|
|
|
+ if (srcUrl.contains("/photoSearch/singlePhotoSearch.action")) {
|
|
|
|
+ imageUrl = srcUrl.replace("/photoSearch/singlePhotoSearch.action",
|
|
|
|
+ "http://51.1.0.67:80/info-query/getImage");
|
|
|
|
+ } else if (srcUrl.contains("/crjPhotoSearch/singlePhotoSearch.action")) {
|
|
|
|
+ imageUrl = srcUrl.replace("/crjPhotoSearch/singlePhotoSearch.action",
|
|
|
|
+ "http://51.1.0.67:80/info-query/getCrjImage");
|
|
|
|
+ }
|
|
|
|
+
|
|
Map<String, String> detailMap = new HashMap<>();
|
|
Map<String, String> detailMap = new HashMap<>();
|
|
for (int i = 0; i < elements.size(); i++) {
|
|
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 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();
|
|
String dataValue = detailDoc.select(".detail-info-list").get(i).select("span").get(1).text();
|
|
detailMap.put(dataName, dataValue);
|
|
detailMap.put(dataName, dataValue);
|
|
|
|
+ detailMap.put("imageUrl", imageUrl);
|
|
}
|
|
}
|
|
if (detailMap.size() != 0) {
|
|
if (detailMap.size() != 0) {
|
|
results.add(detailMap);
|
|
results.add(detailMap);
|