Commit 1d60ae39 authored by wangjinjing's avatar wangjinjing

推送近五分钟车流量

parent 0d99eb1d
...@@ -69,10 +69,10 @@ public class ScheduleTaskConfig { ...@@ -69,10 +69,10 @@ public class ScheduleTaskConfig {
for (Traffalarmrecord record : resultlist) { for (Traffalarmrecord record : resultlist) {
try { try {
ResultObj obj = eventWriteService.updateAndAutoSendEvent(record); ResultObj obj = eventWriteService.updateAndAutoSendEvent(record);
if (obj.getStatus() != 200) { if (obj.getStatus() == 200) {
log.error(record.getRecordid() + " send to guangda fail"); log.error(record.getRecordid() + " send to guangda success");
} else { } else {
log.info(record.getRecordid() + " send to guangda success"); log.info(record.getRecordid() + " send to guangda fail"+obj.getMsg());
} }
} catch (Exception ex) { } catch (Exception ex) {
log.error(record.getRecordid() + " send to guangda fail" + ex.toString()); log.error(record.getRecordid() + " send to guangda fail" + ex.toString());
......
...@@ -307,71 +307,71 @@ public class TraffController { ...@@ -307,71 +307,71 @@ public class TraffController {
} }
//车流量推送 // //车流量推送
@PostMapping("/traffflow") // @PostMapping("/traffflow")
public ResultObj traffflow(@RequestBody Vehicles vehicles) { // public ResultObj traffflow(@RequestBody Vehicles vehicles) {
//
if ("TRAFFIC_STATISTICS_VEHICLES".equalsIgnoreCase(vehicles.getType())) { // if ("TRAFFIC_STATISTICS_VEHICLES".equalsIgnoreCase(vehicles.getType())) {
log.info("Vehicles"); // log.info("Vehicles"+vehicles.toString());
String[] sbAndTd = vehicles.getVideo_id().split("_"); // String[] sbAndTd = vehicles.getVideo_id().split("_");
String sbbh = sbAndTd[0]; // String sbbh = sbAndTd[0];
int tdbh = Integer.valueOf(sbAndTd[1]) + 1; // int tdbh = Integer.valueOf(sbAndTd[1]) + 1;
//根据设备编号查询设备信息 // //根据设备编号查询设备信息
List<Sbtdspsr> sbtdspsrList=sbtdspsrMapper.selectBySbbh(sbbh,tdbh); // List<Sbtdspsr> sbtdspsrList=sbtdspsrMapper.selectBySbbh(sbbh,tdbh);
if(sbtdspsrList.size()>0) { // if(sbtdspsrList.size()>0) {
//重置videoid // //重置videoid
vehicles.setVideo_id(sbbh + "_" + tdbh); // vehicles.setVideo_id(sbbh + "_" + tdbh);
Date date = new Date(Long.valueOf(vehicles.getTs())); // Date date = new Date(Long.valueOf(vehicles.getTs()));
//直接放入表中 // //直接放入表中
List<Vehiclesdetail> vels = vehicles.getObjs(); // List<Vehiclesdetail> vels = vehicles.getObjs();
int result = 0; // int result = 0;
int upnum = 0, downnum = 0; // int upnum = 0, downnum = 0;
VideoDeviceTraffic traff = new VideoDeviceTraffic(); // VideoDeviceTraffic traff = new VideoDeviceTraffic();
for (Vehiclesdetail detail : vels) { // for (Vehiclesdetail detail : vels) {
Vehicle v = new Vehicle(); // Vehicle v = new Vehicle();
v.setId(UUID.randomUUID().toString()); // v.setId(UUID.randomUUID().toString());
v.setCreate_time(date); // v.setCreate_time(date);
v.setType(detail.getType()); // v.setType(detail.getType());
v.setDirection(detail.getDirection()); // v.setDirection(detail.getDirection());
v.setRuleTag(detail.getRuleTag()); // v.setRuleTag(detail.getRuleTag());
v.setClassification_confidence(detail.getClassification_confidence()); // v.setClassification_confidence(detail.getClassification_confidence());
v.setVideo_id(vehicles.getVideo_id()); // v.setVideo_id(vehicles.getVideo_id());
result = traffFlowService.saveTraffFlowDetail(v); // result = traffFlowService.saveTraffFlowDetail(v);
if(detail.getDirection().equals("1")) // if(detail.getRuleTag().equals("1"))
{ // {
upnum++; // upnum++;
} // }
else if(detail.getDirection().equals("1")) // else if(detail.getRuleTag().equals("2"))
{ // {
downnum++; // downnum++;
} // }
} // }
Sbtdspsr sbtdspsr = sbtdspsrList.get(0); // Sbtdspsr sbtdspsr = sbtdspsrList.get(0);
//发送给广达 // //发送给广达
traff.setDeviceId(sbtdspsr.getWbbh()); // traff.setDeviceId(sbtdspsr.getWbbh());
traff.setDateTime(date); // traff.setDateTime(date);
traff.setSsjg(sbtdspsrList.get(0).getXzbh()); // traff.setSsjg(sbtdspsrList.get(0).getXzbh());
traff.setDeviceName(sbtdspsr.getTdmc()); // traff.setDeviceName(sbtdspsr.getTdmc());
if(upnum>0) { // if(upnum>0) {
traff.setFx("1"); // traff.setFx("1");
traff.setFxmc("上行"); // traff.setFxmc("上行");
//发送给广达上行数据 // //发送给广达上行数据
log.info("上行traff"+traff.toString()); // log.info("上行traff"+traff.toString());
traffFlowService.sendMessage(traff); // traffFlowService.sendMessage(traff);
} // }
if(downnum>0) { // if(downnum>0) {
traff.setFx("2"); // traff.setFx("2");
traff.setFxmc("下行"); // traff.setFxmc("下行");
//发送给广达上行数 // //发送给广达上行数
log.info("下行"+traff.toString()); // log.info("下行"+traff.toString());
traffFlowService.sendMessage(traff); // traffFlowService.sendMessage(traff);
} // }
//根据连接的name ,群发根据videoid 查询的结果 // //根据连接的name ,群发根据videoid 查询的结果
webSocket.GroupSendingByVideoid(vehicles.getVideo_id()); // webSocket.GroupSendingByVideoid(vehicles.getVideo_id());
} // }
} // }
return ResultObj.ok(); // return ResultObj.ok();
} // }
//获取自动规则 //获取自动规则
...@@ -420,23 +420,53 @@ public class TraffController { ...@@ -420,23 +420,53 @@ public class TraffController {
String[] sbAndTd = vehicles.getVideo_id().split("_"); String[] sbAndTd = vehicles.getVideo_id().split("_");
String sbbh = sbAndTd[0]; String sbbh = sbAndTd[0];
int tdbh = Integer.valueOf(sbAndTd[1]) + 1; int tdbh = Integer.valueOf(sbAndTd[1]) + 1;
List<Sbtdspsr> sbtdspsrList=sbtdspsrMapper.selectBySbbh(sbbh,tdbh);
if (sbtdspsrList.isEmpty()) {
return ResultObj.error(ResponseEnum.E_1002.getCode(), "设备为:" + sbbh + ",通道为:" + tdbh + "未录入(备案)");
}
//重置videoid //重置videoid
vehicles.setVideo_id(sbbh + "_" + tdbh); vehicles.setVideo_id(sbbh + "_" + tdbh);
//直接放入表中 //直接放入表中
List<AutoVehiclesdetail> vels = vehicles.getObjs(); List<AutoVehiclesdetail> vels = vehicles.getObjs();
int result = 0; int upnum = 0, downnum = 0;
Date date=new Date(Long.valueOf(vehicles.getTs()));
List<VideoDeviceTraffic> trafflist = new ArrayList<>();
for (AutoVehiclesdetail detail : vels) { for (AutoVehiclesdetail detail : vels) {
Vehicle v = new Vehicle(); Vehicle v = new Vehicle();
v.setId(UUID.randomUUID().toString()); v.setId(UUID.randomUUID().toString());
v.setCreate_time(new Date(Long.valueOf(vehicles.getTs()))); v.setCreate_time(date);
v.setType(detail.getType()); v.setType(detail.getType());
v.setDirection(detail.getDirection()); v.setDirection(detail.getDirection());
v.setRuleTag(detail.getDirection().longValue()<=ldir.longValue()?"1":"2"); v.setRuleTag(detail.getDirection().longValue()<=ldir.longValue()?"1":"2");
v.setClassification_confidence(detail.getClassification_confidence()); v.setClassification_confidence(detail.getClassification_confidence());
v.setVideo_id(vehicles.getVideo_id()); v.setVideo_id(vehicles.getVideo_id());
result = traffFlowService.saveTraffFlowDetail(v); traffFlowService.saveTraffFlowDetail(v);
} }
Sbtdspsr sbtdspsr = sbtdspsrList.get(0);
Map map = traffFlowService.getfiveFlowByVideoid(vehicles.getVideo_id());
//发送给广达
VideoDeviceTraffic traff = new VideoDeviceTraffic();
traff.setDeviceId(sbtdspsr.getWbbh());
traff.setDateTime(date);
traff.setSsjg(sbtdspsrList.get(0).getXzbh());
traff.setDeviceName(sbtdspsr.getTdmc());
traff.setSjly("zksy");
traff.setFlowRate(map.get("upfiveflow")==null?"0":String.valueOf(map.get("upfiveflow")));
traff.setFxmc("上行");
traff.setFx("1");
trafflist.add(traff);
VideoDeviceTraffic traffwodn = new VideoDeviceTraffic();
traffwodn.setDeviceId(sbtdspsr.getWbbh());
traffwodn.setDateTime(date);
traffwodn.setSsjg(sbtdspsrList.get(0).getXzbh());
traffwodn.setDeviceName(sbtdspsr.getTdmc());
traffwodn.setSjly("zksy");
traffwodn.setFlowRate(map.get("downfiveflow")==null?"0":String.valueOf(map.get("downfiveflow")));
traffwodn.setFxmc("下行");
traffwodn.setFx("2");
trafflist.add(traffwodn);
traffFlowService.sendMessages(trafflist);
//查询近五分钟的车流量,当天车流量websocket 直接推送过去 //查询近五分钟的车流量,当天车流量websocket 直接推送过去
//根据连接的name ,群发根据videoid 查询的结果 //根据连接的name ,群发根据videoid 查询的结果
webSocket.GroupSendingByVideoid(vehicles.getVideo_id()); webSocket.GroupSendingByVideoid(vehicles.getVideo_id());
......
...@@ -14,5 +14,14 @@ public class Vehicles { ...@@ -14,5 +14,14 @@ public class Vehicles {
private String ts; private String ts;
List<Vehiclesdetail> objs; List<Vehiclesdetail> objs;
@Override
public String toString() {
return "Vehicles{" +
"id='" + id + '\'' +
", type='" + type + '\'' +
", video_id='" + video_id + '\'' +
", ts='" + ts + '\'' +
", objs=" + objs +
'}';
}
} }
...@@ -18,6 +18,7 @@ public interface TraffFlowMapper { ...@@ -18,6 +18,7 @@ public interface TraffFlowMapper {
List<Map> selectFiveAndDayFlow(String videoid); List<Map> selectFiveAndDayFlow(String videoid);
List<Map> selectFiveAndTypeDayFlow(String videoid); List<Map> selectFiveAndTypeDayFlow(String videoid);
Map getfiveFlowByVideoid(String videoid);
Integer statisVehiclesByDay(); Integer statisVehiclesByDay();
......
...@@ -108,15 +108,9 @@ public class EventWriteService { ...@@ -108,15 +108,9 @@ public class EventWriteService {
private List<ResultObj> sendAllMessage(List<Traffalarmrecord> traffalarmrecord) throws InterruptedException, ExecutionException, TimeoutException { private List<ResultObj> sendAllMessage(List<Traffalarmrecord> traffalarmrecord) throws InterruptedException, ExecutionException, TimeoutException {
List<ResultObj> objlist = new ArrayList<>(); List<ResultObj> objlist = new ArrayList<>();
for (Traffalarmrecord record : traffalarmrecord) { for (Traffalarmrecord record : traffalarmrecord) {
completionService.submit(() -> {
ResultObj obj = updateAndSendEvent(record); ResultObj obj = updateAndSendEvent(record);
obj.setData(record.getRecordid()); obj.setData(record.getRecordid());
return obj; objlist.add(obj);
});
}
for (int i = 0; i < traffalarmrecord.size(); i++) {
objlist.add(completionService.poll(10, TimeUnit.SECONDS).get());
} }
return objlist; return objlist;
} }
...@@ -131,7 +125,9 @@ public class EventWriteService { ...@@ -131,7 +125,9 @@ public class EventWriteService {
eventWriteParam.setOccurTime(DateUtils.formatDateToNoSign(traffalarmrecord.getRecordtime())); eventWriteParam.setOccurTime(DateUtils.formatDateToNoSign(traffalarmrecord.getRecordtime()));
//获得外部编号 //获得外部编号
List<Sbtdspsr> sbtdspsr = sbtdspsrMapper.selectBySbbh(traffalarmrecord.getFdid(),traffalarmrecord.getChannelid()); List<Sbtdspsr> sbtdspsr = sbtdspsrMapper.selectBySbbh(traffalarmrecord.getFdid(),traffalarmrecord.getChannelid());
if (sbtdspsr.isEmpty()) {
return ResultObj.error(ResponseEnum.E_1002.getCode(), "设备为:" + traffalarmrecord.getFdid() + ",通道为:" + traffalarmrecord.getChannelid() + "未录入(备案)");
}
eventWriteParam.setEventDeviceID(sbtdspsr.get(0).getWbbh()); eventWriteParam.setEventDeviceID(sbtdspsr.get(0).getWbbh());
eventWriteParam.setEventSupplier(EVENT_SUPPLIER); eventWriteParam.setEventSupplier(EVENT_SUPPLIER);
BASE64Encoder base64Encoder = new BASE64Encoder(); BASE64Encoder base64Encoder = new BASE64Encoder();
......
...@@ -72,6 +72,16 @@ public class TraffFlowService { ...@@ -72,6 +72,16 @@ public class TraffFlowService {
} }
public Map getfiveFlowByVideoid(String videoid) {
return traffFlowMapper.getfiveFlowByVideoid(videoid);
}
public List<VideoDeviceTraffic> getTraffVicleBystatus() { public List<VideoDeviceTraffic> getTraffVicleBystatus() {
return traffFlowMapper.getTraffVicleBystatus(); return traffFlowMapper.getTraffVicleBystatus();
} }
...@@ -85,9 +95,23 @@ public class TraffFlowService { ...@@ -85,9 +95,23 @@ public class TraffFlowService {
HttpEntity<VideoDeviceTraffic> requestEntity = new HttpEntity<>(videoDeviceTraffic, headers); HttpEntity<VideoDeviceTraffic> requestEntity = new HttpEntity<>(videoDeviceTraffic, headers);
try{ try{
ResultObj obj= CompletableFuture.supplyAsync(() -> restTemplate.postForObject(url, requestEntity, ResultObj.class)).get(timeout,TimeUnit.SECONDS); ResultObj obj= CompletableFuture.supplyAsync(() -> restTemplate.postForObject(url, requestEntity, ResultObj.class)).get(timeout,TimeUnit.SECONDS);
log.info("send device result "+obj.getMsg());
}catch (Exception ex){ }catch (Exception ex){
log.error(videoDeviceTraffic.getDeviceId()+videoDeviceTraffic.getDateTime()+":"+ex.toString()); log.error(videoDeviceTraffic.getDeviceId()+videoDeviceTraffic.getDateTime()+":"+ex.toString());
} }
} }
public void sendMessages(List<VideoDeviceTraffic> list){
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
//判断token
String token= qingZhiLoginCacheService.keepAlive();
headers.add("token", token);
HttpEntity<List<VideoDeviceTraffic>> requestEntity = new HttpEntity<>(list, headers);
try{
ResultObj obj= CompletableFuture.supplyAsync(() -> restTemplate.postForObject(url, requestEntity, ResultObj.class)).get(timeout,TimeUnit.SECONDS);
log.info("send devicelist result "+obj.getMsg());
}catch (Exception ex){
log.error("send to guangda list error:"+ex.toString());
}
}
} }
\ No newline at end of file
...@@ -71,6 +71,7 @@ public class FTPUtil { ...@@ -71,6 +71,7 @@ public class FTPUtil {
url = new URL(path); url = new URL(path);
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
log.error("FTP URL error"+e.toString()); log.error("FTP URL error"+e.toString());
return null;
} }
byte[] buffer = null; byte[] buffer = null;
try { try {
......
...@@ -15,13 +15,13 @@ mybatis.configuration.default-statement-timeout=3000 ...@@ -15,13 +15,13 @@ mybatis.configuration.default-statement-timeout=3000
#mybatis.mapperLocations = classpath:xxx.xml #mybatis.mapperLocations = classpath:xxx.xml
logging.level.com.hzjt=debug logging.level.com.hzjt=debug
spring.datasource.username=test #spring.datasource.username=test
spring.datasource.password=test #spring.datasource.password=test
spring.datasource.url=jdbc:oracle:thin:@192.168.168.212:1523:helowin #spring.datasource.url=jdbc:oracle:thin:@192.168.168.212:1523:helowin
#spring.datasource.username=hzjt spring.datasource.username=hzjt
#spring.datasource.password=hzjt spring.datasource.password=hzjt
#spring.datasource.url=jdbc:oracle:thin:@33.50.1.22:1521:orcl spring.datasource.url=jdbc:oracle:thin:@33.50.1.22:1521:orcl
spring.datasource.driverClassName=oracle.jdbc.OracleDriver spring.datasource.driverClassName=oracle.jdbc.OracleDriver
# druid # druid
......
...@@ -102,7 +102,7 @@ ...@@ -102,7 +102,7 @@
b.video_id b.video_id
</insert> </insert>
<delete id="deleteBeforeTwoMonthVehiclesDetails"> <delete id="deleteBeforeTwoMonthVehiclesDetails">
delete from vehicle WHERE create_time <![CDATA[ <= ]]>sysdate-33 delete from vehicle WHERE create_time <![CDATA[ <= ]]>sysdate-30
</delete> </delete>
<delete id="deleteVehiclesByDay"> <delete id="deleteVehiclesByDay">
...@@ -178,5 +178,24 @@ ...@@ -178,5 +178,24 @@
</select> </select>
<select id="getfiveFlowByVideoid" resultType="java.util.HashMap">
select NVL(sum(case
when ruletag = '2' then
1
else
0
end),
0) downfiveflow,
NVL(sum(case
when ruletag = '1' then
1
else
0
end),
0) upfiveflow
from vehicle
where CREATE_TIME >= SYSDATE - 5 / 1440 and video_id=#{videoid}
</select>
</mapper> </mapper>
\ No newline at end of file
package com.hzjt; package com.hzjt;
import com.hzjt.domain.Traffalarmrecord; import com.hzjt.domain.Traffalarmrecord;
import com.hzjt.domain.VideoDeviceTraffic;
import org.junit.Test; import org.junit.Test;
public class ExcelToDbApplicationTests { public class ExcelToDbApplicationTests {
...@@ -10,15 +11,6 @@ public class ExcelToDbApplicationTests { ...@@ -10,15 +11,6 @@ public class ExcelToDbApplicationTests {
@Test @Test
public void t(){ public void t(){
// Ftp ftp = ftpService.reloadFtp();
Traffalarmrecord record=new Traffalarmrecord();
record.setAreaid(Long.valueOf(1));
record.setRecordid(Long.valueOf(1));
record.setAlgotype(1);
record.setFdid("1");
} }
......
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