|
@@ -0,0 +1,83 @@
|
|
|
+package com.hfln.portal.infrastructure.gateway.impl;
|
|
|
+
|
|
|
+import cn.dev33.satoken.stp.StpUtil;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.hfln.portal.common.constant.UserConstants;
|
|
|
+import com.hfln.portal.common.dto.data.event.AlarmEventDTO;
|
|
|
+import com.hfln.portal.common.request.event.AlarmEventParams;
|
|
|
+import com.hfln.portal.common.vo.PageRecord;
|
|
|
+import com.hfln.portal.domain.customer.util.CopyUtils;
|
|
|
+import com.hfln.portal.domain.gateway.StatsGateway;
|
|
|
+import com.hfln.portal.infrastructure.po.AlarmEvent;
|
|
|
+import com.hfln.portal.infrastructure.po.DevInfo;
|
|
|
+import com.hfln.portal.infrastructure.service.AlarmEventService;
|
|
|
+import com.hfln.portal.infrastructure.service.DevInfoService;
|
|
|
+import com.hfln.portal.infrastructure.service.DevShareService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Optional;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
+
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class StatsGatewayImpl implements StatsGateway {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DevShareService devShareService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DevInfoService devInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AlarmEventService alarmEventService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageRecord<AlarmEventDTO> alarmRetentionQuery(AlarmEventParams params) {
|
|
|
+ // 1.从会话中获取当前用户的id
|
|
|
+ Long userId = StpUtil.getSession().getLong(UserConstants.SA_USER_ID);
|
|
|
+
|
|
|
+ // 2.根据userId获取用户自己设备与被分享设备的id
|
|
|
+ //2.1 获取用户被分享的设备id集合 sharedDevIds
|
|
|
+ Optional<List<Long>> sharedDevIds = devShareService.queryDeviceIdByUserId(userId);
|
|
|
+ //2.2 获取用户自己设备的id集合 devIds
|
|
|
+ List<Long> devIds = devInfoService.queryByUserId(userId);
|
|
|
+ //2.3 合并devIds和sharedDevIds
|
|
|
+ List<Long> allDevIds = Stream.concat(
|
|
|
+ Optional.ofNullable(devIds).orElseGet(Collections::emptyList).stream(),
|
|
|
+ sharedDevIds.orElseGet(Collections::emptyList).stream()
|
|
|
+ ).distinct() //去重 + 顺序
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (allDevIds.isEmpty()){
|
|
|
+ PageRecord<AlarmEventDTO> pr = new PageRecord<>();
|
|
|
+ pr.setPageNum(params.getPageNo());
|
|
|
+ pr.setPageSize(params.getPageSize());
|
|
|
+ pr.setRows(Collections.emptyList());
|
|
|
+ pr.setTotal(0L);
|
|
|
+ return pr;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3.分页查询设备
|
|
|
+ Page<AlarmEvent> page = alarmEventService.QueryAlarmEvent(params, allDevIds);
|
|
|
+
|
|
|
+ //转化为DTO
|
|
|
+ List<AlarmEventDTO> dtoList = CopyUtils.copyList(page.getRecords(), AlarmEventDTO.class);
|
|
|
+
|
|
|
+ //新增 填充devName
|
|
|
+ Map<Long, String> devIdNameMap = devInfoService.queryByIds(
|
|
|
+ dtoList.stream().map(AlarmEventDTO::getDevId).collect(Collectors.toSet())
|
|
|
+ ).stream().collect(Collectors.toMap(DevInfo::getDevId, DevInfo::getDevName));
|
|
|
+
|
|
|
+ dtoList.forEach(dto -> dto.setDevName(devIdNameMap.get(dto.getDevId())));
|
|
|
+
|
|
|
+ // 封装成 PageRecord 返回
|
|
|
+ return CopyUtils.copyPage(page, dtoList);
|
|
|
+ }
|
|
|
+}
|