合并暂降模块代码

This commit is contained in:
2022-07-14 09:43:29 +08:00
parent 014c766806
commit 638f5b8f93
56 changed files with 3133 additions and 86 deletions

View File

@@ -64,7 +64,7 @@ public class LogServiceImpl implements ILogService {
userName = RequestUtil.getLoginName(httpServletRequest); userName = RequestUtil.getLoginName(httpServletRequest);
userIndex = userName; userIndex = userName;
} else { } else {
userName = RequestUtil.getUserNickname(request); userName = RequestUtil.getLoginName(request);
userIndex = RequestUtil.getUserIndex(request); userIndex = RequestUtil.getUserIndex(request);
} }
String result = httpResult.getCode().equalsIgnoreCase(CommonResponseEnum.FAIL.getCode()) ? CommonResponseEnum.FAIL.getMessage() : CommonResponseEnum.SUCCESS.getMessage(); String result = httpResult.getCode().equalsIgnoreCase(CommonResponseEnum.FAIL.getCode()) ? CommonResponseEnum.FAIL.getMessage() : CommonResponseEnum.SUCCESS.getMessage();

View File

@@ -11,10 +11,12 @@ import lombok.Getter;
public enum EventResponseEnum { public enum EventResponseEnum {
/** /**
* 谐波模块异常响应码的范围: * 暂降模块异常响应码的范围:
* A00650 ~ A00749 * A00650 ~ A00749
*/ */
HARMONIC_COMMON_ERROR("A00550","谐波模块异常") EVENT_COMMON_ERROR("A00650","暂降模块异常"),
EVENT_NOT_FOUND("A00651","暂降事件或监测点不存在"),
ANALYSEWAVE_NOT_FOUND("A00652","波形文件找不到")
; ;
private final String code; private final String code;

View File

@@ -0,0 +1,10 @@
package com.njcn.event.pojo.constant;
/**
* @author xy
* @date 2021/12/29 15:10
*/
public interface HarmonicValidMessage {
String DATA_NOT_BLANK = "参数不能为空";
}

View File

@@ -0,0 +1,32 @@
package com.njcn.event.pojo.constant;
/**
* @author 徐扬
*/
public interface Param {
/**
* 表名
*/
String EVENT_DETAIL = "pqs_eventdetail";
/**
* 公共字段
*/
String SELECT = "SELECT * FROM ";
String WHERE = " WHERE ";
String TZ_ASIA_SHANGHAI = " tz('Asia/Shanghai')";
/**
* 时间字段
*/
String BEGIN =" 00:00:00";
String END =" 23:59:59";
}

View File

@@ -0,0 +1,31 @@
package com.njcn.event.pojo.param;
import com.njcn.web.pojo.annotation.DateTimeStrValid;
import com.njcn.web.pojo.param.BaseParam;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
/**
* pqs-event
*
* @author cdf
* @date 2022/6/23
*/
@Data
@ApiModel
public class EventBaseParam extends BaseParam implements Serializable {
private static final long serialVersionUID = 1L;
@NotBlank(message = "监测点索引不可为空")
@ApiModelProperty(name = "lineId", value = "监测点索引")
private String lineId;
}

View File

@@ -0,0 +1,25 @@
package com.njcn.event.pojo.param;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
* @version 1.0.0
* @author: chenchao
* @date: 2022/07/07 12:41
*/
@Data
public class WaveFileParam {
@ApiModelProperty("lineId集合")
@NotNull(message = "lineId不可为空")
private List<String> lineId;
@ApiModelProperty("timeId集合")
@NotNull(message = "timeId不可为空")
private List<String> timeId;
}

View File

@@ -0,0 +1,110 @@
package com.njcn.event.pojo.po;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* 装置信息表
*
* @author : zhaojun
* @version : 1.0.0
* @date : 2020年07月07日 9:38
*/
@Data
public class PqDevice implements Serializable {
private static final long serialVersionUID = -85938859401219960L;
/**
* 装置序号
*/
private String id;
/**
* 装置模型0虚拟设备1实际设备2离线设备默认是实际设备
*/
private Integer devModel;
/**
* 数据类型0暂态系统1稳态系统2两个系统
*/
private Integer devDataType;
/**
* 终端运行状态0投运1热备用2停运
*/
private Integer runFlag;
/**
* 通讯状态0中断1正常
*/
private Integer comFlag;
/**
* 设备制造商,字典表
*/
private String manufacturer;
/**
* 定检状态0未检 1已检
*/
private Integer checkFlag;
/**
* 前置类型MMS、CLD字典表
*/
private String frontType;
/**
* 终端型号570、580……字典表
*/
private String devType;
/**
* 网络参数
*/
private String ip;
/**
* 召唤标志0周期触发1变为触发
*/
private Integer callFlag;
/**
* 端口
*/
private Integer port;
/**
* 装置识别码3ds加密
*/
private String series;
/**
* 装置秘钥3ds加密
*/
private String devKey;
/**
* 前置序号Id,前置表
*/
private String nodeId;
/**
* 投运时间
*/
private Date loginTime;
/**
* 数据更新时间
*/
private Date updateTime;
/**
* 本次定检时间,默认等于投运时间
*/
private Date thisTimeCheck;
/**
* 下次定检时间,默认为投运时间后推3年假如时间小于3个月则为待检
*/
private Date nextTimeCheck;
/**
* 电镀功能 0关闭 1开启 默认关闭
*/
private Integer electroplate;
/**
* 对时功能标识符0关闭1开启默认开启
*/
private Integer onTime;
/**
* 合同号
*/
private String contract;
/**
* 装置SIM卡号
*/
private String sim;
}

View File

@@ -0,0 +1,31 @@
package com.njcn.event.pojo.po;
import lombok.Data;
import org.influxdb.annotation.Column;
import org.influxdb.annotation.Measurement;
import java.time.Instant;
/**
* 装置在线率表
*
* @author : zhaojun
* @version : 1.0.0
* @date : 2020年07月07日 9:37
*/
@Data
@Measurement(name = "pqs_onlinerate")
public class PqsOnlinerate {
@Column(name = "time")
private Instant time;
@Column(name = "dev_id")
private String devId;
@Column(name = "offlinemin")
private Integer offlinemin;
@Column(name = "onlinemin")
private Integer onlinemin;
}

View File

@@ -0,0 +1,21 @@
package com.njcn.event.pojo.po;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
/**
* @version 1.0.0
* @author: chenchao
* @date: 2022/06/28 19:41
*/
@Data
@Component
public class WavePath {
@Value("${business.wavePath}")
private String wavePath;
}

View File

@@ -0,0 +1,32 @@
package com.njcn.event.pojo.vo;
import lombok.Data;
import java.util.List;
/**
* pqs-event
* 区域分析
* @author cdf
* @date 2022/6/24
*/
@Data
public class AreaAnalysisVO {
private List<Children> reason;
private List<Children> type;
@Data
public static class Children {
private String name;
private Integer value;
}
}

View File

@@ -0,0 +1,57 @@
package com.njcn.event.pojo.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.Collator;
import java.util.Comparator;
import java.util.Locale;
/**
* 区域统计
*
* @author : zhaojun
* @version : 1.0.0
* @date : 2022年07月08日 8:55
*/
@Data
public class AreaCalculationVO implements Serializable {
private static final long serialVersionUID = 1289723908309235565L;
@ApiModelProperty(name = "areaName", value = "区域名称")
private String areaName;
@ApiModelProperty(name = "monitoringPoints", value = "监测点数")
private Integer monitoringPoints;
@ApiModelProperty(name = "frequency", value = "暂降次数")
private Long frequency;
@ApiModelProperty(name = "sarfi90", value = "SARFI-90")
private Double sarfi9;
/**
* 计算SARFI-90数值
*/
public void computeSarfi90() {
BigDecimal b1 = new BigDecimal(frequency);
BigDecimal b2 = new BigDecimal(monitoringPoints);
if (b1.compareTo(BigDecimal.ZERO) == 0) {
this.sarfi9 = 0.00D;
return;
}
this.sarfi9 = b1.divide(b2, 2, RoundingMode.HALF_UP).doubleValue();
}
public static Comparator<AreaCalculationVO> sortAscAreaName() {
return (o1, o2) -> {
Collator collator = Collator.getInstance(Locale.CHINA);
return collator.compare(o1.getAreaName(), o2.getAreaName());
};
}
}

View File

@@ -0,0 +1,147 @@
package com.njcn.event.pojo.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;
import java.io.Serializable;
import java.util.Collections;
import java.util.List;
/**
* 暂降区域统计信息
*
* @author : zhaojun
* @version : 1.0.0
* @date : 2022年06月24日 11:02
*/
@Data
@Builder
public class AreaStatisticalVO implements Serializable {
private static final long serialVersionUID = -1761181131122017671L;
@ApiModelProperty(name = "areaStatistics", value = "区域统计")
private AreaStatisticsVO areaStatistics;
@ApiModelProperty(name = "voltageStatistics", value = "电压统计")
private VoltageStatisticsVO voltageStatistics;
@ApiModelProperty(name = "monthlyStatistics", value = "月统计")
private MonthlyStatisticsVO monthlyStatistics;
public static AreaStatisticalVO empty() {
return buildVO(AreaStatisticsVO.empty(), VoltageStatisticsVO.empty(), MonthlyStatisticsVO.empty());
}
public static AreaStatisticalVO buildVO(AreaStatisticsVO areaStatistics, VoltageStatisticsVO voltageStatistics,
MonthlyStatisticsVO monthlyStatistics) {
return AreaStatisticalVO.builder()
.areaStatistics(areaStatistics)
.voltageStatistics(voltageStatistics)
.monthlyStatistics(monthlyStatistics)
.build();
}
/**
* 区域统计
*
* @author : zhaojun
* @version : 1.0.0
* @date : 2022年07月08日 8:56
*/
@Data
@Builder
public static class AreaStatisticsVO implements Serializable {
private static final long serialVersionUID = 5966376367805740029L;
@ApiModelProperty(name = "areaCalculation", value = "图表数据")
private List<AreaCalculationVO> areaCalculation;
@ApiModelProperty(name = "frequencySum", value = "总暂降次数")
private Long frequencySum;
@ApiModelProperty(name = "monitoringPointSum", value = "总监测点数")
private Integer monitoringPointSum;
public static AreaStatisticsVO empty() {
return buildVO(0L, 0, Collections.emptyList());
}
public static AreaStatisticsVO buildVO(Long frequencySum, Integer monitoringPointSum,
List<AreaCalculationVO> areaCalculation) {
return AreaStatisticsVO.builder()
.frequencySum(frequencySum)
.monitoringPointSum(monitoringPointSum)
.areaCalculation(areaCalculation)
.build();
}
}
/**
* 电压等级
*
* @author : zhaojun
* @version : 1.0.0
* @date : 2022年07月08日 8:56
*/
@Data
@Builder
public static class VoltageStatisticsVO implements Serializable {
private static final long serialVersionUID = -1529419462716002278L;
@ApiModelProperty(name = "voltageLevelCalculation", value = "图表数据")
private List<VoltageLevelCalculationVO> voltageLevelCalculation;
@ApiModelProperty(name = "frequencySum", value = "总暂降次数")
private Long frequencySum;
@ApiModelProperty(name = "monitoringPointSum", value = "总监测点数")
private Integer monitoringPointSum;
public static VoltageStatisticsVO empty() {
return buildVO(0L, 0, Collections.emptyList());
}
public static VoltageStatisticsVO buildVO(Long frequencySum, Integer monitoringPointSum,
List<VoltageLevelCalculationVO> voltageLevelCalculation) {
return VoltageStatisticsVO.builder()
.frequencySum(frequencySum)
.monitoringPointSum(monitoringPointSum)
.voltageLevelCalculation(voltageLevelCalculation)
.build();
}
}
/**
* 月统计
*
* @author : zhaojun
* @version : 1.0.0
* @date : 2022年07月08日 8:56
*/
@Data
@Builder
public static class MonthlyStatisticsVO implements Serializable {
private static final long serialVersionUID = -1373543779591652398L;
@ApiModelProperty(name = "monthCalculation", value = "图表数据")
private List<MonthCalculationVO> monthCalculation;
@ApiModelProperty(name = "frequencySum", value = "总暂降次数")
private Long frequencySum;
public static MonthlyStatisticsVO empty() {
return buildVO(0L, Collections.emptyList());
}
public static MonthlyStatisticsVO buildVO(Long frequencySum, List<MonthCalculationVO> monthCalculation) {
return MonthlyStatisticsVO.builder()
.frequencySum(frequencySum)
.monthCalculation(monthCalculation)
.build();
}
}
}

View File

@@ -0,0 +1,28 @@
package com.njcn.event.pojo.vo;
import com.njcn.device.pojo.vo.AreaLineInfoVO;
import lombok.Data;
import java.math.BigDecimal;
import java.util.List;
/**
* pqs-event
*
* @author cdf
* @date 2022/7/1
*/
@Data
public class AreaSubLineVO {
private String subName;
private String subId;
private BigDecimal lng;
private BigDecimal lat;
private List<AreaLineInfoVO> children;
}

View File

@@ -0,0 +1,46 @@
package com.njcn.event.pojo.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.influxdb.annotation.Column;
import org.influxdb.annotation.Measurement;
import java.time.LocalDateTime;
/**
* pqs-event
*
* @author cdf
* @date 2022/6/23
*/
@Data
@ApiModel
@Measurement(name = "pqs_eventdetail")
public class EventAnalyseVO {
@ApiModelProperty(name = "time",value = "暂降发生时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime time;
@ApiModelProperty(name = "eventValue",value = "特征幅值")
@Column(name = "event_value")
private Float eventValue;
@ApiModelProperty(name = "persistTime",value = "持续时间ms")
@Column(name = "persist_time")
private Integer persistTime;
@ApiModelProperty(name = "eventType",value = "暂降类型")
@Column(name = "event_type")
private Integer eventType;
@ApiModelProperty(name = "eventReason",value = "暂降原因")
@Column(name = "event_reason")
private Integer eventReason;
@ApiModelProperty(name = "waveType",value = "触发类型")
@Column(name = "wave_type")
private Integer waveType;
}

View File

@@ -0,0 +1,20 @@
package com.njcn.event.pojo.vo;
import lombok.Data;
import org.influxdb.annotation.Column;
import org.influxdb.annotation.Measurement;
import java.io.Serializable;
@Data
@Measurement(name = "pqs_eventdetail")
public class EventDetailCount implements Serializable {
private static final long serialVersionUID = 8972007649569639702L;
@Column(name = "time")
private String timeId;
@Column(name = "count")
private Integer count;
}

View File

@@ -0,0 +1,19 @@
package com.njcn.event.pojo.vo;
import lombok.Data;
import java.io.Serializable;
/**
* @version 1.0.0
* @author: chenchao
* @date: 2022/06/27 15:29
*/
@Data
public class EventDetailVO implements Serializable {
private String id;
private String time;
}

View File

@@ -0,0 +1,28 @@
package com.njcn.event.pojo.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* 获取暂降月统计
*
* @author : zhaojun
* @version : 1.0.0
* @date : 2022年06月24日 11:02
*/
@Data
public class MonthCalculationVO implements Serializable {
private static final long serialVersionUID = -4620564906261989598L;
@ApiModelProperty(name = "month", value = "月份")
private String month;
@ApiModelProperty(name = "notAssociated", value = "未关联暂降次数")
private Long notAssociated;
@ApiModelProperty(name = "linked", value = "已关联处理事件")
private Long linked;
}

View File

@@ -0,0 +1,101 @@
package com.njcn.event.pojo.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;
import java.io.Serializable;
import java.text.Collator;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
/**
* 终端运行统计
* @author : zhaojun
* @version : 1.0.0
* @date : 2022年07月07日 9:34
*/
@Data
@Builder
public class TerminalRunningStatisticsVO implements Serializable {
private static final long serialVersionUID = 9145043242953094855L;
@ApiModelProperty("区域数据")
private TerminalRunningVO area;
@ApiModelProperty("厂家数据")
private TerminalRunningVO factory;
public static TerminalRunningStatisticsVO empty() {
return TerminalRunningStatisticsVO.buildVO(TerminalRunningVO.empty(), TerminalRunningVO.empty());
}
public static TerminalRunningStatisticsVO buildVO(TerminalRunningVO area, TerminalRunningVO factory) {
return TerminalRunningStatisticsVO.builder().area(area).factory(factory).build();
}
@Data
public static class TerminalRunningInfoVO implements Serializable {
private static final long serialVersionUID = -8715455283910823072L;
@ApiModelProperty("区域名称")
private String areaName;
@ApiModelProperty("终端个数")
private Integer numberOfTerminals;
@ApiModelProperty("投运")
private Long normal;
@ApiModelProperty("热备用")
private Long breaks;
@ApiModelProperty("停运")
private Long shutdown;
@ApiModelProperty("在线率")
private Double onlineRate;
public static Comparator<TerminalRunningInfoVO> sortAscAreaName() {
return (o1, o2) -> {
Collator collator = Collator.getInstance(Locale.CHINA);
return collator.compare(o1.getAreaName(), o2.getAreaName());
};
}
}
@Data
@Builder
public static class TerminalRunningVO implements Serializable {
private static final long serialVersionUID = 8990224131248734699L;
@ApiModelProperty("总计-终端个数")
private Integer numberOfTerminals;
@ApiModelProperty("总计-投运")
private Long normal;
@ApiModelProperty("总计-热备用")
private Long breaks;
@ApiModelProperty("总计-停运")
private Long shutdown;
@ApiModelProperty("总计-在线率")
private Double onlineRate;
@ApiModelProperty("列表数据")
private List<TerminalRunningInfoVO> areaInfo;
public static TerminalRunningVO empty() {
return TerminalRunningVO.buildVO(0, 0L, 0L, 0L, 0.00D, Collections.emptyList());
}
public static TerminalRunningVO buildVO(Integer numberOfTerminals, Long normal, Long breaks, Long shutdown, Double onlineRate, List<TerminalRunningInfoVO> areaInfo) {
return TerminalRunningVO.builder().numberOfTerminals(numberOfTerminals).normal(normal).breaks(breaks).shutdown(shutdown).onlineRate(onlineRate).areaInfo(areaInfo).build();
}
}
}

View File

@@ -20,6 +20,11 @@ public class TransientVO implements Serializable {
*/ */
@ApiModelProperty("id") @ApiModelProperty("id")
private String id; private String id;
/**
* 序号
*/
@ApiModelProperty("序号")
private Integer number;
/** /**
* 暂态发生时刻 * 暂态发生时刻
*/ */
@@ -68,8 +73,15 @@ public class TransientVO implements Serializable {
/** /**
* 暂态持续时间 * 暂态持续时间
*/ */
@ApiModelProperty("暂态持续时间") @ApiModelProperty("暂态持续时间(s)")
private Float persistTime; private Float persistTime;
/**
* 实际波形名称
*/
@ApiModelProperty(name = "实际波形名称")
private String waveName;
/** /**
* 暂态严重度 * 暂态严重度
*/ */

View File

@@ -0,0 +1,44 @@
package com.njcn.event.pojo.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Comparator;
/**
* 暂降电压等级统计
*
* @author : zhaojun
* @version : 1.0.0
* @date : 2022年06月24日 11:02
*/
@Data
public class VoltageLevelCalculationVO implements Serializable {
private static final long serialVersionUID = 3801801245395998386L;
@ApiModelProperty(name = "voltageLevel", value = "电压等级")
private String voltageLevel;
@ApiModelProperty(name = "monitoringPoints", value = "监测点数")
private Integer monitoringPoints;
@ApiModelProperty(name = "frequency", value = "暂降次数")
private Long frequency;
/**
* 电压等级升序排序,取KV单位前的数值
*
* @return 排序结果
*/
public static Comparator<VoltageLevelCalculationVO> sortAscVoltageLevel() {
return (o1, o2) -> {
String l1 = o1.getVoltageLevel();
String l2 = o2.getVoltageLevel();
String sub1 = l1.substring(0, l1.length() - 2);
String sub2 = l2.substring(0, l2.length() - 2);
return Double.valueOf(sub1).compareTo(Double.valueOf(sub2));
};
}
}

View File

@@ -0,0 +1,83 @@
package com.njcn.event.pojo.vo;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;
import java.io.Serializable;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/**
* 电压容忍度曲线兼容性统计
*
* @author : zhaojun
* @version : 1.0.0
* @date : 2022年06月24日 11:02
*/
@Data
@Builder
public class VoltageToleranceCurveVO implements Serializable {
private static final long serialVersionUID = -2659670722467310785L;
@ApiModelProperty(name = "totalNumberOfEvents", value = "事件总数")
private Integer totalNumberOfEvents;
@ApiModelProperty(name = "VoltageToleranceCurveDataList", value = "图表数据")
private List<VoltageToleranceCurveDataList> voltageToleranceCurveDataList;
/**
* 构建默认对象
*
* @return 默认对象
*/
public static VoltageToleranceCurveVO empty() {
return VoltageToleranceCurveVO.buildVO(0, Collections.emptyList());
}
/**
* 构建默认对象
*
* @param numberEvents 事件总数
* @param dataList 图表数据
* @return 默认对象
*/
public static VoltageToleranceCurveVO buildVO(int numberEvents, List<VoltageToleranceCurveDataList> dataList) {
return VoltageToleranceCurveVO.builder().totalNumberOfEvents(numberEvents).voltageToleranceCurveDataList(dataList).build();
}
@Data
public static class VoltageToleranceCurveDataList implements Serializable {
private static final long serialVersionUID = 2693688079727369565L;
@ApiModelProperty(name = "lineId", value = "LineId")
private String lineId;
@ApiModelProperty(name = "persistTime", value = "持续时间ms")
private Double persistTime;
@ApiModelProperty(name = "eventValue", value = "特征幅值")
private Double eventValue;
@ApiModelProperty(name = "subName", value = "变电站名称")
private String subName;
@ApiModelProperty(name = "gdName", value = "供电公司名称")
private String gdName;
@ApiModelProperty(name = "time", value = "发生时刻")
private String time;
public static Comparator<VoltageToleranceCurveDataList> sortAscTime() {
return (o1, o2) -> {
DateTime time1 = DateUtil.parseDateTime(o1.getTime());
DateTime time2 = DateUtil.parseDateTime(o2.getTime());
return time1.compareTo(time2);
};
}
}
}

View File

@@ -27,7 +27,7 @@ public class EventlEnumUtil {
value = message.substring(message.indexOf(StrUtil.C_COMMA)+1); value = message.substring(message.indexOf(StrUtil.C_COMMA)+1);
} }
eventDetailResponseEnum = EnumUtils.valueOf(EventResponseEnum.class, value, EventResponseEnum.class.getMethod(BusinessException.GET_MESSAGE_METHOD)); eventDetailResponseEnum = EnumUtils.valueOf(EventResponseEnum.class, value, EventResponseEnum.class.getMethod(BusinessException.GET_MESSAGE_METHOD));
return Objects.isNull(eventDetailResponseEnum) ? EventResponseEnum.HARMONIC_COMMON_ERROR : eventDetailResponseEnum; return Objects.isNull(eventDetailResponseEnum) ? EventResponseEnum.EVENT_COMMON_ERROR : eventDetailResponseEnum;
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
throw new BusinessException(CommonResponseEnum.INTERNAL_ERROR); throw new BusinessException(CommonResponseEnum.INTERNAL_ERROR);
} }

View File

@@ -0,0 +1,18 @@
package com.njcn.event.config;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
/**
* @version 1.0.0
* @author: chenchao
* @date: 2022/06/30 20:02
*/
@Data
@Component
public class EventBaseConfig {
@Value("${business.wavePath}")
private String wavePath;
}

View File

@@ -0,0 +1,21 @@
package com.njcn.event.controller;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* pqs-event
*
* @author cdf
* @date 2022/6/23
*/
@Slf4j
@RestController
@RequestMapping("/advance")
@Api(tags = "高级分析")
@AllArgsConstructor
public class AdvancedAnalysisController {
}

View File

@@ -0,0 +1,67 @@
package com.njcn.event.controller;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.device.pojo.param.DeviceInfoParam;
import com.njcn.event.pojo.vo.AreaAnalysisVO;
import com.njcn.event.pojo.vo.VoltageToleranceCurveVO;
import com.njcn.event.service.AreaAnalysisService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* pqs-event
* 区域分析
*
* @author cdf
* @date 2022/6/24
*/
@Slf4j
@RestController
@RequestMapping("/areaAnalysis")
@Api(tags = "区域分析")
@RequiredArgsConstructor
public class AreaAnalysisController extends BaseController {
private final AreaAnalysisService areaAnalysisService;
/**
* 区域暂降原因,类型
*
* @author cdf
* @date 2022/6/24
*/
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/getEventReason")
@ApiOperation("获取监测点暂降事件分析")
@ApiImplicitParam(name = "deviceInfoParam", value = "暂降事件分析参数", required = true)
public HttpResult<AreaAnalysisVO> getEventReason(@RequestBody @Validated DeviceInfoParam.BusinessParam deviceInfoParam) {
String methodDescribe = getMethodDescribe("getEventReason");
AreaAnalysisVO res = areaAnalysisService.getEventReason(deviceInfoParam);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, res, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/getVoltageToleranceCurve")
@ApiOperation("获取电压容忍度曲线兼容性统计")
@ApiImplicitParam(name = "deviceInfoParam", value = "暂降事件分析参数", required = true)
public HttpResult<VoltageToleranceCurveVO> getVoltageToleranceCurve(@RequestBody @Validated DeviceInfoParam.BusinessParam deviceInfoParam) {
String methodDescribe = getMethodDescribe("getVoltageToleranceCurve");
VoltageToleranceCurveVO res = areaAnalysisService.getVoltageToleranceCurve(deviceInfoParam);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, res, methodDescribe);
}
}

View File

@@ -10,6 +10,7 @@ import com.njcn.device.pojo.param.DeviceInfoParam;
import com.njcn.event.pojo.vo.AreaLineVO; import com.njcn.event.pojo.vo.AreaLineVO;
import com.njcn.event.pojo.vo.EventHeatMapVO; import com.njcn.event.pojo.vo.EventHeatMapVO;
import com.njcn.event.pojo.vo.EventSeverityVO; import com.njcn.event.pojo.vo.EventSeverityVO;
import com.njcn.event.pojo.vo.TerminalRunningStatisticsVO;
import com.njcn.event.service.AreaLineService; import com.njcn.event.service.AreaLineService;
import com.njcn.web.controller.BaseController; import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@@ -18,7 +19,10 @@ import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/** /**
* @author denghuajun * @author denghuajun
@@ -36,6 +40,7 @@ public class AreaController extends BaseController {
/** /**
* 获取监测网分布 * 获取监测网分布
*
* @param deviceInfoParam 参数 * @param deviceInfoParam 参数
* @return 结果 * @return 结果
*/ */
@@ -52,6 +57,7 @@ public class AreaController extends BaseController {
/** /**
* 获取暂降热力图 * 获取暂降热力图
*
* @param deviceInfoParam 参数 * @param deviceInfoParam 参数
* @return 结果 * @return 结果
*/ */
@@ -68,6 +74,7 @@ public class AreaController extends BaseController {
/** /**
* 获取暂降严重度 * 获取暂降严重度
*
* @param deviceInfoParam 参数 * @param deviceInfoParam 参数
* @return 结果 * @return 结果
*/ */
@@ -81,4 +88,23 @@ public class AreaController extends BaseController {
EventSeverityVO result = areaLineService.getEventSeverity(deviceInfoParam); EventSeverityVO result = areaLineService.getEventSeverity(deviceInfoParam);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
} }
/**
* 获取终端运行统计
*
* @param deviceInfoParam 参数
* @return 结果
*/
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/getTerminalRunningStatistics")
@ApiOperation("获取终端运行统计")
@ApiImplicitParam(name = "deviceInfoParam", value = "监测网分布参数", required = true)
public HttpResult<TerminalRunningStatisticsVO> getTerminalRunningStatistics(@RequestBody @Validated DeviceInfoParam.BusinessParam deviceInfoParam) {
String methodDescribe = getMethodDescribe("getTerminalRunningStatistics");
LogUtil.njcnDebug(log, "{},参数为:{}", methodDescribe, deviceInfoParam);
TerminalRunningStatisticsVO result = areaLineService.getTerminalRunningStatistics(deviceInfoParam);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
} }

View File

@@ -0,0 +1,48 @@
package com.njcn.event.controller;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.device.pojo.param.DeviceInfoParam;
import com.njcn.event.pojo.vo.AreaStatisticalVO;
import com.njcn.event.service.AreaStatisticalService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 区域统计
*
* @author : zhaojun
* @version : 1.0.0
* @date : 2022年06月24日 11:02
*/
@Slf4j
@RestController
@RequestMapping("/areaStatistics")
@Api(tags = "区域统计")
@AllArgsConstructor
public class AreaStatisticalController extends BaseController {
private final AreaStatisticalService areaStatisticalService;
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/getAreaCalculation")
@ApiOperation("获取暂降区域电压等级月份统计")
@ApiImplicitParam(name = "deviceInfoParam", value = "暂降事件分析参数", required = true)
public HttpResult<AreaStatisticalVO> getAreaCalculation(@RequestBody @Validated DeviceInfoParam.BusinessParam deviceInfoParam) {
String methodDescribe = getMethodDescribe("getAreaCalculation");
AreaStatisticalVO res = areaStatisticalService.getAreaCalculation(deviceInfoParam);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, res, methodDescribe);
}
}

View File

@@ -104,7 +104,6 @@ public class EventDetailController extends BaseController {
* @param lineIndexes * @param lineIndexes
* @param startTime * @param startTime
* @param endTime * @param endTime
* @param transientParam
* @return * @return
*/ */
@OperateInfo(info = LogEnum.BUSINESS_COMMON) @OperateInfo(info = LogEnum.BUSINESS_COMMON)

View File

@@ -0,0 +1,64 @@
package com.njcn.event.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.event.pojo.param.EventBaseParam;
import com.njcn.event.pojo.po.EventDetail;
import com.njcn.event.service.EventAnalysisService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* pqs-event
* 暂降 监测点
* @author cdf
* @date 2022/6/23
*/
@Slf4j
@RestController
@RequestMapping("/monitor")
@Api(tags = "监测点")
@RequiredArgsConstructor
public class MonitorPointController extends BaseController {
private final EventAnalysisService eventAnalysisService;
/**
* 获取暂降幅值/持续时间分布函数
* @author cdf
* @date 2022/6/23
*/
/**
* 获取监测点暂降事件分析
* @author cdf
* @date 2022/6/23
*/
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/getEventAnalyse")
@ApiOperation("获取监测点暂降事件分析")
@ApiImplicitParam(name = "eventBaseParam", value = "暂降事件分析参数", required = true)
public HttpResult<Page<EventDetail>> getEventAnalyse(@RequestBody @Validated EventBaseParam eventBaseParam){
String methodDescribe = getMethodDescribe("getEventAnalyse");
Page<EventDetail> page = eventAnalysisService.getEventAnalyse(eventBaseParam);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, page, methodDescribe);
}
}

View File

@@ -8,6 +8,7 @@ import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult; import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil; import com.njcn.common.utils.HttpResultUtil;
import com.njcn.event.pojo.param.TransientParam; import com.njcn.event.pojo.param.TransientParam;
import com.njcn.event.pojo.param.WaveFileParam;
import com.njcn.event.pojo.vo.TransientVO; import com.njcn.event.pojo.vo.TransientVO;
import com.njcn.event.service.TransientService; import com.njcn.event.service.TransientService;
import com.njcn.web.controller.BaseController; import com.njcn.web.controller.BaseController;
@@ -20,6 +21,8 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
/** /**
* @author: chenchao * @author: chenchao
* @date: 2022/03/29 10:19 * @date: 2022/03/29 10:19
@@ -58,4 +61,15 @@ public class TransientController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, wave, methodDescribe); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, wave, methodDescribe);
} }
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/downloadWaveFile")
@ApiOperation("暂态波形下载")
@ApiImplicitParam(name = "waveFileParam", value = "波形下载参数", required = true)
public HttpResult downloadWaveFile(@RequestBody @Validated WaveFileParam waveFileParam, HttpServletResponse response) throws Exception {
String methodDescribe = getMethodDescribe("downloadWaveFile");
HttpServletResponse resp = transientService.downloadWaveFile(waveFileParam, response);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, resp, methodDescribe);
}
} }

View File

@@ -0,0 +1,83 @@
package com.njcn.event.controller.area;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.device.pojo.param.DeviceInfoParam;
import com.njcn.device.pojo.vo.TerminalBaseVO;
import com.njcn.event.pojo.po.EventDetail;
import com.njcn.event.pojo.vo.AreaSubLineVO;
import com.njcn.event.service.AreaInfoService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* pqs-event
* 区域信息
* @author cdf
* @date 2022/6/29
*/
@Slf4j
@RestController
@RequestMapping("/areaInfo")
@Api(tags = "区域地理信息")
@AllArgsConstructor
public class AreaInfoController extends BaseController {
private final AreaInfoService areaInfoService;
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/getAreaLineInfo")
@ApiOperation("获取监测点区域信息")
@ApiImplicitParam(name = "deviceInfoParam", value = "参数体", required = true)
public HttpResult<List<AreaSubLineVO>> getAreaLineInfo(@RequestBody @Validated DeviceInfoParam.BusinessParam deviceInfoParam) {
String methodDescribe = getMethodDescribe("getAreaLineInfo");
List<AreaSubLineVO> res = areaInfoService.getAreaLineInfo(deviceInfoParam);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, res, methodDescribe);
}
/**
* 获取区域中断设备
* @author cdf
* @date 2022/6/29
*/
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/getAreaOffDev")
@ApiOperation("获取区域中断设备")
@ApiImplicitParam(name = "deviceInfoParam", value = "参数体", required = true)
public HttpResult<List<TerminalBaseVO>> getAreaOffDev(@RequestBody @Validated DeviceInfoParam.BusinessParam deviceInfoParam) {
String methodDescribe = getMethodDescribe("getAreaOffDev");
List<TerminalBaseVO> res = areaInfoService.getAreaOffDev(deviceInfoParam);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, res, methodDescribe);
}
/**
* 未处理暂降事件列表
* @author cdf
* @date 2022/6/30
*/
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/getNoDealEvents")
@ApiOperation("获取区域未处理暂态事件")
@ApiImplicitParam(name = "deviceInfoParam", value = "参数体", required = true)
public HttpResult<List<EventDetail>> getNoDealEvents(@RequestBody @Validated DeviceInfoParam.BusinessParam deviceInfoParam) {
String methodDescribe = getMethodDescribe("getNoDealEvents");
List<EventDetail> res = areaInfoService.getNoDealEvents(deviceInfoParam);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, res, methodDescribe);
}
}

