随行模式修改

merge-requests/5/merge
Your Name 4 years ago
parent 7839377c92
commit edc5cffb66

@ -26,7 +26,7 @@ public class PathUtil {
public static String createFileName(String fileType,Integer cameraId) {
LocalDateTime now = LocalDateTime.now();
String time = now.format(DateTimeFormatter.ofPattern("yyyy/MM/dd")) + "/camera"+cameraId;
String time = now.format(DateTimeFormatter.ofPattern("yyyy/MM/dd")) + "/"+cameraId;
return time + "/" + now.format(DateTimeFormatter.ofPattern("HHmmss-"))+getRandomString(10) + "."+fileType;
}

@ -1,12 +1,16 @@
package com.zhehekeji.web.controller;
import com.zhehekeji.common.util.PathUtil;
import com.zhehekeji.core.pojo.Result;
import com.zhehekeji.core.util.Assert;
import com.zhehekeji.web.config.ConfigProperties;
import com.zhehekeji.web.entity.Camera;
import com.zhehekeji.web.lib.*;
import com.zhehekeji.web.lib.hik.HCNetSDK;
import com.zhehekeji.web.lib.joyware.NetSDKLib;
import com.zhehekeji.web.mapper.CameraMapper;
import com.zhehekeji.web.service.CameraService;
import com.zhehekeji.web.service.PlcService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
@ -297,11 +301,20 @@ public class CameraControlController {
return Result.success();
}
@Resource
private ConfigProperties configProperties;
@Resource
private PlcService plcService;
@PostMapping("/mp4/{id}/delay")
@ApiOperation(value = "录像")
public Result MP4delay(@PathVariable Integer id) {
checkLogin(id);
TaskDelayExecutor.addMp4DelayTask(id,"D:\\work\\"+LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"))+".mp4",LocalDateTime.now().minusMinutes(2),LocalDateTime.now().minusSeconds(7),12000L);
//checkLogin(id);
plcService.cameraVideo(1,LocalDateTime.now().minusSeconds(id),LocalDateTime.now().plusSeconds(3));
plcService.cameraVideo(2,LocalDateTime.now().minusSeconds(id),LocalDateTime.now().plusSeconds(3));
/*String path = PathUtil.createFileName("mp4",id);
String realPath = configProperties.getSavePath().getMp4Path() + path;
TaskDelayExecutor.addMp4DelayTask(id,realPath,LocalDateTime.now().minusMinutes(2),LocalDateTime.now().minusSeconds(7),12000L);*/
//cameraControlModule.downloadMp4(id,"D:\\work\\"+LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"))+".mp4", LocalDateTime.now().minusMinutes(10),LocalDateTime.now().minusMinutes(8));
return Result.success();
}

@ -50,14 +50,14 @@ public class OrderController {
@ApiOperation("工单开始信号")
@PostMapping("/start")
public Result orderStart(@ApiParam("工单号") @RequestBody PlcCmdInfo plcCmdInfo){
plcService.orderStart(plcCmdInfo);
return Result.success();
}
@ApiOperation("工单结束信号")
@GetMapping("/stop")
public Result orderStop(@ApiParam("工单号") @RequestParam String orderNum,@ApiParam("plc")@RequestParam String plcId){
PlcCmdInfo plcCmdInfo = new PlcCmdInfo();
@PostMapping("/stop")
public Result orderStop(@ApiParam("工单号") @RequestBody PlcCmdInfo plcCmdInfo){
plcService.orderStop(plcCmdInfo);
return Result.success();
}

@ -38,6 +38,7 @@ public class TaskDelayExecutor {
if(cameraDelayTask != null){
if(cameraDelayTask.getType() == 0){
cameraControlModule.downloadMp4(cameraDelayTask.getCameraId(), cameraDelayTask.getPath(), cameraDelayTask.getStartTime(), cameraDelayTask.getEndTime());
}else if(cameraDelayTask.getType() == 1){
cameraControlModule.pic(cameraDelayTask.getCameraId(),0, cameraDelayTask.getPath());

@ -1,5 +1,6 @@
package com.zhehekeji.web.lib.hik;
import com.sun.jna.NativeLong;
import com.sun.jna.ptr.IntByReference;
import com.zhehekeji.common.util.PathUtil;
import com.zhehekeji.core.util.Assert;
@ -10,7 +11,9 @@ import lombok.extern.slf4j.Slf4j;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
@ -254,42 +257,52 @@ public class HikCameraControlModuleImpl implements CameraControlModule {
}
public void downloadMp4(Integer cameraId, String path, LocalDateTime start, LocalDateTime end) {
PathUtil.checkDirc(path);
Duration duration = Duration.between(start, end);
Long seconds = duration.getSeconds();
long timeDiff = 90 - seconds;
if(timeDiff > 0){
//海康录像时间短会下载失败
start = start.minusSeconds(timeDiff);
}
HCNetSDK.NET_DVR_TIME startTime = new HCNetSDK.NET_DVR_TIME();
startTime.setTime(start.getYear(), start.getMonthValue(), start.getDayOfMonth(), start.getHour(), start.getMinute(), start.getSecond());
HCNetSDK.NET_DVR_TIME endTime = new HCNetSDK.NET_DVR_TIME();
endTime.setTime(end.getYear(), end.getMonthValue(), end.getDayOfMonth(), end.getHour(), end.getMinute(), end.getSecond());
// HCNetSDK.NET_DVR_PLAYCOND struDownloadCond = new HCNetSDK.NET_DVR_PLAYCOND();
// struDownloadCond.dwChannel = 1;
// struDownloadCond.struStartTime = startTime;
// struDownloadCond.struStopTime = endTime;
// struDownloadCond.write();
HCNetSDK.NET_DVR_PLAYCOND struDownloadCond = new HCNetSDK.NET_DVR_PLAYCOND();
struDownloadCond.dwChannel = 1;
struDownloadCond.struStartTime = startTime;
struDownloadCond.struStopTime = endTime;
struDownloadCond.write();
log.info("start download mp4 path:{} ,cameraId:{}",path,cameraId);
log.info("start download mp4 path:{} ,cameraId:{},start_time{}end_time:{}",path,cameraId,startTime.toStringTime(),endTime.toStringTime());
int lUserID = CameraConnMap.getConnId(cameraId).intValue();
int result = HikLoginModuleImpl.hcNetsdk.NET_DVR_GetFileByTime_V40(lUserID,path.getBytes(StandardCharsets.UTF_8),struDownloadCond);
if (result < 0) {
log.error("downloadMp4 error code:{},cameraId:{}", HikLoginModuleImpl.hcNetsdk.NET_DVR_GetLastError(),cameraId);
//int result = HikLoginModuleImpl.hcNetsdk.NET_DVR_GetFileByTime_V40(lUserID,path.getBytes(),struDownloadCond);
int result = HikLoginModuleImpl.hcNetsdk.NET_DVR_GetFileByTime(lUserID, 1, startTime, endTime, path);
if (result == -1) {
log.error("downloadMp4 error code:{},cameraId:{},path:{}", HikLoginModuleImpl.hcNetsdk.NET_DVR_GetLastError(),cameraId,path);
} else {
Boolean ok = HikLoginModuleImpl.hcNetsdk.NET_DVR_PlayBackControl(result, HikLoginModuleImpl.hcNetsdk.NET_DVR_PLAYSTART,0,null);
if(!ok){
HikLoginModuleImpl.hcNetsdk.NET_DVR_PlayBackControl(result, HikLoginModuleImpl.hcNetsdk.NET_DVR_PLAYSTART,0,null);
/*if(!ok){
log.error("downloadMp4 error code:{},cameraId:{}", HikLoginModuleImpl.hcNetsdk.NET_DVR_GetLastError(),cameraId);
}
}*/
Timer downloadtimer = new Timer();
downloadtimer.schedule(new DownloadTask(result,downloadtimer,path), 0, 500);
downloadtimer.schedule(new DownloadTask(result,downloadtimer,path,cameraId), 0, 5000);
}
}
class DownloadTask extends java.util.TimerTask {
private Integer handler;
private Timer downloadtimer;
private Integer cameraId;
private String path;
public DownloadTask(Integer handler,Timer downloadtimer,String path){
public DownloadTask(Integer handler,Timer downloadtimer,String path,int cameraId){
this.handler = handler;
this.cameraId = cameraId;
this.downloadtimer = downloadtimer;
this.path = path;
}
@ -301,21 +314,23 @@ public class HikCameraControlModuleImpl implements CameraControlModule {
HikLoginModuleImpl.hcNetsdk.NET_DVR_PlayBackControl(handler, HCNetSDK.NET_DVR_PLAYGETPOS, 0, nPos);
if (nPos.getValue() > 100)
{
log.error("download mp4 error:{},cameraId:{},path:{}",HikLoginModuleImpl.hcNetsdk.NET_DVR_GetLastError(),cameraId,path);
HikLoginModuleImpl.hcNetsdk.NET_DVR_StopGetFile(handler);
downloadtimer.cancel();
log.error("download mp4 error");
}
if (nPos.getValue() == 100)
{
HikLoginModuleImpl.hcNetsdk.NET_DVR_StopGetFile(handler);
downloadtimer.cancel();
HikLoginModuleImpl.hcNetsdk.NET_DVR_StopGetFile(handler);
//ffmpeg转码
log.info("download over");
String ffmpegFile = path+"ffmpeg.mp4";
log.info("download over,cameraId:{}",cameraId);
/*String ffmpegFile = path+"ffmpeg.mp4";
convetor(path,ffmpegFile);
PathUtil.deleteFile(path);
File file = new File(ffmpegFile);
file.renameTo(new File(path));
file.renameTo(new File(path));*/
}else {
log.debug("cameraId:{},progress:{}",cameraId,nPos.getValue());
}
}
}

@ -15,6 +15,7 @@ import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
@ -145,12 +146,13 @@ public class PlcService {
update.setLeftRight2(plcCmdInfo.getLeftRight2());
update.setColumn2(plcCmdInfo.getColumn2());
update.setRow2(plcCmdInfo.getRow2());
if (street.getCamera1Id() != null) {
String path = cameraVideo(street.getCamera1Id(),order.getStartTime(),endTime.plusSeconds(3));
String path = cameraVideo(street.getCamera1Id(),order.getStartTime(),endTime.plusSeconds(5));
update.setVideoPath1(path);
}
if (street.getCamera2Id() != null) {
String path = cameraVideo(street.getCamera2Id(),order.getStartTime(),endTime.plusSeconds(3));
String path = cameraVideo(street.getCamera2Id(),order.getStartTime(),endTime.plusSeconds(5));
update.setVideoPath2(path);
}
orderMapper.updateById(update);
@ -173,8 +175,14 @@ public class PlcService {
public String cameraVideo(Integer cameraId, LocalDateTime startTime, LocalDateTime endTime) {
String path = PathUtil.createFileName("mp4",cameraId);
String realPath = configProperties.getSavePath().getMp4Path() + path;
TaskDelayExecutor.addMp4DelayTask(cameraId,realPath,startTime,endTime,12000L);
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
String realPath = configProperties.getSavePath().getMp4Path() + path;
TaskDelayExecutor.addMp4DelayTask(cameraId,realPath,startTime,endTime,12000L);
}
});
thread.start();
//cameraControlModule.downloadMp4(cameraId,realPath,startTime,endTime);
return path;
}

@ -13,7 +13,6 @@ import com.zhehekeji.web.pojo.street.StreetSearch;
import com.zhehekeji.web.pojo.street.StreetType;
import com.zhehekeji.web.pojo.street.StreetVO;
import com.zhehekeji.web.service.robotic.NettyClient;
import jdk.internal.org.objectweb.asm.Handle;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.cache.annotation.CacheEvict;

@ -64,6 +64,9 @@ public class KsecDecoder extends DelimiterBasedFrameDecoder {
} else if (Cmd.B2.name().equals(cmdName)) {
plcService.gyrateCamera(plcCmdInfo,Cmd.C5.name());
plcService.orderStop(plcCmdInfo);
}
} else if (Cmd.C.name().equals(ksecInfo.getType())) {
tcpLogger.info("info:{}",body);
@ -115,4 +118,17 @@ public class KsecDecoder extends DelimiterBasedFrameDecoder {
in.release();
return null;
}
public class StopThread extends Thread {
private PlcCmdInfo plcCmdInfo;
public StopThread(PlcCmdInfo plcCmdInfo){
this.plcCmdInfo = plcCmdInfo;
}
@Override
public void run() {
plcService.orderStop(plcCmdInfo);
}
}
}

@ -30,7 +30,7 @@ cameraConfig:
cameraType: 1
cameraPassword: a1234567
cameraUser: admin
cameraPort: 37777
cameraPort: 8000
videoServer: 127.0.0.1:8083
#相机抓图延迟 毫秒,这个延迟是等待球机球机转动到位,然后拍照的
delayCaptureTime: 3500
@ -38,7 +38,7 @@ cameraConfig:
# -----图片 mp4下载地址
savePath:
mediaPath: d:\\data\media\
mp4Path: d:\data\mp4\
mp4Path: d://data/mp4/
# ------------服务端类型 0TCP(罗伯泰克) 1:KSEC(JSON)(昆船)
serverMode: 1
ksec:

Loading…
Cancel
Save