Эх сурвалжийг харах

添加异常枚举,统一自定义异常

tangfudong 2 жил өмнө
parent
commit
72af57de8e
39 өөрчлөгдсөн 372 нэмэгдсэн , 139 устгасан
  1. 5 3
      iot-common/src/main/java/cc/iotkit/common/ComponentClassLoader.java
  2. 103 0
      iot-common/src/main/java/cc/iotkit/common/enums/ErrCode.java
  3. 33 0
      iot-common/src/main/java/cc/iotkit/common/enums/IEnum.java
  4. 47 0
      iot-common/src/main/java/cc/iotkit/common/exception/BizException.java
  5. 5 0
      iot-components/iot-DLT645-component/pom.xml
  6. 2 1
      iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/DLT645Component.java
  7. 2 1
      iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/analysis/DLT645Converter.java
  8. 2 1
      iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/analysis/DLT645Data.java
  9. 3 1
      iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/analysis/DLT645DataFormat.java
  10. 3 1
      iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/analysis/DLT645V1997Data.java
  11. 4 3
      iot-components/iot-component-server/src/main/java/cc/iotkit/comps/BizComponentManager.java
  12. 8 7
      iot-components/iot-component-server/src/main/java/cc/iotkit/comps/DeviceComponentManager.java
  13. 8 7
      iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DeviceBehaviourService.java
  14. 2 1
      iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/cilent/TcpClientDeviceComponent.java
  15. 2 1
      iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/server/TcpServerDeviceComponent.java
  16. 5 5
      iot-components/iot-ctwing-component/src/main/java/cc/iotkit/comp/http/CtwingDeviceComponent.java
  17. 6 5
      iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/EmqxDeviceComponent.java
  18. 3 1
      iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/TransparentConverter.java
  19. 5 4
      iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/MqttDeviceComponent.java
  20. 2 1
      iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/MqttVerticle.java
  21. 4 2
      iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/TransparentConverter.java
  22. 5 0
      iot-components/iot-websocket-component/pom.xml
  23. 3 1
      iot-components/iot-websocket-component/src/main/java/cc/iotkit/comp/websocket/WebSocketDeviceComponent.java
  24. 4 3
      iot-components/iot-websocket-component/src/main/java/cc/iotkit/comp/websocket/client/WebSocketClientVerticle.java
  25. 2 1
      iot-components/iot-websocket-component/src/main/java/cc/iotkit/comp/websocket/server/WebSocketServerVerticle.java
  26. 10 9
      iot-data/iot-td-temporal-service/src/main/java/cc/iotkit/temporal/td/service/DbStructureDataImpl.java
  27. 3 2
      iot-message-bus/iot-message-rocketmq/src/main/java/cc/iotkit/rocketmq/RocketMqProducer.java
  28. 3 1
      iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/HttpService.java
  29. 2 1
      iot-rule-engine/src/main/java/cc/iotkit/ruleengine/task/TaskManager.java
  30. 11 10
      iot-standalone/src/main/java/cc/iotkit/manager/controller/DeviceController.java
  31. 3 2
      iot-standalone/src/main/java/cc/iotkit/manager/controller/ProductController.java
  32. 18 17
      iot-standalone/src/main/java/cc/iotkit/manager/controller/ProtocolController.java
  33. 12 11
      iot-standalone/src/main/java/cc/iotkit/manager/controller/RuleEngineController.java
  34. 5 4
      iot-standalone/src/main/java/cc/iotkit/manager/controller/SpaceController.java
  35. 13 12
      iot-standalone/src/main/java/cc/iotkit/manager/controller/SpaceDeviceController.java
  36. 10 9
      iot-standalone/src/main/java/cc/iotkit/manager/controller/UserInfoController.java
  37. 3 2
      iot-standalone/src/main/java/cc/iotkit/manager/controller/VirtualDeviceController.java
  38. 5 4
      iot-standalone/src/main/java/cc/iotkit/manager/service/DataOwnerService.java
  39. 6 5
      iot-standalone/src/main/java/cc/iotkit/manager/service/WeChatService.java

+ 5 - 3
iot-common/src/main/java/cc/iotkit/common/ComponentClassLoader.java

@@ -9,6 +9,8 @@
  */
 package cc.iotkit.common;
 
+import cc.iotkit.common.enums.ErrCode;
+import cc.iotkit.common.exception.BizException;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.StringUtils;
 
