瀏覽代碼

接口调整

hxd 2 月之前
父節點
當前提交
ae4e804c25
共有 28 個文件被更改,包括 453 次插入112 次删除
  1. 2 2
      portal-service-application/src/main/java/com/hfln/portal/application/controller/wap/DeviceController.java
  2. 32 6
      portal-service-application/src/main/java/com/hfln/portal/application/controller/web/WebStatsController.java
  3. 5 2
      portal-service-common/src/main/java/com/hfln/portal/common/dto/data/event/AlarmEventDTO.java
  4. 1 1
      portal-service-common/src/main/java/com/hfln/portal/common/dto/data/event/EventListDTO.java
  5. 53 0
      portal-service-common/src/main/java/com/hfln/portal/common/dto/data/event/StayTimeDTO.java
  6. 0 2
      portal-service-common/src/main/java/com/hfln/portal/common/request/device/DeviceBandingParams.java
  7. 2 0
      portal-service-common/src/main/java/com/hfln/portal/common/request/device/UpdateDeviceParams.java
  8. 26 0
      portal-service-common/src/main/java/com/hfln/portal/common/request/event/AlarmEventParams.java
  9. 12 10
      portal-service-common/src/main/java/com/hfln/portal/common/request/event/EventListParams.java
  10. 28 0
      portal-service-common/src/main/java/com/hfln/portal/common/request/event/StayTimeParams.java
  11. 0 6
      portal-service-common/src/main/java/com/hfln/portal/common/request/room/RoomParam.java
  12. 4 3
      portal-service-common/src/main/java/com/hfln/portal/common/request/room/SubRegionInfo.java
  13. 2 1
      portal-service-domain/src/main/java/com/hfln/portal/domain/customer/util/CopyUtils.java
  14. 1 1
      portal-service-domain/src/main/java/com/hfln/portal/domain/gateway/DeviceGateway.java
  15. 11 5
      portal-service-domain/src/main/java/com/hfln/portal/domain/gateway/WebStatsGateway.java
  16. 91 34
      portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/gateway/impl/DeviceGatewayImpl.java
  17. 1 1
      portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/gateway/impl/WebGatewayImpl.java
  18. 98 8
      portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/gateway/impl/WebStatsGatewayImpl.java
  19. 11 10
      portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/mqtt/MqttSubHandle.java
  20. 3 3
      portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/po/AlarmEvent.java
  21. 6 0
      portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/po/DevInfo.java
  22. 3 3
      portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/po/EventList.java
  23. 5 1
      portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/service/AlarmEventService.java
  24. 1 0
      portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/service/DevInfoService.java
  25. 3 3
      portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/service/EventService.java
  26. 26 2
      portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/service/impl/AlarmEventServiceImpl.java
  27. 14 0
      portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/service/impl/DevInfoServiceImpl.java
  28. 12 8
      portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/service/impl/EventServiceImpl.java

+ 2 - 2
portal-service-application/src/main/java/com/hfln/portal/application/controller/wap/DeviceController.java

