Răsfoiți Sursa

系统模块开发、字典数据处理、引入excel数据处理

xucaiqin 2 ani în urmă
părinte
comite
fc295f312c
61 a modificat fișierele cu 1121 adăugiri și 61 ștergeri
  1. 16 3
      iot-dependencies/pom.xml
  2. 5 0
      iot-framework/iot-common/src/main/java/com/middle/platform/common/constant/Global.java
  3. 2 0
      iot-framework/iot-starter-biz-dict/src/main/java/com/middle/platform/biz/dict/config/DictAutoConfiguration.java
  4. 1 1
      iot-framework/iot-starter-biz-dict/src/main/java/com/middle/platform/biz/dict/core/util/DictFrameworkUtils.java
  5. 48 0
      iot-framework/iot-starter-excel/pom.xml
  6. 21 0
      iot-framework/iot-starter-excel/src/main/java/com/middle/platform/excel/core/annotations/DictFormat.java
  7. 70 0
      iot-framework/iot-starter-excel/src/main/java/com/middle/platform/excel/core/convert/DictConvert.java
  8. 33 0
      iot-framework/iot-starter-excel/src/main/java/com/middle/platform/excel/core/convert/JsonConvert.java
  9. 36 0
      iot-framework/iot-starter-excel/src/main/java/com/middle/platform/excel/core/convert/MoneyConvert.java
  10. 46 0
      iot-framework/iot-starter-excel/src/main/java/com/middle/platform/excel/core/util/ExcelUtils.java
  11. 20 1
      iot-framework/iot-starter-mqtt/pom.xml
  12. 21 0
      iot-framework/iot-starter-mqtt/src/main/java/com/middle/platform/mqtt/properties/MqttProperties.java
  13. 1 0
      iot-framework/iot-starter-mqtt/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
  14. 4 1
      iot-framework/iot-starter-mybatis/pom.xml
  15. 11 0
      iot-framework/iot-starter-redis/src/main/java/com/middle/platform/redis/constant/CacheConstant.java
  16. 1 0
      iot-framework/pom.xml
  17. 6 0
      iot-module/iot-module-data/iot-module-data-biz/pom.xml
  18. 63 0
      iot-module/iot-module-data/iot-module-data-biz/src/main/java/com/middle/platform/data/biz/config/MqttConfig.java
  19. 18 3
      iot-module/iot-module-data/iot-module-data-biz/src/main/java/com/middle/platform/data/biz/controller/IndexController.java
  20. 18 0
      iot-module/iot-module-data/iot-module-data-biz/src/main/java/com/middle/platform/data/biz/mapper/ProductMapper.java
  21. 30 0
      iot-module/iot-module-data/iot-module-data-biz/src/main/java/com/middle/platform/data/biz/pojo/ProductPara.java
  22. 32 0
      iot-module/iot-module-data/iot-module-data-biz/src/main/java/com/middle/platform/data/biz/service/MqttService.java
  23. 17 0
      iot-module/iot-module-data/iot-module-data-biz/src/main/java/com/middle/platform/data/biz/service/mqtt/MqttStrategyFactory.java
  24. 29 0
      iot-module/iot-module-data/iot-module-data-biz/src/main/java/com/middle/platform/data/biz/service/mqtt/MqttTopicInit.java
  25. 6 0
      iot-module/iot-module-data/iot-module-data-biz/src/main/java/com/middle/platform/data/biz/service/mqtt/MqttTopicStrategy.java
  26. 19 0
      iot-module/iot-module-data/iot-module-data-biz/src/main/java/com/middle/platform/data/biz/service/mqtt/impl/AttrReportStrategy.java
  27. 5 0
      iot-module/iot-module-data/iot-module-data-biz/src/main/resources/mapper/ProductMapper.xml
  28. 8 0
      iot-module/iot-module-manage/iot-module-manage-biz/pom.xml
  29. 2 0
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/ManageApplication.java
  30. 17 0
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/config/FeignConfig.java
  31. 10 0
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/constant/UrlCategory.java
  32. 39 0
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/constant/UrlInit.java
  33. 10 0
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/constant/UrlProtocol.java
  34. 18 0
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/controller/IotDeviceController.java
  35. 1 10
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/domain/req/IotProductPara.java
  36. 43 0
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/domain/vo/DeviceImportExcelVo.java
  37. 6 0
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/domain/vo/IotProductVo.java
  38. 6 4
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/mapper/IotUrlMapper.java
  39. 11 0
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/service/IotCloudService.java
  40. 9 0
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/service/IotModService.java
  41. 40 3
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/service/IotProductService.java
  42. 37 0
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/service/IotUrlService.java
  43. 2 0
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/resources/bootstrap.yaml
  44. 1 0
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/resources/mapper/IotProductMapper.xml
  45. 4 2
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/resources/mapper/IotUrlMapper.xml
  46. 14 0
      iot-module/iot-module-system/iot-module-system-api/src/main/java/com/middle/platform/system/api/enums/DictType.java
  47. 17 3
      iot-module/iot-module-system/iot-module-system-api/src/main/java/com/middle/platform/system/api/feign/DictApi.java
  48. 5 1
      iot-module/iot-module-system/iot-module-system-api/src/main/java/com/middle/platform/system/api/feign/UserApi.java
  49. 15 0
      iot-module/iot-module-system/iot-module-system-api/src/main/java/com/middle/platform/system/api/pojo/DictCache.java
  50. 6 1
      iot-module/iot-module-system/iot-module-system-api/src/main/java/com/middle/platform/system/api/pojo/DictDto.java
  51. 20 0
      iot-module/iot-module-system/iot-module-system-api/src/main/java/com/middle/platform/system/api/pojo/UserCache.java
  52. 6 1
      iot-module/iot-module-system/iot-module-system-api/src/main/java/com/middle/platform/system/api/pojo/UserDto.java
  53. 56 3
      iot-module/iot-module-system/iot-module-system-biz/src/main/java/com/middle/platform/system/biz/api/DictApiImpl.java
  54. 20 0
      iot-module/iot-module-system/iot-module-system-biz/src/main/java/com/middle/platform/system/biz/api/UserApiImpl.java
  55. 7 0
      iot-module/iot-module-system/iot-module-system-biz/src/main/java/com/middle/platform/system/biz/mapper/SysDictItemMapper.java
  56. 9 0
      iot-module/iot-module-system/iot-module-system-biz/src/main/java/com/middle/platform/system/biz/mapper/SysUserMapper.java
  57. 26 1
      iot-module/iot-module-system/iot-module-system-biz/src/main/java/com/middle/platform/system/biz/service/SysDictItemService.java
  58. 11 0
      iot-module/iot-module-system/iot-module-system-biz/src/main/java/com/middle/platform/system/biz/service/SysUserService.java
  59. 1 1
      iot-module/iot-module-system/iot-module-system-biz/src/main/resources/logback-spring.xml
  60. 58 22
      iot-module/iot-module-system/iot-module-system-biz/src/main/resources/mapper/SysDictItemMapper.xml
  61. 7 0
      iot-module/iot-module-system/iot-module-system-biz/src/main/resources/mapper/SysUserMapper.xml

+ 16 - 3
iot-dependencies/pom.xml

@@ -33,6 +33,7 @@
         <mybatis-plus-join-boot-starter.version>1.4.6</mybatis-plus-join-boot-starter.version>
         <redisson.version>3.23.4</redisson.version>
         <dm8.jdbc.version>8.1.2.141</dm8.jdbc.version>
+        <taos.version>3.2.7</taos.version>
         <!-- RPC 相关 -->
         <!-- Config 配置中心相关 -->
         <apollo.version>1.9.2</apollo.version>
@@ -172,14 +173,22 @@
                 <artifactId>iot-starter-redis</artifactId>
                 <version>${revision}</version>
             </dependency>
+            <dependency>
+                <groupId>com.middle.platform</groupId>
+                <artifactId>iot-starter-excel</artifactId>
+                <version>${revision}</version>
+            </dependency>
             <!-- RPC 远程调用相关 -->
             <dependency>
                 <groupId>com.middle.platform</groupId>
                 <artifactId>iot-starter-feign</artifactId>
                 <version>${revision}</version>
             </dependency>
-
-
+            <dependency>
+                <groupId>com.middle.platform</groupId>
+                <artifactId>iot-starter-biz-dict</artifactId>
+                <version>${revision}</version>
+            </dependency>
 
             <dependency>
                 <groupId>com.alibaba</groupId>
@@ -215,7 +224,11 @@
                 <artifactId>DmJdbcDriver18</artifactId>
                 <version>${dm8.jdbc.version}</version>
             </dependency>
-
+            <dependency>
+                <groupId>com.taosdata.jdbc</groupId>
+                <artifactId>taos-jdbcdriver</artifactId>
+                <version>${taos.version}</version>
+            </dependency>
             <dependency>
                 <groupId>cn.hutool</groupId>
                 <artifactId>hutool-all</artifactId>

+ 5 - 0
iot-framework/iot-common/src/main/java/com/middle/platform/common/constant/Global.java