View File

@@ -0,0 +1,146 @@
package com.njcn.event.influxdb;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateTime;
import com.njcn.event.pojo.po.EventDetail;
import com.njcn.event.pojo.vo.EventDetailCount;
import com.njcn.influxdb.utils.InfluxDbUtils;
import org.apache.commons.lang3.StringUtils;
import org.influxdb.dto.QueryResult;
import org.influxdb.querybuilder.SelectQueryImpl;
import org.influxdb.querybuilder.SelectionQueryImpl;
import org.influxdb.querybuilder.clauses.Clause;
import org.springframework.stereotype.Component;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.stream.Collectors;
import static com.njcn.influxdb.param.InfluxDBPublicParam.DATABASE;
import static com.njcn.influxdb.param.InfluxDBPublicParam.PQS_EVENT_DETAIL;
import static org.influxdb.querybuilder.BuiltQuery.QueryBuilder.eq;
/**
* 表PqsEventDetail 查询封装
*
* @author : zhaojun
* @version : 1.0.0
* @date : 2022年07月04日 18:36
*/
@Component
public class PqsEventDetailQuery extends QueryBuilder {
protected PqsEventDetailQuery(InfluxDbUtils influxDbUtils) {
super(influxDbUtils);
}
/**
* line_id or条件
*
* @param lineIds line_id
* @return line_id or条件
*/
public static List<Clause> lineIdOr(List<String> lineIds) {
List<Clause> lineIdOr = new ArrayList<>();
for (String lineId : lineIds) {
Clause clause = eq("line_id", lineId);
lineIdOr.add(clause);
}
return lineIdOr;
}
/**
* 指定查询数据库和表
*
* @param column select count 条件
* @see SelectQueryImpl
*/
private SelectQueryImpl fromTable(SelectionQueryImpl column) {
return column.from(DATABASE, PQS_EVENT_DETAIL);
}
/**
* 查询方法
* SELECT在包括一个tag时必须至少指定一个field
*
* @param columnNames 显示的字段名,查询需要指定,减少数据加载
* @param or or条件
* @param and and条件
* @return 结果
*/
public List<EventDetail> selectList(List<String> columnNames, List<Clause> or, List<Clause> and) {
SelectionQueryImpl selectAppendColumnNames = selectAppendColumnNames(columnNames);
SelectQueryImpl selectAppendTable = fromTable(selectAppendColumnNames);
QueryResult query = getQueryResult(or, and, selectAppendTable);
return toPOJO(query, EventDetail.class);
}
/**
* Count方法
*
* @param columnNames 显示的字段名,查询需要指定,减少数据加载
* @param or or条件
* @param and and条件
* @return 结果
*/
public Integer selectCount(List<String> columnNames, List<Clause> or, List<Clause> and) {
SelectionQueryImpl selectAppendColumnNames = countAppendColumnNames(columnNames);
SelectQueryImpl selectAppendTable = fromTable(selectAppendColumnNames);
QueryResult query = getQueryResult(or, and, selectAppendTable);
List<EventDetailCount> eventDetailCounts = toPOJO(query, EventDetailCount.class);
if (CollUtil.isEmpty(eventDetailCounts)) {
return 0;
}
return eventDetailCounts.get(0).getCount();
}
/**
* where条件 时间和reason_type
*
* @param beginOfDay 开始时间
* @param endOfDay 结束时间
* @param type 字段 reason_type
* @param reasonId 字段 reason_type 值
* @return 构建查询and条件
*/
public static List<Clause> timeAndType(String beginOfDay, String endOfDay, String type, String reasonId) {
List<Clause> clauses = timeAnd(beginOfDay, endOfDay);
clauses.add(eq(type, reasonId));
return clauses;
}
/**
* 统计lineIndex的数据
*
* @param eventDetailList influxdb数据
* @return 个数
*/
public static Function<List<String>, Long> countLineIndexes(List<EventDetail> eventDetailList) {
return lineIndexes -> eventDetailList.stream().filter(t -> lineIndexes.contains(t.getLineId())).count();
}
/**
* 统计eventass_index字段非空的个数
*
* @return 个数
*/
public static Function<List<EventDetail>, Long> countEventassIndexIsNoEmpty() {
return eventDetails -> eventDetails.stream().filter(t -> StringUtils.isNotEmpty(t.getEventassIndex())).count();
}
/**
* 时间段内的数据
*
* @param eventDetailList influxdb数据
* @return 数据
*/
public static BiFunction<DateTime, DateTime, List<EventDetail>> getBetweenTimeEventDetailList(List<EventDetail> eventDetailList) {
return (beginTime, endTime) -> eventDetailList.stream().filter(eventDetail -> {
Instant timeId = eventDetail.getTimeId();
return timeId.isAfter(beginTime.toInstant()) && timeId.isBefore(endTime.toInstant());
}).collect(Collectors.toList());
}
}

View File

@@ -0,0 +1,66 @@
package com.njcn.event.influxdb;
import com.njcn.event.pojo.po.PqsOnlinerate;
import com.njcn.influxdb.utils.InfluxDbUtils;
import org.influxdb.dto.QueryResult;
import org.influxdb.querybuilder.SelectQueryImpl;
import org.influxdb.querybuilder.SelectionQueryImpl;
import org.influxdb.querybuilder.clauses.Clause;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import static com.njcn.influxdb.param.InfluxDBPublicParam.DATABASE;
import static com.njcn.influxdb.param.InfluxDBPublicParam.PQS_ONLINERATE;
import static org.influxdb.querybuilder.BuiltQuery.QueryBuilder.eq;
@Component
public class PqsOnlinerateQuery extends QueryBuilder {
protected PqsOnlinerateQuery(InfluxDbUtils influxDbUtils) {
super(influxDbUtils);
}
/**
* 指定查询数据库和表
*
* @param column select count 条件
* @see SelectQueryImpl
*/
private SelectQueryImpl fromTable(SelectionQueryImpl column) {
return column.from(DATABASE, PQS_ONLINERATE);
}
/**
* dev_id or条件
*
* @param devIds dev_id
* @return dev_id or条件
*/
public static List<Clause> devIdOr(List<String> devIds) {
List<Clause> devIdOr = new ArrayList<>();
for (String lineId : devIds) {
Clause clause = eq("dev_id", lineId);
devIdOr.add(clause);
}
return devIdOr;
}
/**
* 查询方法
* SELECT在包括一个tag时必须至少指定一个field
*
* @param columnNames 显示的字段名,查询需要指定,减少数据加载
* @param or or条件
* @param and and条件
* @return 结果
*/
public List<PqsOnlinerate> selectList(List<String> columnNames, List<Clause> or, List<Clause> and) {
SelectionQueryImpl selectAppendColumnNames = selectAppendColumnNames(columnNames);
SelectQueryImpl selectAppendTable = fromTable(selectAppendColumnNames);
QueryResult query = getQueryResult(or, and, selectAppendTable);
return toPOJO(query, PqsOnlinerate.class);
}
}

View File

@@ -0,0 +1,172 @@
package com.njcn.event.influxdb;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.njcn.influxdb.utils.InfluxDbUtils;
import org.influxdb.InfluxDBMapperException;
import org.influxdb.dto.QueryResult;
import org.influxdb.impl.InfluxDBResultMapper;
import org.influxdb.querybuilder.SelectQueryImpl;
import org.influxdb.querybuilder.SelectionQueryImpl;
import org.influxdb.querybuilder.WhereNested;
import org.influxdb.querybuilder.WhereQueryImpl;
import org.influxdb.querybuilder.clauses.Clause;
import java.util.ArrayList;
import java.util.List;
import static org.influxdb.querybuilder.BuiltQuery.QueryBuilder.*;
/**
* 查询抽象
*
* @author : zhaojun
* @version : 1.0.0
* @date : 2022年07月04日 18:36
*/
public abstract class QueryBuilder {
/* 查询工具类 */
private final InfluxDbUtils influxDbUtils;
private final InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
protected QueryBuilder(InfluxDbUtils influxDbUtils) {
this.influxDbUtils = influxDbUtils;
}
/**
* 数据转换
*
* @param queryResult 查询结果
* @param clazz 泛型
* @param <T> 泛型T
* @return 查询结果映射
* @throws InfluxDBMapperException 异常
*/
public <T> List<T> toPOJO(final QueryResult queryResult, final Class<T> clazz) throws InfluxDBMapperException {
return resultMapper.toPOJO(queryResult, clazz);
}
/**
* 查询方法
*
* @param command sql
* @return 查询结果
*/
public QueryResult query(String command) {
return influxDbUtils.query(command);
}
/**
* select语句拼接查询字段
*
* @param columnNames 查询字段
* @see SelectionQueryImpl
*/
public SelectionQueryImpl selectAppendColumnNames(List<String> columnNames) {
SelectionQueryImpl selectionQuery = select();
for (String columnName : columnNames) {
selectionQuery.column(columnName);
}
return selectionQuery;
}
/**
* Count语句拼接查询字段
*
* @param columnNames 查询字段
* @see SelectionQueryImpl
*/
public SelectionQueryImpl countAppendColumnNames(List<String> columnNames) {
SelectionQueryImpl selectionQuery = select();
for (String columnName : columnNames) {
selectionQuery.count(columnName);
}
return selectionQuery;
}
/**
* 组装sql语句,包括or语句和and语句
*
* @param or or条件
* @param and and条件
* @return 查询结果
* @see SelectionQueryImpl
*/
public QueryResult getQueryResult(List<Clause> or, List<Clause> and, SelectQueryImpl selectQuery) {
WhereQueryImpl<SelectQueryImpl> where = selectQuery.where();
whereAndNested(where, or);
appendWhereOther(where, and);
return query(selectQuery.getCommand());
}
/**
* 拼接or条件
*
* @param clauses or条件
* @see WhereQueryImpl
*/
public void whereAndNested(WhereQueryImpl<SelectQueryImpl> whereQuery, List<Clause> clauses) {
WhereNested<WhereQueryImpl<SelectQueryImpl>> andNested = whereQuery.andNested();
if (CollUtil.isNotEmpty(clauses)) {
for (Clause clause : clauses) {
andNested.or(clause);
}
andNested.close();
}
}
/**
* 拼接and条件
*
* @param clauses and条件
* @see WhereQueryImpl
*/
public void appendWhereOther(WhereQueryImpl<SelectQueryImpl> where, List<Clause> clauses) {
if (CollUtil.isNotEmpty(clauses)) {
for (Clause clause : clauses) {
where.and(clause);
}
}
where.tz("Asia/Shanghai");
}
/**
* time and条件
*
* @param gteTime 开始时间
* @param lteTime 结束时间
* @return time and条件
*/
public static List<Clause> timeAnd(String gteTime, String lteTime) {
List<Clause> clauses = new ArrayList<>(15);
clauses.add(gte("time", gteTime));
clauses.add(lte("time", lteTime));
return clauses;
}
/**
* 格式成查询开始时间段
*
* @param time 时间
* @return yyyy-MM-dd 00:00:00
*/
public static String beginOfDay(String time) {
DateTime date = DateUtil.parse(time);
DateTime dateTime = DateUtil.beginOfDay(date);
return DateUtil.formatDateTime(dateTime);
}
/**
* 格式成查询结束时间段
*
* @param time 时间
* @return yyyy-MM-dd 23:59:59
*/
public static String endOfDay(String time) {
DateTime date = DateUtil.parse(time);
DateTime dateTime = DateUtil.endOfDay(date);
return DateUtil.formatDateTime(dateTime);
}
}

