فهرست منبع

1.web端查询日活接口调整
2.小程序新增告警计划模板查询
3.小程序新增告警计划保存
4.小程序新增告警计划查询
5.小程序新增告警计划是否生效
6.小程序新增告警计划删除

hxd 1 ماه پیش
والد
کامیت
9d3e7bf8c7

+ 45 - 45
portal-service-application/src/main/java/com/hfln/portal/application/controller/las/AlarmController.java

@@ -1,45 +1,45 @@
-
-package com.hfln.portal.application.controller.las;
-
-
-import cn.hfln.framework.catchlog.CatchAndLog;
-import cn.hfln.framework.dto.ApiResult;
-import com.hfln.portal.common.dto.data.event.AlarmPlanDTO;
-import com.hfln.portal.common.request.event.AlarmEventNoticeReq;
-import com.hfln.portal.common.request.event.AlarmPlanReq;
-import com.hfln.portal.domain.gateway.LasGateway;
-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 = "告警controller")
-@Slf4j
-@RequestMapping("/alarm")
-public class AlarmController {
-
-    @Autowired
-    private LasGateway lasGateway;
-
-    @Operation(summary = "告警计划查询")
-    @PostMapping("/plan/query")
-    public ApiResult<List<AlarmPlanDTO>> queryPlan(@Valid @RequestBody AlarmPlanReq req) {
-        return ApiResult.success(lasGateway.queryPlan(req));
-    }
-
-    @Operation(summary = "告警事件通知")
-    @PostMapping("/event/notice")
-    public ApiResult<Void> noticeEvent(@Valid @RequestBody AlarmEventNoticeReq req) {
-        return ApiResult.success(lasGateway.noticeEvent(req));
-    }
-
-}
+//
+//package com.hfln.portal.application.controller.las;
+//
+//
+//import cn.hfln.framework.catchlog.CatchAndLog;
+//import cn.hfln.framework.dto.ApiResult;
+//import com.hfln.portal.common.dto.data.event.AlarmPlanDTO;
+//import com.hfln.portal.common.request.event.AlarmEventNoticeReq;
+//import com.hfln.portal.common.request.event.AlarmPlanReq;
+//import com.hfln.portal.domain.gateway.LasGateway;
+//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 = "告警controller")
+//@Slf4j
+//@RequestMapping("/alarm")
+//public class AlarmController {
+//
+//    @Autowired
+//    private LasGateway lasGateway;
+//
+//    @Operation(summary = "告警计划查询")
+//    @PostMapping("/plan/query")
+//    public ApiResult<List<AlarmPlanDTO>> queryPlan(@Valid @RequestBody AlarmPlanReq req) {
+//        return ApiResult.success(lasGateway.queryPlan(req));
+//    }
+//
+//    @Operation(summary = "告警事件通知")
+//    @PostMapping("/event/notice")
+//    public ApiResult<Void> noticeEvent(@Valid @RequestBody AlarmEventNoticeReq req) {
+//        return ApiResult.success(lasGateway.noticeEvent(req));
+//    }
+//
+//}

+ 65 - 0
portal-service-application/src/main/java/com/hfln/portal/application/controller/wap/AlarmController.java

@@ -0,0 +1,65 @@
+package com.hfln.portal.application.controller.wap;
+
+
+import cn.hfln.framework.catchlog.CatchAndLog;
+import cn.hfln.framework.dto.ApiResult;
+import com.hfln.portal.common.dto.data.event.AlarmPlanDTO;
+import com.hfln.portal.common.dto.data.event.AlarmPlanTplDTO;
+import com.hfln.portal.common.request.event.*;
+import com.hfln.portal.domain.gateway.AlarmGateway;
+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 = "告警相关")
+@Slf4j
+@RequestMapping("/wap/alarm")
+public class AlarmController {
+
+    @Autowired
+    private AlarmGateway alarmGateway;
+
+    @PostMapping("/plan/queryTpl")
+    @Operation(summary = "告警计划模板查询")
+    public ApiResult<List<AlarmPlanTplDTO>> queryPlan(@Valid @RequestBody AlarmPlanTplQueryReq req) {
+        return ApiResult.success(alarmGateway.queryPlanTpl(req));
+    }
+
+
+    @PostMapping("/plan/query")
+    @Operation(summary = "告警计划查询")
+    public ApiResult<List<AlarmPlanDTO>> queryPlan(@Valid @RequestBody AlarmPlanQueryReq req) {
+        return ApiResult.success(alarmGateway.queryPlan(req));
+    }
+
+    @PostMapping("/plan/save")
+    @Operation(summary = "告警计划保存")
+    public ApiResult<AlarmPlanDTO> savePlan(@Valid @RequestBody AlarmPlanSaveReq req) {
+        return ApiResult.success(alarmGateway.savePlan(req));
+    }
+
+    @PostMapping("/plan/del")
+    @Operation(summary = "告警计划删除")
+    public ApiResult<Void> delPlan(@Valid @RequestBody AlarmPlanDelReq req) {
+        alarmGateway.delPlan(req);
+        return ApiResult.success();
+    }
+
+    @PostMapping("/plan/enable")
+    @Operation(summary = "告警计划是否生效")
+    public ApiResult<Void> enablePlan(@Valid @RequestBody AlarmPlanEnableReq req) {
+        alarmGateway.enablePlan(req);
+        return ApiResult.success();
+    }
+
+}