@@ -8,5 +8,10 @@ public interface Global {
     int SUCCESS = 200;
     int ERROR = 500;
 
+    /*删除标记*/
+    int DEL = 1;//删除
+
+    int UN_DEL = 0;//正常
+
     String UN_AUTH = "未登录,请先登录";
 }

+ 2 - 0
iot-framework/iot-starter-biz-dict/src/main/java/com/middle/platform/biz/dict/config/DictAutoConfiguration.java

@@ -4,12 +4,14 @@ package com.middle.platform.biz.dict.config;
 import com.middle.platform.biz.dict.core.util.DictFrameworkUtils;
 import com.middle.platform.system.api.feign.DictApi;
 import org.springframework.boot.autoconfigure.AutoConfiguration;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
 import org.springframework.context.annotation.Bean;
 
 @AutoConfiguration
 public class DictAutoConfiguration {
 
     @Bean
+    @ConditionalOnBean(DictApi.class)
     public DictFrameworkUtils dictUtils(DictApi dictApi) {
         DictFrameworkUtils.init(dictApi);
         return new DictFrameworkUtils();

+ 1 - 1
iot-framework/iot-starter-biz-dict/src/main/java/com/middle/platform/biz/dict/core/util/DictFrameworkUtils.java

@@ -47,7 +47,7 @@ public class DictFrameworkUtils {
 
                 @Override
                 public DictDto load(KeyValue<String, String> key) {
-                    return ObjectUtil.defaultIfNull(null,
+                    return ObjectUtil.defaultIfNull(dictApi.getDictValue(key.getKey(),key.getValue()).getData(),
                             DICT_DATA_NULL);
                 }
 

+ 48 - 0
iot-framework/iot-starter-excel/pom.xml

@@ -0,0 +1,48 @@
+<?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">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>com.middle.platform</groupId>
+        <artifactId>iot-framework</artifactId>
+        <version>${revision}</version>
+    </parent>
+
+    <artifactId>iot-starter-excel</artifactId>
+    <packaging>jar</packaging>
+    <properties>
+        <maven.compiler.source>17</maven.compiler.source>
+        <maven.compiler.target>17</maven.compiler.target>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+    <dependencies>
+        <dependency>
+            <groupId>com.middle.platform</groupId>
+            <artifactId>iot-common</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.middle.platform</groupId>
+            <artifactId>iot-starter-biz-dict</artifactId>
+        </dependency>
+        <!-- Web 相关 -->
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-web</artifactId>
+            <scope>provided</scope> <!-- 设置为 provided,只有 ExcelUtils 使用 -->
+        </dependency>
+
+        <dependency>
+            <groupId>jakarta.servlet</groupId>
+            <artifactId>jakarta.servlet-api</artifactId>
+            <scope>provided</scope> <!-- 设置为 provided,只有 ExcelUtils 使用 -->
+        </dependency>
+
+        <!-- 工具类相关 -->
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>easyexcel</artifactId>
+        </dependency>
+    </dependencies>
+
+</project>

+ 21 - 0
iot-framework/iot-starter-excel/src/main/java/com/middle/platform/excel/core/annotations/DictFormat.java

@@ -0,0 +1,21 @@
+package com.middle.platform.excel.core.annotations;
+
+import java.lang.annotation.*;
+
+/**
+ * 字典格式化
+ * 实现将字典数据的值,格式化成字典数据的标签
+ */
+@Target({ElementType.FIELD})
+@Retention(RetentionPolicy.RUNTIME)
+@Inherited
+public @interface DictFormat {
+
+    /**
+     * 例如说,SysDictTypeConstants、InfDictTypeConstants
+     *
+     * @return 字典类型
+     */
+    String value();
+
+}

+ 70 - 0
iot-framework/iot-starter-excel/src/main/java/com/middle/platform/excel/core/convert/DictConvert.java

@@ -0,0 +1,70 @@
+package com.middle.platform.excel.core.convert;
+
+import cn.hutool.core.convert.Convert;
+import com.alibaba.excel.converters.Converter;
+import com.alibaba.excel.enums.CellDataTypeEnum;
+import com.alibaba.excel.metadata.GlobalConfiguration;
+import com.alibaba.excel.metadata.data.ReadCellData;
+import com.alibaba.excel.metadata.data.WriteCellData;
+import com.alibaba.excel.metadata.property.ExcelContentProperty;
+import com.middle.platform.biz.dict.core.util.DictFrameworkUtils;
+import com.middle.platform.excel.core.annotations.DictFormat;
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * Excel 数据字典转换器
+ */
+@Slf4j
+public class DictConvert implements Converter<Object> {
+
+    @Override
+    public Class<?> supportJavaTypeKey() {
+        throw new UnsupportedOperationException("暂不支持,也不需要");
+    }
+
+    @Override
+    public CellDataTypeEnum supportExcelTypeKey() {
+        throw new UnsupportedOperationException("暂不支持,也不需要");
+    }
+
+    @Override
+    public Object convertToJavaData(ReadCellData readCellData, ExcelContentProperty contentProperty,
+                                    GlobalConfiguration globalConfiguration) {
+        // 使用字典解析
+        String type = getType(contentProperty);
+        String label = readCellData.getStringValue();
+        String value = DictFrameworkUtils.parseDictDataValue(type, label);
+        if (value == null) {
+            log.error("[convertToJavaData][type({}) 解析不掉 label({})]", type, label);
+            return null;
+        }
+        // 将 String 的 value 转换成对应的属性
+        Class<?> fieldClazz = contentProperty.getField().getType();
+        return Convert.convert(fieldClazz, value);
+    }
+
+    @Override
+    public WriteCellData<String> convertToExcelData(Object object, ExcelContentProperty contentProperty,
+                                                    GlobalConfiguration globalConfiguration) {
+        // 空时,返回空
+        if (object == null) {
+            return new WriteCellData<>("");
+        }
+
+        // 使用字典格式化
+        String type = getType(contentProperty);
+        String value = String.valueOf(object);
+        String label = DictFrameworkUtils.getDictDataLabel(type, value);
+        if (label == null) {
+            log.error("[convertToExcelData][type({}) 转换不了 label({})]", type, value);
+            return new WriteCellData<>("");
+        }
+        // 生成 Excel 小表格
+        return new WriteCellData<>(label);
+    }
+
+    private static String getType(ExcelContentProperty contentProperty) {
+        return contentProperty.getField().getAnnotation(DictFormat.class).value();
+    }
+
+}

+ 33 - 0
iot-framework/iot-starter-excel/src/main/java/com/middle/platform/excel/core/convert/JsonConvert.java

@@ -0,0 +1,33 @@
+package com.middle.platform.excel.core.convert;
+
+import com.alibaba.excel.converters.Converter;
+import com.alibaba.excel.enums.CellDataTypeEnum;
+import com.alibaba.excel.metadata.GlobalConfiguration;
+import com.alibaba.excel.metadata.data.WriteCellData;
+import com.alibaba.excel.metadata.property.ExcelContentProperty;
+import com.middle.platform.common.utils.JsonUtils;
+
+/**
+ * Excel Json 转换器
+ *
+ */
+public class JsonConvert implements Converter<Object> {
+
+    @Override
+    public Class<?> supportJavaTypeKey() {
+        throw new UnsupportedOperationException("暂不支持,也不需要");
+    }
+
+    @Override
+    public CellDataTypeEnum supportExcelTypeKey() {
+        throw new UnsupportedOperationException("暂不支持,也不需要");
+    }
+
+    @Override
+    public WriteCellData<String> convertToExcelData(Object value, ExcelContentProperty contentProperty,
+                                                    GlobalConfiguration globalConfiguration) {
+        // 生成 Excel 小表格
+        return new WriteCellData<>(JsonUtils.toJsonString(value));
+    }
+
+}

+ 36 - 0
iot-framework/iot-starter-excel/src/main/java/com/middle/platform/excel/core/convert/MoneyConvert.java

@@ -0,0 +1,36 @@
+package com.middle.platform.excel.core.convert;
+
+import com.alibaba.excel.converters.Converter;
+import com.alibaba.excel.enums.CellDataTypeEnum;
+import com.alibaba.excel.metadata.GlobalConfiguration;
+import com.alibaba.excel.metadata.data.WriteCellData;
+import com.alibaba.excel.metadata.property.ExcelContentProperty;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+
+/**
+ * 金额转换器
+ *
+ */
+public class MoneyConvert implements Converter<Integer> {
+
+    @Override
+    public Class<?> supportJavaTypeKey() {
+        throw new UnsupportedOperationException("暂不支持,也不需要");
+    }
+
+    @Override
+    public CellDataTypeEnum supportExcelTypeKey() {
+        throw new UnsupportedOperationException("暂不支持,也不需要");
+    }
+
+    @Override
+    public WriteCellData<String> convertToExcelData(Integer value, ExcelContentProperty contentProperty,
+                                                    GlobalConfiguration globalConfiguration) {
+        BigDecimal result = BigDecimal.valueOf(value)
+                .divide(new BigDecimal(100), 2, RoundingMode.HALF_UP);
+        return new WriteCellData<>(result.toString());
+    }
+
+}

+ 46 - 0
iot-framework/iot-starter-excel/src/main/java/com/middle/platform/excel/core/util/ExcelUtils.java

@@ -0,0 +1,46 @@
+package com.middle.platform.excel.core.util;
+
+import com.alibaba.excel.EasyExcel;
+import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
+import jakarta.servlet.http.HttpServletResponse;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.util.List;
+
+/**
+ * Excel 工具类
+ *
+ */
+public class ExcelUtils {
+
+    /**
+     * 将列表以 Excel 响应给前端
+     *
+     * @param response 响应
+     * @param filename 文件名
+     * @param sheetName Excel sheet 名
+     * @param head Excel head 头
+     * @param data 数据列表哦
+     * @param <T> 泛型,保证 head 和 data 类型的一致性
+     */
+    public static <T> void write(HttpServletResponse response, String filename, String sheetName,
+                                 Class<T> head, List<T> data) throws IOException {
+        // 输出 Excel
+        EasyExcel.write(response.getOutputStream(), head)
+                .autoCloseStream(false) // 不要自动关闭,交给 Servlet 自己处理
+                .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) // 基于 column 长度,自动适配。最大 255 宽度
+                .sheet(sheetName).doWrite(data);
+        // 设置 header 和 contentType。写在最后的原因是,避免报错时,响应 contentType 已经被修改了
+        response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename, "UTF-8"));
+        response.setContentType("application/vnd.ms-excel;charset=UTF-8");
+    }
+
+    public static <T> List<T> read(MultipartFile file, Class<T> head) throws IOException {
+       return EasyExcel.read(file.getInputStream(), head, null)
+                .autoCloseStream(false)  // 不要自动关闭,交给 Servlet 自己处理
+                .doReadAllSync();
+    }
+
+}

+ 20 - 1
iot-framework/iot-starter-mqtt/pom.xml

@@ -10,11 +10,30 @@
     </parent>
 
     <artifactId>iot-starter-mqtt</artifactId>
-
+    <packaging>jar</packaging>
     <properties>
         <maven.compiler.source>17</maven.compiler.source>
         <maven.compiler.target>17</maven.compiler.target>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     </properties>
 
+    <dependencies>
+        <dependency>
+            <groupId>com.middle.platform</groupId>
+            <artifactId>iot-common</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-integration</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.integration</groupId>
+            <artifactId>spring-integration-stream</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.integration</groupId>
+            <artifactId>spring-integration-mqtt</artifactId>
+        </dependency>
+    </dependencies>
+
 </project>

+ 21 - 0
iot-framework/iot-starter-mqtt/src/main/java/com/middle/platform/mqtt/properties/MqttProperties.java

@@ -0,0 +1,21 @@
+package com.middle.platform.mqtt.properties;
+
+import lombok.Getter;
+import lombok.Setter;
+import org.springframework.boot.autoconfigure.AutoConfiguration;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+/**
+ * @author xucaiqin
+ * @date 2023-10-24 13:37:02
+ */
+@Getter
+@Setter
+@AutoConfiguration
+@ConfigurationProperties(prefix = "mqtt")
+public class MqttProperties {
+    private String url;
+    private String username;
+    private String password;
+    private String clientId;
+}

+ 1 - 0
iot-framework/iot-starter-mqtt/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports

@@ -0,0 +1 @@
+com.middle.platform.mqtt.properties.MqttProperties

+ 4 - 1
iot-framework/iot-starter-mybatis/pom.xml

@@ -42,7 +42,10 @@
             <groupId>com.dameng</groupId>
             <artifactId>DmJdbcDriver18</artifactId>
         </dependency>
-
+        <dependency>
+            <groupId>com.taosdata.jdbc</groupId>
+            <artifactId>taos-jdbcdriver</artifactId>
+        </dependency>
         <dependency>
             <groupId>com.alibaba</groupId>
             <artifactId>druid-spring-boot-3-starter</artifactId>

+ 11 - 0
iot-framework/iot-starter-redis/src/main/java/com/middle/platform/redis/constant/CacheConstant.java

@@ -0,0 +1,11 @@
+package com.middle.platform.redis.constant;
+
+/**
+ * @author xucaiqin
+ * @date 2023-12-21 10:47:47
+ */
+public interface CacheConstant {
+    String USER_CACHE = "user:%s";
+    String DICT_CACHE = "dict:%s";
+    String DICT_ITEM_CACHE = "dictItem:%s:%s";
+}

+ 1 - 0
iot-framework/pom.xml

@@ -28,6 +28,7 @@
         <module>iot-starter-satoken</module>
         <module>iot-starter-pagehelper</module>
         <module>iot-starter-biz-dict</module>
+        <module>iot-starter-excel</module>
     </modules>
 
     <properties>

+ 6 - 0
iot-module/iot-module-data/iot-module-data-biz/pom.xml

@@ -55,5 +55,11 @@
             <groupId>com.middle.platform</groupId>
             <artifactId>iot-starter-redis</artifactId>
         </dependency>
+
+        <dependency>
+            <groupId>com.middle.platform</groupId>
+            <artifactId>iot-starter-mqtt</artifactId>
+        </dependency>
+
     </dependencies>
 </project>

+ 63 - 0
iot-module/iot-module-data/iot-module-data-biz/src/main/java/com/middle/platform/data/biz/config/MqttConfig.java

@@ -0,0 +1,63 @@
+package com.middle.platform.data.biz.config;
+
+import com.middle.platform.mqtt.properties.MqttProperties;
+import jakarta.annotation.Resource;
+import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.integration.annotation.IntegrationComponentScan;
+import org.springframework.integration.channel.DirectChannel;
+import org.springframework.integration.core.MessageProducer;
+import org.springframework.integration.mqtt.core.DefaultMqttPahoClientFactory;
+import org.springframework.integration.mqtt.core.MqttPahoClientFactory;
+import org.springframework.integration.mqtt.inbound.MqttPahoMessageDrivenChannelAdapter;
+import org.springframework.integration.mqtt.support.DefaultPahoMessageConverter;
+import org.springframework.messaging.MessageChannel;
+
+/**
+ * @author xucaiqin
+ */
+@Configuration
+@IntegrationComponentScan
+public class MqttConfig {
+    public static final String input = "mqttInputChannel";
+
+    @Resource
+    private MqttProperties mqttProperties;
+
+    @Bean
+    public MqttPahoClientFactory mqttClientFactory() {
+        DefaultMqttPahoClientFactory factory = new DefaultMqttPahoClientFactory();
+        MqttConnectOptions mqttConnectOptions = new MqttConnectOptions();
+        mqttConnectOptions.setServerURIs(new String[]{mqttProperties.getUrl()});
+        mqttConnectOptions.setUserName(mqttProperties.getUsername());
+        mqttConnectOptions.setPassword(mqttProperties.getPassword().toCharArray());
+        // 客户端断线时暂时不清除,直到超时注销
+        mqttConnectOptions.setCleanSession(false);
+        mqttConnectOptions.setAutomaticReconnect(true);
+        factory.setConnectionOptions(mqttConnectOptions);
+        return factory;
+    }
+
+    @Bean
+    public MessageChannel mqttInputChannel() {
+        return new DirectChannel();
+    }
+
+    /**
+     * 消息入站
+     *
+     * @param mqttPahoClientFactory
+     * @return
+     */
+    @Bean("mqttPahoMessageDrivenChannelAdapter")
+    public MessageProducer inbound(MqttPahoClientFactory mqttPahoClientFactory) {
+        MqttPahoMessageDrivenChannelAdapter adapter = new MqttPahoMessageDrivenChannelAdapter(
+                mqttProperties.getClientId(), mqttPahoClientFactory,"/iot/device");
+        adapter.setCompletionTimeout(5000);
+        adapter.setConverter(new DefaultPahoMessageConverter());
+        adapter.setQos(1);
+        adapter.setOutputChannel(mqttInputChannel());
+        return adapter;
+    }
+}

+ 18 - 3
iot-module/iot-module-data/iot-module-data-biz/src/main/java/com/middle/platform/data/biz/controller/IndexController.java

@@ -2,10 +2,14 @@ package com.middle.platform.data.biz.controller;
 
 import com.middle.platform.common.utils.DateTimeUtil;
 import com.middle.platform.common.utils.Result;
+import com.middle.platform.data.biz.mapper.ProductMapper;
+import com.middle.platform.data.biz.pojo.ProductPara;
+import jakarta.annotation.Resource;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.integration.mqtt.inbound.MqttPahoMessageDrivenChannelAdapter;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.Arrays;
 
 /**
  * @author xucaiqin
@@ -16,9 +20,20 @@ import org.springframework.web.bind.annotation.RestController;
 public class IndexController {
     @Value("${spring.application.name}")
     private String name;
+    @Resource
+    private ProductMapper productMapper;
+    @Resource
+    private MqttPahoMessageDrivenChannelAdapter mqttPahoMessageDrivenChannelAdapter;
 
     @GetMapping("")
     public Result<Object> server() {
+        mqttPahoMessageDrivenChannelAdapter.addTopic("/iot/car", 0);
+        System.out.println(Arrays.toString(mqttPahoMessageDrivenChannelAdapter.getTopic()));
         return Result.ok(name + ":" + DateTimeUtil.nowStr());
     }
+
+    @PostMapping("test")
+    public void test(@RequestBody ProductPara productPara) {
+        productMapper.insert(productPara);
+    }
 }

+ 18 - 0
iot-module/iot-module-data/iot-module-data-biz/src/main/java/com/middle/platform/data/biz/mapper/ProductMapper.java

@@ -0,0 +1,18 @@
+package com.middle.platform.data.biz.mapper;
+
+import com.baomidou.dynamic.datasource.annotation.DS;
+import com.middle.platform.data.biz.pojo.ProductPara;
+import org.apache.ibatis.annotations.Insert;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * @author xucaiqin
+ * @date 2023-12-20 09:22:38
+ */
+@Mapper
+@DS("td")
+public interface ProductMapper {
+    @Insert("INSERT INTO device_gnss_${deviceId} (create_time,point_value,raw_value,origin_time) VALUES (#{createTime},#{pointValue},#{rawValue},#{originTime})")
+    void insert(ProductPara productPara);
+
+}

+ 30 - 0
iot-module/iot-module-data/iot-module-data-biz/src/main/java/com/middle/platform/data/biz/pojo/ProductPara.java

@@ -0,0 +1,30 @@
+package com.middle.platform.data.biz.pojo;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.Date;
+
+/**
+ * @author xucaiqin
+ * @date 2023-12-20 09:26:56
+ */
+@Getter
+@Setter
+public class ProductPara {
+    private String deviceId;
+    private String pointId;
+    /**
+     * 处理值,进行过缩放、格式化等操作
+     */
+    private String pointValue;
+
+    /**
+     * 原始值
+     */
+    private String rawValue;
+
+    private Date createTime;
+
+    private Date originTime;
+}

+ 32 - 0
iot-module/iot-module-data/iot-module-data-biz/src/main/java/com/middle/platform/data/biz/service/MqttService.java

@@ -0,0 +1,32 @@
+package com.middle.platform.data.biz.service;
+
+import com.middle.platform.data.biz.config.MqttConfig;
+import com.middle.platform.data.biz.service.mqtt.MqttStrategyFactory;
+import jakarta.annotation.Resource;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.context.annotation.Bean;
+import org.springframework.integration.annotation.ServiceActivator;
+import org.springframework.messaging.MessageHandler;
+import org.springframework.messaging.MessageHeaders;
+import org.springframework.stereotype.Component;
+
+@Component
+@Slf4j
+public class MqttService {
+    @Resource
+    private MqttStrategyFactory mqttStrategyFactory;
+
+    @ServiceActivator(inputChannel = MqttConfig.input)
+    @Bean
+    public MessageHandler test() {
+        return message -> {
+            MessageHeaders headers = message.getHeaders();
+            Object payload = message.getPayload();
+            String topic = (String) headers.get("mqtt_receivedTopic");
+            log.info("topic {}",topic);
+            log.info("payload {}",payload);
+//            MqttTopicStrategy mqttTopicStrategy = mqttStrategyFactory.getByTopic(topic);
+//            mqttTopicStrategy.dealMsg(payload);
+        };
+    }
+}

+ 17 - 0
iot-module/iot-module-data/iot-module-data-biz/src/main/java/com/middle/platform/data/biz/service/mqtt/MqttStrategyFactory.java

@@ -0,0 +1,17 @@
+package com.middle.platform.data.biz.service.mqtt;
+
+import jakarta.annotation.Resource;
+import org.springframework.stereotype.Component;
+
+import java.util.Map;
+
+@Component
+public class MqttStrategyFactory {
+    @Resource
+    private Map<String, MqttTopicStrategy> mqttTopicStrategyMap;
+
+    public MqttTopicStrategy getByTopic(String topic) {
+        return mqttTopicStrategyMap.get(topic);
+    }
+
+}

+ 29 - 0
iot-module/iot-module-data/iot-module-data-biz/src/main/java/com/middle/platform/data/biz/service/mqtt/MqttTopicInit.java

@@ -0,0 +1,29 @@
+package com.middle.platform.data.biz.service.mqtt;
+
+public class MqttTopicInit {
+    private String topic;
+    private String name;
+
+
+//
+//    public static String strategy(String topic) {
+//        for (MqttTopicEnum value : MqttTopicEnum.values()) {
+//            if (StringUtils.equals(value.getTopic(), topic)) {
+//                String beanName = value.getName();
+//                char[] chars = beanName.toCharArray();
+//                chars[0] += 32;
+//                return String.valueOf(chars);
+//            }
+//        }
+//        return null;
+//    }
+//
+//    public static String[] getTopics() {
+//        List<String> res = new ArrayList<>();
+//        for (MqttTopicEnum value : MqttTopicEnum.values()) {
+//            res.add(value.topic);
+//        }
+//        return res.toArray(String[]::new);
+//    }
+
+}

+ 6 - 0
iot-module/iot-module-data/iot-module-data-biz/src/main/java/com/middle/platform/data/biz/service/mqtt/MqttTopicStrategy.java

@@ -0,0 +1,6 @@
+package com.middle.platform.data.biz.service.mqtt;
+
+public interface MqttTopicStrategy {
+    void dealMsg(Object msg);
+
+}

+ 19 - 0
iot-module/iot-module-data/iot-module-data-biz/src/main/java/com/middle/platform/data/biz/service/mqtt/impl/AttrReportStrategy.java

@@ -0,0 +1,19 @@
+package com.middle.platform.data.biz.service.mqtt.impl;
+
+import com.middle.platform.data.biz.service.mqtt.MqttTopicStrategy;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+/**
+ * 属性上报
+ */
+@Service
+@Slf4j
+public class AttrReportStrategy implements MqttTopicStrategy {
+
+    @Override
+    public void dealMsg(Object msg) {
+        log.debug("属性上报数据:{}", msg);
+
+    }
+}

+ 5 - 0
iot-module/iot-module-data/iot-module-data-biz/src/main/resources/mapper/ProductMapper.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.middle.platform.data.biz.mapper.ProductMapper">
+
+</mapper>

+ 8 - 0
iot-module/iot-module-manage/iot-module-manage-biz/pom.xml

@@ -58,5 +58,13 @@
             <groupId>com.middle.platform</groupId>
             <artifactId>iot-starter-redis</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.middle.platform</groupId>
+            <artifactId>iot-starter-excel</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.middle.platform</groupId>
+            <artifactId>iot-module-system-api</artifactId>
+        </dependency>
     </dependencies>
 </project>

+ 2 - 0
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/ManageApplication.java

@@ -2,12 +2,14 @@ package com.middle.platform.manage.biz;
 
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
 
 /**
  * @author xucaiqin
  * @date 2023-12-17 10:50:09
  */
 @SpringBootApplication
+@EnableTransactionManagement
 public class ManageApplication {
 
     public static void main(String[] args) {

+ 17 - 0
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/config/FeignConfig.java

@@ -0,0 +1,17 @@
+package com.middle.platform.manage.biz.config;
+
+import com.middle.platform.system.api.feign.DictApi;
+import com.middle.platform.system.api.feign.UserApi;
+import org.springframework.cloud.openfeign.EnableFeignClients;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * 配置feign接口
+ *
+ * @author xucaiqin
+ * @date 2023-12-19 11:00:25
+ */
+@Configuration
+@EnableFeignClients(clients = {UserApi.class, DictApi.class})
+public class FeignConfig {
+}

+ 10 - 0
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/constant/UrlCategory.java

@@ -0,0 +1,10 @@
+package com.middle.platform.manage.biz.constant;
+
+/**
+ * @author xucaiqin
+ * @date 2023-12-21 09:23:36
+ */
+public interface UrlCategory {
+    Integer init = 1;
+    Integer custom = 2;
+}

+ 39 - 0
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/constant/UrlInit.java

@@ -0,0 +1,39 @@
+package com.middle.platform.manage.biz.constant;
+
+/**
+ * @author xucaiqin
+ * @date 2023-12-21 09:25:19
+ */
+public enum UrlInit {
+    ATTR_UP("/product/%s/${deviceName}/property/post", "设备属性上报", 1, 1),
+    ATTR_DOWN("/product/%s/${deviceName}/property/post_reply", "云端响应属性上报", 2, 2),
+    ;
+    private final String prefix;
+    private final String desc;
+    private final Integer permission;
+    private final Integer func;
+
+
+    UrlInit(String prefix, String desc, Integer permission, Integer func) {
+        this.prefix = prefix;
+        this.desc = desc;
+        this.permission = permission;
+        this.func = func;
+    }
+
+    public String getPrefix() {
+        return prefix;
+    }
+
+    public Integer getPermission() {
+        return permission;
+    }
+
+    public String getDesc() {
+        return desc;
+    }
+
+    public Integer getFunc() {
+        return func;
+    }
+}

+ 10 - 0
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/constant/UrlProtocol.java

@@ -0,0 +1,10 @@
+package com.middle.platform.manage.biz.constant;
+
+/**
+ * @author xucaiqin
+ * @date 2023-12-21 09:23:36
+ */
+public interface UrlProtocol {
+    Integer MQTT = 1;
+    Integer HTTP = 2;
+}

+ 18 - 0
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/controller/IotDeviceController.java

@@ -1,13 +1,19 @@
 package com.middle.platform.manage.biz.controller;
 
 import com.middle.platform.common.utils.Result;
+import com.middle.platform.excel.core.util.ExcelUtils;
 import com.middle.platform.manage.biz.domain.req.DevicePage;
 import com.middle.platform.manage.biz.domain.req.IotDeviceFlag;
 import com.middle.platform.manage.biz.domain.req.IotDevicePara;
+import com.middle.platform.manage.biz.domain.vo.DeviceImportExcelVo;
 import com.middle.platform.manage.biz.service.IotDeviceService;
 import lombok.RequiredArgsConstructor;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.IOException;
+import java.util.List;
 
 
 /**
@@ -44,6 +50,18 @@ public class IotDeviceController {
         return Result.ok(iotDeviceService.save(iotDevicePara));
     }
 
+    /**
+     * 导入设备
+     *
+     * @param file
+     * @return
+     */
+    @PostMapping("/importData")
+    public Result<Object> importData(@RequestParam("file") MultipartFile file) throws IOException {
+        List<DeviceImportExcelVo> list = ExcelUtils.read(file, DeviceImportExcelVo.class);
+        return Result.ok();
+    }
+
     /**
      * 删除设备
      *

+ 1 - 10
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/domain/req/IotProductPara.java

@@ -12,21 +12,12 @@ import lombok.Setter;
 @Setter
 public class IotProductPara {
 
-    /**
-     * 产品编码
-     */
-    private String code;
-
     /**
      * 产品名称
      */
     @NotBlank(message = "产品名称不能为空")
     private String name;
 
-    /**
-     * 密匙(未知作用)
-     */
-    private String secret;
 
     /**
      * 节点类型:1网关、2子设备
@@ -41,7 +32,7 @@ public class IotProductPara {
     private Integer networkType;
 
     /**
-     * 上报协议
+     * 上报协议 1-mqtt 2-http 3-coap 4-tcp 5-udp
      */
     @NotNull(message = "上报协议不能为空")
     private Integer reportProtocol;

+ 43 - 0
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/domain/vo/DeviceImportExcelVo.java

@@ -0,0 +1,43 @@
+package com.middle.platform.manage.biz.domain.vo;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.middle.platform.excel.core.annotations.DictFormat;
+import com.middle.platform.excel.core.convert.DictConvert;
+import com.middle.platform.system.api.enums.DictType;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.experimental.Accessors;
+
+/**
+ * 用户 Excel 导入 VO
+ */
+@Data
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+@Accessors(chain = false) // 设置 chain = false,避免用户导入有问题
+public class DeviceImportExcelVo {
+
+    @ExcelProperty("设备名称")
+    private String name;
+
+    @ExcelProperty("sn")
+    private String sn;
+
+    @ExcelProperty("备注名称")
+    private String subtitle;
+
+    @ExcelProperty("备注")
+    private String remark;
+
+    @ExcelProperty(value = "节点类型", converter = DictConvert.class)
+    @DictFormat(DictType.NODE_TYPE)
+    private Integer nodeType;
+
+    @ExcelProperty(value = "联网类型", converter = DictConvert.class)
+    @DictFormat(DictType.NETWORK_TYPE)
+    private Integer status;
+
+}

+ 6 - 0
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/domain/vo/IotProductVo.java

@@ -34,30 +34,36 @@ public class IotProductVo extends BaseVO {
      * 节点类型:1网关、2子设备
      */
     private Integer nodeType;
+    private String nodeTypeLabel;
 
     /**
      * 联网类型
      */
     private Integer networkType;
+    private String networkTypeLabel;
 
     /**
      * 上报协议
      */
     private Integer reportProtocol;
+    private String reportProtocolLabel;
     /**
      * 设备厂商
      */
     private Integer vendors;
+    private String vendorsLabel;
 
     /**
      * 数据格式
      */
     private Integer dataFormat;
+    private String dataFormatLabel;
 
     /**
      * 认证方式
      */
     private Integer authType;
+    private String authTypeLabel;
 
     /**
      * 产品标签

+ 6 - 4
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/mapper/IotUrlMapper.java

@@ -4,10 +4,12 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.middle.platform.manage.biz.entity.IotUrl;
 import org.apache.ibatis.annotations.Mapper;
 
+import java.util.List;
+
 /**
-* @date 2023-12-19 13:43:38
-* @author xucaiqin
-*/
+ * @author xucaiqin
+ * @date 2023-12-19 13:43:38
+ */
 @Mapper
 public interface IotUrlMapper extends BaseMapper<IotUrl> {
-}
+}

+ 11 - 0
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/service/IotCloudService.java

@@ -1,6 +1,7 @@
 package com.middle.platform.manage.biz.service;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.middle.platform.common.constant.Global;
 import com.middle.platform.common.exception.BusinessException;
 import com.middle.platform.manage.biz.domain.req.IotCloudPara;
 import com.middle.platform.manage.biz.domain.req.IotCloudTest;
@@ -84,4 +85,14 @@ public class IotCloudService {
     public Object getCloud(Long productId) {
         return query(productId);
     }
+
+    /**
+     * 通过产品id删除关联的云函数
+     *
+     * @param id 产品id
+     */
+    public void removeProduct(Long id) {
+        iotCloudMapper.delete(new LambdaQueryWrapper<IotCloud>().eq(IotCloud::getProductId, id).eq(IotCloud::getDelFlag, Global.UN_DEL));
+
+    }
 }

+ 9 - 0
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/service/IotModService.java

@@ -1,6 +1,7 @@
 package com.middle.platform.manage.biz.service;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.middle.platform.common.constant.Global;
 import com.middle.platform.manage.biz.domain.req.IotModPara;
 import com.middle.platform.manage.biz.entity.IotMod;
 import com.middle.platform.manage.biz.mapper.IotModMapper;
@@ -53,4 +54,12 @@ public class IotModService {
     public Object queryMod(Long productId) {
         return query(productId);
     }
+    /**
+     * 通过产品id删除关联的物模型
+     *
+     * @param id 产品id
+     */
+    public void removeProduct(Long id) {
+        iotModMapper.delete(new LambdaQueryWrapper<IotMod>().eq(IotMod::getProductId, id).eq(IotMod::getDelFlag, Global.UN_DEL));
+    }
 }

+ 40 - 3
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/service/IotProductService.java

@@ -1,6 +1,8 @@
 package com.middle.platform.manage.biz.service;
 
+import cn.hutool.core.util.IdUtil;
 import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
 import com.middle.platform.common.exception.BusinessException;
 import com.middle.platform.common.utils.PageRes;
 import com.middle.platform.manage.biz.domain.req.IotProductPara;
@@ -11,11 +13,17 @@ import com.middle.platform.manage.biz.entity.IotDevice;
 import com.middle.platform.manage.biz.entity.IotProduct;
 import com.middle.platform.manage.biz.mapper.IotDeviceMapper;
 import com.middle.platform.manage.biz.mapper.IotProductMapper;
+import com.middle.platform.system.api.enums.DictType;
+import com.middle.platform.system.api.feign.DictApi;
+import com.middle.platform.system.api.feign.UserApi;
+import jakarta.annotation.Resource;
 import lombok.RequiredArgsConstructor;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
+import java.util.Optional;
 
 /**
  * @author xucaiqin
@@ -26,6 +34,14 @@ import java.util.List;
 public class IotProductService {
     private final IotProductMapper iotProductMapper;
     private final IotDeviceMapper iotDeviceMapper;
+    private final IotUrlService iotUrlService;
+    private final IotModService iotModService;
+    private final IotCloudService iotCloudService;
+
+    @Resource
+    private UserApi userApi;
+    @Resource
+    private  DictApi dictApi;
 
     /**
      * 分页查询产品数据
@@ -36,7 +52,19 @@ public class IotProductService {
     public Object pageQuery(ProductPage devicePage) {
         PageHelper.startPage(devicePage.getPage(), devicePage.getPageSize());
         List<IotProductVo> iotProductVos = iotProductMapper.pageQuery(devicePage);
-        return new PageRes<>(iotProductVos);
+        PageInfo<IotProductVo> pageInfo = new PageInfo<>(iotProductVos);
+        iotProductVos.forEach(u -> {
+            Optional.ofNullable(userApi.queryUser(u.getCreateBy())).ifPresent(userCache -> u.setCreateByLabel(userCache.getName()));
+            Optional.ofNullable(userApi.queryUser(u.getUpdateBy())).ifPresent(userCache -> u.setUpdateByLabel(userCache.getName()));
+            Optional.ofNullable(dictApi.query(DictType.AUTH_TYPE, String.valueOf(u.getAuthType()))).ifPresent(cache -> u.setAuthTypeLabel(cache.getLabel()));
+            Optional.ofNullable(dictApi.query(DictType.NODE_TYPE, String.valueOf(u.getNodeType()))).ifPresent(cache -> u.setNodeTypeLabel(cache.getLabel()));
+            Optional.ofNullable(dictApi.query(DictType.NETWORK_TYPE, String.valueOf(u.getNetworkType()))).ifPresent(cache -> u.setNetworkTypeLabel(cache.getLabel()));
+            Optional.ofNullable(dictApi.query(DictType.REPORT_PROTOCOL_TYPE, String.valueOf(u.getReportProtocol()))).ifPresent(cache -> u.setReportProtocolLabel(cache.getLabel()));
+            Optional.ofNullable(dictApi.query(DictType.VENDORS_TYPE, String.valueOf(u.getVendors()))).ifPresent(cache -> u.setVendorsLabel(cache.getLabel()));
+            Optional.ofNullable(dictApi.query(DictType.DATA_FORMAT_TYPE, String.valueOf(u.getDataFormat()))).ifPresent(cache -> u.setDataFormatLabel(cache.getLabel()));
+
+        });
+        return new PageRes<>(pageInfo, iotProductVos);
     }
 
     /**
@@ -47,9 +75,9 @@ public class IotProductService {
      */
     public Object save(IotProductPara iotProductPara) {
         IotProduct iotProduct = new IotProduct();
-        iotProduct.setCode(iotProductPara.getCode());
+        iotProduct.setCode(IdUtil.nanoId(12));
         iotProduct.setName(iotProductPara.getName());
-        iotProduct.setSecret(iotProductPara.getSecret());
+        iotProduct.setSecret(IdUtil.nanoId());
         iotProduct.setNodeType(iotProductPara.getNodeType());
         iotProduct.setNetworkType(iotProductPara.getNetworkType());
         iotProduct.setReportProtocol(iotProductPara.getReportProtocol());
@@ -60,6 +88,8 @@ public class IotProductService {
         iotProduct.setSize(0);
         iotProduct.setRemark(iotProductPara.getRemark());
         iotProductMapper.insert(iotProduct);
+        /*保存默认topic*/
+        iotUrlService.save(iotProduct);
         return null;
     }
 
@@ -69,9 +99,16 @@ public class IotProductService {
      * @param id 产品id
      * @return
      */
+    @Transactional(rollbackFor = Exception.class)
     public Object remove(Long id) {
         delProductCheck(id);
         iotProductMapper.deleteById(id);
+        /*删除物模型*/
+        iotModService.removeProduct(id);
+        /*删除云函数*/
+        iotCloudService.removeProduct(id);
+        /*删除关联url*/
+        iotUrlService.removeProduct(id);
         return true;
     }
 

+ 37 - 0
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/service/IotUrlService.java

@@ -1,8 +1,13 @@
 package com.middle.platform.manage.biz.service;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.middle.platform.common.constant.Global;
 import com.middle.platform.common.exception.BusinessException;
+import com.middle.platform.manage.biz.constant.UrlCategory;
+import com.middle.platform.manage.biz.constant.UrlInit;
+import com.middle.platform.manage.biz.constant.UrlProtocol;
 import com.middle.platform.manage.biz.domain.req.IotUrlPara;
+import com.middle.platform.manage.biz.entity.IotProduct;
 import com.middle.platform.manage.biz.entity.IotUrl;
 import com.middle.platform.manage.biz.mapper.IotUrlMapper;
 import lombok.RequiredArgsConstructor;
@@ -84,4 +89,36 @@ public class IotUrlService {
     public Object getUrl(Long productId, Integer type) {
         return iotUrlMapper.selectList(new LambdaQueryWrapper<IotUrl>().eq(IotUrl::getProductId, productId).eq(IotUrl::getType, type));
     }
+
+
+    /**
+     * 保存产品默认的topic
+     *
+     * @param iotProduct 产品信息
+     */
+    public void save(IotProduct iotProduct) {
+        if (Objects.equals(iotProduct.getReportProtocol(), UrlProtocol.MQTT)) {
+            for (UrlInit value : UrlInit.values()) {
+                IotUrl iotUrl = new IotUrl();
+                iotUrl.setProductId(iotProduct.getId());
+                iotUrl.setCategory(UrlCategory.init);
+                iotUrl.setFunc(value.getFunc());
+                iotUrl.setUrl(String.format(value.getPrefix(), iotProduct.getCode()));
+                iotUrl.setPermission(value.getPermission());
+                iotUrl.setType(iotProduct.getReportProtocol());
+                iotUrl.setRemark(value.getDesc());
+                iotUrlMapper.insert(iotUrl);
+            }
+        }
+
+    }
+
+    /**
+     * 通过产品id删除关联的地址
+     *
+     * @param id 产品id
+     */
+    public void removeProduct(Long id) {
+        iotUrlMapper.delete(new LambdaQueryWrapper<IotUrl>().eq(IotUrl::getProductId, id).eq(IotUrl::getDelFlag, Global.UN_DEL));
+    }
 }

+ 2 - 0
iot-module/iot-module-manage/iot-module-manage-biz/src/main/resources/bootstrap.yaml

@@ -18,5 +18,7 @@ spring:
       write-date-timestamps-as-nanoseconds: false # 设置不使用 nanoseconds 的格式。例如说 1611460870.401,而是直接 1611460870401
       write-durations-as-timestamps: true # 设置 Duration 的格式,使用时间戳
       fail-on-empty-beans: false # 允许序列化无属性的 Bean
+  main:
+    allow-bean-definition-overriding: true
 
 

+ 1 - 0
iot-module/iot-module-manage/iot-module-manage-biz/src/main/resources/mapper/IotProductMapper.xml

@@ -38,6 +38,7 @@
           <if test="keywords != null and keywords != ''">
               and ip.name like concat('%', #{keywords,jdbcType=VARCHAR}, '%')
           </if>
+          and ip.del_flag = 0
       </where>
   </select>
 </mapper>

+ 4 - 2
iot-module/iot-module-manage/iot-module-manage-biz/src/main/resources/mapper/IotUrlMapper.xml

@@ -19,7 +19,9 @@
   </resultMap>
   <sql id="Base_Column_List">
     <!--@mbg.generated-->
-    id, product_id, url, `type`, permission, remark, create_by, create_time, update_by, 
+    id, product_id, url, `type`, permission, remark, create_by, create_time, update_by,
     update_time, delete_time, del_flag
   </sql>
-</mapper>
+
+
+</mapper>

+ 14 - 0
iot-module/iot-module-system/iot-module-system-api/src/main/java/com/middle/platform/system/api/enums/DictType.java

@@ -0,0 +1,14 @@
+package com.middle.platform.system.api.enums;
+
+/**
+ * @author xucaiqin
+ * @date 2023-12-21 11:26:25
+ */
+public interface DictType {
+    String NODE_TYPE = "nodeType";
+    String NETWORK_TYPE = "networkType";
+    String REPORT_PROTOCOL_TYPE = "reportProtocolType";
+    String VENDORS_TYPE = "vendorsType";
+    String DATA_FORMAT_TYPE = "dataFormatType";
+    String AUTH_TYPE = "authType";
+}

+ 17 - 3
iot-module/iot-module-system/iot-module-system-api/src/main/java/com/middle/platform/system/api/feign/DictApi.java

@@ -3,20 +3,34 @@ package com.middle.platform.system.api.feign;
 import com.middle.platform.common.constant.RpcConstants;
 import com.middle.platform.common.utils.Result;
 import com.middle.platform.system.api.enums.ApiConstants;
+import com.middle.platform.system.api.pojo.DictCache;
 import com.middle.platform.system.api.pojo.DictDto;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 
+import java.util.List;
+
 /**
  * @author xucaiqin
  * @date 2023-12-17 13:51:33
  */
-@FeignClient(name = ApiConstants.NAME)
+@FeignClient(name = ApiConstants.NAME, contextId = "dictApi")
 public interface DictApi {
     String PREFIX = RpcConstants.RPC_API_PREFIX + "/dict-data";
 
-    @GetMapping(PREFIX + "/get")
+    @GetMapping(PREFIX + "/getLabel")
     Result<DictDto> getDictData(@RequestParam("dictType") String dictType,
-                                @RequestParam("value") String value);
+                                @RequestParam(value = "value",required = false) String value);
+
+    @GetMapping(PREFIX + "/getValue")
+    Result<DictDto> getDictValue(@RequestParam("dictType") String dictType,
+                                 @RequestParam(value = "label",required = false) String label);
+
+    @GetMapping(PREFIX + "/query")
+    DictCache query(@RequestParam("dictType") String dictType,
+                    @RequestParam("value") String value);
+
+    @GetMapping(PREFIX + "/queryList")
+    List<DictCache> queryList(@RequestParam("dictType") String dictType);
 }

+ 5 - 1
iot-module/iot-module-system/iot-module-system-api/src/main/java/com/middle/platform/system/api/feign/UserApi.java

@@ -3,6 +3,7 @@ package com.middle.platform.system.api.feign;
 import com.middle.platform.common.constant.RpcConstants;
 import com.middle.platform.system.api.enums.ApiConstants;
 import com.middle.platform.system.api.pojo.SysUserFlag;
+import com.middle.platform.system.api.pojo.UserCache;
 import com.middle.platform.system.api.pojo.UserDto;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -14,7 +15,7 @@ import org.springframework.web.bind.annotation.RequestParam;
  * @author xucaiqin
  * @date 2023-12-17 13:51:33
  */
-@FeignClient(name = ApiConstants.NAME)
+@FeignClient(name = ApiConstants.NAME, contextId = "userApi")
 public interface UserApi {
     String prefix = RpcConstants.RPC_API_PREFIX + "/user";
 
@@ -26,4 +27,7 @@ public interface UserApi {
 
     @PostMapping(prefix + "/changeUse")
     void changeUse(@RequestBody SysUserFlag sysUserFlag);
+
+    @GetMapping(prefix + "/query")
+    UserCache queryUser(@RequestParam("id") Long id);
 }

+ 15 - 0
iot-module/iot-module-system/iot-module-system-api/src/main/java/com/middle/platform/system/api/pojo/DictCache.java

@@ -0,0 +1,15 @@
+package com.middle.platform.system.api.pojo;
+
+import lombok.Data;
+
+import java.io.Serial;
+import java.io.Serializable;
+
+@Data
+public class DictCache implements Serializable {
+    @Serial
+    private static final long serialVersionUID = -8320243045652875823L;
+    private String label;
+    private String value;
+    private String dictType;
+}

+ 6 - 1
iot-module/iot-module-system/iot-module-system-api/src/main/java/com/middle/platform/system/api/pojo/DictDto.java

@@ -2,8 +2,13 @@ package com.middle.platform.system.api.pojo;
 
 import lombok.Data;
 
+import java.io.Serial;
+import java.io.Serializable;
+
 @Data
-public class DictDto {
+public class DictDto implements Serializable {
+    @Serial
+    private static final long serialVersionUID = 5537740901976152166L;
     private String label;
     private String value;
     private String dictType;

+ 20 - 0
iot-module/iot-module-system/iot-module-system-api/src/main/java/com/middle/platform/system/api/pojo/UserCache.java

@@ -0,0 +1,20 @@
+package com.middle.platform.system.api.pojo;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.io.Serial;
+import java.io.Serializable;
+
+/**
+ * @author xucaiqin
+ * @date 2023-12-17 10:50:57
+ */
+@Getter
+@Setter
+public class UserCache implements Serializable {
+    @Serial
+    private static final long serialVersionUID = -7706416979092413902L;
+    private Long id;
+    private String name;
+}

+ 6 - 1
iot-module/iot-module-system/iot-module-system-api/src/main/java/com/middle/platform/system/api/pojo/UserDto.java

@@ -3,13 +3,18 @@ package com.middle.platform.system.api.pojo;
 import lombok.Getter;
 import lombok.Setter;
 
+import java.io.Serial;
+import java.io.Serializable;
+
 /**
  * @author xucaiqin
  * @date 2023-12-17 10:50:57
  */
 @Getter
 @Setter
-public class UserDto {
+public class UserDto implements Serializable {
+    @Serial
+    private static final long serialVersionUID = -3306453515047824188L;
     private Long id;
     private String username;
     private String password;

+ 56 - 3
iot-module/iot-module-system/iot-module-system-biz/src/main/java/com/middle/platform/system/biz/api/DictApiImpl.java

@@ -1,14 +1,23 @@
 package com.middle.platform.system.biz.api;
 
 import com.middle.platform.common.utils.Result;
+import com.middle.platform.redis.constant.CacheConstant;
 import com.middle.platform.system.api.feign.DictApi;
+import com.middle.platform.system.api.pojo.DictCache;
 import com.middle.platform.system.api.pojo.DictDto;
 import com.middle.platform.system.biz.service.SysDictItemService;
 import jakarta.annotation.Resource;
+import lombok.RequiredArgsConstructor;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.BeanUtils;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.util.CollectionUtils;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.List;
 import java.util.Objects;
+import java.util.Optional;
 
 /**
  * @author xucaiqin
@@ -16,16 +25,60 @@ import java.util.Objects;
  */
 @RestController
 @Validated
+@RequiredArgsConstructor
 public class DictApiImpl implements DictApi {
+    private final SysDictItemService sysDictItemService;
     @Resource
-    private SysDictItemService sysDictItemService;
+    private RedisTemplate<String, Object> redisTemplate;
 
     @Override
     public Result<DictDto> getDictData(String dictType, String value) {
-        DictDto dictDto = sysDictItemService.queryBy(dictType, value);
-        if (Objects.nonNull(dictDto)) {
+        DictCache dictCache = query(dictType, value);
+        if (Objects.nonNull(dictCache)) {
+            DictDto dictDto = new DictDto();
+            BeanUtils.copyProperties(dictCache, dictDto);
             return Result.ok(dictDto);
         }
         return Result.failed();
     }
+
+    @Override
+    public Result<DictDto> getDictValue(String dictType, String label) {
+        List<DictCache> dictCaches = queryList(dictType);
+        if (CollectionUtils.isEmpty(dictCaches)) {
+            return Result.failed();
+        }
+        Optional<DictDto> first = dictCaches.stream().filter(a -> StringUtils.equals(a.getLabel(), label)).map(d -> {
+            DictDto dictDto = new DictDto();
+            BeanUtils.copyProperties(d, dictDto);
+            return dictDto;
+        }).findFirst();
+        return first.map(Result::ok).orElseGet(Result::failed);
+    }
+
+    @Override
+    public DictCache query(String dictType, String value) {
+        DictCache dictCache = (DictCache) redisTemplate.opsForValue().get(String.format(CacheConstant.DICT_ITEM_CACHE, dictType, value));
+        if (Objects.isNull(dictCache)) {
+            DictCache query = sysDictItemService.query(dictType, value);
+            Optional.ofNullable(query).ifPresent(dict -> redisTemplate.opsForValue().set(String.format(CacheConstant.DICT_ITEM_CACHE, dictType, value), dict));
+            return query;
+        }
+        return dictCache;
+    }
+
+    @Override
+    public List<DictCache> queryList(String dictType) {
+        List<DictCache> dictCache = (List<DictCache>) redisTemplate.opsForValue().get(String.format(CacheConstant.DICT_CACHE, dictType));
+        if (CollectionUtils.isEmpty(dictCache)) {
+            List<DictCache> query = sysDictItemService.query(dictType);
+            Optional.ofNullable(query).ifPresent(user -> {
+                if (!CollectionUtils.isEmpty(user)) {
+                    redisTemplate.opsForValue().set(String.format(CacheConstant.DICT_CACHE, dictType), query);
+                }
+            });
+            return query;
+        }
+        return dictCache;
+    }
 }

+ 20 - 0
iot-module/iot-module-system/iot-module-system-biz/src/main/java/com/middle/platform/system/biz/api/UserApiImpl.java

@@ -1,14 +1,21 @@
 package com.middle.platform.system.biz.api;
 
+import com.middle.platform.redis.constant.CacheConstant;
 import com.middle.platform.system.api.feign.UserApi;
 import com.middle.platform.system.api.pojo.SysUserFlag;
+import com.middle.platform.system.api.pojo.UserCache;
 import com.middle.platform.system.api.pojo.UserDto;
 import com.middle.platform.system.biz.service.SysUserService;
+import jakarta.annotation.Resource;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.Objects;
+import java.util.Optional;
+
 /**
  * @author xucaiqin
  * @date 2023-12-19 10:33:17
@@ -19,6 +26,8 @@ import org.springframework.web.bind.annotation.RestController;
 @Slf4j
 public class UserApiImpl implements UserApi {
     private final SysUserService sysUserService;
+    @Resource
+    private  RedisTemplate<String, Object> redisTemplate;
 
     @Override
     public void resetPassword(Long id) {
@@ -26,6 +35,17 @@ public class UserApiImpl implements UserApi {
         sysUserService.resetPass(id);
     }
 
+    @Override
+    public UserCache queryUser(Long id) {
+        UserCache userCache = (UserCache) redisTemplate.opsForValue().get(String.format(CacheConstant.USER_CACHE, id));
+        if (Objects.isNull(userCache)) {
+            UserCache query = sysUserService.query(id);
+            Optional.ofNullable(query).ifPresent(user -> redisTemplate.opsForValue().set(String.format(CacheConstant.USER_CACHE, id), query));
+            return query;
+        }
+        return userCache;
+    }
+
     @Override
     public void changeUse(SysUserFlag sysUserFlag) {
         sysUserService.changeUse(sysUserFlag);

+ 7 - 0
iot-module/iot-module-system/iot-module-system-biz/src/main/java/com/middle/platform/system/biz/mapper/SysDictItemMapper.java

@@ -1,8 +1,12 @@
 package com.middle.platform.system.biz.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.middle.platform.system.api.pojo.DictCache;
 import com.middle.platform.system.biz.entity.SysDictItem;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
 
 /**
  * @author xucaiqin
@@ -10,4 +14,7 @@ import org.apache.ibatis.annotations.Mapper;
  */
 @Mapper
 public interface SysDictItemMapper extends BaseMapper<SysDictItem> {
+    DictCache queryOne(@Param("dictType") String dictType, @Param("value") String value);
+
+    List<DictCache> queryList(@Param("dictType") String dictType);
 }

+ 9 - 0
iot-module/iot-module-system/iot-module-system-biz/src/main/java/com/middle/platform/system/biz/mapper/SysUserMapper.java

@@ -1,6 +1,7 @@
 package com.middle.platform.system.biz.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.middle.platform.system.api.pojo.UserCache;
 import com.middle.platform.system.api.pojo.UserDto;
 import com.middle.platform.system.biz.entity.SysUser;
 import com.middle.platform.system.biz.pojo.req.SysUserPagePara;
@@ -25,4 +26,12 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
     List<SysUserVo> pageList(SysUserPagePara basePara);
 
     UserDto queryOne(@Param("username") String username);
+
+    /**
+     * 通过id查询用户
+     *
+     * @param id
+     * @return
+     */
+    UserCache queryId(@Param("id") Long id);
 }

+ 26 - 1
iot-module/iot-module-system/iot-module-system-biz/src/main/java/com/middle/platform/system/biz/service/SysDictItemService.java

@@ -3,8 +3,10 @@ package com.middle.platform.system.biz.service;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
+import com.middle.platform.common.constant.Global;
 import com.middle.platform.common.modle.BasePara;
 import com.middle.platform.common.utils.PageRes;
+import com.middle.platform.system.api.pojo.DictCache;
 import com.middle.platform.system.api.pojo.DictDto;
 import com.middle.platform.system.biz.entity.SysDictItem;
 import com.middle.platform.system.biz.mapper.SysDictItemMapper;
@@ -51,7 +53,9 @@ public class SysDictItemService {
 
     public DictDto queryBy(String dictType, String value) {
         SysDictItem sysDictItem = sysDictItemMapper.selectOne(new LambdaQueryWrapper<SysDictItem>()
-                .eq(SysDictItem::getType, dictType).eq(SysDictItem::getValue, value).last("limit 1"));
+                .eq(SysDictItem::getType, dictType).eq(SysDictItem::getValue, value)
+                .eq(SysDictItem::getDelFlag, Global.UN_DEL)
+                .last("limit 1"));
         if (Objects.nonNull(sysDictItem)) {
             DictDto dictDto = new DictDto();
             BeanUtils.copyProperties(sysDictItem, dictDto);
@@ -59,4 +63,25 @@ public class SysDictItemService {
         }
         return null;
     }
+
+    /**
+     * 通过字典类型查询
+     *
+     * @param dictType 字典类型
+     * @return
+     */
+    public List<DictCache> query(String dictType) {
+        return sysDictItemMapper.queryList(dictType);
+    }
+
+    /**
+     * 通过类型和值查询字典
+     *
+     * @param dictType 字典类型
+     * @param value    值
+     * @return
+     */
+    public DictCache query(String dictType, String value) {
+        return sysDictItemMapper.queryOne(dictType, value);
+    }
 }

+ 11 - 0
iot-module/iot-module-system/iot-module-system-biz/src/main/java/com/middle/platform/system/biz/service/SysUserService.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.github.pagehelper.PageHelper;
 import com.middle.platform.common.exception.BusinessException;
 import com.middle.platform.common.utils.HashUtil;
+import com.middle.platform.system.api.pojo.UserCache;
 import com.middle.platform.system.api.pojo.UserDto;
 import com.middle.platform.system.biz.entity.SysUser;
 import com.middle.platform.system.biz.mapper.SysUserMapper;
@@ -84,6 +85,16 @@ public class SysUserService {
         return sysUserMapper.queryOne(username);
     }
 
+    /**
+     * 通过id查询用户
+     *
+     * @param id
+     * @return
+     */
+    public UserCache query(Long id) {
+        return sysUserMapper.queryId(id);
+    }
+
     /**
      * 重置密码
      *

+ 1 - 1
iot-module/iot-module-system/iot-module-system-biz/src/main/resources/logback-spring.xml

@@ -7,7 +7,7 @@
     <!--关闭logback自身的debug日志打印-->
     <statusListener class="ch.qos.logback.core.status.NopStatusListener"/>
     <contextName>logback</contextName>
-
+    <include resource="org/springframework/boot/logging/logback/defaults.xml"/>
     <!-- name的值是变量的名称,value的值时变量定义的值。通过定义的值会被插入到logger上下文中。定义后,可以使“${}”来使用变量。 -->
     <property name="log.path" value="logs"/>
     <springProperty scope="context" name="LOG_HOME" source="spring.application.name"/>

+ 58 - 22
iot-module/iot-module-system/iot-module-system-biz/src/main/resources/mapper/SysDictItemMapper.xml

@@ -1,26 +1,62 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.middle.platform.system.biz.mapper.SysDictItemMapper">
-  <resultMap id="BaseResultMap" type="com.middle.platform.system.biz.entity.SysDictItem">
-    <!--@mbg.generated-->
-    <!--@Table sys_dict_item-->
-    <id column="id" jdbcType="BIGINT" property="id" />
-    <result column="dict_id" jdbcType="BIGINT" property="dictId" />
-    <result column="value" jdbcType="VARCHAR" property="value" />
-    <result column="label" jdbcType="VARCHAR" property="label" />
-    <result column="type" jdbcType="VARCHAR" property="type" />
-    <result column="desc" jdbcType="VARCHAR" property="desc" />
-    <result column="sort" jdbcType="INTEGER" property="sort" />
-    <result column="create_by" jdbcType="BIGINT" property="createBy" />
-    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
-    <result column="update_by" jdbcType="BIGINT" property="updateBy" />
-    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
-    <result column="delete_time" jdbcType="TIMESTAMP" property="deleteTime" />
-    <result column="del_flag" jdbcType="BOOLEAN" property="delFlag" />
-  </resultMap>
-  <sql id="Base_Column_List">
-    <!--@mbg.generated-->
-    id, dict_id, `value`, `label`, `type`, `desc`, sort, create_by, create_time, update_by,
-    update_time, delete_time, del_flag
-  </sql>
+    <resultMap id="BaseResultMap" type="com.middle.platform.system.biz.entity.SysDictItem">
+        <!--@mbg.generated-->
+        <!--@Table sys_dict_item-->
+        <id column="id" jdbcType="BIGINT" property="id"/>
+        <result column="dict_id" jdbcType="BIGINT" property="dictId"/>
+        <result column="value" jdbcType="VARCHAR" property="value"/>
+        <result column="label" jdbcType="VARCHAR" property="label"/>
+        <result column="type" jdbcType="VARCHAR" property="type"/>
+        <result column="desc" jdbcType="VARCHAR" property="desc"/>
+        <result column="sort" jdbcType="INTEGER" property="sort"/>
+        <result column="create_by" jdbcType="BIGINT" property="createBy"/>
+        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
+        <result column="update_by" jdbcType="BIGINT" property="updateBy"/>
+        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
+        <result column="delete_time" jdbcType="TIMESTAMP" property="deleteTime"/>
+        <result column="del_flag" jdbcType="BOOLEAN" property="delFlag"/>
+    </resultMap>
+    <sql id="Base_Column_List">
+        <!--@mbg.generated-->
+        id,
+        dict_id,
+        `value`,
+        `label`,
+        `type`,
+        `desc`,
+        sort,
+        create_by,
+        create_time,
+        update_by,
+        update_time,
+        delete_time,
+        del_flag
+    </sql>
+
+    <select id="queryOne" resultType="com.middle.platform.system.api.pojo.DictCache">
+        select *
+        from sys_dict_item sdi
+        <where>
+            <if test="dictType != null and dictType != ''">
+                and sdi.type = #{dictType,jdbcType=VARCHAR}
+            </if>
+            <if test="value != null and value != ''">
+                and sdi.value = #{value,jdbcType=VARCHAR}
+            </if>
+            and sdi.del_flag = 0
+            limit 1
+        </where>
+    </select>
+    <select id="queryList" resultType="com.middle.platform.system.api.pojo.DictCache">
+        select *
+        from sys_dict_item sdi
+        <where>
+            <if test="dictType != null and dictType != ''">
+                and sdi.type = #{dictType,jdbcType=VARCHAR}
+            </if>
+            and sdi.del_flag = 0
+        </where>
+    </select>
 </mapper>

+ 7 - 0
iot-module/iot-module-system/iot-module-system-biz/src/main/resources/mapper/SysUserMapper.xml

@@ -46,4 +46,11 @@
           limit 1
       </where>
   </select>
+
+  <select id="queryId" resultType="com.middle.platform.system.api.pojo.UserCache">
+      select su.id, su.name
+      from sys_user su
+      where su.id = #{id,jdbcType=BIGINT}
+        and su.del_flag = 0
+  </select>
 </mapper>