View File

@@ -1,12 +0,0 @@
package com.njcn.event.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.njcn.event.pojo.po.EventDetail;
/**
* @author denghuajun
* @version 1.0.0
* @date 2022/3/16
*/
public interface EventDetailMapper extends BaseMapper<EventDetail> {
}

View File

@@ -0,0 +1,24 @@
package com.njcn.event.mapper;
import com.njcn.event.pojo.po.PqDevice;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 装置信息表
*
* @author : zhaojun
* @version : 1.0.0
* @date : 2022年07月07日 9:26
*/
public interface PqDeviceMapper {
/**
* 查询装置的运行状态
*
* @param deviceIndexes 设备index
* @return 设备的运行状态
*/
List<PqDevice> queryRunFlagByDeviceIndexs(@Param("deviceIndexes") List<String> deviceIndexes);
}

View File

@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.njcn.event.mapper.PqDeviceMapper">
<resultMap type="com.njcn.event.pojo.po.PqDevice" id="PqDeviceMap">
<result property="id" column="Id" jdbcType="VARCHAR"/>
<result property="devModel" column="Dev_Model" jdbcType="INTEGER"/>
<result property="devDataType" column="Dev_Data_Type" jdbcType="INTEGER"/>
<result property="runFlag" column="Run_Flag" jdbcType="INTEGER"/>
<result property="comFlag" column="Com_Flag" jdbcType="INTEGER"/>
<result property="manufacturer" column="Manufacturer" jdbcType="VARCHAR"/>
<result property="checkFlag" column="Check_Flag" jdbcType="INTEGER"/>
<result property="frontType" column="Front_Type" jdbcType="VARCHAR"/>
<result property="devType" column="Dev_Type" jdbcType="VARCHAR"/>
<result property="ip" column="IP" jdbcType="VARCHAR"/>
<result property="callFlag" column="Call_Flag" jdbcType="INTEGER"/>
<result property="port" column="Port" jdbcType="INTEGER"/>
<result property="series" column="Series" jdbcType="VARCHAR"/>
<result property="devKey" column="Dev_Key" jdbcType="VARCHAR"/>
<result property="nodeId" column="Node_Id" jdbcType="VARCHAR"/>
<result property="loginTime" column="Login_Time" jdbcType="TIMESTAMP"/>
<result property="updateTime" column="Update_Time" jdbcType="TIMESTAMP"/>
<result property="thisTimeCheck" column="This_Time_Check" jdbcType="TIMESTAMP"/>
<result property="nextTimeCheck" column="Next_Time_Check" jdbcType="TIMESTAMP"/>
<result property="electroplate" column="Electroplate" jdbcType="INTEGER"/>
<result property="onTime" column="On_Time" jdbcType="INTEGER"/>
<result property="contract" column="Contract" jdbcType="VARCHAR"/>
<result property="sim" column="Sim" jdbcType="VARCHAR"/>
</resultMap>
<select id="queryRunFlagByDeviceIndexs" resultMap="PqDeviceMap">
select
Id, Run_Flag from pq_device where Id in
<foreach collection="deviceIndexes" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</select>
</mapper>

View File

@@ -34,5 +34,19 @@
AND B3.Pid = B4.Id AND B3.Pid = B4.Id
</select> </select>
<!-- <select id="getTransientDataById" resultType="TransientVO">-->
<!-- SELECT-->
<!-- A.`Name` name,-->
<!-- A3.`Name` substation-->
<!-- FROM-->
<!-- pq_line A,-->
<!-- pq_line A1,-->
<!-- pq_line A2,-->
<!-- pq_line A3-->
<!-- WHERE A.Id = #{lineId}-->
<!-- AND A.Pid = A1.Id-->
<!-- AND A1.Pid = A2.Id-->
<!-- AND A2.Pid = A3.Id-->
<!-- </select>-->
</mapper> </mapper>

View File

@@ -0,0 +1,31 @@
package com.njcn.event.service;
import com.njcn.device.pojo.param.DeviceInfoParam;
import com.njcn.event.pojo.vo.AreaAnalysisVO;
import com.njcn.event.pojo.vo.VoltageToleranceCurveVO;
/**
* pqs-event
*
* @author cdf
* @date 2022/6/24
*/
public interface AreaAnalysisService {
/**
* 区域暂降原因,类型
*
* @author cdf
* @date 2022/6/24
*/
AreaAnalysisVO getEventReason(DeviceInfoParam.BusinessParam deviceInfoParam);
/**
* 获取电压容忍度曲线兼容性统计
*
* @param deviceInfoParam 查询参数
* @return 电压容忍度曲线兼容性统计
*/
VoltageToleranceCurveVO getVoltageToleranceCurve(DeviceInfoParam.BusinessParam deviceInfoParam);
}

View File

@@ -0,0 +1,39 @@
package com.njcn.event.service;
import com.njcn.device.pojo.param.DeviceInfoParam;
import com.njcn.device.pojo.vo.TerminalBaseVO;
import com.njcn.event.pojo.po.EventDetail;
import com.njcn.event.pojo.vo.AreaSubLineVO;
import java.util.List;
/**
* pqs-event
*
* @author cdf
* @date 2022/6/29
*/
public interface AreaInfoService {
/**
* 获取区域监测点地理信息
* @author cdf
* @date 2022/6/29
*/
List<AreaSubLineVO> getAreaLineInfo(DeviceInfoParam.BusinessParam deviceInfoParam);
/**
* 获取区域监测点地理信息
* @author cdf
* @date 2022/6/29
*/
List<TerminalBaseVO> getAreaOffDev(DeviceInfoParam.BusinessParam deviceInfoParam);
/**
* 获取区域监测点地理信息
* @author cdf
* @date 2022/6/29
*/
List<EventDetail> getNoDealEvents(DeviceInfoParam.BusinessParam deviceInfoParam);
}

View File

@@ -2,9 +2,9 @@ package com.njcn.event.service;
import com.njcn.device.pojo.param.DeviceInfoParam; import com.njcn.device.pojo.param.DeviceInfoParam;
import com.njcn.event.pojo.vo.AreaLineVO; import com.njcn.event.pojo.vo.*;
import com.njcn.event.pojo.vo.EventHeatMapVO;
import com.njcn.event.pojo.vo.EventSeverityVO; import java.util.List;
/** /**
* 区域暂降监测点统计 * 区域暂降监测点统计
@@ -33,4 +33,13 @@ public interface AreaLineService {
* @return 结果 * @return 结果
*/ */
EventSeverityVO getEventSeverity (DeviceInfoParam.BusinessParam deviceInfoParam); EventSeverityVO getEventSeverity (DeviceInfoParam.BusinessParam deviceInfoParam);
/**
* 获取终端运行统计
*
* @param deviceInfoParam 参数
* @return 结果
*/
TerminalRunningStatisticsVO getTerminalRunningStatistics(DeviceInfoParam.BusinessParam deviceInfoParam);
} }

View File

@@ -0,0 +1,24 @@
package com.njcn.event.service;
import com.njcn.device.pojo.param.DeviceInfoParam;
import com.njcn.event.pojo.vo.AreaStatisticalVO;
/**
* 区域统计
*
* @author : zhaojun
* @version : 1.0.0
* @date : 2022年06月24日 11:02
*/
public interface AreaStatisticalService {
/**
* 获取暂降区域 电压等级 月份统计
*
* @param deviceInfoParam 查询参数
* @return 暂降统计信息
*/
AreaStatisticalVO getAreaCalculation(DeviceInfoParam.BusinessParam deviceInfoParam);
}

View File

@@ -0,0 +1,21 @@
package com.njcn.event.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.event.pojo.param.EventBaseParam;
import com.njcn.event.pojo.po.EventDetail;
/**
* pqs-event
* 暂降 监测点
* @author cdf
* @date 2022/6/23
*/
public interface EventAnalysisService {
/**
* 获取暂降事件分析
* @author cdf
* @date 2022/6/23
*/
Page<EventDetail> getEventAnalyse(EventBaseParam eventBaseParam);
}

View File

@@ -0,0 +1,147 @@
package com.njcn.event.service.Impl;
import cn.hutool.core.collection.CollUtil;
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.AreaLineInfoVO;
import com.njcn.event.influxdb.PqsEventDetailQuery;
import com.njcn.event.pojo.po.EventDetail;
import com.njcn.event.pojo.vo.AreaAnalysisVO;
import com.njcn.event.pojo.vo.VoltageToleranceCurveVO;
import com.njcn.event.pojo.vo.VoltageToleranceCurveVO.VoltageToleranceCurveDataList;
import com.njcn.event.service.AreaAnalysisService;
import com.njcn.system.api.DicDataFeignClient;
import com.njcn.system.enums.DicDataTypeEnum;
import com.njcn.system.pojo.po.DictData;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import static com.njcn.event.influxdb.PqsEventDetailQuery.lineIdOr;
import static com.njcn.event.influxdb.PqsEventDetailQuery.timeAndType;
import static com.njcn.event.influxdb.QueryBuilder.*;
/**
* pqs-event
*
* @author cdf
* @date 2022/6/24
*/
@Service
@RequiredArgsConstructor
public class AreaAnalysisServiceImpl implements AreaAnalysisService {
private final GeneralDeviceInfoClient generalDeviceInfoClient;
private final DicDataFeignClient dicDataFeignClient;
private final LineFeignClient lineFeignClient;
private final PqsEventDetailQuery pqsEventDetailQuery;
@Override
public AreaAnalysisVO getEventReason(DeviceInfoParam.BusinessParam deviceInfoParam) {
AreaAnalysisVO areaAnalysisVO = new AreaAnalysisVO();
List<DictData> dicReasonList = dicDataFeignClient.getDicDataByTypeName(DicDataTypeEnum.EVENT_REASON.getName()).getData();
List<DictData> dicTypeList = dicDataFeignClient.getDicDataByTypeName(DicDataTypeEnum.EVENT_TYPE.getName()).getData();
// 获取指定部门下的监测点集合
List<GeneralDeviceDTO> generalDeviceDTOList = generalDeviceInfoClient.getPracticalAllDeviceInfo(deviceInfoParam).getData();
List<String> lineIds = getAllLineIdList(generalDeviceDTOList);
List<AreaAnalysisVO.Children> reasonList = assData(dicReasonList, lineIds, deviceInfoParam.getSearchBeginTime(), deviceInfoParam.getSearchEndTime(), "event_reason");
List<AreaAnalysisVO.Children> typeList = assData(dicTypeList, lineIds, deviceInfoParam.getSearchBeginTime(), deviceInfoParam.getSearchEndTime(), "event_type");
areaAnalysisVO.setReason(reasonList);
areaAnalysisVO.setType(typeList);
return areaAnalysisVO;
}
/**
* 获取电压容忍度曲线兼容性统计
*
* @param deviceInfoParam 查询参数
* @return 电压容忍度曲线兼容性统计
*/
@Override
public VoltageToleranceCurveVO getVoltageToleranceCurve(DeviceInfoParam.BusinessParam deviceInfoParam) {
// 获取指定部门下的监测点集合
List<GeneralDeviceDTO> generalDeviceDTOList = generalDeviceInfoClient.getPracticalAllDeviceInfo(deviceInfoParam).getData();
if (CollUtil.isEmpty(generalDeviceDTOList)) {
return VoltageToleranceCurveVO.empty();
}
List<String> lineIds = getAllLineIdList(generalDeviceDTOList);
if (CollUtil.isEmpty(lineIds)) {
return VoltageToleranceCurveVO.empty();
}
List<AreaLineInfoVO> getBaseLineAreaInfo = lineFeignClient.getBaseLineAreaInfo(lineIds).getData();
if (CollUtil.isEmpty(getBaseLineAreaInfo)) {
return VoltageToleranceCurveVO.empty();
}
Map<String, AreaLineInfoVO> areaLineInfoVOMap =
getBaseLineAreaInfo.parallelStream().collect(Collectors.toConcurrentMap(AreaLineInfoVO::getLineId,
Function.identity()));
List<EventDetail> eventDetailList = pqsEventDetailQuery.selectList(Arrays.asList("line_id", "persist_time", "event_value", "create_time"),
lineIdOr(lineIds), timeAnd(beginOfDay(deviceInfoParam.getSearchBeginTime()),
endOfDay(deviceInfoParam.getSearchEndTime())));
if (CollUtil.isEmpty(eventDetailList)) {
return VoltageToleranceCurveVO.empty();
}
List<VoltageToleranceCurveDataList> curveDataList = eventDetailList.parallelStream()
.map(dto -> {
AreaLineInfoVO info = areaLineInfoVOMap.get(dto.getLineId());
VoltageToleranceCurveDataList voltageToleranceCurve = new VoltageToleranceCurveDataList();
voltageToleranceCurve.setLineId(dto.getLineId());
voltageToleranceCurve.setPersistTime(dto.getPersistTime());
voltageToleranceCurve.setEventValue(dto.getEventValue());
voltageToleranceCurve.setTime(dto.getCreateTime());
voltageToleranceCurve.setGdName(info.getGdName());
voltageToleranceCurve.setSubName(info.getSubName());
return voltageToleranceCurve;
})
.sorted(VoltageToleranceCurveDataList.sortAscTime())
.collect(Collectors.toCollection(() -> Collections.synchronizedList(new ArrayList<>())));
return VoltageToleranceCurveVO.buildVO(eventDetailList.size(), curveDataList);
}
/**
* 获取全部的LineID
*
* @param generalDeviceDTOList Device
* @return lineIds
*/
private List<String> getAllLineIdList(List<GeneralDeviceDTO> generalDeviceDTOList) {
return generalDeviceDTOList.stream().flatMap(dto -> dto.getLineIndexes().stream()).collect(Collectors.toList());
}
private List<AreaAnalysisVO.Children> assData(List<DictData> dicList, List<String> lineIds, String startTime, String endTime, String type) {
List<AreaAnalysisVO.Children> reasonList = new ArrayList<>();
Integer allCount = 0;
for (DictData reason : dicList) {
// 暂降原因类型次数
Integer count = pqsEventDetailQuery.selectCount(Collections.singletonList(type),
lineIdOr(lineIds), timeAndType(beginOfDay(startTime),
endOfDay(endTime), type, reason.getId()));
AreaAnalysisVO.Children children = new AreaAnalysisVO.Children();
children.setName(reason.getName());
children.setValue(count);
allCount += count;
reasonList.add(children);
}
AreaAnalysisVO.Children allType = new AreaAnalysisVO.Children();
allType.setName("总计");
allType.setValue(allCount);
reasonList.add(allType);
return reasonList;
}
}

