响应类型包装
This commit is contained in:
parent
bb5e4ffbac
commit
8a1e514aa0
@ -0,0 +1,27 @@
|
||||
package cn.skcks.docking.gb28181.media.dto.response;
|
||||
|
||||
import cn.skcks.docking.gb28181.common.json.JsonUtils;
|
||||
import cn.skcks.docking.gb28181.media.dto.status.ResponseStatus;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public class ZlmResponse<T> {
|
||||
@Schema(title = "状态码")
|
||||
private ResponseStatus code;
|
||||
|
||||
@Schema(title = "响应消息")
|
||||
private String msg;
|
||||
|
||||
@Schema(title = "响应数据")
|
||||
private T data;
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return JsonUtils.toJson(this);
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package cn.skcks.docking.gb28181.media.dto.status;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum ResponseStatus {
|
||||
Exception(-400,"代码抛异常"),
|
||||
InvalidArgs(-300, "参数不合法"),
|
||||
SqlFailed(-200, "sql执行失败"),
|
||||
AuthFailed(-100,"鉴权失败"),
|
||||
OtherFailed(-1,"业务代码执行失败"),
|
||||
Success(0,"执行成功");
|
||||
|
||||
@JsonValue
|
||||
private final int code;
|
||||
private final String msg;
|
||||
|
||||
@JsonCreator
|
||||
public ResponseStatus fromCode(int code){
|
||||
for (ResponseStatus status : values()) {
|
||||
if (status.getCode() == code) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package cn.skcks.docking.gb28181.media.proxy;
|
||||
|
||||
import cn.skcks.docking.gb28181.common.json.JsonResponse;
|
||||
import cn.skcks.docking.gb28181.media.dto.config.ServerConfig;
|
||||
import cn.skcks.docking.gb28181.media.dto.response.ZlmResponse;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.service.annotation.GetExchange;
|
||||
@ -13,7 +14,7 @@ import java.util.List;
|
||||
public interface ZlmMediaHttpService {
|
||||
|
||||
@GetExchange("/index/api/getServerConfig")
|
||||
JsonResponse<List<ServerConfig>> getServerConfig(@RequestParam String secret);
|
||||
ZlmResponse<List<ServerConfig>> getServerConfig(@RequestParam String secret);
|
||||
|
||||
@GetExchange("/index/api/getServerConfig")
|
||||
ResponseEntity<String> getServerConfigResponseEntity(@RequestParam String secret);
|
||||
|
@ -6,6 +6,7 @@ import cn.hutool.core.date.ZoneUtil;
|
||||
import cn.skcks.docking.gb28181.common.json.JsonResponse;
|
||||
import cn.skcks.docking.gb28181.media.config.ZlmMediaConfig;
|
||||
import cn.skcks.docking.gb28181.media.dto.config.ServerConfig;
|
||||
import cn.skcks.docking.gb28181.media.dto.response.ZlmResponse;
|
||||
import cn.skcks.docking.gb28181.media.proxy.ZlmMediaHttpService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@ -40,8 +41,9 @@ public class MediaServiceTest {
|
||||
ResponseEntity<String> entity = zlMediaHttpService.getServerConfigResponseEntity(secret);
|
||||
log.info("{}", entity.getBody());
|
||||
|
||||
JsonResponse<List<ServerConfig>> test = zlMediaHttpService.getServerConfig(secret);
|
||||
ZlmResponse<List<ServerConfig>> test = zlMediaHttpService.getServerConfig(secret);
|
||||
log.info("{}", test);
|
||||
log.info("{}",test.getCode().getMsg());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user