项目集成华为obs查看波形文件
This commit is contained in:
23
pom.xml
23
pom.xml
@@ -25,6 +25,7 @@
|
|||||||
<module>pqs-process</module>
|
<module>pqs-process</module>
|
||||||
<module>pqs-algorithm</module>
|
<module>pqs-algorithm</module>
|
||||||
|
|
||||||
|
|
||||||
</modules>
|
</modules>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<name>灿能微服务生态系统</name>
|
<name>灿能微服务生态系统</name>
|
||||||
@@ -111,10 +112,8 @@
|
|||||||
<xxl-job.version>2.3.0</xxl-job.version>
|
<xxl-job.version>2.3.0</xxl-job.version>
|
||||||
<mqtt.version>1.2.7</mqtt.version>
|
<mqtt.version>1.2.7</mqtt.version>
|
||||||
<easypoi.version>4.4.0</easypoi.version>
|
<easypoi.version>4.4.0</easypoi.version>
|
||||||
<progressbar.version>0.5.3</progressbar.version>
|
|
||||||
<okhttp.version>4.8.1</okhttp.version>
|
|
||||||
<minio.version>8.2.1</minio.version>
|
|
||||||
<spring-cloud-huawei.version>1.7.0-Hoxton</spring-cloud-huawei.version>
|
<spring-cloud-huawei.version>1.7.0-Hoxton</spring-cloud-huawei.version>
|
||||||
|
<okhttp.version>4.8.1</okhttp.version>
|
||||||
</properties>
|
</properties>
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@@ -341,29 +340,11 @@
|
|||||||
<artifactId>easypoi-spring-boot-starter</artifactId>
|
<artifactId>easypoi-spring-boot-starter</artifactId>
|
||||||
<version>${easypoi.version}</version>
|
<version>${easypoi.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!--调用minio服务器-->
|
|
||||||
<dependency>
|
|
||||||
<groupId>me.tongfei</groupId>
|
|
||||||
<artifactId>progressbar</artifactId>
|
|
||||||
<version>${progressbar.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.squareup.okhttp3</groupId>
|
<groupId>com.squareup.okhttp3</groupId>
|
||||||
<artifactId>okhttp</artifactId>
|
<artifactId>okhttp</artifactId>
|
||||||
<version>${okhttp.version}</version>
|
<version>${okhttp.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>io.minio</groupId>
|
|
||||||
<artifactId>minio</artifactId>
|
|
||||||
<version>${minio.version}</version>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>com.squareup.okhttp3</groupId>
|
|
||||||
<artifactId>okhttp</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
|
||||||
<!-- 多数据源切换,当数据源为oracle时需要使用 -->
|
<!-- 多数据源切换,当数据源为oracle时需要使用 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.baomidou</groupId>
|
<groupId>com.baomidou</groupId>
|
||||||
|
|||||||
@@ -1,50 +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>pqs-common</artifactId>
|
|
||||||
<groupId>com.njcn</groupId>
|
|
||||||
<version>1.0.0</version>
|
|
||||||
</parent>
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<artifactId>common-minio</artifactId>
|
|
||||||
<name>minioss的公共信息</name>
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>8</maven.compiler.source>
|
|
||||||
<maven.compiler.target>8</maven.compiler.target>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.njcn</groupId>
|
|
||||||
<artifactId>common-core</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.njcn</groupId>
|
|
||||||
<artifactId>common-web</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>me.tongfei</groupId>
|
|
||||||
<artifactId>progressbar</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.squareup.okhttp3</groupId>
|
|
||||||
<artifactId>okhttp</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.minio</groupId>
|
|
||||||
<artifactId>minio</artifactId>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>com.squareup.okhttp3</groupId>
|
|
||||||
<artifactId>okhttp</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
package com.njcn.minio.bo;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author hongawen
|
|
||||||
* @version 1.0.0
|
|
||||||
* @date 2022年10月16日 18:40
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class MinIoUploadResDTO implements Serializable {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 475040120689218785L;
|
|
||||||
private String minFileName;
|
|
||||||
private String minFileUrl;
|
|
||||||
|
|
||||||
public MinIoUploadResDTO(String minFileName, String minFileUrl) {
|
|
||||||
this.minFileName = minFileName;
|
|
||||||
this.minFileUrl = minFileUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,104 +0,0 @@
|
|||||||
package com.njcn.minio.bo;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author hongawen
|
|
||||||
* @version 1.0.0
|
|
||||||
* @date 2022年10月16日 18:41
|
|
||||||
*/
|
|
||||||
public class Result<T> implements Serializable {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 6273326371984994386L;
|
|
||||||
private Integer code;
|
|
||||||
private String msg;
|
|
||||||
private T data;
|
|
||||||
|
|
||||||
private Result() {
|
|
||||||
this.code = 200;
|
|
||||||
this.msg = "OK";
|
|
||||||
}
|
|
||||||
|
|
||||||
private Result(T data) {
|
|
||||||
this.code = 200;
|
|
||||||
this.msg = "OK";
|
|
||||||
this.setData(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Result(Integer code, String msg) {
|
|
||||||
this.code = code;
|
|
||||||
this.msg = msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Result(Integer code, String msg, T data) {
|
|
||||||
this.code = code;
|
|
||||||
this.msg = msg;
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Result<T> setError(Integer code, String msg) {
|
|
||||||
this.setCode(code);
|
|
||||||
this.setMsg(msg);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSuccess() {
|
|
||||||
return this.getCode().equals(200);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Result ok() {
|
|
||||||
return new Result();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T> Result ok(T data) {
|
|
||||||
return new Result(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T> Result ok(Integer code, String msg) {
|
|
||||||
return new Result(code, msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T> Result ok(Integer code, String msg, T data) {
|
|
||||||
return new Result(code, msg, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T> Result error() {
|
|
||||||
return new Result(500, "failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T> Result error(String msg) {
|
|
||||||
return new Result(500, msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T> Result error(Integer code, String msg) {
|
|
||||||
return new Result(code, msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T> Result error(Integer code, String msg, T data) {
|
|
||||||
return new Result(code, msg, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getCode() {
|
|
||||||
return this.code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCode(Integer code) {
|
|
||||||
this.code = code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMsg() {
|
|
||||||
return this.msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMsg(String msg) {
|
|
||||||
this.msg = msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
public T getData() {
|
|
||||||
return this.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setData(T data) {
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
package com.njcn.minio.config;
|
|
||||||
|
|
||||||
import io.minio.MinioClient;
|
|
||||||
import lombok.Data;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author hongawen
|
|
||||||
* @version 1.0.0
|
|
||||||
* @date 2022年10月16日 18:37
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@Component
|
|
||||||
@ConfigurationProperties(prefix = "min.io")
|
|
||||||
public class MinIoProperties {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Minio 服务端ip
|
|
||||||
*/
|
|
||||||
private String endpoint;
|
|
||||||
|
|
||||||
private String accessKey;
|
|
||||||
|
|
||||||
private String secretKey;
|
|
||||||
|
|
||||||
private String bucket;
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public MinioClient getMinioClient() {
|
|
||||||
return MinioClient.builder()
|
|
||||||
.endpoint(endpoint).credentials(accessKey, secretKey).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,595 +0,0 @@
|
|||||||
package com.njcn.minio.utils;
|
|
||||||
|
|
||||||
import com.njcn.minio.bo.MinIoUploadResDTO;
|
|
||||||
import com.njcn.minio.config.MinIoProperties;
|
|
||||||
import io.minio.*;
|
|
||||||
import io.minio.Result;
|
|
||||||
import io.minio.http.Method;
|
|
||||||
import io.minio.messages.Bucket;
|
|
||||||
import io.minio.messages.DeleteError;
|
|
||||||
import io.minio.messages.DeleteObject;
|
|
||||||
import io.minio.messages.Item;
|
|
||||||
import lombok.SneakyThrows;
|
|
||||||
import org.apache.tomcat.util.http.fileupload.IOUtils;
|
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@EnableConfigurationProperties({MinIoProperties.class})
|
|
||||||
public class MinIoUtils {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private MinioClient instance;
|
|
||||||
|
|
||||||
private static final String SEPARATOR_DOT = ".";
|
|
||||||
|
|
||||||
private static final String SEPARATOR_ACROSS = "-";
|
|
||||||
|
|
||||||
private static final String SEPARATOR_STR = "";
|
|
||||||
|
|
||||||
// 存储桶名称
|
|
||||||
private static final String chunkBucKet = "miniobucket";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 不排序
|
|
||||||
*/
|
|
||||||
public final static boolean NOT_SORT = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 排序
|
|
||||||
*/
|
|
||||||
public final static boolean SORT = true;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 默认过期时间(分钟)
|
|
||||||
*/
|
|
||||||
private final static Integer DEFAULT_EXPIRY = 60;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除分片
|
|
||||||
*/
|
|
||||||
public final static boolean DELETE_CHUNK_OBJECT = true;
|
|
||||||
/**
|
|
||||||
* 不删除分片
|
|
||||||
*/
|
|
||||||
public final static boolean NOT_DELETE_CHUNK_OBJECT = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断桶是否存在
|
|
||||||
* @param bucketName 桶名
|
|
||||||
* @return boolean
|
|
||||||
* @author exe.wangtaotao
|
|
||||||
* @date 2020/10/21 16:33
|
|
||||||
*/
|
|
||||||
public boolean bucketExists(String bucketName) {
|
|
||||||
try {
|
|
||||||
return instance.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建存储桶
|
|
||||||
* 创建 bucket
|
|
||||||
*
|
|
||||||
* @param bucketName 桶名
|
|
||||||
*/
|
|
||||||
public void makeBucket(String bucketName) {
|
|
||||||
try {
|
|
||||||
boolean isExist = bucketExists(bucketName);
|
|
||||||
if (!isExist) {
|
|
||||||
instance.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return java.util.List<java.lang.String>
|
|
||||||
* @Description 获取文件存储服务的所有存储桶名称
|
|
||||||
* @author exe.wangtaotao
|
|
||||||
* @date 2020/10/21 16:35
|
|
||||||
*/
|
|
||||||
public List<String> listBucketNames() {
|
|
||||||
List<Bucket> bucketList = listBuckets();
|
|
||||||
List<String> bucketListName = new ArrayList<>();
|
|
||||||
for (Bucket bucket : bucketList) {
|
|
||||||
bucketListName.add(bucket.name());
|
|
||||||
}
|
|
||||||
return bucketListName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return java.util.List<io.minio.messages.Bucket>
|
|
||||||
* @Description 列出所有存储桶
|
|
||||||
*/
|
|
||||||
@SneakyThrows
|
|
||||||
private List<Bucket> listBuckets() {
|
|
||||||
return instance.listBuckets();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取对象文件名称列表
|
|
||||||
*
|
|
||||||
* @param bucketName 存储桶名称
|
|
||||||
* @param prefix 对象名称前缀(文件夹 /xx/xx/xxx.jpg 中的 /xx/xx/)
|
|
||||||
* @return objectNames
|
|
||||||
*/
|
|
||||||
public List<String> listObjectNames(String bucketName, String prefix) {
|
|
||||||
return listObjectNames(bucketName, prefix, NOT_SORT);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取对象文件名称列表
|
|
||||||
*
|
|
||||||
* @param bucketName 存储桶名称
|
|
||||||
* @param prefix 对象名称前缀(文件夹 /xx/xx/xxx.jpg 中的 /xx/xx/)
|
|
||||||
* @param sort 是否排序(升序)
|
|
||||||
* @return objectNames
|
|
||||||
*/
|
|
||||||
@SneakyThrows
|
|
||||||
public List<String> listObjectNames(String bucketName, String prefix, Boolean sort) {
|
|
||||||
boolean flag = bucketExists(bucketName);
|
|
||||||
if (flag) {
|
|
||||||
ListObjectsArgs listObjectsArgs;
|
|
||||||
if (null == prefix) {
|
|
||||||
listObjectsArgs = ListObjectsArgs.builder()
|
|
||||||
.bucket(bucketName)
|
|
||||||
.recursive(true)
|
|
||||||
.build();
|
|
||||||
} else {
|
|
||||||
listObjectsArgs = ListObjectsArgs.builder()
|
|
||||||
.bucket(bucketName)
|
|
||||||
.prefix(prefix)
|
|
||||||
.recursive(true)
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
Iterable<Result<Item>> chunks = instance.listObjects(listObjectsArgs);
|
|
||||||
List<String> chunkPaths = new ArrayList<>();
|
|
||||||
for (Result<Item> item : chunks) {
|
|
||||||
chunkPaths.add(item.get().objectName());
|
|
||||||
}
|
|
||||||
if (sort) {
|
|
||||||
chunkPaths.sort(new Str2IntComparator(false));
|
|
||||||
}
|
|
||||||
return chunkPaths;
|
|
||||||
}
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 在桶下创建文件夹,文件夹层级结构根据参数决定
|
|
||||||
*
|
|
||||||
* @param bucket 桶名称
|
|
||||||
* @param WotDir 格式为 xxx/xxx/xxx/
|
|
||||||
*/
|
|
||||||
@SneakyThrows
|
|
||||||
public String createDirectory(String bucket, String WotDir) {
|
|
||||||
if (!this.bucketExists(bucket)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
instance.putObject(PutObjectArgs.builder().bucket(bucket).object(WotDir).stream(
|
|
||||||
new ByteArrayInputStream(new byte[]{}), 0, -1)
|
|
||||||
.build());
|
|
||||||
return WotDir;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除一个文件
|
|
||||||
*
|
|
||||||
* @param bucketName 桶名称
|
|
||||||
* @param objectName /xx/xx/xxx.jpg
|
|
||||||
*/
|
|
||||||
@SneakyThrows
|
|
||||||
public boolean removeObject(String bucketName, String objectName) {
|
|
||||||
|
|
||||||
if (!bucketExists(bucketName)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
instance.removeObject(
|
|
||||||
RemoveObjectArgs.builder()
|
|
||||||
.bucket(bucketName)
|
|
||||||
.object(objectName)
|
|
||||||
.build());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param bucketName 桶名称
|
|
||||||
* @param objectNames /xx/xx/xxx.jpg
|
|
||||||
* @return java.util.List<java.lang.String>
|
|
||||||
* @Description 删除指定桶的多个文件对象, 返回删除错误的对象列表,全部删除成功,返回空列表
|
|
||||||
* @author exe.wangtaotao
|
|
||||||
* @date 2020/10/21 16:43
|
|
||||||
*/
|
|
||||||
@SneakyThrows
|
|
||||||
public List<String> removeObjects(String bucketName, List<String> objectNames) {
|
|
||||||
if (!bucketExists(bucketName)) {
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
List<DeleteObject> deleteObjects = new ArrayList<>(objectNames.size());
|
|
||||||
for (String objectName : objectNames) {
|
|
||||||
deleteObjects.add(new DeleteObject(objectName));
|
|
||||||
}
|
|
||||||
List<String> deleteErrorNames = new ArrayList<>();
|
|
||||||
Iterable<Result<DeleteError>> results = instance.removeObjects(
|
|
||||||
RemoveObjectsArgs.builder()
|
|
||||||
.bucket(bucketName)
|
|
||||||
.objects(deleteObjects)
|
|
||||||
.build());
|
|
||||||
for (Result<DeleteError> result : results) {
|
|
||||||
DeleteError error = result.get();
|
|
||||||
deleteErrorNames.add(error.objectName());
|
|
||||||
}
|
|
||||||
return deleteErrorNames;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取访问对象的外链地址
|
|
||||||
* 获取文件的下载url
|
|
||||||
*
|
|
||||||
* @param bucketName 存储桶名称
|
|
||||||
* @param objectName 对象名称
|
|
||||||
* @param expiry 过期时间(分钟) 最大为7天 超过7天则默认最大值
|
|
||||||
* @return viewUrl
|
|
||||||
*/
|
|
||||||
@SneakyThrows
|
|
||||||
public String getObjectUrl(String bucketName, String objectName, Integer expiry) {
|
|
||||||
expiry = expiryHandle(expiry);
|
|
||||||
return instance.getPresignedObjectUrl(
|
|
||||||
GetPresignedObjectUrlArgs.builder()
|
|
||||||
.method(Method.GET)
|
|
||||||
.bucket(bucketName)
|
|
||||||
.object(objectName)
|
|
||||||
.expiry(expiry)
|
|
||||||
.build()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建上传文件对象的外链
|
|
||||||
*
|
|
||||||
* @param bucketName 存储桶名称
|
|
||||||
* @param objectName 欲上传文件对象的名称
|
|
||||||
* @return uploadUrl
|
|
||||||
*/
|
|
||||||
public String createUploadUrl(String bucketName, String objectName) {
|
|
||||||
return createUploadUrl(bucketName, objectName, DEFAULT_EXPIRY);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建上传文件对象的外链
|
|
||||||
*
|
|
||||||
* @param bucketName 存储桶名称
|
|
||||||
* @param objectName 欲上传文件对象的名称
|
|
||||||
* @param expiry 过期时间(分钟) 最大为7天 超过7天则默认最大值
|
|
||||||
* @return uploadUrl
|
|
||||||
*/
|
|
||||||
@SneakyThrows
|
|
||||||
public String createUploadUrl(String bucketName, String objectName, Integer expiry) {
|
|
||||||
expiry = expiryHandle(expiry);
|
|
||||||
return instance.getPresignedObjectUrl(
|
|
||||||
GetPresignedObjectUrlArgs.builder()
|
|
||||||
.method(Method.PUT)
|
|
||||||
.bucket(bucketName)
|
|
||||||
.object(objectName)
|
|
||||||
.expiry(expiry)
|
|
||||||
.build()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * 批量下载
|
|
||||||
// *
|
|
||||||
// * @param directory
|
|
||||||
// * @return
|
|
||||||
// */
|
|
||||||
// @SneakyThrows
|
|
||||||
// public List<String> downLoadMore(String bucket, String directory) {
|
|
||||||
// Iterable<io.minio.Result<Item>> objs = instance.listObjects(ListObjectsArgs.builder().bucket(bucket).prefix(directory).useUrlEncodingType(false).build());
|
|
||||||
// List<String> list = new ArrayList<>();
|
|
||||||
// for (io.minio.Result<Item> result : objs) {
|
|
||||||
// String objectName = null;
|
|
||||||
// objectName = result.get().objectName();
|
|
||||||
// ObjectStat statObject = instance.statObject(StatObjectArgs.builder().bucket(bucket).object(objectName).build());
|
|
||||||
// if (statObject != null && statObject.length() > 0) {
|
|
||||||
// String fileurl = instance.getPresignedObjectUrl(GetPresignedObjectUrlArgs.builder().bucket(bucket).object(statObject.name()).method(Method.GET).build());
|
|
||||||
// list.add(fileurl);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return list;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param multipartFile 文件
|
|
||||||
* @param bucketName 桶名
|
|
||||||
* @param directory image/
|
|
||||||
* @return java.lang.String
|
|
||||||
* @Description 文件上传
|
|
||||||
* @author exe.wangtaotao
|
|
||||||
* @date 2020/10/21 13:45
|
|
||||||
*/
|
|
||||||
public MinIoUploadResDTO upload(MultipartFile multipartFile, String bucketName, String directory) throws Exception {
|
|
||||||
if (!this.bucketExists(bucketName)) {
|
|
||||||
this.makeBucket(bucketName);
|
|
||||||
}
|
|
||||||
InputStream inputStream = multipartFile.getInputStream();
|
|
||||||
directory = Optional.ofNullable(directory).orElse("");
|
|
||||||
String minFileName = directory + minFileName(multipartFile.getOriginalFilename());
|
|
||||||
//上传文件到指定目录
|
|
||||||
instance.putObject(PutObjectArgs.builder()
|
|
||||||
.bucket(bucketName)
|
|
||||||
.object(minFileName)
|
|
||||||
.contentType(multipartFile.getContentType())
|
|
||||||
.stream(inputStream, inputStream.available(), -1)
|
|
||||||
.build());
|
|
||||||
inputStream.close();
|
|
||||||
// 返回生成文件名、访问路径
|
|
||||||
return new MinIoUploadResDTO(minFileName, getObjectUrl(bucketName, minFileName, DEFAULT_EXPIRY));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param response
|
|
||||||
* @return java.lang.String
|
|
||||||
* @Description 下载文件
|
|
||||||
* @author exe.wangtaotao
|
|
||||||
* @date 2020/10/21 15:18
|
|
||||||
*/
|
|
||||||
public void download(HttpServletResponse response, String bucketName, String minFileName) throws Exception {
|
|
||||||
InputStream fileInputStream = instance.getObject(GetObjectArgs.builder()
|
|
||||||
.bucket(bucketName)
|
|
||||||
.object(minFileName).build());
|
|
||||||
response.setHeader("Content-Disposition", "attachment;filename=" + minFileName);
|
|
||||||
response.setContentType("application/force-download");
|
|
||||||
response.setCharacterEncoding("UTF-8");
|
|
||||||
IOUtils.copy(fileInputStream, response.getOutputStream());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 批量创建分片上传外链
|
|
||||||
*
|
|
||||||
* @param bucketName 存储桶名称
|
|
||||||
* @param objectMD5 欲上传分片文件主文件的MD5
|
|
||||||
* @param chunkCount 分片数量
|
|
||||||
* @return uploadChunkUrls
|
|
||||||
*/
|
|
||||||
public List<String> createUploadChunkUrlList(String bucketName, String objectMD5, Integer chunkCount) {
|
|
||||||
if (null == bucketName) {
|
|
||||||
bucketName = chunkBucKet;
|
|
||||||
}
|
|
||||||
if (null == objectMD5) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
objectMD5 += "/";
|
|
||||||
if (null == chunkCount || 0 == chunkCount) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
List<String> urlList = new ArrayList<>(chunkCount);
|
|
||||||
for (int i = 1; i <= chunkCount; i++) {
|
|
||||||
String objectName = objectMD5 + i + ".chunk";
|
|
||||||
urlList.add(createUploadUrl(bucketName, objectName, DEFAULT_EXPIRY));
|
|
||||||
}
|
|
||||||
return urlList;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建指定序号的分片文件上传外链
|
|
||||||
*
|
|
||||||
* @param bucketName 存储桶名称
|
|
||||||
* @param objectMD5 欲上传分片文件主文件的MD5
|
|
||||||
* @param partNumber 分片序号
|
|
||||||
* @return uploadChunkUrl
|
|
||||||
*/
|
|
||||||
public String createUploadChunkUrl(String bucketName, String objectMD5, Integer partNumber) {
|
|
||||||
if (null == bucketName) {
|
|
||||||
bucketName = chunkBucKet;
|
|
||||||
}
|
|
||||||
if (null == objectMD5) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
objectMD5 += "/" + partNumber + ".chunk";
|
|
||||||
return createUploadUrl(bucketName, objectMD5, DEFAULT_EXPIRY);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取分片文件名称列表
|
|
||||||
*
|
|
||||||
* @param bucketName 存储桶名称
|
|
||||||
* @param ObjectMd5 对象Md5
|
|
||||||
* @return objectChunkNames
|
|
||||||
*/
|
|
||||||
public List<String> listChunkObjectNames(String bucketName, String ObjectMd5) {
|
|
||||||
if (null == bucketName) {
|
|
||||||
bucketName = chunkBucKet;
|
|
||||||
}
|
|
||||||
if (null == ObjectMd5) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return listObjectNames(bucketName, ObjectMd5, SORT);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取分片名称地址HashMap key=分片序号 value=分片文件地址
|
|
||||||
*
|
|
||||||
* @param bucketName 存储桶名称
|
|
||||||
* @param ObjectMd5 对象Md5
|
|
||||||
* @return objectChunkNameMap
|
|
||||||
*/
|
|
||||||
public Map<Integer, String> mapChunkObjectNames(String bucketName, String ObjectMd5) {
|
|
||||||
if (null == bucketName) {
|
|
||||||
bucketName = chunkBucKet;
|
|
||||||
}
|
|
||||||
if (null == ObjectMd5) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
List<String> chunkPaths = listObjectNames(bucketName, ObjectMd5);
|
|
||||||
if (null == chunkPaths || chunkPaths.size() == 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
Map<Integer, String> chunkMap = new HashMap<>(chunkPaths.size());
|
|
||||||
for (String chunkName : chunkPaths) {
|
|
||||||
Integer partNumber = Integer.parseInt(chunkName.substring(chunkName.indexOf("/") + 1, chunkName.lastIndexOf(".")));
|
|
||||||
chunkMap.put(partNumber, chunkName);
|
|
||||||
}
|
|
||||||
return chunkMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 合并分片文件成对象文件
|
|
||||||
*
|
|
||||||
* @param chunkBucKetName 分片文件所在存储桶名称
|
|
||||||
* @param composeBucketName 合并后的对象文件存储的存储桶名称
|
|
||||||
* @param chunkNames 分片文件名称集合
|
|
||||||
* @param objectName 合并后的对象文件名称
|
|
||||||
* @return true/false
|
|
||||||
*/
|
|
||||||
@SneakyThrows
|
|
||||||
public boolean composeObject(String chunkBucKetName, String composeBucketName, List<String> chunkNames, String objectName, boolean isDeleteChunkObject) {
|
|
||||||
if (null == chunkBucKetName) {
|
|
||||||
chunkBucKetName = chunkBucKet;
|
|
||||||
}
|
|
||||||
List<ComposeSource> sourceObjectList = new ArrayList<>(chunkNames.size());
|
|
||||||
for (String chunk : chunkNames) {
|
|
||||||
sourceObjectList.add(
|
|
||||||
ComposeSource.builder()
|
|
||||||
.bucket(chunkBucKetName)
|
|
||||||
.object(chunk)
|
|
||||||
.build()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
instance.composeObject(
|
|
||||||
ComposeObjectArgs.builder()
|
|
||||||
.bucket(composeBucketName)
|
|
||||||
.object(objectName)
|
|
||||||
.sources(sourceObjectList)
|
|
||||||
.build()
|
|
||||||
);
|
|
||||||
if (isDeleteChunkObject) {
|
|
||||||
removeObjects(chunkBucKetName, chunkNames);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 合并分片文件成对象文件
|
|
||||||
*
|
|
||||||
* @param bucketName 存储桶名称
|
|
||||||
* @param chunkNames 分片文件名称集合
|
|
||||||
* @param objectName 合并后的对象文件名称
|
|
||||||
* @return true/false
|
|
||||||
*/
|
|
||||||
public boolean composeObject(String bucketName, List<String> chunkNames, String objectName) {
|
|
||||||
return composeObject(chunkBucKet, bucketName, chunkNames, objectName, NOT_DELETE_CHUNK_OBJECT);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 合并分片文件成对象文件
|
|
||||||
*
|
|
||||||
* @param bucketName 存储桶名称
|
|
||||||
* @param chunkNames 分片文件名称集合
|
|
||||||
* @param objectName 合并后的对象文件名称
|
|
||||||
* @return true/false
|
|
||||||
*/
|
|
||||||
public boolean composeObject(String bucketName, List<String> chunkNames, String objectName, boolean isDeleteChunkObject) {
|
|
||||||
return composeObject(chunkBucKet, bucketName, chunkNames, objectName, isDeleteChunkObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 合并分片文件,合并成功后删除分片文件
|
|
||||||
*
|
|
||||||
* @param bucketName 存储桶名称
|
|
||||||
* @param chunkNames 分片文件名称集合
|
|
||||||
* @param objectName 合并后的对象文件名称
|
|
||||||
* @return true/false
|
|
||||||
*/
|
|
||||||
public boolean composeObjectAndRemoveChunk(String bucketName, List<String> chunkNames, String objectName) {
|
|
||||||
return composeObject(chunkBucKet, bucketName, chunkNames, objectName, DELETE_CHUNK_OBJECT);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param originalFileName 原始名称
|
|
||||||
* @return java.lang.String
|
|
||||||
* @Description 生成上传文件名
|
|
||||||
* @author exe.wangtaotao
|
|
||||||
* @date 2020/10/21 15:07
|
|
||||||
*/
|
|
||||||
public String minFileName(String originalFileName) {
|
|
||||||
String suffix = originalFileName;
|
|
||||||
if (originalFileName.contains(SEPARATOR_DOT)) {
|
|
||||||
suffix = originalFileName.substring(originalFileName.lastIndexOf(SEPARATOR_DOT));
|
|
||||||
}
|
|
||||||
return UUID.randomUUID().toString().replace(SEPARATOR_ACROSS, SEPARATOR_STR).toUpperCase() + suffix;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 将分钟数转换为秒数
|
|
||||||
*
|
|
||||||
* @param expiry 过期时间(分钟数)
|
|
||||||
* @return expiry
|
|
||||||
*/
|
|
||||||
private static int expiryHandle(Integer expiry) {
|
|
||||||
expiry = expiry * 60;
|
|
||||||
if (expiry > 604800) {
|
|
||||||
return 604800;
|
|
||||||
}
|
|
||||||
return expiry;
|
|
||||||
}
|
|
||||||
|
|
||||||
static class Str2IntComparator implements Comparator<String> {
|
|
||||||
private final boolean reverseOrder; // 是否倒序
|
|
||||||
|
|
||||||
public Str2IntComparator(boolean reverseOrder) {
|
|
||||||
this.reverseOrder = reverseOrder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compare(String arg0, String arg1) {
|
|
||||||
Integer intArg0 = Integer.parseInt(arg0.substring(arg0.indexOf("/") + 1, arg0.lastIndexOf(".")));
|
|
||||||
Integer intArg1 = Integer.parseInt(arg1.substring(arg1.indexOf("/") + 1, arg1.lastIndexOf(".")));
|
|
||||||
if (reverseOrder) {
|
|
||||||
return intArg1 - intArg0;
|
|
||||||
} else {
|
|
||||||
return intArg0 - intArg1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/***
|
|
||||||
* 根据url地址获取对象名称
|
|
||||||
* @author hongawen
|
|
||||||
* @date 2022/10/17 20:05
|
|
||||||
* @param objectUrl 对象地址
|
|
||||||
* @return String 对象名称
|
|
||||||
*/
|
|
||||||
public static String getObjectNameByUrl(String objectUrl) {
|
|
||||||
if(objectUrl.indexOf("?") < 0){
|
|
||||||
return "unknownFile";
|
|
||||||
}
|
|
||||||
String objectName = objectUrl.substring(0, objectUrl.indexOf("?"));
|
|
||||||
return objectName.substring(objectName.lastIndexOf("/") + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
37
pqs-common/common-oss/pom.xml
Normal file
37
pqs-common/common-oss/pom.xml
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<?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>
|
||||||
|
<artifactId>pqs-common</artifactId>
|
||||||
|
<groupId>com.njcn</groupId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>common-oss</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
<description>
|
||||||
|
文件服务器处理模块
|
||||||
|
</description>
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.njcn</groupId>
|
||||||
|
<artifactId>huawei-obs-springboot-starter</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.njcn</groupId>
|
||||||
|
<artifactId>minioss-springboot-starter</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.njcn.common.pojo.constant;
|
package com.njcn.oss.constant;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author hongawen
|
* @author hongawen
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.njcn.common.pojo.constant;
|
package com.njcn.oss.constant;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author hongawen
|
* @author hongawen
|
||||||
@@ -32,5 +32,15 @@ public interface OssPath {
|
|||||||
*/
|
*/
|
||||||
String LOAD_TYPE_USER="loadTypeUser/";
|
String LOAD_TYPE_USER="loadTypeUser/";
|
||||||
|
|
||||||
|
/***
|
||||||
|
* 技术监督管理 进度文件
|
||||||
|
*/
|
||||||
|
String ELECTRICITY_QUALITY = "electricityQuality/";
|
||||||
|
|
||||||
|
|
||||||
|
/***
|
||||||
|
* 技术监督管理 普测结果报告
|
||||||
|
*/
|
||||||
|
String SURVEY_RESULT = "surveyresult/";
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.njcn.oss.enums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author hongawen
|
||||||
|
* @version 1.0.0
|
||||||
|
* @date 2023年03月07日 22:58
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public enum OssResponseEnum {
|
||||||
|
/**
|
||||||
|
* 文件服务器异常响应码的范围:
|
||||||
|
* A00550 ~ A00649
|
||||||
|
*/
|
||||||
|
UPLOAD_FILE_ERROR("A00551","上传文件服务器错误,请检查数据"),
|
||||||
|
DOWNLOAD_FILE_ERROR("A00554","下载文件URL不存在,请检查数据")
|
||||||
|
|
||||||
|
;
|
||||||
|
|
||||||
|
private final String code;
|
||||||
|
|
||||||
|
private final String message;
|
||||||
|
|
||||||
|
OssResponseEnum(String code, String message) {
|
||||||
|
this.code = code;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
package com.njcn.oss.utils;
|
||||||
|
|
||||||
|
import com.njcn.common.config.GeneralInfo;
|
||||||
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
|
import com.njcn.huawei.obs.util.OBSUtil;
|
||||||
|
import com.njcn.minioss.bo.MinIoUploadResDTO;
|
||||||
|
import com.njcn.minioss.config.MinIoProperties;
|
||||||
|
import com.njcn.minioss.util.MinIoUtils;
|
||||||
|
import com.njcn.oss.constant.GeneralConstant;
|
||||||
|
import com.njcn.oss.constant.OssPath;
|
||||||
|
import com.njcn.oss.enums.OssResponseEnum;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author hongawen
|
||||||
|
* @version 1.0.0
|
||||||
|
* @date 2023年03月07日 22:24
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class FileStorageUtil {
|
||||||
|
|
||||||
|
private final GeneralInfo generalInfo;
|
||||||
|
|
||||||
|
/***
|
||||||
|
* 华为文件服务器工具类
|
||||||
|
* 若有方法需求或方法不满足,去私有仓库下载huawei-obs-springboot-starter模块进行二次开发
|
||||||
|
* 开发完毕后需deploy到maven私有仓库
|
||||||
|
*/
|
||||||
|
private final OBSUtil obsUtil;
|
||||||
|
|
||||||
|
/***
|
||||||
|
* 免费开源Minioss文件服务器工具类
|
||||||
|
* 若有方法需求或方法不满足,去私有仓库下载minioss-springboot-starter模块进行二次开发
|
||||||
|
* 开发完毕后需deploy到maven私有仓库
|
||||||
|
*/
|
||||||
|
private final MinIoUtils minIoUtils;
|
||||||
|
|
||||||
|
private final MinIoProperties minIoProperties;
|
||||||
|
|
||||||
|
|
||||||
|
/***
|
||||||
|
* 上传MultipartFile文件,
|
||||||
|
* @author hongawen
|
||||||
|
* @date 2023/3/7 22:48
|
||||||
|
* @param multipartFile 文件源
|
||||||
|
* @param dir 服务器文件存放路径
|
||||||
|
*/
|
||||||
|
public String uploadMultipart(MultipartFile multipartFile, String dir) {
|
||||||
|
String filePath;
|
||||||
|
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
||||||
|
filePath = dir + minIoUtils.minFileName(multipartFile.getOriginalFilename());
|
||||||
|
obsUtil.multiFileUpload(multipartFile, filePath);
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
//把名称存入数据
|
||||||
|
MinIoUploadResDTO minIoUploadResDTO = minIoUtils.upload(multipartFile, minIoProperties.getBucket(), dir);
|
||||||
|
filePath = minIoUploadResDTO.getMinFileName();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new BusinessException(OssResponseEnum.UPLOAD_FILE_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return filePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***
|
||||||
|
* 根据文件路径获取文件短期的一个url
|
||||||
|
* @author hongawen
|
||||||
|
* @date 2023/3/7 23:04
|
||||||
|
* @param filePath 文件在服务器的路径
|
||||||
|
*/
|
||||||
|
public String getFileUrl(String filePath){
|
||||||
|
String url;
|
||||||
|
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
||||||
|
url = obsUtil.getFileUrl(filePath);
|
||||||
|
} else {
|
||||||
|
url = minIoUtils.getObjectUrl(minIoProperties.getBucket(), filePath, 7 * 24 * 60 * 60);
|
||||||
|
}
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***
|
||||||
|
* 根据文件路径删除指定文件对象
|
||||||
|
* @author hongawen
|
||||||
|
* @date 2023/3/8 9:25
|
||||||
|
* @param fileName 文件路径名
|
||||||
|
*/
|
||||||
|
public void deleteFile(String fileName){
|
||||||
|
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
||||||
|
obsUtil.delete(fileName);
|
||||||
|
}else{
|
||||||
|
minIoUtils.removeObject(minIoProperties.getBucket(), fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -22,8 +22,8 @@
|
|||||||
<module>common-influxdb</module>
|
<module>common-influxdb</module>
|
||||||
<module>common-poi</module>
|
<module>common-poi</module>
|
||||||
<module>common-echarts</module>
|
<module>common-echarts</module>
|
||||||
<module>common-minio</module>
|
|
||||||
<module>common-huawei</module>
|
<module>common-huawei</module>
|
||||||
|
<module>common-oss</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
|||||||
@@ -75,7 +75,7 @@
|
|||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.njcn</groupId>
|
<groupId>com.njcn</groupId>
|
||||||
<artifactId>huawei-obs-springboot-starter</artifactId>
|
<artifactId>common-oss</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ import cn.hutool.core.date.DateUtil;
|
|||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.njcn.common.config.GeneralInfo;
|
import com.njcn.common.config.GeneralInfo;
|
||||||
import com.njcn.common.pojo.constant.GeneralConstant;
|
|
||||||
import com.njcn.common.pojo.constant.OssPath;
|
|
||||||
import com.njcn.common.pojo.enums.common.ServerEnum;
|
import com.njcn.common.pojo.enums.common.ServerEnum;
|
||||||
import com.njcn.common.pojo.exception.BusinessException;
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
import com.njcn.common.utils.PubUtils;
|
import com.njcn.common.utils.PubUtils;
|
||||||
|
import com.njcn.oss.constant.GeneralConstant;
|
||||||
|
import com.njcn.oss.constant.OssPath;
|
||||||
import com.njcn.device.pq.api.GeneralDeviceInfoClient;
|
import com.njcn.device.pq.api.GeneralDeviceInfoClient;
|
||||||
import com.njcn.device.pq.api.LineFeignClient;
|
import com.njcn.device.pq.api.LineFeignClient;
|
||||||
import com.njcn.device.pq.pojo.dto.GeneralDeviceDTO;
|
import com.njcn.device.pq.pojo.dto.GeneralDeviceDTO;
|
||||||
@@ -48,7 +48,6 @@ import java.time.LocalDateTime;
|
|||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -195,8 +194,6 @@ public class TransientServiceImpl implements TransientService {
|
|||||||
originalData = waveUtil.getComtrade(cfgStream, datStream, 1);
|
originalData = waveUtil.getComtrade(cfgStream, datStream, 1);
|
||||||
// } else if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
// } else if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
||||||
} else {
|
} else {
|
||||||
ip = "192.168.1.190";
|
|
||||||
waveName = "PQMonitor_PQM1_002438_20210508_092859_938";
|
|
||||||
cfgPath = OssPath.WAVE_DIR + ip + StrUtil.SLASH + waveName + GeneralConstant.CFG;
|
cfgPath = OssPath.WAVE_DIR + ip + StrUtil.SLASH + waveName + GeneralConstant.CFG;
|
||||||
datPath = OssPath.WAVE_DIR + ip + StrUtil.SLASH + waveName + GeneralConstant.DAT;
|
datPath = OssPath.WAVE_DIR + ip + StrUtil.SLASH + waveName + GeneralConstant.DAT;
|
||||||
try (
|
try (
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.njcn.event;
|
package com.njcn.event;
|
||||||
|
|
||||||
import com.njcn.common.pojo.constant.OssPath;
|
|
||||||
import com.njcn.event.enums.EventResponseEnum;
|
import com.njcn.event.enums.EventResponseEnum;
|
||||||
import com.njcn.event.pojo.PqsEventDetail;
|
import com.njcn.event.pojo.PqsEventDetail;
|
||||||
import com.njcn.event.pojo.PqsOnlinerateAggregate;
|
import com.njcn.event.pojo.PqsOnlinerateAggregate;
|
||||||
@@ -11,6 +10,7 @@ import com.njcn.event.utils.WaveUtil;
|
|||||||
import com.njcn.huawei.obs.util.OBSUtil;
|
import com.njcn.huawei.obs.util.OBSUtil;
|
||||||
import com.njcn.influxdb.config.InfluxDbConfig;
|
import com.njcn.influxdb.config.InfluxDbConfig;
|
||||||
import com.njcn.influxdb.utils.InfluxDbUtils;
|
import com.njcn.influxdb.utils.InfluxDbUtils;
|
||||||
|
import com.njcn.oss.constant.OssPath;
|
||||||
import org.influxdb.dto.QueryResult;
|
import org.influxdb.dto.QueryResult;
|
||||||
import org.influxdb.impl.InfluxDBResultMapper;
|
import org.influxdb.impl.InfluxDBResultMapper;
|
||||||
import org.influxdb.querybuilder.SelectQueryImpl;
|
import org.influxdb.querybuilder.SelectQueryImpl;
|
||||||
@@ -26,12 +26,9 @@ import org.springframework.boot.test.context.SpringBootTest;
|
|||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
|||||||
@@ -60,18 +60,9 @@
|
|||||||
<artifactId>event-api</artifactId>
|
<artifactId>event-api</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>com.njcn</groupId>
|
|
||||||
<artifactId>common-minio</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!--调用minio服务器-->
|
|
||||||
<dependency>
|
|
||||||
<groupId>me.tongfei</groupId>
|
|
||||||
<artifactId>progressbar</artifactId>
|
|
||||||
<version>0.5.3</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.squareup.okhttp3</groupId>
|
<groupId>com.squareup.okhttp3</groupId>
|
||||||
@@ -101,7 +92,7 @@
|
|||||||
<!--华为obs工具包-->
|
<!--华为obs工具包-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.njcn</groupId>
|
<groupId>com.njcn</groupId>
|
||||||
<artifactId>huawei-obs-springboot-starter</artifactId>
|
<artifactId>common-oss</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
@@ -3,23 +3,16 @@ package com.njcn.harmonic.controller.algorithm;
|
|||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import com.njcn.common.config.GeneralInfo;
|
import com.njcn.common.config.GeneralInfo;
|
||||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||||
import com.njcn.common.pojo.constant.GeneralConstant;
|
|
||||||
import com.njcn.common.pojo.constant.OssPath;
|
|
||||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||||
import com.njcn.common.pojo.exception.BusinessException;
|
|
||||||
import com.njcn.common.pojo.response.HttpResult;
|
import com.njcn.common.pojo.response.HttpResult;
|
||||||
import com.njcn.common.utils.HttpResultUtil;
|
import com.njcn.common.utils.HttpResultUtil;
|
||||||
|
|
||||||
import com.njcn.harmonic.enums.HarmonicResponseEnum;
|
|
||||||
import com.njcn.harmonic.pojo.param.RStatFileVO;
|
import com.njcn.harmonic.pojo.param.RStatFileVO;
|
||||||
import com.njcn.harmonic.pojo.po.RStatFile;
|
import com.njcn.harmonic.pojo.po.RStatFile;
|
||||||
import com.njcn.harmonic.pojo.vo.PwRStatOrgVO;
|
|
||||||
import com.njcn.harmonic.service.algorithm.RStatFileService;
|
import com.njcn.harmonic.service.algorithm.RStatFileService;
|
||||||
import com.njcn.huawei.obs.util.OBSUtil;
|
import com.njcn.oss.constant.OssPath;
|
||||||
import com.njcn.minio.bo.MinIoUploadResDTO;
|
import com.njcn.oss.utils.FileStorageUtil;
|
||||||
import com.njcn.minio.config.MinIoProperties;
|
|
||||||
import com.njcn.minio.utils.MinIoUtils;
|
|
||||||
import com.njcn.web.controller.BaseController;
|
import com.njcn.web.controller.BaseController;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
@@ -29,7 +22,6 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
|
||||||
@@ -41,16 +33,10 @@ public class AlgorithmController extends BaseController {
|
|||||||
|
|
||||||
private final RStatFileService rStatFileService;
|
private final RStatFileService rStatFileService;
|
||||||
|
|
||||||
@Resource
|
private final FileStorageUtil fileStorageUtil;
|
||||||
private MinIoUtils minIoUtils;
|
|
||||||
@Resource
|
|
||||||
private MinIoProperties minIoProperties;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private GeneralInfo generalInfo;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private OBSUtil obsUtil;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 算法保存
|
* 算法保存
|
||||||
@@ -91,16 +77,7 @@ public class AlgorithmController extends BaseController {
|
|||||||
@ResponseBody
|
@ResponseBody
|
||||||
public HttpResult<String> uploadFile(MultipartFile file) {
|
public HttpResult<String> uploadFile(MultipartFile file) {
|
||||||
try {
|
try {
|
||||||
//为2则为:华为OBS
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, fileStorageUtil.uploadMultipart(file,OssPath.ALGORITHM), null);
|
||||||
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
|
||||||
String fileName = file.getOriginalFilename();
|
|
||||||
fileName = OssPath.ALGORITHM + minIoUtils.minFileName(fileName);
|
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, obsUtil.multiFileUpload(file, fileName), null);
|
|
||||||
} else {
|
|
||||||
//把名称存入数据
|
|
||||||
MinIoUploadResDTO upload = minIoUtils.upload(file, minIoProperties.getBucket(), OssPath.ALGORITHM);
|
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, upload.getMinFileUrl(), null);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, null);
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, null);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.njcn.harmonic.service.impl;
|
package com.njcn.harmonic.service.impl;
|
||||||
|
|
||||||
|
import ch.qos.logback.core.rolling.helper.FileStoreUtil;
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
@@ -8,8 +9,6 @@ import cn.hutool.json.JSONObject;
|
|||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.njcn.common.config.GeneralInfo;
|
import com.njcn.common.config.GeneralInfo;
|
||||||
import com.njcn.common.pojo.constant.GeneralConstant;
|
|
||||||
import com.njcn.common.pojo.constant.OssPath;
|
|
||||||
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||||
import com.njcn.common.pojo.exception.BusinessException;
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
import com.njcn.harmonic.enums.HarmonicResponseEnum;
|
import com.njcn.harmonic.enums.HarmonicResponseEnum;
|
||||||
@@ -28,14 +27,11 @@ import com.njcn.harmonic.pojo.vo.ReportTemplateVO;
|
|||||||
import com.njcn.harmonic.pojo.vo.ReportTreeVO;
|
import com.njcn.harmonic.pojo.vo.ReportTreeVO;
|
||||||
import com.njcn.harmonic.pojo.vo.SysDeptTempVO;
|
import com.njcn.harmonic.pojo.vo.SysDeptTempVO;
|
||||||
import com.njcn.harmonic.service.CustomReportService;
|
import com.njcn.harmonic.service.CustomReportService;
|
||||||
import com.njcn.huawei.obs.util.OBSUtil;
|
|
||||||
import com.njcn.influxdb.config.InfluxDbConfig;
|
|
||||||
import com.njcn.influxdb.param.InfluxDBSqlConstant;
|
import com.njcn.influxdb.param.InfluxDBSqlConstant;
|
||||||
import com.njcn.influxdb.param.InfluxDBTableConstant;
|
import com.njcn.influxdb.param.InfluxDBTableConstant;
|
||||||
import com.njcn.influxdb.utils.InfluxDbUtils;
|
import com.njcn.influxdb.utils.InfluxDbUtils;
|
||||||
import com.njcn.minio.bo.MinIoUploadResDTO;
|
import com.njcn.oss.constant.OssPath;
|
||||||
import com.njcn.minio.config.MinIoProperties;
|
import com.njcn.oss.utils.FileStorageUtil;
|
||||||
import com.njcn.minio.utils.MinIoUtils;
|
|
||||||
import com.njcn.system.api.DicDataFeignClient;
|
import com.njcn.system.api.DicDataFeignClient;
|
||||||
import com.njcn.user.api.DeptFeignClient;
|
import com.njcn.user.api.DeptFeignClient;
|
||||||
import com.njcn.user.pojo.dto.DeptDTO;
|
import com.njcn.user.pojo.dto.DeptDTO;
|
||||||
@@ -92,17 +88,7 @@ public class CustomReportServiceImpl implements CustomReportService {
|
|||||||
|
|
||||||
private final GeneralInfo generalInfo;
|
private final GeneralInfo generalInfo;
|
||||||
|
|
||||||
@Resource
|
private final FileStorageUtil fileStorageUtil;
|
||||||
private MinIoUtils minIoUtils;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private MinIoProperties minIoProperties;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private InfluxDbConfig influxDbConfig;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private OBSUtil obsUtil;
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -117,20 +103,7 @@ public class CustomReportServiceImpl implements CustomReportService {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new BusinessException(HarmonicResponseEnum.CUSTOM_REPORT_JSON);
|
throw new BusinessException(HarmonicResponseEnum.CUSTOM_REPORT_JSON);
|
||||||
}
|
}
|
||||||
|
reportTemplateParam.setContent(fileStorageUtil.uploadMultipart(fileContent, OssPath.HARMONIC_EXCEL_TEMPLATE));
|
||||||
//为2则为:华为OBS
|
|
||||||
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
|
||||||
fileName = OssPath.HARMONIC_EXCEL_TEMPLATE + minIoUtils.minFileName(fileName);
|
|
||||||
obsUtil.multiFileUpload(fileContent,fileName);
|
|
||||||
reportTemplateParam.setContent(fileName);
|
|
||||||
} else {
|
|
||||||
//否则认为是minioss
|
|
||||||
//文件上传到Minio服务器,存入文件名
|
|
||||||
MinIoUploadResDTO minIoUploadResDTO = contentToMinio(reportTemplateParam.getFileContent(), OssPath.HARMONIC_EXCEL_TEMPLATE);
|
|
||||||
reportTemplateParam.setContent(minIoUploadResDTO.getMinFileName());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//新增模板表
|
//新增模板表
|
||||||
ExcelRptTemp excelRptTemp = new ExcelRptTemp();
|
ExcelRptTemp excelRptTemp = new ExcelRptTemp();
|
||||||
BeanUtils.copyProperties(reportTemplateParam, excelRptTemp);
|
BeanUtils.copyProperties(reportTemplateParam, excelRptTemp);
|
||||||
@@ -155,7 +128,6 @@ public class CustomReportServiceImpl implements CustomReportService {
|
|||||||
public boolean updateCustomReportTemplate(ReportTemplateParam.UpdateReportTemplateParam reportTemplateParam) {
|
public boolean updateCustomReportTemplate(ReportTemplateParam.UpdateReportTemplateParam reportTemplateParam) {
|
||||||
checkName(reportTemplateParam, true);
|
checkName(reportTemplateParam, true);
|
||||||
MultipartFile fileContent = reportTemplateParam.getFileContent();
|
MultipartFile fileContent = reportTemplateParam.getFileContent();
|
||||||
String fileName = fileContent.getName();
|
|
||||||
//检验模板json数据规范
|
//检验模板json数据规范
|
||||||
try {
|
try {
|
||||||
String content = MultipartFileToString(fileContent);
|
String content = MultipartFileToString(fileContent);
|
||||||
@@ -166,18 +138,8 @@ public class CustomReportServiceImpl implements CustomReportService {
|
|||||||
|
|
||||||
//删除之前的文件
|
//删除之前的文件
|
||||||
ExcelRptTemp excelRptTempOld = excelRptTempMapper.selectById(reportTemplateParam.getId());
|
ExcelRptTemp excelRptTempOld = excelRptTempMapper.selectById(reportTemplateParam.getId());
|
||||||
//为2则为:华为OBS
|
fileStorageUtil.deleteFile(excelRptTempOld.getContent());
|
||||||
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
reportTemplateParam.setContent(fileStorageUtil.uploadMultipart(fileContent, OssPath.HARMONIC_EXCEL_TEMPLATE));
|
||||||
obsUtil.delete(excelRptTempOld.getContent());
|
|
||||||
fileName = OssPath.HARMONIC_EXCEL_TEMPLATE + minIoUtils.minFileName(fileName);
|
|
||||||
obsUtil.multiFileUpload(fileContent,fileName);
|
|
||||||
reportTemplateParam.setContent(fileName);
|
|
||||||
}else{
|
|
||||||
minIoUtils.removeObject(minIoProperties.getBucket(), excelRptTempOld.getContent());
|
|
||||||
//文件上传到Minio服务器,存入文件名
|
|
||||||
MinIoUploadResDTO minIoUploadResDTO = contentToMinio(reportTemplateParam.getFileContent(), OssPath.HARMONIC_EXCEL_TEMPLATE);
|
|
||||||
reportTemplateParam.setContent(minIoUploadResDTO.getMinFileName());
|
|
||||||
}
|
|
||||||
//修改模板数据
|
//修改模板数据
|
||||||
ExcelRptTemp excelRptTemp = new ExcelRptTemp();
|
ExcelRptTemp excelRptTemp = new ExcelRptTemp();
|
||||||
BeanUtils.copyProperties(reportTemplateParam, excelRptTemp);
|
BeanUtils.copyProperties(reportTemplateParam, excelRptTemp);
|
||||||
@@ -218,7 +180,7 @@ public class CustomReportServiceImpl implements CustomReportService {
|
|||||||
@Override
|
@Override
|
||||||
public ExcelRptTemp getCustomReportTemplateById(String id) {
|
public ExcelRptTemp getCustomReportTemplateById(String id) {
|
||||||
ExcelRptTemp excelRptTemp = excelRptTempMapper.selectById(id);
|
ExcelRptTemp excelRptTemp = excelRptTempMapper.selectById(id);
|
||||||
String contentUrl = minIoUtils.getObjectUrl(minIoProperties.getBucket(), excelRptTemp.getContent(), 7 * 24 * 60 * 60);
|
String contentUrl = fileStorageUtil.getFileUrl(excelRptTemp.getContent());
|
||||||
excelRptTemp.setContent(contentUrl);
|
excelRptTemp.setContent(contentUrl);
|
||||||
return excelRptTemp;
|
return excelRptTemp;
|
||||||
}
|
}
|
||||||
@@ -265,9 +227,9 @@ public class CustomReportServiceImpl implements CustomReportService {
|
|||||||
List<ExcelRpt> excelRpts = excelRptMapper.selectList(lambdaQuery);
|
List<ExcelRpt> excelRpts = excelRptMapper.selectList(lambdaQuery);
|
||||||
String content;
|
String content;
|
||||||
if (excelRpts.size() > 0) {
|
if (excelRpts.size() > 0) {
|
||||||
content = minIoUtils.getObjectUrl(minIoProperties.getBucket(), excelRpts.get(0).getContent(), 7 * 24 * 60 * 60);
|
content = fileStorageUtil.getFileUrl(excelRpts.get(0).getContent());
|
||||||
} else {
|
} else {
|
||||||
content = minIoUtils.getObjectUrl(minIoProperties.getBucket(), analyzeReport(reportSearchParam, excelRptTemp), 7 * 24 * 60 * 60);
|
content = fileStorageUtil.getFileUrl(analyzeReport(reportSearchParam, excelRptTemp));
|
||||||
}
|
}
|
||||||
|
|
||||||
//拼接数据
|
//拼接数据
|
||||||
@@ -394,7 +356,7 @@ public class CustomReportServiceImpl implements CustomReportService {
|
|||||||
JSONArray jsonArray = null;
|
JSONArray jsonArray = null;
|
||||||
try {
|
try {
|
||||||
//通过文件服务器获取
|
//通过文件服务器获取
|
||||||
String objectUrl = minIoUtils.getObjectUrl(minIoProperties.getBucket(), excelRptTemp.getContent(), 7 * 24 * 60 * 60);
|
String objectUrl = fileStorageUtil.getFileUrl(excelRptTemp.getContent());
|
||||||
jsonArray = JSONUtil.parseArray(urlToString(objectUrl));
|
jsonArray = JSONUtil.parseArray(urlToString(objectUrl));
|
||||||
jsonArray.forEach(item -> {
|
jsonArray.forEach(item -> {
|
||||||
JSONObject jsonObject = (JSONObject) item;
|
JSONObject jsonObject = (JSONObject) item;
|
||||||
@@ -486,22 +448,9 @@ public class CustomReportServiceImpl implements CustomReportService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
String newContent;
|
|
||||||
File newFile = stringToFile(jsonArray.toString());
|
File newFile = stringToFile(jsonArray.toString());
|
||||||
MultipartFile newMultipartFile = getMultipartFile(newFile);
|
MultipartFile newMultipartFile = getMultipartFile(newFile);
|
||||||
//为2则为:华为OBS
|
String newContent = fileStorageUtil.uploadMultipart(newMultipartFile, OssPath.HARMONIC_EXCEL_REPORT);
|
||||||
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
|
||||||
newContent = newMultipartFile.getName();
|
|
||||||
newContent = OssPath.HARMONIC_EXCEL_REPORT + minIoUtils.minFileName(newContent);
|
|
||||||
obsUtil.multiFileUpload(newMultipartFile,newContent);
|
|
||||||
}else{
|
|
||||||
//否则认为是minioss
|
|
||||||
//文件上传到Minio服务器,存入文件名
|
|
||||||
MinIoUploadResDTO minIoUploadResDTO = contentToMinio(newMultipartFile,OssPath.HARMONIC_EXCEL_REPORT);
|
|
||||||
newContent = minIoUploadResDTO.getMinFileName();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//存入报表库
|
//存入报表库
|
||||||
ExcelRpt excelRpt = new ExcelRpt();
|
ExcelRpt excelRpt = new ExcelRpt();
|
||||||
@@ -574,21 +523,6 @@ public class CustomReportServiceImpl implements CustomReportService {
|
|||||||
endList.add(data);
|
endList.add(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 上传文件到Minio
|
|
||||||
*
|
|
||||||
* @param file 文件
|
|
||||||
* @return 成功标记
|
|
||||||
*/
|
|
||||||
private MinIoUploadResDTO contentToMinio(MultipartFile file, String dir) {
|
|
||||||
try {
|
|
||||||
//把名称存入数据
|
|
||||||
MinIoUploadResDTO upload = minIoUtils.upload(file, minIoProperties.getBucket(), dir);
|
|
||||||
return upload;
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new BusinessException(HarmonicResponseEnum.CUSTOM_REPORT_FILE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件Url 转 String
|
* 文件Url 转 String
|
||||||
|
|||||||
@@ -112,16 +112,11 @@
|
|||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.njcn</groupId>
|
<groupId>com.njcn</groupId>
|
||||||
<artifactId>common-minio</artifactId>
|
<artifactId>common-oss</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!--调用minio服务器-->
|
|
||||||
<dependency>
|
|
||||||
<groupId>me.tongfei</groupId>
|
|
||||||
<artifactId>progressbar</artifactId>
|
|
||||||
<version>0.5.3</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.squareup.okhttp3</groupId>
|
<groupId>com.squareup.okhttp3</groupId>
|
||||||
@@ -129,17 +124,6 @@
|
|||||||
<version>4.8.1</version>
|
<version>4.8.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.minio</groupId>
|
|
||||||
<artifactId>minio</artifactId>
|
|
||||||
<version>8.2.1</version>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>com.squareup.okhttp3</groupId>
|
|
||||||
<artifactId>okhttp</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.njcn</groupId>
|
<groupId>com.njcn</groupId>
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ import com.njcn.harmonic.pojo.po.ExcelRptTemp;
|
|||||||
import com.njcn.influxdb.param.InfluxDBSqlConstant;
|
import com.njcn.influxdb.param.InfluxDBSqlConstant;
|
||||||
import com.njcn.influxdb.param.InfluxDBTableConstant;
|
import com.njcn.influxdb.param.InfluxDBTableConstant;
|
||||||
import com.njcn.influxdb.utils.InfluxDbUtils;
|
import com.njcn.influxdb.utils.InfluxDbUtils;
|
||||||
import com.njcn.minio.bo.MinIoUploadResDTO;
|
import com.njcn.minioss.bo.MinIoUploadResDTO;
|
||||||
import com.njcn.minio.config.MinIoProperties;
|
import com.njcn.oss.constant.OssPath;
|
||||||
import com.njcn.minio.utils.MinIoUtils;
|
import com.njcn.oss.utils.FileStorageUtil;
|
||||||
import com.njcn.prepare.harmonic.constant.AlgorithmParam;
|
import com.njcn.prepare.harmonic.constant.AlgorithmParam;
|
||||||
import com.njcn.prepare.harmonic.mapper.mysql.line.ExcelRptMapper;
|
import com.njcn.prepare.harmonic.mapper.mysql.line.ExcelRptMapper;
|
||||||
import com.njcn.prepare.harmonic.mapper.mysql.line.ExcelRptTempMapper;
|
import com.njcn.prepare.harmonic.mapper.mysql.line.ExcelRptTempMapper;
|
||||||
@@ -65,11 +65,7 @@ public class ReportServiceImpl implements ReportService {
|
|||||||
|
|
||||||
private final GeneralInfo generalInfo;
|
private final GeneralInfo generalInfo;
|
||||||
|
|
||||||
@Resource
|
private final FileStorageUtil fileStorageUtil;
|
||||||
private MinIoUtils minIoUtils;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private MinIoProperties minIoProperties;
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -100,7 +96,7 @@ public class ReportServiceImpl implements ReportService {
|
|||||||
for (ExcelRptTemp excelRptTemp : reportTemplateList) {
|
for (ExcelRptTemp excelRptTemp : reportTemplateList) {
|
||||||
try {
|
try {
|
||||||
//获取content解析数据
|
//获取content解析数据
|
||||||
String objectUrl = minIoUtils.getObjectUrl(minIoProperties.getBucket(), excelRptTemp.getContent(), 7 * 24 * 60 * 60);
|
String objectUrl = fileStorageUtil.getFileUrl(excelRptTemp.getContent());
|
||||||
jsonArray = JSONUtil.parseArray(urlToString(objectUrl));
|
jsonArray = JSONUtil.parseArray(urlToString(objectUrl));
|
||||||
dataList = getDataList(jsonArray);
|
dataList = getDataList(jsonArray);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -144,13 +140,11 @@ public class ReportServiceImpl implements ReportService {
|
|||||||
//月:例如2022十月份,传入2022-10-01进行匹配,有则更新无则插入
|
//月:例如2022十月份,传入2022-10-01进行匹配,有则更新无则插入
|
||||||
//周:例如2022年第五周,传入2022-01-23(周一)进行匹配,有则更新无则插入
|
//周:例如2022年第五周,传入2022-01-23(周一)进行匹配,有则更新无则插入
|
||||||
//日:直接插入,无需配对
|
//日:直接插入,无需配对
|
||||||
//文件上传到Minio服务器,存入文件名
|
//文件上传到文件服务器,存入文件名
|
||||||
MinIoUploadResDTO minIoUploadResDTO = contentToMinio(jsonArray.toString());
|
|
||||||
String afterContent = minIoUploadResDTO.getMinFileName();
|
|
||||||
if (BizParamConstant.STAT_BIZ_DAY.equals(reportParam.getType().toString())){
|
if (BizParamConstant.STAT_BIZ_DAY.equals(reportParam.getType().toString())){
|
||||||
rptInsert(reportParam, lineId, excelRptTemp, afterContent);
|
rptInsert(reportParam, lineId, excelRptTemp, contentToOss(jsonArray.toString()));
|
||||||
}else{
|
}else{
|
||||||
rptBiz(reportParam, lineId, excelRptTemp, afterContent);
|
rptBiz(reportParam, lineId, excelRptTemp, contentToOss(jsonArray.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -331,23 +325,17 @@ public class ReportServiceImpl implements ReportService {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传文件到Minio
|
* 上传文件到Oss
|
||||||
*
|
*
|
||||||
* @param content 文件
|
* @param content 文件
|
||||||
* @return 成功标记
|
* @return 成功标记
|
||||||
*/
|
*/
|
||||||
private MinIoUploadResDTO contentToMinio(String content) {
|
private String contentToOss(String content) {
|
||||||
//上传到minio
|
//上传到minio
|
||||||
String businessTempPath = generalInfo.getBusinessTempPath();
|
String businessTempPath = generalInfo.getBusinessTempPath();
|
||||||
File file = stringToFile(content, businessTempPath + File.separator + "a.json");
|
File file = stringToFile(content, businessTempPath + File.separator + "temp.json");
|
||||||
MultipartFile multiFile = getMultipartFile(file);
|
MultipartFile multiFile = getMultipartFile(file);
|
||||||
try {
|
return fileStorageUtil.uploadMultipart(multiFile, OssPath.HARMONIC_EXCEL_REPORT);
|
||||||
//把名称存入数据
|
|
||||||
MinIoUploadResDTO upload = minIoUtils.upload(multiFile, minIoProperties.getBucket(), "report/");
|
|
||||||
return upload;
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new BusinessException(HarmonicResponseEnum.CUSTOM_REPORT_FILE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -16,10 +16,8 @@ public enum ProcessResponseEnum {
|
|||||||
* A00550 ~ A00649
|
* A00550 ~ A00649
|
||||||
*/
|
*/
|
||||||
PROCESS_COMMON_ERROR("A00550","监督管理模块异常"),
|
PROCESS_COMMON_ERROR("A00550","监督管理模块异常"),
|
||||||
UPLOAD_FILE_ERROR("A00551","上传文件服务器错误,请检查数据"),
|
|
||||||
ARCHIVE_ERROR("A00552","不满足归档调节,操作失败!"),
|
ARCHIVE_ERROR("A00552","不满足归档调节,操作失败!"),
|
||||||
PROCESS_ERROR("A00553","当前流程未审核通过,操作失败!"),
|
PROCESS_ERROR("A00553","当前流程未审核通过,操作失败!"),
|
||||||
DOWNLOAD_FILE_ERROR("A00554","下载文件URL不存在,请检查数据"),
|
|
||||||
|
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|||||||
@@ -67,18 +67,9 @@
|
|||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!--调用minio服务器-->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.njcn</groupId>
|
|
||||||
<artifactId>common-minio</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>me.tongfei</groupId>
|
|
||||||
<artifactId>progressbar</artifactId>
|
|
||||||
<version>0.5.3</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.squareup.okhttp3</groupId>
|
<groupId>com.squareup.okhttp3</groupId>
|
||||||
@@ -117,7 +108,7 @@
|
|||||||
<!--华为obs工具包-->
|
<!--华为obs工具包-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.njcn</groupId>
|
<groupId>com.njcn</groupId>
|
||||||
<artifactId>huawei-obs-springboot-starter</artifactId>
|
<artifactId>common-oss</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import com.njcn.common.pojo.enums.common.LogEnum;
|
|||||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||||
import com.njcn.common.pojo.response.HttpResult;
|
import com.njcn.common.pojo.response.HttpResult;
|
||||||
import com.njcn.common.utils.HttpResultUtil;
|
import com.njcn.common.utils.HttpResultUtil;
|
||||||
import com.njcn.minio.bo.MinIoUploadResDTO;
|
|
||||||
import com.njcn.process.pojo.param.*;
|
import com.njcn.process.pojo.param.*;
|
||||||
import com.njcn.process.pojo.vo.*;
|
import com.njcn.process.pojo.vo.*;
|
||||||
import com.njcn.process.service.IssuesService;
|
import com.njcn.process.service.IssuesService;
|
||||||
@@ -185,11 +184,11 @@ public class ElectricityQualityIssuesController extends BaseController {
|
|||||||
@PostMapping("/uploadFile")
|
@PostMapping("/uploadFile")
|
||||||
@ApiOperation("上传文件")
|
@ApiOperation("上传文件")
|
||||||
@ApiImplicitParam(name = "file", value = "填报进度文件", required = true)
|
@ApiImplicitParam(name = "file", value = "填报进度文件", required = true)
|
||||||
public HttpResult<MinIoUploadResDTO> uploadFile(@RequestParam("file") MultipartFile issuesFile){
|
public HttpResult<String> uploadFile(@RequestParam("file") MultipartFile issuesFile){
|
||||||
String methodDescribe = getMethodDescribe("uploadFile");
|
String methodDescribe = getMethodDescribe("uploadFile");
|
||||||
MinIoUploadResDTO out = issuesService.uploadFile(issuesFile);
|
String filePath = issuesService.uploadFile(issuesFile);
|
||||||
out.setMinFileName(issuesFile.getOriginalFilename());
|
// out.setMinFileName(issuesFile.getOriginalFilename());
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, out, methodDescribe);
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, filePath, methodDescribe);
|
||||||
}
|
}
|
||||||
|
|
||||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DOWNLOAD)
|
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DOWNLOAD)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import com.njcn.common.pojo.enums.common.LogEnum;
|
|||||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||||
import com.njcn.common.pojo.response.HttpResult;
|
import com.njcn.common.pojo.response.HttpResult;
|
||||||
import com.njcn.common.utils.HttpResultUtil;
|
import com.njcn.common.utils.HttpResultUtil;
|
||||||
import com.njcn.minio.bo.MinIoUploadResDTO;
|
import com.njcn.minioss.bo.MinIoUploadResDTO;
|
||||||
import com.njcn.poi.util.PoiUtil;
|
import com.njcn.poi.util.PoiUtil;
|
||||||
import com.njcn.process.pojo.param.*;
|
import com.njcn.process.pojo.param.*;
|
||||||
import com.njcn.process.pojo.po.RGeneralSurveyPlanPO;
|
import com.njcn.process.pojo.po.RGeneralSurveyPlanPO;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.njcn.process.service;
|
package com.njcn.process.service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.njcn.minio.bo.MinIoUploadResDTO;
|
|
||||||
import com.njcn.process.pojo.param.*;
|
import com.njcn.process.pojo.param.*;
|
||||||
import com.njcn.process.pojo.vo.*;
|
import com.njcn.process.pojo.vo.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
@@ -79,7 +78,7 @@ public interface IssuesService {
|
|||||||
/**
|
/**
|
||||||
* 上传文件
|
* 上传文件
|
||||||
*/
|
*/
|
||||||
MinIoUploadResDTO uploadFile(MultipartFile issuesFile);
|
String uploadFile(MultipartFile issuesFile);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 下载文件
|
* 下载文件
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package com.njcn.process.service;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.github.jeffreyning.mybatisplus.service.IMppService;
|
import com.github.jeffreyning.mybatisplus.service.IMppService;
|
||||||
import com.njcn.minio.bo.MinIoUploadResDTO;
|
import com.njcn.minioss.bo.MinIoUploadResDTO;
|
||||||
import com.njcn.process.pojo.param.*;
|
import com.njcn.process.pojo.param.*;
|
||||||
import com.njcn.process.pojo.po.RGeneralSurveyPlanPO;
|
import com.njcn.process.pojo.po.RGeneralSurveyPlanPO;
|
||||||
import com.njcn.process.pojo.vo.SurveyPlanExcel;
|
import com.njcn.process.pojo.vo.SurveyPlanExcel;
|
||||||
|
|||||||
@@ -13,9 +13,8 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.njcn.common.pojo.constant.BizParamConstant;
|
import com.njcn.common.pojo.constant.BizParamConstant;
|
||||||
import com.njcn.common.pojo.exception.BusinessException;
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
import com.njcn.minio.bo.MinIoUploadResDTO;
|
import com.njcn.oss.constant.OssPath;
|
||||||
import com.njcn.minio.config.MinIoProperties;
|
import com.njcn.oss.utils.FileStorageUtil;
|
||||||
import com.njcn.minio.utils.MinIoUtils;
|
|
||||||
import com.njcn.process.enums.ProcessResponseEnum;
|
import com.njcn.process.enums.ProcessResponseEnum;
|
||||||
import com.njcn.process.mapper.*;
|
import com.njcn.process.mapper.*;
|
||||||
import com.njcn.process.pojo.param.*;
|
import com.njcn.process.pojo.param.*;
|
||||||
@@ -41,6 +40,7 @@ import java.util.Objects;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 电能质量问题实现类
|
* 电能质量问题实现类
|
||||||
|
*
|
||||||
* @author xiaoyao
|
* @author xiaoyao
|
||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
* @createTime 2022/11/14 11:03
|
* @createTime 2022/11/14 11:03
|
||||||
@@ -68,11 +68,7 @@ public class IssuesServiceImpl implements IssuesService {
|
|||||||
|
|
||||||
private final RStatElectricQualityProblemLogMapper rStatElectricQualityProblemLogMapper;
|
private final RStatElectricQualityProblemLogMapper rStatElectricQualityProblemLogMapper;
|
||||||
|
|
||||||
@Resource
|
private final FileStorageUtil fileStorageUtil;
|
||||||
private MinIoUtils minIoUtils;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private MinIoProperties minIoProperties;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增电能质量问题流程表信息
|
* 新增电能质量问题流程表信息
|
||||||
@@ -477,12 +473,8 @@ public class IssuesServiceImpl implements IssuesService {
|
|||||||
* 上传文件
|
* 上传文件
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public MinIoUploadResDTO uploadFile(MultipartFile issuesFile) {
|
public String uploadFile(MultipartFile issuesFile) {
|
||||||
try {
|
return fileStorageUtil.uploadMultipart(issuesFile, OssPath.ELECTRICITY_QUALITY);
|
||||||
return minIoUtils.upload(issuesFile, minIoProperties.getBucket(), "electricityQuality/");
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new BusinessException(ProcessResponseEnum.UPLOAD_FILE_ERROR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -560,8 +552,6 @@ public class IssuesServiceImpl implements IssuesService {
|
|||||||
/*已关联工单数量*/
|
/*已关联工单数量*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return issueesAndOrderVO;
|
return issueesAndOrderVO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,16 +5,10 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.njcn.common.config.GeneralInfo;
|
import com.njcn.common.config.GeneralInfo;
|
||||||
import com.njcn.common.pojo.constant.GeneralConstant;
|
import com.njcn.oss.constant.OssPath;
|
||||||
import com.njcn.common.pojo.constant.OssPath;
|
|
||||||
import com.njcn.common.pojo.exception.BusinessException;
|
|
||||||
import com.njcn.device.pms.api.DistributionMonitorClient;
|
import com.njcn.device.pms.api.DistributionMonitorClient;
|
||||||
import com.njcn.huawei.obs.util.OBSUtil;
|
import com.njcn.oss.utils.FileStorageUtil;
|
||||||
import com.njcn.minio.bo.MinIoUploadResDTO;
|
|
||||||
import com.njcn.minio.config.MinIoProperties;
|
|
||||||
import com.njcn.minio.utils.MinIoUtils;
|
|
||||||
import com.njcn.process.constant.Param;
|
import com.njcn.process.constant.Param;
|
||||||
import com.njcn.process.enums.ProcessResponseEnum;
|
|
||||||
import com.njcn.process.mapper.LoadTypeUserManageMapper;
|
import com.njcn.process.mapper.LoadTypeUserManageMapper;
|
||||||
import com.njcn.process.pojo.param.*;
|
import com.njcn.process.pojo.param.*;
|
||||||
import com.njcn.process.pojo.po.RLoadTypeUserManage;
|
import com.njcn.process.pojo.po.RLoadTypeUserManage;
|
||||||
@@ -61,16 +55,12 @@ public class LoadTypeUserManageServiceImpl implements LoadTypeUserManageService
|
|||||||
|
|
||||||
private final DeptFeignClient deptFeignClient;
|
private final DeptFeignClient deptFeignClient;
|
||||||
|
|
||||||
@Resource
|
|
||||||
private MinIoUtils minIoUtils;
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private GeneralInfo generalInfo;
|
private GeneralInfo generalInfo;
|
||||||
|
|
||||||
@Resource
|
private final FileStorageUtil fileStorageUtil;
|
||||||
private OBSUtil obsUtil;
|
|
||||||
@Resource
|
|
||||||
private MinIoProperties minIoProperties;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 干扰源用户分页查询
|
* 干扰源用户分页查询
|
||||||
@@ -111,11 +101,11 @@ public class LoadTypeUserManageServiceImpl implements LoadTypeUserManageService
|
|||||||
BeanUtils.copyProperties(rLoadTypeUserManage, rLoadTypeUserManageVO);
|
BeanUtils.copyProperties(rLoadTypeUserManage, rLoadTypeUserManageVO);
|
||||||
//文件
|
//文件
|
||||||
if (rLoadTypeUserManageVO.getIFilePath() != null) {
|
if (rLoadTypeUserManageVO.getIFilePath() != null) {
|
||||||
String iFile = minIoUtils.getObjectUrl(minIoProperties.getBucket(), rLoadTypeUserManageVO.getIFilePath(), 7 * 24 * 60 * 60);
|
String iFile = fileStorageUtil.getFileUrl(rLoadTypeUserManageVO.getIFilePath());
|
||||||
rLoadTypeUserManageVO.setIFile(iFile);
|
rLoadTypeUserManageVO.setIFile(iFile);
|
||||||
}
|
}
|
||||||
if (rLoadTypeUserManageVO.getAFilePath() != null) {
|
if (rLoadTypeUserManageVO.getAFilePath() != null) {
|
||||||
String aFile = minIoUtils.getObjectUrl(minIoProperties.getBucket(), rLoadTypeUserManageVO.getAFilePath(), 7 * 24 * 60 * 60);
|
String aFile = fileStorageUtil.getFileUrl(rLoadTypeUserManageVO.getAFilePath());
|
||||||
rLoadTypeUserManageVO.setIFile(aFile);
|
rLoadTypeUserManageVO.setIFile(aFile);
|
||||||
}
|
}
|
||||||
return rLoadTypeUserManageVO;
|
return rLoadTypeUserManageVO;
|
||||||
@@ -154,14 +144,7 @@ public class LoadTypeUserManageServiceImpl implements LoadTypeUserManageService
|
|||||||
MultipartFile multipartFile = loadTypeUserIUploadParam.getFile();
|
MultipartFile multipartFile = loadTypeUserIUploadParam.getFile();
|
||||||
//文件上传到Minio服务器,存入文件名
|
//文件上传到Minio服务器,存入文件名
|
||||||
if (Objects.nonNull(multipartFile)) {
|
if (Objects.nonNull(multipartFile)) {
|
||||||
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
rLoadTypeUserManage.setIFilePath(fileStorageUtil.uploadMultipart(multipartFile,OssPath.LOAD_TYPE_USER));
|
||||||
String fileName = OssPath.LOAD_TYPE_USER + minIoUtils.minFileName(multipartFile.getOriginalFilename());
|
|
||||||
obsUtil.multiFileUpload(multipartFile, fileName);
|
|
||||||
rLoadTypeUserManage.setIFilePath(fileName);
|
|
||||||
} else {
|
|
||||||
MinIoUploadResDTO minIoUploadResDTO = fileToMinio(loadTypeUserIUploadParam.getFile(), OssPath.LOAD_TYPE_USER);
|
|
||||||
rLoadTypeUserManage.setIFilePath(minIoUploadResDTO.getMinFileName());
|
|
||||||
}
|
|
||||||
rLoadTypeUserManage.setIUploadTime(new Date());
|
rLoadTypeUserManage.setIUploadTime(new Date());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,21 +203,7 @@ public class LoadTypeUserManageServiceImpl implements LoadTypeUserManageService
|
|||||||
return loadTypeUserPage.setRecords(resultList);
|
return loadTypeUserPage.setRecords(resultList);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 上传文件到Minio
|
|
||||||
*
|
|
||||||
* @param file 文件
|
|
||||||
* @return 成功标记
|
|
||||||
*/
|
|
||||||
private MinIoUploadResDTO fileToMinio(MultipartFile file, String dir) {
|
|
||||||
try {
|
|
||||||
//把名称存入数据
|
|
||||||
MinIoUploadResDTO upload = minIoUtils.upload(file, minIoProperties.getBucket(), dir);
|
|
||||||
return upload;
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new BusinessException(ProcessResponseEnum.UPLOAD_FILE_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传干扰源用户入网报告
|
* 上传干扰源用户入网报告
|
||||||
@@ -250,14 +219,7 @@ public class LoadTypeUserManageServiceImpl implements LoadTypeUserManageService
|
|||||||
MultipartFile multipartFile = loadTypeUserAUploadParam.getFile();
|
MultipartFile multipartFile = loadTypeUserAUploadParam.getFile();
|
||||||
//文件上传到文件服务器,存入文件名
|
//文件上传到文件服务器,存入文件名
|
||||||
if (Objects.nonNull(multipartFile)) {
|
if (Objects.nonNull(multipartFile)) {
|
||||||
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
rLoadTypeUserManage.setAFilePath(fileStorageUtil.uploadMultipart(multipartFile,OssPath.LOAD_TYPE_USER));
|
||||||
String fileName = OssPath.LOAD_TYPE_USER + minIoUtils.minFileName(multipartFile.getOriginalFilename());
|
|
||||||
obsUtil.multiFileUpload(multipartFile, fileName);
|
|
||||||
rLoadTypeUserManage.setIFilePath(fileName);
|
|
||||||
} else {
|
|
||||||
MinIoUploadResDTO minIoUploadResDTO = fileToMinio(loadTypeUserAUploadParam.getFile(), OssPath.LOAD_TYPE_USER);
|
|
||||||
rLoadTypeUserManage.setAFilePath(minIoUploadResDTO.getMinFileName());
|
|
||||||
}
|
|
||||||
rLoadTypeUserManage.setAUploadTime(new Date());
|
rLoadTypeUserManage.setAUploadTime(new Date());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
|
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
|
||||||
import com.njcn.common.pojo.exception.BusinessException;
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
import com.njcn.minio.bo.MinIoUploadResDTO;
|
import com.njcn.minioss.bo.MinIoUploadResDTO;
|
||||||
import com.njcn.minio.config.MinIoProperties;
|
import com.njcn.oss.constant.OssPath;
|
||||||
import com.njcn.minio.utils.MinIoUtils;
|
import com.njcn.oss.enums.OssResponseEnum;
|
||||||
import com.njcn.process.enums.ProcessResponseEnum;
|
import com.njcn.oss.utils.FileStorageUtil;
|
||||||
import com.njcn.process.mapper.RGeneralSurveyPlanDetailMapper;
|
import com.njcn.process.mapper.RGeneralSurveyPlanDetailMapper;
|
||||||
import com.njcn.process.mapper.RGeneralSurveyPlanPOMapper;
|
import com.njcn.process.mapper.RGeneralSurveyPlanPOMapper;
|
||||||
import com.njcn.process.pojo.param.*;
|
import com.njcn.process.pojo.param.*;
|
||||||
@@ -38,7 +38,6 @@ import java.util.stream.Collectors;
|
|||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* Description:
|
* Description:
|
||||||
* 接口文档访问地址:http://serverIP:port/swagger-ui.html
|
* 接口文档访问地址:http://serverIP:port/swagger-ui.html
|
||||||
* Date: 2022/11/11 11:24【需求编号】
|
* Date: 2022/11/11 11:24【需求编号】
|
||||||
@@ -49,25 +48,22 @@ import java.util.stream.Stream;
|
|||||||
@Service
|
@Service
|
||||||
public class RGeneralSurveyPlanPOServiceImpl extends MppServiceImpl<RGeneralSurveyPlanPOMapper, RGeneralSurveyPlanPO> implements RGeneralSurveyPlanPOService {
|
public class RGeneralSurveyPlanPOServiceImpl extends MppServiceImpl<RGeneralSurveyPlanPOMapper, RGeneralSurveyPlanPO> implements RGeneralSurveyPlanPOService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
private @Autowired
|
private RGeneralSurveyPlanDetailService rGeneralSurveyPlanDetailService;
|
||||||
RGeneralSurveyPlanDetailService rGeneralSurveyPlanDetailService;
|
|
||||||
|
|
||||||
private @Autowired
|
|
||||||
RGeneralSurveyPlanPOMapper rGeneralSurveyPlanPOMapper;
|
|
||||||
|
|
||||||
private @Autowired
|
|
||||||
RGeneralSurveyPlanDetailMapper rGeneralSurveyPlanDetailMapper;
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private MinIoUtils minIoUtils;
|
private RGeneralSurveyPlanPOMapper rGeneralSurveyPlanPOMapper;
|
||||||
|
|
||||||
private @Autowired
|
|
||||||
DeptFeignClient deptFeignClient;
|
|
||||||
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private MinIoProperties minIoProperties;
|
private RGeneralSurveyPlanDetailMapper rGeneralSurveyPlanDetailMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DeptFeignClient deptFeignClient;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private FileStorageUtil fileStorageUtil;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param rGeneralSurveyPlanAddParm
|
* @param rGeneralSurveyPlanAddParm
|
||||||
* @Description: addPlan
|
* @Description: addPlan
|
||||||
@@ -207,9 +203,9 @@ public class RGeneralSurveyPlanPOServiceImpl extends MppServiceImpl<RGeneralSurv
|
|||||||
fileCount = Optional.ofNullable(fileCount).orElse(0);
|
fileCount = Optional.ofNullable(fileCount).orElse(0);
|
||||||
for (int i = 0; i < surveyResultUploadParam.getFile().length; i++) {
|
for (int i = 0; i < surveyResultUploadParam.getFile().length; i++) {
|
||||||
String OriginalFilename = surveyResultUploadParam.getFile()[i].getOriginalFilename();
|
String OriginalFilename = surveyResultUploadParam.getFile()[i].getOriginalFilename();
|
||||||
MinIoUploadResDTO minIoUploadResDTO = fileToMinio(surveyResultUploadParam.getFile ( )[i]);
|
String fileStoragePath = fileStorageUtil.uploadMultipart(surveyResultUploadParam.getFile()[i], OssPath.SURVEY_RESULT);
|
||||||
/*filePath格式:minIo服务文件名+##+原始文件名+;*/
|
/*filePath格式:minIo服务文件名+##+原始文件名+;*/
|
||||||
filePath=filePath+minIoUploadResDTO.getMinFileName ()+"##"+OriginalFilename+";";
|
filePath = filePath + fileStoragePath + "##" + OriginalFilename + ";";
|
||||||
fileCount++;
|
fileCount++;
|
||||||
}
|
}
|
||||||
rGeneralSurveyPlanPO.setStatus(4);
|
rGeneralSurveyPlanPO.setStatus(4);
|
||||||
@@ -236,14 +232,14 @@ public class RGeneralSurveyPlanPOServiceImpl extends MppServiceImpl<RGeneralSurv
|
|||||||
rGeneralSurveyPlanPO = this.selectByMultiId(rGeneralSurveyPlanPO);
|
rGeneralSurveyPlanPO = this.selectByMultiId(rGeneralSurveyPlanPO);
|
||||||
String filePath = rGeneralSurveyPlanPO.getFilePath();
|
String filePath = rGeneralSurveyPlanPO.getFilePath();
|
||||||
if (StringUtils.isEmpty(filePath)) {
|
if (StringUtils.isEmpty(filePath)) {
|
||||||
throw new BusinessException(ProcessResponseEnum.DOWNLOAD_FILE_ERROR);
|
throw new BusinessException(OssResponseEnum.DOWNLOAD_FILE_ERROR);
|
||||||
}
|
}
|
||||||
String[] split = filePath.substring(0, filePath.length() - 1).split(";");
|
String[] split = filePath.substring(0, filePath.length() - 1).split(";");
|
||||||
List<MinIoUploadResDTO> collect = Stream.of(split).map(temp -> {
|
List<MinIoUploadResDTO> collect = Stream.of(split).map(temp -> {
|
||||||
String[] split1 = temp.split("##");
|
String[] split1 = temp.split("##");
|
||||||
String OriginalFilename = split1[1];
|
String OriginalFilename = split1[1];
|
||||||
String minoFileName = split1[0];
|
String minoFileName = split1[0];
|
||||||
MinIoUploadResDTO dto = new MinIoUploadResDTO(OriginalFilename,minIoUtils.getObjectUrl (minIoProperties.getBucket ( ), minoFileName, 7 * 24 * 60 * 60));
|
MinIoUploadResDTO dto = new MinIoUploadResDTO(OriginalFilename, fileStorageUtil.getFileUrl(minoFileName));
|
||||||
return dto;
|
return dto;
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
return collect;
|
return collect;
|
||||||
@@ -351,18 +347,4 @@ public class RGeneralSurveyPlanPOServiceImpl extends MppServiceImpl<RGeneralSurv
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 上传文件到Minio
|
|
||||||
*
|
|
||||||
* @param file 文件
|
|
||||||
* @return 成功标记
|
|
||||||
*/
|
|
||||||
private MinIoUploadResDTO fileToMinio(MultipartFile file) {
|
|
||||||
try {
|
|
||||||
MinIoUploadResDTO upload = minIoUtils.upload(file, minIoProperties.getBucket(), "surveyresult/");
|
|
||||||
return upload;
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new BusinessException (ProcessResponseEnum.UPLOAD_FILE_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,11 +44,7 @@
|
|||||||
<artifactId>common-swagger</artifactId>
|
<artifactId>common-swagger</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>com.njcn</groupId>
|
|
||||||
<artifactId>common-minio</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@@ -1,84 +0,0 @@
|
|||||||
package com.njcn;
|
|
||||||
|
|
||||||
import com.njcn.minio.config.MinIoProperties;
|
|
||||||
import com.njcn.minio.utils.MinIoUtils;
|
|
||||||
import org.apache.commons.fileupload.FileItem;
|
|
||||||
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author hongawen
|
|
||||||
* @version 1.0.0
|
|
||||||
* @date 2022年11月02日 19:49
|
|
||||||
*/
|
|
||||||
public class MinioTest extends BaseJunitTest {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private MinIoUtils minIoUtils;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private MinIoProperties minIoProperties;
|
|
||||||
|
|
||||||
/***
|
|
||||||
* 上传
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void upload() throws Exception {
|
|
||||||
String strUrl = "C:\\Users\\DELL\\Desktop\\功能测试文件\\text.json";
|
|
||||||
File file = new File(strUrl);
|
|
||||||
MultipartFile cMultiFile = getMultipartFile(file);
|
|
||||||
System.out.println(minIoUtils.upload(cMultiFile, minIoProperties.getBucket(), "day/"));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/***
|
|
||||||
* 删除
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void removeObject(){
|
|
||||||
String name = "day/8D113DD5CE4B4AB2ABB5E531373E3D88.txt";
|
|
||||||
minIoUtils.removeObject(minIoProperties.getBucket(), name);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/***
|
|
||||||
* 根据对象名获取查看的url
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void getObjectUrl(){
|
|
||||||
String name = "day/8D113DD5CE4B4AB2ABB5E531373E3D88.txt";
|
|
||||||
System.out.println(minIoUtils.getObjectUrl(minIoProperties.getBucket(), name, 7 * 24 * 60 * 60));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static MultipartFile getMultipartFile(File file) {
|
|
||||||
FileItem item = new DiskFileItemFactory().createItem("file"
|
|
||||||
, MediaType.MULTIPART_FORM_DATA_VALUE
|
|
||||||
, true
|
|
||||||
, file.getName());
|
|
||||||
try (InputStream input = new FileInputStream(file);
|
|
||||||
OutputStream os = item.getOutputStream()) {
|
|
||||||
// 流转移
|
|
||||||
IOUtils.copy(input, os);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new IllegalArgumentException("Invalid file: " + e, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new CommonsMultipartFile(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user