View File

@@ -0,0 +1,142 @@
package com.njcn.event.service.Impl;
import cn.hutool.core.collection.CollectionUtil;
import com.njcn.device.api.GeneralDeviceInfoClient;
import com.njcn.device.api.LineFeignClient;
import com.njcn.device.api.TerminalBaseClient;
import com.njcn.device.pojo.dto.GeneralDeviceDTO;
import com.njcn.device.pojo.param.DeviceInfoParam;
import com.njcn.device.pojo.po.Line;
import com.njcn.device.pojo.vo.AreaLineInfoVO;
import com.njcn.device.pojo.vo.TerminalBaseVO;
import com.njcn.event.pojo.constant.Param;
import com.njcn.event.pojo.po.EventDetail;
import com.njcn.event.pojo.vo.AreaSubLineVO;
import com.njcn.event.service.AreaInfoService;
import com.njcn.event.utils.CommUtil;
import com.njcn.influxdb.param.InfluxDBPublicParam;
import com.njcn.influxdb.utils.InfluxDbUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.influxdb.dto.QueryResult;
import org.influxdb.impl.InfluxDBResultMapper;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* pqs-event
* 区域地理信息
*
* @author cdf
* @date 2022/6/29
*/
@Service
@Slf4j
@RequiredArgsConstructor
public class AreaInfoServiceImpl implements AreaInfoService {
private final InfluxDbUtils influxDbUtils;
private final GeneralDeviceInfoClient generalDeviceInfoClient;
private final LineFeignClient lineFeignClient;
private final TerminalBaseClient terminalBaseClient;
@Override
public List<AreaSubLineVO> getAreaLineInfo(DeviceInfoParam.BusinessParam deviceInfoParam) {
List<AreaSubLineVO> resultVOList = new ArrayList<>();
List<GeneralDeviceDTO> generalDeviceDTOList = generalDeviceInfoClient.getPracticalAllDeviceInfo(deviceInfoParam).getData();
List<String> lineIds = generalDeviceDTOList.stream().flatMap(dto -> dto.getLineIndexes().stream()).collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(lineIds)) {
List<AreaLineInfoVO> resList = lineFeignClient.getBaseLineAreaInfo(lineIds).getData();
//查询监测点未处理暂态事件
StringBuilder lineIdsStr = CommUtil.assToInfluxParam(lineIds);
String stringResult = "SELECT count(eventass_index) FROM " + Param.EVENT_DETAIL + Param.WHERE + "time >= '" + deviceInfoParam.getSearchBeginTime() + InfluxDBPublicParam.START_TIME + "' and " + "time <= '" + deviceInfoParam.getSearchEndTime() + InfluxDBPublicParam.END_TIME + "' and " + lineIdsStr + " and eventass_index = '' group by line_id" + InfluxDBPublicParam.TIME_ZONE;
// 结果集
QueryResult result = influxDbUtils.query(stringResult);
if (!result.hasError()) {
List<QueryResult.Series> list = result.getResults().get(0).getSeries();
for (AreaLineInfoVO areaLineInfoVO : resList) {
boolean flag = false;
for (QueryResult.Series tem : list) {
String lineId = tem.getTags().get("line_id");
if (areaLineInfoVO.getLineId().equals(lineId)) {
areaLineInfoVO.setNoDealCount(Double.valueOf(tem.getValues().get(0).get(1).toString()).intValue());
flag = true;
break;
}
}
if (!flag) {
areaLineInfoVO.setNoDealCount(0);
}
}
}
//组装成变电站
if (CollectionUtil.isNotEmpty(resList)) {
Map<String, List<AreaLineInfoVO>> map = resList.stream().collect(Collectors.groupingBy(AreaLineInfoVO::getSubId));
map.forEach((key, value) -> {
AreaSubLineVO areaSubLineVO = new AreaSubLineVO();
areaSubLineVO.setChildren(value);
areaSubLineVO.setSubId(key);
areaSubLineVO.setLat(value.get(0).getLat());
areaSubLineVO.setLng(value.get(0).getLng());
areaSubLineVO.setSubName(value.get(0).getSubName());
resultVOList.add(areaSubLineVO);
});
}
}
return resultVOList;
}
@Override
public List<TerminalBaseVO> getAreaOffDev(DeviceInfoParam.BusinessParam deviceInfoParam) {
List<TerminalBaseVO> res = new ArrayList<>();
List<GeneralDeviceDTO> generalDeviceDTOList = generalDeviceInfoClient.getPracticalAllDeviceInfo(deviceInfoParam).getData();
List<String> devIds = generalDeviceDTOList.stream().flatMap(dto -> dto.getDeviceIndexes().stream()).collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(devIds)) {
res = terminalBaseClient.getDeviceByIdOnOrOff(devIds).getData();
}
return res;
}
@Override
public List<EventDetail> getNoDealEvents(DeviceInfoParam.BusinessParam deviceInfoParam) {
List<EventDetail> resList = new ArrayList<>();
List<GeneralDeviceDTO> generalDeviceDTOList = generalDeviceInfoClient.getPracticalAllDeviceInfo(deviceInfoParam).getData();
List<String> lineIds = generalDeviceDTOList.stream().flatMap(dto -> dto.getLineIndexes().stream()).collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(lineIds)) {
List<Line> lineList = lineFeignClient.getBaseLineList(lineIds).getData();
//查询监测点未处理暂态事件
StringBuilder lineIdsStr = CommUtil.assToInfluxParam(lineIds);
String stringResult = "SELECT * FROM " + Param.EVENT_DETAIL + Param.WHERE + "time >= '" + deviceInfoParam.getSearchBeginTime() + Param.BEGIN + "' and " + "time <= '" + deviceInfoParam.getSearchEndTime() + Param.END + "' and " + lineIdsStr + "and eventass_index = '' " + InfluxDBPublicParam.TIME_ZONE;
// 结果集
QueryResult result = influxDbUtils.query(stringResult);
// 结果集映射到对象中
InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper();
resList = influxDBResultMapper.toPOJO(result, EventDetail.class);
//对未处理暂降事件的监测点替换成中文名称
if (CollectionUtil.isNotEmpty(resList)) {
for (EventDetail eventDetail : resList) {
for (Line tem : lineList) {
if (eventDetail.getLineId().equals(tem.getId())) {
eventDetail.setLineId(tem.getName());
break;
}
}
}
}
}
return resList;
}
}

View File

