Commit 4b7f57e1 authored by wangjinjing's avatar wangjinjing

bug 修复

parent 8203c618
package com.hzjt.controller;
import cn.hutool.json.JSONUtil;
import com.hzjt.domain.Alarm;
import com.hzjt.domain.AlarmEvents;
import com.hzjt.domain.Ftp;
......@@ -65,22 +66,22 @@ public class AlarmController {
Alarm alarm = TransHelper.transAlarmResult(alarmEvents);
alarm.setDept(xzbh);
Result result = new Result();
Traffalarmrecord traffAlarmRecord = new Traffalarmrecord();
traffAlarmRecord.setAreaid(Long.valueOf(xzbh));
traffAlarmRecord.setRecordtype(alarmEvents.getEventType().toLowerCase());
Traffalarmrecord traffAlarmRecord_init = new Traffalarmrecord();
traffAlarmRecord_init.setAreaid(Long.valueOf(xzbh));
traffAlarmRecord_init.setRecordtype(alarmEvents.getEventType().toLowerCase());
if (alarmEvents.getStartTime() != null) {
traffAlarmRecord.setRecordtime(DateUtils.getDateString(new Date(Long.valueOf(alarmEvents.getStartTime()) * 1000L)));
traffAlarmRecord_init.setRecordtime(DateUtils.getDateString(new Date(Long.valueOf(alarmEvents.getStartTime()) * 1000L)));
}
traffAlarmRecord.setFdid(alarmEvents.getDeviceId());
traffAlarmRecord.setChannelid(0);
traffAlarmRecord.setCreatetime(DateUtils.getDateString(new Date()));
traffAlarmRecord.setObjlable(alarm.getObjLabel());
traffAlarmRecord.setPushstatus(9);
traffAlarmRecord.setProcessstatus("0");
traffAlarmRecord.setManualstatus(1);
traffAlarmRecord.setChannelname(alarmEvents.getDeviceName());
traffAlarmRecord.setObjlable(alarmEvents.getObjectType());
traffAlarmRecord_init.setFdid(alarmEvents.getDeviceId());
traffAlarmRecord_init.setChannelid(0);
traffAlarmRecord_init.setCreatetime(DateUtils.getDateString(new Date()));
traffAlarmRecord_init.setObjlable(alarm.getObjLabel());
traffAlarmRecord_init.setPushstatus(9);
traffAlarmRecord_init.setProcessstatus("0");
traffAlarmRecord_init.setManualstatus(1);
traffAlarmRecord_init.setChannelname(alarmEvents.getDeviceName());
traffAlarmRecord_init.setObjlable(alarmEvents.getObjectType());
List<MediaList> imgBase64List = alarmEvents.getMediaList();
String imgEnumHead = "IMG";
int i = 0;
......@@ -89,30 +90,31 @@ public class AlarmController {
while(var12.hasNext()) {
MediaList imgs = (MediaList)var12.next();
if (imgs.getType().contains("jpg")) {
TraffAlarmRecordFromImgEnum.valueOf(imgEnumHead + i).setImg(traffAlarmRecord, imgs.getSrc());
TraffAlarmRecordFromImgEnum.valueOf(imgEnumHead + i).setImg(traffAlarmRecord_init, imgs.getSrc());
++i;
}
if (imgs.getType().contains("mp4")) {
traffAlarmRecord.setVideourlfrom(imgs.getSrc());
traffAlarmRecord_init.setVideourlfrom(imgs.getSrc());
}
}
if (StringEnum.ONE.getValue().equals(this.checkEnable)) {
traffAlarmRecord.setCheckstatus(9);
traffAlarmRecord_init.setCheckstatus(9);
}
Map<Object, Object> map = new HashMap();
map.put("type", "alarm");
traffAlarmRecord.setEventid("66211" + UUIDUtils.createuuid());
this.traffAlarmRecordMapper.inserTraffAlarmRecord(traffAlarmRecord);
traffAlarmRecord_init.setEventid("66211" + UUIDUtils.createuuid());
this.traffAlarmRecordMapper.inserTraffAlarmRecord(traffAlarmRecord_init);
map.put("data", alarm);
map.put("recordid", traffAlarmRecord.getRecordid());
map.put("recordid", traffAlarmRecord_init.getRecordid());
this.webSocket.GroupSending(JsonUtil.beanToString(map));
try {
Traffalarmrecord traffAlarmRecord = JSONUtil.toBean(JsonUtil.beanToString(traffAlarmRecord_init), Traffalarmrecord.class);
String basepath = traffAlarmRecord.getFdid() + (traffAlarmRecord.getChannelid() < 10 ? "0" + traffAlarmRecord.getChannelid() : traffAlarmRecord.getChannelid()) + "/" + DateUtils.formatCurrDayNoSign();
Map<String, Object> transferRecordMap = new HashMap();
FileTransferManager.fetchUrlsFromRecord(traffAlarmRecord, transferRecordMap);
......@@ -121,13 +123,6 @@ public class AlarmController {
Traffalarmrecord recordBak = FileTransferManager.traffAlarmRecordUrlUpdate(results);
log.info("recordBak=={}",JsonUtil.beanToString(recordBak));
log.info("traffAlarmRecord=={}",traffAlarmRecord.getRecordid());
// traffAlarmRecord.setRecordid(recordBak.getRecordid());
// traffAlarmRecord.setImg1path(recordBak.getImg1path());
// traffAlarmRecord.setImg2path(recordBak.getImg2path());
// traffAlarmRecord.setImg3path(recordBak.getImg3path());
// traffAlarmRecord.setImg4path(recordBak.getImg4path());
// traffAlarmRecord.setImg5path(recordBak.getImg5path());
// traffAlarmRecord.setVideopath(recordBak.getVideopath());
this.traffAlarmRecordMapper.updateTraffAlarmRecordUrl(recordBak);
traffAlarmRecord.setPushdesc("success");
traffAlarmRecord.setPushstatus(0);
......
......@@ -6,6 +6,7 @@
package com.hzjt.controller;
import cn.hutool.core.codec.Base64Encoder;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.google.common.util.concurrent.RateLimiter;
import com.hzjt.domain.Alarm;
......@@ -177,51 +178,52 @@ public class TraffController {
}
public void sendevent(Alarm trffClientMessage, Sbtdspsr spr) {
Traffalarmrecord traffAlarmRecord = new Traffalarmrecord();
traffAlarmRecord.setAreaid(Long.valueOf(trffClientMessage.getDept()));
traffAlarmRecord.setRecordtype(trffClientMessage.getIncident_type().toLowerCase());
traffAlarmRecord.setRecordtime(DateUtils.getDateString(new Date(Long.valueOf(trffClientMessage.getTs()))));
traffAlarmRecord.setFdid(trffClientMessage.getVideo_id());
traffAlarmRecord.setChannelid(0);
traffAlarmRecord.setVideourlfrom(trffClientMessage.getVideo_record_url());
traffAlarmRecord.setCreatetime(DateUtils.getDateString(new Date()));
traffAlarmRecord.setObjlable(trffClientMessage.getObjLabel());
traffAlarmRecord.setPushstatus(9);
traffAlarmRecord.setProcessstatus("0");
traffAlarmRecord.setManualstatus(1);
traffAlarmRecord.setChannelname(spr.getTdmc());
Traffalarmrecord traffAlarmRecord_init = new Traffalarmrecord();
traffAlarmRecord_init.setAreaid(Long.valueOf(trffClientMessage.getDept()));
traffAlarmRecord_init.setRecordtype(trffClientMessage.getIncident_type().toLowerCase());
traffAlarmRecord_init.setRecordtime(DateUtils.getDateString(new Date(Long.valueOf(trffClientMessage.getTs()))));
traffAlarmRecord_init.setFdid(trffClientMessage.getVideo_id());
traffAlarmRecord_init.setChannelid(0);
traffAlarmRecord_init.setVideourlfrom(trffClientMessage.getVideo_record_url());
traffAlarmRecord_init.setCreatetime(DateUtils.getDateString(new Date()));
traffAlarmRecord_init.setObjlable(trffClientMessage.getObjLabel());
traffAlarmRecord_init.setPushstatus(9);
traffAlarmRecord_init.setProcessstatus("0");
traffAlarmRecord_init.setManualstatus(1);
traffAlarmRecord_init.setChannelname(spr.getTdmc());
List<String> imgBase64List = trffClientMessage.getImg_base64();
String imgEnumHead = "IMG";
Ftp ftp = this.ftpService.reloadFtp();
String basepath;
for (int i = 0; i < imgBase64List.size(); ++i) {
String path = trffClientMessage.getVideo_id() + (traffAlarmRecord.getChannelid() < 10 ? "0" + traffAlarmRecord.getChannelid() : traffAlarmRecord.getChannelid()) + "/" + DateUtils.formatCurrDayNoSign();
String path = trffClientMessage.getVideo_id() + (traffAlarmRecord_init.getChannelid() < 10 ? "0" + traffAlarmRecord_init.getChannelid() : traffAlarmRecord_init.getChannelid()) + "/" + DateUtils.formatCurrDayNoSign();
basepath = UUIDUtils.createuuid() + ".jpg";
if (FTPUtil.uploadFile(ftp, "gstraff/" + path, basepath, (String) imgBase64List.get(i))) {
TraffAlarmRecordImgEnum.valueOf(imgEnumHead + i).setImg(traffAlarmRecord, path + "/" + basepath);
TraffAlarmRecordImgEnum.valueOf(imgEnumHead + i).setImg(traffAlarmRecord_init, path + "/" + basepath);
}
}
List<String> imgUrls = trffClientMessage.getImg_urls();
for (int j = 0; j < imgUrls.size(); ++j) {
TraffAlarmRecordFromImgEnum.valueOf(imgEnumHead + j).setImg(traffAlarmRecord, (String) imgUrls.get(j));
TraffAlarmRecordFromImgEnum.valueOf(imgEnumHead + j).setImg(traffAlarmRecord_init, (String) imgUrls.get(j));
}
if (StringEnum.ONE.getValue().equals(this.checkEnable)) {
traffAlarmRecord.setCheckstatus(9);
traffAlarmRecord_init.setCheckstatus(9);
}
Map<Object, Object> map = new HashMap();
map.put("type", "alarm");
traffAlarmRecord.setEventid("66211" + UUIDUtils.createuuid());
this.traffAlarmRecordMapper.inserTraffAlarmRecord(traffAlarmRecord);
traffAlarmRecord_init.setEventid("66211" + UUIDUtils.createuuid());
this.traffAlarmRecordMapper.inserTraffAlarmRecord(traffAlarmRecord_init);
map.put("data", trffClientMessage);
map.put("recordid", traffAlarmRecord.getRecordid());
map.put("recordid", traffAlarmRecord_init.getRecordid());
this.webSocket.GroupSending(JsonUtil.beanToString(map));
try {
Traffalarmrecord traffAlarmRecord = JSONUtil.toBean(JsonUtil.beanToString(traffAlarmRecord_init), Traffalarmrecord.class);
basepath = traffAlarmRecord.getFdid() + (traffAlarmRecord.getChannelid() < 10 ? "0" + traffAlarmRecord.getChannelid() : traffAlarmRecord.getChannelid()) + "/" + DateUtils.formatCurrDayNoSign();
Map<String, Object> transferRecordMap = new HashMap();
FileTransferManager.fetchUrlsFromRecord(traffAlarmRecord, transferRecordMap);
......@@ -236,11 +238,10 @@ public class TraffController {
Traffalarmrecord record = new Traffalarmrecord();
record.setRecordid(recordBak.getRecordid());
String url = recordBak.getVideourlfrom();
String finalBasepath = recordBak.getVideopath();
record.setVideopath(recordBak.getVideopath());
log.info("url:{}", url);
log.info("bathpath:{}", recordBak.getVideopath());
this.schedulepool.schedule(() -> {
log.info("finalBasepath====={}", finalBasepath);
try {
HttpURLConnection connection = (HttpURLConnection) (new URL(url)).openConnection();
connection.setReadTimeout(2000);
......@@ -248,14 +249,20 @@ public class TraffController {
connection.setRequestMethod("GET");
if (connection.getResponseCode() == 200) {
InputStream inputStream = connection.getInputStream();
log.info("url:{}", url);
// log.info("url:{}", url);
String pname = DateUtils.formatCurrDayNoSign() + "_" + record.getRecordid() + "_0000_video";
String fileName = pname + ".mp4";
String ftputl = finalBasepath + "/" + fileName;
boolean r = FTPUtil.uploadFile(ftp, "gstraff/" + finalBasepath, fileName, inputStream);
String ftputl = record.getVideopath() + "/" + fileName;
if (record.getVideopath().indexOf("/") > -1) {
boolean r = FTPUtil.uploadFile(ftp, "gstraff/" + recordBak.getVideopath(), fileName, inputStream);
if (r) {
record.setVideopath(ftputl);
log.info("video:{} upload success:", ftputl);
} else {
log.info("video:{} upload fail:", url);
record.setVideopath("");
}
}
} else {
log.info("video:{} upload fail:", url);
......
package com.hzjt.handler;
import cn.hutool.json.JSONUtil;
import com.hzjt.domain.Ftp;
import com.hzjt.domain.Traffalarmrecord;
import com.hzjt.domain.TransferResult;
import com.hzjt.util.DateUtils;
import com.hzjt.util.FTPUtil;
import com.hzjt.util.JsonUtil;
import com.hzjt.util.ThreadPoolUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -32,63 +34,135 @@ public class FileTransferManager {
* @throws Exception
*/
public static List<TransferResult> transferFile(final Map<String, Object> transferRecord, final Ftp ftp, final String basePath) throws Exception {
Integer ret = 0;
final Long recordid = Long.parseLong(transferRecord.get("recordid").toString());
Long recordid = Long.parseLong(transferRecord.get("recordid").toString());
int count = 0;
for (String key : transferRecord.keySet()) {
if (key.equals("img1path") || key.equals("img2path")
|| key.equals("img3path") || key.equals("img4path")
|| key.equals("img5path") || key.equals("videopath")) {
final String url = transferRecord.get(key).toString();
count++;
completionService.submit(() -> {
TransferResult result = new TransferResult(recordid, key, url, "", false);
Iterator var5 = transferRecord.keySet().iterator();
while (true) {
String key;
do {
if (!var5.hasNext()) {
List<TransferResult> listret = new ArrayList();
String filesuff = "videopath".equals(key) ? ".mp4" : ".jpg";
String pname = DateUtils.formatCurrDayNoSign() + "_" + recordid + "_0000_" + key.replace("path", "");
String fileName = pname + filesuff;
// String ftputl = FTPUtil.getFtpUrl(ftp) + basePath + "/" + fileName;
if (key.equals("videopath")) {
// 视频只存值,先不取值
log.info("videopath");
result.setImgpath(basePath);
result.setUrlfrom(url);
for (int i = 0; i < count; ++i) {
listret.add(completionService.poll(4L, TimeUnit.SECONDS).get());
}
return listret;
}
else {
key = (String) var5.next();
} while (!key.equals("img1path") && !key.equals("img2path") && !key.equals("img3path") && !key.equals("img4path") && !key.equals("img5path") && !key.equals("videopath"));
String url = transferRecord.get(key).toString();
++count;
String finalKey = key;
completionService.submit(() -> {
log.info("recordid:{}", recordid);
TransferResult result = new TransferResult(recordid, finalKey, url, "", false);
String pname = DateUtils.formatCurrDayNoSign() + "_" + recordid + "_0000_" + finalKey.replace("path", "");
String filesuff = "videopath".equals(finalKey) ? ".mp4" : ".jpg";
String fileName = pname + filesuff;
String ftputl = basePath + "/" + fileName;
if ("videopath".equals(finalKey)) {
result.setUrlfrom(url);
result.setImgpath(ftputl);
} else {
try {
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
//延迟连接
HttpURLConnection connection = (HttpURLConnection) (new URL(url)).openConnection();
connection.setReadTimeout(2000);
connection.setConnectTimeout(3000);
connection.setRequestMethod("GET");
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
if (connection.getResponseCode() == 200) {
InputStream inputStream = connection.getInputStream();
boolean r = FTPUtil.uploadFile(ftp, "gstraff/" + basePath, fileName, inputStream);
result.setResult(r);
if (r) {
result.setImgpath(basePath + "/" + fileName);
result.setImgpath(ftputl);
log.info("imgpath or videopath success:{}", ftputl);
} else {
log.info("imgpath or videopath fail:{}", ftputl);
}
// log.info("callable thread:" +result.toString());
} else {
log.error("connection code: " + connection.getResponseCode() + " ," + result.toString());
log.error("imgpath or videopath connection error code:{}", connection.getResponseCode() + " ," + result.toString());
}
} catch (IOException e) {
System.out.println(e.toString());
log.error(e.toString());
} catch (IOException var13) {
log.error("imgpath or videopath error:{}", var13.toString());
}
}
return result;
});
}
}
List<TransferResult> listret = new ArrayList<>();
for (int i = 0; i < count; i++) {
listret.add(completionService.poll(10, TimeUnit.SECONDS).get());
}
return listret;
}
// /**
// * @param transferRecord
// * @param ftp
// * @param basePath
// * @return
// * @throws Exception
// */
// public static List<TransferResult> transferFile(final Map<String, Object> transferRecord, final Ftp ftp, final String basePath) throws Exception {
// Integer ret = 0;
// final Long recordid = Long.parseLong(transferRecord.get("recordid").toString());
// int count = 0;
// for (String key : transferRecord.keySet()) {
// if (key.equals("img1path") || key.equals("img2path")
// || key.equals("img3path") || key.equals("img4path")
// || key.equals("img5path") || key.equals("videopath")) {
// final String url = transferRecord.get(key).toString();
// count++;
// completionService.submit(() -> {
// TransferResult result = new TransferResult(recordid, key, url, "", false);
//
// String filesuff = "videopath".equals(key) ? ".mp4" : ".jpg";
// String pname = DateUtils.formatCurrDayNoSign() + "_" + recordid + "_0000_" + key.replace("path", "");
// String fileName = pname + filesuff;
//// String ftputl = FTPUtil.getFtpUrl(ftp) + basePath + "/" + fileName;
// if (key.equals("videopath")) {
// // 视频只存值,先不取值
// log.info("videopath");
// result.setImgpath(basePath);
// result.setUrlfrom(url);
//
// }
// else {
// try {
// HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
// //延迟连接
// connection.setReadTimeout(2000);
// connection.setConnectTimeout(3000);
// connection.setRequestMethod("GET");
// if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
// InputStream inputStream = connection.getInputStream();
//
// boolean r = FTPUtil.uploadFile(ftp, "gstraff/" + basePath, fileName, inputStream);
// result.setResult(r);
// if (r) {
// result.setImgpath(basePath + "/" + fileName);
// }
//// log.info("callable thread:" +result.toString());
// } else {
// log.error("connection code: " + connection.getResponseCode() + " ," + result.toString());
// }
// } catch (IOException e) {
// System.out.println(e.toString());
// log.error(e.toString());
// }
// }
// return result;
// });
// }
// }
// List<TransferResult> listret = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// listret.add(completionService.poll(3, TimeUnit.SECONDS).get());
// }
// return listret;
// }
public static void fetchUrlsFromRecord(Traffalarmrecord record, Map<String, Object> transferRecord) {
......@@ -178,7 +252,8 @@ public class FileTransferManager {
}
}
public static Traffalarmrecord traffAlarmRecordUrlUpdate(List<TransferResult> results) throws Exception {
public static Traffalarmrecord traffAlarmRecordUrlUpdate( List<TransferResult> resultslist) throws Exception {
List<TransferResult> results= JSONUtil.toList(JSONUtil.parseArray(JSONUtil.toJsonStr(resultslist)),TransferResult.class);
Traffalarmrecord record = new Traffalarmrecord();
for (TransferResult result : results) {
record.setRecordid(result.getRecordid());
......
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