Pārlūkot izejas kodu

refa:迁移channel

荭琪枫 2 gadi atpakaļ
vecāks
revīzija
c02bde242c

+ 36 - 0
data/init/channelConfig.json

@@ -0,0 +1,36 @@
+[
+  {
+    "id": "947d22b7-305b-d959-874a-06e277143d44",
+    "channelId": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
+    "title": "告警邮件配置",
+    "param": {
+        "userName":"xxx",
+        "passWord":"xxx",
+        "host":"smtp.qq.com",
+        "port":465,
+        "mailSmtpAuth":true,
+        "from":"1111111@qq.com",
+        "to":"abcdef@yeah.net,1211111@qq.com"
+    },
+    "createAt": 1683816661690
+  },
+  {
+    "id": "75f37720-22bb-4f0b-f127-78f2091507a0",
+    "channelId": "fa1c5eaa-de6e-48b6-805e-8f091c7bb832",
+    "title": "告警钉钉配置",
+    "param": {
+        "dingTalkWebhook":"xxxxxxxxxxxxxxxx",
+        "dingTalkSecret":"xxxx"
+    },
+    "createAt": 1683816661690
+  },
+  {
+    "id": "6e5db9b5-a709-723b-665b-bbca5ce6a62c",
+    "channelId": "fa1c5eaa-de6e-48b6-805e-8f091c7bb833",
+    "title": "告警企业微信配置",
+    "param": {
+            "qyWechatWebhook":"xxxxxxxxxxxxxxxx"
+    },
+    "createAt": 1683816661690
+  }
+]

+ 26 - 0
data/init/channelTemplate.json

@@ -0,0 +1,26 @@
+[
+  {
+    "id": "0640bbe2-788e-ca94-5fb4-c5e7f91e546d",
+    "channelConfigId": "947d22b7-305b-d959-874a-06e277143d44",
+    "channelCode": "Email",
+    "title": "告警邮件模板",
+    "content": "您的设备【${title}】<font color=\"warning\">温度过高</font>",
+    "createAt": 1683816661690
+  },
+  {
+    "id": "7fd90ab1-63c8-cd92-2a58-b7bd04f557f1",
+    "channelConfigId": "75f37720-22bb-4f0b-f127-78f2091507a0",
+    "channelCode": "DingTalk",
+    "title": "告警钉钉模板",
+    "content": "您的设备【${title}】<font color=\"warning\">温度过高</font>",
+    "createAt": 1683816661690
+  },
+  {
+    "id": "74ece781-1d84-220b-cbb2-3270e245bb3b",
+    "channelConfigId": "6e5db9b5-a709-723b-665b-bbca5ce6a62c",
+    "channelCode": "QyWechat",
+    "title": "告警企业微信模板",
+    "content": "您的设备【${title}】<font color=\"warning\">温度过高</font>",
+    "createAt": 1683816661690
+  }
+]

+ 98 - 0
data/init/notifyMessage.json

