规范接口格式 添加 dto2vo 转换工具类
This commit is contained in:
parent
6de430190b
commit
1da36a6a73
@ -7,6 +7,7 @@ import cn.skcks.docking.gb28181.common.json.JsonResponse;
|
||||
import cn.skcks.docking.gb28181.config.SwaggerConfig;
|
||||
import cn.skcks.docking.gb28181.core.sip.message.processor.message.types.recordinfo.reponse.dto.RecordInfoItemDTO;
|
||||
import cn.skcks.docking.gb28181.service.record.RecordService;
|
||||
import cn.skcks.docking.gb28181.service.record.vo.RecordInfoItemVO;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springdoc.core.annotations.ParameterObject;
|
||||
@ -31,7 +32,7 @@ public class RecordController {
|
||||
}
|
||||
|
||||
@GetJson("/getInfo")
|
||||
public DeferredResult<JsonResponse<List<RecordInfoItemDTO>>> getInfo(@ParameterObject @Validated GetInfoDTO dto){
|
||||
return recordService.requestRecordInfo(dto.getDeviceId());
|
||||
public DeferredResult<JsonResponse<List<RecordInfoItemVO>>> getInfo(@ParameterObject @Validated GetInfoDTO dto){
|
||||
return recordService.requestRecordInfo(dto.getDeviceId(), dto.getTimeout(), dto.getDate());
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,26 @@
|
||||
package cn.skcks.docking.gb28181.api.record.dto;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Schema(title = "查询历史录像")
|
||||
@Data
|
||||
public class GetInfoDTO {
|
||||
@NotBlank
|
||||
@Schema(description = "设备id")
|
||||
@Schema(description = "设备id", example = "44050100001180000001")
|
||||
private String deviceId;
|
||||
|
||||
@Min(30)
|
||||
@Schema(description = "超时时间(秒)", example = "30")
|
||||
private long timeout = 30;
|
||||
|
||||
@DateTimeFormat(pattern= DatePattern.NORM_DATE_PATTERN)
|
||||
@Schema(description = "查询日期", example = "2023-08-23")
|
||||
private Date date;
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
|
||||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
|
||||
import jakarta.validation.constraints.Min;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
@ -31,7 +30,7 @@ public class RecordInfoItemDTO {
|
||||
private Date endTime;
|
||||
|
||||
@Min(value = 0)
|
||||
private Integer Secrecy = 0;
|
||||
private Integer secrecy = 0;
|
||||
|
||||
private String type = "all";
|
||||
|
||||
|
@ -16,6 +16,8 @@ import cn.skcks.docking.gb28181.core.sip.service.SipService;
|
||||
import cn.skcks.docking.gb28181.core.sip.utils.SipUtil;
|
||||
import cn.skcks.docking.gb28181.orm.mybatis.dynamic.model.DockingDevice;
|
||||
import cn.skcks.docking.gb28181.service.docking.device.DockingDeviceService;
|
||||
import cn.skcks.docking.gb28181.service.record.convertor.RecordConvertor;
|
||||
import cn.skcks.docking.gb28181.service.record.vo.RecordInfoItemVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -26,6 +28,7 @@ import javax.sip.SipProvider;
|
||||
import javax.sip.header.CallIdHeader;
|
||||
import javax.sip.message.Request;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
@ -40,10 +43,16 @@ public class RecordService {
|
||||
private final SipMessageSender sender;
|
||||
private final SipSubscribe subscribe;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param deviceId 设备id
|
||||
* @param timeout 超时时间
|
||||
* @param date 查询日期
|
||||
*/
|
||||
@SneakyThrows
|
||||
public DeferredResult<JsonResponse<List<RecordInfoItemDTO>>> requestRecordInfo(String deviceId) {
|
||||
log.info("TimeUnit.SECONDS.toMillis(30) {}",TimeUnit.SECONDS.toMillis(30));
|
||||
DeferredResult<JsonResponse<List<RecordInfoItemDTO>>> result = new DeferredResult<>(TimeUnit.SECONDS.toMillis(30));
|
||||
public DeferredResult<JsonResponse<List<RecordInfoItemVO>>> requestRecordInfo(String deviceId, long timeout, Date date) {
|
||||
log.info("查询 设备 => {} {} 的历史媒体记录, 超时时间 {} 秒", deviceId, DateUtil.formatDate(date), timeout);
|
||||
DeferredResult<JsonResponse<List<RecordInfoItemVO>>> result = new DeferredResult<>(TimeUnit.SECONDS.toMillis(timeout));
|
||||
|
||||
DockingDevice device = deviceService.getDevice(deviceId);
|
||||
if (device == null) {
|
||||
@ -59,8 +68,8 @@ public class RecordService {
|
||||
String sn = String.valueOf((int) (Math.random() * 9 + 1) * 100000);
|
||||
RecordInfoRequestDTO dto = RecordInfoRequestDTO.builder()
|
||||
.deviceId(deviceId)
|
||||
.startTime(DateUtil.beginOfDay(DateUtil.offsetDay(DateUtil.date(),-1)))
|
||||
.endTime(DateUtil.endOfDay(DateUtil.offsetDay(DateUtil.date(),-1)))
|
||||
.startTime(DateUtil.beginOfDay(date))
|
||||
.endTime(DateUtil.endOfDay(date))
|
||||
.sn(sn)
|
||||
.build();
|
||||
Request request = SipRequestBuilder.createMessageRequest(device,
|
||||
@ -115,15 +124,17 @@ public class RecordService {
|
||||
public void onComplete() {
|
||||
schedule[0].cancel(true);
|
||||
subscribe.getRecordInfoSubscribe().delPublisher(key);
|
||||
result.setResult(JsonResponse.success(sortedRecordList(list)));
|
||||
result.setResult(JsonResponse.success(RecordConvertor.INSTANCE.dto2Vo(sortedRecordList(list))));
|
||||
log.debug("订阅结束 => {}", key);
|
||||
}
|
||||
};
|
||||
|
||||
subscribe.getRecordInfoSubscribe().addSubscribe(key, subscriber);
|
||||
|
||||
result.onTimeout(()->{
|
||||
result.setResult(JsonResponse.build(ResponseStatus.PARTIAL_CONTENT, sortedRecordList(list),"查询超时, 结果可能不完整"));
|
||||
result.onTimeout(() -> {
|
||||
result.setResult(JsonResponse.build(ResponseStatus.PARTIAL_CONTENT,
|
||||
RecordConvertor.INSTANCE.dto2Vo(sortedRecordList(list)),
|
||||
"查询超时, 结果可能不完整"));
|
||||
subscribe.getRecordInfoSubscribe().delPublisher(key);
|
||||
});
|
||||
|
||||
|
@ -0,0 +1,16 @@
|
||||
package cn.skcks.docking.gb28181.service.record.convertor;
|
||||
|
||||
import cn.skcks.docking.gb28181.core.sip.message.processor.message.types.recordinfo.reponse.dto.RecordInfoItemDTO;
|
||||
import cn.skcks.docking.gb28181.service.record.vo.RecordInfoItemVO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public abstract class RecordConvertor {
|
||||
public static final RecordConvertor INSTANCE = Mappers.getMapper(RecordConvertor.class);
|
||||
abstract public List<RecordInfoItemVO> dto2Vo(List<RecordInfoItemDTO> dto);
|
||||
|
||||
abstract public RecordInfoItemVO dto2Vo(RecordInfoItemDTO dto);
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package cn.skcks.docking.gb28181.service.record.vo;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.skcks.docking.gb28181.core.sip.gb28181.constant.GB28181Constant;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class RecordInfoItemVO {
|
||||
private String deviceId;
|
||||
|
||||
private String name;
|
||||
|
||||
private String address;
|
||||
|
||||
@JsonFormat(pattern = DatePattern.NORM_DATETIME_PATTERN, timezone = GB28181Constant.TIME_ZONE)
|
||||
private Date startTime;
|
||||
|
||||
@JsonFormat(pattern = DatePattern.NORM_DATETIME_PATTERN, timezone = GB28181Constant.TIME_ZONE)
|
||||
private Date endTime;
|
||||
|
||||
private Integer secrecy;
|
||||
|
||||
private String type;
|
||||
|
||||
private Long fileSize;
|
||||
}
|
Loading…
Reference in New Issue
Block a user