Browse Source

Merge branch 'dev-shiheng' of https://gitee.com/iotkit-open-source/iotkit-parent into dev-shiheng

荭琪枫 2 years ago
parent
commit
8a33c66254
15 changed files with 282 additions and 1 deletions
  1. 78 0
      iot-common/iot-message-bus/iot-message-notify/messageCenter.md
  2. 33 0
      iot-common/iot-message-bus/iot-message-notify/pom.xml
  3. 11 0
      iot-common/iot-message-bus/iot-message-notify/readme.md
  4. 9 0
      iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/model/DingTalkMessage.java
  5. 9 0
      iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/model/EmailMessage.java
  6. 10 0
      iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/model/Message.java
  7. 9 0
      iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/model/QyWechatMessage.java
  8. 16 0
      iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/notify/DingTalkEventListener.java
  9. 12 0
      iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/notify/EventListener.java
  10. 35 0
      iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/notify/EventManager.java
  11. 10 0
      iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/notify/EventType.java
  12. 16 0
      iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/notify/MessageEventListener.java
  13. 16 0
      iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/notify/QyWechatEventListener.java
  14. 16 0
      iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/service/MessageService.java
  15. 2 1
      iot-common/iot-message-bus/pom.xml

+ 78 - 0
iot-common/iot-message-bus/iot-message-notify/messageCenter.md

@@ -0,0 +1,78 @@
+# 消息中心
+
+## 数据库设计
+
+### 通道类型配置
+
+~~~mysql
+CREATE TABLE channel_type
+(
+    id         bigint PRIMARY KEY AUTO_INCREMENT COMMENT 'ID',
+    title      varchar(128) NOT NULL COMMENT '标题',
+    createTime timestamp DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+    updateTime timestamp DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间'
+) COMMENT '通道类型';
+
+INSERT INTO channel_type(title, createTime, updateTime)
+VALUES ('邮箱', current_timestamp(), current_timestamp());
+INSERT INTO channel_type(title, createTime, updateTime)
+VALUES ('飞书', current_timestamp(), current_timestamp());
+INSERT INTO channel_type(title, createTime, updateTime)
+VALUES ('短信', current_timestamp(), current_timestamp());
+INSERT INTO channel_type(title, createTime, updateTime)
+VALUES ('钉钉', current_timestamp(), current_timestamp());
+INSERT INTO channel_type(title, createTime, updateTime)
+VALUES ('企业微信', current_timestamp(), current_timestamp());
+
+CREATE TABLE channel
+(
+    id          bigint PRIMARY KEY AUTO_INCREMENT COMMENT 'ID',
+    title       varchar(128) COMMENT '标题',
+    channelType bigint NOT NULL COMMENT '渠道类型',
+    configParam text   NOT NULL COMMENT '配置参数',
+    userId      bigint COMMENT '配置归属',
+    createTime  timestamp DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+    updateTime  timestamp DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间'
+) COMMENT '通道';
+
+
+CREATE TABLE message
+(
+    id         bigint PRIMARY KEY AUTO_INCREMENT COMMENT 'ID',
+    mac        varchar(128) COMMENT '设备MAC',
+    deviceId   varchar(128) COMMENT '设备ID',
+    content    text NOT NULL COMMENT '消息内容',
+    createTime timestamp DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+    updateTime timestamp DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间'
+) COMMENT '消息';
+
+
+
+
+~~~
+
+### 通道类型配置
+
+~~~mysql
+CREATE TABLE channel
+(
+    id          bigint PRIMARY KEY AUTO_INCREMENT COMMENT 'ID',
+    title       varchar(128) COMMENT '类型',
+    configParam text COMMENT '配置参数',
+    createTime  datetime COMMENT '创建时间',
+    updateTime  datetime COMMENT '修改时间'
+) COMMENT '渠道';
+~~~
+
+### 通道订阅
+
+~~~mysql
+CREATE TABLE channel_subscribe
+(
+    id         bigint PRIMARY KEY AUTO_INCREMENT COMMENT 'ID',
+    channelId  bigint COMMENT '通道',
+    userId     bigint COMMENT '用户ID',
+    createTime datetime COMMENT '创建时间',
+    updateTime datetime COMMENT '修改时间'
+) COMMENT '渠道';
+~~~

+ 33 - 0
iot-common/iot-message-bus/iot-message-notify/pom.xml

@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>iot-message-bus</artifactId>
+        <groupId>cc.iotkit</groupId>
+        <version>${revision}</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>iot-message-notify</artifactId>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-autoconfigure</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>cc.iotkit</groupId>
+            <artifactId>iot-model</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>cc.iotkit</groupId>
+            <artifactId>iot-message-core</artifactId>
+        </dependency>
+
+    </dependencies>
+
+</project>

+ 11 - 0
iot-common/iot-message-bus/iot-message-notify/readme.md

@@ -0,0 +1,11 @@
+### 支持rocketMq作为消息总线
+
+版本:0.4.2
+
+rocketMq版本:4.9.4
+
+####开启方式:
+
+1、application.yml中打开注释支持rocketMq作为消息总线
+
+2、pom.xml中打开注释使用rocketmq消息总线

