高级算法 部分

This commit is contained in:
njcn_dhj
2022-08-26 14:24:42 +08:00
parent fda3b2c172
commit 8dda0820d5
22 changed files with 862 additions and 92 deletions

10
pom.xml
View File

@@ -3,7 +3,6 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!--灿能微服务生态系统-->
<groupId>com.njcn</groupId>
<artifactId>pqs</artifactId>
@@ -21,6 +20,7 @@
<module>pqs-job</module>
<module>pqs-job/job-api</module>
<module>pqs-quality</module>
<module>pqs-advance</module>
</modules>
<packaging>pom</packaging>
<name>灿能微服务生态系统</name>
@@ -40,12 +40,12 @@
<!--中间件目标地址-->
<middle.server.url>192.168.1.13</middle.server.url>
<!--微服务模块发布地址-->
<service.server.url>192.168.1.111</service.server.url>
<service.server.url>192.168.1.130</service.server.url>
<!--nacos的ip:port-->
<nacos.url>${middle.server.url}:18848</nacos.url>
<!--服务器发布内容为空-->
<!-- <nacos.namespace></nacos.namespace>-->
<nacos.namespace>fd74182b-1fce-4dba-afa7-2623b0376205</nacos.namespace>
<nacos.namespace>722a16dc-6988-419e-96e9-de885508296b</nacos.namespace>
<!--sentinel:port-->
<!-- <sentinel.url>192.168.1.14:8080</sentinel.url>-->
<sentinel.url>${middle.server.url}:8080</sentinel.url>
@@ -93,7 +93,6 @@
<mqtt.version>1.2.7</mqtt.version>
<easypoi.version>4.4.0</easypoi.version>
</properties>
<dependencyManagement>
<dependencies>
<!--三剑客依赖******start-->
@@ -291,7 +290,6 @@
<artifactId>xxl-job-core</artifactId>
<version>${xxl-job.version}</version>
</dependency>
<dependency>
<groupId>com.github.tocrhz</groupId>
<artifactId>mqtt-spring-boot-starter</artifactId>
@@ -304,7 +302,6 @@
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
@@ -316,7 +313,6 @@
<addResources>true</addResources>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>pqs-advance</artifactId>
<groupId>com.njcn</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>advance-api</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
</project>

View File

@@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>pqs-advance</artifactId>
<groupId>com.njcn</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<dependencies>
<dependency>
<groupId>com.njcn</groupId>
<artifactId>common-web</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.njcn</groupId>
<artifactId>common-swagger</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.njcn</groupId>
<artifactId>event-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.njcn</groupId>
<artifactId>device-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.njcn</groupId>
<artifactId>system-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.njcn</groupId>
<artifactId>user-api</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.njcn</groupId>
<artifactId>common-influxDB</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
<artifactId>advance-boot</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<build>
<finalName>advanceboot</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<compilerArgument>-Xlint:unchecked</compilerArgument>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<!--执行mvn package,即执行 mvn clean package docker:build-->
<execution>
<id>build-image</id>
<phase>${docker.operate}</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
<configuration>
<!--<serverId>36dockerHarbor</serverId>-->
<registryUrl>http://${docker.repostory}</registryUrl>
<!-- 镜像名称 -->
<imageName>${docker.repostory}/${docker.registry.name}/${project.artifactId}</imageName>
<!-- 指定标签 -->
<imageTags>
<imageTag>latest</imageTag>
</imageTags>
<!-- 指定远程 Docker API地址 -->
<dockerHost>${docker.url}</dockerHost>
<dockerDirectory>${basedir}/</dockerDirectory>
<!-- 复制 jar包到docker容器指定目录-->
<resources>
<resource>
<targetPath>/ROOT</targetPath>
<!-- 用于指定需要复制的根目录,${project.build.directory}表示target目录 -->
<directory>${project.build.directory}</directory>
<!-- 用于指定需要复制的文件,${project.build.finalName}.jar就是打包后的target目录下的jar包名称 -->
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,22 @@
package com.njcn.advance;
/**
* @author denghuajun
* @version 1.0.0
* @date 2022年08月18日 09:33
*/
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
@Slf4j
@MapperScan("com.njcn.**.mapper")
@EnableFeignClients(basePackages = "com.njcn")
@SpringBootApplication(scanBasePackages = "com.njcn")
public class
AdvanceBootApplication {
public static void main(String[] args) {
SpringApplication.run(AdvanceBootApplication.class, args);
}
}

