Ver código fonte

通用错误和不同系统的错误码分离

gaodm 6 anos atrás
pai
commit
bea6c2b877

+ 48 - 0
common/src/main/java/com/diagbot/exception/CommonErrorCode.java

@@ -0,0 +1,48 @@
+package com.diagbot.exception;
+
+/**
+ * @Description: 通用错误码
+ *      系统码(3位) + 等级码(1位) + 4位顺序号
+ *      系统码 通用码 000;用户中心 100; 管理中心 200;
+ * @author: gaodm
+ * @time: 2018/8/1 14:56
+ */
+public enum CommonErrorCode implements ErrorCode {
+
+    OK("0", "操作成功"),
+    FAIL("-1", "操作失败"),
+    RPC_ERROR("-2","远程调度失败"),
+    NOT_EXISTS ("00020001", "该数据不存在!"),
+    INSERT_DATA_FAILED("00020002", "数据库写入失败!"),
+    UPDATE_INFO_FAIL("00020003", "更新数据失败!"),
+    PARAM_IS_NULL("00020004", "传入的参数为空!"),
+    PARAM_IS_ERROR("00020005", "传入的参数为错误!"),
+    STATUS_IS_ERROR("00020006", "参数状态错误!");
+
+    private String code;
+    private String msg;
+
+
+    CommonErrorCode(String code, String msg) {
+        this.code = code;
+        this.msg = msg;
+    }
+
+
+    public String getCode() {
+        return code;
+    }
+
+    public String getMsg() {
+        return msg;
+    }
+
+    public static CommonErrorCode codeOf(String code) {
+        for (CommonErrorCode state : values()) {
+            if (state.getCode() == code) {
+                return state;
+            }
+        }
+        return null;
+    }
+}

+ 7 - 51
common/src/main/java/com/diagbot/exception/ErrorCode.java

@@ -1,59 +1,15 @@
 package com.diagbot.exception;
 
+import java.io.Serializable;
+
 /**
- * @Description: 通用错误码
- *      系统码(3位) + 等级码(1位) + 4位顺序号
- *      系统码 通用码 000;用户中心 100; 管理中心 200;
+ * @Description: 错误基础接口
  * @author: gaodm
- * @time: 2018/8/1 14:56
+ * @time: 2018/9/10 11:01
  */
