Ver código fonte

feat(stats): 新增事件统计与动态健康监测分析功能

- 实现了设备名称填充的通用方法,支持通过clientId和devId两种方式
- 新增事件统计查询接口,支持按时间范围查询告警和异常事件
- 添加动态健康监测分析功能,按季度统计事件数量和处理率
- 扩展了事件相关数据传输对象和请求参数类
- 实现了事件季度统计的数据库查询方法
- 在Web端统计网关中集成了新的事件统计和分析功能
- 优化了设备信息填充逻辑,提高了代码复用性
chejianzheng 1 dia atrás
pai
commit
283d3650ef
14 arquivos alterados com 353 adições e 35 exclusões
  1. 20 0
      portal-service-application/src/main/java/com/hfln/portal/application/controller/web/WebStatsV2Controller.java
  2. 35 0
      portal-service-common/src/main/java/com/hfln/portal/common/dto/data/event/EventStatDto.java
  3. 36 0
      portal-service-common/src/main/java/com/hfln/portal/common/dto/data/stat/MonitorAnalyseDTO.java
  4. 23 0
      portal-service-common/src/main/java/com/hfln/portal/common/request/event/EventStatParams.java
  5. 10 0
      portal-service-domain/src/main/java/com/hfln/portal/domain/gateway/WebStatsV2Gateway.java
  6. 0 1
      portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/gateway/impl/WebStatsGatewayImpl.java
  7. 110 1
      portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/gateway/impl/WebStatsV2GatewayImpl.java
  8. 12 0
      portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/mapper/EventListMapper.java
  9. 3 5
      portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/service/DevInfoService.java
  10. 8 0
      portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/service/EventListService.java
  11. 6 0
      portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/service/EventsService.java
  12. 39 25
      portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/service/impl/DevInfoServiceImpl.java
  13. 23 3
      portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/service/impl/EventListServiceImpl.java
  14. 28 0
      portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/service/impl/EventsServiceImpl.java

+ 20 - 0
portal-service-application/src/main/java/com/hfln/portal/application/controller/web/WebStatsV2Controller.java

@@ -4,16 +4,24 @@ package com.hfln.portal.application.controller.web;
 
 import cn.hfln.framework.catchlog.CatchAndLog;
 import cn.hfln.framework.dto.ApiResult;
+import com.hfln.portal.common.dto.data.event.EventStatDto;
+import com.hfln.portal.common.dto.data.event.EventsDTO;
+import com.hfln.portal.common.dto.data.stat.MonitorAnalyseDTO;
 import com.hfln.portal.common.dto.data.stat.ScreenStatsV2DTO;
+import com.hfln.portal.common.request.event.EventStatParams;
 import com.hfln.portal.domain.gateway.WebStatsV2Gateway;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 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 javax.validation.Valid;
+import java.util.List;
+
 @RestController
 @CatchAndLog
 @Tag(name = "web端统计相关-v2")
@@ -29,4 +37,16 @@ public class WebStatsV2Controller {
     public ApiResult<ScreenStatsV2DTO> queryScreen() {
         return ApiResult.success(webStatsV2Gateway.queryScreenV2());
     }
+
+    @PostMapping("/alarmEventsQuery")
+    @Operation(summary = "告警事件统计查询")
+    public ApiResult<List<EventStatDto>> alarmEventsQuery(@RequestBody @Valid EventStatParams params) {
+        return ApiResult.success(webStatsV2Gateway.alarmEventsQuery(params));
+    }
+
+    @PostMapping("/analyse")
+    @Operation(summary = "动态健康监测分析")
+    public ApiResult<MonitorAnalyseDTO> monitorAnalyse() {
+        return ApiResult.success(webStatsV2Gateway.monitorAnalyse());
+    }
 }

+ 35 - 0
portal-service-common/src/main/java/com/hfln/portal/common/dto/data/event/EventStatDto.java

