|
@@ -1,25 +1,17 @@
|
|
|
package com.usky.fire.service.impl;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
-import com.usky.common.core.bean.CommonPage;
|
|
|
-import com.usky.common.mybatis.core.AbstractCrudService;
|
|
|
-import com.usky.common.security.utils.SecurityUtils;
|
|
|
-import com.usky.fire.domain.AlarmDetector;
|
|
|
-import com.usky.fire.mapper.AlarmDetectorMapper;
|
|
|
+import com.usky.common.core.exception.BusinessException;
|
|
|
+import com.usky.common.influx.core.InfluxDbUtils;
|
|
|
import com.usky.fire.service.AlarmDetectorService;
|
|
|
import com.usky.fire.service.util.OnlineMethod;
|
|
|
-import com.usky.fire.service.vo.AlarmDetectorVo;
|
|
|
-import com.usky.fire.service.vo.AlarmFireStatisticalVo;
|
|
|
-import com.usky.system.model.LoginUser;
|
|
|
+import org.influxdb.dto.QueryResult;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.time.LocalDateTime;
|
|
|
-import java.time.format.DateTimeFormatter;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -30,231 +22,91 @@ import java.util.Map;
|
|
|
* @since 2022-08-08
|
|
|
*/
|
|
|
@Service
|
|
|
-public class AlarmDetectorServiceImpl extends AbstractCrudService<AlarmDetectorMapper, AlarmDetector> implements AlarmDetectorService {
|
|
|
+public class AlarmDetectorServiceImpl implements AlarmDetectorService {
|
|
|
|
|
|
- @Override
|
|
|
- public CommonPage<AlarmDetectorVo> alarmDetectorLowerList(Integer handlingStatus, String startDate, String endDate,
|
|
|
- Integer pageNum, Integer pageSize, String systemType) {
|
|
|
- List<Integer> systemTypeList = new ArrayList<>();
|
|
|
- if (systemType != null && !"".equals(systemType)) {
|
|
|
- String[] alarmTypeArray = systemType.split(",");
|
|
|
- for (int i = 0; i < alarmTypeArray.length; i++) {
|
|
|
- systemTypeList.add(Integer.parseInt(alarmTypeArray[i]));
|
|
|
- }
|
|
|
- }
|
|
|
+ @Autowired
|
|
|
+ private InfluxDbUtils influxDbUtils;
|
|
|
|
|
|
- DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
- String userType = null;
|
|
|
- LoginUser loginUser = SecurityUtils.getLoginUser();
|
|
|
- if (loginUser != null && !"".equals(loginUser)) {
|
|
|
- userType = loginUser.getUserType();
|
|
|
- }
|
|
|
- //缺少维保单位部分代码
|
|
|
- List<String> devcieCodeList = new ArrayList<>();
|
|
|
- CommonPage<AlarmDetector> alarmDetectorList = this.alarDetectorList(devcieCodeList, handlingStatus, startDate, endDate, pageNum, pageSize, systemTypeList);
|
|
|
- List<AlarmDetectorVo> list = new ArrayList<>();
|
|
|
- for (int i = 0; i < alarmDetectorList.getRecords().size(); i++) {
|
|
|
- AlarmDetectorVo alarmDetectorVo = new AlarmDetectorVo();
|
|
|
- alarmDetectorVo.setId(alarmDetectorList.getRecords().get(i).getId());
|
|
|
- alarmDetectorVo.setDataSources(alarmDetectorList.getRecords().get(i).getDataSources());
|
|
|
- alarmDetectorVo.setDeviceCode(alarmDetectorList.getRecords().get(i).getDeviceCode());
|
|
|
- alarmDetectorVo.setDataTime(df.format(alarmDetectorList.getRecords().get(i).getDataTime()));
|
|
|
- alarmDetectorVo.setDeviceStatus(alarmDetectorList.getRecords().get(i).getDeviceStatus());
|
|
|
- alarmDetectorVo.setAddress(alarmDetectorList.getRecords().get(i).getAddress());
|
|
|
- alarmDetectorVo.setSystemType(alarmDetectorList.getRecords().get(i).getSystemType());
|
|
|
- alarmDetectorVo.setPortNum(alarmDetectorList.getRecords().get(i).getPortNum());
|
|
|
- alarmDetectorVo.setAlarmType(alarmDetectorList.getRecords().get(i).getAlarmType());
|
|
|
- alarmDetectorVo.setAttributeValue1(alarmDetectorList.getRecords().get(i).getAttributeValue1());
|
|
|
- alarmDetectorVo.setAttributeValue2(alarmDetectorList.getRecords().get(i).getAttributeValue2());
|
|
|
- alarmDetectorVo.setAttributeValue3(alarmDetectorList.getRecords().get(i).getAttributeValue3());
|
|
|
- alarmDetectorVo.setAttributeValue4(alarmDetectorList.getRecords().get(i).getAttributeValue4());
|
|
|
- alarmDetectorVo.setHandler(alarmDetectorList.getRecords().get(i).getHandler());
|
|
|
- if (alarmDetectorList.getRecords().get(i).getHandlingTime() != null) {
|
|
|
- alarmDetectorVo.setHandlingTime(df.format(alarmDetectorList.getRecords().get(i).getHandlingTime()));
|
|
|
- } else {
|
|
|
- alarmDetectorVo.setHandlingTime(null);
|
|
|
- }
|
|
|
- alarmDetectorVo.setHandlingContent(alarmDetectorList.getRecords().get(i).getHandlingContent());
|
|
|
- alarmDetectorVo.setHandlerPhone(alarmDetectorList.getRecords().get(i).getHandlerPhone());
|
|
|
- alarmDetectorVo.setHandlingStatus(alarmDetectorList.getRecords().get(i).getHandlingStatus());
|
|
|
- alarmDetectorVo.setFalseAlarm(alarmDetectorList.getRecords().get(i).getFalseAlarm());
|
|
|
- alarmDetectorVo.setSitePhoto(alarmDetectorList.getRecords().get(i).getSitePhoto());
|
|
|
- alarmDetectorVo.setCompanyName("未定义单位表");
|
|
|
- alarmDetectorVo.setAlarmConten("未定义内容");
|
|
|
- list.add(alarmDetectorVo);
|
|
|
- }
|
|
|
- return new CommonPage<>(list, alarmDetectorList.getTotal(), pageSize, pageNum);
|
|
|
- }
|
|
|
|
|
|
@Override
|
|
|
- public Map<String, Object> detectorStatistics(String systemType) {
|
|
|
- List<Integer> systemTypeList = new ArrayList<>();
|
|
|
- if (systemType != null && !"".equals(systemType)) {
|
|
|
- String[] alarmTypeArray = systemType.split(",");
|
|
|
- for (int i = 0; i < alarmTypeArray.length; i++) {
|
|
|
- systemTypeList.add(Integer.parseInt(alarmTypeArray[i]));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- String userType = null;
|
|
|
- LoginUser loginUser = SecurityUtils.getLoginUser();
|
|
|
- if (loginUser != null && !"".equals(loginUser)) {
|
|
|
- userType = loginUser.getUserType();
|
|
|
- }
|
|
|
- //缺少维保单位部分代码
|
|
|
- List<String> devcieCodeList = new ArrayList<>();
|
|
|
-
|
|
|
- int untreated = this.detectorCount(devcieCodeList, 0, systemTypeList);
|
|
|
- int processed = this.detectorCount(devcieCodeList, 1, systemTypeList);
|
|
|
-// String disposalRate = processed / (untreated + processed) + "%";
|
|
|
- Integer count = untreated + processed;
|
|
|
- String disposalRate = OnlineMethod.myPercent(processed, count);
|
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
- map.put("untreated", untreated);//告警未处理数
|
|
|
- map.put("processed", processed);//告警未处理数
|
|
|
- map.put("disposalRate", disposalRate);//告警处理率
|
|
|
- map.put("alarmCount", count);//告警总数
|
|
|
- return map;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Map<String, Object> detectorStatisticalChart(String systemType, String startDate, String endDate) {
|
|
|
- List<Integer> systemTypeList = new ArrayList<>();
|
|
|
- if (systemType != null && !"".equals(systemType)) {
|
|
|
- String[] alarmTypeArray = systemType.split(",");
|
|
|
- for (int i = 0; i < alarmTypeArray.length; i++) {
|
|
|
- systemTypeList.add(Integer.parseInt(alarmTypeArray[i]));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- String userType = null;
|
|
|
- LoginUser loginUser = SecurityUtils.getLoginUser();
|
|
|
- if (loginUser != null && !"".equals(loginUser)) {
|
|
|
- userType = loginUser.getUserType();
|
|
|
- }
|
|
|
- //缺少维保单位部分代码
|
|
|
- List<String> devcieCodeList = new ArrayList<>();
|
|
|
- List<AlarmFireStatisticalVo> list = baseMapper.selectAlarmDetectorStatistical(devcieCodeList, systemTypeList, startDate, endDate);
|
|
|
- List<Integer> alarmCountList = new ArrayList<>();
|
|
|
- List<Integer> handleCountList = new ArrayList<>();
|
|
|
- List<String> alarmTimeList = new ArrayList<>();
|
|
|
- List<String> handleRateList = new ArrayList<>();
|
|
|
- for (int i = 0; i < list.size(); i++) {
|
|
|
- alarmCountList.add(list.get(i).getCount());
|
|
|
- handleCountList.add(list.get(i).getSum());
|
|
|
- alarmTimeList.add(list.get(i).getAlarmTime());
|
|
|
- handleRateList.add(OnlineMethod.myPercent(list.get(i).getSum(), list.get(i).getCount()));
|
|
|
- }
|
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
- map.put("alarmCountList", alarmCountList);//告警总数
|
|
|
- map.put("handleCountList", handleCountList);//告警处理数量
|
|
|
- map.put("alarmTimeList", alarmTimeList);//告警日期
|
|
|
- map.put("handleRateList", handleRateList);//告警处置占比
|
|
|
- return map;
|
|
|
+ public List<Map<String, Object>> leftData(String field, String deviceCode) {
|
|
|
+ Map<String, Object> maxMap = this.statusData(1, field, deviceCode);
|
|
|
+ Map<String, Object> minMap = this.statusData(2, field, deviceCode);
|
|
|
+ Map<String, Object> lastMap = this.statusData(3, field, deviceCode);
|
|
|
+ List<Map<String, Object>> list = new ArrayList<>();
|
|
|
+ list.add(maxMap);
|
|
|
+ list.add(minMap);
|
|
|
+ list.add(lastMap);
|
|
|
+ return list;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void updateAlarmDetector(AlarmDetector alarmDetector) {
|
|
|
- alarmDetector.setHandler(SecurityUtils.getUsername());
|
|
|
- alarmDetector.setHandlingTime(LocalDateTime.now());
|
|
|
- alarmDetector.setHandlingStatus(1);
|
|
|
- this.updateById(alarmDetector);
|
|
|
- }
|
|
|
|
|
|
@Override
|
|
|
- public List<AlarmDetectorVo> alarmDetectorLowerListExport(Integer handlingStatus, String startDate, String endDate, String systemType) {
|
|
|
- DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
-
|
|
|
- List<Integer> systemTypeList = new ArrayList<>();
|
|
|
- if (systemType != null && !"".equals(systemType)) {
|
|
|
- String[] alarmTypeArray = systemType.split(",");
|
|
|
- for (int i = 0; i < alarmTypeArray.length; i++) {
|
|
|
- systemTypeList.add(Integer.parseInt(alarmTypeArray[i]));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- String userType = null;
|
|
|
- LoginUser loginUser = SecurityUtils.getLoginUser();
|
|
|
- if (loginUser != null && !"".equals(loginUser)) {
|
|
|
- userType = loginUser.getUserType();
|
|
|
- }
|
|
|
- //缺少维保单位部分代码
|
|
|
- List<String> devcieCodeList = new ArrayList<>();
|
|
|
- CommonPage<AlarmDetector> alarmDetectorList = this.alarDetectorList(devcieCodeList, handlingStatus, startDate, endDate, 0, 0, systemTypeList);
|
|
|
- List<AlarmDetectorVo> list = new ArrayList<>();
|
|
|
- for (int i = 0; i < alarmDetectorList.getRecords().size(); i++) {
|
|
|
- AlarmDetectorVo alarmDetectorVo = new AlarmDetectorVo();
|
|
|
- alarmDetectorVo.setId(alarmDetectorList.getRecords().get(i).getId());
|
|
|
- alarmDetectorVo.setDataSources(alarmDetectorList.getRecords().get(i).getDataSources());
|
|
|
- alarmDetectorVo.setDeviceCode(alarmDetectorList.getRecords().get(i).getDeviceCode());
|
|
|
- alarmDetectorVo.setDataTime(df.format(alarmDetectorList.getRecords().get(i).getDataTime()));
|
|
|
- alarmDetectorVo.setDeviceStatus(alarmDetectorList.getRecords().get(i).getDeviceStatus());
|
|
|
- alarmDetectorVo.setAddress(alarmDetectorList.getRecords().get(i).getAddress());
|
|
|
- alarmDetectorVo.setSystemType(alarmDetectorList.getRecords().get(i).getSystemType());
|
|
|
- alarmDetectorVo.setPortNum(alarmDetectorList.getRecords().get(i).getPortNum());
|
|
|
- alarmDetectorVo.setAlarmType(alarmDetectorList.getRecords().get(i).getAlarmType());
|
|
|
- alarmDetectorVo.setAttributeValue1(alarmDetectorList.getRecords().get(i).getAttributeValue1());
|
|
|
- alarmDetectorVo.setAttributeValue2(alarmDetectorList.getRecords().get(i).getAttributeValue2());
|
|
|
- alarmDetectorVo.setAttributeValue3(alarmDetectorList.getRecords().get(i).getAttributeValue3());
|
|
|
- alarmDetectorVo.setAttributeValue4(alarmDetectorList.getRecords().get(i).getAttributeValue4());
|
|
|
- alarmDetectorVo.setHandler(alarmDetectorList.getRecords().get(i).getHandler());
|
|
|
- if (alarmDetectorList.getRecords().get(i).getHandlingTime() != null) {
|
|
|
- alarmDetectorVo.setHandlingTime(df.format(alarmDetectorList.getRecords().get(i).getHandlingTime()));
|
|
|
+ public Map<String, Object> statusData(Integer queryType, String field, String deviceCode) {
|
|
|
+ String fields = "";
|
|
|
+ switch (queryType) {
|
|
|
+ case 1:
|
|
|
+ fields = " MAX(" + field + "),";
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ fields = " MIN(" + field + "),";
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ fields = " LAST(" + field + "),";
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ throw new BusinessException("查询数据类型未定义");
|
|
|
+ }
|
|
|
+ String sql = "SELECT " + fields + "time FROM sp_d" + deviceCode + " tz('Asia/Shanghai')";
|
|
|
+ QueryResult query = influxDbUtils.query(sql);
|
|
|
+ QueryResult.Result oneResult = query.getResults().get(0);
|
|
|
+ Map<String, Object> map = new HashMap<String, Object>();
|
|
|
+ if (oneResult.getSeries() != null) {
|
|
|
+ List<List<Object>> valueList = oneResult.getSeries().stream().map(QueryResult.Series::getValues)
|
|
|
+ .collect(Collectors.toList()).get(0);
|
|
|
+ List<String> columns = oneResult.getSeries().stream().map(QueryResult.Series::getColumns)
|
|
|
+ .collect(Collectors.toList()).get(0);
|
|
|
+ if (valueList != null && valueList.size() > 0) {
|
|
|
+ for (int i = 0; i < valueList.get(0).size(); i++) {
|
|
|
+ if (i == 0) {
|
|
|
+ map.put(columns.get(i), valueList.get(0).get(i) == null ? null : OnlineMethod.timeChange(valueList.get(0).get(i)));
|
|
|
+ } else {
|
|
|
+ map.put(columns.get(i), valueList.get(0).get(i) == null ? null : valueList.get(0).get(i));
|
|
|
+ }
|
|
|
+ }
|
|
|
} else {
|
|
|
- alarmDetectorVo.setHandlingTime(null);
|
|
|
+ for (int i = 0; i < columns.size(); i++) {
|
|
|
+ map.put(columns.get(i), null);
|
|
|
+ }
|
|
|
}
|
|
|
- alarmDetectorVo.setHandlingContent(alarmDetectorList.getRecords().get(i).getHandlingContent());
|
|
|
- alarmDetectorVo.setHandlerPhone(alarmDetectorList.getRecords().get(i).getHandlerPhone());
|
|
|
- alarmDetectorVo.setHandlingStatus(alarmDetectorList.getRecords().get(i).getHandlingStatus());
|
|
|
- alarmDetectorVo.setFalseAlarm(alarmDetectorList.getRecords().get(i).getFalseAlarm());
|
|
|
- alarmDetectorVo.setSitePhoto(alarmDetectorList.getRecords().get(i).getSitePhoto());
|
|
|
- alarmDetectorVo.setCompanyName("未定义单位表");
|
|
|
- alarmDetectorVo.setAlarmConten("未定义内容");
|
|
|
- list.add(alarmDetectorVo);
|
|
|
+ } else {
|
|
|
+ throw new BusinessException(query.getError());
|
|
|
}
|
|
|
- return list;
|
|
|
+ return map;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
@Override
|
|
|
- public Integer detectorCount(List<String> deviceCodeList, Integer handlingStatus, List<Integer> systemTypeList) {
|
|
|
- LambdaQueryWrapper<AlarmDetector> queryWrapper = Wrappers.lambdaQuery();
|
|
|
- if (deviceCodeList.size() > 0) {
|
|
|
- queryWrapper.in(AlarmDetector::getDeviceCode, deviceCodeList);
|
|
|
- }
|
|
|
- if (handlingStatus != null) {
|
|
|
- queryWrapper.eq(AlarmDetector::getHandlingStatus, handlingStatus);
|
|
|
- }
|
|
|
- if (systemTypeList != null && systemTypeList.size() > 0) {
|
|
|
- queryWrapper.in(AlarmDetector::getSystemType, systemTypeList);
|
|
|
- }
|
|
|
- int total = this.count(queryWrapper);
|
|
|
- return total;
|
|
|
- }
|
|
|
-
|
|
|
- public CommonPage<AlarmDetector> alarDetectorList(List<String> deviceCodeList, Integer handlingStatus, String startDate,
|
|
|
- String endDate, Integer pageNum, Integer pageSize, List<Integer> systemTypeList) {
|
|
|
- LambdaQueryWrapper<AlarmDetector> queryWrapper = Wrappers.lambdaQuery();
|
|
|
- if (deviceCodeList.size() > 0) {
|
|
|
- queryWrapper.in(AlarmDetector::getDeviceCode, deviceCodeList);
|
|
|
- }
|
|
|
- if (handlingStatus != null) {
|
|
|
- queryWrapper.eq(AlarmDetector::getHandlingStatus, handlingStatus);
|
|
|
- }
|
|
|
-
|
|
|
- if (systemTypeList != null && systemTypeList.size() > 0) {
|
|
|
- queryWrapper.in(AlarmDetector::getSystemType, systemTypeList);
|
|
|
- }
|
|
|
- if (startDate != null && !"".equals(startDate) && endDate != null && !"".equals(endDate)) {
|
|
|
- queryWrapper.between(AlarmDetector::getDataTime, startDate, endDate);
|
|
|
- }
|
|
|
- int total = this.count(queryWrapper);
|
|
|
- queryWrapper.orderByDesc(AlarmDetector::getId);
|
|
|
- if (pageNum != null && pageNum != 0 && pageSize != null && pageSize != 0) {
|
|
|
- Integer startFate = OnlineMethod.getStartFate(pageNum, pageSize);
|
|
|
- queryWrapper.last("limit " + startFate + "," + pageSize);
|
|
|
+ public Map<String, Object> statisticalChartData(String field, String deviceCode) {
|
|
|
+ String sql = "SELECT " + field + " as A,time as b FROM sp_d" + deviceCode + " WHERE time >= now() - 7d order by time desc";
|
|
|
+ QueryResult query = influxDbUtils.query(sql);
|
|
|
+ QueryResult.Result oneResult = query.getResults().get(0);
|
|
|
+ Map<String, Object> map = new HashMap<String, Object>();
|
|
|
+ if (oneResult.getSeries() != null) {
|
|
|
+ List<List<Object>> valueList = oneResult.getSeries().stream().map(QueryResult.Series::getValues)
|
|
|
+ .collect(Collectors.toList()).get(0);
|
|
|
+ if (valueList != null && valueList.size() > 0) {
|
|
|
+ List<Object> time = new ArrayList<>();
|
|
|
+ List<Object> value = new ArrayList<>();
|
|
|
+ for (int i = 0; i < valueList.size(); i++) {
|
|
|
+ time.add(OnlineMethod.timeChange(valueList.get(i).get(0)));
|
|
|
+ value.add(valueList.get(i).get(1));
|
|
|
+ }
|
|
|
+ map.put("time", time);
|
|
|
+ map.put("value", value);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new BusinessException(query.getError());
|
|
|
}
|
|
|
- List<AlarmDetector> list = this.list(queryWrapper);
|
|
|
- return new CommonPage<>(list, total, pageSize, pageNum);
|
|
|
+ return map;
|
|
|
}
|
|
|
}
|