-public enum ErrorCode {
-
-    OK("0", "操作成功"),
-    FAIL("-1", "操作失败"),
-    RPC_ERROR("-2","远程调度失败"),
-    NOT_EXISTS ("00020001", "该数据不存在!"),
-    INSERT_DATA_FAILED("00020002", "数据库写入失败!"),
-    UPDATE_INFO_FAIL("00020003", "更新数据失败!"),
-    PARAM_IS_NULL("00020004", "传入的参数为空!"),
-    PARAM_IS_ERROR("00020005", "传入的参数为错误!"),
-    STATUS_IS_ERROR("00020006", "参数状态错误!"),
-    VERIFYCODE_ERROR("00020007", "图片验证码生成错误!"),
-
-    USER_NOT_FOUND("10020000","用户不存在"),
-    USER_PASSWORD_ERROR("10020001","密码错误"),
-    GET_TOKEN_FAIL("10020002","获取token失败"),
-    TOKEN_IS_NOT_MATCH_USER("10020003","请使用自己的token进行接口请求"),
-
-    SMS_SEND_ERROR("10020004", "短信发送错误!"),
-    USER_BIND_ERROR("10020005", "用户手机号已经绑定无需再次验证!"),
-    USER_UN_BIND_ERROR("10020006", "用户手机号未绑定无需解绑!"),
-
-    LOG_IS_NOT_EXIST("90020001","该日志不存在");
-    private String code;
-    private String msg;
-
-
-    ErrorCode(String code, String msg) {
-        this.code = code;
-        this.msg = msg;
-    }
-
-
-    public String getCode() {
-        return code;
-    }
+public interface ErrorCode extends Serializable{
 
-    public String getMsg() {
-        return msg;
-    }
+    String getCode();
 
-    public static ErrorCode codeOf(String code) {
-        for (ErrorCode state : values()) {
-            if (state.getCode() == code) {
-                return state;
-            }
-        }
-        return null;
-    }
+    String getMsg();
 }

+ 39 - 0
diagbotman-service/src/main/java/com/diagbot/exception/ServiceErrorCode.java

@@ -0,0 +1,39 @@
+package com.diagbot.exception;
+
+/**
+ * @Description: 本服务错误码
+ *      系统码(3位) + 等级码(1位) + 4位顺序号
+ *      系统码 通用码 000;用户中心 100; 管理中心 200;
+ * @author: gaodm
+ * @time: 2018/9/10 11:11
+ */
+public enum ServiceErrorCode implements ErrorCode {
+    LOG_IS_NOT_EXIST("90020001","该日志不存在");
+
+    private String code;
+    private String msg;
+
+
+    ServiceErrorCode(String code, String msg) {
+        this.code = code;
+        this.msg = msg;
+    }
+
+
+    public String getCode() {
+        return code;
+    }
+
+    public String getMsg() {
+        return msg;
+    }
+
+    public static ServiceErrorCode codeOf(String code) {
+        for (ServiceErrorCode state : values()) {
+            if (state.getCode() == code) {
+                return state;
+            }
+        }
+        return null;
+    }
+}

+ 39 - 0
feedback-service/src/main/java/com/diagbot/exception/ServiceErrorCode.java

@@ -0,0 +1,39 @@
+package com.diagbot.exception;
+
+/**
+ * @Description: 本服务错误码
+ *      系统码(3位) + 等级码(1位) + 4位顺序号
+ *      系统码 通用码 000;用户中心 100; 管理中心 200;
+ * @author: gaodm
+ * @time: 2018/9/10 11:11
+ */
+public enum ServiceErrorCode implements ErrorCode {
+    LOG_IS_NOT_EXIST("90020001","该日志不存在");
+
+    private String code;
+    private String msg;
+
+
+    ServiceErrorCode(String code, String msg) {
+        this.code = code;
+        this.msg = msg;
+    }
+
+
+    public String getCode() {
+        return code;
+    }
+
+    public String getMsg() {
+        return msg;
+    }
+
+    public static ServiceErrorCode codeOf(String code) {
+        for (ServiceErrorCode state : values()) {
+            if (state.getCode() == code) {
+                return state;
+            }
+        }
+        return null;
+    }
+}

+ 39 - 0
knowledge-service/src/main/java/com/diagbot/exception/ServiceErrorCode.java

@@ -0,0 +1,39 @@
+package com.diagbot.exception;
+
+/**
+ * @Description: 本服务错误码
+ *      系统码(3位) + 等级码(1位) + 4位顺序号
+ *      系统码 通用码 000;用户中心 100; 管理中心 200;
+ * @author: gaodm
+ * @time: 2018/9/10 11:11
+ */
+public enum ServiceErrorCode implements ErrorCode {
+    LOG_IS_NOT_EXIST("90020001","该日志不存在");
+
+    private String code;
+    private String msg;
+
+
+    ServiceErrorCode(String code, String msg) {
+        this.code = code;
+        this.msg = msg;
+    }
+
+
+    public String getCode() {
+        return code;
+    }
+
+    public String getMsg() {
+        return msg;
+    }
+
+    public static ServiceErrorCode codeOf(String code) {
+        for (ServiceErrorCode state : values()) {
+            if (state.getCode() == code) {
+                return state;
+            }
+        }
+        return null;
+    }
+}

+ 39 - 0
log-service/src/main/java/com/diagbot/exception/ServiceErrorCode.java

@@ -0,0 +1,39 @@
+package com.diagbot.exception;
+
+/**
+ * @Description: 本服务错误码
+ *      系统码(3位) + 等级码(1位) + 4位顺序号
+ *      系统码 通用码 000;用户中心 100; 管理中心 200;
+ * @author: gaodm
+ * @time: 2018/9/10 11:11
+ */
+public enum ServiceErrorCode implements ErrorCode {
+    LOG_IS_NOT_EXIST("90020001","该日志不存在");
+
+    private String code;
+    private String msg;
+
+
+    ServiceErrorCode(String code, String msg) {
+        this.code = code;
+        this.msg = msg;
+    }
+
+
+    public String getCode() {
+        return code;
+    }
+
+    public String getMsg() {
+        return msg;
+    }
+
+    public static ServiceErrorCode codeOf(String code) {
+        for (ServiceErrorCode state : values()) {
+            if (state.getCode() == code) {
+                return state;
+            }
+        }
+        return null;
+    }
+}

+ 2 - 2
user-service/src/main/java/com/diagbot/config/AliyunConfigurer.java

@@ -6,7 +6,7 @@ import com.aliyuncs.exceptions.ClientException;
 import com.aliyuncs.profile.DefaultProfile;
 import com.aliyuncs.profile.IClientProfile;
 import com.diagbot.exception.CommonException;
-import com.diagbot.exception.ErrorCode;
+import com.diagbot.exception.ServiceErrorCode;
 import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
@@ -38,7 +38,7 @@ public class AliyunConfigurer {
             DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", aliyunConfig.getProduct(), aliyunConfig.getDomain());
         } catch (ClientException e){
             e.printStackTrace();
-            throw new CommonException(ErrorCode.SMS_SEND_ERROR);
+            throw new CommonException(ServiceErrorCode.SMS_SEND_ERROR);
         }
         return new DefaultAcsClient(profile);
     }

