Compare commits
263 Commits
2d3222e03d
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
749c1d954c | ||
| 6089be6b4a | |||
| eb89472670 | |||
| 56cd9a05c3 | |||
| aafd32c7fc | |||
| 79cec4e21b | |||
|
|
615fe78d61 | ||
|
|
5fff0890e8 | ||
|
|
f5e134b194 | ||
|
|
291a20649e | ||
|
|
7eef16599f | ||
| 11750a4f3a | |||
|
|
e6332f1c51 | ||
| 23d87aecc8 | |||
| eff784e94e | |||
|
|
eed647d3d1 | ||
|
|
4a5fde6a47 | ||
|
|
82ab1de5b9 | ||
|
|
ecc56dd2f6 | ||
| 39ae7412a8 | |||
| 52677f84dc | |||
| abdb855919 | |||
| 64bcbfff91 | |||
|
|
499eee6784 | ||
|
|
c58bd87a78 | ||
|
|
0902f92838 | ||
| 87818db6f3 | |||
|
|
850b3174a2 | ||
| aad5943d64 | |||
| 9c467310d5 | |||
| ca3b125424 | |||
|
|
0c5c9bf067 | ||
|
|
c692282ea4 | ||
| 232e84aad3 | |||
| 59f2588488 | |||
|
|
46f521c7a7 | ||
|
|
6d69027e16 | ||
|
|
1afed2c9a4 | ||
|
|
9bb250bdb9 | ||
|
|
d33b3637a5 | ||
|
|
f50f11b159 | ||
| 30984aa908 | |||
|
|
39cfffbf7e | ||
|
|
1aad1aa86b | ||
| fa500ca600 | |||
| 7b9fb1628b | |||
| fcddc064f6 | |||
| 37c5e9cbf8 | |||
| a08c7db24d | |||
| 9225e82edb | |||
| e8cd6da8a0 | |||
| 559620ab66 | |||
| f0b3b81e65 | |||
| 475ca820c8 | |||
|
|
c0db2cf961 | ||
|
|
4e95159e01 | ||
|
|
eec2560fd2 | ||
|
|
94037d588b | ||
| 01a77fa92d | |||
| 9d9150e418 | |||
| ee1ca85a5d | |||
|
|
2c3c716607 | ||
|
|
e1d17c63a2 | ||
|
|
6234ac8ce9 | ||
| 6c91774200 | |||
| fc951e913c | |||
| d138d4353f | |||
| aecee4de49 | |||
|
|
fd04c21997 | ||
| 08d8b5b488 | |||
| 82457bc9c2 | |||
|
|
63330a04a6 | ||
|
|
ad45661c3c | ||
|
|
23de6313a6 | ||
|
|
7a5ef040bb | ||
| 140ed85108 | |||
|
|
99ab77dcf0 | ||
|
|
c772c9cd81 | ||
| 996ec87ea8 | |||
|
|
b6eaff3b1e | ||
|
|
56bf5bb7c9 | ||
|
|
7410d32241 | ||
|
|
41ba37b723 | ||
|
|
3f77d30cfd | ||
| f71f87ced4 | |||
| 32295f60c0 | |||
|
|
d2945b0fb2 | ||
|
|
133766a2c7 | ||
| 2a5a5087ad | |||
| 4edb27d20b | |||
| 71d6636be0 | |||
|
|
8ccdb84ea9 | ||
|
|
5389903ed7 | ||
|
|
0684bdf503 | ||
|
|
d0b4a1ec71 | ||
| 764ca4a12a | |||
|
|
ca992cadbc | ||
|
|
ed166cf1e0 | ||
| 598fa803a1 | |||
| 10050ce418 | |||
| cb688ad7ad | |||
| f6c4d050da | |||
|
|
fd6ec7bdf2 | ||
|
|
ca7f1010b0 | ||
| 97ddd133f0 | |||
| 735c99e8ac | |||
| 9a53399ec9 | |||
| f27276624a | |||
| df149a3cc2 | |||
| 7ca23b9431 | |||
| b27f049c9f | |||
| 23c4a78383 | |||
|
|
c9301d1f8f | ||
|
|
977a0e7a35 | ||
|
|
9143ff5b80 | ||
| 0502dc7508 | |||
| eb689c9852 | |||
|
|
c576bd3bf7 | ||
| 27bac7288c | |||
| a7c69f7c43 | |||
| 33ab825497 | |||
| 22c8ff3b22 | |||
|
|
875d114733 | ||
|
|
bd1fe68060 | ||
| c1d933467e | |||
|
|
e7daf05670 | ||
|
|
e251fc6a1a | ||
| 0e7cc360f7 | |||
| e2d3394669 | |||
| b3ab5d2587 | |||
|
|
ed029139d3 | ||
| 02578546f2 | |||
|
|
09e2f329b7 | ||
|
|
ee2fae105b | ||
| 82efce189a | |||
|
|
be8c14625f | ||
| 95a571d3c3 | |||
| 322001150a | |||
|
|
b805bda25b | ||
| f592f2b580 | |||
|
|
184b2b8fad | ||
|
|
fe029fcb95 | ||
|
|
9143466ce7 | ||
|
|
9409d57243 | ||
| 63603dee08 | |||
|
|
e35bbd9b34 | ||
|
|
ea2173fff4 | ||
| faac7953d3 | |||
| c3cc39973e | |||
| 6d8bfacd0a | |||
|
|
ab5d28e3cb | ||
|
|
2dccb22cf8 | ||
| 6b0bad6047 | |||
| 9ffbdbdf57 | |||
|
|
778f689b3e | ||
|
|
917e3fb2d5 | ||
| e0f1e314a4 | |||
| 2f2ed06a35 | |||
| 277400670d | |||
| a1031109c4 | |||
| eeb27c519b | |||
|
|
670eaf7d38 | ||
| 2b79cefad6 | |||
| 212db18835 | |||
|
|
e9a1c34160 | ||
|
|
fb7a2b7084 | ||
|
|
4b3ec39a11 | ||
|
|
2d255a5dd3 | ||
|
|
614647d36d | ||
|
|
a899614c89 | ||
|
|
2543f87dd2 | ||
|
|
c5074df93d | ||
| 24e4c4de37 | |||
|
|
4f70566c65 | ||
|
|
dc11d34add | ||
| 9f3bb52d9a | |||
|
|
567ba2f56e | ||
|
|
371d4efb29 | ||
|
|
47b08d4797 | ||
| 65805e4f50 | |||
| 41d555121c | |||
|
|
4d48b42c98 | ||
|
|
f5e1fac55d | ||
|
|
cebda9323e | ||
| d09f1472a9 | |||
| b9696e957d | |||
| 12cfecac7e | |||
| 3a97f01383 | |||
|
|
10273dd2b0 | ||
|
|
5e8e03cbb1 | ||
|
|
b103141a54 | ||
|
|
a6d2d6ed47 | ||
| 601a78246e | |||
| 5e7b973d5f | |||
|
|
e89c6a2888 | ||
| 2166529b4d | |||
| 2117e16b61 | |||
|
|
054d5534a8 | ||
|
|
c03a516931 | ||
|
|
0fdc3edb89 | ||
| a730ad61b1 | |||
| 9b758dc7c9 | |||
| a74dd460d1 | |||
| 2708aa8b81 | |||
|
|
6d833678a6 | ||
| be264acd79 | |||
|
|
186d46752c | ||
|
|
e03478eeec | ||
|
|
0c1bb606d6 | ||
|
|
42b619fa56 | ||
|
|
f0894ca0ed | ||
|
|
8a958fa34c | ||
|
|
770fb09223 | ||
|
|
b4e5d0c638 | ||
|
|
eb334cc7c7 | ||
|
|
404d11526a | ||
| 7bac805988 | |||
|
|
e4e04fc5db | ||
| f588a0ffc8 | |||
| f8ffe767dc | |||
|
|
68cbad2fdb | ||
|
|
9b9d75e463 | ||
|
|
62c3c09a6b | ||
|
|
b523a24e5b | ||
|
|
075dfc19d6 | ||
|
|
279c5c7642 | ||
|
|
ff1351b107 | ||
|
|
2dd67f9e3a | ||
|
|
b0ef851479 | ||
|
|
be899a262b | ||
| 4339a37268 | |||
|
|
9659aa257a | ||
| 9d32ca05df | |||
|
|
d48cf09119 | ||
|
|
c38b07ec07 | ||
|
|
87f05c6278 | ||
| e9ac024f73 | |||
| b7e3bb9796 | |||
| 4bebf28b76 | |||
|
|
20ec9bc0b4 | ||
| 5e93eb3691 | |||
| b63fab9085 | |||
|
|
aba66aaf4a | ||
|
|
1c7c514691 | ||
| 04fe9bdbbd | |||
|
|
b41347c596 | ||
|
|
4f75deac43 | ||
| 2c68646fc9 | |||
| 02599eeb81 | |||
| 0cec471ce2 | |||
|
|
102bab7430 | ||
| 28378dcfa1 | |||
| 1692799f0b | |||
| 90471c368d | |||
| 08ec8591f1 | |||
| d038dfe655 | |||
| c1bf8d79ce | |||
| 74420e7107 | |||
|
|
6815e1df4b | ||
|
|
c1dca815e7 | ||
|
|
5c3baf4e57 | ||
|
|
28f7e038ce | ||
| fe1195b7b5 |
17
pom.xml
17
pom.xml
@@ -39,11 +39,12 @@
|
|||||||
</snapshotRepository>
|
</snapshotRepository>
|
||||||
</distributionManagement>
|
</distributionManagement>
|
||||||
<properties>
|
<properties>
|
||||||
|
<spring.profiles.active>sjzx</spring.profiles.active>
|
||||||
<!--中间件目标地址-->
|
<!--中间件目标地址-->
|
||||||
<!-- <middle.server.url>10.95.53.49</middle.server.url>-->
|
<!-- <middle.server.url>10.95.53.49</middle.server.url>-->
|
||||||
<middle.server.url>192.168.1.22</middle.server.url>
|
<middle.server.url>192.168.1.103</middle.server.url>
|
||||||
<!--微服务模块发布地址-->
|
<!--微服务模块发布地址-->
|
||||||
<service.server.url>192.168.1.127</service.server.url>
|
<service.server.url>192.168.2.130</service.server.url>
|
||||||
<!--docker仓库地址-->
|
<!--docker仓库地址-->
|
||||||
<docker.server.url>192.168.1.22</docker.server.url>
|
<docker.server.url>192.168.1.22</docker.server.url>
|
||||||
<!--nacos的ip:port-->
|
<!--nacos的ip:port-->
|
||||||
@@ -51,11 +52,11 @@
|
|||||||
<!--nacos开启鉴权后的用户名-->
|
<!--nacos开启鉴权后的用户名-->
|
||||||
<nacos.username>nacos</nacos.username>
|
<nacos.username>nacos</nacos.username>
|
||||||
<!--nacos的ip:port-->
|
<!--nacos的ip:port-->
|
||||||
<nacos.password>nacos</nacos.password>
|
<nacos.password>njcnpqs</nacos.password>
|
||||||
<!--服务器发布内容为空-->
|
<!--服务器发布内容为空-->
|
||||||
<!-- <nacos.namespace></nacos.namespace>-->
|
<nacos.namespace>hswbpm</nacos.namespace>
|
||||||
<!-- <nacos.namespace>30c701c4-2a94-49d9-82e1-76aa9456573f</nacos.namespace>-->
|
<!-- <nacos.namespace>30c701c4-2a94-49d9-82e1-76aa9456573f</nacos.namespace>-->
|
||||||
<nacos.namespace>78588706-e06f-4580-b612-b26d72493fcb</nacos.namespace>
|
<!-- <nacos.namespace>12b467cc-a7e6-411d-8944-090cbfa09dde</nacos.namespace>-->
|
||||||
<!-- <nacos.namespace>910d0d69-2254-481b-b9f7-7ecf9cb881b0</nacos.namespace>-->
|
<!-- <nacos.namespace>910d0d69-2254-481b-b9f7-7ecf9cb881b0</nacos.namespace>-->
|
||||||
<!-- sentinel:port-->
|
<!-- sentinel:port-->
|
||||||
<sentinel.url>${middle.server.url}:8080</sentinel.url>
|
<sentinel.url>${middle.server.url}:8080</sentinel.url>
|
||||||
@@ -81,6 +82,7 @@
|
|||||||
<springcloud.alibaba.version>2.2.7.RELEASE</springcloud.alibaba.version>
|
<springcloud.alibaba.version>2.2.7.RELEASE</springcloud.alibaba.version>
|
||||||
<hutool.version>5.8.11</hutool.version>
|
<hutool.version>5.8.11</hutool.version>
|
||||||
<knife4j.version>3.0.2</knife4j.version>
|
<knife4j.version>3.0.2</knife4j.version>
|
||||||
|
<postgresql.version>42.3.8</postgresql.version>
|
||||||
<knife4j.aggregation.version>2.0.8</knife4j.aggregation.version>
|
<knife4j.aggregation.version>2.0.8</knife4j.aggregation.version>
|
||||||
<lombok.version>1.18.18</lombok.version>
|
<lombok.version>1.18.18</lombok.version>
|
||||||
<mybatis.version>2.1.3</mybatis.version>
|
<mybatis.version>2.1.3</mybatis.version>
|
||||||
@@ -171,6 +173,11 @@
|
|||||||
<artifactId>knife4j-spring-ui</artifactId>
|
<artifactId>knife4j-spring-ui</artifactId>
|
||||||
<version>${knife4j.version}</version>
|
<version>${knife4j.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.postgresql</groupId>
|
||||||
|
<artifactId>postgresql</artifactId>
|
||||||
|
<version>${postgresql.version}</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.xiaoymin</groupId>
|
<groupId>com.github.xiaoymin</groupId>
|
||||||
<artifactId>knife4j-aggregation-spring-boot-starter</artifactId>
|
<artifactId>knife4j-aggregation-spring-boot-starter</artifactId>
|
||||||
|
|||||||
@@ -2,8 +2,14 @@ package com.njcn.advance.api;
|
|||||||
|
|
||||||
import com.njcn.advance.api.fallback.EventWaveAnalysisFeignClientFallbackFactory;
|
import com.njcn.advance.api.fallback.EventWaveAnalysisFeignClientFallbackFactory;
|
||||||
import com.njcn.advance.pojo.dto.waveAnalysis.EntityAdvancedData;
|
import com.njcn.advance.pojo.dto.waveAnalysis.EntityAdvancedData;
|
||||||
|
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||||
import com.njcn.common.pojo.constant.ServerInfo;
|
import com.njcn.common.pojo.constant.ServerInfo;
|
||||||
|
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.pojo.response.HttpResult;
|
||||||
|
import com.njcn.common.utils.HttpResultUtil;
|
||||||
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
@@ -27,4 +33,7 @@ public interface EventWaveAnalysisFeignClient {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("analysis")
|
@PostMapping("analysis")
|
||||||
HttpResult<EntityAdvancedData> analysis(@RequestParam("eventIndex") String eventIndex);
|
HttpResult<EntityAdvancedData> analysis(@RequestParam("eventIndex") String eventIndex);
|
||||||
|
|
||||||
|
@PostMapping("analysisWlEvent")
|
||||||
|
HttpResult<EntityAdvancedData> analysisWlEvent(@RequestParam("eventIndex") String eventIndex);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,12 @@ public class EventWaveAnalysisFeignClientFallbackFactory implements FallbackFact
|
|||||||
log.error("{}异常,降级处理,异常为:{}", "波形高级分析", throwable.toString());
|
log.error("{}异常,降级处理,异常为:{}", "波形高级分析", throwable.toString());
|
||||||
throw new BusinessException(finalExceptionEnum);
|
throw new BusinessException(finalExceptionEnum);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HttpResult<EntityAdvancedData> analysisWlEvent(String eventIndex) {
|
||||||
|
log.error("{}异常,降级处理,异常为:{}", "物联测点波形高级分析异常", throwable.toString());
|
||||||
|
throw new BusinessException(finalExceptionEnum);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,4 +73,10 @@ public class EventAnalysisDTO {
|
|||||||
* 1 正常计算
|
* 1 正常计算
|
||||||
*/
|
*/
|
||||||
private Integer typeFlag = 1;
|
private Integer typeFlag = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件全路径
|
||||||
|
* 适配物联的暂态事件解析 物联那边事件的路径是全路径,不需要拼接,这个参数可为空
|
||||||
|
*/
|
||||||
|
private String wlFilePath;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,8 +26,6 @@ import java.util.*;
|
|||||||
public class AnalyWave {
|
public class AnalyWave {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************
|
/*****************************************
|
||||||
* 解析comtrate文件工具类
|
* 解析comtrate文件工具类
|
||||||
* author yexb根据Ww算法装换
|
* author yexb根据Ww算法装换
|
||||||
@@ -94,7 +92,7 @@ public class AnalyWave {
|
|||||||
** ** strFilePath *** cfg文件路径
|
** ** strFilePath *** cfg文件路径
|
||||||
* *** auth *** 读取方式 null则使用本地读取方式读取
|
* *** auth *** 读取方式 null则使用本地读取方式读取
|
||||||
******************************************/
|
******************************************/
|
||||||
public AnalyWaveModel.tagDataValue readComtrade(List<String> temCfgList,byte[] array, int iFlag) {
|
public AnalyWaveModel.tagDataValue readComtrade(List<String> temCfgList, byte[] array, int iFlag) {
|
||||||
//初始化参数
|
//初始化参数
|
||||||
ComtradeCfg = new AnalyWaveModel.tagComtradeCfg();
|
ComtradeCfg = new AnalyWaveModel.tagComtradeCfg();
|
||||||
RatesCfg = new AnalyWaveModel.tagRates();
|
RatesCfg = new AnalyWaveModel.tagRates();
|
||||||
@@ -163,148 +161,145 @@ public class AnalyWave {
|
|||||||
iterable.next();
|
iterable.next();
|
||||||
String[] strTempArray;// 读取cfg文件
|
String[] strTempArray;// 读取cfg文件
|
||||||
try {
|
try {
|
||||||
nFreq = 0f;//WW 2019-11-14
|
nFreq = 0f;//WW 2019-11-14
|
||||||
String strFileLine = iterable.next();
|
String strFileLine = iterable.next();
|
||||||
|
strTempArray = strFileLine.split(",");
|
||||||
|
|
||||||
|
for (int i = 0; i < strTempArray.length; i++) {
|
||||||
|
switch (i) {
|
||||||
|
case 0:// 总个数
|
||||||
|
ComtradeCfg.nChannelNum = Integer.parseInt(strTempArray[i]);
|
||||||
|
break;
|
||||||
|
case 1:// 模拟量的个数
|
||||||
|
{
|
||||||
|
String str = strTempArray[i].substring(0, strTempArray[i].length() - 1);
|
||||||
|
ComtradeCfg.nAnalogNum = Integer.parseInt(str);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 2:// 开关量的个数
|
||||||
|
{
|
||||||
|
String str = strTempArray[i].substring(0, strTempArray[i].length() - 1);
|
||||||
|
ComtradeCfg.nDigitalNum = Integer.parseInt(str);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 从第三行到第ComtradeCfg.nChannelNum+3行是模拟量通道和数字量通道
|
||||||
|
for (int i = 0; i < ComtradeCfg.nChannelNum; i++) {
|
||||||
|
AnalyWaveModel.tagOneChannleCfg OneChannlecfg = new AnalyWaveModel.tagOneChannleCfg();
|
||||||
|
ComtradeCfg.OneChannleCfg.add(OneChannlecfg);
|
||||||
|
|
||||||
|
strFileLine = iterable.next();
|
||||||
|
strTempArray = strFileLine.split(",");
|
||||||
|
// 配置总共13项
|
||||||
|
for (int j = 0; j < strTempArray.length; j++) {
|
||||||
|
switch (j) {
|
||||||
|
case 0:// 通道序号
|
||||||
|
OneChannlecfg.nIndex = Integer.parseInt(strTempArray[j]);
|
||||||
|
break;
|
||||||
|
case 1:// 通道名称
|
||||||
|
OneChannlecfg.szChannleName = strTempArray[j];
|
||||||
|
break;
|
||||||
|
case 2:// 相位名称
|
||||||
|
OneChannlecfg.szPhasicName = strTempArray[j];
|
||||||
|
break;
|
||||||
|
case 3:// 监视的通道名称
|
||||||
|
OneChannlecfg.szMonitoredChannleName = strTempArray[j];
|
||||||
|
break;
|
||||||
|
case 4:// 通道的单位
|
||||||
|
OneChannlecfg.szUnitName = strTempArray[j];
|
||||||
|
break;
|
||||||
|
case 5:// 通道的系数
|
||||||
|
OneChannlecfg.fCoefficent = Float.parseFloat(strTempArray[j]);
|
||||||
|
break;
|
||||||
|
case 6:// 通道的偏移量
|
||||||
|
OneChannlecfg.fOffset = Float.parseFloat(strTempArray[j]);
|
||||||
|
break;
|
||||||
|
case 7:// 起始采样时间的偏移量
|
||||||
|
OneChannlecfg.fTimeOffset = Float.parseFloat(strTempArray[j]);
|
||||||
|
break;
|
||||||
|
case 8:// 采样值的最小值
|
||||||
|
OneChannlecfg.nMin = Integer.parseInt(strTempArray[j]);
|
||||||
|
break;
|
||||||
|
case 9:// 采样值的最大值
|
||||||
|
OneChannlecfg.nMax = Integer.parseInt(strTempArray[j]);
|
||||||
|
break;
|
||||||
|
case 10:// 一次变比
|
||||||
|
OneChannlecfg.fPrimary = Float.parseFloat(strTempArray[j]);
|
||||||
|
break;
|
||||||
|
case 11:// 二次变比
|
||||||
|
OneChannlecfg.fSecondary = Float.parseFloat(strTempArray[j]);
|
||||||
|
break;
|
||||||
|
case 12:// 一次值还是二次值标志
|
||||||
|
OneChannlecfg.szValueType = strTempArray[j];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 采样频率
|
||||||
|
strFileLine = iterable.next();
|
||||||
|
float fFreq = Float.parseFloat(strFileLine);
|
||||||
|
nFreq = (float) fFreq;//WW 2019-11-14
|
||||||
|
// 采样段数
|
||||||
|
strFileLine = iterable.next();
|
||||||
|
int nRates = Integer.parseInt(strFileLine);
|
||||||
|
RatesCfg.nRates = nRates;
|
||||||
|
// 获得每段的采样率
|
||||||
|
long nOffset = 0;
|
||||||
|
for (int i = 0; i < nRates; i++) {
|
||||||
|
strFileLine = iterable.next();
|
||||||
strTempArray = strFileLine.split(",");
|
strTempArray = strFileLine.split(",");
|
||||||
|
|
||||||
for (int i = 0; i < strTempArray.length; i++) {
|
AnalyWaveModel.tagOneRate OneRate = new AnalyWaveModel.tagOneRate();
|
||||||
switch (i) {
|
RatesCfg.OneRate.add(OneRate);
|
||||||
case 0:// 总个数
|
|
||||||
ComtradeCfg.nChannelNum = Integer.parseInt(strTempArray[i]);
|
for (int j = 0; j < strTempArray.length; j++) {
|
||||||
|
|
||||||
|
switch (j) {
|
||||||
|
case 0:// 单周波采样点数
|
||||||
|
OneRate.nOneSample = (int) (Float.parseFloat(strTempArray[j]) / nFreq);//WW 2019-11-14
|
||||||
|
break;
|
||||||
|
case 1:// 总点数 //这里的strTemp是一个偏移量
|
||||||
|
OneRate.nSampleNum = (long) (Float.parseFloat(strTempArray[j]) - nOffset);
|
||||||
|
nOffset += OneRate.nSampleNum;
|
||||||
break;
|
break;
|
||||||
case 1:// 模拟量的个数
|
|
||||||
{
|
|
||||||
String str = strTempArray[i].substring(0, strTempArray[i].length() - 1);
|
|
||||||
ComtradeCfg.nAnalogNum = Integer.parseInt(str);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 2:// 开关量的个数
|
|
||||||
{
|
|
||||||
String str = strTempArray[i].substring(0, strTempArray[i].length() - 1);
|
|
||||||
ComtradeCfg.nDigitalNum = Integer.parseInt(str);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 从第三行到第ComtradeCfg.nChannelNum+3行是模拟量通道和数字量通道
|
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss.SSS");
|
||||||
for (int i = 0; i < ComtradeCfg.nChannelNum; i++) {
|
// 波形起始时间
|
||||||
AnalyWaveModel.tagOneChannleCfg OneChannlecfg = new AnalyWaveModel.tagOneChannleCfg();
|
strFileLine = iterable.next();
|
||||||
ComtradeCfg.OneChannleCfg.add(OneChannlecfg);
|
strFileLine = strFileLine.substring(0, strFileLine.length() - 3).replace(",", " ");
|
||||||
|
TimeTrige = sdf.parse(strFileLine);
|
||||||
strFileLine = iterable.next();
|
// 暂态触发时间
|
||||||
strTempArray = strFileLine.split(",");
|
strFileLine = iterable.next();
|
||||||
// 配置总共13项
|
strFileLine = strFileLine.substring(0, strFileLine.length() - 3).replace(",", " ");
|
||||||
for (int j = 0; j < strTempArray.length; j++) {
|
TimeWave = sdf.parse(strFileLine);
|
||||||
switch (j) {
|
|
||||||
case 0:// 通道序号
|
|
||||||
OneChannlecfg.nIndex = Integer.parseInt(strTempArray[j]);
|
|
||||||
break;
|
|
||||||
case 1:// 通道名称
|
|
||||||
OneChannlecfg.szChannleName = strTempArray[j];
|
|
||||||
break;
|
|
||||||
case 2:// 相位名称
|
|
||||||
OneChannlecfg.szPhasicName = strTempArray[j];
|
|
||||||
break;
|
|
||||||
case 3:// 监视的通道名称
|
|
||||||
OneChannlecfg.szMonitoredChannleName = strTempArray[j];
|
|
||||||
break;
|
|
||||||
case 4:// 通道的单位
|
|
||||||
OneChannlecfg.szUnitName = strTempArray[j];
|
|
||||||
break;
|
|
||||||
case 5:// 通道的系数
|
|
||||||
OneChannlecfg.fCoefficent = Float.parseFloat(strTempArray[j]);
|
|
||||||
break;
|
|
||||||
case 6:// 通道的偏移量
|
|
||||||
OneChannlecfg.fOffset = Float.parseFloat(strTempArray[j]);
|
|
||||||
break;
|
|
||||||
case 7:// 起始采样时间的偏移量
|
|
||||||
OneChannlecfg.fTimeOffset = Float.parseFloat(strTempArray[j]);
|
|
||||||
break;
|
|
||||||
case 8:// 采样值的最小值
|
|
||||||
OneChannlecfg.nMin = Integer.parseInt(strTempArray[j]);
|
|
||||||
break;
|
|
||||||
case 9:// 采样值的最大值
|
|
||||||
OneChannlecfg.nMax = Integer.parseInt(strTempArray[j]);
|
|
||||||
break;
|
|
||||||
case 10:// 一次变比
|
|
||||||
OneChannlecfg.fPrimary = Float.parseFloat(strTempArray[j]);
|
|
||||||
break;
|
|
||||||
case 11:// 二次变比
|
|
||||||
OneChannlecfg.fSecondary = Float.parseFloat(strTempArray[j]);
|
|
||||||
break;
|
|
||||||
case 12:// 一次值还是二次值标志
|
|
||||||
OneChannlecfg.szValueType = strTempArray[j];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 采样频率
|
|
||||||
strFileLine = iterable.next();
|
|
||||||
float fFreq = Float.parseFloat(strFileLine);
|
|
||||||
nFreq = (float) fFreq;//WW 2019-11-14
|
|
||||||
// 采样段数
|
|
||||||
strFileLine = iterable.next();
|
|
||||||
int nRates = Integer.parseInt(strFileLine);
|
|
||||||
RatesCfg.nRates = nRates;
|
|
||||||
// 获得每段的采样率
|
|
||||||
long nOffset = 0;
|
|
||||||
for (int i = 0; i < nRates; i++) {
|
|
||||||
strFileLine = iterable.next();
|
|
||||||
strTempArray = strFileLine.split(",");
|
|
||||||
|
|
||||||
AnalyWaveModel.tagOneRate OneRate = new AnalyWaveModel.tagOneRate();
|
|
||||||
RatesCfg.OneRate.add(OneRate);
|
|
||||||
|
|
||||||
for (int j = 0; j < strTempArray.length; j++) {
|
|
||||||
|
|
||||||
switch (j) {
|
|
||||||
case 0:// 单周波采样点数
|
|
||||||
OneRate.nOneSample = (int) (Float.parseFloat(strTempArray[j]) / nFreq);//WW 2019-11-14
|
|
||||||
break;
|
|
||||||
case 1:// 总点数 //这里的strTemp是一个偏移量
|
|
||||||
OneRate.nSampleNum = (long) (Float.parseFloat(strTempArray[j]) - nOffset);
|
|
||||||
nOffset = OneRate.nSampleNum;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss.SSS");
|
|
||||||
// 波形起始时间
|
|
||||||
strFileLine = iterable.next();
|
|
||||||
strFileLine = strFileLine.substring(0, strFileLine.length() - 3).replace(",", " ");
|
|
||||||
TimeTrige = sdf.parse(strFileLine);
|
|
||||||
// 暂态触发时间
|
|
||||||
strFileLine = iterable.next();
|
|
||||||
strFileLine = strFileLine.substring(0, strFileLine.length() - 3).replace(",", " ");
|
|
||||||
TimeWave = sdf.parse(strFileLine);
|
|
||||||
|
|
||||||
Calendar calendar = Calendar.getInstance();
|
|
||||||
calendar.setTime(TimeWave);
|
|
||||||
firstMs = calendar.get(Calendar.MILLISECOND);
|
|
||||||
firstTime = calendar.getTime();
|
|
||||||
|
|
||||||
long a = TimeWave.getTime();
|
|
||||||
long b = TimeTrige.getTime();
|
|
||||||
int c = (int) (a - b);
|
|
||||||
if (c >= 90 && c <= 110) {
|
|
||||||
iPush = 100;
|
|
||||||
} else if (c >= 190 && c <= 210) {
|
|
||||||
iPush = 200;
|
|
||||||
}
|
|
||||||
// 赋值编码格式(二进制)
|
|
||||||
strBinType = iterable.next().toUpperCase();
|
|
||||||
|
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
calendar.setTime(TimeWave);
|
||||||
|
firstMs = calendar.get(Calendar.MILLISECOND);
|
||||||
|
firstTime = calendar.getTime();
|
||||||
|
|
||||||
|
long a = TimeWave.getTime();
|
||||||
|
long b = TimeTrige.getTime();
|
||||||
|
int c = (int) (a - b);
|
||||||
|
if (c >= 90 && c <= 110) {
|
||||||
|
iPush = 100;
|
||||||
|
} else if (c >= 190 && c <= 210) {
|
||||||
|
iPush = 200;
|
||||||
|
}
|
||||||
|
// 赋值编码格式(二进制)
|
||||||
|
strBinType = iterable.next().toUpperCase();
|
||||||
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
logger.error("读取文件内容出错"+e.getMessage());
|
logger.error("读取文件内容出错" + e.getMessage());
|
||||||
return false;
|
return false;
|
||||||
}finally {
|
} finally {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -319,15 +314,8 @@ public class AnalyWave {
|
|||||||
private List<List<Float>> AnalyseComtradeDat(byte[] array, int iFlag) {
|
private List<List<Float>> AnalyseComtradeDat(byte[] array, int iFlag) {
|
||||||
float xValueAll = 0;//初始化xValue的值
|
float xValueAll = 0;//初始化xValue的值
|
||||||
boolean blxValue = false;//判断是否首次登陆
|
boolean blxValue = false;//判断是否首次登陆
|
||||||
|
|
||||||
List<List<Float>> listWaveData = new ArrayList<>();//返回数据
|
List<List<Float>> listWaveData = new ArrayList<>();//返回数据
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 计算每个单独的数据块的大小 4字节的序号 4字节的时间 2字节的值
|
// 计算每个单独的数据块的大小 4字节的序号 4字节的时间 2字节的值
|
||||||
// 示例中的排布是 4字节的序号 4字节的时间 UA(2字节) UB(2字节) UC(2字节) IA(2字节) IB(2字节)
|
// 示例中的排布是 4字节的序号 4字节的时间 UA(2字节) UB(2字节) UC(2字节) IA(2字节) IB(2字节)
|
||||||
// IC(2字节)
|
// IC(2字节)
|
||||||
@@ -470,7 +458,7 @@ public class AnalyWave {
|
|||||||
{
|
{
|
||||||
if (ComtradeCfg.OneChannleCfg.get(j).fPrimary != 0.0f)//根据cfg内的变比,将一次值转换成二次值
|
if (ComtradeCfg.OneChannleCfg.get(j).fPrimary != 0.0f)//根据cfg内的变比,将一次值转换成二次值
|
||||||
{
|
{
|
||||||
fValue = ComtradeCfg.OneChannleCfg.get(j).fSecondary / ComtradeCfg.OneChannleCfg.get(j).fPrimary;
|
fValue = fValue * ComtradeCfg.OneChannleCfg.get(j).fSecondary / ComtradeCfg.OneChannleCfg.get(j).fPrimary;
|
||||||
} else {
|
} else {
|
||||||
fValue = fValue;
|
fValue = fValue;
|
||||||
}
|
}
|
||||||
@@ -500,7 +488,7 @@ public class AnalyWave {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("读取文件出错:" + e.getMessage());
|
logger.error("读取文件出错:" + e.getMessage());
|
||||||
return listWaveData;
|
return listWaveData;
|
||||||
}finally {
|
} finally {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ import java.util.List;
|
|||||||
* angle_diff_cn C相相位负跳变
|
* angle_diff_cn C相相位负跳变
|
||||||
* bph_max_value 不平衡度(单位%)
|
* bph_max_value 不平衡度(单位%)
|
||||||
*/
|
*/
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
@JsonIgnoreProperties(ignoreUnknown = true,value = {"pointer"})
|
||||||
public class BackData extends Structure {
|
public class BackData extends Structure {
|
||||||
public int qvvr_cata_cause[] = new int[256];
|
public int qvvr_cata_cause[] = new int[256];
|
||||||
public int qvvr_phasetype[] = new int[256];
|
public int qvvr_phasetype[] = new int[256];
|
||||||
|
|||||||
@@ -23,8 +23,13 @@ public class CauseStruct extends Structure {
|
|||||||
public static class ByValue extends CauseStruct implements Structure.ByValue {
|
public static class ByValue extends CauseStruct implements Structure.ByValue {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
// protected List<String> getFieldOrder() { // 返回值填入的顺序
|
||||||
|
// return Arrays.asList(new String[] { "cause", "no_cal" });
|
||||||
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<String> getFieldOrder() { // 返回值填入的顺序
|
protected List<String> getFieldOrder() {
|
||||||
return Arrays.asList(new String[] { "cause", "no_cal" });
|
return Arrays.asList("smp_va", "smp_vb", "smp_vc", "smp_rate", "smp_len", "threshold", "cause", "no_cal");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,8 +35,13 @@ public class Rect extends Structure {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
// protected List<String> getFieldOrder() {
|
||||||
|
// return Arrays.asList(new String[] { "evt_num","evt_buf" });
|
||||||
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<String> getFieldOrder() {
|
protected List<String> getFieldOrder() {
|
||||||
return Arrays.asList(new String[] { "evt_num","evt_buf" });
|
return Arrays.asList("smp_va", "smp_vb", "smp_vc", "smp_rate", "smp_len", "evt_num", "evt_buf");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,10 +83,10 @@ public class EventRelevantAnalysisController extends BaseController {
|
|||||||
public HttpResult<Page<RmpEventDetailAssPO>> queryEventsAssPage(@RequestBody BaseParam baseParam){
|
public HttpResult<Page<RmpEventDetailAssPO>> queryEventsAssPage(@RequestBody BaseParam baseParam){
|
||||||
String methodDescribe = getMethodDescribe("queryEventsAssPage");
|
String methodDescribe = getMethodDescribe("queryEventsAssPage");
|
||||||
String searchValue = baseParam.getSearchValue();
|
String searchValue = baseParam.getSearchValue();
|
||||||
Pattern pattern = Pattern.compile(PatternRegex.SPECIAL_REGEX);
|
// Pattern pattern = Pattern.compile(PatternRegex.SPECIAL_REGEX);
|
||||||
if(pattern.matcher(searchValue).find()){
|
// if(pattern.matcher(searchValue).find()){
|
||||||
throw new BusinessException(ValidMessage.SPECIAL_REGEX);
|
// throw new BusinessException(ValidMessage.SPECIAL_REGEX);
|
||||||
}
|
// }
|
||||||
Page<RmpEventDetailAssPO> page = eventRelevantAnalysisService.queryEventsAssPage(baseParam);
|
Page<RmpEventDetailAssPO> page = eventRelevantAnalysisService.queryEventsAssPage(baseParam);
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, page, methodDescribe);
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, page, methodDescribe);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ public class EventWaveAnalysisController extends BaseController {
|
|||||||
|
|
||||||
private final EventWaveAnalysisService eventWaveAnalysisService;
|
private final EventWaveAnalysisService eventWaveAnalysisService;
|
||||||
|
|
||||||
|
|
||||||
@PostMapping("analysis")
|
@PostMapping("analysis")
|
||||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||||
@ApiOperation("波形高级分析")
|
@ApiOperation("波形高级分析")
|
||||||
@@ -43,6 +42,15 @@ public class EventWaveAnalysisController extends BaseController {
|
|||||||
String methodDescribe = getMethodDescribe("analysis");
|
String methodDescribe = getMethodDescribe("analysis");
|
||||||
EntityAdvancedData entityAdvancedData = eventWaveAnalysisService.analysis(eventIndex);
|
EntityAdvancedData entityAdvancedData = eventWaveAnalysisService.analysis(eventIndex);
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, entityAdvancedData, methodDescribe);
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, entityAdvancedData, methodDescribe);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("analysisWlEvent")
|
||||||
|
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||||
|
@ApiOperation("物联事件波形高级分析")
|
||||||
|
@ApiImplicitParam(name = "eventIndex", value = "暂降事件id", required = true)
|
||||||
|
public HttpResult<EntityAdvancedData> analysisWlEvent(@RequestParam("eventIndex") String eventIndex) {
|
||||||
|
String methodDescribe = getMethodDescribe("analysisWlEvent");
|
||||||
|
EntityAdvancedData entityAdvancedData = eventWaveAnalysisService.analysisWlEvent(eventIndex);
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, entityAdvancedData, methodDescribe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,9 @@ public interface QvvrCauseDLL extends Library {
|
|||||||
|
|
||||||
// 创建临时文件
|
// 创建临时文件
|
||||||
String tempDir = System.getProperty("java.io.tmpdir");
|
String tempDir = System.getProperty("java.io.tmpdir");
|
||||||
File tempLibFile = new File(tempDir, "qvvr_" + System.currentTimeMillis() + "_" + libFileName);
|
File tempLibFile = new File(tempDir, libFileName);
|
||||||
|
|
||||||
|
//File tempLibFile = new File(tempDir, "qvvr_" + System.currentTimeMillis() + "_" + libFileName);
|
||||||
|
|
||||||
// 提取库文件到临时目录
|
// 提取库文件到临时目录
|
||||||
try (FileOutputStream out = new FileOutputStream(tempLibFile)) {
|
try (FileOutputStream out = new FileOutputStream(tempLibFile)) {
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
package com.njcn.advance.event.service.impl;
|
package com.njcn.advance.event.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.njcn.advance.event.cause.core.VoltageSagAnalyzer;
|
import com.njcn.advance.enums.EnumEvt;
|
||||||
import com.njcn.advance.event.cause.jna.QvvrCauseDLL;
|
import com.njcn.advance.event.cause.jna.QvvrCauseDLL;
|
||||||
import com.njcn.advance.event.cause.model.AnalysisResult;
|
|
||||||
import com.njcn.advance.event.cause.model.DataFeature;
|
import com.njcn.advance.event.cause.model.DataFeature;
|
||||||
import com.njcn.advance.event.cause.model.QvvrDataStruct;
|
import com.njcn.advance.event.type.jna.*;
|
||||||
import com.njcn.advance.pojo.dto.EventAnalysisDTO;
|
import com.njcn.advance.pojo.dto.EventAnalysisDTO;
|
||||||
import com.njcn.advance.event.service.IEventAdvanceService;
|
import com.njcn.advance.event.service.IEventAdvanceService;
|
||||||
import com.njcn.advance.event.type.jna.QvvrDLL;
|
import com.njcn.advance.pojo.dto.waveAnalysis.Rect;
|
||||||
|
import com.njcn.advance.utils.Utils;
|
||||||
import com.njcn.common.config.GeneralInfo;
|
import com.njcn.common.config.GeneralInfo;
|
||||||
import com.njcn.common.pojo.exception.BusinessException;
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
import com.njcn.event.file.component.WaveFileComponent;
|
import com.njcn.event.file.component.WaveFileComponent;
|
||||||
@@ -21,6 +21,7 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -47,11 +48,12 @@ public class EventAdvanceServiceImpl implements IEventAdvanceService {
|
|||||||
public EventAnalysisDTO analysisCauseAndType(EventAnalysisDTO eventAnalysis) {
|
public EventAnalysisDTO analysisCauseAndType(EventAnalysisDTO eventAnalysis) {
|
||||||
WaveDataDTO waveDataDTO;
|
WaveDataDTO waveDataDTO;
|
||||||
String waveName = eventAnalysis.getWaveName();
|
String waveName = eventAnalysis.getWaveName();
|
||||||
|
String wlFilePath = eventAnalysis.getWlFilePath();
|
||||||
String cfgPath, datPath, cfgPath2, datPath2;
|
String cfgPath, datPath, cfgPath2, datPath2;
|
||||||
String ip = eventAnalysis.getIp();
|
String ip = eventAnalysis.getIp();
|
||||||
if (generalInfo.getBusinessWaveFileStorage() == GeneralConstant.LOCAL_DISK) {
|
if (generalInfo.getBusinessWaveFileStorage() == GeneralConstant.LOCAL_DISK) {
|
||||||
cfgPath = generalInfo.getBusinessWavePath() + File.separator + ip + File.separator + waveName + GeneralConstant.CFG;
|
cfgPath = Objects.isNull(wlFilePath) ? generalInfo.getBusinessWavePath() + File.separator + ip + File.separator + waveName + GeneralConstant.CFG : wlFilePath + GeneralConstant.CFG;
|
||||||
datPath = generalInfo.getBusinessWavePath() + File.separator + ip + File.separator + waveName + GeneralConstant.DAT;
|
datPath = Objects.isNull(wlFilePath) ? generalInfo.getBusinessWavePath() + File.separator + ip + File.separator + waveName + GeneralConstant.DAT : wlFilePath + GeneralConstant.DAT;
|
||||||
log.info("本地磁盘波形文件路径----" + cfgPath);
|
log.info("本地磁盘波形文件路径----" + cfgPath);
|
||||||
InputStream cfgStream = waveFileComponent.getFileInputStreamByFilePath(cfgPath);
|
InputStream cfgStream = waveFileComponent.getFileInputStreamByFilePath(cfgPath);
|
||||||
InputStream datStream = waveFileComponent.getFileInputStreamByFilePath(datPath);
|
InputStream datStream = waveFileComponent.getFileInputStreamByFilePath(datPath);
|
||||||
@@ -60,11 +62,11 @@ public class EventAdvanceServiceImpl implements IEventAdvanceService {
|
|||||||
}
|
}
|
||||||
waveDataDTO = waveFileComponent.getComtrade(cfgStream, datStream, 0);
|
waveDataDTO = waveFileComponent.getComtrade(cfgStream, datStream, 0);
|
||||||
} else {
|
} else {
|
||||||
cfgPath = OssPath.WAVE_DIR + ip + StrUtil.SLASH + waveName + GeneralConstant.CFG;
|
cfgPath = Objects.isNull(wlFilePath) ? OssPath.WAVE_DIR + ip + StrUtil.SLASH + waveName + GeneralConstant.CFG : wlFilePath + GeneralConstant.CFG;
|
||||||
datPath = OssPath.WAVE_DIR + ip + StrUtil.SLASH + waveName + GeneralConstant.DAT;
|
datPath = Objects.isNull(wlFilePath) ? OssPath.WAVE_DIR + ip + StrUtil.SLASH + waveName + GeneralConstant.DAT : wlFilePath + GeneralConstant.DAT;
|
||||||
//适配文件后缀小写
|
//适配文件后缀小写
|
||||||
cfgPath2 = OssPath.WAVE_DIR + ip + StrUtil.SLASH + waveName + GeneralConstant.CFG.toLowerCase();
|
cfgPath2 = Objects.isNull(wlFilePath) ? OssPath.WAVE_DIR + ip + StrUtil.SLASH + waveName + GeneralConstant.CFG.toLowerCase() : wlFilePath + GeneralConstant.CFG.toLowerCase();
|
||||||
datPath2 = OssPath.WAVE_DIR + ip + StrUtil.SLASH + waveName + GeneralConstant.DAT.toLowerCase();
|
datPath2 = Objects.isNull(wlFilePath) ? OssPath.WAVE_DIR + ip + StrUtil.SLASH + waveName + GeneralConstant.DAT.toLowerCase() : wlFilePath + GeneralConstant.DAT.toLowerCase();
|
||||||
log.info("文件服务器波形文件路径----" + cfgPath);
|
log.info("文件服务器波形文件路径----" + cfgPath);
|
||||||
try (
|
try (
|
||||||
InputStream cfgStream = fileStorageUtil.getFileStream(cfgPath);
|
InputStream cfgStream = fileStorageUtil.getFileStream(cfgPath);
|
||||||
@@ -73,7 +75,7 @@ public class EventAdvanceServiceImpl implements IEventAdvanceService {
|
|||||||
if (Objects.isNull(cfgStream) || Objects.isNull(datStream)) {
|
if (Objects.isNull(cfgStream) || Objects.isNull(datStream)) {
|
||||||
throw new BusinessException(WaveFileResponseEnum.ANALYSE_WAVE_NOT_FOUND);
|
throw new BusinessException(WaveFileResponseEnum.ANALYSE_WAVE_NOT_FOUND);
|
||||||
}
|
}
|
||||||
waveDataDTO = waveFileComponent.getComtrade(cfgStream, datStream, 0);
|
waveDataDTO = waveFileComponent.getComtradeNoAddPoints(cfgStream, datStream, 0);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
try {
|
try {
|
||||||
InputStream cfgStream = fileStorageUtil.getFileStream(cfgPath2);
|
InputStream cfgStream = fileStorageUtil.getFileStream(cfgPath2);
|
||||||
@@ -89,8 +91,70 @@ public class EventAdvanceServiceImpl implements IEventAdvanceService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
List<List<Float>> listWaveData = waveDataDTO.getListWaveData();
|
List<List<Float>> listWaveData = waveDataDTO.getListWaveData();
|
||||||
|
// 暂降类型
|
||||||
|
// 创建数据结构
|
||||||
|
QvvrDLL.QvvrDataStruct typeDataStruct = new QvvrDLL.QvvrDataStruct();
|
||||||
|
System.out.println("初始化qvvrdll成功-----------");
|
||||||
|
typeDataStruct.smp_rate = waveDataDTO.getComtradeCfgDTO().getFinalSampleRate();
|
||||||
|
System.out.println("采样率-----------" + typeDataStruct.smp_rate);
|
||||||
|
typeDataStruct.smp_len = listWaveData.size();
|
||||||
|
System.out.println("波形长度-----------" + listWaveData.size());
|
||||||
|
|
||||||
|
// 获取ABC三相的瞬时数据
|
||||||
|
for (int i = 0; i < listWaveData.size(); i++) {
|
||||||
|
typeDataStruct.smp_va[i] = listWaveData.get(i).get(1);
|
||||||
|
typeDataStruct.smp_vb[i] = listWaveData.get(i).get(2);
|
||||||
|
typeDataStruct.smp_vc[i] = listWaveData.get(i).get(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 执行算法分析 - 直接调用C DLL
|
||||||
|
try {
|
||||||
|
QvvrDLL.INSTANCE.qvvr_fun(typeDataStruct);
|
||||||
|
System.out.println("调用qvvrdll成功-----------");
|
||||||
|
|
||||||
|
if (typeDataStruct.evt_num > 0) {
|
||||||
|
// 全局比较找出最小三相电压特征值
|
||||||
|
float globalMinVoltage = Float.MAX_VALUE;
|
||||||
|
int globalFaultType = 10;
|
||||||
|
for (int i = 0; i < typeDataStruct.evt_num; i++) {
|
||||||
|
QvvrDLL.EventBuffer evt = typeDataStruct.evt_buf[i];
|
||||||
|
for (int j = 0; j < evt.u_min_num; j++) {
|
||||||
|
float u3min = evt.u3_min[j];
|
||||||
|
if (u3min < globalMinVoltage) {
|
||||||
|
globalMinVoltage = u3min;
|
||||||
|
globalFaultType = evt.qvvr_cata_type[j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String str = WriteData2File(typeDataStruct);
|
||||||
|
if (Objects.isNull(wlFilePath)) {
|
||||||
|
String hdrPath = OssPath.WAVE_DIR + ip+StrUtil.SLASH;
|
||||||
|
String hdrName = waveName + GeneralConstant.HDR_LOWER;
|
||||||
|
fileStorageUtil.uploadStreamSpecifyName(new ByteArrayInputStream(str.getBytes()),hdrPath,hdrName);
|
||||||
|
} else {
|
||||||
|
// comtrade/00:B7:8D:00:A8:7A/PQMonitor_PQM1_00100_20260204_162453_071_WAV.hdr
|
||||||
|
String fullPath = wlFilePath + GeneralConstant.HDR_LOWER;
|
||||||
|
int lastSlashIndex = fullPath.lastIndexOf('/');
|
||||||
|
String hdrPath = fullPath.substring(0, lastSlashIndex + 1);
|
||||||
|
String hdrName = fullPath.substring(lastSlashIndex + 1);
|
||||||
|
fileStorageUtil.uploadStreamSpecifyName(new ByteArrayInputStream(str.getBytes()),hdrPath,hdrName);
|
||||||
|
}
|
||||||
|
|
||||||
|
//上传HR
|
||||||
|
eventAnalysis.setType(globalFaultType);
|
||||||
|
} else {
|
||||||
|
eventAnalysis.setType(DataFeature.TYPE10);
|
||||||
|
}
|
||||||
|
System.out.println("结束qvvrdll方法调用-----------");
|
||||||
|
} catch (Exception e) {
|
||||||
|
eventAnalysis.setType(DataFeature.TYPE10);
|
||||||
|
eventAnalysis.setTypeFlag(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// 暂降原因JNA的方式
|
// 暂降原因JNA的方式
|
||||||
com.njcn.advance.event.cause.jna.QvvrCauseDLL.QvvrDataStruct causeDataStruct = new com.njcn.advance.event.cause.jna.QvvrCauseDLL.QvvrDataStruct();
|
QvvrCauseDLL.QvvrDataStruct causeDataStruct = new QvvrCauseDLL.QvvrDataStruct();
|
||||||
causeDataStruct.smp_rate = waveDataDTO.getComtradeCfgDTO().getFinalSampleRate();
|
causeDataStruct.smp_rate = waveDataDTO.getComtradeCfgDTO().getFinalSampleRate();
|
||||||
causeDataStruct.smp_len = listWaveData.size();
|
causeDataStruct.smp_len = listWaveData.size();
|
||||||
// 获取ABC三相的瞬时数据
|
// 获取ABC三相的瞬时数据
|
||||||
@@ -112,45 +176,308 @@ public class EventAdvanceServiceImpl implements IEventAdvanceService {
|
|||||||
}
|
}
|
||||||
System.out.println("暂降原因分析完毕===============");
|
System.out.println("暂降原因分析完毕===============");
|
||||||
System.out.println("cause:" + eventAnalysis);
|
System.out.println("cause:" + eventAnalysis);
|
||||||
|
|
||||||
// 暂降类型
|
|
||||||
// 创建数据结构
|
|
||||||
// com.njcn.advance.event.type.jna.QvvrDLL.QvvrDataStruct typeDataStruct = new com.njcn.advance.event.type.jna.QvvrDLL.QvvrDataStruct();
|
|
||||||
// typeDataStruct.smp_rate = waveDataDTO.getComtradeCfgDTO().getFinalSampleRate();
|
|
||||||
// typeDataStruct.smp_len = listWaveData.size();
|
|
||||||
// // 获取ABC三相的瞬时数据
|
|
||||||
// for (int i = 0; i < listWaveData.size(); i++) {
|
|
||||||
// typeDataStruct.smp_va[i] = listWaveData.get(i).get(1);
|
|
||||||
// typeDataStruct.smp_vb[i] = listWaveData.get(i).get(2);
|
|
||||||
// typeDataStruct.smp_vc[i] = listWaveData.get(i).get(3);
|
|
||||||
// }
|
|
||||||
// // 执行算法分析 - 直接调用C DLL
|
|
||||||
// try {
|
|
||||||
// QvvrDLL.INSTANCE.qvvr_fun(typeDataStruct);
|
|
||||||
// if (typeDataStruct.evt_num > 0) {
|
|
||||||
// // 全局比较找出最小三相电压特征值
|
|
||||||
// float globalMinVoltage = Float.MAX_VALUE;
|
|
||||||
// int globalFaultType = 10;
|
|
||||||
// for (int i = 0; i < typeDataStruct.evt_num; i++) {
|
|
||||||
// QvvrDLL.EventBuffer evt = typeDataStruct.evt_buf[i];
|
|
||||||
// for (int j = 0; j < evt.u_min_num; j++) {
|
|
||||||
// float u3min = evt.u3_min[j];
|
|
||||||
// if (u3min < globalMinVoltage) {
|
|
||||||
// globalMinVoltage = u3min;
|
|
||||||
// globalFaultType = evt.qvvr_cata_type[j];
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// eventAnalysis.setType(globalFaultType);
|
|
||||||
// } else {
|
|
||||||
// eventAnalysis.setType(DataFeature.TYPE10);
|
|
||||||
// }
|
|
||||||
// } catch (Exception e) {
|
|
||||||
// eventAnalysis.setType(DataFeature.TYPE10);
|
|
||||||
// eventAnalysis.setTypeFlag(0);
|
|
||||||
// }
|
|
||||||
return eventAnalysis;
|
return eventAnalysis;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String WriteData2File(QvvrDLL.QvvrDataStruct rect) throws Exception {
|
||||||
|
StringBuilder stringBuilder = new StringBuilder("{" + EnumEvt.NEWLINE.getProperty());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @写入返回事件总数
|
||||||
|
*/
|
||||||
|
stringBuilder.append(EnumEvt.setEvtProperty(EnumEvt.EVT_NUM.getProperty()));
|
||||||
|
stringBuilder.append(EnumEvt.setEnter(Utils.int2String(rect.evt_num), 1));
|
||||||
|
stringBuilder.append(EnumEvt.setEvtProperty(EnumEvt.EVT_BUF.getProperty()) + "[");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @写入返回事件参数
|
||||||
|
*/
|
||||||
|
for (int i = 0; i < rect.evt_num; i++) {
|
||||||
|
stringBuilder.append(EnumEvt.setNewLine() + EnumEvt.setTab(2));
|
||||||
|
/**
|
||||||
|
* @波形起始点
|
||||||
|
*/
|
||||||
|
stringBuilder.append(EnumEvt.setEvtProperty(EnumEvt.POW_A.getProperty()));
|
||||||
|
stringBuilder.append(EnumEvt.setEnter(Utils.float2String(rect.evt_buf[i].POW_a), 3));
|
||||||
|
stringBuilder.append(EnumEvt.setEvtProperty(EnumEvt.POW_B.getProperty()));
|
||||||
|
stringBuilder.append(EnumEvt.setEnter(Utils.float2String(rect.evt_buf[i].POW_b), 3));
|
||||||
|
stringBuilder.append(EnumEvt.setEvtProperty(EnumEvt.POW_C.getProperty()));
|
||||||
|
stringBuilder.append(EnumEvt.setEnter(Utils.float2String(rect.evt_buf[i].POW_c), 3));
|
||||||
|
/**
|
||||||
|
* @跳变段电压变化率
|
||||||
|
*/
|
||||||
|
stringBuilder.append(EnumEvt.setEvtProperty(EnumEvt.VOLTAGECHANGE_VA.getProperty()));
|
||||||
|
stringBuilder.append(EnumEvt.setEnter(Utils.float2String(rect.evt_buf[i].Voltagechange_Va), 3));
|
||||||
|
stringBuilder.append(EnumEvt.setEvtProperty(EnumEvt.VOLTAGECHANGE_VB.getProperty()));
|
||||||
|
stringBuilder.append(EnumEvt.setEnter(Utils.float2String(rect.evt_buf[i].Voltagechange_Vb), 3));
|
||||||
|
stringBuilder.append(EnumEvt.setEvtProperty(EnumEvt.VOLTAGECHANGE_VC.getProperty()));
|
||||||
|
stringBuilder.append(EnumEvt.setEnter(Utils.float2String(rect.evt_buf[i].Voltagechange_Vc), 3));
|
||||||
|
/**
|
||||||
|
* @持续时间
|
||||||
|
*/
|
||||||
|
stringBuilder.append(EnumEvt.setEvtProperty(EnumEvt.HOLD_TIME_RMS.getProperty()));
|
||||||
|
stringBuilder.append(EnumEvt.setEnter(Utils.float2String(rect.evt_buf[i].hold_time_rms), 3));
|
||||||
|
stringBuilder.append(EnumEvt.setEvtProperty(EnumEvt.HOLD_TIME_DQ.getProperty()));
|
||||||
|
stringBuilder.append(EnumEvt.setEnter(Utils.float2String(rect.evt_buf[i].hold_time_dq), 3));
|
||||||
|
/**
|
||||||
|
* @分段数目
|
||||||
|
*/
|
||||||
|
stringBuilder.append(EnumEvt.setEvtProperty(EnumEvt.SEG_T_NUM.getProperty()));
|
||||||
|
stringBuilder.append(EnumEvt.setEnter(Utils.int2String(rect.evt_buf[i].SEG_T_num), 3));
|
||||||
|
stringBuilder.append(EnumEvt.setEvtProperty(EnumEvt.SEG_T_IDX.getProperty()));
|
||||||
|
stringBuilder.append(EnumEvt.setNewLine() + EnumEvt.setTab(3));
|
||||||
|
|
||||||
|
for (int j = 0; j < rect.evt_buf[i].SEG_T_num; j++) {
|
||||||
|
stringBuilder.append(EnumEvt.setEvtProperty(Utils.int2String(j)));
|
||||||
|
|
||||||
|
if (rect.evt_buf[i].SEG_T_num - 1 == j) {
|
||||||
|
stringBuilder.append(Utils.int2String(rect.evt_buf[i].SEG_T_idx[j]));
|
||||||
|
} else {
|
||||||
|
stringBuilder.append(EnumEvt.setEnter(Utils.int2String(rect.evt_buf[i].SEG_T_idx[j]), 4));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stringBuilder.append(EnumEvt.setEnter(EnumEvt.setClose(3), 3));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @特征幅值
|
||||||
|
*/
|
||||||
|
stringBuilder.append(EnumEvt.setEvtProperty(EnumEvt.U_MIN_NUM.getProperty()));
|
||||||
|
stringBuilder.append(EnumEvt.setEnter(Utils.int2String(rect.evt_buf[i].u_min_num), 3));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @最小值位置
|
||||||
|
*/
|
||||||
|
for (int k = 0; k < rect.evt_buf[i].u_min_num; k++) {
|
||||||
|
setEigenVlaue(k, stringBuilder, EnumEvt.ORDER_MIN_IDX.getProperty(), null,
|
||||||
|
rect.evt_buf[i].order_min_idx[k]);
|
||||||
|
|
||||||
|
if (rect.evt_buf[i].u_min_num - 1 == k) {
|
||||||
|
stringBuilder.delete(stringBuilder.lastIndexOf(","), stringBuilder.length() - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stringBuilder.append(EnumEvt.setEnter(EnumEvt.setClose(3), 3));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @A相电压特征值
|
||||||
|
*/
|
||||||
|
for (int k = 0; k < rect.evt_buf[i].u_min_num; k++) {
|
||||||
|
setEigenVlaue(k, stringBuilder, EnumEvt.UA_MIN.getProperty(), rect.evt_buf[i].ua_min[k], null);
|
||||||
|
|
||||||
|
if (rect.evt_buf[i].u_min_num - 1 == k) {
|
||||||
|
stringBuilder.delete(stringBuilder.lastIndexOf(","), stringBuilder.length() - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stringBuilder.append(EnumEvt.setEnter(EnumEvt.setClose(3), 3));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @B相电压特征值
|
||||||
|
*/
|
||||||
|
for (int k = 0; k < rect.evt_buf[i].u_min_num; k++) {
|
||||||
|
setEigenVlaue(k, stringBuilder, EnumEvt.UB_MIN.getProperty(), rect.evt_buf[i].ub_min[k], null);
|
||||||
|
|
||||||
|
if (rect.evt_buf[i].u_min_num - 1 == k) {
|
||||||
|
stringBuilder.delete(stringBuilder.lastIndexOf(","), stringBuilder.length() - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stringBuilder.append(EnumEvt.setEnter(EnumEvt.setClose(3), 3));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @C相电压特征值
|
||||||
|
*/
|
||||||
|
for (int k = 0; k < rect.evt_buf[i].u_min_num; k++) {
|
||||||
|
setEigenVlaue(k, stringBuilder, EnumEvt.UC_MIN.getProperty(), rect.evt_buf[i].uc_min[k], null);
|
||||||
|
|
||||||
|
if (rect.evt_buf[i].u_min_num - 1 == k) {
|
||||||
|
stringBuilder.delete(stringBuilder.lastIndexOf(","), stringBuilder.length() - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stringBuilder.append(EnumEvt.setEnter(EnumEvt.setClose(3), 3));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @三相电压特征值
|
||||||
|
*/
|
||||||
|
for (int k = 0; k < rect.evt_buf[i].u_min_num; k++) {
|
||||||
|
setEigenVlaue(k, stringBuilder, EnumEvt.U3_MIN.getProperty(), rect.evt_buf[i].u3_min[k], null);
|
||||||
|
|
||||||
|
if (rect.evt_buf[i].u_min_num - 1 == k) {
|
||||||
|
stringBuilder.delete(stringBuilder.lastIndexOf(","), stringBuilder.length() - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stringBuilder.append(EnumEvt.setEnter(EnumEvt.setClose(3), 3));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @A相相位正跳变
|
||||||
|
*/
|
||||||
|
for (int k = 0; k < rect.evt_buf[i].u_min_num; k++) {
|
||||||
|
setEigenVlaue(k, stringBuilder, EnumEvt.ANGLE_DIFF_AP.getProperty(), rect.evt_buf[i].angle_diff_ap[k],
|
||||||
|
null);
|
||||||
|
|
||||||
|
if (rect.evt_buf[i].u_min_num - 1 == k) {
|
||||||
|
stringBuilder.delete(stringBuilder.lastIndexOf(","), stringBuilder.length() - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stringBuilder.append(EnumEvt.setEnter(EnumEvt.setClose(3), 3));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @B相相位正跳变
|
||||||
|
*/
|
||||||
|
for (int k = 0; k < rect.evt_buf[i].u_min_num; k++) {
|
||||||
|
setEigenVlaue(k, stringBuilder, EnumEvt.ANGLE_DIFF_BP.getProperty(), rect.evt_buf[i].angle_diff_bp[k],
|
||||||
|
null);
|
||||||
|
|
||||||
|
if (rect.evt_buf[i].u_min_num - 1 == k) {
|
||||||
|
stringBuilder.delete(stringBuilder.lastIndexOf(","), stringBuilder.length() - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stringBuilder.append(EnumEvt.setEnter(EnumEvt.setClose(3), 3));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @C相相位正跳变
|
||||||
|
*/
|
||||||
|
for (int k = 0; k < rect.evt_buf[i].u_min_num; k++) {
|
||||||
|
setEigenVlaue(k, stringBuilder, EnumEvt.ANGLE_DIFF_CP.getProperty(), rect.evt_buf[i].angle_diff_cp[k],
|
||||||
|
null);
|
||||||
|
|
||||||
|
if (rect.evt_buf[i].u_min_num - 1 == k) {
|
||||||
|
stringBuilder.delete(stringBuilder.lastIndexOf(","), stringBuilder.length() - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stringBuilder.append(EnumEvt.setEnter(EnumEvt.setClose(3), 3));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @A相相位负跳变
|
||||||
|
*/
|
||||||
|
for (int k = 0; k < rect.evt_buf[i].u_min_num; k++) {
|
||||||
|
setEigenVlaue(k, stringBuilder, EnumEvt.ANGLE_DIFF_AN.getProperty(), rect.evt_buf[i].angle_diff_an[k],
|
||||||
|
null);
|
||||||
|
|
||||||
|
if (rect.evt_buf[i].u_min_num - 1 == k) {
|
||||||
|
stringBuilder.delete(stringBuilder.lastIndexOf(","), stringBuilder.length() - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stringBuilder.append(EnumEvt.setEnter(EnumEvt.setClose(3), 3));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @B相相位负跳变
|
||||||
|
*/
|
||||||
|
for (int k = 0; k < rect.evt_buf[i].u_min_num; k++) {
|
||||||
|
setEigenVlaue(k, stringBuilder, EnumEvt.ANGLE_DIFF_BN.getProperty(), rect.evt_buf[i].angle_diff_bn[k],
|
||||||
|
null);
|
||||||
|
|
||||||
|
if (rect.evt_buf[i].u_min_num - 1 == k) {
|
||||||
|
stringBuilder.delete(stringBuilder.lastIndexOf(","), stringBuilder.length() - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stringBuilder.append(EnumEvt.setEnter(EnumEvt.setClose(3), 3));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @C相相位负跳变
|
||||||
|
*/
|
||||||
|
for (int k = 0; k < rect.evt_buf[i].u_min_num; k++) {
|
||||||
|
setEigenVlaue(k, stringBuilder, EnumEvt.ANGLE_DIFF_CN.getProperty(), rect.evt_buf[i].angle_diff_cn[k],
|
||||||
|
null);
|
||||||
|
|
||||||
|
if (rect.evt_buf[i].u_min_num - 1 == k) {
|
||||||
|
stringBuilder.delete(stringBuilder.lastIndexOf(","), stringBuilder.length() - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stringBuilder.append(EnumEvt.setEnter(EnumEvt.setClose(3), 3));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @不平衡度
|
||||||
|
*/
|
||||||
|
for (int k = 0; k < rect.evt_buf[i].u_min_num; k++) {
|
||||||
|
setEigenVlaue(k, stringBuilder, EnumEvt.BPH_MAX_VALUE.getProperty(), rect.evt_buf[i].bph_max_value[k],
|
||||||
|
null);
|
||||||
|
|
||||||
|
if (rect.evt_buf[i].u_min_num - 1 == k) {
|
||||||
|
stringBuilder.delete(stringBuilder.lastIndexOf(","), stringBuilder.length() - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stringBuilder.append(EnumEvt.setEnter(EnumEvt.setClose(3), 3));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @暂降原因
|
||||||
|
*/
|
||||||
|
for (int k = 0; k < rect.evt_buf[i].u_min_num; k++) {
|
||||||
|
setEigenVlaue(k, stringBuilder, EnumEvt.QVVR_CATA_CAUSE.getProperty(), null,
|
||||||
|
rect.evt_buf[i].qvvr_cata_cause[k]);
|
||||||
|
|
||||||
|
if (rect.evt_buf[i].u_min_num - 1 == k) {
|
||||||
|
stringBuilder.delete(stringBuilder.lastIndexOf(","), stringBuilder.length() - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stringBuilder.append(EnumEvt.setEnter(EnumEvt.setClose(3), 3));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @暂降类型
|
||||||
|
*/
|
||||||
|
for (int k = 0; k < rect.evt_buf[i].u_min_num; k++) {
|
||||||
|
setEigenVlaue(k, stringBuilder, EnumEvt.QVVR_CATA_TYPE.getProperty(), null,
|
||||||
|
rect.evt_buf[i].qvvr_cata_type[k]);
|
||||||
|
|
||||||
|
if (rect.evt_buf[i].u_min_num - 1 == k) {
|
||||||
|
stringBuilder.delete(stringBuilder.lastIndexOf(","), stringBuilder.length() - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stringBuilder.append(EnumEvt.setEnter(EnumEvt.setClose(3), 3));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @暂降相别
|
||||||
|
*/
|
||||||
|
for (int k = 0; k < rect.evt_buf[i].u_min_num; k++) {
|
||||||
|
setEigenVlaue(k, stringBuilder, EnumEvt.QVVR_PHASETYPE.getProperty(), null,
|
||||||
|
rect.evt_buf[i].qvvr_phasetype[k]);
|
||||||
|
|
||||||
|
if (rect.evt_buf[i].u_min_num - 1 == k) {
|
||||||
|
stringBuilder.delete(stringBuilder.lastIndexOf(","), stringBuilder.length() - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stringBuilder.append(EnumEvt.setClose(3));
|
||||||
|
|
||||||
|
if (rect.evt_num - 1 == i) {
|
||||||
|
stringBuilder.append(EnumEvt.setClose(2));
|
||||||
|
stringBuilder.append("]" + EnumEvt.ENTER.getProperty());
|
||||||
|
} else {
|
||||||
|
stringBuilder.append(EnumEvt.setEnter(EnumEvt.setClose(2), 2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stringBuilder.append("}");
|
||||||
|
return stringBuilder.toString();
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @特征值处理
|
||||||
|
*/
|
||||||
|
public void setEigenVlaue(int len, StringBuilder stringBuilder, String string, Float f, Integer integer) {
|
||||||
|
if (0 == len) {
|
||||||
|
stringBuilder.append(EnumEvt.setEvtProperty(string));
|
||||||
|
stringBuilder.append(EnumEvt.setNewLine() + EnumEvt.setTab(3));
|
||||||
|
}
|
||||||
|
|
||||||
|
stringBuilder.append(EnumEvt.setEvtProperty(Integer.toString(len)));
|
||||||
|
|
||||||
|
if (null == f) {
|
||||||
|
stringBuilder.append(EnumEvt.setEnter(Utils.int2String(integer.intValue()), 4));
|
||||||
|
} else {
|
||||||
|
stringBuilder.append(EnumEvt.setEnter(Utils.float2String(f.floatValue()), 4));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,9 @@ public interface QvvrDLL extends Library {
|
|||||||
|
|
||||||
// 创建临时文件
|
// 创建临时文件
|
||||||
String tempDir = System.getProperty("java.io.tmpdir");
|
String tempDir = System.getProperty("java.io.tmpdir");
|
||||||
File tempLibFile = new File(tempDir, "qvvr_" + System.currentTimeMillis() + "_" + libFileName);
|
File tempLibFile = new File(tempDir, libFileName);
|
||||||
|
|
||||||
|
// File tempLibFile = new File(tempDir, "qvvr_" + System.currentTimeMillis() + "_" + libFileName);
|
||||||
|
|
||||||
// 提取库文件到临时目录
|
// 提取库文件到临时目录
|
||||||
try (FileOutputStream out = new FileOutputStream(tempLibFile)) {
|
try (FileOutputStream out = new FileOutputStream(tempLibFile)) {
|
||||||
@@ -95,6 +97,8 @@ public interface QvvrDLL extends Library {
|
|||||||
*/
|
*/
|
||||||
void qvvr_fun(QvvrDataStruct data);
|
void qvvr_fun(QvvrDataStruct data);
|
||||||
|
|
||||||
|
void ping();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对应C语言的qvvr_data_struct结构体
|
* 对应C语言的qvvr_data_struct结构体
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -0,0 +1,381 @@
|
|||||||
|
package com.njcn.advance.responsibility.analysis;
|
||||||
|
|
||||||
|
import com.njcn.advance.responsibility.constant.HarmonicConstants;
|
||||||
|
import com.njcn.advance.responsibility.utils.MathUtils;
|
||||||
|
import org.apache.commons.math3.linear.*;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 典则相关分析类
|
||||||
|
* 实现典则相关系数的计算
|
||||||
|
*
|
||||||
|
* @author hongawen
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
public class CanonicalCorrelationAnalysis {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(CanonicalCorrelationAnalysis.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算典则相关系数
|
||||||
|
* 对应C代码中的TransCancor函数
|
||||||
|
*
|
||||||
|
* @param powerData 功率数据矩阵 [时间][节点]
|
||||||
|
* @param harmonicData 谐波数据向量
|
||||||
|
* @param windowSize 窗口大小
|
||||||
|
* @param nodeCount 节点数量
|
||||||
|
* @return 典则相关系数
|
||||||
|
*/
|
||||||
|
public static float computeCanonicalCorrelation(float[][] powerData, float[] harmonicData,
|
||||||
|
int windowSize, int nodeCount) {
|
||||||
|
logger.info("===== 开始典型相关分析 =====");
|
||||||
|
logger.info("输入参数: windowSize={}, nodeCount={}", windowSize, nodeCount);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 提取窗口数据
|
||||||
|
double[][] x = new double[windowSize][nodeCount];
|
||||||
|
double[] y = new double[windowSize];
|
||||||
|
|
||||||
|
// ===== 数据质量统计(只统计,不影响计算) =====
|
||||||
|
int nanCountPower = 0, infiniteCountPower = 0, zeroCountPower = 0;
|
||||||
|
int nanCountHarmonic = 0, infiniteCountHarmonic = 0, zeroCountHarmonic = 0;
|
||||||
|
double powerSum = 0, harmonicSum = 0;
|
||||||
|
double powerMin = Double.MAX_VALUE, powerMax = -Double.MAX_VALUE;
|
||||||
|
double harmonicMin = Double.MAX_VALUE, harmonicMax = -Double.MAX_VALUE;
|
||||||
|
|
||||||
|
for (int i = 0; i < windowSize; i++) {
|
||||||
|
for (int j = 0; j < nodeCount; j++) {
|
||||||
|
float val = powerData[i][j];
|
||||||
|
x[i][j] = val;
|
||||||
|
|
||||||
|
// 仅统计,不改变原逻辑
|
||||||
|
if (Float.isNaN(val)) {
|
||||||
|
nanCountPower++;
|
||||||
|
} else if (Float.isInfinite(val)) {
|
||||||
|
infiniteCountPower++;
|
||||||
|
} else if (val == 0.0f) {
|
||||||
|
zeroCountPower++;
|
||||||
|
} else {
|
||||||
|
powerSum += val;
|
||||||
|
powerMin = Math.min(powerMin, val);
|
||||||
|
powerMax = Math.max(powerMax, val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float harmonicVal = harmonicData[i];
|
||||||
|
y[i] = harmonicVal;
|
||||||
|
|
||||||
|
// 仅统计,不改变原逻辑
|
||||||
|
if (Float.isNaN(harmonicVal)) {
|
||||||
|
nanCountHarmonic++;
|
||||||
|
} else if (Float.isInfinite(harmonicVal)) {
|
||||||
|
infiniteCountHarmonic++;
|
||||||
|
} else if (harmonicVal == 0.0f) {
|
||||||
|
zeroCountHarmonic++;
|
||||||
|
} else {
|
||||||
|
harmonicSum += harmonicVal;
|
||||||
|
harmonicMin = Math.min(harmonicMin, harmonicVal);
|
||||||
|
harmonicMax = Math.max(harmonicMax, harmonicVal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===== 数据质量报告(只记录日志) =====
|
||||||
|
int totalPowerCount = windowSize * nodeCount;
|
||||||
|
int totalHarmonicCount = windowSize;
|
||||||
|
|
||||||
|
logger.info("功率数据质量分析:");
|
||||||
|
logger.info(" 总数据点: {}", totalPowerCount);
|
||||||
|
logger.info(" NaN数量: {} ({:.2f}%)", nanCountPower, nanCountPower * 100.0 / totalPowerCount);
|
||||||
|
logger.info(" 无穷大数量: {} ({:.2f}%)", infiniteCountPower, infiniteCountPower * 100.0 / totalPowerCount);
|
||||||
|
logger.info(" 零值数量: {} ({:.2f}%)", zeroCountPower, zeroCountPower * 100.0 / totalPowerCount);
|
||||||
|
logger.info(" 有效数据范围: [{}, {}]", powerMin == Double.MAX_VALUE ? "N/A" : powerMin,
|
||||||
|
powerMax == -Double.MAX_VALUE ? "N/A" : powerMax);
|
||||||
|
|
||||||
|
logger.info("谐波数据质量分析:");
|
||||||
|
logger.info(" 总数据点: {}", totalHarmonicCount);
|
||||||
|
logger.info(" NaN数量: {} ({:.2f}%)", nanCountHarmonic, nanCountHarmonic * 100.0 / totalHarmonicCount);
|
||||||
|
logger.info(" 无穷大数量: {} ({:.2f}%)", infiniteCountHarmonic, infiniteCountHarmonic * 100.0 / totalHarmonicCount);
|
||||||
|
logger.info(" 零值数量: {} ({:.2f}%)", zeroCountHarmonic, zeroCountHarmonic * 100.0 / totalHarmonicCount);
|
||||||
|
logger.info(" 有效数据范围: [{}, {}]", harmonicMin == Double.MAX_VALUE ? "N/A" : harmonicMin,
|
||||||
|
harmonicMax == -Double.MAX_VALUE ? "N/A" : harmonicMax);
|
||||||
|
|
||||||
|
// 只记录警告,不停止计算
|
||||||
|
if (nanCountPower > 0 || infiniteCountPower > 0) {
|
||||||
|
logger.warn("功率数据包含异常值!NaN: {}, Infinite: {}", nanCountPower, infiniteCountPower);
|
||||||
|
}
|
||||||
|
if (nanCountHarmonic > 0 || infiniteCountHarmonic > 0) {
|
||||||
|
logger.warn("谐波数据包含异常值!NaN: {}, Infinite: {}", nanCountHarmonic, infiniteCountHarmonic);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算协方差矩阵 SXX
|
||||||
|
logger.info("===== 开始协方差计算 =====");
|
||||||
|
double[][] sxxMatrix = MathUtils.covarianceMatrix(x, windowSize, nodeCount);
|
||||||
|
|
||||||
|
// ===== SXX矩阵诊断(只记录日志)=====
|
||||||
|
double sxxTrace = 0;
|
||||||
|
double sxxFrobeniusNorm = 0;
|
||||||
|
boolean sxxHasNaN = false, sxxHasInfinite = false;
|
||||||
|
|
||||||
|
for (int i = 0; i < nodeCount; i++) {
|
||||||
|
sxxTrace += sxxMatrix[i][i];
|
||||||
|
for (int j = 0; j < nodeCount; j++) {
|
||||||
|
double val = sxxMatrix[i][j];
|
||||||
|
if (Double.isNaN(val)) {
|
||||||
|
sxxHasNaN = true;
|
||||||
|
}
|
||||||
|
if (Double.isInfinite(val)) {
|
||||||
|
sxxHasInfinite = true;
|
||||||
|
}
|
||||||
|
sxxFrobeniusNorm += val * val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sxxFrobeniusNorm = Math.sqrt(sxxFrobeniusNorm);
|
||||||
|
|
||||||
|
logger.info("SXX矩阵诊断:");
|
||||||
|
logger.info(" 维度: {}x{}", nodeCount, nodeCount);
|
||||||
|
logger.info(" 迹(trace): {}", sxxTrace);
|
||||||
|
logger.info(" Frobenius范数: {}", sxxFrobeniusNorm);
|
||||||
|
logger.info(" 包含NaN: {}", sxxHasNaN);
|
||||||
|
logger.info(" 包含无穷大: {}", sxxHasInfinite);
|
||||||
|
logger.info(" 对角线元素: {}", java.util.Arrays.toString(
|
||||||
|
java.util.stream.IntStream.range(0, nodeCount)
|
||||||
|
.mapToDouble(i -> sxxMatrix[i][i])
|
||||||
|
.toArray()));
|
||||||
|
|
||||||
|
// 计算协方差 SYY
|
||||||
|
double syyMatrix = MathUtils.covariance(y, y, windowSize);
|
||||||
|
logger.info("SYY协方差: {}", syyMatrix);
|
||||||
|
|
||||||
|
if (Math.abs(syyMatrix) < HarmonicConstants.MIN_COVARIANCE) {
|
||||||
|
logger.warn("SYY过小 ({}), 调整为最小值: {}", syyMatrix, HarmonicConstants.MIN_COVARIANCE);
|
||||||
|
syyMatrix = HarmonicConstants.MIN_COVARIANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算协方差向量 SXY
|
||||||
|
double[] sxyVector = MathUtils.covarianceVector(x, y, windowSize, nodeCount);
|
||||||
|
|
||||||
|
// ===== SXY向量诊断(只记录日志)=====
|
||||||
|
double sxyNorm = 0;
|
||||||
|
boolean sxyHasNaN = false, sxyHasInfinite = false;
|
||||||
|
for (double val : sxyVector) {
|
||||||
|
if (Double.isNaN(val)) {
|
||||||
|
sxyHasNaN = true;
|
||||||
|
}
|
||||||
|
if (Double.isInfinite(val)) {
|
||||||
|
sxyHasInfinite = true;
|
||||||
|
}
|
||||||
|
sxyNorm += val * val;
|
||||||
|
}
|
||||||
|
sxyNorm = Math.sqrt(sxyNorm);
|
||||||
|
|
||||||
|
logger.info("SXY向量诊断:");
|
||||||
|
logger.info(" 长度: {}", sxyVector.length);
|
||||||
|
logger.info(" L2范数: {}", sxyNorm);
|
||||||
|
logger.info(" 包含NaN: {}", sxyHasNaN);
|
||||||
|
logger.info(" 包含无穷大: {}", sxyHasInfinite);
|
||||||
|
logger.info(" 向量值: {}", java.util.Arrays.toString(sxyVector));
|
||||||
|
|
||||||
|
// 使用Apache Commons Math进行矩阵运算
|
||||||
|
logger.info("===== 开始矩阵分解 =====");
|
||||||
|
RealMatrix sxx = new Array2DRowRealMatrix(sxxMatrix);
|
||||||
|
RealVector sxy = new ArrayRealVector(sxyVector);
|
||||||
|
|
||||||
|
// 计算 SXX^(-1)
|
||||||
|
logger.info("准备计算SXX逆矩阵...");
|
||||||
|
DecompositionSolver solver = new LUDecomposition(sxx).getSolver();
|
||||||
|
RealMatrix invSxx;
|
||||||
|
|
||||||
|
// 检查矩阵奇异性
|
||||||
|
double sxxDet = new LUDecomposition(sxx).getDeterminant();
|
||||||
|
logger.info("SXX矩阵行列式: {}", sxxDet);
|
||||||
|
|
||||||
|
if (Math.abs(sxxDet) < 1e-15) {
|
||||||
|
logger.warn("SXX矩阵几乎奇异 (det={})", sxxDet);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!solver.isNonSingular()) {
|
||||||
|
// 如果矩阵奇异,使用伪逆
|
||||||
|
logger.warn("SXX matrix is singular, using pseudo-inverse");
|
||||||
|
try {
|
||||||
|
SingularValueDecomposition svd = new SingularValueDecomposition(sxx);
|
||||||
|
invSxx = svd.getSolver().getInverse();
|
||||||
|
} catch (Exception svdException) {
|
||||||
|
logger.error("SVD pseudo-inverse failed, using regularized inverse", svdException);
|
||||||
|
// 添加正则化项
|
||||||
|
RealMatrix identity = MatrixUtils.createRealIdentityMatrix(sxx.getRowDimension());
|
||||||
|
RealMatrix regularized = sxx.add(identity.scalarMultiply(1e-10));
|
||||||
|
invSxx = new LUDecomposition(regularized).getSolver().getInverse();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
invSxx = solver.getInverse();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算 U = SXX^(-1) * SXY * (1/SYY) * SXY'
|
||||||
|
RealVector temp = invSxx.operate(sxy);
|
||||||
|
double scale = 1.0 / syyMatrix;
|
||||||
|
RealMatrix uMatrix = temp.outerProduct(sxy).scalarMultiply(scale);
|
||||||
|
|
||||||
|
// 计算特征值 - 添加数值稳定性处理
|
||||||
|
double maxEigenvalue = 0.0;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 首先检查矩阵是否有效
|
||||||
|
double[][] uMatrixData = uMatrix.getData();
|
||||||
|
boolean hasNaN = false;
|
||||||
|
boolean hasInfinite = false;
|
||||||
|
|
||||||
|
for (int i = 0; i < uMatrixData.length; i++) {
|
||||||
|
for (int j = 0; j < uMatrixData[i].length; j++) {
|
||||||
|
if (Double.isNaN(uMatrixData[i][j])) {
|
||||||
|
hasNaN = true;
|
||||||
|
}
|
||||||
|
if (Double.isInfinite(uMatrixData[i][j])) {
|
||||||
|
hasInfinite = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasNaN || hasInfinite) {
|
||||||
|
logger.warn("U matrix contains NaN or Infinite values, returning 0");
|
||||||
|
return 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查矩阵条件数
|
||||||
|
SingularValueDecomposition svdCheck = new SingularValueDecomposition(uMatrix);
|
||||||
|
double conditionNumber = svdCheck.getConditionNumber();
|
||||||
|
|
||||||
|
if (conditionNumber > 1e12) {
|
||||||
|
logger.warn("U matrix is ill-conditioned (condition number: {}), using SVD approach", conditionNumber);
|
||||||
|
|
||||||
|
// 使用SVD方法获取最大奇异值的平方作为最大特征值
|
||||||
|
double[] singularValues = svdCheck.getSingularValues();
|
||||||
|
if (singularValues.length > 0) {
|
||||||
|
maxEigenvalue = singularValues[0] * singularValues[0];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 正常的特征值分解
|
||||||
|
EigenDecomposition eigenDecomposition = new EigenDecomposition(uMatrix);
|
||||||
|
double[] eigenvalues = eigenDecomposition.getRealEigenvalues();
|
||||||
|
|
||||||
|
// 找最大特征值
|
||||||
|
for (double eigenvalue : eigenvalues) {
|
||||||
|
maxEigenvalue = Math.max(maxEigenvalue, Math.abs(eigenvalue));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception eigenException) {
|
||||||
|
logger.warn("EigenDecomposition failed, trying alternative approach: {}", eigenException.getMessage());
|
||||||
|
|
||||||
|
// 备用方案:使用SVD方法
|
||||||
|
try {
|
||||||
|
SingularValueDecomposition svd = new SingularValueDecomposition(uMatrix);
|
||||||
|
double[] singularValues = svd.getSingularValues();
|
||||||
|
if (singularValues.length > 0) {
|
||||||
|
maxEigenvalue = singularValues[0] * singularValues[0];
|
||||||
|
}
|
||||||
|
} catch (Exception svdException) {
|
||||||
|
logger.error("Both EigenDecomposition and SVD failed, returning 0", svdException);
|
||||||
|
return 0.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 典则相关系数是最大特征值的平方根
|
||||||
|
double canonicalCorr = Math.sqrt(Math.abs(maxEigenvalue));
|
||||||
|
|
||||||
|
// 限制在[0,1]范围内
|
||||||
|
if (canonicalCorr > 1.0) {
|
||||||
|
canonicalCorr = 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("===== 典型相关分析计算完成 =====");
|
||||||
|
logger.info("最大特征值: {}", maxEigenvalue);
|
||||||
|
logger.info("典型相关系数: {}", canonicalCorr);
|
||||||
|
logger.info("是否被截断到1.0: {}", canonicalCorr >= 1.0);
|
||||||
|
|
||||||
|
return (float) canonicalCorr;
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error computing canonical correlation", e);
|
||||||
|
logger.error("异常详情: {}", e.getMessage());
|
||||||
|
logger.error("异常类型: {}", e.getClass().getSimpleName());
|
||||||
|
return 0.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 滑动窗口计算典则相关系数序列
|
||||||
|
* 对应C代码中的SlideCanCor函数
|
||||||
|
*
|
||||||
|
* @param powerData 功率数据矩阵 [时间][节点]
|
||||||
|
* @param harmonicData 谐波数据向量
|
||||||
|
* @param windowSize 窗口大小
|
||||||
|
* @param nodeCount 节点数量
|
||||||
|
* @param dataLength 数据总长度
|
||||||
|
* @return 典则相关系数序列
|
||||||
|
*/
|
||||||
|
public static float[] slidingCanonicalCorrelation(float[][] powerData, float[] harmonicData,
|
||||||
|
int windowSize, int nodeCount, int dataLength) {
|
||||||
|
int slideLength = dataLength - windowSize;
|
||||||
|
if (slideLength <= 0) {
|
||||||
|
throw new IllegalArgumentException("Data length must be greater than window size");
|
||||||
|
}
|
||||||
|
|
||||||
|
float[] slideCanCor = new float[slideLength];
|
||||||
|
|
||||||
|
logger.info("Starting sliding canonical correlation analysis, slide length: {}", slideLength);
|
||||||
|
|
||||||
|
for (int i = 0; i < slideLength; i++) {
|
||||||
|
// 提取窗口数据
|
||||||
|
float[][] windowPower = new float[windowSize][nodeCount];
|
||||||
|
float[] windowHarmonic = new float[windowSize];
|
||||||
|
|
||||||
|
for (int j = 0; j < windowSize; j++) {
|
||||||
|
System.arraycopy(powerData[i + j], 0, windowPower[j], 0, nodeCount);
|
||||||
|
windowHarmonic[j] = harmonicData[i + j];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算当前窗口的典则相关系数
|
||||||
|
slideCanCor[i] = computeCanonicalCorrelation(windowPower, windowHarmonic,
|
||||||
|
windowSize, nodeCount);
|
||||||
|
|
||||||
|
if (i % 10 == 0) {
|
||||||
|
logger.debug("Processed window {}/{}", i, slideLength);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("Sliding canonical correlation analysis completed");
|
||||||
|
|
||||||
|
return slideCanCor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算包含/不包含背景的动态相关系数
|
||||||
|
* 对应C代码中的SlideCor函数
|
||||||
|
*
|
||||||
|
* @param powerData 功率数据(单个节点)
|
||||||
|
* @param harmonicData 谐波数据
|
||||||
|
* @param slideCanCor 滑动典则相关系数
|
||||||
|
* @param windowSize 窗口大小
|
||||||
|
* @return 动态相关系数序列
|
||||||
|
*/
|
||||||
|
public static float[] slidingCorrelation(float[] powerData, float[] harmonicData,
|
||||||
|
float[] slideCanCor, int windowSize) {
|
||||||
|
int slideLength = slideCanCor.length;
|
||||||
|
float[] slideCor = new float[slideLength];
|
||||||
|
|
||||||
|
for (int i = 0; i < slideLength; i++) {
|
||||||
|
float[] tempPower = new float[windowSize];
|
||||||
|
float[] tempHarmonic = new float[windowSize];
|
||||||
|
|
||||||
|
for (int j = 0; j < windowSize; j++) {
|
||||||
|
tempPower[j] = powerData[i + j];
|
||||||
|
tempHarmonic[j] = harmonicData[i + j] * slideCanCor[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
slideCor[i] = MathUtils.pearsonCorrelation(tempHarmonic, tempPower, windowSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
return slideCor;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,424 @@
|
|||||||
|
package com.njcn.advance.responsibility.calculator;
|
||||||
|
|
||||||
|
import com.njcn.advance.responsibility.analysis.CanonicalCorrelationAnalysis;
|
||||||
|
import com.njcn.advance.responsibility.constant.CalculationMode;
|
||||||
|
import com.njcn.advance.responsibility.constant.CalculationStatus;
|
||||||
|
import com.njcn.advance.responsibility.constant.HarmonicConstants;
|
||||||
|
import com.njcn.advance.responsibility.model.HarmonicData;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 谐波责任计算主引擎
|
||||||
|
* 严格对应C代码中的harm_res系列函数
|
||||||
|
*
|
||||||
|
* @author hongawen
|
||||||
|
* @version 2.0 - 修复版本,严格对照C代码实现
|
||||||
|
*/
|
||||||
|
public class HarmonicCalculationEngine {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(HarmonicCalculationEngine.class);
|
||||||
|
|
||||||
|
// 对应C代码中的全局变量
|
||||||
|
private int P; // 节点数 p_node
|
||||||
|
private int TL; // 功率数据长度 p_num
|
||||||
|
private int LL; // 谐波数据长度 harm_num
|
||||||
|
private int JIANGE; // 数据间隔比例
|
||||||
|
private int width; // 窗口大小
|
||||||
|
private float XIANE; // 谐波门槛
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主计算入口
|
||||||
|
* 对应C代码中的harm_res函数
|
||||||
|
*
|
||||||
|
* @param data 谐波数据对象
|
||||||
|
* @return 计算是否成功
|
||||||
|
*/
|
||||||
|
public boolean calculate(HarmonicData data) {
|
||||||
|
logger.info("Starting harmonic calculation, mode: {}", data.getCalculationMode());
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (data.getCalculationMode() == CalculationMode.FULL_CALCULATION) {
|
||||||
|
return fullCalculation(data);
|
||||||
|
} else {
|
||||||
|
return partialCalculation(data);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Calculation failed with exception: " + e.getMessage(), e);
|
||||||
|
e.printStackTrace();
|
||||||
|
data.setCalculationStatus(CalculationStatus.FAILED);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 完整计算模式
|
||||||
|
* 严格对应C代码中的harm_res_all函数
|
||||||
|
*
|
||||||
|
* @param data 谐波数据对象
|
||||||
|
* @return 计算是否成功
|
||||||
|
*/
|
||||||
|
private boolean fullCalculation(HarmonicData data) {
|
||||||
|
logger.info("Executing full calculation mode");
|
||||||
|
|
||||||
|
// 1. 数据初始化 - 对应 data_init_all()
|
||||||
|
if (!initializeFullCalculationData(data)) {
|
||||||
|
logger.error("Data initialization failed");
|
||||||
|
data.setCalculationStatus(CalculationStatus.FAILED);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 创建工作数组 - 对应C代码行536-540
|
||||||
|
float[][] a = new float[TL][P]; // 功率数据副本
|
||||||
|
float[] b = new float[LL]; // 谐波数据副本
|
||||||
|
float[] u = new float[TL]; // 对齐后的谐波数据
|
||||||
|
|
||||||
|
// 3. 复制数据 - 对应C代码行542-552
|
||||||
|
for (int i = 0; i < TL; i++) {
|
||||||
|
for (int j = 0; j < P; j++) {
|
||||||
|
a[i][j] = data.getPowerData()[i][j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = 0; i < LL; i++) {
|
||||||
|
b[i] = data.getHarmonicData()[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. 数据对齐处理 - 严格对应C代码行554-562
|
||||||
|
// 注意:C代码是原地修改数组b
|
||||||
|
for (int i = 0; i < LL; i += JIANGE) {
|
||||||
|
float tempt = 0.0f;
|
||||||
|
for (int j = 0; j < JIANGE; j++) {
|
||||||
|
tempt += b[i + j];
|
||||||
|
}
|
||||||
|
b[i] = tempt / JIANGE; // 覆盖原位置
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. 构建Udata - 严格对应C代码行570-580
|
||||||
|
// 注意:使用 i*JIANGE 索引
|
||||||
|
for (int i = 0; i < TL; i++) {
|
||||||
|
u[i] = b[i * JIANGE]; // 关键:使用 i*JIANGE 索引
|
||||||
|
}
|
||||||
|
|
||||||
|
int slcorlength = TL - width;
|
||||||
|
|
||||||
|
// 6. 计算滑动典则相关系数 - 对应C代码行584
|
||||||
|
logger.info("Computing sliding canonical correlation");
|
||||||
|
float[] cancorrelation = CanonicalCorrelationAnalysis.slidingCanonicalCorrelation(
|
||||||
|
a, u, width, P, TL
|
||||||
|
);
|
||||||
|
|
||||||
|
// 7. 保存典则相关系数 - 对应C代码行592-601
|
||||||
|
float[] Core = new float[slcorlength];
|
||||||
|
float[] BjCore = new float[slcorlength];
|
||||||
|
for (int i = 0; i < slcorlength; i++) {
|
||||||
|
Core[i] = cancorrelation[i];
|
||||||
|
BjCore[i] = 1 - cancorrelation[i];
|
||||||
|
}
|
||||||
|
data.setCanonicalCorrelation(Core);
|
||||||
|
data.setBackgroundCanonicalCorr(BjCore);
|
||||||
|
|
||||||
|
// 8. 计算动态相关系数矩阵 - 对应C代码行605-635
|
||||||
|
logger.info("Computing correlation matrix");
|
||||||
|
float[][] simCor = new float[slcorlength][P];
|
||||||
|
|
||||||
|
// 对应C代码行618-632:对每个节点计算动态相关系数
|
||||||
|
for (int i = 0; i < P; i++) {
|
||||||
|
// 提取第i个节点的功率数据
|
||||||
|
float[] xe = new float[TL];
|
||||||
|
for (int m = 0; m < TL; m++) {
|
||||||
|
xe[m] = a[m][i]; // 对应 Pdata.block(0, i, TL, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算该节点的滑动相关系数
|
||||||
|
float[] slidecor = CanonicalCorrelationAnalysis.slidingCorrelation(
|
||||||
|
xe, u, cancorrelation, width
|
||||||
|
);
|
||||||
|
|
||||||
|
// 存储结果
|
||||||
|
for (int j = 0; j < slcorlength; j++) {
|
||||||
|
simCor[j][i] = slidecor[j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data.setCorrelationData(simCor);
|
||||||
|
|
||||||
|
// 9. 计算EK值 - 对应C代码行642-654
|
||||||
|
logger.info("Computing EK values");
|
||||||
|
float[][] EKdata = ResponsibilityCalculator.computeEK(
|
||||||
|
simCor, a, width, P, TL
|
||||||
|
);
|
||||||
|
|
||||||
|
// 10. 计算FK值 - 对应C代码行660-673
|
||||||
|
logger.info("Computing FK values");
|
||||||
|
float[][] FKdata = ResponsibilityCalculator.computeFK(
|
||||||
|
EKdata, width, P, TL
|
||||||
|
);
|
||||||
|
data.setFkData(FKdata);
|
||||||
|
|
||||||
|
// 11. 计算HK值 - 对应C代码行678-691
|
||||||
|
logger.info("Computing HK values");
|
||||||
|
float[][] HKdata = ResponsibilityCalculator.computeHK(
|
||||||
|
BjCore, EKdata, width, P, TL
|
||||||
|
);
|
||||||
|
data.setHkData(HKdata);
|
||||||
|
|
||||||
|
// 12. 设置结果数量 - 对应C代码行693
|
||||||
|
data.setResponsibilityDataCount(slcorlength);
|
||||||
|
|
||||||
|
// 13. 统计超限时段的责任 - 对应C代码行696-724
|
||||||
|
logger.info("Computing responsibility sums");
|
||||||
|
|
||||||
|
// 重要修正:C代码的SumHK函数中,虽然Udata长度是TL,但是循环只遍历前slg(=TL-width)个元素
|
||||||
|
// 所以我们需要传入完整的u数组(长度TL),让sumResponsibility内部处理
|
||||||
|
// 对应C代码:VectorXd Udata(TL); 以及 SumHK函数调用
|
||||||
|
|
||||||
|
// 统计HK责任(包含背景)- 对应C代码行698-710
|
||||||
|
// 注意:传入完整的u数组(TL长度),而不是截取的数组
|
||||||
|
float[] sumHK = ResponsibilityCalculator.sumResponsibility(
|
||||||
|
HKdata, u, XIANE, width, P + 1, TL
|
||||||
|
);
|
||||||
|
data.setSumHKData(sumHK);
|
||||||
|
|
||||||
|
// 统计FK责任(不包含背景)- 对应C代码行712-724
|
||||||
|
// 同样传入完整的u数组和TL参数
|
||||||
|
float[] sumFK = ResponsibilityCalculator.sumResponsibility(
|
||||||
|
FKdata, u, XIANE, width, P, TL
|
||||||
|
);
|
||||||
|
data.setSumFKData(sumFK);
|
||||||
|
|
||||||
|
// 14. 标记计算成功 - 对应C代码行739
|
||||||
|
data.setCalculationStatus(CalculationStatus.CALCULATED);
|
||||||
|
logger.info("Full calculation completed successfully");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化完整计算数据
|
||||||
|
* 对应C代码中的data_init_all函数
|
||||||
|
*/
|
||||||
|
private boolean initializeFullCalculationData(HarmonicData data) {
|
||||||
|
// 设置全局变量 - 对应C代码行478-483
|
||||||
|
P = data.getPowerNodeCount();
|
||||||
|
TL = data.getPowerCount();
|
||||||
|
LL = data.getHarmonicCount();
|
||||||
|
// 对应C代码第481行:JIANGE = pq_buf.harm_num/pq_buf.p_num;
|
||||||
|
// 重要修正:JIANGE应该是 谐波数量/功率点数,不是谐波数量/节点数
|
||||||
|
JIANGE = LL / TL; // 这个是正确的:harm_num / p_num (其中p_num是功率点数)
|
||||||
|
width = data.getWindowSize();
|
||||||
|
XIANE = data.getHarmonicThreshold();
|
||||||
|
|
||||||
|
// 验证数据 - 对应C代码行485-504
|
||||||
|
if (JIANGE * TL != LL || JIANGE < 1) {
|
||||||
|
logger.error("Data length mismatch: JIANGE({}) * TL({}) != LL({})",
|
||||||
|
JIANGE, TL, LL);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (width < HarmonicConstants.MIN_WIN_LEN || width > HarmonicConstants.MAX_WIN_LEN) {
|
||||||
|
logger.error("Invalid window size: {}", width);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TL < 2 * width) {
|
||||||
|
logger.error("Power data length {} is too short for window size {}", TL, width);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (P > HarmonicConstants.MAX_P_NODE || TL > HarmonicConstants.MAX_P_NUM ||
|
||||||
|
LL > HarmonicConstants.MAX_HARM_NUM) {
|
||||||
|
logger.error("Data size exceeds limits");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部分重算模式
|
||||||
|
* 对应C代码中的harm_res_part函数
|
||||||
|
*
|
||||||
|
* @param data 谐波数据对象
|
||||||
|
* @return 计算是否成功
|
||||||
|
*/
|
||||||
|
private boolean partialCalculation(HarmonicData data) {
|
||||||
|
logger.info("Executing partial calculation mode");
|
||||||
|
|
||||||
|
// 1. 数据初始化 - 对应 data_init_part()
|
||||||
|
if (!initializePartialCalculationData(data)) {
|
||||||
|
logger.error("Data initialization failed for partial calculation");
|
||||||
|
data.setCalculationStatus(CalculationStatus.FAILED);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 准备Udata - 对应C代码行816-818
|
||||||
|
// C代码:VectorXd Udata(TL); 并从pq_buf.harm_data复制TL个元素
|
||||||
|
int res_num = data.getResponsibilityDataCount();
|
||||||
|
|
||||||
|
// 验证责任数据行数
|
||||||
|
if (res_num != TL - width) {
|
||||||
|
logger.warn("责任数据行数({})与期望值(TL-width={})不匹配", res_num, TL - width);
|
||||||
|
res_num = TL - width; // 使用正确的值
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重要修正:与C代码保持一致,Udata长度应该是TL,而不是res_num
|
||||||
|
// C代码:VectorXd Udata(TL);
|
||||||
|
float[] Udata = new float[TL];
|
||||||
|
|
||||||
|
// 从harm_data复制TL个元素到Udata
|
||||||
|
// C代码:for (int j = 0; j < TL; j++) Udata[j] = pq_buf.harm_data[j];
|
||||||
|
if (data.getHarmonicData().length < TL) {
|
||||||
|
logger.warn("谐波数据长度({})小于TL({}), 将补零",
|
||||||
|
data.getHarmonicData().length, TL);
|
||||||
|
System.arraycopy(data.getHarmonicData(), 0, Udata, 0, data.getHarmonicData().length);
|
||||||
|
// 剩余部分自动补零
|
||||||
|
} else {
|
||||||
|
System.arraycopy(data.getHarmonicData(), 0, Udata, 0, TL);
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.debug("准备Udata完成: 长度={} (对应C代码TL), 责任数据行数={}", Udata.length, res_num);
|
||||||
|
|
||||||
|
// 3. 统计HK责任 - 对应C代码行806-830
|
||||||
|
logger.info("Recalculating HK responsibility sums");
|
||||||
|
|
||||||
|
// 对应C代码第808-814行:创建新的HKdata矩阵,只包含RES_NUM行
|
||||||
|
// C代码:MatrixXd HKdata(RES_NUM, (P + 1));
|
||||||
|
|
||||||
|
// 添加数据验证
|
||||||
|
if (data.getHkData() == null || data.getHkData().length == 0) {
|
||||||
|
logger.error("HK数据为空或长度为0");
|
||||||
|
data.setCalculationStatus(CalculationStatus.FAILED);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重要:C代码创建了新的RES_NUM行的HKdata,从原始数据复制前RES_NUM行
|
||||||
|
// 对应C代码第808-814行
|
||||||
|
float[][] HKdataForCalc = new float[res_num][P + 1];
|
||||||
|
int copyRows = Math.min(res_num, data.getHkData().length);
|
||||||
|
|
||||||
|
logger.debug("创建用于计算的HK数据矩阵: {}x{}, 从原始数据复制{}行",
|
||||||
|
res_num, P + 1, copyRows);
|
||||||
|
|
||||||
|
for (int i = 0; i < copyRows; i++) {
|
||||||
|
for (int j = 0; j < P + 1; j++) {
|
||||||
|
if (j < data.getHkData()[i].length) {
|
||||||
|
HKdataForCalc[i][j] = data.getHkData()[i][j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
logger.debug("调用HK sumResponsibility参数: HKdata[{}x{}], Udata[{}], TL={}, width={}",
|
||||||
|
HKdataForCalc.length, HKdataForCalc.length > 0 ? HKdataForCalc[0].length : 0,
|
||||||
|
Udata.length, TL, width);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 对应C代码第819行:arrHKsum = SumHK(HKdata, Udata, wdith, colK, TL);
|
||||||
|
float[] sumHK = ResponsibilityCalculator.sumResponsibility(
|
||||||
|
HKdataForCalc, // 使用新创建的RES_NUM行的HK数据
|
||||||
|
Udata, // 长度为TL的数组
|
||||||
|
XIANE,
|
||||||
|
width,
|
||||||
|
P + 1,
|
||||||
|
TL // 传入TL参数
|
||||||
|
);
|
||||||
|
data.setSumHKData(sumHK);
|
||||||
|
logger.debug("HK责任计算完成,结果长度: {}", sumHK != null ? sumHK.length : "null");
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("HK责任计算失败: " + e.getMessage(), e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. 统计FK责任 - 对应C代码行839-851
|
||||||
|
logger.info("Recalculating FK responsibility sums");
|
||||||
|
|
||||||
|
// 对应C代码:虽然没有显式创建新的FKdata,但逻辑相同
|
||||||
|
|
||||||
|
// 添加数据验证
|
||||||
|
if (data.getFkData() == null || data.getFkData().length == 0) {
|
||||||
|
logger.error("FK数据为空或长度为0");
|
||||||
|
data.setCalculationStatus(CalculationStatus.FAILED);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建用于计算的FK数据矩阵(RES_NUM行)
|
||||||
|
float[][] FKdataForCalc = new float[res_num][P];
|
||||||
|
int copyRowsFK = Math.min(res_num, data.getFkData().length);
|
||||||
|
|
||||||
|
logger.debug("创建用于计算的FK数据矩阵: {}x{}, 从原始数据复制{}行",
|
||||||
|
res_num, P, copyRowsFK);
|
||||||
|
|
||||||
|
for (int i = 0; i < copyRowsFK; i++) {
|
||||||
|
for (int j = 0; j < P; j++) {
|
||||||
|
if (j < data.getFkData()[i].length) {
|
||||||
|
FKdataForCalc[i][j] = data.getFkData()[i][j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
logger.debug("调用FK sumResponsibility参数: FKdata[{}x{}], Udata[{}], TL={}, width={}",
|
||||||
|
FKdataForCalc.length, FKdataForCalc.length > 0 ? FKdataForCalc[0].length : 0,
|
||||||
|
Udata.length, TL, width);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 对应C代码第840行:arrHKsum = SumHK(FKdata, Udata, wdith, colK, TL);
|
||||||
|
float[] sumFK = ResponsibilityCalculator.sumResponsibility(
|
||||||
|
FKdataForCalc, // 使用新创建的RES_NUM行的FK数据
|
||||||
|
Udata, // 使用相同的Udata(长度TL)
|
||||||
|
XIANE,
|
||||||
|
width,
|
||||||
|
P,
|
||||||
|
TL // 传入TL参数
|
||||||
|
);
|
||||||
|
data.setSumFKData(sumFK);
|
||||||
|
logger.debug("FK责任计算完成,结果长度: {}", sumFK != null ? sumFK.length : "null");
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("FK责任计算失败: " + e.getMessage(), e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. 标记计算成功 - 对应C代码行858
|
||||||
|
data.setCalculationStatus(CalculationStatus.CALCULATED);
|
||||||
|
logger.info("Partial calculation completed successfully");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化部分计算数据
|
||||||
|
* 对应C代码中的data_init_part函数
|
||||||
|
*/
|
||||||
|
private boolean initializePartialCalculationData(HarmonicData data) {
|
||||||
|
// 设置变量 - 对应C代码行762-766
|
||||||
|
int RES_NUM = data.getResponsibilityDataCount();
|
||||||
|
P = data.getPowerNodeCount();
|
||||||
|
TL = data.getWindowSize() + RES_NUM;
|
||||||
|
width = data.getWindowSize();
|
||||||
|
XIANE = data.getHarmonicThreshold();
|
||||||
|
|
||||||
|
// 验证数据 - 对应C代码行756-778
|
||||||
|
if ((RES_NUM + width) != data.getHarmonicCount()) {
|
||||||
|
logger.error("Data length mismatch: res_num({}) + win({}) != harm_num({})",
|
||||||
|
RES_NUM, width, data.getHarmonicCount());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (width < HarmonicConstants.MIN_WIN_LEN || width > HarmonicConstants.MAX_WIN_LEN) {
|
||||||
|
logger.error("Invalid window size: {}", width);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (P > HarmonicConstants.MAX_P_NODE || TL > HarmonicConstants.MAX_P_NUM) {
|
||||||
|
logger.error("Data size exceeds limits");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证FK和HK数据存在
|
||||||
|
if (data.getFkData() == null || data.getHkData() == null) {
|
||||||
|
logger.error("FK or HK data is null");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,429 @@
|
|||||||
|
package com.njcn.advance.responsibility.calculator;
|
||||||
|
|
||||||
|
import com.njcn.advance.responsibility.analysis.CanonicalCorrelationAnalysis;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 责任指标计算类
|
||||||
|
* 计算谐波责任的各项指标
|
||||||
|
* 严格对应C代码实现
|
||||||
|
*
|
||||||
|
* @author hongawen
|
||||||
|
* @version 2.0 - 修复版本,严格对照C代码实现
|
||||||
|
*/
|
||||||
|
public class ResponsibilityCalculator {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(ResponsibilityCalculator.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算EK值(动态责任指标)
|
||||||
|
* 严格对应C代码中的DyEKCom函数(行300-357)
|
||||||
|
*
|
||||||
|
* @param correlationData 动态相关系数矩阵 [时间][节点]
|
||||||
|
* @param powerData 功率数据矩阵 [时间][节点]
|
||||||
|
* @param windowSize 窗口大小
|
||||||
|
* @param nodeCount 节点数量
|
||||||
|
* @param dataLength 数据长度
|
||||||
|
* @return EK值矩阵
|
||||||
|
*/
|
||||||
|
public static float[][] computeEK(float[][] correlationData, float[][] powerData,
|
||||||
|
int windowSize, int nodeCount, int dataLength) {
|
||||||
|
int slideLength = dataLength - windowSize;
|
||||||
|
float[][] ekData = new float[slideLength][nodeCount];
|
||||||
|
float[][] akData = new float[slideLength][nodeCount];
|
||||||
|
|
||||||
|
logger.info("Computing EK values, slide length: {}", slideLength);
|
||||||
|
|
||||||
|
// 计算AK值 - 对应C代码行307-319
|
||||||
|
for (int i = 0; i < slideLength; i++) {
|
||||||
|
float sumPower = 0;
|
||||||
|
|
||||||
|
// 计算功率总和 - 对应C代码行309-313
|
||||||
|
for (int j = 0; j < nodeCount; j++) {
|
||||||
|
sumPower += powerData[i][j]; // 注意:这里用的是powerData[i][j]
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算AK值 - 对应C代码行314-318
|
||||||
|
for (int j = 0; j < nodeCount; j++) {
|
||||||
|
if (sumPower > 0) {
|
||||||
|
akData[i][j] = correlationData[i][j] * (powerData[i][j] / sumPower);
|
||||||
|
} else {
|
||||||
|
akData[i][j] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 归一化处理得到EK值 - 对应C代码行320-342
|
||||||
|
for (int i = 0; i < slideLength; i++) {
|
||||||
|
// 重要:C代码初始化为0,而不是Float.MIN_VALUE/MAX_VALUE
|
||||||
|
// 对应C代码行322-323
|
||||||
|
float maxValue = 0;
|
||||||
|
float minValue = 0;
|
||||||
|
|
||||||
|
// 找最大最小值 - 对应C代码行322-334
|
||||||
|
for (int j = 0; j < nodeCount; j++) {
|
||||||
|
if (akData[i][j] > maxValue) {
|
||||||
|
maxValue = akData[i][j];
|
||||||
|
}
|
||||||
|
if (akData[i][j] < minValue) {
|
||||||
|
minValue = akData[i][j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float range = maxValue - minValue;
|
||||||
|
|
||||||
|
// 归一化 - 对应C代码行338-341
|
||||||
|
for (int j = 0; j < nodeCount; j++) {
|
||||||
|
if (Math.abs(range) > 1e-10) {
|
||||||
|
ekData[i][j] = (akData[i][j] - minValue) / range;
|
||||||
|
} else {
|
||||||
|
ekData[i][j] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("EK computation completed");
|
||||||
|
|
||||||
|
return ekData;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算FK值(不包含背景的责任指标)
|
||||||
|
* 严格对应C代码中的DyFKCom函数(行358-389)
|
||||||
|
*
|
||||||
|
* @param ekData EK值矩阵
|
||||||
|
* @param windowSize 窗口大小
|
||||||
|
* @param nodeCount 节点数量
|
||||||
|
* @param dataLength 数据长度
|
||||||
|
* @return FK值矩阵
|
||||||
|
*/
|
||||||
|
public static float[][] computeFK(float[][] ekData, int windowSize,
|
||||||
|
int nodeCount, int dataLength) {
|
||||||
|
int slideLength = dataLength - windowSize;
|
||||||
|
float[][] fkData = new float[slideLength][nodeCount];
|
||||||
|
|
||||||
|
logger.info("Computing FK values");
|
||||||
|
|
||||||
|
// 对应C代码行364-376
|
||||||
|
for (int i = 0; i < slideLength; i++) {
|
||||||
|
float sumEK = 0;
|
||||||
|
|
||||||
|
// 计算EK总和 - 对应C代码行366-370
|
||||||
|
for (int j = 0; j < nodeCount; j++) {
|
||||||
|
sumEK += ekData[i][j];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算FK值(归一化)- 对应C代码行372-375
|
||||||
|
for (int j = 0; j < nodeCount; j++) {
|
||||||
|
if (sumEK > 0) {
|
||||||
|
fkData[i][j] = ekData[i][j] / sumEK;
|
||||||
|
} else {
|
||||||
|
fkData[i][j] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("FK computation completed");
|
||||||
|
|
||||||
|
return fkData;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算HK值(包含背景的责任指标)
|
||||||
|
* 严格对应C代码中的DyHKCom函数(行390-429)
|
||||||
|
*
|
||||||
|
* @param backgroundCanCor 背景典则相关系数(1-典则相关系数)
|
||||||
|
* @param ekData EK值矩阵
|
||||||
|
* @param windowSize 窗口大小
|
||||||
|
* @param nodeCount 节点数量
|
||||||
|
* @param dataLength 数据长度
|
||||||
|
* @return HK值矩阵
|
||||||
|
*/
|
||||||
|
public static float[][] computeHK(float[] backgroundCanCor, float[][] ekData,
|
||||||
|
int windowSize, int nodeCount, int dataLength) {
|
||||||
|
int slideLength = dataLength - windowSize;
|
||||||
|
float[][] hkData = new float[slideLength][nodeCount + 1];
|
||||||
|
float[][] newEK = new float[slideLength][nodeCount + 1];
|
||||||
|
|
||||||
|
logger.info("Computing HK values");
|
||||||
|
|
||||||
|
// 构建包含背景的EK矩阵 - 对应C代码行396-403
|
||||||
|
for (int i = 0; i < slideLength; i++) {
|
||||||
|
// 复制原有EK值
|
||||||
|
for (int j = 0; j < nodeCount; j++) {
|
||||||
|
newEK[i][j] = ekData[i][j];
|
||||||
|
}
|
||||||
|
// 添加背景值
|
||||||
|
newEK[i][nodeCount] = backgroundCanCor[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算HK值 - 对应C代码行405-416
|
||||||
|
for (int i = 0; i < slideLength; i++) {
|
||||||
|
float sumEK = 0;
|
||||||
|
|
||||||
|
// 计算总和 - 对应C代码行407-411
|
||||||
|
for (int j = 0; j < nodeCount + 1; j++) {
|
||||||
|
sumEK += newEK[i][j];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 归一化得到HK值 - 对应C代码行412-415
|
||||||
|
for (int j = 0; j < nodeCount + 1; j++) {
|
||||||
|
if (sumEK > 0) {
|
||||||
|
hkData[i][j] = newEK[i][j] / sumEK;
|
||||||
|
} else {
|
||||||
|
hkData[i][j] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("HK computation completed");
|
||||||
|
|
||||||
|
return hkData;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算超限时段的责任总和
|
||||||
|
* 严格对应C代码中的SumHK函数(行431-461)
|
||||||
|
*
|
||||||
|
* @param responsibilityData 责任数据矩阵(FK或HK)[时间][节点]
|
||||||
|
* @param harmonicData 谐波数据(Udata) - 长度为TL
|
||||||
|
* @param threshold 谐波门槛(XIANE)
|
||||||
|
* @param windowSize 窗口大小
|
||||||
|
* @param columnCount 列数(节点数或节点数+1)
|
||||||
|
* @param tl_num 对应C代码的TL参数(总数据点数)
|
||||||
|
* @return 各节点的责任总和百分比
|
||||||
|
*/
|
||||||
|
public static float[] sumResponsibility(float[][] responsibilityData, float[] harmonicData,
|
||||||
|
float threshold, int windowSize, int columnCount, int tl_num) {
|
||||||
|
// 对应C代码:int slg = tl_num - width;
|
||||||
|
int slideLength = tl_num - windowSize; // 使用传入的tl_num计算,而不是从responsibilityData.length推断
|
||||||
|
float[] sumData = new float[columnCount]; // 对应C代码中的 arrHKsum
|
||||||
|
double[] HKSum = new double[columnCount]; // 对应C代码中的 VectorXd HKSum - 使用double精度
|
||||||
|
int exceedCount = 0; // 对应C代码中的 coutt
|
||||||
|
|
||||||
|
// ===== 添加详细调试日志 =====
|
||||||
|
logger.info("======= 开始 sumResponsibility 计算 =======");
|
||||||
|
logger.info("输入参数:");
|
||||||
|
logger.info(" threshold(阈值): {}", threshold);
|
||||||
|
logger.info(" windowSize(窗口大小): {}", windowSize);
|
||||||
|
logger.info(" columnCount(列数): {}", columnCount);
|
||||||
|
logger.info(" tl_num(总数据长度): {}", tl_num);
|
||||||
|
logger.info(" slideLength(滑动长度): {}", slideLength);
|
||||||
|
logger.info(" responsibilityData维度: {}x{}",
|
||||||
|
responsibilityData != null ? responsibilityData.length : "null",
|
||||||
|
responsibilityData != null && responsibilityData.length > 0 ? responsibilityData[0].length : "null");
|
||||||
|
logger.info(" harmonicData长度: {}", harmonicData != null ? harmonicData.length : "null");
|
||||||
|
|
||||||
|
// 数据验证
|
||||||
|
if (harmonicData == null) {
|
||||||
|
logger.error("错误: harmonicData为null!");
|
||||||
|
throw new NullPointerException("harmonicData不能为null");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (responsibilityData == null) {
|
||||||
|
logger.error("错误: responsibilityData为null!");
|
||||||
|
throw new NullPointerException("responsibilityData不能为null");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 关键验证:检查数组长度是否充足
|
||||||
|
// C代码中Udata长度是TL,循环遍历slg=TL-width个元素
|
||||||
|
logger.info("数据验证: slideLength={}, harmonicData.length={}, responsibilityData.length={}",
|
||||||
|
slideLength, harmonicData.length, responsibilityData.length);
|
||||||
|
|
||||||
|
if (harmonicData.length < slideLength) {
|
||||||
|
logger.error("!!!谐波数据长度不足!!!");
|
||||||
|
logger.error("需要访问harmonicData[0]到harmonicData[{}], 但数组长度只有{}",
|
||||||
|
slideLength - 1, harmonicData.length);
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
String.format("谐波数据长度不足: 需要%d, 实际%d", slideLength, harmonicData.length));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (responsibilityData.length < slideLength) {
|
||||||
|
logger.error("!!!责任数据行数不足!!!");
|
||||||
|
logger.error("需要访问responsibilityData[0]到responsibilityData[{}], 但数组长度只有{}",
|
||||||
|
slideLength - 1, responsibilityData.length);
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
String.format("责任数据行数不足: 需要%d, 实际%d", slideLength, responsibilityData.length));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===== 添加数据分布统计 =====
|
||||||
|
logger.info("谐波数据分析:");
|
||||||
|
float harmonicMin = Float.MAX_VALUE, harmonicMax = Float.MIN_VALUE;
|
||||||
|
double harmonicSum = 0;
|
||||||
|
int preliminaryExceedCount = 0;
|
||||||
|
for (int i = 0; i < Math.min(slideLength, harmonicData.length); i++) {
|
||||||
|
float val = harmonicData[i];
|
||||||
|
harmonicMin = Math.min(harmonicMin, val);
|
||||||
|
harmonicMax = Math.max(harmonicMax, val);
|
||||||
|
harmonicSum += val;
|
||||||
|
if (val > threshold) {
|
||||||
|
preliminaryExceedCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
double harmonicAvg = harmonicSum / Math.min(slideLength, harmonicData.length);
|
||||||
|
logger.info(" 谐波数据范围: [{}, {}]", harmonicMin, harmonicMax);
|
||||||
|
logger.info(" 谐波数据平均值: {}", harmonicAvg);
|
||||||
|
logger.info(" 设定阈值: {}", threshold);
|
||||||
|
logger.info(" 初步统计超限个数: {}/{} ({:.2f}%)",
|
||||||
|
preliminaryExceedCount, Math.min(slideLength, harmonicData.length),
|
||||||
|
preliminaryExceedCount * 100.0 / Math.min(slideLength, harmonicData.length));
|
||||||
|
|
||||||
|
// ===== 责任数据分析 =====
|
||||||
|
logger.info("责任数据分析(检查前5行的归一化情况):");
|
||||||
|
for (int i = 0; i < Math.min(5, responsibilityData.length); i++) {
|
||||||
|
float rowSum = 0;
|
||||||
|
for (int j = 0; j < responsibilityData[i].length; j++) {
|
||||||
|
rowSum += responsibilityData[i][j];
|
||||||
|
}
|
||||||
|
logger.info(" 第{}行和: {} (期望值: 1.0, 偏差: {})", i, rowSum, Math.abs(rowSum - 1.0f));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 统计超限时段的责任 - 对应C代码行437-449
|
||||||
|
// 重要:C代码中有一个设计缺陷:coutt在每个j循环中被重置,
|
||||||
|
// 但最后计算百分比时使用的是最后一次j循环的coutt值
|
||||||
|
// 为了严格保持一致,我们也要复现这个逻辑
|
||||||
|
logger.info("===== 开始循环计算每列的累加值 =====");
|
||||||
|
int[] exceedCountPerColumn = new int[columnCount]; // 记录每列的超限次数,用于调试
|
||||||
|
|
||||||
|
for (int j = 0; j < columnCount; j++) {
|
||||||
|
HKSum[j] = 0;
|
||||||
|
exceedCount = 0; // 对应C代码行440: coutt = 0;
|
||||||
|
logger.info("开始计算第{}列 (共{}列)", j, columnCount);
|
||||||
|
|
||||||
|
double columnSum = 0; // 用于调试
|
||||||
|
int columnExceedCount = 0; // 用于调试
|
||||||
|
|
||||||
|
for (int i = 0; i < slideLength; i++) {
|
||||||
|
// 添加越界检查
|
||||||
|
if (i >= harmonicData.length) {
|
||||||
|
logger.error("!!!数组越界!!! 尝试访问harmonicData[{}], 但数组长度只有{}",
|
||||||
|
i, harmonicData.length);
|
||||||
|
logger.error("发生在: j={}, i={}", j, i);
|
||||||
|
throw new ArrayIndexOutOfBoundsException(
|
||||||
|
String.format("访问harmonicData[%d]越界, 数组长度=%d", i, harmonicData.length));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 对应C代码行443-447
|
||||||
|
if (harmonicData[i] > threshold) {
|
||||||
|
double currentResponsibility = responsibilityData[i][j];
|
||||||
|
HKSum[j] += currentResponsibility; // 对应C代码行445
|
||||||
|
exceedCount++; // 对应C代码行446
|
||||||
|
columnSum += currentResponsibility;
|
||||||
|
columnExceedCount++;
|
||||||
|
|
||||||
|
// 只打印前几个超限情况的详细信息
|
||||||
|
if (columnExceedCount <= 3) {
|
||||||
|
logger.info(" 时刻i={}: 谐波值={} > 阈值={}, 责任值={}, 累加到{}",
|
||||||
|
i, harmonicData[i], threshold, currentResponsibility, HKSum[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
exceedCountPerColumn[j] = columnExceedCount;
|
||||||
|
logger.info("第{}列计算完成: 累加值={}, 超限次数={}", j, HKSum[j], columnExceedCount);
|
||||||
|
}
|
||||||
|
// 注意:这里exceedCount保留的是最后一列(j=columnCount-1)的超限次数
|
||||||
|
// 这与C代码的行为一致
|
||||||
|
|
||||||
|
logger.info("===== 循环计算完成 =====");
|
||||||
|
logger.info("最终exceedCount={} (来自最后一列的计算)", exceedCount);
|
||||||
|
logger.info("各列超限次数对比: {}", java.util.Arrays.toString(exceedCountPerColumn));
|
||||||
|
logger.info("各列累加值: {}", java.util.Arrays.toString(HKSum));
|
||||||
|
|
||||||
|
// 计算平均责任百分比 - 对应C代码行453-459
|
||||||
|
logger.info("===== 开始计算最终百分比 =====");
|
||||||
|
for (int i = 0; i < columnCount; i++) {
|
||||||
|
sumData[i] = 0; // 对应C代码行454
|
||||||
|
}
|
||||||
|
|
||||||
|
double totalPercentage = 0; // 用于统计总和
|
||||||
|
for (int i = 0; i < columnCount; i++) {
|
||||||
|
if (exceedCount > 0) {
|
||||||
|
// 对应C代码行458: arrHKsum[i] = 100 * (HKSum(i)/coutt);
|
||||||
|
// 使用double进行计算,然后转换为float
|
||||||
|
double percentage = 100.0 * (HKSum[i] / (double)exceedCount);
|
||||||
|
sumData[i] = (float)percentage;
|
||||||
|
totalPercentage += percentage;
|
||||||
|
|
||||||
|
logger.info("节点{}: 累加值={}, 除以超限次数={}, 百分比={}%",
|
||||||
|
i, HKSum[i], exceedCount, percentage);
|
||||||
|
} else {
|
||||||
|
logger.warn("节点{}: 超限次数为0,百分比设为0", i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("===== 计算结果汇总 =====");
|
||||||
|
logger.info("使用的超限次数(分母): {}", exceedCount);
|
||||||
|
logger.info("各节点百分比: {}", java.util.Arrays.toString(sumData));
|
||||||
|
logger.info("百分比总和: {}% (期望100%)", totalPercentage);
|
||||||
|
logger.info("偏差: {}%", Math.abs(totalPercentage - 100.0));
|
||||||
|
|
||||||
|
if (Math.abs(totalPercentage - 100.0) > 1.0) {
|
||||||
|
logger.warn("!!!注意!!! 百分比总和偏离100%超过1%,可能存在问题");
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("======= sumResponsibility 计算完成 =======");
|
||||||
|
return sumData;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算超限时段的责任总和(兼容版本)
|
||||||
|
* 为了向后兼容,保留不带tl_num参数的版本
|
||||||
|
*
|
||||||
|
* @param responsibilityData 责任数据矩阵(FK或HK)[时间][节点]
|
||||||
|
* @param harmonicData 谐波数据(Udata)
|
||||||
|
* @param threshold 谐波门槛(XIANE)
|
||||||
|
* @param windowSize 窗口大小
|
||||||
|
* @param columnCount 列数(节点数或节点数+1)
|
||||||
|
* @return 各节点的责任总和百分比
|
||||||
|
*/
|
||||||
|
public static float[] sumResponsibility(float[][] responsibilityData, float[] harmonicData,
|
||||||
|
float threshold, int windowSize, int columnCount) {
|
||||||
|
// 如果没有提供tl_num,从数据推断
|
||||||
|
int tl_num = responsibilityData.length + windowSize;
|
||||||
|
return sumResponsibility(responsibilityData, harmonicData, threshold, windowSize, columnCount, tl_num);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算所有节点的动态相关系数矩阵
|
||||||
|
* 这个函数在主引擎中已经内联实现,这里保留作为辅助方法
|
||||||
|
*
|
||||||
|
* @param powerData 功率数据矩阵
|
||||||
|
* @param harmonicData 谐波数据
|
||||||
|
* @param canonicalCorr 典则相关系数序列
|
||||||
|
* @param windowSize 窗口大小
|
||||||
|
* @param nodeCount 节点数量
|
||||||
|
* @return 动态相关系数矩阵
|
||||||
|
*/
|
||||||
|
public static float[][] computeCorrelationMatrix(float[][] powerData, float[] harmonicData,
|
||||||
|
float[] canonicalCorr, int windowSize,
|
||||||
|
int nodeCount) {
|
||||||
|
int slideLength = canonicalCorr.length;
|
||||||
|
float[][] correlationMatrix = new float[slideLength][nodeCount];
|
||||||
|
|
||||||
|
logger.info("Computing correlation matrix for all nodes");
|
||||||
|
|
||||||
|
for (int nodeIdx = 0; nodeIdx < nodeCount; nodeIdx++) {
|
||||||
|
// 提取单个节点的功率数据
|
||||||
|
float[] nodePower = new float[powerData.length];
|
||||||
|
for (int i = 0; i < powerData.length; i++) {
|
||||||
|
nodePower[i] = powerData[i][nodeIdx];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算该节点的动态相关系数
|
||||||
|
float[] nodeCorr = CanonicalCorrelationAnalysis
|
||||||
|
.slidingCorrelation(nodePower, harmonicData, canonicalCorr, windowSize);
|
||||||
|
|
||||||
|
// 存储结果
|
||||||
|
for (int i = 0; i < slideLength; i++) {
|
||||||
|
correlationMatrix[i][nodeIdx] = nodeCorr[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("Correlation matrix computation completed");
|
||||||
|
|
||||||
|
return correlationMatrix;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package com.njcn.advance.responsibility.constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算模式枚举
|
||||||
|
*
|
||||||
|
* @author hongawen
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
public enum CalculationMode {
|
||||||
|
/**
|
||||||
|
* 完整计算模式
|
||||||
|
* 使用电压和功率数据计算相关系数和责任
|
||||||
|
*/
|
||||||
|
FULL_CALCULATION(0, "完整计算模式"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部分重算模式
|
||||||
|
* 使用已有的动态相关系数计算责任
|
||||||
|
*/
|
||||||
|
PARTIAL_RECALCULATION(1, "部分重算模式");
|
||||||
|
|
||||||
|
private final int code;
|
||||||
|
private final String description;
|
||||||
|
|
||||||
|
CalculationMode(int code, String description) {
|
||||||
|
this.code = code;
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CalculationMode fromCode(int code) {
|
||||||
|
for (CalculationMode mode : values()) {
|
||||||
|
if (mode.code == code) {
|
||||||
|
return mode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("Invalid calculation mode code: " + code);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package com.njcn.advance.responsibility.constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算状态枚举
|
||||||
|
*
|
||||||
|
* @author hongawen
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
public enum CalculationStatus {
|
||||||
|
/**
|
||||||
|
* 未计算
|
||||||
|
*/
|
||||||
|
NOT_CALCULATED(0, "未计算"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算完成
|
||||||
|
*/
|
||||||
|
CALCULATED(1, "计算完成"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算失败
|
||||||
|
*/
|
||||||
|
FAILED(-1, "计算失败");
|
||||||
|
|
||||||
|
private final int code;
|
||||||
|
private final String description;
|
||||||
|
|
||||||
|
CalculationStatus(int code, String description) {
|
||||||
|
this.code = code;
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CalculationStatus fromCode(int code) {
|
||||||
|
for (CalculationStatus status : values()) {
|
||||||
|
if (status.code == code) {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NOT_CALCULATED;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package com.njcn.advance.responsibility.constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 谐波责任量化系统常量定义
|
||||||
|
*
|
||||||
|
* @author hongawen
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
public final class HarmonicConstants {
|
||||||
|
|
||||||
|
private HarmonicConstants() {
|
||||||
|
// 防止实例化
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最大谐波数据个数 (1440*100)
|
||||||
|
* 按一分钟间隔,100天处理
|
||||||
|
*/
|
||||||
|
public static final int MAX_HARM_NUM = 144000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最大功率数据个数 (96*100)
|
||||||
|
* 按15分钟间隔,100天处理
|
||||||
|
*/
|
||||||
|
public static final int MAX_P_NUM = 9600;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最大功率节点个数
|
||||||
|
* 按200个限制
|
||||||
|
*/
|
||||||
|
public static final int MAX_P_NODE = 200;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最大数据窗长度 (96*10)
|
||||||
|
* 按15分钟算10天
|
||||||
|
*/
|
||||||
|
public static final int MAX_WIN_LEN = 960;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最小数据窗长度
|
||||||
|
* 按15分钟算一小时
|
||||||
|
*/
|
||||||
|
public static final int MIN_WIN_LEN = 4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认数据窗大小
|
||||||
|
* 一天的数据量(15分钟间隔)
|
||||||
|
*/
|
||||||
|
public static final int DEFAULT_WINDOW_SIZE = 96;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数值计算精度阈值
|
||||||
|
*/
|
||||||
|
public static final double EPSILON = 1e-10;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 协方差计算最小值(避免除零)
|
||||||
|
*/
|
||||||
|
public static final double MIN_COVARIANCE = 1e-5;
|
||||||
|
}
|
||||||
@@ -0,0 +1,286 @@
|
|||||||
|
package com.njcn.advance.responsibility.model;
|
||||||
|
|
||||||
|
import com.njcn.advance.responsibility.constant.CalculationMode;
|
||||||
|
import com.njcn.advance.responsibility.constant.CalculationStatus;
|
||||||
|
import com.njcn.advance.responsibility.constant.HarmonicConstants;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 谐波数据结构类
|
||||||
|
* 对应C语言中的harm_data_struct结构体
|
||||||
|
*
|
||||||
|
* @author hongawen
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
public class HarmonicData {
|
||||||
|
|
||||||
|
// 输入参数
|
||||||
|
private CalculationMode calculationMode; // 计算标志
|
||||||
|
private int harmonicCount; // 谐波数据个数
|
||||||
|
private int powerCount; // 功率数据个数
|
||||||
|
private int powerNodeCount; // 功率负荷节点数
|
||||||
|
private int windowSize; // 数据窗大小
|
||||||
|
private int responsibilityDataCount; // 代入的责任数据个数
|
||||||
|
private float harmonicThreshold; // 谐波电压门槛
|
||||||
|
|
||||||
|
// 数据数组
|
||||||
|
private float[] harmonicData; // 谐波数据序列
|
||||||
|
private float[][] powerData; // 功率数据序列
|
||||||
|
|
||||||
|
// 输入输出数据
|
||||||
|
private float[][] correlationData; // 动态相关系数数据序列
|
||||||
|
private float[][] fkData; // 不包含背景动态谐波责任数据序列
|
||||||
|
private float[][] hkData; // 包含背景动态谐波责任数据序列
|
||||||
|
private float[] canonicalCorrelation; // 典则相关系数
|
||||||
|
private float[] backgroundCanonicalCorr; // 包含背景典则相关系数
|
||||||
|
|
||||||
|
// 输出结果
|
||||||
|
private CalculationStatus calculationStatus; // 计算状态
|
||||||
|
private float[] sumFKData; // 不包含背景谐波责任
|
||||||
|
private float[] sumHKData; // 包含背景谐波责任
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认构造函数
|
||||||
|
*/
|
||||||
|
public HarmonicData() {
|
||||||
|
this.calculationMode = CalculationMode.FULL_CALCULATION;
|
||||||
|
this.calculationStatus = CalculationStatus.NOT_CALCULATED;
|
||||||
|
this.windowSize = HarmonicConstants.DEFAULT_WINDOW_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builder模式构造器
|
||||||
|
*/
|
||||||
|
public static class Builder {
|
||||||
|
private HarmonicData data = new HarmonicData();
|
||||||
|
|
||||||
|
public Builder calculationMode(CalculationMode mode) {
|
||||||
|
data.calculationMode = mode;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder harmonicCount(int count) {
|
||||||
|
data.harmonicCount = count;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder powerCount(int count) {
|
||||||
|
data.powerCount = count;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder powerNodeCount(int count) {
|
||||||
|
data.powerNodeCount = count;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder windowSize(int size) {
|
||||||
|
data.windowSize = size;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder harmonicThreshold(float threshold) {
|
||||||
|
data.harmonicThreshold = threshold;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder harmonicData(float[] data) {
|
||||||
|
this.data.harmonicData = data;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder powerData(float[][] data) {
|
||||||
|
this.data.powerData = data;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HarmonicData build() {
|
||||||
|
// 验证数据
|
||||||
|
validateData();
|
||||||
|
// 初始化数组
|
||||||
|
initializeArrays();
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateData() {
|
||||||
|
if (data.harmonicCount <= 0 || data.harmonicCount > HarmonicConstants.MAX_HARM_NUM) {
|
||||||
|
throw new IllegalArgumentException("Invalid harmonic count: " + data.harmonicCount);
|
||||||
|
}
|
||||||
|
if (data.powerCount <= 0 || data.powerCount > HarmonicConstants.MAX_P_NUM) {
|
||||||
|
throw new IllegalArgumentException("Invalid power count: " + data.powerCount);
|
||||||
|
}
|
||||||
|
if (data.powerNodeCount <= 0 || data.powerNodeCount > HarmonicConstants.MAX_P_NODE) {
|
||||||
|
throw new IllegalArgumentException("Invalid power node count: " + data.powerNodeCount);
|
||||||
|
}
|
||||||
|
if (data.windowSize < HarmonicConstants.MIN_WIN_LEN ||
|
||||||
|
data.windowSize > HarmonicConstants.MAX_WIN_LEN) {
|
||||||
|
throw new IllegalArgumentException("Invalid window size: " + data.windowSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证数据对齐
|
||||||
|
if (data.calculationMode == CalculationMode.FULL_CALCULATION) {
|
||||||
|
int ratio = data.harmonicCount / data.powerCount;
|
||||||
|
if (ratio * data.powerCount != data.harmonicCount || ratio < 1) {
|
||||||
|
throw new IllegalArgumentException("Harmonic data count must be integer multiple of power data count");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initializeArrays() {
|
||||||
|
if (data.harmonicData == null) {
|
||||||
|
data.harmonicData = new float[data.harmonicCount];
|
||||||
|
}
|
||||||
|
if (data.powerData == null) {
|
||||||
|
data.powerData = new float[data.powerCount][data.powerNodeCount];
|
||||||
|
}
|
||||||
|
|
||||||
|
int resultCount = data.powerCount - data.windowSize;
|
||||||
|
if (resultCount > 0) {
|
||||||
|
data.correlationData = new float[resultCount][data.powerNodeCount];
|
||||||
|
data.fkData = new float[resultCount][data.powerNodeCount];
|
||||||
|
data.hkData = new float[resultCount][data.powerNodeCount + 1];
|
||||||
|
data.canonicalCorrelation = new float[resultCount];
|
||||||
|
data.backgroundCanonicalCorr = new float[resultCount];
|
||||||
|
}
|
||||||
|
|
||||||
|
data.sumFKData = new float[data.powerNodeCount];
|
||||||
|
data.sumHKData = new float[data.powerNodeCount + 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getters and Setters
|
||||||
|
public CalculationMode getCalculationMode() {
|
||||||
|
return calculationMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCalculationMode(CalculationMode calculationMode) {
|
||||||
|
this.calculationMode = calculationMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHarmonicCount() {
|
||||||
|
return harmonicCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHarmonicCount(int harmonicCount) {
|
||||||
|
this.harmonicCount = harmonicCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPowerCount() {
|
||||||
|
return powerCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPowerCount(int powerCount) {
|
||||||
|
this.powerCount = powerCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPowerNodeCount() {
|
||||||
|
return powerNodeCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPowerNodeCount(int powerNodeCount) {
|
||||||
|
this.powerNodeCount = powerNodeCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWindowSize() {
|
||||||
|
return windowSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWindowSize(int windowSize) {
|
||||||
|
this.windowSize = windowSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getResponsibilityDataCount() {
|
||||||
|
return responsibilityDataCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResponsibilityDataCount(int responsibilityDataCount) {
|
||||||
|
this.responsibilityDataCount = responsibilityDataCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getHarmonicThreshold() {
|
||||||
|
return harmonicThreshold;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHarmonicThreshold(float harmonicThreshold) {
|
||||||
|
this.harmonicThreshold = harmonicThreshold;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float[] getHarmonicData() {
|
||||||
|
return harmonicData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHarmonicData(float[] harmonicData) {
|
||||||
|
this.harmonicData = harmonicData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float[][] getPowerData() {
|
||||||
|
return powerData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPowerData(float[][] powerData) {
|
||||||
|
this.powerData = powerData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float[][] getCorrelationData() {
|
||||||
|
return correlationData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCorrelationData(float[][] correlationData) {
|
||||||
|
this.correlationData = correlationData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float[][] getFkData() {
|
||||||
|
return fkData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFkData(float[][] fkData) {
|
||||||
|
this.fkData = fkData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float[][] getHkData() {
|
||||||
|
return hkData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHkData(float[][] hkData) {
|
||||||
|
this.hkData = hkData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float[] getCanonicalCorrelation() {
|
||||||
|
return canonicalCorrelation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCanonicalCorrelation(float[] canonicalCorrelation) {
|
||||||
|
this.canonicalCorrelation = canonicalCorrelation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float[] getBackgroundCanonicalCorr() {
|
||||||
|
return backgroundCanonicalCorr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBackgroundCanonicalCorr(float[] backgroundCanonicalCorr) {
|
||||||
|
this.backgroundCanonicalCorr = backgroundCanonicalCorr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CalculationStatus getCalculationStatus() {
|
||||||
|
return calculationStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCalculationStatus(CalculationStatus calculationStatus) {
|
||||||
|
this.calculationStatus = calculationStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float[] getSumFKData() {
|
||||||
|
return sumFKData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSumFKData(float[] sumFKData) {
|
||||||
|
this.sumFKData = sumFKData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float[] getSumHKData() {
|
||||||
|
return sumHKData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSumHKData(float[] sumHKData) {
|
||||||
|
this.sumHKData = sumHKData;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package com.njcn.advance.responsibility.service;
|
||||||
|
|
||||||
|
import com.njcn.advance.responsibility.model.HarmonicData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 谐波责任计算服务接口
|
||||||
|
*
|
||||||
|
* @author hongawen
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
public interface IHarmonicResponsibilityService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行谐波责任计算
|
||||||
|
*
|
||||||
|
* @param data 输入的谐波数据
|
||||||
|
* @return 计算是否成功
|
||||||
|
*/
|
||||||
|
boolean calculate(HarmonicData data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行完整计算
|
||||||
|
*
|
||||||
|
* @param harmonicData 谐波数据数组
|
||||||
|
* @param powerData 功率数据矩阵
|
||||||
|
* @param harmonicCount 谐波数据个数
|
||||||
|
* @param powerCount 功率数据个数
|
||||||
|
* @param nodeCount 节点数量
|
||||||
|
* @param windowSize 窗口大小
|
||||||
|
* @param threshold 谐波门槛
|
||||||
|
* @return 计算结果
|
||||||
|
*/
|
||||||
|
HarmonicData fullCalculation(float[] harmonicData, float[][] powerData,
|
||||||
|
int harmonicCount, int powerCount, int nodeCount,
|
||||||
|
int windowSize, float threshold);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行部分重算
|
||||||
|
*
|
||||||
|
* @param harmonicData 谐波数据数组
|
||||||
|
* @param fkData FK数据矩阵
|
||||||
|
* @param hkData HK数据矩阵
|
||||||
|
* @param harmonicCount 谐波数据个数
|
||||||
|
* @param nodeCount 节点数量
|
||||||
|
* @param windowSize 窗口大小
|
||||||
|
* @param responsibilityCount 责任数据个数
|
||||||
|
* @param threshold 谐波门槛
|
||||||
|
* @return 计算结果
|
||||||
|
*/
|
||||||
|
HarmonicData partialCalculation(float[] harmonicData, float[][] fkData, float[][] hkData,
|
||||||
|
int harmonicCount, int nodeCount, int windowSize,
|
||||||
|
int responsibilityCount, float threshold);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证输入数据的有效性
|
||||||
|
*
|
||||||
|
* @param data 待验证的数据
|
||||||
|
* @return 验证结果消息,null表示验证通过
|
||||||
|
*/
|
||||||
|
String validateData(HarmonicData data);
|
||||||
|
}
|
||||||
@@ -0,0 +1,162 @@
|
|||||||
|
package com.njcn.advance.responsibility.service.impl;
|
||||||
|
|
||||||
|
import com.njcn.advance.responsibility.calculator.HarmonicCalculationEngine;
|
||||||
|
import com.njcn.advance.responsibility.constant.CalculationMode;
|
||||||
|
import com.njcn.advance.responsibility.constant.HarmonicConstants;
|
||||||
|
import com.njcn.advance.responsibility.model.HarmonicData;
|
||||||
|
import com.njcn.advance.responsibility.service.IHarmonicResponsibilityService;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 谐波责任计算服务实现类
|
||||||
|
*
|
||||||
|
* @author hongawen
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class HarmonicResponsibilityServiceImpl implements IHarmonicResponsibilityService {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(HarmonicResponsibilityServiceImpl.class);
|
||||||
|
|
||||||
|
private final HarmonicCalculationEngine engine;
|
||||||
|
|
||||||
|
public HarmonicResponsibilityServiceImpl() {
|
||||||
|
this.engine = new HarmonicCalculationEngine();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean calculate(HarmonicData data) {
|
||||||
|
if (data == null) {
|
||||||
|
logger.error("Input data is null");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String validationError = validateData(data);
|
||||||
|
if (validationError != null) {
|
||||||
|
logger.error("Data validation failed: {}", validationError);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
boolean result = engine.calculate(data);
|
||||||
|
long endTime = System.currentTimeMillis();
|
||||||
|
|
||||||
|
logger.info("Calculation completed in {} ms, result: {}", (endTime - startTime), result);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HarmonicData fullCalculation(float[] harmonicData, float[][] powerData,
|
||||||
|
int harmonicCount, int powerCount, int nodeCount,
|
||||||
|
int windowSize, float threshold) {
|
||||||
|
logger.info("Starting full calculation with harmonicCount={}, powerCount={}, nodeCount={}, windowSize={}",
|
||||||
|
harmonicCount, powerCount, nodeCount, windowSize);
|
||||||
|
|
||||||
|
HarmonicData data = new HarmonicData.Builder()
|
||||||
|
.calculationMode(CalculationMode.FULL_CALCULATION)
|
||||||
|
.harmonicCount(harmonicCount)
|
||||||
|
.powerCount(powerCount)
|
||||||
|
.powerNodeCount(nodeCount)
|
||||||
|
.windowSize(windowSize)
|
||||||
|
.harmonicThreshold(threshold)
|
||||||
|
.harmonicData(harmonicData)
|
||||||
|
.powerData(powerData)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
calculate(data);
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HarmonicData partialCalculation(float[] harmonicData, float[][] fkData, float[][] hkData,
|
||||||
|
int harmonicCount, int nodeCount, int windowSize,
|
||||||
|
int responsibilityCount, float threshold) {
|
||||||
|
logger.info("Starting partial calculation with harmonicCount={}, nodeCount={}, windowSize={}, responsibilityCount={}",
|
||||||
|
harmonicCount, nodeCount, windowSize, responsibilityCount);
|
||||||
|
|
||||||
|
HarmonicData data = new HarmonicData();
|
||||||
|
data.setCalculationMode(CalculationMode.PARTIAL_RECALCULATION);
|
||||||
|
data.setHarmonicCount(harmonicCount);
|
||||||
|
data.setPowerNodeCount(nodeCount);
|
||||||
|
data.setWindowSize(windowSize);
|
||||||
|
data.setResponsibilityDataCount(responsibilityCount);
|
||||||
|
data.setHarmonicThreshold(threshold);
|
||||||
|
data.setHarmonicData(harmonicData);
|
||||||
|
data.setFkData(fkData);
|
||||||
|
data.setHkData(hkData);
|
||||||
|
|
||||||
|
// 初始化输出数组
|
||||||
|
data.setSumFKData(new float[nodeCount]);
|
||||||
|
data.setSumHKData(new float[nodeCount + 1]);
|
||||||
|
|
||||||
|
calculate(data);
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String validateData(HarmonicData data) {
|
||||||
|
if (data == null) {
|
||||||
|
return "Data object is null";
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证基本参数
|
||||||
|
if (data.getHarmonicCount() <= 0 || data.getHarmonicCount() > HarmonicConstants.MAX_HARM_NUM) {
|
||||||
|
return String.format("Invalid harmonic count: %d (should be 1-%d)",
|
||||||
|
data.getHarmonicCount(), HarmonicConstants.MAX_HARM_NUM);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.getCalculationMode() == CalculationMode.FULL_CALCULATION) {
|
||||||
|
// 完整计算模式验证
|
||||||
|
if (data.getPowerCount() <= 0 || data.getPowerCount() > HarmonicConstants.MAX_P_NUM) {
|
||||||
|
return String.format("Invalid power count: %d (should be 1-%d)",
|
||||||
|
data.getPowerCount(), HarmonicConstants.MAX_P_NUM);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.getPowerNodeCount() <= 0 || data.getPowerNodeCount() > HarmonicConstants.MAX_P_NODE) {
|
||||||
|
return String.format("Invalid power node count: %d (should be 1-%d)",
|
||||||
|
data.getPowerNodeCount(), HarmonicConstants.MAX_P_NODE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证数据对齐
|
||||||
|
int ratio = data.getHarmonicCount() / data.getPowerCount();
|
||||||
|
if (ratio * data.getPowerCount() != data.getHarmonicCount()) {
|
||||||
|
return String.format("Harmonic count %d is not aligned with power count %d",
|
||||||
|
data.getHarmonicCount(), data.getPowerCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证数据数组
|
||||||
|
if (data.getHarmonicData() == null || data.getHarmonicData().length < data.getHarmonicCount()) {
|
||||||
|
return "Harmonic data array is null or insufficient";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.getPowerData() == null || data.getPowerData().length < data.getPowerCount()) {
|
||||||
|
return "Power data array is null or insufficient";
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (data.getCalculationMode() == CalculationMode.PARTIAL_RECALCULATION) {
|
||||||
|
// 部分计算模式验证
|
||||||
|
if (data.getResponsibilityDataCount() + data.getWindowSize() != data.getHarmonicCount()) {
|
||||||
|
return String.format("Data length mismatch: resNum(%d) + winSize(%d) != harmCount(%d)",
|
||||||
|
data.getResponsibilityDataCount(), data.getWindowSize(), data.getHarmonicCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.getFkData() == null || data.getHkData() == null) {
|
||||||
|
return "FK or HK data is null for partial calculation";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证窗口大小
|
||||||
|
if (data.getWindowSize() < HarmonicConstants.MIN_WIN_LEN ||
|
||||||
|
data.getWindowSize() > HarmonicConstants.MAX_WIN_LEN) {
|
||||||
|
return String.format("Invalid window size: %d (should be %d-%d)",
|
||||||
|
data.getWindowSize(), HarmonicConstants.MIN_WIN_LEN, HarmonicConstants.MAX_WIN_LEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null; // 验证通过
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,314 @@
|
|||||||
|
package com.njcn.advance.responsibility.utils;
|
||||||
|
|
||||||
|
import com.njcn.advance.responsibility.constant.HarmonicConstants;
|
||||||
|
import org.apache.commons.math3.linear.*;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数学工具类
|
||||||
|
* 提供基础数学计算功能
|
||||||
|
*
|
||||||
|
* @author hongawen
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
public class MathUtils {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(MathUtils.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算协方差
|
||||||
|
*
|
||||||
|
* @param x 数据序列1
|
||||||
|
* @param y 数据序列2
|
||||||
|
* @param width 数据窗宽度
|
||||||
|
* @return 协方差值
|
||||||
|
*/
|
||||||
|
public static double covariance(double[] x, double[] y, int width) {
|
||||||
|
if (x == null || y == null || width <= 0) {
|
||||||
|
throw new IllegalArgumentException("Invalid input parameters for covariance calculation");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x.length < width || y.length < width) {
|
||||||
|
throw new IllegalArgumentException("Data length is less than window width");
|
||||||
|
}
|
||||||
|
|
||||||
|
double meanX = 0.0;
|
||||||
|
double meanY = 0.0;
|
||||||
|
|
||||||
|
// 计算均值
|
||||||
|
for (int i = 0; i < width; i++) {
|
||||||
|
meanX += x[i];
|
||||||
|
meanY += y[i];
|
||||||
|
}
|
||||||
|
meanX /= width;
|
||||||
|
meanY /= width;
|
||||||
|
|
||||||
|
// 计算协方差
|
||||||
|
double cov = 0.0;
|
||||||
|
for (int i = 0; i < width; i++) {
|
||||||
|
cov += (x[i] - meanX) * (y[i] - meanY);
|
||||||
|
}
|
||||||
|
|
||||||
|
return cov / (width - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算协方差(float版本)
|
||||||
|
*/
|
||||||
|
public static float covariance(float[] x, float[] y, int width) {
|
||||||
|
double[] dx = new double[x.length];
|
||||||
|
double[] dy = new double[y.length];
|
||||||
|
for (int i = 0; i < x.length; i++) dx[i] = x[i];
|
||||||
|
for (int i = 0; i < y.length; i++) dy[i] = y[i];
|
||||||
|
return (float) covariance(dx, dy, width);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算Pearson相关系数
|
||||||
|
*
|
||||||
|
* @param x 数据序列1
|
||||||
|
* @param y 数据序列2
|
||||||
|
* @param count 数据长度
|
||||||
|
* @return Pearson相关系数
|
||||||
|
*/
|
||||||
|
public static double pearsonCorrelation(double[] x, double[] y, int count) {
|
||||||
|
if (x == null || y == null || count <= 0) {
|
||||||
|
throw new IllegalArgumentException("Invalid input parameters for Pearson correlation");
|
||||||
|
}
|
||||||
|
|
||||||
|
double meanX = 0.0;
|
||||||
|
double meanY = 0.0;
|
||||||
|
|
||||||
|
// 计算均值
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
meanX += x[i];
|
||||||
|
meanY += y[i];
|
||||||
|
}
|
||||||
|
meanX /= count;
|
||||||
|
meanY /= count;
|
||||||
|
|
||||||
|
// 计算相关系数的各个部分
|
||||||
|
double numerator = 0.0;
|
||||||
|
double denomX = 0.0;
|
||||||
|
double denomY = 0.0;
|
||||||
|
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
double dx = x[i] - meanX;
|
||||||
|
double dy = y[i] - meanY;
|
||||||
|
numerator += dx * dy;
|
||||||
|
denomX += dx * dx;
|
||||||
|
denomY += dy * dy;
|
||||||
|
}
|
||||||
|
|
||||||
|
double denominator = Math.sqrt(denomX * denomY);
|
||||||
|
|
||||||
|
if (Math.abs(denominator) < HarmonicConstants.EPSILON) {
|
||||||
|
logger.warn("Denominator is too small in Pearson correlation calculation");
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return numerator / denominator;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算Pearson相关系数(float版本)
|
||||||
|
*/
|
||||||
|
public static float pearsonCorrelation(float[] x, float[] y, int count) {
|
||||||
|
double[] dx = new double[count];
|
||||||
|
double[] dy = new double[count];
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
dx[i] = x[i];
|
||||||
|
dy[i] = y[i];
|
||||||
|
}
|
||||||
|
return (float) pearsonCorrelation(dx, dy, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算协方差矩阵(SXX)
|
||||||
|
*
|
||||||
|
* @param data 数据矩阵 [时间][节点]
|
||||||
|
* @param width 窗口宽度
|
||||||
|
* @param nodeCount 节点数
|
||||||
|
* @return 协方差矩阵
|
||||||
|
*/
|
||||||
|
public static double[][] covarianceMatrix(double[][] data, int width, int nodeCount) {
|
||||||
|
double[][] covMatrix = new double[nodeCount][nodeCount];
|
||||||
|
|
||||||
|
for (int i = 0; i < nodeCount; i++) {
|
||||||
|
for (int j = 0; j < nodeCount; j++) {
|
||||||
|
double[] col1 = new double[width];
|
||||||
|
double[] col2 = new double[width];
|
||||||
|
|
||||||
|
for (int k = 0; k < width; k++) {
|
||||||
|
col1[k] = data[k][i];
|
||||||
|
col2[k] = data[k][j];
|
||||||
|
}
|
||||||
|
|
||||||
|
covMatrix[i][j] = covariance(col1, col2, width);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return covMatrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算协方差矩阵(float版本)
|
||||||
|
*/
|
||||||
|
public static float[][] covarianceMatrix(float[][] data, int width, int nodeCount) {
|
||||||
|
float[][] covMatrix = new float[nodeCount][nodeCount];
|
||||||
|
|
||||||
|
for (int i = 0; i < nodeCount; i++) {
|
||||||
|
for (int j = 0; j < nodeCount; j++) {
|
||||||
|
float[] col1 = new float[width];
|
||||||
|
float[] col2 = new float[width];
|
||||||
|
|
||||||
|
for (int k = 0; k < width; k++) {
|
||||||
|
col1[k] = data[k][i];
|
||||||
|
col2[k] = data[k][j];
|
||||||
|
}
|
||||||
|
|
||||||
|
covMatrix[i][j] = covariance(col1, col2, width);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return covMatrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算协方差向量(SXY)
|
||||||
|
*
|
||||||
|
* @param data 数据矩阵 [时间][节点]
|
||||||
|
* @param y 目标向量
|
||||||
|
* @param width 窗口宽度
|
||||||
|
* @param nodeCount 节点数
|
||||||
|
* @return 协方差向量
|
||||||
|
*/
|
||||||
|
public static double[] covarianceVector(double[][] data, double[] y, int width, int nodeCount) {
|
||||||
|
double[] covVector = new double[nodeCount];
|
||||||
|
|
||||||
|
for (int i = 0; i < nodeCount; i++) {
|
||||||
|
double[] col = new double[width];
|
||||||
|
for (int k = 0; k < width; k++) {
|
||||||
|
col[k] = data[k][i];
|
||||||
|
}
|
||||||
|
covVector[i] = covariance(col, y, width);
|
||||||
|
}
|
||||||
|
|
||||||
|
return covVector;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算协方差向量(float版本)
|
||||||
|
*/
|
||||||
|
public static float[] covarianceVector(float[][] data, float[] y, int width, int nodeCount) {
|
||||||
|
float[] covVector = new float[nodeCount];
|
||||||
|
|
||||||
|
for (int i = 0; i < nodeCount; i++) {
|
||||||
|
float[] col = new float[width];
|
||||||
|
for (int k = 0; k < width; k++) {
|
||||||
|
col[k] = data[k][i];
|
||||||
|
}
|
||||||
|
covVector[i] = covariance(col, y, width);
|
||||||
|
}
|
||||||
|
|
||||||
|
return covVector;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 矩阵求逆
|
||||||
|
* 使用Apache Commons Math库
|
||||||
|
*
|
||||||
|
* @param matrix 输入矩阵
|
||||||
|
* @return 逆矩阵
|
||||||
|
*/
|
||||||
|
public static double[][] matrixInverse(double[][] matrix) {
|
||||||
|
RealMatrix realMatrix = new Array2DRowRealMatrix(matrix);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 使用LU分解求逆
|
||||||
|
DecompositionSolver solver = new LUDecomposition(realMatrix).getSolver();
|
||||||
|
RealMatrix inverseMatrix = solver.getInverse();
|
||||||
|
return inverseMatrix.getData();
|
||||||
|
} catch (SingularMatrixException e) {
|
||||||
|
logger.error("Matrix is singular, cannot compute inverse", e);
|
||||||
|
throw new RuntimeException("Matrix inversion failed: singular matrix");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算矩阵的特征值
|
||||||
|
*
|
||||||
|
* @param matrix 输入矩阵
|
||||||
|
* @return 特征值数组
|
||||||
|
*/
|
||||||
|
public static double[] eigenvalues(double[][] matrix) {
|
||||||
|
RealMatrix realMatrix = new Array2DRowRealMatrix(matrix);
|
||||||
|
EigenDecomposition eigenDecomposition = new EigenDecomposition(realMatrix);
|
||||||
|
return eigenDecomposition.getRealEigenvalues();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 归一化处理
|
||||||
|
* 将数据归一化到[0,1]区间
|
||||||
|
*
|
||||||
|
* @param data 输入数据
|
||||||
|
* @return 归一化后的数据
|
||||||
|
*/
|
||||||
|
public static double[] normalize(double[] data) {
|
||||||
|
if (data == null || data.length == 0) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
double min = Double.MAX_VALUE;
|
||||||
|
double max = Double.MIN_VALUE;
|
||||||
|
|
||||||
|
// 找最大最小值
|
||||||
|
for (double value : data) {
|
||||||
|
min = Math.min(min, value);
|
||||||
|
max = Math.max(max, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
double range = max - min;
|
||||||
|
if (Math.abs(range) < HarmonicConstants.EPSILON) {
|
||||||
|
return new double[data.length]; // 返回全0数组
|
||||||
|
}
|
||||||
|
|
||||||
|
double[] normalized = new double[data.length];
|
||||||
|
for (int i = 0; i < data.length; i++) {
|
||||||
|
normalized[i] = (data[i] - min) / range;
|
||||||
|
}
|
||||||
|
|
||||||
|
return normalized;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据对齐处理
|
||||||
|
* 将不同采样间隔的数据对齐到相同的时间间隔
|
||||||
|
*
|
||||||
|
* @param data 原始数据
|
||||||
|
* @param originalInterval 原始采样间隔
|
||||||
|
* @param targetInterval 目标采样间隔
|
||||||
|
* @return 对齐后的数据
|
||||||
|
*/
|
||||||
|
public static float[] alignData(float[] data, int originalInterval, int targetInterval) {
|
||||||
|
if (targetInterval % originalInterval != 0) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Target interval must be multiple of original interval");
|
||||||
|
}
|
||||||
|
|
||||||
|
int ratio = targetInterval / originalInterval;
|
||||||
|
int newLength = data.length / ratio;
|
||||||
|
float[] alignedData = new float[newLength];
|
||||||
|
|
||||||
|
for (int i = 0; i < newLength; i++) {
|
||||||
|
float sum = 0;
|
||||||
|
for (int j = 0; j < ratio; j++) {
|
||||||
|
sum += data[i * ratio + j];
|
||||||
|
}
|
||||||
|
alignedData[i] = sum / ratio;
|
||||||
|
}
|
||||||
|
|
||||||
|
return alignedData;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,4 +11,6 @@ import com.njcn.advance.pojo.dto.waveAnalysis.EntityAdvancedData;
|
|||||||
public interface EventWaveAnalysisService {
|
public interface EventWaveAnalysisService {
|
||||||
|
|
||||||
EntityAdvancedData analysis(String eventIndex);
|
EntityAdvancedData analysis(String eventIndex);
|
||||||
|
|
||||||
|
EntityAdvancedData analysisWlEvent(String eventIndex);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -565,7 +565,7 @@ public class SecondaryEvaluationServiceImpl implements SecondaryEvaluationServic
|
|||||||
unblance.add(evaluationResult);
|
unblance.add(evaluationResult);
|
||||||
|
|
||||||
evaluationResult = new AssessResultVO.EvaluationResult();
|
evaluationResult = new AssessResultVO.EvaluationResult();
|
||||||
evaluationResult.setData(result.getApproUnblance().multiply(BigDecimal.valueOf(200)));
|
evaluationResult.setData(result.getApproUnblance());
|
||||||
evaluationResult.setLimitData(overLimit.getUnblance());
|
evaluationResult.setLimitData(overLimit.getUnblance());
|
||||||
evaluationResult.setIsQualified(NumberUtil.isLess(evaluationResult.getData(), evaluationResult.getLimitData()));
|
evaluationResult.setIsQualified(NumberUtil.isLess(evaluationResult.getData(), evaluationResult.getLimitData()));
|
||||||
unblance.add(evaluationResult);
|
unblance.add(evaluationResult);
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ public class GovernSchemeCalcServiceImpl implements IGovernSchemeCalcService {
|
|||||||
throw new BusinessException(AdvanceResponseEnum.INCOMING_LINE_DATA_MISS);
|
throw new BusinessException(AdvanceResponseEnum.INCOMING_LINE_DATA_MISS);
|
||||||
}
|
}
|
||||||
sgGovernSchemeHistoryAllVO.setInComingLineName(sgIncomingLine.getName());
|
sgGovernSchemeHistoryAllVO.setInComingLineName(sgIncomingLine.getName());
|
||||||
|
sgGovernSchemeHistoryAllVO.getQuick().setIncomingLineId(sgIncomingLine.getName());
|
||||||
//时间内的电网接入水平(暂降次数)
|
//时间内的电网接入水平(暂降次数)
|
||||||
String startTime = sgGovernSchemeHistoryParam.getStartTime();
|
String startTime = sgGovernSchemeHistoryParam.getStartTime();
|
||||||
String endTime = sgGovernSchemeHistoryParam.getEndTime();
|
String endTime = sgGovernSchemeHistoryParam.getEndTime();
|
||||||
|
|||||||
@@ -322,10 +322,7 @@ public class SgEventServiceImpl extends ServiceImpl<SgEventMapper, SgEvent> impl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteEventData(List<String> ids) {
|
public boolean deleteEventData(List<String> ids) {
|
||||||
return this.lambdaUpdate()
|
return this.removeByIds(ids);
|
||||||
.set(SgEvent::getState, DataStateEnum.DELETED.getCode())
|
|
||||||
.in(SgEvent::getId, ids)
|
|
||||||
.update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -9,8 +9,10 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|||||||
import com.njcn.advance.enums.AdvanceResponseEnum;
|
import com.njcn.advance.enums.AdvanceResponseEnum;
|
||||||
import com.njcn.advance.mapper.govern.voltage.SgMachineMapper;
|
import com.njcn.advance.mapper.govern.voltage.SgMachineMapper;
|
||||||
import com.njcn.advance.pojo.param.govern.voltage.SgMachineParam;
|
import com.njcn.advance.pojo.param.govern.voltage.SgMachineParam;
|
||||||
|
import com.njcn.advance.pojo.param.govern.voltage.SgUserParam;
|
||||||
import com.njcn.advance.pojo.po.govern.voltage.SgMachine;
|
import com.njcn.advance.pojo.po.govern.voltage.SgMachine;
|
||||||
import com.njcn.advance.pojo.po.govern.voltage.SgSensitiveUnit;
|
import com.njcn.advance.pojo.po.govern.voltage.SgSensitiveUnit;
|
||||||
|
import com.njcn.advance.pojo.po.govern.voltage.SgUser;
|
||||||
import com.njcn.advance.pojo.vo.govern.voltage.SgMachineVO;
|
import com.njcn.advance.pojo.vo.govern.voltage.SgMachineVO;
|
||||||
import com.njcn.advance.service.govern.voltage.ISgMachineService;
|
import com.njcn.advance.service.govern.voltage.ISgMachineService;
|
||||||
import com.njcn.advance.service.govern.voltage.ISgSensitiveUnitService;
|
import com.njcn.advance.service.govern.voltage.ISgSensitiveUnitService;
|
||||||
@@ -56,12 +58,34 @@ public class SgMachineServiceImpl extends ServiceImpl<SgMachineMapper, SgMachine
|
|||||||
@Override
|
@Override
|
||||||
public String addMachine(SgMachineParam sgMachineParam) {
|
public String addMachine(SgMachineParam sgMachineParam) {
|
||||||
SgMachine sgMachine = new SgMachine();
|
SgMachine sgMachine = new SgMachine();
|
||||||
|
checkMachineName(sgMachineParam, false);
|
||||||
|
|
||||||
BeanUtil.copyProperties(sgMachineParam, sgMachine);
|
BeanUtil.copyProperties(sgMachineParam, sgMachine);
|
||||||
//默认为正常状态
|
//默认为正常状态
|
||||||
sgMachine.setState(DataStateEnum.ENABLE.getCode());
|
sgMachine.setState(DataStateEnum.ENABLE.getCode());
|
||||||
this.save(sgMachine);
|
this.save(sgMachine);
|
||||||
return sgMachine.getId();
|
return sgMachine.getId();
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 校验参数,检查是否存在相同名称的业务用户
|
||||||
|
*/
|
||||||
|
private void checkMachineName(SgMachineParam sgMachineParam, boolean isExcludeSelf) {
|
||||||
|
LambdaQueryWrapper<SgMachine> sgUserLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
sgUserLambdaQueryWrapper
|
||||||
|
.eq(SgMachine::getName, sgMachineParam.getName())
|
||||||
|
.eq(SgMachine::getState, DataStateEnum.ENABLE.getCode());
|
||||||
|
//更新的时候,需排除当前记录
|
||||||
|
if (isExcludeSelf) {
|
||||||
|
if (sgMachineParam instanceof SgMachineParam.SgMachineUpdateParam) {
|
||||||
|
sgUserLambdaQueryWrapper.ne(SgMachine::getId, ((SgMachineParam.SgMachineUpdateParam) sgMachineParam).getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int countByAccount = this.count(sgUserLambdaQueryWrapper);
|
||||||
|
//大于等于1个则表示重复
|
||||||
|
if (countByAccount >= 1) {
|
||||||
|
throw new BusinessException(AdvanceResponseEnum.SG_USER_NAME_REPEAT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新设备
|
* 更新设备
|
||||||
@@ -70,6 +94,8 @@ public class SgMachineServiceImpl extends ServiceImpl<SgMachineMapper, SgMachine
|
|||||||
@Override
|
@Override
|
||||||
public boolean updateSgMachine(SgMachineParam.SgMachineUpdateParam updateParam) {
|
public boolean updateSgMachine(SgMachineParam.SgMachineUpdateParam updateParam) {
|
||||||
SgMachine sgMachine = new SgMachine();
|
SgMachine sgMachine = new SgMachine();
|
||||||
|
checkMachineName(updateParam, true);
|
||||||
|
|
||||||
BeanUtil.copyProperties(updateParam, sgMachine);
|
BeanUtil.copyProperties(updateParam, sgMachine);
|
||||||
return this.updateById(sgMachine);
|
return this.updateById(sgMachine);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,15 @@ package com.njcn.advance.service.govern.voltage.impl;
|
|||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.njcn.advance.enums.AdvanceResponseEnum;
|
import com.njcn.advance.enums.AdvanceResponseEnum;
|
||||||
import com.njcn.advance.mapper.govern.voltage.SgSensitiveUnitMapper;
|
import com.njcn.advance.mapper.govern.voltage.SgSensitiveUnitMapper;
|
||||||
|
import com.njcn.advance.pojo.param.govern.voltage.SgMachineParam;
|
||||||
import com.njcn.advance.pojo.param.govern.voltage.SgSensitiveUnitParam;
|
import com.njcn.advance.pojo.param.govern.voltage.SgSensitiveUnitParam;
|
||||||
|
import com.njcn.advance.pojo.po.govern.voltage.SgMachine;
|
||||||
import com.njcn.advance.pojo.po.govern.voltage.SgSensitiveUnit;
|
import com.njcn.advance.pojo.po.govern.voltage.SgSensitiveUnit;
|
||||||
import com.njcn.advance.pojo.vo.govern.voltage.SgSensitiveUnitVO;
|
import com.njcn.advance.pojo.vo.govern.voltage.SgSensitiveUnitVO;
|
||||||
import com.njcn.advance.service.govern.voltage.ISgSensitiveUnitService;
|
import com.njcn.advance.service.govern.voltage.ISgSensitiveUnitService;
|
||||||
@@ -54,12 +57,34 @@ public class SgSensitiveUnitServiceImpl extends ServiceImpl<SgSensitiveUnitMappe
|
|||||||
@Override
|
@Override
|
||||||
public String addSensitiveUnit(SgSensitiveUnitParam sgSensitiveUnitParam) {
|
public String addSensitiveUnit(SgSensitiveUnitParam sgSensitiveUnitParam) {
|
||||||
SgSensitiveUnit sgSensitiveUnit = new SgSensitiveUnit();
|
SgSensitiveUnit sgSensitiveUnit = new SgSensitiveUnit();
|
||||||
|
checkSensitiveUnitName(sgSensitiveUnitParam, false);
|
||||||
|
|
||||||
BeanUtil.copyProperties(sgSensitiveUnitParam, sgSensitiveUnit);
|
BeanUtil.copyProperties(sgSensitiveUnitParam, sgSensitiveUnit);
|
||||||
//默认为正常状态
|
//默认为正常状态
|
||||||
sgSensitiveUnit.setState(DataStateEnum.ENABLE.getCode());
|
sgSensitiveUnit.setState(DataStateEnum.ENABLE.getCode());
|
||||||
this.save(sgSensitiveUnit);
|
this.save(sgSensitiveUnit);
|
||||||
return sgSensitiveUnit.getId();
|
return sgSensitiveUnit.getId();
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 校验参数,检查是否存在相同名称的业务用户
|
||||||
|
*/
|
||||||
|
private void checkSensitiveUnitName(SgSensitiveUnitParam sgSensitiveUnitParam, boolean isExcludeSelf) {
|
||||||
|
LambdaQueryWrapper<SgSensitiveUnit> sgUserLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
sgUserLambdaQueryWrapper
|
||||||
|
.eq(SgSensitiveUnit::getName, sgSensitiveUnitParam.getName())
|
||||||
|
.eq(SgSensitiveUnit::getState, DataStateEnum.ENABLE.getCode());
|
||||||
|
//更新的时候,需排除当前记录
|
||||||
|
if (isExcludeSelf) {
|
||||||
|
if (sgSensitiveUnitParam instanceof SgSensitiveUnitParam.SgSensitiveUnitUpdateParam) {
|
||||||
|
sgUserLambdaQueryWrapper.ne(SgSensitiveUnit::getId, ((SgSensitiveUnitParam.SgSensitiveUnitUpdateParam) sgSensitiveUnitParam).getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int countByAccount = this.count(sgUserLambdaQueryWrapper);
|
||||||
|
//大于等于1个则表示重复
|
||||||
|
if (countByAccount >= 1) {
|
||||||
|
throw new BusinessException(AdvanceResponseEnum.SG_USER_NAME_REPEAT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新元器件
|
* 更新元器件
|
||||||
@@ -69,6 +94,8 @@ public class SgSensitiveUnitServiceImpl extends ServiceImpl<SgSensitiveUnitMappe
|
|||||||
@Override
|
@Override
|
||||||
public boolean updateSgSensitiveUnit(SgSensitiveUnitParam.SgSensitiveUnitUpdateParam updateParam) {
|
public boolean updateSgSensitiveUnit(SgSensitiveUnitParam.SgSensitiveUnitUpdateParam updateParam) {
|
||||||
SgSensitiveUnit sgSensitiveUnit = new SgSensitiveUnit();
|
SgSensitiveUnit sgSensitiveUnit = new SgSensitiveUnit();
|
||||||
|
checkSensitiveUnitName(updateParam, true);
|
||||||
|
|
||||||
BeanUtil.copyProperties(updateParam, sgSensitiveUnit);
|
BeanUtil.copyProperties(updateParam, sgSensitiveUnit);
|
||||||
return this.updateById(sgSensitiveUnit);
|
return this.updateById(sgSensitiveUnit);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,9 +48,11 @@ import io.swagger.models.auth.In;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.sf.json.JSONObject;
|
import net.sf.json.JSONObject;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
@@ -471,6 +473,8 @@ public class EventRelevantAnalysisServiceImpl extends ServiceImpl<RmpEventAdvanc
|
|||||||
|
|
||||||
List<AdvanceEventDetailVO> advanceEventDetailVOList = BeanUtil.copyToList(rmpEventDetailPOList, AdvanceEventDetailVO.class);
|
List<AdvanceEventDetailVO> advanceEventDetailVOList = BeanUtil.copyToList(rmpEventDetailPOList, AdvanceEventDetailVO.class);
|
||||||
advanceEventDetailVOList = advanceEventDetailVOList.stream().peek(item -> {
|
advanceEventDetailVOList = advanceEventDetailVOList.stream().peek(item -> {
|
||||||
|
item.setFeatureAmplitude(roundHalfUp(item.getFeatureAmplitude()*100));
|
||||||
|
|
||||||
if (map.containsKey(item.getLineId())) {
|
if (map.containsKey(item.getLineId())) {
|
||||||
AreaLineInfoVO areaLineInfoVO = map.get(item.getLineId());
|
AreaLineInfoVO areaLineInfoVO = map.get(item.getLineId());
|
||||||
item.setGdName(areaLineInfoVO.getGdName());
|
item.setGdName(areaLineInfoVO.getGdName());
|
||||||
@@ -489,7 +493,17 @@ public class EventRelevantAnalysisServiceImpl extends ServiceImpl<RmpEventAdvanc
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 四舍五入保留两位小数
|
||||||
|
*/
|
||||||
|
private Double roundHalfUp(double num) {
|
||||||
|
if (num == 3.14159) {
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
BigDecimal b = new BigDecimal(num);
|
||||||
|
//保留2位小数
|
||||||
|
return com.njcn.harmonic.utils.PubUtils.dataLimits(b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public Page<RmpEventDetailAssPO> queryEventsAssPage(BaseParam baseParam) {
|
public Page<RmpEventDetailAssPO> queryEventsAssPage(BaseParam baseParam) {
|
||||||
List<LocalDateTime> timeV = PubUtils.checkLocalDate(baseParam.getSearchBeginTime(), baseParam.getSearchEndTime());
|
List<LocalDateTime> timeV = PubUtils.checkLocalDate(baseParam.getSearchBeginTime(), baseParam.getSearchEndTime());
|
||||||
@@ -498,7 +512,7 @@ public class EventRelevantAnalysisServiceImpl extends ServiceImpl<RmpEventAdvanc
|
|||||||
lambdaQueryWrapper.like(RmpEventDetailAssPO::getContentDes, baseParam.getSearchValue());
|
lambdaQueryWrapper.like(RmpEventDetailAssPO::getContentDes, baseParam.getSearchValue());
|
||||||
}
|
}
|
||||||
lambdaQueryWrapper.between(RmpEventDetailAssPO::getTimeId, timeV.get(0), timeV.get(1))
|
lambdaQueryWrapper.between(RmpEventDetailAssPO::getTimeId, timeV.get(0), timeV.get(1))
|
||||||
.orderByAsc(RmpEventDetailAssPO::getTimeId);
|
.orderByDesc(RmpEventDetailAssPO::getTimeId);
|
||||||
return rmpEventDetailAssMapper.selectPage(new Page<>(PageFactory.getPageNum(baseParam), PageFactory.getPageSize(baseParam)), lambdaQueryWrapper);
|
return rmpEventDetailAssMapper.selectPage(new Page<>(PageFactory.getPageNum(baseParam), PageFactory.getPageSize(baseParam)), lambdaQueryWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -720,7 +734,7 @@ public class EventRelevantAnalysisServiceImpl extends ServiceImpl<RmpEventAdvanc
|
|||||||
|
|
||||||
List<AdvanceEventDetailVO> advanceEventDetailVOLsit = querySagEventsAll(startTime, endTime);
|
List<AdvanceEventDetailVO> advanceEventDetailVOLsit = querySagEventsAll(startTime, endTime);
|
||||||
|
|
||||||
|
advanceEventDetailVOLsit = advanceEventDetailVOLsit.stream().filter(temp-> StringUtils.isNotEmpty(temp.getAdvanceType())).collect(Collectors.toList());
|
||||||
for (AdvanceEventDetailVO advanceEventDetailVO : advanceEventDetailVOLsit) { // 获取监测点线路序号
|
for (AdvanceEventDetailVO advanceEventDetailVO : advanceEventDetailVOLsit) { // 获取监测点线路序号
|
||||||
//母线id
|
//母线id
|
||||||
String nodePhysics = advanceEventDetailVO.getVoltageId();
|
String nodePhysics = advanceEventDetailVO.getVoltageId();
|
||||||
@@ -854,6 +868,21 @@ public class EventRelevantAnalysisServiceImpl extends ServiceImpl<RmpEventAdvanc
|
|||||||
/*************************************************************************************
|
/*************************************************************************************
|
||||||
* 获取变压器信息并生成矩阵
|
* 获取变压器信息并生成矩阵
|
||||||
*************************************************************************************/
|
*************************************************************************************/
|
||||||
|
public Map<String, Map<String, Integer>> getNodeBefore(){
|
||||||
|
Map<String, EntityMtrans> entityMtranMap = new HashMap<>(32);
|
||||||
|
|
||||||
|
HandleEvent handleEvent = new HandleEvent();
|
||||||
|
List<EntityLogic> list = relevantLogMapper.getLogic();
|
||||||
|
Map<String, Map<String, Integer>> setNodeSort = new HashMap<>();
|
||||||
|
if (CollectionUtil.isNotEmpty(list)) {
|
||||||
|
Map<String, List<String>> map = getLogicInfo(list);
|
||||||
|
setNodeSort = nodeSort(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
return setNodeSort;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public Map<String, EntityMtrans> getNodeInfo( ) {
|
public Map<String, EntityMtrans> getNodeInfo( ) {
|
||||||
Map<String, EntityMtrans> entityMtranMap = new HashMap<>(32);
|
Map<String, EntityMtrans> entityMtranMap = new HashMap<>(32);
|
||||||
|
|
||||||
|
|||||||
@@ -2,13 +2,16 @@ package com.njcn.advance.service.impl;
|
|||||||
|
|
||||||
import cn.hutool.core.date.TimeInterval;
|
import cn.hutool.core.date.TimeInterval;
|
||||||
import cn.hutool.core.io.IoUtil;
|
import cn.hutool.core.io.IoUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.njcn.advance.enums.EnumEvt;
|
import com.njcn.advance.enums.EnumEvt;
|
||||||
import com.njcn.advance.mapper.RmpEventAdvanceMapper;
|
import com.njcn.advance.mapper.RmpEventAdvanceMapper;
|
||||||
import com.njcn.advance.pojo.dto.waveAnalysis.*;
|
import com.njcn.advance.pojo.dto.waveAnalysis.*;
|
||||||
|
|
||||||
import com.njcn.advance.service.EventWaveAnalysisService;
|
import com.njcn.advance.service.EventWaveAnalysisService;
|
||||||
import com.njcn.advance.utils.*;
|
import com.njcn.advance.utils.JnaCallBalance;
|
||||||
|
import com.njcn.advance.utils.JnaCallDllOrSo;
|
||||||
|
import com.njcn.advance.utils.Utils;
|
||||||
|
import com.njcn.advance.utils.WaveUtils;
|
||||||
import com.njcn.common.pojo.exception.BusinessException;
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
import com.njcn.common.utils.PubUtils;
|
import com.njcn.common.utils.PubUtils;
|
||||||
import com.njcn.device.pq.api.LineFeignClient;
|
import com.njcn.device.pq.api.LineFeignClient;
|
||||||
@@ -26,7 +29,10 @@ import net.sf.json.JSONObject;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
@@ -81,7 +87,13 @@ public class EventWaveAnalysisServiceImpl implements EventWaveAnalysisService {
|
|||||||
inputStreamCfg = fileStorageUtil.getFileStream(OssPath.WAVE_DIR + lineDetailDataVO.getIp() + StrUtil.SLASH + rmpEventDetailPO.getWavePath() + GeneralConstant.CFG);
|
inputStreamCfg = fileStorageUtil.getFileStream(OssPath.WAVE_DIR + lineDetailDataVO.getIp() + StrUtil.SLASH + rmpEventDetailPO.getWavePath() + GeneralConstant.CFG);
|
||||||
inputStreamDat = fileStorageUtil.getFileStream(OssPath.WAVE_DIR + lineDetailDataVO.getIp() + StrUtil.SLASH + rmpEventDetailPO.getWavePath() + GeneralConstant.DAT);
|
inputStreamDat = fileStorageUtil.getFileStream(OssPath.WAVE_DIR + lineDetailDataVO.getIp() + StrUtil.SLASH + rmpEventDetailPO.getWavePath() + GeneralConstant.DAT);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new BusinessException("暂降cfg,dat文件缺失,请联系管理员");
|
try {
|
||||||
|
inputStreamCfg = fileStorageUtil.getFileStream(OssPath.WAVE_DIR + lineDetailDataVO.getIp() + StrUtil.SLASH + rmpEventDetailPO.getWavePath() + GeneralConstant.CFG.toLowerCase());
|
||||||
|
inputStreamDat = fileStorageUtil.getFileStream(OssPath.WAVE_DIR + lineDetailDataVO.getIp() + StrUtil.SLASH + rmpEventDetailPO.getWavePath() + GeneralConstant.DAT.toLowerCase());
|
||||||
|
} catch (Exception e1) {
|
||||||
|
|
||||||
|
throw new BusinessException("暂降cfg,dat文件缺失,请联系管理员");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//读取
|
//读取
|
||||||
@@ -164,17 +176,13 @@ public class EventWaveAnalysisServiceImpl implements EventWaveAnalysisService {
|
|||||||
causeStruct.smp_len = pitchList.size();
|
causeStruct.smp_len = pitchList.size();
|
||||||
causeStruct.smp_rate = (int) wavePitchData.getnOneWaveNum();
|
causeStruct.smp_rate = (int) wavePitchData.getnOneWaveNum();
|
||||||
|
|
||||||
|
|
||||||
String hdrStr = waveUtils.getFile(OssPath.WAVE_DIR + lineDetailDataVO.getIp() + StrUtil.SLASH + rmpEventDetailPO.getWavePath() + GeneralConstant.HDR);
|
String hdrStr = waveUtils.getFile(OssPath.WAVE_DIR + lineDetailDataVO.getIp() + StrUtil.SLASH + rmpEventDetailPO.getWavePath() + GeneralConstant.HDR);
|
||||||
JSONObject jsonObject = JSONObject.fromObject(hdrStr);
|
JSONObject jsonObject = JSONObject.fromObject(hdrStr);
|
||||||
translateData(jsonObject, rmpEventDetailPO.getStartTime(), entityAdvancedData);
|
translateData(jsonObject, rmpEventDetailPO.getStartTime(), entityAdvancedData);
|
||||||
|
|
||||||
|
|
||||||
if (rmpEventDetailPO.getDealFlag() != 1) {
|
if (rmpEventDetailPO.getDealFlag() != 1) {
|
||||||
//如果存在三个文件但是没有调用dll/so计算
|
//如果存在三个文件但是没有调用dll/so计算
|
||||||
|
|
||||||
getDataFromDLL(rmpEventDetailPO, waveOriginalData, rect, entityAdvancedData, causeStruct);
|
getDataFromDLL(rmpEventDetailPO, waveOriginalData, rect, entityAdvancedData, causeStruct);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -208,6 +216,171 @@ public class EventWaveAnalysisServiceImpl implements EventWaveAnalysisService {
|
|||||||
return entityAdvancedData;
|
return entityAdvancedData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EntityAdvancedData analysisWlEvent(String eventIndex) {
|
||||||
|
TimeInterval timeInterval = new TimeInterval();
|
||||||
|
//调用方法获取暂降事件详情
|
||||||
|
RmpEventDetailPO rmpEventDetailPO = rmpEventAdvanceMapper.selectById(eventIndex);
|
||||||
|
EntityAdvancedData entityAdvancedData;
|
||||||
|
|
||||||
|
if (Objects.isNull(rmpEventDetailPO.getFileFlag())) {
|
||||||
|
throw new BusinessException("系统检测到波形文件未从装置招到本地,请联系管理员");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rmpEventDetailPO.getFileFlag() == 1) {
|
||||||
|
//获取所有暂态原因
|
||||||
|
List<DictData> dicDataList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.EVENT_TYPE.getCode()).getData();
|
||||||
|
Map<Integer, DictData> eventTypeMap = dicDataList.stream().collect(Collectors.toMap(DictData::getAlgoDescribe, Function.identity()));
|
||||||
|
InputStream inputStreamCfg;
|
||||||
|
InputStream inputStreamDat;
|
||||||
|
try {
|
||||||
|
inputStreamCfg = fileStorageUtil.getFileStream(rmpEventDetailPO.getWavePath()+ GeneralConstant.CFG);
|
||||||
|
inputStreamDat = fileStorageUtil.getFileStream(rmpEventDetailPO.getWavePath() + GeneralConstant.DAT);
|
||||||
|
} catch (Exception e) {
|
||||||
|
try {
|
||||||
|
inputStreamCfg = fileStorageUtil.getFileStream(rmpEventDetailPO.getWavePath() + GeneralConstant.CFG.toLowerCase());
|
||||||
|
inputStreamDat = fileStorageUtil.getFileStream(rmpEventDetailPO.getWavePath() + GeneralConstant.DAT.toLowerCase());
|
||||||
|
} catch (Exception e1) {
|
||||||
|
throw new BusinessException("暂降cfg,dat文件缺失,请联系管理员");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//读取
|
||||||
|
BufferedReader bufferedReader;
|
||||||
|
InputStreamReader read = null;
|
||||||
|
String strFileLine;
|
||||||
|
byte[] array = {};
|
||||||
|
List<String> temCfgList = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
// 判断文件是否存在
|
||||||
|
array = IoUtil.readBytes(inputStreamDat);
|
||||||
|
// 考虑到编码格式
|
||||||
|
read = new InputStreamReader(inputStreamCfg, StandardCharsets.UTF_8);
|
||||||
|
bufferedReader = new BufferedReader(read);
|
||||||
|
|
||||||
|
while ((strFileLine = bufferedReader.readLine()) != null) {
|
||||||
|
temCfgList.add(strFileLine);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (read != null) {
|
||||||
|
read.close();
|
||||||
|
}
|
||||||
|
if (inputStreamDat != null) {
|
||||||
|
inputStreamDat.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//原始波形
|
||||||
|
WaveData waveOriginalData = getWavedata(rmpEventDetailPO, temCfgList, array, 3);
|
||||||
|
List<List<Float>> originalList = waveOriginalData.getSunData();
|
||||||
|
|
||||||
|
entityAdvancedData = new EntityAdvancedData(originalList.size());
|
||||||
|
|
||||||
|
for (int i = 0; i < originalList.size(); i++) {
|
||||||
|
//坐标轴
|
||||||
|
entityAdvancedData.smp_x[i] = originalList.get(i).get(0);
|
||||||
|
entityAdvancedData.smp_a[i] = originalList.get(i).get(1);
|
||||||
|
entityAdvancedData.smp_b[i] = originalList.get(i).get(2);
|
||||||
|
entityAdvancedData.smp_c[i] = originalList.get(i).get(3);
|
||||||
|
}
|
||||||
|
entityAdvancedData.smp_len = originalList.size();
|
||||||
|
|
||||||
|
//抽点方法计算波形
|
||||||
|
WaveData wavePitchData = getWavedata(rmpEventDetailPO, temCfgList, array, 0);
|
||||||
|
List<List<Float>> pitchList = wavePitchData.getSunData();
|
||||||
|
|
||||||
|
// 将获取到的数据填充到结构体内
|
||||||
|
Rect rect = new Rect();
|
||||||
|
CauseStruct causeStruct = new CauseStruct();
|
||||||
|
|
||||||
|
for (int i = 0; i < pitchList.size(); i++) {
|
||||||
|
rect.smp_va[i] = pitchList.get(i).get(1);
|
||||||
|
causeStruct.smp_va[i] = pitchList.get(i).get(1);
|
||||||
|
|
||||||
|
rect.smp_vb[i] = pitchList.get(i).get(2);
|
||||||
|
causeStruct.smp_vb[i] = pitchList.get(i).get(2);
|
||||||
|
|
||||||
|
rect.smp_vc[i] = pitchList.get(i).get(3);
|
||||||
|
causeStruct.smp_vc[i] = pitchList.get(i).get(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
rect.smp_len = pitchList.size();
|
||||||
|
|
||||||
|
//超过60s的波形直接抛异常给上面处理
|
||||||
|
/*
|
||||||
|
* 波形最大值计算
|
||||||
|
*/
|
||||||
|
int MAX_LENGTH = 128 * 3000;
|
||||||
|
if (rect.smp_len >= MAX_LENGTH) {
|
||||||
|
throw new BusinessException("波形超过60S");
|
||||||
|
}
|
||||||
|
|
||||||
|
rect.smp_rate = (int) wavePitchData.getnOneWaveNum();
|
||||||
|
causeStruct.smp_len = pitchList.size();
|
||||||
|
causeStruct.smp_rate = (int) wavePitchData.getnOneWaveNum();
|
||||||
|
|
||||||
|
if (rmpEventDetailPO.getDealFlag() != 1) {
|
||||||
|
//如果存在三个文件但是没有调用dll/so计算
|
||||||
|
getDataFromDLL(rmpEventDetailPO, waveOriginalData, rect, entityAdvancedData, causeStruct);
|
||||||
|
} else {
|
||||||
|
//已经处理过了,那就根据id获取暂降原因
|
||||||
|
String reason = rmpEventDetailPO.getAdvanceReason();
|
||||||
|
List<DictData> reasonList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.EVENT_REASON.getCode()).getData();
|
||||||
|
Map<String, DictData> eventReasonMap = reasonList.stream().collect(Collectors.toMap(DictData::getId, Function.identity()));
|
||||||
|
if (ObjectUtil.isNotNull(eventReasonMap.get(reason))) {
|
||||||
|
entityAdvancedData.sagReason[0] = eventReasonMap.get(reason).getName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String hdrStr = null;
|
||||||
|
try {
|
||||||
|
hdrStr = waveUtils.getFile(rmpEventDetailPO.getWavePath() + GeneralConstant.HDR.toLowerCase());
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("读取文件服务器波形数据异常:{}",e.getMessage());
|
||||||
|
}
|
||||||
|
if (hdrStr != null) {
|
||||||
|
JSONObject jsonObject = JSONObject.fromObject(hdrStr);
|
||||||
|
translateData(jsonObject, rmpEventDetailPO.getStartTime(), entityAdvancedData);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (rmpEventDetailPO.getDealFlag() != 1) {
|
||||||
|
// //如果存在三个文件但是没有调用dll/so计算
|
||||||
|
// getDataFromDLL(rmpEventDetailPO, waveOriginalData, rect, entityAdvancedData, causeStruct);
|
||||||
|
// }
|
||||||
|
|
||||||
|
/****************************************************************
|
||||||
|
* 根据返回的结果计算,获取暂降类型描述
|
||||||
|
****************************************************************/
|
||||||
|
if (entityAdvancedData.backNumber > 0) {
|
||||||
|
for (int i = 0; i < entityAdvancedData.backNumber; i++) {
|
||||||
|
entityAdvancedData.sagType[i] = eventTypeMap.get(entityAdvancedData.evt_buf[i].qvvr_cata_type[0]).getName();
|
||||||
|
switch (entityAdvancedData.evt_buf[i].qvvr_phasetype[0]) {
|
||||||
|
case 1:
|
||||||
|
entityAdvancedData.sagPhaseType[i] = "单相";
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
entityAdvancedData.sagPhaseType[i] = "两相";
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
entityAdvancedData.sagPhaseType[i] = "三相";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new BusinessException("暂降cfg,dat文件缺失,请联系管理员");
|
||||||
|
}
|
||||||
|
log.info("高级算法波形计算" + timeInterval.interval());
|
||||||
|
return entityAdvancedData;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 事件未进行高级算法处理:系统调用dll处理并保存结果
|
* 事件未进行高级算法处理:系统调用dll处理并保存结果
|
||||||
@@ -352,7 +525,7 @@ public class EventWaveAnalysisServiceImpl implements EventWaveAnalysisService {
|
|||||||
if (StrUtil.isBlank(rmpEventDetailPOQuery.getAdvanceReason())) {
|
if (StrUtil.isBlank(rmpEventDetailPOQuery.getAdvanceReason())) {
|
||||||
|
|
||||||
//暂降原因计算
|
//暂降原因计算
|
||||||
JnaCallDllOrSo jnaCallDllReason = new JnaCallBalance("qvvr_dll_cause");
|
JnaCallDllOrSo jnaCallDllReason = new JnaCallBalance("qvvr_cause_dll");
|
||||||
jnaCallDllReason.setPath();
|
jnaCallDllReason.setPath();
|
||||||
|
|
||||||
JnaCallBalance.Balancelibrary CAUSE = JnaCallBalance.Balancelibrary.INSTANTCE;
|
JnaCallBalance.Balancelibrary CAUSE = JnaCallBalance.Balancelibrary.INSTANTCE;
|
||||||
|
|||||||
@@ -21,8 +21,12 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public interface IRespDataService extends IService<RespData> {
|
public interface IRespDataService extends IService<RespData> {
|
||||||
|
|
||||||
|
ResponsibilityResult getDynamicDataOld(ResponsibilityCalculateParam responsibilityCalculateParam);
|
||||||
|
|
||||||
ResponsibilityResult getDynamicData(ResponsibilityCalculateParam responsibilityCalculateParam);
|
ResponsibilityResult getDynamicData(ResponsibilityCalculateParam responsibilityCalculateParam);
|
||||||
|
|
||||||
|
ResponsibilityResult getResponsibilityDataOld(ResponsibilitySecondCalParam responsibilitySecondCalParam);
|
||||||
|
|
||||||
ResponsibilityResult getResponsibilityData(ResponsibilitySecondCalParam responsibilitySecondCalParam);
|
ResponsibilityResult getResponsibilityData(ResponsibilitySecondCalParam responsibilitySecondCalParam);
|
||||||
|
|
||||||
Page<RespDataDTO> responsibilityList(BaseParam queryParam);
|
Page<RespDataDTO> responsibilityList(BaseParam queryParam);
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ import com.njcn.advance.pojo.param.ResponsibilityCalculateParam;
|
|||||||
import com.njcn.advance.pojo.param.ResponsibilitySecondCalParam;
|
import com.njcn.advance.pojo.param.ResponsibilitySecondCalParam;
|
||||||
import com.njcn.advance.pojo.po.responsibility.RespData;
|
import com.njcn.advance.pojo.po.responsibility.RespData;
|
||||||
import com.njcn.advance.pojo.po.responsibility.RespDataResult;
|
import com.njcn.advance.pojo.po.responsibility.RespDataResult;
|
||||||
|
import com.njcn.advance.responsibility.constant.CalculationStatus;
|
||||||
|
import com.njcn.advance.responsibility.model.HarmonicData;
|
||||||
|
import com.njcn.advance.responsibility.service.IHarmonicResponsibilityService;
|
||||||
import com.njcn.advance.service.responsibility.IRespDataResultService;
|
import com.njcn.advance.service.responsibility.IRespDataResultService;
|
||||||
import com.njcn.advance.service.responsibility.IRespDataService;
|
import com.njcn.advance.service.responsibility.IRespDataService;
|
||||||
import com.njcn.advance.service.responsibility.IRespUserDataService;
|
import com.njcn.advance.service.responsibility.IRespUserDataService;
|
||||||
@@ -91,6 +94,8 @@ public class RespDataServiceImpl extends ServiceImpl<RespDataMapper, RespData> i
|
|||||||
|
|
||||||
private final CommTerminalGeneralClient commTerminalGeneralClient;
|
private final CommTerminalGeneralClient commTerminalGeneralClient;
|
||||||
|
|
||||||
|
private final IHarmonicResponsibilityService harmonicResponsibilityService;
|
||||||
|
|
||||||
public final static int SORT_10 = 10;
|
public final static int SORT_10 = 10;
|
||||||
public final static int INTERVAL_TIME_1 = 1;
|
public final static int INTERVAL_TIME_1 = 1;
|
||||||
public final static int INTERVAL_TIME_3 = 3;
|
public final static int INTERVAL_TIME_3 = 3;
|
||||||
@@ -161,7 +166,8 @@ public class RespDataServiceImpl extends ServiceImpl<RespDataMapper, RespData> i
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponsibilityResult getDynamicData(ResponsibilityCalculateParam responsibilityCalculateParam) {
|
@Deprecated
|
||||||
|
public ResponsibilityResult getDynamicDataOld(ResponsibilityCalculateParam responsibilityCalculateParam) {
|
||||||
ResponsibilityResult result = new ResponsibilityResult();
|
ResponsibilityResult result = new ResponsibilityResult();
|
||||||
//调用c++依赖需要待初始化的参数
|
//调用c++依赖需要待初始化的参数
|
||||||
int pNode, pNum, win, harmNum;
|
int pNode, pNum, win, harmNum;
|
||||||
@@ -419,7 +425,268 @@ public class RespDataServiceImpl extends ServiceImpl<RespDataMapper, RespData> i
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponsibilityResult getResponsibilityData(ResponsibilitySecondCalParam responsibilitySecondCalParam) {
|
public ResponsibilityResult getDynamicData(ResponsibilityCalculateParam responsibilityCalculateParam) {
|
||||||
|
ResponsibilityResult result = new ResponsibilityResult();
|
||||||
|
//调用c++依赖需要待初始化的参数
|
||||||
|
int pNode, pNum, win, harmNum;
|
||||||
|
float harmMk;
|
||||||
|
List<UserDataExcel> userDataExcels = respUserDataService.getUserDataExcelList(responsibilityCalculateParam.getUserDataId());
|
||||||
|
//开始处理,根据接口参数需求,需要节点数(用户数,用户名+监测点号为一个用户),时间范围内功率数据
|
||||||
|
DealDataResult dealDataResult = RespUserDataServiceImpl.getStanderData(userDataExcels, 1);
|
||||||
|
List<String> dateStr = PubUtils.getTimes(DateUtil.parse(responsibilityCalculateParam.getSearchBeginTime(), DatePattern.NORM_DATE_PATTERN), DateUtil.parse(responsibilityCalculateParam.getSearchEndTime(), DatePattern.NORM_DATE_PATTERN));
|
||||||
|
Map<String/*户号@监测点号@户名*/, Map<String/*yyyy-MM-dd天日期*/, List<UserDataExcel>>> finalData = getFinalUserData(dealDataResult, dateStr);
|
||||||
|
//至此,finalData便是我们最终获得的用于计算责任数据,第一个参数节点数值pNode获取到
|
||||||
|
//第一个参数pNode
|
||||||
|
pNode = finalData.size();
|
||||||
|
if (pNode < 1) {
|
||||||
|
//没有合理的用采数据直接返回
|
||||||
|
throw new BusinessException(AdvanceResponseEnum.USER_DATA_P_NODE_PARAMETER_ERROR);
|
||||||
|
}
|
||||||
|
//第二个参数pNum,根据起始时间和截止时间以及监测点测量间隔计算数量
|
||||||
|
RespCommon pNumAndInterval = getPNumAndInterval(finalData, responsibilityCalculateParam.getLineId(), dateStr);
|
||||||
|
pNum = pNumAndInterval.getPNum();
|
||||||
|
int userIntervalTime = pNumAndInterval.getUserIntervalTime();
|
||||||
|
int lineInterval = pNumAndInterval.getLineInterval();
|
||||||
|
//第三个参数win,根据起始时间和截止时间的间隔
|
||||||
|
if (dateStr.size() > 1) {
|
||||||
|
if (userIntervalTime == INTERVAL_TIME_15) {
|
||||||
|
win = WINDOW_96;
|
||||||
|
} else {
|
||||||
|
win = WINDOW_48;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
win = WINDOW_4;
|
||||||
|
}
|
||||||
|
//第四个参数harmMk,默认为0f
|
||||||
|
harmMk = 0f;
|
||||||
|
//第五个参数harmNum,与功率数据保持一致
|
||||||
|
harmNum = pNum;
|
||||||
|
//至此基础数据组装完毕,开始组装功率数据和谐波数据
|
||||||
|
//先做谐波数据,理论上到这步的时候,谐波数据是满足完整性并已经补充完整性到100%,此处需要将谐波数据与功率数据长度匹配上
|
||||||
|
RespHarmData respHarmData = getRespHarmData(responsibilityCalculateParam, lineInterval);
|
||||||
|
//harmData填充完毕后,开始组装功率数据
|
||||||
|
//首先获取当前时间内的各个用户的数据
|
||||||
|
Map<String/*用户名*/, List<UserDataExcel>> originalPData = new HashMap<>(16);
|
||||||
|
List<String> names = new ArrayList<>();
|
||||||
|
Set<String> userNamesFinal = finalData.keySet();
|
||||||
|
for (String userName : userNamesFinal) {
|
||||||
|
List<UserDataExcel> tempData = new ArrayList<>();
|
||||||
|
//根据日期将日期数据全部获取出来z
|
||||||
|
Map<String, List<UserDataExcel>> tempResult = finalData.get(userName);
|
||||||
|
for (String date : dateStr) {
|
||||||
|
tempData.addAll(tempResult.get(date));
|
||||||
|
}
|
||||||
|
//按日期排序
|
||||||
|
Collections.sort(tempData);
|
||||||
|
originalPData.put(userName, tempData);
|
||||||
|
names.add(userName);
|
||||||
|
}
|
||||||
|
//然后开始组装数据
|
||||||
|
float[][] pData = new float[QvvrDataEntity.MAX_P_NUM][QvvrDataEntity.MAX_P_NODE];
|
||||||
|
for (int i = 0; i < names.size(); i++) {
|
||||||
|
//当前某用户测量节点的所有数据
|
||||||
|
List<UserDataExcel> userDataExcelBodies1 = originalPData.get(names.get(i));
|
||||||
|
for (int k = 0; k < userDataExcelBodies1.size(); k++) {
|
||||||
|
float[] pDataStruct = pData[k];
|
||||||
|
if (pDataStruct == null) {
|
||||||
|
pDataStruct = new float[QvvrDataEntity.MAX_P_NODE];
|
||||||
|
}
|
||||||
|
float[] p = pDataStruct;
|
||||||
|
p[i] = userDataExcelBodies1.get(k).getWork().floatValue();
|
||||||
|
pData[k] = pDataStruct;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//至此功率数据也组装完毕,调用友谊提供的接口
|
||||||
|
// QvvrDataEntity qvvrDataEntity = new QvvrDataEntity();
|
||||||
|
// qvvrDataEntity.calFlag = 0;
|
||||||
|
// qvvrDataEntity.pNode = pNode;
|
||||||
|
// qvvrDataEntity.pNum = pNum;
|
||||||
|
// qvvrDataEntity.win = win;
|
||||||
|
// qvvrDataEntity.harmNum = harmNum;
|
||||||
|
// qvvrDataEntity.harmMk = harmMk;
|
||||||
|
// qvvrDataEntity.pData = pData;
|
||||||
|
// qvvrDataEntity.harmData = respHarmData.getHarmData();
|
||||||
|
// ResponsibilityAlgorithm responsibilityAlgorithm = new ResponsibilityAlgorithm();
|
||||||
|
// qvvrDataEntity = responsibilityAlgorithm.getResponsibilityResult(qvvrDataEntity);
|
||||||
|
|
||||||
|
HarmonicData harmonicData = harmonicResponsibilityService.fullCalculation(respHarmData.getHarmData(), pData, harmNum, pNum, pNode, win, harmMk);
|
||||||
|
//至此接口调用结束,开始组装动态责任数据和用户责任量化结果
|
||||||
|
//首先判断cal_ok的标识位是否为1,为0表示程序没有计算出结果
|
||||||
|
if (harmonicData.getCalculationStatus() == CalculationStatus.FAILED) {
|
||||||
|
throw new BusinessException(AdvanceResponseEnum.RESPONSIBILITY_PARAMETER_ERROR);
|
||||||
|
}
|
||||||
|
//没问题后,先玩动态责任数据
|
||||||
|
CustomerData[] customerDatas = new CustomerData[harmonicData.getPowerNodeCount()];
|
||||||
|
float[][] fKdata/*无背景的动态责任数据*/ = harmonicData.getFkData();
|
||||||
|
//第一个时间节点是起始时间+win窗口得到的时间
|
||||||
|
Date sTime = DateUtil.parse(dateStr.get(0).concat(" 00:00:00"), DatePattern.NORM_DATETIME_PATTERN);
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
calendar.setTime(sTime);
|
||||||
|
calendar.add(Calendar.MINUTE, (win - 1) * userIntervalTime);
|
||||||
|
List<Long> timeDatas = new ArrayList<>();
|
||||||
|
for (int i = 0; i < harmonicData.getPowerCount() - harmonicData.getWindowSize(); i++) {
|
||||||
|
calendar.add(Calendar.MINUTE, userIntervalTime);
|
||||||
|
//一个时间点所有的用户数据
|
||||||
|
float[] fKdatum = fKdata[i];
|
||||||
|
for (int k = 0; k < harmonicData.getPowerNodeCount(); k++) {
|
||||||
|
CustomerData customerData = customerDatas[k];
|
||||||
|
if (null == customerData) {
|
||||||
|
customerData = new CustomerData();
|
||||||
|
customerData.setCustomerName(names.get(k));
|
||||||
|
}
|
||||||
|
List<Float> valueDatas = customerData.getValueDatas();
|
||||||
|
Float valueTemp = fKdatum[k];
|
||||||
|
if (valueTemp.isNaN()) {
|
||||||
|
valueTemp = 0.0f;
|
||||||
|
}
|
||||||
|
valueDatas.add(valueTemp);
|
||||||
|
customerData.setValueDatas(valueDatas);
|
||||||
|
customerDatas[k] = customerData;
|
||||||
|
}
|
||||||
|
timeDatas.add(calendar.getTimeInMillis());
|
||||||
|
}
|
||||||
|
//OK拿到所有测量点的数据了,现在就是看如何将相同户号的动态数据进行算术和求值,之前的用户name为:户号@测量点号@用户名
|
||||||
|
Map<String/*用户名(户号)*/, List<CustomerData>> customerDataTemp = new HashMap<>(16);
|
||||||
|
for (CustomerData data : customerDatas) {
|
||||||
|
String customerName = data.getCustomerName();
|
||||||
|
String[] customerInfo = customerName.split("@");
|
||||||
|
String name = customerInfo[2] + "(" + customerInfo[0] + ")";
|
||||||
|
List<CustomerData> customerData = customerDataTemp.get(name);
|
||||||
|
CustomerData temp = data;
|
||||||
|
temp.setCustomerName(name);
|
||||||
|
if (CollectionUtils.isEmpty(customerData)) {
|
||||||
|
customerData = new ArrayList<>();
|
||||||
|
}
|
||||||
|
customerData.add(temp);
|
||||||
|
customerDataTemp.put(name, customerData);
|
||||||
|
}
|
||||||
|
//动态数据组装完成后,开始组装责任数据
|
||||||
|
List<CustomerResponsibility> customerResponsibilities = getCustomerResponsibilityData(names, harmonicData.getSumFKData(), harmonicData.getPowerNodeCount());
|
||||||
|
//根据前十的用户数据,获取这些用户的动态责任数据
|
||||||
|
List<CustomerData> customerData = new ArrayList<>();
|
||||||
|
for (CustomerResponsibility customerResponsibility : customerResponsibilities) {
|
||||||
|
String cusName = customerResponsibility.getCustomerName();
|
||||||
|
List<CustomerData> customerData1 = customerDataTemp.get(cusName);
|
||||||
|
if (CollectionUtils.isEmpty(customerData1)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (customerData1.size() == 1) {
|
||||||
|
//表示用户唯一的
|
||||||
|
customerData.add(customerData1.get(0));
|
||||||
|
} else {
|
||||||
|
// 表示用户可能包含多个监测点号,需要进行数据累加
|
||||||
|
CustomerData customerDataT = new CustomerData();
|
||||||
|
customerDataT.setCustomerName(cusName);
|
||||||
|
//进行数值累加
|
||||||
|
List<Float> valueDatas = new ArrayList<>();
|
||||||
|
for (int i = 0; i < customerData1.get(0).getValueDatas().size(); i++) {
|
||||||
|
float original = 0.0f;
|
||||||
|
for (CustomerData data : customerData1) {
|
||||||
|
original = original + data.getValueDatas().get(i);
|
||||||
|
}
|
||||||
|
valueDatas.add(original);
|
||||||
|
}
|
||||||
|
customerDataT.setValueDatas(valueDatas);
|
||||||
|
customerData.add(customerDataT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result.setDatas(customerData);
|
||||||
|
result.setTimeDatas(timeDatas);
|
||||||
|
result.setResponsibilities(customerResponsibilities);
|
||||||
|
//此次的操作进行入库操作responsibilityData表数据
|
||||||
|
//根据监测点名称+谐波框选的时间来查询,是否做过责任量化
|
||||||
|
String timeWin = responsibilityCalculateParam.getSearchBeginTime().replaceAll(StrPool.DASHED, "").concat(StrPool.DASHED).concat(responsibilityCalculateParam.getSearchEndTime().replaceAll(StrPool.DASHED, ""));
|
||||||
|
String type = responsibilityCalculateParam.getType() == 0 ? "谐波电流" : "谐波电压";
|
||||||
|
//为了避免有监测点名称重复的,最终还是选择使用监测点索引来判断唯一性
|
||||||
|
LambdaQueryWrapper<RespData> respDataLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
respDataLambdaQueryWrapper.eq(RespData::getLineId, responsibilityCalculateParam.getLineId())
|
||||||
|
.eq(RespData::getUserDataId, responsibilityCalculateParam.getUserDataId())
|
||||||
|
.eq(RespData::getTimeWindow, timeWin)
|
||||||
|
.eq(RespData::getDataType, type)
|
||||||
|
.eq(RespData::getState, DataStateEnum.ENABLE.getCode());
|
||||||
|
List<RespData> responsibilityDataTemp = this.baseMapper.selectList(respDataLambdaQueryWrapper);
|
||||||
|
RespData responsibilityData;
|
||||||
|
if (CollectionUtils.isEmpty(responsibilityDataTemp)) {
|
||||||
|
responsibilityData = new RespData();
|
||||||
|
//库中没有记录则可以新建数据进行插入
|
||||||
|
responsibilityData.setLineId(responsibilityCalculateParam.getLineId());
|
||||||
|
responsibilityData.setUserDataId(responsibilityCalculateParam.getUserDataId());
|
||||||
|
responsibilityData.setDataType(type);
|
||||||
|
responsibilityData.setDataTimes(responsibilityCalculateParam.getTime().toString());
|
||||||
|
responsibilityData.setTimeWindow(timeWin);
|
||||||
|
responsibilityData.setState(DataStateEnum.ENABLE.getCode());
|
||||||
|
//进行插入操作
|
||||||
|
this.baseMapper.insert(responsibilityData);
|
||||||
|
} else {
|
||||||
|
//库中存在记录只需要判断次数进行数据更新
|
||||||
|
responsibilityData = responsibilityDataTemp.get(0);
|
||||||
|
String times = responsibilityData.getDataTimes();
|
||||||
|
List<String> timesList = Stream.of(times.split(StrPool.COMMA)).collect(Collectors.toList());
|
||||||
|
Integer time = responsibilityCalculateParam.getTime();
|
||||||
|
if (!timesList.contains(time.toString())) {
|
||||||
|
timesList.add(time.toString());
|
||||||
|
timesList = timesList.stream().sorted().collect(Collectors.toList());
|
||||||
|
responsibilityData.setDataTimes(String.join(StrPool.COMMA, timesList));
|
||||||
|
}
|
||||||
|
//执行更新操作
|
||||||
|
this.baseMapper.updateById(responsibilityData);
|
||||||
|
}
|
||||||
|
//入库完毕之后,需要将必要数据进行序列化存储,方便后期的重复利用
|
||||||
|
/*
|
||||||
|
* 需要序列化三种数据结构 1 cal_flag置为1时需要的一些列参数的CacheQvvrData 2 cal_flag为0时的,动态结果。3 用户责任量化结果
|
||||||
|
* 其中1/2都只需要一个文件即可
|
||||||
|
* 3因为用户限值的变化调整,可能存在很多个文件,具体根据用户的选择而定
|
||||||
|
*
|
||||||
|
* 路径的结构为,temPath+userData+excelName+type+timeWin+lineIndex+time+文件名
|
||||||
|
* 用户责任量化结果,需要再细化到限值
|
||||||
|
*/
|
||||||
|
//首先判断有没有存储记录,没有则存储,有就略过 指定测点、时间窗口、谐波类型、谐波次数判断唯一性
|
||||||
|
LambdaQueryWrapper<RespDataResult> respDataResultLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
respDataResultLambdaQueryWrapper.eq(RespDataResult::getResDataId, responsibilityData.getId())
|
||||||
|
.eq(RespDataResult::getTime, responsibilityCalculateParam.getTime())
|
||||||
|
.eq(RespDataResult::getStartTime, DateUtil.parse(responsibilityCalculateParam.getSearchBeginTime() + " 00:00:00", DatePattern.NORM_DATETIME_PATTERN))
|
||||||
|
.eq(RespDataResult::getEndTime, DateUtil.parse(responsibilityCalculateParam.getSearchEndTime() + " 23:59:59", DatePattern.NORM_DATETIME_PATTERN))
|
||||||
|
.eq(RespDataResult::getLimitValue, respHarmData.getOverLimit());
|
||||||
|
RespDataResult respDataResult = respDataResultService.getOne(respDataResultLambdaQueryWrapper);
|
||||||
|
if (Objects.isNull(respDataResult)) {
|
||||||
|
respDataResult = new RespDataResult();
|
||||||
|
respDataResult.setResDataId(responsibilityData.getId());
|
||||||
|
respDataResult.setTime(responsibilityCalculateParam.getTime());
|
||||||
|
respDataResult.setStartTime(DateUtil.parse(responsibilityCalculateParam.getSearchBeginTime() + " 00:00:00", DatePattern.NORM_DATETIME_PATTERN));
|
||||||
|
respDataResult.setEndTime(DateUtil.parse(responsibilityCalculateParam.getSearchEndTime() + " 23:59:59", DatePattern.NORM_DATETIME_PATTERN));
|
||||||
|
respDataResult.setLimitValue(respHarmData.getOverLimit());
|
||||||
|
//时间横轴数据 timeDatas
|
||||||
|
JSONArray timeDataJson = JSONArray.parseArray(JSON.toJSONString(timeDatas));
|
||||||
|
InputStream timeDataStream = IoUtil.toUtf8Stream(timeDataJson.toString());
|
||||||
|
String timeDataPath = fileStorageUtil.uploadStream(timeDataStream, OssPath.RESPONSIBILITY_USER_RESULT_DATA, FileUtil.generateFileName("json"));
|
||||||
|
respDataResult.setTimeData(timeDataPath);
|
||||||
|
//用户每时刻对应的责任数据
|
||||||
|
JSONArray customerDataJson = JSONArray.parseArray(JSON.toJSONString(customerData));
|
||||||
|
InputStream customerStream = IoUtil.toUtf8Stream(customerDataJson.toString());
|
||||||
|
String customerPath = fileStorageUtil.uploadStream(customerStream, OssPath.RESPONSIBILITY_USER_RESULT_DATA, FileUtil.generateFileName("json"));
|
||||||
|
respDataResult.setUserDetailData(customerPath);
|
||||||
|
//调用qvvr生成的中间数据
|
||||||
|
CacheQvvrData cacheQvvrData = new CacheQvvrData(harmonicData.getPowerNodeCount(), harmonicData.getHarmonicCount(), harmonicData.getHarmonicData(), harmonicData.getFkData(), harmonicData.getHkData(), names, userIntervalTime, harmonicData.getWindowSize(), userIntervalTime, respHarmData.getHarmTime());
|
||||||
|
String cacheJson = PubUtils.obj2json(cacheQvvrData);
|
||||||
|
InputStream cacheQvvrDataStream = IoUtil.toUtf8Stream(cacheJson);
|
||||||
|
String cacheQvvrDataPath = fileStorageUtil.uploadStream(cacheQvvrDataStream, OssPath.RESPONSIBILITY_USER_RESULT_DATA, FileUtil.generateFileName("json"));
|
||||||
|
respDataResult.setQvvrData(cacheQvvrDataPath);
|
||||||
|
//用户前10数据存储
|
||||||
|
JSONArray customerResJson = JSONArray.parseArray(JSON.toJSONString(customerResponsibilities));
|
||||||
|
InputStream customerResStream = IoUtil.toUtf8Stream(customerResJson.toString());
|
||||||
|
String customerResPath = fileStorageUtil.uploadStream(customerResStream, OssPath.RESPONSIBILITY_USER_RESULT_DATA, FileUtil.generateFileName("json"));
|
||||||
|
respDataResult.setUserResponsibility(customerResPath);
|
||||||
|
respDataResultService.save(respDataResult);
|
||||||
|
}
|
||||||
|
//防止过程中创建了大量的对象,主动调用下GC处理
|
||||||
|
System.gc();
|
||||||
|
result.setResponsibilityDataIndex(responsibilityData.getId());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Deprecated
|
||||||
|
public ResponsibilityResult getResponsibilityDataOld(ResponsibilitySecondCalParam responsibilitySecondCalParam) {
|
||||||
ResponsibilityResult result = new ResponsibilityResult();
|
ResponsibilityResult result = new ResponsibilityResult();
|
||||||
//根据时间天数,获取理论上多少次用采数据
|
//根据时间天数,获取理论上多少次用采数据
|
||||||
RespData responsibilityData = this.baseMapper.selectById(responsibilitySecondCalParam.getResDataId());
|
RespData responsibilityData = this.baseMapper.selectById(responsibilitySecondCalParam.getResDataId());
|
||||||
@@ -664,6 +931,258 @@ public class RespDataServiceImpl extends ServiceImpl<RespDataMapper, RespData> i
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponsibilityResult getResponsibilityData(ResponsibilitySecondCalParam responsibilitySecondCalParam) {
|
||||||
|
ResponsibilityResult result = new ResponsibilityResult();
|
||||||
|
//根据时间天数,获取理论上多少次用采数据
|
||||||
|
RespData responsibilityData = this.baseMapper.selectById(responsibilitySecondCalParam.getResDataId());
|
||||||
|
if (Objects.isNull(responsibilityData)) {
|
||||||
|
throw new BusinessException(AdvanceResponseEnum.RESP_DATA_NOT_FOUND);
|
||||||
|
}
|
||||||
|
Overlimit overlimit = lineFeignClient.getOverLimitData(responsibilityData.getLineId()).getData();
|
||||||
|
//获取总数据
|
||||||
|
LambdaQueryWrapper<RespDataResult> respDataResultLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
respDataResultLambdaQueryWrapper.eq(RespDataResult::getResDataId, responsibilityData.getId())
|
||||||
|
.eq(RespDataResult::getTime, responsibilitySecondCalParam.getTime());
|
||||||
|
if (responsibilitySecondCalParam.getType() == 0) {
|
||||||
|
respDataResultLambdaQueryWrapper.eq(RespDataResult::getLimitValue, PubUtils.getValueByMethod(overlimit, "getIharm", responsibilitySecondCalParam.getTime()));
|
||||||
|
} else {
|
||||||
|
respDataResultLambdaQueryWrapper.eq(RespDataResult::getLimitValue, PubUtils.getValueByMethod(overlimit, "getUharm", responsibilitySecondCalParam.getTime()));
|
||||||
|
}
|
||||||
|
RespDataResult respDataResultTemp = respDataResultService.getOne(respDataResultLambdaQueryWrapper);
|
||||||
|
if (Objects.isNull(respDataResultTemp)) {
|
||||||
|
throw new BusinessException(AdvanceResponseEnum.RESP_DATA_NOT_FOUND);
|
||||||
|
}
|
||||||
|
CacheQvvrData cacheQvvrData;
|
||||||
|
try {
|
||||||
|
InputStream fileStream = fileStorageUtil.getFileStream(respDataResultTemp.getQvvrData());
|
||||||
|
String qvvrDataStr = IoUtil.readUtf8(fileStream);
|
||||||
|
cacheQvvrData = PubUtils.json2obj(qvvrDataStr, CacheQvvrData.class);
|
||||||
|
|
||||||
|
} catch (Exception exception) {
|
||||||
|
throw new BusinessException(AdvanceResponseEnum.RESP_RESULT_DATA_NOT_FOUND);
|
||||||
|
}
|
||||||
|
//获取成功后,延长该缓存的生命周期为初始生命时长
|
||||||
|
int win = cacheQvvrData.getWin();
|
||||||
|
//不管窗口为4或者96,都需要考虑最小公倍数
|
||||||
|
//最小公倍数根据监测点测量间隔来获取,可以考虑也由第一步操作缓存起来
|
||||||
|
int minMultiple = cacheQvvrData.getMinMultiple();
|
||||||
|
//谐波横轴所有的时间
|
||||||
|
List<Long> times = cacheQvvrData.getTimes();
|
||||||
|
//首先根据窗口判断限值时间范围是否满足最小窗口
|
||||||
|
Long limitSL = DateUtil.parse(responsibilitySecondCalParam.getLimitStartTime(), DatePattern.NORM_DATETIME_PATTERN).getTime();
|
||||||
|
Long limitEL = DateUtil.parse(responsibilitySecondCalParam.getLimitEndTime(), DatePattern.NORM_DATETIME_PATTERN).getTime();
|
||||||
|
List<Integer> temp = getTimes(times, limitSL, limitEL);
|
||||||
|
//在动态责任数据中,时间的起始索引位置和截止索引位置
|
||||||
|
Integer timeStartIndex = temp.get(0);
|
||||||
|
Integer timeEndIndex = temp.get(1);
|
||||||
|
//间隔中的时间长度
|
||||||
|
int minus = timeEndIndex - timeStartIndex + 1;
|
||||||
|
//组装参数
|
||||||
|
QvvrDataEntity qvvrDataEntity = new QvvrDataEntity();
|
||||||
|
qvvrDataEntity.calFlag = 1;
|
||||||
|
qvvrDataEntity.pNode = cacheQvvrData.getPNode();
|
||||||
|
qvvrDataEntity.harmMk = responsibilitySecondCalParam.getLimitValue();
|
||||||
|
qvvrDataEntity.win = win;
|
||||||
|
int resNum;
|
||||||
|
float[][] FKdata = new float[9600][QvvrDataEntity.MAX_P_NODE];
|
||||||
|
float[][] HKdata = new float[9600][QvvrDataEntity.MAX_P_NODE + 1];
|
||||||
|
float[] harmData = new float[1440 * 100];
|
||||||
|
float[][] fKdataOriginal = cacheQvvrData.getFKData();
|
||||||
|
float[][] hKdataOriginal = cacheQvvrData.getHKData();
|
||||||
|
float[] harmDataOriginal = cacheQvvrData.getHarmData();
|
||||||
|
//如果起始索引与截止索引的差值等于时间轴的长度,则说明用户没有选择限值时间,直接带入全部的原始数据,参与计算即可
|
||||||
|
if (minus == times.size()) {
|
||||||
|
qvvrDataEntity.harmNum = cacheQvvrData.getHarmNum();
|
||||||
|
qvvrDataEntity.resNum = cacheQvvrData.getHarmNum() - cacheQvvrData.getWin();
|
||||||
|
qvvrDataEntity.setFKData(cacheQvvrData.getFKData());
|
||||||
|
qvvrDataEntity.setHKData(cacheQvvrData.getHKData());
|
||||||
|
qvvrDataEntity.harmData = cacheQvvrData.getHarmData();
|
||||||
|
} else {
|
||||||
|
if (win == WINDOW_4) {
|
||||||
|
//当窗口为4时,两个时间限制范围在最小公倍数为15时,最起码有5个有效时间点,在最小公倍数为30时,最起码有3个有效时间点
|
||||||
|
if (minMultiple == INTERVAL_TIME_15) {
|
||||||
|
if (minus < MINUS_5) {
|
||||||
|
throw new BusinessException(AdvanceResponseEnum.WIN_TIME_ERROR);
|
||||||
|
}
|
||||||
|
resNum = minus - MINUS_4;
|
||||||
|
|
||||||
|
} else if (minMultiple == INTERVAL_TIME_30) {
|
||||||
|
if (minus < MINUS_3) {
|
||||||
|
throw new BusinessException(AdvanceResponseEnum.WIN_TIME_ERROR);
|
||||||
|
}
|
||||||
|
resNum = minus - MINUS_2;
|
||||||
|
} else {
|
||||||
|
throw new BusinessException(AdvanceResponseEnum.CALCULATE_INTERVAL_ERROR);
|
||||||
|
}
|
||||||
|
} else if (win == WINDOW_96) {
|
||||||
|
//当窗口为96时,两个时间限值范围在最小公倍数为15时,最起码有97个有效时间点,在最小公倍数为30时,最起码有49个有效时间点
|
||||||
|
if (minMultiple == INTERVAL_TIME_15) {
|
||||||
|
if (minus <= WINDOW_96) {
|
||||||
|
throw new BusinessException(AdvanceResponseEnum.WIN_TIME_ERROR);
|
||||||
|
}
|
||||||
|
resNum = minus - WINDOW_96;
|
||||||
|
} else if (minMultiple == INTERVAL_TIME_30) {
|
||||||
|
if (minus <= WINDOW_48) {
|
||||||
|
throw new BusinessException(AdvanceResponseEnum.WIN_TIME_ERROR);
|
||||||
|
}
|
||||||
|
resNum = minus - WINDOW_48;
|
||||||
|
} else {
|
||||||
|
throw new BusinessException(AdvanceResponseEnum.CALCULATE_INTERVAL_ERROR);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new BusinessException(AdvanceResponseEnum.CALCULATE_INTERVAL_ERROR);
|
||||||
|
}
|
||||||
|
qvvrDataEntity.resNum = resNum;
|
||||||
|
qvvrDataEntity.harmNum = minus;
|
||||||
|
//因为限值时间实际是含头含尾的,所以harmNum需要索引差值+1
|
||||||
|
for (int i = timeStartIndex; i <= timeEndIndex; i++) {
|
||||||
|
harmData[i - timeStartIndex] = harmDataOriginal[i];
|
||||||
|
}
|
||||||
|
qvvrDataEntity.harmData = harmData;
|
||||||
|
//FKData与HKData的值则等于resNum
|
||||||
|
for (int i = timeStartIndex; i < timeStartIndex + resNum; i++) {
|
||||||
|
FKdata[i - timeStartIndex] = fKdataOriginal[i];
|
||||||
|
HKdata[i - timeStartIndex] = hKdataOriginal[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
qvvrDataEntity.setFKData(FKdata);
|
||||||
|
qvvrDataEntity.setHKData(HKdata);
|
||||||
|
}
|
||||||
|
// ResponsibilityAlgorithm responsibilityAlgorithm = new ResponsibilityAlgorithm();
|
||||||
|
// qvvrDataEntity = responsibilityAlgorithm.getResponsibilityResult(qvvrDataEntity);
|
||||||
|
//
|
||||||
|
// if (qvvrDataEntity.calOk == 0) {
|
||||||
|
// throw new BusinessException(AdvanceResponseEnum.RESPONSIBILITY_PARAMETER_ERROR);
|
||||||
|
// }
|
||||||
|
HarmonicData harmonicData = harmonicResponsibilityService.partialCalculation(
|
||||||
|
qvvrDataEntity.getHarmData(), qvvrDataEntity.getFKData(), qvvrDataEntity.getHKData(), qvvrDataEntity.getHarmNum(), qvvrDataEntity.getPNode(), qvvrDataEntity.getWin(), qvvrDataEntity.getResNum(), qvvrDataEntity.getHarmMk());
|
||||||
|
if (harmonicData.getCalculationStatus() == CalculationStatus.FAILED) {
|
||||||
|
throw new BusinessException(AdvanceResponseEnum.RESPONSIBILITY_PARAMETER_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
//没问题后,先玩动态责任数据
|
||||||
|
List<String> names = cacheQvvrData.getNames();
|
||||||
|
CustomerData[] customerDatas = new CustomerData[harmonicData.getPowerNodeCount()];
|
||||||
|
float[][] fKdata/*无背景的动态责任数据*/ = harmonicData.getFkData();
|
||||||
|
//第一个时间节点是起始时间+win窗口得到的时间
|
||||||
|
Date sTime = new Date();
|
||||||
|
sTime.setTime(times.get(timeStartIndex));
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
calendar.setTime(sTime);
|
||||||
|
calendar.add(Calendar.MINUTE, (win - 1) * minMultiple);
|
||||||
|
List<Long> timeDatas = new ArrayList<>();
|
||||||
|
for (int i = 0; i < harmonicData.getHarmonicCount() - harmonicData.getWindowSize(); i++) {
|
||||||
|
calendar.add(Calendar.MINUTE, minMultiple);
|
||||||
|
//一个时间点所有的用户数据
|
||||||
|
float[] fKdatum = fKdata[i];
|
||||||
|
for (int k = 0; k < harmonicData.getPowerNodeCount(); k++) {
|
||||||
|
CustomerData customerData = customerDatas[k];
|
||||||
|
if (null == customerData) {
|
||||||
|
customerData = new CustomerData();
|
||||||
|
customerData.setCustomerName(names.get(k));
|
||||||
|
}
|
||||||
|
List<Float> valueDatas = customerData.getValueDatas();
|
||||||
|
Float valueTemp = fKdatum[k];
|
||||||
|
if (valueTemp.isNaN()) {
|
||||||
|
valueTemp = 0.0f;
|
||||||
|
}
|
||||||
|
valueDatas.add(valueTemp);
|
||||||
|
customerData.setValueDatas(valueDatas);
|
||||||
|
customerDatas[k] = customerData;
|
||||||
|
}
|
||||||
|
timeDatas.add(calendar.getTimeInMillis());
|
||||||
|
}
|
||||||
|
//OK拿到所有测量点的数据了,现在就是看如何将相同户号的动态数据进行算术和求值,之前的用户name为:户号@测量点号@用户名
|
||||||
|
Map<String/*用户名(户号)*/, List<CustomerData>> customerDataTemp = new HashMap<>(32);
|
||||||
|
for (CustomerData data : customerDatas) {
|
||||||
|
String customerName = data.getCustomerName();
|
||||||
|
String[] customerInfo = customerName.split("@");
|
||||||
|
String name = customerInfo[2] + "(" + customerInfo[0] + ")";
|
||||||
|
List<CustomerData> customerData = customerDataTemp.get(name);
|
||||||
|
CustomerData customerTemp = data;
|
||||||
|
customerTemp.setCustomerName(name);
|
||||||
|
if (CollectionUtils.isEmpty(customerData)) {
|
||||||
|
customerData = new ArrayList<>();
|
||||||
|
}
|
||||||
|
customerData.add(customerTemp);
|
||||||
|
customerDataTemp.put(name, customerData);
|
||||||
|
}
|
||||||
|
//调用程序接口后,首先组装责任量化结果
|
||||||
|
float[] sumFKdata = harmonicData.getSumFKData();
|
||||||
|
List<CustomerResponsibility> customerResponsibilities = getCustomerResponsibilityData(names, sumFKdata, harmonicData.getPowerNodeCount());
|
||||||
|
//根据前十的用户数据,获取这些用户的动态责任数据
|
||||||
|
List<CustomerData> customerData = new ArrayList<>();
|
||||||
|
|
||||||
|
for (CustomerResponsibility customerResponsibility : customerResponsibilities) {
|
||||||
|
String cusName = customerResponsibility.getCustomerName();
|
||||||
|
List<CustomerData> customerData1 = customerDataTemp.get(cusName);
|
||||||
|
if (CollectionUtils.isEmpty(customerData1)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (customerData1.size() == 1) {
|
||||||
|
//表示用户唯一的
|
||||||
|
customerData.add(customerData1.get(0));
|
||||||
|
} else {
|
||||||
|
// 表示用户可能包含多个监测点号,需要进行数据累加
|
||||||
|
CustomerData customerDataT = new CustomerData();
|
||||||
|
customerDataT.setCustomerName(cusName);
|
||||||
|
//进行数值累加
|
||||||
|
List<Float> valueDatas = new ArrayList<>();
|
||||||
|
for (int i = 0; i < customerData1.get(0).getValueDatas().size(); i++) {
|
||||||
|
float original = 0.0f;
|
||||||
|
for (CustomerData data : customerData1) {
|
||||||
|
original = original + data.getValueDatas().get(i);
|
||||||
|
}
|
||||||
|
valueDatas.add(original);
|
||||||
|
}
|
||||||
|
customerDataT.setValueDatas(valueDatas);
|
||||||
|
customerData.add(customerDataT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//接着组装动态数据结果
|
||||||
|
result.setResponsibilities(customerResponsibilities);
|
||||||
|
result.setDatas(customerData);
|
||||||
|
result.setTimeDatas(timeDatas);
|
||||||
|
|
||||||
|
//首先判断有没有存储记录,没有则存储,有就略过 指定测点、时间窗口、谐波类型、谐波次数判断唯一性
|
||||||
|
LambdaQueryWrapper<RespDataResult> respDataResultLambdaQueryWrapper1 = new LambdaQueryWrapper<>();
|
||||||
|
respDataResultLambdaQueryWrapper1.eq(RespDataResult::getResDataId, responsibilityData.getId())
|
||||||
|
.eq(RespDataResult::getTime, responsibilitySecondCalParam.getTime())
|
||||||
|
.eq(RespDataResult::getStartTime, DateUtil.parse(responsibilitySecondCalParam.getLimitStartTime(), DatePattern.NORM_DATETIME_PATTERN))
|
||||||
|
.eq(RespDataResult::getEndTime, DateUtil.parse(responsibilitySecondCalParam.getLimitEndTime(), DatePattern.NORM_DATETIME_PATTERN))
|
||||||
|
.eq(RespDataResult::getLimitValue, responsibilitySecondCalParam.getLimitValue());
|
||||||
|
RespDataResult respDataResult = respDataResultService.getOne(respDataResultLambdaQueryWrapper1);
|
||||||
|
if (Objects.isNull(respDataResult)) {
|
||||||
|
respDataResult = new RespDataResult();
|
||||||
|
respDataResult.setResDataId(responsibilityData.getId());
|
||||||
|
respDataResult.setTime(responsibilitySecondCalParam.getTime());
|
||||||
|
respDataResult.setStartTime(DateUtil.parse(responsibilitySecondCalParam.getLimitStartTime(), DatePattern.NORM_DATETIME_PATTERN));
|
||||||
|
respDataResult.setEndTime(DateUtil.parse(responsibilitySecondCalParam.getLimitEndTime(), DatePattern.NORM_DATETIME_PATTERN));
|
||||||
|
respDataResult.setLimitValue(responsibilitySecondCalParam.getLimitValue());
|
||||||
|
//时间横轴数据 timeDatas
|
||||||
|
JSONArray timeDataJson = JSONArray.parseArray(JSON.toJSONString(timeDatas));
|
||||||
|
InputStream timeDataStream = IoUtil.toUtf8Stream(timeDataJson.toString());
|
||||||
|
String timeDataPath = fileStorageUtil.uploadStream(timeDataStream, OssPath.RESPONSIBILITY_USER_RESULT_DATA, FileUtil.generateFileName("json"));
|
||||||
|
respDataResult.setTimeData(timeDataPath);
|
||||||
|
//用户每时刻对应的责任数据
|
||||||
|
JSONArray customerDataJson = JSONArray.parseArray(JSON.toJSONString(customerData));
|
||||||
|
InputStream customerStream = IoUtil.toUtf8Stream(customerDataJson.toString());
|
||||||
|
String customerPath = fileStorageUtil.uploadStream(customerStream, OssPath.RESPONSIBILITY_USER_RESULT_DATA, FileUtil.generateFileName("json"));
|
||||||
|
respDataResult.setUserDetailData(customerPath);
|
||||||
|
//用户前10数据存储
|
||||||
|
JSONArray customerResJson = JSONArray.parseArray(JSON.toJSONString(customerResponsibilities));
|
||||||
|
InputStream customerResStream = IoUtil.toUtf8Stream(customerResJson.toString());
|
||||||
|
String customerResPath = fileStorageUtil.uploadStream(customerResStream, OssPath.RESPONSIBILITY_USER_RESULT_DATA, FileUtil.generateFileName("json"));
|
||||||
|
respDataResult.setUserResponsibility(customerResPath);
|
||||||
|
respDataResultService.save(respDataResult);
|
||||||
|
}
|
||||||
|
//防止过程中创建了大量的对象,主动调用下GC处理
|
||||||
|
System.gc();
|
||||||
|
result.setResponsibilityDataIndex(responsibilityData.getId());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 监测点测量间隔获取最后用于计算的功率数据
|
* 监测点测量间隔获取最后用于计算的功率数据
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
package com.njcn.advance.utils;
|
package com.njcn.advance.utils;
|
||||||
|
|
||||||
import cn.hutool.core.io.resource.ClassPathResource;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.File;
|
||||||
import java.net.URLDecoder;
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* pqs
|
* pqs
|
||||||
@@ -20,21 +20,20 @@ public class JnaCallDllOrSo {
|
|||||||
|
|
||||||
public JnaCallDllOrSo(String name) {
|
public JnaCallDllOrSo(String name) {
|
||||||
super();
|
super();
|
||||||
String suffix = ".dll";
|
|
||||||
try {
|
try {
|
||||||
String os = System.getProperty("os.name");
|
String os = System.getProperty("os.name");
|
||||||
// windows操作系统为1 否则为0
|
|
||||||
int beginIndex = os != null && os.startsWith("Windows") ? 1 : 0;
|
int beginIndex = os != null && os.startsWith("Windows") ? 1 : 0;
|
||||||
String nameDll;
|
String nameDll;
|
||||||
if (beginIndex == 0) {
|
if (beginIndex == 0) {
|
||||||
//linux操作系统
|
nameDll = "lib" + name + ".so";
|
||||||
nameDll = "lib" + name + "_dll";
|
|
||||||
suffix = ".so";
|
|
||||||
} else {
|
} else {
|
||||||
nameDll = name;
|
nameDll = name;
|
||||||
|
if (!name.endsWith(".dll")) {
|
||||||
|
nameDll = name + ".dll";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String tem = "/usr/local/dllFile/"+ nameDll.concat(suffix);
|
String tem = "/usr/local/dllFile/"+ nameDll;
|
||||||
File dockerFile = new File(tem);
|
File dockerFile = new File(tem);
|
||||||
if(!dockerFile.exists()){
|
if(!dockerFile.exists()){
|
||||||
boolean f = dockerFile.getParentFile().mkdirs();
|
boolean f = dockerFile.getParentFile().mkdirs();
|
||||||
@@ -42,7 +41,11 @@ public class JnaCallDllOrSo {
|
|||||||
System.out.println("文件夹创建:"+f);
|
System.out.println("文件夹创建:"+f);
|
||||||
System.out.println("文件创建:"+d);
|
System.out.println("文件创建:"+d);
|
||||||
|
|
||||||
try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(nameDll.concat(suffix))) {
|
try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(nameDll)) {
|
||||||
|
if (inputStream == null) {
|
||||||
|
log.error("找不到资源文件: {}", nameDll);
|
||||||
|
throw new FileNotFoundException("找不到资源文件: " + nameDll);
|
||||||
|
}
|
||||||
try (FileOutputStream outputStream = new FileOutputStream(dockerFile)) {
|
try (FileOutputStream outputStream = new FileOutputStream(dockerFile)) {
|
||||||
byte[] buffer = new byte[1024];
|
byte[] buffer = new byte[1024];
|
||||||
int bytesRead;
|
int bytesRead;
|
||||||
@@ -53,9 +56,11 @@ public class JnaCallDllOrSo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.path = dockerFile.getAbsolutePath();
|
this.path = dockerFile.getAbsolutePath();
|
||||||
|
System.out.println("动态库路径: " + this.path);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("调用高级算法文件异常,异常信息如下:");
|
log.error("调用高级算法文件异常,异常信息如下:");
|
||||||
log.error(e.getMessage());
|
log.error(e.getMessage(), e);
|
||||||
|
throw new RuntimeException("加载动态库失败: " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
56
pqs-advance/advance-boot/src/main/resources/bootstrap-jb.yml
Normal file
56
pqs-advance/advance-boot/src/main/resources/bootstrap-jb.yml
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
#当前服务的基本信息
|
||||||
|
microservice:
|
||||||
|
ename: @artifactId@
|
||||||
|
name: '@name@'
|
||||||
|
version: @version@
|
||||||
|
sentinel:
|
||||||
|
url: @sentinel.url@
|
||||||
|
gateway:
|
||||||
|
url: @gateway.url@
|
||||||
|
server:
|
||||||
|
port: 10211
|
||||||
|
#feign接口开启服务熔断降级处理
|
||||||
|
feign:
|
||||||
|
sentinel:
|
||||||
|
enabled: true
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: @artifactId@
|
||||||
|
#nacos注册中心以及配置中心的指定
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
discovery:
|
||||||
|
server-addr: @nacos.url@
|
||||||
|
namespace: @nacos.namespace@
|
||||||
|
config:
|
||||||
|
username: @nacos.username@
|
||||||
|
password: @nacos.password@
|
||||||
|
server-addr: @nacos.url@
|
||||||
|
namespace: @nacos.namespace@
|
||||||
|
file-extension: yaml
|
||||||
|
shared-configs:
|
||||||
|
- data-id: share-config.yaml
|
||||||
|
refresh: true
|
||||||
|
- data-id: share-config-datasource-db.yaml
|
||||||
|
refresh: true
|
||||||
|
servlet:
|
||||||
|
multipart:
|
||||||
|
max-file-size: 100MB
|
||||||
|
max-request-size: 100MB
|
||||||
|
main:
|
||||||
|
allow-bean-definition-overriding: true
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#项目日志的配置
|
||||||
|
logging:
|
||||||
|
config: http://@nacos.url@/nacos/v1/cs/configs?tenant=@nacos.namespace@&group=DEFAULT_GROUP&dataId=logback.xml
|
||||||
|
level:
|
||||||
|
root: info
|
||||||
|
|
||||||
|
#mybatis配置信息
|
||||||
|
mybatis-plus:
|
||||||
|
#别名扫描
|
||||||
|
type-aliases-package: com.njcn.advance.pojo
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
#当前服务的基本信息
|
||||||
|
microservice:
|
||||||
|
ename: @artifactId@
|
||||||
|
name: '@name@'
|
||||||
|
version: @version@
|
||||||
|
sentinel:
|
||||||
|
url: @sentinel.url@
|
||||||
|
gateway:
|
||||||
|
url: @gateway.url@
|
||||||
|
server:
|
||||||
|
port: 10211
|
||||||
|
#feign接口开启服务熔断降级处理
|
||||||
|
feign:
|
||||||
|
sentinel:
|
||||||
|
enabled: true
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: @artifactId@
|
||||||
|
#nacos注册中心以及配置中心的指定
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
discovery:
|
||||||
|
ip: @service.server.url@
|
||||||
|
server-addr: @nacos.url@
|
||||||
|
username: @nacos.username@
|
||||||
|
password: @nacos.password@
|
||||||
|
namespace: @nacos.namespace@
|
||||||
|
config:
|
||||||
|
server-addr: @nacos.url@
|
||||||
|
username: @nacos.username@
|
||||||
|
password: @nacos.password@
|
||||||
|
namespace: @nacos.namespace@
|
||||||
|
file-extension: yaml
|
||||||
|
shared-configs:
|
||||||
|
- data-id: share-config.yaml
|
||||||
|
refresh: true
|
||||||
|
- data-id: share-config-datasource-db.yaml
|
||||||
|
refresh: true
|
||||||
|
servlet:
|
||||||
|
multipart:
|
||||||
|
max-file-size: 100MB
|
||||||
|
max-request-size: 100MB
|
||||||
|
main:
|
||||||
|
allow-bean-definition-overriding: true
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#项目日志的配置
|
||||||
|
logging:
|
||||||
|
#config: http://@nacos.url@/nacos/v1/cs/configs?tenant=@nacos.namespace@&group=DEFAULT_GROUP&dataId=logback.xml
|
||||||
|
level:
|
||||||
|
root: info
|
||||||
|
|
||||||
|
#mybatis配置信息
|
||||||
|
mybatis-plus:
|
||||||
|
#别名扫描
|
||||||
|
type-aliases-package: com.njcn.advance.pojo
|
||||||
|
|
||||||
|
|
||||||
|
mqtt:
|
||||||
|
client-id: @artifactId@${random.value}
|
||||||
@@ -1,57 +1,3 @@
|
|||||||
#当前服务的基本信息
|
|
||||||
microservice:
|
|
||||||
ename: @artifactId@
|
|
||||||
name: '@name@'
|
|
||||||
version: @version@
|
|
||||||
sentinel:
|
|
||||||
url: @sentinel.url@
|
|
||||||
gateway:
|
|
||||||
url: @gateway.url@
|
|
||||||
server:
|
|
||||||
port: 10211
|
|
||||||
#feign接口开启服务熔断降级处理
|
|
||||||
feign:
|
|
||||||
sentinel:
|
|
||||||
enabled: true
|
|
||||||
spring:
|
spring:
|
||||||
application:
|
profiles:
|
||||||
name: @artifactId@
|
active: sjzx
|
||||||
#nacos注册中心以及配置中心的指定
|
|
||||||
cloud:
|
|
||||||
nacos:
|
|
||||||
discovery:
|
|
||||||
ip: @service.server.url@
|
|
||||||
server-addr: @nacos.url@
|
|
||||||
namespace: @nacos.namespace@
|
|
||||||
config:
|
|
||||||
server-addr: @nacos.url@
|
|
||||||
namespace: @nacos.namespace@
|
|
||||||
file-extension: yaml
|
|
||||||
shared-configs:
|
|
||||||
- data-id: share-config.yaml
|
|
||||||
refresh: true
|
|
||||||
- data-Id: share-config-datasource-db.yaml
|
|
||||||
refresh: true
|
|
||||||
servlet:
|
|
||||||
multipart:
|
|
||||||
max-file-size: 100MB
|
|
||||||
max-request-size: 100MB
|
|
||||||
main:
|
|
||||||
allow-bean-definition-overriding: true
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#项目日志的配置
|
|
||||||
logging:
|
|
||||||
config: http://@nacos.url@/nacos/v1/cs/configs?tenant=@nacos.namespace@&group=DEFAULT_GROUP&dataId=logback.xml
|
|
||||||
level:
|
|
||||||
root: info
|
|
||||||
|
|
||||||
#mybatis配置信息
|
|
||||||
mybatis-plus:
|
|
||||||
#别名扫描
|
|
||||||
type-aliases-package: com.njcn.advance.pojo
|
|
||||||
|
|
||||||
|
|
||||||
mqtt:
|
|
||||||
client-id: @artifactId@${random.value}
|
|
||||||
Binary file not shown.
Binary file not shown.
52
pqs-auth/src/main/resources/bootstrap-jb.yml
Normal file
52
pqs-auth/src/main/resources/bootstrap-jb.yml
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
#当前服务的基本信息
|
||||||
|
microservice:
|
||||||
|
ename: @artifactId@
|
||||||
|
name: '@name@'
|
||||||
|
version: @version@
|
||||||
|
sentinel:
|
||||||
|
url: @sentinel.url@
|
||||||
|
gateway:
|
||||||
|
url: @gateway.url@
|
||||||
|
server:
|
||||||
|
port: 10214
|
||||||
|
#feign接口开启服务熔断降级处理
|
||||||
|
feign:
|
||||||
|
sentinel:
|
||||||
|
enabled: true
|
||||||
|
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: @artifactId@
|
||||||
|
#nacos注册中心以及配置中心的指定
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
discovery:
|
||||||
|
server-addr: @nacos.url@
|
||||||
|
namespace: @nacos.namespace@
|
||||||
|
config:
|
||||||
|
username: @nacos.username@
|
||||||
|
password: @nacos.password@
|
||||||
|
server-addr: @nacos.url@
|
||||||
|
namespace: @nacos.namespace@
|
||||||
|
file-extension: yaml
|
||||||
|
shared-configs:
|
||||||
|
- data-id: share-config.yaml
|
||||||
|
refresh: true
|
||||||
|
- data-id: share-config-datasource-db.yaml
|
||||||
|
refresh: true
|
||||||
|
main:
|
||||||
|
allow-bean-definition-overriding: true
|
||||||
|
|
||||||
|
|
||||||
|
#项目日志的配置
|
||||||
|
logging:
|
||||||
|
config: http://@nacos.url@/nacos/v1/cs/configs?tenant=@nacos.namespace@&group=DEFAULT_GROUP&dataId=logback.xml
|
||||||
|
level:
|
||||||
|
root: info
|
||||||
|
|
||||||
|
|
||||||
|
#mybatis配置信息
|
||||||
|
mybatis-plus:
|
||||||
|
#别名扫描
|
||||||
|
type-aliases-package: com.njcn.user.pojo
|
||||||
|
|
||||||
57
pqs-auth/src/main/resources/bootstrap-sjzx.yml
Normal file
57
pqs-auth/src/main/resources/bootstrap-sjzx.yml
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
#当前服务的基本信息
|
||||||
|
microservice:
|
||||||
|
ename: @artifactId@
|
||||||
|
name: '@name@'
|
||||||
|
version: @version@
|
||||||
|
sentinel:
|
||||||
|
url: @sentinel.url@
|
||||||
|
gateway:
|
||||||
|
url: @gateway.url@
|
||||||
|
server:
|
||||||
|
port: 10214
|
||||||
|
#feign接口开启服务熔断降级处理
|
||||||
|
feign:
|
||||||
|
sentinel:
|
||||||
|
enabled: true
|
||||||
|
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: @artifactId@
|
||||||
|
#nacos注册中心以及配置中心的指定
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
discovery:
|
||||||
|
ip: @service.server.url@
|
||||||
|
server-addr: @nacos.url@
|
||||||
|
username: @nacos.username@
|
||||||
|
password: @nacos.password@
|
||||||
|
namespace: @nacos.namespace@
|
||||||
|
config:
|
||||||
|
server-addr: @nacos.url@
|
||||||
|
username: @nacos.username@
|
||||||
|
password: @nacos.password@
|
||||||
|
namespace: @nacos.namespace@
|
||||||
|
file-extension: yaml
|
||||||
|
shared-configs:
|
||||||
|
- data-id: share-config.yaml
|
||||||
|
refresh: true
|
||||||
|
- data-id: share-config-datasource-db.yaml
|
||||||
|
refresh: true
|
||||||
|
main:
|
||||||
|
allow-bean-definition-overriding: true
|
||||||
|
|
||||||
|
|
||||||
|
#项目日志的配置
|
||||||
|
logging:
|
||||||
|
#config: http://@nacos.url@/nacos/v1/cs/configs?tenant=@nacos.namespace@&group=DEFAULT_GROUP&dataId=logback.xml
|
||||||
|
level:
|
||||||
|
root: info
|
||||||
|
|
||||||
|
|
||||||
|
#mybatis配置信息
|
||||||
|
mybatis-plus:
|
||||||
|
#别名扫描
|
||||||
|
type-aliases-package: com.njcn.user.pojo
|
||||||
|
|
||||||
|
mqtt:
|
||||||
|
client-id: @artifactId@${random.value}
|
||||||
@@ -1,53 +1,3 @@
|
|||||||
#当前服务的基本信息
|
|
||||||
microservice:
|
|
||||||
ename: @artifactId@
|
|
||||||
name: '@name@'
|
|
||||||
version: @version@
|
|
||||||
sentinel:
|
|
||||||
url: @sentinel.url@
|
|
||||||
gateway:
|
|
||||||
url: @gateway.url@
|
|
||||||
server:
|
|
||||||
port: 10214
|
|
||||||
#feign接口开启服务熔断降级处理
|
|
||||||
feign:
|
|
||||||
sentinel:
|
|
||||||
enabled: true
|
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
application:
|
profiles:
|
||||||
name: @artifactId@
|
active: @spring.profiles.active@
|
||||||
#nacos注册中心以及配置中心的指定
|
|
||||||
cloud:
|
|
||||||
nacos:
|
|
||||||
discovery:
|
|
||||||
ip: @service.server.url@
|
|
||||||
server-addr: @nacos.url@
|
|
||||||
namespace: @nacos.namespace@
|
|
||||||
config:
|
|
||||||
server-addr: @nacos.url@
|
|
||||||
namespace: @nacos.namespace@
|
|
||||||
file-extension: yaml
|
|
||||||
shared-configs:
|
|
||||||
- data-id: share-config.yaml
|
|
||||||
refresh: true
|
|
||||||
- data-Id: share-config-datasource-db.yaml
|
|
||||||
refresh: true
|
|
||||||
main:
|
|
||||||
allow-bean-definition-overriding: true
|
|
||||||
|
|
||||||
|
|
||||||
#项目日志的配置
|
|
||||||
logging:
|
|
||||||
config: http://@nacos.url@/nacos/v1/cs/configs?tenant=@nacos.namespace@&group=DEFAULT_GROUP&dataId=logback.xml
|
|
||||||
level:
|
|
||||||
root: info
|
|
||||||
|
|
||||||
|
|
||||||
#mybatis配置信息
|
|
||||||
mybatis-plus:
|
|
||||||
#别名扫描
|
|
||||||
type-aliases-package: com.njcn.user.pojo
|
|
||||||
|
|
||||||
mqtt:
|
|
||||||
client-id: @artifactId@${random.value}
|
|
||||||
@@ -88,7 +88,7 @@ public class BpmSignParam extends BaseEntity implements Serializable {
|
|||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@ApiModelProperty("标识key")
|
@ApiModelProperty("标识key")
|
||||||
private String key;
|
private String signKey;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import org.springframework.context.annotation.DependsOn;
|
|||||||
* @date 2022/11/10
|
* @date 2022/11/10
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@DependsOn("proxyMapperRegister")
|
|
||||||
@MapperScan("com.njcn.**.mapper")
|
@MapperScan("com.njcn.**.mapper")
|
||||||
@EnableFeignClients(basePackages = "com.njcn")
|
@EnableFeignClients(basePackages = "com.njcn")
|
||||||
@SpringBootApplication(scanBasePackages = "com.njcn")
|
@SpringBootApplication(scanBasePackages = "com.njcn")
|
||||||
|
|||||||
@@ -67,8 +67,8 @@ public class BpmCategoryServiceImpl extends ServiceImpl<BpmCategoryMapper, BpmCa
|
|||||||
@Override
|
@Override
|
||||||
public Page<BpmCategoryVO> getCategoryPage(BpmCategoryParam.BpmCategoryQueryParam bpmCategoryQueryParam) {
|
public Page<BpmCategoryVO> getCategoryPage(BpmCategoryParam.BpmCategoryQueryParam bpmCategoryQueryParam) {
|
||||||
QueryWrapper<BpmCategoryVO> categoryVOQueryWrapper = new QueryWrapper<>();
|
QueryWrapper<BpmCategoryVO> categoryVOQueryWrapper = new QueryWrapper<>();
|
||||||
if (StrUtil.isNotBlank(bpmCategoryQueryParam.getName())) {
|
if (StrUtil.isNotBlank(bpmCategoryQueryParam.getSearchValue())) {
|
||||||
categoryVOQueryWrapper.like("bpm_category.name", bpmCategoryQueryParam.getName());
|
categoryVOQueryWrapper.like("bpm_category.name", bpmCategoryQueryParam.getSearchValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StrUtil.isNotBlank(bpmCategoryQueryParam.getCode())) {
|
if (StrUtil.isNotBlank(bpmCategoryQueryParam.getCode())) {
|
||||||
|
|||||||
@@ -106,8 +106,8 @@ public class BpmSignServiceImpl extends ServiceImpl<BpmSignMapper, BpmSign> impl
|
|||||||
bpmSignVOQueryWrapper.like("bpm_sign.name", bpmSignQueryParam.getName());
|
bpmSignVOQueryWrapper.like("bpm_sign.name", bpmSignQueryParam.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StrUtil.isNotBlank(bpmSignQueryParam.getKey())) {
|
if (StrUtil.isNotBlank(bpmSignQueryParam.getSignKey())) {
|
||||||
bpmSignVOQueryWrapper.like("bpm_sign.signKey", bpmSignQueryParam.getKey());
|
bpmSignVOQueryWrapper.like("bpm_sign.sign_key", bpmSignQueryParam.getSignKey());
|
||||||
}
|
}
|
||||||
bpmSignVOQueryWrapper.eq("bpm_sign.state", DataStateEnum.ENABLE.getCode());
|
bpmSignVOQueryWrapper.eq("bpm_sign.state", DataStateEnum.ENABLE.getCode());
|
||||||
bpmSignVOQueryWrapper.orderByAsc("bpm_sign.sort");
|
bpmSignVOQueryWrapper.orderByAsc("bpm_sign.sort");
|
||||||
|
|||||||
71
pqs-bpm/bpm-boot/src/main/resources/bootstrap-jb.yml
Normal file
71
pqs-bpm/bpm-boot/src/main/resources/bootstrap-jb.yml
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
#当前服务的基本信息
|
||||||
|
microservice:
|
||||||
|
ename: @artifactId@
|
||||||
|
name: '@name@'
|
||||||
|
version: @version@
|
||||||
|
sentinel:
|
||||||
|
url: @sentinel.url@
|
||||||
|
gateway:
|
||||||
|
url: @gateway.url@
|
||||||
|
server:
|
||||||
|
port: 10321
|
||||||
|
#feign接口开启服务熔断降级处理
|
||||||
|
feign:
|
||||||
|
sentinel:
|
||||||
|
enabled: true
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: @artifactId@
|
||||||
|
jackson:
|
||||||
|
date-format: yyyy-MM-dd HH:mm:ss
|
||||||
|
time-zone: Asia/Shanghai
|
||||||
|
#nacos注册中心以及配置中心的指定
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
discovery:
|
||||||
|
server-addr: @nacos.url@
|
||||||
|
namespace: @nacos.namespace@
|
||||||
|
config:
|
||||||
|
username: @nacos.username@
|
||||||
|
password: @nacos.password@
|
||||||
|
server-addr: @nacos.url@
|
||||||
|
namespace: @nacos.namespace@
|
||||||
|
file-extension: yaml
|
||||||
|
shared-configs:
|
||||||
|
- data-id: share-config.yaml
|
||||||
|
refresh: true
|
||||||
|
- data-id: share-config-datasource-db.yaml
|
||||||
|
refresh: true
|
||||||
|
main:
|
||||||
|
allow-bean-definition-overriding: true
|
||||||
|
servlet:
|
||||||
|
multipart:
|
||||||
|
max-file-size: 100MB
|
||||||
|
max-request-size: 100MB
|
||||||
|
|
||||||
|
flowable:
|
||||||
|
database-schema-update: false
|
||||||
|
db-history-used: true # flowable6 默认 true 生成信息表,无需手动设置
|
||||||
|
check-process-definitions: false # 设置为 false,禁用 /resources/processes 自动部署 BPMN XML 流程
|
||||||
|
history-level: full # full:保存历史数据的最高级别,可保存全部流程相关细节,包括流程流转各节点参数
|
||||||
|
async-executor-activate: false
|
||||||
|
|
||||||
|
#项目日志的配置
|
||||||
|
logging:
|
||||||
|
config: http://@nacos.url@/nacos/v1/cs/configs?tenant=@nacos.namespace@&group=DEFAULT_GROUP&dataId=logback.xml
|
||||||
|
level:
|
||||||
|
root: info
|
||||||
|
|
||||||
|
|
||||||
|
#mybatis配置信息
|
||||||
|
mybatis-plus:
|
||||||
|
type-aliases-package: com.njcn.bpm.pojo
|
||||||
|
|
||||||
|
gw:
|
||||||
|
url: dwzyywzt-pms3-proxy.com
|
||||||
|
code: 13B9B47F1E483324E05338297A0A0595
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
76
pqs-bpm/bpm-boot/src/main/resources/bootstrap-sjzx.yml
Normal file
76
pqs-bpm/bpm-boot/src/main/resources/bootstrap-sjzx.yml
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
#当前服务的基本信息
|
||||||
|
microservice:
|
||||||
|
ename: @artifactId@
|
||||||
|
name: '@name@'
|
||||||
|
version: @version@
|
||||||
|
sentinel:
|
||||||
|
url: @sentinel.url@
|
||||||
|
gateway:
|
||||||
|
url: @gateway.url@
|
||||||
|
server:
|
||||||
|
port: 10321
|
||||||
|
#feign接口开启服务熔断降级处理
|
||||||
|
feign:
|
||||||
|
sentinel:
|
||||||
|
enabled: true
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: @artifactId@
|
||||||
|
jackson:
|
||||||
|
date-format: yyyy-MM-dd HH:mm:ss
|
||||||
|
time-zone: Asia/Shanghai
|
||||||
|
#nacos注册中心以及配置中心的指定
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
discovery:
|
||||||
|
ip: @service.server.url@
|
||||||
|
server-addr: @nacos.url@
|
||||||
|
username: @nacos.username@
|
||||||
|
password: @nacos.password@
|
||||||
|
namespace: @nacos.namespace@
|
||||||
|
config:
|
||||||
|
server-addr: @nacos.url@
|
||||||
|
namespace: @nacos.namespace@
|
||||||
|
username: @nacos.username@
|
||||||
|
password: @nacos.password@
|
||||||
|
file-extension: yaml
|
||||||
|
shared-configs:
|
||||||
|
- data-id: share-config.yaml
|
||||||
|
refresh: true
|
||||||
|
- data-id: bpm-config.yaml
|
||||||
|
refresh: true
|
||||||
|
main:
|
||||||
|
allow-bean-definition-overriding: true
|
||||||
|
servlet:
|
||||||
|
multipart:
|
||||||
|
max-file-size: 100MB
|
||||||
|
max-request-size: 100MB
|
||||||
|
|
||||||
|
flowable:
|
||||||
|
database-schema-update: false
|
||||||
|
db-history-used: true # flowable6 默认 true 生成信息表,无需手动设置
|
||||||
|
check-process-definitions: false # 设置为 false,禁用 /resources/processes 自动部署 BPMN XML 流程
|
||||||
|
history-level: full # full:保存历史数据的最高级别,可保存全部流程相关细节,包括流程流转各节点参数
|
||||||
|
async-executor-activate: false
|
||||||
|
|
||||||
|
#项目日志的配置
|
||||||
|
logging:
|
||||||
|
#config: http://@nacos.url@/nacos/v1/cs/configs?tenant=@nacos.namespace@&group=DEFAULT_GROUP&dataId=logback.xml
|
||||||
|
level:
|
||||||
|
root: info
|
||||||
|
|
||||||
|
|
||||||
|
#mybatis配置信息
|
||||||
|
mybatis-plus:
|
||||||
|
type-aliases-package: com.njcn.bpm.pojo
|
||||||
|
|
||||||
|
gw:
|
||||||
|
url: dwzyywzt-pms3-proxy.com
|
||||||
|
code: 13B9B47F1E483324E05338297A0A0595
|
||||||
|
|
||||||
|
mqtt:
|
||||||
|
client-id: @artifactId@${random.value}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,72 +1,3 @@
|
|||||||
#当前服务的基本信息
|
|
||||||
microservice:
|
|
||||||
ename: @artifactId@
|
|
||||||
name: '@name@'
|
|
||||||
version: @version@
|
|
||||||
sentinel:
|
|
||||||
url: @sentinel.url@
|
|
||||||
gateway:
|
|
||||||
url: @gateway.url@
|
|
||||||
server:
|
|
||||||
port: 10321
|
|
||||||
#feign接口开启服务熔断降级处理
|
|
||||||
feign:
|
|
||||||
sentinel:
|
|
||||||
enabled: true
|
|
||||||
spring:
|
spring:
|
||||||
application:
|
profiles:
|
||||||
name: @artifactId@
|
active: @spring.profiles.active@
|
||||||
jackson:
|
|
||||||
date-format: yyyy-MM-dd HH:mm:ss
|
|
||||||
time-zone: Asia/Shanghai
|
|
||||||
#nacos注册中心以及配置中心的指定
|
|
||||||
cloud:
|
|
||||||
nacos:
|
|
||||||
discovery:
|
|
||||||
ip: @service.server.url@
|
|
||||||
server-addr: @nacos.url@
|
|
||||||
namespace: @nacos.namespace@
|
|
||||||
config:
|
|
||||||
server-addr: @nacos.url@
|
|
||||||
namespace: @nacos.namespace@
|
|
||||||
file-extension: yaml
|
|
||||||
shared-configs:
|
|
||||||
- data-id: share-config.yaml
|
|
||||||
refresh: true
|
|
||||||
- data-Id: bpm-config.yaml
|
|
||||||
refresh: true
|
|
||||||
main:
|
|
||||||
allow-bean-definition-overriding: true
|
|
||||||
servlet:
|
|
||||||
multipart:
|
|
||||||
max-file-size: 100MB
|
|
||||||
max-request-size: 100MB
|
|
||||||
|
|
||||||
flowable:
|
|
||||||
database-schema-update: false
|
|
||||||
db-history-used: true # flowable6 默认 true 生成信息表,无需手动设置
|
|
||||||
check-process-definitions: false # 设置为 false,禁用 /resources/processes 自动部署 BPMN XML 流程
|
|
||||||
history-level: full # full:保存历史数据的最高级别,可保存全部流程相关细节,包括流程流转各节点参数
|
|
||||||
async-executor-activate: false
|
|
||||||
|
|
||||||
#项目日志的配置
|
|
||||||
logging:
|
|
||||||
config: http://@nacos.url@/nacos/v1/cs/configs?tenant=@nacos.namespace@&group=DEFAULT_GROUP&dataId=logback.xml
|
|
||||||
level:
|
|
||||||
root: info
|
|
||||||
|
|
||||||
|
|
||||||
#mybatis配置信息
|
|
||||||
mybatis-plus:
|
|
||||||
type-aliases-package: com.njcn.bpm.pojo
|
|
||||||
|
|
||||||
gw:
|
|
||||||
url: dwzyywzt-pms3-proxy.com
|
|
||||||
code: 13B9B47F1E483324E05338297A0A0595
|
|
||||||
|
|
||||||
mqtt:
|
|
||||||
client-id: @artifactId@${random.value}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ public class GenerateCode {
|
|||||||
|
|
||||||
private static final String TARGET_DIR = "D://code";
|
private static final String TARGET_DIR = "D://code";
|
||||||
|
|
||||||
private static final String DB_URL = "jdbc:mysql://192.168.1.24:13306/pqsinfo_ln";
|
private static final String DB_URL = "jdbc:mysql://192.168.1.103:13306/pqsinfo_zl";
|
||||||
// private static final String DB_URL = "jdbc:oracle:thin:@192.168.1.170:1521:pqsbase";
|
// private static final String DB_URL = "jdbc:oracle:thin:@192.168.1.170:1521:pqsbase";
|
||||||
|
|
||||||
private static final String USERNAME = "root";
|
private static final String USERNAME = "root";
|
||||||
@@ -30,8 +30,8 @@ public class GenerateCode {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
List<Module> modules = Stream.of(
|
List<Module> modules = Stream.of(
|
||||||
new Module("cdf", "com.njcn.device", "", Stream.of(
|
new Module("xy", "com.njcn.csdevice", "", Stream.of(
|
||||||
"pq_icd_path"
|
"cs_alarm_set"
|
||||||
).collect(Collectors.toList()), "")
|
).collect(Collectors.toList()), "")
|
||||||
).collect(Collectors.toList());
|
).collect(Collectors.toList());
|
||||||
generateJavaFile(modules);
|
generateJavaFile(modules);
|
||||||
|
|||||||
@@ -97,11 +97,11 @@
|
|||||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!--mqtt相关依赖-->
|
<!-- <!–mqtt相关依赖–>-->
|
||||||
<dependency>
|
<!-- <dependency>-->
|
||||||
<groupId>com.github.tocrhz</groupId>
|
<!-- <groupId>com.github.tocrhz</groupId>-->
|
||||||
<artifactId>mqtt-spring-boot-starter</artifactId>
|
<!-- <artifactId>mqtt-spring-boot-starter</artifactId>-->
|
||||||
</dependency>
|
<!-- </dependency>-->
|
||||||
|
|
||||||
<!-- <dependency>-->
|
<!-- <dependency>-->
|
||||||
<!-- <groupId>org.springframework.boot</groupId>-->
|
<!-- <groupId>org.springframework.boot</groupId>-->
|
||||||
|
|||||||
@@ -75,9 +75,9 @@ public interface PatternRegex {
|
|||||||
String ROLE_REGEX = "^[a-zA-Z][a-zA-Z0-9]{2,50}$";
|
String ROLE_REGEX = "^[a-zA-Z][a-zA-Z0-9]{2,50}$";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 部门名称由汉字组成,长度为0-20
|
* 部门名称由汉字组成,长度为0-32 (前端统一32了这边改下长度)
|
||||||
*/
|
*/
|
||||||
String DEPT_NAME_REGEX = "^[\\u4e00-\\u9fa5]{1,20}$";
|
String DEPT_NAME_REGEX = "^[\\u4e00-\\u9fa5]{1,32}$";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 字典名称包括中文、数字、字母、罗马数字、括号以及点号
|
* 字典名称包括中文、数字、字母、罗马数字、括号以及点号
|
||||||
@@ -258,7 +258,7 @@ public interface PatternRegex {
|
|||||||
/**
|
/**
|
||||||
* 任意字符,长度在1-20位,常用于名称、编码等常规录入
|
* 任意字符,长度在1-20位,常用于名称、编码等常规录入
|
||||||
*/
|
*/
|
||||||
String ALL_CHAR_1_20 = "^[-_A-Za-z0-9\\u4e00-\\u9fa5]{1,20}$";
|
String ALL_CHAR_1_20 = "^[-_A-Za-z0-9\\u4e00-\\u9fa5]{1,32}$";
|
||||||
|
|
||||||
String SPECIALCHARACTER ="[<>%'%;()&+/\\\\-\\\\\\\\_|@*?#$!,.]|html";
|
String SPECIALCHARACTER ="[<>%'%;()&+/\\\\-\\\\\\\\_|@*?#$!,.]|html";
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,12 @@ public class SimpleDTO implements Serializable {
|
|||||||
@ApiModelProperty(name = "value", value = "数值")
|
@ApiModelProperty(name = "value", value = "数值")
|
||||||
private String value;
|
private String value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 针对云南曲靖特殊处理的五层树标识符
|
||||||
|
* 特殊在不显示供电公司,显示(变电站、线路)这两个是部门的名称+母线_监测点的名称
|
||||||
|
*/
|
||||||
|
private String deptName;
|
||||||
|
|
||||||
private Integer sort;
|
private Integer sort;
|
||||||
|
|
||||||
private Integer algoDescribe;
|
private Integer algoDescribe;
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import com.njcn.common.pojo.exception.BusinessException;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
@@ -32,6 +33,7 @@ import java.util.*;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static java.lang.Integer.parseInt;
|
import static java.lang.Integer.parseInt;
|
||||||
|
|
||||||
@@ -281,6 +283,30 @@ public class PubUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用于获取对象中,前缀一样,后缀为2~50的属性值
|
||||||
|
*
|
||||||
|
* @param methodPrefix 方法前缀
|
||||||
|
* @param number 方法后缀
|
||||||
|
* @return 对象属性值
|
||||||
|
*/
|
||||||
|
public static Double getValueByMethodDouble(List data ,Class clazz, String methodPrefix, Integer number) {
|
||||||
|
try {
|
||||||
|
Method method = clazz.getMethod(methodPrefix + number);
|
||||||
|
OptionalDouble average = data.stream().mapToDouble(temp -> {
|
||||||
|
try {
|
||||||
|
return (Double) method.invoke(temp);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new BusinessException(CommonResponseEnum.REFLECT_METHOD_EXCEPTION);
|
||||||
|
}
|
||||||
|
}).average();
|
||||||
|
return average.orElse(0.0);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new BusinessException(CommonResponseEnum.REFLECT_METHOD_EXCEPTION);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static List<String> getStartTimeEndTime(String beginDate, String endDate) throws Exception {
|
public static List<String> getStartTimeEndTime(String beginDate, String endDate) throws Exception {
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,11 @@
|
|||||||
<groupId>mysql</groupId>
|
<groupId>mysql</groupId>
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!--vastbase驱动用postgresql-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.postgresql</groupId>
|
||||||
|
<artifactId>postgresql</artifactId>
|
||||||
|
</dependency>
|
||||||
<!--达梦驱动-->
|
<!--达梦驱动-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.dameng</groupId>
|
<groupId>com.dameng</groupId>
|
||||||
@@ -69,6 +74,12 @@
|
|||||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
|
||||||
|
<version>3.5.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!--数据库相关********end-->
|
<!--数据库相关********end-->
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
package com.njcn.echarts.json;
|
package com.njcn.echarts.json;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.collection.ListUtil;
|
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import cn.hutool.json.ObjectMapper;
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.njcn.echarts.pojo.bo.TolerateData;
|
import com.njcn.echarts.pojo.bo.TolerateData;
|
||||||
import com.njcn.echarts.pojo.constant.PicCommonData;
|
import com.njcn.echarts.pojo.constant.PicCommonData;
|
||||||
import org.icepear.echarts.Option;
|
import org.icepear.echarts.Option;
|
||||||
@@ -29,7 +25,6 @@ import org.icepear.echarts.render.Engine;
|
|||||||
|
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -43,6 +38,17 @@ import java.util.stream.Collectors;
|
|||||||
public class LineGenerator {
|
public class LineGenerator {
|
||||||
|
|
||||||
private final static Engine ENGINE = new Engine();
|
private final static Engine ENGINE = new Engine();
|
||||||
|
// null段在图表上的固定视觉宽度(数据点数量)
|
||||||
|
private static final int NULL_PLACEHOLDER_COUNT = 90;
|
||||||
|
// 压缩结果
|
||||||
|
private static class CompressedResult {
|
||||||
|
// 压缩后的数据
|
||||||
|
List<List<Float>> data;
|
||||||
|
// 每个null段的[起始索引, 结束索引](占位点范围)
|
||||||
|
List<int[]> nullRegionIndices;
|
||||||
|
// null段边界处的真实x值(entry, exit交替)
|
||||||
|
List<Float> nullBoundaryRealXValues;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/***
|
/***
|
||||||
@@ -529,6 +535,478 @@ public class LineGenerator {
|
|||||||
return ENGINE.renderJsonOption(instantOption);
|
return ENGINE.renderJsonOption(instantOption);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String generateWaveOption(String title, List<List<Float>> aValue, List<List<Float>> bValue, List<List<Float>> cValue, String unit, Float max, Float min, String a, String b, String c, List<String> colors, Boolean isOpen, Double lastTime, List<Float> sharedNullBoundaryXValues, Integer nPush) {
|
||||||
|
DecimalFormat df1 = new DecimalFormat("#.00");
|
||||||
|
// 压缩null数据:如果有共享边界则用共享边界,否则独立压缩
|
||||||
|
CompressedResult aCompressed;
|
||||||
|
CompressedResult bCompressed;
|
||||||
|
CompressedResult cCompressed;
|
||||||
|
if (sharedNullBoundaryXValues != null && !sharedNullBoundaryXValues.isEmpty()) {
|
||||||
|
aCompressed = compressNullDataWithSharedBoundaries(aValue, sharedNullBoundaryXValues);
|
||||||
|
bCompressed = compressNullDataWithSharedBoundaries(bValue, sharedNullBoundaryXValues);
|
||||||
|
cCompressed = compressNullDataWithSharedBoundaries(cValue, sharedNullBoundaryXValues);
|
||||||
|
} else {
|
||||||
|
aCompressed = compressNullData(aValue);
|
||||||
|
bCompressed = compressNullData(bValue);
|
||||||
|
cCompressed = compressNullData(cValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
Option instantOption = new Option();
|
||||||
|
//取消渲染动画
|
||||||
|
instantOption.setAnimation(false);
|
||||||
|
//背景色
|
||||||
|
instantOption.setBackgroundColor(PicCommonData.PIC_BACK_COLOR);
|
||||||
|
//标题
|
||||||
|
instantOption.setTitle(new Title()
|
||||||
|
.setText(title)
|
||||||
|
.setLeft(PicCommonData.CENTER)
|
||||||
|
.setTextStyle(new Label().setFontSize(14))
|
||||||
|
);
|
||||||
|
//配置颜色
|
||||||
|
instantOption.setColor(colors.toArray(new String[colors.size()]));
|
||||||
|
//配置图例
|
||||||
|
if (isOpen) {
|
||||||
|
instantOption.setLegend(new Legend().setData(new String[]{a, b}).setLeft("10px"));
|
||||||
|
} else {
|
||||||
|
instantOption.setLegend(new Legend().setData(new String[]{a, b, c}).setLeft("10px"));
|
||||||
|
}
|
||||||
|
//上下左右的图内间距
|
||||||
|
instantOption.setGrid(new Grid().setTop("60px").setLeft("70px").setRight("40px").setBottom("10%"));
|
||||||
|
//横坐标(使用压缩后的数据)
|
||||||
|
instantOption.setXAxis(new ValueAxis().setName("ms")
|
||||||
|
.setSplitLine(new SplitLine().setShow(false))
|
||||||
|
.setAxisLine(new AxisLine().setOnZero(false))
|
||||||
|
.setType("category")
|
||||||
|
.setMinInterval(1)
|
||||||
|
);
|
||||||
|
//纵坐标
|
||||||
|
instantOption.setYAxis(new ValueAxis()
|
||||||
|
.setName(unit)
|
||||||
|
.setMax(df1.format(max * 1.1))
|
||||||
|
.setMin(df1.format(min * 1.1))
|
||||||
|
.setPosition(PicCommonData.LEFT)
|
||||||
|
.setAxisLine(new AxisLine().setShow(false).setOnZero(false))
|
||||||
|
);
|
||||||
|
//数据信息(使用压缩后的数据)
|
||||||
|
LineSeries aSeries = new LineSeries()
|
||||||
|
.setName(a)
|
||||||
|
.setSmooth(true)
|
||||||
|
.setSymbol("none")
|
||||||
|
.setConnectNulls(false)
|
||||||
|
.setData(aCompressed.data);
|
||||||
|
LineSeries bSeries = new LineSeries()
|
||||||
|
.setName(b)
|
||||||
|
.setSmooth(true)
|
||||||
|
.setSymbol("none")
|
||||||
|
.setConnectNulls(false)
|
||||||
|
.setData(bCompressed.data);
|
||||||
|
LineSeries cSeries = new LineSeries()
|
||||||
|
.setName(c)
|
||||||
|
.setSmooth(true)
|
||||||
|
.setSymbol("none")
|
||||||
|
.setConnectNulls(false)
|
||||||
|
.setData(cCompressed.data);
|
||||||
|
instantOption.setSeries(new LineSeries[]{aSeries, bSeries, cSeries});
|
||||||
|
|
||||||
|
// 渲染基础JSON
|
||||||
|
String jsonStr = ENGINE.renderJsonOption(instantOption);
|
||||||
|
cn.hutool.json.JSONObject optionJson = JSONUtil.parseObj(jsonStr);
|
||||||
|
cn.hutool.json.JSONArray seriesArray = optionJson.getJSONArray("series");
|
||||||
|
|
||||||
|
// 隐藏x轴默认标签,设置boundaryGap=false,只通过markLine显示关键节点
|
||||||
|
Object xAxisRaw = optionJson.get("xAxis");
|
||||||
|
cn.hutool.json.JSONObject xAxisJson;
|
||||||
|
if (xAxisRaw instanceof cn.hutool.json.JSONArray) {
|
||||||
|
xAxisJson = ((cn.hutool.json.JSONArray) xAxisRaw).getJSONObject(0);
|
||||||
|
} else {
|
||||||
|
xAxisJson = (cn.hutool.json.JSONObject) xAxisRaw;
|
||||||
|
}
|
||||||
|
cn.hutool.json.JSONObject axisLabelJson = new cn.hutool.json.JSONObject();
|
||||||
|
axisLabelJson.set("show", false);
|
||||||
|
xAxisJson.set("axisLabel", axisLabelJson);
|
||||||
|
xAxisJson.set("boundaryGap", false);
|
||||||
|
|
||||||
|
// 添加null markLine/markArea(基于压缩后的数据)
|
||||||
|
addNullMarkLinesForCategoryAxis(seriesArray.getJSONObject(0), aCompressed, lastTime);
|
||||||
|
addNullMarkLinesForCategoryAxis(seriesArray.getJSONObject(1), bCompressed, lastTime);
|
||||||
|
addNullMarkLinesForCategoryAxis(seriesArray.getJSONObject(2), cCompressed, lastTime);
|
||||||
|
// 在第一个series追加自定义横坐标标签markLine
|
||||||
|
addAxisLabelMarkLines(seriesArray.getJSONObject(0), aCompressed, lastTime, nPush);
|
||||||
|
return optionJson.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 提取null边界的真实x值,供其他数据集共享使用 */
|
||||||
|
public static List<Float> extractNullBoundaryXValues(List<List<Float>> data) {
|
||||||
|
List<Integer> boundaries = findNullSegmentBoundaryIndices(data);
|
||||||
|
List<Float> xValues = new ArrayList<>();
|
||||||
|
for (int idx : boundaries) {
|
||||||
|
xValues.add(data.get(idx).get(0));
|
||||||
|
}
|
||||||
|
return xValues;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 使用共享的null边界x值来压缩数据,确保不同数据集压缩结果结构一致 */
|
||||||
|
private static CompressedResult compressNullDataWithSharedBoundaries(List<List<Float>> originalData, List<Float> sharedBoundaryXValues) {
|
||||||
|
if (sharedBoundaryXValues == null || sharedBoundaryXValues.isEmpty()) {
|
||||||
|
return compressNullData(originalData);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 用共享的x值找到本数据集中对应的索引
|
||||||
|
List<Integer> boundaries = new ArrayList<>();
|
||||||
|
for (Float x : sharedBoundaryXValues) {
|
||||||
|
boundaries.add(findClosestValidIndex(originalData, x));
|
||||||
|
}
|
||||||
|
|
||||||
|
CompressedResult result = new CompressedResult();
|
||||||
|
result.data = new ArrayList<>();
|
||||||
|
result.nullRegionIndices = new ArrayList<>();
|
||||||
|
result.nullBoundaryRealXValues = new ArrayList<>(sharedBoundaryXValues);
|
||||||
|
|
||||||
|
int srcIdx = 0;
|
||||||
|
for (int b = 0; b < boundaries.size(); b += 2) {
|
||||||
|
int entryBoundary = boundaries.get(b);
|
||||||
|
int exitBoundary = boundaries.get(b + 1);
|
||||||
|
|
||||||
|
while (srcIdx <= entryBoundary) {
|
||||||
|
result.data.add(originalData.get(srcIdx));
|
||||||
|
srcIdx++;
|
||||||
|
}
|
||||||
|
|
||||||
|
int nullStartIdx = result.data.size();
|
||||||
|
float entryX = sharedBoundaryXValues.get(b);
|
||||||
|
float exitX = sharedBoundaryXValues.get(b + 1);
|
||||||
|
|
||||||
|
for (int p = 0; p < NULL_PLACEHOLDER_COUNT; p++) {
|
||||||
|
List<Float> point = new ArrayList<>();
|
||||||
|
point.add(entryX + (exitX - entryX) * p / NULL_PLACEHOLDER_COUNT);
|
||||||
|
point.add(null);
|
||||||
|
result.data.add(point);
|
||||||
|
}
|
||||||
|
|
||||||
|
int nullEndIdx = result.data.size() - 1;
|
||||||
|
result.nullRegionIndices.add(new int[]{nullStartIdx, nullEndIdx});
|
||||||
|
|
||||||
|
srcIdx = exitBoundary;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (srcIdx < originalData.size()) {
|
||||||
|
result.data.add(originalData.get(srcIdx));
|
||||||
|
srcIdx++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 压缩null数据:删除所有null数据点,替换为固定NULL_PLACEHOLDER_COUNT个占位点
|
||||||
|
* 这样null段在图表上永远只占固定视觉宽度,前后有效数据正常展开
|
||||||
|
*/
|
||||||
|
private static CompressedResult compressNullData(List<List<Float>> originalData) {
|
||||||
|
List<Integer> boundaries = findNullSegmentBoundaryIndices(originalData);
|
||||||
|
|
||||||
|
CompressedResult result = new CompressedResult();
|
||||||
|
result.data = new ArrayList<>();
|
||||||
|
result.nullRegionIndices = new ArrayList<>();
|
||||||
|
result.nullBoundaryRealXValues = new ArrayList<>();
|
||||||
|
|
||||||
|
if (boundaries.isEmpty()) {
|
||||||
|
result.data.addAll(originalData);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
int srcIdx = 0;
|
||||||
|
for (int b = 0; b < boundaries.size(); b += 2) {
|
||||||
|
// 最后一个有效点的索引(null段入口边界)
|
||||||
|
int entryBoundary = boundaries.get(b);
|
||||||
|
// 第一个恢复有效点的索引(null段出口边界)
|
||||||
|
int exitBoundary = boundaries.get(b + 1);
|
||||||
|
|
||||||
|
// 复制有效数据:从srcIdx到entryBoundary
|
||||||
|
while (srcIdx <= entryBoundary) {
|
||||||
|
result.data.add(originalData.get(srcIdx));
|
||||||
|
srcIdx++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 记录边界真实x值
|
||||||
|
result.nullBoundaryRealXValues.add(originalData.get(entryBoundary).get(0));
|
||||||
|
result.nullBoundaryRealXValues.add(originalData.get(exitBoundary).get(0));
|
||||||
|
|
||||||
|
// 插入固定数量的null占位点
|
||||||
|
int nullStartIdx = result.data.size();
|
||||||
|
float entryX = originalData.get(entryBoundary).get(0);
|
||||||
|
float exitX = originalData.get(exitBoundary).get(0);
|
||||||
|
|
||||||
|
for (int p = 0; p < NULL_PLACEHOLDER_COUNT; p++) {
|
||||||
|
List<Float> point = new ArrayList<>();
|
||||||
|
point.add(entryX + (exitX - entryX) * p / NULL_PLACEHOLDER_COUNT);
|
||||||
|
point.add(null);
|
||||||
|
result.data.add(point);
|
||||||
|
}
|
||||||
|
|
||||||
|
int nullEndIdx = result.data.size() - 1;
|
||||||
|
result.nullRegionIndices.add(new int[]{nullStartIdx, nullEndIdx});
|
||||||
|
|
||||||
|
// 跳过原始null数据点,srcIdx跳到exitBoundary
|
||||||
|
srcIdx = exitBoundary;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 复制最后一个null段之后的剩余有效数据
|
||||||
|
while (srcIdx < originalData.size()) {
|
||||||
|
result.data.add(originalData.get(srcIdx));
|
||||||
|
srcIdx++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在压缩数据中查找最接近目标x值的有效数据点索引(跳过null点)
|
||||||
|
*/
|
||||||
|
private static int findClosestValidIndex(List<List<Float>> data, float targetX) {
|
||||||
|
int closestIdx = -1;
|
||||||
|
float minDiff = Float.MAX_VALUE;
|
||||||
|
for (int i = 0; i < data.size(); i++) {
|
||||||
|
Float y = data.get(i).get(1);
|
||||||
|
if (y == null) continue;
|
||||||
|
float diff = Math.abs(data.get(i).get(0) - targetX);
|
||||||
|
if (diff < minDiff) {
|
||||||
|
minDiff = diff;
|
||||||
|
closestIdx = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return closestIdx;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void addAxisLabelMarkLines(cn.hutool.json.JSONObject seriesObj, CompressedResult compressed, Double lastTime, Integer nPush) {
|
||||||
|
boolean hasNull = !compressed.nullRegionIndices.isEmpty();
|
||||||
|
|
||||||
|
// 收集需要标注的横坐标位置:[数据索引, 显示的时间值]
|
||||||
|
List<int[]> labelPositions = new ArrayList<>();
|
||||||
|
// 开头ms(始终显示)
|
||||||
|
labelPositions.add(new int[]{findClosestValidIndex(compressed.data, -nPush), -nPush});
|
||||||
|
// 0ms(始终显示)
|
||||||
|
labelPositions.add(new int[]{findClosestValidIndex(compressed.data, 0f), 0});
|
||||||
|
// npush ms(仅在有null时显示)
|
||||||
|
if (hasNull) {
|
||||||
|
labelPositions.add(new int[]{findClosestValidIndex(compressed.data, nPush), nPush});
|
||||||
|
}
|
||||||
|
// null段边界真实时间值(仅在有null时显示)
|
||||||
|
if (hasNull) {
|
||||||
|
for (Float realX : compressed.nullBoundaryRealXValues) {
|
||||||
|
int idx = findClosestValidIndex(compressed.data, realX);
|
||||||
|
if (idx >= 0) {
|
||||||
|
labelPositions.add(new int[]{idx, (int) Math.round(realX)});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// lastTime(始终显示)
|
||||||
|
if (lastTime != null) {
|
||||||
|
labelPositions.add(new int[]{findClosestValidIndex(compressed.data, lastTime.floatValue()), lastTime.intValue()});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 最后一组数据(始终显示,数据结束位置横坐标)
|
||||||
|
if (lastTime != null) {
|
||||||
|
float lastTime20 = lastTime.floatValue() + nPush;
|
||||||
|
int lastTime20Idx = findClosestValidIndex(compressed.data, lastTime20);
|
||||||
|
if (lastTime20Idx >= 0) {
|
||||||
|
labelPositions.add(new int[]{(lastTime20Idx-2), (int) Math.round(lastTime20)});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取或创建markLine
|
||||||
|
cn.hutool.json.JSONObject existingMarkLine = seriesObj.getJSONObject("markLine");
|
||||||
|
cn.hutool.json.JSONArray markLineData;
|
||||||
|
|
||||||
|
if (existingMarkLine == null) {
|
||||||
|
// 无null的情况:自己创建markLine,包含虚线和横坐标标签
|
||||||
|
markLineData = new cn.hutool.json.JSONArray();
|
||||||
|
|
||||||
|
// x=0 虚线
|
||||||
|
int zeroIdx = findClosestValidIndex(compressed.data, 0f);
|
||||||
|
if (zeroIdx >= 0) {
|
||||||
|
cn.hutool.json.JSONObject zeroLine = new cn.hutool.json.JSONObject();
|
||||||
|
zeroLine.set("xAxis", zeroIdx);
|
||||||
|
cn.hutool.json.JSONObject zeroLabel = new cn.hutool.json.JSONObject();
|
||||||
|
zeroLabel.set("show", false);
|
||||||
|
zeroLine.set("label", zeroLabel);
|
||||||
|
markLineData.add(zeroLine);
|
||||||
|
}
|
||||||
|
// lastTime 虚线
|
||||||
|
if (lastTime != null) {
|
||||||
|
int lastTimeIdx = findClosestValidIndex(compressed.data, lastTime.floatValue());
|
||||||
|
if (lastTimeIdx >= 0) {
|
||||||
|
cn.hutool.json.JSONObject lastTimeLine = new cn.hutool.json.JSONObject();
|
||||||
|
lastTimeLine.set("xAxis", lastTimeIdx);
|
||||||
|
cn.hutool.json.JSONObject lastTimeLabelObj = new cn.hutool.json.JSONObject();
|
||||||
|
lastTimeLabelObj.set("show", false);
|
||||||
|
lastTimeLine.set("label", lastTimeLabelObj);
|
||||||
|
markLineData.add(lastTimeLine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 先收集所有标签到markLineData
|
||||||
|
for (int[] pos : labelPositions) {
|
||||||
|
cn.hutool.json.JSONObject line = new cn.hutool.json.JSONObject();
|
||||||
|
line.set("xAxis", pos[0]);
|
||||||
|
cn.hutool.json.JSONObject lineLineStyle = new cn.hutool.json.JSONObject();
|
||||||
|
lineLineStyle.set("width", 0);
|
||||||
|
line.set("lineStyle", lineLineStyle);
|
||||||
|
cn.hutool.json.JSONObject lineLabel = new cn.hutool.json.JSONObject();
|
||||||
|
lineLabel.set("show", true);
|
||||||
|
lineLabel.set("formatter", String.valueOf(pos[1]));
|
||||||
|
lineLabel.set("position", "start");
|
||||||
|
lineLabel.set("color", "#333");
|
||||||
|
lineLabel.set("fontSize", 10);
|
||||||
|
line.set("label", lineLabel);
|
||||||
|
markLineData.add(line);
|
||||||
|
}
|
||||||
|
// 最后一次性设置到markLine和series
|
||||||
|
existingMarkLine = new cn.hutool.json.JSONObject();
|
||||||
|
existingMarkLine.set("symbol", new String[]{"none", "none"});
|
||||||
|
cn.hutool.json.JSONObject lineStyle = new cn.hutool.json.JSONObject();
|
||||||
|
lineStyle.set("type", "dashed");
|
||||||
|
lineStyle.set("color", "#999");
|
||||||
|
lineStyle.set("width", 1);
|
||||||
|
existingMarkLine.set("lineStyle", lineStyle);
|
||||||
|
cn.hutool.json.JSONObject globalLabel = new cn.hutool.json.JSONObject();
|
||||||
|
globalLabel.set("show", false);
|
||||||
|
existingMarkLine.set("label", globalLabel);
|
||||||
|
existingMarkLine.set("data", markLineData);
|
||||||
|
seriesObj.set("markLine", existingMarkLine);
|
||||||
|
} else {
|
||||||
|
// 有null的情况:追加标签到已有的markLine
|
||||||
|
markLineData = existingMarkLine.getJSONArray("data");
|
||||||
|
for (int[] pos : labelPositions) {
|
||||||
|
cn.hutool.json.JSONObject line = new cn.hutool.json.JSONObject();
|
||||||
|
line.set("xAxis", pos[0]);
|
||||||
|
cn.hutool.json.JSONObject lineLineStyle = new cn.hutool.json.JSONObject();
|
||||||
|
lineLineStyle.set("width", 0);
|
||||||
|
line.set("lineStyle", lineLineStyle);
|
||||||
|
cn.hutool.json.JSONObject lineLabel = new cn.hutool.json.JSONObject();
|
||||||
|
lineLabel.set("show", true);
|
||||||
|
lineLabel.set("formatter", String.valueOf(pos[1]));
|
||||||
|
lineLabel.set("position", "start");
|
||||||
|
lineLabel.set("color", "#333");
|
||||||
|
lineLabel.set("fontSize", 10);
|
||||||
|
line.set("label", lineLabel);
|
||||||
|
markLineData.add(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<Integer> findNullSegmentBoundaryIndices(List<List<Float>> data) {
|
||||||
|
List<Integer> indices = new ArrayList<>();
|
||||||
|
boolean inNullSegment = false;
|
||||||
|
for (int i = 0; i < data.size(); i++) {
|
||||||
|
Float y = data.get(i).get(1);
|
||||||
|
if (y == null) {
|
||||||
|
if (!inNullSegment) {
|
||||||
|
indices.add(i > 0 ? i - 1 : i);
|
||||||
|
inNullSegment = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (inNullSegment) {
|
||||||
|
indices.add(i);
|
||||||
|
inNullSegment = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (inNullSegment) {
|
||||||
|
indices.add(data.size() - 1);
|
||||||
|
}
|
||||||
|
return indices;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void addNullMarkLinesForCategoryAxis(cn.hutool.json.JSONObject seriesObj, CompressedResult compressed, Double lastTime) {
|
||||||
|
if (compressed.nullRegionIndices.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cn.hutool.json.JSONArray markLineData = new cn.hutool.json.JSONArray();
|
||||||
|
// x=0 虚线
|
||||||
|
int zeroIdx = findClosestValidIndex(compressed.data, 0f);
|
||||||
|
if (zeroIdx >= 0) {
|
||||||
|
cn.hutool.json.JSONObject zeroLine = new cn.hutool.json.JSONObject();
|
||||||
|
zeroLine.set("xAxis", zeroIdx);
|
||||||
|
cn.hutool.json.JSONObject zeroLabel = new cn.hutool.json.JSONObject();
|
||||||
|
zeroLabel.set("show", false);
|
||||||
|
zeroLine.set("label", zeroLabel);
|
||||||
|
markLineData.add(zeroLine);
|
||||||
|
}
|
||||||
|
// null段边界的垂直虚线
|
||||||
|
for (int r = 0; r < compressed.nullRegionIndices.size(); r++) {
|
||||||
|
int[] region = compressed.nullRegionIndices.get(r);
|
||||||
|
int nullStartIdx = region[0]; // 第一个占位点索引
|
||||||
|
int nullEndIdx = region[1]; // 最后一个占位点索引
|
||||||
|
|
||||||
|
// 入口虚线:nullStartIdx - 1(null前最后一个有效数据点)
|
||||||
|
cn.hutool.json.JSONObject entryLine = new cn.hutool.json.JSONObject();
|
||||||
|
entryLine.set("xAxis", nullStartIdx - 1);
|
||||||
|
cn.hutool.json.JSONObject entryLabel = new cn.hutool.json.JSONObject();
|
||||||
|
entryLabel.set("show", false);
|
||||||
|
entryLine.set("label", entryLabel);
|
||||||
|
markLineData.add(entryLine);
|
||||||
|
|
||||||
|
// 出口虚线:nullEndIdx(null后第一个有效数据点)
|
||||||
|
cn.hutool.json.JSONObject exitLine = new cn.hutool.json.JSONObject();
|
||||||
|
exitLine.set("xAxis", nullEndIdx);
|
||||||
|
cn.hutool.json.JSONObject exitLabel = new cn.hutool.json.JSONObject();
|
||||||
|
exitLabel.set("show", false);
|
||||||
|
exitLine.set("label", exitLabel);
|
||||||
|
markLineData.add(exitLine);
|
||||||
|
}
|
||||||
|
// 时间持续时间结束的数据点
|
||||||
|
if (lastTime != null) {
|
||||||
|
int lastTimeIdx = findClosestValidIndex(compressed.data, lastTime.floatValue());
|
||||||
|
if (lastTimeIdx >= 0) {
|
||||||
|
cn.hutool.json.JSONObject lastTimeLine = new cn.hutool.json.JSONObject();
|
||||||
|
lastTimeLine.set("xAxis", lastTimeIdx);
|
||||||
|
cn.hutool.json.JSONObject lastTimeLabel = new cn.hutool.json.JSONObject();
|
||||||
|
lastTimeLabel.set("show", false);
|
||||||
|
lastTimeLine.set("label", lastTimeLabel);
|
||||||
|
markLineData.add(lastTimeLine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cn.hutool.json.JSONObject markLine = new cn.hutool.json.JSONObject();
|
||||||
|
markLine.set("symbol", new String[]{"none", "none"});
|
||||||
|
cn.hutool.json.JSONObject lineStyle = new cn.hutool.json.JSONObject();
|
||||||
|
lineStyle.set("type", "dashed");
|
||||||
|
lineStyle.set("color", "#999");
|
||||||
|
lineStyle.set("width", 1);
|
||||||
|
markLine.set("lineStyle", lineStyle);
|
||||||
|
cn.hutool.json.JSONObject globalLabel = new cn.hutool.json.JSONObject();
|
||||||
|
globalLabel.set("show", false);
|
||||||
|
markLine.set("label", globalLabel);
|
||||||
|
markLine.set("data", markLineData);
|
||||||
|
seriesObj.set("markLine", markLine);
|
||||||
|
|
||||||
|
// markArea - 灰色背景覆盖null区域(从入口边界到出口边界)
|
||||||
|
cn.hutool.json.JSONArray markAreaData = new cn.hutool.json.JSONArray();
|
||||||
|
for (int r = 0; r < compressed.nullRegionIndices.size(); r++) {
|
||||||
|
int[] region = compressed.nullRegionIndices.get(r);
|
||||||
|
int nullStartIdx = region[0];
|
||||||
|
int nullEndIdx = region[1];
|
||||||
|
|
||||||
|
cn.hutool.json.JSONArray areaPair = new cn.hutool.json.JSONArray();
|
||||||
|
cn.hutool.json.JSONObject start = new cn.hutool.json.JSONObject();
|
||||||
|
start.set("xAxis", nullStartIdx - 1); // 从入口边界有效数据点
|
||||||
|
cn.hutool.json.JSONObject end = new cn.hutool.json.JSONObject();
|
||||||
|
end.set("xAxis", nullEndIdx); // 到出口边界有效数据点
|
||||||
|
areaPair.add(start);
|
||||||
|
areaPair.add(end);
|
||||||
|
markAreaData.add(areaPair);
|
||||||
|
}
|
||||||
|
cn.hutool.json.JSONObject markArea = new cn.hutool.json.JSONObject();
|
||||||
|
cn.hutool.json.JSONObject itemStyle = new cn.hutool.json.JSONObject();
|
||||||
|
itemStyle.set("color", "rgba(180, 180, 180, 0.2)");
|
||||||
|
itemStyle.set("borderWidth", 0);
|
||||||
|
markArea.set("itemStyle", itemStyle);
|
||||||
|
markArea.set("data", markAreaData);
|
||||||
|
seriesObj.set("markArea", markArea);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param title 标题
|
* @param title 标题
|
||||||
* @param values 数据值
|
* @param values 数据值
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ public class PieGenerator {
|
|||||||
Option reasonOption = new Option();
|
Option reasonOption = new Option();
|
||||||
//取消渲染动画
|
//取消渲染动画
|
||||||
reasonOption.setAnimation(false);
|
reasonOption.setAnimation(false);
|
||||||
|
String[] colorArr = {"#526ADE", "#00BFF5","#FFBF00","#77DA63","#D5FF6B"};
|
||||||
|
reasonOption.setColor(colorArr);
|
||||||
//背景色
|
//背景色
|
||||||
reasonOption.setBackgroundColor(PicCommonData.PIC_BACK_COLOR);
|
reasonOption.setBackgroundColor(PicCommonData.PIC_BACK_COLOR);
|
||||||
//标题
|
//标题
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public class BusinessDataUtil {
|
|||||||
List<List<Double>> unTolerateData = new ArrayList<>();
|
List<List<Double>> unTolerateData = new ArrayList<>();
|
||||||
for (List<Double> list : originData) {
|
for (List<Double> list : originData) {
|
||||||
//是否超过上限
|
//是否超过上限
|
||||||
if (list.get(0) <= 0.03) {
|
if (list.get(0) <= 0.003) {
|
||||||
int line = 230 - 30000 * list.get(0).intValue();
|
int line = 230 - 30000 * list.get(0).intValue();
|
||||||
if (list.get(1) > line) {
|
if (list.get(1) > line) {
|
||||||
unTolerateData.add(list);
|
unTolerateData.add(list);
|
||||||
|
|||||||
@@ -10,9 +10,10 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.client.RestTemplate;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author hongawen
|
* @author hongawen
|
||||||
@@ -55,10 +56,9 @@ public class DrawPicUtil {
|
|||||||
return Objects.requireNonNull(picResult.getBody()).indexOf("image/png") > 0 ? picResult.getBody() : "";
|
return Objects.requireNonNull(picResult.getBody()).indexOf("image/png") > 0 ? picResult.getBody() : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* 绘制波形图
|
|
||||||
* @author hongawen
|
* @author hongawen
|
||||||
|
* 绘制波形图
|
||||||
* @date 2023/6/21 11:01
|
* @date 2023/6/21 11:01
|
||||||
* @return String base64数据
|
* @return String base64数据
|
||||||
*/
|
*/
|
||||||
@@ -77,6 +77,11 @@ public class DrawPicUtil {
|
|||||||
return drawPic(instantJson, width, height);
|
return drawPic(instantJson, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String drawWavePic(String title, List<List<Float>> aValue, List<List<Float>> bValue, List<List<Float>> cValue, String unit, Float max, Float min, String a, String b, String c, List<String> colors, Boolean isOpen, Double lastTime, List<Float> sharedNullBoundaryXValues,Integer nPush) {
|
||||||
|
String instantJson = LineGenerator.generateWaveOption(title, aValue, bValue, cValue, unit, max, min, a, b, c, colors, isOpen, lastTime, sharedNullBoundaryXValues,nPush);
|
||||||
|
return drawPic(instantJson, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* 绘制itic曲线图
|
* 绘制itic曲线图
|
||||||
|
|||||||
@@ -3,11 +3,9 @@ package com.njcn.event.file.component;
|
|||||||
import cn.hutool.core.date.DatePattern;
|
import cn.hutool.core.date.DatePattern;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.io.IoUtil;
|
import cn.hutool.core.io.IoUtil;
|
||||||
import cn.hutool.core.text.StrPool;
|
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
import cn.hutool.core.util.CharsetUtil;
|
import cn.hutool.core.util.CharsetUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
|
||||||
import com.njcn.common.pojo.exception.BusinessException;
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
import com.njcn.common.utils.wave.BitConverter;
|
import com.njcn.common.utils.wave.BitConverter;
|
||||||
import com.njcn.event.file.pojo.dto.*;
|
import com.njcn.event.file.pojo.dto.*;
|
||||||
@@ -16,11 +14,13 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author hongawen
|
* @author hongawen
|
||||||
@@ -81,6 +81,46 @@ public class WaveFileComponent {
|
|||||||
return waveDataDTO;
|
return waveDataDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public WaveDataDTO getComtradeNoAddPoints(InputStream cfgStream, InputStream datStream, int iType) {
|
||||||
|
WaveDataDTO waveDataDTO = new WaveDataDTO();
|
||||||
|
// 首先判断文件路径是否为空
|
||||||
|
// 读取cfg文件
|
||||||
|
ComtradeCfgDTO comtradeCfgDTO = getComtradeCfgNoAddPoints(cfgStream);
|
||||||
|
// 为空或者未找到结束符号
|
||||||
|
if (comtradeCfgDTO == null || !"BINARY".equalsIgnoreCase(comtradeCfgDTO.getStrBinType())) {
|
||||||
|
throw new BusinessException(WaveFileResponseEnum.CFG_DATA_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****根据通道号计算相别** add by yexb -----Start****
|
||||||
|
* 1、判断是否是3的倍数,是3的倍数则是3相
|
||||||
|
* 2、假如不是3的倍数 ,是1的倍数则是单相
|
||||||
|
********************************************************/
|
||||||
|
if (comtradeCfgDTO.getNAnalogNum() % 3 == 0) {
|
||||||
|
comtradeCfgDTO.setNPhasic(3);
|
||||||
|
} else {
|
||||||
|
comtradeCfgDTO.setNPhasic(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 给相别数量赋值
|
||||||
|
waveDataDTO.setIPhasic(comtradeCfgDTO.getNPhasic());
|
||||||
|
|
||||||
|
// 组装解析抬头
|
||||||
|
getWaveTitle(waveDataDTO, comtradeCfgDTO);
|
||||||
|
|
||||||
|
// 解析.dat文件
|
||||||
|
List<List<Float>> listWaveData = getComtradeDatNoAddPoints(comtradeCfgDTO, datStream, iType);
|
||||||
|
|
||||||
|
waveDataDTO.setComtradeCfgDTO(comtradeCfgDTO);
|
||||||
|
|
||||||
|
waveDataDTO.setListWaveData(listWaveData);
|
||||||
|
|
||||||
|
//add by hongawen,将暂态触发起始时间记录下来
|
||||||
|
waveDataDTO.setTime(DateUtil.format(comtradeCfgDTO.getTimeTrige(), DatePattern.NORM_DATETIME_MS_PATTERN));
|
||||||
|
/*****根据通道号计算相别** add by yexb -----end****/
|
||||||
|
|
||||||
|
return waveDataDTO;
|
||||||
|
}
|
||||||
|
|
||||||
/*********************************
|
/*********************************
|
||||||
* 根据波形数据算出rms值数据
|
* 根据波形数据算出rms值数据
|
||||||
* param waveDataDTO 瞬时波形(包含了CFG配置文件)
|
* param waveDataDTO 瞬时波形(包含了CFG配置文件)
|
||||||
@@ -352,6 +392,127 @@ public class WaveFileComponent {
|
|||||||
* return 返回bool为是否解析出错
|
* return 返回bool为是否解析出错
|
||||||
**********************************/
|
**********************************/
|
||||||
private ComtradeCfgDTO getComtradeCfg(InputStream cfgStream) {
|
private ComtradeCfgDTO getComtradeCfg(InputStream cfgStream) {
|
||||||
|
ComtradeCfgDTO comtradeCfgDTO = new ComtradeCfgDTO();
|
||||||
|
try (InputStreamReader read = new InputStreamReader(cfgStream, CharsetUtil.CHARSET_GBK); BufferedReader bufferedReader = new BufferedReader(read);) {
|
||||||
|
// 第一行不关心仅仅是一些描述类的信息
|
||||||
|
String strFileLine = bufferedReader.readLine();
|
||||||
|
|
||||||
|
// 第二行需要关心第二个(模拟量的个数)和第三个参数(开关量的个数)
|
||||||
|
strFileLine = bufferedReader.readLine();
|
||||||
|
// 按“,”进行分割
|
||||||
|
String[] strTempArray = strFileLine.split(StrUtil.COMMA);
|
||||||
|
// 总个数
|
||||||
|
comtradeCfgDTO.setNChannelNum(Integer.parseInt(strTempArray[0]));
|
||||||
|
// 模拟量的个数
|
||||||
|
comtradeCfgDTO.setNAnalogNum(Integer.parseInt(strTempArray[1].substring(0, strTempArray[1].length() - 1)));
|
||||||
|
// 开关量的个数
|
||||||
|
comtradeCfgDTO.setNDigitalNum(Integer.parseInt(strTempArray[2].substring(0, strTempArray[2].length() - 1)));
|
||||||
|
|
||||||
|
// 从第三行开始的ComtradeCfg.nChannelNum行是模拟量通道和数字量通道
|
||||||
|
List<AnalogDTO> lstAnalogDTO = new ArrayList<>();
|
||||||
|
comtradeCfgDTO.setLstAnalogDTO(lstAnalogDTO);
|
||||||
|
for (int i = 0; i < comtradeCfgDTO.getNChannelNum(); i++) {
|
||||||
|
AnalogDTO analogDTO = new AnalogDTO();
|
||||||
|
lstAnalogDTO.add(analogDTO);
|
||||||
|
strFileLine = bufferedReader.readLine();
|
||||||
|
strTempArray = strFileLine.split(StrUtil.COMMA);
|
||||||
|
//通道序号
|
||||||
|
analogDTO.setNIndex(Integer.parseInt(strTempArray[0]));
|
||||||
|
// 通道名称
|
||||||
|
analogDTO.setSzChannleName(strTempArray[1]);
|
||||||
|
// 相位名称
|
||||||
|
analogDTO.setSzPhasicName(strTempArray[2]);
|
||||||
|
// 监视的通道名称
|
||||||
|
analogDTO.setSzMonitoredChannleName(strTempArray[3]);
|
||||||
|
// 通道的单位
|
||||||
|
analogDTO.setSzUnitName(strTempArray[4]);
|
||||||
|
// 通道的系数
|
||||||
|
analogDTO.setFCoefficent(Float.parseFloat(strTempArray[5]));
|
||||||
|
// 通道的偏移量
|
||||||
|
analogDTO.setFOffset(Float.parseFloat(strTempArray[6]));
|
||||||
|
// 起始采样时间的偏移量
|
||||||
|
analogDTO.setFTimeOffset(Float.parseFloat(strTempArray[7]));
|
||||||
|
// 采样值的最小值
|
||||||
|
analogDTO.setNMin(Integer.parseInt(strTempArray[8]));
|
||||||
|
// 采样值的最大值
|
||||||
|
analogDTO.setNMax(Integer.parseInt(strTempArray[9]));
|
||||||
|
// 一次变比
|
||||||
|
analogDTO.setFPrimary(Float.parseFloat(strTempArray[10]));
|
||||||
|
// 二次变比
|
||||||
|
analogDTO.setFSecondary(Float.parseFloat(strTempArray[11]));
|
||||||
|
// 一次值还是二次值标志
|
||||||
|
analogDTO.setSzValueType(strTempArray[12]);
|
||||||
|
}
|
||||||
|
|
||||||
|
//WW 2019-11-14 // 采样频率
|
||||||
|
String freqLine = bufferedReader.readLine();
|
||||||
|
int nFreq;
|
||||||
|
try {
|
||||||
|
// 先尝试解析为double再四舍五入为整数,以兼容"50.00"这样的格式
|
||||||
|
nFreq = (int) Math.round(Double.parseDouble(freqLine));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
// 如果失败则使用原来的整数解析方式
|
||||||
|
nFreq = Integer.parseInt(freqLine);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取采样段数
|
||||||
|
strFileLine = bufferedReader.readLine();
|
||||||
|
int nRates = Integer.parseInt(strFileLine);
|
||||||
|
comtradeCfgDTO.setNRates(nRates);
|
||||||
|
// 获得每段的采样率 //采样率
|
||||||
|
List<RateDTO> lstRate = new ArrayList<>();
|
||||||
|
int nOffset = 0;
|
||||||
|
for (int i = 0; i < nRates; i++) {
|
||||||
|
strFileLine = bufferedReader.readLine();
|
||||||
|
strTempArray = strFileLine.split(StrUtil.COMMA);
|
||||||
|
RateDTO rateDTO = new RateDTO();
|
||||||
|
// 单周波采样点数 //WW 2019-11-14
|
||||||
|
double doubleValue = Double.parseDouble(strTempArray[0]); // 解析为 double
|
||||||
|
int result = (int) (doubleValue / nFreq); // 强制转换为 int
|
||||||
|
rateDTO.setNOneSample(result);
|
||||||
|
// 总点数 //这里的strTemp是一个偏移量
|
||||||
|
rateDTO.setNSampleNum((Integer.parseInt(strTempArray[1]) - nOffset));
|
||||||
|
nOffset += rateDTO.getNSampleNum();
|
||||||
|
lstRate.add(rateDTO);
|
||||||
|
}
|
||||||
|
comtradeCfgDTO.setLstRate(lstRate);
|
||||||
|
// 增加读取波形起始时间个结束时间
|
||||||
|
String timeFormat = "dd/MM/yyyy,HH:mm:ss.SSS";
|
||||||
|
// 波形起始时间
|
||||||
|
strFileLine = bufferedReader.readLine();
|
||||||
|
strFileLine = strFileLine.substring(0, strFileLine.length() - 3);
|
||||||
|
comtradeCfgDTO.setTimeStart(DateUtil.parse(strFileLine, timeFormat));
|
||||||
|
|
||||||
|
// 暂态触发时间
|
||||||
|
strFileLine = bufferedReader.readLine();
|
||||||
|
strFileLine = strFileLine.substring(0, strFileLine.length() - 3);
|
||||||
|
comtradeCfgDTO.setTimeTrige(DateUtil.parse(strFileLine, timeFormat));
|
||||||
|
|
||||||
|
// 获取触发时间的时间 + 毫秒
|
||||||
|
Calendar calendar = DateUtil.calendar(comtradeCfgDTO.getTimeTrige());
|
||||||
|
comtradeCfgDTO.setFirstMs(calendar.get(Calendar.MILLISECOND));
|
||||||
|
comtradeCfgDTO.setFirstTime(calendar.getTime());
|
||||||
|
|
||||||
|
|
||||||
|
long a = comtradeCfgDTO.getTimeStart().getTime();
|
||||||
|
long b = comtradeCfgDTO.getTimeTrige().getTime();
|
||||||
|
|
||||||
|
int c = (int) (b - a);
|
||||||
|
if (c >= 90 && c <= 110) {
|
||||||
|
comtradeCfgDTO.setNPush(100);
|
||||||
|
} else if (c >= 190 && c <= 210) {
|
||||||
|
comtradeCfgDTO.setNPush(200);
|
||||||
|
}
|
||||||
|
// 赋值编码格式(二进制)
|
||||||
|
comtradeCfgDTO.setStrBinType(bufferedReader.readLine().toUpperCase());
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 解析.cfg文件出错
|
||||||
|
comtradeCfgDTO = null;
|
||||||
|
}
|
||||||
|
return comtradeCfgDTO;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ComtradeCfgDTO getComtradeCfgNoAddPoints(InputStream cfgStream) {
|
||||||
ComtradeCfgDTO comtradeCfgDTO = new ComtradeCfgDTO();
|
ComtradeCfgDTO comtradeCfgDTO = new ComtradeCfgDTO();
|
||||||
try (InputStreamReader read = new InputStreamReader(cfgStream, CharsetUtil.CHARSET_GBK); BufferedReader bufferedReader = new BufferedReader(read);) {
|
try (InputStreamReader read = new InputStreamReader(cfgStream, CharsetUtil.CHARSET_GBK); BufferedReader bufferedReader = new BufferedReader(read);) {
|
||||||
// 第一行不关心仅仅是一些描述类的信息
|
// 第一行不关心仅仅是一些描述类的信息
|
||||||
@@ -497,7 +658,7 @@ public class WaveFileComponent {
|
|||||||
int nDigSize = (comtradeCfgDTO.getNDigitalNum() % 16) > 0 ? (comtradeCfgDTO.getNDigitalNum() / 16 + 1) * 2 : comtradeCfgDTO.getNDigitalNum() / 16 * 2;
|
int nDigSize = (comtradeCfgDTO.getNDigitalNum() % 16) > 0 ? (comtradeCfgDTO.getNDigitalNum() / 16 + 1) * 2 : comtradeCfgDTO.getNDigitalNum() / 16 * 2;
|
||||||
int nBlockSize = 2 * Integer.SIZE / 8 + comtradeCfgDTO.getNAnalogNum() * 2 + nDigSize;
|
int nBlockSize = 2 * Integer.SIZE / 8 + comtradeCfgDTO.getNAnalogNum() * 2 + nDigSize;
|
||||||
// 总长度除以每个块的大小
|
// 总长度除以每个块的大小
|
||||||
int nBlockNum = datArray.length / nBlockSize;
|
int nBlockNum = (int)Math.floor(datArray.length / nBlockSize);
|
||||||
|
|
||||||
// 获取采样率
|
// 获取采样率
|
||||||
int finalSampleRate = getFinalWaveSample(comtradeCfgDTO.getLstRate(), iType);
|
int finalSampleRate = getFinalWaveSample(comtradeCfgDTO.getLstRate(), iType);
|
||||||
@@ -511,13 +672,14 @@ public class WaveFileComponent {
|
|||||||
//抽点后新的的采样率
|
//抽点后新的的采样率
|
||||||
List<RateDTO> newLstRate = new ArrayList<>();
|
List<RateDTO> newLstRate = new ArrayList<>();
|
||||||
for (int iRate = 0; iRate < comtradeCfgDTO.getNRates(); iRate++) {
|
for (int iRate = 0; iRate < comtradeCfgDTO.getNRates(); iRate++) {
|
||||||
// if (comtradeCfgDTO.getLstRate().get(iRate).getNOneSample() >= 32) {
|
|
||||||
// 计算本段录波总共有多少波形
|
// 计算本段录波总共有多少波形
|
||||||
nWaveNum = comtradeCfgDTO.getLstRate().get(iRate).getNSampleNum() / comtradeCfgDTO.getLstRate().get(iRate).getNOneSample();
|
nWaveNum = comtradeCfgDTO.getLstRate().get(iRate).getNSampleNum() / comtradeCfgDTO.getLstRate().get(iRate).getNOneSample();
|
||||||
//设置总波形大小
|
//设置总波形大小
|
||||||
comtradeCfgDTO.setNAllWaveNum(comtradeCfgDTO.getNAllWaveNum() + nWaveNum);
|
comtradeCfgDTO.setNAllWaveNum(comtradeCfgDTO.getNAllWaveNum() + nWaveNum);
|
||||||
// 将最低采样率替换到本段录波内
|
// 将最低采样率替换到本段录波内
|
||||||
RateDTO tmpRateDTO = new RateDTO();
|
RateDTO tmpRateDTO = new RateDTO();
|
||||||
|
// C# 原实现中 bool 默认是 false,16~31 点/周波段也应按普通抽点处理
|
||||||
|
tmpRateDTO.bRMSFlag = false;
|
||||||
// 有效值标志,如果是有效值,那么就需要反向补点,而不是抽点
|
// 有效值标志,如果是有效值,那么就需要反向补点,而不是抽点
|
||||||
if (comtradeCfgDTO.getLstRate().get(iRate).getNOneSample() >= 32) {
|
if (comtradeCfgDTO.getLstRate().get(iRate).getNOneSample() >= 32) {
|
||||||
//YXB 2025-08-27
|
//YXB 2025-08-27
|
||||||
@@ -547,12 +709,299 @@ public class WaveFileComponent {
|
|||||||
newLstRate.get(nnInd).setNSampleNum(comtradeCfgDTO.getLstRate().get(iRate).getNOneSample() * nWaveNum);
|
newLstRate.get(nnInd).setNSampleNum(comtradeCfgDTO.getLstRate().get(iRate).getNOneSample() * nWaveNum);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nnInd++;
|
||||||
|
}
|
||||||
|
// 偏移量,采样间隔
|
||||||
|
long nOffSet = 0, nWaveSpan;
|
||||||
|
//两个点之间的时间差
|
||||||
|
float fValue, dfValue;
|
||||||
|
// 计算不同块的采样率
|
||||||
|
int nIndex = 0;
|
||||||
|
// .CFG中采样率
|
||||||
|
RateDTO tmpRateDTO;
|
||||||
|
// nBlockNum 总循环次数
|
||||||
|
for (int i = 0; i < nBlockNum; i++) {
|
||||||
|
tmpRateDTO = comtradeCfgDTO.getLstRate().get(nIndex);
|
||||||
|
// 判断是否进入下一段
|
||||||
|
if (i == tmpRateDTO.getNSampleNum() + nOffSet) {
|
||||||
|
nOffSet += tmpRateDTO.getNSampleNum();
|
||||||
|
nIndex++;
|
||||||
|
if (nIndex == nnInd) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tmpRateDTO = comtradeCfgDTO.getLstRate().get(nIndex);
|
||||||
|
dfValue = (float) 20 / tmpRateDTO.getNOneSample();
|
||||||
|
// C# 原实现中 RMS 段与普通抽点是两条独立控制流,不能挂在同一个取模条件下
|
||||||
|
if (Boolean.TRUE.equals(newLstRate.get(nIndex).bRMSFlag)) {
|
||||||
|
//计算本段补点采样间隔
|
||||||
|
nWaveSpan = newLstRate.get(nIndex).getNOneSample() / tmpRateDTO.getNOneSample();
|
||||||
|
// 计算有多少个周波
|
||||||
|
long allWaveTemp = newLstRate.get(nIndex).getNSampleNum() / newLstRate.get(nIndex).getNOneSample();
|
||||||
|
// 本段需要补多少点
|
||||||
|
long allempSample = newLstRate.get(nIndex).getNOneSample();
|
||||||
|
int segmentEndIndex = (int) (nOffSet + tmpRateDTO.getNSampleNum() - 1);
|
||||||
|
for (int iWaveTemp = 0; iWaveTemp < allWaveTemp; iWaveTemp++) {
|
||||||
|
for (int mTempSample = 0; mTempSample < allempSample; mTempSample++) {
|
||||||
|
// 2 点/周波时,半周波位置需要切换到该周波的第二个原始采样点
|
||||||
|
if (mTempSample / nWaveSpan == 1 && mTempSample % nWaveSpan == 0) {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
//存储局部数据集合,包含了时间,A,B,C三相
|
||||||
|
List<Float> tmpWaveData = new ArrayList<>();
|
||||||
|
for (int j = 0; j < comtradeCfgDTO.getNAnalogNum(); j++) {
|
||||||
|
if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzPhasicName().equalsIgnoreCase("N")) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
float fCoef = comtradeCfgDTO.getLstAnalogDTO().get(j).getFCoefficent();
|
||||||
|
fValue = BitConverter.byte2ToUnsignedShort(datArray, i * nBlockSize + 2 * 4 + j * 2) * fCoef;
|
||||||
|
//WW 2019-11-14
|
||||||
|
/*************************
|
||||||
|
* 1、接口返回的默认是二次值
|
||||||
|
* 2、P是一次值 S是二次值
|
||||||
|
* 3、S(二次值)情况下:
|
||||||
|
* ①、单位为"V"时候则直接等于;
|
||||||
|
* ②、单位为"kV"时候需要乘以1000
|
||||||
|
* 4、P(一次值)情况下:
|
||||||
|
* ①、单位为"V"时候则直接等于;
|
||||||
|
* ②、单位为"kV"时候需要乘以1000
|
||||||
|
*************************/
|
||||||
|
//P是一次值 S是二次值
|
||||||
|
if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzValueType().equalsIgnoreCase("S")) {
|
||||||
|
//判断单位是V还是kV
|
||||||
|
if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzUnitName().equalsIgnoreCase("KV")) {
|
||||||
|
fValue = fValue * 1000.0f;
|
||||||
|
} else {
|
||||||
|
fValue = fValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//P是一次值 S是二次值
|
||||||
|
else if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzValueType().equalsIgnoreCase("P")) {
|
||||||
|
//判断单位是V还是kV
|
||||||
|
if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzUnitName().equalsIgnoreCase("V")) {
|
||||||
|
//根据cfg内的变比,将一次值转换成二次值
|
||||||
|
if (comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary() != 0.0f) {
|
||||||
|
fValue = fValue * comtradeCfgDTO.getLstAnalogDTO().get(j).getFSecondary() / comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary();
|
||||||
|
} else {
|
||||||
|
fValue = fValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//判断单位是V还是kV
|
||||||
|
else if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzUnitName().equalsIgnoreCase("KV")) {
|
||||||
|
//根据cfg内的变比,将一次值转换成二次值
|
||||||
|
if (comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary() != 0.0f) {
|
||||||
|
fValue = fValue * 1000.0f * comtradeCfgDTO.getLstAnalogDTO().get(j).getFSecondary() / comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary();
|
||||||
|
} else {
|
||||||
|
fValue = fValue;
|
||||||
|
}
|
||||||
|
} else //还有可能是 电流,单位是A
|
||||||
|
{
|
||||||
|
//根据cfg内的变比,将一次值转换成二次值
|
||||||
|
if (comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary() != 0.0f) {
|
||||||
|
fValue = fValue * comtradeCfgDTO.getLstAnalogDTO().get(j).getFSecondary() / comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary();
|
||||||
|
} else {
|
||||||
|
fValue = fValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//xValue前移量,假如是第一次时候则需要前移
|
||||||
|
if (!blxValue && j == 0) {
|
||||||
|
xValueAll = (float) (i * 20) / tmpRateDTO.getNOneSample() - comtradeCfgDTO.getNPush();
|
||||||
|
blxValue = true;
|
||||||
|
//只增加一个xValue的值 //增加时间值
|
||||||
|
tmpWaveData.add((float) (Math.round(xValueAll * 100)) / 100);
|
||||||
|
} else if (j == 0) {
|
||||||
|
xValueAll += (float) dfValue / nWaveSpan;
|
||||||
|
//只增加一个xValue的值 //增加时间值
|
||||||
|
tmpWaveData.add((float) (Math.round(xValueAll * 100)) / 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
//不同通道yValue的值都需要增加,最终成ABC三相 //每个通道的值
|
||||||
|
tmpWaveData.add((float) (Math.round(fValue * 100)) / 100);
|
||||||
|
}
|
||||||
|
//把每个单独的值赋予到整体里面去
|
||||||
|
listWaveData.add(tmpWaveData);
|
||||||
|
}
|
||||||
|
// 本周波处理完成后,推进到下一周波的原始采样点
|
||||||
|
if (iWaveTemp < (allWaveTemp - 1)) {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 某些文件的段点数并不是原始每周波点数的整倍数。
|
||||||
|
// RMS 段处理完成后,强制把原始游标对齐到当前段末尾,
|
||||||
|
// 这样外层 for 的下一次自增才能稳定落到下一段起点,避免重复进入同一 RMS 段。
|
||||||
|
i = segmentEndIndex;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算本段抽点采样间隔
|
||||||
|
nWaveSpan = tmpRateDTO.getNOneSample() / newLstRate.get(nIndex).getNOneSample();
|
||||||
|
// 判断是否到了需要抽的采样点
|
||||||
|
if (i % nWaveSpan == 0) {
|
||||||
|
// 计算每个通道的值
|
||||||
|
//存储局部数据集合,包含了时间,A,B,C三相
|
||||||
|
List<Float> tmpWaveData = new ArrayList<>();
|
||||||
|
for (int j = 0; j < comtradeCfgDTO.getNAnalogNum(); j++) {
|
||||||
|
//数据只有电压ABC三相数据,不展示U0、I0等数据 YXB2020-10-09 去除相别为N相的数据
|
||||||
|
if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzPhasicName().equalsIgnoreCase("N")) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
float fCoef = comtradeCfgDTO.getLstAnalogDTO().get(j).getFCoefficent();
|
||||||
|
fValue = BitConverter.byte2ToUnsignedShort(datArray, i * nBlockSize + 2 * 4 + j * 2) * fCoef;
|
||||||
|
|
||||||
|
//WW 2019-11-14
|
||||||
|
/**************************
|
||||||
|
* 1、接口返回的默认是二次值
|
||||||
|
* 2、P是一次值 S是二次值
|
||||||
|
* 3、S(二次值)情况下:
|
||||||
|
* ①、单位为"V"时候则直接等于;
|
||||||
|
* ②、单位为"kV"时候需要乘以1000
|
||||||
|
* 4、P(一次值)情况下:
|
||||||
|
* ①、单位为"V"时候则直接等于;
|
||||||
|
* ②、单位为"kV"时候需要乘以1000
|
||||||
|
**************************/
|
||||||
|
//P是一次值 S是二次值
|
||||||
|
if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzValueType().equalsIgnoreCase("S")) {
|
||||||
|
//判断单位是V还是kV
|
||||||
|
if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzUnitName().equalsIgnoreCase("KV")) {
|
||||||
|
fValue = fValue * 1000.0f;
|
||||||
|
} else {
|
||||||
|
fValue = fValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//P是一次值 S是二次值
|
||||||
|
else if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzValueType().equalsIgnoreCase("P")) {
|
||||||
|
//判断单位是V还是kV
|
||||||
|
if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzUnitName().equalsIgnoreCase("V")) {
|
||||||
|
//根据cfg内的变比,将一次值转换成二次值
|
||||||
|
if (comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary() != 0.0f) {
|
||||||
|
fValue = fValue * comtradeCfgDTO.getLstAnalogDTO().get(j).getFSecondary() / comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary();
|
||||||
|
} else {
|
||||||
|
fValue = fValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//判断单位是V还是kV
|
||||||
|
else if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzUnitName().equalsIgnoreCase("KV")) {
|
||||||
|
//根据cfg内的变比,将一次值转换成二次值
|
||||||
|
if (comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary() != 0.0f) {
|
||||||
|
fValue = fValue * 1000.0f * comtradeCfgDTO.getLstAnalogDTO().get(j).getFSecondary() / comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary();
|
||||||
|
} else {
|
||||||
|
fValue = fValue;
|
||||||
|
}
|
||||||
|
} else //还有可能是 电流,单位是A
|
||||||
|
{
|
||||||
|
//根据cfg内的变比,将一次值转换成二次值
|
||||||
|
if (comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary() != 0.0f) {
|
||||||
|
fValue = fValue * comtradeCfgDTO.getLstAnalogDTO().get(j).getFSecondary() / comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary();
|
||||||
|
} else {
|
||||||
|
fValue = fValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//xValue前移量,假如是第一次时候则需要前移
|
||||||
|
if (!blxValue && j == 0) {
|
||||||
|
xValueAll = (float) (i * 20) / tmpRateDTO.getNOneSample() - comtradeCfgDTO.getNPush();
|
||||||
|
blxValue = true;
|
||||||
|
//只增加一个xValue的值 //增加时间值
|
||||||
|
tmpWaveData.add((float) (Math.round(xValueAll * 100)) / 100);
|
||||||
|
} else if (j == 0) {
|
||||||
|
xValueAll += (float) nWaveSpan * dfValue;
|
||||||
|
//只增加一个xValue的值 //增加时间值
|
||||||
|
tmpWaveData.add((float) (Math.round(xValueAll * 100)) / 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
//不同通道yValue的值都需要增加,最终成ABC三相 //每个通道的值
|
||||||
|
tmpWaveData.add((float) (Math.round(fValue * 100)) / 100);
|
||||||
|
}
|
||||||
|
//把每个单独的值赋予到整体里面去
|
||||||
|
listWaveData.add(tmpWaveData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new BusinessException(WaveFileResponseEnum.DAT_DATA_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
return listWaveData;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<List<Float>> getComtradeDatNoAddPoints(ComtradeCfgDTO comtradeCfgDTO, InputStream datStream, int iType) {
|
||||||
|
//返回数据,如果仅仅做展示后期考虑换String类型,降低内存开销
|
||||||
|
List<List<Float>> listWaveData = new ArrayList<>();
|
||||||
|
//初始化xValue的值
|
||||||
|
float xValueAll = 0;
|
||||||
|
//判断是否首次登陆
|
||||||
|
boolean blxValue = false;
|
||||||
|
byte[] datArray;
|
||||||
|
try {
|
||||||
|
datArray = IoUtil.readBytes(datStream);
|
||||||
|
if (ArrayUtil.isEmpty(datArray)) {
|
||||||
|
throw new BusinessException(WaveFileResponseEnum.DAT_DATA_ERROR);
|
||||||
|
}
|
||||||
|
// 计算每个单独的数据块的大小 4个字节的序号 4个字节的时间 2个字节的值
|
||||||
|
// 示例中的排布是 4个字节的序号 4个字节的时间 UA(2字节) UB(2字节) UC(2字节) IA(2字节) IB(2字节) IC(2字节)
|
||||||
|
int nDigSize = (comtradeCfgDTO.getNDigitalNum() % 16) > 0 ? (comtradeCfgDTO.getNDigitalNum() / 16 + 1) * 2 : comtradeCfgDTO.getNDigitalNum() / 16 * 2;
|
||||||
|
int nBlockSize = 2 * Integer.SIZE / 8 + comtradeCfgDTO.getNAnalogNum() * 2 + nDigSize;
|
||||||
|
// 总长度除以每个块的大小
|
||||||
|
int nBlockNum = (int)Math.floor(datArray.length / nBlockSize);
|
||||||
|
|
||||||
|
// 获取采样率
|
||||||
|
int finalSampleRate = getFinalWaveSample(comtradeCfgDTO.getLstRate(), iType);
|
||||||
|
if (finalSampleRate != -1) {
|
||||||
|
//设置最终采样率
|
||||||
|
comtradeCfgDTO.setFinalSampleRate(finalSampleRate);
|
||||||
|
// 计算转换后的采样率
|
||||||
|
int nnInd = 0;
|
||||||
|
// 抽点后总共多少点数据
|
||||||
|
int nWaveNum;
|
||||||
|
//抽点后新的的采样率
|
||||||
|
List<RateDTO> newLstRate = new ArrayList<>();
|
||||||
|
for (int iRate = 0; iRate < comtradeCfgDTO.getNRates(); iRate++) {
|
||||||
|
if (comtradeCfgDTO.getLstRate().get(iRate).getNOneSample() >= 32) {
|
||||||
|
// 计算本段录波总共有多少波形
|
||||||
|
nWaveNum = comtradeCfgDTO.getLstRate().get(iRate).getNSampleNum() / comtradeCfgDTO.getLstRate().get(iRate).getNOneSample();
|
||||||
|
//设置总波形大小
|
||||||
|
comtradeCfgDTO.setNAllWaveNum(comtradeCfgDTO.getNAllWaveNum() + nWaveNum);
|
||||||
|
// 将最低采样率替换到本段录波内
|
||||||
|
RateDTO tmpRateDTO = new RateDTO();
|
||||||
|
// 有效值标志,如果是有效值,那么就需要反向补点,而不是抽点
|
||||||
|
// if (comtradeCfgDTO.getLstRate().get(iRate).getNOneSample() >= 32) {
|
||||||
|
// //YXB 2025-08-27
|
||||||
|
// tmpRateDTO.bRMSFlag = false;
|
||||||
|
// }
|
||||||
|
// //如果采样是全波有效值或者半波有效值,需要去补足周波点数 YXB 2025-08-27
|
||||||
|
// else if (comtradeCfgDTO.getLstRate().get(iRate).getNOneSample() <= 2) {
|
||||||
|
// //YXB 2025-08-27
|
||||||
|
// tmpRateDTO.bRMSFlag = true;
|
||||||
|
// }
|
||||||
|
newLstRate.add(tmpRateDTO);
|
||||||
|
//iFlag =3 一定不进行抽点算法
|
||||||
|
if (iType != 3) {
|
||||||
|
//true 抽点算法(当前采样率跟统一采样率不一样则是抽点,否则是未抽点)
|
||||||
|
if (!Objects.equals(comtradeCfgDTO.getLstRate().get(iRate).getNOneSample(), comtradeCfgDTO.getFinalSampleRate())) {
|
||||||
|
newLstRate.get(nnInd).setNOneSample(comtradeCfgDTO.getFinalSampleRate());
|
||||||
|
// 计算本段录波按照最低采样点应该有多少录波
|
||||||
|
newLstRate.get(nnInd).setNSampleNum(comtradeCfgDTO.getFinalSampleRate() * nWaveNum);
|
||||||
|
} else {
|
||||||
|
newLstRate.get(nnInd).setNOneSample(comtradeCfgDTO.getLstRate().get(iRate).getNOneSample());
|
||||||
|
// 计算本段录波按照最低采样点应该有多少录波
|
||||||
|
newLstRate.get(nnInd).setNSampleNum(comtradeCfgDTO.getLstRate().get(iRate).getNOneSample() * nWaveNum);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
newLstRate.get(nnInd).setNOneSample(comtradeCfgDTO.getLstRate().get(iRate).getNOneSample());
|
||||||
|
// 计算本段录波按照最低采样点应该有多少录波
|
||||||
|
newLstRate.get(nnInd).setNSampleNum(comtradeCfgDTO.getLstRate().get(iRate).getNOneSample() * nWaveNum);
|
||||||
|
}
|
||||||
|
|
||||||
// 正常的配置中采样率
|
// 正常的配置中采样率
|
||||||
/* comtradeCfgDTO.getLstRate().get(nnInd).setNOneSample(comtradeCfgDTO.getLstRate().get(iRate).getNOneSample());
|
comtradeCfgDTO.getLstRate().get(nnInd).setNOneSample(comtradeCfgDTO.getLstRate().get(iRate).getNOneSample());
|
||||||
comtradeCfgDTO.getLstRate().get(nnInd).setNSampleNum(comtradeCfgDTO.getLstRate().get(iRate).getNSampleNum());*/
|
comtradeCfgDTO.getLstRate().get(nnInd).setNSampleNum(comtradeCfgDTO.getLstRate().get(iRate).getNSampleNum());
|
||||||
|
|
||||||
nnInd++;
|
nnInd++;
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
// 偏移量,采样间隔
|
// 偏移量,采样间隔
|
||||||
long nOffSet = 0, nWaveSpan;
|
long nOffSet = 0, nWaveSpan;
|
||||||
@@ -574,15 +1023,16 @@ public class WaveFileComponent {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tmpRateDTO = comtradeCfgDTO.getLstRate().get(nIndex);
|
nWaveSpan = tmpRateDTO.getNOneSample() / newLstRate.get(nIndex).getNOneSample();
|
||||||
//YXB 2025-08-27 如果是有效值,那么需要去补点,而不是抽点
|
// tmpRateDTO = comtradeCfgDTO.getLstRate().get(nIndex);
|
||||||
if (newLstRate.get(nIndex).bRMSFlag == true) {
|
// //YXB 2025-08-27 如果是有效值,那么需要去补点,而不是抽点
|
||||||
//计算本段补点采样间隔
|
// if (newLstRate.get(nIndex).bRMSFlag == true) {
|
||||||
nWaveSpan = newLstRate.get(nIndex).getNOneSample() / tmpRateDTO.getNOneSample();
|
// //计算本段补点采样间隔
|
||||||
} else {
|
// nWaveSpan = newLstRate.get(nIndex).getNOneSample() / tmpRateDTO.getNOneSample();
|
||||||
// 计算本段抽点采样间隔
|
// } else {
|
||||||
nWaveSpan = tmpRateDTO.getNOneSample() / newLstRate.get(nIndex).getNOneSample();
|
// // 计算本段抽点采样间隔
|
||||||
}
|
// nWaveSpan = tmpRateDTO.getNOneSample() / newLstRate.get(nIndex).getNOneSample();
|
||||||
|
// }
|
||||||
|
|
||||||
dfValue = (float) 20 / tmpRateDTO.getNOneSample();
|
dfValue = (float) 20 / tmpRateDTO.getNOneSample();
|
||||||
// 判断是否到了需要抽的采样点
|
// 判断是否到了需要抽的采样点
|
||||||
@@ -590,183 +1040,87 @@ public class WaveFileComponent {
|
|||||||
// 计算每个通道的值
|
// 计算每个通道的值
|
||||||
//存储局部数据集合,包含了时间,A,B,C三相
|
//存储局部数据集合,包含了时间,A,B,C三相
|
||||||
List<Float> tmpWaveData = new ArrayList<>();
|
List<Float> tmpWaveData = new ArrayList<>();
|
||||||
//YXB 2025-08-27 如果是有效值,那么需要去补点,而不是抽点
|
for (int j = 0; j < comtradeCfgDTO.getNAnalogNum(); j++) {
|
||||||
if (newLstRate.get(nIndex).bRMSFlag == true) {
|
//数据只有电压ABC三相数据,不展示U0、I0等数据 YXB2020-10-09 去除相别为N相的数据
|
||||||
// 计算有多少个周波
|
if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzPhasicName().equalsIgnoreCase("N")) {
|
||||||
long allWaveTemp = newLstRate.get(nIndex).getNSampleNum() / newLstRate.get(nIndex).getNOneSample();
|
break;
|
||||||
// 本段需要补多少点
|
}
|
||||||
long allempSample = newLstRate.get(nIndex).getNOneSample();
|
|
||||||
//int iStartWaveTemp = i ;// 开始补点的起点
|
|
||||||
for (int iWaveTemp = 0; iWaveTemp < allWaveTemp; iWaveTemp++) {
|
|
||||||
for (int mTempSample = 0; mTempSample < allempSample; mTempSample++) {
|
|
||||||
//最多只有半波有效值,也就是每周波是1个或者2个点,然后去补最少16个点
|
|
||||||
if (mTempSample / nWaveSpan == 1 && mTempSample % nWaveSpan == 0) {
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
//存储局部数据集合,包含了时间,A,B,C三相
|
|
||||||
tmpWaveData = new ArrayList<>();
|
|
||||||
for (int j = 0; j < comtradeCfgDTO.getNAnalogNum(); j++) {
|
|
||||||
//数据只有电压ABC三相数据,不展示U0、I0等数据 YXB2020-10-09 去除相别为N相的数据
|
|
||||||
if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzPhasicName().equalsIgnoreCase("N")) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
float fCoef = comtradeCfgDTO.getLstAnalogDTO().get(j).getFCoefficent();
|
|
||||||
|
|
||||||
fValue = BitConverter.byte2ToUnsignedShort(datArray, i * nBlockSize + 2 * 4 + j * 2) * fCoef;
|
float fCoef = comtradeCfgDTO.getLstAnalogDTO().get(j).getFCoefficent();
|
||||||
//WW 2019-11-14
|
fValue = BitConverter.byte2ToUnsignedShort(datArray, i * nBlockSize + 2 * 4 + j * 2) * fCoef;
|
||||||
/*************************
|
|
||||||
* 1、接口返回的默认是二次值
|
|
||||||
* 2、P是一次值 S是二次值
|
|
||||||
* 3、S(二次值)情况下:
|
|
||||||
* ①、单位为"V"时候则直接等于;
|
|
||||||
* ②、单位为"kV"时候需要乘以1000
|
|
||||||
* 4、P(一次值)情况下:
|
|
||||||
* ①、单位为"V"时候则直接等于;
|
|
||||||
* ②、单位为"kV"时候需要乘以1000
|
|
||||||
*************************/
|
|
||||||
//P是一次值 S是二次值
|
|
||||||
if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzValueType().equalsIgnoreCase("S")) {
|
|
||||||
//判断单位是V还是kV
|
|
||||||
if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzUnitName().equalsIgnoreCase("KV")) {
|
|
||||||
fValue = fValue * 1000.0f;
|
|
||||||
} else {
|
|
||||||
fValue = fValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//P是一次值 S是二次值
|
|
||||||
else if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzValueType().equalsIgnoreCase("P")) {
|
|
||||||
//判断单位是V还是kV
|
|
||||||
if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzUnitName().equalsIgnoreCase("V")) {
|
|
||||||
//根据cfg内的变比,将一次值转换成二次值
|
|
||||||
if (comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary() != 0.0f) {
|
|
||||||
fValue = fValue * comtradeCfgDTO.getLstAnalogDTO().get(j).getFSecondary() / comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary();
|
|
||||||
} else {
|
|
||||||
fValue = fValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//判断单位是V还是kV
|
|
||||||
else if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzUnitName().equalsIgnoreCase("KV")) {
|
|
||||||
//根据cfg内的变比,将一次值转换成二次值
|
|
||||||
if (comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary() != 0.0f) {
|
|
||||||
fValue = fValue * 1000.0f * comtradeCfgDTO.getLstAnalogDTO().get(j).getFSecondary() / comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary();
|
|
||||||
} else {
|
|
||||||
fValue = fValue;
|
|
||||||
}
|
|
||||||
} else //还有可能是 电流,单位是A
|
|
||||||
{
|
|
||||||
//根据cfg内的变比,将一次值转换成二次值
|
|
||||||
if (comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary() != 0.0f) {
|
|
||||||
fValue = comtradeCfgDTO.getLstAnalogDTO().get(j).getFSecondary() / comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary();
|
|
||||||
} else {
|
|
||||||
fValue = fValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//xValue前移量,假如是第一次时候则需要前移
|
//WW 2019-11-14
|
||||||
if (!blxValue && j == 0) {
|
/**************************
|
||||||
xValueAll = (float) (i * 20) / tmpRateDTO.getNOneSample() - comtradeCfgDTO.getNPush();
|
* 1、接口返回的默认是二次值
|
||||||
blxValue = true;
|
* 2、P是一次值 S是二次值
|
||||||
//只增加一个xValue的值 //增加时间值
|
* 3、S(二次值)情况下:
|
||||||
tmpWaveData.add((float) (Math.round(xValueAll * 100)) / 100);
|
* ①、单位为"V"时候则直接等于;
|
||||||
} else if (j == 0) {
|
* ②、单位为"kV"时候需要乘以1000
|
||||||
xValueAll += (float) dfValue / nWaveSpan;
|
* 4、P(一次值)情况下:
|
||||||
//只增加一个xValue的值 //增加时间值
|
* ①、单位为"V"时候则直接等于;
|
||||||
tmpWaveData.add((float) (Math.round(xValueAll * 100)) / 100);
|
* ②、单位为"kV"时候需要乘以1000
|
||||||
}
|
**************************/
|
||||||
|
//P是一次值 S是二次值
|
||||||
//不同通道yValue的值都需要增加,最终成ABC三相 //每个通道的值
|
if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzValueType().equalsIgnoreCase("S")) {
|
||||||
tmpWaveData.add((float) (Math.round(fValue * 100)) / 100);
|
//判断单位是V还是kV
|
||||||
}
|
if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzUnitName().equalsIgnoreCase("KV")) {
|
||||||
//把每个单独的值赋予到整体里面去
|
fValue = fValue * 1000.0f;
|
||||||
listWaveData.add(tmpWaveData);
|
} else {
|
||||||
}
|
fValue = fValue;
|
||||||
// 把每个单独的值赋予到整体里面去
|
|
||||||
if (iWaveTemp < (allWaveTemp - 1)) {
|
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
//P是一次值 S是二次值
|
||||||
for (int j = 0; j < comtradeCfgDTO.getNAnalogNum(); j++) {
|
else if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzValueType().equalsIgnoreCase("P")) {
|
||||||
//数据只有电压ABC三相数据,不展示U0、I0等数据 YXB2020-10-09 去除相别为N相的数据
|
//判断单位是V还是kV
|
||||||
if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzPhasicName().equalsIgnoreCase("N")) {
|
if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzUnitName().equalsIgnoreCase("V")) {
|
||||||
break;
|
//根据cfg内的变比,将一次值转换成二次值
|
||||||
}
|
if (comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary() != 0.0f) {
|
||||||
|
fValue = fValue * comtradeCfgDTO.getLstAnalogDTO().get(j).getFSecondary() / comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary();
|
||||||
float fCoef = comtradeCfgDTO.getLstAnalogDTO().get(j).getFCoefficent();
|
|
||||||
fValue = BitConverter.byte2ToUnsignedShort(datArray, i * nBlockSize + 2 * 4 + j * 2) * fCoef;
|
|
||||||
|
|
||||||
//WW 2019-11-14
|
|
||||||
/**************************
|
|
||||||
* 1、接口返回的默认是二次值
|
|
||||||
* 2、P是一次值 S是二次值
|
|
||||||
* 3、S(二次值)情况下:
|
|
||||||
* ①、单位为"V"时候则直接等于;
|
|
||||||
* ②、单位为"kV"时候需要乘以1000
|
|
||||||
* 4、P(一次值)情况下:
|
|
||||||
* ①、单位为"V"时候则直接等于;
|
|
||||||
* ②、单位为"kV"时候需要乘以1000
|
|
||||||
**************************/
|
|
||||||
//P是一次值 S是二次值
|
|
||||||
if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzValueType().equalsIgnoreCase("S")) {
|
|
||||||
//判断单位是V还是kV
|
|
||||||
if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzUnitName().equalsIgnoreCase("KV")) {
|
|
||||||
fValue = fValue * 1000.0f;
|
|
||||||
} else {
|
} else {
|
||||||
fValue = fValue;
|
fValue = fValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//P是一次值 S是二次值
|
//判断单位是V还是kV
|
||||||
else if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzValueType().equalsIgnoreCase("P")) {
|
else if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzUnitName().equalsIgnoreCase("KV")) {
|
||||||
//判断单位是V还是kV
|
//根据cfg内的变比,将一次值转换成二次值
|
||||||
if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzUnitName().equalsIgnoreCase("V")) {
|
if (comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary() != 0.0f) {
|
||||||
//根据cfg内的变比,将一次值转换成二次值
|
fValue = fValue * 1000.0f * comtradeCfgDTO.getLstAnalogDTO().get(j).getFSecondary() / comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary();
|
||||||
if (comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary() != 0.0f) {
|
} else {
|
||||||
fValue = fValue * comtradeCfgDTO.getLstAnalogDTO().get(j).getFSecondary() / comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary();
|
fValue = fValue;
|
||||||
} else {
|
|
||||||
fValue = fValue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//判断单位是V还是kV
|
} else //还有可能是 电流,单位是A
|
||||||
else if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzUnitName().equalsIgnoreCase("KV")) {
|
{
|
||||||
//根据cfg内的变比,将一次值转换成二次值
|
//根据cfg内的变比,将一次值转换成二次值
|
||||||
if (comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary() != 0.0f) {
|
if (comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary() != 0.0f) {
|
||||||
fValue = fValue * 1000.0f * comtradeCfgDTO.getLstAnalogDTO().get(j).getFSecondary() / comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary();
|
fValue = fValue *comtradeCfgDTO.getLstAnalogDTO().get(j).getFSecondary() / comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary();
|
||||||
} else {
|
} else {
|
||||||
fValue = fValue;
|
fValue = fValue;
|
||||||
}
|
|
||||||
} else //还有可能是 电流,单位是A
|
|
||||||
{
|
|
||||||
//根据cfg内的变比,将一次值转换成二次值
|
|
||||||
if (comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary() != 0.0f) {
|
|
||||||
fValue = comtradeCfgDTO.getLstAnalogDTO().get(j).getFSecondary() / comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary();
|
|
||||||
} else {
|
|
||||||
fValue = fValue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//xValue前移量,假如是第一次时候则需要前移
|
|
||||||
if (!blxValue && j == 0) {
|
|
||||||
xValueAll = (float) (i * 20) / tmpRateDTO.getNOneSample() - comtradeCfgDTO.getNPush();
|
|
||||||
blxValue = true;
|
|
||||||
//只增加一个xValue的值 //增加时间值
|
|
||||||
tmpWaveData.add((float) (Math.round(xValueAll * 100)) / 100);
|
|
||||||
} else if (j == 0) {
|
|
||||||
xValueAll += (float) nWaveSpan * dfValue;
|
|
||||||
//只增加一个xValue的值 //增加时间值
|
|
||||||
tmpWaveData.add((float) (Math.round(xValueAll * 100)) / 100);
|
|
||||||
}
|
|
||||||
|
|
||||||
//不同通道yValue的值都需要增加,最终成ABC三相 //每个通道的值
|
|
||||||
tmpWaveData.add((float) (Math.round(fValue * 100)) / 100);
|
|
||||||
}
|
}
|
||||||
//把每个单独的值赋予到整体里面去
|
//xValue前移量,假如是第一次时候则需要前移
|
||||||
listWaveData.add(tmpWaveData);
|
if (!blxValue && j == 0) {
|
||||||
|
xValueAll = (float) (i * 20) / tmpRateDTO.getNOneSample() - comtradeCfgDTO.getNPush();
|
||||||
|
blxValue = true;
|
||||||
|
//只增加一个xValue的值 //增加时间值
|
||||||
|
tmpWaveData.add((float) (Math.round(xValueAll * 100)) / 100);
|
||||||
|
} else if (j == 0) {
|
||||||
|
xValueAll += (float) nWaveSpan * dfValue;
|
||||||
|
//只增加一个xValue的值 //增加时间值
|
||||||
|
tmpWaveData.add((float) (Math.round(xValueAll * 100)) / 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
//不同通道yValue的值都需要增加,最终成ABC三相 //每个通道的值
|
||||||
|
tmpWaveData.add((float) (Math.round(fValue * 100)) / 100);
|
||||||
}
|
}
|
||||||
|
//把每个单独的值赋予到整体里面去
|
||||||
|
listWaveData.add(tmpWaveData);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
throw new BusinessException(WaveFileResponseEnum.DAT_DATA_ERROR);
|
throw new BusinessException(WaveFileResponseEnum.DAT_DATA_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1366,10 +1720,10 @@ public class WaveFileComponent {
|
|||||||
s = sdf.format(d);
|
s = sdf.format(d);
|
||||||
System.out.println(s);
|
System.out.println(s);
|
||||||
WaveFileComponent waveFileComponent = new WaveFileComponent();
|
WaveFileComponent waveFileComponent = new WaveFileComponent();
|
||||||
InputStream cfgStream = waveFileComponent.getFileInputStreamByFilePath("F:\\PQ_PQLD3_9_20250821_081038_640.cfg");
|
InputStream cfgStream = waveFileComponent.getFileInputStreamByFilePath("C:\\Users\\无名\\Desktop\\月报\\2026\\202603\\文档\\暂态事件及波形\\新建文件夹 (3)\\Comtrade\\Comtrade\\10.95.0.201\\PQMonitor_PQM1_001183_20260320_175042_316.CFG");
|
||||||
InputStream datStream = waveFileComponent.getFileInputStreamByFilePath("F:\\PQ_PQLD3_9_20250821_081038_640.dat");
|
InputStream datStream = waveFileComponent.getFileInputStreamByFilePath("C:\\Users\\无名\\Desktop\\月报\\2026\\202603\\文档\\暂态事件及波形\\新建文件夹 (3)\\Comtrade\\Comtrade\\10.95.0.201\\PQMonitor_PQM1_001183_20260320_175042_316.DAT");
|
||||||
// 获取瞬时波形 //获取原始波形值
|
// 获取瞬时波形 //获取原始波形值
|
||||||
WaveDataDTO waveDataDTO = waveFileComponent.getComtrade(cfgStream, datStream, 1);
|
WaveDataDTO waveDataDTO = waveFileComponent.getComtradeNoAddPoints(cfgStream, datStream, 0);
|
||||||
d = new Date();
|
d = new Date();
|
||||||
s = sdf.format(d);
|
s = sdf.format(d);
|
||||||
System.out.println(s);
|
System.out.println(s);
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
package com.njcn.event.file.component;
|
package com.njcn.event.file.component;
|
||||||
|
|
||||||
import cn.hutool.core.img.ImgUtil;
|
import cn.hutool.core.img.ImgUtil;
|
||||||
import cn.hutool.core.io.IoUtil;
|
|
||||||
import cn.hutool.core.util.CharsetUtil;
|
|
||||||
import com.njcn.common.pojo.exception.BusinessException;
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
import com.njcn.common.utils.FileUtil;
|
import com.njcn.common.utils.FileUtil;
|
||||||
|
import com.njcn.echarts.json.LineGenerator;
|
||||||
import com.njcn.echarts.pojo.constant.PicCommonData;
|
import com.njcn.echarts.pojo.constant.PicCommonData;
|
||||||
import com.njcn.echarts.util.DrawPicUtil;
|
import com.njcn.echarts.util.DrawPicUtil;
|
||||||
import com.njcn.event.file.pojo.bo.WaveDataDetail;
|
import com.njcn.event.file.pojo.bo.WaveDataDetail;
|
||||||
@@ -12,21 +11,17 @@ import com.njcn.event.file.pojo.dto.WaveDataDTO;
|
|||||||
import com.njcn.event.file.pojo.enums.WaveFileResponseEnum;
|
import com.njcn.event.file.pojo.enums.WaveFileResponseEnum;
|
||||||
import com.njcn.oss.constant.OssPath;
|
import com.njcn.oss.constant.OssPath;
|
||||||
import com.njcn.oss.utils.FileStorageUtil;
|
import com.njcn.oss.utils.FileStorageUtil;
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import sun.awt.image.BufferedImageGraphicsConfig;
|
import sun.awt.image.BufferedImageGraphicsConfig;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.File;
|
import java.util.Base64;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author hongawen
|
* @author hongawen
|
||||||
@@ -49,36 +44,39 @@ public class WavePicComponent {
|
|||||||
* @date 2023/9/21 15:32
|
* @date 2023/9/21 15:32
|
||||||
* @return String 文件地址
|
* @return String 文件地址
|
||||||
*/
|
*/
|
||||||
public String generateInstantImageZl(List<WaveDataDetail> waveDataDetails) {
|
public String generateInstantImageZl(Integer nPush, List<WaveDataDetail> waveDataDetails, Double lastTime) {
|
||||||
String firstPic = null, secondPic = null, thirdPic = null, forthPic = null;
|
String firstPic = null, secondPic = null, thirdPic = null, forthPic = null;
|
||||||
|
WaveDataDetail waveDataDetail0 = waveDataDetails.get(0);
|
||||||
|
// 从instantData提取null边界x值,作为共享参考(与Shun图保持一致)
|
||||||
|
List<Float> sharedNullBoundaries = LineGenerator.extractNullBoundaryXValues(waveDataDetail0.getInstantData().getAValue());
|
||||||
for (WaveDataDetail waveDataDetail : waveDataDetails) {
|
for (WaveDataDetail waveDataDetail : waveDataDetails) {
|
||||||
if (waveDataDetail.getChannelName().toUpperCase().startsWith("SU")) {
|
if (waveDataDetail.getChannelName().toUpperCase().startsWith("SU")) {
|
||||||
firstPic = drawPicUtil.drawWavePic("电压-电网侧", waveDataDetail.getInstantData().getAValue(),
|
firstPic = drawPicUtil.drawWavePic("电压-电网侧", waveDataDetail.getInstantData().getAValue(),
|
||||||
waveDataDetail.getInstantData().getBValue(), waveDataDetail.getInstantData().getCValue(),
|
waveDataDetail.getInstantData().getBValue(), waveDataDetail.getInstantData().getCValue(),
|
||||||
waveDataDetail.getUnit(), waveDataDetail.getInstantData().getMax(), waveDataDetail.getInstantData().getMin(),
|
waveDataDetail.getUnit(), waveDataDetail.getInstantData().getMax(), waveDataDetail.getInstantData().getMin(),
|
||||||
waveDataDetail.getA(), waveDataDetail.getB(), waveDataDetail.getC(),
|
waveDataDetail.getA(), waveDataDetail.getB(), waveDataDetail.getC(),
|
||||||
waveDataDetail.getColors(), waveDataDetail.getIsOpen()
|
waveDataDetail.getColors(), waveDataDetail.getIsOpen(),lastTime,sharedNullBoundaries,nPush
|
||||||
);
|
);
|
||||||
} else if (waveDataDetail.getChannelName().toUpperCase().startsWith("SI")) {
|
} else if (waveDataDetail.getChannelName().toUpperCase().startsWith("SI")) {
|
||||||
thirdPic = drawPicUtil.drawWavePic("电流-电网侧", waveDataDetail.getInstantData().getAValue(),
|
thirdPic = drawPicUtil.drawWavePic("电流-电网侧", waveDataDetail.getInstantData().getAValue(),
|
||||||
waveDataDetail.getInstantData().getBValue(), waveDataDetail.getInstantData().getCValue(),
|
waveDataDetail.getInstantData().getBValue(), waveDataDetail.getInstantData().getCValue(),
|
||||||
waveDataDetail.getUnit(), waveDataDetail.getInstantData().getMax(), waveDataDetail.getInstantData().getMin(),
|
waveDataDetail.getUnit(), waveDataDetail.getInstantData().getMax(), waveDataDetail.getInstantData().getMin(),
|
||||||
waveDataDetail.getA(), waveDataDetail.getB(), waveDataDetail.getC(),
|
waveDataDetail.getA(), waveDataDetail.getB(), waveDataDetail.getC(),
|
||||||
waveDataDetail.getColors(), waveDataDetail.getIsOpen()
|
waveDataDetail.getColors(), waveDataDetail.getIsOpen(),lastTime,sharedNullBoundaries,nPush
|
||||||
);
|
);
|
||||||
} else if (waveDataDetail.getChannelName().toUpperCase().startsWith("LU")) {
|
} else if (waveDataDetail.getChannelName().toUpperCase().startsWith("LU")) {
|
||||||
secondPic = drawPicUtil.drawWavePic("电压-负载侧", waveDataDetail.getInstantData().getAValue(),
|
secondPic = drawPicUtil.drawWavePic("电压-负载侧", waveDataDetail.getInstantData().getAValue(),
|
||||||
waveDataDetail.getInstantData().getBValue(), waveDataDetail.getInstantData().getCValue(),
|
waveDataDetail.getInstantData().getBValue(), waveDataDetail.getInstantData().getCValue(),
|
||||||
waveDataDetail.getUnit(), waveDataDetail.getInstantData().getMax(), waveDataDetail.getInstantData().getMin(),
|
waveDataDetail.getUnit(), waveDataDetail.getInstantData().getMax(), waveDataDetail.getInstantData().getMin(),
|
||||||
waveDataDetail.getA(), waveDataDetail.getB(), waveDataDetail.getC(),
|
waveDataDetail.getA(), waveDataDetail.getB(), waveDataDetail.getC(),
|
||||||
waveDataDetail.getColors(), waveDataDetail.getIsOpen()
|
waveDataDetail.getColors(), waveDataDetail.getIsOpen(),lastTime,sharedNullBoundaries,nPush
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
forthPic = drawPicUtil.drawWavePic("电流-负载侧", waveDataDetail.getInstantData().getAValue(),
|
forthPic = drawPicUtil.drawWavePic("电流-负载侧", waveDataDetail.getInstantData().getAValue(),
|
||||||
waveDataDetail.getInstantData().getBValue(), waveDataDetail.getInstantData().getCValue(),
|
waveDataDetail.getInstantData().getBValue(), waveDataDetail.getInstantData().getCValue(),
|
||||||
waveDataDetail.getUnit(), waveDataDetail.getInstantData().getMax(), waveDataDetail.getInstantData().getMin(),
|
waveDataDetail.getUnit(), waveDataDetail.getInstantData().getMax(), waveDataDetail.getInstantData().getMin(),
|
||||||
waveDataDetail.getA(), waveDataDetail.getB(), waveDataDetail.getC(),
|
waveDataDetail.getA(), waveDataDetail.getB(), waveDataDetail.getC(),
|
||||||
waveDataDetail.getColors(), waveDataDetail.getIsOpen()
|
waveDataDetail.getColors(), waveDataDetail.getIsOpen(),lastTime,sharedNullBoundaries,nPush
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -91,36 +89,39 @@ public class WavePicComponent {
|
|||||||
* @date 2023/9/21 15:32
|
* @date 2023/9/21 15:32
|
||||||
* @return String 文件地址
|
* @return String 文件地址
|
||||||
*/
|
*/
|
||||||
public String generateRmsImageZl(List<WaveDataDetail> waveDataDetails) {
|
public String generateRmsImageZl(Integer nPush, List<WaveDataDetail> waveDataDetails, Double lastTime) {
|
||||||
String firstPic = null, secondPic = null, thirdPic = null, forthPic = null;
|
String firstPic = null, secondPic = null, thirdPic = null, forthPic = null;
|
||||||
|
WaveDataDetail waveDataDetail0 = waveDataDetails.get(0);
|
||||||
|
// 从instantData提取null边界x值,作为共享参考(与Shun图保持一致)
|
||||||
|
List<Float> sharedNullBoundaries = LineGenerator.extractNullBoundaryXValues(waveDataDetail0.getInstantData().getAValue());
|
||||||
for (WaveDataDetail waveDataDetail : waveDataDetails) {
|
for (WaveDataDetail waveDataDetail : waveDataDetails) {
|
||||||
if (waveDataDetail.getChannelName().toUpperCase().startsWith("SU")) {
|
if (waveDataDetail.getChannelName().toUpperCase().startsWith("SU")) {
|
||||||
firstPic = drawPicUtil.drawWavePic("电压-电网侧", waveDataDetail.getRmsData().getAValue(),
|
firstPic = drawPicUtil.drawWavePic("电压-电网侧", waveDataDetail.getRmsData().getAValue(),
|
||||||
waveDataDetail.getRmsData().getBValue(), waveDataDetail.getRmsData().getCValue(),
|
waveDataDetail.getRmsData().getBValue(), waveDataDetail.getRmsData().getCValue(),
|
||||||
waveDataDetail.getUnit(), waveDataDetail.getRmsData().getMax(), waveDataDetail.getRmsData().getMin(),
|
waveDataDetail.getUnit(), waveDataDetail.getRmsData().getMax(), waveDataDetail.getRmsData().getMin(),
|
||||||
waveDataDetail.getA(), waveDataDetail.getB(), waveDataDetail.getC(),
|
waveDataDetail.getA(), waveDataDetail.getB(), waveDataDetail.getC(),
|
||||||
waveDataDetail.getColors(), waveDataDetail.getIsOpen()
|
waveDataDetail.getColors(), waveDataDetail.getIsOpen(),lastTime,sharedNullBoundaries,nPush
|
||||||
);
|
);
|
||||||
} else if (waveDataDetail.getChannelName().toUpperCase().startsWith("SI")) {
|
} else if (waveDataDetail.getChannelName().toUpperCase().startsWith("SI")) {
|
||||||
thirdPic = drawPicUtil.drawWavePic("电流-电网侧", waveDataDetail.getRmsData().getAValue(),
|
thirdPic = drawPicUtil.drawWavePic("电流-电网侧", waveDataDetail.getRmsData().getAValue(),
|
||||||
waveDataDetail.getRmsData().getBValue(), waveDataDetail.getRmsData().getCValue(),
|
waveDataDetail.getRmsData().getBValue(), waveDataDetail.getRmsData().getCValue(),
|
||||||
waveDataDetail.getUnit(), waveDataDetail.getRmsData().getMax(), waveDataDetail.getRmsData().getMin(),
|
waveDataDetail.getUnit(), waveDataDetail.getRmsData().getMax(), waveDataDetail.getRmsData().getMin(),
|
||||||
waveDataDetail.getA(), waveDataDetail.getB(), waveDataDetail.getC(),
|
waveDataDetail.getA(), waveDataDetail.getB(), waveDataDetail.getC(),
|
||||||
waveDataDetail.getColors(), waveDataDetail.getIsOpen()
|
waveDataDetail.getColors(), waveDataDetail.getIsOpen(),lastTime,sharedNullBoundaries,nPush
|
||||||
);
|
);
|
||||||
} else if (waveDataDetail.getChannelName().toUpperCase().startsWith("LU")) {
|
} else if (waveDataDetail.getChannelName().toUpperCase().startsWith("LU")) {
|
||||||
secondPic = drawPicUtil.drawWavePic("电压-负载侧", waveDataDetail.getRmsData().getAValue(),
|
secondPic = drawPicUtil.drawWavePic("电压-负载侧", waveDataDetail.getRmsData().getAValue(),
|
||||||
waveDataDetail.getRmsData().getBValue(), waveDataDetail.getRmsData().getCValue(),
|
waveDataDetail.getRmsData().getBValue(), waveDataDetail.getRmsData().getCValue(),
|
||||||
waveDataDetail.getUnit(), waveDataDetail.getRmsData().getMax(), waveDataDetail.getRmsData().getMin(),
|
waveDataDetail.getUnit(), waveDataDetail.getRmsData().getMax(), waveDataDetail.getRmsData().getMin(),
|
||||||
waveDataDetail.getA(), waveDataDetail.getB(), waveDataDetail.getC(),
|
waveDataDetail.getA(), waveDataDetail.getB(), waveDataDetail.getC(),
|
||||||
waveDataDetail.getColors(), waveDataDetail.getIsOpen()
|
waveDataDetail.getColors(), waveDataDetail.getIsOpen(),lastTime,sharedNullBoundaries,nPush
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
forthPic = drawPicUtil.drawWavePic("电流-负载侧", waveDataDetail.getRmsData().getAValue(),
|
forthPic = drawPicUtil.drawWavePic("电流-负载侧", waveDataDetail.getRmsData().getAValue(),
|
||||||
waveDataDetail.getRmsData().getBValue(), waveDataDetail.getRmsData().getCValue(),
|
waveDataDetail.getRmsData().getBValue(), waveDataDetail.getRmsData().getCValue(),
|
||||||
waveDataDetail.getUnit(), waveDataDetail.getRmsData().getMax(), waveDataDetail.getRmsData().getMin(),
|
waveDataDetail.getUnit(), waveDataDetail.getRmsData().getMax(), waveDataDetail.getRmsData().getMin(),
|
||||||
waveDataDetail.getA(), waveDataDetail.getB(), waveDataDetail.getC(),
|
waveDataDetail.getA(), waveDataDetail.getB(), waveDataDetail.getC(),
|
||||||
waveDataDetail.getColors(), waveDataDetail.getIsOpen()
|
waveDataDetail.getColors(), waveDataDetail.getIsOpen(),lastTime,sharedNullBoundaries,nPush
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -209,6 +210,47 @@ public class WavePicComponent {
|
|||||||
return picPath;
|
return picPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* 绘制瞬时波形图 App端用来绘制图片,会去掉部分数据,只保留开始数据 结束数据
|
||||||
|
* @author xy
|
||||||
|
* @return String 文件地址
|
||||||
|
*/
|
||||||
|
public String generateImageShun(Integer nPush, List<WaveDataDetail> waveDataDetails, Double lastTime) {
|
||||||
|
String picPath = null;
|
||||||
|
WaveDataDetail waveDataDetail = waveDataDetails.get(0);
|
||||||
|
// 从instantData提取null边界x值,作为共享参考
|
||||||
|
List<Float> sharedNullBoundaries = LineGenerator.extractNullBoundaryXValues(waveDataDetail.getInstantData().getAValue());
|
||||||
|
|
||||||
|
String firstPic = drawPicUtil.drawWavePic(getTitle(waveDataDetail.getChannelName()), waveDataDetail.getInstantData().getAValue(),
|
||||||
|
waveDataDetail.getInstantData().getBValue(), waveDataDetail.getInstantData().getCValue(),
|
||||||
|
waveDataDetail.getUnit(), waveDataDetail.getInstantData().getMax(), waveDataDetail.getInstantData().getMin(),
|
||||||
|
waveDataDetail.getA(), waveDataDetail.getB(), waveDataDetail.getC(),
|
||||||
|
waveDataDetail.getColors(), waveDataDetail.getIsOpen(), lastTime, sharedNullBoundaries,nPush
|
||||||
|
);
|
||||||
|
String secondPic;
|
||||||
|
if (waveDataDetails.size() == 1) {
|
||||||
|
if (firstPic.contains(PicCommonData.PNG_PREFIX)) {
|
||||||
|
firstPic = firstPic.replace(PicCommonData.PNG_PREFIX, "");
|
||||||
|
}
|
||||||
|
byte[] bytes = Base64.getDecoder().decode(firstPic);
|
||||||
|
picPath = fileStorageUtil.uploadStream(new ByteArrayInputStream(bytes), OssPath.EVENT_WAVE_PIC, FileUtil.generateFileName("png"));
|
||||||
|
} else if (waveDataDetails.size() == 2) {
|
||||||
|
waveDataDetail = waveDataDetails.get(1);
|
||||||
|
secondPic = drawPicUtil.drawWavePic(getTitle(waveDataDetail.getChannelName()), waveDataDetail.getInstantData().getAValue(),
|
||||||
|
waveDataDetail.getInstantData().getBValue(), waveDataDetail.getInstantData().getCValue(),
|
||||||
|
waveDataDetail.getUnit(), waveDataDetail.getInstantData().getMax(), waveDataDetail.getInstantData().getMin(),
|
||||||
|
waveDataDetail.getA(), waveDataDetail.getB(), waveDataDetail.getC(),
|
||||||
|
waveDataDetail.getColors(), waveDataDetail.getIsOpen(), lastTime, sharedNullBoundaries,nPush
|
||||||
|
);
|
||||||
|
picPath = composeImage(firstPic, secondPic);
|
||||||
|
}
|
||||||
|
return picPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle(String channelName) {
|
||||||
|
return channelName.toUpperCase().startsWith("U1") ? "电压" : "电流";
|
||||||
|
}
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* 绘制RMS波形图
|
* 绘制RMS波形图
|
||||||
* @author hongawen
|
* @author hongawen
|
||||||
@@ -248,6 +290,44 @@ public class WavePicComponent {
|
|||||||
return picPath;
|
return picPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* 绘制RMS波形图 App端用来绘制图片,会去掉部分数据,只保留开始数据 结束数据
|
||||||
|
* @author xy
|
||||||
|
* @return String 文件地址
|
||||||
|
*/
|
||||||
|
public String generateImageRms(Integer nPush, List<WaveDataDetail> waveDataDetails, Double lastTime) {
|
||||||
|
String picPath = null;
|
||||||
|
WaveDataDetail waveDataDetail = waveDataDetails.get(0);
|
||||||
|
|
||||||
|
// 从instantData提取null边界x值,作为共享参考(与Shun图保持一致)
|
||||||
|
List<Float> sharedNullBoundaries = LineGenerator.extractNullBoundaryXValues(waveDataDetail.getInstantData().getAValue());
|
||||||
|
|
||||||
|
String firstPic = drawPicUtil.drawWavePic(getTitle(waveDataDetail.getChannelName()), waveDataDetail.getRmsData().getAValue(),
|
||||||
|
waveDataDetail.getRmsData().getBValue(), waveDataDetail.getRmsData().getCValue(),
|
||||||
|
waveDataDetail.getUnit(), waveDataDetail.getRmsData().getMax(), waveDataDetail.getRmsData().getMin(),
|
||||||
|
waveDataDetail.getA(), waveDataDetail.getB(), waveDataDetail.getC(),
|
||||||
|
waveDataDetail.getColors(), waveDataDetail.getIsOpen(), lastTime, sharedNullBoundaries,nPush
|
||||||
|
);
|
||||||
|
String secondPic;
|
||||||
|
if (waveDataDetails.size() == 1) {
|
||||||
|
if (firstPic.contains(PicCommonData.PNG_PREFIX)) {
|
||||||
|
firstPic = firstPic.replace(PicCommonData.PNG_PREFIX, "");
|
||||||
|
}
|
||||||
|
byte[] bytes = Base64.getDecoder().decode(firstPic);
|
||||||
|
picPath = fileStorageUtil.uploadStream(new ByteArrayInputStream(bytes), OssPath.EVENT_WAVE_PIC, FileUtil.generateFileName("png"));
|
||||||
|
} else if (waveDataDetails.size() == 2) {
|
||||||
|
waveDataDetail = waveDataDetails.get(1);
|
||||||
|
secondPic = drawPicUtil.drawWavePic(getTitle(waveDataDetail.getChannelName()), waveDataDetail.getRmsData().getAValue(),
|
||||||
|
waveDataDetail.getRmsData().getBValue(), waveDataDetail.getRmsData().getCValue(),
|
||||||
|
waveDataDetail.getUnit(), waveDataDetail.getRmsData().getMax(), waveDataDetail.getRmsData().getMin(),
|
||||||
|
waveDataDetail.getA(), waveDataDetail.getB(), waveDataDetail.getC(),
|
||||||
|
waveDataDetail.getColors(), waveDataDetail.getIsOpen(), lastTime, sharedNullBoundaries,nPush
|
||||||
|
);
|
||||||
|
picPath = composeImage(firstPic, secondPic);
|
||||||
|
}
|
||||||
|
return picPath;
|
||||||
|
}
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* 合成图片
|
* 合成图片
|
||||||
* @author hongawen
|
* @author hongawen
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import com.njcn.event.file.pojo.dto.WaveDataDTO;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author hongawen
|
* @author hongawen
|
||||||
@@ -80,28 +81,49 @@ public class WaveUtil {
|
|||||||
//根据相别来确认标题的名称
|
//根据相别来确认标题的名称
|
||||||
for (int m = 0; m < iPhase; m++) {
|
for (int m = 0; m < iPhase; m++) {
|
||||||
if (waveTitle.get(iPhase * i + m + 1).substring(1).contains("A")) {
|
if (waveTitle.get(iPhase * i + m + 1).substring(1).contains("A")) {
|
||||||
float tmpShunFirstA = sunData.get(j).get(iPhase * i + m + 1) * xishu;
|
if (Objects.isNull(sunData.get(j).get(iPhase * i + m + 1))) {
|
||||||
shunFirstA = tmpShunFirstA;
|
sAValue.add(new ArrayList<Float>() {{
|
||||||
sAValue.add(new ArrayList<Float>() {{
|
add(x);
|
||||||
add(x);
|
add(null);
|
||||||
add(tmpShunFirstA);
|
}});
|
||||||
}});
|
} else {
|
||||||
|
float tmpShunFirstA = sunData.get(j).get(iPhase * i + m + 1) * xishu;
|
||||||
|
shunFirstA = tmpShunFirstA;
|
||||||
|
sAValue.add(new ArrayList<Float>() {{
|
||||||
|
add(x);
|
||||||
|
add(tmpShunFirstA);
|
||||||
|
}});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (waveTitle.get(iPhase * i + m + 1).substring(1).contains("B")) {
|
if (waveTitle.get(iPhase * i + m + 1).substring(1).contains("B")) {
|
||||||
float tmpShunFirstB = sunData.get(j).get(iPhase * i + m + 1) * xishu;
|
if (Objects.isNull(sunData.get(j).get(iPhase * i + m + 1))) {
|
||||||
shunFirstB = tmpShunFirstB;
|
sBValue.add(new ArrayList<Float>() {{
|
||||||
sBValue.add(new ArrayList<Float>() {{
|
add(x);
|
||||||
add(x);
|
add(null);
|
||||||
add(tmpShunFirstB);
|
}});
|
||||||
}});
|
} else {
|
||||||
|
float tmpShunFirstB = sunData.get(j).get(iPhase * i + m + 1) * xishu;
|
||||||
|
shunFirstB = tmpShunFirstB;
|
||||||
|
sBValue.add(new ArrayList<Float>() {{
|
||||||
|
add(x);
|
||||||
|
add(tmpShunFirstB);
|
||||||
|
}});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (waveTitle.get(iPhase * i + m + 1).substring(1).contains("C")) {
|
if (waveTitle.get(iPhase * i + m + 1).substring(1).contains("C")) {
|
||||||
float tmpShunFirstC = sunData.get(j).get(iPhase * i + m + 1) * xishu;
|
if (Objects.isNull(sunData.get(j).get(iPhase * i + m + 1))) {
|
||||||
shunFirstC = tmpShunFirstC;
|
sCValue.add(new ArrayList<Float>() {{
|
||||||
sCValue.add(new ArrayList<Float>() {{
|
add(x);
|
||||||
add(x);
|
add(null);
|
||||||
add(tmpShunFirstC);
|
}});
|
||||||
}});
|
} else {
|
||||||
|
float tmpShunFirstC = sunData.get(j).get(iPhase * i + m + 1) * xishu;
|
||||||
|
shunFirstC = tmpShunFirstC;
|
||||||
|
sCValue.add(new ArrayList<Float>() {{
|
||||||
|
add(x);
|
||||||
|
add(tmpShunFirstC);
|
||||||
|
}});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sfMax = getMax(sfMax, shunFirstA, shunFirstB, shunFirstC);
|
sfMax = getMax(sfMax, shunFirstA, shunFirstB, shunFirstC);
|
||||||
@@ -124,28 +146,50 @@ public class WaveUtil {
|
|||||||
//根据相别来确认标题的名称
|
//根据相别来确认标题的名称
|
||||||
for (int m = 0; m < iPhase; m++) {
|
for (int m = 0; m < iPhase; m++) {
|
||||||
if (waveTitle.get(iPhase * i + m + 1).substring(1).contains("A")) {
|
if (waveTitle.get(iPhase * i + m + 1).substring(1).contains("A")) {
|
||||||
float tmpRmsFirstA = rmsData.get(k).get(iPhase * i + m + 1) * xishu;
|
if (Objects.isNull(rmsData.get(k).get(iPhase * i + m + 1))) {
|
||||||
rmsFirstA = tmpRmsFirstA;
|
rAValue.add(new ArrayList<Float>() {{
|
||||||
rAValue.add(new ArrayList<Float>() {{
|
add(x);
|
||||||
add(x);
|
add(null);
|
||||||
add(tmpRmsFirstA);
|
}});
|
||||||
}});
|
} else {
|
||||||
|
float tmpRmsFirstA = rmsData.get(k).get(iPhase * i + m + 1) * xishu;
|
||||||
|
rmsFirstA = tmpRmsFirstA;
|
||||||
|
rAValue.add(new ArrayList<Float>() {{
|
||||||
|
add(x);
|
||||||
|
add(tmpRmsFirstA);
|
||||||
|
}});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (waveTitle.get(iPhase * i + m + 1).substring(1).contains("B")) {
|
if (waveTitle.get(iPhase * i + m + 1).substring(1).contains("B")) {
|
||||||
float tmpRmsFirstB = rmsData.get(k).get(iPhase * i + m + 1) * xishu;
|
if (Objects.isNull(rmsData.get(k).get(iPhase * i + m + 1))) {
|
||||||
rmsFirstB = tmpRmsFirstB;
|
rBValue.add(new ArrayList<Float>() {{
|
||||||
rBValue.add(new ArrayList<Float>() {{
|
add(x);
|
||||||
add(x);
|
add(null);
|
||||||
add(tmpRmsFirstB);
|
}});
|
||||||
}});
|
} else {
|
||||||
|
float tmpRmsFirstB = rmsData.get(k).get(iPhase * i + m + 1) * xishu;
|
||||||
|
rmsFirstB = tmpRmsFirstB;
|
||||||
|
rBValue.add(new ArrayList<Float>() {{
|
||||||
|
add(x);
|
||||||
|
add(tmpRmsFirstB);
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (waveTitle.get(iPhase * i + m + 1).substring(1).contains("C")) {
|
if (waveTitle.get(iPhase * i + m + 1).substring(1).contains("C")) {
|
||||||
float tmpRmsFirstC = rmsData.get(k).get(iPhase * i + m + 1) * xishu;
|
if (Objects.isNull(rmsData.get(k).get(iPhase * i + m + 1))) {
|
||||||
rmsFirstC = tmpRmsFirstC;
|
rCValue.add(new ArrayList<Float>() {{
|
||||||
rCValue.add(new ArrayList<Float>() {{
|
add(x);
|
||||||
add(x);
|
add(null);
|
||||||
add(tmpRmsFirstC);
|
}});
|
||||||
}});
|
} else {
|
||||||
|
float tmpRmsFirstC = rmsData.get(k).get(iPhase * i + m + 1) * xishu;
|
||||||
|
rmsFirstC = tmpRmsFirstC;
|
||||||
|
rCValue.add(new ArrayList<Float>() {{
|
||||||
|
add(x);
|
||||||
|
add(tmpRmsFirstC);
|
||||||
|
}});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rfMax = getMax(sfMax, rmsFirstA, rmsFirstB, rmsFirstC);
|
rfMax = getMax(sfMax, rmsFirstA, rmsFirstB, rmsFirstC);
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.njcn.microservice.listener;
|
package com.njcn.microservice.listener;
|
||||||
|
|
||||||
|
import ch.qos.logback.classic.Level;
|
||||||
|
import ch.qos.logback.classic.Logger;
|
||||||
import ch.qos.logback.classic.LoggerContext;
|
import ch.qos.logback.classic.LoggerContext;
|
||||||
import ch.qos.logback.classic.joran.JoranConfigurator;
|
import ch.qos.logback.classic.joran.JoranConfigurator;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -34,33 +36,46 @@ public class NacosLogbackConfigLoader implements SpringApplicationRunListener, A
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void environmentPrepared(ConfigurableEnvironment environment) {
|
public void environmentPrepared(ConfigurableEnvironment environment) {
|
||||||
// String serverAddr = environment.getProperty("spring.cloud.nacos.config.server-addr");
|
String active = environment.getProperty("spring.profiles.active");
|
||||||
// String namespace = environment.getProperty("spring.cloud.nacos.config.namespace");
|
if(!"jb".equalsIgnoreCase(active)){
|
||||||
// String projectName = environment.getProperty("microservice.ename");
|
String serverAddr = environment.getProperty("spring.cloud.nacos.config.server-addr");
|
||||||
// String logLevel = environment.getProperty("logging.level.root");
|
String namespace = environment.getProperty("spring.cloud.nacos.config.namespace");
|
||||||
// String url = String.format("http://%s/nacos/v1/cs/configs?tenant=%s&group=DEFAULT_GROUP&dataId=logback.xml", serverAddr, namespace);
|
String projectName = environment.getProperty("microservice.ename");
|
||||||
// HttpHeaders headers = new HttpHeaders();
|
String logLevel = environment.getProperty("logging.level.root");
|
||||||
// headers.set("cndl408125hawen", "lanxia201");
|
String url = String.format("http://%s/nacos/v1/cs/configs?tenant=%s&group=DEFAULT_GROUP&dataId=logback.xml", serverAddr, namespace);
|
||||||
// HttpEntity<String> entity = new HttpEntity<>(headers);
|
HttpHeaders headers = new HttpHeaders();
|
||||||
// RestTemplate restTemplate = new RestTemplate();
|
headers.set("cndl408125hawen", "lanxia201");
|
||||||
// ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
|
HttpEntity<String> entity = new HttpEntity<>(headers);
|
||||||
// if (response.getStatusCode().is2xxSuccessful()) {
|
RestTemplate restTemplate = new RestTemplate();
|
||||||
// String logbackConfigContent = response.getBody();
|
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
|
||||||
// //替换项目名称
|
if (response.getStatusCode().is2xxSuccessful()) {
|
||||||
// logbackConfigContent = logbackConfigContent.replace("projectDefaultName",projectName);
|
String logbackConfigContent = response.getBody();
|
||||||
// logbackConfigContent = logbackConfigContent.replace("logDefaultLevel",logLevel);
|
//替换项目名称
|
||||||
// // 应用获取到的Logback配置
|
logbackConfigContent = logbackConfigContent.replace("projectDefaultName",projectName);
|
||||||
// applyLogbackConfig(logbackConfigContent);
|
logbackConfigContent = logbackConfigContent.replace("logDefaultLevel",logLevel);
|
||||||
// }
|
// 应用获取到的Logback配置
|
||||||
|
applyLogbackConfig(logbackConfigContent,logLevel);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyLogbackConfig(String logbackConfigContent) {
|
private void applyLogbackConfig(String logbackConfigContent,String logLevel) {
|
||||||
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
|
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
|
||||||
JoranConfigurator configurator = new JoranConfigurator();
|
JoranConfigurator configurator = new JoranConfigurator();
|
||||||
configurator.setContext(context);
|
configurator.setContext(context);
|
||||||
context.reset();
|
context.reset();
|
||||||
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(logbackConfigContent.getBytes(StandardCharsets.UTF_8))) {
|
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(logbackConfigContent.getBytes(StandardCharsets.UTF_8))) {
|
||||||
configurator.doConfigure(inputStream);
|
configurator.doConfigure(inputStream);
|
||||||
|
Logger root = context.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
|
||||||
|
if("debug".equalsIgnoreCase(logLevel)){
|
||||||
|
root.setLevel(Level.DEBUG);
|
||||||
|
}
|
||||||
|
if("info".equalsIgnoreCase(logLevel)){
|
||||||
|
root.setLevel(Level.INFO);
|
||||||
|
}
|
||||||
|
if("error".equalsIgnoreCase(logLevel)){
|
||||||
|
root.setLevel(Level.ERROR);
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,12 +30,86 @@ public interface BusinessTopic {
|
|||||||
|
|
||||||
String NJCN_APP_FILE_STREAM_TOPIC = "njcnAppFileStreamTopic";
|
String NJCN_APP_FILE_STREAM_TOPIC = "njcnAppFileStreamTopic";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 云前置主题
|
||||||
|
*/
|
||||||
|
String CLD_ASK_REAL_DATA_TOPIC = "ask_real_data_Topic";
|
||||||
|
|
||||||
|
String CLD_HANDLE_REAL_DATA_TOPIC = "Real_Time_Data_Topic";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 云前置心跳主题
|
||||||
|
*/
|
||||||
|
String HEART_BEAT_TOPIC = "Heart_Beat_Topic";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 云前置状态反转主题
|
||||||
|
*/
|
||||||
|
String DEVICE_RUN_FLAG_TOPIC = "Device_Run_Flag_Topic";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 云前置日志主题
|
||||||
|
*/
|
||||||
|
String LOG_TOPIC = "log_Topic";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 台账更新下发
|
||||||
|
*/
|
||||||
|
String CONTROL_TOPIC = "control_Topic";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 台账更新前置端响应
|
||||||
|
*/
|
||||||
|
String REPLY_TOPIC = "Reply_Topic";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 前置进程控制
|
||||||
|
*/
|
||||||
|
String PROCESS_TOPIC = "process_Topic";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 补召下发命令
|
||||||
|
*/
|
||||||
|
String ASK_RECALL_TOPIC = "ask_recall_Topic";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 补召应答命令
|
||||||
|
*/
|
||||||
|
String REPLY_RECALL_TOPIC = "reply_recall_Topic";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 治理心跳过期处理主题
|
||||||
|
*/
|
||||||
|
String HEARTBEAT_TIMEOUT_TOPIC = "heartbeat_timeout_topic";
|
||||||
|
|
||||||
|
|
||||||
/********************************数据中心*********************************/
|
/********************************数据中心*********************************/
|
||||||
|
|
||||||
String RMP_EVENT_DETAIL_TOPIC = "rmpEventDetailTopic";
|
String RMP_EVENT_DETAIL_TOPIC = "rmpEventDetailTopic";
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * 云前置文件信息请求主题
|
||||||
|
// */
|
||||||
|
// String FILE_INFO_REQUEST_TOPIC = "fileInfoRequestTopic";
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 云前置文件信息响应主题
|
||||||
|
// */
|
||||||
|
// String FILE_INFO_RESPONSE_TOPIC = "fileInfoResponseTopic";
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 云前置文件下载请求主题
|
||||||
|
// */
|
||||||
|
// String FILE_DOWNLOAD_REQUEST_TOPIC = "fileDownloadRequestTopic";
|
||||||
|
// /**
|
||||||
|
// * 云前置文件下载响应主题
|
||||||
|
// */
|
||||||
|
// String FILE_DOWNLOAD_RESPONSE_TOPIC = "fileDownloadResponseTopic";
|
||||||
|
|
||||||
|
String CLOUD_TOPIC = "Cloud_Topic";
|
||||||
|
|
||||||
|
String CLOUD_REPLY_TOPIC = "Cloud_Reply_Topic";
|
||||||
|
|
||||||
|
|
||||||
interface AppDataTag {
|
interface AppDataTag {
|
||||||
|
|
||||||
@@ -79,5 +153,17 @@ public interface BusinessTopic {
|
|||||||
String STREAM_TAG = "streamInfo";
|
String STREAM_TAG = "streamInfo";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface HeartTag {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* apf 心跳
|
||||||
|
*/
|
||||||
|
String APF_TAG = "apf";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cld 心跳
|
||||||
|
*/
|
||||||
|
String CLD_TAG = "cld";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,14 +28,14 @@ public class AppFileMessage extends BaseMessage {
|
|||||||
|
|
||||||
private Integer code;
|
private Integer code;
|
||||||
|
|
||||||
private AppFileMessage.Msg msg;
|
private Msg msg;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public static class Msg{
|
public static class Msg{
|
||||||
|
|
||||||
private String type;
|
private String type;
|
||||||
|
|
||||||
private AppFileMessage.FileInfo fileInfo;
|
private FileInfo fileInfo;
|
||||||
|
|
||||||
private String data;
|
private String data;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package com.njcn.mq.message;
|
||||||
|
|
||||||
|
import com.njcn.middle.rocket.domain.BaseMessage;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xy
|
||||||
|
*/
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Data
|
||||||
|
public class BZEventMessage extends BaseMessage {
|
||||||
|
|
||||||
|
//补召事件
|
||||||
|
@Data
|
||||||
|
public static class Event{
|
||||||
|
|
||||||
|
@ApiModelProperty("请求的guid")
|
||||||
|
private String guid;
|
||||||
|
|
||||||
|
@ApiModelProperty("终端id")
|
||||||
|
private String terminalId;
|
||||||
|
|
||||||
|
@ApiModelProperty("监测点id")
|
||||||
|
private List<String> monitorIdList;
|
||||||
|
|
||||||
|
@ApiModelProperty("数据类型 0 稳态 1 暂态事件 2 暂态波形")
|
||||||
|
private Integer dataType;
|
||||||
|
|
||||||
|
@ApiModelProperty("时间范围")
|
||||||
|
private List<String> timeInterval;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//补召波形
|
||||||
|
@Data
|
||||||
|
public static class File{
|
||||||
|
|
||||||
|
@ApiModelProperty("请求的guid")
|
||||||
|
private String guid;
|
||||||
|
|
||||||
|
@ApiModelProperty("终端id")
|
||||||
|
private String terminalId;
|
||||||
|
|
||||||
|
@ApiModelProperty("监测点id")
|
||||||
|
private String monitorId;
|
||||||
|
|
||||||
|
@ApiModelProperty("数据类型 0 稳态 1 暂态事件 2 暂态波形")
|
||||||
|
private Integer dataType;
|
||||||
|
|
||||||
|
@ApiModelProperty("缺失波形时标集合")
|
||||||
|
private List<String> timeList;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package com.njcn.mq.message;
|
||||||
|
|
||||||
|
import com.njcn.middle.rocket.domain.BaseMessage;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类的介绍:
|
||||||
|
*
|
||||||
|
* @author xuyang
|
||||||
|
* @version 1.0.0
|
||||||
|
* @createTime 2025/9/29 15:06
|
||||||
|
*/
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class BzMessage extends BaseMessage {
|
||||||
|
|
||||||
|
@ApiModelProperty("唯一标识")
|
||||||
|
private String guid;
|
||||||
|
|
||||||
|
@ApiModelProperty("补召类型")
|
||||||
|
private String dataType;
|
||||||
|
|
||||||
|
@ApiModelProperty("响应码")
|
||||||
|
private Integer code;
|
||||||
|
|
||||||
|
@ApiModelProperty("结果")
|
||||||
|
private String result;
|
||||||
|
|
||||||
|
@ApiModelProperty("设备id")
|
||||||
|
private String terminalId;
|
||||||
|
|
||||||
|
@ApiModelProperty("监测点id")
|
||||||
|
private String monitorId;
|
||||||
|
|
||||||
|
@ApiModelProperty("补召起始时间")
|
||||||
|
private String recallStartDate;
|
||||||
|
|
||||||
|
@ApiModelProperty("补召结束时间")
|
||||||
|
private String recallEndDate;
|
||||||
|
|
||||||
|
@ApiModelProperty("前置服务器id")
|
||||||
|
private String nodeId;
|
||||||
|
|
||||||
|
@ApiModelProperty("前置进程")
|
||||||
|
private String processNo;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package com.njcn.mq.message;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类的介绍:日志信息
|
||||||
|
*
|
||||||
|
* @author xuyang
|
||||||
|
* @version 1.0.0
|
||||||
|
* @createTime 2025/9/18 15:06
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class CldControlMessage {
|
||||||
|
|
||||||
|
@ApiModelProperty("请求的guid")
|
||||||
|
private String guid;
|
||||||
|
|
||||||
|
@ApiModelProperty("功能代号")
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
@ApiModelProperty("前置服务器id")
|
||||||
|
private String nodeId;
|
||||||
|
|
||||||
|
@ApiModelProperty("指定处理的进程号")
|
||||||
|
private Integer processNo;
|
||||||
|
|
||||||
|
@ApiModelProperty("delete用于杀死进程")
|
||||||
|
private String fun;
|
||||||
|
|
||||||
|
@ApiModelProperty("进程数")
|
||||||
|
private Integer processNum;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.njcn.mq.message;
|
||||||
|
|
||||||
|
import com.njcn.middle.rocket.domain.BaseMessage;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类的介绍:
|
||||||
|
*
|
||||||
|
* @author xuyang
|
||||||
|
* @version 1.0.0
|
||||||
|
* @createTime 2023/8/11 15:06
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class CldDeviceRunFlagMessage extends BaseMessage {
|
||||||
|
|
||||||
|
@ApiModelProperty("设备id")
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@ApiModelProperty("前置类型")
|
||||||
|
private String date;
|
||||||
|
|
||||||
|
@ApiModelProperty("状态 0:中断 1:连接")
|
||||||
|
private String status;
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.njcn.mq.message;
|
||||||
|
|
||||||
|
import com.njcn.middle.rocket.domain.BaseMessage;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类的介绍:
|
||||||
|
*
|
||||||
|
* @author xuyang
|
||||||
|
* @version 1.0.0
|
||||||
|
* @createTime 2023/8/11 15:06
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class CldHeartBeatMessage extends BaseMessage {
|
||||||
|
|
||||||
|
@ApiModelProperty("前置类型")
|
||||||
|
private String frontType;
|
||||||
|
|
||||||
|
@ApiModelProperty("前置id")
|
||||||
|
private String nodeId;
|
||||||
|
|
||||||
|
@ApiModelProperty("进程id")
|
||||||
|
private Integer processNo;
|
||||||
|
|
||||||
|
@ApiModelProperty("状态")
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package com.njcn.mq.message;
|
||||||
|
|
||||||
|
import com.njcn.middle.rocket.domain.BaseMessage;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类的介绍:日志信息
|
||||||
|
*
|
||||||
|
* @author xuyang
|
||||||
|
* @version 1.0.0
|
||||||
|
* @createTime 2025/9/18 15:06
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class CldLogMessage extends BaseMessage {
|
||||||
|
|
||||||
|
@ApiModelProperty("前置id")
|
||||||
|
private String nodeId;
|
||||||
|
|
||||||
|
@ApiModelProperty("进程id")
|
||||||
|
private String processNo;
|
||||||
|
|
||||||
|
@ApiModelProperty("监测点id、装置id")
|
||||||
|
private String businessId;
|
||||||
|
|
||||||
|
@ApiModelProperty("级别(process进程、terminal装置、measurepoint监测点)")
|
||||||
|
private String level;
|
||||||
|
|
||||||
|
@ApiModelProperty("日志等级")
|
||||||
|
private String grade;
|
||||||
|
|
||||||
|
@ApiModelProperty("告警码")
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
@ApiModelProperty("告警时间")
|
||||||
|
private String time;
|
||||||
|
|
||||||
|
@ApiModelProperty("日志信息")
|
||||||
|
private String log;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
package com.njcn.mq.message;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cld设备更新台账实体
|
||||||
|
* @author xy
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class CldUpdateLedgerMessage implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@ApiModelProperty("消息唯一标识")
|
||||||
|
private String guid;
|
||||||
|
|
||||||
|
@ApiModelProperty("add_terminal/delete_terminal/ledger_modify")
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
@ApiModelProperty("进程号")
|
||||||
|
private Integer processNo;
|
||||||
|
|
||||||
|
@ApiModelProperty("数据")
|
||||||
|
private List<CldDeviceDto> data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class CldDeviceDto implements Serializable {
|
||||||
|
|
||||||
|
@ApiModelProperty("最大进程数")
|
||||||
|
private Integer maxProcessNum;
|
||||||
|
|
||||||
|
@ApiModelProperty("进程号")
|
||||||
|
private Integer node;
|
||||||
|
|
||||||
|
@ApiModelProperty("设备id")
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@ApiModelProperty("设备MAC")
|
||||||
|
private String ip;
|
||||||
|
|
||||||
|
@ApiModelProperty("设备型号")
|
||||||
|
private String devType;
|
||||||
|
|
||||||
|
@ApiModelProperty("设备名称")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@ApiModelProperty("监测点信息集合")
|
||||||
|
private List<CldMonitorDto> monitorData;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class CldMonitorDto implements Serializable {
|
||||||
|
|
||||||
|
@ApiModelProperty("监测点id")
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@ApiModelProperty("监测点名称")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@ApiModelProperty("监测点线路号")
|
||||||
|
private String lineNo;
|
||||||
|
|
||||||
|
@ApiModelProperty("电压等级")
|
||||||
|
private String voltageLevel;
|
||||||
|
|
||||||
|
@ApiModelProperty("status")
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
@ApiModelProperty("接线方式")
|
||||||
|
private String ptType;
|
||||||
|
|
||||||
|
@ApiModelProperty("设备id")
|
||||||
|
private String deviceId;
|
||||||
|
|
||||||
|
@ApiModelProperty("pt一次变比")
|
||||||
|
private Double pt1;
|
||||||
|
|
||||||
|
@ApiModelProperty("pt二次变比")
|
||||||
|
private Double pt2;
|
||||||
|
|
||||||
|
@ApiModelProperty("ct一次变比")
|
||||||
|
private Double ct1;
|
||||||
|
|
||||||
|
@ApiModelProperty("ct二次变比")
|
||||||
|
private Double ct2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.njcn.mq.message;
|
||||||
|
|
||||||
|
import com.njcn.middle.rocket.domain.BaseMessage;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xy
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class HeartbeatTimeoutMessage extends BaseMessage implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private String nDid;
|
||||||
|
|
||||||
|
private Long timestamp;
|
||||||
|
|
||||||
|
private Integer delayLevel;
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package com.njcn.mq.message;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类的介绍:
|
||||||
|
*
|
||||||
|
* @author xuyang
|
||||||
|
* @version 1.0.0
|
||||||
|
* @createTime 2023/8/11 15:06
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class RealDataMessage {
|
||||||
|
|
||||||
|
@ApiModelProperty("终端序号")
|
||||||
|
private String devSeries;
|
||||||
|
|
||||||
|
@ApiModelProperty("监测点序号")
|
||||||
|
private Integer line;
|
||||||
|
|
||||||
|
@ApiModelProperty("实时数据开启/关闭")
|
||||||
|
private Boolean realData;
|
||||||
|
|
||||||
|
@ApiModelProperty("Soe开启/关闭")
|
||||||
|
private Boolean soeData;
|
||||||
|
|
||||||
|
@ApiModelProperty("限制")
|
||||||
|
private Integer limit;
|
||||||
|
|
||||||
|
@ApiModelProperty("限制")
|
||||||
|
private Integer count;
|
||||||
|
|
||||||
|
@ApiModelProperty("idx")
|
||||||
|
private Integer idx;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package com.njcn.mq.message;
|
||||||
|
|
||||||
|
import com.njcn.middle.rocket.domain.BaseMessage;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类的介绍:
|
||||||
|
*
|
||||||
|
* @author xuyang
|
||||||
|
* @version 1.0.0
|
||||||
|
* @createTime 2025/9/29 15:06
|
||||||
|
*/
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class UpdateLedgerMessage extends BaseMessage {
|
||||||
|
|
||||||
|
@ApiModelProperty("唯一标识")
|
||||||
|
private String guid;
|
||||||
|
|
||||||
|
@ApiModelProperty("数据")
|
||||||
|
private List<HandleData> data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class HandleData implements Serializable {
|
||||||
|
|
||||||
|
@ApiModelProperty("设备id")
|
||||||
|
private String deviceId;
|
||||||
|
|
||||||
|
@ApiModelProperty("响应码")
|
||||||
|
private Integer code;
|
||||||
|
|
||||||
|
@ApiModelProperty("结果描述")
|
||||||
|
private String result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.njcn.mq.template;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.njcn.middle.rocket.domain.BaseMessage;
|
||||||
|
import com.njcn.middle.rocket.template.RocketMQEnhanceTemplate;
|
||||||
|
import com.njcn.mq.constant.BusinessResource;
|
||||||
|
import com.njcn.mq.constant.BusinessTopic;
|
||||||
|
import org.apache.rocketmq.client.producer.SendResult;
|
||||||
|
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类的介绍:补召事件
|
||||||
|
*
|
||||||
|
* @author xuyang
|
||||||
|
* @version 1.0.0
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class BZEventMessageTemplate extends RocketMQEnhanceTemplate {
|
||||||
|
|
||||||
|
public BZEventMessageTemplate(RocketMQTemplate template) {
|
||||||
|
super(template);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SendResult sendMember(Object message, String tag) {
|
||||||
|
BaseMessage baseMessage = new BaseMessage();
|
||||||
|
baseMessage.setSource(BusinessResource.WEB_RESOURCE);
|
||||||
|
baseMessage.setMessageBody(JSON.toJSONString(message));
|
||||||
|
return send(BusinessTopic.ASK_RECALL_TOPIC,tag,baseMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.njcn.mq.template;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.njcn.middle.rocket.domain.BaseMessage;
|
||||||
|
import com.njcn.middle.rocket.template.RocketMQEnhanceTemplate;
|
||||||
|
import com.njcn.mq.constant.BusinessResource;
|
||||||
|
import com.njcn.mq.constant.BusinessTopic;
|
||||||
|
import com.njcn.mq.message.CldControlMessage;
|
||||||
|
import org.apache.rocketmq.client.producer.SendResult;
|
||||||
|
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类的介绍:实时数据模板
|
||||||
|
*
|
||||||
|
* @author xuyang
|
||||||
|
* @version 1.0.0
|
||||||
|
* @createTime 2023/8/11 15:28
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class CldControlMessageTemplate extends RocketMQEnhanceTemplate {
|
||||||
|
|
||||||
|
public CldControlMessageTemplate(RocketMQTemplate template) {
|
||||||
|
super(template);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SendResult sendMember(CldControlMessage message, String tag) {
|
||||||
|
BaseMessage baseMessage = new BaseMessage();
|
||||||
|
baseMessage.setSource(BusinessResource.WEB_RESOURCE);
|
||||||
|
baseMessage.setMessageBody(new Gson().toJson(message));
|
||||||
|
return send(BusinessTopic.PROCESS_TOPIC,tag,baseMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.njcn.mq.template;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.njcn.middle.rocket.domain.BaseMessage;
|
||||||
|
import com.njcn.middle.rocket.template.RocketMQEnhanceTemplate;
|
||||||
|
import com.njcn.mq.constant.BusinessResource;
|
||||||
|
import com.njcn.mq.constant.BusinessTopic;
|
||||||
|
import com.njcn.mq.message.CldUpdateLedgerMessage;
|
||||||
|
import org.apache.rocketmq.client.producer.SendResult;
|
||||||
|
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类的介绍:实时数据模板
|
||||||
|
*
|
||||||
|
* @author xuyang
|
||||||
|
* @version 1.0.0
|
||||||
|
* @createTime 2023/8/11 15:28
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class CldUpdateLedgerMessageTemplate extends RocketMQEnhanceTemplate {
|
||||||
|
|
||||||
|
public CldUpdateLedgerMessageTemplate(RocketMQTemplate template) {
|
||||||
|
super(template);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SendResult sendMember(CldUpdateLedgerMessage cldUpdateLedgerMessage, String tag) {
|
||||||
|
BaseMessage baseMessage = new BaseMessage();
|
||||||
|
baseMessage.setSource(BusinessResource.WEB_RESOURCE);
|
||||||
|
baseMessage.setMessageBody(new Gson().toJson(cldUpdateLedgerMessage));
|
||||||
|
return send(BusinessTopic.CONTROL_TOPIC,tag,baseMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.njcn.mq.template;
|
||||||
|
|
||||||
|
import com.njcn.middle.rocket.template.RocketMQEnhanceTemplate;
|
||||||
|
import com.njcn.mq.constant.BusinessResource;
|
||||||
|
import com.njcn.mq.constant.BusinessTopic;
|
||||||
|
import com.njcn.mq.message.HeartbeatTimeoutMessage;
|
||||||
|
import org.apache.rocketmq.client.producer.SendResult;
|
||||||
|
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类的介绍:
|
||||||
|
*
|
||||||
|
* @author xuyang
|
||||||
|
* @version 1.0.0
|
||||||
|
* @createTime 2023/8/11 15:28
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class HeartbeatTimeoutMessageTemplate extends RocketMQEnhanceTemplate {
|
||||||
|
|
||||||
|
public HeartbeatTimeoutMessageTemplate(RocketMQTemplate template) {
|
||||||
|
super(template);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SendResult sendMember(HeartbeatTimeoutMessage heartbeatTimeoutMessage) {
|
||||||
|
heartbeatTimeoutMessage.setSource(BusinessResource.WEB_RESOURCE);
|
||||||
|
return send(BusinessTopic.HEARTBEAT_TIMEOUT_TOPIC, BusinessTopic.HeartTag.APF_TAG, heartbeatTimeoutMessage, heartbeatTimeoutMessage.getDelayLevel());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.njcn.mq.template;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.njcn.middle.rocket.domain.BaseMessage;
|
||||||
|
import com.njcn.middle.rocket.template.RocketMQEnhanceTemplate;
|
||||||
|
import com.njcn.mq.constant.BusinessResource;
|
||||||
|
import com.njcn.mq.constant.BusinessTopic;
|
||||||
|
import com.njcn.mq.message.RealDataMessage;
|
||||||
|
import org.apache.rocketmq.client.producer.SendResult;
|
||||||
|
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类的介绍:实时数据模板
|
||||||
|
*
|
||||||
|
* @author xuyang
|
||||||
|
* @version 1.0.0
|
||||||
|
* @createTime 2023/8/11 15:28
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class RealDataMessageTemplate extends RocketMQEnhanceTemplate {
|
||||||
|
|
||||||
|
public RealDataMessageTemplate(RocketMQTemplate template) {
|
||||||
|
super(template);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SendResult sendMember(RealDataMessage realDataMessage,String tag) {
|
||||||
|
BaseMessage baseMessage = new BaseMessage();
|
||||||
|
baseMessage.setSource(BusinessResource.WEB_RESOURCE);
|
||||||
|
baseMessage.setMessageBody(new Gson().toJson(realDataMessage));
|
||||||
|
return send(BusinessTopic.CLD_ASK_REAL_DATA_TOPIC,tag,baseMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -48,6 +48,28 @@
|
|||||||
<artifactId>minioss-springboot-starter</artifactId>
|
<artifactId>minioss-springboot-starter</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.njcn</groupId>
|
||||||
|
<artifactId>aliyun-oss-springboot-starter</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-core</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-api</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.aliyun.oss</groupId>
|
||||||
|
<artifactId>aliyun-sdk-oss</artifactId>
|
||||||
|
<version>3.18.0</version>
|
||||||
|
<optional>false</optional>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -13,6 +13,7 @@ public interface GeneralConstant {
|
|||||||
Integer LOCAL_DISK = 1;
|
Integer LOCAL_DISK = 1;
|
||||||
Integer HUAWEI_OBS = 2;
|
Integer HUAWEI_OBS = 2;
|
||||||
Integer MINIO_OSS = 3;
|
Integer MINIO_OSS = 3;
|
||||||
|
Integer AliYUN_OSS = 4;
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* 波形文件的3种后缀
|
* 波形文件的3种后缀
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ public interface OssPath {
|
|||||||
*/
|
*/
|
||||||
String WAVE_DIR="comtrade/";
|
String WAVE_DIR="comtrade/";
|
||||||
|
|
||||||
|
String WAVE_FILE="wave/";
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* 下载文件
|
* 下载文件
|
||||||
*/
|
*/
|
||||||
@@ -167,4 +169,14 @@ public interface OssPath {
|
|||||||
*/
|
*/
|
||||||
String CONFIGURATIONNAME = "configuration.json";
|
String CONFIGURATIONNAME = "configuration.json";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APP 稳态报告路径
|
||||||
|
*/
|
||||||
|
String APP_HARMONIC_REPORT = "app/report/harmonic/";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APP 暂态报告路径
|
||||||
|
*/
|
||||||
|
String APP_EVENT_REPORT = "app/report/event/";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
package com.njcn.oss.utils;
|
package com.njcn.oss.utils;
|
||||||
|
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.core.lang.UUID;
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import com.aliyun.oss.OSS;
|
||||||
|
import com.njcn.ali.oss.config.AliYunOssConfig;
|
||||||
|
import com.njcn.ali.oss.util.AliYunOssUtils;
|
||||||
import com.njcn.common.config.GeneralInfo;
|
import com.njcn.common.config.GeneralInfo;
|
||||||
import com.njcn.common.pojo.exception.BusinessException;
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
|
import com.njcn.huawei.obs.config.HuaweiObsProperties;
|
||||||
import com.njcn.huawei.obs.util.OBSUtil;
|
import com.njcn.huawei.obs.util.OBSUtil;
|
||||||
import com.njcn.minioss.bo.MinIoUploadResDTO;
|
import com.njcn.minioss.bo.MinIoUploadResDTO;
|
||||||
import com.njcn.minioss.config.MinIossProperties;
|
import com.njcn.minioss.config.MinIossProperties;
|
||||||
@@ -11,8 +15,9 @@ import com.njcn.minioss.util.MinIoUtils;
|
|||||||
import com.njcn.oss.constant.GeneralConstant;
|
import com.njcn.oss.constant.GeneralConstant;
|
||||||
import com.njcn.oss.constant.OssPath;
|
import com.njcn.oss.constant.OssPath;
|
||||||
import com.njcn.oss.enums.OssResponseEnum;
|
import com.njcn.oss.enums.OssResponseEnum;
|
||||||
|
import com.obs.services.ObsClient;
|
||||||
|
import com.obs.services.model.PutObjectRequest;
|
||||||
import io.minio.*;
|
import io.minio.*;
|
||||||
import io.minio.errors.*;
|
|
||||||
import io.minio.messages.Item;
|
import io.minio.messages.Item;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -65,6 +70,16 @@ public class FileStorageUtil {
|
|||||||
|
|
||||||
private final MinIossProperties minIossProperties;
|
private final MinIossProperties minIossProperties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 阿里云文件服务器
|
||||||
|
*/
|
||||||
|
private final AliYunOssUtils aliYunOssUtils;
|
||||||
|
|
||||||
|
private final HuaweiObsProperties huaweiObsProperties;
|
||||||
|
|
||||||
|
private final OSS ossClient;
|
||||||
|
private final AliYunOssConfig ossConfig;
|
||||||
|
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* 上传MultipartFile文件,
|
* 上传MultipartFile文件,
|
||||||
@@ -78,7 +93,7 @@ public class FileStorageUtil {
|
|||||||
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
||||||
filePath = dir + minIoUtils.minFileName(multipartFile.getOriginalFilename());
|
filePath = dir + minIoUtils.minFileName(multipartFile.getOriginalFilename());
|
||||||
obsUtil.uploadMultipart(multipartFile, filePath);
|
obsUtil.uploadMultipart(multipartFile, filePath);
|
||||||
} else if(generalInfo.getBusinessFileStorage() == GeneralConstant.MINIO_OSS){
|
} else if (generalInfo.getBusinessFileStorage() == GeneralConstant.MINIO_OSS) {
|
||||||
try {
|
try {
|
||||||
//把名称存入数据
|
//把名称存入数据
|
||||||
MinIoUploadResDTO minIoUploadResDTO = minIoUtils.upload(multipartFile, minIossProperties.getBucket(), dir);
|
MinIoUploadResDTO minIoUploadResDTO = minIoUtils.upload(multipartFile, minIossProperties.getBucket(), dir);
|
||||||
@@ -86,18 +101,29 @@ public class FileStorageUtil {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new BusinessException(OssResponseEnum.UPLOAD_FILE_ERROR);
|
throw new BusinessException(OssResponseEnum.UPLOAD_FILE_ERROR);
|
||||||
}
|
}
|
||||||
}else {
|
} else if (generalInfo.getBusinessFileStorage() == GeneralConstant.AliYUN_OSS) {
|
||||||
|
filePath = dir;
|
||||||
|
aliYunOssUtils.uploadFile(dir, multipartFile);
|
||||||
|
} else {
|
||||||
try {
|
try {
|
||||||
// 确保目录存在
|
// 构建完整目录:基准目录 + dir子目录
|
||||||
Path uploadPath = Paths.get(generalInfo.getLocalStorePath());
|
Path basePath = Paths.get(generalInfo.getLocalStorePath());
|
||||||
|
// 将dir作为子目录添加
|
||||||
|
Path uploadPath = basePath.resolve(dir);
|
||||||
|
|
||||||
|
// 确保完整目录存在(包括dir子目录)
|
||||||
if (!Files.exists(uploadPath)) {
|
if (!Files.exists(uploadPath)) {
|
||||||
Files.createDirectories(uploadPath);
|
Files.createDirectories(uploadPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 生成本地文件名(可以添加时间戳或UUID防止重名)
|
// 生成本地文件名(处理扩展名,防止异常)
|
||||||
String originalFilename = multipartFile.getOriginalFilename();
|
String originalFilename = multipartFile.getOriginalFilename();
|
||||||
String fileExtension = originalFilename.substring(originalFilename.lastIndexOf("."));
|
String fileExtension = "";
|
||||||
String newFilename = UUID.randomUUID().toString() + fileExtension;
|
int extIndex = originalFilename.lastIndexOf(".");
|
||||||
|
if (extIndex > 0 && extIndex < originalFilename.length() - 1) {
|
||||||
|
fileExtension = originalFilename.substring(extIndex);
|
||||||
|
}
|
||||||
|
String newFilename = IdUtil.simpleUUID().toUpperCase() + fileExtension;
|
||||||
|
|
||||||
// 构建完整路径
|
// 构建完整路径
|
||||||
Path filePathPath = uploadPath.resolve(newFilename);
|
Path filePathPath = uploadPath.resolve(newFilename);
|
||||||
@@ -105,7 +131,7 @@ public class FileStorageUtil {
|
|||||||
// 保存文件
|
// 保存文件
|
||||||
multipartFile.transferTo(filePathPath.toFile());
|
multipartFile.transferTo(filePathPath.toFile());
|
||||||
|
|
||||||
// 返回相对路径或完整路径,根据需求调整
|
// 返回相对路径或完整路径
|
||||||
filePath = dir + File.separator + newFilename;
|
filePath = dir + File.separator + newFilename;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new BusinessException("本地文件上传失败: " + e.getMessage());
|
throw new BusinessException("本地文件上传失败: " + e.getMessage());
|
||||||
@@ -127,6 +153,9 @@ public class FileStorageUtil {
|
|||||||
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
||||||
filePath = dir + minIoUtils.minFileName(multipartFile.getOriginalFilename());
|
filePath = dir + minIoUtils.minFileName(multipartFile.getOriginalFilename());
|
||||||
obsUtil.uploadMultipart(multipartFile, filePath);
|
obsUtil.uploadMultipart(multipartFile, filePath);
|
||||||
|
} else if (generalInfo.getBusinessFileStorage() == GeneralConstant.AliYUN_OSS) {
|
||||||
|
filePath = dir;
|
||||||
|
aliYunOssUtils.uploadFile(dir, multipartFile);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
//把名称存入数据
|
//把名称存入数据
|
||||||
@@ -152,7 +181,7 @@ public class FileStorageUtil {
|
|||||||
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
||||||
filePath = dir + minIoUtils.minFileName(fileName);
|
filePath = dir + minIoUtils.minFileName(fileName);
|
||||||
obsUtil.uploadStream(inputStream, filePath);
|
obsUtil.uploadStream(inputStream, filePath);
|
||||||
} else if (generalInfo.getBusinessFileStorage() == GeneralConstant.MINIO_OSS){
|
} else if (generalInfo.getBusinessFileStorage() == GeneralConstant.MINIO_OSS) {
|
||||||
try {
|
try {
|
||||||
//把名称存入数据
|
//把名称存入数据
|
||||||
MinIoUploadResDTO minIoUploadResDTO = minIoUtils.uploadStream(inputStream, minIossProperties.getBucket(), dir, minIoUtils.minFileName(fileName));
|
MinIoUploadResDTO minIoUploadResDTO = minIoUtils.uploadStream(inputStream, minIossProperties.getBucket(), dir, minIoUtils.minFileName(fileName));
|
||||||
@@ -160,14 +189,17 @@ public class FileStorageUtil {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new BusinessException(OssResponseEnum.UPLOAD_FILE_ERROR);
|
throw new BusinessException(OssResponseEnum.UPLOAD_FILE_ERROR);
|
||||||
}
|
}
|
||||||
}else {
|
} else if (generalInfo.getBusinessFileStorage() == GeneralConstant.AliYUN_OSS) {
|
||||||
|
filePath = dir + fileName;
|
||||||
|
aliYunOssUtils.uploadFile(filePath, inputStream);
|
||||||
|
} else {
|
||||||
// 本地存储逻辑
|
// 本地存储逻辑
|
||||||
try {
|
try {
|
||||||
// 1. 获取本地存储路径
|
// 1. 获取本地存储路径
|
||||||
String localStoragePath = generalInfo.getLocalStorePath();
|
String localStoragePath = generalInfo.getLocalStorePath();
|
||||||
|
|
||||||
// 2. 确保目录存在(如果不存在则创建)
|
// 2. 确保目录存在(如果不存在则创建)
|
||||||
File targetDir = new File(localStoragePath +File.separator+ dir);
|
File targetDir = new File(localStoragePath + File.separator + dir);
|
||||||
if (!targetDir.exists()) {
|
if (!targetDir.exists()) {
|
||||||
boolean created = targetDir.mkdirs();
|
boolean created = targetDir.mkdirs();
|
||||||
if (!created) {
|
if (!created) {
|
||||||
@@ -185,7 +217,7 @@ public class FileStorageUtil {
|
|||||||
// 5. 返回相对路径
|
// 5. 返回相对路径
|
||||||
filePath = dir + finalFileName;
|
filePath = dir + finalFileName;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new BusinessException(OssResponseEnum.UPLOAD_FILE_ERROR,e.getMessage());
|
throw new BusinessException(OssResponseEnum.UPLOAD_FILE_ERROR, e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return filePath;
|
return filePath;
|
||||||
@@ -201,6 +233,9 @@ public class FileStorageUtil {
|
|||||||
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
||||||
filePath = dir + minIoUtils.minFileName(fileName);
|
filePath = dir + minIoUtils.minFileName(fileName);
|
||||||
obsUtil.uploadStream(inputStream, filePath);
|
obsUtil.uploadStream(inputStream, filePath);
|
||||||
|
} else if (generalInfo.getBusinessFileStorage() == GeneralConstant.AliYUN_OSS) {
|
||||||
|
filePath = dir + fileName;
|
||||||
|
aliYunOssUtils.uploadFile(filePath, inputStream);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
//把名称存入数据
|
//把名称存入数据
|
||||||
@@ -224,6 +259,8 @@ public class FileStorageUtil {
|
|||||||
String url;
|
String url;
|
||||||
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
||||||
url = obsUtil.getFileUrl(filePath);
|
url = obsUtil.getFileUrl(filePath);
|
||||||
|
} else if (generalInfo.getBusinessFileStorage() == GeneralConstant.AliYUN_OSS) {
|
||||||
|
url = aliYunOssUtils.generatePresignedUrl(filePath, 3600);
|
||||||
} else {
|
} else {
|
||||||
url = minIoUtils.getObjectUrl(minIossProperties.getBucket(), filePath, 7 * 24 * 60 * 60);
|
url = minIoUtils.getObjectUrl(minIossProperties.getBucket(), filePath, 7 * 24 * 60 * 60);
|
||||||
}
|
}
|
||||||
@@ -242,10 +279,12 @@ public class FileStorageUtil {
|
|||||||
try {
|
try {
|
||||||
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
||||||
inputStream = obsUtil.downloadStream(filePath);
|
inputStream = obsUtil.downloadStream(filePath);
|
||||||
} else if(generalInfo.getBusinessFileStorage() == GeneralConstant.MINIO_OSS) {
|
} else if (generalInfo.getBusinessFileStorage() == GeneralConstant.MINIO_OSS) {
|
||||||
inputStream = minIoUtils.downloadStream(minIossProperties.getBucket(), filePath);
|
inputStream = minIoUtils.downloadStream(minIossProperties.getBucket(), filePath);
|
||||||
}else {
|
} else if (generalInfo.getBusinessFileStorage() == GeneralConstant.AliYUN_OSS) {
|
||||||
Path path = Paths.get(generalInfo.getLocalStorePath()+File.separator+filePath);
|
inputStream = aliYunOssUtils.downloadStream(filePath);
|
||||||
|
} else {
|
||||||
|
Path path = Paths.get(generalInfo.getLocalStorePath() + File.separator + filePath);
|
||||||
inputStream = Files.newInputStream(path);
|
inputStream = Files.newInputStream(path);
|
||||||
}
|
}
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
@@ -266,12 +305,13 @@ public class FileStorageUtil {
|
|||||||
try {
|
try {
|
||||||
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
||||||
inputStream = obsUtil.downloadStream(filePath);
|
inputStream = obsUtil.downloadStream(filePath);
|
||||||
} else if(generalInfo.getBusinessFileStorage() == GeneralConstant.MINIO_OSS){
|
} else if (generalInfo.getBusinessFileStorage() == GeneralConstant.MINIO_OSS) {
|
||||||
inputStream = minIoUtils.downloadStream(minIossProperties.getBucket(), filePath);
|
inputStream = minIoUtils.downloadStream(minIossProperties.getBucket(), filePath);
|
||||||
}else {
|
} else if (generalInfo.getBusinessFileStorage() == GeneralConstant.AliYUN_OSS) {
|
||||||
|
inputStream = aliYunOssUtils.downloadStream(filePath);
|
||||||
|
} else {
|
||||||
// 本地存储处理
|
// 本地存储处理
|
||||||
Path path = Paths.get(generalInfo.getLocalStorePath()+File.separator+filePath);
|
Path path = Paths.get(generalInfo.getLocalStorePath() + File.separator + filePath);
|
||||||
System.out.println("下载文件路径:"+generalInfo.getLocalStorePath()+File.separator+filePath);
|
|
||||||
inputStream = Files.newInputStream(path);
|
inputStream = Files.newInputStream(path);
|
||||||
|
|
||||||
// 设置下载文件名(从路径中提取)
|
// 设置下载文件名(从路径中提取)
|
||||||
@@ -324,8 +364,17 @@ public class FileStorageUtil {
|
|||||||
public void deleteFile(String fileName) {
|
public void deleteFile(String fileName) {
|
||||||
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
||||||
obsUtil.delete(fileName);
|
obsUtil.delete(fileName);
|
||||||
} else {
|
} else if (generalInfo.getBusinessFileStorage() == GeneralConstant.MINIO_OSS) {
|
||||||
minIoUtils.removeObject(minIossProperties.getBucket(), fileName);
|
minIoUtils.removeObject(minIossProperties.getBucket(), fileName);
|
||||||
|
} else if (generalInfo.getBusinessFileStorage() == GeneralConstant.AliYUN_OSS) {
|
||||||
|
aliYunOssUtils.deleteFile(fileName);
|
||||||
|
} else if (generalInfo.getBusinessFileStorage() == GeneralConstant.LOCAL_DISK) {
|
||||||
|
Path path = Paths.get(generalInfo.getLocalStorePath() + File.separator + fileName);
|
||||||
|
try {
|
||||||
|
Files.delete(path);
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.info("删除本地文件{}失败失败原因{}", path, e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -395,11 +444,70 @@ public class FileStorageUtil {
|
|||||||
|
|
||||||
file = File.createTempFile(lastItem.objectName(), "xlsx");
|
file = File.createTempFile(lastItem.objectName(), "xlsx");
|
||||||
FileUtil.writeFromStream(stream, file);
|
FileUtil.writeFromStream(stream, file);
|
||||||
}else if(generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS){
|
} else if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
||||||
file = obsUtil.getLastFile(OssPath.LOGBAK);
|
file = obsUtil.getLastFile(OssPath.LOGBAK);
|
||||||
|
} else if (generalInfo.getBusinessFileStorage() == GeneralConstant.AliYUN_OSS) {
|
||||||
|
file = aliYunOssUtils.getLastFile(directory);
|
||||||
}
|
}
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void mkdir(String directoryPath) {
|
||||||
|
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
||||||
|
this.createDirectoryHW(directoryPath);
|
||||||
|
} else if (generalInfo.getBusinessFileStorage() == GeneralConstant.MINIO_OSS) {
|
||||||
|
minIoUtils.createDirectory(minIossProperties.getBucket(), directoryPath);
|
||||||
|
} else if (generalInfo.getBusinessFileStorage() == GeneralConstant.AliYUN_OSS) {
|
||||||
|
this.createDirectoryAli(directoryPath);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 华为文件服务器创建空目录
|
||||||
|
*
|
||||||
|
* @param dirPath
|
||||||
|
*/
|
||||||
|
private void createDirectoryHW(String dirPath) {
|
||||||
|
ObsClient obsClient = null;
|
||||||
|
try {
|
||||||
|
obsClient = this.huaweiObsProperties.getInstance();
|
||||||
|
String bucketName = this.huaweiObsProperties.getObs().getBucket();
|
||||||
|
|
||||||
|
// 确保路径以 / 结尾
|
||||||
|
String directoryKey = dirPath.endsWith("/") ? dirPath : dirPath + "/";
|
||||||
|
|
||||||
|
// 创建空对象作为目录占位符
|
||||||
|
InputStream emptyStream = new ByteArrayInputStream(new byte[0]);
|
||||||
|
PutObjectRequest request = new PutObjectRequest(bucketName, directoryKey, emptyStream);
|
||||||
|
obsClient.putObject(request);
|
||||||
|
|
||||||
|
log.info("已创建目录占位符:" + directoryKey);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("创建目录失败" + dirPath, e);
|
||||||
|
} finally {
|
||||||
|
this.huaweiObsProperties.destroy(obsClient);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 阿里云文件服务器创建空目录
|
||||||
|
*
|
||||||
|
* @param dirPath
|
||||||
|
*/
|
||||||
|
public void createDirectoryAli(String dirPath) {
|
||||||
|
try {
|
||||||
|
// 确保路径以 / 结尾,表示目录
|
||||||
|
String directoryKey = dirPath.endsWith("/") ? dirPath : dirPath + "/";
|
||||||
|
|
||||||
|
// 创建空输入流作为目录占位符
|
||||||
|
ByteArrayInputStream emptyStream = new ByteArrayInputStream(new byte[0]);
|
||||||
|
|
||||||
|
this.ossClient.putObject(this.ossConfig.getBucket(), directoryKey, emptyStream);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("创建目录失败:" + dirPath, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -239,18 +239,47 @@ public class ExcelUtil {
|
|||||||
* @param strings 下拉内容
|
* @param strings 下拉内容
|
||||||
*/
|
*/
|
||||||
public static void selectList(Workbook workbook, int firstCol, int lastCol, String[] strings) {
|
public static void selectList(Workbook workbook, int firstCol, int lastCol, String[] strings) {
|
||||||
Sheet sheet = workbook.getSheetAt(0);
|
// Sheet sheet = workbook.getSheetAt(0);
|
||||||
// 生成下拉列表
|
// // 生成下拉列表
|
||||||
// 只对(x,x)单元格有效
|
// // 只对(x,x)单元格有效
|
||||||
CellRangeAddressList cellRangeAddressList = new CellRangeAddressList(2, 65535, firstCol, lastCol);
|
// CellRangeAddressList cellRangeAddressList = new CellRangeAddressList(2, 65535, firstCol, lastCol);
|
||||||
// 生成下拉框内容
|
// // 生成下拉框内容
|
||||||
DataValidationHelper dvHelper = sheet.getDataValidationHelper();
|
// DataValidationHelper dvHelper = sheet.getDataValidationHelper();
|
||||||
XSSFDataValidationConstraint dvConstraint = (XSSFDataValidationConstraint)
|
// XSSFDataValidationConstraint dvConstraint = (XSSFDataValidationConstraint)
|
||||||
dvHelper.createExplicitListConstraint(strings);
|
// dvHelper.createExplicitListConstraint(strings);
|
||||||
XSSFDataValidation validation = (XSSFDataValidation) dvHelper.createValidation(
|
// XSSFDataValidation validation = (XSSFDataValidation) dvHelper.createValidation(
|
||||||
dvConstraint, cellRangeAddressList);
|
// dvConstraint, cellRangeAddressList);
|
||||||
// 对sheet页生效
|
// // 对sheet页生效
|
||||||
sheet.addValidationData(validation);
|
// sheet.addValidationData(validation);
|
||||||
|
|
||||||
|
Sheet targetSheet = workbook.getSheetAt(0);
|
||||||
|
|
||||||
|
// ===================== 关键:每个下拉用唯一名称的隐藏Sheet =====================
|
||||||
|
String uniqueHiddenName = "dropdown_" + firstCol + "_" + lastCol + "_" + System.currentTimeMillis();
|
||||||
|
Sheet hiddenSheet = workbook.createSheet(uniqueHiddenName);
|
||||||
|
// 隐藏数据源Sheet
|
||||||
|
workbook.setSheetHidden(workbook.getSheetIndex(hiddenSheet), true);
|
||||||
|
|
||||||
|
// 写入选项到隐藏Sheet
|
||||||
|
for (int i = 0; i < strings.length; i++) {
|
||||||
|
Row row = hiddenSheet.createRow(i);
|
||||||
|
Cell cell = row.createCell(0);
|
||||||
|
cell.setCellValue(strings[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构造引用公式(无长度限制)
|
||||||
|
String formula = uniqueHiddenName + "!$A$1:$A$" + strings.length;
|
||||||
|
|
||||||
|
// 下拉作用范围:第3行 ~ 65536行
|
||||||
|
CellRangeAddressList range = new CellRangeAddressList(2, 65535, firstCol, lastCol);
|
||||||
|
DataValidationHelper helper = targetSheet.getDataValidationHelper();
|
||||||
|
DataValidationConstraint constraint = helper.createFormulaListConstraint(formula);
|
||||||
|
DataValidation validation = helper.createValidation(constraint, range);
|
||||||
|
|
||||||
|
// 必加:防止下拉冲突、不显示
|
||||||
|
validation.setShowErrorBox(true);
|
||||||
|
validation.setShowPromptBox(true);
|
||||||
|
targetSheet.addValidationData(validation);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -4,13 +4,15 @@ import cn.hutool.core.io.FileUtil;
|
|||||||
import cn.hutool.core.util.CharsetUtil;
|
import cn.hutool.core.util.CharsetUtil;
|
||||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||||
import com.njcn.common.pojo.exception.BusinessException;
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
import org.apache.poi.ss.usermodel.Workbook;
|
import org.apache.poi.ss.usermodel.*;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
|
||||||
|
|
||||||
import javax.servlet.ServletOutputStream;
|
import javax.servlet.ServletOutputStream;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author hongawen
|
* @author hongawen
|
||||||
@@ -76,6 +78,59 @@ public class PoiUtil {
|
|||||||
fileName = URLEncoder.encode(fileName, CharsetUtil.UTF_8);
|
fileName = URLEncoder.encode(fileName, CharsetUtil.UTF_8);
|
||||||
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
|
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
|
||||||
response.setContentType("application/octet-stream;charset=" + CharsetUtil.UTF_8);
|
response.setContentType("application/octet-stream;charset=" + CharsetUtil.UTF_8);
|
||||||
|
//将带*号的列变成红色
|
||||||
|
Sheet sheetAt = workbook.getSheetAt(0);
|
||||||
|
//获取列数
|
||||||
|
int physicalNumberOfCells = sheetAt.getRow(0).getPhysicalNumberOfCells();
|
||||||
|
//没有表格标题,只有表格头
|
||||||
|
for (int i = 0; i < 2; i++) {
|
||||||
|
//获取行
|
||||||
|
Row row = sheetAt.getRow(i);
|
||||||
|
if (Objects.isNull(row)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (int j = 0; j < physicalNumberOfCells; j++) {
|
||||||
|
//获取单元格对象
|
||||||
|
Cell cell = row.getCell(j);
|
||||||
|
//获取单元格样式对象
|
||||||
|
CellStyle cellStyle = workbook.createCellStyle();
|
||||||
|
//获取单元格内容对象
|
||||||
|
Font font = workbook.createFont();
|
||||||
|
font.setFontHeightInPoints((short) 12);
|
||||||
|
//一定要装入 样式中才会生效
|
||||||
|
cellStyle.setFont(font);
|
||||||
|
//设置居中对齐
|
||||||
|
cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
||||||
|
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||||
|
//设置单元格字体颜色
|
||||||
|
cell.setCellStyle(cellStyle);
|
||||||
|
//获取当前值
|
||||||
|
String stringCellValue = cell.getStringCellValue();
|
||||||
|
if (stringCellValue.contains("*")) {
|
||||||
|
// 创建一个富文本
|
||||||
|
XSSFRichTextString xssfRichTextString = new XSSFRichTextString(stringCellValue);
|
||||||
|
int startIndex = stringCellValue.indexOf("*");
|
||||||
|
int entIndex = stringCellValue.lastIndexOf("*");
|
||||||
|
if (entIndex != 0) {
|
||||||
|
Font font3 = workbook.createFont();
|
||||||
|
font3.setFontHeightInPoints((short) 12);
|
||||||
|
font3.setColor(Font.COLOR_NORMAL);
|
||||||
|
xssfRichTextString.applyFont(0, entIndex, font3);
|
||||||
|
}
|
||||||
|
//设置带*样式
|
||||||
|
Font font1 = workbook.createFont();
|
||||||
|
font1.setFontHeightInPoints((short) 12);
|
||||||
|
font1.setColor(Font.COLOR_RED);
|
||||||
|
xssfRichTextString.applyFont(startIndex, entIndex + 1, font1);
|
||||||
|
//其他样式
|
||||||
|
Font font2 = workbook.createFont();
|
||||||
|
font2.setFontHeightInPoints((short) 12);
|
||||||
|
font2.setColor(Font.COLOR_NORMAL);
|
||||||
|
xssfRichTextString.applyFont(entIndex + 1, stringCellValue.length(), font2);
|
||||||
|
cell.setCellValue(xssfRichTextString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
workbook.write(outputStream);
|
workbook.write(outputStream);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@@ -115,4 +115,8 @@ public interface AppRedisKey {
|
|||||||
* 补召文件
|
* 补召文件
|
||||||
*/
|
*/
|
||||||
String MAKE_UP_FILES = "makeUpFilesKey:";
|
String MAKE_UP_FILES = "makeUpFilesKey:";
|
||||||
|
|
||||||
|
String COMMON_REQUEST = "commonRequestKey:";
|
||||||
|
|
||||||
|
String COMMON_RESOPNSE = "commonResponseKey:";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,27 @@ public enum RedisKeyEnum {
|
|||||||
/***
|
/***
|
||||||
* 存放用户的角色关系
|
* 存放用户的角色关系
|
||||||
*/
|
*/
|
||||||
USER_ROLE_TYPE_KEY("USER_ROLE_TYPE_KEY", -1L);
|
USER_ROLE_TYPE_KEY("USER_ROLE_TYPE_KEY", -1L),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 云前置心跳
|
||||||
|
*/
|
||||||
|
CLD_HEART_BEAT_KEY("CLD_HEART_BEAT:", 180L),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户日志队列
|
||||||
|
*/
|
||||||
|
USER_LOG_QUEUE("USER_LOG_QUEUE", -1L),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户日志邮件推送队列
|
||||||
|
*/
|
||||||
|
USER_LOG_EMAIL_QUEUE("USER_LOG_EMAIL_QUEUE", -1L),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 终端日志
|
||||||
|
*/
|
||||||
|
DEVICE_LOG_QUEUE("DEVICE_LOG_QUEUE", -1L);
|
||||||
|
|
||||||
|
|
||||||
private final String key;
|
private final String key;
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package com.njcn.redis.utils;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Redis 消息队列工具类
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class RedisMessageQueueUtil {
|
||||||
|
|
||||||
|
private final RedisTemplate<String, Object> redisTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 推送消息到队列(左推)
|
||||||
|
*
|
||||||
|
* @param queueKey 队列Key
|
||||||
|
* @param message 消息内容(JSON字符串)
|
||||||
|
*/
|
||||||
|
public void pushMessage(String queueKey, String message) {
|
||||||
|
try {
|
||||||
|
redisTemplate.opsForList().leftPush(queueKey, message);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("推送消息到队列失败,queueKey={}", queueKey, e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 阻塞式弹出消息(右弹)
|
||||||
|
*
|
||||||
|
* @param queueKey 队列Key
|
||||||
|
* @param timeout 超时时间(秒)
|
||||||
|
* @return 消息内容,超时返回null
|
||||||
|
*/
|
||||||
|
public String popMessage(String queueKey, long timeout) {
|
||||||
|
try {
|
||||||
|
Object result = redisTemplate.opsForList().rightPop(queueKey, timeout, TimeUnit.SECONDS);
|
||||||
|
return result != null ? result.toString() : null;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("弹出消息失败,queueKey={}", queueKey, e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取队列长度(用于监控)
|
||||||
|
*
|
||||||
|
* @param queueKey 队列Key
|
||||||
|
* @return 队列长度
|
||||||
|
*/
|
||||||
|
public Long getQueueSize(String queueKey) {
|
||||||
|
try {
|
||||||
|
return redisTemplate.opsForList().size(queueKey);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("获取队列长度失败,queueKey={}", queueKey, e);
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,9 +2,7 @@ package com.njcn.redis.utils;
|
|||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||||
import org.springframework.data.redis.core.RedisCallback;
|
import org.springframework.data.redis.core.*;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@@ -325,13 +323,54 @@ public class RedisUtil {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public List<?> getLikeListAllValues(String key) {
|
public List<?> getLikeListAllValues(String key) {
|
||||||
List<Object> info=new ArrayList<>();
|
List<Object> info = new ArrayList<>();
|
||||||
for (String s : redisTemplate.keys(key + "*")) {
|
// 使用 SCAN 替代 keys,解决 Tair 禁用 KEYS 命令的问题
|
||||||
|
Set<String> keys = redisTemplate.execute((RedisCallback<Set<String>>) connection -> {
|
||||||
|
Set<String> keySet = new HashSet<>();
|
||||||
|
ScanOptions options = ScanOptions.scanOptions()
|
||||||
|
.match(key + "*")
|
||||||
|
.count(1000)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
try (Cursor<byte[]> cursor = connection.scan(options)) {
|
||||||
|
while (cursor.hasNext()) {
|
||||||
|
keySet.add(new String(cursor.next()));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("Redis SCAN 模糊查询失败", e);
|
||||||
|
}
|
||||||
|
return keySet;
|
||||||
|
});
|
||||||
|
for (String s : keys) {
|
||||||
info.add(redisTemplate.opsForValue().get(s));
|
info.add(redisTemplate.opsForValue().get(s));
|
||||||
}
|
}
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据key模糊查询,并取出所有符合条件的key集合
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
public Set<String> scanKeysByPattern(String pattern, int count) {
|
||||||
|
Set<String> keys = new HashSet<>();
|
||||||
|
ScanOptions options = ScanOptions.scanOptions()
|
||||||
|
.match(pattern)
|
||||||
|
.count(count)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
try (Cursor<byte[]> cursor = redisTemplate.getConnectionFactory()
|
||||||
|
.getConnection()
|
||||||
|
.scan(options)) {
|
||||||
|
while (cursor.hasNext()) {
|
||||||
|
keys.add(new String(cursor.next()));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("扫描Redis keys失败", e);
|
||||||
|
}
|
||||||
|
return keys;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据切库
|
* 数据切库
|
||||||
* @param dbIndex
|
* @param dbIndex
|
||||||
|
|||||||
@@ -45,6 +45,9 @@ public class Knife4jSwaggerConfig {
|
|||||||
@Value("${microservice.gateway.url}")
|
@Value("${microservice.gateway.url}")
|
||||||
private String gatewayUrl;
|
private String gatewayUrl;
|
||||||
|
|
||||||
|
@Value("${swagger.enable:true}")
|
||||||
|
private Boolean swaggerEnable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* swagger通用配置
|
* swagger通用配置
|
||||||
*/
|
*/
|
||||||
@@ -56,6 +59,7 @@ public class Knife4jSwaggerConfig {
|
|||||||
"com.njcn.prepare.harmonic.controller",
|
"com.njcn.prepare.harmonic.controller",
|
||||||
"com.njcn.prepare.event.controller",
|
"com.njcn.prepare.event.controller",
|
||||||
"com.njcn.device.pq.controller",
|
"com.njcn.device.pq.controller",
|
||||||
|
"com.njcn.device.terminal.controller",
|
||||||
"com.njcn.device.pms.controller",
|
"com.njcn.device.pms.controller",
|
||||||
"com.njcn.auth.controller",
|
"com.njcn.auth.controller",
|
||||||
"com.njcn.system.controller",
|
"com.njcn.system.controller",
|
||||||
@@ -71,6 +75,7 @@ public class Knife4jSwaggerConfig {
|
|||||||
"com.njcn.cswarn.controller",
|
"com.njcn.cswarn.controller",
|
||||||
"com.njcn.csharmonic.controller",
|
"com.njcn.csharmonic.controller",
|
||||||
"com.njcn.cssystem.controller",
|
"com.njcn.cssystem.controller",
|
||||||
|
"com.njcn.csreport.controller",
|
||||||
"com.njcn.advance.controller",
|
"com.njcn.advance.controller",
|
||||||
"com.njcn.stat.controller",
|
"com.njcn.stat.controller",
|
||||||
"com.njcn.rt.controller",
|
"com.njcn.rt.controller",
|
||||||
@@ -81,7 +86,11 @@ public class Knife4jSwaggerConfig {
|
|||||||
"com.njcn.supervision.controller",
|
"com.njcn.supervision.controller",
|
||||||
"com.njcn.algorithm",
|
"com.njcn.algorithm",
|
||||||
"com.njcn.dataProcess",
|
"com.njcn.dataProcess",
|
||||||
"com.njcn.migration"
|
"com.njcn.migration",
|
||||||
|
"com.njcn.harmonic.rstatlimitrate.controller",
|
||||||
|
"com.njcn.device.device.controller",
|
||||||
|
"com.njcn.device.userledger.controller",
|
||||||
|
"com.njcn.migration.read.controller"
|
||||||
)
|
)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
List<GrantType> grantTypes = new ArrayList<>();
|
List<GrantType> grantTypes = new ArrayList<>();
|
||||||
@@ -94,7 +103,7 @@ public class Knife4jSwaggerConfig {
|
|||||||
//securyContext
|
//securyContext
|
||||||
return new Docket(DocumentationType.SWAGGER_2)
|
return new Docket(DocumentationType.SWAGGER_2)
|
||||||
.apiInfo(apiInfo())
|
.apiInfo(apiInfo())
|
||||||
.enable(true)
|
.enable(swaggerEnable)
|
||||||
.select()
|
.select()
|
||||||
// 指定添加swagger注解的方法
|
// 指定添加swagger注解的方法
|
||||||
// .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
|
// .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ public class FeignConfig {
|
|||||||
@Bean
|
@Bean
|
||||||
public Decoder feignDecoder() {
|
public Decoder feignDecoder() {
|
||||||
return (response, type) -> {
|
return (response, type) -> {
|
||||||
|
|
||||||
String bodyStr = Util.toString(response.body().asReader(Util.UTF_8));
|
String bodyStr = Util.toString(response.body().asReader(Util.UTF_8));
|
||||||
//对结果进行转换
|
//对结果进行转换
|
||||||
HttpResult<Object> result = PubUtils.json2obj(bodyStr, type);
|
HttpResult<Object> result = PubUtils.json2obj(bodyStr, type);
|
||||||
@@ -60,6 +61,8 @@ public class FeignConfig {
|
|||||||
}
|
}
|
||||||
switch (commonResponseEnum) {
|
switch (commonResponseEnum) {
|
||||||
case SUCCESS:
|
case SUCCESS:
|
||||||
|
// case NO_DATA:
|
||||||
|
// case FAIL:
|
||||||
return result;
|
return result;
|
||||||
default:
|
default:
|
||||||
throw new BusinessException(result);
|
throw new BusinessException(result);
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ public interface ValidMessage {
|
|||||||
|
|
||||||
String NAME_NOT_BLANK = "名称不能为空,请检查name参数";
|
String NAME_NOT_BLANK = "名称不能为空,请检查name参数";
|
||||||
|
|
||||||
String NAME_FORMAT_ERROR = "名称格式错误,存在特殊符号或超过20字符,请检查name参数";
|
String NAME_FORMAT_ERROR = "名称格式错误,存在特殊符号或超过32字符,请检查name参数";
|
||||||
|
|
||||||
String INDUSTRY_NOT_BLANK = "行业不能为空,请检查industry参数";
|
String INDUSTRY_NOT_BLANK = "行业不能为空,请检查industry参数";
|
||||||
String INDUSTRY_FORMAT_ERROR = "行业格式错误,请检查industry参数";
|
String INDUSTRY_FORMAT_ERROR = "行业格式错误,请检查industry参数";
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package com.njcn.web.service.impl;
|
package com.njcn.web.service.impl;
|
||||||
|
|
||||||
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
|
||||||
import com.njcn.common.config.GeneralInfo;
|
import com.njcn.common.config.GeneralInfo;
|
||||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
|
||||||
import com.njcn.common.pojo.constant.LogInfo;
|
import com.njcn.common.pojo.constant.LogInfo;
|
||||||
import com.njcn.common.pojo.dto.DeviceLogDTO;
|
import com.njcn.common.pojo.dto.DeviceLogDTO;
|
||||||
import com.njcn.common.pojo.dto.LogInfoDTO;
|
import com.njcn.common.pojo.dto.LogInfoDTO;
|
||||||
@@ -10,6 +8,8 @@ import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
|||||||
import com.njcn.common.pojo.response.HttpResult;
|
import com.njcn.common.pojo.response.HttpResult;
|
||||||
import com.njcn.common.utils.PubUtils;
|
import com.njcn.common.utils.PubUtils;
|
||||||
import com.njcn.common.utils.ReflectCommonUtil;
|
import com.njcn.common.utils.ReflectCommonUtil;
|
||||||
|
import com.njcn.redis.pojo.enums.RedisKeyEnum;
|
||||||
|
import com.njcn.redis.utils.RedisMessageQueueUtil;
|
||||||
import com.njcn.web.advice.DeviceLog;
|
import com.njcn.web.advice.DeviceLog;
|
||||||
import com.njcn.web.service.ILogService;
|
import com.njcn.web.service.ILogService;
|
||||||
import com.njcn.web.utils.RequestUtil;
|
import com.njcn.web.utils.RequestUtil;
|
||||||
@@ -46,8 +46,15 @@ public class LogServiceImpl implements ILogService {
|
|||||||
|
|
||||||
|
|
||||||
private final GeneralInfo generalInfo;
|
private final GeneralInfo generalInfo;
|
||||||
|
/**
|
||||||
|
* mqtt处理日志异步发布
|
||||||
|
*/
|
||||||
|
// private final MqttPublisher publisher;
|
||||||
|
|
||||||
private final MqttPublisher publisher;
|
/**
|
||||||
|
* redis队列处理日志异步发布
|
||||||
|
*/
|
||||||
|
private final RedisMessageQueueUtil redisMessageQueueUtil;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -82,14 +89,27 @@ public class LogServiceImpl implements ILogService {
|
|||||||
String operateType = ReflectCommonUtil.getOperateTypeByMethod(returnType.getMethod());
|
String operateType = ReflectCommonUtil.getOperateTypeByMethod(returnType.getMethod());
|
||||||
Integer severity = levelStringToNumber(level);
|
Integer severity = levelStringToNumber(level);
|
||||||
LogInfoDTO logInfoDTO = new LogInfoDTO(loginName, userName, ip, methodDescribe, operateType, result.equalsIgnoreCase("失败") ? 0 : 1, "", severity, type.equalsIgnoreCase("业务事件") ? 0 : 1, generalInfo.getMicroServiceName(), userIndex, LocalDateTime.now());
|
LogInfoDTO logInfoDTO = new LogInfoDTO(loginName, userName, ip, methodDescribe, operateType, result.equalsIgnoreCase("失败") ? 0 : 1, "", severity, type.equalsIgnoreCase("业务事件") ? 0 : 1, generalInfo.getMicroServiceName(), userIndex, LocalDateTime.now());
|
||||||
publisher.send("/userLog", PubUtils.obj2json(logInfoDTO), 2, false);
|
// publisher.send("/userLog", PubUtils.obj2json(logInfoDTO), 2, false);
|
||||||
|
|
||||||
|
redisMessageQueueUtil.pushMessage(
|
||||||
|
RedisKeyEnum.USER_LOG_QUEUE.getKey(),
|
||||||
|
PubUtils.obj2json(logInfoDTO)
|
||||||
|
);
|
||||||
|
|
||||||
//推送审计消息功能
|
//推送审计消息功能
|
||||||
if (severity != 0) {
|
if (severity != 0) {
|
||||||
if (!logInfoDTO.getLoginName().equals(LogInfo.UNKNOWN_USER)) {
|
if (!logInfoDTO.getLoginName().equals(LogInfo.UNKNOWN_USER)) {
|
||||||
publisher.send("/userLogPush", PubUtils.obj2json(logInfoDTO), 2, false);
|
/**注意,此处是给前端推送的,如果没有了mqtt协议,此处前端就无消息可消费了*/
|
||||||
|
// publisher.send("/userLogPush", PubUtils.obj2json(logInfoDTO), 2, false);
|
||||||
|
|
||||||
//发送邮箱功能
|
//发送邮箱功能
|
||||||
if (severity == 2 && logInfoDTO.getResult() == 0) {
|
if (severity == 2 && logInfoDTO.getResult() == 0) {
|
||||||
//publisher.send("/userLogEmailPush", PubUtils.obj2json(logInfoDTO), 2, false);
|
//publisher.send("/userLogEmailPush", PubUtils.obj2json(logInfoDTO), 2, false);
|
||||||
|
|
||||||
|
// redisMessageQueueUtil.pushMessage(
|
||||||
|
// RedisKeyEnum.USER_LOG_EMAIL_QUEUE.getKey(),
|
||||||
|
// PubUtils.obj2json(logInfoDTO)
|
||||||
|
// );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -97,8 +117,11 @@ public class LogServiceImpl implements ILogService {
|
|||||||
if (Objects.nonNull((returnType.getMethod())) && (returnType.getMethod()).isAnnotationPresent(DeviceLog.class)) {
|
if (Objects.nonNull((returnType.getMethod())) && (returnType.getMethod()).isAnnotationPresent(DeviceLog.class)) {
|
||||||
String deviceOperate = returnType.getMethod().getAnnotation(DeviceLog.class).operateType();
|
String deviceOperate = returnType.getMethod().getAnnotation(DeviceLog.class).operateType();
|
||||||
DeviceLogDTO deviceLogDTO = new DeviceLogDTO(userName, deviceOperate, result.equalsIgnoreCase("失败") ? 0 : 1, "", loginName, userIndex);
|
DeviceLogDTO deviceLogDTO = new DeviceLogDTO(userName, deviceOperate, result.equalsIgnoreCase("失败") ? 0 : 1, "", loginName, userIndex);
|
||||||
publisher.send("/deviceLog", PubUtils.obj2json(deviceLogDTO), 2, false);
|
// publisher.send("/deviceLog", PubUtils.obj2json(deviceLogDTO), 2, false);
|
||||||
|
redisMessageQueueUtil.pushMessage(
|
||||||
|
RedisKeyEnum.DEVICE_LOG_QUEUE.getKey(),
|
||||||
|
PubUtils.obj2json(deviceLogDTO)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,7 +158,11 @@ public class LogServiceImpl implements ILogService {
|
|||||||
String operateType = ReflectCommonUtil.getOperateTypeByMethod(method);
|
String operateType = ReflectCommonUtil.getOperateTypeByMethod(method);
|
||||||
Integer severity = levelStringToNumber(level);
|
Integer severity = levelStringToNumber(level);
|
||||||
LogInfoDTO logInfoDTO = new LogInfoDTO(tempLogInfo.getLoginName(), tempLogInfo.getUserName(), tempLogInfo.getIp(), ReflectCommonUtil.getMethodDescribeByMethod(method), operateType, result.equalsIgnoreCase("失败") ? 0 : 1, message, severity, type.equalsIgnoreCase("业务事件") ? 0 : 1, generalInfo.getMicroServiceName(), userIndex, LocalDateTime.now());
|
LogInfoDTO logInfoDTO = new LogInfoDTO(tempLogInfo.getLoginName(), tempLogInfo.getUserName(), tempLogInfo.getIp(), ReflectCommonUtil.getMethodDescribeByMethod(method), operateType, result.equalsIgnoreCase("失败") ? 0 : 1, message, severity, type.equalsIgnoreCase("业务事件") ? 0 : 1, generalInfo.getMicroServiceName(), userIndex, LocalDateTime.now());
|
||||||
publisher.send("/userLog", PubUtils.obj2json(logInfoDTO), 1, false);
|
// publisher.send("/userLog", PubUtils.obj2json(logInfoDTO), 1, false);
|
||||||
|
redisMessageQueueUtil.pushMessage(
|
||||||
|
RedisKeyEnum.USER_LOG_QUEUE.getKey(),
|
||||||
|
PubUtils.obj2json(logInfoDTO)
|
||||||
|
);
|
||||||
auditPush(severity, logInfoDTO);
|
auditPush(severity, logInfoDTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,7 +190,11 @@ public class LogServiceImpl implements ILogService {
|
|||||||
Integer severity = levelStringToNumber(level);
|
Integer severity = levelStringToNumber(level);
|
||||||
String operateType = ReflectCommonUtil.getOperateTypeByMethod(method);
|
String operateType = ReflectCommonUtil.getOperateTypeByMethod(method);
|
||||||
LogInfoDTO logInfoDTO = new LogInfoDTO(loginName, "", ip, ReflectCommonUtil.getMethodDescribeByMethod(method), operateType, result.equalsIgnoreCase("失败") ? 0 : 1, message, severity, type.equalsIgnoreCase("业务事件") ? 0 : 1, generalInfo.getMicroServiceName(), loginName, LocalDateTime.now());
|
LogInfoDTO logInfoDTO = new LogInfoDTO(loginName, "", ip, ReflectCommonUtil.getMethodDescribeByMethod(method), operateType, result.equalsIgnoreCase("失败") ? 0 : 1, message, severity, type.equalsIgnoreCase("业务事件") ? 0 : 1, generalInfo.getMicroServiceName(), loginName, LocalDateTime.now());
|
||||||
publisher.send("/userLog", PubUtils.obj2json(logInfoDTO), 1, false);
|
// publisher.send("/userLog", PubUtils.obj2json(logInfoDTO), 1, false);
|
||||||
|
redisMessageQueueUtil.pushMessage(
|
||||||
|
RedisKeyEnum.USER_LOG_QUEUE.getKey(),
|
||||||
|
PubUtils.obj2json(logInfoDTO)
|
||||||
|
);
|
||||||
auditPush(severity, logInfoDTO);
|
auditPush(severity, logInfoDTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,7 +202,12 @@ public class LogServiceImpl implements ILogService {
|
|||||||
//推送审计消息功能
|
//推送审计消息功能
|
||||||
if (severity != 0) {
|
if (severity != 0) {
|
||||||
if (!logInfoDTO.getLoginName().equals(LogInfo.UNKNOWN_USER)) {
|
if (!logInfoDTO.getLoginName().equals(LogInfo.UNKNOWN_USER)) {
|
||||||
publisher.send("/userLogPush", PubUtils.obj2json(logInfoDTO), 2, false);
|
/**注意,此处是给前端推送的,如果没有了mqtt协议,此处前端就无消息可消费了*/
|
||||||
|
// publisher.send("/userLogPush", PubUtils.obj2json(logInfoDTO), 2, false);
|
||||||
|
// redisMessageQueueUtil.pushMessage(
|
||||||
|
// RedisKeyEnum.USER_LOG_QUEUE.getKey(),
|
||||||
|
// PubUtils.obj2json(logInfoDTO)
|
||||||
|
// );
|
||||||
//发送邮箱功能
|
//发送邮箱功能
|
||||||
if (severity == 2 && logInfoDTO.getResult() == 0) {
|
if (severity == 2 && logInfoDTO.getResult() == 0) {
|
||||||
//publisher.send("/userLogEmailPush", PubUtils.obj2json(logInfoDTO), 2, false);
|
//publisher.send("/userLogEmailPush", PubUtils.obj2json(logInfoDTO), 2, false);
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
package com.njcn.web.utils;
|
package com.njcn.web.utils;
|
||||||
|
|
||||||
import org.springframework.http.HttpEntity;
|
import cn.hutool.json.JSONArray;
|
||||||
import org.springframework.http.HttpHeaders;
|
import cn.hutool.json.JSONObject;
|
||||||
import org.springframework.http.HttpMethod;
|
import cn.hutool.json.JSONUtil;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.http.*;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
@@ -15,8 +18,11 @@ import java.util.Map;
|
|||||||
* @createDate 2019-02-08
|
* @createDate 2019-02-08
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@Component
|
||||||
public class RestTemplateUtil {
|
public class RestTemplateUtil {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(RestTemplateUtil.class);
|
||||||
|
|
||||||
private static final RestTemplate restTemplate = new RestTemplate();
|
private static final RestTemplate restTemplate = new RestTemplate();
|
||||||
|
|
||||||
// ----------------------------------GET-------------------------------------------------------
|
// ----------------------------------GET-------------------------------------------------------
|
||||||
@@ -146,7 +152,8 @@ public class RestTemplateUtil {
|
|||||||
* @return ResponseEntity 响应对象封装类
|
* @return ResponseEntity 响应对象封装类
|
||||||
*/
|
*/
|
||||||
public static <T> ResponseEntity<T> post(String url, Object requestBody, Class<T> responseType) {
|
public static <T> ResponseEntity<T> post(String url, Object requestBody, Class<T> responseType) {
|
||||||
return restTemplate.postForEntity(url, requestBody, responseType);
|
Object actualBody = convertHutoolJsonToStandard(requestBody);
|
||||||
|
return restTemplate.postForEntity(url, actualBody, responseType);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -159,7 +166,8 @@ public class RestTemplateUtil {
|
|||||||
* @return ResponseEntity 响应对象封装类
|
* @return ResponseEntity 响应对象封装类
|
||||||
*/
|
*/
|
||||||
public static <T> ResponseEntity<T> post(String url, Object requestBody, Class<T> responseType, Object... uriVariables) {
|
public static <T> ResponseEntity<T> post(String url, Object requestBody, Class<T> responseType, Object... uriVariables) {
|
||||||
return restTemplate.postForEntity(url, requestBody, responseType, uriVariables);
|
Object actualBody = convertHutoolJsonToStandard(requestBody);
|
||||||
|
return restTemplate.postForEntity(url, actualBody, responseType, uriVariables);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -172,7 +180,21 @@ public class RestTemplateUtil {
|
|||||||
* @return ResponseEntity 响应对象封装类
|
* @return ResponseEntity 响应对象封装类
|
||||||
*/
|
*/
|
||||||
public static <T> ResponseEntity<T> post(String url, Object requestBody, Class<T> responseType, Map<String, ?> uriVariables) {
|
public static <T> ResponseEntity<T> post(String url, Object requestBody, Class<T> responseType, Map<String, ?> uriVariables) {
|
||||||
return restTemplate.postForEntity(url, requestBody, responseType, uriVariables);
|
Object actualBody = convertHutoolJsonToStandard(requestBody);
|
||||||
|
return restTemplate.postForEntity(url, actualBody, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Object convertHutoolJsonToStandard(Object requestBody) {
|
||||||
|
if (requestBody instanceof JSONObject || requestBody instanceof JSONArray) {
|
||||||
|
try {
|
||||||
|
com.fasterxml.jackson.databind.ObjectMapper objectMapper = new com.fasterxml.jackson.databind.ObjectMapper();
|
||||||
|
return objectMapper.readValue(JSONUtil.toJsonStr(requestBody), Object.class);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("Hutool JSON转标准结构失败,尝试直接使用字符串", e);
|
||||||
|
return requestBody;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return requestBody;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -263,6 +285,24 @@ public class RestTemplateUtil {
|
|||||||
return restTemplate.exchange(url, HttpMethod.POST, requestEntity, responseType, uriVariables);
|
return restTemplate.exchange(url, HttpMethod.POST, requestEntity, responseType, uriVariables);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public <T> ResponseEntity<T> post(String url, Object requestBody, HttpHeaders headers, Class<T> responseType) {
|
||||||
|
try {
|
||||||
|
if (headers == null) {
|
||||||
|
headers = new HttpHeaders();
|
||||||
|
}
|
||||||
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
|
||||||
|
HttpEntity<Object> entity = new HttpEntity<>(requestBody, headers);
|
||||||
|
log.info("发送POST请求到: {}", url);
|
||||||
|
ResponseEntity<T> response = restTemplate.postForEntity(url, entity, responseType);
|
||||||
|
log.info("POST请求响应状态: {}", response.getStatusCode());
|
||||||
|
return response;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("POST请求异常: {}", e.getMessage(), e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------PUT-------------------------------------------------------
|
// ----------------------------------PUT-------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -60,6 +60,7 @@
|
|||||||
<artifactId>pqs-influx</artifactId>
|
<artifactId>pqs-influx</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -51,6 +51,13 @@ public interface CommTerminalGeneralClient {
|
|||||||
@PostMapping("deptGetLine")
|
@PostMapping("deptGetLine")
|
||||||
HttpResult<List<DeptGetChildrenMoreDTO>> deptGetLine(@RequestBody @Validated DeptGetLineParam deptGetLineParam);
|
HttpResult<List<DeptGetChildrenMoreDTO>> deptGetLine(@RequestBody @Validated DeptGetLineParam deptGetLineParam);
|
||||||
|
|
||||||
|
@PostMapping("deptGetLineInfo")
|
||||||
|
HttpResult<List<MonitorCommLedgerInfoDTO>> deptGetLineInfo(@RequestBody @Validated DeptGetLineParam deptGetLineParam);
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("deptGetAllLine")
|
||||||
|
HttpResult<List<DeptGetChildrenMoreDTO>> deptGetAllLine(@RequestBody @Validated DeptGetLineParam deptGetLineParam);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据单位获取所有变电站
|
* 根据单位获取所有变电站
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import com.njcn.device.biz.utils.DeviceEnumUtil;
|
|||||||
import feign.hystrix.FallbackFactory;
|
import feign.hystrix.FallbackFactory;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -50,6 +51,19 @@ public class CommTerminalGeneralClientFallbackFactory implements FallbackFactory
|
|||||||
throw new BusinessException(finalExceptionEnum);
|
throw new BusinessException(finalExceptionEnum);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HttpResult<List<MonitorCommLedgerInfoDTO>> deptGetLineInfo(DeptGetLineParam deptGetLineParam) {
|
||||||
|
log.error("{}异常,降级处理,异常为:{}", "根据部门获取监测点信息", throwable.toString());
|
||||||
|
throw new BusinessException(finalExceptionEnum);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HttpResult<List<DeptGetChildrenMoreDTO>> deptGetAllLine(DeptGetLineParam deptGetLineParam) {
|
||||||
|
log.error("{}异常,降级处理,异常为:{}", "根据单位获取all监测点信息", throwable.toString());
|
||||||
|
throw new BusinessException(finalExceptionEnum);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HttpResult<List<DeptGetSubStationDTO>> deptSubStation(DeptGetLineParam deptGetLineParam) {
|
public HttpResult<List<DeptGetSubStationDTO>> deptSubStation(DeptGetLineParam deptGetLineParam) {
|
||||||
log.error("{}异常,降级处理,异常为:{}", "根据单位获取所有变电站", throwable.toString());
|
log.error("{}异常,降级处理,异常为:{}", "根据单位获取所有变电站", throwable.toString());
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ public enum DeviceResponseEnum {
|
|||||||
|
|
||||||
DEVICE_SAME_NAME("A0290","设备名称已存在"),
|
DEVICE_SAME_NAME("A0290","设备名称已存在"),
|
||||||
DEVICE_REPETITION("A0291","设备名称重复"),
|
DEVICE_REPETITION("A0291","设备名称重复"),
|
||||||
|
MODEL_NAME_REPEAT("A00350","名称不可重复"),
|
||||||
DEVICE_IP_REPETITION("A0292","设备ip端口号重复"),
|
DEVICE_IP_REPETITION("A0292","设备ip端口号重复"),
|
||||||
DEVICE_SAME_IP("A0293","当前设备ip端口号已存在"),
|
DEVICE_SAME_IP("A0293","当前设备ip端口号已存在"),
|
||||||
DEVICE_EMPTY("A0294","设备为空"),
|
DEVICE_EMPTY("A0294","设备为空"),
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.njcn.device.biz.mapper;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.njcn.device.biz.pojo.po.Overlimit;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* Mapper 接口
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author xy
|
||||||
|
* @since 2022-01-04
|
||||||
|
*/
|
||||||
|
@DS("sjzx")
|
||||||
|
@Mapper
|
||||||
|
public interface OverLimitWlMapper extends BaseMapper<Overlimit> {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user