@@ -1,6 +1,7 @@
package com.njcn.event.service.Impl; package com.njcn.event.service.Impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import com.njcn.common.pojo.enums.common.ServerEnum; import com.njcn.common.pojo.enums.common.ServerEnum;
import com.njcn.device.api.GeneralDeviceInfoClient; import com.njcn.device.api.GeneralDeviceInfoClient;
@@ -9,17 +10,32 @@ import com.njcn.device.pojo.dto.GeneralDeviceDTO;
import com.njcn.device.pojo.param.DeviceInfoParam; import com.njcn.device.pojo.param.DeviceInfoParam;
import com.njcn.device.pojo.vo.LineDetailVO; import com.njcn.device.pojo.vo.LineDetailVO;
import com.njcn.device.pojo.vo.LineDeviceStateVO; import com.njcn.device.pojo.vo.LineDeviceStateVO;
import com.njcn.event.pojo.vo.*;
import com.njcn.device.pojo.vo.SubstationDetailVO; 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.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.AreaLineService;
import com.njcn.influxdb.utils.InfluxDbUtils; import com.njcn.influxdb.utils.InfluxDbUtils;
import com.njcn.system.pojo.enums.StatisticsEnum;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.influxdb.dto.QueryResult; import org.influxdb.dto.QueryResult;
import org.influxdb.impl.InfluxDBResultMapper; import org.influxdb.impl.InfluxDBResultMapper;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*; import java.util.*;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.stream.Collectors;
import static com.njcn.event.influxdb.PqsOnlinerateQuery.devIdOr;
import static com.njcn.event.influxdb.QueryBuilder.*;
/** /**
* @author denghuajun * @author denghuajun
@@ -37,6 +53,9 @@ public class AreaLineServiceImpl implements AreaLineService {
private final InfluxDbUtils influxDbUtils; private final InfluxDbUtils influxDbUtils;
private final PqsOnlinerateQuery pqsOnlinerateQuery;
private final PqDeviceMapper pqDeviceMapper;
@Override @Override
public AreaLineVO getAreaLineVO(DeviceInfoParam deviceInfoParam) { public AreaLineVO getAreaLineVO(DeviceInfoParam deviceInfoParam) {
@@ -204,6 +223,108 @@ public class AreaLineServiceImpl implements AreaLineService {
return eventSeverityVO; return eventSeverityVO;
} }
/**
* 获取终端运行统计
*
* @param deviceInfoParam 参数
* @return 结果
*/
@Override
public TerminalRunningStatisticsVO getTerminalRunningStatistics(DeviceInfoParam.BusinessParam deviceInfoParam) {
// 区域计算
TerminalRunningVO area = analyzeTerminalRun(deviceInfoParam);
// 厂家计算
deviceInfoParam.getStatisticalType().setCode(StatisticsEnum.MANUFACTURER.getCode());
TerminalRunningVO factory = analyzeTerminalRun(deviceInfoParam);
return TerminalRunningStatisticsVO.buildVO(area, factory);
}
private TerminalRunningVO analyzeTerminalRun(DeviceInfoParam.BusinessParam deviceInfoParam) {
List<GeneralDeviceDTO> generalDeviceDTOList = generalDeviceInfoClient.getPracticalAllDeviceInfo(deviceInfoParam).getData();
if (CollUtil.isEmpty(generalDeviceDTOList)) {
return TerminalRunningVO.empty();
}
List<String> deviceIndexList =
generalDeviceDTOList.stream().flatMap(dto -> dto.getDeviceIndexes().stream()).collect(Collectors.toList());
if (CollUtil.isEmpty(deviceIndexList)) {
return TerminalRunningVO.empty();
}
List<PqsOnlinerate> pqsOnlinerateList =
pqsOnlinerateQuery.selectList(Arrays.asList("dev_id", "offlinemin", "onlinemin"),
devIdOr(deviceIndexList),
timeAnd(beginOfDay(deviceInfoParam.getSearchBeginTime()), endOfDay(deviceInfoParam.getSearchEndTime())));
List<PqDevice> pqDeviceList = pqDeviceMapper.queryRunFlagByDeviceIndexs(deviceIndexList);
List<TerminalRunningInfoVO> terminalRun = generalDeviceDTOList.parallelStream().map(dto -> {
List<String> deviceIndexes = dto.getDeviceIndexes();
TerminalRunningInfoVO terminalRunningInfoVO = new TerminalRunningInfoVO();
terminalRunningInfoVO.setAreaName(dto.getName());
terminalRunningInfoVO.setNumberOfTerminals(deviceIndexes.size());
terminalRunningInfoVO.setNormal(countDeviceRunStatus(pqDeviceList).apply(0, deviceIndexes));
terminalRunningInfoVO.setBreaks(countDeviceRunStatus(pqDeviceList).apply(1, deviceIndexes));
terminalRunningInfoVO.setShutdown(countDeviceRunStatus(pqDeviceList).apply(2, deviceIndexes));
terminalRunningInfoVO.setOnlineRate(computingDeviceOnlineRate(pqsOnlinerateList).apply(deviceIndexes));
return terminalRunningInfoVO;
}).sorted(TerminalRunningInfoVO.sortAscAreaName())
.collect(Collectors.toCollection(() -> Collections.synchronizedList(new ArrayList<>())));
Integer terminalSum = terminalRun.stream().mapToInt(TerminalRunningInfoVO::getNumberOfTerminals)
.sum();
Long normalSum = terminalRun.stream().mapToLong(TerminalRunningInfoVO::getNormal)
.sum();
Long breaksSum = terminalRun.stream().mapToLong(TerminalRunningInfoVO::getBreaks)
.sum();
Long shutdownSum = terminalRun.stream().mapToLong(TerminalRunningInfoVO::getShutdown)
.sum();
Double onlineRateAvg = computingDeviceOnlineRate(pqsOnlinerateList).apply(deviceIndexList);
return TerminalRunningVO.buildVO(terminalSum, normalSum, breaksSum, shutdownSum,
onlineRateAvg, terminalRun);
}
/**
* 计算装置在线率,在线率计算公式
* OnlineRate = OnLineMin/( OnLineMin+ OffLineMin) * 100%
*
* @param pqsOnlinerateList 装置在线记录
* @return 在线率
*/
private Function<List<String>, Double> computingDeviceOnlineRate(List<PqsOnlinerate> pqsOnlinerateList) {
return deviceIndexes -> {
List<PqsOnlinerate> value = pqsOnlinerateList.stream()
.filter(t -> deviceIndexes.contains(t.getDevId()))
.collect(Collectors.toList());
int onlineSum = value.stream().mapToInt(PqsOnlinerate::getOnlinemin).sum();
int offlineSum = value.stream().mapToInt(PqsOnlinerate::getOfflinemin).sum();
BigDecimal b1 = new BigDecimal(onlineSum);
BigDecimal b2 = new BigDecimal(offlineSum);
BigDecimal c = new BigDecimal(100);
if (b1.compareTo(BigDecimal.ZERO) == 0) {
return 0.00D;
}
return b1.divide(b1.add(b2), 4, RoundingMode.HALF_UP).multiply(c).doubleValue();
};
}
/**
* 根据终端运行状态0投运1热备用2停运查询数据数量
*
* @param pqDeviceList 设备列表
* @return 数据数量
*/
private BiFunction<Integer, List<String>, Long> countDeviceRunStatus(List<PqDevice> pqDeviceList) {
return (runFlag, deviceIndexes) -> pqDeviceList.stream()
.filter(t -> Objects.equals(t.getRunFlag(), runFlag))
.filter(t -> deviceIndexes.contains(t.getId()))
.count();
}
public List<EventHeatDeatilVO> getContion(DeviceInfoParam.BusinessParam deviceInfoParam, List<String> lineIndexs) { public List<EventHeatDeatilVO> getContion(DeviceInfoParam.BusinessParam deviceInfoParam, List<String> lineIndexs) {
// 组装sql语句 // 组装sql语句

View File

@@ -0,0 +1,198 @@
package com.njcn.event.service.Impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.njcn.device.api.GeneralDeviceInfoClient;
import com.njcn.device.pojo.dto.GeneralDeviceDTO;
import com.njcn.device.pojo.param.DeviceInfoParam;
import com.njcn.event.influxdb.PqsEventDetailQuery;
import com.njcn.event.pojo.po.EventDetail;
import com.njcn.event.pojo.vo.AreaCalculationVO;
import com.njcn.event.pojo.vo.AreaStatisticalVO;
import com.njcn.event.pojo.vo.AreaStatisticalVO.AreaStatisticsVO;
import com.njcn.event.pojo.vo.AreaStatisticalVO.MonthlyStatisticsVO;
import com.njcn.event.pojo.vo.AreaStatisticalVO.VoltageStatisticsVO;
import com.njcn.event.pojo.vo.MonthCalculationVO;
import com.njcn.event.pojo.vo.VoltageLevelCalculationVO;
import com.njcn.event.service.AreaStatisticalService;
import com.njcn.system.pojo.enums.StatisticsEnum;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static com.njcn.event.influxdb.PqsEventDetailQuery.*;
/**
* 区域统计
*
* @author : zhaojun
* @version : 1.0.0
* @date : 2022年06月24日 11:02
*/
@Service
@RequiredArgsConstructor
public class AreaStatisticalServiceImpl implements AreaStatisticalService {
private final GeneralDeviceInfoClient generalDeviceInfoClient;
private final PqsEventDetailQuery pqsEventDetailQuery;
/**
* 获取暂降区域 电压等级 月份统计
*
* @param deviceInfoParam 查询参数
* @return 暂降统计信息
*/
@Override
public AreaStatisticalVO getAreaCalculation(DeviceInfoParam.BusinessParam deviceInfoParam) {
// 获取指定部门下的监测点集合
List<GeneralDeviceDTO> generalDeviceDTOList = generalDeviceInfoClient.getPracticalAllDeviceInfo(deviceInfoParam).getData();
if (CollUtil.isEmpty(generalDeviceDTOList)) {
return AreaStatisticalVO.empty();
}
List<String> lineIds = generalDeviceDTOList.stream().flatMap(dto -> dto.getLineIndexes().stream()).collect(Collectors.toList());
if (CollUtil.isEmpty(lineIds)) {
return AreaStatisticalVO.empty();
}
List<EventDetail> eventDetailList = pqsEventDetailQuery.selectList(Arrays.asList("line_id", "eventass_index"),
lineIdOr(lineIds),
timeAnd(beginOfDay(deviceInfoParam.getSearchBeginTime()), endOfDay(deviceInfoParam.getSearchEndTime())));
if (CollUtil.isEmpty(eventDetailList)) {
return AreaStatisticalVO.empty();
}
AreaStatisticsVO areaStatisticsVO = statisticsAreaInfo(generalDeviceDTOList, eventDetailList);
MonthlyStatisticsVO monthCalculationVOS = statisticsMonthInfo(deviceInfoParam, eventDetailList);
deviceInfoParam.getStatisticalType().setCode(StatisticsEnum.VOLTAGE_LEVEL.getCode());
List<GeneralDeviceDTO> voltageLevelList = generalDeviceInfoClient.getPracticalAllDeviceInfo(deviceInfoParam).getData();
VoltageStatisticsVO voltageStatisticsVO = statisticalVoltageLevelInfo(voltageLevelList, eventDetailList);
return AreaStatisticalVO.buildVO(areaStatisticsVO, voltageStatisticsVO, monthCalculationVOS);
}
/**
* 统计月份信息
*
* @param deviceInfoParam 参数
* @param eventDetailList influxdb数据
* @return 统计月份信息
*/
private MonthlyStatisticsVO statisticsMonthInfo(DeviceInfoParam.BusinessParam deviceInfoParam, List<EventDetail> eventDetailList) {
List<DateTime> timeLimit = calculateTheTimePeriodRange(deviceInfoParam);
List<DateTime> monthStartAndEnd = calculateMonthStartAndEnd(timeLimit);
List<MonthCalculationVO> monthCalculationVOList = new ArrayList<>(monthStartAndEnd.size());
MonthCalculationVO monthCalculationVO;
for (int i = 0; i < monthStartAndEnd.size(); i += 2) {
DateTime beginMon = monthStartAndEnd.get(i);
DateTime endMon = monthStartAndEnd.get(i + 1);
List<EventDetail> eventDetails = getBetweenTimeEventDetailList(eventDetailList).apply(beginMon, endMon);
// 时间段内总记录数
Long count = (long) eventDetails.size();
// 时间段内非空记录数,剔除等于空的
Long linkedCount = countEventassIndexIsNoEmpty().apply(eventDetails);
monthCalculationVO = new MonthCalculationVO();
monthCalculationVO.setMonth(beginMon.toDateStr().substring(0, 7));
monthCalculationVO.setNotAssociated(count - linkedCount);
monthCalculationVO.setLinked(linkedCount);
monthCalculationVOList.add(monthCalculationVO);
}
Long notAssociatedSum = monthCalculationVOList.stream().mapToLong(MonthCalculationVO::getNotAssociated).sum();
return MonthlyStatisticsVO.buildVO(notAssociatedSum, monthCalculationVOList);
}
/**
* 统计电压等级信息
*
* @param generalDeviceDTOList 监测点数据
* @param eventDetailList influxdb数据
* @return 统计电压等级信息
*/
private VoltageStatisticsVO statisticalVoltageLevelInfo(List<GeneralDeviceDTO> generalDeviceDTOList, List<EventDetail> eventDetailList) {
List<VoltageLevelCalculationVO> voltageLevelCalculation = generalDeviceDTOList.parallelStream().map(t -> {
VoltageLevelCalculationVO voltageLevelCalculationVO = new VoltageLevelCalculationVO();
voltageLevelCalculationVO.setVoltageLevel(t.getName());
voltageLevelCalculationVO.setMonitoringPoints(t.getLineIndexes().size());
voltageLevelCalculationVO.setFrequency(countLineIndexes(eventDetailList).apply(t.getLineIndexes()));
return voltageLevelCalculationVO;
}).collect(Collectors.toCollection(() -> Collections.synchronizedList(new ArrayList<>())));
// 求和暂降次数
Long frequencySum = voltageLevelCalculation.stream().mapToLong(VoltageLevelCalculationVO::getFrequency).sum();
// 求装置数量
Integer monitoringPointSum = voltageLevelCalculation.stream().mapToInt(VoltageLevelCalculationVO::getMonitoringPoints).sum();
return VoltageStatisticsVO.buildVO(frequencySum, monitoringPointSum, voltageLevelCalculation);
}
/**
* 统计区域信息
*
* @param generalDeviceDTOList 监测点数据
* @param eventDetailList influxdb数据
* @return 统计区域信息
*/
private AreaStatisticsVO statisticsAreaInfo(List<GeneralDeviceDTO> generalDeviceDTOList, List<EventDetail> eventDetailList) {
List<AreaCalculationVO> areaCalculation = generalDeviceDTOList.parallelStream().map(t -> {
AreaCalculationVO calculationVO = new AreaCalculationVO();
calculationVO.setAreaName(t.getName());
calculationVO.setMonitoringPoints(t.getLineIndexes().size());
calculationVO.setFrequency(countLineIndexes(eventDetailList).apply(t.getLineIndexes()));
calculationVO.computeSarfi90();
return calculationVO;
}).sorted(AreaCalculationVO.sortAscAreaName()).collect(Collectors.toCollection(() -> Collections.synchronizedList(new ArrayList<>())));
// 求和暂降次数
Long frequencySum = areaCalculation.stream().mapToLong(AreaCalculationVO::getFrequency).sum();
// 求装置数量
Integer monitoringPointSum = areaCalculation.stream().mapToInt(AreaCalculationVO::getMonitoringPoints).sum();
return AreaStatisticsVO.buildVO(frequencySum, monitoringPointSum, areaCalculation);
}
/**
* 计算出月的开始时间和结束时间
*
* @param timeLimit 查询参数
* @return 月的开始时间和结束时间
*/
private List<DateTime> calculateMonthStartAndEnd(List<DateTime> timeLimit) {
return timeLimit.stream().flatMap(dateTime -> {
DateTime dateTime1 = DateUtil.beginOfMonth(dateTime);
DateTime dateTime2 = DateUtil.endOfMonth(dateTime);
return Stream.of(dateTime1, dateTime2);
}).collect(Collectors.toList());
}
/**
* 根据开始时间结束时间, 获取时间年月范围
*
* @param deviceInfoParam 查询参数
* @return 获取时间年月范围
*/
private List<DateTime> calculateTheTimePeriodRange(DeviceInfoParam.BusinessParam deviceInfoParam) {
DateTime beginTime = DateUtil.parse(deviceInfoParam.getSearchBeginTime(), DatePattern.NORM_DATE_PATTERN);
DateTime endTime = DateUtil.parse(deviceInfoParam.getSearchEndTime(), DatePattern.NORM_DATE_PATTERN);
return DateUtil.rangeToList(beginTime, endTime, DateField.MONTH);
}
}

View File

@@ -0,0 +1,67 @@
package com.njcn.event.service.Impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.utils.PubUtils;
import com.njcn.event.pojo.constant.Param;
import com.njcn.event.pojo.param.EventBaseParam;
import com.njcn.event.pojo.po.EventDetail;
import com.njcn.event.service.EventAnalysisService;
import com.njcn.influxdb.utils.InfluxDbUtils;
import lombok.RequiredArgsConstructor;
import org.influxdb.dto.QueryResult;
import org.influxdb.impl.InfluxDBResultMapper;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
/**
* pqs-event
*
* @author cdf
* @date 2022/6/23
*/
@Service
@RequiredArgsConstructor
public class EventAnalysisServiceImpl implements EventAnalysisService {
private final InfluxDbUtils influxDbUtils;
@Override
public Page<EventDetail> getEventAnalyse(EventBaseParam eventBaseParam) {
//查询sql语句
StringBuilder stringResult = new StringBuilder(Param.SELECT).append(Param.EVENT_DETAIL).append(Param.WHERE).
append("time >= '").append(DateUtil.beginOfDay(DateUtil.parse(eventBaseParam.getSearchBeginTime()))).append("' and ").append("time <= '").append(DateUtil.endOfDay(DateUtil.parse(eventBaseParam.getSearchEndTime()))).append("' and ")
.append("line_id= '").append(eventBaseParam.getLineId()).append("'");
int i = (eventBaseParam.getPageNum() - 1)*eventBaseParam.getPageSize();
stringResult.append("LIMIT ").append(eventBaseParam.getPageSize()).append(" OFFSET ").append(i).append(" tz('Asia/Shanghai')");
//查询sql语句总条数
StringBuilder stringTotal = new StringBuilder("SELECT COUNT(num) as aa FROM ").append(Param.EVENT_DETAIL).append(" WHERE ") .append("time >= '").append(DateUtil.beginOfDay(DateUtil.parse(eventBaseParam.getSearchBeginTime()))).append("' and ")
.append("time <= '").append(DateUtil.endOfDay(DateUtil.parse(eventBaseParam.getSearchEndTime()))).append("' and ");
stringTotal.append("line_id= '").append(eventBaseParam.getLineId()).append("' tz('Asia/Shanghai')");
//结果集
QueryResult result = influxDbUtils.query(stringResult.toString());
//总条数
QueryResult resultTotal = influxDbUtils.query(stringTotal.toString());
//结果集映射到对象中
InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper();
List<EventDetail> eventDetailList = influxDBResultMapper.toPOJO(result, EventDetail.class);
Page<EventDetail> page = new Page<>();
long total = new BigDecimal(resultTotal.getResults().get(0).getSeries().get(0).getValues().get(0).get(1).toString()).longValue();
page.setTotal(total);
page.setRecords(eventDetailList);
page.setCurrent(eventBaseParam.getPageNum());
page.setSize(eventBaseParam.getPageSize());
return page;
}
}

View File

@@ -1,8 +1,6 @@
package com.njcn.event.service.Impl; package com.njcn.event.service.Impl;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.event.mapper.EventDetailMapper;
import com.njcn.event.pojo.po.EventDetail; import com.njcn.event.pojo.po.EventDetail;
import com.njcn.event.service.EventDetailService; import com.njcn.event.service.EventDetailService;
import com.njcn.influxdb.utils.InfluxDbUtils; import com.njcn.influxdb.utils.InfluxDbUtils;
@@ -14,6 +12,7 @@ import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.util.List; import java.util.List;
import java.util.Objects;
/** /**
* @author denghuajun * @author denghuajun
@@ -23,7 +22,7 @@ import java.util.List;
@Slf4j @Slf4j
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class EventDetailServiceImpl extends ServiceImpl<EventDetailMapper, EventDetail> implements EventDetailService { public class EventDetailServiceImpl implements EventDetailService {
private final InfluxDbUtils influxDbUtils; private final InfluxDbUtils influxDbUtils;
@@ -33,10 +32,9 @@ public class EventDetailServiceImpl extends ServiceImpl<EventDetailMapper, Event
StringBuilder stringBuilder = new StringBuilder(); 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("time >= '").append(DateUtil.beginOfDay(DateUtil.parse(startTime))).append("' and ").append("time <= '").append(DateUtil.endOfDay(DateUtil.parse(endTime))).append("' and ");
//sql语句 //sql语句
stringBuilder.append("line_id ='").append(id).append("'"); stringBuilder.append("line_id ='").append(id).append("'").append(" tz('Asia/Shanghai')");
String sql = "select * from pqs_eventdetail where " + stringBuilder.toString(); String sql = "select * from pqs_eventdetail where " + stringBuilder;
System.out.println("sql>>>>>>>>>>>>>>>>>>>>>>>>"+sql);
//获取暂降事件 //获取暂降事件
QueryResult result = influxDbUtils.query(sql); QueryResult result = influxDbUtils.query(sql);
InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper(); InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper();
@@ -49,17 +47,18 @@ public class EventDetailServiceImpl extends ServiceImpl<EventDetailMapper, Event
EventDetail eventDetail = new EventDetail(); EventDetail eventDetail = new EventDetail();
//组装sql语句 //组装sql语句
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("time >= '").append(time).append("' and ").append("line_id ='").append(id).append("' limit 1 tz('Asia/Shanghai')"); stringBuilder.append("time = '").append(time).append("' and ").append("line_id ='").append(id).append("' limit 1 tz('Asia/Shanghai')");
String sql = "select * from pqs_eventdetail where " + stringBuilder; String sql = "select * from pqs_eventdetail where " + stringBuilder;
System.out.println("sql>>>>>>>>>>>>>>>>>>>>>>>>"+sql);
//获取暂降事件 //获取暂降事件
QueryResult result = influxDbUtils.query(sql); QueryResult result = influxDbUtils.query(sql);
InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper(); InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper();
if (!Objects.isNull(result)) {
List<EventDetail> detailList = influxDBResultMapper.toPOJO(result, EventDetail.class); List<EventDetail> detailList = influxDBResultMapper.toPOJO(result, EventDetail.class);
if (!CollectionUtils.isEmpty(detailList)) { if (!CollectionUtils.isEmpty(detailList)) {
eventDetail = detailList.get(0); eventDetail = detailList.get(0);
} }
}
return eventDetail; return eventDetail;
} }
@@ -72,11 +71,12 @@ public class EventDetailServiceImpl extends ServiceImpl<EventDetailMapper, Event
if (lineIndexes.size() - i != 1) { if (lineIndexes.size() - i != 1) {
stringBuilder.append("line_id ='").append(lineIndexes.get(i)).append("' or "); stringBuilder.append("line_id ='").append(lineIndexes.get(i)).append("' or ");
} else { } else {
stringBuilder.append("line_id ='").append(lineIndexes.get(i)).append("' "); stringBuilder.append("line_id ='").append(lineIndexes.get(i)).append("' ").append(" tz('Asia/Shanghai')");
} }
} }
//sql语句 //sql语句
String sql = "SELECT * FROM pqs_eventdetail WHERE " + stringBuilder; String sql = "SELECT * FROM pqs_eventdetail WHERE " + stringBuilder;
System.out.println("sql------------->>>"+sql);
//结果集 //结果集
QueryResult result = influxDbUtils.query(sql); QueryResult result = influxDbUtils.query(sql);
//结果集映射到对象中 //结果集映射到对象中
@@ -101,7 +101,7 @@ public class EventDetailServiceImpl extends ServiceImpl<EventDetailMapper, Event
} }
} }
int i = (pageNum - 1)*pageSize; int i = (pageNum - 1)*pageSize;
stringBuilder.append("LIMIT ").append(pageSize).append(" OFFSET ").append(i); stringBuilder.append("LIMIT ").append(pageSize).append(" OFFSET ").append(i).append(" tz('Asia/Shanghai')");
//sql语句 //sql语句
String sql = "SELECT * FROM pqs_eventdetail WHERE " + stringBuilder; String sql = "SELECT * FROM pqs_eventdetail WHERE " + stringBuilder;
//结果集 //结果集

View File

@@ -3,13 +3,18 @@ package com.njcn.event.service.Impl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.pojo.dto.wave.WaveDataDTO; import com.njcn.common.pojo.dto.wave.WaveDataDTO;
import com.njcn.common.pojo.enums.common.ServerEnum; import com.njcn.common.pojo.enums.common.ServerEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.utils.PubUtils;
import com.njcn.common.utils.wave.AnalyWave; import com.njcn.common.utils.wave.AnalyWave;
import com.njcn.device.api.GeneralDeviceInfoClient; import com.njcn.device.api.GeneralDeviceInfoClient;
import com.njcn.device.api.LineFeignClient; import com.njcn.device.api.LineFeignClient;
import com.njcn.device.pojo.dto.GeneralDeviceDTO; import com.njcn.device.pojo.dto.GeneralDeviceDTO;
import com.njcn.device.pojo.vo.LineDetailDataVO; import com.njcn.device.pojo.vo.LineDetailDataVO;
import com.njcn.event.config.EventBaseConfig;
import com.njcn.event.enums.EventResponseEnum;
import com.njcn.event.mapper.TransientMapper; import com.njcn.event.mapper.TransientMapper;
import com.njcn.event.pojo.param.TransientParam; import com.njcn.event.pojo.param.TransientParam;
import com.njcn.event.pojo.param.WaveFileParam;
import com.njcn.event.pojo.po.EventDetail; import com.njcn.event.pojo.po.EventDetail;
import com.njcn.event.pojo.vo.TransientVO; import com.njcn.event.pojo.vo.TransientVO;
import com.njcn.event.service.EventDetailService; import com.njcn.event.service.EventDetailService;
@@ -18,6 +23,8 @@ import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.time.Instant; import java.time.Instant;
@@ -28,6 +35,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/** /**
* @author: chenchao * @author: chenchao
@@ -46,6 +55,8 @@ public class TransientServiceImpl implements TransientService {
private final EventDetailService eventDetailService; private final EventDetailService eventDetailService;
private final EventBaseConfig eventBaseConfig;
@Override @Override
public Page<TransientVO> getTransientData(TransientParam transientParam) { public Page<TransientVO> getTransientData(TransientParam transientParam) {
Page<TransientVO> page = new Page<>(); Page<TransientVO> page = new Page<>();
@@ -76,12 +87,15 @@ public class TransientServiceImpl implements TransientService {
// List<EventDetail> detailList = partition.get(transientParam.getPageNum() - 1); // List<EventDetail> detailList = partition.get(transientParam.getPageNum() - 1);
if (!CollectionUtils.isEmpty(eventDetailData)) { if (!CollectionUtils.isEmpty(eventDetailData)) {
List<String> collect = eventDetailData.stream().map(EventDetail::getLineId).collect(Collectors.toList()); List<String> collect = eventDetailData.stream().map(EventDetail::getLineId).collect(Collectors.toList());
collect = collect.stream().distinct().collect(Collectors.toList());
List<TransientVO> transientData = transientMapper.getTransientData(collect); List<TransientVO> transientData = transientMapper.getTransientData(collect);
int i = 1;
for (EventDetail eventDetail: eventDetailData) { for (EventDetail eventDetail: eventDetailData) {
if (!Objects.isNull(eventDetail)) { if (!Objects.isNull(eventDetail)) {
TransientVO transientVO = new TransientVO(); TransientVO transientVO = new TransientVO();
transientVO.setId(eventDetail.getLineId()); transientVO.setId(eventDetail.getLineId());
transientVO.setNumber(i++);
transientVO.setWaveName(eventDetail.getWaveName());
Instant timeId = eventDetail.getTimeId(); Instant timeId = eventDetail.getTimeId();
ZoneId zoneId = ZoneId.systemDefault(); ZoneId zoneId = ZoneId.systemDefault();
LocalDateTime localDateTime = LocalDateTime.ofInstant(timeId, zoneId); LocalDateTime localDateTime = LocalDateTime.ofInstant(timeId, zoneId);
@@ -112,14 +126,15 @@ public class TransientServiceImpl implements TransientService {
transientVO.setTrigType("录波"); transientVO.setTrigType("录波");
break; break;
} }
Double value = new BigDecimal(eventDetail.getEventValue()).setScale(3, BigDecimal.ROUND_DOWN).doubleValue(); Double value = new BigDecimal(eventDetail.getEventValue()).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
transientVO.setEventValue(value); transientVO.setEventValue(new BigDecimal(value*100).setScale(0,BigDecimal.ROUND_HALF_UP).doubleValue());
Double values = new BigDecimal(1 - value).setScale(3, BigDecimal.ROUND_DOWN).doubleValue(); transientVO.setEventValues(100-transientVO.getEventValue());
transientVO.setEventValues(values);
transientVO.setPersistTime((Float.parseFloat(eventDetail.getPersistTime().toString()))/1000); transientVO.setPersistTime((Float.parseFloat(eventDetail.getPersistTime().toString()))/1000);
Float eventValue = Float.parseFloat(eventDetail.getEventValue().toString()); Float eventValue = Float.parseFloat(eventDetail.getEventValue().toString());
transientVO.setYZD(getYZD(transientVO.getPersistTime(), eventValue)); Float persistTime = Float.parseFloat(eventDetail.getPersistTime().toString());
transientVO.setYZD(getYZD(persistTime, eventValue));
transientVOS.add(transientVO); transientVOS.add(transientVO);
} }
} }
@@ -143,20 +158,306 @@ public class TransientServiceImpl implements TransientService {
@Override @Override
public WaveDataDTO getTransientAnalyseWave(String timeId, String lineId) { public WaveDataDTO getTransientAnalyseWave(String timeId, String lineId) {
WaveDataDTO waveDataDTO = new WaveDataDTO();
//根据监测点id获取监测点详情 //根据监测点id获取监测点详情
LineDetailDataVO lineDetailData = lineFeignClient.getLineDetailData(lineId).getData(); LineDetailDataVO lineDetailData = lineFeignClient.getLineDetailData(lineId).getData();
String ip = lineDetailData.getIp();
EventDetail eventDetailByTime = eventDetailService.getEventDetailByTime(lineId, timeId); EventDetail eventDetailByTime = eventDetailService.getEventDetailByTime(lineId, timeId);
String ip = lineDetailData.getIp();
String waveName = eventDetailByTime.getWaveName(); String waveName = eventDetailByTime.getWaveName();
// TransientVO transientVO = transientMapper.getTransientDataById(lineId);
// String name = transientVO.getName();
// String substation = transientVO.getSubstation();
// Double eventValue = new BigDecimal(eventDetailByTime.getEventValue()).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
// Double v = new BigDecimal(eventValue*100).setScale(0,BigDecimal.ROUND_HALF_UP).doubleValue();
// Double persistTime = eventDetailByTime.getPersistTime()/1000;
// waveDataVO.setName("变电站名称: "+ substation +" 监测点名称: "+ name +" 发生时刻: "+ timeId +" 暂降幅值: "+ v +"% 持续时间: "+ persistTime +"s");
// waveDataVO.setTargetName("相电压有效值");
AnalyWave analyWave = new AnalyWave(); AnalyWave analyWave = new AnalyWave();
System.out.println("path----------------------"+"C:\\Users\\陈超\\Desktop\\Comtrade\\"+ip+"\\"+waveName); WaveDataDTO comtrade = analyWave.getComtrade(eventBaseConfig.getWavePath()+"\\"+ip+"\\"+waveName+".CFG", 1);
WaveDataDTO comtrade = analyWave.getComtrade("C:\\Users\\陈超\\Desktop\\Comtrade\\192.168.0.58\\222.CFG", 1); if (Objects.isNull(comtrade.getComtradeCfgDTO())) {
// WaveDataDTO comtrade = analyWave.getComtrade("C:\\Users\\陈超\\Desktop\\Comtrade\\"+ip+"\\"+waveName, 1); throw new BusinessException(EventResponseEnum.ANALYSEWAVE_NOT_FOUND);
WaveDataDTO waveDataDTO = analyWave.getValidData(comtrade); }
// WaveDataDTO comtrade = analyWave.getComtrade("C:\\Users\\陈超\\Desktop\\comtrade\\192.168.0.58\\222.CFG", 1);
waveDataDTO = analyWave.getValidData(comtrade);
waveDataDTO.setPtType(PubUtils.ptTypeName(lineDetailData.getPtType()));
double pt1 = Double.parseDouble(lineDetailData.getPt().split("/")[0]);
double pt2 = Double.parseDouble(lineDetailData.getPt().split("/")[1]);
double ct1 = Double.parseDouble(lineDetailData.getCt().split("/")[0]);
double ct2 = Double.parseDouble(lineDetailData.getCt().split("/")[1]);
waveDataDTO.setPt(pt1/pt2);
waveDataDTO.setCt(ct1/ct2);
return waveDataDTO; return waveDataDTO;
} }
@Override
public HttpServletResponse downloadWaveFile(WaveFileParam waveFileParam, HttpServletResponse response) throws Exception {
List<String> lineId = waveFileParam.getLineId();
List<String> timeId = waveFileParam.getTimeId();
copyTempData(timeId,lineId);
zipCompress(new File("C:\\Users\\陈超\\Desktop\\YSWJ\\comtrade"));
String zipPath = "C:\\Users\\陈超\\Desktop\\YSWJ\\comtrade.zip";
try {
// path是指欲下载的文件的路径。
File file = new File(zipPath);
// 取得文件名。
String filename = file.getName();
// 取得文件的后缀名。
String ext = filename.substring(filename.lastIndexOf(".") + 1).toUpperCase();
// 以流的形式下载文件。
InputStream fis = new BufferedInputStream(new FileInputStream(zipPath));
byte[] buffer = new byte[fis.available()];
fis.read(buffer);
fis.close();
// 清空response
response.reset();
// 设置response的Header
response.addHeader("Content-Disposition", "attachment;filename=" + new String(filename.getBytes()));
response.addHeader("Content-Length", "" + file.length());
OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
response.setContentType("application/octet-stream");
toClient.write(buffer);
toClient.flush();
toClient.close();
} catch (IOException ex) {
ex.printStackTrace();
}
delFile(zipPath);
deleteDirectoryLegacyIO(new File("C:\\Users\\陈超\\Desktop\\YSWJ\\comtrade"));
return response;
}
/**复制保存文件 */
public void copyTempData(List<String> timeId, List<String> lineId) throws IOException {
for (int i=0; i<timeId.size(); i++) {
//根据监测点id获取监测点详情
LineDetailDataVO lineDetailData = lineFeignClient.getLineDetailData(lineId.get(i)).getData();
EventDetail eventDetailByTime = eventDetailService.getEventDetailByTime(lineId.get(i), timeId.get(i));
if (Objects.isNull(lineDetailData.getIp()) && Objects.isNull(eventDetailByTime.getWaveName())) {
throw new BusinessException(EventResponseEnum.EVENT_NOT_FOUND);
}
String ip = lineDetailData.getIp();
String waveName = eventDetailByTime.getWaveName();
File srcCFGFile = new File(eventBaseConfig.getWavePath()+"\\"+ip+"\\"+waveName+".CFG");
File srcDATFile = new File(eventBaseConfig.getWavePath()+"\\"+ip+"\\"+waveName+".DAT");
if (!srcCFGFile.exists() && !srcDATFile.exists()) {
throw new BusinessException(EventResponseEnum.ANALYSEWAVE_NOT_FOUND);
}
File temp = new File("C:\\Users\\陈超\\Desktop\\YSWJ\\comtrade\\"+ip);
temp.mkdirs();
// File cfg = new File("C:\\Users\\陈超\\Desktop\\YSWJ\\comtrade\\a1234567890\\"+srcCFGFile.getName());
// File dat = new File("C:\\Users\\陈超\\Desktop\\YSWJ\\comtrade\\a1234567890\\"+srcDATFile.getName());
File cfg = new File("C:\\Users\\陈超\\Desktop\\YSWJ\\comtrade\\"+ip+"\\"+srcCFGFile.getName());
File dat = new File("C:\\Users\\陈超\\Desktop\\YSWJ\\comtrade\\"+ip+"\\"+srcDATFile.getName());
writeFile(srcCFGFile,cfg);
writeFile(srcDATFile,dat);
}
}
//读写文件
public static void writeFile(File wave, File temp) throws IOException {
FileInputStream fis=new FileInputStream(wave);
FileOutputStream fos=new FileOutputStream(temp);
int len;
byte[] bys=new byte[1024];
while((len=fis.read(bys))!=-1){
fos.write(bys, 0, len);
fos.flush();
}
fos.close();
fis.close();
}
//==========================================================================================================
/**
* 将文件夹及文件夹包含的内容压缩成zip文件
* (为了解决中文乱码的问题ZipOutputStream用org.apache.tools.zip.*)
* @param inputFile 源文件(夹)
* @return File 压缩后的文件(路径在源文件的文件夹路径下)
*/
public static File zipCompress(File inputFile) throws Exception {
File zipFile = null;
ZipOutputStream zos = null;
if(inputFile != null && inputFile.exists()) {
try {
String path = inputFile.getCanonicalPath();
String zipFileName = path + ".zip";
zipFile = new File(zipFileName);
if(zipFile.exists()) {
zipFile.delete();
}
zipFile.createNewFile();//创建文件
zos = new ZipOutputStream(new FileOutputStream(zipFile));
//压缩文件或文件夹
compressFile(zos, inputFile, inputFile.getName());
}catch(Exception e) {
System.out.println("文件压缩异常:" + e);
throw e;
}finally {
try {
if(zos != null) {
//先调用outputStream的flush()再关闭流;
//流如果未正常关闭,则会在解压的时候出现压缩文件损坏的现象
zos.flush();
zos.close();
}
}catch(Exception ex) {
System.out.println("输出流关闭异常:" + ex);
}
}
}
return zipFile;
}
/**
* 压缩文件或文件夹 (ZipEntry 使用org.apache.tools.zip.*,不要用 java.util.zip.*)
* @param zos zip输出流
* @param sourceFile 源文件
* @param baseName 父路径
* @throws Exception 异常
*/
public static void compressFile(ZipOutputStream zos, File sourceFile, String baseName) throws Exception{
if(!sourceFile.exists()) {
return;
}
//若路径为目录(文件夹)
if(sourceFile.isDirectory()) {
//取出文件夹中的文件(或子文件夹)
File[] fileList = sourceFile.listFiles();
//若文件夹为空,则创建一个目录进入点
if(fileList.length == 0) {
//文件名称后跟File.separator表示这是一个文件夹
zos.putNextEntry(new ZipEntry(baseName + File.separator));
//若文件夹非空则递归调用compressFile,对文件夹中的每个文件或每个文件夹进行压缩
}else {
for(int i = 0; i < fileList.length; i++) {
compressFile(zos, fileList[i],
baseName + File.separator + fileList[i].getName());
}
}
//若为文件,则先创建目录进入点,再将文件写入zip文件中
}else {
ZipEntry ze = new ZipEntry(baseName);
//设置ZipEntry的最后修改时间为源文件的最后修改时间
ze.setTime(sourceFile.lastModified());
zos.putNextEntry(ze);
FileInputStream fis = new FileInputStream(sourceFile);
copyStream(fis, zos);
try {
if(fis != null) {
fis.close();
}
}catch(Exception e) {
System.out.println("输入流关闭异常:" + e);
}
}
}
/**
* 流拷贝
* @param in 输入流
* @param out 输出流
* @throws IOException
*/
public static void copyStream(InputStream in, OutputStream out) throws IOException{
int bufferLength = 1024 * 100;
synchronized(in) {
synchronized(out) {
int count = 0;
byte[] buffer = new byte[bufferLength];
while((count = in.read(buffer, 0, bufferLength)) != -1) {
out.write(buffer, 0, count);
}
out.flush();
}
}
}
//=================================================================================================================
/**处理文件路径和指定压缩包位置 */
public static String downloadWaveMoreFile(List<String> pathList) {
List<File> list = new ArrayList<>();
for (String string: pathList) {
String path = string;
//待压缩的多个源文件
File f1 = new File(path+".CFG");
File f2 = new File(path+".DAT");
list.add(f1);
list.add(f2);
}
File[] srcfile = list.toArray(new File[0]);
String zipPath = "C:\\Users\\陈超\\Desktop\\YSWJ\\新下载的波形文件.zip";
//压缩后的文件存放路径
File zipfile = new File(zipPath);
zipFiles(srcfile, zipfile);
return zipPath;
}
/**
* 压缩多个文件成一个zip文件
* @param srcfile源文件列表
* @param zipfile压缩后的文件
*/
public static void zipFiles(File[] srcfile, File zipfile) {
byte[] buf = new byte[1024];
try {
//ZipOutputStream类完成文件或文件夹的压缩
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipfile));
for (int i = 0; i < srcfile.length; i++) {
FileInputStream in = new FileInputStream(srcfile[i]);
out.putNextEntry(new ZipEntry(srcfile[i].getName()));
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
out.closeEntry();
in.close();
}
out.close();
System.out.println("压缩完成.");
} catch (Exception e) {
e.printStackTrace();
}
}
/**删除文件(夹)和空文件夹 */
private void deleteDirectoryLegacyIO(File file) {
File[] list = file.listFiles(); //无法做到list多层文件夹数据
if (list != null) {
for (File temp : list) { //先去递归删除子文件夹及子文件
deleteDirectoryLegacyIO(temp); //注意这里是递归调用
}
}
if (file.delete()) { //再删除自己本身的文件夹
System.out.printf("删除成功 : %s%n", file);
} else {
System.err.printf("删除失败 : %s%n", file);
}
}
/**
* 删除文件
* @param filePathAndName 指定得路径
*/
public static void delFile(String filePathAndName) {
try {
String filePath = filePathAndName;
filePath = filePath.toString();
java.io.File myDelFile = new java.io.File(filePath);
myDelFile.delete();
} catch (Exception e) {
System.out.println("删除文件操作出错");
e.printStackTrace();
}
}
/** /**
* 获取该事件的严重度 * 获取该事件的严重度
* *

View File

@@ -3,8 +3,11 @@ package com.njcn.event.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.pojo.dto.wave.WaveDataDTO; import com.njcn.common.pojo.dto.wave.WaveDataDTO;
import com.njcn.event.pojo.param.TransientParam; import com.njcn.event.pojo.param.TransientParam;
import com.njcn.event.pojo.param.WaveFileParam;
import com.njcn.event.pojo.vo.TransientVO; import com.njcn.event.pojo.vo.TransientVO;
import javax.servlet.http.HttpServletResponse;
/** /**
* @author: chenchao * @author: chenchao
* @date: 2022/03/29 10:40 * @date: 2022/03/29 10:40
@@ -25,5 +28,11 @@ public interface TransientService {
* @return * @return
*/ */
WaveDataDTO getTransientAnalyseWave(String timeId, String lineId); WaveDataDTO getTransientAnalyseWave(String timeId, String lineId);
/**
* 功能描述: 暂态事件波形文件下载
* @param waveFileParam
* @return
*/
HttpServletResponse downloadWaveFile(WaveFileParam waveFileParam, HttpServletResponse response) throws Exception;
} }

