代码调整
This commit is contained in:
50
pqs-common/common-minio/pom.xml
Normal file
50
pqs-common/common-minio/pom.xml
Normal file
@@ -0,0 +1,50 @@
|
||||
<?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>
|
||||
@@ -0,0 +1,24 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,595 @@
|
||||
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
|
||||
*/
|
||||
private 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);
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@
|
||||
<module>common-influxdb</module>
|
||||
<module>common-poi</module>
|
||||
<module>common-echarts</module>
|
||||
<module>common-minio</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
|
||||
@@ -62,13 +62,4 @@ public interface Param {
|
||||
String PHASIC_TYPE = "phasic_type";
|
||||
String PARENT_ID = "0";
|
||||
|
||||
/**
|
||||
* 算法处理
|
||||
*/
|
||||
String TARGET_FREQ = "freq";
|
||||
String TARGET_RMS = "rms";
|
||||
String TARGET_RMS_LVR = "rms_lvr";
|
||||
String TARGET_V_THD = "v_thd";
|
||||
String TARGET_V_UNBALANCE = "v_unbalance";
|
||||
|
||||
}
|
||||
|
||||
@@ -26,14 +26,7 @@ public enum HarmonicResponseEnum {
|
||||
CUSTOM_TYPE("A00555","字典中未查询到报表模板类型"),
|
||||
CUSTOM_REPORT_ACTIVE("A00556","不存在激活的自定义报告模板"),
|
||||
CUSTOM_REPORT_EMPTY("A00557","自定义报表模板异常,模板数据为空"),
|
||||
|
||||
ALGORITHM_LINE_EMPTY("A00558","算法监测点数据为空"),
|
||||
ALGORITHM_FREP_RULE("A00559","该监测点频率数据异常"),
|
||||
ALGORITHM_RMS_RULE("A00560","该监测点相变压数据异常"),
|
||||
ALGORITHM_RMS_LVR_RULE("A00561","该监测点线变压数据异常"),
|
||||
ALGORITHM_V_THD_RULE("A00562","该监测点电压总谐波畸变率数据异常"),
|
||||
ALGORITHM_V_UNBALANCE_RULE("A00563","该监测点负序电压不平衡度数据异常"),
|
||||
ALGORITHM_DATA_ERROR("A00564","未获取到data数据"),
|
||||
CUSTOM_REPORT_FILE("A00558","上传文件服务器错误,请检查数据"),
|
||||
;
|
||||
|
||||
private final String code;
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
package com.njcn.harmonic.pojo.param;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 算法通用查询参数
|
||||
*
|
||||
* @author qijian
|
||||
* @date 2022/10/26
|
||||
*/
|
||||
@Data
|
||||
public class AlgorithmSearchParam {
|
||||
|
||||
@ApiModelProperty(name = "id",value = "编号")
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty(name = "type",value = "时间类型")
|
||||
private Integer type;
|
||||
|
||||
@ApiModelProperty(name = "datadate",value = "查询时间")
|
||||
private String datadate;
|
||||
|
||||
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package com.njcn.harmonic.pojo.po;
|
||||
|
||||
import lombok.Data;
|
||||
import org.influxdb.annotation.Column;
|
||||
import org.influxdb.annotation.Measurement;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
/**
|
||||
* DataV influxDB别名映射表
|
||||
*
|
||||
* @author qijian
|
||||
* @version 1.0.0
|
||||
* @createTime 2022/10/27 15:27
|
||||
*/
|
||||
@Data
|
||||
@Measurement(name = "data_v")
|
||||
public class DataV {
|
||||
|
||||
@Column(name = "time")
|
||||
private Instant time;
|
||||
|
||||
@Column(name = "line_id")
|
||||
private String lineId;
|
||||
|
||||
@Column(name = "freq_max")
|
||||
private Double frepMAX;
|
||||
|
||||
@Column(name = "freq_min")
|
||||
private Double frepMIN;
|
||||
|
||||
@Column(name = "rms_max")
|
||||
private Double rmsMAX;
|
||||
|
||||
@Column(name = "rms_min")
|
||||
private Double rmsMIN;
|
||||
|
||||
@Column(name = "rms_lvr_max")
|
||||
private Double rmsLvrMAX;
|
||||
|
||||
@Column(name = "rms_lvr_min")
|
||||
private Double rmsLvrMIN;
|
||||
|
||||
@Column(name = "v_thd_max")
|
||||
private Double vThdMAX;
|
||||
|
||||
@Column(name = "v_thd_min")
|
||||
private Double vThdMIN;
|
||||
|
||||
@Column(name = "v_unbalance_max")
|
||||
private Double vUnbalanceMAX;
|
||||
|
||||
@Column(name = "v_unbalance_min")
|
||||
private Double vUnbalanceMIN;
|
||||
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package com.njcn.harmonic.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* (PmsAbnormalRules)实体类
|
||||
*
|
||||
* @author qijian
|
||||
* @since 2022-10-27 14:49:22
|
||||
*/
|
||||
@Data
|
||||
@TableName(value = "pms_abnormal_rules")
|
||||
public class PmsAbnormalRules implements Serializable {
|
||||
private static final long serialVersionUID = -68797682413850371L;
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
private String id;
|
||||
/**
|
||||
* 规则类型(字典 0 数据异常 1......)
|
||||
*/
|
||||
private Integer type;
|
||||
/**
|
||||
* 指标名称
|
||||
*/
|
||||
private String targetName;
|
||||
/**
|
||||
* 对应字段
|
||||
*/
|
||||
private String target;
|
||||
/**
|
||||
* 下限
|
||||
*/
|
||||
private Double lowerLimit;
|
||||
/**
|
||||
* 上限
|
||||
*/
|
||||
private Double upperLimit;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
package com.njcn.harmonic.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* (RMpIntegrityD)实体类
|
||||
*
|
||||
* @author qijian
|
||||
* @since 2022-10-26 14:10:32
|
||||
*/
|
||||
@Data
|
||||
@TableName(value = "r_mp_integrity_d")
|
||||
public class RMpIntegrityD implements Serializable {
|
||||
private static final long serialVersionUID = 320784653665837465L;
|
||||
/**
|
||||
* 监测点id
|
||||
*/
|
||||
private String measurementPointId;
|
||||
/**
|
||||
* 生成数据的时间,每天统计一次
|
||||
*/
|
||||
private Date dataDate;
|
||||
/**
|
||||
* 有效接入分钟数量
|
||||
*/
|
||||
private Integer effectiveMinuteCount;
|
||||
/**
|
||||
* 频率平均值指标数据个数
|
||||
*/
|
||||
private Integer freqCount;
|
||||
/**
|
||||
* 相电压有效值平均值指标数据个数
|
||||
*/
|
||||
private Integer phaseVoltageCount;
|
||||
/**
|
||||
* 线电压有效值平均值指标数据个数
|
||||
*/
|
||||
private Integer lineVoltageCount;
|
||||
/**
|
||||
* 电压总谐波畸变率平均值指标数据个数
|
||||
*/
|
||||
private Integer vThdCount;
|
||||
/**
|
||||
* 三相电压不平衡度平均值指标数据个数
|
||||
*/
|
||||
private Integer unbalanceCount;
|
||||
/**
|
||||
* 监测点短时闪变、电压波动类指标数据个数
|
||||
*/
|
||||
private Integer pstCount;
|
||||
/**
|
||||
* 监测点长时闪变指标数据个数
|
||||
*/
|
||||
private Integer pltCount;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
package com.njcn.harmonic.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* (RStatAbnormalD)实体类
|
||||
*
|
||||
* @author qijian
|
||||
* @since 2022-10-27 14:49:43
|
||||
*/
|
||||
@Data
|
||||
@TableName(value = "r_stat_abnormal_d")
|
||||
public class RStatAbnormalD implements Serializable {
|
||||
private static final long serialVersionUID = 130540916944391303L;
|
||||
/**
|
||||
* 时间
|
||||
*/
|
||||
private Date dataDate;
|
||||
/**
|
||||
* 监测点ID
|
||||
*/
|
||||
private String measurementPointId;
|
||||
/**
|
||||
* 数据是否异常(0异常,1正常)
|
||||
*/
|
||||
private Integer valueAlarm;
|
||||
|
||||
}
|
||||
|
||||
@@ -60,6 +60,11 @@
|
||||
<artifactId>event-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>common-minio</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
package com.njcn.harmonic.controller;
|
||||
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.harmonic.pojo.param.AlgorithmSearchParam;
|
||||
import com.njcn.harmonic.service.DataExceptionService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author qijian
|
||||
* @date 2022/10/26
|
||||
* 数据是否异常
|
||||
*/
|
||||
@Validated
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/dataException")
|
||||
@Api(tags = "数据是否异常")
|
||||
@AllArgsConstructor
|
||||
public class DataExceptionController extends BaseController {
|
||||
|
||||
private final DataExceptionService dataExceptionService;
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/lineDataException")
|
||||
@ApiOperation("监测点数据是否异常")
|
||||
@ApiImplicitParam(name = "algorithmSearchParam", value = "算法通用查询参数", required = true)
|
||||
public HttpResult<Boolean> lineDataException(@RequestBody @Validated AlgorithmSearchParam algorithmSearchParam) {
|
||||
String methodDescribe = getMethodDescribe("lineDataException");
|
||||
boolean res = dataExceptionService.lineDataException(algorithmSearchParam);
|
||||
if(res){
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
package com.njcn.harmonic.controller;
|
||||
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.harmonic.pojo.param.AlgorithmSearchParam;
|
||||
import com.njcn.harmonic.service.DataIntegrityRateService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author qijian
|
||||
* @date 2022/10/26
|
||||
* 数据完整率算法
|
||||
*/
|
||||
@Validated
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/dataIntegrityRate")
|
||||
@Api(tags = "数据完整率算法")
|
||||
@AllArgsConstructor
|
||||
public class DataIntegrityRateController extends BaseController {
|
||||
|
||||
private final DataIntegrityRateService dataIntegrityRateService;
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/lineDataIntegrityRate")
|
||||
@ApiOperation("监测点日数据完整率")
|
||||
@ApiImplicitParam(name = "algorithmSearchParam", value = "算法通用查询参数", required = true)
|
||||
public HttpResult<Boolean> lineDataIntegrityRate(@RequestBody @Validated AlgorithmSearchParam algorithmSearchParam) {
|
||||
String methodDescribe = getMethodDescribe("lineDataIntegrityRate");
|
||||
boolean res = dataIntegrityRateService.lineDataIntegrityRate(algorithmSearchParam);
|
||||
if(res){
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,13 @@ import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.common.utils.LogUtil;
|
||||
import com.njcn.device.pq.pojo.dto.PollutionLineDTO;
|
||||
import com.njcn.device.pq.pojo.dto.PollutionSubstationDTO;
|
||||
import com.njcn.harmonic.pojo.param.HarmonicPublicParam;
|
||||
import com.njcn.harmonic.pojo.param.PollutionSubstationQuryParam;
|
||||
import com.njcn.harmonic.pojo.vo.PollutionSubstationVO;
|
||||
import com.njcn.harmonic.pojo.vo.PollutionVO;
|
||||
import com.njcn.harmonic.service.IPollutionService;
|
||||
import com.njcn.harmonic.service.PollutionSubstationService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -41,6 +46,9 @@ public class PollutionSubstationController extends BaseController {
|
||||
|
||||
private final PollutionSubstationService pollutionSubstationService;
|
||||
|
||||
private final IPollutionService pollutionService;
|
||||
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/getPollutionSubstationData")
|
||||
@ApiOperation("按变电站及指标类型展示污染")
|
||||
@@ -52,5 +60,37 @@ public class PollutionSubstationController extends BaseController {
|
||||
return HttpResultUtil.assembleCommonResponseResult (CommonResponseEnum.SUCCESS, list, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/deptSubstationRelations")
|
||||
@ApiOperation("污区图-部门变电站关系")
|
||||
@ApiImplicitParam(name = "param", value = "实体参数", required = true)
|
||||
public HttpResult<List<PollutionVO>> deptSubstationRelations(@RequestBody HarmonicPublicParam param) {
|
||||
String methodDescribe = getMethodDescribe("deptSubstationRelations");
|
||||
LogUtil.njcnDebug(log, "{},实体参数:{}", methodDescribe, param);
|
||||
List<PollutionVO> list = pollutionSubstationService.getDeptSubstationRelations(param);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/getSubstationInfoById")
|
||||
@ApiOperation("污区图-根据部门获取变电站详情")
|
||||
@ApiImplicitParam(name = "param", value = "部门参数", required = true)
|
||||
public HttpResult<List<PollutionSubstationDTO>> getSubstationInfoById(@RequestBody HarmonicPublicParam param) {
|
||||
String methodDescribe = getMethodDescribe("getSubstationInfoById");
|
||||
LogUtil.njcnDebug(log, "{},部门参数:{}", methodDescribe, param);
|
||||
List<PollutionSubstationDTO> list = pollutionSubstationService.getSubstationInfoById(param);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/getLineInfoById")
|
||||
@ApiOperation("污区图-根据变电站获取监测点详情")
|
||||
@ApiImplicitParam(name = "param", value = "变电站参数", required = true)
|
||||
public HttpResult<List<PollutionLineDTO>> getLineInfoById(@RequestBody HarmonicPublicParam param) {
|
||||
String methodDescribe = getMethodDescribe("getLineInfoById");
|
||||
LogUtil.njcnDebug(log, "{},变电站参数:{}", methodDescribe, param);
|
||||
List<PollutionLineDTO> list = pollutionSubstationService.getLineInfoById(param);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.njcn.harmonic.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.njcn.harmonic.pojo.po.PmsAbnormalRules;
|
||||
|
||||
/**
|
||||
* PmsAbnormalRulesMapper
|
||||
*
|
||||
* @author qijian
|
||||
* @date 2022/10/26
|
||||
*/
|
||||
public interface PmsAbnormalRulesMapper extends BaseMapper<PmsAbnormalRules> {
|
||||
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.njcn.harmonic.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.njcn.harmonic.pojo.po.RMpIntegrityD;
|
||||
|
||||
/**
|
||||
* RMpIntegrityDMapper
|
||||
*
|
||||
* @author qijian
|
||||
* @date 2022/10/26
|
||||
*/
|
||||
public interface RMpIntegrityDMapper extends BaseMapper<RMpIntegrityD> {
|
||||
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.njcn.harmonic.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.njcn.harmonic.pojo.po.RStatAbnormalD;
|
||||
|
||||
/**
|
||||
* RStatAbnormalDMapper
|
||||
*
|
||||
* @author qijian
|
||||
* @date 2022/10/26
|
||||
*/
|
||||
public interface RStatAbnormalDMapper extends BaseMapper<RStatAbnormalD> {
|
||||
|
||||
}
|
||||
@@ -31,7 +31,7 @@ public interface CustomReportService {
|
||||
* @author qijian
|
||||
* @date 2022/10/18
|
||||
*/
|
||||
boolean updateCustomReportTemplate(ReportTemplateParam reportTemplateParam);
|
||||
boolean updateCustomReportTemplate(ReportTemplateParam.UpdateReportTemplateParam reportTemplateParam);
|
||||
|
||||
/**
|
||||
* 根据id获取模板
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.njcn.harmonic.service;
|
||||
|
||||
import com.njcn.harmonic.pojo.param.AlgorithmSearchParam;
|
||||
|
||||
/**
|
||||
* 数据是否异常
|
||||
*
|
||||
* @author qijian
|
||||
* @version 1.0.0
|
||||
* @createTime 2022/10/26 - 10:09
|
||||
*/
|
||||
public interface DataExceptionService {
|
||||
|
||||
/**
|
||||
* 监测点数据是否异常
|
||||
* @author qijian
|
||||
* @date 2022/10/26
|
||||
*/
|
||||
boolean lineDataException(AlgorithmSearchParam algorithmSearchParam);
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.njcn.harmonic.service;
|
||||
|
||||
import com.njcn.harmonic.pojo.param.AlgorithmSearchParam;
|
||||
|
||||
/**
|
||||
* 数据完整率算法
|
||||
*
|
||||
* @author qijian
|
||||
* @version 1.0.0
|
||||
* @createTime 2022/10/26 - 10:09
|
||||
*/
|
||||
public interface DataIntegrityRateService {
|
||||
|
||||
/**
|
||||
* 监测点日数据完整率
|
||||
* @author qijian
|
||||
* @date 2022/10/26
|
||||
*/
|
||||
boolean lineDataIntegrityRate(AlgorithmSearchParam algorithmSearchParam);
|
||||
}
|
||||
@@ -1,9 +1,13 @@
|
||||
package com.njcn.harmonic.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.device.pq.pojo.dto.PollutionLineDTO;
|
||||
import com.njcn.device.pq.pojo.dto.PollutionSubstationDTO;
|
||||
import com.njcn.harmonic.pojo.param.HarmonicPublicParam;
|
||||
import com.njcn.harmonic.pojo.param.PollutionSubstationQuryParam;
|
||||
import com.njcn.harmonic.pojo.po.RStatPollutionSubstationM;
|
||||
import com.njcn.harmonic.pojo.vo.PollutionSubstationVO;
|
||||
import com.njcn.harmonic.pojo.vo.PollutionVO;
|
||||
|
||||
import java.util.List;
|
||||
/**
|
||||
@@ -26,4 +30,29 @@ public interface PollutionSubstationService extends IService<RStatPollutionSubst
|
||||
* @Date: 2022/10/13
|
||||
*/
|
||||
List<PollutionSubstationVO> getPollutionSubstationData(PollutionSubstationQuryParam pollutionSubstationQuryParam);
|
||||
/**
|
||||
* @Description: getDeptSubstationRelations
|
||||
* @Param: [param]
|
||||
* @return: java.util.List<com.njcn.harmonic.pojo.vo.PollutionVO>
|
||||
* @Author: clam
|
||||
* @Date: 2022/11/3
|
||||
*/
|
||||
List<PollutionVO> getDeptSubstationRelations(HarmonicPublicParam param);
|
||||
/**
|
||||
* @Description: getSubstationInfoById
|
||||
* @Param: [param]
|
||||
* @return: java.util.List<com.njcn.device.pq.pojo.dto.PollutionSubstationDTO>
|
||||
* @Author: clam
|
||||
* @Date: 2022/11/3
|
||||
*/
|
||||
List<PollutionSubstationDTO> getSubstationInfoById(HarmonicPublicParam param);
|
||||
|
||||
/**
|
||||
* @Description: getLineInfoById
|
||||
* @Param: [param]
|
||||
* @return: java.util.List<com.njcn.device.pq.pojo.dto.PollutionLineDTO>
|
||||
* @Author: clam
|
||||
* @Date: 2022/11/3
|
||||
*/
|
||||
List<PollutionLineDTO> getLineInfoById(HarmonicPublicParam param);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.njcn.common.config.GeneralInfo;
|
||||
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.harmonic.enums.HarmonicResponseEnum;
|
||||
@@ -29,19 +30,30 @@ import com.njcn.influxdb.config.InfluxDbConfig;
|
||||
import com.njcn.influxdb.param.InfluxDBSqlConstant;
|
||||
import com.njcn.influxdb.param.InfluxDBTableConstant;
|
||||
import com.njcn.influxdb.utils.InfluxDbUtils;
|
||||
import com.njcn.minio.bo.MinIoUploadResDTO;
|
||||
import com.njcn.minio.config.MinIoProperties;
|
||||
import com.njcn.minio.utils.MinIoUtils;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
import com.njcn.user.api.DeptFeignClient;
|
||||
import com.njcn.user.pojo.dto.DeptDTO;
|
||||
import com.njcn.web.utils.WebUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.fileupload.FileItem;
|
||||
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.influxdb.dto.QueryResult;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -75,6 +87,14 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
|
||||
private final DeptTempMapper deptTempMapper;
|
||||
|
||||
private final GeneralInfo generalInfo;
|
||||
|
||||
@Resource
|
||||
private MinIoUtils minIoUtils;
|
||||
|
||||
@Resource
|
||||
private MinIoProperties minIoProperties;
|
||||
|
||||
@Resource
|
||||
private InfluxDbConfig influxDbConfig;
|
||||
|
||||
@@ -89,6 +109,10 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
throw new BusinessException(HarmonicResponseEnum.CUSTOM_REPORT_JSON);
|
||||
}
|
||||
|
||||
//文件上传到Minio服务器,存入文件名
|
||||
MinIoUploadResDTO minIoUploadResDTO = contentToMinio(reportTemplateParam.getContent());
|
||||
reportTemplateParam.setContent(minIoUploadResDTO.getMinFileName());
|
||||
|
||||
//新增模板表
|
||||
ExcelRptTemp excelRptTemp = new ExcelRptTemp();
|
||||
BeanUtils.copyProperties(reportTemplateParam, excelRptTemp);
|
||||
@@ -110,7 +134,7 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateCustomReportTemplate(ReportTemplateParam reportTemplateParam) {
|
||||
public boolean updateCustomReportTemplate(ReportTemplateParam.UpdateReportTemplateParam reportTemplateParam) {
|
||||
checkName(reportTemplateParam, true);
|
||||
|
||||
//检验模板json数据规范
|
||||
@@ -120,6 +144,14 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
throw new BusinessException(HarmonicResponseEnum.CUSTOM_REPORT_JSON);
|
||||
}
|
||||
|
||||
//删除之前的文件
|
||||
ExcelRptTemp excelRptTempOld = excelRptTempMapper.selectById(reportTemplateParam.getId());
|
||||
minIoUtils.removeObject(minIoProperties.getBucket(), excelRptTempOld.getContent());
|
||||
|
||||
//文件上传到Minio服务器,存入文件名
|
||||
MinIoUploadResDTO minIoUploadResDTO = contentToMinio(reportTemplateParam.getContent());
|
||||
reportTemplateParam.setContent(minIoUploadResDTO.getMinFileName());
|
||||
|
||||
//修改模板数据
|
||||
ExcelRptTemp excelRptTemp = new ExcelRptTemp();
|
||||
BeanUtils.copyProperties(reportTemplateParam, excelRptTemp);
|
||||
@@ -159,10 +191,12 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
|
||||
@Override
|
||||
public ExcelRptTemp getCustomReportTemplateById(String id) {
|
||||
return excelRptTempMapper.selectById(id);
|
||||
ExcelRptTemp excelRptTemp = excelRptTempMapper.selectById(id);
|
||||
String contentUrl = minIoUtils.getObjectUrl(minIoProperties.getBucket(), excelRptTemp.getContent(), 7 * 24 * 60 * 60);
|
||||
excelRptTemp.setContent(contentUrl);
|
||||
return excelRptTemp;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<ReportTemplateVO> getTemplateList(ReportSearchParam reportSearchParam) {
|
||||
return excelRptTempMapper.getReportTemplateList(reportSearchParam);
|
||||
@@ -203,7 +237,9 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
List<ReportTemplateDTO> reportTemplateDTOList = new ArrayList<>();
|
||||
JSONArray jsonArray = null;
|
||||
try {
|
||||
jsonArray = JSONUtil.parseArray(excelRptTemp.getContent());
|
||||
//通过文件服务器获取
|
||||
String objectUrl = minIoUtils.getObjectUrl(minIoProperties.getBucket(), excelRptTemp.getContent(), 7 * 24 * 60 * 60);
|
||||
jsonArray = JSONUtil.parseArray(urlToString(objectUrl));
|
||||
jsonArray.forEach(item -> {
|
||||
JSONObject jsonObject = (JSONObject) item;
|
||||
JSONArray itemArr = (JSONArray) jsonObject.get("celldata");
|
||||
@@ -294,7 +330,9 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
});
|
||||
}
|
||||
|
||||
String content = jsonArray.toString();
|
||||
//文件上传到Minio服务器,存入文件名
|
||||
MinIoUploadResDTO minIoUploadResDTO = contentToMinio(jsonArray.toString());
|
||||
String content = minIoUploadResDTO.getMinFileName();
|
||||
//根据模板激活状态,判断是否进库(未激活不进库,已激活进库)
|
||||
if (DataStateEnum.ENABLE.getCode().equals(reportSearchParam.getActivation())) {
|
||||
//存入报表库
|
||||
@@ -309,7 +347,7 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
excelRptMapper.insert(excelRpt);
|
||||
}
|
||||
|
||||
return content;
|
||||
return minIoUtils.getObjectUrl(minIoProperties.getBucket(), content, 7 * 24 * 60 * 60);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -468,4 +506,105 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
endList.add(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件到Minio
|
||||
*
|
||||
* @param content 文件
|
||||
* @return 成功标记
|
||||
*/
|
||||
private MinIoUploadResDTO contentToMinio(String content) {
|
||||
//上传到minio
|
||||
String businessTempPath = generalInfo.getBusinessTempPath();
|
||||
File file = stringToFile(content, businessTempPath + File.separator + "a.json");
|
||||
MultipartFile multiFile = getMultipartFile(file);
|
||||
try {
|
||||
//把名称存入数据
|
||||
MinIoUploadResDTO upload = minIoUtils.upload(multiFile, minIoProperties.getBucket(), "report/");
|
||||
return upload;
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException(HarmonicResponseEnum.CUSTOM_REPORT_FILE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字符串写入指定文件
|
||||
*
|
||||
* @param res 原字符串
|
||||
* @param filePath 文件路径
|
||||
* @return 成功标记
|
||||
*/
|
||||
public File stringToFile(String res, String filePath) {
|
||||
boolean flag = true;
|
||||
BufferedReader bufferedReader = null;
|
||||
BufferedWriter bufferedWriter = null;
|
||||
File distFile = new File(filePath);
|
||||
try {
|
||||
if (!distFile.getParentFile().exists()){
|
||||
distFile.getParentFile().mkdirs();
|
||||
}
|
||||
bufferedReader = new BufferedReader(new StringReader(res));
|
||||
bufferedWriter = new BufferedWriter(new FileWriter(distFile));
|
||||
//先清空
|
||||
bufferedWriter.write("");
|
||||
char buf[] = new char[1024]; //字符缓冲区
|
||||
int len;
|
||||
while ((len = bufferedReader.read(buf)) != -1) {
|
||||
bufferedWriter.write(buf, 0, len);
|
||||
}
|
||||
bufferedWriter.flush();
|
||||
bufferedReader.close();
|
||||
bufferedWriter.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (bufferedReader != null) {
|
||||
try {
|
||||
bufferedReader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return distFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将文件转成Multipart
|
||||
*
|
||||
* @param file 文件
|
||||
* @return 成功标记
|
||||
*/
|
||||
private 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将文件Url转成String
|
||||
*
|
||||
* @param objectUrl 文件url
|
||||
* @return 成功标记
|
||||
*/
|
||||
private String urlToString(String objectUrl) throws IOException {
|
||||
URL url = new URL(objectUrl);
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
String line = " ";
|
||||
while ((line = in.readLine()) != null){
|
||||
buffer.append(line);
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,182 +0,0 @@
|
||||
package com.njcn.harmonic.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.device.pq.api.LineFeignClient;
|
||||
import com.njcn.device.pq.pojo.vo.LineDetailDataVO;
|
||||
import com.njcn.harmonic.constant.Param;
|
||||
import com.njcn.harmonic.enums.HarmonicResponseEnum;
|
||||
import com.njcn.harmonic.mapper.PmsAbnormalRulesMapper;
|
||||
import com.njcn.harmonic.mapper.RStatAbnormalDMapper;
|
||||
import com.njcn.harmonic.pojo.param.AlgorithmSearchParam;
|
||||
import com.njcn.harmonic.pojo.po.DataV;
|
||||
import com.njcn.harmonic.pojo.po.PmsAbnormalRules;
|
||||
import com.njcn.harmonic.pojo.po.RStatAbnormalD;
|
||||
import com.njcn.harmonic.service.DataExceptionService;
|
||||
import com.njcn.influxdb.config.InfluxDbConfig;
|
||||
import com.njcn.influxdb.param.InfluxDBPublicParam;
|
||||
import com.njcn.influxdb.param.InfluxDBSqlConstant;
|
||||
import com.njcn.influxdb.param.InfluxDBTableConstant;
|
||||
import com.njcn.influxdb.utils.InfluxDbUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.influxdb.dto.QueryResult;
|
||||
import org.influxdb.impl.InfluxDBResultMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 数据是否异常
|
||||
*
|
||||
* @author qijian
|
||||
* @version 1.0.0
|
||||
* @createTime 2022/10/26 - 10:09
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class DataExceptionServiceImpl implements DataExceptionService {
|
||||
|
||||
private final InfluxDbUtils influxDbUtils;
|
||||
|
||||
private final LineFeignClient lineFeignClient;
|
||||
|
||||
private final PmsAbnormalRulesMapper pmsAbnormalRulesMapper;
|
||||
|
||||
private final RStatAbnormalDMapper rStatAbnormalDMapper;
|
||||
|
||||
@Resource
|
||||
private InfluxDbConfig influxDbConfig;
|
||||
|
||||
/**
|
||||
* 监测点数据是否异常
|
||||
* @author qijian
|
||||
* @date 2022/10/26
|
||||
*/
|
||||
@Override
|
||||
public boolean lineDataException(AlgorithmSearchParam algorithmSearchParam) {
|
||||
//测试
|
||||
// InfluxDbUtils influxDBUtil = new InfluxDbUtils("admin", "njcnpqs", "http://192.168.1.18:8086", "pqsbase", "");
|
||||
//初始化
|
||||
InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
|
||||
String searchSql;
|
||||
String sql;
|
||||
QueryResult query;
|
||||
DataV dataV;
|
||||
Date date = DateUtil.parse(algorithmSearchParam.getDatadate());
|
||||
String lineId = algorithmSearchParam.getId();
|
||||
|
||||
//入库数据初始化
|
||||
RStatAbnormalD rStatAbnormalD = new RStatAbnormalD();
|
||||
rStatAbnormalD.setDataDate(date);
|
||||
rStatAbnormalD.setMeasurementPointId(lineId);
|
||||
rStatAbnormalD.setValueAlarm(0);
|
||||
|
||||
//1、取出规则
|
||||
List<PmsAbnormalRules> pmsAbnormalRules = pmsAbnormalRulesMapper.selectList(null);
|
||||
|
||||
//2、取出电压
|
||||
List<String> lineIds = new ArrayList<>();
|
||||
lineIds.add(lineId);
|
||||
List<LineDetailDataVO> lineDetailList = lineFeignClient.getLineDetailList(lineIds).getData();
|
||||
if (lineDetailList.size() == 0){
|
||||
throw new BusinessException(HarmonicResponseEnum.ALGORITHM_LINE_EMPTY);
|
||||
}
|
||||
String scale = lineDetailList.get(0).getScale().replace("kV","");
|
||||
|
||||
//3、根据规则表进行判断
|
||||
//取前四项进行比较(相别为A)
|
||||
searchSql = "MAX(freq) as freq_max,MIN(freq) as freq_min,MAX(rms) as rms_max,MIN(rms) as rms_min,MAX(rms_lvr) as rms_lvr_max,MIN(rms_lvr) as rms_lvr_min,MAX(v_thd) as v_thd_max,MIN(v_thd) as v_thd_min ";
|
||||
sql = getAppend(lineId, date, searchSql, "A");
|
||||
query = influxDbUtils.query(sql);
|
||||
dataV = resultMapper.toPOJO(query, DataV.class).get(0);
|
||||
|
||||
//开始判断业务
|
||||
HarmonicResponseEnum harmonicResponseEnum = null;
|
||||
for (PmsAbnormalRules pmsAbnormalRule : pmsAbnormalRules) {
|
||||
//每项数据进行上下限比较(MAX和MIN),若有一项不在数据范围内,则为异常
|
||||
switch (pmsAbnormalRule.getTarget()) {
|
||||
case Param.TARGET_FREQ:
|
||||
//频率:正常比较
|
||||
if (dataV.getFrepMIN() < pmsAbnormalRule.getLowerLimit() || dataV.getFrepMAX() > pmsAbnormalRule.getUpperLimit()){
|
||||
harmonicResponseEnum = HarmonicResponseEnum.ALGORITHM_FREP_RULE;
|
||||
}
|
||||
break;
|
||||
case Param.TARGET_RMS:
|
||||
//相电压有效值特殊处理:在【0.85p.u.,1.2p.u.】之间;p.u=电压等级/1.732
|
||||
pmsAbnormalRule.setLowerLimit((pmsAbnormalRule.getLowerLimit() * (Double.parseDouble(scale) / 1.732)));
|
||||
pmsAbnormalRule.setUpperLimit((pmsAbnormalRule.getUpperLimit() * (Double.parseDouble(scale) / 1.732)));
|
||||
if (dataV.getRmsMIN() < pmsAbnormalRule.getLowerLimit() || dataV.getRmsMAX() > pmsAbnormalRule.getUpperLimit()){
|
||||
harmonicResponseEnum = HarmonicResponseEnum.ALGORITHM_RMS_RULE;
|
||||
}
|
||||
break;
|
||||
case Param.TARGET_RMS_LVR:
|
||||
//线电压有效值特殊处理:在【0.85p.u.,1.2p.u.】之间;p.u=电压等级
|
||||
pmsAbnormalRule.setLowerLimit((pmsAbnormalRule.getLowerLimit() * Double.parseDouble(scale)));
|
||||
pmsAbnormalRule.setUpperLimit((pmsAbnormalRule.getUpperLimit() * Double.parseDouble(scale)));
|
||||
if (dataV.getRmsLvrMIN() < pmsAbnormalRule.getLowerLimit() || dataV.getRmsLvrMAX() > pmsAbnormalRule.getUpperLimit()){
|
||||
harmonicResponseEnum = HarmonicResponseEnum.ALGORITHM_RMS_LVR_RULE;
|
||||
}
|
||||
break;
|
||||
case Param.TARGET_V_THD:
|
||||
//电压总谐波畸变率:正常比较
|
||||
if (dataV.getVThdMIN() < pmsAbnormalRule.getLowerLimit() || dataV.getVThdMAX() > pmsAbnormalRule.getUpperLimit()){
|
||||
harmonicResponseEnum = HarmonicResponseEnum.ALGORITHM_V_THD_RULE;
|
||||
}
|
||||
break;
|
||||
case Param.TARGET_V_UNBALANCE:
|
||||
//三相不平衡度:正常比较(相别为T)
|
||||
searchSql = "MAX(v_unbalance) as v_unbalance_max,MIN(v_unbalance) as v_unbalance_min ";
|
||||
sql = getAppend(lineId, date, searchSql, "T");
|
||||
query = influxDbUtils.query(sql);
|
||||
dataV = resultMapper.toPOJO(query, DataV.class).get(0);
|
||||
if (dataV.getVUnbalanceMIN() < pmsAbnormalRule.getLowerLimit() || dataV.getVUnbalanceMAX() > pmsAbnormalRule.getUpperLimit()){
|
||||
harmonicResponseEnum = HarmonicResponseEnum.ALGORITHM_V_UNBALANCE_RULE;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (harmonicResponseEnum != null){
|
||||
//入库
|
||||
LambdaQueryWrapper<RStatAbnormalD> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(RStatAbnormalD::getMeasurementPointId, lineId).eq(RStatAbnormalD::getDataDate, date);
|
||||
RStatAbnormalD rStatAbnormalDOne = rStatAbnormalDMapper.selectOne(lambdaQueryWrapper);
|
||||
if (Objects.isNull(rStatAbnormalDOne)){
|
||||
rStatAbnormalDMapper.insert(rStatAbnormalD);
|
||||
}
|
||||
throw new BusinessException(harmonicResponseEnum);
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼装sql
|
||||
* @param id,date,searchSql,tableName 参数
|
||||
* @return 结果
|
||||
*/
|
||||
private String getAppend(String id, Date date, String searchSql,String type) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append(InfluxDBSqlConstant.SELECT).append(searchSql)
|
||||
.append(InfluxDBSqlConstant.FROM).append(InfluxDBPublicParam.DATA_V)
|
||||
.append(InfluxDBSqlConstant.WHERE).append(InfluxDBPublicParam.TIME).append(InfluxDBSqlConstant.GE).append(InfluxDBSqlConstant.QM).append(DateUtil.beginOfDay(date)).append(InfluxDBSqlConstant.QM)
|
||||
.append(InfluxDBSqlConstant.AND).append(InfluxDBPublicParam.TIME).append(InfluxDBSqlConstant.LE).append(InfluxDBSqlConstant.QM).append(DateUtil.endOfDay(date)).append(InfluxDBSqlConstant.QM)
|
||||
.append(InfluxDBSqlConstant.AND).append(InfluxDBPublicParam.LINE_ID).append(InfluxDBSqlConstant.EQ).append(InfluxDBSqlConstant.QM).append(id).append(InfluxDBSqlConstant.QM)
|
||||
.append(InfluxDBSqlConstant.AND).append(InfluxDBPublicParam.VALUE_TYPE).append(InfluxDBSqlConstant.EQ).append(InfluxDBSqlConstant.QM).append(InfluxDBTableConstant.AVG).append(InfluxDBSqlConstant.QM);
|
||||
if (InfluxDBTableConstant.PHASE_TYPE_T.equals(type)){
|
||||
stringBuilder.append(InfluxDBSqlConstant.AND).append(InfluxDBPublicParam.PHASIC_TYPE).append(InfluxDBSqlConstant.EQ).append(InfluxDBSqlConstant.QM).append(InfluxDBTableConstant.PHASE_TYPE_T).append(InfluxDBSqlConstant.QM);
|
||||
}else{
|
||||
stringBuilder.append(InfluxDBSqlConstant.AND).append(InfluxDBPublicParam.PHASIC_TYPE).append(InfluxDBSqlConstant.EQ).append(InfluxDBSqlConstant.QM).append(InfluxDBTableConstant.PHASE_TYPE_A).append(InfluxDBSqlConstant.QM);
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
}
|
||||
@@ -1,192 +0,0 @@
|
||||
package com.njcn.harmonic.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.device.pq.api.LineFeignClient;
|
||||
import com.njcn.device.pq.pojo.vo.LineDetailDataVO;
|
||||
import com.njcn.harmonic.enums.HarmonicResponseEnum;
|
||||
import com.njcn.harmonic.mapper.RMpIntegrityDMapper;
|
||||
import com.njcn.harmonic.pojo.param.AlgorithmSearchParam;
|
||||
import com.njcn.harmonic.pojo.po.RMpIntegrityD;
|
||||
import com.njcn.harmonic.service.DataIntegrityRateService;
|
||||
import com.njcn.influxdb.config.InfluxDbConfig;
|
||||
import com.njcn.influxdb.param.InfluxDBPublicParam;
|
||||
import com.njcn.influxdb.param.InfluxDBSqlConstant;
|
||||
import com.njcn.influxdb.param.InfluxDBTableConstant;
|
||||
import com.njcn.influxdb.utils.InfluxDbUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.influxdb.dto.QueryResult;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 数据完整率算法
|
||||
*
|
||||
* @author qijian
|
||||
* @version 1.0.0
|
||||
* @createTime 2022/10/26 - 10:09
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class DataIntegrityRateServiceImpl implements DataIntegrityRateService {
|
||||
|
||||
private final InfluxDbUtils influxDbUtils;
|
||||
|
||||
private final RMpIntegrityDMapper rMpIntegrityDMapper;
|
||||
|
||||
private final LineFeignClient lineFeignClient;
|
||||
|
||||
@Resource
|
||||
private InfluxDbConfig influxDbConfig;
|
||||
|
||||
/**
|
||||
* 监测点日数据完整率
|
||||
* @author qijian
|
||||
* @date 2022/10/26
|
||||
*/
|
||||
@Override
|
||||
public boolean lineDataIntegrityRate(AlgorithmSearchParam algorithmSearchParam) {
|
||||
//测试
|
||||
// InfluxDbUtils influxDBUtil = new InfluxDbUtils("admin", "njcnpqs", "http://192.168.1.18:8086", "pqsbase", "");
|
||||
//初始化
|
||||
String searchSql;
|
||||
String tableName;
|
||||
String sql;
|
||||
QueryResult query;
|
||||
QueryResult.Series series;
|
||||
List<String> columns;
|
||||
List<List<Object>> values;
|
||||
RMpIntegrityD rMpIntegrityD = new RMpIntegrityD();
|
||||
Date date = DateUtil.parse(algorithmSearchParam.getDatadate());
|
||||
|
||||
//1、有效接入分钟数量:根据监测点编号获取统计间隔,1440 / 统计间隔 = 有效接入分钟数量
|
||||
List<String> lineIds = new ArrayList<>();
|
||||
lineIds.add(algorithmSearchParam.getId());
|
||||
List<LineDetailDataVO> lineDetailList = lineFeignClient.getLineDetailList(lineIds).getData();
|
||||
if (lineDetailList.size() == 0){
|
||||
throw new BusinessException(HarmonicResponseEnum.ALGORITHM_LINE_EMPTY);
|
||||
}
|
||||
Integer effectiveMinuteCount = 1440 / lineDetailList.get(0).getTimeInterval();
|
||||
rMpIntegrityD.setEffectiveMinuteCount(effectiveMinuteCount);
|
||||
|
||||
//2、根据data_v表获取五项稳态指标日数量(count)
|
||||
searchSql = "count(freq) as freqCount,count(rms) as phaseVoltageCount,count(rms_lvr) as lineVoltageCount,count(v_thd) as vThdCount,count(v_unbalance) as unbalanceCount ";
|
||||
tableName = InfluxDBPublicParam.DATA_V;
|
||||
sql = getAppend(algorithmSearchParam.getId(), date, searchSql, tableName);
|
||||
query = influxDbUtils.query(sql);
|
||||
series = getSeries(query);
|
||||
|
||||
if (Objects.nonNull(series.getColumns())){
|
||||
columns = series.getColumns();
|
||||
values = series.getValues();
|
||||
for (List<Object> columnValue : values) {
|
||||
for (int i = 0; i < columnValue.size(); i++) {
|
||||
if (columns.get(i).equals("freqCount")) {
|
||||
rMpIntegrityD.setFreqCount(Integer.parseInt(convertDoubleToString(columnValue.get(i))));
|
||||
}else if (columns.get(i).equals("phaseVoltageCount")) {
|
||||
rMpIntegrityD.setPhaseVoltageCount(Integer.parseInt(convertDoubleToString(columnValue.get(i))));
|
||||
}else if (columns.get(i).equals("lineVoltageCount")) {
|
||||
rMpIntegrityD.setLineVoltageCount(Integer.parseInt(convertDoubleToString(columnValue.get(i))));
|
||||
}else if (columns.get(i).equals("vThdCount")) {
|
||||
rMpIntegrityD.setVThdCount(Integer.parseInt(convertDoubleToString(columnValue.get(i))));
|
||||
}else if (columns.get(i).equals("unbalanceCount")) {
|
||||
rMpIntegrityD.setUnbalanceCount(Integer.parseInt(convertDoubleToString(columnValue.get(i))));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//3、根据day_flicker表获取两项闪变指标数量(count)
|
||||
searchSql = "count(pst) as pstCount,count(plt) as pltCount ";
|
||||
tableName = InfluxDBPublicParam.DATA_FLICKER;
|
||||
sql = getAppend(algorithmSearchParam.getId(), date, searchSql, tableName);
|
||||
query = influxDbUtils.query(sql);
|
||||
series = getSeries(query);
|
||||
|
||||
if (Objects.nonNull(series.getColumns())){
|
||||
columns = series.getColumns();
|
||||
values = series.getValues();
|
||||
for (List<Object> columnValue : values) {
|
||||
for (int i = 0; i < columnValue.size(); i++) {
|
||||
if (columns.get(i).equals("pstCount")) {
|
||||
rMpIntegrityD.setPstCount(Integer.parseInt(convertDoubleToString(columnValue.get(i))));
|
||||
}else if (columns.get(i).equals("pltCount")) {
|
||||
rMpIntegrityD.setPltCount(Integer.parseInt(convertDoubleToString(columnValue.get(i))));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//4、存库
|
||||
LambdaQueryWrapper<RMpIntegrityD> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(RMpIntegrityD::getMeasurementPointId, algorithmSearchParam.getId()).eq(RMpIntegrityD::getDataDate, date);
|
||||
RMpIntegrityD rMpIntegrityDOne = rMpIntegrityDMapper.selectOne(lambdaQueryWrapper);
|
||||
if (Objects.nonNull(rMpIntegrityDOne)){
|
||||
rMpIntegrityDMapper.update(rMpIntegrityD,lambdaQueryWrapper);
|
||||
}else{
|
||||
rMpIntegrityD.setMeasurementPointId(algorithmSearchParam.getId());
|
||||
rMpIntegrityD.setDataDate(date);
|
||||
rMpIntegrityDMapper.insert(rMpIntegrityD);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Double转String
|
||||
* @param val 参数
|
||||
* @return 结果
|
||||
*/
|
||||
private String convertDoubleToString(Object val) {
|
||||
DecimalFormat decimalFormat = new DecimalFormat("###################.###########");
|
||||
return decimalFormat.format(val);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取series
|
||||
* @param query 参数
|
||||
* @return 结果
|
||||
*/
|
||||
private QueryResult.Series getSeries(QueryResult query) {
|
||||
QueryResult.Series series = new QueryResult.Series();
|
||||
List<QueryResult.Result> results = query.getResults();
|
||||
if (results.size() != 0) {
|
||||
QueryResult.Result result = results.get(0);
|
||||
if (result.getSeries() != null){
|
||||
List<QueryResult.Series> seriess = result.getSeries();
|
||||
if (seriess.size() != 0) {
|
||||
series = seriess.get(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
return series;
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼装sql
|
||||
* @param id,date,searchSql,tableName 参数
|
||||
* @return 结果
|
||||
*/
|
||||
private String getAppend(String id, Date date, String searchSql,String tableName) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append(InfluxDBSqlConstant.SELECT).append(searchSql)
|
||||
.append(InfluxDBSqlConstant.FROM).append(tableName)
|
||||
.append(InfluxDBSqlConstant.WHERE).append(InfluxDBPublicParam.TIME).append(InfluxDBSqlConstant.GE).append(InfluxDBSqlConstant.QM).append(DateUtil.beginOfDay(date)).append(InfluxDBSqlConstant.QM)
|
||||
.append(InfluxDBSqlConstant.AND).append(InfluxDBPublicParam.TIME).append(InfluxDBSqlConstant.LE).append(InfluxDBSqlConstant.QM).append(DateUtil.endOfDay(date)).append(InfluxDBSqlConstant.QM)
|
||||
.append(InfluxDBSqlConstant.AND).append(InfluxDBPublicParam.LINE_ID).append(InfluxDBSqlConstant.EQ).append(InfluxDBSqlConstant.QM).append(id).append(InfluxDBSqlConstant.QM)
|
||||
.append(InfluxDBSqlConstant.AND).append(InfluxDBPublicParam.PHASIC_TYPE).append(InfluxDBSqlConstant.EQ).append(InfluxDBSqlConstant.QM).append(InfluxDBTableConstant.PHASE_TYPE_A).append(InfluxDBSqlConstant.QM);
|
||||
if (InfluxDBPublicParam.DATA_V.equals(tableName)){
|
||||
stringBuilder.append(InfluxDBSqlConstant.AND).append(InfluxDBPublicParam.VALUE_TYPE).append(InfluxDBSqlConstant.EQ).append(InfluxDBSqlConstant.QM).append(InfluxDBTableConstant.AVG).append(InfluxDBSqlConstant.QM);
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
}
|
||||
@@ -8,21 +8,27 @@ import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.device.pq.api.GeneralDeviceInfoClient;
|
||||
import com.njcn.device.pq.api.LineFeignClient;
|
||||
import com.njcn.device.pq.api.SubstationFeignClient;
|
||||
import com.njcn.device.pq.pojo.dto.GeneralDeviceDTO;
|
||||
import com.njcn.device.pq.pojo.dto.PollutionSubstationDTO;
|
||||
import com.njcn.device.pq.pojo.dto.SubstationDTO;
|
||||
import com.njcn.device.pq.pojo.dto.*;
|
||||
import com.njcn.harmonic.mapper.RMpPollutionDPOMapper;
|
||||
import com.njcn.harmonic.mapper.RStatPollutionOrgMPOMapper;
|
||||
import com.njcn.harmonic.mapper.RStatPollutionSubstationMMapper;
|
||||
import com.njcn.harmonic.pojo.param.HarmonicPublicParam;
|
||||
import com.njcn.harmonic.pojo.param.PollutionSubstationQuryParam;
|
||||
import com.njcn.harmonic.pojo.po.RMpPollutionDPO;
|
||||
import com.njcn.harmonic.pojo.po.RStatPollutionOrgMPO;
|
||||
import com.njcn.harmonic.pojo.po.RStatPollutionSubstationM;
|
||||
import com.njcn.harmonic.pojo.vo.PollutionSubstationVO;
|
||||
import com.njcn.harmonic.pojo.vo.PollutionVO;
|
||||
import com.njcn.harmonic.service.PollutionSubstationService;
|
||||
import com.njcn.web.utils.RequestUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -52,6 +58,8 @@ public class PollutionSubstationServiceImpl extends ServiceImpl<RStatPollutionSu
|
||||
private final GeneralInfo generalInfo;
|
||||
|
||||
|
||||
private final RStatPollutionOrgMPOMapper rStatPollutionOrgMPOMapper;
|
||||
private final RMpPollutionDPOMapper rMpPollutionDPOMapper;
|
||||
/**
|
||||
* @param pollutionSubstationQuryParam
|
||||
* @Description: getPollutionSubstationData
|
||||
@@ -122,4 +130,154 @@ public class PollutionSubstationServiceImpl extends ServiceImpl<RStatPollutionSu
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description: getDeptSubstationRelations
|
||||
* @Param: [param]
|
||||
* @return: java.util.List<com.njcn.harmonic.pojo.vo.PollutionVO>
|
||||
* @Author: clam
|
||||
* @Date: 2022/11/3
|
||||
*/
|
||||
@Override
|
||||
public List<PollutionVO> getDeptSubstationRelations(HarmonicPublicParam harmonicPublicParam) {
|
||||
harmonicPublicParam.setServerName(generalInfo.getMicroServiceName());
|
||||
List<PollutionVO> list = new ArrayList<>();
|
||||
List<String> lineList = new ArrayList<>();
|
||||
List<PollutionLineDTO> lineInfo = new ArrayList<>();
|
||||
PollutionParamDTO paramDTO = new PollutionParamDTO();
|
||||
|
||||
String pollutionType = harmonicPublicParam.getStatisticalType ( ).getCode ( );
|
||||
|
||||
String searchBeginTime = harmonicPublicParam.getSearchBeginTime ( ).substring (0,7);
|
||||
if (StringUtils.isBlank(RequestUtil.getDeptIndex())){
|
||||
return list;
|
||||
}
|
||||
List<GeneralDeviceDTO> sub = generalDeviceInfoClient.getPracticalRunDeviceInfo(harmonicPublicParam).getData();
|
||||
sub.forEach (temp ->{
|
||||
PollutionVO pollutionVO = new PollutionVO ();
|
||||
String detpid = temp.getIndex ();
|
||||
String name =temp.getName ();
|
||||
List<String> subIndexes = temp.getSubIndexes ( );
|
||||
pollutionVO.setId (detpid);
|
||||
pollutionVO.setName (name);
|
||||
pollutionVO.setData (-1.0);
|
||||
QueryWrapper<RStatPollutionOrgMPO> rStatPollutionOrgMPOQueryWrapper = new QueryWrapper<> ();
|
||||
rStatPollutionOrgMPOQueryWrapper.eq ("org_id", detpid).
|
||||
eq ("pollution_type", pollutionType).
|
||||
apply("DATE_FORMAT( data_date ,'%Y-%m') = '"+searchBeginTime+"'");
|
||||
RStatPollutionOrgMPO rStatPollutionOrgMPO = rStatPollutionOrgMPOMapper.selectOne (rStatPollutionOrgMPOQueryWrapper);
|
||||
;
|
||||
|
||||
Optional.ofNullable (rStatPollutionOrgMPO).ifPresent (a->pollutionVO.setData (a.getValue ()));
|
||||
|
||||
List<PollutionVO> subPollutionVO = new ArrayList<>();
|
||||
subIndexes.forEach (subIndex->{
|
||||
PollutionVO pollutionsubVO = new PollutionVO ();
|
||||
PollutionSubstationDTO pollutionSubstationDTO = lineFeignClient.getSubstationInfo(subIndex).getData();
|
||||
String id = pollutionSubstationDTO.getId ( );
|
||||
pollutionsubVO.setId (id);
|
||||
pollutionsubVO.setName ( pollutionSubstationDTO.getName ());
|
||||
pollutionsubVO.setPid (temp.getIndex ());
|
||||
pollutionsubVO.setData (-1.0);
|
||||
QueryWrapper<RStatPollutionSubstationM> wrapper = new QueryWrapper<> ();
|
||||
wrapper.eq ("substation_id",id).
|
||||
eq ("pollution_type", pollutionType).
|
||||
apply("DATE_FORMAT( data_date ,'%Y-%m') = '"+searchBeginTime+"'");
|
||||
RStatPollutionSubstationM rStatPollutionSubstationM = pollutionSubstationMMapper.selectOne (wrapper);
|
||||
|
||||
Optional.ofNullable (rStatPollutionSubstationM).ifPresent (t->pollutionsubVO.setData (t.getValue ()));
|
||||
subPollutionVO.add (pollutionsubVO) ;
|
||||
});
|
||||
pollutionVO.setChildren (subPollutionVO);
|
||||
|
||||
list.add (pollutionVO);
|
||||
});
|
||||
|
||||
if (!CollectionUtils.isEmpty(list)){
|
||||
return list.stream().sorted(Comparator.comparing(PollutionVO::getData).reversed().thenComparing(PollutionVO::getName)).collect(Collectors.toList());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description: getSubstationInfoById
|
||||
* @Param: [param]
|
||||
* @return: java.util.List<com.njcn.device.pq.pojo.dto.PollutionSubstationDTO>
|
||||
* @Author: clam
|
||||
* @Date: 2022/11/3
|
||||
*/
|
||||
@Override
|
||||
public List<PollutionSubstationDTO> getSubstationInfoById(HarmonicPublicParam deptParam) {
|
||||
deptParam.setServerName(generalInfo.getMicroServiceName());
|
||||
List<PollutionSubstationDTO> list = new ArrayList<>();
|
||||
List<GeneralDeviceDTO> sub = generalDeviceInfoClient.getPracticalRunDeviceInfoAsSubstation(deptParam).getData();
|
||||
|
||||
String pollutionType = deptParam.getStatisticalType ( ).getCode ( );
|
||||
SimpleDateFormat s = new SimpleDateFormat();
|
||||
String searchBeginTime = deptParam.getSearchBeginTime ( ).substring (0,7);
|
||||
sub.forEach(item->{
|
||||
PollutionSubstationDTO pollutionSubstationDTO = lineFeignClient.getSubstationInfo(item.getIndex()).getData();
|
||||
|
||||
QueryWrapper<RStatPollutionSubstationM> wrapper = new QueryWrapper<> ();
|
||||
wrapper.eq ("substation_id",pollutionSubstationDTO.getId ()).
|
||||
eq ("pollution_type", pollutionType).
|
||||
apply("DATE_FORMAT( data_date ,'%Y-%m') = '"+searchBeginTime+"'");
|
||||
RStatPollutionSubstationM rStatPollutionSubstationM = pollutionSubstationMMapper.selectOne (wrapper);
|
||||
|
||||
Optional.ofNullable (rStatPollutionSubstationM).ifPresent (t->pollutionSubstationDTO.setData (t.getValue ()));
|
||||
|
||||
list.add(pollutionSubstationDTO);
|
||||
});
|
||||
if (!CollectionUtils.isEmpty(list)){
|
||||
return list.stream().sorted(Comparator.comparing(PollutionSubstationDTO::getData).reversed().thenComparing(PollutionSubstationDTO::getName)).collect(Collectors.toList());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description: getLineInfoById
|
||||
* @Param: [param]
|
||||
* @return: java.util.List<com.njcn.device.pq.pojo.dto.PollutionLineDTO>
|
||||
* @Author: clam
|
||||
* @Date: 2022/11/3
|
||||
*/
|
||||
@Override
|
||||
public List<PollutionLineDTO> getLineInfoById(HarmonicPublicParam harmonicPublicParam) {
|
||||
harmonicPublicParam.setServerName(generalInfo.getMicroServiceName());
|
||||
List<PollutionLineDTO> list = new ArrayList<>();
|
||||
List<String> line = new ArrayList<>();
|
||||
|
||||
|
||||
String pollutionType = harmonicPublicParam.getStatisticalType ( ).getCode ( );
|
||||
|
||||
String searchBeginTime = harmonicPublicParam.getSearchBeginTime ( ).substring (0,7);
|
||||
PollutionParamDTO paramDTO = new PollutionParamDTO();
|
||||
if (StringUtils.isBlank(RequestUtil.getDeptIndex())){
|
||||
return list;
|
||||
}
|
||||
List<GeneralDeviceDTO> sub = generalDeviceInfoClient.getPracticalRunDeviceInfoAsSubstation(harmonicPublicParam).getData();
|
||||
sub.forEach(item->{
|
||||
if (Objects.equals(harmonicPublicParam.getId(),item.getIndex())){
|
||||
if (!CollectionUtils.isEmpty(item.getLineIndexes())){
|
||||
line.addAll(item.getLineIndexes());
|
||||
}
|
||||
}
|
||||
});
|
||||
if (!CollectionUtils.isEmpty(line)){
|
||||
paramDTO.setLineList(line);
|
||||
list = lineFeignClient.getLineInfo(paramDTO).getData();
|
||||
|
||||
List<RMpPollutionDPO> lineData = rMpPollutionDPOMapper.selectMaxList ( line,pollutionType,searchBeginTime);
|
||||
if (!CollectionUtils.isEmpty(lineData)){
|
||||
list.stream().map(list1->lineData.stream().filter(list2-> Objects.equals(list1.getId(),list2.getLineId ())).findAny().map(m->{
|
||||
/*todo 根据 pollutionType映射lineData取哪个字段目前先取一个值测试 */
|
||||
list1.setData(m.getVDev ());
|
||||
return list1;
|
||||
})).collect(Collectors.toList());
|
||||
}
|
||||
} else {
|
||||
return list;
|
||||
}
|
||||
return list.stream().sorted(Comparator.comparing(PollutionLineDTO::getData).reversed().thenComparing(PollutionLineDTO::getName)).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -66,19 +66,17 @@
|
||||
<artifactId>harmonic-prepare</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>harmonic-prepare</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<scope>compile</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>common-swagger</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.njcn</groupId>-->
|
||||
<!-- <artifactId>harmonic-prepare</artifactId>-->
|
||||
<!-- <version>1.0.0</version>-->
|
||||
<!-- <exclusions>-->
|
||||
<!-- <exclusion>-->
|
||||
<!-- <groupId>com.njcn</groupId>-->
|
||||
<!-- <artifactId>common-swagger</artifactId>-->
|
||||
<!-- </exclusion>-->
|
||||
<!-- </exclusions>-->
|
||||
<!-- </dependency>-->
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -3,6 +3,10 @@ microservice:
|
||||
ename: @artifactId@
|
||||
name: '@name@'
|
||||
version: @version@
|
||||
sentinel:
|
||||
url: @sentinel.url@
|
||||
gateway:
|
||||
url: @gateway.url@
|
||||
server:
|
||||
port: 10218
|
||||
#feign接口开启服务熔断降级处理
|
||||
|
||||
@@ -99,6 +99,12 @@
|
||||
<version>${org.projectlombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>common-minio</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -35,8 +35,8 @@ public class CoustomReportFeignClientFallbackFactory implements FallbackFactory<
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new CoustmReportFeignClient() {
|
||||
@Override
|
||||
public HttpResult<Boolean> batchReport(LineParam reportParam){
|
||||
log.error("{}异常,降级处理,异常为:{}", "自定义报表预处理任务: ", throwable.toString());
|
||||
public HttpResult<Boolean> batchReport(@RequestBody LineParam reportParam){
|
||||
log.error("{}异常,降级处理,异常为:{}", "Date数据转Day数据: ", throwable.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -33,7 +33,7 @@ public class DayDataFeignClientFallbackFactory implements FallbackFactory<DayDat
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new DayDataFeignClient() {
|
||||
@Override
|
||||
public HttpResult<Boolean> dayDataHanlder(LineParam jobParam){
|
||||
public HttpResult<Boolean> dayDataHanlder(@RequestBody LineParam jobParam){
|
||||
log.error("{}异常,降级处理,异常为:{}", "Date数据转Day数据: ", throwable.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@ public class IntegrityFeignClientFallbackFactory implements FallbackFactory<Inte
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new IntegrityFeignClient() {
|
||||
@Override
|
||||
public HttpResult<String> computeDataIntegrity(LineParam lineParam) {
|
||||
log.error("{}异常,降级处理,异常为:{}", "数据完整性预处理: ", throwable.toString());
|
||||
public HttpResult<String> computeDataIntegrity(@RequestBody @Validated LineParam lineParam) {
|
||||
log.error("{}异常,降级处理,异常为:{}", "数据完整性处理: ", throwable.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -34,8 +34,8 @@ public class LimitTargetFeignClientFallbackFactory implements FallbackFactory<Li
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new LimitTargetFeignClient() {
|
||||
@Override
|
||||
public HttpResult<String> getLimitTargetData(LineParam lineParam) {
|
||||
log.error("{}异常,降级处理,异常为:{}", "越限次数数据预处理: ", throwable.toString());
|
||||
public HttpResult<String> getLimitTargetData(@RequestBody @Validated LineParam lineParam) {
|
||||
log.error("{}异常,降级处理,异常为:{}", "越限数据: ", throwable.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -33,8 +33,8 @@ public class LimitrateFeignClientFallbackFactory implements FallbackFactory<Limi
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new LimitrateFeignClient() {
|
||||
@Override
|
||||
public HttpResult<Boolean> limitRateHanlder(LineParam limitRateHanlderParam ){
|
||||
log.error("{}异常,降级处理,异常为:{}", "越限是否数据预处理: ", throwable.toString());
|
||||
public HttpResult<Boolean> limitRateHanlder(@RequestBody LineParam limitRateHanlderParam ){
|
||||
log.error("{}异常,降级处理,异常为:{}", "越限数据处理: ", throwable.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -28,7 +28,7 @@ public class NormalFeignClientFallbackFactory implements FallbackFactory<NormalL
|
||||
return new NormalLimitFeignClient() {
|
||||
@Override
|
||||
public HttpResult<String> getNormLimitData() {
|
||||
log.error("{}异常,降级处理,异常为:{}", "告警数据预处理: ", throwable.toString());
|
||||
log.error("{}异常,降级处理,异常为:{}", "告警数据: ", throwable.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -30,8 +30,8 @@ public class OnlineRateFeignClientFallbackFactory implements FallbackFactory<Onl
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new OnlineRateFeignClient() {
|
||||
@Override
|
||||
public HttpResult<String> getOnlineRateData(LineParam lineParam){
|
||||
log.error("{}异常,降级处理,异常为:{}", "在线率数据预处理: ", throwable.toString());
|
||||
public HttpResult<String> getOnlineRateData(@RequestBody @Validated LineParam lineParam){
|
||||
log.error("{}异常,降级处理,异常为:{}", "在线率: ", throwable.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -31,8 +31,8 @@ public class PollutionFeignClientFallbackFactory implements FallbackFactory<Poll
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new PollutionFeignClient() {
|
||||
@Override
|
||||
public HttpResult<String> processPollutionData(LineParam lineParam){
|
||||
log.error("{}异常,降级处理,异常为:{}", "污区数据预处理: ", throwable.toString());
|
||||
public HttpResult<String> processPollutionData(@RequestBody @Validated LineParam lineParam){
|
||||
log.error("{}异常,降级处理,异常为:{}", "污区数据: ", throwable.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.device.pq.api.LineFeignClient;
|
||||
import com.njcn.prepare.harmonic.pojo.param.LimitRateHanlderParam;
|
||||
import com.njcn.prepare.harmonic.pojo.param.LineParam;
|
||||
import com.njcn.prepare.harmonic.service.line.DayDataService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -20,6 +20,7 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -47,7 +48,8 @@ public class DayDataController extends BaseController {
|
||||
@ApiImplicitParam(value = "jobParam",name = "jobParam",required = true)
|
||||
@PostMapping("dayDataHanlder")
|
||||
@OperateInfo(info = LogEnum.BUSINESS_MEDIUM)
|
||||
public HttpResult<Boolean> dayDataHanlder(@RequestBody LimitRateHanlderParam jobParam ){
|
||||
public HttpResult<Boolean> dayDataHanlder(@RequestBody LineParam jobParam ){
|
||||
log.info(LocalDateTime.now()+"dayDataHanlder开始执行");
|
||||
String methodDescribe = getMethodDescribe("dayDataHanlder");
|
||||
Boolean result = true;
|
||||
List<String> indexLists = new ArrayList<> ();
|
||||
@@ -56,9 +58,10 @@ public class DayDataController extends BaseController {
|
||||
}else{
|
||||
indexLists = jobParam.getLineIds ();
|
||||
}
|
||||
String startTime = jobParam.getDataDate ()+" "+"00:00:00";
|
||||
String endTime = jobParam.getDataDate ()+" "+"23:59:59";
|
||||
|
||||
|
||||
dayDataService.dayDataJobHandler (indexLists,jobParam.getStartTime (),jobParam.getEndTime ());
|
||||
dayDataService.dayDataJobHandler (indexLists,startTime,endTime);
|
||||
if (result){
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||
} else {
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.device.pq.api.LineFeignClient;
|
||||
import com.njcn.prepare.harmonic.pojo.param.LimitRateHanlderParam;
|
||||
import com.njcn.prepare.harmonic.pojo.param.LineParam;
|
||||
import com.njcn.prepare.harmonic.service.Impl.line.LimitRateService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -48,7 +48,7 @@ public class LimitrateController extends BaseController {
|
||||
@ApiImplicitParam(value = "limitRateHanlderParam",name = "limitRateHanlderParam",required = true)
|
||||
@PostMapping("LimitRateHanlder")
|
||||
@OperateInfo(info = LogEnum.BUSINESS_MEDIUM)
|
||||
public HttpResult<Boolean> limitRateHanlder(@RequestBody LimitRateHanlderParam limitRateHanlderParam ){
|
||||
public HttpResult<Boolean> limitRateHanlder(@RequestBody LineParam limitRateHanlderParam ){
|
||||
String methodDescribe = getMethodDescribe("limitRateHanlder");
|
||||
Boolean result = true;
|
||||
List<String> indexLists = new ArrayList<> ();
|
||||
@@ -57,9 +57,10 @@ public class LimitrateController extends BaseController {
|
||||
}else{
|
||||
indexLists = limitRateHanlderParam.getLineIds ();
|
||||
}
|
||||
String startTime = limitRateHanlderParam.getDataDate ()+" "+"00:00:00";
|
||||
String endTime = limitRateHanlderParam.getDataDate ()+" "+"23:59:59";
|
||||
|
||||
|
||||
limitRateService.limitRateJobHandler (indexLists,limitRateHanlderParam.getStartTime (),limitRateHanlderParam.getEndTime ());
|
||||
limitRateService.limitRateJobHandler (indexLists,startTime,endTime);
|
||||
if (result){
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||
} else {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.njcn.prepare.harmonic.mapper.line.ExcelRptTempMapper">
|
||||
|
||||
<select id="getActiveTempList" resultType="com.njcn.prepare.harmonic.pojo.po.ExcelRptTemp">
|
||||
<select id="getActiveTempList" resultType="ExcelRptTemp">
|
||||
SELECT
|
||||
DISTINCT t1.*
|
||||
FROM
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.time.Instant;
|
||||
* @createTime 2022/10/21 13:45
|
||||
*/
|
||||
@Data
|
||||
@Measurement(name = "data_polluction")
|
||||
@Measurement(name = "harmonic_pollution")
|
||||
public class DataPolluctionPO {
|
||||
|
||||
@Column(name = "line_id")
|
||||
|
||||
@@ -22,6 +22,9 @@ public class PqsCommunicatePO {
|
||||
@Column(name = "line_id")
|
||||
private String lineId;
|
||||
|
||||
@Column(name = "dev_id")
|
||||
private String devId;
|
||||
|
||||
@Column(name = "type")
|
||||
private Integer type;
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ public class OnlineRateServiceImpl implements OnlineRateService {
|
||||
* 获取pqs_communicate数据
|
||||
*/
|
||||
private List<PqsCommunicatePO> getCommunicateData(String lineId){
|
||||
QueryResult sqlResult = influxDbUtils.query("SELECT * FROM pqs_communicate where line_id = '" + lineId +"' order by time desc limit 1 tz('Asia/Shanghai')");
|
||||
QueryResult sqlResult = influxDbUtils.query("SELECT * FROM pqs_communicate where dev_id = '" + lineId +"' order by time desc limit 1 tz('Asia/Shanghai')");
|
||||
InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
|
||||
return resultMapper.toPOJO(sqlResult, PqsCommunicatePO.class);
|
||||
}
|
||||
@@ -86,7 +86,7 @@ public class OnlineRateServiceImpl implements OnlineRateService {
|
||||
* 获取范围时间内的pqs_communicate数据
|
||||
*/
|
||||
private List<PqsCommunicatePO> getCommunicateData(String lineId, String date){
|
||||
QueryResult sqlResult = influxDbUtils.query("SELECT * FROM pqs_communicate where time >= '" + date + " 00:00:00' and time <= '" + date + " 23:59:59' and line_id = '" + lineId +"' order by time asc tz('Asia/Shanghai')");
|
||||
QueryResult sqlResult = influxDbUtils.query("SELECT * FROM pqs_communicate where time >= '" + date + " 00:00:00' and time <= '" + date + " 23:59:59' and dev_id = '" + lineId +"' order by time asc tz('Asia/Shanghai')");
|
||||
InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
|
||||
return resultMapper.toPOJO(sqlResult, PqsCommunicatePO.class);
|
||||
}
|
||||
|
||||
@@ -106,14 +106,14 @@ public class PollutionServiceImpl implements PollutionService {
|
||||
pollutionList = processPollutionList(lineIdList,harmonicVoltageList,harmonicCurrentList,frequencyDeviationList,voltageDeviationList,threePhaseVoltageList,negativeSequenceList,interharmonicVoltageList,voltageFlickerList);
|
||||
|
||||
Date dateOut = new Date();
|
||||
//入表data_polluction
|
||||
//入表harmonic_pollution
|
||||
if (StrUtil.isNotBlank(lineParam.getDataDate())){
|
||||
dateOut = DateUtil.parse(lineParam.getDataDate());
|
||||
}
|
||||
insertPolluction(pollutionList,dateOut.getTime());
|
||||
LogUtil.njcnDebug(log, "监测点污染指标数据data_polluction插入耗时:{}", timer.intervalRestart());
|
||||
LogUtil.njcnDebug(log, "监测点污染指标数据harmonic_pollution插入耗时:{}", timer.intervalRestart());
|
||||
}else {
|
||||
//获取data_polluction数据
|
||||
//获取harmonic_pollution数据
|
||||
pollutionList = getDataPolluction(lineParam);
|
||||
}
|
||||
//MySql入表污区图表等
|
||||
@@ -153,7 +153,7 @@ public class PollutionServiceImpl implements PollutionService {
|
||||
List<PollutionDTO> pollutionDTOList = new ArrayList<>();
|
||||
InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
|
||||
for (String lineId : lineList){
|
||||
String sql="SELECT * FROM data_polluction where line_id = '" + lineId +"' "+processDate(lineParam.getDataDate(),lineParam.getType());
|
||||
String sql="SELECT * FROM harmonic_pollution where line_id = '" + lineId +"' "+processDate(lineParam.getDataDate(),lineParam.getType());
|
||||
QueryResult dataPolluctionResult = influxDbUtils.query(sql);
|
||||
List<DataPolluctionPO> threePhaseList = resultMapper.toPOJO(dataPolluctionResult, DataPolluctionPO.class);
|
||||
for (DataPolluctionPO dataPolluction : threePhaseList){
|
||||
@@ -624,7 +624,7 @@ public class PollutionServiceImpl implements PollutionService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 监测点污染指标数据入表 data_polluction
|
||||
* 监测点污染指标数据入表 harmonic_pollution
|
||||
*/
|
||||
private void insertPolluction(List<PollutionDTO> list, long time){
|
||||
List<String> records = new ArrayList<String>();
|
||||
@@ -640,7 +640,7 @@ public class PollutionServiceImpl implements PollutionService {
|
||||
fields.put("i_all",item.getIAll());
|
||||
fields.put("v_inharm",item.getVInharm());
|
||||
fields.put("plt",item.getPlt());
|
||||
Point point = influxDbUtils.pointBuilder("data_polluction", time, TimeUnit.MILLISECONDS,tags, fields);
|
||||
Point point = influxDbUtils.pointBuilder("harmonic_pollution", time, TimeUnit.MILLISECONDS,tags, fields);
|
||||
BatchPoints batchPoints = BatchPoints.database(influxDbUtils.getDbName()).tag("line_id", item.getLineId()).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
|
||||
batchPoints.point(point);
|
||||
records.add(batchPoints.lineProtocol());
|
||||
|
||||
@@ -7,6 +7,7 @@ import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.cloud.commons.lang.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.njcn.common.config.GeneralInfo;
|
||||
import com.njcn.common.pojo.constant.BizParamConstant;
|
||||
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
@@ -16,6 +17,9 @@ import com.njcn.harmonic.pojo.dto.ReportTemplateDTO;
|
||||
import com.njcn.influxdb.param.InfluxDBSqlConstant;
|
||||
import com.njcn.influxdb.param.InfluxDBTableConstant;
|
||||
import com.njcn.influxdb.utils.InfluxDbUtils;
|
||||
import com.njcn.minio.bo.MinIoUploadResDTO;
|
||||
import com.njcn.minio.config.MinIoProperties;
|
||||
import com.njcn.minio.utils.MinIoUtils;
|
||||
import com.njcn.prepare.harmonic.constant.Param;
|
||||
import com.njcn.prepare.harmonic.mapper.line.ExcelRptMapper;
|
||||
import com.njcn.prepare.harmonic.mapper.line.ExcelRptTempMapper;
|
||||
@@ -25,9 +29,18 @@ import com.njcn.prepare.harmonic.pojo.po.ExcelRptTemp;
|
||||
import com.njcn.prepare.harmonic.service.line.ReportService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.fileupload.FileItem;
|
||||
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.influxdb.dto.QueryResult;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -49,6 +62,14 @@ public class ReportServiceImpl implements ReportService {
|
||||
|
||||
private final ExcelRptMapper excelRptMapper;
|
||||
|
||||
private final GeneralInfo generalInfo;
|
||||
|
||||
@Resource
|
||||
private MinIoUtils minIoUtils;
|
||||
|
||||
@Resource
|
||||
private MinIoProperties minIoProperties;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean batchReport(LineParam reportParam) {
|
||||
@@ -77,7 +98,8 @@ public class ReportServiceImpl implements ReportService {
|
||||
for (ExcelRptTemp excelRptTemp : reportTemplateList) {
|
||||
try {
|
||||
//获取content解析数据
|
||||
jsonArray = JSONUtil.parseArray(excelRptTemp.getContent());
|
||||
String objectUrl = minIoUtils.getObjectUrl(minIoProperties.getBucket(), excelRptTemp.getContent(), 7 * 24 * 60 * 60);
|
||||
jsonArray = JSONUtil.parseArray(urlToString(objectUrl));
|
||||
dataList = getDataList(jsonArray);
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException(HarmonicResponseEnum.CUSTOM_REPORT_JSON);
|
||||
@@ -120,7 +142,9 @@ public class ReportServiceImpl implements ReportService {
|
||||
//月:例如2022十月份,传入2022-10-01进行匹配,有则更新无则插入
|
||||
//周:例如2022年第五周,传入2022-01-23(周一)进行匹配,有则更新无则插入
|
||||
//日:直接插入,无需配对
|
||||
String afterContent = jsonArray.toString();
|
||||
//文件上传到Minio服务器,存入文件名
|
||||
MinIoUploadResDTO minIoUploadResDTO = contentToMinio(jsonArray.toString());
|
||||
String afterContent = minIoUploadResDTO.getMinFileName();
|
||||
if (BizParamConstant.STAT_BIZ_DAY.equals(reportParam.getType().toString())){
|
||||
rptInsert(reportParam, lineId, excelRptTemp, afterContent);
|
||||
}else{
|
||||
@@ -299,4 +323,106 @@ public class ReportServiceImpl implements ReportService {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 上传文件到Minio
|
||||
*
|
||||
* @param content 文件
|
||||
* @return 成功标记
|
||||
*/
|
||||
private MinIoUploadResDTO contentToMinio(String content) {
|
||||
//上传到minio
|
||||
String businessTempPath = generalInfo.getBusinessTempPath();
|
||||
File file = stringToFile(content, businessTempPath + File.separator + "a.json");
|
||||
MultipartFile multiFile = getMultipartFile(file);
|
||||
try {
|
||||
//把名称存入数据
|
||||
MinIoUploadResDTO upload = minIoUtils.upload(multiFile, minIoProperties.getBucket(), "report/");
|
||||
return upload;
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException(HarmonicResponseEnum.CUSTOM_REPORT_FILE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字符串写入指定文件
|
||||
*
|
||||
* @param res 原字符串
|
||||
* @param filePath 文件路径
|
||||
* @return 成功标记
|
||||
*/
|
||||
public File stringToFile(String res, String filePath) {
|
||||
boolean flag = true;
|
||||
BufferedReader bufferedReader = null;
|
||||
BufferedWriter bufferedWriter = null;
|
||||
File distFile = new File(filePath);
|
||||
try {
|
||||
if (!distFile.getParentFile().exists()){
|
||||
distFile.getParentFile().mkdirs();
|
||||
}
|
||||
bufferedReader = new BufferedReader(new StringReader(res));
|
||||
bufferedWriter = new BufferedWriter(new FileWriter(distFile));
|
||||
//先清空
|
||||
bufferedWriter.write("");
|
||||
char buf[] = new char[1024]; //字符缓冲区
|
||||
int len;
|
||||
while ((len = bufferedReader.read(buf)) != -1) {
|
||||
bufferedWriter.write(buf, 0, len);
|
||||
}
|
||||
bufferedWriter.flush();
|
||||
bufferedReader.close();
|
||||
bufferedWriter.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (bufferedReader != null) {
|
||||
try {
|
||||
bufferedReader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return distFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将文件转成Multipart
|
||||
*
|
||||
* @param file 文件
|
||||
* @return 成功标记
|
||||
*/
|
||||
private 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将文件Url读取,转为String
|
||||
*
|
||||
* @param objectUrl 文件url
|
||||
* @return 成功标记
|
||||
*/
|
||||
private String urlToString(String objectUrl) throws IOException {
|
||||
URL url = new URL(objectUrl);
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
String line = " ";
|
||||
while ((line = in.readLine()) != null){
|
||||
buffer.append(line);
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -44,6 +44,11 @@
|
||||
<artifactId>common-swagger</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>common-minio</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
84
pqs-user/user-boot/src/test/java/com/njcn/MinioTest.java
Normal file
84
pqs-user/user-boot/src/test/java/com/njcn/MinioTest.java
Normal file
@@ -0,0 +1,84 @@
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
1
pqs.ipr
1
pqs.ipr
@@ -289,6 +289,7 @@
|
||||
<module filepath="$PROJECT_DIR$/pqs-common/common-influxdb/common-influxDB.iml"/>
|
||||
<module filepath="$PROJECT_DIR$/pqs-common/common-poi/common-poi.iml"/>
|
||||
<module filepath="$PROJECT_DIR$/pqs-common/common-echarts/common-echarts.iml"/>
|
||||
<module filepath="$PROJECT_DIR$/pqs-common/common-minio/common-minio.iml"/>
|
||||
<module filepath="$PROJECT_DIR$/pqs-common/pqs-common.iml"/>
|
||||
<module filepath="$PROJECT_DIR$/pqs-gateway/pqs-gateway.iml"/>
|
||||
<module filepath="$PROJECT_DIR$/pqs-user/user-api/user-api.iml"/>
|
||||
|
||||
Reference in New Issue
Block a user