Commit 1d60ae39 authored by wangjinjing's avatar wangjinjing

推送近五分钟车流量

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