继续简化 MANSCDPUtils.XMLBuilder

This commit is contained in:
shikong 2023-09-25 00:34:23 +08:00
parent 6efb97875f
commit f92c9a70f0
5 changed files with 89 additions and 3 deletions

View File

@ -0,0 +1,24 @@
package cn.skcks.docking.gb28181.sip.manscdp.deviceinfo.request;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@JacksonXmlRootElement(localName = "Query")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class DeviceInfoRequestDTO {
@Builder.Default
private String cmdType = "DeviceInfo";
@JacksonXmlProperty(localName = "SN")
private String sn;
@JacksonXmlProperty(localName = "DeviceID")
private String deviceId;
}

View File

@ -0,0 +1,48 @@
package cn.skcks.docking.gb28181.sip.manscdp.deviceinfo.response;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@JacksonXmlRootElement(localName = "Response")
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Data
public class DeviceInfoResponseDTO {
@Builder.Default
private String cmdType = "DeviceInfo";
@JacksonXmlProperty(localName = "SN")
private String sn;
@JacksonXmlProperty(localName = "DeviceID")
private String deviceId;
private String deviceName;
@Builder.Default
private String Result = "OK";
/**
* 设备生产商
*/
private String manufacturer;
/**
* 设备型号(可选)
*/
private String model;
/**
* 设备固件版本(可选)
*/
private String firmware;
/**
* 视频输入通道数(可选)
*/
private Integer channel;
}

View File

@ -1,4 +1,4 @@
package cn.skcks.docking.gb28181.sip.manscdp.keepalive;
package cn.skcks.docking.gb28181.sip.manscdp.keepalive.notify;
import cn.skcks.docking.gb28181.constant.CmdType;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;

View File

@ -54,6 +54,10 @@ public class MANSCDPUtils {
}
}
public static <T> XMLBuilder<T> build(T data){
return new XMLBuilder<>(data);
}
@SneakyThrows
public static byte[] writeXmlWithEncoding(Object obj, String charset){
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

View File

@ -4,14 +4,14 @@ import cn.skcks.docking.gb28181.sip.manscdp.catalog.query.CatalogDeviceListDTO;
import cn.skcks.docking.gb28181.sip.manscdp.catalog.query.CatalogItemDTO;
import cn.skcks.docking.gb28181.sip.manscdp.catalog.query.CatalogQueryDTO;
import cn.skcks.docking.gb28181.sip.manscdp.catalog.response.CatalogResponseDTO;
import cn.skcks.docking.gb28181.sip.manscdp.keepalive.KeepaliveNotifyDTO;
import cn.skcks.docking.gb28181.sip.manscdp.deviceinfo.request.DeviceInfoRequestDTO;
import cn.skcks.docking.gb28181.sip.manscdp.keepalive.notify.KeepaliveNotifyDTO;
import cn.skcks.docking.gb28181.sip.utils.MANSCDPUtils;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@Slf4j
@ -86,4 +86,14 @@ public class MANSCDPTest {
responseDTO = MANSCDPUtils.parse(serialize, CatalogResponseDTO.class);
log.info("{}",responseDTO);
}
@Test
public void deviceInfo(){
DeviceInfoRequestDTO deviceInfoRequestDTO = DeviceInfoRequestDTO.builder()
.deviceId(deviceId)
.sn(sn)
.build();
MANSCDPUtils.XMLBuilder<DeviceInfoRequestDTO> xmlBuilder = MANSCDPUtils.build(deviceInfoRequestDTO);
log.info("\n{}", MANSCDPUtils.toXml(xmlBuilder));
}
}