View File

@@ -0,0 +1,53 @@
#当前服务的基本信息
microservice:
ename: @artifactId@
name: '@name@'
version: @version@
sentinel:
url: @sentinel.url@
gateway:
url: @gateway.url@
server:
port: 10210
#feign接口开启服务熔断降级处理
feign:
sentinel:
enabled: true
spring:
application:
name: @artifactId@
#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.advance.pojo
mqtt:
client-id: @artifactId@${random.value}

24
pqs-advance/pom.xml Normal file
View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>pqs</artifactId>
<groupId>com.njcn</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>pqs-advance</artifactId>
<packaging>pom</packaging>
<modules>
<module>advance-api</module>
<module>advance-boot</module>
</modules>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
</project>

View File

@@ -0,0 +1,27 @@
package com.njcn.device.pojo.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* @author denghuajun
* @version 1.0.0
* @date 2022年08月15日 14:03
*/
@Data
public class AbnomalCommuncateVO implements Serializable {
@ApiModelProperty("年份")
private String year;
@ApiModelProperty("月份")
private String month;
@ApiModelProperty("日期")
private String day;
@ApiModelProperty("异常次数")
private String abnormalTimes;
}

View File

@@ -0,0 +1,25 @@
package com.njcn.device.pojo.vo;
import com.njcn.common.pojo.constant.PatternRegex;
import com.njcn.device.pojo.param.DeviceInfoParam;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.Pattern;
import java.io.Serializable;
import java.util.List;
/**
* @author denghuajun
* @date 2022/8/14
*
*/
@Data
public class DeviceAbnormalVO implements Serializable {
@ApiModelProperty("是否有下级")
private Boolean isPid;
@ApiModelProperty("数值")
private List<AbnomalCommuncateVO> data;
}

View File

@@ -21,6 +21,9 @@ public class DeviceOnlineDataVO implements Serializable {
@ApiModelProperty("")
private String month;
@ApiModelProperty("")
private String day;
@ApiModelProperty("在线率")
private Float onlineRate;
}

View File

@@ -97,5 +97,14 @@ public class OperationContrController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/getComunicateStatics")
@ApiOperation("获取中断异常统计")
@ApiImplicitParam(name = "conditionBusinessParam", value = "实体", required = true)
public HttpResult<DeviceAbnormalVO> getComunicateStatics(@RequestBody @Validated DeviceInfoParam.ConditionBusinessParam conditionBusinessParam) {
String methodDescribe = getMethodDescribe("getComunicateStatics");
DeviceAbnormalVO result = lineService.getComunicateStatics(conditionBusinessParam);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
}

View File

@@ -141,5 +141,11 @@ public interface LineService {
*/
List<Line> getBaseLineList(List<String> lineIndex);
/**
* 获取终端异常数据
* @param deviceInfoParam 参数
* @return 结果
*/
DeviceAbnormalVO getComunicateStatics(DeviceInfoParam.ConditionBusinessParam deviceInfoParam);
}

View File

