Commit 463d1df1 by libin

对接海南刑警大队,添加同步接处警信息功能。

parent 7a83f16c
......@@ -38,7 +38,10 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
......
package com.founder.config;
import com.founder.service.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import static org.springframework.core.Ordered.LOWEST_PRECEDENCE;
@Component
@Order(LOWEST_PRECEDENCE)
public class StartConfig implements CommandLineRunner {
@Autowired
private ResourceService resourceService;
@Override
public void run(String... args) throws Exception {
System.out.println("api项目启动完毕!");
resourceService.updateJjxx();
resourceService.updateCjxx();
}
}
......@@ -19,4 +19,8 @@ public interface XxcxDao {
List<TbZhzxJjxx> queryJjxx(TbZhzxJjxxView param);
List<TbZhzxCjxx> queryCjxx(TbZhzxCjxxView param);
int insertJjxx(TbZhzxJjxx param);
int insertCjxx(TbZhzxCjxx param);
}
package com.founder.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.founder.dao.XxcxDao;
import com.founder.model.TbZhzxCjxx;
import com.founder.model.TbZhzxJjxx;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.io.IOException;
import java.net.URI;
import java.util.*;
@Service
public class ResourceService {
public Logger logger = LoggerFactory.getLogger(this.getClass());
@Value("${hnxjzd.getResource.url}")
private String getResourceUrl;
@Value("${hnxjzd.queryResource.url}")
private String queryResourceUrl;
@Value("${hnxjzd.pauseResource.url}")
private String pauseResourceUrl;
@Value("${hnxjzd.resource.jjxx}")
private String jjxxId;
@Value("${hnxjzd.resource.cjxx}")
private String cjxxId;
@Value("${hnxjzd.apiKey}")
private String apiKey;
@Value("${hnxjzd.kafka.server}")
private String kafkaServer;
@Value("${hnxjzd.kafka.groupId}")
private String groupId;
@Autowired
private XxcxDao xxcxDao;
@Async
public void updateJjxx(){
Map<String,Object> topicInfo = getJjxxTopic();
queryResource(topicInfo,"JJXX");
}
@Async
public void updateCjxx(){
Map<String,Object> topicInfo = getCjxxTopic();
queryResource(topicInfo,"CJXX");
}
private Map<String,Object> getJjxxTopic(){
return queryResourceTopicName(jjxxId);
}
private Map<String,Object> getCjxxTopic(){
return queryResourceTopicName(cjxxId);
}
private Map<String,Object> queryResourceTopicName(String resource){
Map<String,Object> result = new HashMap<>();
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = null;
String resultString = "";
try {
//添加参数
URIBuilder builder = new URIBuilder(getResourceUrl);
builder.addParameter("requestid", apiKey);
builder.addParameter("sourceid", resource);
URI uri = builder.build();
//logger.info(uri.toString());
// 创建Http Post请求
HttpGet httpGet = new HttpGet(uri);
//添加请求头
httpGet.addHeader("apikey",apiKey);
logger.info(httpGet.getURI().toString());
// 执行http请求
response = httpClient.execute(httpGet);
resultString = EntityUtils.toString(response.getEntity(), "utf-8");
//resultString = "{ \"code\": 200,\"code_message\": \"\",\"message\": \"成功\",\"data\": {\"topic\": \"AZNB46000000000000015_4699980060\",\"time\": 1615191601,\"status\": \"1\",\"isSuccess\": true},\"error_data\": null}";
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if(response!=null){
response.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
if(!StringUtils.isEmpty(resultString)){
logger.info(resultString);
JSONObject jsonObject = JSON.parseObject(resultString);
String code = jsonObject.getString("code");
JSONObject data = jsonObject.getJSONObject("data");
if("200".equals(code)){
if(data!=null){
String topicName = data.getString("topic");
String status = data.getString("status");
result.put("topicName",topicName);
result.put("status",status);
}else{
logger.warn("["+resource+"]返回topic数据为空");
result.put("status",null);
}
}else{
logger.warn("请求资源返回状态码["+code+"],"+jsonObject.getString("code_message"));
result.put("status",null);
}
}else{
logger.warn("请求资源返回内容为空!");
result.put("status",null);
}
return result;
}
private void queryResource(Map<String,Object> resourceInfo,String type){
String status = (String)resourceInfo.get("status");
if(!StringUtils.isEmpty(status)){
String topicName = (String)resourceInfo.get("topicName");
Properties props = new Properties();
props.put("bootstrap.servers", kafkaServer); // 注意:kafka地址,根据现场配
props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
props.put("group.id", groupId); // 注意:不同的厂商,使用不同的消费者组
props.put("auto.offset.reset", "earliest");
props.put("session.timeout.ms", "6000");
props.put("heartbeat.interval.ms", "2000");
@SuppressWarnings("resource")
KafkaConsumer<String, String> consumer = new KafkaConsumer<String, String>(props);
//kafka队列名 topicName
consumer.subscribe(Collections.singleton(topicName));
// 循环消费 任务进度 并更新前台界面
while (true) {
ConsumerRecords<String, String> records = consumer.poll(10000);//消费间隔单位:毫秒
for (ConsumerRecord<String, String> consumerRecord : records) {
logger.info(consumerRecord.key()+":"+consumerRecord.value()); // 消息key:taskid的值// 消息value:消息的json字符串
try {
if("JJXX".equals(type)){
TbZhzxJjxx entity = parseJjxx(consumerRecord.value());
xxcxDao.insertJjxx(entity);
}else if("CJXX".equals(type)){
TbZhzxCjxx entity = parseCjxx(consumerRecord.value());
xxcxDao.insertCjxx(entity);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
private TbZhzxJjxx parseJjxx(String value){
JSONObject jsonObject = JSON.parseObject(value);
TbZhzxJjxx tbZhzxJjxx = null;
if(jsonObject!=null){
Iterator<String> iterator = jsonObject.keySet().iterator();
JSONObject destJSON = new JSONObject();
while(iterator.hasNext()){
String key = iterator.next();
Object keyValue = jsonObject.get(key);
String humpKey = UnderlineToHump(key);
destJSON.put(humpKey,keyValue);
}
tbZhzxJjxx = destJSON.toJavaObject(TbZhzxJjxx.class);
}
return tbZhzxJjxx;
}
private TbZhzxCjxx parseCjxx(String value){
JSONObject jsonObject = JSON.parseObject(value);
TbZhzxCjxx tbZhzxCjxx = null;
if(jsonObject!=null){
Iterator<String> iterator = jsonObject.keySet().iterator();
JSONObject destJSON = new JSONObject();
while(iterator.hasNext()){
String key = iterator.next();
Object keyValue = jsonObject.get(key);
String humpKey = UnderlineToHump(key);
destJSON.put(humpKey,keyValue);
}
tbZhzxCjxx = destJSON.toJavaObject(TbZhzxCjxx.class);
}
return tbZhzxCjxx;
}
private String UnderlineToHump(String para){
StringBuilder result=new StringBuilder();
String a[]=para.split("_");
for(String s:a){
if (!para.contains("_")) {
result.append(s);
continue;
}
if(result.length()==0){
result.append(s.toLowerCase());
}else{
result.append(s.substring(0, 1).toUpperCase());
result.append(s.substring(1).toLowerCase());
}
}
return result.toString();
}
}
......@@ -33,3 +33,23 @@ xxcx:
orc: http://39.99.224.27:8866/predict/chinese_ocr_db_crnn_mobile
ce: http://39.99.224.27:8866/predict/chinese_ocr_db_crnn_mobile
ce1: http://39.99.224.27:8866/predict/ocr_system
#海南接处警资源服务
hnxjzd:
getResource: #标准资源订阅服务-申请订阅
url: http://74.6.57.208:30030/S-460000000000-ZNB-22-00405
id: S-460000000000-ZNB-22-00405
queryResource: #标准资源订阅服务-订阅状态查询服务
url: http://74.6.57.208:30030/S-460000000000-ZNB-22-00406
id: S-460000000000-ZNB-22-00406
pauseResource: #标准资源订阅服务-暂停订阅
url: http://74.6.57.208:30030/S-460000000000-ZNB-22-00307
id: S-460000000000-ZNB-22-00407
resource:
#接警信息资源编号
jjxx: 4699980060
#处警信息资源编号
cjxx: 4699980647
apiKey: AZNB46000000000000015
kafka:
server: 74.6.57.11:9092
groupId: hnxjzd001
\ No newline at end of file
......@@ -240,4 +240,272 @@
<if test="pjsj != null and pjsj != ''"> AND PJSJ = #{pjsj , jdbcType=VARCHAR } </if>
<if test="asjbh != null and asjbh != ''"> AND ASJBH = #{asjbh , jdbcType=VARCHAR } </if>
</select>
<insert id="insertCjxx" parameterType="com.founder.model.TbZhzxCjxx">
INSERT INTO TB_M_ZHZX_CJXX (
FORM_XFSJ
,FORM_GXSJC
,FORM_JJDXSJ
,FORM_SBSJ
,FORM_DDSJ
,FORM_FJJSSJ
,FORM_FJPJSJ
,FORM_PCSDDSJ
,FORM_PCSJSSJ
,FORM_RKSJ
,FORM_CJSJ
,FORM_GXSJ
,FORM_ODS_RKSJ
,FORM_JRSJ
,ASJBH
,PJDBH
,JJDBH
,PJSJ
,XFSJ
,PJYXM
,SJDWDM
,PJLYH
,SJRXM
,PJYJ
,PJDZT
,GXSJC
,SFZXXS
,SFYFDX
,JJDXNR
,JJDXSJ
,SBSJ
,SBNR
,DDSJ
,FJJSSJ
,FJPJSJ
,FJJJR
,PCSDDSJ
,PCSJSSJ
,CDCLBM
,ZBQK
,XZQH
,RKSJ
,CJDWDM
,CJDWMC
,CJRXM
,CJSJ
,GXDWDM
,GXDWMC
,GXRXM
,GXSJ
,ODS_RKSJ
,JRSJ
,DIC_XZQH
,FORM_PJSJ
)
VALUES(
#{ formXfsj , jdbcType=VARCHAR }
,#{ formGxsjc , jdbcType=VARCHAR }
,#{ formJjdxsj , jdbcType=VARCHAR }
,#{ formSbsj , jdbcType=VARCHAR }
,#{ formDdsj , jdbcType=VARCHAR }
,#{ formFjjssj , jdbcType=VARCHAR }
,#{ formFjpjsj , jdbcType=VARCHAR }
,#{ formPcsddsj , jdbcType=VARCHAR }
,#{ formPcsjssj , jdbcType=VARCHAR }
,#{ formRksj , jdbcType=VARCHAR }
,#{ formCjsj , jdbcType=VARCHAR }
,#{ formGxsj , jdbcType=VARCHAR }
,#{ formOdsRksj , jdbcType=VARCHAR }
,#{ formJrsj , jdbcType=VARCHAR }
,#{ asjbh , jdbcType=VARCHAR }
,#{ pjdbh , jdbcType=VARCHAR }
,#{ jjdbh , jdbcType=VARCHAR }
,#{ pjsj , jdbcType=VARCHAR }
,#{ xfsj , jdbcType=VARCHAR }
,#{ pjyxm , jdbcType=VARCHAR }
,#{ sjdwdm , jdbcType=VARCHAR }
,#{ pjlyh , jdbcType=VARCHAR }
,#{ sjrxm , jdbcType=VARCHAR }
,#{ pjyj , jdbcType=VARCHAR }
,#{ pjdzt , jdbcType=VARCHAR }
,#{ gxsjc , jdbcType=VARCHAR }
,#{ sfzxxs , jdbcType=VARCHAR }
,#{ sfyfdx , jdbcType=VARCHAR }
,#{ jjdxnr , jdbcType=VARCHAR }
,#{ jjdxsj , jdbcType=VARCHAR }
,#{ sbsj , jdbcType=VARCHAR }
,#{ sbnr , jdbcType=VARCHAR }
,#{ ddsj , jdbcType=VARCHAR }
,#{ fjjssj , jdbcType=VARCHAR }
,#{ fjpjsj , jdbcType=VARCHAR }
,#{ fjjjr , jdbcType=VARCHAR }
,#{ pcsddsj , jdbcType=VARCHAR }
,#{ pcsjssj , jdbcType=VARCHAR }
,#{ cdclbm , jdbcType=VARCHAR }
,#{ zbqk , jdbcType=VARCHAR }
,#{ xzqh , jdbcType=VARCHAR }
,#{ rksj , jdbcType=VARCHAR }
,#{ cjdwdm , jdbcType=VARCHAR }
,#{ cjdwmc , jdbcType=VARCHAR }
,#{ cjrxm , jdbcType=VARCHAR }
,#{ cjsj , jdbcType=VARCHAR }
,#{ gxdwdm , jdbcType=VARCHAR }
,#{ gxdwmc , jdbcType=VARCHAR }
,#{ gxrxm , jdbcType=VARCHAR }
,#{ gxsj , jdbcType=VARCHAR }
,#{ odsRksj , jdbcType=VARCHAR }
,#{ jrsj , jdbcType=VARCHAR }
,#{ dicXzqh , jdbcType=VARCHAR }
,#{ formPjsj , jdbcType=VARCHAR }
)
</insert>
<insert id="insertJjxx" parameterType="com.founder.model.TbZhzxJjxx">
INSERT INTO TB_M_ZHZX_JJXX (
ASJBH
,JJDW
,JJDBH
,GLJJDBH
,BJFSDM
,JJYXM
,BJSJ
,JJCZSJ
,BJDH
,YHXM
,YHDZ
,JJLYH
,THSC
,BJRXM
,BJRXB
,LHLBDM
,LXDH
,SFDD
,BJNR
,GXDWDM
,BJLBDM
,BJLXDM
,BJXLDM
,BJCPH
,SYQX
,CLQX
,JJDSCBZ
,ZJLY
,LDGBH
,CLLX
,RKSJC
,FKYQ
,HZDJ
,JZLB
,JZJG
,QHCS
,BZWQK
,BLQK
,SFBW
,RSWXZ
,YFWXWZ
,YWBZXL
,YFTY
,YWBKRY
,GIS_X
,GIS_Y
,SFZXXS
,BCJJNR
,YJDW
,YJR
,YJSM
,XZQH
,RKSJ
,CJDWDM
,CJDWMC
,CJRXM
,CJSJ
,GXDWMC
,GXRXM
,GXSJ
,ODS_RKSJ
,JRSJ
,DIC_JJDW
,DIC_BJFSDM
,DIC_LHLBDM
,DIC_XZQH
,FORM_BJSJ
,FORM_JJCZSJ
,FORM_RKSJC
,FORM_RKSJ
,FORM_CJSJ
,FORM_ODS_RKSJ
,FORM_JRSJ
)
VALUES(
#{ asjbh , jdbcType=VARCHAR }
,#{ jjdw , jdbcType=VARCHAR }
,#{ jjdbh , jdbcType=VARCHAR }
,#{ gljjdbh , jdbcType=VARCHAR }
,#{ bjfsdm , jdbcType=VARCHAR }
,#{ jjyxm , jdbcType=VARCHAR }
,#{ bjsj , jdbcType=VARCHAR }
,#{ jjczsj , jdbcType=VARCHAR }
,#{ bjdh , jdbcType=VARCHAR }
,#{ yhxm , jdbcType=VARCHAR }
,#{ yhdz , jdbcType=VARCHAR }
,#{ jjlyh , jdbcType=VARCHAR }
,#{ thsc , jdbcType=VARCHAR }
,#{ bjrxm , jdbcType=VARCHAR }
,#{ bjrxb , jdbcType=VARCHAR }
,#{ lhlbdm , jdbcType=VARCHAR }
,#{ lxdh , jdbcType=VARCHAR }
,#{ sfdd , jdbcType=VARCHAR }
,#{ bjnr , jdbcType=VARCHAR }
,#{ gxdwdm , jdbcType=VARCHAR }
,#{ bjlbdm , jdbcType=VARCHAR }
,#{ bjlxdm , jdbcType=VARCHAR }
,#{ bjxldm , jdbcType=VARCHAR }
,#{ bjcph , jdbcType=VARCHAR }
,#{ syqx , jdbcType=VARCHAR }
,#{ clqx , jdbcType=VARCHAR }
,#{ jjdscbz , jdbcType=VARCHAR }
,#{ zjly , jdbcType=VARCHAR }
,#{ ldgbh , jdbcType=VARCHAR }
,#{ cllx , jdbcType=VARCHAR }
,#{ rksjc , jdbcType=VARCHAR }
,#{ fkyq , jdbcType=VARCHAR }
,#{ hzdj , jdbcType=VARCHAR }
,#{ jzlb , jdbcType=VARCHAR }
,#{ jzjg , jdbcType=VARCHAR }
,#{ qhcs , jdbcType=VARCHAR }
,#{ bzwqk , jdbcType=VARCHAR }
,#{ blqk , jdbcType=VARCHAR }
,#{ sfbw , jdbcType=VARCHAR }
,#{ rswxz , jdbcType=VARCHAR }
,#{ yfwxwz , jdbcType=VARCHAR }
,#{ ywbzxl , jdbcType=VARCHAR }
,#{ yfty , jdbcType=VARCHAR }
,#{ ywbkry , jdbcType=VARCHAR }
,#{ gisX , jdbcType=VARCHAR }
,#{ gisY , jdbcType=VARCHAR }
,#{ sfzxxs , jdbcType=VARCHAR }
,#{ bcjjnr , jdbcType=VARCHAR }
,#{ yjdw , jdbcType=VARCHAR }
,#{ yjr , jdbcType=VARCHAR }
,#{ yjsm , jdbcType=VARCHAR }
,#{ xzqh , jdbcType=VARCHAR }
,#{ rksj , jdbcType=VARCHAR }
,#{ cjdwdm , jdbcType=VARCHAR }
,#{ cjdwmc , jdbcType=VARCHAR }
,#{ cjrxm , jdbcType=VARCHAR }
,#{ cjsj , jdbcType=VARCHAR }
,#{ gxdwmc , jdbcType=VARCHAR }
,#{ gxrxm , jdbcType=VARCHAR }
,#{ gxsj , jdbcType=VARCHAR }
,#{ odsRksj , jdbcType=VARCHAR }
,#{ jrsj , jdbcType=VARCHAR }
,#{ dicJjdw , jdbcType=VARCHAR }
,#{ dicBjfsdm , jdbcType=VARCHAR }
,#{ dicLhlbdm , jdbcType=VARCHAR }
,#{ dicXzqh , jdbcType=VARCHAR }
,#{ formBjsj , jdbcType=VARCHAR }
,#{ formJjczsj , jdbcType=VARCHAR }
,#{ formRksjc , jdbcType=VARCHAR }
,#{ formRksj , jdbcType=VARCHAR }
,#{ formCjsj , jdbcType=VARCHAR }
,#{ formOdsRksj , jdbcType=VARCHAR }
,#{ formJrsj , jdbcType=VARCHAR }
)
</insert>
</mapper>
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