Commit 74c3ce96 authored by zhoumaotao's avatar zhoumaotao

oa接口调用最终版

parent d3d7558f
package com.gavel.kwell.config;
import org.apache.http.conn.HttpClientConnectionManager;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
@Configuration
public class RestTemplateConfig {
@Bean
public HttpClientConnectionManager poolingConnectionManager() {
PoolingHttpClientConnectionManager poolingConnectionManager = new PoolingHttpClientConnectionManager();
poolingConnectionManager.setMaxTotal(1000); // 连接池最大连接数
poolingConnectionManager.setDefaultMaxPerRoute(500); // 每个主机的并发
return poolingConnectionManager;
}
@Bean
public HttpClientBuilder httpClientBuilder() {
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
//设置HTTP连接管理器
httpClientBuilder.setConnectionManager(poolingConnectionManager());
return httpClientBuilder;
}
@Bean("restTemplate")
public RestTemplate restTemplate(){
HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory();
httpRequestFactory.setHttpClient(httpClientBuilder().build());
httpRequestFactory.setConnectionRequestTimeout(3000);//获取链接超时时间
httpRequestFactory.setConnectTimeout(3000);//指客户端和服务器建立连接的timeout
httpRequestFactory.setReadTimeout(120000);//读取数据的超时时间
RestTemplate restTemplate=new RestTemplate(httpRequestFactory);
return restTemplate;
}
}
......@@ -4,25 +4,26 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.gavel.common.base.service.impl.BaseEditServiceImpl;
import com.gavel.common.business.service.CommonService;
import com.gavel.common.utils.*;
import com.gavel.common.utils.CollectionUtils;
import com.gavel.common.utils.DateUtils;
import com.gavel.common.utils.NumberUtils;
import com.gavel.common.utils.StringUtils;
import com.gavel.kwell.dao.GpfkcxDao;
import com.gavel.kwell.dao.KmesBoardDao;
import com.gavel.kwell.persistent.Gpfkjg;
import com.gavel.kwell.service.KmesBoardService;
import com.gavel.kwell.utils.DateCalculateUtil;
import com.gavel.kwell.utils.KemsHttpUtil;
import com.gavel.kwell.utils.KwellParamEnum;
import com.gavel.kwell.vo.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.*;
......@@ -43,8 +44,6 @@ public class KmesBoardServiceImpl extends BaseEditServiceImpl implements KmesBoa
@Autowired
private CommonService commonService;
@Autowired
private RestTemplate restTemplate;
@Override
public void initService(){
......@@ -315,20 +314,9 @@ public class KmesBoardServiceImpl extends BaseEditServiceImpl implements KmesBoa
@Override
public KqtjVO queryOA() {
KqtjVO kqtjVO = new KqtjVO();
String time = DateUtils.formatDate(DateUtils.getDateTime(),"yyyyMMddHHmmss");
String url = "http://oa.kewell.com.cn/api/cube/restful/interface/getModeDataPageList/mes_kqtj";
StringBuilder param = new StringBuilder();
param.append("{\"datajson\":{\"operationinfo\":{\"operator\":\"1\"},\"mainTable\":{},\"pageInfo\":{\"pageNo\":\"1\",\"pageSize\":\"10\"},");
param.append("\"header\":{\"systemid\":\"oa\",");
param.append("\"currentDateTime\":").append("\""+time+"\"").append(",\"Md5\":").append("\""+MD5Utils.md5Hex("oa"+"123456"+time)+"\"").append("}}}");
try {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set(HttpHeaders.ACCEPT_CHARSET, StandardCharsets.UTF_8.toString());
HttpEntity httpEntity = new HttpEntity<>(param, headers);
ResponseEntity<String> exchange = restTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class);
String body = exchange.getBody();
String body = KemsHttpUtil.postWithParamsForString(url);
logger.info("返回信息:"+body);
JSONObject jsonObject = JSONObject.parseObject(body);
int ydrs =0;
......
package com.gavel.kwell.utils;
import com.gavel.common.utils.DateUtils;
import com.gavel.common.utils.MD5Utils;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import java.io.IOException;
public class KemsHttpUtil {
public static String postWithParamsForString(String url) throws IOException{
String jsonStr = "";
CloseableHttpClient httpClient = HttpClients.createDefault();
String requestBody = createRequestBody();
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
StringEntity entity = new StringEntity(requestBody);
httpPost.setEntity(entity);
CloseableHttpResponse response = httpClient.execute(httpPost);
jsonStr = EntityUtils.toString(response.getEntity());
return jsonStr;
}
private static String createRequestBody() {
String time = DateUtils.formatDate(DateUtils.getDateTime(),"yyyyMMddHHmmss");
StringBuilder param = new StringBuilder();
param.append("datajson={\"operationinfo\":{\"operator\":\"1\"},\"mainTable\":{},\"pageInfo\":{\"pageNo\":\"1\",\"pageSize\":\"10\"},");
param.append("\"header\":{\"systemid\":\"oa\",");
param.append("\"currentDateTime\":").append("\""+time+"\"").append(",\"Md5\":").append("\""+ MD5Utils.md5Hex("oa"+"123456"+time)+"\"").append("}}");
return param.toString();
}
}
......@@ -9,6 +9,10 @@ public class KqtjVO extends BaseEntity {
private Integer sdrs;//实到人数
private Integer xjrs;//休假人数
private Double zscl;
public Integer getYdrs() {
return ydrs;
}
......@@ -24,4 +28,20 @@ public class KqtjVO extends BaseEntity {
public void setSdrs(Integer sdrs) {
this.sdrs = sdrs;
}
public Integer getXjrs() {
return xjrs;
}
public void setXjrs(Integer xjrs) {
this.xjrs = xjrs;
}
public Double getZscl() {
return zscl;
}
public void setZscl(Double zscl) {
this.zscl = zscl;
}
}
......@@ -259,9 +259,9 @@
function apiqueryOA(){
HTTP.post("queryOA", {}, function(result) {
if (result['success']) {
let data=result.data.records||{}
$("#ydrs").text(data.ydrs||0)
$("#sdrs").text(data.ydrs||0)
let data=result.data.records||{};
$("#ydrs").text(data.ydrs||0);
$("#sdrs").text(data.sdrs||0)
} else {
console.log("请求失败")
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment