结构调整
This commit is contained in:
parent
1a11418868
commit
6de430190b
@ -1,10 +1,12 @@
|
||||
package cn.skcks.docking.gb28181.common.json;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Data
|
||||
@SuppressWarnings("unused")
|
||||
@Schema(title = "返回结果")
|
||||
@ -12,52 +14,50 @@ public class JsonResponse<T> {
|
||||
@Schema(title = "状态码")
|
||||
private int code;
|
||||
|
||||
@Schema(title = "响应消息")
|
||||
private String msg;
|
||||
|
||||
@Schema(title = "响应数据")
|
||||
private T data;
|
||||
|
||||
public JsonResponse(int code, String msg, T data) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
this.data = data;
|
||||
}
|
||||
@Schema(title = "响应消息")
|
||||
private String msg;
|
||||
|
||||
public static <T> JsonResponse<T> success(T data) {
|
||||
return JsonResponse.build(data, ResponseStatus.OK);
|
||||
}
|
||||
|
||||
public static <T> JsonResponse<T> success(T data, String message) {
|
||||
return JsonResponse.build(data, ResponseStatus.OK.getCode(), message);
|
||||
return JsonResponse.build(ResponseStatus.OK.getCode(), data, message);
|
||||
}
|
||||
|
||||
public static <T> JsonResponse<T> error(T data) {
|
||||
return JsonResponse.build(data, ResponseStatus.INTERNAL_SERVER_ERROR);
|
||||
public static <T> JsonResponse<T> error(String message) {
|
||||
return JsonResponse.build(ResponseStatus.INTERNAL_SERVER_ERROR.getCode(), null, message);
|
||||
}
|
||||
|
||||
public static <T> JsonResponse<T> error(T data, String message) {
|
||||
return JsonResponse.build(data, ResponseStatus.INTERNAL_SERVER_ERROR.getCode(), message);
|
||||
return JsonResponse.build(ResponseStatus.INTERNAL_SERVER_ERROR.getCode(), data, message);
|
||||
}
|
||||
|
||||
public static <T> JsonResponse<T> build(ResponseStatus status) {
|
||||
return new JsonResponse<>(status.getCode(), status.getMessage(),null);
|
||||
return new JsonResponse<>(status.getCode(), null, status.getMessage());
|
||||
}
|
||||
|
||||
public static <T> JsonResponse<T> build(T data, ResponseStatus status) {
|
||||
return new JsonResponse<>(status.getCode(), status.getMessage(), data);
|
||||
return new JsonResponse<>(status.getCode(), data, status.getMessage());
|
||||
}
|
||||
|
||||
public static <T> JsonResponse<T> build(ResponseStatus status,String message) {
|
||||
return new JsonResponse<>(status.getCode(), message, null);
|
||||
public static <T> JsonResponse<T> build(ResponseStatus status, String message) {
|
||||
return new JsonResponse<>(status.getCode(), null, message);
|
||||
}
|
||||
|
||||
public static <T> JsonResponse<T> build(T data, int status, String msg) {
|
||||
return new JsonResponse<>(status, msg, data);
|
||||
public static <T> JsonResponse<T> build(ResponseStatus status, T data, String message) {
|
||||
return new JsonResponse<>(status.getCode(), data, message);
|
||||
}
|
||||
|
||||
public static <T> JsonResponse<T> build(int status, T data, String msg) {
|
||||
return new JsonResponse<>(status, data, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
public String toString() {
|
||||
return JsonUtils.toJson(this);
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ public enum ResponseStatus {
|
||||
CREATED(201, "Created"),
|
||||
ACCEPTED(202, "Accepted"),
|
||||
NO_CONTENT(204, "No Content"),
|
||||
PARTIAL_CONTENT(206, "Partial Content"),
|
||||
MOVED_PERMANENTLY(301, "Moved Permanently"),
|
||||
FOUND(302, "Found"),
|
||||
SEE_OTHER(303, "See Other"),
|
||||
|
@ -0,0 +1,53 @@
|
||||
package cn.skcks.docking.gb28181.core.sip.message;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
import javax.sip.SipFactory;
|
||||
import javax.sip.address.Address;
|
||||
import javax.sip.address.AddressFactory;
|
||||
import javax.sip.address.SipURI;
|
||||
import javax.sip.header.FromHeader;
|
||||
import javax.sip.header.HeaderFactory;
|
||||
import javax.sip.header.MaxForwardsHeader;
|
||||
import javax.sip.header.ToHeader;
|
||||
|
||||
public class MessageHelper {
|
||||
public static SipFactory getSipFactory() {
|
||||
return SipFactory.getInstance();
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static AddressFactory createAddressFactory() {
|
||||
return getSipFactory().createAddressFactory();
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static HeaderFactory createHeaderFactory() {
|
||||
return getSipFactory().createHeaderFactory();
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static SipURI createSipURI(String id, String address) {
|
||||
return createAddressFactory().createSipURI(id, address);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static Address createAddress(SipURI uri) {
|
||||
return createAddressFactory().createAddress(uri);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static FromHeader createFromHeader(Address fromAddress, String fromTag) {
|
||||
return createHeaderFactory().createFromHeader(fromAddress, fromTag);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static ToHeader createToHeader(Address toAddress, String toTag) {
|
||||
return createHeaderFactory().createToHeader(toAddress, toTag);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static MaxForwardsHeader createMaxForwardsHeader(int maxForwards) {
|
||||
return createHeaderFactory().createMaxForwardsHeader(maxForwards);
|
||||
}
|
||||
}
|
@ -14,6 +14,7 @@ import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.stereotype.Component;
|
||||
import cn.skcks.docking.gb28181.core.sip.message.MessageHelper;
|
||||
|
||||
import javax.sip.InvalidArgumentException;
|
||||
import javax.sip.PeerUnavailableException;
|
||||
@ -39,22 +40,22 @@ public class SipRequestBuilder implements ApplicationContextAware {
|
||||
|
||||
@SneakyThrows
|
||||
private static SipURI getSipURI(String id,String address){
|
||||
return getSipFactory().createAddressFactory().createSipURI(id, address);
|
||||
return MessageHelper.createSipURI(id, address);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private static Address getAddress(SipURI uri){
|
||||
return getSipFactory().createAddressFactory().createAddress(uri);
|
||||
return MessageHelper.createAddress(uri);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private static FromHeader getFromHeader(Address fromAddress,String fromTag){
|
||||
return getSipFactory().createHeaderFactory().createFromHeader(fromAddress, fromTag);
|
||||
return MessageHelper.createFromHeader(fromAddress, fromTag);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private static ToHeader getToHeader(Address toAddress,String toTag){
|
||||
return getSipFactory().createHeaderFactory().createToHeader(toAddress, toTag);
|
||||
return MessageHelper.createToHeader(toAddress, toTag);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@ -77,11 +78,11 @@ public class SipRequestBuilder implements ApplicationContextAware {
|
||||
List<ViaHeader> viaHeaders = getDeviceViaHeaders(device, viaTag);
|
||||
// from
|
||||
SipURI fromSipURI = getSipURI(sipConfig.getId(), sipConfig.getDomain());
|
||||
Address fromAddress = getAddress(fromSipURI);
|
||||
Address fromAddress = MessageHelper.createAddress(fromSipURI);
|
||||
FromHeader fromHeader = getFromHeader(fromAddress, fromTag);
|
||||
// to
|
||||
SipURI toSipURI = getSipURI(device.getDeviceId(), device.getHostAddress());
|
||||
Address toAddress = getAddress(toSipURI);
|
||||
Address toAddress = MessageHelper.createAddress(toSipURI);
|
||||
ToHeader toHeader = getToHeader(toAddress, toTag);
|
||||
|
||||
// Forwards
|
||||
@ -108,11 +109,11 @@ public class SipRequestBuilder implements ApplicationContextAware {
|
||||
|
||||
// from
|
||||
SipURI fromSipURI = getSipURI(sipConfig.getId(), sipConfig.getDomain());
|
||||
Address fromAddress = getAddress(fromSipURI);
|
||||
Address fromAddress = MessageHelper.createAddress(fromSipURI);
|
||||
FromHeader fromHeader = getFromHeader(fromAddress, fromTag); // 必须要有标记,否则无法创建会话,无法回应ack
|
||||
// to
|
||||
SipURI toSipURI = getSipURI(channelId, device.getHostAddress());
|
||||
Address toAddress = getAddress(toSipURI);
|
||||
Address toAddress = MessageHelper.createAddress(toSipURI);
|
||||
ToHeader toHeader = getToHeader(toAddress, null);
|
||||
|
||||
// Forwards
|
||||
@ -124,8 +125,8 @@ public class SipRequestBuilder implements ApplicationContextAware {
|
||||
|
||||
request.addHeader(SipUtil.createUserAgentHeader());
|
||||
|
||||
Address concatAddress = getAddress(getSipURI(sipConfig.getId(), device.getLocalIp() + ":" + sipConfig.getPort()));
|
||||
// Address concatAddress = getAddress(getSipURI(sipConfig.getId(), device.getHost().getIp()+":"+device.getHost().getPort()));
|
||||
Address concatAddress = MessageHelper.createAddress(getSipURI(sipConfig.getId(), device.getLocalIp() + ":" + sipConfig.getPort()));
|
||||
// Address concatAddress = MessageHelper.createAddress(getSipURI(sipConfig.getId(), device.getHost().getIp()+":"+device.getHost().getPort()));
|
||||
request.addHeader(getSipFactory().createHeaderFactory().createContactHeader(concatAddress));
|
||||
// Subject
|
||||
SubjectHeader subjectHeader = getSipFactory().createHeaderFactory().createSubjectHeader(String.format("%s:%s,%s:%s", channelId, ssrc, sipConfig.getId(), 0));
|
||||
@ -146,11 +147,11 @@ public class SipRequestBuilder implements ApplicationContextAware {
|
||||
viaHeaders.add(viaHeader);
|
||||
// from
|
||||
SipURI fromSipURI = getSipURI(sipConfig.getId(), sipConfig.getDomain());
|
||||
Address fromAddress = getAddress(fromSipURI);
|
||||
Address fromAddress = MessageHelper.createAddress(fromSipURI);
|
||||
FromHeader fromHeader = getFromHeader(fromAddress, fromTag); // 必须要有标记,否则无法创建会话,无法回应ack
|
||||
// to
|
||||
SipURI toSipURI = getSipURI(channelId, device.getHostAddress());
|
||||
Address toAddress = getAddress(toSipURI);
|
||||
Address toAddress = MessageHelper.createAddress(toSipURI);
|
||||
ToHeader toHeader = getToHeader(toAddress, null);
|
||||
|
||||
// Forwards
|
||||
@ -160,8 +161,8 @@ public class SipRequestBuilder implements ApplicationContextAware {
|
||||
CSeqHeader cSeqHeader = getSipFactory().createHeaderFactory().createCSeqHeader(getCSeq(), Request.INVITE);
|
||||
request = getSipFactory().createMessageFactory().createRequest(requestLine, Request.INVITE, callIdHeader, cSeqHeader, fromHeader, toHeader, viaHeaders, maxForwards);
|
||||
|
||||
Address concatAddress = getAddress(getSipURI(sipConfig.getId(), device.getLocalIp() + ":" + sipConfig.getPort()));
|
||||
// Address concatAddress = getAddress(getSipURI(sipConfig.getId(), device.getHost().getIp()+":"+device.getHost().getPort()));
|
||||
Address concatAddress = MessageHelper.createAddress(getSipURI(sipConfig.getId(), device.getLocalIp() + ":" + sipConfig.getPort()));
|
||||
// Address concatAddress = MessageHelper.createAddress(getSipURI(sipConfig.getId(), device.getHost().getIp()+":"+device.getHost().getPort()));
|
||||
request.addHeader(getSipFactory().createHeaderFactory().createContactHeader(concatAddress));
|
||||
|
||||
request.addHeader(SipUtil.createUserAgentHeader());
|
||||
@ -185,11 +186,11 @@ public class SipRequestBuilder implements ApplicationContextAware {
|
||||
viaHeaders.add(viaHeader);
|
||||
// from
|
||||
SipURI fromSipURI = getSipURI(sipConfig.getId(), sipConfig.getDomain());
|
||||
Address fromAddress = getAddress(fromSipURI);
|
||||
Address fromAddress = MessageHelper.createAddress(fromSipURI);
|
||||
FromHeader fromHeader = getFromHeader(fromAddress, transactionInfo.getFromTag());
|
||||
// to
|
||||
SipURI toSipURI = getSipURI(channelId, device.getHostAddress());
|
||||
Address toAddress = getAddress(toSipURI);
|
||||
Address toAddress = MessageHelper.createAddress(toSipURI);
|
||||
ToHeader toHeader = getToHeader(toAddress, transactionInfo.getToTag());
|
||||
|
||||
// Forwards
|
||||
@ -202,7 +203,7 @@ public class SipRequestBuilder implements ApplicationContextAware {
|
||||
|
||||
request.addHeader(SipUtil.createUserAgentHeader());
|
||||
|
||||
Address concatAddress = getAddress(getSipURI(sipConfig.getId(), device.getLocalIp() + ":" + sipConfig.getPort()));
|
||||
Address concatAddress = MessageHelper.createAddress(getSipURI(sipConfig.getId(), device.getLocalIp() + ":" + sipConfig.getPort()));
|
||||
request.addHeader(getSipFactory().createHeaderFactory().createContactHeader(concatAddress));
|
||||
|
||||
request.addHeader(SipUtil.createUserAgentHeader());
|
||||
@ -222,11 +223,11 @@ public class SipRequestBuilder implements ApplicationContextAware {
|
||||
viaHeaders.add(viaHeader);
|
||||
// from
|
||||
SipURI fromSipURI = getSipURI(sipConfig.getId(), sipConfig.getDomain());
|
||||
Address fromAddress = getAddress(fromSipURI);
|
||||
Address fromAddress = MessageHelper.createAddress(fromSipURI);
|
||||
FromHeader fromHeader = getFromHeader(fromAddress, requestOld == null ? SipUtil.generateFromTag() : requestOld.getFromTag());
|
||||
// to
|
||||
SipURI toSipURI = getSipURI(device.getDeviceId(), device.getHostAddress());
|
||||
Address toAddress = getAddress(toSipURI);
|
||||
Address toAddress = MessageHelper.createAddress(toSipURI);
|
||||
ToHeader toHeader = getToHeader(toAddress, requestOld == null ? null : requestOld.getToTag());
|
||||
|
||||
// Forwards
|
||||
@ -239,7 +240,7 @@ public class SipRequestBuilder implements ApplicationContextAware {
|
||||
toHeader, viaHeaders, maxForwards);
|
||||
|
||||
|
||||
Address concatAddress = getAddress(getSipURI(sipConfig.getId(), device.getLocalIp() + ":" + sipConfig.getPort()));
|
||||
Address concatAddress = MessageHelper.createAddress(getSipURI(sipConfig.getId(), device.getLocalIp() + ":" + sipConfig.getPort()));
|
||||
request.addHeader(getSipFactory().createHeaderFactory().createContactHeader(concatAddress));
|
||||
|
||||
// Expires
|
||||
@ -275,11 +276,11 @@ public class SipRequestBuilder implements ApplicationContextAware {
|
||||
viaHeaders.add(viaHeader);
|
||||
// from
|
||||
SipURI fromSipURI = getSipURI(sipConfig.getId(), sipConfig.getDomain());
|
||||
Address fromAddress = getAddress(fromSipURI);
|
||||
Address fromAddress = MessageHelper.createAddress(fromSipURI);
|
||||
FromHeader fromHeader = getFromHeader(fromAddress, transactionInfo.getFromTag());
|
||||
// to
|
||||
SipURI toSipURI = getSipURI(channelId, device.getHostAddress());
|
||||
Address toAddress = getAddress(toSipURI);
|
||||
Address toAddress = MessageHelper.createAddress(toSipURI);
|
||||
ToHeader toHeader = getToHeader(toAddress, transactionInfo.getToTag());
|
||||
|
||||
// Forwards
|
||||
@ -292,7 +293,7 @@ public class SipRequestBuilder implements ApplicationContextAware {
|
||||
|
||||
request.addHeader(SipUtil.createUserAgentHeader());
|
||||
|
||||
Address concatAddress = getAddress(getSipURI(sipConfig.getId(), device.getLocalIp() + ":" + sipConfig.getPort()));
|
||||
Address concatAddress = MessageHelper.createAddress(getSipURI(sipConfig.getId(), device.getLocalIp() + ":" + sipConfig.getPort()));
|
||||
request.addHeader(getSipFactory().createHeaderFactory().createContactHeader(concatAddress));
|
||||
|
||||
request.addHeader(SipUtil.createUserAgentHeader());
|
||||
@ -323,7 +324,7 @@ public class SipRequestBuilder implements ApplicationContextAware {
|
||||
|
||||
request.addHeader(SipUtil.createUserAgentHeader());
|
||||
|
||||
Address concatAddress = getAddress(getSipURI(sipConfig.getId(), localIp + ":" + sipConfig.getPort()));
|
||||
Address concatAddress = MessageHelper.createAddress(getSipURI(sipConfig.getId(), localIp + ":" + sipConfig.getPort()));
|
||||
request.addHeader(getSipFactory().createHeaderFactory().createContactHeader(concatAddress));
|
||||
|
||||
request.addHeader(SipUtil.createUserAgentHeader());
|
||||
|
@ -2,6 +2,7 @@ package cn.skcks.docking.gb28181.service.record;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.skcks.docking.gb28181.common.json.JsonResponse;
|
||||
import cn.skcks.docking.gb28181.common.json.ResponseStatus;
|
||||
import cn.skcks.docking.gb28181.common.xml.XmlUtils;
|
||||
import cn.skcks.docking.gb28181.core.sip.gb28181.constant.CmdType;
|
||||
import cn.skcks.docking.gb28181.core.sip.message.processor.message.types.recordinfo.query.dto.RecordInfoRequestDTO;
|
||||
@ -58,8 +59,8 @@ public class RecordService {
|
||||
String sn = String.valueOf((int) (Math.random() * 9 + 1) * 100000);
|
||||
RecordInfoRequestDTO dto = RecordInfoRequestDTO.builder()
|
||||
.deviceId(deviceId)
|
||||
.startTime(DateUtil.beginOfDay(DateUtil.date()))
|
||||
.endTime(DateUtil.endOfDay(DateUtil.date()))
|
||||
.startTime(DateUtil.beginOfDay(DateUtil.offsetDay(DateUtil.date(),-1)))
|
||||
.endTime(DateUtil.endOfDay(DateUtil.offsetDay(DateUtil.date(),-1)))
|
||||
.sn(sn)
|
||||
.build();
|
||||
Request request = SipRequestBuilder.createMessageRequest(device,
|
||||
@ -122,7 +123,7 @@ public class RecordService {
|
||||
subscribe.getRecordInfoSubscribe().addSubscribe(key, subscriber);
|
||||
|
||||
result.onTimeout(()->{
|
||||
result.setResult(JsonResponse.success(sortedRecordList(list),"查询超时, 结果可能不完整"));
|
||||
result.setResult(JsonResponse.build(ResponseStatus.PARTIAL_CONTENT, sortedRecordList(list),"查询超时, 结果可能不完整"));
|
||||
subscribe.getRecordInfoSubscribe().delPublisher(key);
|
||||
});
|
||||
|
||||
|
@ -10,7 +10,7 @@ public interface ZlmResponseConvertor {
|
||||
ZlmResponseConvertor INSTANCE = Mappers.getMapper(ZlmResponseConvertor.class);
|
||||
|
||||
default <T> JsonResponse<T> toJsonResponse(ZlmResponse<T> response){
|
||||
return JsonResponse.build(response.getData(), response.getCode().getCode(), response.getMsg());
|
||||
return JsonResponse.build(response.getCode().getCode(), response.getData(), response.getMsg());
|
||||
}
|
||||
default <T> ZlmResponse<T> toZlmResponse(JsonResponse<T> response){
|
||||
return new ZlmResponse<>(ResponseStatus.fromCode(response.getCode()), response.getData(), response.getMsg());
|
||||
|
Loading…
Reference in New Issue
Block a user