Commit 6ce69f25 by liuyaxin

接入管理IRS接口

parent 34467a0c
......@@ -54,5 +54,20 @@
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>2.0.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -10,6 +10,7 @@ import com.founder.commonutils.util.HaiKangUtils;
import com.founder.commonutils.util.HttpClient;
import com.founder.publicapi.mapper.qgxzMapper.TbStAsjqgMapper;
import com.founder.publicapi.service.CqImportListener;
import com.founder.publicapi.service.CqService;
import com.founder.servicebase.logs.OperLog;
import com.founder.servicebase.logs.OperationType;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
......@@ -1519,4 +1520,95 @@ public class CqController {
result = httpClientCq.doGet("http://77.1.249.56:880/addrdata/proxy/013d407166ec4fa56eb1e1f8cbe183b9/e2ef524fbf3d9fe611d5a8e90fefdc9c/addrdata/associate/api/geo",headMap ,params);
return JSONObject.parseObject(result);
}
/**
* 重庆市毕业大中专学生信息_ES R-500000000000-00000663
* 重庆市情报中职学校在校生信息_ES R-500000000000-00001272
* 重庆市大中小学幼儿园学生及父母信息_ES R-500000000000-00000180
* 重庆市情报信息中心学校教职员工信息_ES R-500000000000-00001208
* 重庆市情报在校大学生信息_ES R-500000000000-00001077
* 重庆市情报在校研究生信息_ES R-500000000000-00000470
*
* */
@Autowired
private CqService cqService;
@OperLog(message = "重庆市毕业大中专学生信息_ES", operation = OperationType.QUERY)
@PostMapping("/cqsbydzzxsxxRequest")
@ApiOperation(value = "重庆市毕业大中专学生信息_ES", notes = "重庆市毕业大中专学生信息_ES")
public JSONObject cqsbydzzxsxx(@RequestBody JSONObject parasm) {
JSONObject resultCar = null;
try {
resultCar = cqService.doPostJsonByIRSInterface( parasm.toJSONString());
} catch (Exception e) {
e.printStackTrace();
}
return resultCar;
}
@OperLog(message = "重庆市情报中职学校在校生信息_ES", operation = OperationType.QUERY)
@PostMapping("/cqsqbzzxxzxsxxRequest")
@ApiOperation(value = "重庆市情报中职学校在校生信息_ES", notes = "重庆市情报中职学校在校生信息_ES")
public JSONObject cqsqbzzxxzxsxx(@RequestBody JSONObject parasm) {
JSONObject resultCar = null;
try {
resultCar = cqService.doPostJsonByIRSInterface( parasm.toJSONString());
} catch (Exception e) {
e.printStackTrace();
}
return resultCar;
}
@OperLog(message = "重庆市大中小学幼儿园学生及父母信息_ES", operation = OperationType.QUERY)
@PostMapping("/cqsdzxyeyxsjfmxxRequest")
@ApiOperation(value = "重庆市大中小学幼儿园学生及父母信息_ES", notes = "重庆市大中小学幼儿园学生及父母信息_ES")
public JSONObject cqsdzxyeyxsjfmxx(@RequestBody JSONObject parasm) {
JSONObject resultCar = null;
try {
resultCar = cqService.doPostJsonByIRSInterface( parasm.toJSONString());
} catch (Exception e) {
e.printStackTrace();
}
return resultCar;
}
@OperLog(message = "重庆市情报信息中心学校教职员工信息_ES", operation = OperationType.QUERY)
@PostMapping("/cqsqbxxzxxxjzygxxRequest")
@ApiOperation(value = "重庆市情报信息中心学校教职员工信息_ES", notes = "重庆市情报信息中心学校教职员工信息_ES")
public JSONObject cqsqbxxzxxxjzygxx(@RequestBody JSONObject parasm) {
JSONObject resultCar = null;
try {
resultCar = cqService.doPostJsonByIRSInterface( parasm.toJSONString());
} catch (Exception e) {
e.printStackTrace();
}
return resultCar;
}
@OperLog(message = "重庆市情报在校大学生信息_ES", operation = OperationType.QUERY)
@PostMapping("/cqsxxzxdxsxxRequest")
@ApiOperation(value = "重庆市情报在校大学生信息_ES", notes = "重庆市情报在校大学生信息_ES")
public JSONObject cqsxxzxdxsxx(@RequestBody JSONObject parasm) {
JSONObject resultCar = null;
try {
resultCar = cqService.doPostJsonByIRSInterface(parasm.toJSONString());
} catch (Exception e) {
e.printStackTrace();
}
return resultCar;
}
@OperLog(message = "重庆市情报在校研究生信息_ES", operation = OperationType.QUERY)
@PostMapping("/cqsqbzxyjsxxRequest")
@ApiOperation(value = "重庆市情报在校研究生信息_ES", notes = "重庆市情报在校研究生信息_ES")
public JSONObject cqsqbzxyjsxx(@RequestBody JSONObject parasm) {
JSONObject resultCar = null;
try {
resultCar = cqService.doPostJsonByIRSInterface(parasm.toJSONString());
} catch (Exception e) {
e.printStackTrace();
}
return resultCar;
}
}
package com.founder.publicapi.service;
import com.alibaba.fastjson.JSONObject;
public interface CqService {
JSONObject doPostJsonByIRSInterface(String jsonStr);
}
package com.founder.publicapi.service.serviceimpl;
import com.alibaba.fastjson.JSONObject;
import com.founder.commonutils.util.HttpClient;
import com.founder.publicapi.service.CqService;
import org.apache.http.HttpStatus;
import org.apache.http.StatusLine;
import org.apache.http.client.config.RequestConfig;
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.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import javax.xml.bind.DatatypeConverter;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
@Service
public class CqServiceImpl implements CqService {
private static RequestConfig requestConfig = null;
static{
// 设置请求和传输超时时间
//setConnectTimeout:设置连接超时时间,单位毫秒。
//setSocketTimeout:请求获取数据的超时时间,单位毫秒。 如果访问一个接口,多少时间内无法返回数据,就直接放弃此次调用。
//setConnectionRequestTimeout:设置从connect Manager获取Connection 超时时间,单位毫秒
requestConfig = RequestConfig.custom().setSocketTimeout(120000).setConnectTimeout(120000).build();
}
/**
* IRS接口对接
* */
@Override
public JSONObject doPostJsonByIRSInterface(String jsonStr) {
String url="http://10.154.255.235:7511/unisearch/local/request";
// post请求返回结果
CloseableHttpClient httpClient = HttpClients.createDefault();
JSONObject jsonResult = null;
HttpPost httpPost = new HttpPost(url);
// 设置请求和传输超时时间
httpPost.setConfig(requestConfig);
httpPost.setHeader("Content-Type", "application/json");
httpPost.setHeader("appCode", "app-17b28bu004");
httpPost.setHeader("token", "Bearer "+getIRSToken());
try{
//设置参数解决中文乱码
if (null != jsonStr){
StringEntity entity = new StringEntity(jsonStr,"utf-8");
entity.setContentEncoding("UTF-8");
entity.setContentType("application/json");
httpPost.setEntity(entity);
}
//发送请求
CloseableHttpResponse result = httpClient.execute(httpPost);
System.out.println("StatusCode===="+result.getStatusLine().getStatusCode());
if (result.getStatusLine().getStatusCode() == HttpStatus.SC_OK){
// 读取服务器返回的json数据(然后解析)
jsonResult = JSONObject.parseObject(EntityUtils.toString(result.getEntity(), "utf-8"));
}else{
throw new Exception();
}
}catch (Exception e){
e.printStackTrace();
}finally{
httpPost.releaseConnection();
}
return jsonResult;
}
@Autowired
RedisTemplate redisTemplate;
public String getIRSToken() {
String redisKey="CQSERVICE:IRS:TOKEN";
if(redisTemplate.hasKey(redisKey)){
return (String) redisTemplate.opsForValue().get(redisKey);
}
String url="http://77.1.249.1/sso/oauth2/token?grant_type=client_credentials";
String username="9b58bf7e";
String password="c1ca97043465fb51ab2906ef01f2d8b3";
CloseableHttpClient httpClient = HttpClientBuilder.create().build(); //获取浏览器信息
HttpPost httpPost = new HttpPost(url);
String token = null;
try {
//username password 自行修改 中间":"不可少
String encoding = DatatypeConverter.printBase64Binary((username+":"+password).getBytes("UTF-8"));
httpPost.setHeader("Authorization", "Basic " + encoding);
CloseableHttpResponse response = httpClient.execute(httpPost);
StatusLine statusLine = response.getStatusLine(); //获取请求对象中的响应行对象
int responseCode = statusLine.getStatusCode();
if ((responseCode >= 200 && responseCode < 300) || responseCode == 409) {
//获取响应信息
try {
JSONObject jsonResult = JSONObject.parseObject(EntityUtils.toString(response.getEntity(), "utf-8"));
token=jsonResult.getString("access_token");
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (IOException e) {
e.printStackTrace();
}
redisTemplate.opsForValue().set(redisKey,token,60L, TimeUnit.MINUTES);
return token;
}
}
......@@ -23,9 +23,11 @@ spring.datasource.qgdb.password=XzxtPwd#50
spring.datasource.qgdb.type=com.alibaba.druid.pool.DruidDataSource
#redis
spring.redis.host=47.92.225.109
spring.redis.port=3001
spring.redis.password=CcXzxt
spring.redis.database=1
spring.redis.timeout=6000ms
spring.redis.host=77.1.24.81
spring.redis.port=6379
spring.redis.password=cqxzxt@50
#\u6570\u636E\u5206\u6790\u4E0A\u4F20\u7684\u8DEF\u5F84
hnkshFilePath=/data/excel/kshExcel/
......
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