@@ -0,0 +1,35 @@
+package com.hfln.portal.common.dto.data.event;
+
+import com.hfln.portal.common.vo.BaseVO;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.time.LocalDateTime;
+
+
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class EventStatDto extends BaseVO {
+
+    @Schema(description = "消息名称")
+    private String eventName;
+
+    @Schema(description = "设备编码")
+    private String clientId;
+
+    @Schema(description = "设备ID")
+    private Long devId;
+
+    @Schema(description = "设备名称")
+    private String devName;
+
+    @Schema(description = "事件类型 fall 告警事件 alarm 异常事件")
+    private String eventType;
+
+    @Schema(description = "是否处理:0-未处理,1-已处理")
+    private Integer isHandle;
+
+    @Schema(description = "事件更新时间")
+    private LocalDateTime updateTime;
+}

+ 36 - 0
portal-service-common/src/main/java/com/hfln/portal/common/dto/data/stat/MonitorAnalyseDTO.java

@@ -0,0 +1,36 @@
+package com.hfln.portal.common.dto.data.stat;
+
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class MonitorAnalyseDTO {
+
+    @Schema(description = "季度统计信息列表")
+    private List<QuarterStatInfo> quarterStatInfos;
+
+    @Data
+    @Schema(description = "月统计信息")
+    public static class QuarterStatInfo {
+
+        @Schema(description = "季度,格式: yyyy-MM")
+        private String quarter;
+
+        @Schema(description = "事件统计信息列表")
+        private List<EventStat> eventStats;
+    }
+
+    @Data
+    @Schema(description = "事件统计信息")
+    public static class EventStat {
+        @Schema(description = "事件类型 fall 告警信息 alarm 异常事件")
+        private String eventType;
+        @Schema(description = "事件数量")
+        private int count;
+        @Schema(description = "事件处理率")
+        private Double handleRate;
+    }
+}

+ 23 - 0
portal-service-common/src/main/java/com/hfln/portal/common/request/event/EventStatParams.java

@@ -0,0 +1,23 @@
+package com.hfln.portal.common.request.event;
+
+import com.hfln.portal.common.vo.BaseVO;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import javax.validation.constraints.NotNull;
+import java.time.LocalDate;
+
+
+@EqualsAndHashCode(callSuper = true)
+@Data
+public class EventStatParams extends BaseVO {
+
+    @Schema(description = "起始时间 格式yyyy-MM-dd")
+    @NotNull(message = "起始时间 不能为空")
+    private LocalDate createTimeStart;
+
+    @Schema(description = "结束时间 格式yyyy-MM-dd")
+    @NotNull(message = "结束时间 不能为空")
+    private LocalDate createTimeEnd;
+}

+ 10 - 0
portal-service-domain/src/main/java/com/hfln/portal/domain/gateway/WebStatsV2Gateway.java

@@ -1,9 +1,19 @@
 package com.hfln.portal.domain.gateway;
 
+import com.hfln.portal.common.dto.data.event.EventStatDto;
+import com.hfln.portal.common.dto.data.stat.MonitorAnalyseDTO;
 import com.hfln.portal.common.dto.data.stat.ScreenStatsV2DTO;
+import com.hfln.portal.common.request.event.EventStatParams;
+
+import java.util.List;
 
 public interface WebStatsV2Gateway {
 
     ScreenStatsV2DTO queryScreenV2();
+
+    List<EventStatDto> alarmEventsQuery(EventStatParams params);
+
+    MonitorAnalyseDTO monitorAnalyse();
+
 }
 

+ 0 - 1
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/gateway/impl/WebStatsGatewayImpl.java