+ 2 - 2
portal-service-application/src/main/java/com/hfln/portal/application/controller/web/WebStatsController.java

@@ -6,7 +6,7 @@ import cn.hfln.framework.catchlog.CatchAndLog;
 import cn.hfln.framework.dto.ApiResult;
 import com.hfln.portal.common.dto.data.event.EventListDTO;
 import com.hfln.portal.common.dto.data.event.EventsDTO;
-import com.hfln.portal.common.dto.data.user.UserDailyActiveResult;
+import com.hfln.portal.common.dto.data.user.UserDailyActiveDTO;
 import com.hfln.portal.common.request.event.EventListParams;
 import com.hfln.portal.common.request.event.WebEventsParams;
 import com.hfln.portal.common.request.user.UserDailyActiveParams;
@@ -48,7 +48,7 @@ public class WebStatsController {
 
     @PostMapping("/queryUserDailyActive")
     @Operation(summary = "查询用户日活跃")
-    public ApiResult<UserDailyActiveResult> queryUserDailyActive(@Valid @RequestBody UserDailyActiveParams params) {
+    public ApiResult<PageRecord<UserDailyActiveDTO>> queryUserDailyActive(@Valid @RequestBody UserDailyActiveParams params) {
         return ApiResult.success(webStatsGateway.queryUserDailyActive(params));
     }
 }

+ 4 - 5
portal-service-common/src/main/java/com/hfln/portal/common/dto/data/user/UserDailyActiveResult.java → portal-service-common/src/main/java/com/hfln/portal/common/dto/data/user/UserDailyActiveDTO.java

@@ -3,14 +3,13 @@ package com.hfln.portal.common.dto.data.user;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
 
-import java.util.List;
-
 @Data
-public class UserDailyActiveResult {
+public class UserDailyActiveDTO {
+
+    @Schema(description = "用户手机号")
+    private String phone;
 
     @Schema(description = "用户访问总次数")
     private Integer visitCount;
 
-    @Schema(description = "用户日活记录列表")
-    private List<UsersDailyActiveDTO> records;
 }

+ 9 - 8
portal-service-common/src/main/java/com/hfln/portal/common/request/user/UserDailyActiveParams.java

@@ -1,22 +1,23 @@
 package com.hfln.portal.common.request.user;
 
-import com.hfln.portal.common.vo.BaseVO;
+import com.hfln.portal.common.vo.PageVo;
 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 UserDailyActiveParams extends BaseVO {
+public class UserDailyActiveParams extends PageVo {
 
-    @Schema(description = "用户ID")
-    @NotNull
-    private Long userId;
+    @Schema(description = "用户手机号")
+    private String phone;
 
-    @Schema(description = "查询日期 ,如果为空则默认当天  入参示例: 2025-08-25")
-    private LocalDate queryDate;
+    @Schema(description = "起始时间 格式yyyy-MM-dd")
+    private LocalDate createTimeStart;
+
+    @Schema(description = "结束时间 格式yyyy-MM-dd")
+    private LocalDate createTimeEnd;
 }

+ 16 - 16
portal-service-domain/src/main/java/com/hfln/portal/domain/gateway/LasGateway.java

@@ -1,16 +1,16 @@
-package com.hfln.portal.domain.gateway;
-
-import com.hfln.portal.common.dto.data.event.AlarmPlanDTO;
-import com.hfln.portal.common.request.event.AlarmEventNoticeReq;
-import com.hfln.portal.common.request.event.AlarmPlanReq;
-
-import java.util.List;
-
-public interface LasGateway {
-
-
-    List<AlarmPlanDTO> queryPlan(AlarmPlanReq req);
-
-    Void noticeEvent(AlarmEventNoticeReq req);
-}
-
+//package com.hfln.portal.domain.gateway;
+//
+//import com.hfln.portal.common.dto.data.event.AlarmPlanDTO;
+//import com.hfln.portal.common.request.event.AlarmEventNoticeReq;
+//import com.hfln.portal.common.request.event.AlarmPlanReq;
+//
+//import java.util.List;
+//
+//public interface LasGateway {
+//
+//
+//    List<AlarmPlanDTO> queryPlan(AlarmPlanReq req);
+//
+//    Void noticeEvent(AlarmEventNoticeReq req);
+//}
+//

+ 2 - 2
portal-service-domain/src/main/java/com/hfln/portal/domain/gateway/WebStatsGateway.java

@@ -2,7 +2,7 @@ package com.hfln.portal.domain.gateway;
 
 import com.hfln.portal.common.dto.data.event.EventListDTO;
 import com.hfln.portal.common.dto.data.event.EventsDTO;
-import com.hfln.portal.common.dto.data.user.UserDailyActiveResult;
+import com.hfln.portal.common.dto.data.user.UserDailyActiveDTO;
 import com.hfln.portal.common.request.event.EventListParams;
 import com.hfln.portal.common.request.event.WebEventsParams;
 import com.hfln.portal.common.request.user.UserDailyActiveParams;
@@ -15,6 +15,6 @@ public interface WebStatsGateway {
 
     PageRecord<EventsDTO> alarmEventsQuery(WebEventsParams params);
 
-    UserDailyActiveResult queryUserDailyActive(UserDailyActiveParams params);
+    PageRecord<UserDailyActiveDTO> queryUserDailyActive(UserDailyActiveParams params);
 }
 

+ 33 - 33
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/gateway/impl/LasGatewayImpl.java

@@ -1,33 +1,33 @@
-package com.hfln.portal.infrastructure.gateway.impl;
-
-import com.hfln.portal.common.dto.data.event.AlarmPlanDTO;
-import com.hfln.portal.common.request.event.AlarmEventNoticeReq;
-import com.hfln.portal.common.request.event.AlarmPlanReq;
-import com.hfln.portal.domain.gateway.LasGateway;
-import com.hfln.portal.infrastructure.service.AlarmPlanService;
-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;
-
-@Slf4j
-@Service
-public class LasGatewayImpl implements LasGateway {
-
-    @Autowired
-    private AlarmPlanService alarmPlanService;
-
-
-
-    @Override
-    public List<AlarmPlanDTO> queryPlan(AlarmPlanReq req) {
-        return Collections.emptyList();
-    }
-
-    @Override
-    public Void noticeEvent(AlarmEventNoticeReq req) {
-        return null;
-    }
-}
+//package com.hfln.portal.infrastructure.gateway.impl;
+//
+//import com.hfln.portal.common.dto.data.event.AlarmPlanDTO;
+//import com.hfln.portal.common.request.event.AlarmEventNoticeReq;
+//import com.hfln.portal.common.request.event.AlarmPlanReq;
+//import com.hfln.portal.domain.gateway.LasGateway;
+//import com.hfln.portal.infrastructure.service.AlarmPlanService;
+//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;
+//
+//@Slf4j
+//@Service
+//public class LasGatewayImpl implements LasGateway {
+//
+//    @Autowired
+//    private AlarmPlanService alarmPlanService;
+//
+//
+//
+//    @Override
+//    public List<AlarmPlanDTO> queryPlan(AlarmPlanReq req) {
+//        return Collections.emptyList();
+//    }
+//
+//    @Override
+//    public Void noticeEvent(AlarmEventNoticeReq req) {
+//        return null;
+//    }
+//}

+ 105 - 52
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/gateway/impl/WebStatsGatewayImpl.java

@@ -1,13 +1,13 @@
 package com.hfln.portal.infrastructure.gateway.impl;
 
 import cn.dev33.satoken.stp.StpUtil;
+import com.alibaba.excel.util.StringUtils;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.hfln.portal.common.constant.UserConstants;
 import com.hfln.portal.common.dto.data.event.EventListDTO;
 import com.hfln.portal.common.dto.data.event.EventsDTO;
-import com.hfln.portal.common.dto.data.user.UserDailyActiveResult;
-import com.hfln.portal.common.dto.data.user.UsersDailyActiveDTO;
+import com.hfln.portal.common.dto.data.user.UserDailyActiveDTO;
 import com.hfln.portal.common.request.event.EventListParams;
 import com.hfln.portal.common.request.event.WebEventsParams;
 import com.hfln.portal.common.request.user.UserDailyActiveParams;
@@ -17,19 +17,13 @@ import com.hfln.portal.domain.customer.util.CopyUtils;
 import com.hfln.portal.domain.gateway.WebStatsGateway;
 import com.hfln.portal.infrastructure.po.DailyActiveUsers;
 import com.hfln.portal.infrastructure.po.EventList;
-import com.hfln.portal.infrastructure.service.DailyActiveUsersService;
-import com.hfln.portal.infrastructure.service.DevInfoService;
-import com.hfln.portal.infrastructure.service.EventListService;
-import com.hfln.portal.infrastructure.service.EventsService;
+import com.hfln.portal.infrastructure.po.UserInfo;
+import com.hfln.portal.infrastructure.service.*;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.time.LocalDate;
-import java.time.LocalDateTime;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
+import java.util.*;
 import java.util.stream.Collectors;
 
 @Slf4j
@@ -49,6 +43,10 @@ public class WebStatsGatewayImpl implements WebStatsGateway {
     @Autowired
     private EventsService eventsService;
 
+    @Autowired
+    private UserService userService;
+
+
     @Override
     public PageRecord<EventListDTO> fallQuery(EventListParams params) {
         Long tenantId =  (Long) StpUtil.getSession().get(UserConstants.SA_USER_TENANT_ID);
@@ -91,50 +89,105 @@ public class WebStatsGatewayImpl implements WebStatsGateway {
 
 
     @Override
-    public UserDailyActiveResult queryUserDailyActive(UserDailyActiveParams params) {
-
-        // 1.处理查询日期,入参为空则默认当天
-        LocalDate queryDate = (params.getQueryDate() != null) ? params.getQueryDate() : LocalDate.now();
-        LocalDateTime startOfDay = queryDate.atStartOfDay();
-        LocalDateTime endOfDay = queryDate.plusDays(1).atStartOfDay().minusNanos(1);
-
-        // 2. 查询总访问次数
-        LambdaQueryWrapper<DailyActiveUsers> countWrapper = new LambdaQueryWrapper<>();
-        countWrapper.eq(DailyActiveUsers::getUserId, params.getUserId())
-                .between(DailyActiveUsers::getCreateTime, startOfDay, endOfDay);
-        long totalCount = dailyActiveUsersService.count(countWrapper);
-
-        if (totalCount == 0) {
-            UserDailyActiveResult emptyResult = new UserDailyActiveResult();
-            emptyResult.setVisitCount(0);
-            emptyResult.setRecords(Collections.emptyList());
-            return emptyResult;
-        }
+    public PageRecord<UserDailyActiveDTO> queryUserDailyActive(UserDailyActiveParams params) {
+
+        PageRecord<UserDailyActiveDTO> pageRecord = new PageRecord<>();
 
-        // 3. 查询用户单日的日活记录(按时间倒序)
         LambdaQueryWrapper<DailyActiveUsers> queryWrapper = new LambdaQueryWrapper<>();
-        queryWrapper.eq(DailyActiveUsers::getUserId, params.getUserId())
-                .between(DailyActiveUsers::getCreateTime, startOfDay, endOfDay)
-                .orderByDesc(DailyActiveUsers::getCreateTime);
-
-        List<DailyActiveUsers> dailyActiveUsers = dailyActiveUsersService.list(queryWrapper);
-
-        // 4. 转换 DTO
-        List<UsersDailyActiveDTO> records = dailyActiveUsers.stream().map(record -> {
-            UsersDailyActiveDTO dto = new UsersDailyActiveDTO();
-            dto.setDailyActiveId(record.getDailyActiveId());
-            dto.setUserId(record.getUserId());
-            dto.setVisitTime(record.getCreateTime()); // visitTime = createTime
-            return dto;
-        }).collect(Collectors.toList());
-
-        // 5. 封装结果
-        UserDailyActiveResult result = new UserDailyActiveResult();
-        result.setVisitCount((int) totalCount);
-        result.setRecords(records);
-
-        return result;
+        if (Objects.nonNull(params.getCreateTimeStart())) {
+            queryWrapper.ge(DailyActiveUsers::getCreateTime, params.getCreateTimeStart());
+        }
+        if (Objects.nonNull(params.getCreateTimeEnd())) {
+            queryWrapper.lt(DailyActiveUsers::getCreateTime, params.getCreateTimeEnd().plusDays(1));
+        }
+        queryWrapper.orderByDesc(DailyActiveUsers::getCreateTime);
+
+        // ------------------------
+        // 手机号不为空 → 查询指定用户
+        // ------------------------
+        if (StringUtils.isNotBlank(params.getPhone())) {
+            final String phone = params.getPhone();
+            UserInfo userInfo = userService.lambdaQuery()
+                    .eq(UserInfo::getPhone, phone)
+                    .one();
+
+            if (userInfo == null) {
+                pageRecord.setRows(Collections.emptyList());
+                pageRecord.setTotal(0L);
+                pageRecord.setPageNum(params.getPageNo());
+                pageRecord.setPageSize(params.getPageSize());
+                pageRecord.setTotalPageNum(0);
+                return pageRecord;
+            }
+
+            queryWrapper.eq(DailyActiveUsers::getUserId, userInfo.getUserId());
+            List<DailyActiveUsers> userRecords = dailyActiveUsersService.list(queryWrapper);
+
+            UserDailyActiveDTO dto = new UserDailyActiveDTO();
+            dto.setPhone(phone);
+            dto.setVisitCount(userRecords.size());
+
+            pageRecord.setRows(Collections.singletonList(dto));
+            pageRecord.setTotal(userRecords.isEmpty() ? 0L : 1L);
+            pageRecord.setPageNum(params.getPageNo());
+            pageRecord.setPageSize(params.getPageSize());
+            pageRecord.setTotalPageNum(1);
+            return pageRecord;
+        }
+
+        // ------------------------
+        // 手机号为空 → 查询所有用户
+        // ------------------------
+        List<DailyActiveUsers> allRecords = dailyActiveUsersService.list(queryWrapper);
+        if (allRecords.isEmpty()) {
+            pageRecord.setRows(Collections.emptyList());
+            pageRecord.setTotal(0L);
+            pageRecord.setPageNum(params.getPageNo());
+            pageRecord.setPageSize(params.getPageSize());
+            pageRecord.setTotalPageNum(0);
+            return pageRecord;
+        }
+
+        // 批量查询用户信息
+        Set<Long> userIds = allRecords.stream()
+                .map(DailyActiveUsers::getUserId)
+                .collect(Collectors.toSet());
+        List<UserInfo> userInfos = userService.listByIds(userIds);
+        Map<Long, String> userIdPhoneMap = userInfos.stream()
+                .collect(Collectors.toMap(UserInfo::getUserId, UserInfo::getPhone));
+
+        // 聚合访问次数
+        Map<Long, Long> visitCountMap = allRecords.stream()
+                .collect(Collectors.groupingBy(DailyActiveUsers::getUserId, Collectors.counting()));
+
+        // 转 DTO 列表
+        List<UserDailyActiveDTO> dtoList = visitCountMap.entrySet().stream()
+                .map(entry -> {
+                    UserDailyActiveDTO dto = new UserDailyActiveDTO();
+                    dto.setPhone(userIdPhoneMap.get(entry.getKey()));
+                    dto.setVisitCount(entry.getValue().intValue());
+                    return dto;
+                }).collect(Collectors.toList());
+
+        // ------------------------
+        // Java 层分页
+        // ------------------------
+        int pageNo = params.getPageNo();
+        int pageSize = params.getPageSize();
+        int total = dtoList.size();
+        int start = (pageNo - 1) * pageSize;
+        int end = Math.min(start + pageSize, total);
+        List<UserDailyActiveDTO> pageList = start >= total ? Collections.emptyList() : dtoList.subList(start, end);
+
+        pageRecord.setRows(pageList);
+        pageRecord.setTotal((long) total);
+        pageRecord.setPageNum(pageNo);
+        pageRecord.setPageSize(pageSize);
+        pageRecord.setTotalPageNum((total + pageSize - 1) / pageSize);
+
+        return pageRecord;
     }
 }
 
+