Selaa lähdekoodia

add 基础信息配置

GITZYY 7 kuukautta sitten
vanhempi
commit
9bd3f28858

+ 52 - 0
egress-gateway-service-domain/src/main/java/com/hrsk/cloud/eg/domain/common/constant/ResultCode.java

@@ -0,0 +1,52 @@
+package com.hrsk.cloud.eg.domain.common.constant;
+
+public enum ResultCode {
+    // 全局
+    NO_LOGIN(-10,"未登录","未登录"),
+    GLOBAL_REQUEST_OK(0,"请求成功标志","请求成功"),
+    GLOBAL_REQUEST_FAIL(1,"请求失败标志","请求失败"),
+    GLOBAL_PARAM_MISSING(6,"全局参数缺失","不能为空"),
+    GLOBAL_VERIFICATION_ERROR(7,"验证码错误","验证码错误"),
+    GLOBAL_NOT_LOGIN(-130,"未登录标志","请先登录"),
+    GLOBAL_MISS_TOKEN(-130,"token缺失","请先登录"),
+    INFO_DOCUMENT_LIST(300,"暂无素材信息","暂无素材信息"),
+    INFO_FQA_LIST(310,"暂无问答信息","暂无问答信息"),
+    INFO_MSG_LIST(320,"暂无消息信息","暂无消息信息"),
+    INFO_USERFEEDBACK_LIST(340,"暂无意见反馈信息","暂无意见反馈信息"),
+    INFO_APPVERSIONLOG_LIST(350,"暂无APP更新日志信息","暂无APP更新日志信息"),
+    INFO_APPVERSION_LIST(330,"暂无版本更新信息","暂无版本更新信息"),
+    THIRDSERVER_REQUEST_EXCEPTION(100,"第三方接口连接异常","第三方接口连接异常"),
+    THIRDSERVER_RESPONSE_EXCEPTION(100,"第三方接口返回数据异常","第三方接口返回数据异常"),
+    OTHER_DATATYPE_FAIL(94,"数据类错误","数据类型错误"),
+    SYSTEM_EXCEPTION(999,"系统异常,请稍后再试","系统异常,请稍后再试"),
+    GLOBAL_REAL_EXISTS(201,"身份证已经被实名","请求失败"),
+    GLOBAL_REAL_MISMATCH(202,"姓名与身份证号不匹配","请求失败"),
+    GLOBAL_REAL_SERVICE(203,"实名认证接口异常","请求失败"),
+    GLOBAL_REAL_LOCK(204,"密码错误超过三次","密码输出错误锁定5分钟,请稍后再试"),
+    GLOBAL_GO_VERIFYSMS_LOGIN(205,"短信验证登录","短信验证登录"),
+    GLOBAL_INTERFACE_LIMIT(206,"接口访问频繁","接口访问太过频繁,请稍后再试")
+    ;
+    private int code;
+    private String description;
+    private String msg;
+
+    ResultCode(int code, String description, String msg) {
+        this.code = code;
+        this.description = description;
+        this.msg = msg;
+    }
+
+    public int getCode() {
+        return code;
+    }
+
+    public String getMsg() {
+        return msg;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+
+}

+ 83 - 0
egress-gateway-service-domain/src/main/java/com/hrsk/cloud/eg/domain/common/response/DefaultResponseVo.java

@@ -0,0 +1,83 @@
+package com.hrsk.cloud.eg.domain.common.response;
+
+import com.hrsk.cloud.eg.domain.common.constant.ResultCode;
+import org.apache.commons.lang3.StringUtils;
+
+import java.io.Serializable;
+
+/**
+ * Author: zhangyy
+ * Date: 2019/4/2
+ * Description: No Description
+ */
+public class DefaultResponseVo<T> implements Serializable {
+    private T data;
+
+    public T getData() {
+        return data;
+    }
+
+    public Integer code;
+
+    public String msg;
+
+    public String getMsg(){
+        return msg ;
+    }
+
+    public void setMsg(String msg){
+        this.msg = msg;
+    }
+
+    public Integer getCode(){
+       return code ;
+    }
+
+    public void setCode(Integer code){
+        this.code = code;
+    }
+
+    public void setData(T data) {
+        this.data = data;
+    }
+
+    public static DefaultResponseVo success(){
+        return createDefaultResponseVo(ResultCode.GLOBAL_REQUEST_OK.getCode(),"成功",null);
+    }
+    public static DefaultResponseVo success(String message){
+        return createDefaultResponseVo(ResultCode.GLOBAL_REQUEST_OK.getCode(),message,null);
+    }
+    public static <T> DefaultResponseVo<T> success(T data){
+        return createDefaultResponseVo(ResultCode.GLOBAL_REQUEST_OK.getCode(),"成功",data);
+    }
+    public static <T> DefaultResponseVo<T> success(String message, T object){
+        return createDefaultResponseVo(ResultCode.GLOBAL_REQUEST_OK.getCode(),message,object);
+    }
+
+    public static <T> DefaultResponseVo<T> fail(String message, T data){
+        return createDefaultResponseVo(ResultCode.GLOBAL_REQUEST_FAIL.getCode(),message,data);
+    }
+
+    public static DefaultResponseVo fail(String message){
+        return createDefaultResponseVo(ResultCode.GLOBAL_REQUEST_FAIL.getCode(),message,null);
+    }
+
+    public static DefaultResponseVo fail(int code,String message){
+        return createDefaultResponseVo(code,message,null);
+    }
+
+    public static DefaultResponseVo other(int code,String message){
+        return createDefaultResponseVo(code,message,null);
+    }
+
+    public static <T> DefaultResponseVo<T> createDefaultResponseVo(Integer code, String message, T data){
+        DefaultResponseVo<T> responseVo = new DefaultResponseVo<T>();
+        if(code!=null)
+            responseVo.setCode(code);
+        if(StringUtils.isNotBlank(message))
+            responseVo.setMsg(message);
+        if(data!=null)
+            responseVo.setData(data);
+        return responseVo;
+    }
+}

+ 80 - 0
egress-gateway-service-infrastructure/src/main/java/com/hrsk/cloud/eg/infrastructure/exception/ExceptionAdvice.java

@@ -0,0 +1,80 @@
+package com.hrsk.cloud.eg.infrastructure.exception;
+
+import com.hrsk.cloud.eg.domain.common.constant.ResultCode;
+import com.hrsk.cloud.eg.domain.common.response.DefaultResponseVo;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.boot.context.properties.bind.BindException;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.http.converter.HttpMessageNotReadableException;
+import org.springframework.web.HttpRequestMethodNotSupportedException;
+import org.springframework.web.bind.MethodArgumentNotValidException;
+import org.springframework.web.bind.ServletRequestBindingException;
+import org.springframework.web.bind.annotation.ControllerAdvice;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+
+import javax.validation.ConstraintViolationException;
+
+
+/**
+ * 全局异常处理器
+ */
+@ControllerAdvice
+@Slf4j
+public class ExceptionAdvice {
+
+    @ExceptionHandler(Exception.class)
+    public ResponseEntity<DefaultResponseVo> exception(Exception exception) {
+        DefaultResponseVo result = new DefaultResponseVo<>();
+        ResponseEntity<DefaultResponseVo> springResponse = handleSpringException(exception);
+        if (springResponse != null) {
+            return springResponse;
+        }
+
+        if (exception instanceof IllegalArgumentException) {
+            result.setCode(ResultCode.GLOBAL_REQUEST_FAIL.getCode());
+            result.setMsg(exception.getMessage());
+            return ResponseEntity.ok(result);
+        }
+        if (exception instanceof BindException) {
+            result.setCode(ResultCode.GLOBAL_REQUEST_FAIL.getCode());
+            result.setMsg(exception.getMessage());
+            return ResponseEntity.ok(result);
+        }
+        if (exception instanceof ConstraintViolationException) {
+            result.setCode(ResultCode.GLOBAL_REQUEST_FAIL.getCode());
+            result.setMsg(exception.getMessage());
+            return ResponseEntity.ok(result);
+        }
+        if (exception instanceof BindException) {
+            BindException bizException = (BindException) exception;
+            result.setCode(ResultCode.GLOBAL_REQUEST_FAIL.getCode());
+            result.setMsg(ResultCode.GLOBAL_REQUEST_FAIL.getMsg());
+            result.setData(null);
+            return ResponseEntity.ok(result);
+        }
+        if (exception instanceof MethodArgumentNotValidException) {
+            MethodArgumentNotValidException bindException = (MethodArgumentNotValidException) exception;
+            result.setCode(400);
+            result.setMsg(bindException.getBindingResult().getFieldError().getDefaultMessage());
+            result.setData(null);
+            return ResponseEntity.ok(result);
+        }
+        log.error("全局未知异常,异常信息:{}", exception.getMessage(), exception);
+        result = DefaultResponseVo.fail(ResultCode.GLOBAL_REQUEST_FAIL.getMsg());
+        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(result);
+    }
+
+    private ResponseEntity<DefaultResponseVo> handleSpringException(Exception exception) {
+        if (exception instanceof ServletRequestBindingException) {
+            return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(DefaultResponseVo.fail(exception.getMessage()));
+        }
+        if (exception instanceof HttpRequestMethodNotSupportedException) {
+            return ResponseEntity.status(HttpStatus.METHOD_NOT_ALLOWED).body(DefaultResponseVo.fail(exception.getMessage()));
+        }
+        if (exception instanceof HttpMessageNotReadableException) {
+            return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(DefaultResponseVo.fail(exception.getMessage()));
+        }
+        return null;
+    }
+}

+ 0 - 5
egress-gateway-service-infrastructure/src/test/java/com/hrsk/cloud/op/eg/repository/CustomerMapperTest.java

@@ -1,16 +1,11 @@
 package com.hrsk.cloud.op.eg.repository;
 
 
-import com.hrsk.cloud.eg.infrastructure.clinent.config.RetryRestTemplate;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
-import org.springframework.web.client.RestTemplate;
 
-import javax.annotation.Resource;
 
 
 /**