浏览代码

fix: oss 配置调试

regan 2 年之前
父节点
当前提交
fe810c5d8f
共有 18 个文件被更改,包括 159 次插入484 次删除
  1. 0 62
      iot-components/iot-component-oss/pom.xml
  2. 0 56
      iot-components/iot-component-oss/src/main/java/cc/iotkit/oss/config/OssAutoConfiguration.java
  3. 0 45
      iot-components/iot-component-oss/src/main/java/cc/iotkit/oss/properties/OssProperties.java
  4. 0 87
      iot-components/iot-component-oss/src/main/java/cc/iotkit/oss/service/OssTemplate.java
  5. 0 172
      iot-components/iot-component-oss/src/main/java/cc/iotkit/oss/service/impl/OssTemplateImpl.java
  6. 0 2
      iot-components/iot-component-oss/src/main/resources/META-INF/spring.factories
  7. 93 0
      iot-components/iot-component-tcp/dependency-reduced-pom.xml
  8. 0 1
      iot-components/pom.xml
  9. 0 6
      iot-module/iot-contribution/pom.xml
  10. 5 6
      iot-module/iot-manager/pom.xml
  11. 10 13
      iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/OtaController.java
  12. 35 21
      iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/OtaService.java
  13. 6 4
      iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysOssController.java
  14. 1 1
      iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysProfileController.java
  15. 1 1
      iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysOssBo.java
  16. 1 1
      iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysOssVo.java
  17. 1 1
      iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysOssService.java
  18. 6 5
      iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysOssServiceImpl.java

+ 0 - 62
iot-components/iot-component-oss/pom.xml