@@ -103,7 +103,6 @@ public class WebStatsGatewayImpl implements WebStatsGateway {
         List<EventsDTO> dtoList = CopyUtils.copyList(eventsPage.getRecords(), EventsDTO.class);
 
         // 4.填充devName
-//        devInfoService.fillDevNames(dtoList);
         devInfoService.fillDevNames(dtoList, EventsDTO::getClientId, EventsDTO::setDevName);
 
         // 5.封装成 PageRecord 返回

+ 110 - 1
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/gateway/impl/WebStatsV2GatewayImpl.java

@@ -1,7 +1,12 @@
 package com.hfln.portal.infrastructure.gateway.impl;
 
+import com.hfln.portal.common.dto.data.event.EventStatDto;
+import com.hfln.portal.common.dto.data.stat.MonitorAnalyseDTO;
 import com.hfln.portal.common.dto.data.stat.ScreenStatsV2DTO;
+import com.hfln.portal.common.request.event.EventStatParams;
 import com.hfln.portal.domain.gateway.WebStatsV2Gateway;
+import com.hfln.portal.infrastructure.po.EventList;
+import com.hfln.portal.infrastructure.po.Events;
 import com.hfln.portal.infrastructure.service.*;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -9,6 +14,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
 import java.math.BigDecimal;
+import java.time.LocalDate;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -17,7 +23,6 @@ import java.util.Map;
 @Service
 public class WebStatsV2GatewayImpl implements WebStatsV2Gateway {
 
-
     @Autowired
     private DevInfoService devInfoService;
 
@@ -30,6 +35,12 @@ public class WebStatsV2GatewayImpl implements WebStatsV2Gateway {
     @Autowired
     private AdminUserService adminuserService;
 
+    @Autowired
+    private EventsService eventsService;
+
+    @Autowired
+    private EventListService eventListService;
+
     @Override
     public ScreenStatsV2DTO queryScreenV2() {
         ScreenStatsV2DTO res = new ScreenStatsV2DTO();
@@ -86,6 +97,104 @@ public class WebStatsV2GatewayImpl implements WebStatsV2Gateway {
         res.setUserDistributionList(userDistributionList);
         return res;
     }
+
+    @Override
+    public List<EventStatDto> alarmEventsQuery(EventStatParams params) {
+
+        List<EventStatDto> res = new ArrayList<>();
+        // 查询 跌倒事件
+        List<EventList> eventLists = eventListService.queryList(params);
+        if (!CollectionUtils.isEmpty(eventLists)) {
+            List<EventStatDto> res1 = new ArrayList<>();
+            eventLists.forEach(events -> {
+                EventStatDto eventStatDto = new EventStatDto();
+                eventStatDto.setEventName(null);
+                eventStatDto.setDevId(events.getDevId());
+                eventStatDto.setDevName(null);
+                eventStatDto.setEventType("fall");
+                eventStatDto.setIsHandle(events.getIsHandle());
+                eventStatDto.setUpdateTime(events.getUpdateTime());
+                res1.add(eventStatDto);
+            });
+            devInfoService.fillDevNamesByDevId(res1, EventStatDto::getDevId, EventStatDto::setDevName, EventStatDto::setClientId);
+            res.addAll(res1);
+        }
+
+        // 查询 告警事件
+        List<Events> eventsList = eventsService.queryList(params);
+        if (!CollectionUtils.isEmpty(eventsList)) {
+            List<EventStatDto> res2 = new ArrayList<>();
+            eventsList.forEach(events -> {
+                EventStatDto eventStatDto = new EventStatDto();
+                eventStatDto.setEventName(null);
+                eventStatDto.setClientId(events.getClientId());
+                eventStatDto.setDevName(null);
+                eventStatDto.setEventType("alarm");
+                eventStatDto.setIsHandle(events.getIsHandle());
+                eventStatDto.setUpdateTime(events.getUpdateTime());
+                res2.add(eventStatDto);
+            });
+            devInfoService.fillDevNames(res2, EventStatDto::getClientId, EventStatDto::setDevName);
+            res.addAll(res2);
+        }
+        return res;
+    }
+
+    @Override
+    public MonitorAnalyseDTO monitorAnalyse() {
+
+        MonitorAnalyseDTO res = new MonitorAnalyseDTO();
+        res.setQuarterStatInfos(new ArrayList<>());
+        // 跌倒事件统计
+
+        int year = LocalDate.now().getYear();
+        // 第一季度
+        LocalDate startDate = LocalDate.of(year, 1, 1);
+        LocalDate endDate = LocalDate.of(year, 3, 31).plusDays(1);
+        res.getQuarterStatInfos().add(queryQuarterStatInfo(startDate, endDate, year + "第一季度"));
+
+        // 第二季度
+        startDate = LocalDate.of(year, 4, 1);
+        endDate = LocalDate.of(year, 6, 30).plusDays(1);
+        res.getQuarterStatInfos().add(queryQuarterStatInfo(startDate, endDate, year + "第二季度"));
+
+        // 第三季度
+        startDate = LocalDate.of(year, 7, 1);
+        endDate = LocalDate.of(year, 9, 30).plusDays(1);
+        res.getQuarterStatInfos().add(queryQuarterStatInfo(startDate, endDate, year + "第三季度"));
+
+        // 第四季度
+        startDate = LocalDate.of(year, 10, 1);
+        endDate = LocalDate.of(year, 12, 31).plusDays(1);
+        res.getQuarterStatInfos().add(queryQuarterStatInfo(startDate, endDate, year + "第四季度"));
+
+        return res;
+    }
+
+    private MonitorAnalyseDTO.QuarterStatInfo queryQuarterStatInfo(LocalDate startDate, LocalDate endDate, String quarter) {
+
+        MonitorAnalyseDTO.QuarterStatInfo firstQuarter = new MonitorAnalyseDTO.QuarterStatInfo();
+        firstQuarter.setQuarter(quarter);
+        firstQuarter.setEventStats(new ArrayList<>());
+        // 跌倒事件统计
+        MonitorAnalyseDTO.EventStat fallEventStat = new MonitorAnalyseDTO.EventStat();
+        fallEventStat.setEventType("fall");
+        Map<String, BigDecimal> eventListMap = eventListService.queryByQuarter(startDate, endDate);
+        if (!CollectionUtils.isEmpty(eventListMap)) {
+            fallEventStat.setCount(eventListMap.get("fallingCount") == null ? 0 : eventListMap.get("fallingCount").intValue());
+            if (fallEventStat.getCount() > 0) {
+                fallEventStat.setHandleRate(eventListMap.get("handleCount") == null ? 0.00 : (eventListMap.get("handleCount").divide(eventListMap.get("fallingCount"), 4 ,BigDecimal.ROUND_HALF_UP)).doubleValue());
+            }
+        }
+        firstQuarter.getEventStats().add(fallEventStat);
+        // 告警事件统计
+        MonitorAnalyseDTO.EventStat alarmEventStat = new MonitorAnalyseDTO.EventStat();
+        alarmEventStat.setEventType("alarm");
+        Long alarmCount = eventsService.queryByQuarter(startDate, endDate);
+        alarmEventStat.setCount(alarmCount == null ? 0 : alarmCount.intValue());
+        firstQuarter.getEventStats().add(alarmEventStat);
+        return firstQuarter;
+    }
 }
 
 

+ 12 - 0
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/mapper/EventListMapper.java

@@ -6,8 +6,10 @@ import com.hfln.portal.infrastructure.po.EventList;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Select;
 
+import java.math.BigDecimal;
 import java.time.LocalDate;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 事件列表表 Mapper 接口
@@ -32,4 +34,14 @@ public interface EventListMapper extends BaseMapper<EventList> {
             "GROUP BY DATE_FORMAT(e.create_time, '%Y-%m-%d') " +
             "ORDER BY date ASC ")
     List<ScreenFallingDTO.FallingDayStatInfo> queryEventsInSevenDays(Long tenantId, LocalDate startDate);
+
+    @Select("SELECT " +
+            "    sum(1) AS 'fallingCount', " +
+            "    SUM(CASE WHEN is_handle = 1 THEN 1 ELSE 0 END) AS 'handleCount' " +
+            "FROM event_list e " +
+            "WHERE 1 = 1 " +
+            "    AND e.create_time >= #{startDate}" +
+            "    AND e.create_time < #{endDate}"
+    )
+    Map<String, BigDecimal> queryByQuarter(LocalDate startDate, LocalDate endDate);
 }

+ 3 - 5
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/service/DevInfoService.java

@@ -46,9 +46,7 @@ public interface DevInfoService extends IService<DevInfo> {
 
     Map<String, BigDecimal> queryStatInfoV2();
 
-    /**
-     * 批量填充设备名称
-     */
-//    void fillDevNames(List<EventsDTO> dtoList);
 
-    <T> void fillDevNames(List<T> list, Function<T, String> clientIdGetter, BiConsumer<T, String> devNameSetter);}
+    <T> void fillDevNames(List<T> list, Function<T, String> clientIdGetter, BiConsumer<T, String> devNameSetter);
+    <T> void fillDevNamesByDevId(List<T> list, Function<T, Long> devIdGetter, BiConsumer<T, String> devNameSetter, BiConsumer<T, String> clientIdSetter);
+}

+ 8 - 0
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/service/EventListService.java

@@ -5,10 +5,14 @@ import com.baomidou.mybatisplus.extension.service.IService;
 import com.hfln.portal.common.dto.data.event.EventListDTO;
 import com.hfln.portal.common.dto.data.stat.ScreenFallingDTO;
 import com.hfln.portal.common.request.event.EventListParams;
+import com.hfln.portal.common.request.event.EventStatParams;
 import com.hfln.portal.common.request.event.WapEventListParams;
 import com.hfln.portal.infrastructure.po.EventList;
 
+import java.math.BigDecimal;
+import java.time.LocalDate;
 import java.util.List;
+import java.util.Map;
 
 public interface EventListService extends IService<EventList> {
 
@@ -21,4 +25,8 @@ public interface EventListService extends IService<EventList> {
     List<ScreenFallingDTO.FallingMonthStatInfo> queryEventsInSixMonths(Long tenantId);
 
     List<ScreenFallingDTO.FallingDayStatInfo> queryEventsInSevenDays(Long tenantId);
+
+    Map<String, BigDecimal> queryByQuarter(LocalDate startDate, LocalDate endDate);
+
+    List<EventList> queryList(EventStatParams params);
 }

+ 6 - 0
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/service/EventsService.java

@@ -3,10 +3,12 @@ package com.hfln.portal.infrastructure.service;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.hfln.portal.common.dto.data.stat.ScreenAlarmDTO;
+import com.hfln.portal.common.request.event.EventStatParams;
 import com.hfln.portal.common.request.event.WapEventsParams;
 import com.hfln.portal.common.request.event.WebEventsParams;
 import com.hfln.portal.infrastructure.po.Events;
 
+import java.time.LocalDate;
 import java.util.List;
 
 public interface EventsService extends IService<Events> {
@@ -20,4 +22,8 @@ public interface EventsService extends IService<Events> {
     List<ScreenAlarmDTO.AlarmMonthStatInfo> queryEventsInSixMonths(Long tenantId);
 
     List<ScreenAlarmDTO.AlarmDayStatInfo> queryEventsInSevenDays(Long tenantId);
+
+    Long queryByQuarter(LocalDate startDate, LocalDate endDate);
+
+    List<Events> queryList(EventStatParams params);
 }

+ 39 - 25
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/service/impl/DevInfoServiceImpl.java

@@ -270,34 +270,11 @@ public class DevInfoServiceImpl extends ServiceImpl<DevInfoMapper, DevInfo> impl
         return this.baseMapper.queryStatInfoV2(LocalDate.now().with(TemporalAdjusters.firstDayOfMonth()));
     }
 
-//    @Override
-//    public void fillDevNames(List<EventsDTO> dtoList) {
-//        if (CollectionUtils.isEmpty(dtoList)){
-//            return;
-//        }
-//
-//        Set<String> allClientIds = dtoList.stream()
-//                .map(EventsDTO::getClientId)
-//                .collect(Collectors.toSet());
-//
-//        if (!allClientIds.isEmpty()) {
-//            Map<String, String> devIdNameMap = this.queryByClientIds(allClientIds)
-//                    .stream()
-//                    .collect(Collectors.toMap(
-//                            DevInfo::getClientId,
-//                            dev -> Optional.ofNullable(dev.getDevName()).orElse("未命名设备")
-//                    ));
-//
-//            dtoList.forEach(dto -> dto.setDevName(devIdNameMap.getOrDefault(dto.getClientId(),"未知设备")));
-//        }
-//    }
-
     @Override
     public <T> void fillDevNames(
             List<T> list,
             Function<T, String> clientIdGetter,
             BiConsumer<T, String> devNameSetter) {
-
         if (CollectionUtils.isEmpty(list)) {
             return;
         }
@@ -306,12 +283,12 @@ public class DevInfoServiceImpl extends ServiceImpl<DevInfoMapper, DevInfo> impl
                 .map(clientIdGetter)
                 .filter(Objects::nonNull)
                 .collect(Collectors.toSet());
-
         if (allClientIds.isEmpty()) {
             return;
         }
+        List<DevInfo> devInfos = this.queryByClientIds(allClientIds);
 
-        Map<String, String> devIdNameMap = this.queryByClientIds(allClientIds)
+        Map<String, String> devIdNameMap = devInfos
                 .stream()
                 .collect(Collectors.toMap(
                         DevInfo::getClientId,
@@ -319,8 +296,45 @@ public class DevInfoServiceImpl extends ServiceImpl<DevInfoMapper, DevInfo> impl
                 ));
 
         list.forEach(item -> {
+            if (clientIdGetter != null) {
+
+            }
             String clientId = clientIdGetter.apply(item);
             devNameSetter.accept(item, devIdNameMap.getOrDefault(clientId, "未知设备"));
         });
     }
+
+    @Override
+    public <T> void fillDevNamesByDevId(
+            List<T> list,
+            Function<T, Long> devIdGetter,
+            BiConsumer<T, String> devNameSetter
+            , BiConsumer<T, String> clientIdSetter) {
+
+        if (CollectionUtils.isEmpty(list)) {
+            return;
+        }
+
+        Set<Long> devIds = list.stream()
+                .map(devIdGetter)
+                .filter(Objects::nonNull)
+                .collect(Collectors.toSet());
+        if (devIds.isEmpty()) {
+            return;
+        }
+        List<DevInfo> devInfos = this.baseMapper.selectBatchIds(devIds);
+
+        Map<Long, DevInfo> devIdNameMap = devInfos
+                .stream()
+                .collect(Collectors.toMap(
+                        DevInfo::getDevId,
+                        Function.identity()
+                ));
+
+        list.forEach(item -> {
+            Long devId = devIdGetter.apply(item);
+            devNameSetter.accept(item, devIdNameMap.get(devId) == null ? null : devIdNameMap.get(devId).getDevName());
+            clientIdSetter.accept(item, devIdNameMap.get(devId) == null ? null : devIdNameMap.get(devId).getClientId());
+        });
+    }
 }

+ 23 - 3
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/service/impl/EventListServiceImpl.java

@@ -6,19 +6,20 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.hfln.portal.common.dto.data.event.EventListDTO;
 import com.hfln.portal.common.dto.data.stat.ScreenFallingDTO;
 import com.hfln.portal.common.request.event.EventListParams;
+import com.hfln.portal.common.request.event.EventStatParams;
 import com.hfln.portal.common.request.event.WapEventListParams;
+import com.hfln.portal.infrastructure.config.UserContext;
 import com.hfln.portal.infrastructure.mapper.EventListMapper;
 import com.hfln.portal.infrastructure.po.EventList;
 import com.hfln.portal.infrastructure.service.EventListService;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 
+import java.math.BigDecimal;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.temporal.TemporalAdjusters;
-import java.util.Collections;
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
 import java.util.stream.Collectors;
 
 @Service
@@ -109,4 +110,23 @@ public class EventListServiceImpl extends ServiceImpl<EventListMapper, EventList
         LocalDate startDate = today.minusDays(6);
         return this.baseMapper.queryEventsInSevenDays(tenantId, startDate);
     }