+ 47 - 0
user-service/src/main/java/com/diagbot/exception/ServiceErrorCode.java

@@ -0,0 +1,47 @@
+package com.diagbot.exception;
+
+/**
+ * @Description: 本服务错误码
+ *      系统码(3位) + 等级码(1位) + 4位顺序号
+ *      系统码 通用码 000;用户中心 100; 管理中心 200;
+ * @author: gaodm
+ * @time: 2018/9/10 11:11
+ */
+public enum ServiceErrorCode implements ErrorCode {
+    USER_NOT_FOUND("10020000","用户不存在"),
+    USER_PASSWORD_ERROR("10020001","密码错误"),
+    GET_TOKEN_FAIL("10020002","获取token失败"),
+    TOKEN_IS_NOT_MATCH_USER("10020003","请使用自己的token进行接口请求"),
+
+    SMS_SEND_ERROR("10020004", "短信发送错误!"),
+    USER_BIND_ERROR("10020005", "用户手机号已经绑定无需再次验证!"),
+    USER_UN_BIND_ERROR("10020006", "用户手机号未绑定无需解绑!"),
+    VERIFYCODE_ERROR("10020007", "图片验证码生成错误!");
+
+    private String code;
+    private String msg;
+
+
+    ServiceErrorCode(String code, String msg) {
+        this.code = code;
+        this.msg = msg;
+    }
+
+
+    public String getCode() {
+        return code;
+    }
+
+    public String getMsg() {
+        return msg;
+    }
+
+    public static ServiceErrorCode codeOf(String code) {
+        for (ServiceErrorCode state : values()) {
+            if (state.getCode() == code) {
+                return state;
+            }
+        }
+        return null;
+    }
+}

+ 4 - 4
user-service/src/main/java/com/diagbot/facade/UserFacade.java

@@ -6,7 +6,7 @@ import com.diagbot.dto.RespDTO;
 import com.diagbot.entity.JWT;
 import com.diagbot.entity.User;
 import com.diagbot.exception.CommonException;
