Răsfoiți Sursa

feat:增加内置oss

xiwa 1 an în urmă
părinte
comite
e818736dad

+ 2 - 1
.gitignore

@@ -32,4 +32,5 @@ data/elasticsearch
 .DS_Store
 dependency-reduced-pom.xml
 /data/plugins
-/data/dist
+/data/dist
+/data/iot-oss

+ 10 - 27
data/init/sys_oss_config.json

@@ -6,15 +6,16 @@
   "updateTime" : 1708254322687,
   "tenantId" : "000000",
   "id" : 1,
-  "configKey" : "minio",
+  "configKey" : "oss-embed",
   "accessKey" : "admin",
-  "secretKey" : "iita@123",
-  "bucketName" : "iotkit",
+  "secretKey" : "123",
+  "bucketName" : "iot",
   "prefix" : "",
-  "endpoint" : "159.75.222.119:9000",
+  "endpoint" : "localhost:8086/iot-oss",
+  "outside": "localhost:8086/iot-oss",
   "domain" : "",
   "isHttps" : null,
-  "region" : "",
+  "region" : "local",
   "status" : "0",
   "ext1" : "",
   "remark" : null,
@@ -33,6 +34,7 @@
   "bucketName" : "ruoyi",
   "prefix" : "",
   "endpoint" : "s3-cn-north-1.qiniucs.com",
+  "outside": "s3-cn-north-1.qiniucs.com",
   "domain" : "",
   "isHttps" : null,
   "region" : "",
@@ -54,6 +56,7 @@
   "bucketName" : "ruoyi",
   "prefix" : "",
   "endpoint" : "oss-cn-beijing.aliyuncs.com",
+  "outside": "oss-cn-beijing.aliyuncs.com",
   "domain" : "",
   "isHttps" : null,
   "region" : "",
@@ -75,6 +78,7 @@
   "bucketName" : "ruoyi-1250000000",
   "prefix" : "",
   "endpoint" : "cos.ap-beijing.myqcloud.com",
+  "outside": "cos.ap-beijing.myqcloud.com",
   "domain" : "",
   "isHttps" : null,
   "region" : "ap-beijing",
@@ -82,25 +86,4 @@
   "ext1" : "",
   "remark" : null,
   "accessPolicy" : "1"
-}, {
-  "createDept" : 103,
-  "createBy" : 1,
-  "createTime" : 1708254322708,
-  "updateBy" : 1,
-  "updateTime" : 1708254322708,
-  "tenantId" : "000000",
-  "id" : 5,
-  "configKey" : "image",
-  "accessKey" : "ruoyi",
-  "secretKey" : "ruoyi123",
-  "bucketName" : "ruoyi",
-  "prefix" : "image",
-  "endpoint" : "127.0.0.1:9000",
-  "domain" : "",
-  "isHttps" : null,
-  "region" : "",
-  "status" : "1",
-  "ext1" : "",
-  "remark" : null,
-  "accessPolicy" : "1"
-} ]
+}]

+ 2 - 2
iot-dao/iot-data-model/pom.xml

@@ -5,9 +5,9 @@
     <parent>
         <artifactId>iot-dao</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.5.2-SNAPSHOT</version>
+        <version>0.5.3</version>
     </parent>
-    <version>0.5.2-SNAPSHOT</version>
+    <version>0.5.3</version>
     <modelVersion>4.0.0</modelVersion>
 
     <artifactId>iot-data-model</artifactId>

+ 2 - 2
iot-dao/iot-data-service/pom.xml

@@ -5,10 +5,10 @@
     <parent>
         <artifactId>iot-dao</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.5.2-SNAPSHOT</version>
+        <version>0.5.3</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
-    <version>0.5.2-SNAPSHOT</version>
+    <version>0.5.3</version>
     <artifactId>iot-data-service</artifactId>
 
     <dependencies>

+ 2 - 2
iot-dao/iot-data-serviceImpl-cache/pom.xml

@@ -5,10 +5,10 @@
     <parent>
         <artifactId>iot-dao</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.5.2-SNAPSHOT</version>
+        <version>0.5.3</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
-    <version>0.5.2-SNAPSHOT</version>
+    <version>0.5.3</version>
     <artifactId>iot-data-serviceImpl-cache</artifactId>
 
     <dependencies>

+ 2 - 2
iot-dao/iot-data-serviceImpl-rdb/pom.xml

@@ -5,9 +5,9 @@
     <parent>
         <artifactId>iot-dao</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.5.2-SNAPSHOT</version>
+        <version>0.5.3</version>
     </parent>
-    <version>0.5.2-SNAPSHOT</version>
+    <version>0.5.3</version>
     <modelVersion>4.0.0</modelVersion>
     <artifactId>iot-data-serviceImpl-rdb</artifactId>
     <description>

+ 2 - 2
iot-dao/iot-temporal-service/pom.xml

