mirror of
https://gitee.com/pan648540858/wvp-GB28181-pro.git
synced 2026-05-25 14:37:53 +08:00
[1078] 完善抓图
This commit is contained in:
parent
8c3e9320fa
commit
cefc87ad47
@ -101,6 +101,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
defaultExcludes.add("/api/device/query/snap/**");
|
defaultExcludes.add("/api/device/query/snap/**");
|
||||||
defaultExcludes.add("/index/hook/abl/**");
|
defaultExcludes.add("/index/hook/abl/**");
|
||||||
defaultExcludes.add("/api/jt1078/playback/download");
|
defaultExcludes.add("/api/jt1078/playback/download");
|
||||||
|
defaultExcludes.add("/api/jt1078/snap");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -26,6 +26,9 @@ public class JTMediaEventInfo {
|
|||||||
@Schema(description = "媒体数据")
|
@Schema(description = "媒体数据")
|
||||||
private byte[] mediaData;
|
private byte[] mediaData;
|
||||||
|
|
||||||
|
@Schema(description = "位置信息汇报")
|
||||||
|
private JTPositionBaseInfo positionBaseInfo;
|
||||||
|
|
||||||
|
|
||||||
public static JTMediaEventInfo decode(ByteBuf buf) {
|
public static JTMediaEventInfo decode(ByteBuf buf) {
|
||||||
JTMediaEventInfo jtMediaEventInfo = new JTMediaEventInfo();
|
JTMediaEventInfo jtMediaEventInfo = new JTMediaEventInfo();
|
||||||
@ -35,6 +38,9 @@ public class JTMediaEventInfo {
|
|||||||
jtMediaEventInfo.setEventCode(buf.readUnsignedByte());
|
jtMediaEventInfo.setEventCode(buf.readUnsignedByte());
|
||||||
jtMediaEventInfo.setChannelId(buf.readUnsignedByte());
|
jtMediaEventInfo.setChannelId(buf.readUnsignedByte());
|
||||||
|
|
||||||
|
ByteBuf byteBuf = buf.readSlice(28);
|
||||||
|
jtMediaEventInfo.setPositionBaseInfo(JTPositionBaseInfo.decode(byteBuf));
|
||||||
|
|
||||||
byte[] bytes = new byte[buf.readableBytes()];
|
byte[] bytes = new byte[buf.readableBytes()];
|
||||||
buf.readBytes(bytes);
|
buf.readBytes(bytes);
|
||||||
jtMediaEventInfo.setMediaData(bytes);
|
jtMediaEventInfo.setMediaData(bytes);
|
||||||
|
|||||||
@ -871,15 +871,15 @@ public class JT1078Controller {
|
|||||||
@Operation(summary = "JT-抓图", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
@Operation(summary = "JT-抓图", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||||
@Parameter(name = "phoneNumber", description = "设备编号", required = true)
|
@Parameter(name = "phoneNumber", description = "设备编号", required = true)
|
||||||
@Parameter(name = "channelId", description = "通道编号", required = true)
|
@Parameter(name = "channelId", description = "通道编号", required = true)
|
||||||
@PostMapping("/snap")
|
@GetMapping("/snap")
|
||||||
public void snap(HttpServletResponse response, String phoneNumber, Integer channelId){
|
public void snap(HttpServletResponse response, String phoneNumber, Integer channelId){
|
||||||
|
|
||||||
log.info("[JT-抓图] 设备编号: {}, 通道编号: {}", phoneNumber, channelId );
|
log.info("[JT-抓图] 设备编号: {}, 通道编号: {}", phoneNumber, channelId );
|
||||||
Assert.notNull(channelId, "缺少通道编号");
|
Assert.notNull(channelId, "缺少通道编号");
|
||||||
try {
|
try {
|
||||||
ServletOutputStream outputStream = response.getOutputStream();
|
ServletOutputStream outputStream = response.getOutputStream();
|
||||||
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
response.setContentType(MediaType.IMAGE_JPEG_VALUE);
|
||||||
response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(phoneNumber + "_" + channelId + ".jpg", "UTF-8"));
|
// response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(phoneNumber + "_" + channelId + ".jpg", "UTF-8"));
|
||||||
service.snap(phoneNumber, channelId, outputStream);
|
service.snap(phoneNumber, channelId, outputStream);
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), e.getMessage());
|
throw new ControllerException(ErrorCode.ERROR100.getCode(), e.getMessage());
|
||||||
|
|||||||
@ -27,17 +27,9 @@ public class J0801 extends Re {
|
|||||||
|
|
||||||
private final static Logger log = LoggerFactory.getLogger(J0801.class);
|
private final static Logger log = LoggerFactory.getLogger(J0801.class);
|
||||||
|
|
||||||
private JTPositionBaseInfo positionBaseInfo;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Rs decode0(ByteBuf buf, Header header, Session session) {
|
protected Rs decode0(ByteBuf buf, Header header, Session session) {
|
||||||
JTMediaEventInfo mediaEventInfo = JTMediaEventInfo.decode(buf);
|
JTMediaEventInfo mediaEventInfo = JTMediaEventInfo.decode(buf);
|
||||||
ByteBuf byteBuf = buf.readSlice(28);
|
|
||||||
positionBaseInfo = JTPositionBaseInfo.decode(byteBuf);
|
|
||||||
File mediaEventFile = new File("mediaEvent");
|
|
||||||
if (!mediaEventFile.exists()) {
|
|
||||||
mediaEventFile.mkdirs();
|
|
||||||
}
|
|
||||||
log.info("[JT-多媒体数据上传]: {}", mediaEventInfo);
|
log.info("[JT-多媒体数据上传]: {}", mediaEventInfo);
|
||||||
SessionManager.INSTANCE.response(header.getPhoneNumber(), "0801", null, mediaEventInfo);
|
SessionManager.INSTANCE.response(header.getPhoneNumber(), "0801", null, mediaEventInfo);
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@ -761,6 +761,7 @@ public class jt1078ServiceImpl implements Ijt1078Service {
|
|||||||
log.info("[JT-抓图] 图片上传完成,抓图编号: {}, 设备编号: {}, 通道编号: {}", ids.get(0), phoneNumber, channelId);
|
log.info("[JT-抓图] 图片上传完成,抓图编号: {}, 设备编号: {}, 通道编号: {}", ids.get(0), phoneNumber, channelId);
|
||||||
try {
|
try {
|
||||||
outputStream.write(mediaEventInfo.getMediaData());
|
outputStream.write(mediaEventInfo.getMediaData());
|
||||||
|
outputStream.flush();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.info("[JT-抓图] 数据写入异常,抓图编号: {}, 设备编号: {}, 通道编号: {}", ids.get(0), phoneNumber, channelId, e);
|
log.info("[JT-抓图] 数据写入异常,抓图编号: {}, 设备编号: {}, 通道编号: {}", ids.get(0), phoneNumber, channelId, e);
|
||||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "数据写入异常");
|
throw new ControllerException(ErrorCode.ERROR100.getCode(), "数据写入异常");
|
||||||
|
|||||||
@ -116,22 +116,19 @@
|
|||||||
</div>
|
</div>
|
||||||
<devicePlayer ref="devicePlayer" />
|
<devicePlayer ref="devicePlayer" />
|
||||||
<channelEdit v-if="jtChannel" ref="channelEdit" :jt-channel="jtChannel" :close-edit="closeEdit" />
|
<channelEdit v-if="jtChannel" ref="channelEdit" :jt-channel="jtChannel" :close-edit="closeEdit" />
|
||||||
<shooting ref="shooting" />
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import devicePlayer from '../jtDevicePlayer.vue'
|
import devicePlayer from '../jtDevicePlayer.vue'
|
||||||
import channelEdit from './edit.vue'
|
import channelEdit from './edit.vue'
|
||||||
import shooting from './shooting.vue'
|
import dayjs from 'dayjs'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'ChannelList',
|
name: 'ChannelList',
|
||||||
components: {
|
components: {
|
||||||
channelEdit,
|
channelEdit,
|
||||||
devicePlayer,
|
devicePlayer
|
||||||
shooting
|
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
deviceId: {
|
deviceId: {
|
||||||
@ -325,9 +322,35 @@ export default {
|
|||||||
},
|
},
|
||||||
// 编辑
|
// 编辑
|
||||||
shooting(row) {
|
shooting(row) {
|
||||||
const baseUrl = window.baseUrl
|
// 文件下载地址
|
||||||
let dev = (process.env.NODE_ENV === 'development' ? process.env.VUE_APP_BASE_API : baseUrl)
|
const baseUrl = window.baseUrl ? window.baseUrl : ''
|
||||||
window.open(`${dev}/api/jt1078/snap?phoneNumber=${this.deviceId}&channelId=${row.channelId}`)
|
const fileUrl = ((process.env.NODE_ENV === 'development') ? process.env.VUE_APP_BASE_API : baseUrl) + `/api/jt1078/snap?phoneNumber=${this.device.phoneNumber}&channelId=${row.channelId}`
|
||||||
|
|
||||||
|
// 设置请求头
|
||||||
|
const headers = new Headers()
|
||||||
|
headers.append('access-token', this.$store.getters.token) // 设置授权头,替换YourAccessToken为实际的访问令牌
|
||||||
|
// 发起 请求
|
||||||
|
fetch(fileUrl, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: headers
|
||||||
|
})
|
||||||
|
.then(response => response.blob())
|
||||||
|
.then(blob => {
|
||||||
|
console.log(blob)
|
||||||
|
// 创建一个虚拟的链接元素,模拟点击下载
|
||||||
|
const link = document.createElement('a')
|
||||||
|
link.href = window.URL.createObjectURL(blob)
|
||||||
|
link.download = `${this.device.phoneNumber}-${row.channelId}-${dayjs().format('YYYYMMDDHHmmss')}.jpg` // 设置下载文件名,替换filename.ext为实际的文件名和扩展名
|
||||||
|
document.body.appendChild(link)
|
||||||
|
|
||||||
|
// 模拟点击
|
||||||
|
link.click()
|
||||||
|
|
||||||
|
// 移除虚拟链接元素
|
||||||
|
document.body.removeChild(link)
|
||||||
|
this.$message.success('已申请截图', { closed: true })
|
||||||
|
})
|
||||||
|
.catch(error => console.error('下载失败:', error))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user