@@ -0,0 +1,98 @@
+[
+  {
+    "id": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
+    "content": "你的设备【热水器】温度过高",
+    "messageType": "alert",
+    "status": true,
+    "createAt": 1683816661690,
+    "updateAt": 1683816661690
+  },
+  {
+    "id": "fa1c5eaa-de6e-48b6-805e-8f091c7bb832",
+    "content": "你的设备【热水器】温度过高",
+    "messageType": "alert",
+    "status": true,
+    "createAt": 1683816661690,
+    "updateAt": 1683816661690
+  },
+  {
+    "id": "fa1c5eaa-de6e-48b6-805e-8f091c7bb833",
+    "content": "你的设备【热水器】温度过高",
+    "messageType": "alert",
+    "status": false,
+    "createAt": 1683816661690,
+    "updateAt": 1683816661690
+  },
+  {
+    "id": "fa1c5eaa-de6e-48b6-805e-8f091c7bb834",
+    "content": "你的设备【热水器】温度过高",
+    "messageType": "alert",
+    "status": true,
+    "createAt": 1683816661690,
+    "updateAt": 1683816661690
+  },
+  {
+    "id": "fa1c5eaa-de6e-48b6-805e-8f091c7bb835",
+    "content": "你的设备【热水器】温度过高",
+    "messageType": "alert",
+    "status": false,
+    "createAt": 1683816661690,
+    "updateAt": 1683816661690
+  },
+  {
+    "id": "fa1c5eaa-de6e-48b6-805e-8f091c7bb836",
+    "content": "你的设备【热水器】温度过高",
+    "messageType": "alert",
+    "status": true,
+    "createAt": 1683816661690,
+    "updateAt": 1683816661690
+  },
+  {
+    "id": "fa1c5eaa-de6e-48b6-805e-8f091c7bb837",
+    "content": "你的设备【热水器】温度过高",
+    "messageType": "alert",
+    "status": true,
+    "createAt": 1683816661690,
+    "updateAt": 1683816661690
+  },
+  {
+    "id": "fa1c5eaa-de6e-48b6-805e-8f091c7bb838",
+    "content": "你的设备【热水器】温度过高",
+    "messageType": "alert",
+    "status": true,
+    "createAt": 1683816661690,
+    "updateAt": 1683816661690
+  },
+  {
+    "id": "fa1c5eaa-de6e-48b6-805e-8f091c7bb839",
+    "content": "你的设备【热水器】温度过高",
+    "messageType": "alert",
+    "status": false,
+    "createAt": 1683816661690,
+    "updateAt": 1683816661690
+  },
+  {
+    "id": "fa1c5eaa-de6e-48b6-805e-8f091c7bb840",
+    "content": "你的设备【热水器】温度过高",
+    "messageType": "alert",
+    "status": true,
+    "createAt": 1683816661690,
+    "updateAt": 1683816661690
+  },
+  {
+    "id": "fa1c5eaa-de6e-48b6-805e-8f091c7bb841",
+    "content": "你的设备【热水器】温度过高",
+    "messageType": "alert",
+    "status": false,
+    "createAt": 1683816661690,
+    "updateAt": 1683816661690
+  },
+  {
+    "id": "fa1c5eaa-de6e-48b6-805e-8f091c7bb842",
+    "content": "你的设备【热水器】温度过高",
+    "messageType": "alert",
+    "status": true,
+    "createAt": 1683816661690,
+    "updateAt": 1683816661690
+  }
+]

+ 20 - 1
iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/notify/ChannelConfig.java

@@ -1,11 +1,14 @@
 package cc.iotkit.model.notify;
 
 import cc.iotkit.model.Id;
+import com.fasterxml.jackson.annotation.JsonInclude;
 import lombok.AllArgsConstructor;
 import lombok.Builder;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 
+import java.io.Serializable;
+
 /**
  * author: 石恒
  * date: 2023-05-11 16:30
@@ -23,7 +26,23 @@ public class ChannelConfig implements Id<String> {
 
     private String title;
 
-    private String param;
+    private ChannelParam param;
 
     private Long createAt;
+
+    @Data
+    @JsonInclude(JsonInclude.Include.NON_NULL)
+    public static class ChannelParam implements Serializable {
+        private String userName;
+        private String passWord;
+        private String host;
+        private Integer port;
+        private Boolean mailSmtpAuth;
+        private String from;
+        private String to;
+        private String dingTalkWebhook;
+        private String dingTalkSecret;
+        private String qyWechatWebhook;
+
+    }
 }

+ 31 - 0
iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/notify/NotifyMessage.java

@@ -0,0 +1,31 @@
+package cc.iotkit.model.notify;
+
+import cc.iotkit.model.Id;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @Author: 石恒
+ * @Date: 2023/5/13 15:22
+ * @Description:
+ */
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class NotifyMessage implements Id<String> {
+
+    private String id;
+
+    private String content;
+
+    private String messageType;
+
+    private Boolean status;
+
+    private Long createAt;
+
+    private Long updateAt;
+}

+ 12 - 0
iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/INotifyMessageData.java

