From e9562d7d31d65237db06b35302c3713752c6fdfb Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Sat, 18 May 2024 07:29:15 +0800 Subject: [PATCH] =?UTF-8?q?1078-=E5=AD=98=E5=82=A8=E5=A4=9A=E5=AA=92?= =?UTF-8?q?=E4=BD=93=E6=95=B0=E6=8D=AE=E4=B8=8A=E4=BC=A0=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jt1078/bean/JTQueryMediaDataCommand.java | 15 ++++ .../iot/vmp/jt1078/cmd/JT1078Template.java | 12 +++ .../jt1078/controller/JT1078Controller.java | 14 ++++ .../iot/vmp/jt1078/proc/request/J0801.java | 9 +++ .../iot/vmp/jt1078/proc/response/J8803.java | 27 +++++++ .../iot/vmp/jt1078/proc/response/J8804.java | 75 +++++++++++++++++++ .../vmp/jt1078/service/Ijt1078Service.java | 3 + .../service/impl/jt1078ServiceImpl.java | 7 ++ 8 files changed, 162 insertions(+) create mode 100644 src/main/java/com/genersoft/iot/vmp/jt1078/proc/response/J8803.java create mode 100644 src/main/java/com/genersoft/iot/vmp/jt1078/proc/response/J8804.java diff --git a/src/main/java/com/genersoft/iot/vmp/jt1078/bean/JTQueryMediaDataCommand.java b/src/main/java/com/genersoft/iot/vmp/jt1078/bean/JTQueryMediaDataCommand.java index f11a282a1..9d6cbcb02 100644 --- a/src/main/java/com/genersoft/iot/vmp/jt1078/bean/JTQueryMediaDataCommand.java +++ b/src/main/java/com/genersoft/iot/vmp/jt1078/bean/JTQueryMediaDataCommand.java @@ -24,6 +24,9 @@ public class JTQueryMediaDataCommand { @Schema(description = "结束时间") private String endTime; + @Schema(description = "删除标志, 0:保留;1:删除, 存储多媒体数据上传命令中使用") + private Integer delete; + public ByteBuf decode() { ByteBuf byteBuf = Unpooled.buffer(); @@ -32,6 +35,9 @@ public class JTQueryMediaDataCommand { byteBuf.writeByte(event); byteBuf.writeBytes(BCDUtil.strToBcd(DateUtil.yyyy_MM_dd_HH_mm_ssTo1078(startTime))); byteBuf.writeBytes(BCDUtil.strToBcd(DateUtil.yyyy_MM_dd_HH_mm_ssTo1078(endTime))); + if (delete != null) { + byteBuf.writeByte(delete); + } return byteBuf; } @@ -75,6 +81,14 @@ public class JTQueryMediaDataCommand { this.endTime = endTime; } + public Integer getDelete() { + return delete; + } + + public void setDelete(Integer delete) { + this.delete = delete; + } + @Override public String toString() { return "JTQueryMediaDataCommand{" + @@ -83,6 +97,7 @@ public class JTQueryMediaDataCommand { ", event=" + event + ", startTime='" + startTime + '\'' + ", endTime='" + endTime + '\'' + + ", delete='" + delete + '\'' + '}'; } } diff --git a/src/main/java/com/genersoft/iot/vmp/jt1078/cmd/JT1078Template.java b/src/main/java/com/genersoft/iot/vmp/jt1078/cmd/JT1078Template.java index ef111071c..af6f53109 100644 --- a/src/main/java/com/genersoft/iot/vmp/jt1078/cmd/JT1078Template.java +++ b/src/main/java/com/genersoft/iot/vmp/jt1078/cmd/JT1078Template.java @@ -42,6 +42,7 @@ public class JT1078Template { private static final String H8702 = "8702"; private static final String H8801 = "8801"; private static final String H8802 = "8802"; + private static final String H8803 = "8803"; private static final String H9101 = "9101"; private static final String H9102 = "9102"; private static final String H9201 = "9201"; @@ -593,4 +594,15 @@ public class JT1078Template { .build(); return SessionManager.INSTANCE.request(cmd, timeOut); } + + public Object updateMediaData(String devId, J8803 j8803, int timeOut) { + Cmd cmd = new Cmd.Builder() + .setDevId(devId) + .setPackageNo(randomInt()) + .setMsgId(H8803) + .setRespId(H0802) + .setRs(j8803) + .build(); + return SessionManager.INSTANCE.request(cmd, timeOut); + } } diff --git a/src/main/java/com/genersoft/iot/vmp/jt1078/controller/JT1078Controller.java b/src/main/java/com/genersoft/iot/vmp/jt1078/controller/JT1078Controller.java index 4f6853890..5abdaa7d3 100644 --- a/src/main/java/com/genersoft/iot/vmp/jt1078/controller/JT1078Controller.java +++ b/src/main/java/com/genersoft/iot/vmp/jt1078/controller/JT1078Controller.java @@ -777,5 +777,19 @@ public class JT1078Controller { return WVPResult.fail(ErrorCode.ERROR100); } } + + @Operation(summary = "1078-存储多媒体数据上传命令", security = @SecurityRequirement(name = JwtUtils.HEADER)) + @Parameter(name = "param", description = "存储多媒体数据参数", required = true) + @PostMapping("/media-data-update") + public WVPResult> updateMediaData(@RequestBody QueryMediaDataParam param){ + + logger.info("[1078-存储多媒体数据上传命令] param: {}", param ); + List ids = service.updateMediaData(param.getDeviceId(), param.getQueryMediaDataCommand()); + if (ids != null) { + return WVPResult.success(ids); + }else { + return WVPResult.fail(ErrorCode.ERROR100); + } + } } diff --git a/src/main/java/com/genersoft/iot/vmp/jt1078/proc/request/J0801.java b/src/main/java/com/genersoft/iot/vmp/jt1078/proc/request/J0801.java index d9d4a8f4e..70db51ec5 100644 --- a/src/main/java/com/genersoft/iot/vmp/jt1078/proc/request/J0801.java +++ b/src/main/java/com/genersoft/iot/vmp/jt1078/proc/request/J0801.java @@ -13,6 +13,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.ApplicationEvent; +import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; @@ -35,6 +36,10 @@ public class J0801 extends Re { ByteBuf byteBuf = buf.readSlice(28); positionBaseInfo = JTPositionBaseInfo.decode(byteBuf); String fileName = "mediaEvent/" + mediaEventInfo.getId() + "."; + File mediaEventFile = new File("mediaEvent"); + if (!mediaEventFile.exists()) { + mediaEventFile.mkdirs(); + } switch (mediaEventInfo.getCode()){ case 0: fileName += "jpg"; @@ -54,6 +59,10 @@ public class J0801 extends Re { } try { ByteBuf dst = buf.readBytes(buf.readableBytes()); + File file = new File(fileName); + if (!file.exists()) { + file.createNewFile(); + } FileOutputStream fileOutputStream = new FileOutputStream(fileName); fileOutputStream.write(dst.array()); fileOutputStream.close(); diff --git a/src/main/java/com/genersoft/iot/vmp/jt1078/proc/response/J8803.java b/src/main/java/com/genersoft/iot/vmp/jt1078/proc/response/J8803.java new file mode 100644 index 000000000..575222941 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/jt1078/proc/response/J8803.java @@ -0,0 +1,27 @@ +package com.genersoft.iot.vmp.jt1078.proc.response; + +import com.genersoft.iot.vmp.jt1078.annotation.MsgId; +import com.genersoft.iot.vmp.jt1078.bean.JTQueryMediaDataCommand; +import io.netty.buffer.ByteBuf; + +/** + * 存储多媒体数据上传命令 + */ +@MsgId(id = "8803") +public class J8803 extends Rs { + + JTQueryMediaDataCommand command; + + @Override + public ByteBuf encode() { + return command.decode(); + } + + public JTQueryMediaDataCommand getCommand() { + return command; + } + + public void setCommand(JTQueryMediaDataCommand command) { + this.command = command; + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/jt1078/proc/response/J8804.java b/src/main/java/com/genersoft/iot/vmp/jt1078/proc/response/J8804.java new file mode 100644 index 000000000..8e71804b2 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/jt1078/proc/response/J8804.java @@ -0,0 +1,75 @@ +package com.genersoft.iot.vmp.jt1078.proc.response; + +import com.genersoft.iot.vmp.jt1078.annotation.MsgId; +import com.genersoft.iot.vmp.jt1078.bean.JTQueryMediaDataCommand; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; + +/** + * 录音开始/停止命令 + */ +@MsgId(id = "8804") +public class J8804 extends Rs { + + /** + * 录音命令, 0:停止录音;0X01:开始录音 + */ + private int commond; + + /** + * 录音时长,单位为秒(s) ,0 表示一直录音 + */ + private int duration; + + /** + * 保存标志, 0:实时上传;1:保存 + */ + private int save; + + /** + * 音频采样率, 0:8K;1:11K;2:23K;3:32K;其他保留 + */ + private int samplingRate; + + @Override + public ByteBuf encode() { + ByteBuf byteBuf = Unpooled.buffer(); + byteBuf.writeByte(commond); + byteBuf.writeShort((short)(duration & 0xffff)); + byteBuf.writeByte(save); + byteBuf.writeByte(samplingRate); + return byteBuf; + } + + public int getCommond() { + return commond; + } + + public void setCommond(int commond) { + this.commond = commond; + } + + public int getDuration() { + return duration; + } + + public void setDuration(int duration) { + this.duration = duration; + } + + public int getSave() { + return save; + } + + public void setSave(int save) { + this.save = save; + } + + public int getSamplingRate() { + return samplingRate; + } + + public void setSamplingRate(int samplingRate) { + this.samplingRate = samplingRate; + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/jt1078/service/Ijt1078Service.java b/src/main/java/com/genersoft/iot/vmp/jt1078/service/Ijt1078Service.java index be89ef5cc..0e98b60eb 100644 --- a/src/main/java/com/genersoft/iot/vmp/jt1078/service/Ijt1078Service.java +++ b/src/main/java/com/genersoft/iot/vmp/jt1078/service/Ijt1078Service.java @@ -99,4 +99,7 @@ public interface Ijt1078Service { List shooting(String deviceId, JTShootingCommand shootingCommand); List queryMediaData(String deviceId, JTQueryMediaDataCommand queryMediaDataCommand); + + List updateMediaData(String deviceId, JTQueryMediaDataCommand queryMediaDataCommand); + } diff --git a/src/main/java/com/genersoft/iot/vmp/jt1078/service/impl/jt1078ServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/jt1078/service/impl/jt1078ServiceImpl.java index 887b4dd05..4e7bf3348 100644 --- a/src/main/java/com/genersoft/iot/vmp/jt1078/service/impl/jt1078ServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/jt1078/service/impl/jt1078ServiceImpl.java @@ -720,4 +720,11 @@ public class jt1078ServiceImpl implements Ijt1078Service { j8802.setCommand(queryMediaDataCommand); return (List)jt1078Template.queryMediaData(deviceId, j8802, 300); } + + @Override + public List updateMediaData(String deviceId, JTQueryMediaDataCommand queryMediaDataCommand) { + J8803 j8803 = new J8803(); + j8803.setCommand(queryMediaDataCommand); + return (List)jt1078Template.updateMediaData(deviceId, j8803, 300); + } }