@@ -23,6 +23,8 @@ import com.njcn.device.pojo.param.DeviceInfoParam;
import com.njcn.device.pojo.po.*;
import com.njcn.device.pojo.vo.*;
import com.njcn.device.service.LineService;
import com.njcn.device.utils.PublicDateUtil;
import com.njcn.event.pojo.po.EventDetail;
import com.njcn.influxdb.param.InfluxDBPublicParam;
import com.njcn.influxdb.utils.InfluxDbUtils;
import com.njcn.system.api.AreaFeignClient;
@@ -42,7 +44,6 @@ import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@@ -73,8 +74,6 @@ public class LineServiceImpl extends ServiceImpl<LineMapper, Line> implements Li
private final SubstationMapper substationMapper;
private final CommunicateMapper communicateMapper;
private final GeneralDeviceService generalDeviceService;
private final LineMapper lineMapper;
@@ -260,7 +259,6 @@ public class LineServiceImpl extends ServiceImpl<LineMapper, Line> implements Li
List<GeneralDeviceDTO> generalDeviceDTOList = generalDeviceService.getDeviceInfo(deviceInfoParam, Stream.of(0).collect(Collectors.toList()), Stream.of(1).collect(Collectors.toList()));
for (GeneralDeviceDTO generalDeviceDTO : generalDeviceDTOList) {
//根据部门id去获取省份信息
Area area = areaFeignClient.areaDeptPro(generalDeviceDTO.getIndex()).getData();
LineDistributionVO lineDistributionVO = new LineDistributionVO();
lineDistributionVO.setName(generalDeviceDTO.getName());
lineDistributionVO.setValue(generalDeviceDTO.getLineIndexes().size());
@@ -672,4 +670,215 @@ public class LineServiceImpl extends ServiceImpl<LineMapper, Line> implements Li
return this.list(lambdaQueryWrapper);
}
@SneakyThrows
@Override
public DeviceAbnormalVO getComunicateStatics(DeviceInfoParam.ConditionBusinessParam conditionBusinessParam) {
DeviceAbnormalVO deviceAbnormalVO = new DeviceAbnormalVO();
//获取所有监测点
List<GeneralDeviceDTO> generalDeviceDTOList = generalDeviceService.getDeviceInfo(conditionBusinessParam, null, Stream.of(1).collect(Collectors.toList()));
List<String> lineIndexs = generalDeviceDTOList.stream().flatMap(dto -> dto.getLineIndexes().stream()).collect(Collectors.toList());
if (conditionBusinessParam.getTimeFlag() == 0) {
List<String> intervalTime = this.getIntervalTime(conditionBusinessParam.getSearchBeginTime(), conditionBusinessParam.getSearchEndTime());
List<AbnomalCommuncateVO> abnomalCommuncateVOS = new ArrayList<>();
deviceAbnormalVO.setIsPid(true);
for (String interTime : intervalTime) {
System.out.println(lineIndexs);
AbnomalCommuncateVO inter = new AbnomalCommuncateVO();
String startTime, endTime;
inter.setMonth(interTime.substring(5));
inter.setYear(interTime.substring(0, 4));
startTime = PublicDateUtil.getFisrtDayOfMonth(Integer.parseInt(interTime.substring(0,4)),Integer.parseInt (interTime.substring(5)));
endTime = PublicDateUtil.getLastDayOfMonth(Integer.parseInt(interTime.substring(0,4)),Integer.parseInt(interTime.substring(5)));
List<Communicate> communicateList = getCommunicateAbnorm(lineIndexs,startTime,endTime);
inter.setDay("/");
if (communicateList.size()==0){
inter.setAbnormalTimes("3.14159");
}else {
inter.setAbnormalTimes(String.valueOf(communicateList.size()));
}
abnomalCommuncateVOS.add(inter);
}
deviceAbnormalVO.setData(abnomalCommuncateVOS);
} else {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date dt = simpleDateFormat.parse(conditionBusinessParam.getSearchBeginTime());
Date dtDate = simpleDateFormat.parse(conditionBusinessParam.getSearchEndTime());
Integer year = Integer.valueOf(String.format("%tY", dt));
Integer mon = Integer.valueOf(String.format("%tm", dt));
Integer day = Integer.valueOf(String.format("%td", dtDate));
List<String> intervalTime = this.getIntervalDateTime(year, mon,day);
List<AbnomalCommuncateVO> abnomalCommuncateVOS = new ArrayList<>();
deviceAbnormalVO.setIsPid(false);
for (String interTime : intervalTime) {
AbnomalCommuncateVO inter = new AbnomalCommuncateVO();
String startTime, endTime;
inter.setMonth(interTime.substring(5,7));
inter.setYear(interTime.substring(0, 4));
inter.setDay(interTime.substring(8));
startTime = sdf.format(DateUtil.beginOfDay(DateUtil.parse(interTime)));
endTime = sdf.format(DateUtil.endOfDay(DateUtil.parse(interTime)));
List<Communicate> communicateList = getCommunicateAbnorm(lineIndexs,startTime,endTime);
if (communicateList.size()==0){
inter.setAbnormalTimes("3.14159");
}else {
inter.setAbnormalTimes(String.valueOf(communicateList.size()));
}
abnomalCommuncateVOS.add(inter);
}
deviceAbnormalVO.setData(abnomalCommuncateVOS);
}
return deviceAbnormalVO;
}
/**
* 根据用户选择的时间区间返回月份日期
*/
@SneakyThrows
private List<String> getIntervalTime(String startTime, String endTime) {
List<String> times = new ArrayList<>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
Date start = sdf.parse(startTime);
Date end = sdf.parse(endTime);
// 同月
if (start.getTime() == end.getTime()) {
String time = startTime.substring(0, 7);
times.add(time);
} else if (start.getYear() == end.getYear()) {
// 同年
int startM = start.getMonth() + 1;
int endM = end.getMonth() + 1;
int temp = endM - startM;
for (int i = 0; i <= temp; i++) {
String time = start.getYear() + 1900 + "";
int month = startM + i;
if (month < 10) {
time = time + "-0" + month;
} else {
time = time + "-" + month;
}
times.add(time);
}
} else {
// 不同年!!!!这里忽略了年份之间跨年的情况
int startY = start.getYear() + 1900;
int startM = start.getMonth() + 1;
int endY = end.getYear() + 1900;
int endM = end.getMonth() + 1;
int tempS = 12 - startM;
// 连续的年份
if (endY - startY == 1) {
// 第一年的时间获取
for (int i = 0; i <= tempS; i++) {
int month = startM + i;
String time = startY + "-";
if (month < 10) {
time = time + "0" + month;
} else {
time = time + month;
}
times.add(time);
}
// 第二年的时间获取
for (int i = 1; i <= endM; i++) {
String time = endY + "-";
if (i < 10) {
time = time + "0" + i;
} else {
time = time + i;
}
times.add(time);
}
} else {
// 不连续的年份
// 第一年的时间获取
for (int i = 0; i <= tempS; i++) {
int month = startM + i;
String time = startY + "-";
if (month < 10) {
time = time + "0" + month;
} else {
time = time + month;
}
times.add(time);
}
int tempY = endY - startY;
// 中间年份的时间
for (int i = 1; i < tempY; i++) {
for (int j = 1; j <= 12; j++) {
String time = startY + i + "-";
if (j < 10) {
time = time + "0" + j;
} else {
time = time + j;
}
times.add(time);
}
}
// 最后一年的时间获取
for (int i = 1; i <= endM; i++) {
String time = endY + "-";
if (i < 10) {
time = time + "0" + i;
} else {
time = time + i;
}
times.add(time);
}
}
}
return times;
}
@SneakyThrows
private List<String> getIntervalDateTime(Integer startTime, Integer endTime,Integer dd) {
List<String> list = new ArrayList<>();
Calendar calendar = Calendar.getInstance(Locale.CHINA);
calendar.set(startTime, endTime - 1, 1);
int year = calendar.get(Calendar.YEAR);//年份
int month = calendar.get(Calendar.MONTH) + 1;//月份
for (int i = 1; i <= dd; i++) {
String date = null;
if (month < 10 && i < 10) {
date = year + "-0" + month + "-0" + i;
}
if (month < 10 && i >= 10) {
date = year + "-0" + month + "-" + i;
}
if (month >= 10 && i < 10) {
date = year + "-" + month + "-0" + i;
}
if (month >= 10 && i >= 10) {
date = year + "-" + month + "-" + i;
}
list.add(date);
}
return list;
}
public List<Communicate> getCommunicateAbnorm(List<String> lineIndex, String startTime, String endTime) {
//组装sql语句
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("time >= '").append(DateUtil.beginOfDay(DateUtil.parse(startTime))).append("' and ").append("time <= '").append(DateUtil.endOfDay(DateUtil.parse(endTime))).append("' and ");
stringBuilder.append("(");
for (int i = 0; i < lineIndex.size(); i++) {
if (lineIndex.size() - i != 1) {
stringBuilder.append("line_id = '").append(lineIndex.get(i)).append("' or ");
} else {
stringBuilder.append("line_id = '").append(lineIndex.get(i)).append("')");
}
}
stringBuilder.append("and type = 0").append(" group by line_id ").append(InfluxDBPublicParam.TIME_ZONE);
String sql = "select * from " + InfluxDBPublicParam.PQS_COMMUNICATE + " where " + stringBuilder.toString();
QueryResult result = influxDbUtils.query(sql);
InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper();
List<Communicate> communicateList = influxDBResultMapper.toPOJO(result, Communicate.class);
return communicateList;
}
}