+ 9 - 0
iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/model/DingTalkMessage.java

@@ -0,0 +1,9 @@
+package cc.iotkit.message.model;
+
+/**
+ * author: 石恒
+ * date: 2023-05-08 15:58
+ * description:
+ **/
+public class DingTalkMessage extends Message{
+}

+ 9 - 0
iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/model/EmailMessage.java

@@ -0,0 +1,9 @@
+package cc.iotkit.message.model;
+
+/**
+ * author: 石恒
+ * date: 2023-05-08 15:58
+ * description:
+ **/
+public class EmailMessage extends Message {
+}

+ 10 - 0
iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/model/Message.java

@@ -0,0 +1,10 @@
+package cc.iotkit.message.model;
+
+/**
+ * author: 石恒
+ * date: 2023-05-08 15:15
+ * description:
+ **/
+public abstract class Message {
+    private String content;
+}

+ 9 - 0
iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/model/QyWechatMessage.java

@@ -0,0 +1,9 @@
+package cc.iotkit.message.model;
+
+/**
+ * author: 石恒
+ * date: 2023-05-08 15:58
+ * description:
+ **/
+public class QyWechatMessage extends Message{
+}

+ 16 - 0
iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/notify/DingTalkEventListener.java

@@ -0,0 +1,16 @@
+package cc.iotkit.message.notify;
+
+import cc.iotkit.message.model.Message;
+
+/**
+ * author: 石恒
+ * date: 2023-05-08 15:09
+ * description:
+ **/
+public class DingTalkEventListener implements EventListener{
+
+    @Override
+    public void doEvent(Message message) {
+
+    }
+}

+ 12 - 0
iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/notify/EventListener.java

@@ -0,0 +1,12 @@
+package cc.iotkit.message.notify;
+
+import cc.iotkit.message.model.Message;
+
+/**
+ * author: 石恒
+ * date: 2023-05-08 15:08
+ * description:
+ **/
+public interface EventListener {
+    void doEvent(Message message);
+}

+ 35 - 0
iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/notify/EventManager.java

@@ -0,0 +1,35 @@
+package cc.iotkit.message.notify;
+
+import cc.iotkit.message.model.Message;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * author: 石恒
+ * date: 2023-05-08 15:17
+ * description:
+ **/
+public class EventManager {
+
+    Map<Enum<EventType>, List<EventListener>> listeners = new HashMap<>();
+
+    public void subscribe(Enum<EventType> eventType, EventListener listener) {
+        List<EventListener> users = listeners.get(eventType);
+        users.add(listener);
+    }
+
+    public void unsubscribe(Enum<EventType> eventType, EventListener listener) {
+        List<EventListener> users = listeners.get(eventType);
+        users.remove(listener);
+    }
+
+    public void notify(Enum<EventType> eventType, Message result) {
+        List<EventListener> users = listeners.get(eventType);
+        for (EventListener listener : users) {
+            listener.doEvent(result);
+        }
+    }
+
+}

+ 10 - 0
iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/notify/EventType.java

@@ -0,0 +1,10 @@
+package cc.iotkit.message.notify;
+
+/**
+ * author: 石恒
+ * date: 2023-05-08 15:21
+ * description:
+ **/
+public enum EventType {
+    MQ, Message
+}

+ 16 - 0
iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/notify/MessageEventListener.java

@@ -0,0 +1,16 @@
+package cc.iotkit.message.notify;
+
+import cc.iotkit.message.model.Message;
+
+/**
+ * author: 石恒
+ * date: 2023-05-08 15:09
+ * description:
+ **/
+public class MessageEventListener implements EventListener{
+
+    @Override
+    public void doEvent(Message message) {
+
+    }
+}

+ 16 - 0
iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/notify/QyWechatEventListener.java

@@ -0,0 +1,16 @@
+package cc.iotkit.message.notify;
+
+import cc.iotkit.message.model.Message;
+
+/**
+ * author: 石恒
+ * date: 2023-05-08 15:09
+ * description:
+ **/
+public class QyWechatEventListener implements EventListener{
+
+    @Override
+    public void doEvent(Message message) {
+
+    }
+}

+ 16 - 0
iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/service/MessageService.java

@@ -0,0 +1,16 @@
+package cc.iotkit.message.service;
+
+import cc.iotkit.message.notify.EventManager;
+
+/**
+ * author: 石恒
+ * date: 2023-05-08 16:02
+ * description:
+ **/
+public class MessageService {
+
+    public static void main(String[] args) {
+        EventManager em = new EventManager();
+        em.notify();
+    }
+}

+ 2 - 1
iot-common/iot-message-bus/pom.xml

@@ -19,6 +19,7 @@
         <module>iot-message-core</module>
         <module>iot-vertx-event-bus</module>
         <module>iot-message-rocketmq</module>
+        <module>iot-message-notify</module>
     </modules>
 
     <dependencies>
@@ -44,4 +45,4 @@
 
     </dependencies>
 
-</project>
+</project>