View File

@@ -0,0 +1,34 @@
package com.njcn.event.utils;
import cn.hutool.core.collection.CollectionUtil;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* pqs-event
* 公共方法
* @author cdf
* @date 2022/6/30
*/
@Component
public class CommUtil {
/**
* 组装为influxdb监测点参数
*
* @param lineIds 监测点参数
* @return StringBuilder
*/
public static StringBuilder assToInfluxParam(List<String> lineIds){
StringBuilder lineIdsStr = new StringBuilder("(");
for (int i = 0; i < lineIds.size(); i++) {
if (lineIds.size() - i != 1) {
lineIdsStr.append("line_id ='").append(lineIds.get(i)).append("' or ");
} else {
lineIdsStr.append("line_id ='").append(lineIds.get(i)).append("') ");
}
}
return lineIdsStr;
}
}

View File

@@ -0,0 +1,118 @@
package com.njcn.event;
import com.njcn.event.pojo.PqsEventDetail;
import com.njcn.event.pojo.PqsOnlinerateAggregate;
import com.njcn.event.pojo.PqsEventDetailCount;
import com.njcn.influxdb.utils.InfluxDbUtils;
import org.influxdb.dto.QueryResult;
import org.influxdb.impl.InfluxDBResultMapper;
import org.influxdb.querybuilder.SelectQueryImpl;
import org.influxdb.querybuilder.SelectionQueryImpl;
import org.influxdb.querybuilder.WhereNested;
import org.influxdb.querybuilder.WhereQueryImpl;
import org.influxdb.querybuilder.clauses.Clause;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Arrays;
import java.util.List;
import static com.njcn.influxdb.param.InfluxDBPublicParam.DATABASE;
import static com.njcn.influxdb.param.InfluxDBPublicParam.PQS_EVENT_DETAIL;
import static org.influxdb.querybuilder.BuiltQuery.QueryBuilder.*;
import static org.influxdb.querybuilder.FunctionFactory.sum;
@RunWith(SpringRunner.class)
@SpringBootTest
public class EventBootApplicationTest {
@Autowired
private InfluxDbUtils influxDbUtils;
// TODO https://github.com/influxdata/influxdb-java/blob/master/QUERY_BUILDER.md
@Test
public void queryList() {
// or 条件数据
List<Clause> clauses = getClauses();
SelectQueryImpl selectQuery = select().column("line_id").column("eventass_index").from(DATABASE, PQS_EVENT_DETAIL);
WhereQueryImpl<SelectQueryImpl> where = selectQuery.where();
// WHERE (line_id = '1' OR line_id = '2' OR line_id = '3') 加上前后()
whereAndNested(clauses, where);
// AND time >= '2022-05-01T00:00:00Z' AND time <= '2022-09-01T00:00:00Z' tz('Asia/Shanghai');
where.and(gte("time", "2022-05-01T00:00:00Z")).and(lte("time", "2022-09-01T00:00:00Z"));
where.tz("Asia/Shanghai");
QueryResult result = influxDbUtils.query(selectQuery.getCommand());
InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper();
List<PqsEventDetail> re = influxDBResultMapper.toPOJO(result, PqsEventDetail.class);
Assert.assertTrue(re.size() > 0);
}
@Test
public void queryCount() {
// or 条件数据
List<Clause> clauses = getClauses();
SelectQueryImpl selectQuery = select().count("eventass_index").from(DATABASE, PQS_EVENT_DETAIL);
WhereQueryImpl<SelectQueryImpl> where = selectQuery.where();
// WHERE (line_id = '1' OR line_id = '2' OR line_id = '3') 加上前后()
whereAndNested(clauses, where);
// AND time >= '2022-05-01T00:00:00Z' AND time <= '2022-09-01T00:00:00Z' tz('Asia/Shanghai');
where.and(gte("time", "2022-05-01T00:00:00Z")).and(lte("time", "2022-09-01T00:00:00Z"));
where.tz("Asia/Shanghai");
QueryResult result = influxDbUtils.query(selectQuery.getCommand());
InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper();
List<PqsEventDetailCount> re = influxDBResultMapper.toPOJO(result, PqsEventDetailCount.class);
Assert.assertTrue(re.size() > 0);
}
@Test
public void queryAggregate() {
// SELECT (SUM(onlinemin) / (SUM(onlinemin) + SUM(offlinemin))) * 100 FROM pqs_onlinerate
SelectionQueryImpl select = select();
SelectionQueryImpl sum = select.op(op(sum("onlinemin"), "/", op(sum("onlinemin"), "+", sum("offlinemin"))), "*", 100)
.as("value");
SelectQueryImpl selectQuery = sum.from(DATABASE, "pqs_onlinerate");
WhereQueryImpl<SelectQueryImpl> where = selectQuery.where();
// AND time >= '2022-05-01T00:00:00Z' AND time <= '2022-09-01T00:00:00Z' tz('Asia/Shanghai');
where.and(gte("time", "2022-05-01T00:00:00Z")).and(lte("time", "2022-09-01T00:00:00Z"));
where.tz("Asia/Shanghai");
QueryResult result = influxDbUtils.query(selectQuery.getCommand());
InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper();
List<PqsOnlinerateAggregate> re = influxDBResultMapper.toPOJO(result, PqsOnlinerateAggregate.class);
Assert.assertTrue(re.size() > 0);
}
private List<Clause> getClauses() {
Clause c1 = eq("line_id", "5e467a40023b299070682eb21f2ec9a1");
Clause c2 = eq("line_id", "183245996f303ebfd80eeb3377cecdc2");
Clause c3 = eq("line_id", "0d46f54420246e999d5c68b3133f668c");
return Arrays.asList(c1, c2, c3);
}
private void whereAndNested(List<Clause> clauses, WhereQueryImpl<SelectQueryImpl> whereQuery) {
WhereNested<WhereQueryImpl<SelectQueryImpl>> andNested = whereQuery.andNested();
for (Clause clause : clauses) {
andNested.or(clause);
}
andNested.close();
}
}