@@ -0,0 +1,12 @@
+package cc.iotkit.data.manager;
+
+import cc.iotkit.data.ICommonData;
+import cc.iotkit.model.notify.NotifyMessage;
+
+/**
+ * @Author: 石恒
+ * @Date: 2023/5/13 18:32
+ * @Description:
+ */
+public interface INotifyMessageData extends ICommonData<NotifyMessage, String> {
+}

+ 13 - 0
iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/NotifyMessageRepository.java

@@ -0,0 +1,13 @@
+package cc.iotkit.data.dao;
+
+import cc.iotkit.data.model.TbNotifyMessage;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+/**
+ * @Author: 石恒
+ * @Date: 2023/5/13 18:36
+ * @Description:
+ */
+public interface NotifyMessageRepository extends JpaRepository<TbNotifyMessage, String> {
+
+}

+ 44 - 0
iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/ChannelConfigMapper.java

@@ -0,0 +1,44 @@
+package cc.iotkit.data.model;
+
+import cc.iotkit.common.utils.JsonUtils;
+import cc.iotkit.model.notify.ChannelConfig;
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+import org.mapstruct.Mappings;
+
+import java.util.Objects;
+
+/**
+ * @Author: 石恒
+ * @Date: 2023/5/11 21:02
+ * @Description:
+ */
+@Mapper(componentModel = "spring")
+public interface ChannelConfigMapper {
+
+    @Mappings({
+            @Mapping(target = "param", expression = "java(stingToParam(vo.getParam()))")
+    })
+    ChannelConfig toDto(TbChannelConfig vo);
+
+    @Mappings({
+            @Mapping(target = "param", expression = "java(paramToSting(dto.getParam()))")
+    })
+    TbChannelConfig toVo(ChannelConfig dto);
+
+    default String paramToSting(ChannelConfig.ChannelParam param) {
+        if (Objects.isNull(param)) {
+            return null;
+        }
+        return JsonUtils.toJsonString(param);
+
+    }
+
+    default ChannelConfig.ChannelParam stingToParam(String param) {
+        if (Objects.isNull(param)) {
+            return null;
+        }
+        return JsonUtils.parse(param, ChannelConfig.ChannelParam.class);
+
+    }
+}

+ 3 - 5
iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbChannelConfig.java

@@ -7,10 +7,7 @@ import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import org.hibernate.annotations.GenericGenerator;
 
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.Table;
+import javax.persistence.*;
 
 /**
  * @Author: 石恒
@@ -21,7 +18,7 @@ import javax.persistence.Table;
 @Entity
 @Table(name = "channel_config")
 @ApiModel(value = "通道配置")
-@AutoMapper(target= ChannelConfig.class)
+@AutoMapper(target = ChannelConfig.class)
 public class TbChannelConfig {
     @Id
     @GeneratedValue(generator = "SnowflakeIdGenerator")
@@ -36,6 +33,7 @@ public class TbChannelConfig {
     private String title;
 
     @ApiModelProperty(value = "通道配置参数")
+    @Column(columnDefinition = "TEXT")
     private String param;
 
     @ApiModelProperty(value = "创建时间")

+ 38 - 0
iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbNotifyMessage.java

@@ -0,0 +1,38 @@
+package cc.iotkit.data.model;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import org.hibernate.annotations.GenericGenerator;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+/**
+ * @Author: 石恒
+ * @Date: 2023/5/13 18:33
+ * @Description:
+ */
+@Data
+@Entity
+@ApiModel(value = "通知消息")
+@Table(name = "notify_message")
+public class TbNotifyMessage {
+    @Id
+    @GeneratedValue(generator = "SnowflakeIdGenerator")
+    @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator")
+    @ApiModelProperty(value = "通知消息id")
+    private String id;
+
+    private String content;
+
+    private String messageType;
+
+    private Boolean status;
+
+    private Long createAt;
+
+    private Long updateAt;
+}

+ 22 - 4
iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ChannelConfigDataImpl.java

@@ -1,13 +1,12 @@
 package cc.iotkit.data.service;
 
 import cc.iotkit.common.api.PageRequest;
-import cc.iotkit.common.utils.MapstructUtils;
 import cc.iotkit.data.dao.IJPACommData;
 import cc.iotkit.data.manager.IChannelConfigData;
 import cc.iotkit.data.dao.ChannelConfigRepository;