View File

@@ -42,6 +42,11 @@
<groupId>org.influxdb</groupId>
<artifactId>influxdb-java</artifactId>
</dependency>
<dependency>
<groupId>com.sun.jna</groupId>
<artifactId>jna</artifactId>
<version>3.0.9</version>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,41 @@
package com.njcn.event.pojo.po;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* @author denghuajun
* @version 1.0.0
* @date 2022年08月18日 13:42
* 电压区域综合评估基本类
*/
@Data
public class BalanceInfo implements Serializable {
@Data
public class PointInfo {
private Integer pointId;
private String pointName;
private QtIdx qtIdx;
private float civ;
private int l;
public PointInfo() {
super();
qtIdx = new QtIdx();
}
}
@ApiModelProperty("区域的index")
private String areaIndex;
@ApiModelProperty("区域名称")
private String areaName;
@ApiModelProperty("系统最终的评估分")
private float ci;
@ApiModelProperty("监测点的详细信息")
private List<PointInfo> list;
@ApiModelProperty("标识是否经过计算默认为0-未计算1-计算")
private int isCount;
}

View File

@@ -0,0 +1,50 @@
package com.njcn.event.pojo.po;
import com.sun.jna.Structure;
import io.swagger.annotations.ApiModelProperty;
import java.util.List;
/**
* @author denghuajun
* @version 1.0.0
* @date 2022年08月18日 13:45
* //单个监测点的暂降事件计算评价指标
*/
public class QtIdx extends Structure {
@ApiModelProperty("暂降幅值")
public float r_esm;
@ApiModelProperty("sarifi-90")
public int sarfi_90;
@ApiModelProperty("sarifi-50")
public int sarifi_50;
@ApiModelProperty("暂降能量")
public float r_asei;
@ApiModelProperty("严重程度")
public float r_assi;
public static class ByReference extends QtIdx implements Structure.ByReference {
}
public static class ByValue extends QtIdx implements Structure.ByValue {
}
@Override
protected List getFieldOrder() {
return null;
}
@Override
public boolean equals(Object obj) {
if (obj == null || !(obj instanceof QtIdx))
return false;
if (this == obj)
return true;
QtIdx instance = (QtIdx) obj;
return (r_esm == instance.r_esm) && (sarfi_90 == instance.sarfi_90) && (sarifi_50 == instance.sarifi_50) && (r_asei == instance.r_asei) && (r_assi == instance.r_assi);
}
}

