调整抓拍代码
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
package com.genersoft.iot.vmp.jt1078.controller;
|
||||
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.conf.ftpServer.FtpSetting;
|
||||
import com.genersoft.iot.vmp.conf.UserSetting;
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
import com.genersoft.iot.vmp.conf.ftpServer.FtpSetting;
|
||||
import com.genersoft.iot.vmp.conf.security.JwtUtils;
|
||||
import com.genersoft.iot.vmp.jt1078.bean.*;
|
||||
import com.genersoft.iot.vmp.jt1078.controller.bean.*;
|
||||
@@ -19,17 +19,9 @@ import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import org.apache.commons.io.monitor.FileAlterationListenerAdaptor;
|
||||
import org.apache.commons.io.monitor.FileAlterationMonitor;
|
||||
import org.apache.commons.io.monitor.FileAlterationObserver;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -39,17 +31,11 @@ import javax.annotation.Resource;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@@ -840,7 +826,9 @@ public class JT1078Controller {
|
||||
ServletOutputStream outputStream = response.getOutputStream();
|
||||
response.setContentType(MediaType.IMAGE_JPEG_VALUE);
|
||||
// response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(phoneNumber + "_" + channelId + ".jpg", "UTF-8"));
|
||||
service.snap(phoneNumber, channelId, outputStream);
|
||||
byte[] data = service.snap(phoneNumber, channelId);
|
||||
outputStream.write(data);
|
||||
outputStream.flush();
|
||||
}catch (Exception e) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), e.getMessage());
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.genersoft.iot.vmp.jt1078.proc.request;
|
||||
|
||||
import com.genersoft.iot.vmp.jt1078.annotation.MsgId;
|
||||
import com.genersoft.iot.vmp.jt1078.bean.JTMediaEventInfo;
|
||||
import com.genersoft.iot.vmp.jt1078.bean.JTPositionBaseInfo;
|
||||
import com.genersoft.iot.vmp.jt1078.proc.Header;
|
||||
import com.genersoft.iot.vmp.jt1078.proc.response.J8001;
|
||||
import com.genersoft.iot.vmp.jt1078.proc.response.Rs;
|
||||
@@ -11,16 +10,8 @@ import com.genersoft.iot.vmp.jt1078.session.Session;
|
||||
import com.genersoft.iot.vmp.jt1078.session.SessionManager;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 多媒体数据上传
|
||||
*/
|
||||
@@ -34,7 +25,7 @@ public class J0801 extends Re {
|
||||
log.info("[JT-多媒体数据上传]: {}", mediaEventInfo);
|
||||
// try {
|
||||
// if (mediaEventInfo.getMediaData() != null) {
|
||||
// File file = new File("/home/lin/source.jpg");
|
||||
// File file = new File("./source.jpg");
|
||||
// if (file.exists()) {
|
||||
// file.delete();
|
||||
// }
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package com.genersoft.iot.vmp.jt1078.service;
|
||||
|
||||
import com.genersoft.iot.vmp.common.CommonCallback;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.jt1078.bean.*;
|
||||
import com.genersoft.iot.vmp.jt1078.proc.request.J1205;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
@@ -124,7 +122,7 @@ public interface Ijt1078Service {
|
||||
|
||||
void recordDownload(String filePath, ServletOutputStream outputStream);
|
||||
|
||||
void snap(String phoneNumber, int channelId, ServletOutputStream outputStream);
|
||||
byte[] snap(String phoneNumber, int channelId);
|
||||
|
||||
void uploadOneMedia(String phoneNumber, Long mediaId, ServletOutputStream outputStream, boolean delete);
|
||||
|
||||
|
||||
@@ -860,7 +860,7 @@ public class jt1078ServiceImpl implements Ijt1078Service {
|
||||
|
||||
|
||||
@Override
|
||||
public void snap(String phoneNumber, int channelId, ServletOutputStream outputStream) {
|
||||
public byte[] snap(String phoneNumber, int channelId) {
|
||||
J8801 j8801 = new J8801();
|
||||
|
||||
// 设置抓图默认参数
|
||||
@@ -894,13 +894,7 @@ public class jt1078ServiceImpl implements Ijt1078Service {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), ErrorCode.ERROR100.getMsg());
|
||||
}
|
||||
log.info("[JT-抓图] 图片上传完成,抓图编号: {}, 设备编号: {}, 通道编号: {}", ids.get(0), phoneNumber, channelId);
|
||||
try {
|
||||
outputStream.write(mediaEventInfo.getMediaData());
|
||||
outputStream.flush();
|
||||
} catch (IOException e) {
|
||||
log.info("[JT-抓图] 数据写入异常,抓图编号: {}, 设备编号: {}, 通道编号: {}", ids.get(0), phoneNumber, channelId, e);
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "数据写入异常");
|
||||
}
|
||||
return mediaEventInfo.getMediaData();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -333,6 +333,12 @@ export default {
|
||||
// 设置请求头
|
||||
const headers = new Headers()
|
||||
headers.append('access-token', this.$store.getters.token) // 设置授权头,替换YourAccessToken为实际的访问令牌
|
||||
|
||||
let timer = setTimeout(() => {
|
||||
this.$message.error('等待截图超时', { closed: true })
|
||||
controller.abort('timeout')
|
||||
}, 15000)
|
||||
|
||||
// 发起 请求
|
||||
fetch(fileUrl, {
|
||||
method: 'GET',
|
||||
@@ -341,7 +347,7 @@ export default {
|
||||
})
|
||||
.then(response => response.blob())
|
||||
.then(blob => {
|
||||
console.log(blob)
|
||||
window.clearTimeout(timer)
|
||||
// 创建一个虚拟的链接元素,模拟点击下载
|
||||
const link = document.createElement('a')
|
||||
link.href = window.URL.createObjectURL(blob)
|
||||
@@ -352,12 +358,10 @@ export default {
|
||||
// 移除虚拟链接元素
|
||||
document.body.removeChild(link)
|
||||
})
|
||||
.catch(error => console.error('下载失败:', error))
|
||||
|
||||
setTimeout(() => {
|
||||
this.$message.error('等待截图超时', { closed: true })
|
||||
controller.abort('timeout')
|
||||
}, 15000)
|
||||
.catch(error => {
|
||||
window.clearTimeout(timer)
|
||||
console.error('下载失败:', error)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user