+import cc.iotkit.data.model.ChannelConfigMapper;
 import cc.iotkit.data.model.TbChannelConfig;
 import cc.iotkit.common.api.Paging;
-import cc.iotkit.model.notify.Channel;
 import cc.iotkit.model.notify.ChannelConfig;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.context.annotation.Primary;
@@ -20,6 +19,7 @@ import javax.annotation.Resource;
 import java.util.Collection;
 import java.util.List;
 import java.util.UUID;
+import java.util.stream.Collectors;
 
 /**
  * author: 石恒
@@ -33,6 +33,9 @@ public class ChannelConfigDataImpl implements IChannelConfigData, IJPACommData<C
     @Resource
     private ChannelConfigRepository channelConfigRepository;
 
+    @Resource
+    private ChannelConfigMapper channelConfigMapper;
+
     @Override
     public JpaRepository getBaseRepository() {
         return channelConfigRepository;
@@ -50,7 +53,7 @@ public class ChannelConfigDataImpl implements IChannelConfigData, IJPACommData<C
 
     @Override
     public ChannelConfig findById(String id) {
-        return MapstructUtils.convert(channelConfigRepository.findById(id).orElse(null), ChannelConfig.class);
+        return channelConfigMapper.toDto(channelConfigRepository.findById(id).orElse(null));
     }
 
     @Override
@@ -63,9 +66,24 @@ public class ChannelConfigDataImpl implements IChannelConfigData, IJPACommData<C
         if (StringUtils.isBlank(data.getId())) {
             data.setId(UUID.randomUUID().toString());
         }
-        channelConfigRepository.save(MapstructUtils.convert(data, TbChannelConfig.class));
+        channelConfigRepository.save(channelConfigMapper.toVo(data));
         return data;
     }
 
+    @Override
+    public List<ChannelConfig> findAll() {
+        return channelConfigRepository.findAll().stream().map(channelConfigMapper::toDto)
+                .collect(Collectors.toList());
+    }
 
+    @Override
+    public Paging<ChannelConfig> findAll(PageRequest<ChannelConfig> pageRequest) {
+        Page<TbChannelConfig> tbChannelConfigs = channelConfigRepository.findAll(Pageable.ofSize(pageRequest.getPageSize()).withPage(pageRequest.getPageNum() - 1));
+        return new Paging<>(
+                tbChannelConfigs.getTotalElements(),
+                tbChannelConfigs.getContent()
+                        .stream().map(channelConfigMapper::toDto)
+                        .collect(Collectors.toList())
+        );
+    }
 }

+ 52 - 0
iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/NotifyMessageDataImpl.java

@@ -0,0 +1,52 @@
+package cc.iotkit.data.service;
+
+import cc.iotkit.common.api.Paging;
+import cc.iotkit.common.utils.MapstructUtils;
+import cc.iotkit.data.dao.IJPACommData;
+import cc.iotkit.data.dao.NotifyMessageRepository;
+import cc.iotkit.data.manager.INotifyMessageData;
+import cc.iotkit.data.model.TbNotifyMessage;
+import cc.iotkit.data.model.TbOtaPackage;
+import cc.iotkit.model.notify.Channel;
+import cc.iotkit.model.notify.NotifyMessage;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.context.annotation.Primary;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.List;
+import java.util.UUID;
+import java.util.stream.Collectors;
+
+/**
+ * @Author: 石恒
+ * @Date: 2023/5/13 18:35
+ * @Description:
+ */
+@Primary
+@Service
+public class NotifyMessageDataImpl implements INotifyMessageData, IJPACommData<NotifyMessage, String> {
+
+    @Resource
+    private NotifyMessageRepository notifyMessageRepository;
+
+
+    @Override
+    public JpaRepository getBaseRepository() {
+        return notifyMessageRepository;
+    }
+
+    @Override
+    public Class getJpaRepositoryClass() {
+        return TbNotifyMessage.class;
+    }
+
+    @Override
+    public Class getTClass() {
+        return NotifyMessage.class;
+    }
+
+}