Commit 12254c87 authored by yzm's avatar yzm

修复ftpbug

parent 42a7d921
......@@ -93,10 +93,6 @@
<version>1.9</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
......@@ -120,15 +116,9 @@
<artifactId>spring-boot-starter-quartz</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.6</version>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
<!-- redis -->
......@@ -142,12 +132,6 @@
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
<!-- HttpClient依赖 -->
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
......
package com.cx.cn.cxquartz.config;
import com.cx.cn.cxquartz.service.quartz.SbtdspsrService;
import com.cx.cn.cxquartz.util.RestUtil;
import com.cx.cn.cxquartz.vo.Sbtdspsr;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import java.util.Calendar;
import java.util.List;
@Configuration
@EnableScheduling
public class ScheduleTaskConfig {
@Autowired
private SbtdspsrService sbtdspsrService;
@Value("${file.getrtspbyurl}")
private String getrtspbyurl;
RestUtil restUtil=new RestUtil();
/***
* 每隔20分钟执行一遍判断rtsp 是否变换
*/
@Scheduled(cron = "0 0 2 * * ? ")
private void statis() {
//查询所有监控设备,更新rtsp 地址
List<Sbtdspsr> sbtdpsrList= sbtdspsrService.list();
//调用decice 端口获得新的rtsp 地址,如果与表里的一样无需更新,不一样则立即更新
for(Sbtdspsr sbtd:sbtdpsrList)
{
restUtil.rtspChangeVlue(sbtd.getSbbh(),sbtd.getSqurllj(),getrtspbyurl);
}
}
......
......@@ -20,20 +20,14 @@ import org.springframework.context.annotation.PropertySource;
import org.springframework.http.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import sun.net.www.protocol.ftp.FtpURLConnection;
import javax.imageio.ImageIO;
import javax.jws.Oneway;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.List;
......@@ -41,82 +35,53 @@ import java.util.concurrent.*;
@RestController
@RequestMapping("/ext")
@PropertySource("classpath:file.properties")
public class ExtController {
private static final Logger logger = LoggerFactory.getLogger(ExtController.class);
@Autowired
private QuartzService quartzService;
@Value("${file.uploadpath}")
private String uploadpath;
@Value("${file.alarmpath}")
private String alarmpath;
@Value("${file.alarmurl}")
private String alarmurl;
@Value("${file.recordurl}")
private String recordurl;
@Value("${file.rtspurl}")
private String rtspurl;
@Value("${file.recogurl}")
private String recogurl;
@Value("${file.getrtspbyurl}")
private String getrtspbyurl;
@Value("${file.publicpictureurl}")
private String publicpictureurl;
@Autowired
private RestTemplate restTemplate;
@Autowired
private SbtdspsrService sbtdspsrService;
@Autowired
FtpService ftpService;
@Autowired
private QuartzTaskInformationsService quartzTaskInformationsService;
@Autowired
TraffAlarmRecordService traffAlarmRecordService;
@Autowired
TraffPictureService traffPictureService;
@Autowired
PedestrianService pedestrianService;
@Autowired
TrafficService trafficService;
@Autowired
FaceService faceService;
@Value("${file.ftppath}")
private String ftppath;
@Autowired
PeopleridebicycService peopleridebicycService;
@Autowired
WebSocket webSocket;
@Autowired
CodeService codeservice;
@Autowired
EventWriteService eventWriteService;
private static CompletionService<PictureResult> threadService = new ExecutorCompletionService<PictureResult>(ThreadPoolUtil.getPool());
RestUtil restutil=new RestUtil();
@RequestMapping(value = "/patrolCtrlRecord", method = RequestMethod.POST)
public String upload(HttpServletRequest request) {
try {
......@@ -128,7 +93,6 @@ public class ExtController {
String[] fileParam = null;//文件名称数组
String filename = "", fileatream = "", picturetime;//文件名拼接成的日期,图片生成时间
SimpleDateFormat simpledate = new SimpleDateFormat("yyyyMMddHHmmss"), newsimpledate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//日期转换成特定格式
List<File> newfilelist = new ArrayList<>();
RecursiveGetJsonData fileutil = new RecursiveGetJsonData();
fileutil.getDataFromFile(uploadpath, "jpeg");
List<File> jsonFile = fileutil.getJsonFileList(); //获得文件夹下所有文件信息
......@@ -147,58 +111,56 @@ public class ExtController {
headers.add("access-token", session.getAttribute("token").toString());
ExecutorService fixedThreadPool = Executors.newFixedThreadPool(5);
for (File file : jsonFile) {
fixedThreadPool.execute(new Runnable() {
public void run() {
String[] fileParam = file.getAbsolutePath().split("\\\\");
String filename = fileParam[fileParam.length - 2] + fileParam[fileParam.length - 1].replace(".jpeg", "");
if (null != fileParam && fileParam.length > 4) {
String fileatream = fileutil.ImageToBase64ByLocal(file);
for (PatrolCtrlRecord record : recordList) {
if (record.getDeviceid().equals(fileParam[fileParam.length - 3])) {
try {
String picturetime = newsimpledate.format(simpledate.parse(filename));
record.setPatrolTime(picturetime);
record.setRecordSrc("2");
record.setFile(fileatream);
//调用推送接口
HttpEntity<String> requestEntity = new HttpEntity<String>(JSONObject.toJSONString(record), headers);
ResponseEntity<String> response = restTemplate.exchange(recordurl, HttpMethod.POST, requestEntity, String.class);
String body = response.getBody();
JSONObject json = JSONObject.parseObject(body);
if (null != json.getString("status") && json.getString("status").equals("0")) {
record.setFile(null);
record.setPatrolTime(filename);
quartzService.insertRecord(record);
logger.info("ext/patrolCtrlRecord success-->" + file.getAbsolutePath());
} else {
logger.info("ext/patrolCtrlRecord fail-->" + fileParam[fileParam.length - 1] + body);
}
PatrolCtrlAlarm alarm = new PatrolCtrlAlarm();
alarm.setCameraCode(record.getCameraCode());
alarm.setCameraName(record.getCameraName());
alarm.setFile(fileatream);
alarm.setTime(picturetime);
alarm.setType("2");
//调用告警接口
ResponseEntity<String> alarmresponse = restTemplate.exchange(alarmurl, HttpMethod.POST, new HttpEntity<String>(JSONObject.toJSONString(alarm), headers), String.class);
JSONObject alarmjson = JSONObject.parseObject(alarmresponse.getBody());
if (null != alarmjson.getString("status") && alarmjson.getString("status").equals("0")) {
alarm.setFile(null);
alarm.setTime(filename);
quartzService.insertAlarm(alarm);
logger.info("ext/alarm success-->" + file.getAbsolutePath());
} else {
logger.info("ext/alarm fail-->" + fileParam[fileParam.length - 1] + alarmresponse.getBody());
}
} catch (Exception e) {
logger.error("ext/patrolCtrlRecord-->" + e.toString());
fixedThreadPool.execute(() -> {
String[] fileParam1 = file.getAbsolutePath().split("\\\\");
String filename1 = fileParam1[fileParam1.length - 2] + fileParam1[fileParam1.length - 1].replace(".jpeg", "");
if (null != fileParam1 && fileParam1.length > 4) {
String fileatream1 = fileutil.ImageToBase64ByLocal(file);
for (PatrolCtrlRecord record : recordList) {
if (record.getDeviceid().equals(fileParam1[fileParam1.length - 3])) {
try {
String picturetime1 = newsimpledate.format(simpledate.parse(filename1));
record.setPatrolTime(picturetime1);
record.setRecordSrc("2");
record.setFile(fileatream1);
//调用推送接口
HttpEntity<String> requestEntity = new HttpEntity<>(JSONObject.toJSONString(record), headers);
ResponseEntity<String> response = restTemplate.exchange(recordurl, HttpMethod.POST, requestEntity, String.class);
String body = response.getBody();
JSONObject json = JSONObject.parseObject(body);
if (null != json.getString("status") && json.getString("status").equals("0")) {
record.setFile(null);
record.setPatrolTime(filename1);
quartzService.insertRecord(record);
logger.info("ext/patrolCtrlRecord success-->" + file.getAbsolutePath());
} else {
logger.info("ext/patrolCtrlRecord fail-->" + fileParam1[fileParam1.length - 1] + body);
}
PatrolCtrlAlarm alarm = new PatrolCtrlAlarm();
alarm.setCameraCode(record.getCameraCode());
alarm.setCameraName(record.getCameraName());
alarm.setFile(fileatream1);
alarm.setTime(picturetime1);
alarm.setType("2");
//调用告警接口
ResponseEntity<String> alarmresponse = restTemplate.exchange(alarmurl, HttpMethod.POST, new HttpEntity<>(JSONObject.toJSONString(alarm), headers), String.class);
JSONObject alarmjson = JSONObject.parseObject(alarmresponse.getBody());
if (null != alarmjson.getString("status") && alarmjson.getString("status").equals("0")) {
alarm.setFile(null);
alarm.setTime(filename1);
quartzService.insertAlarm(alarm);
logger.info("ext/alarm success-->" + file.getAbsolutePath());
} else {
logger.info("ext/alarm fail-->" + fileParam1[fileParam1.length - 1] + alarmresponse.getBody());
}
} catch (Exception e) {
logger.error("ext/patrolCtrlRecord-->" + e.toString());
}
}
}
}
}
});
logger.info("ext/patrolCtrlRecord success-->" + "总共" + jsonFile.size() + "张,推送成功" + resultSuccess + "张,告警成功" + alarmresultSuccess + "张");
}
......@@ -229,9 +191,9 @@ public class ExtController {
List<String> imgUrls = new ArrayList<>();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
Map<String, Object> maps = new HashMap<String, Object>();
Map<String, Object> maps = new HashMap<>();
if(null==sbtdspsr.getSqurllj() ||"".equals(sbtdspsr.getSqurllj())){
String rtsp=getnewRtspVlue(sbtdspsr.getSbbh());
String rtsp=restutil.getnewRtspVlue(sbtdspsr.getSbbh(),getrtspbyurl);
sbtdspsr.setSqurllj(rtsp);
}
maps.put("rtspvalue", sbtdspsr.getSqurllj());
......@@ -246,13 +208,11 @@ public class ExtController {
String body = exchange.getBody();
logger.info("getRTSP/1->body:",body);
if(null==body|| "".equals(body)){
JSONObject json = JSONObject.parseObject(exchange.getBody());
//rtsp地址可能改变,重新获取
if(!videoid.contains("rtsp")) {
String rtsp = getnewRtspVlue(sbtdspsr.getSbbh());
String rtsp =restutil.getnewRtspVlue(sbtdspsr.getSbbh(),getrtspbyurl);
maps.put("rtspvalue", rtsp);
}
}
else{
JSONObject json = JSONObject.parseObject(exchange.getBody());
......@@ -264,108 +224,66 @@ public class ExtController {
}catch (Exception ex)
{
//rtsp地址可能改变,重新获取
String rtsp=getnewRtspVlue(sbtdspsr.getSbbh());
String rtsp=restutil.getnewRtspVlue(sbtdspsr.getSbbh(),getrtspbyurl);
maps.put("rtspvalue", rtsp);
}
try{
if(imgUrls.size()==0){
logger.info("no picture data ");
return ResultUtil.success();
}
//根据rtsp 进行图片获取及存储
TraffAlarmRecord record = new TraffAlarmRecord();
Map<String, Object> transferRecordMap = new HashMap<>();
TraffAlarmRecord traffAlarmRecord = new TraffAlarmRecord();
traffAlarmRecord.setFdid(sbtdspsr.getSbbh());
traffAlarmRecord.setChannelid(Integer.parseInt(String.valueOf(sbtdspsr.getTdbh())));
traffAlarmRecord.setAreaid(Long.parseLong(sbtdspsr.getXzbh()));
int i = 0;
if(imgUrls.size()>0) {
i = 1;
}
while (i < photonum) {
i++;
//第一张判断是否已经抽完图片,最多5张
if (i > 4) {
break;
}
ResponseEntity<String> exchange = restTemplate.exchange(rtspurl + "?url={rtspvalue}&refresh={refresh}",
HttpMethod.GET, formEntity, String.class, maps);
if(null!=exchange.getBody()|| !"".equals(exchange.getBody())) {
JSONObject json = JSONObject.parseObject(exchange.getBody());
if (null != json.getString("ret") && json.getString("ret").equals("0")) {
//获得图片地址
imgUrls.add(json.getString("url"));
}
}
}
traffAlarmRecord.setCreatetime(new Date());
traffAlarmRecord.setPushstatus(9);
//免审
traffAlarmRecord.setCheckstatus(9);
//未提取特征
traffAlarmRecord.setProcessstatus("-2");
//存储到ftp 上去
for (int k = 0; k < imgUrls.size(); k++) {
TraffAlarmRecordFromImgEnum.valueOf("IMG" + k).setImg(traffAlarmRecord, imgUrls.get(k));
}
String basepath = "gstraff/" + traffAlarmRecord.getFdid() + (traffAlarmRecord.getChannelid() < 10 ? "0" + traffAlarmRecord.getChannelid() : traffAlarmRecord.getChannelid()) + "/" + DateUtils.formatCurrDayNoSign();
Ftp ftp = ftpService.reloadFtp();
//入表
Long recordid = Long.parseLong(String.valueOf(traffAlarmRecordService.inserTraffAlarmRecord(traffAlarmRecord)));
FileTransferManager.fetchUrlsFromRecord(traffAlarmRecord, transferRecordMap);
List<TransferResult> results = FileTransferManager.transferFile(transferRecordMap, ftp, basepath);
// logger.info("缓存数据上传结果:" + results.toString());
TraffAlarmRecord recordBak = FileTransferManager.traffAlarmRecordUrlUpdate(results);
traffAlarmRecord.setImg1path(recordBak.getImg1path());
traffAlarmRecord.setImg2path(recordBak.getImg2path());
traffAlarmRecord.setImg3path(recordBak.getImg3path());
traffAlarmRecord.setImg4path(recordBak.getImg4path());
traffAlarmRecord.setImg5path(recordBak.getImg5path());
traffAlarmRecord.setVideopath(recordBak.getVideopath());
//更新图片地址
traffAlarmRecordService.updateTraffAlarmRecordUrl(traffAlarmRecord);
try{
if(imgUrls.size()==0){
logger.info("no picture data ");
return ResultUtil.success();
} catch(Exception e){
logger.error("ext/getRTSPr-->error" + e.toString());
}
return ResultUtil.success();
//根据rtsp 进行图片获取及存储
Map<String, Object> transferRecordMap = new HashMap<>();
TraffAlarmRecord traffAlarmRecord = new TraffAlarmRecord();
traffAlarmRecord.setFdid(sbtdspsr.getSbbh());
traffAlarmRecord.setChannelid(Integer.parseInt(String.valueOf(sbtdspsr.getTdbh())));
traffAlarmRecord.setAreaid(Long.parseLong(sbtdspsr.getXzbh()));
int i = 0;
if(imgUrls.size()>0) {
i = 1;
}
//抽取图片
restutil.getPicture(imgUrls, maps, formEntity,rtspurl);
traffAlarmRecord.setCreatetime(new Date());
traffAlarmRecord.setPushstatus(9);
//免审
traffAlarmRecord.setCheckstatus(9);
//未提取特征
traffAlarmRecord.setProcessstatus("-2");
//存储到ftp 上去
for (int k = 0; k < imgUrls.size(); k++) {
TraffAlarmRecordFromImgEnum.valueOf("IMG" + k).setImg(traffAlarmRecord, imgUrls.get(k));
}
String basepath = "gstraff/" + traffAlarmRecord.getFdid() + (traffAlarmRecord.getChannelid() < 10 ? "0" + traffAlarmRecord.getChannelid() : traffAlarmRecord.getChannelid()) + "/" + DateUtils.formatCurrDayNoSign();
Ftp ftp = ftpService.reloadFtp();
//入表
traffAlarmRecordService.inserTraffAlarmRecord(traffAlarmRecord);
FileTransferManager.fetchUrlsFromRecord(traffAlarmRecord, transferRecordMap);
List<TransferResult> results = FileTransferManager.transferFile(transferRecordMap, ftp, basepath);
// logger.info("缓存数据上传结果:" + results.toString());
TraffAlarmRecord recordBak = FileTransferManager.traffAlarmRecordUrlUpdate(results);
traffAlarmRecord.setImg1path(recordBak.getImg1path());
traffAlarmRecord.setImg2path(recordBak.getImg2path());
traffAlarmRecord.setImg3path(recordBak.getImg3path());
traffAlarmRecord.setImg4path(recordBak.getImg4path());
traffAlarmRecord.setImg5path(recordBak.getImg5path());
traffAlarmRecord.setVideopath(recordBak.getVideopath());
//更新图片地址
traffAlarmRecordService.updateTraffAlarmRecordUrl(traffAlarmRecord);
return ResultUtil.success();
} catch(Exception e){
logger.error("ext/getRTSPr-->error" + e.toString());
}
return ResultUtil.success();
}
public String getnewRtspVlue(String devicecode ){
String rtspnewvalue="";
Map<String, String> map = new HashMap<>();
map.put("deviceCode", devicecode);
ResponseEntity<String> responseEntity = restTemplate.getForEntity(getrtspbyurl+"?deviceCode={deviceCode}", String.class, map);
JSONObject json = JSONObject.parseObject(responseEntity.getBody());
if (null != json.getString("errorCode") && json.getString("errorCode").equals("0")) {
//返回rtsp 地址
json = JSONObject.parseObject(json.getString("data"));
if (null != json.get("rtspUri") && !"".equals(json.get("rtspUri"))) {
rtspnewvalue = String.valueOf(json.get("rtspUri"));
if(rtspnewvalue.contains("rtsp")) {
//更新sbtdspsr 地址
int result = sbtdspsrService.updateRecogByRtsp(rtspnewvalue, devicecode);
if (result > 0) {
logger.info("更新rtsp success");
} else {
logger.info("设备" + devicecode + "不存在");
}
}
else {
logger.info("获取失败");
}
}
}
return rtspnewvalue;
}
/***
* 适配算法偏移-30 的情况
* @param taskno
* @param taskno 设备编号
* @return
*/
@RequestMapping(value = "/getRecog", method = RequestMethod.POST)
......@@ -375,13 +293,17 @@ public String getnewRtspVlue(String devicecode ){
String model ="1";
String recordtype ="1";
//图片框选出来的范围
Long[] roiarray=new Long[4];
String videoid="",tdmc="";
Long[] roiarray;
String videoid,tdmc;
HttpHeaders headers = new HttpHeaders();
BASE64Encoder base64Encoder = new BASE64Encoder();
if (null != mapList && !mapList.equals("") && mapList.size()>0) {
//获得该监控的检测业务与检测范围
for (Map<String, Object> map: mapList) {
for (Map.Entry<String, Object> maps:map.entrySet()) {
for (Map<String, Object> mapobj: mapList) {
roiarray=new Long[4];
videoid="";
tdmc="";
for (Map.Entry<String, Object> maps:mapobj.entrySet()) {
if("videoid".equals(maps.getKey())){
videoid = String.valueOf(maps.getValue());
}
......@@ -408,166 +330,162 @@ public String getnewRtspVlue(String devicecode ){
tdmc=String.valueOf(maps.getValue());
}
}
}
//查询该监控下面还没有经过分析的数据
String basepath = "gstraff/" + videoid+ "/" + DateUtils.formatCurrDayNoSign();
Map<String, Object> map = new HashMap<>();
if(videoid.split("_").length<2){
logger.info("监控不存在"+videoid);
return ResultUtil.success();
}
map.put("sbbh", videoid.split("_")[0]);
map.put("tdbh", videoid.split("_")[1]);
map.put("sbbh", videoid);
List<TraffAlarmRecord> traffalarmrecordlist = traffAlarmRecordService.getTraffAlarmRecordByProgress(map);
if(traffalarmrecordlist.size()<1) {
return ResultUtil.success();
}
BASE64Decoder base64Decoder = new BASE64Decoder();
//开启多线程
//调用结构化服务,获得图片返回结果
HttpHeaders headers = new HttpHeaders();
BASE64Encoder base64Encoder = new BASE64Encoder();
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
HttpEntity<String> requestEntity = null;
for (TraffAlarmRecord transferRecord : traffalarmrecordlist) {
GoalStructureParam param = FileTransferManager.getGoalStructureParam(roiarray,
Integer.parseInt(model == null ? "1" : "".equals(model) ? "1" : model
), base64Encoder, transferRecord);
if (param.getImageList().size() < 1) {
logger.info(" no imagelist ");
if (getAlarm(model, recordtype, roiarray, tdmc, headers, base64Encoder, basepath, traffalarmrecordlist))
return ResultUtil.success();
}
return ResultUtil.success();
}else {
logger.info("监控不属于该范围");
}
//更新record 表Progress 字段,0为 未检测,-2 为检测失败,将检测
//结果进行额外封装入表
logger.error("rtsp 不存在-->");
return ResultUtil.fail();
}
public boolean getAlarm(String model, String recordtype, Long[] roiarray, String tdmc, HttpHeaders headers, BASE64Encoder base64Encoder, String basepath, List<TraffAlarmRecord> traffalarmrecordlist) {
HttpEntity<String> requestEntity;
for (TraffAlarmRecord transferRecord : traffalarmrecordlist) {
GoalStructureParam param = FileTransferManager.getGoalStructureParam(roiarray,
Integer.parseInt(model == null ? "1" : "".equals(model) ? "1" : model
), base64Encoder, transferRecord);
if (param.getImageList().size() < 1) {
logger.info(" no imagelist ");
transferRecord.setProcessstatus("-1");
traffAlarmRecordService.updateTraffAlarmRecordProcess(transferRecord);
continue;
}
requestEntity = new HttpEntity<>(JSONObject.toJSONString(param), headers);
try {
ResponseEntity<String> response = restTemplate.exchange(recogurl, HttpMethod.POST, requestEntity, String.class);
String body = response.getBody();
JSONObject result = JSONObject.parseObject(body);
if (null != result.get("ret") && result.get("ret").equals("200")) {
//获得返回结果,根据 Metadata.type 判断是人,车,人骑车,并将详细信息入对应的表
List<TraffpictureParam> objectList = JSONArray.parseArray(String.valueOf(result.get("ObjectList")), TraffpictureParam.class);
//获得 type,更新 recordalarm 为已分析
transferRecord.setProcessstatus("-1");
traffAlarmRecordService.updateTraffAlarmRecordProcess(transferRecord);
continue;
}
requestEntity = new HttpEntity<>(JSONObject.toJSONString(param), headers);
try {
ResponseEntity<String> response = restTemplate.exchange(recogurl, HttpMethod.POST, requestEntity, String.class);
String body = response.getBody();
JSONObject result = JSONObject.parseObject(body);
if (null != result.get("ret") && result.get("ret").equals("200")) {
//获得返回结果,根据 Metadata.type 判断是人,车,人骑车,并将详细信息入对应的表
List<TraffpictureParam> objectList = (List<TraffpictureParam>) JSONArray.parseArray(String.valueOf(result.get("ObjectList")), TraffpictureParam.class);
//获得 type
//更新 recordalarm 为已分析
transferRecord.setProcessstatus("-1");
traffAlarmRecordService.updateTraffAlarmRecordProcess(transferRecord);
if (objectList.size() < 1) {
logger.info(" no picturedata ");
continue;
if (objectList.size() < 1) {
logger.info(" no picturedata ");
continue;
}
TraffrecordData traffrecordData=new TraffrecordData();
//根据结构化统计查询是否超过密度,超过则预警
Code code = codeservice.selectalarmNum(recordtype);
roiarray[0] = roiarray[0] - 30;
roiarray[1] = roiarray[1] - 30;
roiarray[2] = roiarray[2] - 30;
roiarray[3] = roiarray[3] - 30;
//判断是否统计结构化数据
TraffpictureParam traffpictureParamresult = new TraffpictureParam();
traffpictureParamresult.setImagedata(transferRecord.getImg1path());
if (("6".equals(recordtype) || "2".equals(recordtype))) {
if (null != code && null != code.getAlarmnum() && code.getAlarmnum() < objectList.size()) {
setTraffpictureParam(recordtype, transferRecord, traffpictureParamresult);
traffpictureParamresult.setTargetnum(objectList.size());
//超过则预警
traffpictureParamresult.setRecordtype(recordtype);
traffPictureService.updateTraffpicture(traffpictureParamresult);
}
TraffrecordData sendtozhiui=new TraffrecordData();
//根据结构化统计查询是否超过密度,超过则预警
Code code = codeservice.selectalarmNum(recordtype);
roiarray[0] = roiarray[0] - 30;
roiarray[1] = roiarray[1] - 30;
roiarray[2] = roiarray[2] - 30;
roiarray[3] = roiarray[3] - 30;
//判断是否统计结构化数据
TraffpictureParam traffpictureParamresult = new TraffpictureParam();
traffpictureParamresult.setImagedata(transferRecord.getImg1path());
if (("6".equals(recordtype) || "2".equals(recordtype))) {
if (null != code && null != code.getAlarmnum() && code.getAlarmnum() < objectList.size()) {
setTraffpictureParam(recordtype, base64Encoder, transferRecord, traffpictureParamresult);
traffpictureParamresult.setTargetnum(objectList.size());
//超过则预警
traffpictureParamresult.setRecordtype(recordtype);
traffPictureService.updateTraffpicture(traffpictureParamresult);
}
else{
return ResultUtil.success();
}
else{
return true;
}
}
// if ((("6".equals(recordtype) || "2".equals(recordtype))
// && (null != code && null != code.getAlarmnum() && code.getAlarmnum() < objectList.size()))
// && (!"6".equals(recordtype) && !"2".equals(recordtype))) {
List<ObjectBoundingBox> list = new ArrayList<>();
for (TraffpictureParam traffpictureParam : objectList) {
//根据imageid 获得 base64图片
JSONObject metadata = JSONObject.parseObject(String.valueOf(traffpictureParam.getMetadata()));
JSONObject ObjectBoundingBox = metadata.getJSONObject("ObjectBoundingBox");
//获得物体特征值
if (null == ObjectBoundingBox) {
list.add(new ObjectBoundingBox(metadata.getIntValue("LeftTopX") + roiarray[0].intValue(),
metadata.getIntValue("LeftTopY") + roiarray[1].intValue(),
metadata.getIntValue("RightBtmX") - metadata.getIntValue("LeftTopX"),
metadata.getIntValue("RightBtmY") - metadata.getIntValue("LeftTopY")
));
} else {
list.add(new ObjectBoundingBox(ObjectBoundingBox.getIntValue("X") + roiarray[0].intValue(),
ObjectBoundingBox.getIntValue("Y") + roiarray[1].intValue(),
ObjectBoundingBox.getIntValue("W"),
ObjectBoundingBox.getIntValue("H")
));
}
//根据对应的解析结果获得相应的数据,存放到对应的表中
getMetaData(recordtype, roiarray, base64Encoder, transferRecord, traffpictureParamresult, list, traffpictureParam, metadata);
List<ObjectBoundingBox> list = new ArrayList<>();
for (TraffpictureParam traffpictureParam : objectList) {
//根据imageid 获得 base64图片
JSONObject metadata = JSONObject.parseObject(String.valueOf(traffpictureParam.getMetadata()));
JSONObject ObjectBoundingBox = metadata.getJSONObject("ObjectBoundingBox");
//获得物体特征值
if (null == ObjectBoundingBox) {
list.add(new ObjectBoundingBox(metadata.getIntValue("LeftTopX") + roiarray[0].intValue(),
metadata.getIntValue("LeftTopY") + roiarray[1].intValue(),
metadata.getIntValue("RightBtmX") - metadata.getIntValue("LeftTopX"),
metadata.getIntValue("RightBtmY") - metadata.getIntValue("LeftTopY")
));
} else {
list.add(new ObjectBoundingBox(ObjectBoundingBox.getIntValue("X") + roiarray[0].intValue(),
ObjectBoundingBox.getIntValue("Y") + roiarray[1].intValue(),
ObjectBoundingBox.getIntValue("W"),
ObjectBoundingBox.getIntValue("H")
));
}
//根据对应的解析结果获得相应的数据,存放到对应的表中
getMetaData(recordtype, roiarray, base64Encoder, transferRecord, traffpictureParamresult, list, traffpictureParam, metadata);
}
//更新 traffpicture特征值
try {
byte[] Img = FTPUtil.getFtpPicBytes(traffpictureParamresult.getImagedata());
if (null != Img) {
ByteArrayInputStream bais = new ByteArrayInputStream(Img);
BufferedImage image = ImageIO.read(bais);
Graphics g = image.getGraphics();
g.setColor(Color.RED);
//遍历所有特征值,画到图片上
for (ObjectBoundingBox box : list) {
if (null != box) {
g.drawRect(box.getX(), box.getY(), box.getW(), box.getH());
}
//更新 traffpicture特征值
try {
byte[] Img = FTPUtil.getFtpPicBytes(traffpictureParamresult.getImagedata());
if (null != Img) {
ByteArrayInputStream bais = new ByteArrayInputStream(Img);
BufferedImage image = ImageIO.read(bais);
Graphics g = image.getGraphics();
g.setColor(Color.RED);
//遍历所有特征值,画到图片上
for (ObjectBoundingBox box : list) {
if (null != box) {
g.drawRect(box.getX(), box.getY(), box.getW(), box.getH());
}
}
ByteArrayOutputStream stream = new ByteArrayOutputStream();
ImageIO.write(image, "png", stream);
//上传ftp
Ftp ftp = ftpService.reloadFtp();
String filename = DateUtils.formatCurrDateNoSign() + "imgdata.png";
String ftputl = FTPUtil.getFtpUrl(ftp) + basepath + "/" + traffpictureParamresult.getId() + "/" + filename;
traffpictureParamresult.setImagedata(ftputl);
//base 64 图片
String png_base64 = base64Encoder.encode(stream.toByteArray()).trim();
FTPUtil.uploadFile(ftp, basepath + "/" + traffpictureParamresult.getId(), filename,png_base64 );
ByteArrayOutputStream stream = new ByteArrayOutputStream();
ImageIO.write(image, "png", stream);
//上传ftp
Ftp ftp = ftpService.reloadFtp();
String filename = DateUtils.formatCurrDateNoSign() + "imgdata.png";
String ftputl = FTPUtil.getFtpUrl(ftp) + basepath + "/" + traffpictureParamresult.getId() + "/" + filename;
traffpictureParamresult.setImagedata(ftputl);
//base 64 图片
String png_base64 = base64Encoder.encode(stream.toByteArray()).trim();
FTPUtil.uploadFile(ftp, basepath + "/" + traffpictureParamresult.getId(), filename,png_base64 );
}
} catch (Exception ex) {
logger.info("base64画框异常:" + ex.toString());
}
traffPictureService.updateTraffpicture(traffpictureParamresult);
//推送给第三方的base64
sendtozhiui.setImagedata(publicpictureurl+"/fielagent?ftpPath="+traffpictureParamresult.getId());
//赋值推送第三方数据
sendtozhiui.setRecordlevel(code.getAlarmlevel());
sendtozhiui.setTargetnum(code.getMaxnum());
sendtozhiui.setRecordname(code.getName());
sendtozhiui.setTdmc(tdmc);
//推送给第三方
eventWriteService.sendEvent(traffpictureParamresult,sendtozhiui);
//推送告警到前端
webSocket.GroupSending(JSONObject.toJSONString(traffpictureParamresult));
} catch (Exception ex) {
logger.info("base64画框异常:" + ex.toString());
}
traffPictureService.updateTraffpicture(traffpictureParamresult);
//推送给第三方的base64
traffrecordData.setImagedata(publicpictureurl+"?location="+traffpictureParamresult.getImagedata().replace("ftp://"+ftppath+"/",""));
//赋值推送第三方数据
traffrecordData.setRecordlevel(code.getAlarmlevel());
traffrecordData.setTargetnum(code.getMaxnum());
traffrecordData.setRecordname(code.getName());
traffrecordData.setTdmc(tdmc);
//推送给第三方
eventWriteService.sendEvent(traffpictureParamresult,traffrecordData);
logger.info(" send to meili: {}",JSONObject.toJSON(traffrecordData));
//推送告警到前端
webSocket.GroupSending(JSONObject.toJSONString(traffpictureParamresult));
}
} catch (Exception ex) {
//推送失败
transferRecord.setProcessstatus("-3");
traffAlarmRecordService.updateTraffAlarmRecordProcess(transferRecord);
}
} catch (Exception ex) {
//推送失败
transferRecord.setProcessstatus("-3");
traffAlarmRecordService.updateTraffAlarmRecordProcess(transferRecord);
}
return ResultUtil.success();
} else {
logger.info("监控不属于该范围");
}
//更新record 表Progress 字段,0为 未检测,-2 为检测失败,将检测
//结果进行额外封装入表
logger.error("rtsp 不存在-->");
return ResultUtil.fail();
return false;
}
private void getMetaData(String recordtype, Long[] roiarray, BASE64Encoder base64Encoder, TraffAlarmRecord transferRecord, TraffpictureParam traffpictureParamresult, List<ObjectBoundingBox> list, TraffpictureParam traffpictureParam, JSONObject metadata) {
......@@ -575,7 +493,7 @@ public String getnewRtspVlue(String devicecode ){
traffpictureParamresult.setMetatype(String.valueOf(metadata.get("Type")));
//规定区域内出现告警对象
if(null==traffpictureParamresult.getId()) {
setTraffpictureParam(recordtype, base64Encoder, transferRecord, traffpictureParamresult);
setTraffpictureParam(recordtype, transferRecord, traffpictureParamresult);
}
if ("1".equals(metadata.get("Type"))) {
//规定范围内检测到人
......@@ -691,7 +609,6 @@ public String getnewRtspVlue(String devicecode ){
/***
* 原来推送
* @param recordtype
* @param base64Encoder
* @param transferRecord
* @param traffpictureParam
*/
......@@ -985,7 +902,7 @@ public String getnewRtspVlue(String devicecode ){
// logger.error("rtsp 不存在-->");
// return ResultUtil.fail();
// }
private void setTraffpictureParam(String recordtype, BASE64Encoder base64Encoder, TraffAlarmRecord transferRecord, TraffpictureParam traffpictureParam) {
private void setTraffpictureParam(String recordtype, TraffAlarmRecord transferRecord, TraffpictureParam traffpictureParam) {
traffpictureParam.setAreaid(transferRecord.getAreaid());
traffpictureParam.setFdid(transferRecord.getFdid());
traffpictureParam.setRecordid(transferRecord.getRecordid());
......
......@@ -35,7 +35,7 @@ public class IndexController {
@Autowired
private RestTemplate restTemplate;
@Value("${ftppath}")
@Value("${file.ftppath}")
private String ftppath;
@Autowired
......
......@@ -45,7 +45,7 @@ public class QuartzController {
private String rtspurl;
@Value("${ftppath}")
@Value("${file.ftppath}")
private String ftppath;
......
......@@ -9,6 +9,5 @@ public interface SbtdspsrService {
List<Sbtdspsr> selectByRtsp(String videoid);
List<Map> selectRecogByRtsp(String rtsp);
int updateRecogByRtsp(String rtsp,String devicecode);
List<Sbtdspsr> list();
}
package com.cx.cn.cxquartz.service.quartz.impl;
import com.alibaba.fastjson.JSONObject;
import com.cx.cn.cxquartz.dao.SbtdspsrMapper;
import com.cx.cn.cxquartz.service.quartz.SbtdspsrService;
import com.cx.cn.cxquartz.vo.Sbtdspsr;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.util.HashMap;
import java.util.List;
......
package com.cx.cn.cxquartz.util;
import com.alibaba.fastjson.JSONObject;
import com.cx.cn.cxquartz.controller.ExtController;
import com.cx.cn.cxquartz.service.quartz.SbtdspsrService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class RestUtil {
private static final Logger logger = LoggerFactory.getLogger(RestUtil.class);
@Autowired
private RestTemplate restTemplate;
@Autowired
SbtdspsrService sbtdspsrService;
public String getnewRtspVlue(String devicecode,String getrtspbyurl ){
String rtspnewvalue="";
Map<String, String> map = new HashMap<>();
map.put("deviceCode", devicecode);
ResponseEntity<String> responseEntity = restTemplate.getForEntity(getrtspbyurl+"?deviceCode={deviceCode}", String.class, map);
JSONObject json = JSONObject.parseObject(responseEntity.getBody());
if (null != json.getString("errorCode") && json.getString("errorCode").equals("0")) {
//返回rtsp 地址
json = JSONObject.parseObject(json.getString("data"));
if (null != json.get("rtspUri") && !"".equals(json.get("rtspUri"))) {
rtspnewvalue = String.valueOf(json.get("rtspUri"));
if(rtspnewvalue.contains("rtsp")) {
//更新sbtdspsr 地址
int result = sbtdspsrService.updateRecogByRtsp(rtspnewvalue, devicecode);
if (result > 0) {
logger.info("更新rtsp success");
} else {
logger.info("设备" + devicecode + "不存在");
}
}
else {
logger.info("获取失败");
}
}
}
return rtspnewvalue;
}
public void rtspChangeVlue(String devicecode,String oldrtsp,String getrtspbyurl ){
String rtspnewvalue="";
Map<String, String> map = new HashMap<>();
map.put("deviceCode", devicecode);
ResponseEntity<String> responseEntity = restTemplate.getForEntity(getrtspbyurl+"?deviceCode={deviceCode}", String.class, map);
JSONObject json = JSONObject.parseObject(responseEntity.getBody());
if (null != json.getString("errorCode") && json.getString("errorCode").equals("0")) {
//返回rtsp 地址
json = JSONObject.parseObject(json.getString("data"));
if (null != json.get("rtspUri") && !"".equals(json.get("rtspUri"))) {
rtspnewvalue = String.valueOf(json.get("rtspUri"));
//与新获得的rtsp 比较,如果一样则不更新,否则更新
if(oldrtsp.contains("rtsp") && !oldrtsp.equals(rtspnewvalue)) {
//更新sbtdspsr 地址
int result = sbtdspsrService.updateRecogByRtsp(rtspnewvalue, devicecode);
if (result > 0) {
logger.info("更新rtsp success");
} else {
logger.info("设备" + devicecode + "不存在");
}
}
else {
logger.info("获取失败");
}
}
}
}
public void getPicture(List<String> imgUrls, Map<String, Object> maps, HttpEntity<String> formEntity,String rtspurl) {
ResponseEntity<String> exchange = restTemplate.exchange(rtspurl + "?url={rtspvalue}&refresh={refresh}",
HttpMethod.GET, formEntity, String.class, maps);
if(null!=exchange.getBody()) {
JSONObject json = JSONObject.parseObject(exchange.getBody());
if (null != json.getString("ret") && json.getString("ret").equals("0")) {
//获得图片地址
imgUrls.add(json.getString("url"));
}
}
}
}
......@@ -11,12 +11,12 @@ mybatis:
spring:
datasource:
# url: jdbc:mysql://192.168.168.212:3306/imagepro?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
#username: zn06
#password: znznzn8
url: jdbc:mysql://172.16.24.29:3306/imagepro?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true
url: jdbc:mysql://192.168.168.110:3306/imagepro?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
username: root
password: 123456
# url: jdbc:mysql://172.16.24.29:3306/imagepro?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true
# username: root
# password: 123456
driver-class-name: com.mysql.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource
filters: stat
......@@ -51,6 +51,4 @@ spring:
logging:
level:
com.cx.cn.cxquartz.dao:
debug
debug
\ No newline at end of file
......@@ -20,6 +20,6 @@ eventwrite.url=http://countryside.51iwifi.com/gw/hesc-mq/hesc/mq/receive/cameraa
countryside.appid=05744e80b2c211ebe32a8e271066b19e
countryside.appsecret=a55a8870b2e911ebe32a8e271066b19e
countryside.tokenurl=http://countryside.51iwifi.com/gw/getAccessToken
file.publicpictureurl=http://zjh189.ncpoi.cc:10001
ftppath=jiuling:9ling.cn@172.16.24.29:21
file.publicpictureurl=http://zjh189.ncpoi.cc:10001/api/alg/files
file.ftppath=jiuling:9ling.cn@172.16.24.29:21
......@@ -20,7 +20,7 @@
<select id="selectRecogByRtsp" parameterType="java.lang.String" resultType="java.util.HashMap">
SELECT DISTINCT
(select concat(sbbh,"_",tdbh) from sbtdspsr where sbbh=b.videoid or squrllj=b.videoid limit 1) videoid,
(select sbbh from sbtdspsr where sbbh=b.videoid or squrllj=b.videoid limit 1) videoid,
(select tdmc from sbtdspsr where sbbh=b.videoid or squrllj=b.videoid limit 1) tdmc,
metatype,
recordtype,
......@@ -31,7 +31,7 @@
FROM
quartz_task_informations b
WHERE
(videoid=#{rtsp} or executeparamter=#{rtsp})
(videoid=#{rtsp} or executeparamter=#{rtsp})and recordtype is not null
</select>
<update id="updateRecogByRtsp" parameterType="java.util.HashMap" >
......
......@@ -162,7 +162,7 @@
</update>
<select id="getTraffAlarmRecordByProgress" parameterType="java.util.HashMap" resultType="com.cx.cn.cxquartz.vo.TraffAlarmRecord">
select * from traffalarmrecord where fdid=#{sbbh} and channelid=#{tdbh} and processstatus='-2'
select * from traffalarmrecord where fdid=#{sbbh} and processstatus='-2'
</select>
<update id="updateTraffAlarmRecordProcess" parameterType="com.cx.cn.cxquartz.vo.TraffAlarmRecord">
......
......@@ -72,7 +72,18 @@
</div>
<div class="form-group"><label
class="col-sm-2 control-label text-right">监控id:</label>
class="col-sm-2 control-label text-right">监控id:</label>
<select class="form-control" id="metatype">
<option th:value="3DHCA343714GMCE"
山河村
</option>
<option th:value="3DHCA34401BUXS9">
赵家上村
</option>
<option th:value="3YSCA44524PUH3B" >
3YSCA44524PUH3B
</option>
</select>
</div>
<div class="form-group">
......@@ -81,8 +92,8 @@
id="videoid" class="form-control" style="width:65%;float: left">
<a id="getrtsp" href=" javascript:void(0)"
style="float: left;padding-left: 12px;padding-top: 10px;">获得监控图片</a>
<a id="getwidth" href=" javascript:void(0)"
style="float: left;padding-left: 12px;padding-top: 10px;">编辑监控范围</a>
<!--<a id="getwidth" href=" javascript:void(0)"-->
<!--style="float: left;padding-left: 12px;padding-top: 10px;">编辑监控范围</a>-->
</div>
</div>
......@@ -95,7 +106,6 @@
</option>
<option th:value="2">
行人、骑行、车辆检测识别
</option>
<option th:value="3" >
人脸检测识别
......
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