Commit 522be973 by 毛树良

<feat>:增加同步天壤的对接逻辑

1 parent d10278e9
...@@ -3,11 +3,13 @@ package com.viontech.tvp; ...@@ -3,11 +3,13 @@ package com.viontech.tvp;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import cn.hutool.json.xml.JSONXMLSerializer; import cn.hutool.json.xml.JSONXMLSerializer;
import com.viontech.tvp.task.TianRangTask;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.cxf.endpoint.Client; import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory; import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.Date; import java.util.Date;
import java.util.Optional; import java.util.Optional;
...@@ -26,11 +28,22 @@ import java.util.concurrent.TimeUnit; ...@@ -26,11 +28,22 @@ import java.util.concurrent.TimeUnit;
@Slf4j @Slf4j
public class ForwardService { public class ForwardService {
private static final ThreadPoolExecutor POOL = new ThreadPoolExecutor(20, 40, 1, TimeUnit.MINUTES, new LinkedBlockingQueue<>(1000), new ThreadPoolExecutor.CallerRunsPolicy()); private static final ThreadPoolExecutor POOL = new ThreadPoolExecutor(20, 40, 1, TimeUnit.MINUTES, new LinkedBlockingQueue<>(1000), new ThreadPoolExecutor.CallerRunsPolicy());
private static final ThreadPoolExecutor TIANRANG_POOL = new ThreadPoolExecutor(20, 30, 1, TimeUnit.MINUTES, new LinkedBlockingQueue<>(1000), new ThreadPoolExecutor.CallerRunsPolicy());
@Value("${vion.tvp.url}") @Value("${vion.tvp.url}")
private String tvpUrl; private String tvpUrl;
@Value("${vion.tianrang.switch:0}")
private String tianrangSwitch;
@Value("${vion.tianrang.url:}")
private String tianrangUrl;
public void forwardAsync(JSONObject fxData) { public void forwardAsync(JSONObject fxData) {
POOL.submit(new Task(fxData, tvpUrl)); POOL.submit(new Task(fxData, tvpUrl));
if ("1".equals(tianrangSwitch)) {
log.info("同步天壤平台:{},url:{}", tianrangSwitch, tianrangUrl);
if (!StringUtils.isEmpty(tianrangUrl)) {
TIANRANG_POOL.submit(new TianRangTask(fxData, tianrangUrl));
}
}
} }
private static class Task implements Runnable { private static class Task implements Runnable {
......
package com.viontech.tvp.task;
import cn.hutool.core.date.DateUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import lombok.extern.slf4j.Slf4j;
import java.util.Date;
/**
* 同步天壤平台Task
* @author msl
* @date 2022/10/17
*/
@Slf4j
public class TianRangTask implements Runnable {
private final JSONObject fxData;
private final String url;
public TianRangTask(JSONObject fxData, String url) {
this.fxData = fxData;
this.url = url;
}
@Override
public void run() {
//构造请求参数
String params = buildParam(fxData);
log.info("发送tianrang参数:{}", params);
//发送请求
String sendResult = HttpUtil.post(url, params, 20000);
log.info("发送tianrang结果:{}", sendResult);
}
public String buildParam(JSONObject fxData) {
long startTime = 0;
long endTime = 0;
String eventId = "";
String illegalCode = "";
String deviceCode = "";
String deviceName = "";
try {
JSONObject eventData = fxData.getJSONObject("event_data");
String startDt = eventData.getStr("start_dt").replaceAll("T", " ");
Date startParse = DateUtil.parse(startDt, "yyyy-MM-dd HH:mm:ss.SSS");
startTime = DateUtil.offsetHour(startParse, 8).getTime();
String endDt = eventData.getStr("end_dt").replaceAll("T", " ");
Date endParse = DateUtil.parse(endDt, "yyyy-MM-dd HH:mm:ss.SSS");
endTime = DateUtil.offsetHour(endParse, 8).getTime();
eventId = eventData.getStr("ID");
JSONObject illegal = eventData.getJSONObject("illegal");
illegalCode = illegal.getStr("code");
deviceCode = eventData.getJSONObject("device").getStr("code");
deviceName = eventData.getJSONObject("device").getStr("name");
} catch (Exception e) {
log.error("buildParam.Exception:{}", e.getMessage(), e);
}
JSONArray result = new JSONArray();
JSONObject obj = new JSONObject();
obj.set("targetType", "cross");
obj.set("targetId", deviceCode);
obj.set("targetName", deviceName);
obj.set("eventId", eventId);
obj.set("eventCode", illegalCode);
// obj.set("eventName", "压线");
obj.set("startTime", startTime);
obj.set("endTime", endTime);
result.add(obj);
return result.toString();
}
}
server.port=60005 server.port=60005
vion.tvp.url=http://192.168.2.36:8080/EHL_TVPDB_WEBSERVICE/services/TvpService?wsdl
\ No newline at end of file \ No newline at end of file
vion.tvp.url=http://192.168.2.36:8080/EHL_TVPDB_WEBSERVICE/services/TvpService?wsdl
# Խ
vion.tianrang.switch=1
vion.tianrang.url=http://13.104.24.227:8030/api/v1/event/offsiteLawEnforcement
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!