-import com.diagbot.exception.ErrorCode;
+import com.diagbot.exception.ServiceErrorCode;
 import com.diagbot.service.impl.UserServiceImpl;
 import com.diagbot.util.UserUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -47,17 +47,17 @@ public class UserFacade extends UserServiceImpl {
     public RespDTO login(String username , String password){
         User user= this.findByName(username);
         if(null==user){
-            throw new CommonException(ErrorCode.USER_NOT_FOUND);
+            throw new CommonException(ServiceErrorCode.USER_NOT_FOUND);
         }
         PasswordEncoder passwordEncoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
         if(!passwordEncoder.matches(password,user.getPassword())){
-            throw new CommonException(ErrorCode.USER_PASSWORD_ERROR);
+            throw new CommonException(ServiceErrorCode.USER_PASSWORD_ERROR);
         }
 
         JWT jwt = authServiceClient.getToken("Basic dWFhLXNlcnZpY2U6MTIzNDU2", "password", username, password);
         // 获得用户菜单
         if(null==jwt){
-            throw new CommonException(ErrorCode.GET_TOKEN_FAIL);
+            throw new CommonException(ServiceErrorCode.GET_TOKEN_FAIL);
         }
         LoginDTO loginDTO=new LoginDTO();
         loginDTO.setUser(user);

+ 19 - 20
user-service/src/main/java/com/diagbot/facade/VerFacade.java

@@ -3,10 +3,10 @@ package com.diagbot.facade;
 import com.diagbot.dto.ImgVerCreatDTO;
 import com.diagbot.entity.ImgVerInfo;
 import com.diagbot.entity.SwsVerInfo;
-import com.diagbot.entity.User;
 import com.diagbot.enums.VisibleIdTypeEnum;
+import com.diagbot.exception.CommonErrorCode;
 import com.diagbot.exception.CommonException;
-import com.diagbot.exception.ErrorCode;
+import com.diagbot.exception.ServiceErrorCode;
 import com.diagbot.idc.VisibleIdCreater;
 import com.diagbot.service.ImgVerService;
 import com.diagbot.service.SmsVerService;
@@ -19,7 +19,6 @@ import com.diagbot.vo.SmsVerCreatVO;
 import com.diagbot.vo.SmsVerVerVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
-import springfox.documentation.annotations.ApiIgnore;
 
 /**
  * @Description: 用户验证业务层
@@ -70,23 +69,23 @@ public class VerFacade {
     public Boolean getSmsVerification(SmsVerCreatVO smsVerCreatVO){
         //参数验证
         if (null == smsVerCreatVO){
-            throw new CommonException(ErrorCode.PARAM_IS_NULL,
+            throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
                     "短信验证码创建信息不能为空!");
         }
         if (StringUtil.isBlank(smsVerCreatVO.getImgId())){
-            throw new CommonException(ErrorCode.PARAM_IS_NULL,
+            throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
                     "图片验证码唯一标志不能为空!");
         }
         if (StringUtil.isBlank(smsVerCreatVO.getCode())){
-            throw new CommonException(ErrorCode.PARAM_IS_NULL,
+            throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
                     "图片验证码不能为空!");
         }
         if (StringUtil.isBlank(smsVerCreatVO.getMobile())){
-            throw new CommonException(ErrorCode.PARAM_IS_NULL,
+            throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
                     "用户电话不能为空!");
         }
         if (!RegexValidateUtil.checkMobileNumber(smsVerCreatVO.getMobile())){
-            throw new CommonException(ErrorCode.PARAM_IS_ERROR,
+            throw new CommonException(CommonErrorCode.PARAM_IS_ERROR,
                     "用户电话格式错误!");
         }
         //验证图片验证码
@@ -97,7 +96,7 @@ public class VerFacade {
             //todo 验证该用户是否被注册
             Boolean isReg = false;
             if (isReg){
-                throw new CommonException(ErrorCode.PARAM_IS_ERROR, "该号码已经被注册!");
+                throw new CommonException(CommonErrorCode.PARAM_IS_ERROR, "该号码已经被注册!");
             }
 
             //验证是否超过两分钟
@@ -105,12 +104,12 @@ public class VerFacade {
             if (null != swsVerInfoCheck){
                 if (DateUtil.after(DateUtil.addMinutes(swsVerInfoCheck.getCreateTime(), 2),
                         DateUtil.now())){
-                    throw new CommonException(ErrorCode.SMS_SEND_ERROR,
+                    throw new CommonException(ServiceErrorCode.SMS_SEND_ERROR,
                             "同一用户两分钟之内不能重复发送验证短信,请两分钟之后再次发送!");
                 }
             }
         } else {
-            throw new CommonException(ErrorCode.PARAM_IS_ERROR, "图片验证码错误!");
+            throw new CommonException(CommonErrorCode.PARAM_IS_ERROR, "图片验证码错误!");
         }
 
         //发送短信
@@ -132,27 +131,27 @@ public class VerFacade {
     public Boolean verifySmsVerification(SmsVerVerVO smsVerVerVO){
         //参数验证
         if (null == smsVerVerVO){
-            throw new CommonException(ErrorCode.PARAM_IS_NULL,
+            throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
                     "短信验证码验证输入信息不能为空!");
         }
         if (StringUtil.isBlank(smsVerVerVO.getImgId())){
-            throw new CommonException(ErrorCode.PARAM_IS_NULL,
+            throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
                     "图片验证码唯一标志不能为空!");
         }
         if (StringUtil.isBlank(smsVerVerVO.getCode())){
-            throw new CommonException(ErrorCode.PARAM_IS_NULL,
+            throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
                     "图片验证码不能为空!");
         }
         if (StringUtil.isBlank(smsVerVerVO.getMobile())){
-            throw new CommonException(ErrorCode.PARAM_IS_NULL,
+            throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
                     "用户电话不能为空!");
         }
         if (StringUtil.isBlank(smsVerVerVO.getSmsCode())){
-            throw new CommonException(ErrorCode.PARAM_IS_NULL,
+            throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
                     "短信验证码不能为空!");
         }
         if (!RegexValidateUtil.checkMobileNumber(smsVerVerVO.getMobile())){
-            throw new CommonException(ErrorCode.PARAM_IS_ERROR,
+            throw new CommonException(CommonErrorCode.PARAM_IS_ERROR,
                     "用户电话格式错误!");
         }
         //验证图片验证码
@@ -163,10 +162,10 @@ public class VerFacade {
             //todo 验证该用户是否被注册
             Boolean isReg = false;
             if (isReg){
-                throw new CommonException(ErrorCode.PARAM_IS_ERROR, "该号码已经被注册!");
+                throw new CommonException(CommonErrorCode.PARAM_IS_ERROR, "该号码已经被注册!");
             }
         } else {
-            throw new CommonException(ErrorCode.PARAM_IS_ERROR, "图片验证码错误!");
+            throw new CommonException(CommonErrorCode.PARAM_IS_ERROR, "图片验证码错误!");
         }
         //验证用户短信信息
         SwsVerInfo swsVerInfo = new SwsVerInfo();
@@ -174,7 +173,7 @@ public class VerFacade {
         swsVerInfo.setCode(smsVerVerVO.getSmsCode());
         Boolean smsVer = smsVerService.verifySmsVerification(swsVerInfo);
         if (!smsVer){
-            throw new CommonException(ErrorCode.PARAM_IS_ERROR, "短信验证未通过!");
+            throw new CommonException(CommonErrorCode.PARAM_IS_ERROR, "短信验证未通过!");
         }
         //todo 将用户信息加入数据库
         Boolean registSuccess = true;

+ 10 - 10
user-service/src/main/java/com/diagbot/service/impl/ImgVerServiceImpl.java

@@ -2,7 +2,7 @@ package com.diagbot.service.impl;
 
 import com.diagbot.entity.ImgVerInfo;
 import com.diagbot.exception.CommonException;
-import com.diagbot.exception.ErrorCode;
+import com.diagbot.exception.CommonErrorCode;
 import com.diagbot.service.ImgVerService;
 import com.diagbot.util.DateUtil;
 import com.diagbot.util.StringUtil;
@@ -56,11 +56,11 @@ public class ImgVerServiceImpl implements ImgVerService {
     @Override
     public byte[] createImgVerification(ImgVerInfo imgVerInfo){
         if (null == imgVerInfo){
-            throw new CommonException(ErrorCode.PARAM_IS_NULL,
+            throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
                     "用户图片验证信息不能为空!");
         }
         if (StringUtil.isBlank(imgVerInfo.getImgId())){
-            throw new CommonException(ErrorCode.PARAM_IS_NULL,
+            throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
                     "图片验证码唯一标志不能为空!");
         }
         //生成图片验证码
@@ -97,15 +97,15 @@ public class ImgVerServiceImpl implements ImgVerService {
     @Override
     public Boolean verifyImgVerification(ImgVerInfo imgVerInfo){
         if (null == imgVerInfo){
-            throw new CommonException(ErrorCode.PARAM_IS_NULL,
+            throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
                     "用户图片验证信息不能为空!");
         }
         if (StringUtil.isBlank(imgVerInfo.getImgId())){
-            throw new CommonException(ErrorCode.PARAM_IS_NULL,
+            throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
                     "图片验证码唯一标志不能为空!");
         }
         if (StringUtil.isBlank(imgVerInfo.getCode())){
-            throw new CommonException(ErrorCode.PARAM_IS_NULL,
+            throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
                     "验证码不能为空!");
         }
         //从redis中取出
@@ -122,24 +122,24 @@ public class ImgVerServiceImpl implements ImgVerService {
         });
         if (imgVerInfoRes == null) {
             log.info("用户图片验证信息不存在!");
-            throw new CommonException(ErrorCode.NOT_EXISTS,
+            throw new CommonException(CommonErrorCode.NOT_EXISTS,
                     "用户图片验证信息不存在!");
         }
         //判断是否是想要的对象
         if (!imgVerInfoRes.getImgId().equals(imgVerInfo.getImgId())) {
             log.info("图片验证码唯一标志不一致!图片验证码唯一标志:{}", imgVerInfo.getImgId());
-            throw new CommonException(ErrorCode.PARAM_IS_ERROR,
+            throw new CommonException(CommonErrorCode.PARAM_IS_ERROR,
                     "图片验证码唯一标志不一致!");
         }
         if (!(imgVerInfoRes.getCode()).equals(imgVerInfo.getCode().toUpperCase())) {
             log.info("用户图片验证码不一致!验证码:{}", imgVerInfo.getCode());
-            throw new CommonException(ErrorCode.PARAM_IS_ERROR,
+            throw new CommonException(CommonErrorCode.PARAM_IS_ERROR,
                     "用户图片验证码不一致!");
         }
         //判断是否过期
         if (!DateUtil.after(imgVerInfoRes.getExpireTime(), DateUtil.now())) {
             log.info("图片验证码已过期,请重新获取!过期时间:{}", imgVerInfoRes.getExpireTime());
-            throw new CommonException(ErrorCode.PARAM_IS_ERROR,
+            throw new CommonException(CommonErrorCode.PARAM_IS_ERROR,
                     "图片验证码已过期,请重新获取!");
         }
         return true;

+ 15 - 14
user-service/src/main/java/com/diagbot/service/impl/SmsVerServiceImpl.java

@@ -4,8 +4,9 @@ import com.aliyuncs.IAcsClient;
 import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
 import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
 import com.diagbot.entity.SwsVerInfo;
+import com.diagbot.exception.CommonErrorCode;
 import com.diagbot.exception.CommonException;
-import com.diagbot.exception.ErrorCode;
+import com.diagbot.exception.ServiceErrorCode;
 import com.diagbot.service.SmsVerService;
 import com.diagbot.util.DateUtil;
 import com.diagbot.util.GsonUtil;
@@ -58,7 +59,7 @@ public class SmsVerServiceImpl implements SmsVerService {
 
     public String smsSend(String mobile,String smsTemplateCode){
         if (StringUtil.isBlank(mobile)){
-            throw new CommonException(ErrorCode.PARAM_IS_NULL,
+            throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
                     "电话号码不能为空!");
         }
 
@@ -86,11 +87,11 @@ public class SmsVerServiceImpl implements SmsVerService {
             SendSmsResponse rsp = acsClient.getAcsResponse(request);
             System.out.println(GsonUtil.toJson(rsp));
             if ((null == rsp) || !(rsp.getCode().equals("OK"))){
-                throw new CommonException(ErrorCode.SMS_SEND_ERROR);
+                throw new CommonException(ServiceErrorCode.SMS_SEND_ERROR);
             }
         } catch (Exception e) {
             e.printStackTrace();
-            throw new CommonException(ErrorCode.SMS_SEND_ERROR);
+            throw new CommonException(ServiceErrorCode.SMS_SEND_ERROR);
         }
         return code;
     }
@@ -101,15 +102,15 @@ public class SmsVerServiceImpl implements SmsVerService {
     @Override
     public Boolean createSmsVerification(SwsVerInfo swsVerInfo){
         if (null == swsVerInfo){
-            throw new CommonException(ErrorCode.PARAM_IS_NULL,
+            throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
                     "用户短信验证信息不能为空!");
         }
         if (StringUtil.isBlank(swsVerInfo.getMobile())){
-            throw new CommonException(ErrorCode.PARAM_IS_NULL,
+            throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
                     "用户电话不能为空!");
         }
         if (StringUtil.isBlank(swsVerInfo.getCode())){
-            throw new CommonException(ErrorCode.PARAM_IS_NULL,
+            throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
                     "验证码不能为空!");
         }
         swsVerInfo.setCreateTime(DateUtil.now());
@@ -143,15 +144,15 @@ public class SmsVerServiceImpl implements SmsVerService {
     @Override
     public Boolean verifySmsVerification(SwsVerInfo swsVerInfo){
         if (null == swsVerInfo){
-            throw new CommonException(ErrorCode.PARAM_IS_NULL,
+            throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
                     "用户短信验证信息不能为空!");
         }
         if (StringUtil.isBlank(swsVerInfo.getMobile())){
-            throw new CommonException(ErrorCode.PARAM_IS_NULL,
+            throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
                     "用户电话不能为空!");
         }
         if (StringUtil.isBlank(swsVerInfo.getCode())){
-            throw new CommonException(ErrorCode.PARAM_IS_NULL,
+            throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
                     "短信验证码不能为空!");
         }
         //从redis中取出
@@ -168,24 +169,24 @@ public class SmsVerServiceImpl implements SmsVerService {
         });
         if (swsVerInfoRes == null) {
             log.info("用户短信验证信息不存在!用户电话:{}", swsVerInfo.getMobile());
-            throw new CommonException(ErrorCode.NOT_EXISTS,
+            throw new CommonException(CommonErrorCode.NOT_EXISTS,
                     "用户短信验证信息不存在!");
         }
         //判断是否是想要的对象
         if (!swsVerInfoRes.getMobile().equals(swsVerInfo.getMobile())) {
             log.info("用户电话不一致! 用户电话:{}", swsVerInfo.getMobile());
-            throw new CommonException(ErrorCode.PARAM_IS_ERROR,
+            throw new CommonException(CommonErrorCode.PARAM_IS_ERROR,
                     "用户电话不一致!");
         }
         if (!swsVerInfoRes.getCode().equals(swsVerInfo.getCode())) {
             log.info("用户短信验证码不一致!用户电话:{},验证码:{}", swsVerInfo.getMobile(),swsVerInfo.getCode());
-            throw new CommonException(ErrorCode.PARAM_IS_ERROR,
+            throw new CommonException(CommonErrorCode.PARAM_IS_ERROR,
                     "用户短息验证码不一致!");
         }
         //判断是否过期
         if (!DateUtil.after(swsVerInfoRes.getExpireTime(), DateUtil.now())) {
             log.info("短息验证码已过期,请重新获取!用户电话:{},过期时间:{}", swsVerInfo.getMobile(), swsVerInfoRes.getExpireTime());
-            throw new CommonException(ErrorCode.PARAM_IS_ERROR,
+            throw new CommonException(CommonErrorCode.PARAM_IS_ERROR,
                     "短息验证码已过期,请重新获取!");
         }
         return true;

+ 2 - 2
user-service/src/main/java/com/diagbot/util/VerifyCodeUtils.java

@@ -1,7 +1,7 @@
 package com.diagbot.util;
 
 import com.diagbot.exception.CommonException;
-import com.diagbot.exception.ErrorCode;
+import com.diagbot.exception.ServiceErrorCode;
 
 import javax.imageio.ImageIO;
 import java.awt.*;
@@ -272,7 +272,7 @@ public class VerifyCodeUtils {
             outputImage(w, h, bos, verifyCode);
             return new Object[]{verifyCode, bos.toByteArray()};
         } catch (IOException e){
-            throw new CommonException(ErrorCode.VERIFYCODE_ERROR);
+            throw new CommonException(ServiceErrorCode.VERIFYCODE_ERROR);
         }
     }
 

+ 2 - 2
user-service/src/main/java/com/diagbot/web/UserController.java

@@ -4,8 +4,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.diagbot.annotation.SysLogger;
 import com.diagbot.dto.RespDTO;
 import com.diagbot.entity.User;
+import com.diagbot.exception.CommonErrorCode;
 import com.diagbot.exception.CommonException;
-import com.diagbot.exception.ErrorCode;
 import com.diagbot.facade.UserFacade;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -80,7 +80,7 @@ public class UserController {
     public RespDTO createUserTran(@RequestBody User user){
         //参数判读省略,判读该用户在数据库是否已经存在省略
         userFacade.createUser(user);
-        throw new CommonException(ErrorCode.FAIL);
+        throw new CommonException(CommonErrorCode.FAIL);
 //        return RespDTO.onSuc(user);
     }