终端异常统计接口开发
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
package com.njcn.device.pq.pojo.po;
|
||||
|
||||
import com.njcn.db.bo.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class TopMsgPO extends BaseEntity {
|
||||
|
||||
private String cityName;
|
||||
|
||||
private String subName;
|
||||
|
||||
private String deviceName;
|
||||
|
||||
/**
|
||||
* 终端异常设备数量
|
||||
*/
|
||||
private Integer deviceAbnormalNum;
|
||||
|
||||
private String lineGrade;
|
||||
|
||||
/**
|
||||
* 日期
|
||||
*/
|
||||
private String time;
|
||||
|
||||
/**
|
||||
* 装置id
|
||||
*/
|
||||
private String devId;
|
||||
|
||||
/**
|
||||
* 通信中断次数
|
||||
*/
|
||||
private Integer comOutCount;
|
||||
|
||||
/**
|
||||
* 通信中断时间段描述
|
||||
*/
|
||||
private String comOutDesc;
|
||||
|
||||
/**
|
||||
* 数据完整性标识 0.不达标 1.达标
|
||||
*/
|
||||
private String integrityFlag;
|
||||
|
||||
/**
|
||||
* 数据完整性
|
||||
*/
|
||||
private Integer integrityValue;
|
||||
|
||||
/**
|
||||
* 告警次数
|
||||
*/
|
||||
private Integer alarmCount;
|
||||
|
||||
/**
|
||||
* 告警描述
|
||||
*/
|
||||
private String alarmDesc;
|
||||
|
||||
/**
|
||||
* 流量超标标识 0.不达标 1.达标
|
||||
*/
|
||||
private Integer flowFlag;
|
||||
|
||||
/**
|
||||
* 流量使用百分比
|
||||
*/
|
||||
private float flowValue;
|
||||
|
||||
/**
|
||||
* 状态 0.删除 1.正常
|
||||
*/
|
||||
private String state;
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.common.utils.LogUtil;
|
||||
import com.njcn.device.pq.pojo.param.DeviceInfoParam;
|
||||
import com.njcn.device.pq.pojo.param.PqsParam;
|
||||
import com.njcn.device.pq.pojo.po.TopMsgPO;
|
||||
import com.njcn.device.pq.pojo.vo.*;
|
||||
import com.njcn.device.pq.service.LineService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
@@ -142,4 +143,24 @@ public class OperationContrController extends BaseController {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/getDailyDeviceAbnormalStatistics")
|
||||
@ApiOperation("获取终端异常统计")
|
||||
@ApiImplicitParam(name = "conditionBusinessParam", value = "实体", required = true)
|
||||
public HttpResult<Page<TopMsgPO>> dailyDeviceAbnormalStatistics(@RequestBody PqsParam param) {
|
||||
String methodDescribe = getMethodDescribe("dailyDeviceAbnormalStatistics");
|
||||
Page<TopMsgPO> result = lineService.dailyDeviceAbnormalStatistics(param);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/getDailyDeviceAbnormal")
|
||||
@ApiOperation("获取终端异常")
|
||||
@ApiImplicitParam(name = "conditionBusinessParam", value = "实体", required = true)
|
||||
public HttpResult<List<TopMsgPO>> dailyDeviceAbnormal(@RequestBody DeviceInfoParam.BusinessParam conditionBusinessParam) {
|
||||
String methodDescribe = getMethodDescribe("dailyDeviceAbnormal");
|
||||
List<TopMsgPO> result = lineService.dailyDeviceAbnormal(conditionBusinessParam);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.njcn.device.pq.mapper;
|
||||
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.njcn.device.pq.pojo.po.TopMsgPO;
|
||||
import com.njcn.device.pq.pojo.vo.LineFlowMealDetailVO;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface TopMsgMapper {
|
||||
|
||||
Page<TopMsgPO> getTopMsg(Page<TopMsgPO> page,@Param("lineGrade") String lineGrade, @Param("startTime") DateTime startTime, @Param("endTime") DateTime endTime);
|
||||
List<TopMsgPO> getTopMsgDetail(@Param("lineGrade") String lineGrade,@Param("startTime") DateTime startTime, @Param("endTime") DateTime endTime);
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?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.device.pq.mapper.TopMsgMapper">
|
||||
|
||||
<select id="getTopMsg" resultType="com.njcn.device.pq.pojo.po.TopMsgPO">
|
||||
SELECT
|
||||
ptm.Time_Id AS time,
|
||||
COUNT(ptm.Dev_Id) AS deviceAbnormalNum,
|
||||
GROUP_CONCAT(sdd.Name) AS lineGrade
|
||||
FROM pq_line line
|
||||
INNER JOIN pq_line vol ON line.pid=vol.id
|
||||
INNER JOIN pq_line device ON vol.pid=device.id
|
||||
INNER JOIN pqs_top_msg ptm ON ptm.Dev_Id = device.Id
|
||||
LEFT JOIN pq_line_detail pld ON pld.Id=line.Id
|
||||
LEFT JOIN sys_dict_data sdd ON sdd.Id=pld.Line_Grade
|
||||
WHERE
|
||||
ptm.State=1
|
||||
AND
|
||||
ptm.Time_Id between #{startTime} and #{endTime}
|
||||
<if test="lineGrade!=null and lineGrade!=''">
|
||||
AND pld.Line_Grade=#{lineGrade}
|
||||
</if>
|
||||
GROUP BY ptm.Time_Id
|
||||
</select>
|
||||
|
||||
<select id="getTopMsgDetail" resultType="com.njcn.device.pq.pojo.po.TopMsgPO">
|
||||
SELECT
|
||||
device.Id AS devId,
|
||||
city.Name AS cityName,
|
||||
sub.Name AS subName,
|
||||
device.Name AS deviceName,
|
||||
ptm.Integrity_Value AS integrityValue,
|
||||
ptm.Integrity_Flag AS integrityFlag,
|
||||
ptm.Comout_Count AS comOutCount,
|
||||
ptm.Comout_Desc AS comOutDesc,
|
||||
ptm.Alarm_Count AS alarmCount,
|
||||
ptm.Alarm_Desc AS alarmDesc,
|
||||
ptm.Flow_Value AS flowValue
|
||||
FROM pq_line line
|
||||
INNER JOIN pq_line vol ON line.pid=vol.id
|
||||
INNER JOIN pq_line device ON vol.pid=device.id
|
||||
INNER JOIN pq_line sub ON device.pid=sub.id
|
||||
INNER JOIN pq_line city ON sub.pid=city.id
|
||||
INNER JOIN pqs_top_msg ptm ON ptm.Dev_Id = device.Id
|
||||
LEFT JOIN pq_line_detail pld ON pld.Id=line.Id
|
||||
WHERE
|
||||
ptm.State=1
|
||||
AND
|
||||
ptm.Time_Id between #{startTime} and #{endTime}
|
||||
<if test="lineGrade!=null and lineGrade!=''">
|
||||
AND pld.Line_Grade=#{lineGrade}
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.njcn.device.pq.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.njcn.device.pq.pojo.dto.PollutionLineDTO;
|
||||
import com.njcn.device.pq.pojo.dto.PollutionParamDTO;
|
||||
@@ -8,11 +7,9 @@ import com.njcn.device.pq.pojo.dto.PollutionSubstationDTO;
|
||||
import com.njcn.device.pq.pojo.param.DeviceInfoParam;
|
||||
import com.njcn.device.pq.pojo.param.PqsParam;
|
||||
import com.njcn.device.pq.pojo.po.Line;
|
||||
import com.njcn.device.pq.pojo.po.LineDetail;
|
||||
import com.njcn.device.pq.pojo.po.Overlimit;
|
||||
import com.njcn.device.pq.pojo.po.TopMsgPO;
|
||||
import com.njcn.device.pq.pojo.vo.*;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -207,4 +204,8 @@ public interface LineService {
|
||||
Integer getLineCountBySubstation(String subIndex);
|
||||
|
||||
Page<LineFlowMealDetailVO>getNewDeviceRunStatistics(PqsParam deviceInfoParam);
|
||||
|
||||
Page<TopMsgPO> dailyDeviceAbnormalStatistics(PqsParam param);
|
||||
|
||||
List<TopMsgPO> dailyDeviceAbnormal(DeviceInfoParam.BusinessParam conditionBusinessParam);
|
||||
}
|
||||
|
||||
@@ -25,20 +25,15 @@ import com.njcn.device.pq.pojo.param.PqsParam;
|
||||
import com.njcn.device.pq.pojo.po.*;
|
||||
import com.njcn.device.pq.pojo.vo.*;
|
||||
import com.njcn.device.pq.mapper.*;
|
||||
import com.njcn.device.pq.service.DeptLineService;
|
||||
import com.njcn.device.pq.service.LineService;
|
||||
import com.njcn.device.pq.service.TerminalBaseService;
|
||||
import com.njcn.device.pq.utils.PublicDateUtil;
|
||||
import com.njcn.influxdb.param.InfluxDBPublicParam;
|
||||
import com.njcn.influxdb.utils.InfluxDbUtils;
|
||||
import com.njcn.system.api.AreaFeignClient;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
import com.njcn.user.api.DeptFeignClient;
|
||||
import com.njcn.user.pojo.dto.DeptDTO;
|
||||
import com.njcn.web.pojo.vo.LineDataVO;
|
||||
import com.njcn.web.utils.GeneralUtil;
|
||||
import com.njcn.web.utils.RequestUtil;
|
||||
import com.njcn.web.utils.WebUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -87,16 +82,7 @@ public class LineServiceImpl extends ServiceImpl<LineMapper, Line> implements Li
|
||||
|
||||
private final InfluxDbUtils influxDbUtils;
|
||||
|
||||
private final DeptFeignClient deptFeignClient;
|
||||
|
||||
private final DeptLineService deptLineService;
|
||||
|
||||
private final TerminalBaseService terminalBaseService;
|
||||
|
||||
private final OnlineRateMapper onlineRateMapper;
|
||||
|
||||
private final PqsMonthFlowMapper pqsMonthFlowMapper;
|
||||
|
||||
private final TopMsgMapper topMsgMapper;
|
||||
|
||||
|
||||
@Override
|
||||
@@ -400,10 +386,24 @@ public class LineServiceImpl extends ServiceImpl<LineMapper, Line> implements Li
|
||||
new Page(deviceInfoParam.getPageNum(), deviceInfoParam.getPageSize()),
|
||||
deviceIndexes,
|
||||
DateUtil.beginOfDay(DateUtil.parse(deviceInfoParam.getSearchBeginTime())),
|
||||
DateUtil.beginOfDay(DateUtil.parse(deviceInfoParam.getSearchEndTime())));
|
||||
DateUtil.endOfDay(DateUtil.parse(deviceInfoParam.getSearchEndTime())));
|
||||
return page;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<TopMsgPO> dailyDeviceAbnormalStatistics(PqsParam param) {
|
||||
Page topMsg = topMsgMapper.getTopMsg(new Page(param.getPageNum(), param.getPageSize()), param.getLineGrade(), DateUtil.beginOfDay(DateUtil.parse(param.getSearchBeginTime())),
|
||||
DateUtil.endOfDay(DateUtil.parse(param.getSearchEndTime())));
|
||||
return topMsg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TopMsgPO> dailyDeviceAbnormal(DeviceInfoParam.BusinessParam param) {
|
||||
List<TopMsgPO> topMsgDetails = topMsgMapper.getTopMsgDetail(param.getLineGrade(), DateUtil.beginOfDay(DateUtil.parse(param.getSearchBeginTime())),
|
||||
DateUtil.endOfDay(DateUtil.parse(param.getSearchEndTime())));
|
||||
return topMsgDetails;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LineFlowMealDetailVO> getDeviceRunStatistics(DeviceInfoParam.BusinessParam deviceInfoParam) {
|
||||
ArrayList<LineFlowMealDetailVO> lineFlowMealDetailList = new ArrayList<>();
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.njcn.prepare.harmonic.pojo.mysql.po.line;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.njcn.db.bo.BaseEntity;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import io.swagger.models.auth.In;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class AlarmPO extends BaseEntity {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 监测点Id
|
||||
*/
|
||||
private String id;
|
||||
|
||||
private String deviceId;
|
||||
|
||||
|
||||
/**
|
||||
* 告警描述
|
||||
*/
|
||||
private String alarmDesc;
|
||||
|
||||
/**
|
||||
* 监测点告警次数
|
||||
*/
|
||||
private Integer alarmCount = 0;
|
||||
|
||||
/**
|
||||
* 装置下属监测点等级 : 0-极重要 1-重要 2-普通 3-不重要
|
||||
* */
|
||||
private Integer level;
|
||||
|
||||
|
||||
/**
|
||||
* 1.装置 2.监测点
|
||||
*/
|
||||
private Integer alarmDevLineType;
|
||||
|
||||
/**
|
||||
* 理论数据量
|
||||
*/
|
||||
private BigDecimal due;
|
||||
|
||||
/**
|
||||
* 实际数据量
|
||||
*/
|
||||
private BigDecimal real;
|
||||
|
||||
/**
|
||||
* 数据完整性
|
||||
*/
|
||||
private BigDecimal integrity;
|
||||
|
||||
|
||||
private Float flowMeal;
|
||||
|
||||
|
||||
private Float statisValue;
|
||||
|
||||
|
||||
private Float flowProportion;
|
||||
|
||||
/**
|
||||
* 通讯终端次数
|
||||
*/
|
||||
private Integer comOutNum = 0;
|
||||
|
||||
/**
|
||||
* 中断时间段描述
|
||||
*/
|
||||
private String comOutDesc;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.njcn.prepare.harmonic.pojo.mysql.po.line;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
|
||||
@Data
|
||||
public class AlarmStrategyVO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@ApiModelProperty("id")
|
||||
private String id;
|
||||
/**
|
||||
* 等级
|
||||
*/
|
||||
@ApiModelProperty("等级")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty("告警等级code:与高级算法内部Id描述对应")
|
||||
private Integer algoDesc;
|
||||
/**
|
||||
* 数据完整性标准
|
||||
*/
|
||||
@ApiModelProperty("数据完整性标准")
|
||||
private Integer integrityValue;
|
||||
/**
|
||||
* 在线率标准
|
||||
*/
|
||||
@ApiModelProperty("在线率标准")
|
||||
private Integer onlineValue;
|
||||
/**
|
||||
* 离线持续时间
|
||||
*/
|
||||
@ApiModelProperty("离线持续时间")
|
||||
private Integer offTimeValue;
|
||||
/**
|
||||
* 告警次数
|
||||
*/
|
||||
@ApiModelProperty("告警次数")
|
||||
private Integer warnValue;
|
||||
/**
|
||||
* 更新日期
|
||||
*/
|
||||
@ApiModelProperty("更新日期")
|
||||
private LocalDateTime updateTime;
|
||||
/**
|
||||
* 更新用户
|
||||
*/
|
||||
@ApiModelProperty("更新用户")
|
||||
private String updateBy;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package com.njcn.prepare.harmonic.pojo.mysql.po.line;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.njcn.db.bo.BaseEntity;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
// @TableName("pq_line")
|
||||
public class LinePO extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 监测点Id
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 所属装置id
|
||||
*/
|
||||
private String deviceId;
|
||||
|
||||
/**
|
||||
* 父节点(0为根节点)
|
||||
*/
|
||||
private String pid;
|
||||
|
||||
/**
|
||||
* 上层所有节点
|
||||
*/
|
||||
private String pids;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 等级:0-项目名称;1- 工程名称;2-单位;3-部门;4-终端;5-母线;6-监测点
|
||||
*/
|
||||
private Integer level;
|
||||
|
||||
/**
|
||||
* 排序(默认为0,有特殊排序需要时候人为输入)
|
||||
*/
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 状态 0-删除;1-正常;默认正常
|
||||
*/
|
||||
private Integer state;
|
||||
|
||||
/**
|
||||
* 监测点等级
|
||||
*/
|
||||
private String lineGrade;
|
||||
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 告警描述
|
||||
*/
|
||||
private String alarmDesc;
|
||||
|
||||
/**
|
||||
* 监测点告警次数
|
||||
*/
|
||||
private Integer alarmCount;
|
||||
|
||||
|
||||
/**
|
||||
* 1.装置 2.监测点
|
||||
*/
|
||||
private Integer alarmDevLineType;
|
||||
|
||||
/**
|
||||
* 在线率
|
||||
*/
|
||||
private Float onlineRate;
|
||||
|
||||
@ApiModelProperty("数据完整性")
|
||||
private Float integrity;
|
||||
|
||||
@ApiModelProperty("理论数据量")
|
||||
private Integer due;
|
||||
|
||||
@ApiModelProperty("实际数据量")
|
||||
private Integer real;
|
||||
|
||||
@ApiModelProperty("套餐流量")
|
||||
private Float flowMeal;
|
||||
|
||||
@ApiModelProperty("已用流量")
|
||||
private Float statisValue;
|
||||
|
||||
@ApiModelProperty("流量占比")
|
||||
private Float flowProportion;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.njcn.prepare.harmonic.pojo.mysql.po.line;
|
||||
|
||||
import com.njcn.db.bo.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class TopMsgPO extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 日期
|
||||
*/
|
||||
private String time;
|
||||
|
||||
/**
|
||||
* 装置id
|
||||
*/
|
||||
private String devId;
|
||||
|
||||
/**
|
||||
* 通信中断次数
|
||||
*/
|
||||
private Integer comOutCount;
|
||||
|
||||
/**
|
||||
* 通信中断时间段描述
|
||||
*/
|
||||
private String comOutDesc;
|
||||
|
||||
/**
|
||||
* 数据完整性标识 0.不达标 1.达标
|
||||
*/
|
||||
private String integrityFlag;
|
||||
|
||||
/**
|
||||
* 数据完成性百分比
|
||||
*/
|
||||
private Integer integrityValue;
|
||||
|
||||
/**
|
||||
* 告警次数
|
||||
*/
|
||||
private Integer alarmCount;
|
||||
|
||||
/**
|
||||
* 告警描述
|
||||
*/
|
||||
private String alarmDesc;
|
||||
|
||||
/**
|
||||
* 流量超标标识 0.不达标 1.达标
|
||||
*/
|
||||
private Integer flowFlag;
|
||||
|
||||
/**
|
||||
* 流量使用百分比
|
||||
*/
|
||||
private float flowValue;
|
||||
|
||||
/**
|
||||
* 状态 0.删除 1.正常
|
||||
*/
|
||||
private String state;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.njcn.prepare.harmonic.pojo.param;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class DeviceAbnormaStatisticsParam implements Serializable {
|
||||
|
||||
@ApiModelProperty("开始时间")
|
||||
private String beginTime;
|
||||
|
||||
@ApiModelProperty("结束时间")
|
||||
private String endTime;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.njcn.prepare.harmonic.controller.device;
|
||||
|
||||
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.prepare.harmonic.pojo.param.DeviceAbnormaStatisticsParam;
|
||||
import com.njcn.prepare.harmonic.service.mysql.device.DeviceAbnormalStatisticsService;
|
||||
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.web.bind.annotation.*;
|
||||
|
||||
@Slf4j
|
||||
@Api(tags = "终端异常")
|
||||
@RestController
|
||||
@RequestMapping("/deviceAbnormal")
|
||||
@RequiredArgsConstructor
|
||||
public class DeviceAbnormalController extends BaseController {
|
||||
|
||||
private final DeviceAbnormalStatisticsService deviceAbnormaStatisticsService;
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/statistics")
|
||||
@ApiOperation("终端异常统计")
|
||||
@ApiImplicitParam(name = "param", value = "参数", required = true)
|
||||
public HttpResult<Boolean> dailyDeviceAbnormaStatistics(@RequestBody DeviceAbnormaStatisticsParam param){
|
||||
String methodDescribe = getMethodDescribe("dailyDeviceAbnormaStatistics");
|
||||
boolean res = deviceAbnormaStatisticsService.dailyDeviceAbnormaStatistics(param);
|
||||
if(res){
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.njcn.prepare.harmonic.mapper.mysql.device;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import com.njcn.prepare.harmonic.pojo.mysql.po.line.AlarmPO;
|
||||
import com.njcn.prepare.harmonic.pojo.mysql.po.line.AlarmStrategyVO;
|
||||
import com.njcn.prepare.harmonic.pojo.mysql.po.line.LinePO;
|
||||
import com.njcn.prepare.harmonic.pojo.mysql.po.line.TopMsgPO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface DeviceAbnormaStatisticsMapper {
|
||||
|
||||
List<LinePO> getLines();
|
||||
|
||||
List<AlarmPO> getAlarmByDevice(@Param("startTime") DateTime startTime, @Param("endTime") DateTime endTime);
|
||||
|
||||
List<AlarmPO> getAlarmByLines(@Param("startTime") DateTime startTime, @Param("endTime") DateTime endTime);
|
||||
|
||||
Boolean insertTopMsg(@Param("list") List<TopMsgPO> topMsgPOS);
|
||||
|
||||
List<AlarmStrategyVO> selectAlarmStrategy();
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
<?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.prepare.harmonic.mapper.mysql.device.DeviceAbnormaStatisticsMapper">
|
||||
<insert id="insertTopMsg">
|
||||
INSERT INTO pqs_top_msg(
|
||||
`Time_Id`,
|
||||
`Dev_Id`,
|
||||
`Comout_Count`,
|
||||
`Comout_Desc`,
|
||||
`Integrity_Flag`,
|
||||
`Integrity_Value`,
|
||||
`Alarm_Count`,
|
||||
`Alarm_Desc`,
|
||||
`Flow_Flag`,
|
||||
`Flow_Value`,
|
||||
`State`
|
||||
) VALUES
|
||||
<foreach collection="list" separator="," item="item">
|
||||
(
|
||||
now(),
|
||||
#{item.devId},
|
||||
#{item.comOutCount},
|
||||
#{item.comOutDesc},
|
||||
#{item.integrityFlag},
|
||||
#{item.integrityValue},
|
||||
IFNULL(#{item.alarmCount},0),
|
||||
#{item.alarmDesc},
|
||||
#{item.flowFlag},
|
||||
#{item.flowValue},
|
||||
1
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<select id="getLines" resultType="com.njcn.prepare.harmonic.pojo.mysql.po.line.LinePO">
|
||||
(SELECT line.Id AS Id,
|
||||
device.id AS deviceId,
|
||||
COUNT(ca.Id) AS alarmCount,
|
||||
GROUP_CONCAT(ca.Remark) AS alarmDesc
|
||||
FROM pq_line line
|
||||
INNER JOIN pq_line vol ON line.pid=vol.id
|
||||
INNER JOIN pq_line device ON vol.pid=device.id
|
||||
LEFT JOIN pq_device pd ON device.id=pd.id
|
||||
LEFT JOIN pq_line_detail pld ON pld.id=line.id
|
||||
LEFT JOIN cld_alarm ca ON ca.Line_Id=line.id
|
||||
WHERE
|
||||
pd.Dev_Model=1
|
||||
AND
|
||||
pd.Run_Flag=0
|
||||
AND
|
||||
pld.Line_Grade is NOT NULL
|
||||
GROUP BY deviceId)
|
||||
UNION ALL
|
||||
(SELECT device.Id AS Id,
|
||||
device.id AS deviceId,
|
||||
COUNT(ca.Id) AS alarmCount,
|
||||
GROUP_CONCAT(ca.Remark) AS alarmDesc
|
||||
FROM pq_line line
|
||||
INNER JOIN pq_line vol ON line.pid=vol.id
|
||||
INNER JOIN pq_line device ON vol.pid=device.id
|
||||
LEFT JOIN pq_device pd ON device.id=pd.id
|
||||
LEFT JOIN pq_line_detail pld ON pld.id=line.id
|
||||
LEFT JOIN cld_alarm ca ON ca.Line_Id=device.id
|
||||
WHERE
|
||||
pd.Dev_Model=1
|
||||
AND
|
||||
pd.Run_Flag=0
|
||||
AND
|
||||
pld.Line_Grade is NOT NULL
|
||||
GROUP BY deviceId)
|
||||
</select>
|
||||
|
||||
<select id="getAlarmByDevice" resultType="com.njcn.prepare.harmonic.pojo.mysql.po.line.AlarmPO">
|
||||
SELECT t.*,
|
||||
(t.statisValue)/t.flowMeal flowProportion
|
||||
FROM
|
||||
(
|
||||
SELECT device.Id AS Id,
|
||||
device.id AS deviceId,
|
||||
COUNT(ca.Id) AS alarmCount,
|
||||
GROUP_CONCAT(ca.Remark) AS alarmDesc,
|
||||
IFNULL(d.flow, (select flow from cld_flow_meal where type = 0 and flag = 1)) + ifnull(d1.flow, 0) flowMeal,
|
||||
IFNULL(pmf.Actual_Value,0) statisValue
|
||||
FROM pq_line line
|
||||
INNER JOIN pq_line vol ON line.pid=vol.id
|
||||
INNER JOIN pq_line device ON vol.pid=device.id
|
||||
LEFT JOIN pq_device pd ON device.id=pd.id
|
||||
LEFT JOIN pq_line_detail pld ON pld.id=line.id
|
||||
LEFT JOIN cld_alarm ca ON ca.Line_Id=device.id
|
||||
LEFT JOIN pqs_month_flow pmf ON pmf.Dev_Id=device.id
|
||||
LEFT JOIN cld_dev_meal c ON device.id = c.line_id
|
||||
LEFT JOIN cld_flow_meal d ON c.Base_Meal_Id = d.id
|
||||
LEFT JOIN cld_flow_meal d1 ON c.Ream_Meal_Id = d1.id
|
||||
WHERE
|
||||
pd.Dev_Model = 1
|
||||
AND
|
||||
pd.Run_Flag = 0
|
||||
AND
|
||||
pld.Line_Grade is NOT NULL
|
||||
AND
|
||||
ca.Occurred_Time between #{startTime} and #{endTime}
|
||||
GROUP BY deviceId
|
||||
) t
|
||||
ORDER BY flowProportion DESC
|
||||
</select>
|
||||
|
||||
<select id="getAlarmByLines" resultType="com.njcn.prepare.harmonic.pojo.mysql.po.line.AlarmPO">
|
||||
SELECT GROUP_CONCAT(line.Id) AS Id,
|
||||
device.id AS deviceId,
|
||||
COUNT(ca.Id) AS alarmCount,
|
||||
GROUP_CONCAT(ca.Remark) AS alarmDesc,
|
||||
MIN(sdd.Algo_Describe) AS `level`,
|
||||
IFNULL(SUM(pi.Due),0) AS due,
|
||||
IFNULL(SUM(pi.Real),0) AS `real`
|
||||
FROM pq_line line
|
||||
INNER JOIN pq_line vol ON line.pid=vol.id
|
||||
INNER JOIN pq_line device ON vol.pid=device.id
|
||||
LEFT JOIN pq_device pd ON device.id=pd.id
|
||||
LEFT JOIN pq_line_detail pld ON pld.id=line.id
|
||||
LEFT JOIN cld_alarm ca ON ca.Line_Id=line.id
|
||||
LEFT JOIN pqs_integrity pi ON pi.LINE_Id=line.Id
|
||||
LEFT JOIN sys_dict_data sdd ON sdd.Id=pld.Line_Grade
|
||||
WHERE
|
||||
pd.Dev_Model=1
|
||||
AND
|
||||
pd.Run_Flag=0
|
||||
AND
|
||||
pld.Line_Grade is NOT NULL
|
||||
AND
|
||||
ca.Occurred_Time between #{startTime} and #{endTime}
|
||||
GROUP BY deviceId
|
||||
ORDER BY alarmCount DESC
|
||||
</select>
|
||||
<select id="selectAlarmStrategy" resultType="com.njcn.prepare.harmonic.pojo.mysql.po.line.AlarmStrategyVO">
|
||||
SELECT
|
||||
A.`Id` id,
|
||||
B.`Name` name,
|
||||
A.`Integrity_Value` integrityValue,
|
||||
A.`Online_Value` onlineValue,
|
||||
A.`Offtime_Value` offTimeValue,
|
||||
A.`Warn_Value` warnValue,
|
||||
A.`Update_Time` updateTime,
|
||||
B.Algo_Describe algoDesc
|
||||
FROM
|
||||
pqs_alarm_strategy A,
|
||||
sys_dict_data B
|
||||
WHERE A.State = 1
|
||||
AND A.Id = B.Id
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,133 @@
|
||||
package com.njcn.prepare.harmonic.service.mysql.Impl.device;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.njcn.device.pq.pojo.po.Communicate;
|
||||
import com.njcn.influxdb.param.InfluxDBPublicParam;
|
||||
import com.njcn.influxdb.utils.InfluxDbUtils;
|
||||
import com.njcn.prepare.harmonic.mapper.mysql.device.DeviceAbnormaStatisticsMapper;
|
||||
import com.njcn.prepare.harmonic.pojo.dto.GeneralDeviceDTO;
|
||||
import com.njcn.prepare.harmonic.pojo.mysql.po.line.AlarmPO;
|
||||
import com.njcn.prepare.harmonic.pojo.mysql.po.line.AlarmStrategyVO;
|
||||
import com.njcn.prepare.harmonic.pojo.mysql.po.line.LinePO;
|
||||
import com.njcn.prepare.harmonic.pojo.mysql.po.line.TopMsgPO;
|
||||
import com.njcn.prepare.harmonic.pojo.param.DeviceAbnormaStatisticsParam;
|
||||
import com.njcn.prepare.harmonic.service.mysql.device.DeviceAbnormalStatisticsService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.influxdb.dto.QueryResult;
|
||||
import org.influxdb.impl.InfluxDBResultMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatisticsService {
|
||||
|
||||
private final DeviceAbnormaStatisticsMapper deviceAbnormaStatisticsMapper;
|
||||
|
||||
private final InfluxDbUtils influxDbUtils;
|
||||
@Override
|
||||
public boolean dailyDeviceAbnormaStatistics(DeviceAbnormaStatisticsParam param) {
|
||||
// 获取监测点告警
|
||||
List<AlarmPO> lineAlarms = deviceAbnormaStatisticsMapper.getAlarmByLines(
|
||||
DateUtil.beginOfDay(DateUtil.parse(param.getBeginTime())),
|
||||
DateUtil.beginOfDay(DateUtil.parse(param.getEndTime())));
|
||||
Map<String, List<AlarmPO>> lineMap = new HashMap<>();
|
||||
if (CollectionUtil.isNotEmpty(lineAlarms)){
|
||||
// 根据装置分组
|
||||
lineMap = lineAlarms.stream().collect(Collectors.groupingBy(AlarmPO::getDeviceId));
|
||||
}
|
||||
|
||||
// 获取设备流量
|
||||
List<AlarmPO> deviceAlarms = deviceAbnormaStatisticsMapper.getAlarmByDevice(
|
||||
DateUtil.beginOfDay(DateUtil.parse(param.getBeginTime())),
|
||||
DateUtil.beginOfDay(DateUtil.parse(param.getEndTime())));
|
||||
List<String> devs = deviceAlarms.stream().map(AlarmPO::getId).collect(Collectors.toList());
|
||||
devs.add("6469e77fda42db12c7ca6620a092f03c");
|
||||
Map<String, List<Communicate>> comMap = new HashMap<>();
|
||||
// 获取通信中断信息
|
||||
List<Communicate> communicate = getCommunicate(devs, param.getBeginTime(), param.getEndTime());
|
||||
if (CollectionUtil.isNotEmpty(communicate)){
|
||||
comMap = communicate.stream().collect(Collectors.groupingBy(Communicate::getId));
|
||||
}
|
||||
for (AlarmPO deviceAlarm : deviceAlarms) {
|
||||
if (!lineMap.containsKey(deviceAlarm.getId())) {
|
||||
continue;
|
||||
}
|
||||
AlarmPO lineAlarm = lineMap.get(deviceAlarm.getId()).get(0);
|
||||
deviceAlarm.setAlarmCount(deviceAlarm.getAlarmCount() + lineAlarm.getAlarmCount());
|
||||
if (lineAlarm.getDue().compareTo(BigDecimal.ZERO) == 0) {
|
||||
deviceAlarm.setIntegrity(BigDecimal.ZERO);
|
||||
} else {
|
||||
deviceAlarm.setIntegrity(lineAlarm.getReal().divide(lineAlarm.getDue(), 2, BigDecimal.ROUND_HALF_UP));
|
||||
}
|
||||
if (lineAlarm.getLevel() != null) {
|
||||
deviceAlarm.setLevel(lineAlarm.getLevel());
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(comMap)) {
|
||||
List<Communicate> communicates = comMap.get(deviceAlarm.getId());
|
||||
int comOut = communicates.stream().filter(t -> t.getType() == 0).collect(Collectors.toList()).size();
|
||||
deviceAlarm.setComOutNum(comOut);
|
||||
}
|
||||
}
|
||||
Map<Integer, List<AlarmPO>> levelMap = deviceAlarms.stream().collect(Collectors.groupingBy(AlarmPO::getLevel));
|
||||
List<AlarmStrategyVO> alarmStrategyVOS = deviceAbnormaStatisticsMapper.selectAlarmStrategy();
|
||||
List<TopMsgPO> alarmExceptions = new ArrayList<>();
|
||||
for (AlarmStrategyVO strategyVO : alarmStrategyVOS) {
|
||||
if (!levelMap.containsKey(strategyVO.getAlgoDesc())){
|
||||
continue;
|
||||
}
|
||||
List<AlarmPO> alarmPOS = levelMap.get(strategyVO.getAlgoDesc());
|
||||
for (AlarmPO alarmPO : alarmPOS) {
|
||||
TopMsgPO topMsg = new TopMsgPO();
|
||||
topMsg.setDevId(alarmPO.getId());
|
||||
topMsg.setFlowFlag(1);
|
||||
topMsg.setComOutCount(alarmPO.getComOutNum() == 0 ? 0 : alarmPO.getComOutNum());
|
||||
if (alarmPO.getIntegrity().intValue()<strategyVO.getIntegrityValue()) {
|
||||
topMsg.setIntegrityFlag("0");
|
||||
topMsg.setIntegrityValue(alarmPO.getIntegrity().intValue());
|
||||
}
|
||||
if (alarmPO.getAlarmCount()>strategyVO.getWarnValue()){
|
||||
topMsg.setAlarmCount(alarmPO.getAlarmCount());
|
||||
topMsg.setAlarmDesc(alarmPO.getAlarmDesc());
|
||||
}
|
||||
if (alarmPO.getStatisValue()>alarmPO.getFlowMeal()) {
|
||||
topMsg.setFlowFlag(0);
|
||||
topMsg.setFlowValue(alarmPO.getFlowProportion());
|
||||
}
|
||||
alarmExceptions.add(topMsg);
|
||||
}
|
||||
}
|
||||
return deviceAbnormaStatisticsMapper.insertTopMsg(alarmExceptions);
|
||||
}
|
||||
|
||||
|
||||
public List<Communicate> getCommunicate(List<String> devs, String startTime, String endTime) {
|
||||
//组装sql语句
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append("time >= '").append(DateUtil.beginOfDay(DateUtil.parse(startTime))).append("' and ").append("time <= '").append(DateUtil.endOfDay(DateUtil.parse(endTime))).append("' and ");
|
||||
for (int i = 0; i < devs.size(); i++) {
|
||||
if (devs.size() - i != 1) {
|
||||
stringBuilder.append("dev_id ='").append(devs.get(i)).append("' or ");
|
||||
} else {
|
||||
stringBuilder.append("dev_id ='").append(devs.get(i)).append("' ");
|
||||
}
|
||||
}
|
||||
String sql = "select * from " + InfluxDBPublicParam.PQS_COMMUNICATE + " where " + stringBuilder.toString() + InfluxDBPublicParam.TIME_ZONE;
|
||||
//获取暂降事件
|
||||
QueryResult result = influxDbUtils.query(sql);
|
||||
InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper();
|
||||
List<Communicate> communicateList = influxDBResultMapper.toPOJO(result, Communicate.class);
|
||||
return communicateList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.njcn.prepare.harmonic.service.mysql.device;
|
||||
|
||||
import com.njcn.prepare.harmonic.pojo.param.DeviceAbnormaStatisticsParam;
|
||||
|
||||
public interface DeviceAbnormalStatisticsService {
|
||||
boolean dailyDeviceAbnormaStatistics(DeviceAbnormaStatisticsParam param);
|
||||
}
|
||||
Reference in New Issue
Block a user