1078-完善查询终端参数接口
This commit is contained in:
@@ -17,6 +17,7 @@ public class JT1078Template {
|
||||
|
||||
private final Random random = new Random();
|
||||
|
||||
private static final String H8103 = "8103";
|
||||
private static final String H8104 = "8104";
|
||||
private static final String H8106 = "8106";
|
||||
private static final String H9101 = "9101";
|
||||
@@ -43,7 +44,7 @@ public class JT1078Template {
|
||||
* @param devId 设备号
|
||||
* @param j9101 开启视频参数
|
||||
*/
|
||||
public String startLive(String devId, J9101 j9101, Integer timeOut) {
|
||||
public Object startLive(String devId, J9101 j9101, Integer timeOut) {
|
||||
Cmd cmd = new Cmd.Builder()
|
||||
.setDevId(devId)
|
||||
.setPackageNo(randomInt())
|
||||
@@ -60,7 +61,7 @@ public class JT1078Template {
|
||||
* @param devId 设备号
|
||||
* @param j9102 关闭视频参数
|
||||
*/
|
||||
public String stopLive(String devId, J9102 j9102, Integer timeOut) {
|
||||
public Object stopLive(String devId, J9102 j9102, Integer timeOut) {
|
||||
Cmd cmd = new Cmd.Builder()
|
||||
.setDevId(devId)
|
||||
.setPackageNo(randomInt())
|
||||
@@ -77,7 +78,7 @@ public class JT1078Template {
|
||||
* @param devId 设备号
|
||||
* @param j9205 查询音视频列表
|
||||
*/
|
||||
public String queryBackTime(String devId, J9205 j9205, Integer timeOut) {
|
||||
public Object queryBackTime(String devId, J9205 j9205, Integer timeOut) {
|
||||
Cmd cmd = new Cmd.Builder()
|
||||
.setDevId(devId)
|
||||
.setPackageNo(randomInt())
|
||||
@@ -94,7 +95,7 @@ public class JT1078Template {
|
||||
* @param devId 设备号
|
||||
* @param j9201 视频回放参数
|
||||
*/
|
||||
public String startBackLive(String devId, J9201 j9201, Integer timeOut) {
|
||||
public Object startBackLive(String devId, J9201 j9201, Integer timeOut) {
|
||||
Cmd cmd = new Cmd.Builder()
|
||||
.setDevId(devId)
|
||||
.setPackageNo(randomInt())
|
||||
@@ -111,7 +112,7 @@ public class JT1078Template {
|
||||
* @param devId 设备号
|
||||
* @param j9202 控制视频回放参数
|
||||
*/
|
||||
public String controlBackLive(String devId, J9202 j9202, Integer timeOut) {
|
||||
public Object controlBackLive(String devId, J9202 j9202, Integer timeOut) {
|
||||
Cmd cmd = new Cmd.Builder()
|
||||
.setDevId(devId)
|
||||
.setPackageNo(randomInt())
|
||||
@@ -128,7 +129,7 @@ public class JT1078Template {
|
||||
* @param devId 设备号
|
||||
* @param j9206 文件上传参数
|
||||
*/
|
||||
public String fileUpload(String devId, J9206 j9206, Integer timeOut) {
|
||||
public Object fileUpload(String devId, J9206 j9206, Integer timeOut) {
|
||||
Cmd cmd = new Cmd.Builder()
|
||||
.setDevId(devId)
|
||||
.setPackageNo(randomInt())
|
||||
@@ -145,7 +146,7 @@ public class JT1078Template {
|
||||
* @param devId 设备号
|
||||
* @param j9207 文件上传控制参数
|
||||
*/
|
||||
public String fileUploadControl(String devId, J9207 j9207, Integer timeOut) {
|
||||
public Object fileUploadControl(String devId, J9207 j9207, Integer timeOut) {
|
||||
Cmd cmd = new Cmd.Builder()
|
||||
.setDevId(devId)
|
||||
.setPackageNo(randomInt())
|
||||
@@ -162,7 +163,7 @@ public class JT1078Template {
|
||||
* @param devId 设备号
|
||||
* @param j9301 云台旋转参数
|
||||
*/
|
||||
public String ptzRotate(String devId, J9301 j9301, Integer timeOut) {
|
||||
public Object ptzRotate(String devId, J9301 j9301, Integer timeOut) {
|
||||
Cmd cmd = new Cmd.Builder()
|
||||
.setDevId(devId)
|
||||
.setPackageNo(randomInt())
|
||||
@@ -179,7 +180,7 @@ public class JT1078Template {
|
||||
* @param devId 设备号
|
||||
* @param j9302 云台焦距控制参数
|
||||
*/
|
||||
public String ptzFocal(String devId, J9302 j9302, Integer timeOut) {
|
||||
public Object ptzFocal(String devId, J9302 j9302, Integer timeOut) {
|
||||
Cmd cmd = new Cmd.Builder()
|
||||
.setDevId(devId)
|
||||
.setPackageNo(randomInt())
|
||||
@@ -196,7 +197,7 @@ public class JT1078Template {
|
||||
* @param devId 设备号
|
||||
* @param j9303 云台光圈控制参数
|
||||
*/
|
||||
public String ptzIris(String devId, J9303 j9303, Integer timeOut) {
|
||||
public Object ptzIris(String devId, J9303 j9303, Integer timeOut) {
|
||||
Cmd cmd = new Cmd.Builder()
|
||||
.setDevId(devId)
|
||||
.setPackageNo(randomInt())
|
||||
@@ -213,7 +214,7 @@ public class JT1078Template {
|
||||
* @param devId 设备号
|
||||
* @param j9304 云台雨刷控制参数
|
||||
*/
|
||||
public String ptzWiper(String devId, J9304 j9304, Integer timeOut) {
|
||||
public Object ptzWiper(String devId, J9304 j9304, Integer timeOut) {
|
||||
Cmd cmd = new Cmd.Builder()
|
||||
.setDevId(devId)
|
||||
.setPackageNo(randomInt())
|
||||
@@ -230,7 +231,7 @@ public class JT1078Template {
|
||||
* @param devId 设备号
|
||||
* @param j9305 云台红外补光控制参数
|
||||
*/
|
||||
public String ptzSupplementaryLight(String devId, J9305 j9305, Integer timeOut) {
|
||||
public Object ptzSupplementaryLight(String devId, J9305 j9305, Integer timeOut) {
|
||||
Cmd cmd = new Cmd.Builder()
|
||||
.setDevId(devId)
|
||||
.setPackageNo(randomInt())
|
||||
@@ -247,7 +248,7 @@ public class JT1078Template {
|
||||
* @param devId 设备号
|
||||
* @param j9306 云台变倍控制参数
|
||||
*/
|
||||
public String ptzZoom(String devId, J9306 j9306, Integer timeOut) {
|
||||
public Object ptzZoom(String devId, J9306 j9306, Integer timeOut) {
|
||||
Cmd cmd = new Cmd.Builder()
|
||||
.setDevId(devId)
|
||||
.setPackageNo(randomInt())
|
||||
@@ -263,7 +264,7 @@ public class JT1078Template {
|
||||
*
|
||||
* @param devId 设备号
|
||||
*/
|
||||
public String getDeviceConfig(String devId, J8104 j8104, Integer timeOut) {
|
||||
public Object getDeviceConfig(String devId, J8104 j8104, Integer timeOut) {
|
||||
|
||||
Cmd cmd = new Cmd.Builder()
|
||||
.setDevId(devId)
|
||||
@@ -280,7 +281,7 @@ public class JT1078Template {
|
||||
*
|
||||
* @param devId 设备号
|
||||
*/
|
||||
public String getDeviceSpecifyConfig(String devId, J8106 j8106, Integer timeOut) {
|
||||
public Object getDeviceSpecifyConfig(String devId, J8106 j8106, Integer timeOut) {
|
||||
|
||||
Cmd cmd = new Cmd.Builder()
|
||||
.setDevId(devId)
|
||||
@@ -292,6 +293,23 @@ public class JT1078Template {
|
||||
return SessionManager.INSTANCE.request(cmd, timeOut);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置终端参数
|
||||
*
|
||||
* @param devId 设备号
|
||||
*/
|
||||
public Object setDeviceSpecifyConfig(String devId, J8103 j8103, Integer timeOut) {
|
||||
|
||||
Cmd cmd = new Cmd.Builder()
|
||||
.setDevId(devId)
|
||||
.setPackageNo(randomInt())
|
||||
.setMsgId(H8103)
|
||||
.setRespId(H0001)
|
||||
.setRs(j8103)
|
||||
.build();
|
||||
return SessionManager.INSTANCE.request(cmd, timeOut);
|
||||
}
|
||||
|
||||
private Long randomInt() {
|
||||
return (long) random.nextInt(1000) + 1;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.genersoft.iot.vmp.jt1078.controller;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.genersoft.iot.vmp.conf.UserSetting;
|
||||
import com.genersoft.iot.vmp.conf.security.JwtUtils;
|
||||
import com.genersoft.iot.vmp.jt1078.bean.JTDevice;
|
||||
@@ -314,10 +315,20 @@ public class JT1078Controller {
|
||||
@Operation(summary = "查询终端参数", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@GetMapping("/config")
|
||||
public void config(String deviceId, String[] params){
|
||||
public JTDeviceConfig config(String deviceId, String[] params){
|
||||
|
||||
logger.info("[1078-查询终端参数] deviceId:{}", deviceId);
|
||||
service.config(deviceId, params, null);
|
||||
return service.queryConfig(deviceId, params, null);
|
||||
}
|
||||
|
||||
@Operation(summary = "设置终端参数", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@Parameter(name = "config", description = "终端参数", required = true)
|
||||
@PostMapping("/set-config")
|
||||
public void setConfig(@RequestBody SetConfigParam config){
|
||||
|
||||
logger.info("[1078-设置终端参数] 参数: {}", config.toString());
|
||||
service.setConfig(config.getDeviceId(), config.getConfig());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.genersoft.iot.vmp.jt1078.controller;
|
||||
|
||||
import com.genersoft.iot.vmp.jt1078.bean.JTDeviceConfig;
|
||||
|
||||
public class SetConfigParam {
|
||||
|
||||
private String deviceId;
|
||||
private JTDeviceConfig config;
|
||||
|
||||
public String getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
public void setDeviceId(String deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public JTDeviceConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public void setConfig(JTDeviceConfig config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SetConfigParam{" +
|
||||
"deviceId='" + deviceId + '\'' +
|
||||
", config=" + config +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ public class J0001 extends Re {
|
||||
|
||||
@Override
|
||||
protected Rs handler(Header header, Session session, Ijt1078Service service) {
|
||||
SessionManager.INSTANCE.response(header.getTerminalId(), "0001", (long) respNo, JSON.toJSONString(this));
|
||||
SessionManager.INSTANCE.response(header.getTerminalId(), "0001", (long) respNo, result);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ public class J0003 extends Re {
|
||||
|
||||
@Override
|
||||
protected Rs handler(Header header, Session session, Ijt1078Service service) {
|
||||
SessionManager.INSTANCE.response(header.getTerminalId(), "0001", (long) respNo, JSON.toJSONString(this));
|
||||
SessionManager.INSTANCE.response(header.getTerminalId(), "0001", (long) respNo, result);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.genersoft.iot.vmp.jt1078.proc.request;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.genersoft.iot.vmp.jt1078.annotation.MsgId;
|
||||
import com.genersoft.iot.vmp.jt1078.bean.JTDevice;
|
||||
import com.genersoft.iot.vmp.jt1078.bean.JTDeviceConfig;
|
||||
@@ -13,6 +14,7 @@ import com.genersoft.iot.vmp.jt1078.proc.response.J8001;
|
||||
import com.genersoft.iot.vmp.jt1078.proc.response.Rs;
|
||||
import com.genersoft.iot.vmp.jt1078.service.Ijt1078Service;
|
||||
import com.genersoft.iot.vmp.jt1078.session.Session;
|
||||
import com.genersoft.iot.vmp.jt1078.session.SessionManager;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -131,15 +133,11 @@ public class J0104 extends Re {
|
||||
System.err.println(field.getGenericType().getTypeName());
|
||||
continue;
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (NoSuchMethodException e) {
|
||||
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
System.out.println(deviceConfig);
|
||||
SessionManager.INSTANCE.response(header.getTerminalId(), "0104", (long) respNo, deviceConfig);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -156,5 +154,4 @@ public class J0104 extends Re {
|
||||
public ApplicationEvent getEvent() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -50,8 +50,7 @@ public class J1205 extends Re {
|
||||
|
||||
@Override
|
||||
protected Rs handler(Header header, Session session, Ijt1078Service service) {
|
||||
// TODO 可能未处理分包的情况
|
||||
SessionManager.INSTANCE.response(header.getTerminalId(), "1205", (long) respNo, JSON.toJSONString(this));
|
||||
SessionManager.INSTANCE.response(header.getTerminalId(), "1205", (long) respNo, recordList);
|
||||
J8001 j8001 = new J8001();
|
||||
j8001.setRespNo(header.getSn());
|
||||
j8001.setRespId(header.getMsgId());
|
||||
|
||||
@@ -42,5 +42,7 @@ public interface Ijt1078Service {
|
||||
|
||||
void wiper(String deviceId, String channelId, String command);
|
||||
|
||||
void config(String deviceId, String[] params, GeneralCallback<StreamInfo> callback);
|
||||
JTDeviceConfig queryConfig(String deviceId, String[] params, GeneralCallback<StreamInfo> callback);
|
||||
|
||||
void setConfig(String deviceId, JTDeviceConfig config);
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ public class jt1078ServiceImpl implements Ijt1078Service {
|
||||
j9101.setTcpPort(ssrcInfo.getPort());
|
||||
j9101.setUdpPort(ssrcInfo.getPort());
|
||||
j9101.setType(0);
|
||||
String s = jt1078Template.startLive(deviceId, j9101, 6);
|
||||
Object s = jt1078Template.startLive(deviceId, j9101, 6);
|
||||
System.out.println("ssss=== " + s);
|
||||
|
||||
}
|
||||
@@ -276,17 +276,13 @@ public class jt1078ServiceImpl implements Ijt1078Service {
|
||||
j9205.setMediaType(0);
|
||||
j9205.setStreamType(0);
|
||||
j9205.setStorageType(0);
|
||||
String J1205JSON = jt1078Template.queryBackTime(deviceId, j9205, 20);
|
||||
if (J1205JSON == null) {
|
||||
return null;
|
||||
}
|
||||
J1205 j1205 = JSON.parseObject(J1205JSON, J1205.class);
|
||||
if (j1205 == null) {
|
||||
List<J1205.JRecordItem> JRecordItemList = (List<J1205.JRecordItem>) jt1078Template.queryBackTime(deviceId, j9205, 20);
|
||||
if (JRecordItemList == null || JRecordItemList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
logger.info("[1078-查询录像列表] deviceId: {}, channelId: {}, startTime: {}, endTime: {}, 结果: {}条"
|
||||
, deviceId, channelId, startTime, endTime, j1205.getRecordList().size() );
|
||||
return j1205.getRecordList();
|
||||
, deviceId, channelId, startTime, endTime, JRecordItemList.size() );
|
||||
return JRecordItemList;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -365,8 +361,7 @@ public class jt1078ServiceImpl implements Ijt1078Service {
|
||||
j9201.setType(0);
|
||||
j9201.setStartTime(DateUtil.yyyy_MM_dd_HH_mm_ssTo1078(startTime));
|
||||
j9201.setEndTime(DateUtil.yyyy_MM_dd_HH_mm_ssTo1078(endTime));
|
||||
String s = jt1078Template.startBackLive(deviceId, j9201, 20);
|
||||
System.out.println("111ssss=== " + s);
|
||||
jt1078Template.startBackLive(deviceId, j9201, 20);
|
||||
|
||||
}
|
||||
|
||||
@@ -496,13 +491,13 @@ public class jt1078ServiceImpl implements Ijt1078Service {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void config(String deviceId, String[] params, GeneralCallback<StreamInfo> callback) {
|
||||
public JTDeviceConfig queryConfig(String deviceId, String[] params, GeneralCallback<StreamInfo> callback) {
|
||||
if (deviceId == null) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
if (params == null || params.length == 0) {
|
||||
J8104 j8104 = new J8104();
|
||||
jt1078Template.getDeviceConfig(deviceId, j8104, 6);
|
||||
return (JTDeviceConfig)jt1078Template.getDeviceConfig(deviceId, j8104, 20);
|
||||
}else {
|
||||
long[] paramBytes = new long[params.length];
|
||||
for (int i = 0; i < params.length; i++) {
|
||||
@@ -521,7 +516,14 @@ public class jt1078ServiceImpl implements Ijt1078Service {
|
||||
}
|
||||
J8106 j8106 = new J8106();
|
||||
j8106.setParams(paramBytes);
|
||||
jt1078Template.getDeviceSpecifyConfig(deviceId, j8106, 6);
|
||||
return (JTDeviceConfig)jt1078Template.getDeviceSpecifyConfig(deviceId, j8106, 20);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConfig(String deviceId, JTDeviceConfig config) {
|
||||
J8103 j8103 = new J8103();
|
||||
j8103.setConfig(config);
|
||||
jt1078Template.setDeviceSpecifyConfig(deviceId, j8103, 6);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public enum SessionManager {
|
||||
private final static Logger log = LoggerFactory.getLogger(SessionManager.class);
|
||||
|
||||
// 用与消息的缓存
|
||||
private final Map<String, SynchronousQueue<String>> topicSubscribers = new ConcurrentHashMap<>();
|
||||
private final Map<String, SynchronousQueue<Object>> topicSubscribers = new ConcurrentHashMap<>();
|
||||
|
||||
// session的缓存
|
||||
private final Map<Object, Session> sessionMap;
|
||||
@@ -66,20 +66,20 @@ public enum SessionManager {
|
||||
* 发送同步消息,接收响应
|
||||
* 默认超时时间6秒
|
||||
*/
|
||||
public String request(Cmd cmd) {
|
||||
public Object request(Cmd cmd) {
|
||||
// 默认6秒
|
||||
int timeOut = 6000;
|
||||
return request(cmd, timeOut);
|
||||
}
|
||||
|
||||
public String request(Cmd cmd, Integer timeOut) {
|
||||
public Object request(Cmd cmd, Integer timeOut) {
|
||||
Session session = this.get(cmd.getDevId());
|
||||
if (session == null) {
|
||||
log.error("DevId: {} not online!", cmd.getDevId());
|
||||
return null;
|
||||
}
|
||||
String requestKey = requestKey(cmd.getDevId(), cmd.getRespId(), cmd.getPackageNo());
|
||||
SynchronousQueue<String> subscribe = subscribe(requestKey);
|
||||
SynchronousQueue<Object> subscribe = subscribe(requestKey);
|
||||
if (subscribe == null) {
|
||||
log.error("DevId: {} key:{} send repaid", cmd.getDevId(), requestKey);
|
||||
return null;
|
||||
@@ -95,9 +95,9 @@ public enum SessionManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Boolean response(String devId, String respId, Long responseNo, String data) {
|
||||
public Boolean response(String devId, String respId, Long responseNo, Object data) {
|
||||
String requestKey = requestKey(devId, respId, responseNo);
|
||||
SynchronousQueue<String> queue = topicSubscribers.get(requestKey);
|
||||
SynchronousQueue<Object> queue = topicSubscribers.get(requestKey);
|
||||
if (queue != null) {
|
||||
try {
|
||||
return queue.offer(data, 2, TimeUnit.SECONDS);
|
||||
@@ -113,10 +113,10 @@ public enum SessionManager {
|
||||
topicSubscribers.remove(key);
|
||||
}
|
||||
|
||||
private SynchronousQueue<String> subscribe(String key) {
|
||||
SynchronousQueue<String> queue = null;
|
||||
private SynchronousQueue<Object> subscribe(String key) {
|
||||
SynchronousQueue<Object> queue = null;
|
||||
if (!topicSubscribers.containsKey(key))
|
||||
topicSubscribers.put(key, queue = new SynchronousQueue<String>());
|
||||
topicSubscribers.put(key, queue = new SynchronousQueue<>());
|
||||
return queue;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user