@@ -1,62 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0"
-         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-    <parent>
-        <artifactId>iot-components</artifactId>
-        <groupId>cc.iotkit</groupId>
-        <version>${revision}</version>
-    </parent>
-    <modelVersion>4.0.0</modelVersion>
-
-    <properties>
-        <hutool.version>5.8.18</hutool.version>
-    </properties>
-
-    <artifactId>iot-component-oss</artifactId>
-
-    <dependencies>
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>com.amazonaws</groupId>
-            <artifactId>aws-java-sdk-s3</artifactId>
-            <version>1.12.470</version>
-        </dependency>
-        <dependency>
-            <groupId>cn.hutool</groupId>
-            <artifactId>hutool-core</artifactId>
-            <version>${hutool.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.projectlombok</groupId>
-            <artifactId>lombok</artifactId>
-        </dependency>
-    </dependencies>
-
-    <build>
-        <plugins>
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-compiler-plugin</artifactId>
-                <configuration>
-                    <source>${java.version}</source>
-                    <target>${java.version}</target>
-                    <encoding>utf8</encoding>
-                </configuration>
-            </plugin>
-        </plugins>
-        <resources>
-            <resource>
-                <directory>src/main/java</directory>
-                <includes>
-                    <include>**/*.xml</include>
-                </includes>
-                <filtering>false</filtering>
-            </resource>
-        </resources>
-    </build>
-
-</project>

+ 0 - 56
iot-components/iot-component-oss/src/main/java/cc/iotkit/oss/config/OssAutoConfiguration.java

@@ -1,56 +0,0 @@
-package cc.iotkit.oss.config;
-
-import cc.iotkit.oss.properties.OssProperties;
-import cc.iotkit.oss.service.OssTemplate;
-import cc.iotkit.oss.service.impl.OssTemplateImpl;
-import com.amazonaws.ClientConfiguration;
-import com.amazonaws.auth.AWSCredentials;
-import com.amazonaws.auth.AWSCredentialsProvider;
-import com.amazonaws.auth.AWSStaticCredentialsProvider;
-import com.amazonaws.auth.BasicAWSCredentials;
-import com.amazonaws.client.builder.AwsClientBuilder;
-import com.amazonaws.services.s3.AmazonS3;
-import com.amazonaws.services.s3.AmazonS3Client;
-import lombok.RequiredArgsConstructor;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
-import org.springframework.boot.context.properties.EnableConfigurationProperties;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-/**
- * @Author: 石恒
- * @Date: 2023/5/22 21:15
- * @Description:
- */
-
-@Configuration
-@RequiredArgsConstructor
-@EnableConfigurationProperties(OssProperties.class)
-public class OssAutoConfiguration {
-
-    @Bean
-    @ConditionalOnMissingBean
-    public AmazonS3 ossClient(OssProperties ossProperties) {
-        // 客户端配置,主要是全局的配置信息
-        ClientConfiguration clientConfiguration = new ClientConfiguration();
-        clientConfiguration.setMaxConnections(ossProperties.getMaxConnections());
-        // url以及region配置
-        AwsClientBuilder.EndpointConfiguration endpointConfiguration = new AwsClientBuilder.EndpointConfiguration(
-                ossProperties.getEndpoint(), ossProperties.getRegion());
-        // 凭证配置
-        AWSCredentials awsCredentials = new BasicAWSCredentials(ossProperties.getAccessKey(),
-                ossProperties.getSecretKey());
-        AWSCredentialsProvider awsCredentialsProvider = new AWSStaticCredentialsProvider(awsCredentials);
-        // build amazonS3Client客户端
-        return AmazonS3Client.builder().withEndpointConfiguration(endpointConfiguration)
-                .withClientConfiguration(clientConfiguration).withCredentials(awsCredentialsProvider)
-                .disableChunkedEncoding().withPathStyleAccessEnabled(ossProperties.getPathStyleAccess()).build();
-    }
-
-    @Bean
-    @ConditionalOnBean(AmazonS3.class)
-    public OssTemplate ossTemplate(AmazonS3 amazonS3){
-        return new OssTemplateImpl(amazonS3);
-    }
-}

+ 0 - 45
iot-components/iot-component-oss/src/main/java/cc/iotkit/oss/properties/OssProperties.java

@@ -1,45 +0,0 @@
-package cc.iotkit.oss.properties;
-
-import lombok.Data;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-
-/**
- * @Author: 石恒
- * @Date: 2023/5/22 21:10
- * @Description:
- */
-@Data
-@ConfigurationProperties(prefix = "oss")
-public class OssProperties {
-    /**
-     * 对象存储服务的URL
-     */
-    private String endpoint;
-
-    /**
-     * 区域
-     */
-    private String region;
-
-    /**
-     * true path-style nginx 反向代理和S3默认支持 pathStyle模式 {http://endpoint/bucketname}
-     * false supports virtual-hosted-style 阿里云等需要配置为 virtual-hosted-style 模式{http://bucketname.endpoint}
-     * 只是url的显示不一样
-     */
-    private Boolean pathStyleAccess = true;
-
-    /**
-     * Access key
-     */
-    private String accessKey;
-
-    /**
-     * Secret key
-     */
-    private String secretKey;
-
-    /**
-     * 最大线程数,默认:100
-     */
-    private Integer maxConnections = 100;
-}

+ 0 - 87
iot-components/iot-component-oss/src/main/java/cc/iotkit/oss/service/OssTemplate.java

@@ -1,87 +0,0 @@
-package cc.iotkit.oss.service;
-
-import com.amazonaws.services.s3.model.Bucket;
-import com.amazonaws.services.s3.model.S3Object;
-import com.amazonaws.services.s3.model.S3ObjectSummary;
-
-import java.io.InputStream;
-import java.util.List;
-
-/**
- * @Author: 石恒
- * @Date: 2023/5/22 21:13
- * @Description:
- */
-public interface OssTemplate {
-
-    /**
-     * 创建bucket
-     * @param bucketName bucket名称
-     */
-    void createBucket(String bucketName);
-
-    /**
-     * 获取所有的bucket
-     * @return
-     */
-    List<Bucket> getAllBuckets();
-
-    /**
-     * 通过bucket名称删除bucket
-     * @param bucketName
-     */
-    void removeBucket(String bucketName);
-
-    /**
-     * 上传文件
-     * @param bucketName bucket名称
-     * @param objectName 文件名称
-     * @param stream 文件流
-     * @param contextType 文件类型
-     * @throws Exception
-     */
-    void putObject(String bucketName, String objectName, InputStream stream, String contextType) throws Exception;
-
-    /**
-     * 上传文件
-     * @param bucketName bucket名称
-     * @param objectName 文件名称
-     * @param stream 文件流
-     * @throws Exception
-     */
-    void putObject(String bucketName, String objectName, InputStream stream) throws Exception;
-
-    /**
-     * 获取文件
-     * @param bucketName bucket名称
-     * @param objectName 文件名称
-     * @return S3Object
-     */
-    S3Object getObject(String bucketName, String objectName);
-
-    /**
-     * 获取对象的url
-     * @param bucketName
-     * @param objectName
-     * @param expires
-     * @return
-     */
-    String getObjectURL(String bucketName, String objectName, Integer expires);
-
-    /**
-     * 通过bucketName和objectName删除对象
-     * @param bucketName
-     * @param objectName
-     * @throws Exception
-     */
-    void removeObject(String bucketName, String objectName) throws Exception;
-
-    /**
-     * 根据文件前置查询文件
-     * @param bucketName bucket名称
-     * @param prefix 前缀
-     * @param recursive 是否递归查询
-     * @return S3ObjectSummary 列表
-     */
-    List<S3ObjectSummary> getAllObjectsByPrefix(String bucketName, String prefix, boolean recursive);
-}

+ 0 - 172
iot-components/iot-component-oss/src/main/java/cc/iotkit/oss/service/impl/OssTemplateImpl.java

@@ -1,172 +0,0 @@
-package cc.iotkit.oss.service.impl;
-
-import cc.iotkit.oss.service.OssTemplate;
-import com.amazonaws.services.s3.AmazonS3;
-import com.amazonaws.services.s3.model.*;
-import com.amazonaws.util.IOUtils;
-import lombok.RequiredArgsConstructor;
-import lombok.SneakyThrows;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.List;
-
-/**
- * @Author: 石恒
- * @Date: 2023/5/22 21:14
- * @Description:
- */
-
-@RequiredArgsConstructor
-public class OssTemplateImpl implements OssTemplate {
-
-    private final AmazonS3 amazonS3;
-
-    /**
-     * 创建Bucket
-     * AmazonS3:https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateBucket.html
-     * @param bucketName bucket名称
-     */
-    @Override
-    @SneakyThrows
-    public void createBucket(String bucketName) {
-        if ( !amazonS3.doesBucketExistV2(bucketName) ) {
-            amazonS3.createBucket((bucketName));
-        }
-    }
-
-    /**
-     * 获取所有的buckets
-     * AmazonS3:https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListBuckets.html
-     * @return
-     */
-    @Override
-    @SneakyThrows
-    public List<Bucket> getAllBuckets() {
-        return amazonS3.listBuckets();
-    }
-
-    /**
-     * 通过Bucket名称删除Bucket
-     * AmazonS3:https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteBucket.html
-     * @param bucketName
-     */
-    @Override
-    @SneakyThrows
-    public void removeBucket(String bucketName) {
-        amazonS3.deleteBucket(bucketName);
-    }
-
-    /**
-     * 上传对象
-     * @param bucketName bucket名称
-     * @param objectName 文件名称
-     * @param stream 文件流
-     * @param contextType 文件类型
-     * AmazonS3:https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObject.html
-     */
-    @Override
-    @SneakyThrows
-    public void putObject(String bucketName, String objectName, InputStream stream, String contextType) {
-        putObject(bucketName, objectName, stream, stream.available(), contextType);
-    }
-    /**
-     * 上传对象
-     * @param bucketName bucket名称
-     * @param objectName 文件名称
-     * @param stream 文件流
-     * AmazonS3:https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObject.html
-     */
-    @Override
-    @SneakyThrows
-    public void putObject(String bucketName, String objectName, InputStream stream) {
-        putObject(bucketName, objectName, stream, stream.available(), "application/octet-stream");
-    }
-
-    /**
-     * 通过bucketName和objectName获取对象
-     * @param bucketName bucket名称
-     * @param objectName 文件名称
-     * @return
-     * AmazonS3:https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObject.html
-     */
-    @Override
-    @SneakyThrows
-    public S3Object getObject(String bucketName, String objectName) {
-        return amazonS3.getObject(bucketName, objectName);
-    }
-
-    /**
-     * 获取对象的url
-     * @param bucketName
-     * @param objectName
-     * @param expires
-     * @return
-     * AmazonS3:https://docs.aws.amazon.com/AmazonS3/latest/API/API_GeneratePresignedUrl.html
-     */
-    @Override
-    @SneakyThrows
-    public String getObjectURL(String bucketName, String objectName, Integer expires) {
-        Date date = new Date();
-        Calendar calendar = new GregorianCalendar();
-        calendar.setTime(date);
-        calendar.add(Calendar.DAY_OF_MONTH, expires);
-        URL url = amazonS3.generatePresignedUrl(bucketName, objectName, calendar.getTime());
-        return url.toString();
-    }
-
-    /**
-     * 通过bucketName和objectName删除对象
-     * @param bucketName
-     * @param objectName
-     * AmazonS3:https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteObject.html
-     */
-    @Override
-    @SneakyThrows
-    public void removeObject(String bucketName, String objectName) {
-        amazonS3.deleteObject(bucketName, objectName);
-    }
-
-    /**
-     * 根据bucketName和prefix获取对象集合
-     * @param bucketName bucket名称
-     * @param prefix 前缀
-     * @param recursive 是否递归查询
-     * @return
-     * AmazonS3:https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjects.html
-     */
-    @Override
-    @SneakyThrows
-    public List<S3ObjectSummary> getAllObjectsByPrefix(String bucketName, String prefix, boolean recursive) {
-        ObjectListing objectListing = amazonS3.listObjects(bucketName, prefix);
-        return objectListing.getObjectSummaries();
-    }
-
-
-    /**
-     *
-     * @param bucketName
-     * @param objectName
-     * @param stream
-     * @param size
-     * @param contextType
-     * @return
-     */
-    @SneakyThrows
-    private PutObjectResult putObject(String bucketName, String objectName, InputStream stream, long size,
-                                      String contextType)  {
-
-        byte[] bytes = IOUtils.toByteArray(stream);
-        ObjectMetadata objectMetadata = new ObjectMetadata();
-        objectMetadata.setContentLength(size);
-        objectMetadata.setContentType(contextType);
-        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
-        // 上传
-        return amazonS3.putObject(bucketName, objectName, byteArrayInputStream, objectMetadata);
-
-    }
-}

+ 0 - 2
iot-components/iot-component-oss/src/main/resources/META-INF/spring.factories

@@ -1,2 +0,0 @@
-org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
-  cc.iotkit.oss.config.OssAutoConfiguration

+ 93 - 0
iot-components/iot-component-tcp/dependency-reduced-pom.xml

@@ -0,0 +1,93 @@
+<?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/maven-v4_0_0.xsd">
+  <parent>
+    <artifactId>iot-components</artifactId>
+    <groupId>cc.iotkit</groupId>
+    <version>${revision}</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>iot-component-tcp</artifactId>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-shade-plugin</artifactId>
+        <version>3.2.4</version>
+        <executions>
+          <execution>
+            <phase>package</phase>
+            <goals>
+              <goal>shade</goal>
+            </goals>
+          </execution>
+        </executions>
+        <configuration>
+          <artifactSet>
+            <includes>
+              <include>io.vertx:vertx-core</include>
+            </includes>
+          </artifactSet>
+        </configuration>
+      </plugin>
+      <plugin>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <configuration>
+          <source>${java.version}</source>
+          <target>${java.version}</target>
+          <forceJavacCompilerUse>true</forceJavacCompilerUse>
+          <useIncrementalCompilation>false</useIncrementalCompilation>
+          <encoding>utf8</encoding>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.13.2</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>io.projectreactor</groupId>
+      <artifactId>reactor-core</artifactId>
+      <version>3.4.29</version>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.projectlombok</groupId>
+      <artifactId>lombok</artifactId>
+      <version>1.18.26</version>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+      <version>1.7.36</version>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>cc.iotkit</groupId>
+      <artifactId>iot-common-core</artifactId>
+      <version>0.4.5-SNAPSHOT</version>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>cc.iotkit</groupId>
+      <artifactId>iot-component-base</artifactId>
+      <version>0.4.5-SNAPSHOT</version>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>cc.iotkit</groupId>
+      <artifactId>iot-data-service</artifactId>
+      <version>0.4.5-SNAPSHOT</version>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>cc.iotkit</groupId>
+      <artifactId>iot-script-engine</artifactId>
+      <version>0.4.5-SNAPSHOT</version>
+      <scope>compile</scope>
+    </dependency>
+  </dependencies>
+</project>

+ 0 - 1
iot-components/pom.xml

@@ -21,7 +21,6 @@
         <module>iot-component-tcp</module>
         <module>iot-DLT645-component</module>
         <module>iot-websocket-component</module>
-        <module>iot-component-oss</module>
    <!--     <module>iot-ctwing-component</module>-->
     </modules>
 

+ 0 - 6
iot-module/iot-contribution/pom.xml

@@ -71,12 +71,6 @@
             <artifactId>iot-screen</artifactId>
         </dependency>
 
-        <dependency>
-            <groupId>cc.iotkit</groupId>
-            <artifactId>iot-component-oss</artifactId>
-            <version>${revision}</version>
-        </dependency>
-
         <dependency>
             <groupId>cc.iotkit</groupId>
             <artifactId>iot-component-server</artifactId>

+ 5 - 6
iot-module/iot-manager/pom.xml

@@ -64,12 +64,6 @@
             <artifactId>iot-screen</artifactId>
         </dependency>
 
-        <dependency>
-            <groupId>cc.iotkit</groupId>
-            <artifactId>iot-component-oss</artifactId>
-            <version>${revision}</version>
-        </dependency>
-
         <dependency>
             <groupId>cc.iotkit</groupId>
             <artifactId>iot-component-server</artifactId>
@@ -90,6 +84,11 @@
             <artifactId>iot-message-core</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>cc.iotkit</groupId>
+            <artifactId>iot-common-oss</artifactId>
+        </dependency>
+
         <dependency>
             <groupId>cc.iotkit</groupId>
             <artifactId>iot-temporal-service</artifactId>

+ 10 - 13
iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/OtaController.java

@@ -3,6 +3,7 @@ package cc.iotkit.manager.controller;
 import cc.iotkit.common.api.PageRequest;
 import cc.iotkit.common.api.Paging;
 import cc.iotkit.common.api.Request;
+import cc.iotkit.common.web.core.BaseController;
 import cc.iotkit.manager.dto.bo.ota.DeviceOtaInfoBo;
 import cc.iotkit.manager.dto.bo.ota.DeviceUpgradeBo;
 import cc.iotkit.manager.dto.bo.ota.OtaPackageBo;
@@ -10,15 +11,13 @@ import cc.iotkit.manager.dto.vo.ota.DeviceOtaInfoVo;
 import cc.iotkit.manager.dto.vo.ota.OtaPackageUploadVo;
 import cc.iotkit.manager.service.OtaService;
 import cc.iotkit.model.ota.OtaPackage;
+import cn.hutool.core.util.ObjectUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.StringUtils;
+import org.springframework.http.MediaType;
 import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
@@ -33,20 +32,18 @@ import javax.validation.Valid;
 @Slf4j
 @RestController
 @RequestMapping("/ota")
-public class OtaController {
+public class OtaController extends BaseController {
 
     @Resource
     private OtaService otaService;
 
     @ApiOperation("升级包上传")
-    @PostMapping("/package/upload")
-    public OtaPackageUploadVo packageUpload(MultipartFile file) throws Exception {
-        if (!file.isEmpty()) {
-            String fileName = file.getOriginalFilename();
-            String suffix = StringUtils.isEmpty(fileName) ? "" : fileName.substring(fileName.lastIndexOf("."));
-            return otaService.uploadFile(file, suffix);
+    @PostMapping(value = "/package/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
+    public OtaPackageUploadVo packageUpload(@RequestPart("file") MultipartFile file, @RequestParam("requestId") String requestId) throws Exception {
+        if (ObjectUtil.isNull(file)) {
+            fail("上传文件不能为空");
         }
-        return null;
+        return otaService.uploadFile(file);
     }
 
     @ApiOperation("新增升级包")

+ 35 - 21
iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/OtaService.java

@@ -2,28 +2,33 @@ package cc.iotkit.manager.service;
 
 import cc.iotkit.common.api.PageRequest;
 import cc.iotkit.common.api.Paging;
+import cc.iotkit.common.exception.BizException;
+import cc.iotkit.common.oss.core.OssClient;
+import cc.iotkit.common.oss.factory.OssFactory;
+import cc.iotkit.common.utils.StringUtils;
 import cc.iotkit.data.manager.IDeviceOtaInfoData;
-import cc.iotkit.data.manager.IOtaDeviceData;
 import cc.iotkit.data.manager.IOtaPackageData;
+import cc.iotkit.data.system.ISysOssData;
 import cc.iotkit.manager.dto.bo.ota.DeviceOtaInfoBo;
 import cc.iotkit.manager.dto.bo.ota.OtaPackageBo;
 import cc.iotkit.manager.dto.vo.ota.DeviceOtaInfoVo;
 import cc.iotkit.manager.dto.vo.ota.OtaPackageUploadVo;
 import cc.iotkit.model.ota.DeviceOtaInfo;
 import cc.iotkit.model.ota.OtaPackage;
-import cc.iotkit.oss.service.OssTemplate;
+import cc.iotkit.model.system.SysOss;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.commons.io.FileUtils;
-import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
-
-import java.io.*;
+import cc.iotkit.common.oss.entity.UploadResult;
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
 import java.security.MessageDigest;
 import java.util.List;
-import java.util.UUID;
 
 /**
  * @Author: 石恒
@@ -36,27 +41,36 @@ import java.util.UUID;
 public class OtaService {
 
     private final IOtaPackageData iOtaPackageData;
-    private final IOtaDeviceData iOtaDeviceData;
     private final DeviceService deviceService;
     private final IDeviceOtaInfoData deviceOtaInfoData;
-    private final OssTemplate ossTemplate;
-
+    private final ISysOssData sysOssData;
 
-    @Value("${oss.region}")
-    private String region;
-    @Value("${oss.buckName}")
-    private String buckName;
+    public OtaPackageUploadVo uploadFile(MultipartFile file) throws Exception {
+        String originalFileName = file.getOriginalFilename();
+        if(originalFileName ==null){
+            throw new BizException("文件名为空,获取失败");
+        }
+        String suffix = StringUtils.substring(originalFileName, originalFileName.lastIndexOf("."), originalFileName.length());
+        OssClient storage = OssFactory.instance();
+        UploadResult uploadResult;
+        try {
+            uploadResult = storage.uploadSuffix(file.getBytes(), suffix, file.getContentType());
+        } catch (IOException e) {
+            throw new BizException(e.getMessage());
+        }
+        // 保存文件信息
+        SysOss oss = new SysOss();
+        oss.setUrl(uploadResult.getUrl());
+        oss.setFileSuffix(suffix);
+        oss.setFileName(uploadResult.getFilename());
+        oss.setOriginalName(originalFileName);
+        oss.setService(storage.getConfigKey());
+        sysOssData.save(oss);
 
-    public OtaPackageUploadVo uploadFile(MultipartFile file, String suffix) throws Exception {
-        InputStream inputStream = file.getInputStream();
-        long size = file.getSize();
-        String objectName = UUID.randomUUID().toString().replaceAll("-", "") + suffix;
-        ossTemplate.putObject(buckName, objectName, inputStream);
-        String url = "https://" + region + "/" + objectName;
         String md5 = md5OfFile(file);
         OtaPackageUploadVo otaPackageUploadVo = new OtaPackageUploadVo();
-        otaPackageUploadVo.setUrl(url);
-        otaPackageUploadVo.setSize(size);
+        otaPackageUploadVo.setUrl(uploadResult.getUrl());
+        otaPackageUploadVo.setSize(file.getSize());
         otaPackageUploadVo.setMd5(md5);
         return otaPackageUploadVo;
     }

+ 6 - 4
iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysOssController.java

@@ -42,9 +42,10 @@ public class SysOssController extends BaseController {
      * 查询OSS对象存储列表
      */
     @SaCheckPermission("system:oss:list")
+    @ApiOperation(value = "查询OSS对象存储列表", notes = "查询OSS对象存储列表")
     @PostMapping("/list")
-    public Paging<SysOssVo> list(@Validated(QueryGroup.class) SysOssBo bo, PageRequest<?> query) {
-        return ossService.queryPageList(bo, query);
+    public Paging<SysOssVo> list(@Validated(QueryGroup.class) @RequestBody PageRequest<SysOssBo> query) {
+        return ossService.queryPageList(query);
     }
 
     /**
@@ -67,7 +68,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) {
+    public SysOssUploadVo upload(@RequestPart("file") MultipartFile file,@RequestParam("requestId") String requestId) {
         if (ObjectUtil.isNull(file)) {
             fail("上传文件不能为空");
         }
@@ -75,7 +76,7 @@ public class SysOssController extends BaseController {
         SysOssUploadVo uploadVo = new SysOssUploadVo();
         uploadVo.setUrl(oss.getUrl());
         uploadVo.setFileName(oss.getOriginalName());
-        uploadVo.setOssId(oss.getOssId().toString());
+        uploadVo.setOssId(oss.getId().toString());
         return uploadVo;
     }
 
@@ -85,6 +86,7 @@ public class SysOssController extends BaseController {
      */
     @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());
     }

+ 1 - 1
iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysProfileController.java

@@ -121,7 +121,7 @@ public class SysProfileController extends BaseController {
             }
             SysOssVo oss = ossService.upload(avatarfile);
             String avatar = oss.getUrl();
-            if (userService.updateUserAvatar(LoginHelper.getUserId(), oss.getOssId())) {
+            if (userService.updateUserAvatar(LoginHelper.getUserId(), oss.getId())) {
                 AvatarVo avatarVo = new AvatarVo();
                 avatarVo.setImgUrl(avatar);
                 return avatarVo;

+ 1 - 1
iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysOssBo.java

@@ -19,7 +19,7 @@ public class SysOssBo extends BaseDto {
     /**
      * ossId
      */
-    private Long ossId;
+    private Long id;
 
     /**
      * 文件名

+ 1 - 1
iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysOssVo.java

@@ -20,7 +20,7 @@ public class SysOssVo implements Serializable {
     /**
      * 对象存储主键
      */
-    private Long ossId;
+    private Long id;
 
     /**
      * 文件名

+ 1 - 1
iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysOssService.java

@@ -17,7 +17,7 @@ import java.util.List;
  */
 public interface ISysOssService {
 
-    Paging<SysOssVo> queryPageList(SysOssBo sysOss, PageRequest<?> query);
+    Paging<SysOssVo> queryPageList(PageRequest<SysOssBo> query);
 
     List<SysOssVo> listByIds(Collection<Long> ossIds);
 

+ 6 - 5
iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysOssServiceImpl.java

@@ -41,16 +41,17 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
     private final ISysOssData sysOssData;
 
     @Override
-    public Paging<SysOssVo> queryPageList(SysOssBo bo, PageRequest<?> query) {
-        return new Paging<>();
+    public Paging<SysOssVo> queryPageList(PageRequest<SysOssBo> query) {
+        return sysOssData.findAll(query.to(SysOss.class)).to(SysOssVo.class);
     }
 
     @Override
     public List<SysOssVo> listByIds(Collection<Long> ossIds) {
         List<SysOssVo> list = new ArrayList<>();
         for (Long id : ossIds) {
-            SysOssVo vo = SpringUtils.getAopProxy(this).getById(id);
-            if (ObjectUtil.isNotNull(vo)) {
+            SysOss oss = sysOssData.findById(id);
+            if (ObjectUtil.isNotNull(oss)) {
+                SysOssVo vo = MapstructUtils.convert(oss, SysOssVo.class);
                 list.add(this.matchingUrl(vo));
             }
         }
@@ -100,7 +101,7 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
         oss.setFileName(uploadResult.getFilename());
         oss.setOriginalName(originalFileName);
         oss.setService(storage.getConfigKey());
-        sysOssData.save(oss);
+        oss = sysOssData.save(oss);
         SysOssVo sysOssVo = MapstructUtils.convert(oss, SysOssVo.class);
         return this.matchingUrl(sysOssVo);
     }