mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-10 19:36:50 +08:00
接口替换-背水一战
This commit is contained in:
@@ -20,6 +20,7 @@ import com.boe.feign.api.usercenter.remote.AudienceRemoteClient;
|
|||||||
import com.boe.feign.api.usercenter.remote.UserRemoteClient;
|
import com.boe.feign.api.usercenter.remote.UserRemoteClient;
|
||||||
import com.boe.feign.api.usercenter.reps.AudienceMemberVo;
|
import com.boe.feign.api.usercenter.reps.AudienceMemberVo;
|
||||||
import com.boe.feign.api.usercenter.reps.Response;
|
import com.boe.feign.api.usercenter.reps.Response;
|
||||||
|
import com.xboe.api.infrastructure.res.InfraResult;
|
||||||
import com.xboe.api.vo.*;
|
import com.xboe.api.vo.*;
|
||||||
import com.xboe.common.PageList;
|
import com.xboe.common.PageList;
|
||||||
import com.xboe.common.Pagination;
|
import com.xboe.common.Pagination;
|
||||||
@@ -89,7 +90,7 @@ public class ThirdApi {
|
|||||||
searcher.setPid(316L);
|
searcher.setPid(316L);
|
||||||
searcher.setType(1);
|
searcher.setType(1);
|
||||||
List<Dict> dictList = dictRemoteClient.getList(searcher);
|
List<Dict> dictList = dictRemoteClient.getList(searcher);
|
||||||
String responseBody = JSON.toJSONString(dictList);
|
String responseBody = JSON.toJSONString(InfraResult.suc(dictList));
|
||||||
log.info("正在获取例外人员工号 responseBody = " + responseBody);
|
log.info("正在获取例外人员工号 responseBody = " + responseBody);
|
||||||
try {
|
try {
|
||||||
Optional<DictResult> dictResultOptional = Optional.of(responseBody)
|
Optional<DictResult> dictResultOptional = Optional.of(responseBody)
|
||||||
|
|||||||
@@ -0,0 +1,103 @@
|
|||||||
|
package com.xboe.api.infrastructure.res;
|
||||||
|
|
||||||
|
import com.boe.feign.api.courseweb.reps.MessageEnum;
|
||||||
|
import com.boe.feign.api.courseweb.reps.ResultStatus;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class InfraResult<T> implements Serializable {
|
||||||
|
|
||||||
|
private boolean isSuccess = true;
|
||||||
|
private boolean show = false;
|
||||||
|
private String version = "1.1.0";
|
||||||
|
private int code;
|
||||||
|
private String msg;
|
||||||
|
private T data;
|
||||||
|
|
||||||
|
public InfraResult() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public InfraResult(boolean isSuccess, int code, String msg) {
|
||||||
|
this.isSuccess = isSuccess;
|
||||||
|
this.code = code;
|
||||||
|
this.msg = msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InfraResult(boolean isSuccess, int code, String msg, T data) {
|
||||||
|
this.isSuccess = isSuccess;
|
||||||
|
this.code = code;
|
||||||
|
this.msg = msg;
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InfraResult(MessageEnum messageEnum) {
|
||||||
|
this.code = messageEnum.getCode();
|
||||||
|
this.msg = messageEnum.getMessage();
|
||||||
|
this.show = messageEnum.isShow();
|
||||||
|
}
|
||||||
|
|
||||||
|
public InfraResult(MessageEnum messageEnum, T data) {
|
||||||
|
this.code = messageEnum.getCode();
|
||||||
|
this.msg = messageEnum.getMessage();
|
||||||
|
this.show = messageEnum.isShow();
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InfraResult(boolean isSuccess, MessageEnum messageEnum) {
|
||||||
|
this.isSuccess = isSuccess;
|
||||||
|
this.code = messageEnum.getCode();
|
||||||
|
this.msg = messageEnum.getMessage();
|
||||||
|
this.show = messageEnum.isShow();
|
||||||
|
}
|
||||||
|
|
||||||
|
public InfraResult(boolean isSuccess, MessageEnum messageEnum, T data) {
|
||||||
|
this.isSuccess = isSuccess;
|
||||||
|
this.code = messageEnum.getCode();
|
||||||
|
this.msg = messageEnum.getMessage();
|
||||||
|
this.show = messageEnum.isShow();
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessageEnum(MessageEnum messageEnum) {
|
||||||
|
this.code = messageEnum.getCode();
|
||||||
|
this.msg = messageEnum.getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
public InfraResult(ResultStatus status, T data) {
|
||||||
|
this.code = status.getCode();
|
||||||
|
this.msg = status.getMessage();
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static InfraResult error(String message) {
|
||||||
|
return new InfraResult(true, -1, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static InfraResult error(MessageEnum messageEnum) {
|
||||||
|
return new InfraResult(messageEnum);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static InfraResult error(MessageEnum messageEnum, String errMsg) {
|
||||||
|
return new InfraResult(messageEnum,errMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static InfraResult error(ResultStatus error) {
|
||||||
|
return new InfraResult(error, new HashMap<>(20));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static InfraResult suc(Object data) {
|
||||||
|
return new InfraResult(ResultStatus.SUCCESS, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static InfraResult ok() {
|
||||||
|
return new InfraResult(ResultStatus.SUCCESS, new HashMap<>(20));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.xboe.config;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
//@Configuration
|
||||||
|
public class JacksonConfig {
|
||||||
|
|
||||||
|
// @Bean
|
||||||
|
// public ObjectMapper objectMapper() {
|
||||||
|
// ObjectMapper mapper = new ObjectMapper();
|
||||||
|
// mapper.registerModule(new JavaTimeModule());
|
||||||
|
// mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY,true);
|
||||||
|
// return mapper;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,11 +1,15 @@
|
|||||||
package com.xboe.config;
|
package com.xboe.config;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.http.converter.HttpMessageConverter;
|
import org.springframework.http.converter.HttpMessageConverter;
|
||||||
|
import org.springframework.http.converter.cbor.MappingJackson2CborHttpMessageConverter;
|
||||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
@@ -16,13 +20,19 @@ public class WebConfig implements WebMvcConfigurer {
|
|||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(WebConfig.class);
|
private static final Logger logger = LoggerFactory.getLogger(WebConfig.class);
|
||||||
|
|
||||||
|
|
||||||
//结果处理器
|
//结果处理器
|
||||||
@Bean
|
@Bean
|
||||||
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter(ObjectMapper objectMapper) {
|
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter(ObjectMapper objectMapper) {
|
||||||
return new LoggingMappingJackson2HttpMessageConverter(objectMapper);
|
return new LoggingMappingJackson2HttpMessageConverter(objectMapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ObjectMapper objectMapper() {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
mapper.registerModule(new JavaTimeModule());
|
||||||
|
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY,true);
|
||||||
|
return mapper;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 在默认的消息转换器基础上添加或移除某些转换器
|
* 在默认的消息转换器基础上添加或移除某些转换器
|
||||||
* 保证StringHttpMessageConverter在FastJsonHttpMessageConverter前被调用
|
* 保证StringHttpMessageConverter在FastJsonHttpMessageConverter前被调用
|
||||||
@@ -31,8 +41,8 @@ public class WebConfig implements WebMvcConfigurer {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
|
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||||
converters.removeIf(t -> t instanceof MappingJackson2HttpMessageConverter);
|
converters.removeIf(t -> t instanceof MappingJackson2HttpMessageConverter || t instanceof MappingJackson2CborHttpMessageConverter);
|
||||||
converters.add(mappingJackson2HttpMessageConverter(new ObjectMapper()));
|
converters.add(mappingJackson2HttpMessageConverter(objectMapper()));
|
||||||
for (HttpMessageConverter<?> converterLoop : converters) {
|
for (HttpMessageConverter<?> converterLoop : converters) {
|
||||||
logger.info("==######### Registered e message converter: {}", converterLoop.getClass().getName());
|
logger.info("==######### Registered e message converter: {}", converterLoop.getClass().getName());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user