View File

@@ -0,0 +1,81 @@
package com.njcn.event.pojo;
import lombok.Data;
import org.influxdb.annotation.Column;
import org.influxdb.annotation.Measurement;
import java.time.Instant;
import static com.njcn.influxdb.param.InfluxDBPublicParam.PQS_EVENT_DETAIL;
@Data
@Measurement(name = PQS_EVENT_DETAIL)
public class PqsEventDetail {
@Column(name = "line_id")
private String lineId;
@Column(name = "time")
private Instant time;
@Column(name = "event_describe")
private String eventDescribe;
@Column(name = "wave_type")
private Integer waveType;
@Column(name = "persist_time")
private Double persistTime;
@Column(name = "event_value")
private Double eventValue;
@Column(name = "event_reason")
private String eventReason;
@Column(name = "event_type")
private String eventType;
@Column(name = "eventass_index")
private String eventassIndex;
@Column(name = "dq_time")
private Integer dqTime;
@Column(name = "deal_time")
private String dealTime;
@Column(name = "deal_flag")
private Integer dealFlag;
@Column(name = "num")
private Integer num;
@Column(name = "file_flag")
private Integer fileFlag;
@Column(name = "first_time")
private String firstTime;
@Column(name = "first_type")
private String firstType;
@Column(name = "first_ms")
private Integer firstMs;
@Column(name = "wave_name")
private String waveName;
@Column(name = "energy")
private Double energy;
@Column(name = "severity")
private Double severity;
@Column(name = "sagsource")
private String sagSource;
@Column(name = "create_time")
private String createTime;
}

View File

@@ -0,0 +1,20 @@
package com.njcn.event.pojo;
import lombok.Data;
import org.influxdb.annotation.Column;
import org.influxdb.annotation.Measurement;
import java.time.Instant;
import static com.njcn.influxdb.param.InfluxDBPublicParam.PQS_EVENT_DETAIL;
@Data
@Measurement(name = PQS_EVENT_DETAIL)
public class PqsEventDetailCount {
@Column(name = "time")
private Instant time;
@Column(name = "count")
private Integer count;
}

View File

@@ -0,0 +1,18 @@
package com.njcn.event.pojo;
import lombok.Data;
import org.influxdb.annotation.Column;
import org.influxdb.annotation.Measurement;
import java.time.Instant;
@Data
@Measurement(name = "pqs_onlinerate")
public class PqsOnlinerateAggregate {
@Column(name = "time")
private Instant time;
@Column(name = "value")
private Double value;
}