+
+    @Override
+    public Map<String, BigDecimal> queryByQuarter(LocalDate startDate, LocalDate endDate) {
+        return this.baseMapper.queryByQuarter(startDate, endDate);
+    }
+
+    @Override
+    public List<EventList> queryList(EventStatParams params) {
+        LambdaQueryWrapper<EventList> queryWrapper = new LambdaQueryWrapper<>();
+
+        // 1. 时间过滤
+        Optional.ofNullable(params.getCreateTimeStart())
+                .ifPresent(start -> queryWrapper.ge(EventList::getCreateTime, start));
+        Optional.ofNullable(params.getCreateTimeEnd())
+                .ifPresent(end -> queryWrapper.lt(EventList::getCreateTime, end.plusDays(1)));
+        Optional.ofNullable(UserContext.getTenantId())
+                .ifPresent(tenantId -> queryWrapper.eq(EventList::getTenantId, tenantId));
+        return this.baseMapper.selectList(queryWrapper);
+    }
 }

+ 28 - 0
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/service/impl/EventsServiceImpl.java

@@ -4,10 +4,13 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.hfln.portal.common.dto.data.stat.ScreenAlarmDTO;
+import com.hfln.portal.common.request.event.EventStatParams;
 import com.hfln.portal.common.request.event.WapEventsParams;
 import com.hfln.portal.common.request.event.WebEventsParams;
 import com.hfln.portal.domain.customer.AdminUserType;