@@ -83,8 +83,8 @@ public class DeviceController {
 
     @GetMapping("/getWcTimes")
     @Operation(summary = "查询当天上厕所次数")
-    public ApiResult<WcTimesQueryRes> getWcTimes(@RequestParam("clientId") Long clientId, @RequestParam("time") String time) {
-        return ApiResult.success(deviceGateway.getWcTimes(clientId, time));
+    public ApiResult<WcTimesQueryRes> getWcTimes(@RequestParam("devId") Long devId, @RequestParam("time") String time) {
+        return ApiResult.success(deviceGateway.getWcTimes(devId, time));
     }
 
     @PostMapping("/transfer")

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

@@ -3,13 +3,26 @@ 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.AlarmEventDTO;
+import com.hfln.portal.common.dto.data.event.EventListDTO;
+import com.hfln.portal.common.dto.data.event.StayTimeDTO;
+import com.hfln.portal.common.request.event.AlarmEventParams;
+import com.hfln.portal.common.request.event.EventListParams;
+import com.hfln.portal.common.request.event.StayTimeParams;
+import com.hfln.portal.common.vo.PageRecord;
 import com.hfln.portal.domain.gateway.WebStatsGateway;
+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;
+
 @RestController
 @CatchAndLog
 @Tag(name = "web端统计相关")
@@ -20,10 +33,23 @@ public class WebStatsController {
     @Autowired
     private WebStatsGateway webStatsGateway;
 
-//    @PostMapping("/addDic")
-//    @Operation(summary = "添加字典类值")
-//    public ApiResult<Void> addDic(@RequestBody @Valid DicAddParam param){
-//        webGateway.addDic(param);
-//        return ApiResult.success();
-//    }
+    @PostMapping("/fallQuery")
+    @Operation(summary = "跌倒统计查询")
+    public ApiResult<PageRecord<EventListDTO>> fallQuery(@Valid @RequestBody EventListParams  params) {
+        return ApiResult.success(webStatsGateway.fallQuery(params));
+    }
+
+    @PostMapping("/generalRetentionQuery")
+    @Operation(summary = "一般滞留统计查询")
+    public ApiResult<PageRecord<StayTimeDTO>> generalRetentionQuery(@Valid @RequestBody StayTimeParams params) {
+        return ApiResult.success(webStatsGateway.generalRetentionQuery(params));
+    }
+
+
+    @PostMapping("/alarmRetentionQuery")
+    @Operation(summary = "异常滞留统计查询")
+    public ApiResult<PageRecord<AlarmEventDTO>> alarmRetentionQuery(@Valid @RequestBody AlarmEventParams params) {
+        return ApiResult.success(webStatsGateway.alarmRetentionQuery(params));
+    }
+
 }

+ 5 - 2
portal-service-common/src/main/java/com/hfln/portal/common/dto/data/event/AlarmEventDTO.java

@@ -8,12 +8,15 @@ import lombok.EqualsAndHashCode;
 @EqualsAndHashCode(callSuper = true)
 public class AlarmEventDTO extends BaseVO {
 
+    /**
+     * 告警表主键ID
+     */
     private Long alarmEventId;
 
     /**
-     * 设备ID
+     * 设备表主键ID
      */
-    private Long clientId;
+    private Long devId;
 
     /**
      * 姿势

+ 1 - 1
portal-service-common/src/main/java/com/hfln/portal/common/dto/data/event/EventListDTO.java

@@ -18,7 +18,7 @@ public class EventListDTO extends BaseVO {
      * 设备ID
      */
     @Schema(description = "设备Id")
-    private String devId;
+    private Long devId;
 
     /**
      * 姿态

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

@@ -0,0 +1,53 @@
+package com.hfln.portal.common.dto.data.event;
+
+
+import com.hfln.portal.common.vo.BaseVO;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.time.LocalDateTime;
+
+@EqualsAndHashCode(callSuper = true)
+@Data
+public class StayTimeDTO extends BaseVO {
+
+    /**
+     * stay_time表主键id
+     */
+    private Long stayTimeId;
+
+    /**
+     * 设备表主键id
+     */
+    private Long devId;
+
+    /**
+     * 设备客户端id
+     */
+    private String clientId;
+
+    /**
+     * 设备名称
+     */
+    private String devName;
+
+    /**
+     *  停留类型
+     */
+    private Integer type;
+
+    /**
+     * 进入时间
+     */
+    private LocalDateTime enterTime;
+
+    /**
+     * 离开时间
+     */
+    private LocalDateTime leaveTime;
+
+    /**
+     * 停留时长(秒)
+     */
+    private Integer stayTime;
+}

+ 0 - 2
portal-service-common/src/main/java/com/hfln/portal/common/request/device/DeviceBandingParams.java

@@ -77,6 +77,4 @@ public class DeviceBandingParams extends BaseVO {
     @DecimalMin(value = "200", message = "zzEnd不能小于200")
     @DecimalMax(value = "300", message = "zzEnd不能大于300")
     private BigDecimal zzEnd;
-
-
 }

+ 2 - 0
portal-service-common/src/main/java/com/hfln/portal/common/request/device/UpdateDeviceParams.java

@@ -82,4 +82,6 @@ public class UpdateDeviceParams extends BaseVO {
     @DecimalMax(value = "300", message = "zzEnd不能大于300")
     private BigDecimal zzEnd;
 
+    @Schema(description = "设备跌倒确认时间")
+    private BigDecimal fallingConfirm;
 }

+ 26 - 0
portal-service-common/src/main/java/com/hfln/portal/common/request/event/AlarmEventParams.java

@@ -0,0 +1,26 @@
+package com.hfln.portal.common.request.event;
+
+import com.hfln.portal.common.vo.PageVo;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.time.LocalDate;
+
+
+@EqualsAndHashCode(callSuper = true)
+@Data
+public class AlarmEventParams extends PageVo {
+
+    @Schema(description = "设备ID")
+    private Long devId;
+
+    @Schema(description = "租户id")
+    private Long tenantId;
+
+    @Schema(description = "起始时间 格式yyyy-MM-dd")
+    private LocalDate createTimeStart;
+
+    @Schema(description = "结束时间 格式yyyy-MM-dd")
+    private LocalDate createTimeEnd;
+}

+ 12 - 10
portal-service-common/src/main/java/com/hfln/portal/common/request/event/EventListParams.java

@@ -5,22 +5,24 @@ import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 
-import javax.validation.constraints.NotEmpty;
-import java.util.Date;
+import java.time.LocalDate;
 
 @EqualsAndHashCode(callSuper = true)
 @Data
-@Schema(description = "事件列表查询")
+@Schema(description = "跌倒事件列表查询")
 public class EventListParams extends PageVo {
 
-    @NotEmpty(message = "设备ID不能为空!")
-    @Schema(description = "设备ID", required = true)
-    private String devId;
 
-    @Schema(description = "开始时间", required = true)
-    private Date startTime;
+    @Schema(description = "设备ID")
+    private Long devId;
 
-    @Schema(description = "结束时间", required = true)
-    private Date endTime;
+    @Schema(description = "租户id")
+    private Long tenantId;
+
+    @Schema(description = "起始时间 格式yyyy-MM-dd")
+    private LocalDate createTimeStart;
+
+    @Schema(description = "结束时间 格式yyyy-MM-dd")
+    private LocalDate createTimeEnd;
 
 }

+ 28 - 0
portal-service-common/src/main/java/com/hfln/portal/common/request/event/StayTimeParams.java

@@ -0,0 +1,28 @@
+package com.hfln.portal.common.request.event;
+
+import com.hfln.portal.common.vo.PageVo;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.time.LocalDate;
+
+
+@EqualsAndHashCode(callSuper = true)
+@Data
+@Schema(description = "一般滞留事件查询")
+public class StayTimeParams extends PageVo {
+
+
+    @Schema(description = "设备ID")
+    private Long devId;
+
+    @Schema(description = "租户id")
+    private Long tenantId;
+
+    @Schema(description = "起始时间 格式yyyy-MM-dd")
+    private LocalDate createTimeStart;
+
+    @Schema(description = "结束时间 格式yyyy-MM-dd")
+    private LocalDate createTimeEnd;
+}

+ 0 - 6
portal-service-common/src/main/java/com/hfln/portal/common/request/room/RoomParam.java

@@ -16,12 +16,6 @@ public class RoomParam extends BaseVO {
 
 
     /**
-     * 主键ID
-     */
-    @Schema(description = "主键ID")
-    private Long roomId;
-
-    /**
      * 设备ID
      */
     @Schema(description = "设备ID")

+ 4 - 3
portal-service-common/src/main/java/com/hfln/portal/common/request/room/SubRegionInfo.java

@@ -27,9 +27,10 @@ public class SubRegionInfo {
     @Schema(description = "屏蔽子区域Z结束")
     private BigDecimal stopZz;
 
+    @Schema(description = "默认0")
     private Integer isLowSnr;
 
-    @Schema(description = "是否为门: 0-是,1-不是")
+    @Schema(description = "默认传0 是否为门: 0-是,1-不是")
     private Integer isDoor;
 
     @Schema(description = "人员进入时间 默认3")
@@ -38,9 +39,9 @@ public class SubRegionInfo {
     @Schema(description = "人员离开时间 默认3")
     private BigDecimal presenceExitDuration;
 
-    @Schema(description = "是否开启区域跟踪存在 0-否,1-是")
+    @Schema(description = "默认1 是否开启区域跟踪存在 0-否,1-是")
     private BigDecimal trackPresence;
 
-    @Schema(description = "是否屏蔽区域跌倒检测 0-否,1-是")
+    @Schema(description = "默认1 是否屏蔽区域跌倒检测 0-否,1-是")
     private BigDecimal excludeFalling;
 }

+ 2 - 1
portal-service-domain/src/main/java/com/hfln/portal/domain/customer/util/CopyUtils.java

@@ -5,6 +5,7 @@ import com.hfln.portal.common.vo.PageRecord;
 import org.springframework.beans.BeanUtils;
 import org.springframework.util.CollectionUtils;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -25,7 +26,7 @@ public class CopyUtils {
     public static <T> List<T> copyList(List<?> sourceList, Class<T> clazz) {
 
         if (CollectionUtils.isEmpty(sourceList)) {
-            return null;
+            return new ArrayList<>();
         }
 
         return sourceList.stream()

+ 1 - 1
portal-service-domain/src/main/java/com/hfln/portal/domain/gateway/DeviceGateway.java

@@ -91,7 +91,7 @@ public interface DeviceGateway {
 
     String getFloorPlan(String groupUuid);
 
-    WcTimesQueryRes getWcTimes(Long client, String time);
+    WcTimesQueryRes getWcTimes(Long devId, String time);
 
 
 

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

@@ -1,14 +1,20 @@
 package com.hfln.portal.domain.gateway;
 
-import com.hfln.portal.common.dto.data.pub.DicItemDto;
-
-import java.util.List;
+import com.hfln.portal.common.dto.data.event.AlarmEventDTO;
+import com.hfln.portal.common.dto.data.event.EventListDTO;
+import com.hfln.portal.common.dto.data.event.StayTimeDTO;
+import com.hfln.portal.common.request.event.AlarmEventParams;
+import com.hfln.portal.common.request.event.EventListParams;
+import com.hfln.portal.common.request.event.StayTimeParams;
+import com.hfln.portal.common.vo.PageRecord;
 
 public interface WebStatsGateway {
 
 
-    List<DicItemDto> query(String dicType);
+    PageRecord<EventListDTO> fallQuery(EventListParams params);
+
+    PageRecord<StayTimeDTO> generalRetentionQuery(StayTimeParams params);
 
-//    void uploadWJ(MultipartFile file,  String fileType) throws IOException;
+    PageRecord<AlarmEventDTO> alarmRetentionQuery(AlarmEventParams params);
 }
 

+ 91 - 34
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/gateway/impl/DeviceGatewayImpl.java

@@ -46,6 +46,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.lang.reflect.Field;
 import java.math.BigDecimal;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
@@ -248,35 +249,7 @@ public class DeviceGatewayImpl implements DeviceGateway {
         }
 
         //4.通过MQTT把信息参数发送到设备
-        String topic = String.format(TopicConstants.TOPIC_SET_DEVICE_PARAM, devInfo.getClientId());
-
-        //构建检测区域
-        Map<String, BigDecimal> base = new HashMap<>();
-        base.put("x_cm_start", request.getXxStart());
-        base.put("x_cm_stop", request.getXxEnd());
-        base.put("y_cm_start", request.getYyStart());
-        base.put("y_cm_stop", request.getYyEnd());
-        base.put("z_cm_start", request.getZzStart());
-        base.put("z_cm_stop", request.getZzEnd());
-        Map<String, Map<String, BigDecimal>> baseParent = new HashMap<>();
-        baseParent.put("base", base);
-
-        //构建安装高度
-        Map<String, BigDecimal> z_cm = new HashMap<>();
-        z_cm.put("z_cm", request.getHeight());
-
-
-        //发送最终消息
-        JSONObject jsonObject = new JSONObject();
-        jsonObject.put("ext_region", baseParent);
-        jsonObject.put("sensor_location", z_cm);
-
-        try {
-            mqttClient.sendMessage(topic, jsonObject.toJSONString());
-        } catch (Exception e) {
-            log.error("发送设备参数到MQTT失败", e);
-            throw new BizException(ErrorEnum.MQTT_SEND_ERROR.getErrorCode(), ErrorEnum.MQTT_SEND_ERROR.getErrorMessage());
-        }
+        sendDeviceParamsToMqtt(devInfo.getClientId(), request);
 
         return updateResult;
     }
@@ -341,8 +314,13 @@ public class DeviceGatewayImpl implements DeviceGateway {
             throw new BizException(ErrorEnum.DEVICE_IS_NOT_EXIST.getErrorCode(), ErrorEnum.DEVICE_IS_NOT_EXIST.getErrorMessage());
         }
 
+        //2.校验是否为主绑人
+        if (!devInfo.getUserId().equals(params.getUserId())){
+            throw new BizException(ErrorEnum.USER_NO_PERMISSION.getErrorCode(), ErrorEnum.USER_NO_PERMISSION.getErrorMessage());
+        }
 
-        //2..更新数据
+
+        //3.更新数据
         devInfo.setTenantId(params.getTenantId());
         devInfo.setDevName(params.getDevName());
         devInfo.setHeight(params.getHeight());
@@ -359,9 +337,14 @@ public class DeviceGatewayImpl implements DeviceGateway {
         devInfo.setZzEnd(params.getZzEnd());
         devInfo.setLength(params.getXxEnd().subtract(params.getXxStart()));
         devInfo.setWidth(params.getYyEnd().subtract(params.getYyStart()));
+        devInfo.setFallingConfirm(params.getFallingConfirm());
 
         boolean updated = devInfoService.updateById(devInfo);
-        return  updated;
+        
+        //4.通过MQTT把信息参数发送到设备
+        sendDeviceParamsToMqtt(devInfo.getClientId(), params);
+        
+        return updated;
     }
 
 
@@ -374,6 +357,80 @@ public class DeviceGatewayImpl implements DeviceGateway {
         }
     }
 
+    /**
+     * 发送设备参数到MQTT的通用方法
+     * @param clientId 设备客户端ID
+     * @param params 设备参数(DeviceBandingParams或UpdateDeviceParams)
+     */
+    private void sendDeviceParamsToMqtt(String clientId, Object params) {
+        String topic = String.format(TopicConstants.TOPIC_SET_DEVICE_PARAM, clientId);
+
+        //构建检测区域
+        Map<String, BigDecimal> base = new HashMap<>();
+        base.put("x_cm_start", getFieldValue(params, "xxStart"));
+        base.put("x_cm_stop", getFieldValue(params, "xxEnd"));
+        base.put("y_cm_start", getFieldValue(params, "yyStart"));
+        base.put("y_cm_stop", getFieldValue(params, "yyEnd"));
+        base.put("z_cm_start", getFieldValue(params, "zzStart"));
+        base.put("z_cm_stop", getFieldValue(params, "zzEnd"));
+        Map<String, Map<String, BigDecimal>> baseParent = new HashMap<>();
+        baseParent.put("base", base);
+
+        //构建安装高度
+        Map<String, BigDecimal> z_cm = new HashMap<>();
+        z_cm.put("z_cm", getFieldValue(params, "height"));
+
+        //构建跌倒确认时间
+        Map<String, Integer> fallingStateMachineDurations = new HashMap<>();
+        // 从参数中获取跌倒确认时间
+        BigDecimal fallingConfirm = getFieldValue(params, "fallingConfirm");
+        if (fallingConfirm != null && fallingConfirm.compareTo(BigDecimal.ZERO) > 0) {
+            int confirmTime = fallingConfirm.intValue();
+            fallingStateMachineDurations.put("durationUntilConfirm_sec", confirmTime);
+            // minTimeOfTarInFallLoc_sec 是 durationUntilConfirm_sec的90%
+            fallingStateMachineDurations.put("minTimeOfTarInFallLoc_sec", (int)(confirmTime * 0.9));
+            // 固定默认值
+            fallingStateMachineDurations.put("durationUntilCalling_sec", 13);
+            fallingStateMachineDurations.put("durationUntilReset_sec", 3);
+        } else {
+            // 使用默认值
+            fallingStateMachineDurations.put("durationUntilConfirm_sec", 53);
+            fallingStateMachineDurations.put("minTimeOfTarInFallLoc_sec", 33);
+            fallingStateMachineDurations.put("durationUntilCalling_sec", 13);
+            fallingStateMachineDurations.put("durationUntilReset_sec", 3);
+        }
+
+        //发送最终消息
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("ext_region", baseParent);
+        jsonObject.put("sensor_location", z_cm);
+        jsonObject.put("fallingStateMachineDurations", fallingStateMachineDurations);
+
+        try {
+            mqttClient.sendMessage(topic, jsonObject.toJSONString());
+        } catch (Exception e) {
+            log.error("发送设备参数到MQTT失败", e);
+            throw new BizException(ErrorEnum.MQTT_SEND_ERROR.getErrorCode(), ErrorEnum.MQTT_SEND_ERROR.getErrorMessage());
+        }
+    }
+
+    /**
+     * 通过反射获取对象字段值
+     * @param obj 对象
+     * @param fieldName 字段名
+     * @return 字段值
+     */
+    private BigDecimal getFieldValue(Object obj, String fieldName) {
+        try {
+            Field field = obj.getClass().getDeclaredField(fieldName);
+            field.setAccessible(true);
+            return (BigDecimal) field.get(obj);
+        } catch (Exception e) {
+            log.error("获取字段值失败: {}", fieldName, e);
+            return BigDecimal.ZERO;
+        }
+    }
+
 
     @Override
     public Boolean updateDeviceLocation(DeviceLocationParams params) {
@@ -557,7 +614,7 @@ public class DeviceGatewayImpl implements DeviceGateway {
                 extSubRegions.add(regionJson);
             }
             JSONObject infoMsg = new JSONObject();
-            subRegionMsg.put("ext_sub_regions", extSubRegions);
+            infoMsg.put("ext_sub_regions", extSubRegions);
 
             String topicDev = String.format(TopicConstants.TOPIC_SET_DEVICE_PARAM, devInfo.getClientId());
             try {
@@ -873,11 +930,11 @@ public class DeviceGatewayImpl implements DeviceGateway {
     }
 
     @Override
-    public WcTimesQueryRes getWcTimes(Long clientId, String time) {
+    public WcTimesQueryRes getWcTimes(Long devId, String time) {
 
         LocalDate inputDate = LocalDate.parse(time);
         LocalDate tomorrow = inputDate.plusDays(1);
-        List<AlarmEvent> list = alarmEventService.list(new LambdaQueryWrapper<AlarmEvent>().eq(AlarmEvent::getClientId, clientId).ge(AlarmEvent::getCreateTime, inputDate).lt(AlarmEvent::getCreateTime, tomorrow));
+        List<AlarmEvent> list = alarmEventService.list(new LambdaQueryWrapper<AlarmEvent>().eq(AlarmEvent::getDevId, devId).ge(AlarmEvent::getCreateTime, inputDate).lt(AlarmEvent::getCreateTime, tomorrow));
         WcTimesQueryRes res = new WcTimesQueryRes();
         if (CollectionUtils.isEmpty(list)) {
 

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

@@ -136,7 +136,7 @@ public class WebGatewayImpl implements WebGateway {
             queryReq.setPageSize(10);
         }
 
-        // 执行分页查询,根据tenantId是否为空来选择不同的查询方法
+        // 执行分页查询
         Long tenantId =  (Long) StpUtil.getSession().get(UserConstants.SA_USER_TENANT_ID);
         Page<DevInfo> devInfoPage = devInfoService.queryDevList(queryReq, tenantId);
         // 换为目标DTO

+ 98 - 8
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/gateway/impl/WebStatsGatewayImpl.java

@@ -1,14 +1,30 @@
 package com.hfln.portal.infrastructure.gateway.impl;
 
-import com.hfln.portal.common.dto.data.pub.DicItemDto;
+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.dto.data.event.EventListDTO;
+import com.hfln.portal.common.dto.data.event.StayTimeDTO;
+import com.hfln.portal.common.request.event.AlarmEventParams;
+import com.hfln.portal.common.request.event.EventListParams;
+import com.hfln.portal.common.request.event.StayTimeParams;
+import com.hfln.portal.common.vo.PageRecord;
+import com.hfln.portal.domain.customer.AdminUserType;
 import com.hfln.portal.domain.customer.util.CopyUtils;
 import com.hfln.portal.domain.gateway.WebStatsGateway;
-import com.hfln.portal.infrastructure.service.OssFileService;
-import com.hfln.portal.infrastructure.service.TblDicItemService;
+import com.hfln.portal.infrastructure.po.AlarmEvent;
+import com.hfln.portal.infrastructure.po.EventList;
+import com.hfln.portal.infrastructure.po.StayTime;
+import com.hfln.portal.infrastructure.service.AlarmEventService;
+import com.hfln.portal.infrastructure.service.DevInfoService;
+import com.hfln.portal.infrastructure.service.EventService;
+import com.hfln.portal.infrastructure.service.StayTimeService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.List;
 
 @Slf4j
@@ -17,17 +33,91 @@ public class WebStatsGatewayImpl implements WebStatsGateway {
 
 
     @Autowired
-    private TblDicItemService tblDicItemService;
+    private DevInfoService devInfoService;
 
+    @Autowired
+    private EventService eventService;
 
     @Autowired
-    private OssFileService ossFileService;
+    private StayTimeService stayTimeService;
 
+    @Autowired
+    private AlarmEventService alarmEventService;
 
     @Override
-    public List<DicItemDto> query(String dicType) {
-        return CopyUtils.copyList(tblDicItemService.queryByDicType(dicType), DicItemDto.class);
+    public PageRecord<EventListDTO> fallQuery(EventListParams params) {
+        Long tenantId =  (Long) StpUtil.getSession().get(UserConstants.SA_USER_TENANT_ID);
+        String userType =  (String) StpUtil.getSession().get(UserConstants.SA_USER_TYPE);
+
+        if (AdminUserType.getBgManagerTypes().contains(userType)){
+            tenantId = params.getTenantId();
+        }
+
+        List<Long> devIdList = new ArrayList<>();
+        //根据租户id查询devId集合
+        if(tenantId != null && tenantId != 0){
+           devIdList =  devInfoService.queryByTenantId(tenantId);
+        }
+        // 如果tenantId为0或null,则不添加设备ID查询条件,查询所有事件(超管权限)
+
+        //调用返回Page<EventList>
+        Page<EventList> page = eventService.queryEventList(params, devIdList);
+
+        //转化为DTO
+        List<EventListDTO> dtoList = CopyUtils.copyList(page.getRecords(), EventListDTO.class);
+
+        // 封装成 PageRecord 返回
+        return CopyUtils.copyPage(page, dtoList);
     }
 
-}
 
+
+    @Override
+    public PageRecord<StayTimeDTO> generalRetentionQuery(StayTimeParams params) {
+        Long tenantId =  (Long) StpUtil.getSession().get(UserConstants.SA_USER_TENANT_ID);
+        String userType =  (String) StpUtil.getSession().get(UserConstants.SA_USER_TYPE);
+
+        if (AdminUserType.getBgManagerTypes().contains(userType)){
+            tenantId = params.getTenantId();
+        }
+
+        List<Long> devIdList = new ArrayList<>();
+        //根据租户id查询devId集合
+        if(tenantId != null && tenantId != 0){
+            devIdList =  devInfoService.queryByTenantId(tenantId);
+        }
+
+        Page<StayTime> page = stayTimeService.queryStayTime(params, devIdList);
+
+        //转化为DTO
+        List<StayTimeDTO> dtoList = CopyUtils.copyList(page.getRecords(), StayTimeDTO.class);
+
+        // 封装成 PageRecord 返回
+        return CopyUtils.copyPage(page, dtoList);
+    }
+
+    @Override
+    public PageRecord<AlarmEventDTO> alarmRetentionQuery(AlarmEventParams params) {
+        Long tenantId =  (Long) StpUtil.getSession().get(UserConstants.SA_USER_TENANT_ID);
+        String userType =  (String) StpUtil.getSession().get(UserConstants.SA_USER_TYPE);
+
+        if (AdminUserType.getBgManagerTypes().contains(userType)){
+            tenantId = params.getTenantId();
+        }
+
+        List<Long> devIdList = new ArrayList<>();
+        //根据租户id查询devId集合
+        if(tenantId != null && tenantId != 0){
+            devIdList =  devInfoService.queryByTenantId(tenantId);
+        }
+
+        Page<AlarmEvent> page = alarmEventService.queryAlarmEvent(params, devIdList);
+
+        //转化为DTO
+        List<AlarmEventDTO> dtoList = CopyUtils.copyList(page.getRecords(), AlarmEventDTO.class);
+
+        // 封装成 PageRecord 返回
+        return CopyUtils.copyPage(page, dtoList);
+    }
+}
+ 

+ 11 - 10
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/mqtt/MqttSubHandle.java

@@ -165,17 +165,18 @@ public class MqttSubHandle {
         //  存储跌倒事件
         if (messageType == 3) {
 
-            event = obj.getString("event");
-            if (event.equals("fall_confirmed")) {
-                EventList eventListVO = new EventList();
-                eventListVO.setDevId(dev.getDevId());
-                eventListVO.setPose(pose);
-                eventListVO.setIsHandle(0);
-                eventListVO.setTargetPoints(targetPointsStr);
-                eventListVO.setEventType(messageType);
-                eventService.save(eventListVO);
+                event = obj.getString("event");
+                if (event.equals("fall_confirmed")) {
+                    EventList eventListVO = new EventList();
+                    eventListVO.setDevId(dev.getDevId());
+                    eventListVO.setPose((int)pose);
+                    eventListVO.setIsHandle(0);
+                    eventListVO.setTargetPoints(targetPointsStr);
+                    eventListVO.setEventType((int)messageType);
+                    eventService.save(eventListVO);
+                }
             }
-        }
+
 //        if (!targetPointsStr.equals(dev.getTargetPoints())) {
 //        } else {
 //            log.info("此次targetPoints与上次相同!");

+ 3 - 3
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/po/AlarmEvent.java

@@ -11,7 +11,7 @@ import lombok.EqualsAndHashCode;
  */
 @Data
 @EqualsAndHashCode(callSuper = true)
-@TableName("AlarmEvent")
+@TableName("alarm_event")
 public class AlarmEvent extends BasePO {
     /**
      * 主键ID
@@ -20,9 +20,9 @@ public class AlarmEvent extends BasePO {
     private Long alarmEventId;
 
     /**
-     * 设备ID
+     * 设备表主键ID
      */
-    private Long clientId;
+    private Long devId;
 
     /**
      * 滞留时间表主键id

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

@@ -198,6 +198,12 @@ public class DevInfo extends BasePO {
      */
     @TableField("active_time")
     private LocalDateTime activeTime;
+
+    /**
+     * 跌倒确认时间
+     */
+    @TableField("falling_confirm")
+    private BigDecimal fallingConfirm;
     /**
      * 设备信息常量类
      */

+ 3 - 3
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/po/EventList.java

@@ -22,14 +22,14 @@ public class EventList extends BasePO {
     private Long eventListId;
 
     /**
-     * dev_info ID
+     * 设备表主键id
      */
     private Long devId;
 
     /**
      * 姿态
      */
-    private Byte pose;
+    private Integer pose;
 
     /**
      * target数组
@@ -39,7 +39,7 @@ public class EventList extends BasePO {
     /**
      * 事件类型
      */
-    private Byte eventType;
+    private Integer eventType;
 
     /**
      * 是否处理:0-未处理,1-已处理

+ 5 - 1
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/service/AlarmEventService.java

@@ -1,9 +1,13 @@
 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.request.event.AlarmEventParams;
 import com.hfln.portal.infrastructure.po.AlarmEvent;
 
-public interface AlarmEventService extends IService<AlarmEvent> {
+import java.util.List;
 
+public interface AlarmEventService extends IService<AlarmEvent> {
 
+        Page<AlarmEvent> queryAlarmEvent(AlarmEventParams params, List<Long> devIdList);
 }

+ 1 - 0
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/service/DevInfoService.java

@@ -27,4 +27,5 @@ public interface DevInfoService extends IService<DevInfo> {
 
     DevInfo queryOneByClientId(String clientId);
 
+    List<Long> queryByTenantId(Long tenantId);
 }

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

@@ -2,12 +2,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.request.event.EventListParams;
 import com.hfln.portal.infrastructure.po.EventList;
 
-import java.util.Date;
+import java.util.List;
 
 public interface EventService extends IService<EventList> {
 
-    Page<EventList> queryEventListByDevId(String devId, Date start, Date end, Integer pageNo, Integer pageSize);
-
+    Page<EventList> queryEventList(EventListParams params, List<Long> devIdList);
 }

+ 26 - 2
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/service/impl/AlarmEventServiceImpl.java

@@ -3,16 +3,40 @@ package com.hfln.portal.infrastructure.service.impl;
 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.request.event.AlarmEventParams;
 import com.hfln.portal.infrastructure.mapper.AlarmEventMapper;
 import com.hfln.portal.infrastructure.po.AlarmEvent;
-import com.hfln.portal.infrastructure.po.EventList;
 import com.hfln.portal.infrastructure.service.AlarmEventService;
 import org.springframework.stereotype.Service;
 
-import java.util.Date;
+import java.util.List;
 import java.util.Objects;
 
 @Service
 public class AlarmEventServiceImpl extends ServiceImpl<AlarmEventMapper, AlarmEvent> implements AlarmEventService {
 
+
+    @Override
+    public Page<AlarmEvent> queryAlarmEvent(AlarmEventParams params, List<Long> devIdList) {
+        Page<AlarmEvent> page = new Page<>(params.getPageNo(), params.getPageSize());
+
+        // 2. 构建查询条件
+        LambdaQueryWrapper<AlarmEvent> queryWrapper = new LambdaQueryWrapper<>();
+        if (devIdList != null && !devIdList.isEmpty()){
+            queryWrapper.in(AlarmEvent::getDevId, devIdList);
+        }
+        // 如果devIdList为空,则不添加设备ID查询条件,查询所有事件
+
+        // 3. 添加日期条件
+        if (Objects.nonNull(params.getCreateTimeStart())) {
+            queryWrapper.ge(AlarmEvent::getCreateTime, params.getCreateTimeStart());
+        }
+        if (Objects.nonNull(params.getCreateTimeEnd())) {
+            queryWrapper.le(AlarmEvent::getCreateTime, params.getCreateTimeEnd());
+        }
+
+        // 4. 设置排序
+        queryWrapper.orderByDesc(AlarmEvent::getCreateTime);
+        return this.baseMapper.selectPage(page, queryWrapper);
+    }
 }

+ 14 - 0
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/service/impl/DevInfoServiceImpl.java

@@ -116,6 +116,7 @@ public class DevInfoServiceImpl extends ServiceImpl<DevInfoMapper, DevInfo> impl
                 .setIfNotNull(DevInfo::getYyEnd, request.getYyEnd())
                 .setIfNotNull(DevInfo::getZzStart, request.getZzStart())
                 .setIfNotNull(DevInfo::getZzEnd, request.getZzEnd())
+                .setIfNotNull(DevInfo::getFallingConfirm, 53)
                 // 无条件更新的字段
                 .set(DevInfo::getUpdateTime, LocalDateTime.now())
                 .set(DevInfo::getOnline, 1);
@@ -207,4 +208,17 @@ public class DevInfoServiceImpl extends ServiceImpl<DevInfoMapper, DevInfo> impl
         return this.baseMapper.selectOne(wrapper);
     }
 
+    @Override
+    public List<Long> queryByTenantId(Long tenantId){
+        LambdaQueryWrapper<DevInfo> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(DevInfo::getTenantId, tenantId)
+                .select(DevInfo::getDevId);
+
+        List<DevInfo> list = this.list(wrapper);
+
+        return list.stream().map(DevInfo::getDevId).collect(Collectors.toList());
+
+    }
+
+
 }

+ 12 - 8
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/service/impl/EventServiceImpl.java

@@ -3,30 +3,34 @@ package com.hfln.portal.infrastructure.service.impl;
 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.request.event.EventListParams;
 import com.hfln.portal.infrastructure.mapper.EventListMapper;
 import com.hfln.portal.infrastructure.po.EventList;
 import com.hfln.portal.infrastructure.service.EventService;
 import org.springframework.stereotype.Service;
 
-import java.util.Date;
+import java.util.List;
 import java.util.Objects;
 
 @Service
 public class EventServiceImpl extends ServiceImpl<EventListMapper, EventList> implements EventService {
     @Override
-    public Page<EventList> queryEventListByDevId(String devId, Date start, Date end, Integer pageNo, Integer pageSize) {
-        Page<EventList> page = new Page<>(pageNo, pageSize);
+    public Page<EventList> queryEventList(EventListParams params, List<Long> devIdList) {
+        Page<EventList> page = new Page<>(params.getPageNo(), params.getPageSize());
 
         // 2. 构建查询条件
         LambdaQueryWrapper<EventList> queryWrapper = new LambdaQueryWrapper<>();
-        queryWrapper.eq(EventList::getDevId, devId).eq(EventList::getEventType, 3);
+        if (devIdList != null && !devIdList.isEmpty()){
+            queryWrapper.in(EventList::getDevId, devIdList);
+        }
+        // 如果devIdList为空,则不添加设备ID查询条件,查询所有事件
 
         // 3. 添加日期条件
-        if (Objects.nonNull(start)) {
-            queryWrapper.ge(EventList::getCreateTime, start);
+        if (Objects.nonNull(params.getCreateTimeStart())) {
+            queryWrapper.ge(EventList::getCreateTime, params.getCreateTimeStart());
         }
-        if (Objects.nonNull(end)) {
-            queryWrapper.le(EventList::getCreateTime, end);
+        if (Objects.nonNull(params.getCreateTimeEnd())) {
+            queryWrapper.le(EventList::getCreateTime, params.getCreateTimeEnd());
         }
 
         // 4. 设置排序