@@ -5,10 +5,10 @@
     <parent>
         <artifactId>iot-dao</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.5.2-SNAPSHOT</version>
+        <version>0.5.3</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
-    <version>0.5.2-SNAPSHOT</version>
+    <version>0.5.3</version>
     <artifactId>iot-temporal-service</artifactId>
 
     <dependencies>

+ 1 - 1
iot-dao/iot-temporal-serviceImpl-es/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iot-dao</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.5.2-SNAPSHOT</version>
+        <version>0.5.3</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 1 - 1
iot-dao/iot-temporal-serviceImpl-iotdb/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iot-dao</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.5.2-SNAPSHOT</version>
+        <version>0.5.3</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 2 - 2
iot-dao/iot-temporal-serviceImpl-td/pom.xml

@@ -5,10 +5,10 @@
     <parent>
         <artifactId>iot-dao</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.5.2-SNAPSHOT</version>
+        <version>0.5.3</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
-    <version>0.5.2-SNAPSHOT</version>
+    <version>0.5.3</version>
     <artifactId>iot-temporal-serviceImpl-td</artifactId>
 
     <description>

+ 2 - 2
iot-dao/iot-temporal-serviceImpl-ts/pom.xml

@@ -6,9 +6,9 @@
     <parent>
         <artifactId>iot-dao</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.5.2-SNAPSHOT</version>
+        <version>0.5.3</version>
     </parent>
-    <version>0.5.2-SNAPSHOT</version>
+    <version>0.5.3</version>
     <artifactId>iot-temporal-serviceImpl-ts</artifactId>
 
     <description>

+ 1 - 1
iot-dao/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iotkit-parent</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.5.2-SNAPSHOT</version>
+        <version>0.5.3</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <packaging>pom</packaging>

+ 1 - 1
iot-module/iot-manager/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iot-module</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.5.2-SNAPSHOT</version>
+        <version>0.5.3</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 1 - 1
iot-module/iot-message-notify/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iot-module</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.5.2-SNAPSHOT</version>
+        <version>0.5.3</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 1 - 1
iot-module/iot-openapi/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iot-module</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.5.2-SNAPSHOT</version>
+        <version>0.5.3</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 1 - 1
iot-module/iot-plugin/iot-plugin-main/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iot-plugin</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.5.2-SNAPSHOT</version>
+        <version>0.5.3</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 1 - 1
iot-module/iot-plugin/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iot-module</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.5.2-SNAPSHOT</version>
+        <version>0.5.3</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 1 - 1
iot-module/iot-rule-engine/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iot-module</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.5.2-SNAPSHOT</version>
+        <version>0.5.3</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 1 - 1
iot-module/iot-screen/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iot-module</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.5.2-SNAPSHOT</version>
+        <version>0.5.3</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 1 - 1
iot-module/iot-system/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iot-module</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.5.2-SNAPSHOT</version>
+        <version>0.5.3</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 22 - 7
iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysOssController.java

@@ -6,6 +6,8 @@ import cc.iotkit.common.api.Paging;
 import cc.iotkit.common.api.Request;
 import cc.iotkit.common.log.annotation.Log;
 import cc.iotkit.common.log.enums.BusinessType;
+import cc.iotkit.common.oss.core.OssClient;
+import cc.iotkit.common.oss.factory.OssFactory;
 import cc.iotkit.common.validate.QueryGroup;
 import cc.iotkit.common.web.core.BaseController;
 import cc.iotkit.system.dto.bo.SysOssBo;
@@ -13,16 +15,23 @@ import cc.iotkit.system.dto.vo.SysOssUploadVo;
 import cc.iotkit.system.dto.vo.SysOssVo;
 import cc.iotkit.system.service.ISysOssService;
 import cn.dev33.satoken.annotation.SaCheckPermission;
+import cn.hutool.core.io.IoUtil;
 import cn.hutool.core.util.ObjectUtil;
+import com.amazonaws.services.s3.model.ObjectMetadata;
 import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
+import org.springframework.http.HttpHeaders;
 import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;
 
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
 import java.util.List;
 
 /**
@@ -50,7 +59,6 @@ public class SysOssController extends BaseController {
 
     /**
      * 查询OSS对象基于id串
-     *
      */
     @ApiOperation(value = "查询OSS对象基于id串", notes = "查询OSS对象基于id串")
     @SaCheckPermission("system:oss:list")
