|
|
@ -1,16 +1,16 @@ |
|
|
|
package com.supervise.rms.config; |
|
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
import cn.hutool.json.JSONArray; |
|
|
|
import cn.hutool.json.JSONException; |
|
|
|
import cn.hutool.json.JSONObject; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.google.gson.Gson; |
|
|
|
import com.supervise.rms.api.businessriskdata.BusinessRiskDataDto; |
|
|
|
import com.supervise.rms.api.Feign.projectinformation.ProjectInformationFeign; |
|
|
|
import com.supervise.rms.api.Feign.projectinformation.ProjectInformationQuery; |
|
|
|
import com.supervise.rms.api.Feign.projectinformation.ProjectInformationVo; |
|
|
|
import com.supervise.rms.api.businessriskdate.BusinessRiskDateDto; |
|
|
|
import com.supervise.rms.api.enterpriseinformation.EnterpriseInformation; |
|
|
|
import com.supervise.rms.biz.businessriskdate.BusinessRiskDateService; |
|
|
|
import com.supervise.rms.biz.enterpriseinformation.EnterpriseInformationService; |
|
|
|
import com.yxt.common.core.query.PagerQuery; |
|
|
|
import com.yxt.common.core.result.ResultBean; |
|
|
|
import com.yxt.common.core.vo.PagerVo; |
|
|
|
import org.apache.commons.codec.digest.DigestUtils; |
|
|
|
import org.apache.http.Header; |
|
|
|
import org.apache.http.HttpEntity; |
|
|
@ -27,10 +27,10 @@ import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; |
|
|
|
import org.apache.http.util.EntityUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.scheduling.annotation.EnableScheduling; |
|
|
|
import org.springframework.scheduling.annotation.Scheduled; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import javax.net.ssl.SSLContext; |
|
|
|
import javax.net.ssl.TrustManager; |
|
|
|
import javax.net.ssl.X509TrustManager; |
|
|
@ -38,23 +38,19 @@ import java.io.IOException; |
|
|
|
import java.security.KeyManagementException; |
|
|
|
import java.security.NoSuchAlgorithmException; |
|
|
|
import java.security.cert.X509Certificate; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
/** |
|
|
|
* @author feikefei |
|
|
|
* @create 2023-06-07-9:37 |
|
|
|
*/ |
|
|
|
@Component |
|
|
|
@EnableScheduling |
|
|
|
public class QichachaConfig { |
|
|
|
private static PoolingHttpClientConnectionManager httpClientConnectionManager; |
|
|
|
@Autowired |
|
|
|
private EnterpriseInformationService enterpriseInformationService; |
|
|
|
@Autowired |
|
|
|
private BusinessRiskDateService businessRiskDateService; |
|
|
|
@Resource |
|
|
|
private ProjectInformationFeign projectInformationFeign; |
|
|
|
|
|
|
|
@Value("${qichacha.appKey}") |
|
|
|
private String APPkey; |
|
|
@ -63,20 +59,34 @@ public class QichachaConfig { |
|
|
|
@Value("${qichacha.URL}") |
|
|
|
private String URL; |
|
|
|
|
|
|
|
//设置连接超时时间,单位毫秒。
|
|
|
|
public final static int CONNECT_TIMEOUT = 30000; |
|
|
|
//设置从connect Manager获取Connection 超时时间,单位毫秒。这个属性是新加的属性,因为目前版本是可以共享连接池的。
|
|
|
|
public final static int CONNECT_REQUEST_TIMEOUT = 10000; |
|
|
|
//请求获取数据的超时时间,单位毫秒。 如果访问一个接口,多少时间内无法返回数据,就直接放弃此次调用。
|
|
|
|
public final static int SOCKET_TIMEOUT = 30000; |
|
|
|
|
|
|
|
//每周日凌晨1点执行
|
|
|
|
//每周日凌晨1点执行 每两秒执行0/2 * * * * ?
|
|
|
|
// @Scheduled(cron = "0 0 1 ? * 1")
|
|
|
|
public void enterpriseRiskInquiry(){ |
|
|
|
String currDay = DateUtil.format(new Date(), "yyyy-MM-dd"); |
|
|
|
List<EnterpriseInformation> list = enterpriseInformationService.enterpriseInformationList(); |
|
|
|
for (EnterpriseInformation enterpriseInformation : list) { |
|
|
|
String paramStr = "searchKey=" + enterpriseInformation.getEnterpriseName(); |
|
|
|
//创建对象设置参数
|
|
|
|
PagerQuery<ProjectInformationQuery> query = new PagerQuery<>(); |
|
|
|
query.setCurrent(1); |
|
|
|
query.setSize(15); |
|
|
|
query.setParams(new ProjectInformationQuery()); |
|
|
|
//调用项目管理 项目接口
|
|
|
|
ResultBean<PagerVo<ProjectInformationVo>> listPage = projectInformationFeign.listPage(query); |
|
|
|
List<ProjectInformationVo> records = listPage.getData().getRecords(); |
|
|
|
//使用set进行去重
|
|
|
|
// HashSet<String> set = new HashSet<>();
|
|
|
|
// for (ProjectInformationVo record : records) {
|
|
|
|
// set.add(record.getEnterpriseName());
|
|
|
|
// }
|
|
|
|
// Iterator<String> iterator = set.iterator();
|
|
|
|
// while (iterator.hasNext()){
|
|
|
|
// iterator.next();
|
|
|
|
// }
|
|
|
|
String name = ""; |
|
|
|
for (ProjectInformationVo datum : records) { |
|
|
|
if (name.equals(datum.getEnterpriseName())){ |
|
|
|
continue; |
|
|
|
} |
|
|
|
name = datum.getEnterpriseName(); |
|
|
|
String paramStr = "searchKey=" + datum.getEnterpriseName(); |
|
|
|
try { |
|
|
|
HttpHead reqHeader = new HttpHead(); |
|
|
|
String[] autherHeader = RandomAuthentHeader(); |
|
|
@ -86,7 +96,7 @@ public class QichachaConfig { |
|
|
|
String tokenJson = httpGet(reqUri, reqHeader.getAllHeaders()); |
|
|
|
System.out.println(String.format("==========================>this is response:{%s}", tokenJson)); |
|
|
|
BusinessRiskDateDto businessRiskDateDto = FormartJson(tokenJson); |
|
|
|
businessRiskDateDto.setBusinessName(enterpriseInformation.getEnterpriseName()); |
|
|
|
businessRiskDateDto.setBusinessName(datum.getEnterpriseName()); |
|
|
|
businessRiskDateDto.setExecutionTime(currDay); |
|
|
|
Map<String, Object> result = businessRiskDateDto.getResult(); |
|
|
|
if (result == null){ |
|
|
@ -102,67 +112,6 @@ public class QichachaConfig { |
|
|
|
} |
|
|
|
|
|
|
|
public static void main(String[] args) throws Exception { |
|
|
|
// List<String> arrayList = new ArrayList();
|
|
|
|
// arrayList.add("石家庄瀚川商贸有限公司");
|
|
|
|
// arrayList.add("石家庄富荣食品有限公司");
|
|
|
|
// arrayList.add("河北昌特汽车贸易有限公司");
|
|
|
|
// arrayList.add("河北旭东能源科技有限公司");
|
|
|
|
|
|
|
|
// Map<String, Object> map = new HashMap();
|
|
|
|
// map.put("searchKey","searchKey=石家庄瀚川商贸有限公司");
|
|
|
|
// String uriBuilder = URL;
|
|
|
|
// // 2.设置请求参数
|
|
|
|
// if (map != null) {
|
|
|
|
// // 遍历请求参数
|
|
|
|
// for (Map.Entry<String, Object> entry : map.entrySet()) {
|
|
|
|
// // 封装请求参数
|
|
|
|
// uriBuilder = uriBuilder.concat("?key=").concat(APPKEY).concat("&").concat(entry.getValue().toString());
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// System.out.println("输出"+uriBuilder);
|
|
|
|
// // 3.创建请求对象httpGet
|
|
|
|
// HttpGet httpGet = new HttpGet(uriBuilder);
|
|
|
|
// /*
|
|
|
|
// * 添加请求头信息
|
|
|
|
// */
|
|
|
|
// String[] autherHeader = RandomAuthentHeader();
|
|
|
|
// httpGet.setHeader("Token", autherHeader[0]);
|
|
|
|
// httpGet.setHeader("Timespan", autherHeader[1]);
|
|
|
|
//
|
|
|
|
// // 3. 使用Httpclient发起请求
|
|
|
|
// CloseableHttpClient httpclient = HttpClients.createDefault();
|
|
|
|
// RequestConfig requestConfig = RequestConfig.custom()
|
|
|
|
// .setConnectTimeout(CONNECT_TIMEOUT)//设置连接超时时间,单位毫秒。
|
|
|
|
// .setConnectionRequestTimeout(CONNECT_REQUEST_TIMEOUT)//设置从connect Manager获取Connection 超时时间,单位毫秒。这个属性是新加的属性,因为目前版本是可以共享连接池的。
|
|
|
|
// .setSocketTimeout(SOCKET_TIMEOUT)//请求获取数据的超时时间,单位毫秒。 如果访问一个接口,多少时间内无法返回数据,就直接放弃此次调用。
|
|
|
|
// .build();
|
|
|
|
// httpGet.setConfig(requestConfig);
|
|
|
|
// CloseableHttpResponse response = httpclient.execute(httpGet);
|
|
|
|
//
|
|
|
|
// // 4. 解析返回数据,封装HttpResult
|
|
|
|
// // 4.1状态码
|
|
|
|
// int code = response.getStatusLine().getStatusCode();
|
|
|
|
// // 4.2 响应体内容
|
|
|
|
// String body = null;
|
|
|
|
// if (response.getEntity() != null) {
|
|
|
|
// body = EntityUtils.toString(response.getEntity(), "UTF-8");
|
|
|
|
// }
|
|
|
|
// System.out.println("************-----------****************");
|
|
|
|
// System.out.println(body);
|
|
|
|
// String paramStr = "searchKey=石家庄瀚川商贸有限公司";
|
|
|
|
try { |
|
|
|
// HttpHead reqHeader = new HttpHead();
|
|
|
|
// String[] autherHeader = RandomAuthentHeader();
|
|
|
|
// reqHeader.setHeader("Token", autherHeader[0]);
|
|
|
|
// reqHeader.setHeader("Timespan", autherHeader[1]);
|
|
|
|
// final String reqUri = URL.concat("?key=").concat(APPkey).concat("&").concat(paramStr);
|
|
|
|
// String tokenJson = httpGet(reqUri, reqHeader.getAllHeaders());
|
|
|
|
// System.out.println(String.format("==========================>this is response:{%s}", tokenJson));
|
|
|
|
//
|
|
|
|
// BusinessRiskDateDto businessRiskDateDto = FormartJson(tokenJson);
|
|
|
|
}catch (Exception e){ |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 获取Auth Code
|
|
|
|