|
|
@@ -1,23 +1,29 @@
|
|
|
package com.sckw.slope.detection.service;
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
+import com.alibaba.excel.util.DateUtils;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import com.sckw.core.exception.BusinessException;
|
|
|
+import com.sckw.core.model.constant.Global;
|
|
|
+import com.sckw.core.model.enums.AlarmTitleEnum;
|
|
|
+import com.sckw.core.model.enums.AlarmTypeEnum;
|
|
|
import com.sckw.core.model.enums.DictEnum;
|
|
|
import com.sckw.core.model.enums.DictItemEnum;
|
|
|
import com.sckw.core.model.page.PageRes;
|
|
|
import com.sckw.core.model.vo.BaseList;
|
|
|
import com.sckw.core.model.vo.PublicBaseList;
|
|
|
import com.sckw.core.web.response.HttpResult;
|
|
|
+import com.sckw.redis.utils.RedissonUtils;
|
|
|
import com.sckw.slope.detection.dao.mysql.*;
|
|
|
import com.sckw.slope.detection.dao.tdengine.DevicesMapper;
|
|
|
import com.sckw.slope.detection.model.dos.mysql.*;
|
|
|
import com.sckw.slope.detection.model.dos.tdengine.Devices;
|
|
|
import com.sckw.slope.detection.model.dto.HeaderData;
|
|
|
import com.sckw.slope.detection.model.dto.SystemDict;
|
|
|
+import com.sckw.slope.detection.model.param.AlarmLogThresholdExport;
|
|
|
import com.sckw.slope.detection.model.param.AlarmLogThresholdQuery;
|
|
|
import com.sckw.slope.detection.model.param.AlarmStatisticsQuery;
|
|
|
import com.sckw.slope.detection.model.vo.AlarmLogThresholdVO;
|
|
|
@@ -25,6 +31,7 @@ import com.sckw.slope.detection.model.vo.KwsAlarmVO;
|
|
|
import com.sckw.slope.detection.model.vo.ThresholdLogDetailVO;
|
|
|
import com.sckw.slope.detection.model.vo.ThresholdRecordDetailVO;
|
|
|
import com.sckw.slope.detection.model.vo.excel.KwsAlarmExportVO;
|
|
|
+import com.sckw.slope.detection.model.vo.excel.ThresholdRecordDetailExportVO;
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -38,8 +45,10 @@ import java.math.BigDecimal;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author lfdc
|
|
|
@@ -123,6 +132,7 @@ public class KwsAlarmService {
|
|
|
if (StringUtils.isNotBlank(query.getProjectId())) {
|
|
|
wrapper.eq(KwsAlarm::getProjectId, Long.parseLong(query.getProjectId()));
|
|
|
}
|
|
|
+ wrapper.orderByDesc(KwsAlarm::getCreateTime);
|
|
|
List<KwsAlarm> list = alarmMapper.selectList(wrapper);
|
|
|
List<KwsAlarmVO> alarmVOS = new ArrayList<>();
|
|
|
PageInfo<KwsAlarm> info = new PageInfo<KwsAlarm>(list);
|
|
|
@@ -169,18 +179,31 @@ public class KwsAlarmService {
|
|
|
.set(KwsAlarm::getStatus, 1)
|
|
|
.eq(KwsAlarm::getId, id)
|
|
|
);
|
|
|
+ alarmDetailMapper.update(null, new LambdaUpdateWrapper<KwsAlarmDetail>()
|
|
|
+ .set(KwsAlarmDetail::getStatus, 1)
|
|
|
+ .eq(KwsAlarmDetail::getAlarmId, id)
|
|
|
+ );
|
|
|
});
|
|
|
return HttpResult.ok("消息已读");
|
|
|
}
|
|
|
|
|
|
- public List<KwsAlarmExportVO> export(AlarmLogThresholdQuery query, HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ public List<KwsAlarmExportVO> export(AlarmLogThresholdExport query, HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ List<Long> idsList = null;
|
|
|
+ String ids = query.getIds();
|
|
|
+ if (StringUtils.isNotBlank(ids) && (!"all".equals(ids))) {
|
|
|
+ idsList = com.sckw.core.utils.StringUtils.splitStrToList(ids, Long.class);
|
|
|
+ }
|
|
|
HeaderData headerData = commonService.getHeaderData(request);
|
|
|
LambdaQueryWrapper<KwsAlarm> wrapper = new LambdaQueryWrapper<>();
|
|
|
wrapper.eq(StringUtils.isNotBlank(headerData.getMountainId()), KwsAlarm::getMountainId, headerData.getMountainId())
|
|
|
- .eq(KwsAlarm::getStatus, query.getStatus());
|
|
|
+ .eq(KwsAlarm::getStatus, query.getStatus()).orderByDesc(KwsAlarm::getCreateTime)
|
|
|
+ ;
|
|
|
if (StringUtils.isNotBlank(query.getProjectId())) {
|
|
|
wrapper.eq(KwsAlarm::getProjectId, Long.parseLong(query.getProjectId()));
|
|
|
}
|
|
|
+ if (!CollectionUtils.isEmpty(idsList) && idsList.size() > 0) {
|
|
|
+ wrapper.in(KwsAlarm::getId, idsList);
|
|
|
+ }
|
|
|
List<KwsAlarm> list = alarmMapper.selectList(wrapper);
|
|
|
List<KwsAlarmExportVO> alarmVOS = new ArrayList<>();
|
|
|
if (CollectionUtils.isEmpty(list)) {
|
|
|
@@ -189,30 +212,80 @@ public class KwsAlarmService {
|
|
|
Map<String, SystemDict> thresholdLevel = commonService.getDictByDictCode(DictEnum.THRESHOLD_LEVEL);
|
|
|
Map<String, SystemDict> alarmType = commonService.getDictByDictCode(DictEnum.ALARM_TYPE);
|
|
|
Map<String, SystemDict> alarmDetailType = commonService.getDictByDictCode(DictEnum.ALARM_DETAIL_TYPE);
|
|
|
+ String now = DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
|
|
|
+ System.out.println("数据翻译开始时间" + now);
|
|
|
+ int i = 1;
|
|
|
+ List<KwsProject> projectList = projectMapper.selectList(null);
|
|
|
+ Map<Long, String> projectMap = projectList.stream().collect(Collectors.toMap(KwsProject::getId, KwsProject::getName));
|
|
|
+ List<KwsDevice> deviceList = deviceMapper.selectList(null);
|
|
|
+ Map<Long, String> deviceMap = deviceList.stream().collect(Collectors.toMap(KwsDevice::getId, KwsDevice::getName));
|
|
|
for (KwsAlarm kwsAlarm : list) {
|
|
|
- KwsDevice kwsDevice = deviceMapper.selectOne(new LambdaQueryWrapper<KwsDevice>()
|
|
|
- .eq(StringUtils.isNotBlank(headerData.getMountainId()), KwsDevice::getMountainId, headerData.getMountainId())
|
|
|
- .eq(KwsDevice::getId, kwsAlarm.getDeviceId()));
|
|
|
- KwsProject project = projectMapper.selectOne(new LambdaQueryWrapper<KwsProject>()
|
|
|
- .eq(KwsProject::getId, Long.parseLong(kwsAlarm.getProjectId()))
|
|
|
- .eq(StringUtils.isNotBlank(headerData.getMountainId()), KwsProject::getMountainId, headerData.getMountainId())
|
|
|
- );
|
|
|
+ i++;
|
|
|
+ System.out.println("数据翻译开始时间" + i + "次数" + now);
|
|
|
KwsAlarmExportVO vo = new KwsAlarmExportVO();
|
|
|
BeanUtils.copyProperties(kwsAlarm, vo);
|
|
|
- vo.setLevel(kwsAlarm.getLevel() == null ? null :
|
|
|
- (thresholdLevel == null ? String.valueOf(kwsAlarm.getLevel()) : thresholdLevel.get(String.valueOf(kwsAlarm.getLevel())).getLabel()));
|
|
|
- vo.setType(kwsAlarm.getType() == null ? null :
|
|
|
- (alarmType == null ? String.valueOf(kwsAlarm.getType()) : alarmType.get(String.valueOf(kwsAlarm.getType())).getLabel()));
|
|
|
- vo.setDeviceName(kwsDevice == null ? kwsAlarm.getDeviceId().toString() : kwsDevice.getName());
|
|
|
- vo.setProjectName(project == null ? kwsAlarm.getProjectId() : project.getName());
|
|
|
- vo.setAlarmLevel(kwsAlarm.getTitle() == null ? null :
|
|
|
- (alarmDetailType == null ? kwsAlarm.getTitle() : alarmDetailType.get(kwsAlarm.getTitle()).getLabel()));
|
|
|
+
|
|
|
+ String levelTime = DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
|
|
|
+ System.out.println("数据翻译等级开始时间" + i + "次数" + levelTime);
|
|
|
+ vo.setLevel(kwsAlarm.getLevel() == null ? null : (thresholdLevel.get(String.valueOf(kwsAlarm.getLevel())).getLabel()));
|
|
|
+ String levelEndTime = DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
|
|
|
+ System.out.println("数据翻译等级结束时间" + i + "次数" + levelEndTime);
|
|
|
+
|
|
|
+ String typeTime = DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
|
|
|
+ System.out.println("数据翻译类型开始时间" + i + "次数" + typeTime);
|
|
|
+ vo.setType(kwsAlarm.getType() == null ? null : (alarmType.get(String.valueOf(kwsAlarm.getType())).getLabel()));
|
|
|
+ String typeEndTime = DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
|
|
|
+ System.out.println("数据翻译类型结束时间" + i + "次数" + typeEndTime);
|
|
|
+
|
|
|
+
|
|
|
+ String deviceTime = DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
|
|
|
+ System.out.println("数据翻译设备名称开始时间" + i + "次数" + deviceTime);
|
|
|
+ vo.setDeviceName(deviceMap == null ? kwsAlarm.getDeviceId().toString() : deviceMap.get(kwsAlarm.getDeviceId()));
|
|
|
+ String deviceEndTime = DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
|
|
|
+ System.out.println("数据翻译设备名称结束时间" + i + "次数" + deviceEndTime);
|
|
|
+
|
|
|
+ String projectTime = DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
|
|
|
+ System.out.println("数据翻译项目名称开始时间" + i + "次数" + projectTime);
|
|
|
+ vo.setProjectName(projectMap == null ? kwsAlarm.getProjectId() : projectMap.get(Long.parseLong(kwsAlarm.getProjectId())));
|
|
|
+ String projectEndTime = DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
|
|
|
+ System.out.println("数据翻译项目名称结束时间" + i + "次数" + projectEndTime);
|
|
|
+
|
|
|
+ String alarmTime = DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
|
|
|
+ System.out.println("数据翻译告警等级开始时间" + i + "次数" + alarmTime);
|
|
|
+ vo.setAlarmLevel(kwsAlarm.getTitle() == null ? null : (alarmDetailType.get(kwsAlarm.getTitle()).getLabel()));
|
|
|
+ String alarmEndTime = DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
|
|
|
+ System.out.println("数据翻译告警等级结束时间" + i + "次数" + alarmEndTime);
|
|
|
+
|
|
|
vo.setStartTime(kwsAlarm.getCreateTime());
|
|
|
vo.setEndTime(kwsAlarm.getUpdateTime());
|
|
|
- Long count = alarmDetailMapper.selectCount(new LambdaQueryWrapper<KwsAlarmDetail>().eq(KwsAlarmDetail::getAlarmId, kwsAlarm.getId()));
|
|
|
- vo.setTriggerTimes(count.intValue());
|
|
|
+
|
|
|
+ String countTime = DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
|
|
|
+ System.out.println("数据翻译统计开始时间" + i + "次数" + countTime);
|
|
|
+// Long count = alarmDetailMapper.selectCount(new LambdaQueryWrapper<KwsAlarmDetail>().eq(KwsAlarmDetail::getAlarmId, kwsAlarm.getId()));
|
|
|
+ /**结合到mqtt阈值触发数据存储*/
|
|
|
+ String count = null;
|
|
|
+ Long id = kwsAlarm.getId();
|
|
|
+ if (AlarmTypeEnum.ALARM_ONE.getStatus().equals(String.valueOf(kwsAlarm.getType()))) {
|
|
|
+ /**阈值次数存redis*/
|
|
|
+ String key = Global.REDIS_SYS_ALARM_PREFIX + Global.POUND + String.valueOf(id) + Global.POUND + AlarmTypeEnum.ALARM_ONE.getStatus()
|
|
|
+ + Global.POUND + AlarmTitleEnum.ALARM_TITLE_TWO.getStatus();
|
|
|
+ count = RedissonUtils.getString(key);
|
|
|
+ } else {
|
|
|
+ /**阈值次数存redis*/
|
|
|
+ String key = Global.REDIS_SYS_ALARM_PREFIX + Global.POUND + String.valueOf(id) + Global.POUND + AlarmTypeEnum.ALARM_TWO.getStatus()
|
|
|
+ + Global.POUND + AlarmTitleEnum.ALARM_TITLE_ONE.getStatus();
|
|
|
+ count = RedissonUtils.getString(key);
|
|
|
+ }
|
|
|
+ vo.setTriggerTimes(count);
|
|
|
+ String countEndTime = DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
|
|
|
+ System.out.println("数据翻译统计结束时间" + i + "次数" + countEndTime);
|
|
|
+
|
|
|
alarmVOS.add(vo);
|
|
|
+ String format = DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
|
|
|
+ System.out.println("数据翻译结束时间" + i + "次数" + format);
|
|
|
}
|
|
|
+ System.out.println("数据翻译开始时间" + now);
|
|
|
+ System.out.println("数据翻译结束时间" + DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS"));
|
|
|
return alarmVOS;
|
|
|
}
|
|
|
|
|
|
@@ -224,7 +297,9 @@ public class KwsAlarmService {
|
|
|
KwsAlarm kwsAlarm = alarmMapper.selectById(id);
|
|
|
PageHelper.startPage(baseList.getPage(), baseList.getPageSize());
|
|
|
List<KwsAlarmDetail> detailList = alarmDetailMapper.selectList(new LambdaQueryWrapper<KwsAlarmDetail>()
|
|
|
- .eq(KwsAlarmDetail::getAlarmId, Long.parseLong(id)));
|
|
|
+ .eq(KwsAlarmDetail::getAlarmId, Long.parseLong(id))
|
|
|
+ .eq(KwsAlarmDetail::getStatus, 0)
|
|
|
+ );
|
|
|
PageInfo<ThresholdRecordDetailVO> info = new PageInfo(detailList);
|
|
|
if (CollectionUtils.isEmpty(detailList)) {
|
|
|
return PageRes.build(info, detailList);
|
|
|
@@ -234,7 +309,32 @@ public class KwsAlarmService {
|
|
|
// Map<String, SystemDict> alarmType = commonService.getDictByDictCode(DictEnum.ALARM_TYPE);
|
|
|
Map<String, SystemDict> thresholdLevel = commonService.getDictByDictCode(DictEnum.THRESHOLD_LEVEL);
|
|
|
if ("1".equals(kwsAlarm.getType())) {
|
|
|
-
|
|
|
+ for (KwsAlarmDetail detail : detailList) {
|
|
|
+ Long pid = detail.getPid();
|
|
|
+ KwsDevice kwsDevice = deviceMapper.selectById(pid);
|
|
|
+ ThresholdRecordDetailVO vo = new ThresholdRecordDetailVO();
|
|
|
+ vo.setId(detail.getId());
|
|
|
+ vo.setAlarmLevel(kwsAlarm.getLevel() == null ? null :
|
|
|
+ (thresholdLevel == null ? String.valueOf(kwsAlarm.getLevel()) : thresholdLevel.get(String.valueOf(kwsAlarm.getLevel())).getLabel()));
|
|
|
+// vo.setType(kwsThreshold.getItemName() == null ? null :
|
|
|
+// (dictByDictCode == null ? kwsThreshold.getItemName() : dictByDictCode.get(kwsThreshold.getItemName()).getLabel()));
|
|
|
+// vo.setValue(detail.getVal());
|
|
|
+// vo.setItemName(kwsThreshold.getItemName());
|
|
|
+ vo.setPhone("");
|
|
|
+ StringBuilder location = new StringBuilder();
|
|
|
+ if (StringUtils.isNotBlank(kwsDevice.getLogicLng())) {
|
|
|
+ location.append(kwsDevice.getLogicLng()).append(";");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(kwsDevice.getLogicLat())) {
|
|
|
+ location.append(kwsDevice.getLogicLat()).append(";");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(kwsDevice.getLogicAlt())) {
|
|
|
+ location.append(kwsDevice.getLogicAlt()).append(";");
|
|
|
+ }
|
|
|
+ vo.setLocation(location.toString());
|
|
|
+ vo.setCreateTime(detail.getCreateTime());
|
|
|
+ list.add(vo);
|
|
|
+ }
|
|
|
} else {
|
|
|
for (KwsAlarmDetail detail : detailList) {
|
|
|
Long pid = detail.getPid();
|
|
|
@@ -249,7 +349,18 @@ public class KwsAlarmService {
|
|
|
vo.setItemName(kwsThreshold.getItemName());
|
|
|
vo.setPhone(kwsThreshold.getPhones());
|
|
|
KwsDevice kwsDevice = deviceMapper.selectById(kwsThreshold.getDeviceId());
|
|
|
- vo.setLocation(kwsDevice == null ? null : kwsDevice.getLogicAlt() + ";" + kwsDevice.getLogicLat() + ";" + kwsDevice.getLogicLng());
|
|
|
+ StringBuilder location = new StringBuilder();
|
|
|
+ if (StringUtils.isNotBlank(kwsDevice.getLogicLng())) {
|
|
|
+ location.append(kwsDevice.getLogicLng()).append(";");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(kwsDevice.getLogicLat())) {
|
|
|
+ location.append(kwsDevice.getLogicLat()).append(";");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(kwsDevice.getLogicAlt())) {
|
|
|
+ location.append(kwsDevice.getLogicAlt()).append(";");
|
|
|
+ }
|
|
|
+// vo.setLocation(kwsDevice == null ? null : kwsDevice.getLogicAlt() + ";" + kwsDevice.getLogicLat() + ";" + kwsDevice.getLogicLng());
|
|
|
+ vo.setLocation(location.toString());
|
|
|
vo.setCreateTime(detail.getCreateTime());
|
|
|
list.add(vo);
|
|
|
}
|
|
|
@@ -316,8 +427,8 @@ public class KwsAlarmService {
|
|
|
vo.setOriginalOffset(computeOriginalOffset);
|
|
|
}
|
|
|
} else {
|
|
|
- vo.setCurrentValue(deviceReference.getCurrentValue());
|
|
|
- vo.setOriginalValue(deviceReference.getOriginalValue());
|
|
|
+ vo.setCurrentValue(deviceReference == null ? null : deviceReference.getCurrentValue());
|
|
|
+ vo.setOriginalValue(deviceReference == null ? null : deviceReference.getOriginalValue());
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@@ -550,12 +661,25 @@ public class KwsAlarmService {
|
|
|
return HttpResult.ok(returnList);
|
|
|
}
|
|
|
|
|
|
- public List<ThresholdRecordDetailVO> exportDetail(PublicBaseList baseList, HttpServletRequest request) {
|
|
|
- String id = baseList.getId();
|
|
|
- KwsAlarm kwsAlarm = alarmMapper.selectById(id);
|
|
|
+ public List<ThresholdRecordDetailExportVO> exportDetail(BaseList baseList, HttpServletRequest request) {
|
|
|
+ List<ThresholdRecordDetailExportVO> list = new ArrayList<>();
|
|
|
+ String parentId = baseList.getParentId();
|
|
|
+ if (StringUtils.isBlank(parentId)) {
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+ String ids = baseList.getIds();
|
|
|
+ List<Long> idsList = new ArrayList<>();
|
|
|
+ if (StringUtils.isNotBlank(ids) && (!"all".equals(ids))) {
|
|
|
+ idsList = com.sckw.core.utils.StringUtils.splitStrToList(ids, Long.class);
|
|
|
+ }
|
|
|
List<KwsAlarmDetail> detailList = alarmDetailMapper.selectList(new LambdaQueryWrapper<KwsAlarmDetail>()
|
|
|
- .eq(KwsAlarmDetail::getAlarmId, Long.parseLong(id)));
|
|
|
- List<ThresholdRecordDetailVO> list = new ArrayList<>();
|
|
|
+ .eq(KwsAlarmDetail::getAlarmId, Long.parseLong(parentId))
|
|
|
+ .in(!CollectionUtils.isEmpty(idsList), KwsAlarmDetail::getId, idsList)
|
|
|
+ );
|
|
|
+ if (CollectionUtils.isEmpty(detailList)) {
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+ KwsAlarm kwsAlarm = alarmMapper.selectById(detailList.get(0).getAlarmId());
|
|
|
Map<String, SystemDict> dictByDictCode = commonService.getDictByDictCode(DictEnum.MODEL_PART);
|
|
|
Map<String, SystemDict> alarmType = commonService.getDictByDictCode(DictEnum.ALARM_TYPE);
|
|
|
if ("1".equals(kwsAlarm.getType())) {
|
|
|
@@ -564,7 +688,7 @@ public class KwsAlarmService {
|
|
|
for (KwsAlarmDetail detail : detailList) {
|
|
|
Long pid = detail.getPid();
|
|
|
KwsThreshold kwsThreshold = thresholdMapper.selectById(pid);
|
|
|
- ThresholdRecordDetailVO vo = new ThresholdRecordDetailVO();
|
|
|
+ ThresholdRecordDetailExportVO vo = new ThresholdRecordDetailExportVO();
|
|
|
vo.setId(detail.getId());
|
|
|
vo.setAlarmLevel(kwsAlarm.getType() == null ? null :
|
|
|
(alarmType == null ? String.valueOf(kwsAlarm.getType()) : alarmType.get(String.valueOf(kwsAlarm.getType())).getLabel()));
|