响应类型包装
This commit is contained in:
parent
8a1e514aa0
commit
b083222690
@ -64,6 +64,17 @@
|
|||||||
<artifactId>springdoc-openapi-starter-common</artifactId>
|
<artifactId>springdoc-openapi-starter-common</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!--MapStruct-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mapstruct</groupId>
|
||||||
|
<artifactId>mapstruct</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mapstruct</groupId>
|
||||||
|
<artifactId>mapstruct-processor</artifactId>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
|
@ -14,12 +14,12 @@ public class ZlmResponse<T> {
|
|||||||
@Schema(title = "状态码")
|
@Schema(title = "状态码")
|
||||||
private ResponseStatus code;
|
private ResponseStatus code;
|
||||||
|
|
||||||
@Schema(title = "响应消息")
|
|
||||||
private String msg;
|
|
||||||
|
|
||||||
@Schema(title = "响应数据")
|
@Schema(title = "响应数据")
|
||||||
private T data;
|
private T data;
|
||||||
|
|
||||||
|
@Schema(title = "响应消息")
|
||||||
|
private String msg;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(){
|
public String toString(){
|
||||||
return JsonUtils.toJson(this);
|
return JsonUtils.toJson(this);
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
package cn.skcks.docking.gb28181.media.dto.response;
|
||||||
|
|
||||||
|
import cn.skcks.docking.gb28181.common.json.JsonResponse;
|
||||||
|
import cn.skcks.docking.gb28181.media.dto.status.ResponseStatus;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
default <T> ZlmResponse<T> toZlmResponse(JsonResponse<T> response){
|
||||||
|
return new ZlmResponse<>(ResponseStatus.fromCode(response.getCode()), response.getData(), response.getMsg());
|
||||||
|
}
|
||||||
|
}
|
@ -21,7 +21,7 @@ public enum ResponseStatus {
|
|||||||
private final String msg;
|
private final String msg;
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
public ResponseStatus fromCode(int code){
|
public static ResponseStatus fromCode(int code){
|
||||||
for (ResponseStatus status : values()) {
|
for (ResponseStatus status : values()) {
|
||||||
if (status.getCode() == code) {
|
if (status.getCode() == code) {
|
||||||
return status;
|
return status;
|
||||||
|
@ -7,6 +7,7 @@ import cn.skcks.docking.gb28181.common.json.JsonResponse;
|
|||||||
import cn.skcks.docking.gb28181.media.config.ZlmMediaConfig;
|
import cn.skcks.docking.gb28181.media.config.ZlmMediaConfig;
|
||||||
import cn.skcks.docking.gb28181.media.dto.config.ServerConfig;
|
import cn.skcks.docking.gb28181.media.dto.config.ServerConfig;
|
||||||
import cn.skcks.docking.gb28181.media.dto.response.ZlmResponse;
|
import cn.skcks.docking.gb28181.media.dto.response.ZlmResponse;
|
||||||
|
import cn.skcks.docking.gb28181.media.dto.response.ZlmResponseConvertor;
|
||||||
import cn.skcks.docking.gb28181.media.proxy.ZlmMediaHttpService;
|
import cn.skcks.docking.gb28181.media.proxy.ZlmMediaHttpService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@ -42,8 +43,12 @@ public class MediaServiceTest {
|
|||||||
log.info("{}", entity.getBody());
|
log.info("{}", entity.getBody());
|
||||||
|
|
||||||
ZlmResponse<List<ServerConfig>> test = zlMediaHttpService.getServerConfig(secret);
|
ZlmResponse<List<ServerConfig>> test = zlMediaHttpService.getServerConfig(secret);
|
||||||
log.info("{}", test);
|
JsonResponse<List<ServerConfig>> jsonResponse = ZlmResponseConvertor.INSTANCE.toJsonResponse(test);
|
||||||
log.info("{}",test.getCode().getMsg());
|
log.info("{}", jsonResponse);
|
||||||
|
|
||||||
|
ZlmResponse<List<ServerConfig>> zlmResponse = ZlmResponseConvertor.INSTANCE.toZlmResponse(jsonResponse);
|
||||||
|
log.info("{}", zlmResponse);
|
||||||
|
log.info("{}", zlmResponse.getCode().getMsg());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user