View File

@@ -0,0 +1,18 @@
package com.njcn.event.pojo.po;
import lombok.Data;
import java.io.Serializable;
/**
* @author denghuajun
* @version 1.0.0
* @date 2022年08月19日 11:10
*/
@Data
public class Sarifi implements Serializable {
private Float sarifiValue;
private Float time;
private Float pt1;
private Float pt2;
}

View File

@@ -7,6 +7,7 @@ import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.common.utils.LogUtil;
import com.njcn.device.pojo.param.DeviceInfoParam;
import com.njcn.event.pojo.po.BalanceInfo;
import com.njcn.event.pojo.vo.AreaLineVO;
import com.njcn.event.pojo.vo.EventHeatMapVO;
import com.njcn.event.pojo.vo.EventSeverityVO;
@@ -24,6 +25,8 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* @author denghuajun
* @version 1.0.0
@@ -107,4 +110,21 @@ public class AreaController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
/**
* 获取暂降严重度
*
* @param deviceInfoParam 参数
* @return 结果
*/
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/getBalanceInfo")
@ApiOperation("获取区域暂降综合评估")
@ApiImplicitParam(name = "deviceInfoParam", value = "参数", required = true)
public HttpResult<List<BalanceInfo>> getBalanceInfo(@RequestBody @Validated DeviceInfoParam.BusinessParam deviceInfoParam) {
String methodDescribe = getMethodDescribe("getBalanceInfo");
LogUtil.njcnDebug(log, "{},参数为:{}", methodDescribe, deviceInfoParam);
List<BalanceInfo> result = areaLineService.getBalanceInfo(deviceInfoParam);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
}

View File

@@ -2,6 +2,7 @@ package com.njcn.event.service;
import com.njcn.device.pojo.param.DeviceInfoParam;
import com.njcn.event.pojo.po.BalanceInfo;
import com.njcn.event.pojo.vo.*;
import java.util.List;
@@ -42,4 +43,11 @@ public interface AreaLineService {
*/
TerminalRunningStatisticsVO getTerminalRunningStatistics(DeviceInfoParam.BusinessParam deviceInfoParam);
/**
* 获取区域暂降综合评估
* @param deviceInfoParam 参数
* @return 结果
*/
List<BalanceInfo> getBalanceInfo(DeviceInfoParam.BusinessParam deviceInfoParam);
}