@@ -65,13 +67,13 @@ public class ComponentClassLoader {
     public static <T> T getComponent(String name, File jarFile) throws Exception {
         String className = addUrl(name, jarFile);
         if (StringUtils.isBlank(className)) {
-            throw new RuntimeException("component class does not exist");
+            throw new BizException(ErrCode.GET_SPI_COMPONENT_ERROR);
         }
         Class<T> componentClass = findClass(name, className);
         return componentClass.getDeclaredConstructor().newInstance();
     }
 
-    public static <T> T getConverter(String name, File jarFile) throws Exception {
+    public static <T> T getConverter(String name) throws Exception {
         URLClassLoader classLoader = classLoaders.get(name);
         InputStream is = classLoader.getResourceAsStream("convert.spi");
         if (is == null) {
@@ -81,7 +83,7 @@ public class ComponentClassLoader {
         //多行只取第1行,并处理空格
         String[] lines = IOUtils.toString(is, StandardCharsets.UTF_8).split("\\s");
         if (lines.length == 0) {
-            throw new RuntimeException("convert class does not exist");
+            throw new BizException(ErrCode.GET_SPI_CONVERT_ERROR);
         }
         String className = lines[0].trim();
         Class<T> converterClass = findClass(name, className);

+ 103 - 0
iot-common/src/main/java/cc/iotkit/common/enums/ErrCode.java

@@ -0,0 +1,103 @@
+package cc.iotkit.common.enums;
+
+/**
+ * @author :tfd
+ * 异常枚举类
+ *
+ */
+public enum ErrCode implements IEnum{
+    /**
+     * 系统通用异常段
+     * */
+    PARAMS_EXCEPTION(00000000, "参数异常"),
+    SYSTEM_EXCEPTION(00000000, "系统异常"),
+    UNKNOWN_EXCEPTION(00000000, "未知异常"),
+    SYSTEM_ERROR(00000000, "服务器内部错误"),
+    METHOD_NOT_ALLOWED(00000000, "请求方法不支持"),
+    NOT_FOUND(00000000, "请求资源不存在"),
+    FORBIDDEN(00000000, "请求被拒绝"),
+    UNAUTHORIZED_EXCEPTION(00000000, "未授权访问"),
+
+
+    /**
+     * 组件通用异常段
+     * */
+    GET_COMPONENT_INSTANCE_ERROR(00000000, "获取通讯组件实例失败"),
+    GET_COMPONENT_SCRIPT_ERROR(00000000, "获取通讯组件脚本失败"),
+    GET_CONVERT_ERROR(00000000, "获取转换器失败"),
+    GET_SPI_COMPONENT_ERROR(00000000, "获取组件CLASS失败"),
+    GET_SPI_CONVERT_ERROR(00000000, "获取转换器CLASS失败"),
+    COMPONENT_NOT_FOUND(00000000, "通讯组件不存在"),
+    SEND_DESTINATION_NOT_FOUND(00000000, "发送目标不存在"),
+    MSG_CONVERT_ERROR(00000000, "消息转换失败"),
+    DEVICE_REGISTER_ERROR(00000000, "设备注册失败"),
+    COMPONENT_ID_BLANK(00000000, "通讯组件ID为空"),
+    COMPONENT_JAR_NOT_FOUND(00000000, "通讯组件JAR包为空"),
+    COMPONENT_ALREADY(00000000, "通讯组件已经存在"),
+    SAVE_COMPONENT_SCRIPT_ERROR(00000000, "保存通讯组件脚本失败"),
+    SAVE_CONVERT_SCRIPT_ERROR(00000000, "保存转换器脚本失败"),
+    ADD_COMPONENT_ERROR(00000000, "添加通讯组件失败"),
+    ADD_CONVERT_ERROR(00000000, "添加转换器失败"),
+    CONVERT_NOT_FOUND(00000000, "转换器不存在"),
+    DELETE_CONVERT_ERROR(00000000, "删除转换器失败"),
+    DELETE_COMPONENT_ERROR(00000000, "删除通讯组件失败"),
+    PRODUCT_SECRET_ERROR(00000000, "产品密钥错误"),
+    COMPONENT_START_ERROR(00000000, "通讯组件启动失败"),
+    INIT_PRODUCER_ERROR(00000000, "初始化MQ生产者失败"),
+    SEND_MSG_ERROR(00000000, "发送消息失败"),
+
+
+    /**
+     * 业务通用异常段
+     * */
+    TASK_NOT_SUPPORT_RENEW(00000000, "任务不支持续订"),
+    GROUP_ALREADY(00000000, "分组已经存在"),
+    GROUP_NOT_FOUND(00000000, "分组不存在"),
+    PRODUCT_NOT_FOUND(00000000, "产品不存在"),
+    DEVICE_NOT_FOUND(00000000, "设备不存在"),
+    DEVICE_OFFLINE(00000000, "设备已离线"),
+    DEVICE_ALREADY(00000000, "设备已存在"),
+    MODEL_ALREADY(00000000, "型号已存在"),
+    MODEL_SCRIPT_NOT_FOUND(00000000, "产品型号脚本不存在"),
+    PRODUCT_MODEL_NOT_FOUND(00000000, "产品型号不存在"),
+    FILE_NOT_FOUND(00000000, "文件不存在"),
+    RULE_NOT_FOUND(00000000, "规则不存在"),
+    RULE_ALREADY_RUNNING(00000000, "规则已运行"),
+    SEND_REQUEST_ERROR(00000000, "发送请求失败"),
+    TASK_NOT_FOUND(00000000, "任务不存在"),
+    RENEW_TASK_ERROR(00000000, "重启任务失败"),
+    HOME_NOT_FOUND(00000000, "家庭不存在"),
+    CURRENT_HOME_NOT_FOUND(00000000, "当前家庭不存在"),
+    SPACE_NOT_FOUND(00000000, "空间不存在"),
+    SPACE_DEVICE_NOT_FOUND(00000000, "空间设备不存在"),
+    DATA_BLANK(00000000, "数据为空"),
+    DATA_LENGTH_ERROR(00000000, "数据长度错误"),
+    DATA_FORMAT_ERROR(00000000, "数据格式错误"),
+    USER_NOT_FOUND(00000000, "用户不存在"),
+    RESET_PWD_ERROR(00000000, "重置密码失败"),
+    UPDATE_PWD_ERROR(00000000, "修改密码失败"),
+    PWD_ERROR(00000000, "密码错误"),
+    STATE_ERROR(00000000, "状态错误"),
+    RECORD_NOT_FOUND(00000000, "记录不存在"),
+    ADD_PLATFORM_USER_ERROR(00000000, "添加平台用户失败"),
+    UPLOAD_FILE_ERROR(00000000, "上传文件失败");
+
+
+    private int code;
+    private String message;
+
+    ErrCode(int code, String message) {
+        this.code = code;
+        this.message = message;
+    }
+
+    @Override
+    public Integer getKey() {
+        return this.code;
+    }
+
+    @Override
+    public String getValue() {
+        return this.message;
+    }
+}

+ 33 - 0
iot-common/src/main/java/cc/iotkit/common/enums/IEnum.java

@@ -0,0 +1,33 @@
+package cc.iotkit.common.enums;
+
+public interface IEnum {
+    /**
+     * 获取枚举的key
+     */
+    Integer getKey();
+
+    /**
+     * 获取枚举的下标
+     */
+    String getValue();
+
+    /**
+     * 将参数反序列化为枚举
+     *
+     * @param param 当前值
+     * @param clazz 枚举类型
+     */
+    static <T extends Enum<T> & IEnum> T parse(Integer param, Class<T> clazz) {
+        if (param == null || clazz == null) {
+            return null;
+        }
+        T[] enums = clazz.getEnumConstants();
+        for (T t : enums) {
+            Integer key = t.getKey();
+            if (key.equals(param)) {
+                return t;
+            }
+        }
+        return null;
+    }
+}

+ 47 - 0
iot-common/src/main/java/cc/iotkit/common/exception/BizException.java

@@ -9,8 +9,13 @@
  */
 package cc.iotkit.common.exception;
 
+import cc.iotkit.common.enums.ErrCode;
+
 public class BizException extends RuntimeException{
 
+    private int code;
+    private String message;
+
     public BizException() {
     }
 
@@ -18,6 +23,31 @@ public class BizException extends RuntimeException{
         super(message);
     }
 
+    /**
+     * 统一异常消息处理
+     *
+     * @param ErrCode 异常枚举值
+     */
+    public BizException(ErrCode ErrCode) {
+        this.message = ErrCode.getValue();
+    }
+
+    public BizException(ErrCode ErrCode, Throwable cause) {
+        super(cause);
+        this.message = ErrCode.getValue();
+    }
+
+    /**
+     * 自定义异常消息处理
+     *
+     * @param code
+     * @param message
+     */
+    public BizException(int code, String message) {
+        this.code = code;
+        this.message = message;
+    }
+
     public BizException(String message, Throwable cause) {
         super(message, cause);
     }
@@ -25,4 +55,21 @@ public class BizException extends RuntimeException{
     public BizException(Throwable cause) {
         super(cause);
     }
+
+    public int getCode() {
+        return code;
+    }
+
+    public void setCode(int code) {
+        this.code = code;
+    }
+
+    @Override
+    public String getMessage() {
+        return message;
+    }
+
+    public void setMessage(String message) {
+        this.message = message;
+    }
 }

+ 5 - 0
iot-components/iot-DLT645-component/pom.xml

@@ -28,6 +28,11 @@
             <artifactId>iot-component-base</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>cc.iotkit</groupId>
+            <artifactId>iot-common</artifactId>
+        </dependency>
+
         <dependency>
             <groupId>cn.hutool</groupId>
             <artifactId>hutool-core</artifactId>

+ 2 - 1
iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/DLT645Component.java

@@ -9,6 +9,7 @@
  */
 package cc.iotkit.comp.DLT645;
 
+import cc.iotkit.common.enums.ErrCode;
 import cc.iotkit.common.exception.BizException;
 import cc.iotkit.common.utils.JsonUtil;
 import cc.iotkit.comp.AbstractDeviceComponent;
@@ -63,7 +64,7 @@ public class DLT645Component extends AbstractDeviceComponent {
             countDownLatch.await();
             future.succeeded();
         } catch (Throwable e) {
-            throw new BizException("start GLT645 component error", e);
+            throw new BizException(ErrCode.COMPONENT_START_ERROR, e);
         }
     }
 

+ 2 - 1
iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/analysis/DLT645Converter.java

@@ -1,5 +1,6 @@
 package cc.iotkit.comp.DLT645.analysis;
 
+import cc.iotkit.common.exception.BizException;
 import cc.iotkit.common.thing.ThingService;
 import cc.iotkit.common.utils.JsonUtil;
 import cc.iotkit.common.utils.UniqueIdUtil;
@@ -83,7 +84,7 @@ public class DLT645Converter implements IConverter {
         // 根据对象名获取对象格式信息,这个格式信息,记录在CSV文件中
         DLT645Data dataEntity = DLT645Analysis.inst().getTemplateByDIn().get(dataIdentifier);
         if (dataEntity == null) {
-            throw new RuntimeException("CSV模板文件中未定义对象:" + dataIdentifier + " ,你需要在模板中添加该对象信息");
+            throw new BizException("CSV模板文件中未定义对象:" + dataIdentifier + " ,你需要在模板中添加该对象信息");
         }
         byte byFun = Byte.decode(String.valueOf(DLT645FunCode.getCodev1997(funCode)));
 

+ 2 - 1
iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/analysis/DLT645Data.java

@@ -1,5 +1,6 @@
 package cc.iotkit.comp.DLT645.analysis;
 
+import cc.iotkit.common.exception.BizException;
 import lombok.Data;
 
 import java.util.Map;
@@ -64,7 +65,7 @@ public abstract class DLT645Data {
         // 获取字典信息
         DLT645Data dict = dinMap.get(this.getKey());
         if (dict == null) {
-            throw new RuntimeException("DIn info err,please configure:" + this.getKey());
+            throw new BizException("DIn info err,please configure:" + this.getKey());
         }
 
         this.format = dict.format;

+ 3 - 1
iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/analysis/DLT645DataFormat.java

@@ -1,5 +1,7 @@
 package cc.iotkit.comp.DLT645.analysis;
 
+import cc.iotkit.common.enums.ErrCode;
+import cc.iotkit.common.exception.BizException;
 import cc.iotkit.comp.DLT645.utils.ByteUtils;
 import lombok.Data;
 
@@ -57,7 +59,7 @@ public class DLT645DataFormat {
     public Object decodeValue(byte[] data, String format, int start, int length) throws RuntimeException {
         // 前面4个字节是DI0~DI3
         if (data.length < length + start) {
-            throw new RuntimeException("数据长度不正确!");
+            throw new BizException(ErrCode.DATA_LENGTH_ERROR);
         }
 
         // 各种XX.XX格式

+ 3 - 1
iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/analysis/DLT645V1997Data.java

@@ -1,5 +1,7 @@
 package cc.iotkit.comp.DLT645.analysis;
 
+import cc.iotkit.common.enums.ErrCode;
+import cc.iotkit.common.exception.BizException;
 import lombok.Getter;
 import lombok.Setter;
 
@@ -35,7 +37,7 @@ public class DLT645V1997Data extends DLT645Data {
     @Override
     public void setDIn(byte[] value) {
         if (value.length < 2) {
-            throw new RuntimeException("数据长度小于2字节!");
+            throw new BizException(ErrCode.DATA_LENGTH_ERROR);
         }
 
         // DI值

+ 4 - 3
iot-components/iot-component-server/src/main/java/cc/iotkit/comps/BizComponentManager.java

@@ -11,6 +11,7 @@ package cc.iotkit.comps;
 
 
 import cc.iotkit.common.ComponentClassLoader;
+import cc.iotkit.common.enums.ErrCode;
 import cc.iotkit.common.exception.BizException;
 import cc.iotkit.comp.CompConfig;
 import cc.iotkit.comp.IComponent;
@@ -68,7 +69,7 @@ public class BizComponentManager {
         Path path = componentConfig.getComponentFilePath(id);
         File file = path.resolve(component.getJarFile()).toAbsolutePath().toFile();
         if (!file.exists()) {
-            throw new BizException("jar file:" + file.getAbsolutePath() + " not found");
+            throw new BizException(ErrCode.FILE_NOT_FOUND);
         }
 
         IComponent componentInstance;
@@ -76,7 +77,7 @@ public class BizComponentManager {
             componentInstance = ComponentClassLoader.getComponent(component.getId(), file);
         } catch (Throwable e) {
             ComponentClassLoader.closeClassLoader(component.getId());
-            throw new BizException("get component instance error");
+            throw new BizException(ErrCode.GET_COMPONENT_INSTANCE_ERROR,e);
         }
         try {
             String componentScript = FileUtils.readFileToString(path.
@@ -85,7 +86,7 @@ public class BizComponentManager {
             componentInstance.putScriptEnv("deviceBehaviour", deviceBehaviourService);
             componentInstance.putScriptEnv("apiTool", new ApiTool());
         } catch (IOException e) {
-            throw new BizException("get component script error", e);
+            throw new BizException(ErrCode.GET_COMPONENT_SCRIPT_ERROR,e);
         }
         componentInstance.create(new CompConfig(300, component.getConfig()));
 

+ 8 - 7
iot-components/iot-component-server/src/main/java/cc/iotkit/comps/DeviceComponentManager.java

@@ -11,6 +11,7 @@ package cc.iotkit.comps;
 
 
 import cc.iotkit.common.ComponentClassLoader;
+import cc.iotkit.common.enums.ErrCode;
 import cc.iotkit.common.exception.BizException;
 import cc.iotkit.common.thing.ThingService;
 import cc.iotkit.common.utils.JsonUtil;
@@ -106,7 +107,7 @@ public class DeviceComponentManager {
         try {
             componentInstance = ComponentClassLoader.getComponent(component.getId(), file);
         } catch (Throwable e) {
-            throw new BizException("get device component instance error", e);
+            throw new BizException(ErrCode.GET_COMPONENT_INSTANCE_ERROR, e);
         }
         componentInstance.create(new CompConfig(300, component.getConfig()));
 
@@ -114,9 +115,9 @@ public class DeviceComponentManager {
             if(component.CONVER_TYPE_STATIC.equals(component.getConverType())){
                 IConverter converterInstance;
                 try {
-                    converterInstance=ComponentClassLoader.getConverter(component.getId(), file);
+                    converterInstance=ComponentClassLoader.getConverter(component.getId());
                 } catch (Throwable e) {
-                    throw new BizException("get device convert instance error", e);
+                    throw new BizException(ErrCode.GET_SPI_CONVERT_ERROR, e);
                 }
                 componentInstance.setConverter(converterInstance);
             }else{
@@ -129,7 +130,7 @@ public class DeviceComponentManager {
             componentInstance.setScript(componentScript);
             register(id, componentInstance);
         } catch (IOException e) {
-            throw new BizException("get device component script error", e);
+            throw new BizException(ErrCode.GET_COMPONENT_SCRIPT_ERROR, e);
         }
     }
 
@@ -200,7 +201,7 @@ public class DeviceComponentManager {
     public void send(ThingService<?> service) {
         log.info("start exec device service:{}", JsonUtil.toJsonString(service));
         if (components.size() == 0) {
-            throw new BizException("there is no components");
+            throw new BizException(ErrCode.COMPONENT_NOT_FOUND);
         }
 
         DeviceInfo deviceInfo = deviceInfoData.findByProductKeyAndDeviceName(service.getProductKey(), service.getDeviceName());
@@ -217,7 +218,7 @@ public class DeviceComponentManager {
 
         IComponent component = deviceRouter.getRouter(linkPk, linkDn);
         if (!(component instanceof IDeviceComponent)) {
-            throw new BizException("send destination does not exist");
+            throw new BizException(ErrCode.SEND_DESTINATION_NOT_FOUND);
         }
         IDeviceComponent deviceComponent = (IDeviceComponent) component;
 
@@ -233,7 +234,7 @@ public class DeviceComponentManager {
         //对下发消息进行编码转换
         DeviceMessage message = deviceComponent.getConverter().encode(service, device);
         if (message == null) {
-            throw new BizException("encode send message failed");
+            throw new BizException(ErrCode.MSG_CONVERT_ERROR);
         }
 
         String sendMid = message.getMid();

+ 8 - 7
iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DeviceBehaviourService.java

@@ -10,6 +10,7 @@
 package cc.iotkit.comps.service;
 
 import cc.iotkit.common.Constants;
+import cc.iotkit.common.enums.ErrCode;
 import cc.iotkit.common.exception.BizException;
 import cc.iotkit.common.utils.DeviceUtil;
 import cc.iotkit.common.utils.JsonUtil;
@@ -17,8 +18,8 @@ import cc.iotkit.common.utils.UniqueIdUtil;
 import cc.iotkit.comp.model.DeviceState;
 import cc.iotkit.comp.model.RegisterInfo;
 import cc.iotkit.data.IDeviceInfoData;
-import cc.iotkit.data.IProductModelData;
 import cc.iotkit.data.IProductData;
+import cc.iotkit.data.IProductModelData;
 import cc.iotkit.model.device.DeviceInfo;
 import cc.iotkit.model.device.message.ThingModelMessage;
 import cc.iotkit.model.product.Product;
@@ -69,7 +70,7 @@ public class DeviceBehaviourService {
             throw e;
         } catch (Throwable e) {
             log.error("register device error", e);
-            throw new BizException("register device error", e);
+            throw new BizException(ErrCode.DEVICE_REGISTER_ERROR, e);
         }
     }
 
@@ -84,7 +85,7 @@ public class DeviceBehaviourService {
             if (StringUtils.isBlank(pk) && StringUtils.isNotBlank(model)) {
                 ProductModel productModel = productModelData.findByModel(model);
                 if (productModel == null) {
-                    throw new BizException("product model does not exist");
+                    throw new BizException(ErrCode.PRODUCT_MODEL_NOT_FOUND);
                 }
                 pk = productModel.getProductKey();
             }
@@ -92,7 +93,7 @@ public class DeviceBehaviourService {
 
         Product product = productData.findById(pk);
         if (product == null) {
-            throw new BizException("Product does not exist");
+            throw new BizException(ErrCode.PRODUCT_NOT_FOUND);
         }
         String uid = product.getUid();
         DeviceInfo device = deviceInfoData.findByProductKeyAndDeviceName(pk, info.getDeviceName());
@@ -158,10 +159,10 @@ public class DeviceBehaviourService {
                            String deviceSecret) {
         DeviceInfo deviceInfo = deviceInfoData.findByProductKeyAndDeviceName(productKey, deviceName);
         if (deviceInfo == null) {
-            throw new BizException("device does not exist");
+            throw new BizException(ErrCode.DEVICE_NOT_FOUND);
         }
         if (!Constants.PRODUCT_SECRET.equals(productSecret)) {
-            throw new BizException("incorrect productSecret");
+            throw new BizException(ErrCode.PRODUCT_SECRET_ERROR);
         }
 
         //todo 按产品ProductSecret认证,子设备需要父设备认证后可通过验证
@@ -189,7 +190,7 @@ public class DeviceBehaviourService {
         DeviceInfo device = deviceInfoData.findByProductKeyAndDeviceName(productKey, deviceName);
         if (device == null) {
             log.warn("productKey: {},deviceName:{},online: {}", productKey, deviceName, online);
-            throw new BizException("device does not exist");
+            throw new BizException(ErrCode.DEVICE_NOT_FOUND);
         }
         deviceStateChange(device, online);
 

+ 2 - 1
iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/cilent/TcpClientDeviceComponent.java

@@ -1,5 +1,6 @@
 package cc.iotkit.comp.tcp.cilent;
 
+import cc.iotkit.common.enums.ErrCode;
 import cc.iotkit.common.exception.BizException;
 import cc.iotkit.common.utils.JsonUtil;
 import cc.iotkit.comp.AbstractDeviceComponent;
@@ -43,7 +44,7 @@ public class TcpClientDeviceComponent extends AbstractDeviceComponent {
                     }));
             future.succeeded();
         } catch (Throwable e) {
-            throw new BizException("start client component error", e);
+            throw new BizException(ErrCode.COMPONENT_START_ERROR, e);
         }
 
     }

+ 2 - 1
iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/server/TcpServerDeviceComponent.java

@@ -1,5 +1,6 @@
 package cc.iotkit.comp.tcp.server;
 
+import cc.iotkit.common.enums.ErrCode;
 import cc.iotkit.common.exception.BizException;
 import cc.iotkit.common.utils.JsonUtil;
 import cc.iotkit.comp.AbstractDeviceComponent;
@@ -44,7 +45,7 @@ public class TcpServerDeviceComponent extends AbstractDeviceComponent {
                     }));
             future.succeeded();
         }catch (Throwable e){
-            throw new BizException("start tcpserver component error", e);
+            throw new BizException(ErrCode.COMPONENT_START_ERROR, e);
         }
 
     }

+ 5 - 5
iot-components/iot-ctwing-component/src/main/java/cc/iotkit/comp/http/CtwingDeviceComponent.java

@@ -103,13 +103,13 @@ public class CtwingDeviceComponent extends AbstractDeviceComponent {
     public DeviceMessage send(DeviceMessage message) {
         Object obj = message.getContent();
         if (!(obj instanceof Map)) {
-            throw new BizException("message content is not Map");
+            throw new BizException(ErrCode.DATA_FORMAT_ERROR);
         }
         SendContent msg = new SendContent();
         try {
             BeanUtils.populate(msg, (Map<String, ? extends Object>) obj);
         } catch (Throwable e) {
-            throw new BizException("message content is incorrect");
+            throw new BizException(ErrCode.DATA_FORMAT_ERROR);
         }
 
         CreateCommandRequest request = new CreateCommandRequest();
@@ -129,18 +129,18 @@ public class CtwingDeviceComponent extends AbstractDeviceComponent {
         try {
             response = commandClient.CreateCommand(request);
         } catch (Exception e) {
-            throw new RuntimeException("send cmd to ctwing error", e);
+            throw new BizException("send cmd to ctwing error", e);
         }
 
         String body = new String(response.getBody());
         log.info("send ctwing cmd result:{}", body);
         if (response.getStatusCode() != 200) {
-            throw new RuntimeException("send cmd to ctwing error:" + body);
+            throw new BizException("send cmd to ctwing error:" + body);
         }
 
         CtwingCmdRsp cmdRsp = JsonUtil.parse(body, CtwingCmdRsp.class);
         if (cmdRsp.code != 0) {
-            throw new RuntimeException("send cmd to ctwing failed:" + body);
+            throw new BizException("send cmd to ctwing failed:" + body);
         }
 
         return message;

+ 6 - 5
iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/EmqxDeviceComponent.java

@@ -9,7 +9,9 @@
  */
 package cc.iotkit.comp.emqx;
 
+import cc.iotkit.common.enums.ErrCode;
 import cc.iotkit.common.exception.BizException;
+import cc.iotkit.common.thing.ThingService;
 import cc.iotkit.common.utils.JsonUtil;
 import cc.iotkit.common.utils.ThreadUtil;
 import cc.iotkit.comp.AbstractDeviceComponent;
@@ -18,7 +20,6 @@ import cc.iotkit.comp.IMessageHandler;
 import cc.iotkit.comp.model.DeviceState;
 import cc.iotkit.comp.utils.SpringUtils;
 import cc.iotkit.converter.DeviceMessage;
-import cc.iotkit.common.thing.ThingService;
 import cc.iotkit.data.IDeviceInfoData;
 import cc.iotkit.model.device.DeviceInfo;
 import cc.iotkit.model.device.message.ThingModelMessage;
@@ -88,7 +89,7 @@ public class EmqxDeviceComponent extends AbstractDeviceComponent implements Runn
 
             emqxConnectTask.scheduleWithFixedDelay(this, 0, 3, TimeUnit.SECONDS);
         } catch (Throwable e) {
-            throw new BizException("start emqx auth component error", e);
+            throw new BizException(ErrCode.COMPONENT_START_ERROR, e);
         }
     }
 
@@ -166,7 +167,7 @@ public class EmqxDeviceComponent extends AbstractDeviceComponent implements Runn
             }).exceptionHandler(event -> log.error("client fail", event));
 
         } catch (Throwable e) {
-            throw new BizException("start emqx component error", e);
+            throw new BizException(ErrCode.COMPONENT_START_ERROR, e);
         }
     }
 
@@ -218,14 +219,14 @@ public class EmqxDeviceComponent extends AbstractDeviceComponent implements Runn
     public DeviceMessage send(DeviceMessage message) {
         Object obj = message.getContent();
         if (!(obj instanceof Map)) {
-            throw new BizException("message content is not Map");
+            throw new BizException(ErrCode.DATA_FORMAT_ERROR);
         }
         Message msg = new Message();
         try {
             //obj中的key,如果bean中有这个属性,就把这个key对应的value值赋给msg的属性
             BeanUtils.populate(msg, (Map<String, ? extends Object>) obj);
         } catch (Throwable e) {
-            throw new BizException("message content is incorrect");
+            throw new BizException(ErrCode.DATA_FORMAT_ERROR);
         }
 
         log.info("publish topic:{},payload:{}", msg.getTopic(), msg.getPayload());

+ 3 - 1
iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/TransparentConverter.java

@@ -10,6 +10,8 @@
 package cc.iotkit.comp.emqx;
 
 
+import cc.iotkit.common.enums.ErrCode;
+import cc.iotkit.common.exception.BizException;
 import cc.iotkit.common.thing.ThingService;
 import cc.iotkit.comp.utils.SpringUtils;
 import cc.iotkit.converter.Device;
@@ -96,7 +98,7 @@ public class TransparentConverter {
             productModel = getScript(ProductModel.getDefaultModel(pk));
         }
         if (productModel == null) {
-            throw new RuntimeException("product model script does not exist");
+            throw new BizException(ErrCode.MODEL_SCRIPT_NOT_FOUND);
         }
 
         String productKey = productModel.getProductKey();

+ 5 - 4
iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/MqttDeviceComponent.java

@@ -9,13 +9,14 @@
  */
 package cc.iotkit.comp.mqtt;
 
+import cc.iotkit.common.enums.ErrCode;
 import cc.iotkit.common.exception.BizException;
+import cc.iotkit.common.thing.ThingService;
 import cc.iotkit.common.utils.JsonUtil;
 import cc.iotkit.comp.AbstractDeviceComponent;
 import cc.iotkit.comp.CompConfig;
 import cc.iotkit.comp.model.DeviceState;
 import cc.iotkit.converter.DeviceMessage;
-import cc.iotkit.common.thing.ThingService;
 import cc.iotkit.model.device.message.ThingModelMessage;
 import io.vertx.core.Future;
 import io.vertx.core.Vertx;
@@ -62,7 +63,7 @@ public class MqttDeviceComponent extends AbstractDeviceComponent {
             countDownLatch.await();
             future.succeeded();
         } catch (Throwable e) {
-            throw new BizException("start mqtt component error", e);
+            throw new BizException(ErrCode.COMPONENT_START_ERROR, e);
         }
     }
 
@@ -107,13 +108,13 @@ public class MqttDeviceComponent extends AbstractDeviceComponent {
 
         Object obj = message.getContent();
         if (!(obj instanceof Map)) {
-            throw new BizException("message content is not Map");
+            throw new BizException(ErrCode.DATA_FORMAT_ERROR);
         }
         Message msg = new Message();
         try {
             BeanUtils.populate(msg, (Map<String, ? extends Object>) obj);
         } catch (Throwable e) {
-            throw new BizException("message content is incorrect");
+            throw new BizException(ErrCode.DATA_FORMAT_ERROR);
         }
         log.info("publish topic:{},payload:{}", msg.getTopic(), msg.getPayload());
         mqttVerticle.publish(parent.getProductKey(), parent.getDeviceName(),

+ 2 - 1
iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/MqttVerticle.java

@@ -9,6 +9,7 @@
  */
 package cc.iotkit.comp.mqtt;
 
+import cc.iotkit.common.enums.ErrCode;
 import cc.iotkit.common.exception.BizException;
 import cc.iotkit.comp.IMessageHandler;
 import cc.iotkit.comp.model.ReceiveResult;
@@ -200,7 +201,7 @@ public class MqttVerticle extends AbstractVerticle {
     public void publish(String productKey, String deviceName, String topic, String msg) {
         MqttEndpoint endpoint = endpointMap.get(getEndpointKey(productKey, deviceName));
         if (endpoint == null) {
-            throw new BizException("endpoint does not exist");
+            throw new BizException(ErrCode.SEND_DESTINATION_NOT_FOUND);
         }
         Future<Integer> result = endpoint.publish(topic, Buffer.buffer(msg),
                 MqttQoS.AT_LEAST_ONCE, false, false);

+ 4 - 2
iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/TransparentConverter.java

@@ -10,10 +10,12 @@
 package cc.iotkit.comp.mqtt;
 
 
+import cc.iotkit.common.enums.ErrCode;
+import cc.iotkit.common.exception.BizException;
+import cc.iotkit.common.thing.ThingService;
 import cc.iotkit.comp.utils.SpringUtils;
 import cc.iotkit.converter.Device;
 import cc.iotkit.converter.DeviceMessage;
-import cc.iotkit.common.thing.ThingService;
 import cc.iotkit.data.IDeviceInfoData;
 import cc.iotkit.data.IProductModelData;
 import cc.iotkit.model.device.DeviceInfo;
@@ -96,7 +98,7 @@ public class TransparentConverter {
             productModel = getScript(ProductModel.getDefaultModel(pk));
         }
         if (productModel == null) {
-            throw new RuntimeException("product model script does not exist");
+            throw new BizException(ErrCode.MODEL_SCRIPT_NOT_FOUND);
         }
 
         String productKey = productModel.getProductKey();

+ 5 - 0
iot-components/iot-websocket-component/pom.xml

@@ -23,6 +23,11 @@
             <artifactId>lombok</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>cc.iotkit</groupId>
+            <artifactId>iot-common</artifactId>
+        </dependency>
+
         <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>

+ 3 - 1
iot-components/iot-websocket-component/src/main/java/cc/iotkit/comp/websocket/WebSocketDeviceComponent.java

@@ -1,5 +1,6 @@
 package cc.iotkit.comp.websocket;
 
+import cc.iotkit.common.enums.ErrCode;
 import cc.iotkit.common.exception.BizException;
 import cc.iotkit.common.utils.JsonUtil;
 import cc.iotkit.comp.AbstractDeviceComponent;
@@ -12,6 +13,7 @@ import io.vertx.core.Future;
 import io.vertx.core.Vertx;
 import lombok.*;
 import lombok.extern.slf4j.Slf4j;
+
 import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.CountDownLatch;
@@ -54,7 +56,7 @@ public class WebSocketDeviceComponent extends AbstractDeviceComponent {
             countDownLatch.await();
             future.succeeded();
         } catch (Throwable e) {
-            throw new BizException("start websocket component error", e);
+            throw new BizException(ErrCode.COMPONENT_START_ERROR, e);
         }
     }
 

+ 4 - 3
iot-components/iot-websocket-component/src/main/java/cc/iotkit/comp/websocket/client/WebSocketClientVerticle.java

@@ -1,5 +1,6 @@
 package cc.iotkit.comp.websocket.client;
 
+import cc.iotkit.common.enums.ErrCode;
 import cc.iotkit.common.exception.BizException;
 import cc.iotkit.common.utils.JsonUtil;
 import cc.iotkit.comp.model.ReceiveResult;
@@ -8,14 +9,14 @@ import cc.iotkit.comp.websocket.AbstractDeviceVerticle;
 import cc.iotkit.converter.DeviceMessage;
 import io.vertx.core.Future;
 import io.vertx.core.http.HttpClient;
-import io.vertx.core.http.HttpClientOptions;
 import io.vertx.core.http.WebSocket;
 import io.vertx.core.http.WebSocketConnectOptions;
 import lombok.*;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 
-import java.util.*;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
 @Slf4j
@@ -96,7 +97,7 @@ public class WebSocketClientVerticle extends AbstractDeviceVerticle {
     public DeviceMessage send(DeviceMessage message) {
         Object obj = message.getContent();
         if (!(obj instanceof Map)) {
-            throw new BizException("message content is not Map");
+            throw new BizException(ErrCode.DATA_FORMAT_ERROR);
         }
         String msgStr = JsonUtil.toJsonString(obj);
         log.info("send msg payload:{}", msgStr);

+ 2 - 1
iot-components/iot-websocket-component/src/main/java/cc/iotkit/comp/websocket/server/WebSocketServerVerticle.java

@@ -1,6 +1,7 @@
 package cc.iotkit.comp.websocket.server;
 
 
+import cc.iotkit.common.enums.ErrCode;
 import cc.iotkit.common.exception.BizException;
 import cc.iotkit.common.utils.JsonUtil;
 import cc.iotkit.comp.websocket.AbstractDeviceVerticle;
@@ -154,7 +155,7 @@ public class WebSocketServerVerticle extends AbstractDeviceVerticle {
         ServerWebSocket wsClient = wsClients.get(message.getDeviceName());
         Object obj = message.getContent();
         if (!(obj instanceof Map)) {
-            throw new BizException("message content is not Map");
+            throw new BizException(ErrCode.DATA_FORMAT_ERROR);
         }
         String msgStr = JsonUtil.toJsonString(obj);
         log.info("send msg payload:{}", msgStr);

+ 10 - 9
iot-data/iot-td-temporal-service/src/main/java/cc/iotkit/temporal/td/service/DbStructureDataImpl.java

@@ -9,6 +9,7 @@
  */
 package cc.iotkit.temporal.td.service;
 
+import cc.iotkit.common.exception.BizException;
 import cc.iotkit.common.utils.JsonUtil;
 import cc.iotkit.model.product.ThingModel;
 import cc.iotkit.temporal.IDbStructureData;
@@ -49,7 +50,7 @@ public class DbStructureDataImpl implements IDbStructureData {
         //执行sql
         TdResponse response = tdRestApi.execSql(sql);
         if (TdResponse.CODE_SUCCESS != response.getCode()) {
-            throw new RuntimeException(String.format(
+            throw new BizException(String.format(
                     "create td stable failed,code:%s,desc:%s"
                     , response.getCode(), response.getDesc()));
         }
@@ -66,7 +67,7 @@ public class DbStructureDataImpl implements IDbStructureData {
             String sql = TableManager.getDescTableSql(tbName);
             TdResponse response = tdRestApi.execSql(sql);
             if (response.getCode() != TdResponse.CODE_SUCCESS) {
-                throw new RuntimeException("get des table error:" + JsonUtil.toJsonString(response));
+                throw new BizException("get des table error:" + JsonUtil.toJsonString(response));
             }
 
             List<TdField> oldFields = FieldParser.parse(response.getData());
@@ -81,7 +82,7 @@ public class DbStructureDataImpl implements IDbStructureData {
                 sql = TableManager.getAddSTableColumnSql(tbName, addFields);
                 response = tdRestApi.execSql(sql);
                 if (response.getCode() != TdResponse.CODE_SUCCESS) {
-                    throw new RuntimeException("add table column error:" + JsonUtil.toJsonString(response));
+                    throw new BizException("add table column error:" + JsonUtil.toJsonString(response));
                 }
             }
 
@@ -98,7 +99,7 @@ public class DbStructureDataImpl implements IDbStructureData {
                 sql = TableManager.getModifySTableColumnSql(tbName, modifyFields);
                 response = tdRestApi.execSql(sql);
                 if (response.getCode() != TdResponse.CODE_SUCCESS) {
-                    throw new RuntimeException("modify table column error:" + JsonUtil.toJsonString(response));
+                    throw new BizException("modify table column error:" + JsonUtil.toJsonString(response));
                 }
             }
 
@@ -113,7 +114,7 @@ public class DbStructureDataImpl implements IDbStructureData {
                 sql = TableManager.getDropSTableColumnSql(tbName, dropFields);
                 response = tdRestApi.execSql(sql);
                 if (response.getCode() != TdResponse.CODE_SUCCESS) {
-                    throw new RuntimeException("drop table column error:" + JsonUtil.toJsonString(response));
+                    throw new BizException("drop table column error:" + JsonUtil.toJsonString(response));
                 }
             }
         } catch (Throwable e) {
@@ -135,7 +136,7 @@ public class DbStructureDataImpl implements IDbStructureData {
         ), new TdField("rule_id", "NCHAR", 50));
         TdResponse response = tdRestApi.execSql(sql);
         if (response.getCode() != TdResponse.CODE_SUCCESS) {
-            throw new RuntimeException("create stable rule_log error:" + JsonUtil.toJsonString(response));
+            throw new BizException("create stable rule_log error:" + JsonUtil.toJsonString(response));
         }
 
         //创建规则日志超级表
@@ -145,7 +146,7 @@ public class DbStructureDataImpl implements IDbStructureData {
         ), new TdField("task_id", "NCHAR", 50));
         response = tdRestApi.execSql(sql);
         if (response.getCode() != TdResponse.CODE_SUCCESS) {
-            throw new RuntimeException("create stable task_log error:" + JsonUtil.toJsonString(response));
+            throw new BizException("create stable task_log error:" + JsonUtil.toJsonString(response));
         }
 
         //创建物模型消息超级表
@@ -162,7 +163,7 @@ public class DbStructureDataImpl implements IDbStructureData {
         ), new TdField("device_id", "NCHAR", 50));
         response = tdRestApi.execSql(sql);
         if (response.getCode() != TdResponse.CODE_SUCCESS) {
-            throw new RuntimeException("create stable thing_model_message error:" + JsonUtil.toJsonString(response));
+            throw new BizException("create stable thing_model_message error:" + JsonUtil.toJsonString(response));
         }
 
         //创建虚拟设备日志超级表
@@ -173,7 +174,7 @@ public class DbStructureDataImpl implements IDbStructureData {
         ), new TdField("virtual_device_id", "NCHAR", 50));
         response = tdRestApi.execSql(sql);
         if (response.getCode() != TdResponse.CODE_SUCCESS) {
-            throw new RuntimeException("create stable virtual_device_log error:" + JsonUtil.toJsonString(response));
+            throw new BizException("create stable virtual_device_log error:" + JsonUtil.toJsonString(response));
         }
 
     }

+ 3 - 2
iot-message-bus/iot-message-rocketmq/src/main/java/cc/iotkit/rocketmq/RocketMqProducer.java

@@ -1,5 +1,6 @@
 package cc.iotkit.rocketmq;
 
+import cc.iotkit.common.enums.ErrCode;
 import cc.iotkit.common.exception.BizException;
 import cc.iotkit.common.utils.JsonUtil;
 import cc.iotkit.mq.MqProducer;
@@ -18,7 +19,7 @@ public class RocketMqProducer<T> implements MqProducer<T> {
             producer.setNamesrvAddr(nameServer);
             producer.start();
         } catch (Throwable e) {
-            throw new BizException("init producer error", e);
+            throw new BizException(ErrCode.INIT_PRODUCER_ERROR, e);
         }
     }
 
@@ -28,7 +29,7 @@ public class RocketMqProducer<T> implements MqProducer<T> {
             producer.send(new Message(topic,
                     JsonUtil.toJsonString(msg).getBytes(StandardCharsets.UTF_8)));
         } catch (Throwable e) {
-            throw new BizException("publish msg error", e);
+            throw new BizException(ErrCode.SEND_MSG_ERROR, e);
         }
     }
 

+ 3 - 1
iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/HttpService.java

@@ -9,6 +9,8 @@
  */
 package cc.iotkit.ruleengine.action;
 
+import cc.iotkit.common.enums.ErrCode;
+import cc.iotkit.common.exception.BizException;
 import cc.iotkit.common.utils.JsonUtil;
 import cc.iotkit.model.device.message.ThingModelMessage;
 import com.fasterxml.jackson.core.type.TypeReference;
@@ -68,7 +70,7 @@ public class HttpService extends ScriptService {
             responseBody = body == null ? "" : body.string();
             log.info("send result,code:{},response:{}", responseCode, responseBody);
         } catch (IOException e) {
-            throw new RuntimeException("send request failed", e);
+            throw new BizException(ErrCode.SEND_REQUEST_ERROR, e);
         }
 
         return String.format("send request,url:%s,method:%s,receive response,code:%s,body:%s",

+ 2 - 1
iot-rule-engine/src/main/java/cc/iotkit/ruleengine/task/TaskManager.java

@@ -9,6 +9,7 @@
  */
 package cc.iotkit.ruleengine.task;
 
+import cc.iotkit.common.enums.ErrCode;
 import cc.iotkit.common.exception.BizException;
 import cc.iotkit.data.ITaskInfoData;
 import cc.iotkit.model.Paging;
@@ -140,7 +141,7 @@ public class TaskManager implements ApplicationContextAware {
 
     public void renewTask(TaskInfo task) throws SchedulerException {
         if (!TaskInfo.TYPE_DELAY.equals(task.getType())) {
-            throw new BizException("task not support renew");
+            throw new BizException(ErrCode.TASK_NOT_SUPPORT_RENEW);
         }
         saveTask(task);
     }

+ 11 - 10
iot-standalone/src/main/java/cc/iotkit/manager/controller/DeviceController.java

@@ -10,6 +10,7 @@
 package cc.iotkit.manager.controller;
 
 import cc.iotkit.common.Constants;
+import cc.iotkit.common.enums.ErrCode;
 import cc.iotkit.common.exception.BizException;
 import cc.iotkit.common.utils.DeviceUtil;
 import cc.iotkit.common.utils.ReflectUtil;
@@ -83,7 +84,7 @@ public class DeviceController {
                                       @PathVariable("service") String service,
                                       @RequestBody Map<String, Object> args) {
         if (StringUtils.isBlank(deviceId) || StringUtils.isBlank(service)) {
-            throw new RuntimeException("deviceId/service is blank.");
+            throw new BizException(ErrCode.PARAMS_EXCEPTION);
         }
         return new InvokeResult(deviceService.invokeService(deviceId, service, args));
     }
@@ -92,7 +93,7 @@ public class DeviceController {
     public InvokeResult invokeServicePropertySet(@PathVariable("deviceId") String deviceId,
                                       @RequestBody List<String> propertyNames) {
         if (StringUtils.isBlank(deviceId)) {
-            throw new RuntimeException("deviceId/service is blank.");
+            throw new BizException(ErrCode.PARAMS_EXCEPTION);
         }
         return new InvokeResult(deviceService.getProperty(deviceId, propertyNames, true));
     }
@@ -132,7 +133,7 @@ public class DeviceController {
     public void createDevice(String productKey, String deviceName, String parentId) {
         Product product = productData.findById(productKey);
         if (product == null) {
-            throw new BizException("the product does not exist");
+            throw new BizException(ErrCode.PRODUCT_NOT_FOUND);
         }
 
         //生成设备密钥
@@ -162,7 +163,7 @@ public class DeviceController {
     public List<DeviceInfo> getChildren(@PathVariable("deviceId") String deviceId) {
         DeviceInfo deviceInfo = deviceInfoData.findByDeviceId(deviceId);
         if (deviceInfo == null) {
-            throw new BizException("device does not exist");
+            throw new BizException(ErrCode.DEVICE_NOT_FOUND);
         }
 
         dataOwnerService.checkOwner(deviceInfo);
@@ -287,7 +288,7 @@ public class DeviceController {
     public void addGroup(DeviceGroup group) {
         group.setUid(AuthUtil.getUserId());
         if (deviceGroupData.findById(group.getId()) != null) {
-            throw new BizException("group id already exists");
+            throw new BizException(ErrCode.GROUP_ALREADY);
         }
         deviceGroupData.save(group);
     }
@@ -299,7 +300,7 @@ public class DeviceController {
     public void saveGroup(DeviceGroup group) {
         DeviceGroup dbGroup = deviceGroupData.findById(group.getId());
         if (dbGroup == null) {
-            throw new BizException("group id does not exists");
+            throw new BizException(ErrCode.GROUP_NOT_FOUND);
         }
         dataOwnerService.checkOwner(dbGroup);
         ReflectUtil.copyNoNulls(group, dbGroup);
@@ -316,7 +317,7 @@ public class DeviceController {
     public void deleteGroup(@PathVariable("id") String id) {
         DeviceGroup group = deviceGroupData.findById(id);
         if (group == null) {
-            throw new BizException("device group does not exist");
+            throw new BizException(ErrCode.GROUP_NOT_FOUND);
         }
         dataOwnerService.checkOwner(group);
         //删除分组
@@ -333,7 +334,7 @@ public class DeviceController {
     public void clearGroup(@PathVariable("id") String id) {
         DeviceGroup group = deviceGroupData.findById(id);
         if (group == null) {
-            throw new BizException("device group does not exist");
+            throw new BizException(ErrCode.GROUP_NOT_FOUND);
         }
         dataOwnerService.checkOwner(group);
 
@@ -352,7 +353,7 @@ public class DeviceController {
     public void addToGroup(@PathVariable("group") String group, @RequestBody List<String> devices) {
         DeviceGroup deviceGroup = deviceGroupData.findById(group);
         if (deviceGroup == null) {
-            throw new BizException("device group does not exists");
+            throw new BizException(ErrCode.GROUP_NOT_FOUND);
         }
         dataOwnerService.checkOwner(deviceGroup);
 
@@ -380,7 +381,7 @@ public class DeviceController {
     public void removeDevices(@PathVariable("group") String group, @RequestBody List<String> devices) {
         DeviceGroup deviceGroup = deviceGroupData.findById(group);
         if (deviceGroup == null) {
-            throw new BizException("device group does not exists");
+            throw new BizException(ErrCode.GROUP_NOT_FOUND);
         }
         dataOwnerService.checkOwner(deviceGroup);
 

+ 3 - 2
iot-standalone/src/main/java/cc/iotkit/manager/controller/ProductController.java

@@ -9,6 +9,7 @@
  */
 package cc.iotkit.manager.controller;
 
+import cc.iotkit.common.enums.ErrCode;
 import cc.iotkit.common.exception.BizException;
 import cc.iotkit.common.utils.JsonUtil;
 import cc.iotkit.data.ICategoryData;
@@ -178,13 +179,13 @@ public class ProductController {
         String productKey = productModel.getProductKey();
         Product product = productData.findById(productKey);
         if (product == null) {
-            throw new BizException("product does not exist");
+            throw new BizException(ErrCode.PRODUCT_NOT_FOUND);
         }
         dataOwnerService.checkOwner(product);
 
         ProductModel oldScript = productModelData.findByModel(model);
         if (oldScript != null && !oldScript.getProductKey().equals(productKey)) {
-            throw new BizException("model already exists");
+            throw new BizException(ErrCode.MODEL_ALREADY);
         }
 
         productModel.setModifyAt(System.currentTimeMillis());

+ 18 - 17
iot-standalone/src/main/java/cc/iotkit/manager/controller/ProtocolController.java

@@ -9,6 +9,7 @@
  */
 package cc.iotkit.manager.controller;
 
+import cc.iotkit.common.enums.ErrCode;
 import cc.iotkit.common.exception.BizException;
 import cc.iotkit.common.utils.ReflectUtil;
 import cc.iotkit.comps.ComponentManager;
@@ -62,7 +63,7 @@ public class ProtocolController {
             @RequestParam("file") MultipartFile file,
             @RequestParam("id") String id) {
         if (file == null) {
-            throw new BizException("file is null");
+            throw new BizException(ErrCode.PARAMS_EXCEPTION);
         }
         log.info("saving upload jar file:{}", file.getName());
         String fileName = StringUtils.cleanPath(Objects.requireNonNull(file.getOriginalFilename()));
@@ -78,7 +79,7 @@ public class ProtocolController {
             Files.copy(file.getInputStream(), targetLocation, StandardCopyOption.REPLACE_EXISTING);
             return id;
         } catch (IOException ex) {
-            throw new BizException("upload jar error", ex);
+            throw new BizException(ErrCode.UPLOAD_FILE_ERROR, ex);
         }
     }
 
@@ -87,23 +88,23 @@ public class ProtocolController {
         String id = component.getId();
         //jar包上传后生成的id
         if (!StringUtils.hasLength(id)) {
-            throw new BizException("component id is blank");
+            throw new BizException(ErrCode.COMPONENT_ID_BLANK);
         }
         Path jarPath = componentConfig.getComponentFilePath(id);
         if (!jarPath.resolve(component.getJarFile()).toFile().exists()) {
-            throw new BizException("component jar file does not exist");
+            throw new BizException(ErrCode.COMPONENT_JAR_NOT_FOUND);
         }
 
         ProtocolComponent protocolComponent = protocolComponentData.findById(id);
         if (protocolComponent != null) {
-            throw new BizException("component already exists");
+            throw new BizException(ErrCode.COMPONENT_ALREADY);
         }
         try {
             component.setCreateAt(System.currentTimeMillis());
             component.setUid(AuthUtil.getUserId());
             protocolComponentData.save(component);
         } catch (Throwable e) {
-            throw new BizException("add protocol component error", e);
+            throw new BizException(ErrCode.ADD_COMPONENT_ERROR, e);
         }
     }
 
@@ -111,11 +112,11 @@ public class ProtocolController {
     public void saveComponent(ProtocolComponent component) {
         String id = component.getId();
         if (!StringUtils.hasLength(id)) {
-            throw new BizException("component id is blank");
+            throw new BizException(ErrCode.COMPONENT_ID_BLANK);
         }
         Path jarPath = componentConfig.getComponentFilePath(id);
         if (!jarPath.resolve(component.getJarFile()).toFile().exists()) {
-            throw new BizException("component jar file does not exist");
+            throw new BizException(ErrCode.COMPONENT_JAR_NOT_FOUND);
         }
 
         ProtocolComponent oldComponent = getAndCheckComponent(id);
@@ -125,7 +126,7 @@ public class ProtocolController {
             componentManager.deRegister(id);
             protocolComponentData.save(component);
         } catch (Throwable e) {
-            throw new BizException("add protocol component error", e);
+            throw new BizException(ErrCode.ADD_COMPONENT_ERROR, e);
         }
     }
 
@@ -167,7 +168,7 @@ public class ProtocolController {
 
             componentManager.deRegister(id);
         } catch (Throwable e) {
-            throw new BizException("save protocol component script error", e);
+            throw new BizException(ErrCode.SAVE_COMPONENT_SCRIPT_ERROR, e);
         }
     }
 
@@ -179,7 +180,7 @@ public class ProtocolController {
     private ProtocolComponent getAndCheckComponent(@PathVariable("id") String id) {
         ProtocolComponent oldComponent = protocolComponentData.findById(id);
         if (oldComponent == null) {
-            throw new BizException("the component does not exists");
+            throw new BizException(ErrCode.COMPONENT_NOT_FOUND);
         }
         dataOwnerService.checkOwner(oldComponent);
         return oldComponent;
@@ -205,7 +206,7 @@ public class ProtocolController {
             }
             protocolComponentData.deleteById(component.getId());
         } catch (Throwable e) {
-            throw new BizException("delete protocol component error", e);
+            throw new BizException(ErrCode.DELETE_COMPONENT_ERROR, e);
         }
     }
 
@@ -236,7 +237,7 @@ public class ProtocolController {
             converter.setUid(AuthUtil.getUserId());
             protocolConverterData.save(converter);
         } catch (Throwable e) {
-            throw new BizException("add protocol converter error", e);
+            throw new BizException(ErrCode.ADD_CONVERT_ERROR, e);
         }
     }
 
@@ -247,14 +248,14 @@ public class ProtocolController {
         try {
             protocolConverterData.save(converter);
         } catch (Throwable e) {
-            throw new BizException("add protocol converter error", e);
+            throw new BizException(ErrCode.ADD_CONVERT_ERROR, e);
         }
     }
 
     private ProtocolConverter getAndCheckConverter(String id) {
         ProtocolConverter converter = protocolConverterData.findById(id);
         if (converter == null) {
-            throw new BizException("the protocol converter does not exists");
+            throw new BizException(ErrCode.CONVERT_NOT_FOUND);
         }
 
         dataOwnerService.checkOwner(converter);
@@ -297,7 +298,7 @@ public class ProtocolController {
             protocolConverterData.save(converter);
 
         } catch (Throwable e) {
-            throw new BizException("save protocol converter script error", e);
+            throw new BizException(ErrCode.SAVE_CONVERT_SCRIPT_ERROR, e);
         }
     }
 
@@ -319,7 +320,7 @@ public class ProtocolController {
             }
             protocolConverterData.deleteById(id);
         } catch (Throwable e) {
-            throw new BizException("delete protocol converter error", e);
+            throw new BizException(ErrCode.DELETE_CONVERT_ERROR, e);
         }
     }
 

+ 12 - 11
iot-standalone/src/main/java/cc/iotkit/manager/controller/RuleEngineController.java

@@ -9,6 +9,7 @@
  */
 package cc.iotkit.manager.controller;
 
+import cc.iotkit.common.enums.ErrCode;
 import cc.iotkit.common.exception.BizException;
 import cc.iotkit.common.utils.ReflectUtil;
 import cc.iotkit.data.IRuleInfoData;
@@ -86,10 +87,10 @@ public class RuleEngineController {
         } else {
             RuleInfo ruleInfo = ruleInfoData.findById(rule.getId());
             if (ruleInfo == null) {
-                throw new BizException("Rule does not exist");
+                throw new BizException(ErrCode.RULE_NOT_FOUND);
             }
             if (RuleInfo.STATE_RUNNING.equals(ruleInfo.getState())) {
-                throw new BizException("Rule is running");
+                throw new BizException(ErrCode.RULE_ALREADY_RUNNING);
             }
 
             dataOwnerService.checkOwner(ruleInfo);
@@ -108,7 +109,7 @@ public class RuleEngineController {
     public void pauseRule(@PathVariable("ruleId") String ruleId) {
         RuleInfo ruleInfo = ruleInfoData.findById(ruleId);
         if (ruleInfo == null) {
-            throw new BizException("Rule does not exist");
+            throw new BizException(ErrCode.RULE_NOT_FOUND);
         }
         dataOwnerService.checkOwner(ruleInfo);
         ruleInfo.setState(RuleInfo.STATE_STOPPED);
@@ -120,7 +121,7 @@ public class RuleEngineController {
     public void resumeRule(@PathVariable("ruleId") String ruleId) {
         RuleInfo ruleInfo = ruleInfoData.findById(ruleId);
         if (ruleInfo == null) {
-            throw new BizException("Rule does not exist");
+            throw new BizException(ErrCode.RULE_NOT_FOUND);
         }
         dataOwnerService.checkOwner(ruleInfo);
         ruleInfo.setState(RuleInfo.STATE_RUNNING);
@@ -132,7 +133,7 @@ public class RuleEngineController {
     public void deleteRule(@PathVariable("ruleId") String ruleId) {
         RuleInfo ruleInfo = ruleInfoData.findById(ruleId);
         if (ruleInfo == null) {
-            throw new BizException("Rule does not exist");
+            throw new BizException(ErrCode.RULE_NOT_FOUND);
         }
         dataOwnerService.checkOwner(ruleInfo);
         ruleInfoData.deleteById(ruleInfo.getId());
@@ -174,7 +175,7 @@ public class RuleEngineController {
         } else {
             TaskInfo oldTask = taskInfoData.findById(taskInfo.getId());
             if (oldTask == null) {
-                throw new BizException("Task does not exist");
+                throw new BizException(ErrCode.TASK_NOT_FOUND);
             }
             taskInfo = ReflectUtil.copyNoNulls(taskInfo, oldTask);
             dataOwnerService.checkOwner(taskInfo);
@@ -187,7 +188,7 @@ public class RuleEngineController {
     public void pauseTask(@PathVariable("taskId") String taskId) {
         TaskInfo taskInfo = taskInfoData.findById(taskId);
         if (taskInfo == null) {
-            throw new BizException("Task does not exist");
+            throw new BizException(ErrCode.TASK_NOT_FOUND);
         }
         dataOwnerService.checkOwner(taskInfo);
         taskManager.pauseTask(taskId, "stop by " + AuthUtil.getUserId());
@@ -197,7 +198,7 @@ public class RuleEngineController {
     public void resumeTask(@PathVariable("taskId") String taskId) {
         TaskInfo taskInfo = taskInfoData.findById(taskId);
         if (taskInfo == null) {
-            throw new BizException("Task does not exist");
+            throw new BizException(ErrCode.TASK_NOT_FOUND);
         }
         dataOwnerService.checkOwner(taskInfo);
         taskManager.resumeTask(taskId, "resume by " + AuthUtil.getUserId());
@@ -207,7 +208,7 @@ public class RuleEngineController {
     public void renewTask(@PathVariable("taskId") String taskId) {
         TaskInfo taskInfo = taskInfoData.findById(taskId);
         if (taskInfo == null) {
-            throw new BizException("Task does not exist");
+            throw new BizException(ErrCode.TASK_NOT_FOUND);
         }
         dataOwnerService.checkOwner(taskInfo);
         try {
@@ -215,7 +216,7 @@ public class RuleEngineController {
             taskManager.updateTaskState(taskId, TaskInfo.STATE_RUNNING, "renew by " + AuthUtil.getUserId());
         } catch (SchedulerException e) {
             log.error("renew task error", e);
-            throw new BizException("renew task error");
+            throw new BizException(ErrCode.RENEW_TASK_ERROR);
         }
     }
 
@@ -224,7 +225,7 @@ public class RuleEngineController {
     public void deleteTask(@PathVariable("taskId") String taskId) {
         TaskInfo taskInfo = taskInfoData.findById(taskId);
         if (taskInfo == null) {
-            throw new BizException("Task does not exist");
+            throw new BizException(ErrCode.TASK_NOT_FOUND);
         }
 
         dataOwnerService.checkOwner(taskInfo);

+ 5 - 4
iot-standalone/src/main/java/cc/iotkit/manager/controller/SpaceController.java

@@ -9,13 +9,14 @@
  */
 package cc.iotkit.manager.controller;
 
+import cc.iotkit.common.enums.ErrCode;
 import cc.iotkit.common.exception.BizException;
 import cc.iotkit.data.IHomeData;
 import cc.iotkit.data.ISpaceData;
 import cc.iotkit.manager.service.DataOwnerService;
-import cc.iotkit.utils.AuthUtil;
 import cc.iotkit.model.space.Home;
 import cc.iotkit.model.space.Space;
+import cc.iotkit.utils.AuthUtil;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
@@ -70,7 +71,7 @@ public class SpaceController {
     public void saveHome(@PathVariable("id") String id, Home home) {
         Home oldHome = homeData.findById(id);
         if (home==null) {
-            throw new BizException("home does not exist");
+            throw new BizException(ErrCode.HOME_NOT_FOUND);
         }
         dataOwnerService.checkOwner(oldHome);
         if (StringUtils.isNotBlank(home.getName())) {
@@ -98,7 +99,7 @@ public class SpaceController {
         String uid = AuthUtil.getUserId();
         Home currHome = homeData.findByUidAndCurrent(uid, true);
         if (currHome == null) {
-            throw new BizException("current home does not exist");
+            throw new BizException(ErrCode.CURRENT_HOME_NOT_FOUND);
         }
         spaceData.save(Space.builder()
                 .homeId(currHome.getId())
@@ -124,7 +125,7 @@ public class SpaceController {
     private Space checkExistAndOwner(String id) {
         Space space = spaceData.findById(id);
         if (space == null) {
-            throw new BizException("space does not exist");
+            throw new BizException(ErrCode.SPACE_NOT_FOUND);
         }
 
         dataOwnerService.checkOwner(space);

+ 13 - 12
iot-standalone/src/main/java/cc/iotkit/manager/controller/SpaceDeviceController.java

@@ -10,19 +10,20 @@
 package cc.iotkit.manager.controller;
 
 import cc.iotkit.common.Constants;
+import cc.iotkit.common.enums.ErrCode;
 import cc.iotkit.common.exception.BizException;
 import cc.iotkit.data.*;
 import cc.iotkit.manager.model.vo.FindDeviceVo;
 import cc.iotkit.manager.model.vo.SpaceDeviceVo;
 import cc.iotkit.manager.service.DataOwnerService;
-import cc.iotkit.model.space.Home;
-import cc.iotkit.utils.AuthUtil;
 import cc.iotkit.model.UserInfo;
 import cc.iotkit.model.device.DeviceInfo;
 import cc.iotkit.model.product.Category;
 import cc.iotkit.model.product.Product;
+import cc.iotkit.model.space.Home;
 import cc.iotkit.model.space.Space;
 import cc.iotkit.model.space.SpaceDevice;
+import cc.iotkit.utils.AuthUtil;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
@@ -150,11 +151,11 @@ public class SpaceDeviceController {
     @GetMapping(Constants.API_SPACE.FIND_DEVICE)
     List<FindDeviceVo> findDevice(String mac) {
         if (StringUtils.isBlank(mac)) {
-            throw new BizException("mac is blank");
+            throw new BizException(ErrCode.DATA_BLANK);
         }
 
         if (mac.trim().length() < 3) {
-            throw new BizException("mac 长度不能小于3");
+            throw new BizException(ErrCode.DATA_LENGTH_ERROR);
         }
 
         List<FindDeviceVo> findDeviceVos = new ArrayList<>();
@@ -206,17 +207,17 @@ public class SpaceDeviceController {
         String deviceId = device.getDeviceId();
         DeviceInfo deviceInfo = deviceInfoData.findByDeviceId(deviceId);
         if (deviceInfo == null) {
-            throw new BizException("device does not exist");
+            throw new BizException(ErrCode.DEVICE_NOT_FOUND);
         }
         String spaceId = device.getSpaceId();
         Space space = spaceData.findById(spaceId);
         if (space == null) {
-            throw new BizException("space does not exist");
+            throw new BizException(ErrCode.SPACE_NOT_FOUND);
         }
 
         SpaceDevice oldSpaceDevice = spaceDeviceData.findByDeviceId(deviceId);
         if (oldSpaceDevice != null) {
-            throw new BizException("device has been added");
+            throw new BizException(ErrCode.DEVICE_ALREADY);
         }
 
         SpaceDevice spaceDevice = SpaceDevice.builder()
@@ -240,7 +241,7 @@ public class SpaceDeviceController {
         String uid = AuthUtil.getUserId();
         UserInfo userInfo = userInfoData.findById(uid);
         if (userInfo == null) {
-            throw new BizException("user does not exist");
+            throw new BizException(ErrCode.USER_NOT_FOUND);
         }
         if (!subUid.contains(uid)) {
             subUid.add(uid);
@@ -265,7 +266,7 @@ public class SpaceDeviceController {
         String uid = AuthUtil.getUserId();
         SpaceDevice spaceDevice = spaceDeviceData.findByDeviceIdAndUid(deviceId, uid);
         if (spaceDevice == null) {
-            throw new BizException("space device does not exist");
+            throw new BizException(ErrCode.SPACE_DEVICE_NOT_FOUND);
         }
         dataOwnerService.checkOwner(spaceDevice);
 
@@ -273,7 +274,7 @@ public class SpaceDeviceController {
         DeviceInfo deviceInfo = deviceInfoData.findByDeviceId(deviceId);
         UserInfo userInfo = userInfoData.findById(uid);
         if (userInfo == null) {
-            throw new BizException("user does not exist");
+            throw new BizException(ErrCode.USER_NOT_FOUND);
         }
 
         List<String> platforms = userInfo.getUsePlatforms();
@@ -295,7 +296,7 @@ public class SpaceDeviceController {
         dataOwnerService.checkOwner(spaceDevice);
         SpaceDevice oldData = spaceDeviceData.findById(spaceDevice.getId());
         if (oldData == null) {
-            throw new BizException("space device does not exist");
+            throw new BizException(ErrCode.SPACE_DEVICE_NOT_FOUND);
         }
         oldData.setName(spaceDevice.getName());
         oldData.setSpaceId(spaceDevice.getSpaceId());
@@ -323,7 +324,7 @@ public class SpaceDeviceController {
     public void setOpenUid(String deviceId, String platform, String openUid) {
         SpaceDevice spaceDevice = spaceDeviceData.findByDeviceId(deviceId);
         if (spaceDevice == null) {
-            throw new BizException("space device does not exist");
+            throw new BizException(ErrCode.SPACE_DEVICE_NOT_FOUND);
         }
 
         //只能修改自己的设备

+ 10 - 9
iot-standalone/src/main/java/cc/iotkit/manager/controller/UserInfoController.java

@@ -10,6 +10,7 @@
 package cc.iotkit.manager.controller;
 
 import cc.iotkit.common.Constants;
+import cc.iotkit.common.enums.ErrCode;
 import cc.iotkit.common.exception.BizException;
 import cc.iotkit.common.utils.ReflectUtil;
 import cc.iotkit.data.IHomeData;
@@ -66,7 +67,7 @@ public class UserInfoController {
             user.setSecret(AuthUtil.enCryptPwd(Constants.PWD_SYSTEM_USER));
             userInfoData.save(user);
         } catch (Throwable e) {
-            throw new BizException("add platform user error", e);
+            throw new BizException(ErrCode.ADD_PLATFORM_USER_ERROR, e);
         }
     }
 
@@ -79,12 +80,12 @@ public class UserInfoController {
         try {
             UserInfo user = userInfoData.findByUid(uid);
             if (user == null) {
-                throw new BizException("user does not exist");
+                throw new BizException(ErrCode.USER_NOT_FOUND);
             }
             user.setSecret(AuthUtil.enCryptPwd(Constants.PWD_SYSTEM_USER));
             userInfoData.save(user);
         } catch (Throwable e) {
-            throw new BizException("reset pwd failed", e);
+            throw new BizException(ErrCode.RESET_PWD_ERROR, e);
         }
     }
 
@@ -133,7 +134,7 @@ public class UserInfoController {
     public void deleteClientUser(@PathVariable("id") String id) {
         UserInfo user = userInfoData.findById(id);
         if (user == null) {
-            throw new BizException("user does not exist");
+            throw new BizException(ErrCode.USER_NOT_FOUND);
         }
         userInfoData.deleteById(id);
     }
@@ -145,7 +146,7 @@ public class UserInfoController {
             return;
         }
         if (!AuthUtil.getUserId().equals(oldUser.getOwnerId())) {
-            throw new BizException("无权限操作");
+            throw new BizException(ErrCode.UNAUTHORIZED_EXCEPTION);
         }
         ReflectUtil.copyNoNulls(user, oldUser);
         userInfoData.save(oldUser);
@@ -158,15 +159,15 @@ public class UserInfoController {
     public void modifyPwd(@PathVariable("uid") String uid, String oldPwd, String newPwd) {
         UserInfo user = userInfoData.findByUid(uid);
         if (user == null) {
-            throw new BizException("user does not exist");
+            throw new BizException(ErrCode.USER_NOT_FOUND);
         }
         if (!AuthUtil.getUserId().equals(user.getId())) {
-            throw new BizException("permission denied");
+            throw new BizException(ErrCode.UNAUTHORIZED_EXCEPTION);
         }
 
         try {
             if (!AuthUtil.checkPwd(oldPwd, user.getSecret())) {
-                throw new BizException("旧密码不正确");
+                throw new BizException(ErrCode.PWD_ERROR);
             }
 
             user.setSecret(AuthUtil.enCryptPwd(newPwd));
@@ -174,7 +175,7 @@ public class UserInfoController {
         } catch (BizException e) {
             throw e;
         } catch (Throwable e) {
-            throw new BizException("modify pwd failed", e);
+            throw new BizException(ErrCode.UPDATE_PWD_ERROR, e);
         }
     }
 

+ 3 - 2
iot-standalone/src/main/java/cc/iotkit/manager/controller/VirtualDeviceController.java

@@ -9,6 +9,7 @@
  */
 package cc.iotkit.manager.controller;
 
+import cc.iotkit.common.enums.ErrCode;
 import cc.iotkit.common.exception.BizException;
 import cc.iotkit.common.utils.ReflectUtil;
 import cc.iotkit.data.IVirtualDeviceData;
@@ -91,7 +92,7 @@ public class VirtualDeviceController {
         VirtualDevice oldData = checkOwner(id);
         if (!VirtualDevice.STATE_RUNNING.equals(state)
                 && !VirtualDevice.STATE_STOPPED.equals(state)) {
-            throw new BizException("state is illegal");
+            throw new BizException(ErrCode.STATE_ERROR);
         }
         oldData.setState(state);
         if (VirtualDevice.STATE_RUNNING.equals(state)) {
@@ -155,7 +156,7 @@ public class VirtualDeviceController {
     private VirtualDevice checkOwner(String id) {
         VirtualDevice oldData = virtualDeviceData.findById(id);
         if (oldData == null) {
-            throw new BizException("record does not exist");
+            throw new BizException(ErrCode.RECORD_NOT_FOUND);
         }
 
         dataOwnerService.checkOwner(oldData);

+ 5 - 4
iot-standalone/src/main/java/cc/iotkit/manager/service/DataOwnerService.java

@@ -9,11 +9,12 @@
  */
 package cc.iotkit.manager.service;
 
+import cc.iotkit.common.enums.ErrCode;
 import cc.iotkit.common.exception.BizException;
 import cc.iotkit.data.ICommonData;
-import cc.iotkit.utils.AuthUtil;
 import cc.iotkit.model.Owned;
 import cc.iotkit.model.device.DeviceInfo;
+import cc.iotkit.utils.AuthUtil;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
 
@@ -60,7 +61,7 @@ public class DataOwnerService {
             }
         }
 
-        throw new BizException("无权限操作");
+        throw new BizException(ErrCode.UNAUTHORIZED_EXCEPTION);
     }
 
     /**
@@ -88,7 +89,7 @@ public class DataOwnerService {
             return;
         }
 
-        throw new BizException("无权限操作");
+        throw new BizException(ErrCode.UNAUTHORIZED_EXCEPTION);
     }
 
     /**
@@ -105,7 +106,7 @@ public class DataOwnerService {
         }
 
         if (!AuthUtil.hasWriteRole()) {
-            throw new BizException("无权操作");
+            throw new BizException(ErrCode.UNAUTHORIZED_EXCEPTION);
         }
     }
 }

+ 6 - 5
iot-standalone/src/main/java/cc/iotkit/manager/service/WeChatService.java

@@ -10,6 +10,7 @@
 package cc.iotkit.manager.service;
 
 import cc.iotkit.common.Constants;
+import cc.iotkit.common.exception.BizException;
 import cc.iotkit.common.utils.CodecUtil;
 import cc.iotkit.common.utils.JsonUtil;
 import cc.iotkit.data.IUserInfoData;
@@ -31,20 +32,20 @@ public class WeChatService {
     public String login(String encryptedData, String iv, String loginCode) {
         WxSession wxSession = authCode2Session(Constants.WECHAT_APP_ID, Constants.WECHAT_APP_SECRET, loginCode);
         if (wxSession == null) {
-            throw new RuntimeException("调用微信端授权认证接口错误");
+            throw new BizException("调用微信端授权认证接口错误");
         }
         if (StringUtils.isEmpty(wxSession.getOpenid())) {
-            throw new RuntimeException("微信授权认证失败");
+            throw new BizException("微信授权认证失败");
         }
         if (wxSession.getErrcode() != 0) {
-            throw new RuntimeException("微信授权认证失败:" + wxSession.getErrmsg());
+            throw new BizException("微信授权认证失败:" + wxSession.getErrmsg());
         }
 
         UserInfo userInfo = userInfoData.findById(wxSession.getOpenid());
         //判断用户表中是否存在该用户,不存在则进行解密得到用户信息,并进行新增用户
         String strUserInfo = WeChatUtil.decryptData(encryptedData, wxSession.getSession_key(), iv);
         if (StringUtils.isEmpty(strUserInfo)) {
-            throw new RuntimeException("解密用户信息错误");
+            throw new BizException("解密用户信息错误");
         }
         UserInfo decryptUser = JsonUtil.parse(strUserInfo, UserInfo.class);
         if (userInfo == null) {
@@ -57,7 +58,7 @@ public class WeChatService {
         try {
             return CodecUtil.aesEncrypt(System.currentTimeMillis() + "_" + wxSession.getOpenid(), Constants.ACCOUNT_SECRET);
         } catch (Throwable e) {
-            throw new RuntimeException("微信授权认证失败");
+            throw new BizException("微信授权认证失败");
         }
     }