@@ -68,7 +76,7 @@ public class SysOssController extends BaseController {
     @SaCheckPermission("system:oss:upload")
     @Log(title = "OSS对象存储", businessType = BusinessType.INSERT)
     @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
-    public SysOssUploadVo upload(@RequestPart("file") MultipartFile file,@RequestParam("requestId") String requestId) {
+    public SysOssUploadVo upload(@RequestPart("file") MultipartFile file, @RequestParam("requestId") String requestId) {
         if (ObjectUtil.isNull(file)) {
             fail("上传文件不能为空");
         }
@@ -82,19 +90,26 @@ public class SysOssController extends BaseController {
 
     /**
      * 下载OSS对象
-     *
      */
     @SaCheckPermission("system:oss:download")
     @PostMapping("/downloadById")
     @ApiOperation(value = "下载OSS对象", notes = "下载OSS对象")
-    public void download(@RequestBody @Validated Request<Long> bo, HttpServletResponse response) throws IOException {
-        ossService.download(bo.getData());
+    public ResponseEntity<StreamingResponseBody> download(@RequestBody @Validated Request<Long> bo) throws IOException {
+        SysOssVo ossVo = ossService.getById(bo.getData());
+        OssClient storage = OssFactory.instance();
+        ObjectMetadata objectMetadata = storage.getObjectMetadata(ossVo.getUrl());
+        InputStream objectContent = storage.getObjectContent(ossVo.getUrl());
+        return ResponseEntity
+                .ok()
+                .header(HttpHeaders.ACCEPT_RANGES, "bytes")
+                .header("download-filename", ossVo.getFileName())
+                .contentLength(objectMetadata.getContentLength())
+                .contentType(MediaType.APPLICATION_OCTET_STREAM)
+                .body(out -> IoUtil.copy(objectContent, out));
     }
 
     /**
      * 删除OSS对象存储
-     *
-
      */
     @ApiOperation(value = "删除OSS对象存储", notes = "删除OSS对象存储")
     @SaCheckPermission("system:oss:remove")

+ 0 - 28
iot-module/iot-system/src/main/java/cc/iotkit/system/runner/SystemApplicationRunner.java

@@ -1,28 +0,0 @@
-package cc.iotkit.system.runner;
-
-import cc.iotkit.system.service.ISysOssConfigService;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.boot.ApplicationArguments;
-import org.springframework.boot.ApplicationRunner;
-import org.springframework.stereotype.Component;
-
-/**
- * 初始化 system 模块对应业务数据
- *
- * @author Lion Li
- */
-@Slf4j
-@RequiredArgsConstructor
-@Component
-public class SystemApplicationRunner implements ApplicationRunner {
-
-    private final ISysOssConfigService ossConfigService;
-
-    @Override
-    public void run(ApplicationArguments args) {
-        ossConfigService.init();
-        log.info("初始化OSS配置成功");
-    }
-
-}

+ 14 - 12
iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysOssConfigServiceImpl.java

@@ -21,13 +21,14 @@ import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.ObjectUtil;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
 
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
+import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
 /**
@@ -44,17 +45,23 @@ public class SysOssConfigServiceImpl implements ISysOssConfigService {
 
     private final ISysOssConfigData baseData;
 
+    @Scheduled(fixedRate = 10, timeUnit = TimeUnit.SECONDS)
+    private void keepAlive() {
+        String configKey = RedisUtils.getCacheObject(OssConstant.DEFAULT_CONFIG_KEY);
+        if(configKey==null){
+            init();
+        }
+    }
+
     /**
      * 项目启动时,初始化参数到缓存,加载配置类
      */
     @Override
     public void init() {
         List<SysOssConfig> list = baseData.findAll();
-
         List<SysOssConfig> notEmptyTenantIdList = list.stream().filter(item -> StringUtils.isNotBlank(item.getTenantId())).collect(Collectors.toList());
         Map<String, List<SysOssConfig>> map = StreamUtils.groupByKey(notEmptyTenantIdList, SysOssConfig::getTenantId);
         try {
-
             for (Map.Entry<String, List<SysOssConfig>> stringListEntry : map.entrySet()) {
                 TenantHelper.setDynamic(stringListEntry.getKey());
                 for (SysOssConfig config : stringListEntry.getValue()) {
@@ -142,16 +149,11 @@ public class SysOssConfigServiceImpl implements ISysOssConfigService {
      * 启用禁用状态
      */
     @Override
-    @Transactional(rollbackFor = Exception.class)
     public int updateOssConfigStatus(SysOssConfigBo bo) {
-//        SysOssConfig sysOssConfig = MapstructUtils.convert(bo, SysOssConfig.class);
-//        int row = baseData.save(null, new LambdaUpdateWrapper<SysOssConfig>()
-//            .set(SysOssConfig::getStatus, "1"));
-//        row += baseMapper.updateById(sysOssConfig);
-//        if (row > 0) {
-//            RedisUtils.setCacheObject(OssConstant.DEFAULT_CONFIG_KEY, sysOssConfig.getConfigKey());
-//        }
-//        return row;
+        SysOssConfig old = baseData.findById(bo.getId());
+        old.setStatus(bo.getStatus());
+        baseData.save(old);
+        RedisUtils.deleteObject(OssConstant.DEFAULT_CONFIG_KEY);
         return 0;
     }
 

+ 1 - 1
iot-module/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iotkit-parent</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.5.2-SNAPSHOT</version>
+        <version>0.5.3</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 21 - 9
iot-starter/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iotkit-parent</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.5.2-SNAPSHOT</version>
+        <version>0.5.3</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 
@@ -23,6 +23,12 @@
             <artifactId>vertx-web-client</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>jakarta.xml.bind</groupId>
+            <artifactId>jakarta.xml.bind-api</artifactId>
+            <version>4.0.1</version>
+        </dependency>
+
         <dependency>
             <groupId>cc.iotkit</groupId>
             <artifactId>iot-common-tenant</artifactId>
@@ -40,10 +46,10 @@
         </dependency>
 
         <!--打开注释使用rocketmq消息总线-->
-<!--        <dependency>-->
-<!--            <groupId>cc.iotkit</groupId>-->
-<!--            <artifactId>iot-message-rocketmq</artifactId>-->
-<!--        </dependency>-->
+        <!--        <dependency>-->
+        <!--            <groupId>cc.iotkit</groupId>-->
+        <!--            <artifactId>iot-message-rocketmq</artifactId>-->
+        <!--        </dependency>-->
 
         <dependency>
             <groupId>cc.iotkit</groupId>
@@ -83,10 +89,16 @@
         <!--        </dependency>-->
 
         <!--打开注释 启用tdengine数据库-->
-<!--        <dependency>-->
-<!--            <groupId>cc.iotkit</groupId>-->
-<!--            <artifactId>iot-temporal-serviceImpl-td</artifactId>-->
-<!--        </dependency>-->
+        <!--        <dependency>-->
+        <!--            <groupId>cc.iotkit</groupId>-->
+        <!--            <artifactId>iot-temporal-serviceImpl-td</artifactId>-->
+        <!--        </dependency>-->
+
+        <!--内置oss-->
+        <dependency>
+            <groupId>cc.iotkit</groupId>
+            <artifactId>iot-oss-embed</artifactId>
+        </dependency>
 
         <!--====================第三方库===================-->
 

+ 5 - 0
iot-starter/src/main/java/cc/iotkit/Application.java

@@ -15,6 +15,8 @@ import com.gitee.starblues.loader.launcher.SpringMainBootstrap;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.FilterType;
 import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
 import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.transaction.annotation.EnableTransactionManagement;
@@ -22,6 +24,9 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc;
 
 @Slf4j
 @SpringBootApplication
+@ComponentScan(excludeFilters = {
+        @ComponentScan.Filter(type = FilterType.REGEX, pattern = ".*s3mock.*Controller")
+})
 @EnableTransactionManagement
 @EnableWebMvc
 @EnableJpaAuditing

+ 1 - 2
iot-starter/src/main/resources/application.yml

@@ -128,7 +128,7 @@ spring:
 
   mvc:
     pathmatch:
-      matching-strategy: ant_path_matcher
+      matching-strategy: path_pattern_parser
 #  profiles:
 #    active: mysql
 
@@ -210,4 +210,3 @@ plugin:
   mainPackage: cc.iotkit
   pluginPath:
     - ./data/plugins
-

+ 1 - 1
iot-test-tool/iot-virtual-device/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iot-test-tool</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.5.2-SNAPSHOT</version>
+        <version>0.5.3</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 1 - 1
iot-test-tool/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iotkit-parent</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.5.2-SNAPSHOT</version>
+        <version>0.5.3</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <packaging>pom</packaging>

+ 8 - 2
pom.xml

@@ -12,7 +12,7 @@
 
     <groupId>cc.iotkit</groupId>
     <artifactId>iotkit-parent</artifactId>
-    <version>0.5.2-SNAPSHOT</version>
+    <version>0.5.3</version>
     <name>${project.artifactId}</name>
     <description>奇特物联是一个开源的物联网基础开发平台,提供了物联网及相关业务开发的常见基础功能,
         能帮助你快速搭建自己的物联网相关业务平台。
@@ -29,7 +29,7 @@
 
     <properties>
         <java.version>11</java.version>
-        <iot-iita-core.version>1.0.4</iot-iita-core.version>
+        <iot-iita-core.version>1.0.5</iot-iita-core.version>
         <spring-boot.version>2.7.11</spring-boot.version>
         <vertx.version>4.2.2</vertx.version>
         <satoken.version>1.34.0</satoken.version>
@@ -406,6 +406,12 @@
                 <version>${project.version}</version>
             </dependency>
 
+            <dependency>
+                <groupId>cc.iotkit</groupId>
+                <artifactId>iot-oss-embed</artifactId>
+                <version>${iot-iita-core.version}</version>
+            </dependency>
+
         </dependencies>
     </dependencyManagement>
     <build>