[1078] 完善抓图

This commit is contained in:
lin
2025-07-11 21:41:50 +08:00
parent 8c3e9320fa
commit cefc87ad47
6 changed files with 42 additions and 19 deletions

View File

@@ -101,6 +101,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
defaultExcludes.add("/api/device/query/snap/**");
defaultExcludes.add("/index/hook/abl/**");
defaultExcludes.add("/api/jt1078/playback/download");
defaultExcludes.add("/api/jt1078/snap");

View File

@@ -26,6 +26,9 @@ public class JTMediaEventInfo {
@Schema(description = "媒体数据")
private byte[] mediaData;
@Schema(description = "位置信息汇报")
private JTPositionBaseInfo positionBaseInfo;
public static JTMediaEventInfo decode(ByteBuf buf) {
JTMediaEventInfo jtMediaEventInfo = new JTMediaEventInfo();
@@ -35,6 +38,9 @@ public class JTMediaEventInfo {
jtMediaEventInfo.setEventCode(buf.readUnsignedByte());
jtMediaEventInfo.setChannelId(buf.readUnsignedByte());
ByteBuf byteBuf = buf.readSlice(28);
jtMediaEventInfo.setPositionBaseInfo(JTPositionBaseInfo.decode(byteBuf));
byte[] bytes = new byte[buf.readableBytes()];
buf.readBytes(bytes);
jtMediaEventInfo.setMediaData(bytes);

View File

@@ -871,15 +871,15 @@ public class JT1078Controller {
@Operation(summary = "JT-抓图", security = @SecurityRequirement(name = JwtUtils.HEADER))
@Parameter(name = "phoneNumber", description = "设备编号", required = true)
@Parameter(name = "channelId", description = "通道编号", required = true)
@PostMapping("/snap")
@GetMapping("/snap")
public void snap(HttpServletResponse response, String phoneNumber, Integer channelId){
log.info("[JT-抓图] 设备编号: {}, 通道编号: {}", phoneNumber, channelId );
Assert.notNull(channelId, "缺少通道编号");
try {
ServletOutputStream outputStream = response.getOutputStream();
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(phoneNumber + "_" + channelId + ".jpg", "UTF-8"));
response.setContentType(MediaType.IMAGE_JPEG_VALUE);
// response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(phoneNumber + "_" + channelId + ".jpg", "UTF-8"));
service.snap(phoneNumber, channelId, outputStream);
}catch (Exception e) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), e.getMessage());

View File

@@ -27,17 +27,9 @@ public class J0801 extends Re {
private final static Logger log = LoggerFactory.getLogger(J0801.class);
private JTPositionBaseInfo positionBaseInfo;
@Override
protected Rs decode0(ByteBuf buf, Header header, Session session) {
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);
SessionManager.INSTANCE.response(header.getPhoneNumber(), "0801", null, mediaEventInfo);
return null;

View File

@@ -761,6 +761,7 @@ public class jt1078ServiceImpl implements Ijt1078Service {
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(), "数据写入异常");