View File

@@ -8,19 +8,22 @@ import com.njcn.device.api.GeneralDeviceInfoClient;
import com.njcn.device.api.LineFeignClient;
import com.njcn.device.pojo.dto.GeneralDeviceDTO;
import com.njcn.device.pojo.param.DeviceInfoParam;
import com.njcn.device.pojo.vo.LineDetailDataVO;
import com.njcn.device.pojo.vo.LineDetailVO;
import com.njcn.device.pojo.vo.LineDeviceStateVO;
import com.njcn.device.pojo.vo.SubstationDetailVO;
import com.njcn.event.influxdb.PqsOnlinerateQuery;
import com.njcn.event.mapper.PqDeviceMapper;
import com.njcn.event.pojo.po.PqDevice;
import com.njcn.event.pojo.po.PqsOnlinerate;
import com.njcn.event.pojo.po.*;
import com.njcn.event.pojo.vo.*;
import com.njcn.event.pojo.vo.TerminalRunningStatisticsVO.TerminalRunningInfoVO;
import com.njcn.event.pojo.vo.TerminalRunningStatisticsVO.TerminalRunningVO;
import com.njcn.event.service.AreaLineService;
import com.njcn.event.service.EventDetailService;
import com.njcn.influxdb.param.InfluxDBPublicParam;
import com.njcn.influxdb.utils.InfluxDbUtils;
import com.njcn.system.pojo.enums.StatisticsEnum;
import com.sun.org.apache.regexp.internal.RE;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.influxdb.dto.QueryResult;
@@ -37,6 +40,8 @@ import java.util.stream.Collectors;
import static com.njcn.event.influxdb.PqsOnlinerateQuery.devIdOr;
import static com.njcn.event.influxdb.QueryBuilder.*;
import com.njcn.event.pojo.po.BalanceInfo.PointInfo;
/**
* @author denghuajun
* @version 1.0.0
@@ -57,6 +62,8 @@ public class AreaLineServiceImpl implements AreaLineService {
private final PqDeviceMapper pqDeviceMapper;
private final EventDetailService eventDetailService;
@Override
public AreaLineVO getAreaLineVO(DeviceInfoParam deviceInfoParam) {
AreaLineVO areaLineVO = new AreaLineVO();
@@ -241,6 +248,45 @@ public class AreaLineServiceImpl implements AreaLineService {
return TerminalRunningStatisticsVO.buildVO(area, factory);
}
@Override
public List<BalanceInfo> getBalanceInfo(DeviceInfoParam.BusinessParam deviceInfoParam) {
List<BalanceInfo> balanceInfos = new ArrayList<>();
//获取符合条件的监测点
List<GeneralDeviceDTO> generalDeviceDTOList = generalDeviceInfoClient.getPracticalAllDeviceInfo(deviceInfoParam).getData();
if (CollUtil.isEmpty(generalDeviceDTOList)) {
return balanceInfos;
}
for (GeneralDeviceDTO generalDeviceDTO : generalDeviceDTOList) {
BalanceInfo balanceInfo = new BalanceInfo();
balanceInfo.setAreaName(generalDeviceDTO.getName());
balanceInfo.setAreaIndex(generalDeviceDTO.getIndex());
//监测点
List<String> lineList = generalDeviceDTO.getLineIndexes();
List<PointInfo> list = new ArrayList<>();
for (String lineIndex : lineList) {
PointInfo pointInfo = balanceInfo.new PointInfo();
Float value = getSarfiValue(deviceInfoParam.getSearchBeginTime(), deviceInfoParam.getSearchEndTime(), 0.9f, lineIndex);
pointInfo.getQtIdx().r_esm = (value == null ? 0f : value);
pointInfo.getQtIdx().sarfi_90 = getSarfiCount(deviceInfoParam.getSearchBeginTime(), deviceInfoParam.getSearchEndTime(), 0.9f, lineIndex); // 统计小于0.9的总数
pointInfo.getQtIdx().sarifi_50 = getSarfiCount(deviceInfoParam.getSearchBeginTime(), deviceInfoParam.getSearchEndTime(), 0.5f, lineIndex); // 统计小于0.9的总数 // 统计小于0.5的总数
//获取当前监测点的暂降信息
List<EventDetail> eventDetailList = getEventDetailInfo(lineIndex, 0.9f, deviceInfoParam.getSearchBeginTime(), deviceInfoParam.getSearchEndTime());
if(eventDetailList.size()>0) {
//获取监测点信息
LineDetailDataVO lineDetailVO = lineFeignClient.getLineDetailData(lineIndex).getData();
List<Sarifi> sarifis = new ArrayList<>();
for (EventDetail eventDetail:eventDetailList){
Sarifi sarifi = new Sarifi();
sarifi.setTime(eventDetail.getPersistTime().floatValue());
}
}
}
}
return balanceInfos;
}
private TerminalRunningVO analyzeTerminalRun(DeviceInfoParam.BusinessParam deviceInfoParam) {
List<GeneralDeviceDTO> generalDeviceDTOList = generalDeviceInfoClient.getPracticalAllDeviceInfo(deviceInfoParam).getData();
@@ -366,4 +412,69 @@ public class AreaLineServiceImpl implements AreaLineService {
List<EventHeatDeatilVO> eventdetailList = influxDBResultMapper.toPOJO(result, EventHeatDeatilVO.class);
return eventdetailList;
}
public Float getSarfiValue(String startTime, String endTime, Float fvalue, String id) {
Float retList = 0f;
//组装sql语句
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("time >= '").append(DateUtil.beginOfDay(DateUtil.parse(startTime))).append("' and ").append("time <= '").append(DateUtil.endOfDay(DateUtil.parse(endTime))).append("' and ");
stringBuilder.append("line_id = '").append(id).append("'").append(" and event_value <=").append(fvalue).append(InfluxDBPublicParam.TIME_ZONE);
String sql = "select mean(event_value) from " + InfluxDBPublicParam.PQS_EVENT_DETAIL + " where " + stringBuilder.toString();
QueryResult queryResult = influxDbUtils.query(sql);
List<QueryResult.Result> results = queryResult.getResults();
if (results == null || results.isEmpty()) {
return retList;
}
QueryResult.Result result = results.get(0);
List<QueryResult.Series> seriess = result.getSeries();
if (seriess == null || seriess.isEmpty()) {
return retList;
}
QueryResult.Series series = seriess.get(0);
List<List<Object>> values = series.getValues();
for (List<Object> columnValue : values) {
retList = BigDecimal.valueOf(Float.parseFloat(columnValue.get(1).toString())).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
}
return retList;
}
public Integer getSarfiCount(String startTime, String endTime, Float fvalue, String id) {
Integer retList = 0;
//组装sql语句
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("time >= '").append(DateUtil.beginOfDay(DateUtil.parse(startTime))).append("' and ").append("time <= '").append(DateUtil.endOfDay(DateUtil.parse(endTime))).append("' and ");
stringBuilder.append("line_id = '").append(id).append("'").append(" and event_value <=").append(fvalue).append(" and persist_time<6000").append(InfluxDBPublicParam.TIME_ZONE);
String sql = "select count(*) from " + InfluxDBPublicParam.PQS_EVENT_DETAIL + " where " + stringBuilder.toString();
QueryResult queryResult = influxDbUtils.query(sql);
List<QueryResult.Result> results = queryResult.getResults();
if (results == null || results.isEmpty()) {
return retList;
}
QueryResult.Result result = results.get(0);
List<QueryResult.Series> seriess = result.getSeries();
if (seriess == null || seriess.isEmpty()) {
return retList;
}
QueryResult.Series series = seriess.get(0);
List<List<Object>> values = series.getValues();
for (List<Object> columnValue : values) {
retList = (Integer) columnValue.get(1);
}
return retList;
}
public List<EventDetail> getEventDetailInfo(String id, Float fvalue, String startTime, String endTime) {
//组装sql语句
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("time >= '").append(DateUtil.beginOfDay(DateUtil.parse(startTime))).append("' and ").append("time <= '").append(DateUtil.endOfDay(DateUtil.parse(endTime))).append("' and ");
//sql语句
stringBuilder.append("line_id ='").append(id).append("'").append(" and event_value <=").append(fvalue).append(" and persist_time < 60000").append(" tz('Asia/Shanghai')");
String sql = "select * from pqs_eventdetail where " + stringBuilder;
//获取暂降事件
QueryResult result = influxDbUtils.query(sql);
InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper();
List<EventDetail> eventDetailList = influxDBResultMapper.toPOJO(result, EventDetail.class);
return eventDetailList;
}
}