+import com.hfln.portal.infrastructure.config.UserContext;
 import com.hfln.portal.infrastructure.mapper.EventsMapper;
+import com.hfln.portal.infrastructure.po.BasePO;
 import com.hfln.portal.infrastructure.po.Events;
 import com.hfln.portal.infrastructure.service.EventsService;
 import org.springframework.stereotype.Service;
@@ -145,4 +148,29 @@ public class EventsServiceImpl extends ServiceImpl<EventsMapper, Events> impleme
         LocalDate startDate = today.minusDays(6);
         return this.baseMapper.queryEventsInSevenDays(tenantId, startDate);
     }
+
+    @Override
+    public Long queryByQuarter(LocalDate startDate, LocalDate endDate) {
+
+        LambdaQueryWrapper<Events> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.ge(Events::getCreateTime, startDate)
+                .eq(Events::getIsDeleted, BasePO.DeleteFlag.NOT_DELETED)
+                .lt(Events::getCreateTime, endDate);
+        return this.baseMapper.selectCount(queryWrapper);
+    }
+
+    @Override
+    public List<Events> queryList(EventStatParams params) {
+
+        LambdaQueryWrapper<Events> queryWrapper = new LambdaQueryWrapper<>();
+
+        // 1. 时间过滤
+        Optional.ofNullable(params.getCreateTimeStart())
+                .ifPresent(start -> queryWrapper.ge(Events::getCreateTime, start));
+        Optional.ofNullable(params.getCreateTimeEnd())
+                .ifPresent(end -> queryWrapper.lt(Events::getCreateTime, end.plusDays(1)));
+        Optional.ofNullable(UserContext.getTenantId())
+                .ifPresent(tenantId -> queryWrapper.eq(Events::getTenantId, tenantId));
+        return this.baseMapper.selectList(queryWrapper);
+    }
 }