Jelajahi Sumber

feat: 合并ServiceActivator相关的业务处理

yangliu 4 bulan lalu
induk
melakukan
dfe51e191f
57 mengubah file dengan 1879 tambahan dan 5464 penghapusan
  1. 0 27
      device-service-application/src/main/java/com/hfln/device/application/controller/TestController.java
  2. 0 17
      device-service-application/src/main/java/com/hfln/device/application/controller/web/Test.java
  3. 0 27
      device-service-application/src/main/java/com/hfln/device/application/facade/DingFacadeImpl.java
  4. 4 4
      device-service-application/src/main/java/com/hfln/device/application/service/impl/DeviceCommandServiceImpl.java
  5. 0 30
      device-service-client-starter/src/main/java/com/hfln/device/client/api/fallback/DingFacadeFeignFallbackFactory.java
  6. 0 83
      device-service-client-starter/src/main/java/com/hfln/device/client/api/fallback/StationFacadeFeignFallbackFactory.java
  7. 0 187
      device-service-client-starter/src/main/java/com/hfln/device/client/api/fallback/UserFacadeFeignFallbackFactory.java
  8. 0 13
      device-service-common/src/main/java/com/hfln/device/common/request/TestRequest.java
  9. 0 240
      device-service-domain/src/main/java/com/hfln/device/domain/service/DeviceConfigService.java
  10. 2 1
      device-service-domain/src/main/java/com/hfln/device/domain/service/impl/AlarmServiceImpl.java
  11. 2 7
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/config/MqttConfig.java
  12. 410 262
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/gateway/MqttGatewayImpl.java
  13. 0 498
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/gateway/impl/DeviceGatewayImpl.java.bak
  14. 0 762
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/gateway/impl/MqttGatewayDefaultImpl.java
  15. 0 17
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mapper/ClientUserMapper.java
  16. 0 12
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mapper/DevRoomMapper.java
  17. 0 12
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mapper/DevTargetMapper.java
  18. 0 12
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mapper/GroupFloorplanMapper.java
  19. 0 12
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mapper/RecordPlanMapper.java
  20. 0 12
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mapper/RecordPlanTimeMapper.java
  21. 0 12
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mapper/StatInfoMapper.java
  22. 0 12
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mapper/TblMenuMapper.java
  23. 0 12
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mapper/TblOprLogMapper.java
  24. 0 12
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mapper/TblOrgMapper.java
  25. 0 12
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mapper/TblParameterMapper.java
  26. 0 12
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mapper/TblRoleMapper.java
  27. 0 12
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mapper/TblUserRoleMapper.java
  28. 0 12
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mapper/TblWxpaycertMapper.java
  29. 0 362
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mqtt/MqttGatewayEmqxImpl.java
  30. 8 3
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mqtt/MqttHandlerImpl.java
  31. 0 496
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mqtt/MqttMessageHandler.java
  32. 0 299
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mqtt/MqttSubscriberHandler.java
  33. 312 30
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mqtt/handler/AppMessageHandler.java
  34. 400 21
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mqtt/handler/DeviceMessageHandler.java
  35. 434 12
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mqtt/handler/MpsMessageHandler.java
  36. 307 27
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mqtt/handler/OpcMessageHandler.java
  37. 0 222
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mqtt/subscriber/AppMessageSubscriber.java
  38. 0 49
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mqtt/subscriber/BehaviorAnalysisSubscriber.java
  39. 0 50
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mqtt/subscriber/DasMessageSubscriber.java
  40. 0 414
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mqtt/subscriber/DeviceMessageSubscriber.java
  41. 0 287
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mqtt/subscriber/MpsMessageSubscriber.java
  42. 0 159
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mqtt/subscriber/OpcMessageSubscriber.java
  43. 0 33
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/po/DevRoom.java
  44. 0 59
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/po/DevTarget.java
  45. 0 30
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/po/GroupFloorPlan.java
  46. 0 56
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/po/RecordPlan.java
  47. 0 50
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/po/RecordPlanTime.java
  48. 0 51
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/po/StatInfo.java
  49. 0 42
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/po/TblDicItem.java
  50. 0 50
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/po/TblMenu.java
  51. 0 51
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/po/TblOprLog.java
  52. 0 46
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/po/TblOrg.java
  53. 0 40
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/po/TblParameter.java
  54. 0 35
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/po/TblRole.java
  55. 0 29
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/po/TblUserRole.java
  56. 0 47
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/po/TblWxpaycert.java
  57. 0 83
      device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/service/impl/MenuServiceImpl.java

+ 0 - 27
device-service-application/src/main/java/com/hfln/device/application/controller/TestController.java

@@ -1,27 +0,0 @@
-//package com.hfln.device.application.controller;
-//
-//
-//import cn.hfln.framework.mqtt.annotation.MqttSubscribe;
-//import cn.hfln.framework.mqtt.template.MqttTemplate;
-//import cn.hfln.framework.catchlog.CatchAndLog;
-//import cn.hfln.framework.dto.ApiResult;
-//import lombok.extern.slf4j.Slf4j;
-//import org.springframework.beans.factory.annotation.Autowired;
-//import org.springframework.web.bind.annotation.GetMapping;
-//import org.springframework.web.bind.annotation.RestController;
-//
-//@RestController
-//@Slf4j
-//@CatchAndLog
-//public class TestController {
-//
-//    @Autowired
-//    private MqttTemplate mqttTemplate;
-//
-//    @GetMapping("/demo")
-//    public ApiResult<Boolean> get() {
-//        String topic = "my/1/topic";
-//        mqttTemplate.send(topic,"test message");
-//        return ApiResult.success(true);
-//    }
-//}

+ 0 - 17
device-service-application/src/main/java/com/hfln/device/application/controller/web/Test.java

@@ -1,17 +0,0 @@
-//package com.hfln.device.application.controller.web;
-//
-//import cn.hfln.framework.mqtt.annotation.MqttSubscribe;
-//import lombok.extern.slf4j.Slf4j;
-//import org.springframework.stereotype.Component;
-//
-///**
-// * 测试MQTT消息订阅
-// */
-//@Component
-//@Slf4j
-//public class Test {
-//    @MqttSubscribe(topic = "my/+/topic")
-//    public void listen(String msg) {
-//        log.info("{}----------------------------------------", msg);
-//    }
-//}

+ 0 - 27
device-service-application/src/main/java/com/hfln/device/application/facade/DingFacadeImpl.java

@@ -1,27 +0,0 @@
-//package com.hfln.device.application.facade;
-//
-//import cn.hfln.framework.catchlog.CatchAndLog;
-//import cn.hfln.framework.dto.ApiResult;
-//import com.hfln.device.common.facade.DingFacade;
-//import com.hfln.device.common.request.user.DingUserSyncReq;
-//import com.hfln.device.domain.gateway.UserGateway;
-//import org.springframework.web.bind.annotation.RestController;
-//
-//import javax.annotation.Resource;
-//
-///**
-// * @Author: huangls
-// * @CreateTime: 2023-11-29
-// */
-//@CatchAndLog
-//@RestController
-//public class DingFacadeImpl implements DingFacade {
-//
-//    @Resource
-//    private UserGateway userGateway;
-//
-//    @Override
-//    public ApiResult<Boolean> syncDingUserInfo(DingUserSyncReq reqs) {
-//        return ApiResult.success(userGateway.syncDingUserInfo(reqs));
-//    }
-//}

+ 4 - 4
device-service-application/src/main/java/com/hfln/device/application/service/impl/DeviceCommandServiceImpl.java

@@ -49,7 +49,7 @@ public class DeviceCommandServiceImpl implements DeviceCommandService {
     public void handleGetDeviceInfo(String deviceId) {
         log.info("Handling get device info request for device: {}", deviceId);
         // 向设备发送获取信息请求
-        String topic = String.format("/dev/%s/get_device_info", deviceId);
+        String topic = String.format(MqttTopics.DEV_REP_DEV_INFO.replace("+", "%s"), deviceId);
         Device device = new Device();
         device.setDevId(deviceId);
         mqttGateway.sendDeviceStatusMessage(device);
@@ -187,7 +187,7 @@ public class DeviceCommandServiceImpl implements DeviceCommandService {
         String message = (String) responseData.get("message");
         
         // 使用MqttGateway发送绑定响应消息
-        String topic = "/das/bind_device/response";
+        String topic = MqttTopics.DAS_BIND_DEVICE_RESPONSE;
         
         Map<String, Object> payload = new HashMap<>();
         payload.put("deviceId", deviceId);
@@ -208,7 +208,7 @@ public class DeviceCommandServiceImpl implements DeviceCommandService {
         String message = (String) responseData.get("message");
         
         // 使用MqttGateway发送解绑响应消息
-        String topic = "/das/unbind_device/response";
+        String topic = MqttTopics.DAS_UNBIND_DEVICE_RESPONSE;
         
         Map<String, Object> payload = new HashMap<>();
         payload.put("deviceId", deviceId);
@@ -233,7 +233,7 @@ public class DeviceCommandServiceImpl implements DeviceCommandService {
         // 通过MQTT发送告警参数
         Map<String, Object> response = new HashMap<>();
         response.put("global", alarmParams);
-        String topic = "/das/report_alarm_param";
+        String topic = MqttTopics.DAS_REPORT_ALARM_PARAM;
 
         mqttGateway.sendToMqtt(topic, response.toString());
 

+ 0 - 30
device-service-client-starter/src/main/java/com/hfln/device/client/api/fallback/DingFacadeFeignFallbackFactory.java

@@ -1,30 +0,0 @@
-//package com.hfln.device.client.api.fallback;
-//
-//import cn.hfln.framework.dto.ApiResult;
-//import com.hfln.device.client.api.feign.DingFacadeFeign;
-//import feign.hystrix.FallbackFactory;
-//import lombok.extern.slf4j.Slf4j;
-//import org.springframework.stereotype.Component;
-//
-///**
-// * DingFacadeFeignFallbackFactory
-// *
-// * @author cw
-// * @date 2024/6/19 17:43
-// */
-//@Component
-//@Slf4j
-//public class DingFacadeFeignFallbackFactory implements FallbackFactory<DingFacadeFeign> {
-//    @Override
-//    public DingFacadeFeign create(Throwable cause) {
-//        log.error("UserFacadeFeignFallbackFactory error", cause);
-//        return new DingFacadeFeign() {
-//            @Override
-//            public ApiResult<Boolean> syncDingUserInfo(DingUserSyncReq reqs) {
-//                return ApiResult.failed("鍚屾閽夐拤鐢ㄦ埛淇℃伅澶辫触");
-//            }
-//        };
-//    }
-//}
-
-

+ 0 - 83
device-service-client-starter/src/main/java/com/hfln/device/client/api/fallback/StationFacadeFeignFallbackFactory.java

@@ -1,83 +0,0 @@
-//package com.hfln.device.client.api.fallback;
-//
-//import cn.wideth.framework.dto.ApiResult;
-//import com.hfln.device.client.api.feign.StationFacadeFeign;
-//import com.hfln.device.common.request.station.StationListReq;
-//import com.hfln.device.common.request.station.StationOpReq;
-//import com.hfln.device.common.vo.StationVO;
-//import feign.hystrix.FallbackFactory;
-//import lombok.extern.slf4j.Slf4j;
-//import org.springframework.stereotype.Component;
-//
-//import java.math.BigDecimal;
-//import java.util.ArrayList;
-//import java.util.List;
-//
-///**
-// * StationFacadeFeignFallbackFactory
-// *
-// * @author cw
-// * @date 2024/6/20 9:06
-// */
-//@Component
-//@Slf4j
-//public class StationFacadeFeignFallbackFactory implements FallbackFactory<StationFacadeFeign> {
-//    @Override
-//    public StationFacadeFeign create(Throwable throwable) {
-//        log.error("StationFacadeFeignFallbackFactory error", throwable);
-//
-//        return new StationFacadeFeign() {
-//            @Override
-//            public ApiResult<Boolean> addStation(StationOpReq req) {
-//                return ApiResult.failed("娣诲姞澶辫触");
-//            }
-//
-//            @Override
-//            public ApiResult<StationVO> getStationById(Long id) {
-//                return ApiResult.success();
-//            }
-//
-//            @Override
-//            public ApiResult<Boolean> updateStation(Long id, StationOpReq req) {
-//                return ApiResult.failed("淇敼澶辫触");
-//            }
-//
-//            @Override
-//            public ApiResult<Boolean> deleteStation(Long id) {
-//                return ApiResult.failed();
-//            }
-//
-//            @Override
-//            public ApiResult<Boolean> batchDelStation(List<Long> ids) {
-//                return ApiResult.failed();
-//            }
-//
-//            @Override
-//            public ApiResult<List<StationVO>> listStationByIds(List<Long> ids) {
-//                return ApiResult.success(new ArrayList<>());
-//            }
-//
-//            @Override
-//            public ApiResult<List<StationVO>> listStation(StationListReq req) {
-//                return ApiResult.success(new ArrayList<>());
-//            }
-//
-//            @Override
-//            public ApiResult<Boolean> updateStationStatus(Long id, String status) {
-//                return ApiResult.failed();
-//            }
-//
-//            @Override
-//            public ApiResult<Boolean> updateStationDutyScope(Long id, BigDecimal dutyScope) {
-//                return ApiResult.failed();
-//            }
-//
-//            @Override
-//            public ApiResult<Boolean> checkStationNameRepeat(Long id, String name) {
-//                return ApiResult.success(false);
-//            }
-//        };
-//    }
-//}
-
-

+ 0 - 187
device-service-client-starter/src/main/java/com/hfln/device/client/api/fallback/UserFacadeFeignFallbackFactory.java

@@ -1,187 +0,0 @@
-//package com.hfln.device.client.api.fallback;
-//
-//import cn.wideth.framework.dto.ApiResult;
-//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-//import com.hfln.device.client.api.feign.UserFacadeFeign;
-//import com.hfln.device.common.request.user.*;
-//import com.hfln.device.common.vo.*;
-//import feign.hystrix.FallbackFactory;
-//import lombok.extern.slf4j.Slf4j;
-//import org.springframework.stereotype.Component;
-//
-//import java.util.ArrayList;
-//import java.util.List;
-//
-///**
-// * UserFacadeFeignFallbackFactory
-// *
-// * @author cw
-// * @date 2024/6/19 17:45
-// */
-//@Component
-//@Slf4j
-//public class UserFacadeFeignFallbackFactory implements FallbackFactory<UserFacadeFeign> {
-//    @Override
-//    public UserFacadeFeign create(Throwable cause) {
-//        log.error("UserFacadeFeignFallbackFactory error", cause);
-//        return new UserFacadeFeign() {
-//
-//            @Override
-//            public ApiResult<UserVO> getUserByUserId(Long userId) {
-//                return ApiResult.success(new UserVO());
-//            }
-//
-//            @Override
-//            public ApiResult<UserVO> getUserByUserName(String userName) {
-//                return ApiResult.failed(cause.getMessage());
-//            }
-//
-//            @Override
-//            public ApiResult<Boolean> add(UserAddReq req) {
-//                return ApiResult.failed(cause.getMessage());
-//            }
-//
-//            @Override
-//            public ApiResult<Long> addUserReturnId(UserAddReq req) {
-//                return ApiResult.failed(cause.getMessage());
-//            }
-//
-//            @Override
-//            public ApiResult<Boolean> update(UserUpdateReq req) {
-//                return ApiResult.failed(cause.getMessage());
-//            }
-//
-//            @Override
-//            public ApiResult<Boolean> delete(Long userId) {
-//                return ApiResult.failed(cause.getMessage());
-//            }
-//
-//            @Override
-//            public ApiResult<Boolean> batchDel(List<Long> userIds) {
-//                return ApiResult.failed(cause.getMessage());
-//            }
-//
-//            @Override
-//            public ApiResult<Boolean> updateUserStatus(Long userId, String status) {
-//                return ApiResult.failed(cause.getMessage());
-//            }
-//
-//            @Override
-//            public ApiResult<List<UserBaseInfoVO>> listByOrgId(Long orgId, String realName) {
-//                return ApiResult.failed(cause.getMessage());
-//            }
-//
-//            @Override
-//            public ApiResult<Boolean> updateOnlineStatus(Long userId, String onlineStatus) {
-//                return ApiResult.failed(cause.getMessage());
-//            }
-//
-//            @Override
-//            public ApiResult<List<UserBaseInfoVO>> listByStation(Long userId, Long stationId) {
-//                return ApiResult.failed(cause.getMessage());
-//            }
-//
-//            @Override
-//            public ApiResult<List<UserVO>> listByUserIds(List<Long> userIds) {
-//                return ApiResult.failed(cause.getMessage());
-//            }
-//
-//            @Override
-//            public ApiResult<Boolean> updatePwd(UserUpdatePwdReq req) {
-//                return ApiResult.failed(cause.getMessage());
-//            }
-//
-//            @Override
-//            public ApiResult<Boolean> updateOtherPwd(UserUpdateOtherPwdReq req) {
-//                return ApiResult.failed(cause.getMessage());
-//            }
-//
-//            @Override
-//            public ApiResult<Page<UserPageVO>> page(UserPageReq req) {
-//                return ApiResult.failed(cause.getMessage());
-//            }
-//
-//            @Override
-//            public ApiResult<List<UserPageVO>> list(UserListReq req) {
-//                return ApiResult.failed(cause.getMessage());
-//            }
-//
-//            @Override
-//            public ApiResult<List<UserPageVO>> listByUserTypes(UserListByTypesReq req) {
-//                return ApiResult.failed(cause.getMessage());
-//            }
-//
-//            @Override
-//            public ApiResult<List<UserPageVO>> listDriverAndDoc(UserListReq req) {
-//                return ApiResult.failed(cause.getMessage());
-//            }
-//
-//            @Override
-//            public ApiResult<List<UserPageVO>> listDispatcher(UserListReq req) {
-//                return ApiResult.failed(cause.getMessage());
-//            }
-//
-//            @Override
-//            public ApiResult<List<UserPageVO>> listAllDispatcher(UserListReq req) {
-//                return ApiResult.failed(cause.getMessage());
-//            }
-//
-//            @Override
-//            public ApiResult<Boolean> updateUseStatusBatch(UserUpdateUseStatusReq req) {
-//                return ApiResult.failed(cause.getMessage());
-//            }
-//
-//            @Override
-//            public ApiResult<List<UserBaseInfoVO>> listIdleUser(ListIdleUserReq req) {
-//                return ApiResult.failed(cause.getMessage());
-//            }
-//
-//            @Override
-//            public ApiResult<List<UserBaseInfoVO>> listDisPatcherByUserTypes(ListIdleUserReq req) {
-//                return ApiResult.failed(cause.getMessage());
-//            }
-//
-//            @Override
-//            public ApiResult<Page<ClientUserVO>> pageClientUser(ClientUserQueryReq req) {
-//                return ApiResult.failed(cause.getMessage());
-//            }
-//
-//            @Override
-//            public ApiResult<List<ClientUserVO>> listClientUser(ClientUserQueryReq req) {
-//                return ApiResult.failed(cause.getMessage());
-//            }
-//
-//            @Override
-//            public ApiResult<ClientUserVO> getClientUserVO(Long userId) {
-//                return ApiResult.failed(cause.getMessage());
-//            }
-//
-//            @Override
-//            public ApiResult<ClientUserVO> getClientUserByPhoneNumber(String phone) {
-//                return ApiResult.failed(cause.getMessage());
-//            }
-//
-//            @Override
-//            public ApiResult<String> updateClientUserInfo(ClientUserUpdateReq updateReq) {
-//                return ApiResult.failed(cause.getMessage());
-//            }
-//
-//            @Override
-//            public ApiResult<Boolean> hasSitNumber(String sitNumber) {
-//                return ApiResult.failed(cause.getMessage());
-//            }
-//
-//            @Override
-//            public ApiResult<List<ClientUserVO>> getWechatUserByUserIds(List<Long> userIds) {
-//                return ApiResult.success(new ArrayList<>());
-//            }
-//
-//            @Override
-//            public ApiResult<List<CommonStatisticsVO>> userStatistics(Long orgId) {
-//                return ApiResult.success(new ArrayList<>());
-//            }
-//        };
-//    }
-//}
-
-

+ 0 - 13
device-service-common/src/main/java/com/hfln/device/common/request/TestRequest.java

@@ -1,13 +0,0 @@
-package com.hfln.device.common.request;
-
-import lombok.Data;
-
-/**
- * @USER: YangLiu
- * @DATE: 2023/10/16 11:21
- * @DESC:
- */
-@Data
-public class TestRequest {
-    private Long id;
-}

+ 0 - 240
device-service-domain/src/main/java/com/hfln/device/domain/service/DeviceConfigService.java

@@ -1,240 +0,0 @@
-//package com.hfln.device.domain.service;
-//
-//import com.hfln.device.domain.entity.Device;
-//import com.hfln.device.domain.gateway.DeviceGateway;
-//import com.hfln.device.domain.gateway.MqttGateway;
-//import lombok.extern.slf4j.Slf4j;
-//import org.springframework.beans.factory.annotation.Autowired;
-//import org.springframework.stereotype.Service;
-//
-//import java.util.Map;
-//import java.util.Optional;
-//
-///**
-// * 设备配置服务
-// * 负责设备配置相关的领域逻辑
-// */
-//@Service
-//@Slf4j
-//public class DeviceConfigService {
-//
-//    @Autowired
-//    private DeviceManagerService deviceManagerService;
-//
-//    @Autowired
-//    private DeviceGateway deviceGateway;
-//
-//    @Autowired
-//    private MqttGateway mqttGateway;
-//
-//    /**
-//     * 更新设备网络配置
-//     *
-//     * @param deviceId 设备ID
-//     * @param networkInfo 网络信息
-//     * @return 是否更新成功
-//     */
-//    public boolean updateDeviceNetwork(String deviceId, Device.NetworkInfo networkInfo) {
-//        try {
-//            Optional<Device> deviceOpt = deviceManagerService.getDeviceFromCache(deviceId);
-//            if (!deviceOpt.isPresent()) {
-//                log.warn("Device not found: {}", deviceId);
-//                return false;
-//            }
-//
-//            Device device = deviceOpt.get();
-//
-//            // 更新网络配置
-//            device.setNetwork(networkInfo);
-//
-//            // 更新缓存
-//            deviceManagerService.updateDeviceInCache(device);
-//
-//            // 更新数据库
-//            deviceGateway.updateDeviceNetwork(deviceId, networkInfo);
-//
-//            // 发送配置更新通知
-//            mqttGateway.sendNetworkConfigUpdate(deviceId, networkInfo);
-//
-//            log.info("Device network updated: {}", deviceId);
-//            return true;
-//        } catch (Exception e) {
-//            log.error("Error updating device network: {}", e.getMessage(), e);
-//            return false;
-//        }
-//    }
-//
-//    /**
-//     * 更新设备安装参数
-//     *
-//     * @param deviceId 设备ID
-//     * @param installParam 安装参数
-//     * @return 是否更新成功
-//     */
-//    public boolean updateDeviceInstallParam(String deviceId, Device.InstallParam installParam) {
-//        try {
-//            Optional<Device> deviceOpt = deviceManagerService.getDeviceFromCache(deviceId);
-//            if (!deviceOpt.isPresent()) {
-//                log.warn("Device not found: {}", deviceId);
-//                return false;
-//            }
-//
-//            Device device = deviceOpt.get();
-//
-//            // 更新安装参数
-//            device.setInstallParam(installParam);
-//
-//            // 更新缓存
-//            deviceManagerService.updateDeviceInCache(device);
-//
-//            // 更新数据库
-//            deviceGateway.updateDeviceInstallParam(deviceId, installParam);
-//
-//            // 发送配置更新通知
-//            mqttGateway.sendInstallParamUpdate(deviceId, installParam);
-//
-//            log.info("Device install parameters updated: {}", deviceId);
-//            return true;
-//        } catch (Exception e) {
-//            log.error("Error updating device install parameters: {}", e.getMessage(), e);
-//            return false;
-//        }
-//    }
-//
-//    /**
-//     * 更新设备跟踪区域
-//     *
-//     * @param deviceId 设备ID
-//     * @param trackingRegion 跟踪区域
-//     * @return 是否更新成功
-//     */
-//    public boolean updateDeviceTrackingRegion(String deviceId, Device.TrackingRegion trackingRegion) {
-//        try {
-//            Optional<Device> deviceOpt = deviceManagerService.getDeviceFromCache(deviceId);
-//            if (!deviceOpt.isPresent()) {
-//                log.warn("Device not found: {}", deviceId);
-//                return false;
-//            }
-//
-//            Device device = deviceOpt.get();
-//            Device.InstallParam installParam = device.getInstallParam();
-//
-//            if (installParam == null) {
-//                installParam = Device.InstallParam.builder()
-//                        .mountPlain("Wall")
-//                        .isCeiling(0)
-//                        .height(0.0f)
-//                        .trackingRegion(trackingRegion)
-//                        .build();
-//            } else {
-//                // 更新跟踪区域
-//                installParam.setTrackingRegion(trackingRegion);
-//            }
-//
-//            // 设置更新后的安装参数
-//            device.setInstallParam(installParam);
-//
-//            // 更新缓存
-//            deviceManagerService.updateDeviceInCache(device);
-//
-//            // 更新数据库
-//            deviceGateway.updateDeviceInstallParam(deviceId, installParam);
-//
-//            // 发送配置更新通知
-//            mqttGateway.sendTrackingRegionUpdate(deviceId, trackingRegion);
-//
-//            log.info("Device tracking region updated: {}", deviceId);
-//            return true;
-//        } catch (Exception e) {
-//            log.error("Error updating device tracking region: {}", e.getMessage(), e);
-//            return false;
-//        }
-//    }
-//
-//    /**
-//     * 更新设备告警计划
-//     *
-//     * @param deviceId 设备ID
-//     * @param alarmSchedule 告警计划
-//     * @return 是否更新成功
-//     */
-//    public boolean updateDeviceAlarmSchedule(String deviceId, Map<String, Object> alarmSchedule) {
-//        try {
-//            Optional<Device> deviceOpt = deviceManagerService.getDeviceFromCache(deviceId);
-//            if (!deviceOpt.isPresent()) {
-//                log.warn("Device not found: {}", deviceId);
-//                return false;
-//            }
-//
-//            Device device = deviceOpt.get();
-//
-//            // 更新告警计划
-//            device.setAlarmSchedule(alarmSchedule);
-//
-//            // 更新缓存
-//            deviceManagerService.updateDeviceInCache(device);
-//
-//            // 更新数据库
-//            deviceGateway.updateDeviceAlarmSchedule(deviceId, alarmSchedule);
-//
-//            // 发送配置更新通知
-//            mqttGateway.sendAlarmScheduleUpdate(deviceId, alarmSchedule);
-//
-//            log.info("Device alarm schedule updated: {}", deviceId);
-//            return true;
-//        } catch (Exception e) {
-//            log.error("Error updating device alarm schedule: {}", e.getMessage(), e);
-//            return false;
-//        }
-//    }
-//
-//    /**
-//     * 重启设备
-//     *
-//     * @param deviceId 设备ID
-//     * @return 是否发送成功
-//     */
-//    public boolean restartDevice(String deviceId) {
-//        try {
-//            Optional<Device> deviceOpt = deviceManagerService.getDeviceFromCache(deviceId);
-//            if (!deviceOpt.isPresent() || deviceOpt.get().getOnline() != 1) {
-//                log.warn("Device not found or offline: {}", deviceId);
-//                return false;
-//            }
-//
-//            // 发送重启命令
-//            mqttGateway.sendDeviceCommand(deviceId, "restart", null);
-//
-//            log.info("Restart command sent to device: {}", deviceId);
-//            return true;
-//        } catch (Exception e) {
-//            log.error("Error sending restart command: {}", e.getMessage(), e);
-//            return false;
-//        }
-//    }
-//
-//    /**
-//     * 重置设备
-//     *
-//     * @param deviceId 设备ID
-//     * @return 是否发送成功
-//     */
-//    public boolean resetDevice(String deviceId) {
-//        try {
-//            Optional<Device> deviceOpt = deviceManagerService.getDeviceFromCache(deviceId);
-//            if (!deviceOpt.isPresent() || deviceOpt.get().getOnline() != 1) {
-//                log.warn("Device not found or offline: {}", deviceId);
-//                return false;
-//            }
-//
-//            // 发送重置命令
-//            mqttGateway.sendDeviceCommand(deviceId, "reset", null);
-//
-//            log.info("Reset command sent to device: {}", deviceId);
-//            return true;
-//        } catch (Exception e) {
-//            log.error("Error sending reset command: {}", e.getMessage(), e);
-//            return false;
-//        }
-//    }
-//}

+ 2 - 1
device-service-domain/src/main/java/com/hfln/device/domain/service/impl/AlarmServiceImpl.java

@@ -12,6 +12,7 @@ import com.hfln.device.domain.vo.BehaviorPattern;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import com.hfln.device.common.constant.mqtt.topic.MqttTopics;
 
 import java.util.*;
 
@@ -540,7 +541,7 @@ public class AlarmServiceImpl implements AlarmService {
             deviceManagerService.updateDeviceInCache(device);
             
             // 发送MQTT告警消息
-            String topic = "/das/alarm_event";
+            String topic = MqttTopics.DAS_ALARM_EVENT;
             mqttGateway.sendToMqtt(topic, JsonUtil.toJsonString(alarmData));
             
             // 保存告警记录到数据库

+ 2 - 7
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/config/MqttConfig.java

@@ -320,12 +320,7 @@ public class MqttConfig {
     }
     
     /**
-     * 指定主要使用的MQTT网关实现
-     * 使用重构后的MqttGatewayImpl作为主要实现
+     * 由于MqttGatewayImpl已设置@Primary注解,
+     * 无需额外配置,Spring会自动选择MqttGatewayImpl作为主要实现
      */
-    @Bean
-    @Primary
-    public MqttGateway primaryMqttGateway(MqttGateway mqttGatewayImpl) {
-        return mqttGatewayImpl;
-    }
 } 

+ 410 - 262
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/gateway/MqttGatewayImpl.java

@@ -2,11 +2,14 @@ package com.hfln.device.infrastructure.gateway;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.hfln.device.common.constant.mqtt.topic.MqttTopics;
+import com.hfln.device.domain.constant.DeviceConstants;
 import com.hfln.device.domain.entity.Device;
 import com.hfln.device.domain.gateway.MqttGateway;
 import lombok.extern.slf4j.Slf4j;
+import org.jetbrains.annotations.NotNull;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Primary;
 import org.springframework.integration.mqtt.outbound.MqttPahoMessageHandler;
 import org.springframework.integration.mqtt.support.MqttHeaders;
 import org.springframework.messaging.Message;
@@ -19,17 +22,16 @@ import java.util.Map;
 
 /**
  * MQTT网关实现类 - 基于Spring Integration MQTT
+ * 合并了原MqttGatewayDefaultImpl的优秀特性
  */
 @Component
+@Primary
 @Slf4j
 public class MqttGatewayImpl implements MqttGateway {
 
     @Autowired
     private MqttPahoMessageHandler mqttOutbound;
     
-    @Value("${mqtt.topic.prefix:hfln/device/}")
-    private String topicPrefix;
-    
     @Autowired
     private ObjectMapper objectMapper;
     
@@ -106,342 +108,460 @@ public class MqttGatewayImpl implements MqttGateway {
     
     @Override
     public void sendDeviceStatusMessage(Device device) {
-        String deviceId = device.getDevId();
-        String topic = topicPrefix + deviceId + "/status";
-        
-        Map<String, Object> payload = new HashMap<>();
-        payload.put("deviceId", deviceId);
-        payload.put("online", device.getOnline());
-        payload.put("timestamp", System.currentTimeMillis());
-        
-        publish(topic, payload);
-        log.debug("Device status message sent: {}", topic);
+        try {
+            Map<String, Object> payload = new HashMap<>();
+            payload.put("message", "notify");
+            payload.put("timestamp", System.currentTimeMillis());
+            payload.put("dev_id", device.getDevId());
+            payload.put("online", device.getOnline());
+            payload.put("dev_type", device.getDevType());
+            payload.put("software", device.getSoftware());
+            payload.put("hardware", device.getHardware());
+            
+            // 网络信息
+            Map<String, Object> network = new HashMap<>();
+            if (device.getNetwork() != null) {
+                network.put("ssid", device.getNetwork().getSsid());
+                network.put("password", device.getNetwork().getPassword());
+                network.put("ip", device.getNetwork().getIp());
+            }
+            payload.put("network", network);
+            
+            // 雷达参数
+            Map<String, Object> radarParam = new HashMap<>();
+            if (device.getInstallParam() != null) {
+                radarParam.put("mount_plain", device.getInstallParam().getMountPlain());
+                radarParam.put("height", device.getInstallParam().getHeight());
+                
+                // 跟踪区域
+                Map<String, Object> trackingRegion = getStringObjectMap(device.getInstallParam().getTrackingRegion());
+                radarParam.put("tracking_region", trackingRegion);
+            }
+            payload.put("radar_param", radarParam);
+            
+            sendMessage(MqttTopics.DAS_STATUS, payload);
+            log.debug("Device status message sent: {}", device.getDevId());
+        } catch (Exception e) {
+            log.error("Error sending device status message: {}", device.getDevId(), e);
+        }
+    }
+    
+    @NotNull
+    private static Map<String, Object> getStringObjectMap(Device.TrackingRegion trackingRegion) {
+        Map<String, Object> trackingRegionMap = new HashMap<>();
+        if (trackingRegion != null) {
+            trackingRegionMap.put("start_x", trackingRegion.getStartX());
+            trackingRegionMap.put("start_y", trackingRegion.getStartY());
+            trackingRegionMap.put("start_z", trackingRegion.getStartZ());
+            trackingRegionMap.put("stop_x", trackingRegion.getStopX());
+            trackingRegionMap.put("stop_y", trackingRegion.getStopY());
+            trackingRegionMap.put("stop_z", trackingRegion.getStopZ());
+        }
+        return trackingRegionMap;
     }
     
     @Override
     public void sendRealtimePoseMessage(String deviceId, int pose, Object targetPoint) {
-        String topic = topicPrefix + deviceId + "/pose";
-        
-        Map<String, Object> payload = new HashMap<>();
-        payload.put("deviceId", deviceId);
-        payload.put("pose", pose);
-        payload.put("targetPoint", targetPoint);
-        payload.put("timestamp", System.currentTimeMillis());
-        
-        publish(topic, payload);
-        log.debug("Real-time pose message sent: {}", topic);
+        try {
+            Map<String, Object> payload = new HashMap<>();
+            payload.put("message", "notify");
+            payload.put("message_type", DeviceConstants.MessageType.MSG_REALTIME_TARGET.getCode());
+            payload.put("timestamp", System.currentTimeMillis());
+            payload.put("dev_id", deviceId);
+            payload.put("pose", pose);
+            payload.put("target_point", targetPoint);
+            
+            sendMessage(MqttTopics.DAS_REALTIME_POS, payload);
+        } catch (Exception e) {
+            log.error("Error sending realtime pose message: {}", deviceId, e);
+        }
     }
     
     @Override
     public void sendAlarmMessage(String deviceId, String alarmType, Map<String, Object> data) {
-        String topic = topicPrefix + deviceId + "/alarm";
-        
-        Map<String, Object> payload = new HashMap<>(data);
-        payload.put("deviceId", deviceId);
-        payload.put("alarmType", alarmType);
-        payload.put("timestamp", System.currentTimeMillis());
-        
-        publish(topic, payload);
-        log.info("Alarm message sent: {}, type: {}", topic, alarmType);
+        try {
+            Map<String, Object> payload = new HashMap<>(data);
+            payload.put("message", "notify");
+            payload.put("message_type", DeviceConstants.MessageType.MSG_ALARM_EVENT.getCode());
+            payload.put("dev_id", deviceId);
+            payload.put("timestamp", System.currentTimeMillis());
+            payload.put("alarmType", alarmType);
+            
+            sendMessage(MqttTopics.DAS_ALARM_EVENT, payload);
+            log.info("Alarm message sent: {}, type: {}", deviceId, alarmType);
+        } catch (Exception e) {
+            log.error("Error sending alarm message: {}, type: {}", deviceId, alarmType, e);
+        }
     }
     
     @Override
     public void sendBehaviorAnalysisResult(String deviceId, Object behaviorPattern) {
-        String topic = topicPrefix + deviceId + "/behavior";
-        
-        Map<String, Object> payload = new HashMap<>();
-        payload.put("deviceId", deviceId);
-        payload.put("behaviorPattern", behaviorPattern);
-        payload.put("timestamp", System.currentTimeMillis());
-        
-        publish(topic, payload);
-        log.debug("Behavior analysis result sent: {}", topic);
+        try {
+            Map<String, Object> payload = new HashMap<>();
+            payload.put("message", "notify");
+            payload.put("dev_id", deviceId);
+            payload.put("behaviorPattern", behaviorPattern);
+            payload.put("timestamp", System.currentTimeMillis());
+            
+            sendMessage(MqttTopics.DAS_BEHAVIOR_ANALYSIS, payload);
+            log.debug("Behavior analysis result sent: {}", deviceId);
+        } catch (Exception e) {
+            log.error("Error sending behavior analysis result: {}", deviceId, e);
+        }
     }
     
     @Override
     public boolean sendCommandToDevice(String deviceId, String command, Object payload) {
-        String topic = topicPrefix + deviceId + "/command";
-        
-        Map<String, Object> message = new HashMap<>();
-        message.put("deviceId", deviceId);
-        message.put("command", command);
-        message.put("payload", payload);
-        message.put("timestamp", System.currentTimeMillis());
-        
-        try {
-            publish(topic, message);
-            log.info("Command sent to device: {}, command: {}", topic, command);
+        try {
+            Map<String, Object> message = new HashMap<>();
+            message.put("command", command);
+            message.put("payload", payload);
+            message.put("timestamp", System.currentTimeMillis());
+            
+            String topic = String.format(MqttTopics.DEV_COMMAND, deviceId);
+            sendMessage(topic, message);
+            log.info("Command sent to device: {}, command: {}", deviceId, command);
             return true;
         } catch (Exception e) {
-            log.error("Failed to send command to device: {}, command: {}, error: {}", topic, command, e.getMessage());
+            log.error("Failed to send command to device: {}, command: {}, error: {}", deviceId, command, e.getMessage());
             return false;
         }
     }
     
     @Override
     public void sendFallAlarmMessage(String deviceId, int pose, List<Float> targetPoint) {
-        String topic = topicPrefix + deviceId + "/fall";
-        
-        Map<String, Object> payload = new HashMap<>();
-        payload.put("deviceId", deviceId);
-        payload.put("pose", pose);
-        payload.put("targetPoint", targetPoint);
-        payload.put("timestamp", System.currentTimeMillis());
-        
-        publish(topic, payload);
-        log.info("Fall alarm message sent: {}", topic);
+        try {
+            Map<String, Object> payload = new HashMap<>();
+            payload.put("message", "notify");
+            payload.put("message_type", DeviceConstants.MessageType.MSG_EVENT_FALL.getCode());
+            payload.put("dev_id", deviceId);
+            payload.put("pose", pose);
+            payload.put("target_point", targetPoint);
+            payload.put("alarmType", "fall");
+            payload.put("timestamp", System.currentTimeMillis());
+            
+            // 跌倒告警使用QoS 2确保可靠传输
+            sendMessage(MqttTopics.DAS_ALARM_EVENT, payload, 2);
+            log.info("Fall alarm message sent: {}", deviceId);
+        } catch (Exception e) {
+            log.error("Error sending fall alarm message: {}", deviceId, e);
+        }
     }
     
     @Override
     public void sendDeviceRebootCommand(String deviceId) {
-        String topic = topicPrefix + deviceId + "/command";
-        
-        Map<String, Object> payload = new HashMap<>();
-        payload.put("command", "reboot");
-        payload.put("timestamp", System.currentTimeMillis());
-        
-        publish(topic, payload);
-        log.info("Device reboot command sent: {}", deviceId);
+        try {
+            Map<String, Object> payload = new HashMap<>();
+            String topic = DeviceConstants.MqttConstant.TOPIC_DEVICE_PREFIX + deviceId + "/reboot";
+            sendMessage(topic, payload);
+            log.info("Device reboot command sent: {}", deviceId);
+        } catch (Exception e) {
+            log.error("Error sending device reboot command: {}", deviceId, e);
+        }
     }
     
     @Override
     public void sendDeviceResetCommand(String deviceId) {
-        String topic = topicPrefix + deviceId + "/command";
-        
-        Map<String, Object> payload = new HashMap<>();
-        payload.put("command", "reset");
-        payload.put("timestamp", System.currentTimeMillis());
-        
-        publish(topic, payload);
-        log.info("Device reset command sent: {}", deviceId);
+        try {
+            Map<String, Object> payload = new HashMap<>();
+            String topic = DeviceConstants.MqttConstant.TOPIC_DEVICE_PREFIX + deviceId + "/reset";
+            sendMessage(topic, payload);
+            log.info("Device reset command sent: {}", deviceId);
+        } catch (Exception e) {
+            log.error("Error sending device reset command: {}", deviceId, e);
+        }
     }
     
     @Override
     public void sendDeviceCommand(String deviceId, String command, Map<String, Object> params) {
-        String topic = topicPrefix + deviceId + "/command";
-        
-        Map<String, Object> payload = new HashMap<>();
-        payload.put("command", command);
-        payload.put("params", params);
-        payload.put("timestamp", System.currentTimeMillis());
-        
-        publish(topic, payload);
-        log.info("Device command sent: {}, command: {}", deviceId, command);
+        try {
+            Map<String, Object> payload = new HashMap<>();
+            payload.put("command", command);
+            payload.put("params", params);
+            payload.put("timestamp", System.currentTimeMillis());
+            
+            String topic = DeviceConstants.MqttConstant.TOPIC_DEVICE_PREFIX + deviceId + "/" + command;
+            sendMessage(topic, payload);
+            log.info("Device command sent: {}, command: {}", deviceId, command);
+        } catch (Exception e) {
+            log.error("Error sending device command: {}, command: {}", deviceId, command, e);
+        }
     }
     
     @Override
     public void sendDeviceKeepAliveResponse(String deviceId, int status) {
-        String topic = topicPrefix + deviceId + "/keepalive/response";
-        
-        Map<String, Object> payload = new HashMap<>();
-        payload.put("status", status);
-        payload.put("timestamp", System.currentTimeMillis());
-        
-        publish(topic, payload);
-        log.debug("Keep-alive response sent: {}, status: {}", deviceId, status);
+        try {
+            Map<String, Object> payload = new HashMap<>();
+            payload.put("code", status);
+            
+            String topic = DeviceConstants.MqttConstant.TOPIC_DAS_PREFIX + deviceId + "/keepalive";
+            sendMessage(topic, payload);
+            log.debug("Device keepalive response sent: {}, code: {}", deviceId, status);
+        } catch (Exception e) {
+            log.error("Error sending device keepalive response: {}", deviceId, e);
+        }
     }
     
     @Override
     public void sendDeviceNotFoundResponse(String deviceId) {
-        String topic = topicPrefix + deviceId + "/response";
-        
-        Map<String, Object> payload = new HashMap<>();
-        payload.put("status", "error");
-        payload.put("message", "Device not found");
-        payload.put("timestamp", System.currentTimeMillis());
-        
-        publish(topic, payload);
-        log.warn("Device not found response sent: {}", deviceId);
+        try {
+            Map<String, Object> payload = new HashMap<>();
+            payload.put("code", 404);
+            payload.put("message", "Device not found");
+            
+            String topic = MqttTopics.APP_DEVICE_INFO_RESPONSE;
+            sendMessage(topic, payload);
+            log.debug("Device not found response sent: {}", deviceId);
+        } catch (Exception e) {
+            log.error("Error sending device not found response: {}", deviceId, e);
+        }
     }
     
     @Override
     public void sendAlarmAckMessage(String deviceId, Long eventId) {
-        String topic = topicPrefix + deviceId + "/alarm/ack";
-        
-        Map<String, Object> payload = new HashMap<>();
-        payload.put("eventId", eventId);
-        payload.put("timestamp", System.currentTimeMillis());
-        
-        publish(topic, payload);
-        log.info("Alarm acknowledgment message sent: {}, eventId: {}", deviceId, eventId);
+        try {
+            Map<String, Object> payload = new HashMap<>();
+            payload.put("dev_id", deviceId);
+            payload.put("event_id", eventId);
+            payload.put("timestamp", System.currentTimeMillis());
+            
+            sendMessage(MqttTopics.APP_FALL_EVENT_ACK, payload);
+            log.debug("Alarm acknowledgment sent: {}, eventId: {}", deviceId, eventId);
+        } catch (Exception e) {
+            log.error("Error sending alarm acknowledgment: {}, eventId: {}", deviceId, eventId, e);
+        }
     }
     
     @Override
     public void sendDeviceParamSetCommand(String deviceId, String paramType, String paramName, float value) {
-        String topic = topicPrefix + deviceId + "/param/set";
-        
-        Map<String, Object> payload = new HashMap<>();
-        payload.put("paramType", paramType);
-        payload.put("paramName", paramName);
-        payload.put("value", value);
-        payload.put("timestamp", System.currentTimeMillis());
-        
-        publish(topic, payload);
-        log.info("Parameter set command sent: {}, type: {}, name: {}, value: {}", deviceId, paramType, paramName, value);
+        try {
+            Map<String, Object> payload = new HashMap<>();
+            payload.put("param_type", paramType);
+            payload.put("param_name", paramName);
+            payload.put("value", value);
+            payload.put("timestamp", System.currentTimeMillis());
+            
+            String topic = DeviceConstants.MqttConstant.TOPIC_DEVICE_PREFIX + deviceId + "/set_param";
+            sendMessage(topic, payload);
+            log.info("Device parameter set command sent: {}, {}={}", deviceId, paramName, value);
+        } catch (Exception e) {
+            log.error("Error sending device parameter set command: {}", deviceId, e);
+        }
     }
     
     @Override
     public void sendSetDeviceParamCommand(String deviceId, String paramType, String paramName, Float value) {
-        sendDeviceParamSetCommand(deviceId, paramType, paramName, value);
+        sendDeviceParamSetCommand(deviceId, paramType, paramName, value != null ? value : 0.0f);
     }
     
     @Override
     public void sendUpdateNetworkCommand(String deviceId, String ssid, String password) {
-        String topic = topicPrefix + deviceId + "/network/update";
-        
-        Map<String, Object> payload = new HashMap<>();
-        payload.put("ssid", ssid);
-        payload.put("password", password);
-        payload.put("timestamp", System.currentTimeMillis());
-        
-        publish(topic, payload);
-        log.info("Network update command sent: {}, SSID: {}", deviceId, ssid);
+        try {
+            Map<String, Object> payload = new HashMap<>();
+            payload.put("ssid", ssid);
+            payload.put("password", password);
+            payload.put("timestamp", System.currentTimeMillis());
+            
+            String topic = DeviceConstants.MqttConstant.TOPIC_DEVICE_PREFIX + deviceId + "/network";
+            sendMessage(topic, payload);
+            log.info("Network update command sent: {}", deviceId);
+        } catch (Exception e) {
+            log.error("Error sending network update command: {}", deviceId, e);
+        }
     }
     
     @Override
     public void sendDeviceLoginResponse(String deviceId, int code) {
-        String topic = topicPrefix + deviceId + "/login/response";
-        
-        Map<String, Object> payload = new HashMap<>();
-        payload.put("code", code);
-        payload.put("timestamp", System.currentTimeMillis());
-        
-        publish(topic, payload);
-        log.debug("Device login response sent: {}, code: {}", deviceId, code);
+        try {
+            Map<String, Object> payload = new HashMap<>();
+            payload.put("code", code);
+            payload.put("expires", 90); // 过期时间,单位秒
+            
+            String topic = DeviceConstants.MqttConstant.TOPIC_DAS_PREFIX + deviceId + "/login";
+            sendMessage(topic, payload);
+            log.debug("Device login response sent: {}, code: {}", deviceId, code);
+        } catch (Exception e) {
+            log.error("Error sending device login response: {}", deviceId, e);
+        }
     }
     
     @Override
     public void sendEventMessage(String deviceId, int pose, Object targetPoint, String event) {
-        String topic = topicPrefix + deviceId + "/event";
-        
-        Map<String, Object> payload = new HashMap<>();
-        payload.put("deviceId", deviceId);
-        payload.put("pose", pose);
-        payload.put("targetPoint", targetPoint);
-        payload.put("event", event);
-        payload.put("timestamp", System.currentTimeMillis());
-        
-        publish(topic, payload);
-        log.info("Event message sent: {}, event: {}", deviceId, event);
+        try {
+            Map<String, Object> payload = new HashMap<>();
+            payload.put("message", "notify");
+            payload.put("message_type", DeviceConstants.MessageType.MSG_EVENT_FALL.getCode());
+            payload.put("dev_id", deviceId);
+            payload.put("event", event);
+            payload.put("timestamp", System.currentTimeMillis());
+            payload.put("pose", pose);
+            payload.put("target_point", targetPoint);
+            
+            // 对于确认的跌倒事件,使用QoS 2
+            int qos = "fall_confirmed".equals(event) ? 2 : 0;
+            sendMessage(MqttTopics.DAS_EVENT, payload, qos);
+        } catch (Exception e) {
+            log.error("Error sending event message: {}, event: {}", deviceId, event, e);
+        }
     }
     
     @Override
     public void sendAlarmEventMessage(String deviceId, String description, String table, int tableId) {
-        String topic = topicPrefix + deviceId + "/alarm/event";
-        
-        Map<String, Object> payload = new HashMap<>();
-        payload.put("deviceId", deviceId);
-        payload.put("description", description);
-        payload.put("table", table);
-        payload.put("tableId", tableId);
-        payload.put("timestamp", System.currentTimeMillis());
-        
-        publish(topic, payload);
-        log.info("Alarm event message sent: {}, description: {}", deviceId, description);
+        try {
+            Map<String, Object> payload = new HashMap<>();
+            payload.put("message", "notify");
+            payload.put("message_type", DeviceConstants.MessageType.MSG_ALARM_EVENT.getCode());
+            payload.put("dev_id", deviceId);
+            payload.put("timestamp", System.currentTimeMillis());
+            payload.put("desc", description);
+            payload.put("table", table);
+            payload.put("table_id", tableId);
+            
+            sendMessage(MqttTopics.DAS_ALARM_EVENT, payload);
+        } catch (Exception e) {
+            log.error("Error sending alarm event message: {}, desc: {}", deviceId, description, e);
+        }
     }
     
     @Override
     public void sendExistenceMessage(String deviceId, String event) {
-        String topic = topicPrefix + deviceId + "/existence";
-        
-        Map<String, Object> payload = new HashMap<>();
-        payload.put("deviceId", deviceId);
-        payload.put("event", event);
-        payload.put("timestamp", System.currentTimeMillis());
-        
-        publish(topic, payload);
-        log.info("Existence event message sent: {}, event: {}", deviceId, event);
+        try {
+            Map<String, Object> payload = new HashMap<>();
+            payload.put("message", "notify");
+            payload.put("message_type", DeviceConstants.MessageType.MSG_EVENT_EXIST.getCode());
+            payload.put("dev_id", deviceId);
+            payload.put("event", event);
+            payload.put("timestamp", System.currentTimeMillis());
+            
+            sendMessage(MqttTopics.DAS_EXIST_EVENT, payload);
+        } catch (Exception e) {
+            log.error("Error sending existence message: {}, event: {}", deviceId, event, e);
+        }
     }
     
     @Override
     public void sendNetworkConfigUpdate(String deviceId, Device.NetworkInfo networkInfo) {
-        String topic = topicPrefix + deviceId + "/network/config";
-        
-        Map<String, Object> payload = new HashMap<>();
-        payload.put("deviceId", deviceId);
-        payload.put("networkInfo", networkInfo);
-        payload.put("timestamp", System.currentTimeMillis());
-        
-        publish(topic, payload);
-        log.info("Network config update sent: {}", deviceId);
+        try {
+            Map<String, Object> payload = new HashMap<>();
+            payload.put("dev_id", deviceId);
+            if (networkInfo != null) {
+                payload.put("ssid", networkInfo.getSsid());
+                payload.put("password", networkInfo.getPassword());
+                payload.put("ip", networkInfo.getIp());
+            }
+            payload.put("timestamp", System.currentTimeMillis());
+            
+            String topic = DeviceConstants.MqttConstant.TOPIC_DEVICE_PREFIX + deviceId + "/network_config";
+            sendMessage(topic, payload);
+            log.info("Network config update sent: {}", deviceId);
+        } catch (Exception e) {
+            log.error("Error sending network config update: {}", deviceId, e);
+        }
     }
     
     @Override
     public void sendInstallParamUpdate(String deviceId, Device.InstallParam installParam) {
-        String topic = topicPrefix + deviceId + "/install/param";
-        
-        Map<String, Object> payload = new HashMap<>();
-        payload.put("deviceId", deviceId);
-        payload.put("installParam", installParam);
-        payload.put("timestamp", System.currentTimeMillis());
-        
-        publish(topic, payload);
-        log.info("Install parameter update sent: {}", deviceId);
+        try {
+            Map<String, Object> payload = new HashMap<>();
+            payload.put("dev_id", deviceId);
+            if (installParam != null) {
+                payload.put("mount_plain", installParam.getMountPlain());
+                payload.put("height", installParam.getHeight());
+                
+                // 跟踪区域
+                if (installParam.getTrackingRegion() != null) {
+                    Map<String, Object> trackingRegion = getStringObjectMap(installParam.getTrackingRegion());
+                    payload.put("tracking_region", trackingRegion);
+                }
+            }
+            payload.put("timestamp", System.currentTimeMillis());
+            
+            String topic = DeviceConstants.MqttConstant.TOPIC_DEVICE_PREFIX + deviceId + "/install_param";
+            sendMessage(topic, payload);
+            log.info("Install parameter update sent: {}", deviceId);
+        } catch (Exception e) {
+            log.error("Error sending install parameter update: {}", deviceId, e);
+        }
     }
     
     @Override
     public void sendTrackingRegionUpdate(String deviceId, Device.TrackingRegion trackingRegion) {
-        String topic = topicPrefix + deviceId + "/tracking/region";
-        
-        Map<String, Object> payload = new HashMap<>();
-        payload.put("deviceId", deviceId);
-        payload.put("trackingRegion", trackingRegion);
-        payload.put("timestamp", System.currentTimeMillis());
-        
-        publish(topic, payload);
-        log.info("Tracking region update sent: {}", deviceId);
+        try {
+            Map<String, Object> payload = new HashMap<>();
+            payload.put("dev_id", deviceId);
+            if (trackingRegion != null) {
+                Map<String, Object> regionMap = getStringObjectMap(trackingRegion);
+                payload.put("tracking_region", regionMap);
+            }
+            payload.put("timestamp", System.currentTimeMillis());
+            
+            String topic = DeviceConstants.MqttConstant.TOPIC_DEVICE_PREFIX + deviceId + "/tracking_region";
+            sendMessage(topic, payload);
+            log.info("Tracking region update sent: {}", deviceId);
+        } catch (Exception e) {
+            log.error("Error sending tracking region update: {}", deviceId, e);
+        }
     }
     
     @Override
     public void sendAlarmScheduleUpdate(String deviceId, Map<String, Object> alarmSchedule) {
-        String topic = topicPrefix + deviceId + "/alarm/schedule";
-        
-        Map<String, Object> payload = new HashMap<>();
-        payload.put("deviceId", deviceId);
-        payload.put("alarmSchedule", alarmSchedule);
-        payload.put("timestamp", System.currentTimeMillis());
-        
-        publish(topic, payload);
-        log.info("Alarm schedule update sent: {}", deviceId);
+        try {
+            Map<String, Object> payload = new HashMap<>();
+            payload.put("dev_id", deviceId);
+            payload.put("alarm_schedule", alarmSchedule);
+            payload.put("timestamp", System.currentTimeMillis());
+            
+            String topic = DeviceConstants.MqttConstant.TOPIC_DEVICE_PREFIX + deviceId + "/alarm_schedule";
+            sendMessage(topic, payload);
+            log.info("Alarm schedule update sent: {}", deviceId);
+        } catch (Exception e) {
+            log.error("Error sending alarm schedule update: {}", deviceId, e);
+        }
     }
     
     @Override
     public void sendDeviceInfoResponse(String deviceId, Device device) {
-        String topic = topicPrefix + deviceId + "/info/response";
-        
-        Map<String, Object> payload = new HashMap<>();
-        payload.put("deviceId", deviceId);
-        payload.put("device", device);
-        payload.put("timestamp", System.currentTimeMillis());
-        
-        publish(topic, payload);
-        log.debug("Device info response sent: {}", deviceId);
+        try {
+            Map<String, Object> payload = new HashMap<>();
+            payload.put("dev_id", deviceId);
+            payload.put("device", device);
+            payload.put("timestamp", System.currentTimeMillis());
+            
+            sendMessage(MqttTopics.APP_DEVICE_INFO_RESPONSE, payload);
+            log.debug("Device info response sent: {}", deviceId);
+        } catch (Exception e) {
+            log.error("Error sending device info response: {}", deviceId, e);
+        }
     }
     
     @Override
     public void sendStatusMessage(String deviceId, String status, Map<String, Object> data) {
-        String topic = topicPrefix + deviceId + "/status";
-        
-        Map<String, Object> payload = new HashMap<>(data);
-        payload.put("deviceId", deviceId);
-        payload.put("status", status);
-        payload.put("timestamp", System.currentTimeMillis());
-        
-        publish(topic, payload);
-        log.debug("Device status message sent: {}, status: {}", topic, status);
+        try {
+            Map<String, Object> payload = new HashMap<>(data);
+            payload.put("dev_id", deviceId);
+            payload.put("status", status);
+            payload.put("timestamp", System.currentTimeMillis());
+            
+            sendMessage(MqttTopics.DAS_STATUS, payload);
+            log.debug("Device status message sent: {}, status: {}", deviceId, status);
+        } catch (Exception e) {
+            log.error("Error sending status message: {}, status: {}", deviceId, status, e);
+        }
     }
     
     @Override
     public void sendBehaviorMessage(String deviceId, String behaviorType, Map<String, Object> data) {
-        String topic = topicPrefix + deviceId + "/behavior";
-        
-        Map<String, Object> payload = new HashMap<>(data);
-        payload.put("deviceId", deviceId);
-        payload.put("behaviorType", behaviorType);
-        payload.put("timestamp", System.currentTimeMillis());
-        
-        publish(topic, payload);
-        log.debug("Behavior message sent: {}, type: {}", topic, behaviorType);
+        try {
+            Map<String, Object> payload = new HashMap<>(data);
+            payload.put("dev_id", deviceId);
+            payload.put("behaviorType", behaviorType);
+            payload.put("timestamp", System.currentTimeMillis());
+            
+            sendMessage(MqttTopics.DAS_BEHAVIOR_ANALYSIS, payload);
+            log.debug("Behavior message sent: {}, type: {}", deviceId, behaviorType);
+        } catch (Exception e) {
+            log.error("Error sending behavior message: {}, type: {}", deviceId, behaviorType, e);
+        }
     }
     
     @Override
@@ -452,9 +572,7 @@ public class MqttGatewayImpl implements MqttGateway {
             payload.put("global", globalConfig);
             payload.put("timestamp", System.currentTimeMillis());
             
-            String topic = "/das/report_alarm_param";
-            publish(topic, payload);
-            
+            sendMessage(MqttTopics.DAS_REPORT_ALARM_PARAM, payload);
             log.debug("Alarm parameter response sent: code={}, config={}", code, globalConfig);
         } catch (Exception e) {
             log.error("Failed to send alarm parameter response", e);
@@ -469,9 +587,7 @@ public class MqttGatewayImpl implements MqttGateway {
             payload.put("global", globalConfig);
             payload.put("timestamp", System.currentTimeMillis());
             
-            String topic = "/das/set_alarm_param_ack";
-            publish(topic, payload);
-            
+            sendMessage(MqttTopics.DAS_SET_ALARM_PARAM_ACK, payload);
             log.debug("Set alarm parameter acknowledgment sent: code={}, config={}", code, globalConfig);
         } catch (Exception e) {
             log.error("Failed to send set alarm parameter acknowledgment", e);
@@ -480,35 +596,45 @@ public class MqttGatewayImpl implements MqttGateway {
     
     @Override
     public void sendResponse(String topic, int code, Map<String, Object> data) {
-        Map<String, Object> payload = new HashMap<>(data);
-        payload.put("code", code);
-        payload.put("timestamp", System.currentTimeMillis());
-        
-        publish(topic, payload);
-        log.debug("Response sent to topic: {}, code: {}", topic, code);
+        try {
+            Map<String, Object> payload = new HashMap<>(data);
+            payload.put("code", code);
+            payload.put("timestamp", System.currentTimeMillis());
+            
+            sendMessage(topic, payload);
+            log.debug("Response sent to topic: {}, code: {}", topic, code);
+        } catch (Exception e) {
+            log.error("Error sending response to topic: {}", topic, e);
+        }
     }
     
     @Override
     public void sendCommand(String topic, String command, Map<String, Object> params) {
-        Map<String, Object> payload = new HashMap<>();
-        payload.put("command", command);
-        if (params != null) {
+        try {
+            Map<String, Object> payload = new HashMap<>();
+            payload.put("command", command);
             payload.put("params", params);
+            payload.put("timestamp", System.currentTimeMillis());
+            
+            sendMessage(topic, payload);
+            log.debug("Command sent to topic: {}, command: {}", topic, command);
+        } catch (Exception e) {
+            log.error("Error sending command to topic: {}", topic, e);
         }
-        payload.put("timestamp", System.currentTimeMillis());
-        
-        publish(topic, payload);
-        log.debug("Command sent to topic: {}, command: {}", topic, command);
     }
     
     @Override
     public void sendGenericMessage(String topic, String messageType, Map<String, Object> messageData) {
-        Map<String, Object> payload = new HashMap<>(messageData);
-        payload.put("messageType", messageType);
-        payload.put("timestamp", System.currentTimeMillis());
-        
-        publish(topic, payload);
-        log.debug("Generic message sent to topic: {}, type: {}", topic, messageType);
+        try {
+            Map<String, Object> payload = new HashMap<>(messageData);
+            payload.put("message_type", messageType);
+            payload.put("timestamp", System.currentTimeMillis());
+            
+            sendMessage(topic, payload);
+            log.debug("Generic message sent to topic: {}, type: {}", topic, messageType);
+        } catch (Exception e) {
+            log.error("Error sending generic message to topic: {}", topic, e);
+        }
     }
     
     @Override
@@ -517,7 +643,8 @@ public class MqttGatewayImpl implements MqttGateway {
     }
     
     /**
-     * 发送消息到MQTT服务器
+     * 发送消息到MQTT服务器 - 增强版
+     * 支持动态QoS和消息保留设置
      * @param topic 主题
      * @param payload 负载
      * @param qos 质量等级
@@ -538,4 +665,25 @@ public class MqttGatewayImpl implements MqttGateway {
             log.error("Failed to send MQTT message to topic: {}, error: {}", topic, e.getMessage());
         }
     }
+    
+    /**
+     * 发送消息 - 私有方法
+     * 默认QoS 1,适合大多数业务场景
+     */
+    private void sendMessage(String topic, Object payload) {
+        sendMessage(topic, payload, 1);
+    }
+    
+    /**
+     * 发送消息 - 支持动态QoS
+     */
+    private void sendMessage(String topic, Object payload, int qos) {
+        try {
+            String json = objectMapper.writeValueAsString(payload);
+            sendToMqtt(topic, json, qos, false);
+            log.debug("MQTT message sent to topic: {}", topic);
+        } catch (Exception e) {
+            log.error("Error sending MQTT message to topic: {}", topic, e);
+        }
+    }
 } 

+ 0 - 498
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/gateway/impl/DeviceGatewayImpl.java.bak

@@ -1,498 +0,0 @@
-package com.hfln.device.infrastructure.gateway.impl;
-
-import cn.hfln.framework.extension.BizException;
-import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.hfln.device.common.dto.data.device.DeviceDTO;
-import com.hfln.device.common.dto.data.event.EventListDTO;
-import com.hfln.device.common.dto.data.home.HomeInfoDTO;
-import com.hfln.device.common.request.device.DeviceBandingParams;
-import com.hfln.device.common.request.device.DeviceListParams;
-import com.hfln.device.common.request.device.DeviceLocationParams;
-import com.hfln.device.common.request.event.EventListParams;
-import com.hfln.device.common.vo.PageRecord;
-import com.hfln.device.domain.event.MqttHandler;
-import com.hfln.device.domain.exception.ErrorEnum;
-import com.hfln.device.domain.gateway.DeviceGateway;
-import com.hfln.device.infrastructure.mapper.DevInfoMapper;
-import com.hfln.device.infrastructure.po.DevGroup;
-import com.hfln.device.infrastructure.po.DevInfo;
-import com.hfln.device.infrastructure.po.DevShare;
-import com.hfln.device.infrastructure.po.EventList;
-import com.hfln.device.infrastructure.service.*;
-import org.apache.commons.collections4.CollectionUtils;
-import org.springframework.beans.BeanUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
-import java.math.BigDecimal;
-import java.math.RoundingMode;
-import java.util.*;
-import java.util.stream.Collectors;
-
-import com.hfln.device.domain.entity.Device;
-import com.hfln.device.infrastructure.po.DevRetentionAlarm;
-import com.hfln.device.infrastructure.po.StayTime;
-import com.hfln.device.infrastructure.mapper.DevRetentionAlarmMapper;
-import com.hfln.device.infrastructure.mapper.StayTimeMapper;
-
-import lombok.extern.slf4j.Slf4j;
-
-@Slf4j
-@Service
-public class DeviceGatewayImpl implements DeviceGateway {
-
-    @Autowired
-    private DevShareService devShareService;
-
-    @Autowired
-    private DevInfoService devInfoService;
-
-    @Autowired
-    private GroupShareService groupShareService;
-
-    @Autowired
-    private DevGroupService devGroupService;
-
-    @Autowired
-    private EventService eventService;
-
-    @Autowired
-    private MqttHandler mqttHandler;
-
-    @Autowired
-    private DevInfoMapper devInfoMapper;
-    
-    @Autowired
-    private StayTimeMapper stayTimeMapper;
-    
-    @Autowired
-    private DevRetentionAlarmMapper devRetentionAlarmMapper;
-
-    @Override
-    public HomeInfoDTO queryHomeInfo(Long userId) {
-        HomeInfoDTO homeInfoDTO = new HomeInfoDTO();
-        //todo 添加轮播图相关信息
-        homeInfoDTO.setCarouselImage(null);
-        /*
-          查询设备详情
-         */
-        // 查询当前OpenId被分享的设备
-        Optional<List<String>> sharedDevIds = devShareService.queryDeviceIdByUserId(userId);
-
-        List<DeviceDTO> deviceDTOs = new ArrayList<>();
-        List<DevInfo> devInfos = devInfoService.queryDeviceList(userId, null, null, sharedDevIds.orElse(Collections.emptyList()));
-
-        for (DevInfo devInfo : devInfos) {
-            DeviceDTO dto = new DeviceDTO();
-            BeanUtils.copyProperties(devInfo, dto);
-            deviceDTOs.add(dto);
-        }
-        homeInfoDTO.setDeviceList(deviceDTOs);
-
-        /*
-         * 查询群组数量
-         */
-        // 查询被分享群组
-        List<String> groupUUid = groupShareService.queryGroupUUidByUserId(userId);
-        List<DevGroup> devGroups = devGroupService.queryGroupByUserId(userId, groupUUid);
-        homeInfoDTO.setGroupNum(devGroups.size());
-
-        /*
-         * 查询被分享数量
-         */
-        homeInfoDTO.setShareNum(devShareService.querySharedNumByUserId(userId).size());
-
-        return homeInfoDTO;
-    }
-
-
-    @Override
-    public List<DeviceDTO> queryDeviceList(DeviceListParams request) {
-
-        Optional<List<String>> sharedDevIds = devShareService.queryDeviceIdByUserId(request.getUserId());
-
-        List<DeviceDTO> deviceDTOs = new ArrayList<>();
-        List<DevInfo> devInfos = devInfoService.queryDeviceList(request.getUserId(), request.getKeyWord(),
-                request.getStatus(), sharedDevIds.orElse(Collections.emptyList()));
-
-        for (DevInfo devInfo : devInfos) {
-            DeviceDTO dto = new DeviceDTO();
-            BeanUtils.copyProperties(devInfo, dto);
-            deviceDTOs.add(dto);
-        }
-        return deviceDTOs;
-    }
-
-    @Override
-    @Transactional
-    public Boolean deviceUnBind(Long userId, String deviceId) {
-        List<DevInfo> devInfos = devInfoService.queryDevices(userId, deviceId);
-        boolean updateFlag;
-        // 绑定人解绑
-        if (CollectionUtils.isNotEmpty(devInfos) && !devInfos.isEmpty()) {
-            //更新设备表
-            boolean flag = devInfoService.update(null,
-                    Wrappers.<DevInfo>lambdaUpdate()
-                            .set(DevInfo::getUserId, null)
-                            .eq(DevInfo::getDevId, deviceId));
-            //更新设备分享表
-            boolean flagV2 = devShareService.update(null,
-                    Wrappers.<DevShare>lambdaUpdate()
-                            .set(DevShare::getState, 0)
-                            .set(DevShare::getIsDeleted, 1)
-                            .eq(DevShare::getDevId, deviceId));
-            updateFlag = flag && flagV2;
-        } else {
-            // 被分享者解绑
-            updateFlag = devShareService.update(null,
-                    Wrappers.<DevShare>lambdaUpdate()
-                            .set(DevShare::getState, 0)
-                            .set(DevShare::getIsDeleted, 1)
-                            .eq(DevShare::getDevId, deviceId)
-                            .eq(DevShare::getSharedUserId, userId));
-        }
-
-        return updateFlag;
-    }
-
-
-    @Override
-    public Boolean deviceBind(DeviceBandingParams request) {
-        // 1. 检查设备是否存在
-        DevInfo devInfo = devInfoService.getOne(
-                Wrappers.<DevInfo>lambdaQuery()
-                        .eq(DevInfo::getDevId, request.getDevId())
-        );
-        if (Objects.isNull(devInfo)) {
-            throw new BizException(ErrorEnum.DEVICE_IS_NOT_EXIST.getErrorCode(), ErrorEnum.DEVICE_IS_NOT_EXIST.getErrorMessage());
-        }
-        if (Objects.nonNull(devInfo.getUserId())) {
-            throw new BizException(ErrorEnum.DEVICE_IS_BINDING.getErrorCode(), ErrorEnum.DEVICE_IS_BINDING.getErrorMessage());
-        }
-
-        // 3. 更新设备信息
-        return devInfoService.updateDevice(devInfo.getDevInfoId(), request);
-    }
-
-
-    @Override
-    public DeviceDTO queryDeviceById(String deviceId) {
-        DevInfo devInfo = devInfoService.getOne(
-                Wrappers.<DevInfo>lambdaQuery()
-                        .eq(DevInfo::getDevId, deviceId));
-        if (Objects.isNull(devInfo)) {
-            throw new BizException(ErrorEnum.DEVICE_IS_NOT_EXIST.getErrorCode(), ErrorEnum.DEVICE_IS_NOT_EXIST.getErrorMessage());
-        }
-        DeviceDTO dto = new DeviceDTO();
-        BeanUtils.copyProperties(devInfo, dto);
-        return dto;
-    }
-
-
-    @Override
-    public PageRecord<EventListDTO> queryEventByPage(EventListParams request) {
-        Integer pageNo = Optional.ofNullable(request.getPageNo()).orElse(1);
-        Integer pageSize = Optional.ofNullable(request.getPageNo()).orElse(10);
-
-        // 执行分页查询
-        Page<EventList> eventPage = eventService.queryEventListByDevId(request.getDeviceId(),
-                request.getStartTime(), request.getEndTime(), pageNo, pageSize);
-        // 换为目标VO
-        List<EventListDTO> targets = convertToTargetVO(eventPage.getRecords());
-        return getEventListDTOPageRecord(eventPage, targets);
-    }
-
-    // 填充PageRecord
-    private PageRecord<EventListDTO> getEventListDTOPageRecord(Page<EventList> eventPage, List<EventListDTO> targets) {
-        int totalPages = (int) Math.ceil((double) eventPage.getTotal() / eventPage.getSize());
-        PageRecord<EventListDTO> pageRecord = new PageRecord<>();
-        pageRecord.setRows(targets);
-        pageRecord.setTotal(eventPage.getTotal());
-        pageRecord.setPageNum((int) eventPage.getCurrent());
-        pageRecord.setPageSize((int) eventPage.getSize());
-        pageRecord.setOutTotalPageNum(eventPage.getCurrent() > totalPages);
-        pageRecord.setTotalPageNum(totalPages);
-        return pageRecord;
-    }
-
-    // 实体转换方法
-    private List<EventListDTO> convertToTargetVO(List<EventList> records) {
-        return records.stream().map(event -> {
-            EventListDTO vo = new EventListDTO();
-            // 使用BeanUtils简化属性拷贝
-            BeanUtils.copyProperties(event, vo);
-            return vo;
-        }).collect(Collectors.toList());
-    }
-
-
-    @Override
-    public Boolean handleEvent(Long eventId) {
-        LambdaUpdateWrapper<EventList> updateWrapper = new LambdaUpdateWrapper<>();
-        updateWrapper.eq(EventList::getEventListId, eventId)
-                .set(EventList::getIsHandle, 1);
-        return this.eventService.update(updateWrapper);
-    }
-
-
-    @Override
-    @Transactional(rollbackFor = Exception.class)
-    public Boolean updateDevice(DeviceBandingParams request) {
-        // 1. 安全获取长度和宽度,提供默认值
-        BigDecimal length = Optional.ofNullable(request.getLength()).orElse(BigDecimal.ZERO);
-        BigDecimal width = Optional.ofNullable(request.getWidth()).orElse(BigDecimal.ZERO);
-
-        // 2. 计算半长半宽
-        BigDecimal halfLength = length.divide(BigDecimal.valueOf(2), 10, RoundingMode.HALF_UP);
-        BigDecimal halfWidth = width.divide(BigDecimal.valueOf(2), 10, RoundingMode.HALF_UP);
-
-        // 3. 设置默认值
-        setIfNull(request::getXStart, () -> halfLength, request::setXStart);
-        setIfNull(request::getXEnd, () -> halfLength, request::setXEnd);
-        setIfNull(request::getYStart, () -> halfWidth, request::setYStart);
-        setIfNull(request::getYEnd, () -> halfWidth, request::setYEnd);
-
-
-        Boolean flag = devInfoService.updateDevice(request.getDevId(), request);
-        DevInfo devInfo = devInfoService.getOne(
-                Wrappers.<DevInfo>lambdaQuery()
-                        .eq(DevInfo::getDevId, request.getDevId()));
-
-        //检查parts.length >= 2确保数组有足够元素,提供默认值"2.0"
-        String result = Optional.ofNullable(devInfo.getSoftware())
-                .filter(s -> s.contains("."))
-                .map(s -> s.split("\\."))
-                .filter(parts -> parts.length >= 2)
-                .map(parts -> parts[0] + "." + parts[1])
-                .orElse("2.0");
-
-        mqttHandler.handleDeviceUpdateMessage(result, request);
-        return flag;
-    }
-
-
-    // 辅助方法:如果值为null则设置默认值
-    private <T> void setIfNull(java.util.function.Supplier<T> getter,
-                               java.util.function.Supplier<T> defaultValueSupplier,
-                               java.util.function.Consumer<T> setter) {
-        if (getter.get() == null) {
-            setter.accept(defaultValueSupplier.get());
-        }
-    }
-
-
-    @Override
-    public Boolean updateDeviceLocation(DeviceLocationParams params) {
-
-        DevInfo devInfo = devInfoService.getOne(
-                Wrappers.<DevInfo>lambdaQuery()
-                        .eq(DevInfo::getDevId, params.getDeviceId()));
-        if (Objects.isNull(devInfo)) {
-            throw new BizException(ErrorEnum.DEVICE_IS_NOT_EXIST.getErrorCode(), ErrorEnum.DEVICE_IS_NOT_EXIST.getErrorMessage());
-        }
-        LambdaUpdateWrapper<DevInfo> updateWrapper = Wrappers.lambdaUpdate();
-        // 仅当字段非空时才更新
-        if (Objects.nonNull(params.getXValue())) {
-            updateWrapper.set(DevInfo::getX, params.getXValue());
-        }
-        if (Objects.nonNull(params.getYValue())) {
-            updateWrapper.set(DevInfo::getY, params.getYValue());
-        }
-        // 如果所有字段均为空,无需更新
-        if (params.getXValue() == null && params.getYValue() == null) {
-            return false;
-        }
-        return devInfoService.update(updateWrapper);
-    }
-
-    /**
-     * 获取所有设备信息
-     * @return 设备列表
-     */
-    @Override
-    public List<Device> findAllDevices() {
-        List<DevInfo> devInfoList = devInfoMapper.selectList(null);
-        return devInfoList.stream().map(this::convertToDevice).collect(Collectors.toList());
-    }
-
-    /**
-     * 根据设备ID查询设备
-     * @param devId 设备ID
-     * @return 设备信息
-     */
-    @Override
-    public Optional<Device> findDeviceById(String devId) {
-        DevInfo devInfo = devInfoMapper.selectById(devId);
-        return Optional.ofNullable(devInfo).map(this::convertToDevice);
-    }
-
-    /**
-     * 保存设备信息
-     * @param device 设备信息
-     * @return 保存后的设备
-     */
-    @Override
-    public Device saveDevice(Device device) {
-        DevInfo devInfo = convertToDevInfo(device);
-        if (devInfoMapper.selectById(device.getDevId()) != null) {
-            devInfoMapper.updateById(devInfo);
-        } else {
-            devInfoMapper.insert(devInfo);
-        }
-        return device;
-    }
-
-    /**
-     * 更新设备在线状态
-     * @param devId 设备ID
-     * @param online 在线状态
-     * @return 成功与否
-     */
-    @Override
-    public boolean updateDeviceOnlineStatus(String devId, Integer online) {
-        DevInfo devInfo = new DevInfo();
-        devInfo.setDevId(devId);
-        devInfo.setOnline(online);
-        return devInfoMapper.updateById(devInfo) > 0;
-    }
-
-    /**
-     * 更新设备保活时间
-     * @param devId 设备ID
-     * @param keepaliveTime 保活时间
-     * @return 成功与否
-     */
-    @Override
-    public boolean updateDeviceKeepAliveTime(String devId, Long keepaliveTime) {
-        // 仅在内存中维护保活时间,不需要持久化到数据库
-        return true;
-    }
-
-    /**
-     * 记录设备停留时间
-     * @param devId 设备ID
-     * @param enterTime 进入时间
-     * @param leaveTime 离开时间
-     * @param stayTime 停留时间
-     * @return 成功与否
-     */
-    @Override
-    public boolean recordDeviceStayTime(String devId, Long enterTime, Long leaveTime, String stayTime) {
-        StayTime stayTimeEntity = new StayTime();
-        stayTimeEntity.setDevId(devId);
-        stayTimeEntity.setEnterTime(new Date(enterTime));
-        stayTimeEntity.setLeaveTime(new Date(leaveTime));
-        stayTimeEntity.setStayTime(stayTime);
-        stayTimeEntity.setCreateTime(new Date());
-        stayTimeEntity.setUpdateTime(new Date());
-        
-        return stayTimeMapper.insert(stayTimeEntity) > 0;
-    }
-
-    /**
-     * 记录设备滞留告警
-     * @param devId 设备ID
-     * @param alarmTime 告警时间
-     * @param alarmType 告警类型
-     * @param description 告警描述
-     * @return 成功与否
-     */
-    @Override
-    public boolean recordDeviceRetentionAlarm(String devId, Long alarmTime, String alarmType, String description) {
-        DevRetentionAlarm alarm = new DevRetentionAlarm();
-        alarm.setDevId(devId);
-        alarm.setAlarmTime(new Date(alarmTime));
-        alarm.setAlarmType(alarmType);
-        alarm.setDescription(description);
-        alarm.setStatus(0); // 未处理
-        alarm.setCreateTime(new Date());
-        alarm.setUpdateTime(new Date());
-        
-        return devRetentionAlarmMapper.insert(alarm) > 0;
-    }
-    
-    /**
-     * 将DevInfo转换为Device
-     */
-    private Device convertToDevice(DevInfo devInfo) {
-        if (devInfo == null) {
-            return null;
-        }
-        
-        Device.TrackingRegion trackingRegion = Device.TrackingRegion.builder()
-                .startX(devInfo.getStartX())
-                .startY(devInfo.getStartY())
-                .startZ(devInfo.getStartZ())
-                .stopX(devInfo.getStopX())
-                .stopY(devInfo.getStopY())
-                .stopZ(devInfo.getStopZ())
-                .build();
-        
-        Device.InstallParam installParam = Device.InstallParam.builder()
-                .mountPlain(devInfo.getMountPlain())
-                .isCeiling(0) // 默认值
-                .height(devInfo.getHeight())
-                .trackingRegion(trackingRegion)
-                .build();
-        
-        Device.NetworkInfo network = Device.NetworkInfo.builder()
-                .ssid(devInfo.getSsid())
-                .password(devInfo.getPassword())
-                .ip(devInfo.getIp())
-                .build();
-        
-        return Device.builder()
-                .devId(devInfo.getDevId())
-                .online(devInfo.getOnline())
-                .devType(devInfo.getDevType())
-                .software(devInfo.getSoftware())
-                .hardware(devInfo.getHardware())
-                .network(network)
-                .installParam(installParam)
-                .build();
-    }
-    
-    /**
-     * 将Device转换为DevInfo
-     */
-    private DevInfo convertToDevInfo(Device device) {
-        if (device == null) {
-            return null;
-        }
-        
-        DevInfo devInfo = new DevInfo();
-        devInfo.setDevId(device.getDevId());
-        devInfo.setOnline(device.getOnline());
-        devInfo.setDevType(device.getDevType());
-        devInfo.setSoftware(device.getSoftware());
-        devInfo.setHardware(device.getHardware());
-        
-        if (device.getNetwork() != null) {
-            devInfo.setSsid(device.getNetwork().getSsid());
-            devInfo.setPassword(device.getNetwork().getPassword());
-            devInfo.setIp(device.getNetwork().getIp());
-        }
-        
-        if (device.getInstallParam() != null) {
-            devInfo.setMountPlain(device.getInstallParam().getMountPlain());
-            devInfo.setHeight(device.getInstallParam().getHeight());
-            
-            if (device.getInstallParam().getTrackingRegion() != null) {
-                devInfo.setStartX(device.getInstallParam().getTrackingRegion().getStartX());
-                devInfo.setStartY(device.getInstallParam().getTrackingRegion().getStartY());
-                devInfo.setStartZ(device.getInstallParam().getTrackingRegion().getStartZ());
-                devInfo.setStopX(device.getInstallParam().getTrackingRegion().getStopX());
-                devInfo.setStopY(device.getInstallParam().getTrackingRegion().getStopY());
-                devInfo.setStopZ(device.getInstallParam().getTrackingRegion().getStopZ());
-            }
-        }
-        
-        devInfo.setCreateTime(new Date());
-        devInfo.setUpdateTime(new Date());
-        
-        return devInfo;
-    }
-}

+ 0 - 762
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/gateway/impl/MqttGatewayDefaultImpl.java

@@ -1,762 +0,0 @@
-package com.hfln.device.infrastructure.gateway.impl;
-
-import com.alibaba.fastjson2.JSON;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.hfln.device.domain.constant.DeviceConstants;
-import com.hfln.device.domain.entity.Device;
-import com.hfln.device.domain.gateway.MqttGateway;
-import lombok.extern.slf4j.Slf4j;
-import org.jetbrains.annotations.NotNull;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.integration.mqtt.outbound.MqttPahoMessageHandler;
-import org.springframework.integration.support.MessageBuilder;
-import org.springframework.messaging.Message;
-import org.springframework.stereotype.Component;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * MQTT网关默认实现类
- */
-@Component("mqttGatewayDefault")
-@Slf4j
-public class MqttGatewayDefaultImpl implements MqttGateway {
-
-    @Autowired
-    private MqttPahoMessageHandler mqttOutbound;
-
-    private final ObjectMapper objectMapper = new ObjectMapper();
-
-    @Override
-    public void initialize() {
-        log.info("MQTT Gateway initialized");
-    }
-    
-    @Override
-    public void publish(String topic, Object payload) {
-        try {
-            sendMessage(topic, payload);
-            log.debug("Message published to topic: {}", topic);
-        } catch (Exception e) {
-            log.error("Error publishing message to topic: {}", topic, e);
-        }
-    }
-
-    @Override
-    public void sendDeviceLoginResponse(String deviceId, int code) {
-        try {
-            Map<String, Object> payload = new HashMap<>();
-            payload.put("code", code);
-            payload.put("expires", 90); // 过期时间,单位秒
-            
-            String topic = DeviceConstants.MqttConstant.TOPIC_DAS_PREFIX + deviceId + "/login";
-            sendMessage(topic, payload);
-            log.debug("Device login response sent: {}, code: {}", deviceId, code);
-        } catch (Exception e) {
-            log.error("Error sending device login response: {}", deviceId, e);
-        }
-    }
-
-    @Override
-    public void sendDeviceKeepAliveResponse(String deviceId, int code) {
-        try {
-            Map<String, Object> payload = new HashMap<>();
-            payload.put("code", code);
-            
-            String topic = DeviceConstants.MqttConstant.TOPIC_DAS_PREFIX + deviceId + "/keepalive";
-            sendMessage(topic, payload);
-            log.debug("Device keepalive response sent: {}, code: {}", deviceId, code);
-        } catch (Exception e) {
-            log.error("Error sending device keepalive response: {}", deviceId, e);
-        }
-    }
-
-    @Override
-    public void sendDeviceStatusMessage(Device device) {
-        try {
-            Map<String, Object> payload = new HashMap<>();
-            payload.put("message", "notify");
-            payload.put("timestamp", System.currentTimeMillis());
-            payload.put("dev_id", device.getDevId());
-            payload.put("online", device.getOnline());
-            payload.put("dev_type", device.getDevType());
-            payload.put("software", device.getSoftware());
-            payload.put("hardware", device.getHardware());
-            
-            // 网络信息
-            Map<String, Object> network = new HashMap<>();
-            if (device.getNetwork() != null) {
-                network.put("ssid", device.getNetwork().getSsid());
-                network.put("password", device.getNetwork().getPassword());
-                network.put("ip", device.getNetwork().getIp());
-            }
-            payload.put("network", network);
-            
-            // 雷达参数
-            Map<String, Object> radarParam = new HashMap<>();
-            if (device.getInstallParam() != null) {
-                radarParam.put("mount_plain", device.getInstallParam().getMountPlain());
-                radarParam.put("height", device.getInstallParam().getHeight());
-                
-                // 跟踪区域
-                Map<String, Object> trackingRegion = getStringObjectMap(device.getInstallParam().getTrackingRegion());
-                radarParam.put("tracking_region", trackingRegion);
-            }
-            payload.put("radar_param", radarParam);
-            
-            sendMessage(DeviceConstants.MqttConstant.TOPIC_DAS_STATUS, payload);
-            log.debug("Device status message sent: {}", device.getDevId());
-        } catch (Exception e) {
-            log.error("Error sending device status message: {}", device.getDevId(), e);
-        }
-    }
-
-    @Override
-    public void sendRealtimePoseMessage(String deviceId, int pose, Object targetPoint) {
-        try {
-            Map<String, Object> payload = new HashMap<>();
-            payload.put("message", "notify");
-            payload.put("message_type", DeviceConstants.MessageType.MSG_REALTIME_TARGET.getCode());
-            payload.put("timestamp", System.currentTimeMillis());
-            payload.put("dev_id", deviceId);
-            payload.put("pose", pose);
-            payload.put("target_point", targetPoint);
-            
-            sendMessage(DeviceConstants.MqttConstant.TOPIC_DAS_REALTIME_POS, payload);
-        } catch (Exception e) {
-            log.error("Error sending realtime pose message: {}", deviceId, e);
-        }
-    }
-
-    @Override
-    public void sendEventMessage(String deviceId, int pose, Object targetPoint, String event) {
-        try {
-            Map<String, Object> payload = new HashMap<>();
-            payload.put("message", "notify");
-            payload.put("message_type", DeviceConstants.MessageType.MSG_EVENT_FALL.getCode());
-            payload.put("dev_id", deviceId);
-            payload.put("event", event);
-            payload.put("timestamp", System.currentTimeMillis());
-            payload.put("pose", pose);
-            payload.put("target_point", targetPoint);
-            
-            // 对于确认的跌倒事件,使用QoS 2
-            int qos = "fall_confirmed".equals(event) ? 2 : 0;
-            sendMessage(DeviceConstants.MqttConstant.TOPIC_DAS_EVENT, payload, qos);
-        } catch (Exception e) {
-            log.error("Error sending event message: {}, event: {}", deviceId, event, e);
-        }
-    }
-
-    @Override
-    public void sendAlarmEventMessage(String deviceId, String description, String table, int tableId) {
-        try {
-            Map<String, Object> payload = new HashMap<>();
-            payload.put("message", "notify");
-            payload.put("message_type", DeviceConstants.MessageType.MSG_ALARM_EVENT.getCode());
-            payload.put("dev_id", deviceId);
-            payload.put("timestamp", System.currentTimeMillis());
-            payload.put("desc", description);
-            payload.put("table", table);
-            payload.put("table_id", tableId);
-            
-            sendMessage(DeviceConstants.MqttConstant.TOPIC_DAS_ALARM_EVENT, payload);
-        } catch (Exception e) {
-            log.error("Error sending alarm event message: {}, desc: {}", deviceId, description, e);
-        }
-    }
-
-    @Override
-    public void sendExistenceMessage(String deviceId, String event) {
-        try {
-            Map<String, Object> payload = new HashMap<>();
-            payload.put("message", "notify");
-            payload.put("message_type", DeviceConstants.MessageType.MSG_EVENT_EXIST.getCode());
-            payload.put("dev_id", deviceId);
-            payload.put("event", event);
-            payload.put("timestamp", System.currentTimeMillis());
-            
-            sendMessage(DeviceConstants.MqttConstant.TOPIC_DAS_EXIST_EVENT, payload);
-        } catch (Exception e) {
-            log.error("Error sending existence message: {}, event: {}", deviceId, event, e);
-        }
-    }
-
-    @Override
-    public void sendDeviceRebootCommand(String deviceId) {
-        try {
-            Map<String, Object> payload = new HashMap<>();
-            String topic = DeviceConstants.MqttConstant.TOPIC_DEVICE_PREFIX + deviceId + "/reboot";
-            sendMessage(topic, payload);
-            log.info("Device reboot command sent: {}", deviceId);
-        } catch (Exception e) {
-            log.error("Error sending device reboot command: {}", deviceId, e);
-        }
-    }
-
-    @Override
-    public void sendDeviceParamSetCommand(String deviceId, String mountPlain, String area, float height) {
-        try {
-            Map<String, Object> payload = new HashMap<>();
-            payload.put("dev_id", deviceId);
-            payload.put("mounting_plain", mountPlain);
-            payload.put("height", height);
-            
-            // 解析area参数
-            Map<String, Object> areaObj = JSON.parseObject(area);
-            payload.put("area", areaObj);
-
-            String topic = "/device/" + deviceId + "/set_param";
-            sendMessage(topic, payload);
-            log.info("Device parameter set command sent: {}", deviceId);
-        } catch (Exception e) {
-            log.error("Error sending device parameter set command: {}", deviceId, e);
-        }
-    }
-
-    @Override
-    public void sendNetworkConfigUpdate(String deviceId, Device.NetworkInfo networkInfo) {
-        try {
-            Map<String, Object> payload = new HashMap<>();
-            payload.put("dev_id", deviceId);
-            payload.put("ssid", networkInfo.getSsid());
-            payload.put("password", networkInfo.getPassword());
-            
-            String topic = DeviceConstants.MqttConstant.TOPIC_DEVICE_PREFIX + deviceId + "/update_network";
-            sendMessage(topic, payload);
-            log.info("Network config update sent: {}", deviceId);
-        } catch (Exception e) {
-            log.error("Error sending network config update: {}", deviceId, e);
-        }
-    }
-
-    @Override
-    public void sendInstallParamUpdate(String deviceId, Device.InstallParam installParam) {
-        try {
-            Map<String, Object> payload = new HashMap<>();
-            payload.put("dev_id", deviceId);
-            
-            Map<String, Object> radarParam = new HashMap<>();
-            radarParam.put("mount_plain", installParam.getMountPlain());
-            radarParam.put("height", installParam.getHeight());
-            
-            payload.put("radar_param", radarParam);
-            
-            String topic = DeviceConstants.MqttConstant.TOPIC_DEVICE_PREFIX + deviceId + "/update";
-            sendMessage(topic, payload);
-            log.info("Install param update sent: {}", deviceId);
-        } catch (Exception e) {
-            log.error("Error sending install param update: {}", deviceId, e);
-        }
-    }
-
-    @Override
-    public void sendTrackingRegionUpdate(String deviceId, Device.TrackingRegion trackingRegion) {
-        try {
-            Map<String, Object> payload = new HashMap<>();
-            payload.put("dev_id", deviceId);
-            
-            Map<String, Object> radarParam = new HashMap<>();
-            radarParam.put("tracking_region", getStringObjectMap(trackingRegion));
-            
-            payload.put("radar_param", radarParam);
-            
-            String topic = DeviceConstants.MqttConstant.TOPIC_DEVICE_PREFIX + deviceId + "/update";
-            sendMessage(topic, payload);
-            log.info("Tracking region update sent: {}", deviceId);
-        } catch (Exception e) {
-            log.error("Error sending tracking region update: {}", deviceId, e);
-        }
-    }
-
-    @NotNull
-    private static Map<String, Object> getStringObjectMap(Device.TrackingRegion trackingRegion) {
-        Map<String, Object> trackingRegionMap = new HashMap<>();
-        trackingRegionMap.put("start_x", trackingRegion.getStartX());
-        trackingRegionMap.put("start_y", trackingRegion.getStartY());
-        trackingRegionMap.put("start_z", trackingRegion.getStartZ());
-        trackingRegionMap.put("stop_x", trackingRegion.getStopX());
-        trackingRegionMap.put("stop_y", trackingRegion.getStopY());
-        trackingRegionMap.put("stop_z", trackingRegion.getStopZ());
-        return trackingRegionMap;
-    }
-
-    @Override
-    public void sendAlarmScheduleUpdate(String deviceId, Map<String, Object> alarmSchedule) {
-        try {
-            Map<String, Object> payload = new HashMap<>();
-            payload.put("dev_id", deviceId);
-            payload.put("alarm_schedule", alarmSchedule);
-            
-            String topic = DeviceConstants.MqttConstant.TOPIC_DEVICE_PREFIX + deviceId + "/update";
-            sendMessage(topic, payload);
-            log.info("Alarm schedule update sent: {}", deviceId);
-        } catch (Exception e) {
-            log.error("Error sending alarm schedule update: {}", deviceId, e);
-        }
-    }
-
-    @Override
-    public void sendDeviceCommand(String deviceId, String command, Map<String, Object> params) {
-        try {
-            Map<String, Object> payload = new HashMap<>();
-            payload.put("command", command);
-            payload.put("params", params);
-            
-            String topic = DeviceConstants.MqttConstant.TOPIC_DEVICE_PREFIX + deviceId + "/command";
-            sendMessage(topic, payload);
-            log.info("Device command sent: {}, command: {}", deviceId, command);
-        } catch (Exception e) {
-            log.error("Error sending device command: {}, command: {}", deviceId, command, e);
-        }
-    }
-
-    @Override
-    public void sendSetDeviceParamCommand(String deviceId, String mountPlain, String area, Float height) {
-        sendDeviceParamSetCommand(deviceId, mountPlain, area, height);
-    }
-
-    @Override
-    public void sendDeviceInfoResponse(String deviceId, Device device) {
-        try {
-            Map<String, Object> payload = new HashMap<>();
-            payload.put("deviceId", deviceId);
-            payload.put("code", 0); // 成功响应码
-            
-            // 设备参数
-            Map<String, Object> deviceParams = new HashMap<>();
-            if (device.getInstallParam() != null) {
-                deviceParams.put("mounting_plain", device.getInstallParam().getMountPlain());
-                deviceParams.put("height", device.getInstallParam().getHeight());
-                
-                // 区域参数
-                if (device.getInstallParam().getTrackingRegion() != null) {
-                    Map<String, Object> area = new HashMap<>();
-                    Device.TrackingRegion region = device.getInstallParam().getTrackingRegion();
-                    area.put("start_x", region.getStartX());
-                    area.put("start_y", region.getStartY());
-                    area.put("start_z", region.getStartZ());
-                    area.put("stop_x", region.getStopX());
-                    area.put("stop_y", region.getStopY());
-                    area.put("stop_z", region.getStopZ());
-                    
-                    deviceParams.put("area", area);
-                }
-            }
-            
-            payload.put("params", deviceParams);
-            
-            String topic = "/mps/get_device_info/response";
-            sendMessage(topic, payload);
-            log.info("Device info response sent: {}", deviceId);
-        } catch (Exception e) {
-            log.error("Error sending device info response: {}", deviceId, e);
-        }
-    }
-
-    @Override
-    public void sendDeviceNotFoundResponse(String deviceId) {
-        try {
-            Map<String, Object> payload = new HashMap<>();
-            payload.put("deviceId", deviceId);
-            payload.put("code", 1); // 设备不存在响应码
-            
-            String topic = "/mps/get_device_info/response";
-            sendMessage(topic, payload);
-            log.info("Device not found response sent: {}", deviceId);
-        } catch (Exception e) {
-            log.error("Error sending device not found response: {}", deviceId, e);
-        }
-    }
-
-    @Override
-    public void sendDeviceResetCommand(String deviceId) {
-        try {
-            Map<String, Object> payload = new HashMap<>();
-            payload.put("command", "reset");
-            
-            String topic = DeviceConstants.MqttConstant.TOPIC_DEVICE_PREFIX + deviceId + "/command";
-            sendMessage(topic, payload);
-            log.info("Device reset command sent: {}", deviceId);
-        } catch (Exception e) {
-            log.error("Error sending device reset command: {}", deviceId, e);
-        }
-    }
-
-    @Override
-    public void sendUpdateNetworkCommand(String deviceId, String ssid, String password) {
-        try {
-            Map<String, Object> payload = new HashMap<>();
-            payload.put("command", "update_network");
-            
-            Map<String, Object> params = new HashMap<>();
-            params.put("ssid", ssid);
-            params.put("password", password);
-            
-            payload.put("params", params);
-            
-            String topic = DeviceConstants.MqttConstant.TOPIC_DEVICE_PREFIX + deviceId + "/command";
-            sendMessage(topic, payload);
-            log.info("Update network command sent: {}", deviceId);
-        } catch (Exception e) {
-            log.error("Error sending update network command: {}", deviceId, e);
-        }
-    }
-
-    @Override
-    public void sendAlarmAckMessage(String deviceId, Long eventId) {
-        try {
-            Map<String, Object> payload = new HashMap<>();
-            payload.put("deviceId", deviceId);
-            payload.put("eventId", eventId);
-            
-            String topic = "/app/fall_event/ack";
-            sendMessage(topic, payload);
-            log.info("Alarm ack message sent: {}, eventId: {}", deviceId, eventId);
-        } catch (Exception e) {
-            log.error("Error sending alarm ack message: {}, eventId: {}", deviceId, eventId, e);
-        }
-    }
-
-    @Override
-    public void sendFallAlarmMessage(String deviceId, int pose, List<Float> targetPoint) {
-        try {
-            Map<String, Object> payload = new HashMap<>();
-            payload.put("message", "notify");
-            payload.put("message_type", DeviceConstants.MessageType.MSG_EVENT_FALL.getCode());
-            payload.put("dev_id", deviceId);
-            payload.put("event", "fall");
-            payload.put("timestamp", System.currentTimeMillis());
-            payload.put("pose", pose);
-            payload.put("target_point", targetPoint);
-            
-            // 对于确认的跌倒事件,使用QoS 2
-            int qos = 2;
-            sendMessage(DeviceConstants.MqttConstant.TOPIC_DAS_EVENT, payload, qos);
-        } catch (Exception e) {
-            log.error("Error sending fall alarm message: {}", deviceId, e);
-        }
-    }
-
-    @Override
-    public boolean sendCommandToDevice(String deviceId, String command, Object payload) {
-        try {
-            String topic = DeviceConstants.MqttConstant.TOPIC_DEVICE_PREFIX + deviceId + "/" + command;
-            sendMessage(topic, payload);
-            log.info("Command sent to device: {}, command: {}", deviceId, command);
-            return true;
-        } catch (Exception e) {
-            log.error("Error sending command to device: {}, command: {}", deviceId, command, e);
-            return false;
-        }
-    }
-
-    @Override
-    public void sendAlarmMessage(String deviceId, String eventType, Map<String, Object> data) {
-        try {
-            Map<String, Object> payload = new HashMap<>();
-            payload.put("message", "notify");
-            payload.put("message_type", DeviceConstants.MessageType.MSG_ALARM_EVENT.getCode());
-            payload.put("dev_id", deviceId);
-            payload.put("event_type", eventType);
-            payload.put("content", data);
-            payload.put("timestamp", System.currentTimeMillis());
-            
-            sendMessage(DeviceConstants.MqttConstant.TOPIC_DAS_ALARM_EVENT, payload);
-            log.info("Alarm message sent: {}, event type: {}", deviceId, eventType);
-        } catch (Exception e) {
-            log.error("Error sending alarm message: {}, event type: {}", deviceId, eventType, e);
-        }
-    }
-    
-    @Override
-    public void sendBehaviorAnalysisResult(String deviceId, Object behaviorPattern) {
-        try {
-            Map<String, Object> payload = new HashMap<>();
-            payload.put("message", "notify");
-            payload.put("message_type", DeviceConstants.MessageType.MSG_BEHAVIOR_ANALYSIS.getCode());
-            payload.put("dev_id", deviceId);
-            payload.put("behavior_pattern", behaviorPattern);
-            payload.put("timestamp", System.currentTimeMillis());
-            
-            sendMessage(DeviceConstants.MqttConstant.TOPIC_DAS_EVENT, payload);
-            log.info("Behavior analysis result sent: {}", deviceId);
-        } catch (Exception e) {
-            log.error("Error sending behavior analysis result: {}", deviceId, e);
-        }
-    }
-
-    @Override
-    public void sendToMqtt(String topic, String payload) {
-        try {
-            Message<String> message = MessageBuilder
-                    .withPayload(payload)
-                    .setHeader("mqtt_topic", topic)
-                    .build();
-            
-            mqttOutbound.handleMessage(message);
-            log.debug("Raw MQTT message sent to topic: {}", topic);
-        } catch (Exception e) {
-            log.error("Error sending raw MQTT message: {}", topic, e);
-        }
-    }
-    
-    @Override
-    public void sendStatusMessage(String deviceId, String status, Map<String, Object> data) {
-        try {
-            Map<String, Object> payload = new HashMap<>(data);
-            payload.put("dev_id", deviceId);
-            payload.put("status", status);
-            payload.put("timestamp", System.currentTimeMillis());
-            
-            sendMessage(DeviceConstants.MqttConstant.TOPIC_DAS_STATUS, payload);
-            log.debug("Status message sent: {}, status: {}", deviceId, status);
-        } catch (Exception e) {
-            log.error("Error sending status message: {}, status: {}", deviceId, status, e);
-        }
-    }
-    
-    @Override
-    public void sendBehaviorMessage(String deviceId, String behaviorType, Map<String, Object> data) {
-        try {
-            Map<String, Object> payload = new HashMap<>();
-            payload.put("message", "notify");
-            payload.put("message_type", DeviceConstants.MessageType.MSG_BEHAVIOR.getCode());
-            payload.put("dev_id", deviceId);
-            payload.put("behavior_type", behaviorType);
-            payload.put("timestamp", System.currentTimeMillis());
-            
-            // 添加数据
-            payload.putAll(data);
-            
-            sendMessage(DeviceConstants.MqttConstant.TOPIC_DAS_BEHAVIOR, payload);
-        } catch (Exception e) {
-            log.error("Error sending behavior message: {}, behavior: {}", deviceId, behaviorType, e);
-        }
-    }
-    
-    /**
-     * 此方法已被新的接口方法替代,保留此方法是为了兼容性
-     * @deprecated 使用 {@link #sendAlarmMessage(String, String, Map)} 替代
-     */
-    @Deprecated
-    public void sendAlarmMessageLegacy(String deviceId, String eventType, Object message) {
-        try {
-            Map<String, Object> data = new HashMap<>();
-            data.put("event_type", eventType);
-            data.put("message", message);
-            
-            // 调用新的方法
-            sendAlarmMessage(deviceId, eventType, data);
-        } catch (Exception e) {
-            log.error("Error sending legacy alarm message: {}, type: {}", deviceId, eventType, e);
-        }
-    }
-
-    @Override
-    public void sendAlarmParamResponse(int code, Map<String, Object> globalConfig) {
-        try {
-            Map<String, Object> payload = new HashMap<>();
-            payload.put("code", code);
-            payload.put("global_config", globalConfig);
-            payload.put("timestamp", System.currentTimeMillis());
-            
-            sendMessage(DeviceConstants.MqttConstant.TOPIC_DAS_ALARM_PARAM_RESPONSE, payload);
-            log.debug("Alarm parameter response sent, code: {}", code);
-        } catch (Exception e) {
-            log.error("Error sending alarm parameter response, code: {}", code, e);
-        }
-    }
-    
-    @Override
-    public void sendSetAlarmParamAck(int code, Map<String, Object> globalConfig) {
-        try {
-            Map<String, Object> payload = new HashMap<>();
-            payload.put("code", code);
-            payload.put("global_config", globalConfig);
-            payload.put("timestamp", System.currentTimeMillis());
-            
-            sendMessage(DeviceConstants.MqttConstant.TOPIC_DAS_SET_ALARM_PARAM_ACK, payload);
-            log.debug("Set alarm parameter acknowledgement sent, code: {}", code);
-        } catch (Exception e) {
-            log.error("Error sending set alarm parameter acknowledgement, code: {}", code, e);
-        }
-    }
-
-    @Override
-    public void sendResponse(String topic, int code, Map<String, Object> data) {
-        try {
-            Map<String, Object> payload = new HashMap<>(data);
-            payload.put("code", code);
-            payload.put("timestamp", System.currentTimeMillis());
-            
-            sendMessage(topic, payload);
-            log.debug("Response sent to topic: {}, code: {}", topic, code);
-        } catch (Exception e) {
-            log.error("Error sending response to topic: {}", topic, e);
-        }
-    }
-
-    private void sendMessage(String topic, Object payload) {
-        sendMessage(topic, payload, 1); // 默认使用QoS 1
-    }
-
-    private void sendMessage(String topic, Object payload, int qos) {
-        try {
-            String json = objectMapper.writeValueAsString(payload);
-            Message<String> message = MessageBuilder.withPayload(json).build();
-            mqttOutbound.setDefaultQos(qos);
-            mqttOutbound.handleMessage(message);
-            log.debug("MQTT message sent to topic: {}, payload: {}", topic, json);
-        } catch (Exception e) {
-            log.error("Error sending MQTT message to topic: {}", topic, e);
-        }
-    }
-
-    @Override
-    public void publish(String topic, Object payload, int qos, boolean retain) {
-        try {
-            Message<String> message = MessageBuilder
-                    .withPayload(objectMapper.writeValueAsString(payload))
-                    .setHeader("mqtt_topic", topic)
-                    .setHeader("mqtt_qos", qos)
-                    .setHeader("mqtt_retained", retain)
-                    .build();
-            
-            mqttOutbound.handleMessage(message);
-            log.debug("Message published to topic: {} with QoS: {}, retain: {}", topic, qos, retain);
-        } catch (Exception e) {
-            log.error("Error publishing message to topic: {}", topic, e);
-        }
-    }
-    
-    @Override
-    public void publishJson(String topic, Object payload) {
-        try {
-            String json = objectMapper.writeValueAsString(payload);
-            Message<String> message = MessageBuilder
-                    .withPayload(json)
-                    .setHeader("mqtt_topic", topic)
-                    .build();
-            
-            mqttOutbound.handleMessage(message);
-            log.debug("JSON message published to topic: {}", topic);
-        } catch (Exception e) {
-            log.error("Error publishing JSON message to topic: {}", topic, e);
-        }
-    }
-    
-    @Override
-    public void publishJson(String topic, Object payload, int qos, boolean retain) {
-        try {
-            String json = objectMapper.writeValueAsString(payload);
-            Message<String> message = MessageBuilder
-                    .withPayload(json)
-                    .setHeader("mqtt_topic", topic)
-                    .setHeader("mqtt_qos", qos)
-                    .setHeader("mqtt_retained", retain)
-                    .build();
-            
-            mqttOutbound.handleMessage(message);
-            log.debug("JSON message published to topic: {} with QoS: {}, retain: {}", topic, qos, retain);
-        } catch (Exception e) {
-            log.error("Error publishing JSON message to topic: {}", topic, e);
-        }
-    }
-    
-    @Override
-    public void sendMessage(String topic, String message) {
-        try {
-            Message<String> mqttMessage = MessageBuilder
-                    .withPayload(message)
-                    .setHeader("mqtt_topic", topic)
-                    .build();
-            
-            mqttOutbound.handleMessage(mqttMessage);
-            log.debug("Message sent to topic: {}", topic);
-        } catch (Exception e) {
-            log.error("Error sending message to topic: {}", topic, e);
-        }
-    }
-    
-    @Override
-    public void sendMessage(String topic, String message, int qos, boolean retain) {
-        try {
-            Message<String> mqttMessage = MessageBuilder
-                    .withPayload(message)
-                    .setHeader("mqtt_topic", topic)
-                    .setHeader("mqtt_qos", qos)
-                    .setHeader("mqtt_retained", retain)
-                    .build();
-            
-            mqttOutbound.handleMessage(mqttMessage);
-            log.debug("Message sent to topic: {} with QoS: {}, retain: {}", topic, qos, retain);
-        } catch (Exception e) {
-            log.error("Error sending message to topic: {}", topic, e);
-        }
-    }
-    
-    @Override
-    public void sendSync(String topic, Object payload) throws Exception {
-        String json = objectMapper.writeValueAsString(payload);
-        Message<String> message = MessageBuilder
-                .withPayload(json)
-                .setHeader("mqtt_topic", topic)
-                .build();
-        
-        mqttOutbound.handleMessage(message);
-        log.debug("Message sent synchronously to topic: {}", topic);
-    }
-    
-    @Override
-    public void subscribe(String topic, int qos) {
-        log.warn("Subscribe method not implemented in MqttGatewayDefaultImpl");
-    }
-    
-    @Override
-    public void unsubscribe(String topic) {
-        log.warn("Unsubscribe method not implemented in MqttGatewayDefaultImpl");
-    }
-    
-    @Override
-    public boolean isConnected() {
-        return true; // 假设始终连接,实际应根据mqttOutbound状态判断
-    }
-    
-    @Override
-    public void disconnect() {
-        log.warn("Disconnect method not implemented in MqttGatewayDefaultImpl");
-    }
-    
-    @Override
-    public void sendGenericMessage(String topic, String messageType, Map<String, Object> messageData) {
-        try {
-            Map<String, Object> payload = new HashMap<>(messageData);
-            payload.put("message_type", messageType);
-            payload.put("timestamp", System.currentTimeMillis());
-            
-            sendMessage(topic, payload);
-            log.debug("Generic message sent to topic: {}, type: {}", topic, messageType);
-        } catch (Exception e) {
-            log.error("Error sending generic message to topic: {}", topic, e);
-        }
-    }
-    
-    @Override
-    public void sendCommand(String topic, String command, Map<String, Object> params) {
-        try {
-            Map<String, Object> payload = new HashMap<>();
-            payload.put("command", command);
-            payload.put("params", params);
-            payload.put("timestamp", System.currentTimeMillis());
-            
-            sendMessage(topic, payload);
-            log.debug("Command sent to topic: {}, command: {}", topic, command);
-        } catch (Exception e) {
-            log.error("Error sending command to topic: {}", topic, e);
-        }
-    }
-} 

+ 0 - 17
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mapper/ClientUserMapper.java

@@ -1,17 +0,0 @@
-//package com.hfln.device.infrastructure.mapper;
-//
-//import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-//import com.hfln.device.infrastructure.po.ClientUserPO;
-//import org.apache.ibatis.annotations.Mapper;
-//
-///**
-// * 瀹㈡埛琛∕apper
-// *
-// * @author huolifu
-// * @date 2023/10/30 16:43
-// **/
-//@Mapper
-//public interface ClientUserMapper extends BaseMapper<ClientUserPO> {
-//}
-
-

+ 0 - 12
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mapper/DevRoomMapper.java

@@ -1,12 +0,0 @@
-package com.hfln.device.infrastructure.mapper;
-
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.hfln.device.infrastructure.po.DevRoom;
-import org.apache.ibatis.annotations.Mapper;
-
-/**
- * 设备房间表 Mapper 接口
- */
-@Mapper
-public interface DevRoomMapper extends BaseMapper<DevRoom> {
-} 

+ 0 - 12
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mapper/DevTargetMapper.java

@@ -1,12 +0,0 @@
-package com.hfln.device.infrastructure.mapper;
-
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.hfln.device.infrastructure.po.DevTarget;
-import org.apache.ibatis.annotations.Mapper;
-
-/**
- * 设备目标表 Mapper 接口
- */
-@Mapper
-public interface DevTargetMapper extends BaseMapper<DevTarget> {
-} 

+ 0 - 12
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mapper/GroupFloorplanMapper.java

@@ -1,12 +0,0 @@
-package com.hfln.device.infrastructure.mapper;
-
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.hfln.device.infrastructure.po.GroupFloorPlan;
-import org.apache.ibatis.annotations.Mapper;
-
-/**
- * 群组平面图表 Mapper 接口
- */
-@Mapper
-public interface GroupFloorplanMapper extends BaseMapper<GroupFloorPlan> {
-} 

+ 0 - 12
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mapper/RecordPlanMapper.java

@@ -1,12 +0,0 @@
-package com.hfln.device.infrastructure.mapper;
-
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.hfln.device.infrastructure.po.RecordPlan;
-import org.apache.ibatis.annotations.Mapper;
-
-/**
- * 录制计划表 Mapper 接口
- */
-@Mapper
-public interface RecordPlanMapper extends BaseMapper<RecordPlan> {
-} 

+ 0 - 12
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mapper/RecordPlanTimeMapper.java

@@ -1,12 +0,0 @@
-package com.hfln.device.infrastructure.mapper;
-
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.hfln.device.infrastructure.po.RecordPlanTime;
-import org.apache.ibatis.annotations.Mapper;
-
-/**
- * 录制计划时间表 Mapper 接口
- */
-@Mapper
-public interface RecordPlanTimeMapper extends BaseMapper<RecordPlanTime> {
-} 

+ 0 - 12
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mapper/StatInfoMapper.java

@@ -1,12 +0,0 @@
-package com.hfln.device.infrastructure.mapper;
-
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.hfln.device.infrastructure.po.StatInfo;
-import org.apache.ibatis.annotations.Mapper;
-
-/**
- * 停留时间表 Mapper 接口
- */
-@Mapper
-public interface StatInfoMapper extends BaseMapper<StatInfo> {
-}

+ 0 - 12
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mapper/TblMenuMapper.java

@@ -1,12 +0,0 @@
-package com.hfln.device.infrastructure.mapper;
-
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.hfln.device.infrastructure.po.TblMenu;
-import org.apache.ibatis.annotations.Mapper;
-
-/**
- * 菜单表 Mapper 接口
- */
-@Mapper
-public interface TblMenuMapper extends BaseMapper<TblMenu> {
-} 

+ 0 - 12
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mapper/TblOprLogMapper.java

@@ -1,12 +0,0 @@
-package com.hfln.device.infrastructure.mapper;
-
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.hfln.device.infrastructure.po.TblOprLog;
-import org.apache.ibatis.annotations.Mapper;
-
-/**
- * 操作日志表 Mapper 接口
- */
-@Mapper
-public interface TblOprLogMapper extends BaseMapper<TblOprLog> {
-} 

+ 0 - 12
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mapper/TblOrgMapper.java

@@ -1,12 +0,0 @@
-package com.hfln.device.infrastructure.mapper;
-
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.hfln.device.infrastructure.po.TblOrg;
-import org.apache.ibatis.annotations.Mapper;
-
-/**
- * 组织机构表 Mapper 接口
- */
-@Mapper
-public interface TblOrgMapper extends BaseMapper<TblOrg> {
-} 

+ 0 - 12
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mapper/TblParameterMapper.java

@@ -1,12 +0,0 @@
-package com.hfln.device.infrastructure.mapper;
-
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.hfln.device.infrastructure.po.TblParameter;
-import org.apache.ibatis.annotations.Mapper;
-
-/**
- * 参数配置表 Mapper 接口
- */
-@Mapper
-public interface TblParameterMapper extends BaseMapper<TblParameter> {
-} 

+ 0 - 12
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mapper/TblRoleMapper.java

@@ -1,12 +0,0 @@
-package com.hfln.device.infrastructure.mapper;
-
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.hfln.device.infrastructure.po.TblRole;
-import org.apache.ibatis.annotations.Mapper;
-
-/**
- * 角色表 Mapper 接口
- */
-@Mapper
-public interface TblRoleMapper extends BaseMapper<TblRole> {
-} 

+ 0 - 12
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mapper/TblUserRoleMapper.java

@@ -1,12 +0,0 @@
-package com.hfln.device.infrastructure.mapper;
-
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.hfln.device.infrastructure.po.TblUserRole;
-import org.apache.ibatis.annotations.Mapper;
-
-/**
- * 用户角色关联表 Mapper 接口
- */
-@Mapper
-public interface TblUserRoleMapper extends BaseMapper<TblUserRole> {
-} 

+ 0 - 12
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mapper/TblWxpaycertMapper.java

@@ -1,12 +0,0 @@
-package com.hfln.device.infrastructure.mapper;
-
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.hfln.device.infrastructure.po.TblWxpaycert;
-import org.apache.ibatis.annotations.Mapper;
-
-/**
- * 微信支付证书表 Mapper 接口
- */
-@Mapper
-public interface TblWxpaycertMapper extends BaseMapper<TblWxpaycert> {
-} 

+ 0 - 362
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mqtt/MqttGatewayEmqxImpl.java

@@ -1,362 +0,0 @@
-//package com.hfln.device.infrastructure.mqtt;
-//
-//import cn.hfln.framework.mqtt.gateway.DefaultMqttGateway;
-//import cn.hfln.framework.mqtt.template.MqttTemplate;
-//import com.alibaba.fastjson2.JSON;
-//import com.hfln.device.common.constant.mqtt.topic.MqttTopics;
-//import com.hfln.device.common.constant.mqtt.topic.TopicConstants;
-//import com.hfln.device.common.util.DateTimeUtil;
-//import com.hfln.device.domain.entity.Device;
-//import com.hfln.device.domain.gateway.MqttGateway;
-//import lombok.extern.slf4j.Slf4j;
-//import org.eclipse.paho.client.mqttv3.MqttClient;
-//import org.springframework.beans.factory.annotation.Autowired;
-//import org.springframework.beans.factory.annotation.Value;
-//import org.springframework.stereotype.Component;
-//
-//import java.util.HashMap;
-//import java.util.List;
-//import java.util.Map;
-//
-///**
-// * MQTT网关EMQX实现类
-// */
-//@Slf4j
-//@Component("mqttGatewayEmqx")
-//public class MqttGatewayEmqxImpl extends DefaultMqttGateway implements MqttGateway {
-//
-//    private static final int QOS = 1;                  // MQTT服务质量等级
-//    private static final boolean RETAIN = true;        // MQTT保留消息标志
-//
-//    @Autowired
-//    public MqttGatewayEmqxImpl(MqttTemplate mqttTemplate, MqttClient mqttClient) {
-//        super(mqttTemplate, mqttClient);
-//    }
-//
-//    @Override
-//    public void initialize() {
-//        super.initialize();
-//        log.info("MqttGatewayEmqx initialized");
-//    }
-//
-//    @Override
-//    public void sendDeviceLoginResponse(String deviceId, int code) {
-//        Map<String, Object> payload = new HashMap<>();
-//        payload.put("deviceId", deviceId);
-//        payload.put("code", code);
-//        payload.put("timestamp", DateTimeUtil.getCurrentTimestamp());
-//
-//        String topic = String.format(TopicConstants.TOPIC_LOGIN_RESPONSE, deviceId);
-//        publishJson(topic, payload, QOS, RETAIN);
-//    }
-//
-//    @Override
-//    public void sendDeviceKeepAliveResponse(String deviceId, int code) {
-//        Map<String, Object> payload = new HashMap<>();
-//        payload.put("deviceId", deviceId);
-//        payload.put("code", code);
-//        payload.put("timestamp", DateTimeUtil.getCurrentTimestamp());
-//
-//        String topic = String.format(TopicConstants.TOPIC_KEEPALIVE_RESPONSE, deviceId);
-//        publishJson(topic, payload, QOS, RETAIN);
-//    }
-//
-//    @Override
-//    public void sendDeviceStatusMessage(Device device) {
-//        Map<String, Object> payload = new HashMap<>();
-//        payload.put("deviceId", device.getDevId());
-//        payload.put("status", device.getOnline());
-//        payload.put("timestamp", DateTimeUtil.getCurrentTimestamp());
-//
-//        String topic = MqttTopics.DAS_STATUS;
-//        publishJson(topic, payload, QOS, RETAIN);
-//    }
-//
-//    @Override
-//    public void sendRealtimePoseMessage(String deviceId, int pose, Object targetPoint) {
-//        Map<String, Object> payload = new HashMap<>();
-//        payload.put("deviceId", deviceId);
-//        payload.put("pose", pose);
-//        payload.put("targetPoint", targetPoint);
-//        payload.put("timestamp", DateTimeUtil.getCurrentTimestamp());
-//
-//        String topic = MqttTopics.DAS_REALTIME_POS;
-//        publishJson(topic, payload, QOS, RETAIN);
-//    }
-//
-//    @Override
-//    public void sendAlarmMessage(String deviceId, String alarmType, Map<String, Object> data) {
-//        Map<String, Object> payload = new HashMap<>(data);
-//        payload.put("deviceId", deviceId);
-//        payload.put("alarmType", alarmType);
-//        payload.put("timestamp", DateTimeUtil.getCurrentTimestamp());
-//
-//        String topic = MqttTopics.DAS_EVENT;
-//        publishJson(topic, payload, QOS, RETAIN);
-//    }
-//
-//    @Override
-//    public void sendEventMessage(String deviceId, int pose, Object targetPoint, String event) {
-//        Map<String, Object> payload = new HashMap<>();
-//        payload.put("deviceId", deviceId);
-//        payload.put("pose", pose);
-//        payload.put("targetPoint", targetPoint);
-//        payload.put("event", event);
-//        payload.put("timestamp", DateTimeUtil.getCurrentTimestamp());
-//
-//        String topic = MqttTopics.DAS_EVENT;
-//        publishJson(topic, payload, QOS, RETAIN);
-//    }
-//
-//    @Override
-//    public void sendAlarmEventMessage(String deviceId, String description, String table, int tableId) {
-//        Map<String, Object> payload = new HashMap<>();
-//        payload.put("deviceId", deviceId);
-//        payload.put("description", description);
-//        payload.put("table", table);
-//        payload.put("tableId", tableId);
-//        payload.put("timestamp", DateTimeUtil.getCurrentTimestamp());
-//
-//        String topic = MqttTopics.DAS_ALARM_EVENT;
-//        publishJson(topic, payload, QOS, RETAIN);
-//    }
-//
-//    @Override
-//    public void sendExistenceMessage(String deviceId, String event) {
-//        Map<String, Object> payload = new HashMap<>();
-//        payload.put("deviceId", deviceId);
-//        payload.put("event", event);
-//        payload.put("timestamp", DateTimeUtil.getCurrentTimestamp());
-//
-//        String topic = MqttTopics.DAS_EXIST_EVENT;
-//        publishJson(topic, payload, QOS, RETAIN);
-//    }
-//
-//    @Override
-//    public void sendDeviceRebootCommand(String deviceId) {
-//        sendDeviceCommand(deviceId, "reboot", null);
-//    }
-//
-//    @Override
-//    public void sendDeviceParamSetCommand(String deviceId, String mountPlain, String area, float height) {
-//        Map<String, Object> params = new HashMap<>();
-//        params.put("mountPlain", mountPlain);
-//        params.put("area", area);
-//        params.put("height", height);
-//
-//        sendDeviceCommand(deviceId, "setParam", params);
-//    }
-//
-//    @Override
-//    public void sendNetworkConfigUpdate(String deviceId, Device.NetworkInfo networkInfo) {
-//        Map<String, Object> payload = new HashMap<>();
-//        payload.put("deviceId", deviceId);
-//        payload.put("networkInfo", networkInfo);
-//        payload.put("timestamp", DateTimeUtil.getCurrentTimestamp());
-//
-//        String topic = TopicConstants.getDeviceSpecificTopic(deviceId, "network_config_update");
-//        publishJson(topic, payload, QOS, RETAIN);
-//    }
-//
-//    @Override
-//    public void sendInstallParamUpdate(String deviceId, Device.InstallParam installParam) {
-//        Map<String, Object> payload = new HashMap<>();
-//        payload.put("deviceId", deviceId);
-//        payload.put("installParam", installParam);
-//        payload.put("timestamp", DateTimeUtil.getCurrentTimestamp());
-//
-//        String topic = TopicConstants.getDeviceSpecificTopic(deviceId, "install_param_update");
-//        publishJson(topic, payload, QOS, RETAIN);
-//    }
-//
-//    @Override
-//    public void sendTrackingRegionUpdate(String deviceId, Device.TrackingRegion trackingRegion) {
-//        Map<String, Object> payload = new HashMap<>();
-//        payload.put("deviceId", deviceId);
-//        payload.put("trackingRegion", trackingRegion);
-//        payload.put("timestamp", DateTimeUtil.getCurrentTimestamp());
-//
-//        String topic = TopicConstants.getDeviceSpecificTopic(deviceId, "tracking_region_update");
-//        publishJson(topic, payload, QOS, RETAIN);
-//    }
-//
-//    @Override
-//    public void sendAlarmScheduleUpdate(String deviceId, Map<String, Object> alarmSchedule) {
-//        Map<String, Object> payload = new HashMap<>();
-//        payload.put("deviceId", deviceId);
-//        payload.put("alarmSchedule", alarmSchedule);
-//        payload.put("timestamp", DateTimeUtil.getCurrentTimestamp());
-//
-//        String topic = TopicConstants.getDeviceSpecificTopic(deviceId, "alarm_schedule_update");
-//        publishJson(topic, payload, QOS, RETAIN);
-//    }
-//
-//    @Override
-//    public void sendDeviceCommand(String deviceId, String command, Map<String, Object> params) {
-//        Map<String, Object> payload = new HashMap<>();
-//        payload.put("deviceId", deviceId);
-//        payload.put("command", command);
-//        if (params != null) {
-//            payload.put("params", params);
-//        }
-//        payload.put("timestamp", DateTimeUtil.getCurrentTimestamp());
-//
-//        String topic = TopicConstants.getDeviceSpecificTopic(deviceId, "command");
-//        publishJson(topic, payload, QOS, RETAIN);
-//    }
-//
-//    @Override
-//    public void sendSetDeviceParamCommand(String deviceId, String mountPlain, String area, Float height) {
-//        Map<String, Object> params = new HashMap<>();
-//        if (mountPlain != null) {
-//            params.put("mountPlain", mountPlain);
-//        }
-//        if (area != null) {
-//            params.put("area", area);
-//        }
-//        if (height != null) {
-//            params.put("height", height);
-//        }
-//
-//        sendDeviceCommand(deviceId, "setParam", params);
-//    }
-//
-//    @Override
-//    public void sendDeviceInfoResponse(String deviceId, Device device) {
-//        Map<String, Object> payload = new HashMap<>();
-//        payload.put("deviceId", deviceId);
-//        payload.put("device", device);
-//        payload.put("timestamp", DateTimeUtil.getCurrentTimestamp());
-//
-//        String topic = MqttTopics.APP_DEVICE_INFO_RESPONSE;
-//        publishJson(topic, payload, QOS, RETAIN);
-//    }
-//
-//    @Override
-//    public void sendDeviceNotFoundResponse(String deviceId) {
-//        Map<String, Object> payload = new HashMap<>();
-//        payload.put("deviceId", deviceId);
-//        payload.put("code", 404);
-//        payload.put("message", "Device not found");
-//        payload.put("timestamp", DateTimeUtil.getCurrentTimestamp());
-//
-//        String topic = MqttTopics.APP_DEVICE_INFO_RESPONSE;
-//        publishJson(topic, payload, QOS, RETAIN);
-//    }
-//
-//    @Override
-//    public void sendDeviceResetCommand(String deviceId) {
-//        sendDeviceCommand(deviceId, "reset", null);
-//    }
-//
-//    @Override
-//    public void sendUpdateNetworkCommand(String deviceId, String ssid, String password) {
-//        Map<String, Object> params = new HashMap<>();
-//        params.put("ssid", ssid);
-//        params.put("password", password);
-//
-//        sendDeviceCommand(deviceId, "updateNetwork", params);
-//    }
-//
-//    @Override
-//    public void sendAlarmAckMessage(String deviceId, Long eventId) {
-//        Map<String, Object> payload = new HashMap<>();
-//        payload.put("deviceId", deviceId);
-//        payload.put("eventId", eventId);
-//        payload.put("timestamp", DateTimeUtil.getCurrentTimestamp());
-//
-//        String topic = MqttTopics.APP_ALARM_ACK;
-//        publishJson(topic, payload, QOS, RETAIN);
-//    }
-//
-//    @Override
-//    public void sendFallAlarmMessage(String deviceId, int pose, List<Float> targetPoint) {
-//        Map<String, Object> payload = new HashMap<>();
-//        payload.put("deviceId", deviceId);
-//        payload.put("pose", pose);
-//        payload.put("targetPoint", targetPoint);
-//        payload.put("event", "fall");
-//        payload.put("timestamp", DateTimeUtil.getCurrentTimestamp());
-//
-//        String topic = MqttTopics.DAS_EVENT;
-//        publishJson(topic, payload, QOS, RETAIN);
-//    }
-//
-//    @Override
-//    public boolean sendCommandToDevice(String deviceId, String command, Object payload) {
-//        try {
-//            Map<String, Object> message = new HashMap<>();
-//            message.put("deviceId", deviceId);
-//            message.put("command", command);
-//            message.put("payload", payload);
-//            message.put("timestamp", DateTimeUtil.getCurrentTimestamp());
-//
-//            String topic = TopicConstants.getDeviceSpecificTopic(deviceId, "command");
-//            publishJson(topic, message, QOS, RETAIN);
-//            return true;
-//        } catch (Exception e) {
-//            log.error("Error sending command to device: {}", deviceId, e);
-//            return false;
-//        }
-//    }
-//
-//    @Override
-//    public void sendStatusMessage(String deviceId, String status, Map<String, Object> data) {
-//        Map<String, Object> payload = new HashMap<>(data);
-//        payload.put("deviceId", deviceId);
-//        payload.put("status", status);
-//        payload.put("timestamp", DateTimeUtil.getCurrentTimestamp());
-//
-//        String topic = MqttTopics.DAS_STATUS;
-//        publishJson(topic, payload, QOS, RETAIN);
-//    }
-//
-//    @Override
-//    public void sendBehaviorMessage(String deviceId, String behaviorType, Map<String, Object> data) {
-//        Map<String, Object> payload = new HashMap<>(data);
-//        payload.put("deviceId", deviceId);
-//        payload.put("behaviorType", behaviorType);
-//        payload.put("timestamp", DateTimeUtil.getCurrentTimestamp());
-//
-//        String topic = MqttTopics.DAS_BEHAVIOR_ANALYSIS;
-//        publishJson(topic, payload, QOS, RETAIN);
-//    }
-//
-//    @Override
-//    public void sendBehaviorAnalysisResult(String deviceId, Object behaviorPattern) {
-//        Map<String, Object> payload = new HashMap<>();
-//        payload.put("deviceId", deviceId);
-//        payload.put("behaviorPattern", behaviorPattern);
-//        payload.put("timestamp", DateTimeUtil.getCurrentTimestamp());
-//
-//        String topic = MqttTopics.DAS_BEHAVIOR_ANALYSIS;
-//        publishJson(topic, payload, QOS, RETAIN);
-//    }
-//
-//    @Override
-//    public void sendToMqtt(String topic, String payload) {
-//        sendMessage(topic, payload, QOS, RETAIN);
-//    }
-//
-//    @Override
-//    public void sendAlarmParamResponse(int code, Map<String, Object> globalConfig) {
-//        Map<String, Object> payload = new HashMap<>();
-//        payload.put("code", code);
-//        payload.put("globalConfig", globalConfig);
-//        payload.put("timestamp", DateTimeUtil.getCurrentTimestamp());
-//
-//        String topic = MqttTopics.DAS_ALARM_PARAM_RESPONSE;
-//        publishJson(topic, payload, QOS, RETAIN);
-//    }
-//
-//    @Override
-//    public void sendSetAlarmParamAck(int code, Map<String, Object> globalConfig) {
-//        Map<String, Object> payload = new HashMap<>();
-//        payload.put("code", code);
-//        payload.put("globalConfig", globalConfig);
-//        payload.put("timestamp", DateTimeUtil.getCurrentTimestamp());
-//
-//        String topic = MqttTopics.DAS_SET_ALARM_PARAM_ACK;
-//        publishJson(topic, payload, QOS, RETAIN);
-//    }
-//}

+ 8 - 3
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mqtt/MqttHandlerImpl.java

@@ -1,6 +1,7 @@
 package com.hfln.device.infrastructure.mqtt;
 
 import com.alibaba.fastjson2.JSONObject;
+import com.hfln.device.common.constant.mqtt.topic.MqttTopics;
 import com.hfln.device.common.constant.mqtt.topic.TopicConstants;
 import com.hfln.device.common.request.device.DeviceBandingParams;
 import com.hfln.device.domain.entity.Device;
@@ -12,6 +13,10 @@ import java.math.BigDecimal;
 import java.util.HashMap;
 import java.util.Map;
 
+/**
+ * MQTT消息处理器
+ * 负责处理设备相关的MQTT消息发送
+ */
 @Component
 public class MqttHandlerImpl {
     // 常量定义
@@ -162,7 +167,7 @@ public class MqttHandlerImpl {
      */
     public void sendBindDeviceResponse(String deviceId, Long userId, boolean result, String message) {
         // 构建主题
-        String topic = "/das/bind_device/response";
+        String topic = MqttTopics.DAS_BIND_DEVICE_RESPONSE;
         
         // 构建消息体
         Map<String, Object> payload = new HashMap<>();
@@ -185,7 +190,7 @@ public class MqttHandlerImpl {
      */
     public void sendUnbindDeviceResponse(String deviceId, Long userId, boolean result, String message) {
         // 构建主题
-        String topic = "/das/unbind_device/response";
+        String topic = MqttTopics.DAS_UNBIND_DEVICE_RESPONSE;
         
         // 构建消息体
         Map<String, Object> payload = new HashMap<>();
@@ -212,7 +217,7 @@ public class MqttHandlerImpl {
      * @param alarmInfo 告警信息
      */
     public void sendAlarmEvent(Map<String, Object> alarmInfo) {
-        String topic = "/das/alarm/event";
+        String topic = MqttTopics.DAS_ALARM_EVENT;
         mqttGateway.publish(topic, alarmInfo);
     }
 } 

+ 0 - 496
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mqtt/MqttMessageHandler.java

@@ -1,496 +0,0 @@
-package com.hfln.device.infrastructure.mqtt;
-
-import com.alibaba.fastjson2.JSON;
-import com.alibaba.fastjson2.JSONObject;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.hfln.device.domain.constant.DeviceConstants;
-import com.hfln.device.domain.entity.Device;
-import com.hfln.device.domain.gateway.DeviceGateway;
-import com.hfln.device.domain.gateway.MqttGateway;
-import com.hfln.device.domain.service.DeviceManagerService;
-import com.hfln.device.domain.port.DeviceEventPort;
-import com.hfln.device.infrastructure.mapper.FallEventMapper;
-import com.hfln.device.infrastructure.po.FallEvent;
-import com.hfln.device.common.constant.mqtt.topic.MqttTopics;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.context.annotation.Bean;
-import org.springframework.integration.annotation.ServiceActivator;
-import org.springframework.messaging.Message;
-import org.springframework.messaging.MessageHandler;
-import org.springframework.messaging.MessagingException;
-import org.springframework.stereotype.Component;
-
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
-import java.time.LocalDateTime;
-
-/**
- * MQTT消息处理器
- * 
- * ⚠️ 注意:为避免与@MqttSubscriber注解方式产生重复消费,
- * 此类中的@ServiceActivator方法已被禁用。
- * 
- * 现在统一使用各个Subscriber类处理MQTT消息:
- * - DeviceMessageSubscriber: 处理设备相关消息
- * - MpsMessageSubscriber: 处理小程序消息  
- * - AppMessageSubscriber: 处理应用消息
- * - OpcMessageSubscriber: 处理OPC消息
- */
-//@Component // 已禁用,使用Spring Integration MQTT替代
-@Slf4j
-public class MqttMessageHandler {
-
-    @Autowired
-    private DeviceManagerService deviceManagerService;
-
-    @Autowired
-    private DeviceGateway deviceGateway;
-
-    @Autowired
-    private MqttGateway mqttGateway;
-
-    @Autowired
-    private FallEventMapper fallEventMapper;
-
-    @Autowired
-    @Qualifier("deviceEventServiceImpl")
-    private DeviceEventPort deviceEventPort;
-
-    private final ObjectMapper objectMapper = new ObjectMapper();
-
-    // 设备登录主题匹配模式
-    private static final Pattern DEV_LOGIN_PATTERN = Pattern.compile(MqttTopics.Pattern.DEV_LOGIN);
-    
-    // 设备保活主题匹配模式
-    private static final Pattern DEV_KEEPALIVE_PATTERN = Pattern.compile(MqttTopics.Pattern.DEV_KEEPALIVE);
-    
-    // 设备上报信息主题匹配模式
-    private static final Pattern DEV_REPORT_INFO_PATTERN = Pattern.compile(MqttTopics.Pattern.DEV_REP_DEV_INFO);
-    
-    // 设备上报参数主题匹配模式
-    private static final Pattern DEV_REPORT_PARAM_PATTERN = Pattern.compile(MqttTopics.Pattern.DEV_REP_DEV_PARAM);
-    
-    // 设备上报跌倒事件主题匹配模式
-    private static final Pattern DEV_REPORT_FALL_PATTERN = Pattern.compile(MqttTopics.Pattern.DEV_REP_FALL_EVENT);
-
-    // 设备上报点云数据主题匹配模式
-    private static final Pattern DEV_CLOUDPOINT_PATTERN = Pattern.compile(MqttTopics.Pattern.DEV_CLOUDPOINT);
-
-    // 设备DSP数据主题匹配模式
-    private static final Pattern DEV_DSP_DATA_PATTERN = Pattern.compile(MqttTopics.Pattern.DEV_DSP_DATA);
-
-    // 小程序跌倒确认主题匹配模式
-    private static final Pattern MPS_FALL_EVENT_ACK_PATTERN = Pattern.compile(MqttTopics.Pattern.MPS_FALL_EVENT_ACK);
-
-    // 设备重启主题匹配模式
-    private static final Pattern DEV_REBOOT_PATTERN = Pattern.compile(MqttTopics.Pattern.MPS_DEV_REBOOT);
-
-    /**
-     * ⚠️ 临时处理器:处理MQTT入站消息
-     * 
-     * 由于cn.hfln.framework.mqtt框架自动创建了入站适配器并发送消息到mqttInputChannel,
-     * 我们需要提供一个处理器来避免"no subscribers"错误。
-     * 
-     * 此处理器仅记录日志,不进行任何业务处理。
-     * 所有实际的业务处理都由各个@MqttSubscriber注解的方法处理。
-     */
-    @Bean
-    @ServiceActivator(inputChannel = "mqttInputChannel")
-    public MessageHandler handleMessage() {
-        return new MessageHandler() {
-            @Override
-            public void handleMessage(Message<?> message) throws MessagingException {
-                try {
-                    String topic = (String) message.getHeaders().get("mqtt_receivedTopic");
-                    String payload = (String) message.getPayload();
-                    
-                    // 仅记录调试日志,不进行任何业务处理
-                    // 所有业务处理由@MqttSubscriber注解的方法完成
-                    log.debug("Spring Integration received MQTT message (ignored): topic={}", topic);
-                    
-                } catch (Exception e) {
-                    log.debug("Error in Spring Integration MQTT handler (ignored): {}", e.getMessage());
-                }
-            }
-        };
-    }
-    
-    /**
-     * ⚠️ 以下方法保留用于工具类用途,不再直接处理MQTT消息
-     * 如果需要在Subscriber中复用这些逻辑,可以将此类改为@Service
-     */
-    
-    /**
-     * 处理设备登录消息
-     */
-    private void handleDeviceLogin(String topic, String payload) {
-        try {
-            JSONObject jsonObject = JSON.parseObject(payload);
-            Map<String, Object> deviceInfo = (Map<String, Object>) jsonObject.get("device_info");
-            
-            if (deviceInfo == null) {
-                log.warn("Invalid device login message, missing device_info: {}", payload);
-                return;
-            }
-            
-            String deviceId = (String) deviceInfo.get("deviceid");
-            
-            // 委托给应用层服务处理,传入完整的payload作为第三个参数
-            Map<String, Object> fullPayload = objectMapper.readValue(payload, HashMap.class);
-            deviceEventPort.handleDeviceLogin(deviceId, deviceInfo, fullPayload);
-            
-        } catch (Exception e) {
-            log.error("Error handling device login: {}", e.getMessage(), e);
-        }
-    }
-    
-    /**
-     * 处理设备保活消息
-     */
-    private void handleDeviceKeepAlive(String topic, String payload) {
-        try {
-            Matcher matcher = DEV_KEEPALIVE_PATTERN.matcher(topic);
-            if (matcher.find()) {
-                String deviceId = matcher.group(1);
-                
-                // 委托给应用层服务处理
-                deviceEventPort.handleDeviceKeepAlive(deviceId);
-            }
-        } catch (Exception e) {
-            log.error("Error handling device keepalive: {}", e.getMessage(), e);
-        }
-    }
-    
-    /**
-     * 处理设备上报信息
-     * 
-     * 注意:Python版本中,设备信息上报不会自动发送状态消息
-     * 仅在设备状态发生变化(如从离线变为在线)时才发送状态通知
-     */
-    private void handleDeviceReportInfo(String topic, String payload) {
-        try {
-            JSONObject message = JSON.parseObject(payload);
-            
-            if (!message.containsKey("deviceid") || 
-                !message.containsKey("device_type") || 
-                !message.containsKey("firmware") || 
-                !message.containsKey("device_ip")) {
-                log.warn("Invalid device info report: {}", payload);
-                return;
-            }
-            
-            String deviceId = (String) message.get("deviceid");
-            String deviceType = (String) message.get("device_type");
-            String software = (String) message.get("firmware");
-            String deviceIp = (String) message.get("device_ip");
-            
-            // 检查设备是否已注册
-            Optional<Device> existingDevice = deviceManagerService.getDeviceFromCache(deviceId);
-            
-            if (existingDevice.isPresent()) {
-                Device device = existingDevice.get();
-                boolean statusChanged = false;
-                
-                // 更新设备信息
-                device.setDevType(deviceType);
-                device.setSoftware(software);
-                if (device.getNetwork() != null) {
-                    device.getNetwork().setIp(deviceIp);
-                }
-                
-                // 仅在设备状态发生变化时才标记需要发送状态消息
-                if (device.getOnline() != 1) {
-                    device.updateOnlineStatus(1);
-                    device.updateKeepAliveTime(System.currentTimeMillis());
-                    statusChanged = true;
-                    
-                    // 更新数据库
-                    deviceGateway.updateDeviceOnlineStatus(deviceId, 1);
-                }
-                
-                deviceManagerService.updateDeviceInCache(device);
-                
-                // 只有在状态发生变化时才发送设备状态通知
-                if (statusChanged) {
-                    mqttGateway.sendDeviceStatusMessage(device);
-                    log.info("Device status changed to online: {}", deviceId);
-                } else {
-                    log.debug("Device info updated without status change: {}", deviceId);
-                }
-            }
-            
-        } catch (Exception e) {
-            log.error("Error handling device report info: {}", e.getMessage(), e);
-        }
-    }
-    
-    /**
-     * 处理设备上报参数
-     * 
-     * 注意:Python版本中,参数更新不会自动发送状态消息
-     * 仅更新设备信息,不进行额外的消息发送
-     */
-    private void handleDeviceReportParam(String topic, String payload) {
-        try {
-            Matcher matcher = DEV_REPORT_PARAM_PATTERN.matcher(topic);
-            if (matcher.find()) {
-                String deviceId = matcher.group(1);
-                JSONObject message = JSON.parseObject(payload);
-                
-                log.debug("Device param report: {}, payload: {}", deviceId, payload);
-                
-                // 获取设备参数
-                Map<String, Object> deviceParams = (Map<String, Object>) message.get("device_param");
-                if (deviceParams != null) {
-                    Optional<Device> existingDevice = deviceManagerService.getDeviceFromCache(deviceId);
-                    
-                    if (existingDevice.isPresent()) {
-                        Device device = existingDevice.get();
-                        
-                        // 更新设备参数
-                        if (deviceParams.containsKey("mounting_plain")) {
-                            String mountPlain = (String) deviceParams.get("mounting_plain");
-                            if (device.getInstallParam() != null) {
-                                device.getInstallParam().setMountPlain(mountPlain);
-                            }
-                        }
-                        
-                        if (deviceParams.containsKey("sensor_height")) {
-                            Float height = ((Number) deviceParams.get("sensor_height")).floatValue();
-                            if (device.getInstallParam() != null) {
-                                device.getInstallParam().setHeight(height);
-                            }
-                        }
-                        
-                        // 更新跟踪区域
-                        Map<String, Object> trackingRegion = (Map<String, Object>) deviceParams.get("tracking_region");
-                        if (trackingRegion != null && device.getInstallParam() != null && 
-                            device.getInstallParam().getTrackingRegion() != null) {
-                            
-                            Device.TrackingRegion region = device.getInstallParam().getTrackingRegion();
-                            
-                            if (trackingRegion.containsKey("start_x")) {
-                                region.setStartX(((Number) trackingRegion.get("start_x")).intValue());
-                            }
-                            if (trackingRegion.containsKey("start_y")) {
-                                region.setStartY(((Number) trackingRegion.get("start_y")).intValue());
-                            }
-                            if (trackingRegion.containsKey("start_z")) {
-                                region.setStartZ(((Number) trackingRegion.get("start_z")).intValue());
-                            }
-                            if (trackingRegion.containsKey("stop_x")) {
-                                region.setStopX(((Number) trackingRegion.get("stop_x")).intValue());
-                            }
-                            if (trackingRegion.containsKey("stop_y")) {
-                                region.setStopY(((Number) trackingRegion.get("stop_y")).intValue());
-                            }
-                            if (trackingRegion.containsKey("stop_z")) {
-                                region.setStopZ(((Number) trackingRegion.get("stop_z")).intValue());
-                            }
-                        }
-                        
-                        // 更新设备缓存
-                        deviceManagerService.updateDeviceInCache(device);
-                        
-                        // 更新数据库
-                        deviceGateway.saveDevice(device);
-                        
-                        // Python版本不在此处发送设备状态消息,仅记录日志
-                        log.info("Device parameters updated: {}", deviceId);
-                    }
-                }
-            }
-        } catch (Exception e) {
-            log.error("Error handling device report param: {}", e.getMessage(), e);
-        }
-    }
-    
-    /**
-     * 处理设备上报跌倒事件
-     */
-    private void handleDeviceReportFall(String topic, String payload) {
-        try {
-            Matcher matcher = DEV_REPORT_FALL_PATTERN.matcher(topic);
-            if (matcher.find()) {
-                String deviceId = matcher.group(1);
-                Map<String, Object> message = objectMapper.readValue(payload, HashMap.class);
-                
-                log.info("Device fall event: {}, payload: {}", deviceId, payload);
-                
-                // 获取跌倒事件信息
-                String event = (String) message.get("event");
-                Integer pose = ((Number) message.get("pose")).intValue();
-                List<Number> targetPointList = (List<Number>) message.get("target_point");
-                
-                // 转换目标点数据
-                List<Float> targetPoint = targetPointList.stream()
-                        .map(number -> number.floatValue())
-                        .collect(Collectors.toList());
-                
-                // 委托给应用层服务处理
-                // 转换为新的方法签名:handleFallEvent(deviceId, timestamp, type, event, fallLocX, fallLocY, fallLocZ, tarHeightEst)
-                Long timestamp = System.currentTimeMillis();
-                Float fallLocX = targetPoint.size() > 0 ? targetPoint.get(0) : 0.0f;
-                Float fallLocY = targetPoint.size() > 1 ? targetPoint.get(1) : 0.0f;
-                Float fallLocZ = targetPoint.size() > 2 ? targetPoint.get(2) : 0.0f;
-                Float tarHeightEst = targetPoint.size() > 3 ? targetPoint.get(3) : 0.0f;
-                
-                deviceEventPort.handleFallEvent(deviceId, timestamp, "fall", event, fallLocX, fallLocY, fallLocZ, tarHeightEst);
-                
-                // 保存事件到数据库
-                if ("fall_confirmed".equals(event)) {
-                    saveFallEvent(deviceId, pose, targetPoint);
-                }
-            }
-        } catch (Exception e) {
-            log.error("Error handling device fall event: {}", e.getMessage(), e);
-        }
-    }
-    
-    /**
-     * 保存跌倒事件
-     */
-    private void saveFallEvent(String deviceId, int pose, List<Float> targetPoint) {
-        try {
-            // 创建跌倒事件记录
-            FallEvent fallEvent = new FallEvent();
-            fallEvent.setDevId(deviceId);
-            fallEvent.setEventTime(new Date());
-            fallEvent.setEventType("fall");
-            fallEvent.setPose(pose);
-            
-            // 设置目标点坐标
-            if (targetPoint != null && targetPoint.size() >= 3) {
-                fallEvent.setTargetX(targetPoint.get(0));
-                fallEvent.setTargetY(targetPoint.get(1));
-                fallEvent.setTargetZ(targetPoint.get(2));
-            }
-            
-            // 设置状态为未处理
-            fallEvent.setStatus(0);
-            
-            // 保存到数据库
-            fallEventMapper.insert(fallEvent);
-            
-            log.info("Fall event saved: {}", deviceId);
-        } catch (Exception e) {
-            log.error("Error saving fall event: {}", e.getMessage(), e);
-        }
-    }
-    
-    /**
-     * 处理设备上报点云数据
-     * 
-     * 注意:Python版本中,点云数据的处理更加谨慎
-     * 不会自动发送实时姿态消息,仅进行数据记录和处理
-     */
-    private void handleDeviceCloudPoint(String topic, String payload) {
-        try {
-            Matcher matcher = DEV_CLOUDPOINT_PATTERN.matcher(topic);
-            if (matcher.find()) {
-                String deviceId = matcher.group(1);
-                Map<String, Object> message = objectMapper.readValue(payload, HashMap.class);
-                
-                log.debug("Device cloud point: {}", deviceId);
-                
-                // 获取点云数据
-                List<List<Number>> pointCloud = (List<List<Number>>) message.get("point_cloud");
-                
-                // Python版本中,点云数据主要用于算法处理
-                // 不会自动转发实时姿态消息,仅进行内部处理
-                // 这里可以添加算法处理,如姿态识别等
-                
-                // 注释掉自动转发功能,避免重复消息
-                // mqttGateway.sendRealtimePoseMessage(deviceId, 
-                //         DeviceConstants.PoseEnum.POSE_STANDING.getCode(), // 默认姿态
-                //         pointCloud.get(0)); // 使用第一个点作为目标点
-                
-                log.debug("Cloud point data processed for device: {}", deviceId);
-            }
-        } catch (Exception e) {
-            log.error("Error handling device cloud point: {}", e.getMessage(), e);
-        }
-    }
-    
-    /**
-     * 处理设备DSP数据
-     */
-    private void handleDeviceDspData(String topic, String payload) {
-        try {
-            Matcher matcher = DEV_DSP_DATA_PATTERN.matcher(topic);
-            if (matcher.find()) {
-                String deviceId = matcher.group(1);
-                
-                log.debug("Device DSP data: {}", deviceId);
-                
-                // 这里可以添加DSP数据处理逻辑
-                // Python版本中,DSP数据主要用于内部算法处理
-            }
-        } catch (Exception e) {
-            log.error("Error handling device DSP data: {}", e.getMessage(), e);
-        }
-    }
-    
-    /**
-     * 处理跌倒事件确认
-     */
-    private void handleFallEventAck(String topic, String payload) {
-        try {
-            Map<String, Object> message = objectMapper.readValue(payload, HashMap.class);
-            
-            String deviceId = (String) message.get("deviceId");
-            Long eventId = ((Number) message.get("eventId")).longValue();
-            
-            // 委托给应用层服务处理
-            deviceEventPort.handleAlarmAck(deviceId, eventId);
-            
-        } catch (Exception e) {
-            log.error("Error handling fall event acknowledgement: {}", e.getMessage(), e);
-        }
-    }
-    
-    /**
-     * 处理设备重启命令
-     */
-    private void handleDeviceReboot(String topic, String payload) {
-        try {
-            Matcher matcher = DEV_REBOOT_PATTERN.matcher(topic);
-            if (matcher.find()) {
-                String deviceId = matcher.group(1);
-                
-                log.info("Device reboot command: {}", deviceId);
-                
-                // 向设备发送重启命令
-                mqttGateway.sendDeviceRebootCommand(deviceId);
-            }
-        } catch (Exception e) {
-            log.error("Error handling device reboot command: {}", e.getMessage(), e);
-        }
-    }
-    
-    /**
-     * 匹配主题
-     */
-    private boolean matchTopic(Pattern pattern, String topic) {
-        return pattern.matcher(topic).matches();
-    }
-    
-    /**
-     * 从主题中提取设备ID
-     */
-    private String extractDeviceId(Pattern pattern, String topic) {
-        Matcher matcher = pattern.matcher(topic);
-        if (matcher.find()) {
-            return matcher.group(1);
-        }
-        return null;
-    }
-} 

+ 0 - 299
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mqtt/MqttSubscriberHandler.java

@@ -1,299 +0,0 @@
-//package com.hfln.device.infrastructure.mqtt;
-//
-//import cn.hfln.framework.mqtt.template.MqttTemplate;
-//import com.alibaba.fastjson2.JSONObject;
-//import com.hfln.device.application.service.DeviceCommandService;
-//import com.hfln.device.application.service.DeviceEventService;
-//import com.hfln.device.common.constant.mqtt.topic.TopicConstants;
-//import com.hfln.device.domain.entity.Device;
-//import lombok.extern.slf4j.Slf4j;
-//import org.springframework.beans.factory.annotation.Autowired;
-//import org.springframework.stereotype.Component;
-//
-//import java.util.HashMap;
-//import java.util.Map;
-//
-///**
-// * MQTT消息订阅处理器
-// * 负责接收MQTT消息并调用应用层服务处理业务逻辑
-// */
-//@Component
-//@Slf4j
-//public class MqttSubscriberHandler {
-//
-//    private static final int QOS = 1;
-//    private static final boolean RETAIN = true;
-//
-//    @Autowired
-//    private MqttTemplate mqttTemplate;
-//
-//    @Autowired
-//    private DeviceCommandService deviceCommandService;
-//
-//    @Autowired
-//    private DeviceEventService deviceEventService;
-//
-//    /**
-//     * 处理设备登录消息
-//     */
-//    public void handleDeviceLogin(String deviceId, Map<String, Object> deviceInfo) {
-//        log.info("处理设备登录消息: deviceId={}", deviceId);
-//
-//        // 调用应用层服务处理设备登录,传入完整的payload作为第三个参数
-//        deviceEventService.handleDeviceLogin(deviceId, deviceInfo, deviceInfo);
-//
-//        // 发送登录响应消息
-//        sendLoginResponse(deviceId);
-//    }
-//
-//    /**
-//     * 发送登录响应消息
-//     */
-//    private void sendLoginResponse(String deviceId) {
-//        String topic = String.format(TopicConstants.TOPIC_LOGIN_RESPONSE, deviceId);
-//
-//        JSONObject message = new JSONObject();
-//        message.put("message", "login_response");
-//        message.put("timestamp", System.currentTimeMillis());
-//        message.put("dev_id", deviceId);
-//        message.put("result", true);
-//
-//        // 发送MQTT消息
-//        mqttTemplate.sendJson(topic, message, QOS, false);
-//
-//        log.info("发送设备登录响应: deviceId={}", deviceId);
-//    }
-//
-//    /**
-//     * 处理设备保活消息
-//     */
-//    public void handleDeviceKeepAlive(String deviceId) {
-//        log.info("处理设备保活消息: deviceId={}", deviceId);
-//
-//        // 更新设备保活时间
-//        deviceEventService.updateDeviceKeepAliveTime(deviceId, System.currentTimeMillis());
-//    }
-//
-//    /**
-//     * 处理设备状态更新消息
-//     */
-//    public void handleDeviceStatusUpdate(String deviceId, boolean online) {
-//        log.info("处理设备状态更新消息: deviceId={}, online={}", deviceId, online);
-//
-//        // 更新设备在线状态
-//        deviceEventService.updateDeviceOnlineStatus(deviceId, online ? 1 : 0);
-//    }
-//
-//    /**
-//     * 处理设备停留时间消息
-//     */
-//    public void handleDeviceStayTime(String deviceId, Long enterTime, Long leaveTime, String stayTime) {
-//        log.info("处理设备停留时间消息: deviceId={}, enterTime={}, leaveTime={}", deviceId, enterTime, leaveTime);
-//
-//        // 记录设备停留时间
-//        deviceEventService.recordDeviceStayTime(deviceId, enterTime, leaveTime, stayTime);
-//    }
-//
-//    /**
-//     * 处理设备滞留告警消息
-//     */
-//    public void handleDeviceRetentionAlarm(String deviceId, Long alarmTime, String alarmType, String description) {
-//        log.info("处理设备滞留告警消息: deviceId={}, alarmTime={}, alarmType={}", deviceId, alarmTime, alarmType);
-//
-//        // 记录设备滞留告警
-//        deviceEventService.recordDeviceRetentionAlarm(deviceId, alarmTime, alarmType, description);
-//    }
-//
-//    /**
-//     * 处理绑定设备请求
-//     */
-//    public void handleBindDeviceRequest(String deviceId, Long userId) {
-//        log.info("处理绑定设备请求: deviceId={}, userId={}", deviceId, userId);
-//
-//        // 调用应用层服务绑定设备
-//        boolean result = deviceCommandService.bindDevice(deviceId, userId);
-//
-//        // 发送绑定响应
-//        Map<String, Object> responseData = new HashMap<>();
-//        responseData.put("deviceId", deviceId);
-//        responseData.put("userId", userId);
-//        responseData.put("result", result);
-//        responseData.put("message", result ? "绑定成功" : "绑定失败");
-//        deviceCommandService.publishBindDeviceResponse(responseData);
-//    }
-//
-//    /**
-//     * 处理解绑设备请求
-//     */
-//    public void handleUnbindDeviceRequest(String deviceId, Long userId) {
-//        log.info("处理解绑设备请求: deviceId={}, userId={}", deviceId, userId);
-//
-//        // 调用应用层服务解绑设备
-//        boolean result = deviceCommandService.unbindDevice(deviceId, userId);
-//
-//        // 发送解绑响应
-//        Map<String, Object> responseData = new HashMap<>();
-//        responseData.put("deviceId", deviceId);
-//        responseData.put("userId", userId);
-//        responseData.put("result", result);
-//        responseData.put("message", result ? "解绑成功" : "解绑失败");
-//        deviceCommandService.publishUnbindDeviceResponse(responseData);
-//    }
-//
-//    /**
-//     * 处理更新设备网络配置请求
-//     */
-//    public void handleUpdateNetworkRequest(String deviceId, Device.NetworkInfo networkInfo) {
-//        log.info("处理更新设备网络配置请求: deviceId={}", deviceId);
-//
-//        // 更新到新接口
-//        deviceCommandService.handleUpdateDeviceNetwork(deviceId,
-//                networkInfo.getSsid(), networkInfo.getPassword());
-//    }
-//
-//    /**
-//     * 处理更新设备安装参数请求
-//     */
-//    public void handleUpdateInstallParamRequest(String deviceId, Device.InstallParam installParam) {
-//        log.info("处理更新设备安装参数请求: deviceId={}", deviceId);
-//
-//        // 更新到新接口
-//        String area = null;
-//        if (installParam.getTrackingRegion() != null) {
-//            area = String.format("%d,%d,%d,%d,%d,%d",
-//                installParam.getTrackingRegion().getStartX(),
-//                installParam.getTrackingRegion().getStartY(),
-//                installParam.getTrackingRegion().getStartZ(),
-//                installParam.getTrackingRegion().getStopX(),
-//                installParam.getTrackingRegion().getStopY(),
-//                installParam.getTrackingRegion().getStopZ());
-//        }
-//
-//        deviceCommandService.handleSetDeviceParam(deviceId,
-//                installParam.getMountPlain(), area, installParam.getHeight());
-//    }
-//
-//    /**
-//     * 处理更新设备告警计划请求
-//     */
-//    public void handleUpdateAlarmScheduleRequest(String deviceId, Map<String, Object> alarmSchedule) {
-//        log.info("处理更新设备告警计划请求: deviceId={}", deviceId);
-//
-//        // 使用新的告警参数设置接口
-//        deviceCommandService.handleSetAlarmParam(alarmSchedule);
-//    }
-//
-//    /**
-//     * 发送设备告警事件消息
-//     */
-//    public void sendAlarmEvent(Map<String, Object> alarmInfo) {
-//        String deviceId = alarmInfo.get("dev_id").toString();
-//        String description = alarmInfo.get("desc").toString();
-//        String table = alarmInfo.get("table").toString();
-//        int tableId = Integer.parseInt(alarmInfo.get("table_id").toString());
-//
-//        // 调用应用层服务发送告警事件
-//        deviceEventService.sendAlarmEventMessage(deviceId, description, table, tableId);
-//    }
-//
-//    /**
-//     * 发送设备状态更新消息
-//     */
-//    public void sendDeviceStatusUpdate(Device device) {
-//        String deviceId = device.getDevId();
-//        String topic = String.format(TopicConstants.TOPIC_DEV_UPDATE, deviceId);
-//
-//        JSONObject message = new JSONObject();
-//        message.put("message", "notify");
-//        message.put("timestamp", System.currentTimeMillis());
-//        message.put("dev_id", deviceId);
-//        message.put("online", device.getOnline() == 1);
-//        message.put("dev_type", device.getDevType());
-//        message.put("firmware", device.getSoftware());
-//        message.put("hardware", device.getHardware());
-//
-//        if (device.getNetwork() != null) {
-//            JSONObject network = new JSONObject();
-//            network.put("ssid", device.getNetwork().getSsid());
-//            network.put("password", device.getNetwork().getPassword());
-//            network.put("ip", device.getNetwork().getIp());
-//            message.put("network", network);
-//        }
-//
-//        if (device.getInstallParam() != null) {
-//            JSONObject radarParam = new JSONObject();
-//            radarParam.put("mount_plain", device.getInstallParam().getMountPlain());
-//            radarParam.put("height", device.getInstallParam().getHeight());
-//
-//            if (device.getInstallParam().getTrackingRegion() != null) {
-//                JSONObject trackingRegion = new JSONObject();
-//                trackingRegion.put("start_x", device.getInstallParam().getTrackingRegion().getStartX());
-//                trackingRegion.put("start_y", device.getInstallParam().getTrackingRegion().getStartY());
-//                trackingRegion.put("start_z", device.getInstallParam().getTrackingRegion().getStartZ());
-//                trackingRegion.put("stop_x", device.getInstallParam().getTrackingRegion().getStopX());
-//                trackingRegion.put("stop_y", device.getInstallParam().getTrackingRegion().getStopY());
-//                trackingRegion.put("stop_z", device.getInstallParam().getTrackingRegion().getStopZ());
-//                radarParam.put("tracking_region", trackingRegion);
-//            }
-//
-//            message.put("radar_param", radarParam);
-//        }
-//
-//        // 发送MQTT消息
-//        mqttTemplate.sendJson(topic, message, QOS, RETAIN);
-//    }
-//
-//    /**
-//     * 发送设备状态更新消息
-//     */
-//    public void sendDeviceStatusUpdate(String deviceId, Map<String, Object> statusInfo) {
-//        String topic = String.format(TopicConstants.TOPIC_DEV_UPDATE, deviceId);
-//
-//        JSONObject message = new JSONObject();
-//        message.put("message", "notify");
-//        message.put("timestamp", System.currentTimeMillis());
-//        message.put("dev_id", deviceId);
-//
-//        // 添加状态信息
-//        for (Map.Entry<String, Object> entry : statusInfo.entrySet()) {
-//            message.put(entry.getKey(), entry.getValue());
-//        }
-//
-//        // 发送MQTT消息
-//        mqttTemplate.sendJson(topic, message, QOS, RETAIN);
-//    }
-//
-//    /**
-//     * 发送设备绑定响应消息
-//     */
-//    public void sendBindDeviceResponse(String deviceId, Long userId, boolean result, String message) {
-//        log.info("发送设备绑定响应: deviceId={}, userId={}, result={}", deviceId, userId, result);
-//
-//        // 构建响应消息
-//        Map<String, Object> responseData = new HashMap<>();
-//        responseData.put("deviceId", deviceId);
-//        responseData.put("userId", userId);
-//        responseData.put("result", result);
-//        responseData.put("message", message);
-//
-//        // 使用新接口发送响应
-//        deviceCommandService.publishBindDeviceResponse(responseData);
-//    }
-//
-//    /**
-//     * 发送设备解绑响应消息
-//     */
-//    public void sendUnbindDeviceResponse(String deviceId, Long userId, boolean result, String message) {
-//        log.info("发送设备解绑响应: deviceId={}, userId={}, result={}", deviceId, userId, result);
-//
-//        // 构建响应消息
-//        Map<String, Object> responseData = new HashMap<>();
-//        responseData.put("deviceId", deviceId);
-//        responseData.put("userId", userId);
-//        responseData.put("result", result);
-//        responseData.put("message", message);
-//
-//        // 使用新接口发送响应
-//        deviceCommandService.publishUnbindDeviceResponse(responseData);
-//    }
-//}

+ 312 - 30
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mqtt/handler/AppMessageHandler.java

@@ -17,8 +17,27 @@ import java.util.Optional;
 
 /**
  * 应用消息处理器
- * 使用Spring Integration MQTT替代@MqttSubscriber注解
- * 处理来自移动应用的MQTT消息
+ * 基于Spring Integration MQTT替代@MqttSubscriber注解
+ * 
+ * 业务流程说明:
+ * 1. 接收来自移动应用端(APP)的MQTT消息
+ * 2. 根据不同的主题路由到相应的处理方法
+ * 3. 处理用户与设备的交互操作
+ * 4. 维护设备状态和用户操作记录
+ * 
+ * 支持的应用消息类型:
+ * - 跌倒事件确认 (fall_event_ack) - 用户确认收到跌倒告警
+ * - 设备绑定 (bind_device) - 用户添加新设备到监控列表
+ * - 设备解绑 (unbind_device) - 用户移除设备
+ * - 设备参数设置 (set_device_param) - 用户调整设备配置
+ * 
+ * 应用场景:
+ * - 家属通过手机APP管理老人监护设备
+ * - 医护人员通过管理系统配置设备参数
+ * - 告警确认和设备状态管理
+ * 
+ * @author 设备接入服务
+ * @version 1.0
  */
 @Component
 @Slf4j
@@ -34,6 +53,17 @@ public class AppMessageHandler {
     @Autowired
     private DeviceManagerService deviceManagerService;
 
+    /**
+     * MQTT消息统一入口处理方法
+     * 
+     * 业务流程:
+     * 1. 从消息头提取MQTT主题和负载
+     * 2. 根据主题类型路由到具体的处理方法
+     * 3. 记录用户操作日志
+     * 4. 异常情况统一捕获和处理
+     * 
+     * @param message Spring Integration封装的MQTT消息对象
+     */
     public void handleMessage(Message<?> message) {
         try {
             String topic = (String) message.getHeaders().get("mqtt_receivedTopic");
@@ -72,41 +102,77 @@ public class AppMessageHandler {
 
     /**
      * 处理跌倒事件确认
+     * 
+     * Python对应方法:deal_fall_event_ack
+     * 业务流程:
+     * 1. 解析跌倒事件确认消息
+     * 2. 验证设备ID的有效性
+     * 3. 检查设备是否存在于缓存中
+     * 4. 检查告警是否已经被确认(避免重复确认)
+     * 5. 更新设备的告警确认状态
+     * 6. 记录告警确认时间戳
+     * 7. 刷新设备缓存信息
+     * 8. 停止告警通知流程
+     * 
+     * 告警确认机制说明:
+     * - 当设备检测到跌倒事件时,会向相关人员发送告警
+     * - 用户收到告警后,可以通过APP确认告警
+     * - 确认后停止重复通知,但保留告警记录
+     * - 每个告警只能确认一次,重复确认会被忽略
+     * 
+     * 消息格式:
+     * {
+     *   "dev_id": "设备ID",
+     *   "event_id": "事件ID(可选)",
+     *   "user_id": "确认用户ID(可选)"
+     * }
+     * 
+     * @param topic MQTT主题:/app/fall_event/ack
+     * @param payload JSON格式的确认消息
      */
     private void handleFallEventAck(String topic, String payload) {
         try {
             Map<String, Object> messageData = JsonUtil.parseMap(payload);
             
-            log.debug("Received fall event ack: {}", payload);
+            log.info("Processing fall event acknowledgment: {}", payload);
             
             String devId = (String) messageData.get("dev_id");
             if (devId == null) {
-                log.debug("error: invalid param, {}", topic);
+                log.warn("Invalid fall event ack message, missing dev_id: {}", payload);
                 return;
             }
             
-            // 获取设备
+            // 获取设备信息
             Optional<Device> deviceOpt = deviceManagerService.getDeviceFromCache(devId);
             if (!deviceOpt.isPresent()) {
-                log.debug("error: deal_fall_event_ack, no device: {}", devId);
+                log.warn("Fall event ack for non-existent device: {}", devId);
                 return;
             }
             
             Device device = deviceOpt.get();
             
-            // 检查设备是否已确认
+            // 检查设备是否已确认告警
             if (Boolean.TRUE.equals(device.getAlarmAck())) {
-                return; // 已确认,直接返回
+                log.info("Fall event already acknowledged for device: {}", devId);
+                return; // 已确认,直接返回避免重复处理
             }
             
             // 设置告警确认状态和时间
-            long now = System.currentTimeMillis();
+            long currentTime = System.currentTimeMillis();
             device.setAlarmAck(true);
-            device.setLastAlarmAckTime(now);
+            device.setLastAlarmAckTime(currentTime);
+            
+            // 记录确认操作
+            String userId = (String) messageData.get("user_id");
+            String eventId = (String) messageData.get("event_id");
+            log.info("Fall event acknowledged for device: {}, user: {}, event: {}, time: {}", 
+                    devId, userId, eventId, currentTime);
             
             // 更新设备缓存
             deviceManagerService.updateDeviceInCache(device);
             
+            log.info("Fall alarm acknowledgment processed successfully for device: {}", devId);
+            
         } catch (Exception e) {
             log.error("Error handling fall event ack: {}", e.getMessage(), e);
         }
@@ -114,63 +180,187 @@ public class AppMessageHandler {
     
     /**
      * 处理添加设备请求
+     * 
+     * Python对应方法:deal_add_device
+     * 业务流程:
+     * 1. 解析添加设备请求消息
+     * 2. 验证设备ID的格式和有效性
+     * 3. 检查设备是否已经存在于系统中
+     * 4. 从数据库查询设备的详细信息
+     * 5. 验证设备的授权和权限
+     * 6. 将设备添加到用户的监控列表
+     * 7. 初始化设备状态和配置
+     * 8. 发送添加结果响应给APP
+     * 
+     * 设备添加流程:
+     * - 用户通过扫描二维码或输入设备ID添加设备
+     * - 系统验证设备的合法性和可用性
+     * - 建立用户与设备的绑定关系
+     * - 初始化设备的默认配置参数
+     * 
+     * 权限控制:
+     * - 每个设备只能被有限数量的用户绑定
+     * - 需要验证用户是否有权限添加该设备
+     * - 管理员可以强制解除设备绑定
+     * 
+     * @param topic MQTT主题:/app/bind_device
+     * @param payload JSON格式的添加设备请求
      */
     private void handleAddDevice(String topic, String payload) {
         try {
             Map<String, Object> messageData = JsonUtil.parseMap(payload);
             
-            log.debug("Received add device request: {}", payload);
+            log.info("Processing add device request: {}", payload);
             
             String devId = (String) messageData.get("dev_id");
-            if (devId == null) {
+            if (devId == null || devId.trim().isEmpty()) {
+                log.warn("Invalid add device message, missing or empty dev_id: {}", payload);
                 return;
             }
             
-            // 查询数据库
-            log.debug("TODO: Query device info from database for devId: {}", devId);
+            // 验证设备ID格式(假设设备ID有特定格式要求)
+            if (!isValidDeviceId(devId)) {
+                log.warn("Invalid device ID format: {}", devId);
+                return;
+            }
+            
+            // 检查设备是否已经存在于缓存中
+            Optional<Device> existingDevice = deviceManagerService.getDeviceFromCache(devId);
+            if (existingDevice.isPresent()) {
+                log.info("Device {} already exists in system", devId);
+                // 可以选择更新设备信息或返回已存在的状态
+            }
+            
+            // 获取用户信息(如果消息中包含)
+            String userId = (String) messageData.get("user_id");
+            String userType = (String) messageData.get("user_type");
+            
+            log.info("User {} ({}) attempting to add device: {}", userId, userType, devId);
+            
+            // 委托给应用层服务处理设备添加逻辑
+            // 应用层将处理:数据库查询、权限验证、绑定关系建立、配置初始化
+            deviceCommandService.handleAddDevice(devId);
+            
+            log.info("Add device request submitted for processing: {}", devId);
             
         } catch (Exception e) {
-            log.debug("deal_add_device error: {}", e.getMessage());
+            log.error("Error handling add device request: {}", e.getMessage(), e);
         }
     }
     
     /**
      * 处理删除设备请求
+     * 
+     * Python对应方法:deal_del_device
+     * 业务流程:
+     * 1. 解析删除设备请求消息
+     * 2. 验证设备ID和用户权限
+     * 3. 检查设备是否存在于系统中
+     * 4. 验证用户是否有权限删除该设备
+     * 5. 解除用户与设备的绑定关系
+     * 6. 清理设备相关的配置和数据
+     * 7. 从缓存中移除设备信息
+     * 8. 发送删除结果响应给APP
+     * 
+     * 设备删除影响:
+     * - 解除用户与设备的监控关系
+     * - 停止该设备的告警通知
+     * - 清理相关的配置数据
+     * - 保留历史数据用于审计
+     * 
+     * 安全考虑:
+     * - 只有设备的绑定用户可以删除设备
+     * - 管理员可以强制删除任何设备
+     * - 删除操作需要记录审计日志
+     * 
+     * @param topic MQTT主题:/app/unbind_device
+     * @param payload JSON格式的删除设备请求
      */
     private void handleDeleteDevice(String topic, String payload) {
         try {
             Map<String, Object> messageData = JsonUtil.parseMap(payload);
             
-            log.debug("Received delete device request: {}", payload);
+            log.info("Processing delete device request: {}", payload);
             
             String devId = (String) messageData.get("dev_id");
-            if (devId == null) {
+            if (devId == null || devId.trim().isEmpty()) {
+                log.warn("Invalid delete device message, missing or empty dev_id: {}", payload);
                 return;
             }
             
             // 检查设备是否存在
             Optional<Device> deviceOpt = deviceManagerService.getDeviceFromCache(devId);
             if (!deviceOpt.isPresent()) {
-                log.debug("error: deal_del_device, no device: {}", devId);
+                log.warn("Attempt to delete non-existent device: {}", devId);
                 return;
             }
             
-            // 删除设备
+            Device device = deviceOpt.get();
+            
+            // 获取用户信息进行权限验证
+            String userId = (String) messageData.get("user_id");
+            String userType = (String) messageData.get("user_type");
+            
+            log.info("User {} ({}) attempting to delete device: {}", userId, userType, devId);
+            
+            // 记录设备删除前的状态
+            log.info("Deleting device: {} - Current status: online={}, last_seen={}", 
+                    devId, device.getOnline(), device.getLastAlarmAckTime());
+            
+            // 从缓存中移除设备
             deviceManagerService.removeDeviceFromCache(devId);
             
+            // 委托给应用层服务处理设备删除的后续逻辑
+            // 应用层将处理:数据库清理、绑定关系解除、历史数据归档
+            deviceCommandService.handleDeleteDevice(devId);
+            
+            log.info("Device deletion processed successfully: {}", devId);
+            
         } catch (Exception e) {
-            log.error("deal_del_device error: {}", e.getMessage());
+            log.error("Error handling delete device request: {}", e.getMessage(), e);
         }
     }
     
     /**
      * 处理设备参数设置请求
+     * 
+     * Python对应方法:deal_set_dev_param
+     * 业务流程:
+     * 1. 解析设备参数设置请求
+     * 2. 验证所有必需字段的完整性
+     * 3. 检查设备是否存在且在线
+     * 4. 验证参数值的合理性和安全性
+     * 5. 构造参数设置命令
+     * 6. 向设备发送参数配置指令
+     * 7. 等待设备确认参数设置结果
+     * 8. 更新数据库中的设备配置
+     * 
+     * 支持的参数类型:
+     * - mounting_plain: 设备安装平面类型(顶装/侧装)
+     * - height: 设备安装高度(米)
+     * - area: 监测区域坐标范围
+     *   - start_x, start_y, start_z: 区域起始坐标
+     *   - stop_x, stop_y, stop_z: 区域结束坐标
+     * 
+     * 参数验证规则:
+     * - 高度范围:1.5-4.0米
+     * - 区域坐标:在设备检测范围内
+     * - 安装平面:只能是预定义的几种类型
+     * 
+     * 坐标系说明:
+     * - 以设备为原点的3D坐标系
+     * - X轴:水平方向(左右)
+     * - Y轴:水平方向(前后)
+     * - Z轴:垂直方向(上下)
+     * 
+     * @param topic MQTT主题:/app/set_device_param
+     * @param payload JSON格式的参数设置请求
      */
     private void handleSetDeviceParam(String topic, String payload) {
         try {
             Map<String, Object> messageData = JsonUtil.parseMap(payload);
             
-            log.debug("Received set device param request: {}", payload);
+            log.info("Processing set device param request: {}", payload);
             
             // 严格验证所有必需字段
             String devId = (String) messageData.get("dev_id");
@@ -178,21 +368,37 @@ public class AppMessageHandler {
             Number heightNum = (Number) messageData.get("height");
             Map<String, Object> area = (Map<String, Object>) messageData.get("area");
             
+            // 字段完整性检查
             if (devId == null || mountingPlain == null || heightNum == null || area == null ||
                 !area.containsKey("start_x") || !area.containsKey("start_y") || !area.containsKey("start_z") ||
                 !area.containsKey("stop_x") || !area.containsKey("stop_y") || !area.containsKey("stop_z")) {
-                log.debug("error: invalid param, {}", topic);
+                log.warn("Invalid set device param message, missing required fields: {}", payload);
                 return;
             }
             
             // 检查设备是否存在
             Optional<Device> deviceOpt = deviceManagerService.getDeviceFromCache(devId);
             if (!deviceOpt.isPresent()) {
-                log.debug("error: no device: {}, {}", devId, topic);
+                log.warn("Attempt to set parameters for non-existent device: {}", devId);
                 return;
             }
             
+            Device device = deviceOpt.get();
             Float height = heightNum.floatValue();
+            
+            // 参数合理性验证
+            if (height < 1.5f || height > 4.0f) {
+                log.warn("Invalid height value for device {}: {}m (must be 1.5-4.0m)", devId, height);
+                return;
+            }
+            
+            // 验证安装平面类型
+            if (!isValidMountingPlain(mountingPlain)) {
+                log.warn("Invalid mounting plain for device {}: {}", devId, mountingPlain);
+                return;
+            }
+            
+            // 提取并验证区域坐标
             Number startX = (Number) area.get("start_x");
             Number startY = (Number) area.get("start_y");
             Number startZ = (Number) area.get("start_z");
@@ -200,16 +406,92 @@ public class AppMessageHandler {
             Number stopY = (Number) area.get("stop_y");
             Number stopZ = (Number) area.get("stop_z");
             
-            // 格式化区域字符串
-            String areaStr = String.format("%s,%s,%s,%s,%s,%s", 
-                startX, stopX, startY, stopY, startZ, stopZ);
+            // 验证坐标的合理性
+            if (!isValidAreaCoordinates(startX, startY, startZ, stopX, stopY, stopZ)) {
+                log.warn("Invalid area coordinates for device {}: start=({},{},{}), stop=({},{},{})", 
+                        devId, startX, startY, startZ, stopX, stopY, stopZ);
+                return;
+            }
+            
+            // 格式化区域字符串(按照设备协议要求的格式)
+            String areaStr = String.format("%.2f,%.2f,%.2f,%.2f,%.2f,%.2f", 
+                startX.floatValue(), stopX.floatValue(), 
+                startY.floatValue(), stopY.floatValue(), 
+                startZ.floatValue(), stopZ.floatValue());
             
-            // 向设备端发送参数设置命令
-            log.debug("TODO: Send device param setting command for devId: {}, mountingPlain: {}, area: {}, height: {}", 
-                     devId, mountingPlain, areaStr, height);
+            log.info("Setting parameters for device {}: mounting={}, height={}m, area={}", 
+                    devId, mountingPlain, height, areaStr);
+            
+            // 检查设备在线状态
+            if (!Boolean.TRUE.equals(device.getOnline())) {
+                log.warn("Attempting to set parameters for offline device: {}", devId);
+                // 可以选择暂存参数配置,待设备上线后下发
+            }
+            
+            // 委托给应用层服务处理参数设置
+            // 应用层将处理:参数下发、设备确认、数据库更新、配置同步
+            deviceCommandService.handleSetDeviceParam(devId, mountingPlain, areaStr, height);
+            
+            log.info("Device parameter setting request submitted for device: {}", devId);
             
         } catch (Exception e) {
-            log.error("deal_set_dev_param error: {}", e.getMessage());
+            log.error("Error handling set device param request: {}", e.getMessage(), e);
+        }
+    }
+    
+    /**
+     * 验证设备ID格式是否合法
+     * 
+     * @param devId 设备ID
+     * @return true如果格式合法,false否则
+     */
+    private boolean isValidDeviceId(String devId) {
+        // 实现设备ID格式验证逻辑
+        // 例如:长度检查、字符集检查、校验位验证等
+        return devId != null && devId.length() >= 6 && devId.length() <= 32 
+               && devId.matches("^[a-zA-Z0-9_-]+$");
+    }
+    
+    /**
+     * 验证安装平面类型是否有效
+     * 
+     * @param mountingPlain 安装平面类型
+     * @return true如果类型有效,false否则
+     */
+    private boolean isValidMountingPlain(String mountingPlain) {
+        // 定义有效的安装平面类型
+        return "ceiling".equals(mountingPlain) || "wall".equals(mountingPlain) 
+               || "table".equals(mountingPlain) || "floor".equals(mountingPlain);
+    }
+    
+    /**
+     * 验证区域坐标是否合理
+     * 
+     * @param startX, startY, startZ 起始坐标
+     * @param stopX, stopY, stopZ 结束坐标
+     * @return true如果坐标合理,false否则
+     */
+    private boolean isValidAreaCoordinates(Number startX, Number startY, Number startZ,
+                                         Number stopX, Number stopY, Number stopZ) {
+        // 检查坐标值是否为null
+        if (startX == null || startY == null || startZ == null ||
+            stopX == null || stopY == null || stopZ == null) {
+            return false;
+        }
+        
+        // 检查坐标范围是否合理(假设设备检测范围为10m x 10m x 3m)
+        float[] coords = {startX.floatValue(), startY.floatValue(), startZ.floatValue(),
+                         stopX.floatValue(), stopY.floatValue(), stopZ.floatValue()};
+        
+        for (float coord : coords) {
+            if (coord < -10.0f || coord > 10.0f) {
+                return false;
+            }
         }
+        
+        // 检查起始坐标是否小于结束坐标
+        return startX.floatValue() < stopX.floatValue() &&
+               startY.floatValue() < stopY.floatValue() &&
+               startZ.floatValue() < stopZ.floatValue();
     }
 } 

+ 400 - 21
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mqtt/handler/DeviceMessageHandler.java

@@ -17,8 +17,27 @@ import java.util.stream.Collectors;
 
 /**
  * 设备消息处理器
- * 使用Spring Integration MQTT替代@MqttSubscriber注解
- * 处理设备相关的MQTT消息
+ * 基于Spring Integration MQTT替代@MqttSubscriber注解
+ * 
+ * 业务流程说明:
+ * 1. 接收来自设备端(雷达传感器)的MQTT消息
+ * 2. 根据不同的主题路由到相应的处理方法
+ * 3. 解析消息内容并进行数据验证
+ * 4. 委托给应用层服务进行业务处理
+ * 
+ * 支持的设备消息类型:
+ * - 设备登录/注册 (login)
+ * - 设备心跳保活 (keepalive)  
+ * - 设备信息上报 (report_device_info)
+ * - 设备参数上报 (report_device_param)
+ * - 实时数据流 (dsp_data)
+ * - 点云数据 (cloudpoint)
+ * - 跌倒事件上报 (report_falling_event)
+ * - 存在事件上报 (report_presence_event)
+ * - 调试参数设置/获取 (set_debug_param/get_debug_param)
+ * 
+ * @author 设备接入服务
+ * @version 1.0
  */
 @Component
 @Slf4j
@@ -30,6 +49,17 @@ public class DeviceMessageHandler {
     @Qualifier("deviceEventServiceImpl")
     private DeviceEventPort deviceEventPort;
 
+    /**
+     * MQTT消息统一入口处理方法
+     * 
+     * 业务流程:
+     * 1. 从消息头提取MQTT主题和负载
+     * 2. 从主题路径中提取操作类型(action)
+     * 3. 根据操作类型路由到具体的处理方法
+     * 4. 异常情况统一捕获和日志记录
+     * 
+     * @param message Spring Integration封装的MQTT消息对象
+     */
     public void handleMessage(Message<?> message) {
         try {
             String topic = (String) message.getHeaders().get("mqtt_receivedTopic");
@@ -92,10 +122,32 @@ public class DeviceMessageHandler {
 
     /**
      * 处理设备登录消息
+     * 
+     * Python对应方法:deal_dev_login
+     * 业务流程:
+     * 1. 解析设备登录消息,提取device_info信息
+     * 2. 验证设备ID和设备信息的完整性
+     * 3. 更新设备在线状态和最后登录时间
+     * 4. 将设备信息存储到Redis缓存中
+     * 5. 向DAS服务发送设备登录响应
+     * 6. 如果是新设备,触发设备注册流程
+     * 
+     * 消息格式:
+     * {
+     *   "device_info": {
+     *     "deviceid": "设备ID",
+     *     "device_type": "设备类型",
+     *     "firmware": "固件版本",
+     *     "device_ip": "设备IP地址"
+     *   }
+     * }
+     * 
+     * @param topic MQTT主题,格式:/dev/{device_id}/login
+     * @param payload JSON格式的消息内容
      */
     private void handleDeviceLogin(String topic, String payload) {
         try {
-            log.info("Received device login message: {}", topic);
+            log.info("Processing device login message: {}", topic);
             
             Map<String, Object> messageData = JsonUtil.parseMap(payload);
             Map<String, Object> deviceInfo = (Map<String, Object>) messageData.get("device_info");
@@ -107,7 +159,17 @@ public class DeviceMessageHandler {
             
             String deviceId = (String) deviceInfo.get("deviceid");
             
+            // 验证必要字段
+            if (deviceId == null || deviceInfo.get("device_type") == null || 
+                deviceInfo.get("firmware") == null || deviceInfo.get("device_ip") == null) {
+                log.warn("Invalid device login message, missing required fields: {}", payload);
+                return;
+            }
+            
+            log.info("Device {} attempting to login with info: {}", deviceId, deviceInfo);
+            
             // 委托给应用层服务处理
+            // 应用层将处理:设备认证、状态更新、缓存刷新、响应发送
             deviceEventPort.handleDeviceLogin(deviceId, deviceInfo, messageData);
             
         } catch (Exception e) {
@@ -117,14 +179,36 @@ public class DeviceMessageHandler {
 
     /**
      * 处理设备保活消息
+     * 
+     * Python对应方法:deal_dev_keepalive
+     * 业务流程:
+     * 1. 从主题中提取设备ID
+     * 2. 更新设备的最后心跳时间
+     * 3. 更新设备在线状态为ONLINE
+     * 4. 刷新Redis缓存中的设备信息
+     * 5. 向设备发送心跳响应确认
+     * 6. 重置设备离线计时器
+     * 
+     * 心跳机制说明:
+     * - 设备每隔30秒发送一次心跳
+     * - 服务端超过90秒未收到心跳则判定设备离线
+     * - 心跳消息通常不带额外数据载荷
+     * 
+     * @param topic MQTT主题,格式:/dev/{device_id}/keepalive
+     * @param payload 通常为空或包含简单的时间戳
      */
     private void handleDeviceKeepAlive(String topic, String payload) {
         try {
             String deviceId = extractDeviceIdFromTopic(topic);
             if (deviceId != null) {
-                log.debug("Received device keepalive: {}", deviceId);
+                log.debug("Processing device keepalive: {}", deviceId);
+                
+                // 记录心跳接收时间用于离线检测
+                long currentTime = System.currentTimeMillis();
+                log.trace("Device {} heartbeat received at: {}", deviceId, currentTime);
                 
                 // 委托给应用层服务处理
+                // 应用层将处理:在线状态更新、心跳时间记录、离线检测重置
                 deviceEventPort.handleDeviceKeepAlive(deviceId);
             }
         } catch (Exception e) {
@@ -134,6 +218,28 @@ public class DeviceMessageHandler {
 
     /**
      * 处理设备上报设备信息
+     * 
+     * Python对应方法:deal_dev_report_device_info
+     * 业务流程:
+     * 1. 解析设备信息报告消息
+     * 2. 验证设备ID、设备类型、固件版本、IP地址等必要字段
+     * 3. 更新数据库中的设备基本信息
+     * 4. 刷新Redis缓存中的设备信息
+     * 5. 检查固件版本是否需要升级
+     * 6. 向设备发送信息接收确认
+     * 
+     * 消息格式:
+     * {
+     *   "deviceid": "设备ID",
+     *   "device_type": "雷达传感器类型",
+     *   "firmware": "固件版本号",
+     *   "device_ip": "设备IP地址",
+     *   "mac_address": "MAC地址",
+     *   "serial_number": "序列号"
+     * }
+     * 
+     * @param topic MQTT主题,格式:/dev/{device_id}/report_device_info
+     * @param payload JSON格式的设备信息
      */
     private void handleDeviceReportDeviceInfo(String topic, String payload) {
         try {
@@ -141,7 +247,7 @@ public class DeviceMessageHandler {
             if (deviceId != null) {
                 Map<String, Object> messageData = JsonUtil.parseMap(payload);
                 
-                log.info("Device info report: {}, payload: {}", deviceId, payload);
+                log.info("Processing device info report: {}, payload: {}", deviceId, payload);
                 
                 // 验证必要字段
                 if (!messageData.containsKey("deviceid") || !messageData.containsKey("device_type") ||
@@ -150,7 +256,16 @@ public class DeviceMessageHandler {
                     return;
                 }
                 
+                // 记录设备信息更新
+                String deviceType = (String) messageData.get("device_type");
+                String firmware = (String) messageData.get("firmware");
+                String deviceIp = (String) messageData.get("device_ip");
+                
+                log.info("Device {} info: type={}, firmware={}, ip={}", 
+                        deviceId, deviceType, firmware, deviceIp);
+                
                 // 委托给应用层服务处理
+                // 应用层将处理:设备信息验证、数据库更新、缓存刷新、版本检查
                 deviceEventPort.handleDeviceLogin(deviceId, messageData, messageData);
             }
         } catch (Exception e) {
@@ -160,6 +275,24 @@ public class DeviceMessageHandler {
 
     /**
      * 处理设备上报设备参数
+     * 
+     * Python对应方法:deal_dev_report_device_param
+     * 业务流程:
+     * 1. 解析设备参数报告消息
+     * 2. 验证参数的有效性和完整性
+     * 3. 更新数据库中的设备配置参数
+     * 4. 刷新Redis缓存中的设备参数
+     * 5. 检查参数是否与期望配置一致
+     * 6. 如有差异,重新下发正确的参数配置
+     * 
+     * 参数类型包括:
+     * - 安装参数:mounting_plain(安装平面)、height(安装高度)
+     * - 跟踪区域:tracking_region(监测区域坐标)
+     * - 告警计划:alarm_schedule(告警时间表)
+     * - 调试参数:debug_param(调试配置)
+     * 
+     * @param topic MQTT主题,格式:/dev/{device_id}/report_device_param
+     * @param payload JSON格式的设备参数
      */
     private void handleDeviceReportDeviceParam(String topic, String payload) {
         try {
@@ -167,9 +300,21 @@ public class DeviceMessageHandler {
             if (deviceId != null) {
                 Map<String, Object> messageData = JsonUtil.parseMap(payload);
                 
-                log.info("Device parameter report: {}, payload: {}", deviceId, payload);
+                log.info("Processing device parameter report: {}, payload: {}", deviceId, payload);
+                
+                // 检查参数类型并记录
+                if (messageData.containsKey("mounting_plain") || messageData.containsKey("height")) {
+                    log.debug("Device {} reported installation parameters", deviceId);
+                }
+                if (messageData.containsKey("tracking_region")) {
+                    log.debug("Device {} reported tracking region", deviceId);
+                }
+                if (messageData.containsKey("alarm_schedule")) {
+                    log.debug("Device {} reported alarm schedule", deviceId);
+                }
                 
                 // 委托给应用层服务处理
+                // 应用层将处理:参数验证、数据库更新、配置同步、差异检查
                 deviceEventPort.handleDeviceParamReport(deviceId, messageData);
             }
         } catch (Exception e) {
@@ -178,7 +323,25 @@ public class DeviceMessageHandler {
     }
 
     /**
-     * 处理设备实时数据
+     * 处理设备实时数据流
+     * 
+     * Python对应方法:deal_dev_dsp_data
+     * 业务流程:
+     * 1. 接收设备的DSP(数字信号处理)数据
+     * 2. 解析实时传感器数据
+     * 3. 进行数据质量检查和异常过滤
+     * 4. 存储到时序数据库(如InfluxDB)
+     * 5. 触发实时行为分析算法
+     * 6. 检测异常模式并生成告警
+     * 
+     * DSP数据特点:
+     * - 高频率:每秒多次上报
+     * - 大数据量:包含复杂的传感器数据
+     * - 实时性要求:需要快速处理和响应
+     * - 主要用于行为模式识别和异常检测
+     * 
+     * @param topic MQTT主题,格式:/dev/{device_id}/dsp_data
+     * @param payload JSON格式的DSP数据,包含传感器原始数据
      */
     private void handleDeviceDspData(String topic, String payload) {
         try {
@@ -186,9 +349,23 @@ public class DeviceMessageHandler {
             if (deviceId != null) {
                 Map<String, Object> messageData = JsonUtil.parseMap(payload);
                 
-                log.debug("Device dsp data: {}", deviceId);
+                log.trace("Processing device DSP data: {}", deviceId); // 使用trace级别避免日志过多
+                
+                // 检查数据完整性
+                if (messageData.containsKey("timestamp")) {
+                    Long timestamp = ((Number) messageData.get("timestamp")).longValue();
+                    long currentTime = System.currentTimeMillis();
+                    long delay = currentTime - timestamp;
+                    
+                    // 检查数据时延
+                    if (delay > 5000) { // 超过5秒的数据认为过期
+                        log.warn("Device {} DSP data is too old: delay={}ms", deviceId, delay);
+                        return;
+                    }
+                }
                 
                 // 委托给应用层服务处理
+                // 应用层将处理:数据质量检查、时序存储、行为分析、异常检测
                 deviceEventPort.handleDspData(deviceId, messageData);
             }
         } catch (Exception e) {
@@ -198,6 +375,25 @@ public class DeviceMessageHandler {
 
     /**
      * 处理设备点云数据
+     * 
+     * Python对应方法:deal_dev_cloudpoint
+     * 业务流程:
+     * 1. 接收雷达设备生成的3D点云数据
+     * 2. 解析点云坐标和跟踪目标信息
+     * 3. 进行点云数据预处理和噪声过滤
+     * 4. 存储到专用的点云数据库
+     * 5. 触发3D空间分析算法
+     * 6. 生成人体姿态和位置信息
+     * 7. 检测跌倒和异常行为模式
+     * 
+     * 点云数据结构:
+     * - cloud_points: 3D点云坐标数组 [[x,y,z], ...]
+     * - tracker_targets: 跟踪目标数组 [[x,y,z], ...]
+     * - 坐标系:通常以设备为原点的3D坐标系
+     * - 单位:通常为米或厘米
+     * 
+     * @param topic MQTT主题,格式:/dev/{device_id}/cloudpoint
+     * @param payload JSON格式的点云数据
      */
     private void handleDeviceCloudPoint(String topic, String payload) {
         try {
@@ -205,13 +401,30 @@ public class DeviceMessageHandler {
             if (deviceId != null) {
                 Map<String, Object> messageData = JsonUtil.parseMap(payload);
                 
-                log.debug("Device cloud point data: {}", deviceId);
+                log.trace("Processing device cloud point data: {}", deviceId);
                 
                 // 获取点云数据和目标点
                 List<List<Number>> cloudPoints = (List<List<Number>>) messageData.get("cloud_points");
                 List<List<Number>> trackerTargets = (List<List<Number>>) messageData.get("tracker_targets");
                 
-                // 转换数据类型
+                // 数据质量检查
+                if (cloudPoints != null && !cloudPoints.isEmpty()) {
+                    log.trace("Device {} cloud points count: {}", deviceId, cloudPoints.size());
+                    
+                    // 检查点云数据的合理性
+                    for (List<Number> point : cloudPoints) {
+                        if (point.size() != 3) {
+                            log.warn("Invalid cloud point format in device {}: {}", deviceId, point);
+                            return;
+                        }
+                    }
+                }
+                
+                if (trackerTargets != null && !trackerTargets.isEmpty()) {
+                    log.trace("Device {} tracker targets count: {}", deviceId, trackerTargets.size());
+                }
+                
+                // 转换数据类型为Float以确保精度
                 List<List<Float>> cloudPointsFloat = null;
                 if (cloudPoints != null) {
                     cloudPointsFloat = cloudPoints.stream()
@@ -231,6 +444,7 @@ public class DeviceMessageHandler {
                 }
                 
                 // 委托给应用层服务处理
+                // 应用层将处理:点云处理、3D分析、姿态识别、行为检测
                 deviceEventPort.handleCloudPoint(deviceId, cloudPointsFloat, trackerTargetsFloat);
             }
         } catch (Exception e) {
@@ -240,6 +454,28 @@ public class DeviceMessageHandler {
 
     /**
      * 处理设备上报跌倒事件
+     * 
+     * Python对应方法:deal_dev_report_falling_event
+     * 业务流程:
+     * 1. 接收设备检测到的跌倒事件
+     * 2. 验证跌倒事件数据的完整性
+     * 3. 记录跌倒发生的时间、位置、严重程度
+     * 4. 触发紧急告警流程
+     * 5. 通知相关人员(家属、医护人员)
+     * 6. 存储到告警事件数据库
+     * 7. 等待人工确认或自动解除
+     * 
+     * 跌倒事件数据:
+     * - timestamp: 跌倒发生时间戳
+     * - type: 事件类型(通常为"fall")
+     * - event: 具体事件描述
+     * - fallLocX/Y/Z: 跌倒位置坐标(厘米单位)
+     * - tarHeightEst: 目标高度估计值
+     * 
+     * 坐标转换:设备上报的坐标通常以厘米为单位,需要转换为米
+     * 
+     * @param topic MQTT主题,格式:/dev/{device_id}/report_falling_event
+     * @param payload JSON格式的跌倒事件数据
      */
     private void handleDeviceReportFallEvent(String topic, String payload) {
         try {
@@ -247,27 +483,32 @@ public class DeviceMessageHandler {
             if (deviceId != null) {
                 Map<String, Object> messageData = JsonUtil.parseMap(payload);
                 
-                log.info("Device fall event: {}, payload: {}", deviceId, payload);
+                log.warn("FALL EVENT DETECTED - Device: {}, payload: {}", deviceId, payload);
                 
                 // 验证必要字段
                 if (!messageData.containsKey("timestamp") || !messageData.containsKey("type") ||
                     !messageData.containsKey("event") || !messageData.containsKey("fallLocX") ||
                     !messageData.containsKey("fallLocY") || !messageData.containsKey("fallLocZ") ||
                     !messageData.containsKey("tarHeightEst")) {
-                    log.warn("Invalid fall event message, missing required fields: {}", payload);
+                    log.error("Invalid fall event message, missing required fields: {}", payload);
                     return;
                 }
                 
                 Long timestamp = ((Number) messageData.get("timestamp")).longValue();
                 String type = (String) messageData.get("type");
                 String event = (String) messageData.get("event");
-                // 坐标单位转换:厘米转米
+                
+                // 坐标单位转换:厘米转米(设备上报的坐标通常是厘米单位)
                 Float fallLocX = ((Number) messageData.get("fallLocX")).floatValue() / 100.0f;
                 Float fallLocY = ((Number) messageData.get("fallLocY")).floatValue() / 100.0f;
                 Float fallLocZ = ((Number) messageData.get("fallLocZ")).floatValue() / 100.0f;
                 Float tarHeightEst = ((Number) messageData.get("tarHeightEst")).floatValue();
                 
+                log.error("CRITICAL: Fall detected at device {} - Location: ({}, {}, {}), Height: {}, Time: {}", 
+                         deviceId, fallLocX, fallLocY, fallLocZ, tarHeightEst, timestamp);
+                
                 // 委托给应用层服务处理
+                // 应用层将处理:告警生成、通知发送、数据库记录、确认等待
                 deviceEventPort.handleFallEvent(deviceId, timestamp, type, event, 
                     fallLocX, fallLocY, fallLocZ, tarHeightEst);
             }
@@ -278,6 +519,30 @@ public class DeviceMessageHandler {
 
     /**
      * 处理设备上报存在事件
+     * 
+     * Python对应方法:deal_dev_report_presence_event
+     * 业务流程:
+     * 1. 接收设备检测到的人员存在/离开事件
+     * 2. 验证存在事件数据的有效性
+     * 3. 更新人员活动状态记录
+     * 4. 统计人员在场时间和活动模式
+     * 5. 检测长时间无活动的异常情况
+     * 6. 生成活动报告和统计数据
+     * 
+     * 存在事件类型:
+     * - "presence_detected": 检测到人员存在
+     * - "presence_lost": 人员离开监测区域
+     * - "motion_detected": 检测到活动
+     * - "motion_stopped": 活动停止
+     * 
+     * 业务价值:
+     * - 用于老人日常活动监测
+     * - 异常行为模式识别
+     * - 生活规律分析
+     * - 健康状况评估
+     * 
+     * @param topic MQTT主题,格式:/dev/{device_id}/report_presence_event
+     * @param payload JSON格式的存在事件数据
      */
     private void handleDeviceReportPresenceEvent(String topic, String payload) {
         try {
@@ -285,7 +550,7 @@ public class DeviceMessageHandler {
             if (deviceId != null) {
                 Map<String, Object> messageData = JsonUtil.parseMap(payload);
                 
-                log.info("Device presence event: {}, payload: {}", deviceId, payload);
+                log.info("Processing device presence event: {}, payload: {}", deviceId, payload);
                 
                 // 验证必要字段
                 if (!messageData.containsKey("timestamp") || !messageData.containsKey("type") ||
@@ -298,7 +563,31 @@ public class DeviceMessageHandler {
                 String type = (String) messageData.get("type");
                 String event = (String) messageData.get("event");
                 
+                // 记录存在事件的详细信息
+                log.info("Device {} presence event: type={}, event={}, time={}", 
+                        deviceId, type, event, timestamp);
+                
+                // 根据事件类型进行不同的处理
+                switch (event) {
+                    case "presence_detected":
+                        log.info("Person entered monitoring area of device {}", deviceId);
+                        break;
+                    case "presence_lost":
+                        log.info("Person left monitoring area of device {}", deviceId);
+                        break;
+                    case "motion_detected":
+                        log.debug("Motion detected by device {}", deviceId);
+                        break;
+                    case "motion_stopped":
+                        log.debug("Motion stopped at device {}", deviceId);
+                        break;
+                    default:
+                        log.debug("Unknown presence event: {} from device {}", event, deviceId);
+                        break;
+                }
+                
                 // 委托给应用层服务处理
+                // 应用层将处理:状态更新、活动统计、模式分析、异常检测
                 deviceEventPort.handleExistEvent(deviceId, timestamp, type, event);
             }
         } catch (Exception e) {
@@ -307,7 +596,31 @@ public class DeviceMessageHandler {
     }
 
     /**
-     * 处理设置调试参数
+     * 处理设置调试参数请求
+     * 
+     * Python对应方法:deal_set_debug_param
+     * 业务流程:
+     * 1. 接收调试参数设置请求
+     * 2. 验证参数的合法性和安全性
+     * 3. 更新设备的调试配置
+     * 4. 向设备下发新的调试参数
+     * 5. 等待设备确认参数设置结果
+     * 6. 记录调试参数变更日志
+     * 
+     * 调试参数类型:
+     * - 检测灵敏度设置
+     * - 算法参数调整
+     * - 日志级别控制
+     * - 数据采集频率
+     * - 测试模式开关
+     * 
+     * 安全考虑:
+     * - 只允许授权用户修改调试参数
+     * - 关键参数修改需要审批
+     * - 所有变更都有审计日志
+     * 
+     * @param topic MQTT主题,格式:/dev/{device_id}/set_debug_param
+     * @param payload JSON格式的调试参数数据
      */
     private void handleSetDebugParam(String topic, String payload) {
         try {
@@ -315,9 +628,30 @@ public class DeviceMessageHandler {
             if (deviceId != null) {
                 Map<String, Object> messageData = JsonUtil.parseMap(payload);
                 
-                log.info("Set debug param: {}, payload: {}", deviceId, payload);
+                log.info("Processing set debug param request: {}, payload: {}", deviceId, payload);
+                
+                // 记录调试参数设置请求
+                if (messageData.containsKey("debug_level")) {
+                    log.info("Setting debug level for device {}: {}", deviceId, messageData.get("debug_level"));
+                }
+                if (messageData.containsKey("sensitivity")) {
+                    log.info("Setting sensitivity for device {}: {}", deviceId, messageData.get("sensitivity"));
+                }
+                if (messageData.containsKey("test_mode")) {
+                    log.info("Setting test mode for device {}: {}", deviceId, messageData.get("test_mode"));
+                }
+                
+                // 安全检查:验证调试参数的合理范围
+                if (messageData.containsKey("sensitivity")) {
+                    Number sensitivity = (Number) messageData.get("sensitivity");
+                    if (sensitivity.doubleValue() < 0 || sensitivity.doubleValue() > 100) {
+                        log.warn("Invalid sensitivity value for device {}: {}", deviceId, sensitivity);
+                        return;
+                    }
+                }
                 
                 // 委托给应用层服务处理
+                // 应用层将处理:参数验证、权限检查、设备下发、状态跟踪
                 deviceEventPort.handleSetDebugParam(deviceId, messageData);
             }
         } catch (Exception e) {
@@ -326,7 +660,31 @@ public class DeviceMessageHandler {
     }
 
     /**
-     * 处理获取调试参数
+     * 处理获取调试参数请求
+     * 
+     * Python对应方法:deal_get_debug_param
+     * 业务流程:
+     * 1. 接收调试参数查询请求
+     * 2. 验证请求者的权限
+     * 3. 从设备或缓存中获取当前调试参数
+     * 4. 构造参数响应消息
+     * 5. 通过MQTT发送参数信息给请求方
+     * 
+     * 返回的调试参数包括:
+     * - 当前检测灵敏度
+     * - 算法版本和参数
+     * - 日志级别设置
+     * - 设备运行状态
+     * - 性能统计信息
+     * 
+     * 用途:
+     * - 远程调试和故障排查
+     * - 性能监控和优化
+     * - 设备状态检查
+     * - 参数配置验证
+     * 
+     * @param topic MQTT主题,格式:/dev/{device_id}/get_debug_param
+     * @param payload JSON格式的查询请求
      */
     private void handleGetDebugParam(String topic, String payload) {
         try {
@@ -334,9 +692,19 @@ public class DeviceMessageHandler {
             if (deviceId != null) {
                 Map<String, Object> messageData = JsonUtil.parseMap(payload);
                 
-                log.info("Get debug param: {}, payload: {}", deviceId, payload);
+                log.info("Processing get debug param request: {}, payload: {}", deviceId, payload);
+                
+                // 检查查询的参数类型
+                if (messageData.containsKey("param_type")) {
+                    String paramType = (String) messageData.get("param_type");
+                    log.debug("Requested debug param type for device {}: {}", deviceId, paramType);
+                }
+                
+                // 记录调试参数查询请求
+                log.debug("Debug param query from device {} with request: {}", deviceId, messageData);
                 
                 // 委托给应用层服务处理
+                // 应用层将处理:权限验证、参数获取、响应构造、消息发送
                 deviceEventPort.handleGetDebugParam(deviceId, messageData);
             }
         } catch (Exception e) {
@@ -345,7 +713,13 @@ public class DeviceMessageHandler {
     }
 
     /**
-     * 从主题中提取设备ID
+     * 从MQTT主题中提取设备ID
+     * 
+     * 支持的主题格式:/dev/{device_id}/{action}
+     * 使用正则表达式匹配主题路径中的设备ID部分
+     * 
+     * @param topic MQTT主题字符串
+     * @return 设备ID,如果解析失败返回null
      */
     private String extractDeviceIdFromTopic(String topic) {
         Matcher matcher = DEV_ID_PATTERN.matcher(topic);
@@ -356,8 +730,13 @@ public class DeviceMessageHandler {
     }
     
     /**
-     * 从主题中提取操作名称(最后一段)
-     * 格式:/dev/{device_id}/{action}
+     * 从MQTT主题中提取操作名称(最后一段路径)
+     * 
+     * 主题格式:/dev/{device_id}/{action}
+     * 例如:/dev/123456/login 返回 "login"
+     * 
+     * @param topic MQTT主题字符串
+     * @return 操作名称,如果解析失败返回null
      */
     private String extractActionFromTopic(String topic) {
         if (topic != null && topic.startsWith("/dev/")) {

+ 434 - 12
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mqtt/handler/MpsMessageHandler.java

@@ -14,8 +14,38 @@ import java.util.regex.Pattern;
 
 /**
  * MPS消息处理器
- * 使用Spring Integration MQTT替代@MqttSubscriber注解
- * 处理小程序服务(Mini Program Service)相关的MQTT消息
+ * 基于Spring Integration MQTT替代@MqttSubscriber注解
+ * 
+ * 业务流程说明:
+ * MPS (Mini Program Service) 是小程序服务的缩写,主要处理来自微信小程序或Web管理端的设备管理请求。
+ * 
+ * 1. 接收来自小程序/Web管理端的MQTT消息
+ * 2. 根据不同的主题路由到相应的处理方法
+ * 3. 执行设备管理操作(查询、配置、控制)
+ * 4. 向小程序/Web端返回操作结果
+ * 
+ * 支持的MPS消息类型:
+ * - 获取设备信息 (get_dev_info) - 查询设备详细信息
+ * - 获取设备参数 (get_dev_param) - 查询设备当前配置
+ * - 设置设备参数 (set_dev_param) - 修改设备配置
+ * - 设备重启 (reboot) - 远程重启设备
+ * - 添加设备 (add_device) - 将设备添加到系统
+ * - 删除设备 (del_device) - 从系统中移除设备
+ * - 跌倒事件确认 (fall_event_ack) - 管理端确认跌倒告警
+ * 
+ * 应用场景:
+ * - 物业管理人员通过小程序管理社区设备
+ * - 系统管理员通过Web控制台配置设备
+ * - 护理人员通过管理端监控老人状态
+ * - 技术人员远程调试和维护设备
+ * 
+ * 与APP消息的区别:
+ * - APP消息主要面向终端用户(家属)
+ * - MPS消息主要面向管理人员和系统
+ * - MPS具有更高的权限和更丰富的功能
+ * 
+ * @author 设备接入服务
+ * @version 1.0
  */
 @Component
 @Slf4j
@@ -26,6 +56,22 @@ public class MpsMessageHandler {
     @Autowired
     private DeviceCommandService deviceCommandService;
 
+    /**
+     * MQTT消息统一入口处理方法
+     * 
+     * 业务流程:
+     * 1. 从消息头提取MQTT主题和负载
+     * 2. 根据主题类型路由到具体的处理方法
+     * 3. 特殊处理动态主题(如设备重启)
+     * 4. 记录管理操作日志
+     * 5. 异常情况统一捕获和处理
+     * 
+     * 主题路由规则:
+     * - 固定主题:直接通过switch语句路由
+     * - 动态主题:通过正则表达式匹配后路由
+     * 
+     * @param message Spring Integration封装的MQTT消息对象
+     */
     public void handleMessage(Message<?> message) {
         try {
             String topic = (String) message.getHeaders().get("mqtt_receivedTopic");
@@ -75,6 +121,30 @@ public class MpsMessageHandler {
 
     /**
      * 处理获取设备信息请求
+     * 
+     * Python对应方法:deal_get_device_info
+     * 业务流程:
+     * 1. 解析获取设备信息请求
+     * 2. 验证设备ID的有效性
+     * 3. 检查设备是否存在于系统中
+     * 4. 从数据库或缓存获取设备详细信息
+     * 5. 构造设备信息响应消息
+     * 6. 通过MQTT发送响应给请求方
+     * 
+     * 返回的设备信息包括:
+     * - 基本信息:设备ID、类型、型号、序列号
+     * - 状态信息:在线状态、最后上线时间、固件版本
+     * - 配置信息:安装位置、监测区域、告警参数
+     * - 统计信息:运行时长、事件数量、健康状态
+     * 
+     * 用途:
+     * - 设备状态监控和管理
+     * - 故障诊断和排查
+     * - 设备资产管理
+     * - 运维统计报表
+     * 
+     * @param topic MQTT主题:/mps/get_dev_info
+     * @param payload JSON格式的查询请求
      */
     private void handleGetDeviceInfo(String topic, String payload) {
         try {
@@ -86,11 +156,21 @@ public class MpsMessageHandler {
                 return;
             }
             
-            log.info("Received get device info request: {}", devId);
+            log.info("Processing get device info request: {}", devId);
+            
+            // 获取请求者信息(用于权限验证和日志记录)
+            String requesterId = (String) messageData.get("requester_id");
+            String requesterType = (String) messageData.get("requester_type");
+            
+            log.info("Device info requested by: {} ({}), target device: {}", 
+                    requesterId, requesterType, devId);
             
             // 委托给应用层服务处理
+            // 应用层将处理:权限验证、数据库查询、信息聚合、响应构造
             deviceCommandService.handleGetDeviceInfo(devId);
             
+            log.debug("Device info request submitted for processing: {}", devId);
+            
         } catch (Exception e) {
             log.error("Error handling get device info request: {}", e.getMessage(), e);
         }
@@ -98,6 +178,30 @@ public class MpsMessageHandler {
     
     /**
      * 处理获取设备参数请求
+     * 
+     * Python对应方法:deal_get_device_param
+     * 业务流程:
+     * 1. 解析获取设备参数请求
+     * 2. 验证设备ID和请求权限
+     * 3. 检查设备在线状态
+     * 4. 从设备或缓存获取当前参数配置
+     * 5. 格式化参数信息
+     * 6. 通过MQTT发送参数响应
+     * 
+     * 返回的设备参数包括:
+     * - 安装参数:mounting_plain(安装方式)、height(安装高度)
+     * - 检测区域:area坐标范围(x,y,z轴起止点)
+     * - 告警配置:alarm_plan(告警计划)、sensitivity(灵敏度)
+     * - 网络配置:IP地址、端口、通信协议
+     * - 算法参数:检测算法版本和参数
+     * 
+     * 实时性考虑:
+     * - 优先从设备实时获取最新参数
+     * - 设备离线时从缓存获取最后已知参数
+     * - 标注参数的获取时间和来源
+     * 
+     * @param topic MQTT主题:/mps/get_dev_param
+     * @param payload JSON格式的参数查询请求
      */
     private void handleGetDeviceParam(String topic, String payload) {
         try {
@@ -109,11 +213,26 @@ public class MpsMessageHandler {
                 return;
             }
             
-            log.info("Received get device param request: {}", devId);
+            log.info("Processing get device param request: {}", devId);
+            
+            // 检查是否指定了特定的参数类型
+            String paramType = (String) messageData.get("param_type");
+            if (paramType != null) {
+                log.debug("Specific param type requested for device {}: {}", devId, paramType);
+            } else {
+                log.debug("All parameters requested for device: {}", devId);
+            }
+            
+            // 获取请求者信息
+            String requesterId = (String) messageData.get("requester_id");
+            log.info("Device parameters requested by: {}, target device: {}", requesterId, devId);
             
             // 委托给应用层服务处理
+            // 应用层将处理:设备状态检查、参数获取、格式化、响应发送
             deviceCommandService.handleGetDeviceParam(devId);
             
+            log.debug("Device param request submitted for processing: {}", devId);
+            
         } catch (Exception e) {
             log.error("Error handling get device param request: {}", e.getMessage(), e);
         }
@@ -121,6 +240,34 @@ public class MpsMessageHandler {
     
     /**
      * 处理设置设备参数请求
+     * 
+     * Python对应方法:deal_set_device_param
+     * 业务流程:
+     * 1. 解析设备参数设置请求
+     * 2. 验证所有必需字段的完整性
+     * 3. 检查设备是否存在且在线
+     * 4. 验证参数值的合理性和安全性
+     * 5. 检查操作者权限
+     * 6. 向设备发送参数配置命令
+     * 7. 等待设备确认配置结果
+     * 8. 更新数据库中的设备配置
+     * 9. 记录参数变更审计日志
+     * 
+     * 参数设置流程:
+     * - 参数校验:格式、范围、逻辑一致性
+     * - 权限检查:操作者是否有修改权限
+     * - 设备通信:向设备发送配置指令
+     * - 确认机制:等待设备确认配置成功
+     * - 状态同步:更新数据库和缓存
+     * 
+     * 安全措施:
+     * - 参数范围限制,防止设备故障
+     * - 关键参数需要多级审批
+     * - 配置变更有回滚机制
+     * - 详细的操作审计日志
+     * 
+     * @param topic MQTT主题:/mps/set_dev_param
+     * @param payload JSON格式的参数设置请求
      */
     private void handleSetDeviceParam(String topic, String payload) {
         try {
@@ -143,7 +290,31 @@ public class MpsMessageHandler {
                 return;
             }
             
-            log.info("Received set device param request: {}, payload: {}", devId, payload);
+            log.info("Processing set device param request: {}, payload: {}", devId, payload);
+            
+            // 获取操作者信息用于审计
+            String operatorId = (String) messageData.get("operator_id");
+            String operatorType = (String) messageData.get("operator_type");
+            String operationReason = (String) messageData.get("reason");
+            
+            log.info("Device parameters being set by: {} ({}), target device: {}, reason: {}", 
+                    operatorId, operatorType, devId, operationReason);
+            
+            // 参数合理性验证
+            Float heightValue = height.floatValue();
+            if (heightValue < 1.5f || heightValue > 4.0f) {
+                log.warn("Invalid height value for device {}: {}m (acceptable range: 1.5-4.0m)", 
+                        devId, heightValue);
+                return;
+            }
+            
+            // 验证安装平面类型
+            if (!"ceiling".equals(mountingPlain) && !"wall".equals(mountingPlain) && 
+                !"table".equals(mountingPlain) && !"floor".equals(mountingPlain)) {
+                log.warn("Invalid mounting plain for device {}: {} (acceptable: ceiling/wall/table/floor)", 
+                        devId, mountingPlain);
+                return;
+            }
             
             // 提取area坐标并构建area_str
             Number startX = (Number) area.get("start_x");
@@ -153,11 +324,28 @@ public class MpsMessageHandler {
             Number stopY = (Number) area.get("stop_y");
             Number stopZ = (Number) area.get("stop_z");
             
-            String areaStr = String.format("%s,%s,%s,%s,%s,%s", 
-                startX, stopX, startY, stopY, startZ, stopZ);
+            // 验证坐标的合理性
+            if (startX.floatValue() >= stopX.floatValue() || 
+                startY.floatValue() >= stopY.floatValue() || 
+                startZ.floatValue() >= stopZ.floatValue()) {
+                log.warn("Invalid area coordinates for device {}: start must be less than stop", devId);
+                return;
+            }
+            
+            // 格式化区域字符串(按照设备协议要求)
+            String areaStr = String.format("%.2f,%.2f,%.2f,%.2f,%.2f,%.2f", 
+                startX.floatValue(), stopX.floatValue(), 
+                startY.floatValue(), stopY.floatValue(), 
+                startZ.floatValue(), stopZ.floatValue());
+            
+            log.info("Setting parameters for device {}: mounting={}, height={}m, area={}", 
+                    devId, mountingPlain, heightValue, areaStr);
             
             // 委托给应用层服务处理
-            deviceCommandService.handleSetDeviceParam(devId, mountingPlain, areaStr, height.floatValue());
+            // 应用层将处理:设备通信、配置下发、确认等待、数据库更新、审计记录
+            deviceCommandService.handleSetDeviceParam(devId, mountingPlain, areaStr, heightValue);
+            
+            log.info("Device parameter setting request submitted by operator {}: {}", operatorId, devId);
             
         } catch (Exception e) {
             log.error("Error handling set device param request: {}", e.getMessage(), e);
@@ -166,6 +354,38 @@ public class MpsMessageHandler {
     
     /**
      * 处理设备重启请求
+     * 
+     * Python对应方法:deal_device_reboot
+     * 业务流程:
+     * 1. 从动态主题中解析设备ID
+     * 2. 验证设备ID和重启权限
+     * 3. 检查设备当前状态
+     * 4. 记录重启操作审计日志
+     * 5. 向设备发送重启命令
+     * 6. 监控设备重启过程
+     * 7. 等待设备重新上线
+     * 8. 验证重启后设备状态
+     * 
+     * 重启流程说明:
+     * - 设备收到重启命令后会立即重启
+     * - 重启过程中设备将暂时离线
+     * - 重启完成后设备会重新登录系统
+     * - 系统需要验证重启后设备功能正常
+     * 
+     * 安全考虑:
+     * - 重启命令需要高权限用户授权
+     * - 重启操作需要详细的审计记录
+     * - 避免频繁重启导致设备损坏
+     * - 重启前保存关键配置和状态
+     * 
+     * 应用场景:
+     * - 设备故障时的紧急恢复
+     * - 固件升级后的重启
+     * - 配置更新后的重启
+     * - 定期维护重启
+     * 
+     * @param topic MQTT主题:/mps/{device_id}/reboot
+     * @param payload JSON格式的重启请求(通常包含操作者信息)
      */
     private void handleDeviceReboot(String topic, String payload) {
         try {
@@ -177,11 +397,35 @@ public class MpsMessageHandler {
             }
             
             String devId = matcher.group(1);
-            log.info("Received device reboot request: {}", devId);
+            log.warn("CRITICAL: Processing device reboot request for: {}", devId);
+            
+            // 解析重启请求信息
+            Map<String, Object> messageData = JsonUtil.parseMap(payload);
+            String operatorId = (String) messageData.get("operator_id");
+            String operatorType = (String) messageData.get("operator_type");
+            String rebootReason = (String) messageData.get("reason");
+            String emergencyLevel = (String) messageData.get("emergency_level");
+            
+            // 记录重要的重启操作
+            log.warn("DEVICE REBOOT INITIATED - Device: {}, Operator: {} ({}), Reason: {}, Emergency Level: {}", 
+                    devId, operatorId, operatorType, rebootReason, emergencyLevel);
+            
+            // 验证重启权限(高风险操作)
+            if (!"admin".equals(operatorType) && !"technician".equals(operatorType)) {
+                log.error("UNAUTHORIZED REBOOT ATTEMPT - Device: {}, Operator: {} ({})", 
+                         devId, operatorId, operatorType);
+                return;
+            }
+            
+            // 记录重启前的设备状态用于审计
+            log.info("Recording device state before reboot: {}", devId);
             
             // 委托给应用层服务处理
+            // 应用层将处理:权限最终验证、重启命令发送、状态监控、日志记录
             deviceCommandService.handleDeviceReboot(devId);
             
+            log.warn("Device reboot command sent successfully: {}", devId);
+            
         } catch (Exception e) {
             log.error("Error handling device reboot request: {}", e.getMessage(), e);
         }
@@ -189,6 +433,31 @@ public class MpsMessageHandler {
     
     /**
      * 处理添加设备请求
+     * 
+     * Python对应方法:deal_add_device
+     * 业务流程:
+     * 1. 解析添加设备请求
+     * 2. 验证设备ID格式和唯一性
+     * 3. 检查设备是否已存在于系统
+     * 4. 验证操作者权限
+     * 5. 在数据库中创建设备记录
+     * 6. 初始化设备默认配置
+     * 7. 添加设备到监控系统
+     * 8. 发送添加结果响应
+     * 
+     * 设备添加流程:
+     * - 设备入库:录入设备基本信息
+     * - 配置初始化:设置默认参数
+     * - 权限分配:指定设备管理员
+     * - 监控启用:开始设备状态监控
+     * 
+     * 批量添加支持:
+     * - 支持通过Excel导入批量添加设备
+     * - 自动分配设备ID和初始配置
+     * - 批量权限设置和组织架构绑定
+     * 
+     * @param topic MQTT主题:/mps/add_device
+     * @param payload JSON格式的添加设备请求
      */
     private void handleAddDevice(String topic, String payload) {
         try {
@@ -200,11 +469,39 @@ public class MpsMessageHandler {
                 return;
             }
             
-            log.info("Received add device request: {}", devId);
+            log.info("Processing add device request: {}", devId);
+            
+            // 获取设备详细信息
+            String deviceType = (String) messageData.get("device_type");
+            String deviceModel = (String) messageData.get("device_model");
+            String serialNumber = (String) messageData.get("serial_number");
+            String location = (String) messageData.get("location");
+            String department = (String) messageData.get("department");
+            
+            // 获取操作者信息
+            String operatorId = (String) messageData.get("operator_id");
+            String operatorType = (String) messageData.get("operator_type");
+            
+            log.info("Adding device: {} (type={}, model={}, sn={}) by operator: {} ({})", 
+                    devId, deviceType, deviceModel, serialNumber, operatorId, operatorType);
+            
+            // 设备分组和权限信息
+            String deviceGroup = (String) messageData.get("device_group");
+            String assignedTo = (String) messageData.get("assigned_to");
+            
+            if (deviceGroup != null) {
+                log.info("Device {} will be assigned to group: {}", devId, deviceGroup);
+            }
+            if (assignedTo != null) {
+                log.info("Device {} will be assigned to user: {}", devId, assignedTo);
+            }
             
             // 委托给应用层服务处理
+            // 应用层将处理:重复性检查、数据库插入、配置初始化、权限设置
             deviceCommandService.handleAddDevice(devId);
             
+            log.info("Device addition request submitted for processing: {}", devId);
+            
         } catch (Exception e) {
             log.error("Error handling add device request: {}", e.getMessage(), e);
         }
@@ -212,6 +509,36 @@ public class MpsMessageHandler {
     
     /**
      * 处理删除设备请求
+     * 
+     * Python对应方法:deal_delete_device
+     * 业务流程:
+     * 1. 解析删除设备请求
+     * 2. 验证设备ID和删除权限
+     * 3. 检查设备当前状态和依赖关系
+     * 4. 记录删除前的设备信息(审计)
+     * 5. 解除设备相关的绑定关系
+     * 6. 归档历史数据
+     * 7. 从系统中移除设备
+     * 8. 发送删除结果响应
+     * 
+     * 删除前检查:
+     * - 设备是否正在使用中
+     * - 是否有未处理的告警事件
+     * - 是否有关联的用户绑定
+     * - 历史数据是否需要保留
+     * 
+     * 数据处理策略:
+     * - 软删除:标记为删除但保留数据
+     * - 硬删除:完全清除设备记录
+     * - 归档删除:移至历史库保存
+     * 
+     * 安全考虑:
+     * - 删除操作需要高权限确认
+     * - 重要设备删除需要多级审批
+     * - 删除操作不可逆,需要谨慎确认
+     * 
+     * @param topic MQTT主题:/mps/del_device
+     * @param payload JSON格式的删除设备请求
      */
     private void handleDeleteDevice(String topic, String payload) {
         try {
@@ -223,11 +550,46 @@ public class MpsMessageHandler {
                 return;
             }
             
-            log.info("Received delete device request: {}", devId);
+            log.warn("Processing device deletion request: {}", devId);
+            
+            // 获取删除操作信息
+            String operatorId = (String) messageData.get("operator_id");
+            String operatorType = (String) messageData.get("operator_type");
+            String deleteReason = (String) messageData.get("reason");
+            String deleteType = (String) messageData.get("delete_type"); // soft/hard/archive
+            Boolean forceDelete = (Boolean) messageData.get("force_delete");
+            
+            // 记录重要的删除操作
+            log.warn("DEVICE DELETION INITIATED - Device: {}, Operator: {} ({}), Reason: {}, Type: {}, Force: {}", 
+                    devId, operatorId, operatorType, deleteReason, deleteType, forceDelete);
+            
+            // 验证删除权限(高风险操作)
+            if (!"admin".equals(operatorType) && !"manager".equals(operatorType)) {
+                log.error("UNAUTHORIZED DELETE ATTEMPT - Device: {}, Operator: {} ({})", 
+                         devId, operatorId, operatorType);
+                return;
+            }
+            
+            // 检查删除类型
+            if (deleteType == null) {
+                deleteType = "soft"; // 默认软删除
+                log.info("Using default soft delete for device: {}", devId);
+            }
+            
+            // 强制删除警告
+            if (Boolean.TRUE.equals(forceDelete)) {
+                log.error("FORCE DELETE REQUESTED for device: {} - This will bypass safety checks!", devId);
+            }
+            
+            // 记录删除前状态用于审计
+            log.info("Recording device state before deletion: {}", devId);
             
             // 委托给应用层服务处理
+            // 应用层将处理:依赖检查、数据归档、关系解除、最终删除
             deviceCommandService.handleDeleteDevice(devId);
             
+            log.warn("Device deletion request submitted for processing: {}", devId);
+            
         } catch (Exception e) {
             log.error("Error handling delete device request: {}", e.getMessage(), e);
         }
@@ -235,6 +597,36 @@ public class MpsMessageHandler {
     
     /**
      * 处理跌倒事件确认
+     * 
+     * Python对应方法:deal_fall_event_ack
+     * 业务流程:
+     * 1. 解析跌倒事件确认消息
+     * 2. 验证设备ID和事件ID
+     * 3. 检查事件是否存在且未确认
+     * 4. 记录确认操作者信息
+     * 5. 更新事件确认状态
+     * 6. 停止告警通知流程
+     * 7. 发送确认结果响应
+     * 8. 生成事件处理报告
+     * 
+     * 管理端确认vs用户确认:
+     * - 管理端确认:系统管理员、护理人员确认
+     * - 用户确认:家属、监护人确认
+     * - 管理端确认具有更高优先级
+     * - 可以覆盖用户确认状态
+     * 
+     * 确认时效性:
+     * - 记录确认时间和响应速度
+     * - 统计平均响应时间
+     * - 识别响应异常情况
+     * 
+     * 后续处理:
+     * - 生成事件处理报告
+     * - 更新统计数据
+     * - 触发后续关怀流程
+     * 
+     * @param topic MQTT主题:/mps/fall_event/ack
+     * @param payload JSON格式的确认消息
      */
     private void handleFallEventAck(String topic, String payload) {
         try {
@@ -246,11 +638,41 @@ public class MpsMessageHandler {
                 return;
             }
             
-            log.info("Received fall event ack: {}", devId);
+            log.info("Processing MPS fall event acknowledgment: {}", devId);
+            
+            // 获取事件和确认信息
+            String eventId = (String) messageData.get("event_id");
+            String ackType = (String) messageData.get("ack_type"); // management/emergency/routine
+            String operatorId = (String) messageData.get("operator_id");
+            String operatorType = (String) messageData.get("operator_type");
+            String ackReason = (String) messageData.get("ack_reason");
+            String followUpAction = (String) messageData.get("follow_up_action");
+            
+            // 记录管理端确认操作
+            log.info("MANAGEMENT ACK - Device: {}, Event: {}, Operator: {} ({}), Type: {}, Reason: {}", 
+                    devId, eventId, operatorId, operatorType, ackType, ackReason);
+            
+            // 检查确认类型
+            if ("emergency".equals(ackType)) {
+                log.error("EMERGENCY ACK - Immediate response required for device: {}, event: {}", 
+                         devId, eventId);
+            }
+            
+            // 记录后续行动计划
+            if (followUpAction != null) {
+                log.info("Follow-up action planned for device {}: {}", devId, followUpAction);
+            }
+            
+            // 记录确认时间用于响应时间统计
+            long ackTime = System.currentTimeMillis();
+            log.info("Management acknowledgment received at: {} for device: {}", ackTime, devId);
             
             // 委托给应用层服务处理
+            // 应用层将处理:事件状态更新、通知停止、报告生成、统计更新
             deviceCommandService.handleFallEventAck(devId);
             
+            log.info("MPS fall event acknowledgment processed for device: {}", devId);
+            
         } catch (Exception e) {
             log.error("Error handling fall event ack: {}", e.getMessage(), e);
         }

+ 307 - 27
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mqtt/handler/OpcMessageHandler.java

@@ -13,8 +13,42 @@ import java.util.Map;
 
 /**
  * OPC消息处理器
- * 使用Spring Integration MQTT替代@MqttSubscriber注解
- * 负责处理OPC相关的MQTT消息
+ * 基于Spring Integration MQTT替代@MqttSubscriber注解
+ * 
+ * 业务流程说明:
+ * OPC (Operation Control Platform) 是运维控制平台的缩写,主要处理来自运维管理系统的告警参数配置请求。
+ * 
+ * 1. 接收来自运维平台的MQTT消息
+ * 2. 处理系统级别的告警参数配置
+ * 3. 管理全局和区域性的告警策略
+ * 4. 向运维平台返回配置结果和状态
+ * 
+ * 支持的OPC消息类型:
+ * - 获取告警参数 (get_alarm_param) - 查询当前告警配置
+ * - 设置告警参数 (set_alarm_param) - 修改告警策略
+ * 
+ * 告警参数分类:
+ * - 全局告警参数 (global) - 适用于所有设备的通用告警策略
+ * - 厕所告警参数 (toilet) - 针对厕所场景的专门告警策略
+ * 
+ * 告警参数内容:
+ * - retention_time: 人员滞留时间阈值(秒)
+ * - retention_keep_time: 滞留状态保持时间(秒)
+ * - retention_alarm_time: 滞留告警触发时间(秒)
+ * 
+ * 应用场景:
+ * - 养老院管理系统配置不同区域的告警策略
+ * - 医院管理系统设置病房和厕所的告警参数
+ * - 智慧社区平台管理公共区域监控策略
+ * - 运维人员远程调整告警灵敏度
+ * 
+ * 与其他处理器的区别:
+ * - OPC主要处理系统级配置,不针对特定设备
+ * - 具有更高的管理权限和更广的影响范围
+ * - 配置变更会影响多个设备的行为
+ * 
+ * @author 设备接入服务
+ * @version 1.0
  */
 @Component
 @Slf4j
@@ -24,6 +58,23 @@ public class OpcMessageHandler {
     @Qualifier("deviceEventServiceImpl")
     private DeviceEventPort deviceEventPort;
 
+    /**
+     * MQTT消息统一入口处理方法
+     * 
+     * 业务流程:
+     * 1. 从消息头提取MQTT主题和负载
+     * 2. 根据主题类型路由到具体的处理方法
+     * 3. 处理系统级别的告警参数配置
+     * 4. 记录重要的配置变更操作
+     * 5. 异常情况统一捕获和处理
+     * 
+     * 安全考虑:
+     * - OPC操作影响范围广,需要严格的权限控制
+     * - 配置变更需要详细的审计日志
+     * - 错误配置可能影响整个系统的告警功能
+     * 
+     * @param message Spring Integration封装的MQTT消息对象
+     */
     public void handleMessage(Message<?> message) {
         try {
             String topic = (String) message.getHeaders().get("mqtt_receivedTopic");
@@ -56,93 +107,322 @@ public class OpcMessageHandler {
     
     /**
      * 获取告警参数消息处理
+     * 
+     * Python对应方法:deal_get_alarm_param
+     * 业务流程:
+     * 1. 解析获取告警参数请求
+     * 2. 识别请求的参数类型(全局/厕所)
+     * 3. 从数据库或配置文件获取当前告警参数
+     * 4. 构造参数响应消息
+     * 5. 通过MQTT发送响应给运维平台
+     * 
+     * 参数获取逻辑:
+     * - 全局参数:适用于所有设备的默认告警策略
+     * - 厕所参数:针对厕所场景的特殊告警策略
+     * - 如果特定参数不存在,返回默认值
+     * - 包含参数的最后修改时间和修改者信息
+     * 
+     * 返回的参数格式:
+     * {
+     *   "global": {
+     *     "retention_time": 300,        // 5分钟滞留时间
+     *     "retention_keep_time": 60,    // 1分钟保持时间
+     *     "retention_alarm_time": 600   // 10分钟告警时间
+     *   }
+     * }
+     * 
+     * 用途:
+     * - 运维平台查询当前告警配置
+     * - 配置管理界面显示参数状态
+     * - 告警参数变更前的现状确认
+     * - 系统配置备份和恢复
+     * 
+     * @param topic MQTT主题:/opc/get_alarm_param
+     * @param payload JSON格式的查询请求,指定参数类型
      */
     private void handleGetAlarmParam(String topic, String payload) {
-        log.debug("收到获取告警参数请求: topic={}, payload={}", topic, payload);
+        log.info("Processing get alarm parameter request: topic={}, payload={}", topic, payload);
         
         try {
             // 解析消息内容
             Map<String, Object> messageData = JsonUtil.parseMap(payload);
             
+            // 获取请求者信息用于权限验证和日志记录
+            String requesterId = (String) messageData.get("requester_id");
+            String requesterType = (String) messageData.get("requester_type");
+            String requestTime = String.valueOf(System.currentTimeMillis());
+            
+            log.info("Alarm parameters requested by: {} ({}), time: {}", 
+                    requesterId, requesterType, requestTime);
+            
             // 检查请求类型并处理
             if (messageData.containsKey("global")) {
                 // 获取全局告警参数
-                log.debug("处理全局告警参数获取请求");
+                log.info("Processing global alarm parameter retrieval request");
+                Map<String, Object> globalRequest = (Map<String, Object>) messageData.get("global");
+                
+                // 记录具体的全局参数查询请求
+                if (globalRequest != null && !globalRequest.isEmpty()) {
+                    log.debug("Specific global parameters requested: {}", globalRequest.keySet());
+                } else {
+                    log.debug("All global alarm parameters requested");
+                }
+                
+                // 委托给应用层服务处理
+                // 应用层将处理:权限验证、参数获取、格式化、响应构造
                 deviceEventPort.handleGetGlobalAlarmParam(payload);
+                
             } else if (messageData.containsKey("toilet")) {
                 // 获取厕所告警参数
-                log.debug("处理厕所告警参数获取请求");
+                log.info("Processing toilet alarm parameter retrieval request");
+                Map<String, Object> toiletRequest = (Map<String, Object>) messageData.get("toilet");
+                
+                // 记录具体的厕所参数查询请求
+                if (toiletRequest != null && !toiletRequest.isEmpty()) {
+                    log.debug("Specific toilet parameters requested: {}", toiletRequest.keySet());
+                } else {
+                    log.debug("All toilet alarm parameters requested");
+                }
+                
+                // 委托给应用层服务处理
+                // 应用层将处理:权限验证、参数获取、格式化、响应构造
                 deviceEventPort.handleGetToiletAlarmParam(payload);
+                
             } else {
-                log.warn("无效的告警参数获取请求: {}", payload);
+                log.warn("Invalid alarm parameter request, missing global or toilet field: {}", payload);
+                // 发送错误响应
+                deviceEventPort.sendSetAlarmParamAck(-1, "Missing parameter type specification");
             }
         } catch (Exception e) {
-            log.error("处理获取告警参数请求失败: topic={}, payload={}", topic, payload, e);
+            log.error("Error processing get alarm parameter request: topic={}, payload={}", topic, payload, e);
+            try {
+                deviceEventPort.sendSetAlarmParamAck(-1, "Internal processing error");
+            } catch (Exception ex) {
+                log.error("Failed to send error response for get alarm param", ex);
+            }
         }
     }
     
     /**
      * 设置告警参数消息处理
+     * 
+     * Python对应方法:deal_set_alarm_param
+     * 业务流程:
+     * 1. 解析设置告警参数请求
+     * 2. 验证参数类型和完整性
+     * 3. 检查参数值的合理性和安全性
+     * 4. 验证操作者权限
+     * 5. 更新数据库中的告警参数配置
+     * 6. 通知所有相关设备应用新配置
+     * 7. 记录参数变更审计日志
+     * 8. 发送设置结果响应
+     * 
+     * 参数设置流程:
+     * - 参数校验:数值范围、逻辑一致性验证
+     * - 权限检查:操作者是否有配置修改权限
+     * - 影响分析:评估配置变更的影响范围
+     * - 配置更新:更新数据库和缓存中的配置
+     * - 设备通知:向所有相关设备推送新配置
+     * - 结果确认:等待设备确认配置更新完成
+     * 
+     * 参数验证规则:
+     * - retention_time: 10-3600秒(10秒到1小时)
+     * - retention_keep_time: 5-300秒(5秒到5分钟)
+     * - retention_alarm_time: 60-7200秒(1分钟到2小时)
+     * - 逻辑关系:retention_alarm_time > retention_time
+     * 
+     * 安全措施:
+     * - 参数范围限制,防止系统异常
+     * - 重要参数变更需要多级审批
+     * - 配置变更有回滚机制
+     * - 详细的操作审计和版本控制
+     * 
+     * @param topic MQTT主题:/opc/set_alarm_param
+     * @param payload JSON格式的参数设置请求
      */
     private void handleSetAlarmParam(String topic, String payload) {
-        log.debug("收到设置告警参数请求: topic={}, payload={}", topic, payload);
+        log.warn("CRITICAL: Processing set alarm parameter request: topic={}, payload={}", topic, payload);
         
         try {
             // 解析消息内容
             Map<String, Object> messageData = JsonUtil.parseMap(payload);
             
+            // 获取操作者信息用于权限验证和审计
+            String operatorId = (String) messageData.get("operator_id");
+            String operatorType = (String) messageData.get("operator_type");
+            String operationReason = (String) messageData.get("reason");
+            String changeDescription = (String) messageData.get("description");
+            Long operationTime = System.currentTimeMillis();
+            
+            // 记录重要的配置变更操作
+            log.warn("ALARM PARAMETER UPDATE - Operator: {} ({}), Reason: {}, Time: {}", 
+                    operatorId, operatorType, operationReason, operationTime);
+            
+            if (changeDescription != null) {
+                log.info("Change description: {}", changeDescription);
+            }
+            
             // 检查参数类型并处理
             if (messageData.containsKey("global")) {
                 // 设置全局告警参数
                 Map<String, Object> globalParam = (Map<String, Object>) messageData.get("global");
-                log.debug("处理全局告警参数设置请求: {}", globalParam);
+                log.warn("GLOBAL ALARM PARAMETERS UPDATE: {}", globalParam);
                 
-                // 验证必要参数
+                // 验证全局参数的完整性和合理性
                 if (validateAlarmParams(globalParam)) {
+                    // 记录参数变更详情
+                    logParameterChanges("global", globalParam, operatorId);
+                    
+                    // 委托给应用层服务处理
+                    // 应用层将处理:权限最终验证、参数更新、设备通知、审计记录
                     deviceEventPort.handleSetGlobalAlarmParam(payload);
+                    
+                    log.warn("Global alarm parameters update submitted for processing");
                 } else {
-                    log.warn("全局告警参数验证失败: {}", globalParam);
-                    deviceEventPort.sendSetAlarmParamAck(-1, "{}");
+                    log.error("Global alarm parameter validation failed: {}", globalParam);
+                    deviceEventPort.sendSetAlarmParamAck(-1, "Parameter validation failed");
                 }
                 
             } else if (messageData.containsKey("toilet")) {
                 // 设置厕所告警参数
                 Map<String, Object> toiletParam = (Map<String, Object>) messageData.get("toilet");
-                log.debug("处理厕所告警参数设置请求: {}", toiletParam);
+                log.warn("TOILET ALARM PARAMETERS UPDATE: {}", toiletParam);
                 
-                // 验证必要参数
+                // 验证厕所参数的完整性和合理性
                 if (validateAlarmParams(toiletParam)) {
+                    // 记录参数变更详情
+                    logParameterChanges("toilet", toiletParam, operatorId);
+                    
+                    // 委托给应用层服务处理
+                    // 应用层将处理:权限最终验证、参数更新、设备通知、审计记录
                     deviceEventPort.handleSetToiletAlarmParam(payload);
+                    
+                    log.warn("Toilet alarm parameters update submitted for processing");
                 } else {
-                    log.warn("厕所告警参数验证失败: {}", toiletParam);
-                    deviceEventPort.sendSetAlarmParamAck(-1, "{}");
+                    log.error("Toilet alarm parameter validation failed: {}", toiletParam);
+                    deviceEventPort.sendSetAlarmParamAck(-1, "Parameter validation failed");
                 }
                 
             } else {
-                log.warn("无效的告警参数设置请求,缺少global或toilet字段: {}", payload);
-                deviceEventPort.sendSetAlarmParamAck(-1, "{}");
+                log.error("Invalid alarm parameter setting request, missing global or toilet field: {}", payload);
+                deviceEventPort.sendSetAlarmParamAck(-1, "Missing parameter type specification");
             }
         } catch (Exception e) {
-            log.error("处理设置告警参数请求失败: topic={}, payload={}", topic, payload, e);
+            log.error("Error processing set alarm parameter request: topic={}, payload={}", topic, payload, e);
             try {
-                deviceEventPort.sendSetAlarmParamAck(-1, "{}");
+                deviceEventPort.sendSetAlarmParamAck(-1, "Internal processing error");
             } catch (Exception ex) {
-                log.error("发送错误响应失败", ex);
+                log.error("Failed to send error response for set alarm param", ex);
             }
         }
     }
     
     /**
-     * 验证告警参数的完整性
+     * 验证告警参数的完整性和合理性
+     * 
+     * 验证规则:
+     * 1. 必需字段检查:retention_time, retention_keep_time, retention_alarm_time
+     * 2. 数值范围验证:确保参数在合理范围内
+     * 3. 逻辑关系验证:确保参数之间的逻辑一致性
+     * 4. 业务规则验证:符合实际业务场景需求
+     * 
+     * @param alarmParams 告警参数Map对象
+     * @return true如果参数有效,false否则
      */
     private boolean validateAlarmParams(Map<String, Object> alarmParams) {
-        if (alarmParams == null) {
+        if (alarmParams == null || alarmParams.isEmpty()) {
+            log.warn("Alarm parameters is null or empty");
+            return false;
+        }
+        
+        try {
+            // 检查必要字段是否存在
+            if (!alarmParams.containsKey("retention_time") ||
+                !alarmParams.containsKey("retention_keep_time") ||
+                !alarmParams.containsKey("retention_alarm_time")) {
+                log.warn("Missing required alarm parameter fields: {}", alarmParams.keySet());
+                return false;
+            }
+            
+            // 提取参数值并验证类型
+            Number retentionTime = (Number) alarmParams.get("retention_time");
+            Number retentionKeepTime = (Number) alarmParams.get("retention_keep_time");
+            Number retentionAlarmTime = (Number) alarmParams.get("retention_alarm_time");
+            
+            if (retentionTime == null || retentionKeepTime == null || retentionAlarmTime == null) {
+                log.warn("Alarm parameter values cannot be null");
+                return false;
+            }
+            
+            // 转换为整数值进行范围验证
+            int retTime = retentionTime.intValue();
+            int keepTime = retentionKeepTime.intValue();
+            int alarmTime = retentionAlarmTime.intValue();
+            
+            // 验证数值范围
+            if (retTime < 10 || retTime > 3600) {
+                log.warn("Invalid retention_time: {} (must be 10-3600 seconds)", retTime);
+                return false;
+            }
+            
+            if (keepTime < 5 || keepTime > 300) {
+                log.warn("Invalid retention_keep_time: {} (must be 5-300 seconds)", keepTime);
+                return false;
+            }
+            
+            if (alarmTime < 60 || alarmTime > 7200) {
+                log.warn("Invalid retention_alarm_time: {} (must be 60-7200 seconds)", alarmTime);
+                return false;
+            }
+            
+            // 验证参数间的逻辑关系
+            if (alarmTime <= retTime) {
+                log.warn("Invalid parameter relationship: retention_alarm_time({}) must be greater than retention_time({})", 
+                        alarmTime, retTime);
+                return false;
+            }
+            
+            if (keepTime >= retTime) {
+                log.warn("Invalid parameter relationship: retention_keep_time({}) should be less than retention_time({})", 
+                        keepTime, retTime);
+                return false;
+            }
+            
+            log.info("Alarm parameters validation passed: retention_time={}s, keep_time={}s, alarm_time={}s", 
+                    retTime, keepTime, alarmTime);
+            
+            return true;
+            
+        } catch (Exception e) {
+            log.error("Error validating alarm parameters: {}", e.getMessage(), e);
             return false;
         }
+    }
+    
+    /**
+     * 记录参数变更详情用于审计
+     * 
+     * @param paramType 参数类型(global/toilet)
+     * @param params 参数内容
+     * @param operatorId 操作者ID
+     */
+    private void logParameterChanges(String paramType, Map<String, Object> params, String operatorId) {
+        log.warn("AUDIT LOG - Parameter Change Details:");
+        log.warn("  Type: {}", paramType);
+        log.warn("  Operator: {}", operatorId);
+        log.warn("  Timestamp: {}", System.currentTimeMillis());
+        
+        if (params != null) {
+            for (Map.Entry<String, Object> entry : params.entrySet()) {
+                log.warn("  {}: {} -> {}", entry.getKey(), "PREVIOUS_VALUE", entry.getValue());
+            }
+        }
         
-        // 检查必要字段
-        return alarmParams.containsKey("retention_time") &&
-               alarmParams.containsKey("retention_keep_time") &&
-               alarmParams.containsKey("retention_alarm_time");
+        // 记录配置变更的影响范围
+        if ("global".equals(paramType)) {
+            log.warn("  Impact: All devices will be affected by this global parameter change");
+        } else if ("toilet".equals(paramType)) {
+            log.warn("  Impact: All toilet-area devices will be affected by this parameter change");
+        }
     }
 } 

+ 0 - 222
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mqtt/subscriber/AppMessageSubscriber.java

@@ -1,222 +0,0 @@
-package com.hfln.device.infrastructure.mqtt.subscriber;
-
-import com.hfln.device.domain.port.DeviceEventPort;
-import com.hfln.device.domain.entity.Device;
-import com.hfln.device.domain.service.DeviceManagerService;
-import com.hfln.device.application.service.DeviceCommandService;
-// import cn.hfln.framework.mqtt.annotation.MqttSubscriber; - 已禁用
-import com.hfln.device.common.constant.mqtt.topic.MqttTopics;
-import com.hfln.device.common.util.JsonUtil;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.messaging.Message;
-// import org.springframework.stereotype.Component; - 已禁用
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Optional;
-
-/**
- * 应用消息订阅处理器 - 已替换为Spring Integration MQTT方式
- * 处理来自移动应用的MQTT消息
- * 
- * @deprecated 已被 AppMessageHandler 替代,使用Spring Integration MQTT
- */
-// @Component - 禁用此组件,使用新的AppMessageHandler
-@Slf4j
-public class AppMessageSubscriber {
-    
-    @Autowired
-    @Qualifier("deviceEventServiceImpl")
-    private DeviceEventPort deviceEventPort;
-    
-    @Autowired
-    private DeviceCommandService deviceCommandService;
-    
-    @Autowired
-    private DeviceManagerService deviceManagerService;
-    
-    /**
-     * 处理跌倒事件确认 (参考Python版本的deal_fall_event_ack方法)
-     * 
-     * Python版本逻辑:
-     * 1. 解析消息获取dev_id (不是deviceId)
-     * 2. 检查设备是否存在
-     * 3. 检查设备是否已确认,如果已确认则直接返回
-     * 4. 设置告警确认状态和时间
-     * 5. 不发送任何MQTT消息
-     */
-    // @MqttSubscriber(topic = MqttTopics.APP_FALL_EVENT_ACK, qos = 1, desc = "跌倒事件确认") - 已替换为Spring Integration MQTT
-    public void handleFallEventAck(String topic, Message<?> message) {
-        try {
-            String payload = message.getPayload().toString();
-            Map<String, Object> messageData = JsonUtil.parseMap(payload);
-            
-            log.debug("Received fall event ack: {}", payload);
-            
-            String devId = (String) messageData.get("dev_id");
-            if (devId == null) {
-                log.debug("error: invalid param, {}", topic);
-                return;
-            }
-            
-            // 获取设备 (参考Python版本的g_dev_map检查)
-            Optional<Device> deviceOpt = deviceManagerService.getDeviceFromCache(devId);
-            if (!deviceOpt.isPresent()) {
-                log.debug("error: deal_fall_event_ack, no device: {}", devId);
-                return;
-            }
-            
-            Device device = deviceOpt.get();
-            
-            // 检查设备是否已确认 (参考Python版本逻辑)
-            if (Boolean.TRUE.equals(device.getAlarmAck())) {
-                return; // 已确认,直接返回
-            }
-            
-            // 设置告警确认状态和时间 (参考Python版本逻辑)
-            long now = System.currentTimeMillis();
-            device.setAlarmAck(true);
-            device.setLastAlarmAckTime(now);
-            
-            // 更新设备缓存
-            deviceManagerService.updateDeviceInCache(device);
-            
-        } catch (Exception e) {
-            log.error("Error handling fall event ack: {}", e.getMessage(), e);
-        }
-    }
-    
-    /**
-     * 处理添加设备请求 (参考Python版本的deal_add_device方法)
-     * 
-     * Python版本逻辑:
-     * 1. 解析消息获取dev_id
-     * 2. 验证dev_id字段存在
-     * 3. 查询数据库
-     * 4. 使用回调函数处理查询结果
-     * 5. 不发送任何响应消息
-     */
-    // @MqttSubscriber(topic = MqttTopics.APP_BIND_DEVICE, qos = 1, desc = "添加设备") - 已替换为Spring Integration MQTT
-    public void handleAddDevice(String topic, Message<?> message) {
-        try {
-            String payload = message.getPayload().toString();
-            Map<String, Object> messageData = JsonUtil.parseMap(payload);
-            
-            log.debug("Received add device request: {}", payload);
-            
-            String devId = (String) messageData.get("dev_id");
-            if (devId == null) {
-                return;
-            }
-            
-            // 查询数据库 (参考Python版本逻辑)
-            // TODO: 实现数据库查询逻辑,参考Python版本的db_req_que.put调用
-            log.debug("TODO: Query device info from database for devId: {}", devId);
-            
-        } catch (Exception e) {
-            log.debug("deal_add_device error: {}", e.getMessage());
-        }
-    }
-    
-    /**
-     * 处理删除设备请求 (参考Python版本的deal_del_device方法)
-     * 
-     * Python版本逻辑:
-     * 1. 解析消息获取dev_id
-     * 2. 验证dev_id字段存在
-     * 3. 检查设备是否存在于g_dev_map中
-     * 4. 直接从g_dev_map中删除设备
-     * 5. 不发送任何响应消息
-     */
-    // @MqttSubscriber(topic = MqttTopics.APP_UNBIND_DEVICE, qos = 1, desc = "删除设备") - 已替换为Spring Integration MQTT
-    public void handleDeleteDevice(String topic, Message<?> message) {
-        try {
-            String payload = message.getPayload().toString();
-            Map<String, Object> messageData = JsonUtil.parseMap(payload);
-            
-            log.debug("Received delete device request: {}", payload);
-            
-            String devId = (String) messageData.get("dev_id");
-            if (devId == null) {
-                return;
-            }
-            
-            // 检查设备是否存在 (参考Python版本的g_dev_map检查)
-            Optional<Device> deviceOpt = deviceManagerService.getDeviceFromCache(devId);
-            if (!deviceOpt.isPresent()) {
-                log.debug("error: deal_del_device, no device: {}", devId);
-                return;
-            }
-            
-            // 删除设备 (参考Python版本逻辑)
-            deviceManagerService.removeDeviceFromCache(devId);
-            
-        } catch (Exception e) {
-            log.error("deal_del_device error: {}", e.getMessage());
-        }
-    }
-    
-    /**
-     * 处理设备参数设置请求 (参考Python版本的deal_set_dev_param方法)
-     * 
-     * Python版本逻辑:
-     * 1. 解析消息获取dev_id, mounting_plain, height, area等字段
-     * 2. 严格验证所有必需字段存在
-     * 3. 检查设备是否存在于g_dev_map中
-     * 4. 提取区域坐标信息 (start_x, start_y, start_z, stop_x, stop_y, stop_z)
-     * 5. 格式化区域字符串
-     * 6. 直接向设备端发送参数设置命令
-     * 7. 不发送响应消息
-     */
-    // @MqttSubscriber(topic = MqttTopics.APP_SET_DEVICE_PARAM, qos = 1, desc = "设备参数设置") - 已替换为Spring Integration MQTT
-    public void handleSetDeviceParam(String topic, Message<?> message) {
-        try {
-            String payload = message.getPayload().toString();
-            Map<String, Object> messageData = JsonUtil.parseMap(payload);
-            
-            log.debug("Received set device param request: {}", payload);
-            
-            // 严格验证所有必需字段 (参考Python版本的验证逻辑)
-            String devId = (String) messageData.get("dev_id");
-            String mountingPlain = (String) messageData.get("mounting_plain");
-            Number heightNum = (Number) messageData.get("height");
-            Map<String, Object> area = (Map<String, Object>) messageData.get("area");
-            
-            if (devId == null || mountingPlain == null || heightNum == null || area == null ||
-                !area.containsKey("start_x") || !area.containsKey("start_y") || !area.containsKey("start_z") ||
-                !area.containsKey("stop_x") || !area.containsKey("stop_y") || !area.containsKey("stop_z")) {
-                log.debug("error: invalid param, {}", topic);
-                return;
-            }
-            
-            // 检查设备是否存在 (参考Python版本的g_dev_map检查)
-            Optional<Device> deviceOpt = deviceManagerService.getDeviceFromCache(devId);
-            if (!deviceOpt.isPresent()) {
-                log.debug("error: no device: {}, {}", devId, topic);
-                return;
-            }
-            
-            Float height = heightNum.floatValue();
-            Number startX = (Number) area.get("start_x");
-            Number startY = (Number) area.get("start_y");
-            Number startZ = (Number) area.get("start_z");
-            Number stopX = (Number) area.get("stop_x");
-            Number stopY = (Number) area.get("stop_y");
-            Number stopZ = (Number) area.get("stop_z");
-            
-            // 格式化区域字符串 (参考Python版本逻辑)
-            String areaStr = String.format("%s,%s,%s,%s,%s,%s", 
-                startX, stopX, startY, stopY, startZ, stopZ);
-            
-            // 直接向设备端发送参数设置命令 (参考Python版本逻辑)
-            // TODO: 实现向设备发送参数设置命令,参考Python版本的mqtt_send.set_dev_param_msg调用
-            log.debug("TODO: Send device param setting command for devId: {}, mountingPlain: {}, area: {}, height: {}", 
-                     devId, mountingPlain, areaStr, height);
-            
-        } catch (Exception e) {
-            log.error("deal_set_dev_param error: {}", e.getMessage());
-        }
-    }
-} 

+ 0 - 49
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mqtt/subscriber/BehaviorAnalysisSubscriber.java

@@ -1,49 +0,0 @@
-package com.hfln.device.infrastructure.mqtt.subscriber;
-
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Component;
-
-/**
- * ❌ 该类在Python版本中不存在,应该被删除
- * 
- * 🚨 重要发现:经过对比Python版本代码,发现此类完全多余!
- * 
- * Python版本分析 (post_process.py):
- * 1. Python版本没有任何"行为分析"消息处理
- * 2. Python版本只有姿态识别处理逻辑:
- *    - 收集点云数据 (get_max_len_cloud_points)
- *    - 向算法服务发送POST请求 (requests.post)
- *    - 获取姿态识别结果 (predicted_class)
- *    - 检测跌倒姿态并发送跌倒事件 (mqtt_send.event_msg)
- * 3. 不存在"/das/behavior_analysis"主题的订阅
- * 4. 不存在复杂的行为模式创建逻辑
- * 5. 不存在BehaviorPattern、BehaviorConstants等概念
- * 
- * Java版本问题:
- * ❌ 创建了不存在的BehaviorAnalysisSubscriber类
- * ❌ 监听了不存在的/das/behavior_analysis主题  
- * ❌ 添加了复杂的行为分析逻辑
- * ❌ 处理了不存在的行为模式消息
- * 
- * 修正方案:
- * ✅ 此类应该被完全删除
- * ✅ 姿态识别逻辑应该在设备处理逻辑中实现
- * ✅ 跌倒检测应该在DeviceEventServiceImpl中处理
- * 
- * TODO: 删除此类及相关的:
- * - BehaviorPattern类
- * - BehaviorConstants类
- * - handleBehaviorAnalysis相关方法
- * - DAS_BEHAVIOR_ANALYSIS主题定义
- */
-@Slf4j
-@Component
-@Deprecated
-public class BehaviorAnalysisSubscriber {
-    
-    public BehaviorAnalysisSubscriber() {
-        log.warn("⚠️  BehaviorAnalysisSubscriber类在Python版本中不存在,应该被删除!");
-        log.warn("⚠️  Python版本只有简单的姿态识别逻辑,没有复杂的行为分析");
-        log.warn("⚠️  参考Python版本的post_process.py,只需要姿态识别和跌倒检测");
-    }
-} 

+ 0 - 50
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mqtt/subscriber/DasMessageSubscriber.java

@@ -1,50 +0,0 @@
-package com.hfln.device.infrastructure.mqtt.subscriber;
-
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Component;
-
-/**
- * ❌ 该类在Python版本中不存在,应该被删除!
- * 
- * 🚨 重要发现:Python版本根本不订阅任何/das/#消息!
- * 
- * Python版本分析 (mqtt_recv.py deal_recv_msg):
- * 
- * Python版本只处理3类消息:
- * 1. /dev/# - 设备直接发送的消息 (deal_dev_msg)
- * 2. /mps/# - 小程序发送的消息 (deal_mps_msg) 
- * 3. /opc/# - 运维客户端消息 (deal_opc_msg)
- * 
- * DAS在Python版本中的真实角色:
- * - DAS是消息发布者,不是订阅者
- * - DAS接收设备原始消息,处理后发布到其他主题
- * - Python版本没有任何订阅/das/#的代码
- * 
- * Java版本的错误设计:
- * ❌ 错误地将DAS当作消息订阅者
- * ❌ 创建了大量不存在的/das/#消息订阅
- * ❌ 添加了Python版本没有的复杂处理逻辑
- * 
- * 正确的架构:
- * ✅ DAS应该是独立的消息处理服务
- * ✅ DAS应该订阅/dev/#消息并发布处理结果
- * ✅ 其他服务订阅DAS发布的消息
- * 
- * 应该删除的订阅:
- * - DAS_STATUS, DAS_CLOUDPOINT, DAS_REALTIME_POS
- * - DAS_EVENT, DAS_EXIST_EVENT, DAS_ALARM_EVENT
- * - DAS_SET_DEV_PARAM, DAS_REPORT_ALARM_PARAM
- * - DAS_DEVICE_ACTIVITY, DAS_DEVICE_REST 等
- */
-@Component
-@Slf4j
-@Deprecated
-public class DasMessageSubscriber {
-    
-    public DasMessageSubscriber() {
-        log.warn("⚠️  DasMessageSubscriber类在Python版本中不存在!");
-        log.warn("⚠️  Python版本不订阅任何/das/#消息,DAS是消息发布者不是订阅者!");
-        log.warn("⚠️  Python版本只订阅:/dev/#(设备消息)、/mps/#(APP消息)、/opc/#(运维消息)");
-        log.warn("⚠️  参考Python版本mqtt_recv.py的deal_recv_msg方法");
-    }
-} 

+ 0 - 414
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mqtt/subscriber/DeviceMessageSubscriber.java

@@ -1,414 +0,0 @@
-package com.hfln.device.infrastructure.mqtt.subscriber;
-
-import com.hfln.device.domain.port.DeviceEventPort;
-// import cn.hfln.framework.mqtt.annotation.MqttSubscriber; - 已禁�?import com.hfln.device.common.constant.mqtt.topic.MqttTopics;
-import org.springframework.beans.factory.annotation.Qualifier;
-import com.hfln.device.common.util.JsonUtil;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.messaging.Message;
-// import org.springframework.stereotype.Component; - 已禁用
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
-
-/**
- * 设备消息订阅处理�?- 已替换为Spring Integration MQTT方式
- * 处理设备相关的MQTT消息
- * 严格按照Python版本mqtt_recv.py中的deal_dev_xxx方法实现
- * 
- * @deprecated 已被 DeviceMessageHandler 替代,使用Spring Integration MQTT
- */
-// @Component - 禁用此组件,使用新的DeviceMessageHandler
-@Slf4j
-public class DeviceMessageSubscriber {
-
-    private static final Pattern DEV_ID_PATTERN = Pattern.compile("^/dev/([^/]+)/.*$");
-    
-    @Autowired
-    @Qualifier("deviceEventServiceImpl")
-    protected DeviceEventPort deviceEventPort;
-    
-    /**
-     * 处理设备登录消息
-     * 对应Python版本的deal_dev_login方法
-     * 主题�?dev/{dev_id}/login
-     * 
-     * Python处理流程�?     * 1. 解析payload获取device_info、ext_region、sensor_location
-     * 2. 提取设备基本信息:deviceid、firmware、blu_ver、device_type、device_ip
-     * 3. 从ext_region.base提取跟踪区域坐标:x1,x2,y1,y2,z1,z2
-     * 4. 从sensor_location提取安装高度:z_cm
-     * 5. 检查设备是否已注册�?     *    - 已注册且在线:直接发送登录响应,不发送状态消息(避免重复上线�?     *    - 已注册但离线:设置在线状态,更新保活时间,发送登录响应和状态消�?     *    - 未注册:创建新设备,入库,发送登录响应和状态消�?     * 6. 数据库操作:更新在线状态到数据�?     * 7. MQTT消息:发送登录响�?+ 状态变更消息(仅新设备或重新上线)
-     */
-    // @MqttSubscriber(topic = MqttTopics.DEV_LOGIN, qos = 1, desc = "设备登录")
-    public void handleDeviceLogin(String topic, Message<?> message) {
-        try {
-            log.info("Received device login message: {}", topic);
-            
-            String payload = message.getPayload().toString();
-            Map<String, Object> messageData = JsonUtil.parseMap(payload);
-            Map<String, Object> deviceInfo = (Map<String, Object>) messageData.get("device_info");
-            
-            if (deviceInfo == null) {
-                log.warn("Invalid device login message, missing device_info: {}", payload);
-                return;
-            }
-            
-            String deviceId = (String) deviceInfo.get("deviceid");
-            
-            // 委托给应用层服务处理
-            deviceEventPort.handleDeviceLogin(deviceId, deviceInfo, messageData);
-            
-        } catch (Exception e) {
-            log.error("Error handling device login: {}", e.getMessage(), e);
-        }
-    }
-    
-    /**
-     * 处理设备上报设备信息
-     * 对应Python版本的deal_report_device_info方法
-     * 主题�?dev/{dev_id}/report_device_info
-     * 
-     * Python处理流程�?     * 1. 解析设备信息payload,验证必要字段:
-     *    - deviceid:设备ID
-     *    - device_type:设备类�?     *    - firmware:固件版�?     *    - device_ip:设备IP地址
-     * 2. 检查设备是否已注册�?     *    - 已注册设备:更新设备信息,如果设备离线则重新上线
-     *    - 未注册设备:创建新设备并注册上线
-     * 3. 更新设备信息到缓存和数据库:
-     *    - 设备类型、软件版本、IP地址�?     * 4. 发送设备状态和信息更新消息�?     *    - 登录响应消息
-     *    - 设备状态变更消�?     *    - 设备信息更新消息
-     * 5. 此方法主要用于设备信息同步和状态管�?     */
-    // @MqttSubscriber(topic = MqttTopics.DEV_REP_DEV_INFO, qos = 1, desc = "设备上报设备信息")
-    public void handleDeviceReportDeviceInfo(String topic, Message<?> message) {
-        try {
-            String deviceId = extractDeviceIdFromTopic(topic);
-            if (deviceId != null) {
-                String payload = message.getPayload().toString();
-                Map<String, Object> messageData = JsonUtil.parseMap(payload);
-                
-                log.info("Device info report: {}, payload: {}", deviceId, payload);
-                
-                // 验证必要字段
-                if (!messageData.containsKey("deviceid") || !messageData.containsKey("device_type") ||
-                    !messageData.containsKey("firmware") || !messageData.containsKey("device_ip")) {
-                    log.warn("Invalid device info message, missing required fields: {}", payload);
-                    return;
-                }
-                
-                // 委托给应用层服务处理(可以复用登录逻辑或创建专门的设备信息处理方法�?                deviceEventPort.handleDeviceLogin(deviceId, messageData, messageData);
-            }
-        } catch (Exception e) {
-            log.error("Error handling device info report: {}", e.getMessage(), e);
-        }
-    }
-    
-    /**
-     * 处理设备保活消息
-     * 对应Python版本的deal_dev_keepalive方法  
-     * 主题�?dev/{dev_id}/keepalive
-     * 
-     * Python处理流程�?     * 1. 检查设备是否已注册和在线状�?     * 2. 检查调试参数是否拒绝心跳(调试模式下可禁用保活�?     * 3. 更新设备的最后保活时间戳(last_keepalive_time�?     * 4. 如果设备当前离线状态,则:
-     *    - 设置设备为在线状�?     *    - 更新数据库状�?     *    - 发送设备状态变更消息到MQTT
-     * 5. 根据设备状态发送不同的响应码:
-     *    - 在线设备:返回成功码�?�?     *    - 离线设备:返回禁止码�?�?     *    - 未注册设备:返回未授权码�?�?     * 6. 只发送心跳响应,不发送其他业务消�?     */
-    // @MqttSubscriber(topic = MqttTopics.DEV_KEEPALIVE, qos = 1, desc = "设备保活")
-    public void handleDeviceKeepAlive(String topic, Message<?> message) {
-        try {
-            String deviceId = extractDeviceIdFromTopic(topic);
-            if (deviceId != null) {
-                log.debug("Received device keepalive: {}", deviceId);
-                
-                // 委托给应用层服务处理
-                deviceEventPort.handleDeviceKeepAlive(deviceId);
-            }
-        } catch (Exception e) {
-            log.error("Error handling device keepalive: {}", e.getMessage(), e);
-        }
-    }
-    
-    /**
-     * 处理设备上报设备参数
-     * 对应Python版本的deal_report_device_param方法
-     * 主题�?dev/{dev_id}/report_device_param
-     * 
-     * Python处理流程�?     * 1. 解析消息数据,获取设备参数信�?     * 2. 验证参数格式和合法性(参数名、数据类型、取值范围)
-     * 3. 更新设备参数配置到数据库(device_params表)
-     * 4. 记录参数变更历史到日志系�?     * 5. 发送参数更新确认消息到设备
-     * 6. 如果是关键参数变更(如检测区域、灵敏度),触发相关业务逻辑�?     *    - 更新告警配置
-     *    - 重新计算检测阈�?     *    - 通知其他子系统参数变�?     * 7. 缓存参数到Redis以提高查询性能
-     */
-    // @MqttSubscriber(topic = MqttTopics.DEV_REP_DEV_PARAM, qos = 1, desc = "设备上报设备参数")
-    public void handleDeviceReportDeviceParam(String topic, Message<?> message) {
-        try {
-            String deviceId = extractDeviceIdFromTopic(topic);
-            if (deviceId != null) {
-                String payload = message.getPayload().toString();
-                Map<String, Object> messageData = JsonUtil.parseMap(payload);
-                
-                log.info("Device parameter report: {}, payload: {}", deviceId, payload);
-                
-                // 委托给应用层服务处理
-                deviceEventPort.handleDeviceParamReport(deviceId, messageData);
-            }
-        } catch (Exception e) {
-            log.error("Error handling device parameter report: {}", e.getMessage(), e);
-        }
-    }
-    
-    /**
-     * 处理设备实时数据
-     * 对应Python版本的deal_dsp_data方法
-     * 主题�?dev/{dev_id}/dsp_data
-     * 
-     * Python处理流程�?     * 1. 解析DSP(数字信号处理)实时数据�?     * 2. 提取目标位置、姿态、生命体征等关键信息�?     *    - pose:姿态信息(站立、坐着、躺下等�?     *    - targets:目标位置坐标列�?     *    - vital_signs:生命体征数据(心率、呼吸等�?     * 3. 执行数据质量检查和异常值过�?     * 4. 更新设备实时状态缓存(Redis�?     * 5. 触发实时告警检测逻辑�?     *    - 跌倒检测算�?     *    - 异常行为识别
-     *    - 生命体征异常告警
-     * 6. 发送实时位置姿态消息到指定MQTT主题
-     * 7. 记录关键数据到时序数据库(InfluxDB,如有配置)
-     * 8. QoS设置�?,允许部分数据丢失以保证实时�?     */
-    // @MqttSubscriber(topic = "/dev/+/dsp_data", qos = 0, desc = "设备实时数据")
-    public void handleDeviceDspData(String topic, Message<?> message) {
-        try {
-            String deviceId = extractDeviceIdFromTopic(topic);
-            if (deviceId != null) {
-                String payload = message.getPayload().toString();
-                Map<String, Object> messageData = JsonUtil.parseMap(payload);
-                
-                log.debug("Device dsp data: {}", deviceId);
-                
-                // 委托给应用层服务处理
-                deviceEventPort.handleDspData(deviceId, messageData);
-            }
-        } catch (Exception e) {
-            log.error("Error handling device dsp data: {}", e.getMessage(), e);
-        }
-    }
-
-    /**
-     * 处理设备点云数据
-     * 对应Python版本的deal_cloudpoint方法
-     * 主题�?dev/{dev_id}/cloudpoint
-     * 
-     * Python处理流程�?     * 1. 解析点云数据(cloud_points)和目标跟踪数据(tracker_targets�?     * 2. 对点云数据进行格式验证和异常值过滤:
-     *    - 检查坐标范围是否在传感器检测区域内
-     *    - 过滤噪点和无效数据点
-     * 3. 计算目标在跟踪区域内的精确位置坐�?     * 4. 执行目标识别和分类算法:
-     *    - 区分人体目标和环境物�?     *    - 计算目标尺寸和形状特�?     * 5. 更新目标跟踪状态和轨迹数据�?     *    - 关联历史轨迹
-     *    - 预测目标运动趋势
-     * 6. 检测目标的进入/离开区域事件
-     * 7. 发送实时位置姿态消息到MQTT主题
-     * 8. 记录轨迹数据到数据库(可选,用于行为分析�?     * 9. QoS设置�?,优先保证数据传输的实时�?     */
-    // @MqttSubscriber(topic = MqttTopics.DEV_CLOUDPOINT, qos = 0, desc = "设备点云数据")
-    public void handleDeviceCloudPoint(String topic, Message<?> message) {
-        try {
-            String deviceId = extractDeviceIdFromTopic(topic);
-            if (deviceId != null) {
-                String payload = message.getPayload().toString();
-                Map<String, Object> messageData = JsonUtil.parseMap(payload);
-                
-                log.debug("Device cloud point data: {}", deviceId);
-                
-                // 获取点云数据和目标点(按照Python版本的字段名)
-                List<List<Number>> cloudPoints = (List<List<Number>>) messageData.get("cloud_points");
-                List<List<Number>> trackerTargets = (List<List<Number>>) messageData.get("tracker_targets");
-                
-                // 转换数据类型
-                List<List<Float>> cloudPointsFloat = null;
-                if (cloudPoints != null) {
-                    cloudPointsFloat = cloudPoints.stream()
-                            .map(point -> point.stream()
-                                    .map(number -> number.floatValue())
-                                    .collect(Collectors.toList()))
-                            .collect(Collectors.toList());
-                }
-                
-                List<List<Float>> trackerTargetsFloat = null;
-                if (trackerTargets != null) {
-                    trackerTargetsFloat = trackerTargets.stream()
-                            .map(target -> target.stream()
-                                    .map(number -> number.floatValue())
-                                    .collect(Collectors.toList()))
-                            .collect(Collectors.toList());
-                }
-                
-                // 委托给应用层服务处理
-                deviceEventPort.handleCloudPoint(deviceId, cloudPointsFloat, trackerTargetsFloat);
-            }
-        } catch (Exception e) {
-            log.error("Error handling device cloud point data: {}", e.getMessage(), e);
-        }
-    }
-    
-    /**
-     * 处理设备上报跌倒事�?     * 对应Python版本的deal_report_falling_event方法
-     * 主题�?dev/{dev_id}/report_falling_event
-     * 
-     * Python处理流程�?     * 1. 解析跌倒事件数据,验证必要字段�?     *    - timestamp:事件发生时间戳
-     *    - type:事件类型标�?     *    - event:具体事件描�?     *    - fallLocX/Y/Z:跌倒位置坐标(厘米单位�?     *    - tarHeightEst:目标高度估计�?     * 2. 坐标单位转换:厘米转换为米(除以100�?     * 3. 验证跌倒位置是否在设备检测区域内
-     * 4. 检查告警间隔限制,防止重复告警�?     *    - 检查最近告警时�?     *    - 应用告警间隔配置
-     * 5. 创建跌倒告警记录:
-     *    - 记录到数据库
-     *    - 设置告警级别和状�?     * 6. 发送告警通知�?     *    - MQTT告警消息
-     *    - 短信/邮件通知(根据配置)
-     *    - 推送到监控中心
-     * 7. 更新设备状态和统计信息
-     * 8. QoS设置�?,确保重要告警消息可靠传�?     */
-    // @MqttSubscriber(topic = MqttTopics.DEV_REP_FALL_EVENT, qos = 1, desc = "设备上报跌倒事�?)
-    public void handleDeviceReportFallEvent(String topic, Message<?> message) {
-        try {
-            String deviceId = extractDeviceIdFromTopic(topic);
-            if (deviceId != null) {
-                String payload = message.getPayload().toString();
-                Map<String, Object> messageData = JsonUtil.parseMap(payload);
-                
-                log.info("Device fall event: {}, payload: {}", deviceId, payload);
-                
-                // 按照Python版本解析字段
-                if (!messageData.containsKey("timestamp") || !messageData.containsKey("type") ||
-                    !messageData.containsKey("event") || !messageData.containsKey("fallLocX") ||
-                    !messageData.containsKey("fallLocY") || !messageData.containsKey("fallLocZ") ||
-                    !messageData.containsKey("tarHeightEst")) {
-                    log.warn("Invalid fall event message, missing required fields: {}", payload);
-                    return;
-                }
-                
-                Long timestamp = ((Number) messageData.get("timestamp")).longValue();
-                String type = (String) messageData.get("type");
-                String event = (String) messageData.get("event");
-                // 注意:Python版本中坐标单位是厘米,需要除�?00转换为米
-                Float fallLocX = ((Number) messageData.get("fallLocX")).floatValue() / 100.0f;
-                Float fallLocY = ((Number) messageData.get("fallLocY")).floatValue() / 100.0f;
-                Float fallLocZ = ((Number) messageData.get("fallLocZ")).floatValue() / 100.0f;
-                Float tarHeightEst = ((Number) messageData.get("tarHeightEst")).floatValue();
-                
-                // 委托给应用层服务处理
-                deviceEventPort.handleFallEvent(deviceId, timestamp, type, event, 
-                    fallLocX, fallLocY, fallLocZ, tarHeightEst);
-            }
-        } catch (Exception e) {
-            log.error("Error handling device fall event: {}", e.getMessage(), e);
-        }
-    }
-    
-    /**
-     * 处理设备上报存在事件
-     * 对应Python版本的deal_report_presence_event方法
-     * 主题�?dev/{dev_id}/report_presence_event
-     * 
-     * Python处理流程�?     * 1. 解析存在事件数据,验证必要字段:
-     *    - timestamp:事件发生时间戳
-     *    - type:事件类型(进入/离开/持续存在等)
-     *    - event:具体事件描�?     * 2. 根据事件类型执行不同的业务逻辑�?     *    - "enter":目标进入检测区�?     *    - "leave":目标离开检测区�?     *    - "stay":目标持续停�?     * 3. 更新目标存在状态和停留时间�?     *    - 计算停留持续时间
-     *    - 更新区域占用状�?     * 4. 触发相关业务规则�?     *    - 长时间停留告�?     *    - 异常进出记录
-     *    - 区域活动统计
-     * 5. 发送事件消息到相关系统�?     *    - 实时监控面板
-     *    - 行为分析模块
-     *    - 统计分析系统
-     * 6. 记录事件到数据库供后续分�?     * 7. QoS设置�?,确保重要事件消息可靠传�?     */
-    // @MqttSubscriber(topic = MqttTopics.DEV_REP_PRES_EVENT, qos = 1, desc = "设备上报存在事件")
-    public void handleDeviceReportPresenceEvent(String topic, Message<?> message) {
-        try {
-            String deviceId = extractDeviceIdFromTopic(topic);
-            if (deviceId != null) {
-                String payload = message.getPayload().toString();
-                Map<String, Object> messageData = JsonUtil.parseMap(payload);
-                
-                log.info("Device presence event: {}, payload: {}", deviceId, payload);
-                
-                // 按照Python版本解析字段
-                if (!messageData.containsKey("timestamp") || !messageData.containsKey("type") ||
-                    !messageData.containsKey("event")) {
-                    log.warn("Invalid presence event message, missing required fields: {}", payload);
-                    return;
-                }
-                
-                Long timestamp = ((Number) messageData.get("timestamp")).longValue();
-                String type = (String) messageData.get("type");
-                String event = (String) messageData.get("event");
-                
-                // 委托给应用层服务处理
-                deviceEventPort.handleExistEvent(deviceId, timestamp, type, event);
-            }
-        } catch (Exception e) {
-            log.error("Error handling device presence event: {}", e.getMessage(), e);
-        }
-    }
-    
-    /**
-     * 处理设置调试参数
-     * 对应Python版本的deal_set_debug_param方法
-     * 主题�?dev/{dev_id}/set_debug_param
-     * 
-     * Python处理流程�?     * 1. 解析调试参数设置请求,验证参数合法�?     * 2. 支持的调试参数类型:
-     *    - reject_keepalive:拒绝心跳保�?     *    - log_level:日志级别设�?     *    - detection_sensitivity:检测灵敏度
-     *    - filter_params:数据过滤参�?     * 3. 验证参数权限和安全性:
-     *    - 检查操作权�?     *    - 验证参数值范�?     * 4. 更新设备调试配置�?     *    - 更新内存中的调试状�?     *    - 同步到Redis缓存
-     *    - 记录到数据库(debug_configs表)
-     * 5. 应用调试参数�?     *    - 动态调整设备行�?     *    - 修改数据处理逻辑
-     * 6. 发送设置结果响应给设备
-     * 7. 记录调试操作日志,便于问题追�?     * 8. QoS设置�?,确保调试指令可靠传�?     */
-    // @MqttSubscriber(topic = MqttTopics.DEV_SET_DEBUG, qos = 1, desc = "设置调试参数")
-    public void handleSetDebugParam(String topic, Message<?> message) {
-        try {
-            String deviceId = extractDeviceIdFromTopic(topic);
-            if (deviceId != null) {
-                String payload = message.getPayload().toString();
-                Map<String, Object> messageData = JsonUtil.parseMap(payload);
-                
-                log.info("Set debug param: {}, payload: {}", deviceId, payload);
-                
-                // 委托给应用层服务处理
-                deviceEventPort.handleSetDebugParam(deviceId, messageData);
-            }
-        } catch (Exception e) {
-            log.error("Error handling set debug param: {}", e.getMessage(), e);
-        }
-    }
-    
-    /**
-     * 处理获取调试参数
-     * 对应Python版本的deal_get_debug_param方法
-     * 主题�?dev/{dev_id}/get_debug_param
-     * 
-     * Python处理流程�?     * 1. 解析调试参数查询请求
-     * 2. 验证查询权限和设备状�?     * 3. 从多个数据源获取调试参数�?     *    - 内存中的实时调试状�?     *    - Redis缓存中的配置
-     *    - 数据库中的持久化配置
-     * 4. 组装完整的调试参数响应:
-     *    - 当前生效的调试参�?     *    - 参数来源和优先级
-     *    - 参数设置时间和操作�?     * 5. 格式化响应数据:
-     *    - 标准化参数格�?     *    - 添加参数说明和约�?     * 6. 发送调试参数响应到设备
-     * 7. 记录查询操作日志
-     * 8. QoS设置�?,确保查询响应可靠传�?     */
-    // @MqttSubscriber(topic = MqttTopics.DEV_GET_DEBUG, qos = 1, desc = "获取调试参数")
-    public void handleGetDebugParam(String topic, Message<?> message) {
-        try {
-            String deviceId = extractDeviceIdFromTopic(topic);
-            if (deviceId != null) {
-                String payload = message.getPayload().toString();
-                Map<String, Object> messageData = JsonUtil.parseMap(payload);
-                
-                log.info("Get debug param: {}, payload: {}", deviceId, payload);
-                
-                // 委托给应用层服务处理
-                deviceEventPort.handleGetDebugParam(deviceId, messageData);
-            }
-        } catch (Exception e) {
-            log.error("Error handling get debug param: {}", e.getMessage(), e);
-        }
-    }
-    
-    /**
-     * 从主题中提取设备ID
-     * 格式�?dev/{device_id}/xxx
-     */
-    protected String extractDeviceIdFromTopic(String topic) {
-        Matcher matcher = DEV_ID_PATTERN.matcher(topic);
-        if (matcher.find()) {
-            return matcher.group(1);
-        }
-        return null;
-    }
-} 

+ 0 - 287
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mqtt/subscriber/MpsMessageSubscriber.java

@@ -1,287 +0,0 @@
-package com.hfln.device.infrastructure.mqtt.subscriber;
-
-import com.hfln.device.application.service.DeviceCommandService;
-// import cn.hfln.framework.mqtt.annotation.MqttSubscriber; - 已禁用
-import com.hfln.device.common.constant.mqtt.topic.MqttTopics;
-import com.hfln.device.common.util.JsonUtil;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.messaging.Message;
-// import org.springframework.stereotype.Component; - 已禁用
-
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * MPS消息订阅处理器 - 已替换为Spring Integration MQTT方式
- * 处理小程序服务(Mini Program Service)相关的MQTT消息
- * 严格按照Python版本mqtt_recv.py中的deal_mps_msg方法实现
- * 
- * @deprecated 已被 MpsMessageHandler 替代,使用Spring Integration MQTT
- */
-// @Component - 禁用此组件,使用新的MpsMessageHandler
-@Slf4j
-public class MpsMessageSubscriber {
-
-    private static final Pattern DEV_REBOOT_PATTERN = Pattern.compile("^/mps/([^/]+)/reboot$");
-    
-    @Autowired
-    private DeviceCommandService deviceCommandService;
-    
-    /**
-     * 处理获取设备信息请求
-     * 对应Python版本的deal_get_dev_info_param方法
-     * 主题:/mps/get_device_info
-     * 
-     * Python处理流程:
-     * 1. 解析payload获取dev_id字段
-     * 2. 验证dev_id是否存在于设备缓存中
-     * 3. 向设备端发送get_device_info命令
-     * 4. 通过mqtt_send.get_dev_info_msg(dev_id, "get_device_info")发送请求
-     */
-    // @MqttSubscriber(topic = MqttTopics.MPS_GET_DEV_INFO, qos = 1, desc = "获取设备信息") - 已替换为Spring Integration MQTT
-    public void handleGetDeviceInfo(String topic, Message<?> message) {
-        try {
-            String payload = message.getPayload().toString();
-            Map<String, Object> messageData = JsonUtil.parseMap(payload);
-            
-            String devId = (String) messageData.get("dev_id");
-            if (devId == null) {
-                log.warn("Invalid get device info message, missing dev_id: {}", payload);
-                return;
-            }
-            
-            log.info("Received get device info request: {}", devId);
-            
-            // 委托给应用层服务处理
-            deviceCommandService.handleGetDeviceInfo(devId);
-            
-        } catch (Exception e) {
-            log.error("Error handling get device info request: {}", e.getMessage(), e);
-        }
-    }
-    
-    /**
-     * 处理获取设备参数请求
-     * 对应Python版本的deal_get_dev_info_param方法
-     * 主题:/mps/get_device_param
-     * 
-     * Python处理流程:
-     * 1. 解析payload获取dev_id字段
-     * 2. 验证dev_id是否存在于设备缓存中
-     * 3. 向设备端发送get_device_param命令
-     * 4. 通过mqtt_send.get_dev_info_msg(dev_id, "get_device_param")发送请求
-     * 注意:Python版本中get_device_info和get_device_param使用同一个处理方法
-     */
-    // @MqttSubscriber(topic = MqttTopics.MPS_GET_DEV_PARAM, qos = 1, desc = "获取设备参数") - 已替换为Spring Integration MQTT
-    public void handleGetDeviceParam(String topic, Message<?> message) {
-        try {
-            String payload = message.getPayload().toString();
-            Map<String, Object> messageData = JsonUtil.parseMap(payload);
-            
-            String devId = (String) messageData.get("dev_id");
-            if (devId == null) {
-                log.warn("Invalid get device param message, missing dev_id: {}", payload);
-                return;
-            }
-            
-            log.info("Received get device param request: {}", devId);
-            
-            // 委托给应用层服务处理(与获取设备信息使用相同的服务方法)
-            deviceCommandService.handleGetDeviceParam(devId);
-            
-        } catch (Exception e) {
-            log.error("Error handling get device param request: {}", e.getMessage(), e);
-        }
-    }
-    
-    /**
-     * 处理设置设备参数请求
-     * 对应Python版本的deal_set_dev_param方法
-     * 主题:/mps/set_device_param
-     * 
-     * Python处理流程:
-     * 1. 解析payload验证必要字段:dev_id, mounting_plain, height, area
-     * 2. 从area对象中提取坐标:start_x, start_y, start_z, stop_x, stop_y, stop_z
-     * 3. 构建area_str格式:"start_x,stop_x,start_y,stop_y,start_z,stop_z"
-     * 4. 验证设备是否存在于设备缓存中
-     * 5. 通过mqtt_send.set_dev_param_msg(dev_id, mounting_plain, area_str, height)发送设置命令
-     */
-    // @MqttSubscriber(topic = MqttTopics.MPS_SET_DEV_PARAM, qos = 1, desc = "设置设备参数") - 已替换为Spring Integration MQTT
-    public void handleSetDeviceParam(String topic, Message<?> message) {
-        try {
-            String payload = message.getPayload().toString();
-            Map<String, Object> messageData = JsonUtil.parseMap(payload);
-            
-            String devId = (String) messageData.get("dev_id");
-            String mountingPlain = (String) messageData.get("mounting_plain");
-            Number height = (Number) messageData.get("height");
-            Map<String, Object> area = (Map<String, Object>) messageData.get("area");
-            
-            if (devId == null || mountingPlain == null || height == null || area == null) {
-                log.warn("Invalid set device param message, missing required fields: {}", payload);
-                return;
-            }
-            
-            // 验证area对象中的坐标字段
-            if (!area.containsKey("start_x") || !area.containsKey("start_y") || !area.containsKey("start_z") ||
-                !area.containsKey("stop_x") || !area.containsKey("stop_y") || !area.containsKey("stop_z")) {
-                log.warn("Invalid area parameters in set device param message: {}", payload);
-                return;
-            }
-            
-            log.info("Received set device param request: {}, payload: {}", devId, payload);
-            
-            // 提取area坐标并构建area_str (按照Python版本的格式)
-            Number startX = (Number) area.get("start_x");
-            Number startY = (Number) area.get("start_y");
-            Number startZ = (Number) area.get("start_z");
-            Number stopX = (Number) area.get("stop_x");
-            Number stopY = (Number) area.get("stop_y");
-            Number stopZ = (Number) area.get("stop_z");
-            
-            String areaStr = String.format("%s,%s,%s,%s,%s,%s", 
-                startX, stopX, startY, stopY, startZ, stopZ);
-            
-            // 委托给应用层服务处理
-            deviceCommandService.handleSetDeviceParam(devId, mountingPlain, areaStr, height.floatValue());
-            
-        } catch (Exception e) {
-            log.error("Error handling set device param request: {}", e.getMessage(), e);
-        }
-    }
-    
-    /**
-     * 处理设备重启请求
-     * 对应Python版本的deal_reboot方法
-     * 主题:/mps/{dev_id}/reboot
-     * 
-     * Python处理流程:
-     * 1. 从topic路径中解析dev_id(格式:/mps/{dev_id}/reboot)
-     * 2. 通过mqtt_send.dev_reboot(dev_id)向设备发送重启命令
-     * 注意:Python版本是从topic路径解析设备ID,不是从payload
-     */
-    // @MqttSubscriber(topic = MqttTopics.MPS_DEV_REBOOT, qos = 1, desc = "设备重启") - 已替换为Spring Integration MQTT
-    public void handleDeviceReboot(String topic, Message<?> message) {
-        try {
-            // 按照Python版本从topic解析设备ID
-            Matcher matcher = DEV_REBOOT_PATTERN.matcher(topic);
-            if (!matcher.find()) {
-                log.warn("Invalid reboot topic format: {}", topic);
-                return;
-            }
-            
-            String devId = matcher.group(1);
-            log.info("Received device reboot request: {}", devId);
-            
-            // 委托给应用层服务处理
-            deviceCommandService.handleDeviceReboot(devId);
-            
-        } catch (Exception e) {
-            log.error("Error handling device reboot request: {}", e.getMessage(), e);
-        }
-    }
-    
-    /**
-     * 处理添加设备请求
-     * 对应Python版本的deal_add_device方法
-     * 主题:/mps/add_device
-     * 
-     * Python处理流程:
-     * 1. 解析payload获取dev_id字段
-     * 2. 验证dev_id是否存在
-     * 3. 查询数据库获取设备信息
-     * 4. 通过数据库请求队列执行sql_query_one_dev_info查询
-     * 5. 结果通过回调dev_mng.cb_handle_query_one_dev_info处理
-     */
-    // @MqttSubscriber(topic = "/mps/add_device", qos = 1, desc = "添加设备") - 已替换为Spring Integration MQTT
-    public void handleAddDevice(String topic, Message<?> message) {
-        try {
-            String payload = message.getPayload().toString();
-            Map<String, Object> messageData = JsonUtil.parseMap(payload);
-            
-            String devId = (String) messageData.get("dev_id");
-            if (devId == null) {
-                log.warn("Invalid add device message, missing dev_id: {}", payload);
-                return;
-            }
-            
-            log.info("Received add device request: {}", devId);
-            
-            // 委托给应用层服务处理
-            deviceCommandService.handleAddDevice(devId);
-            
-        } catch (Exception e) {
-            log.error("Error handling add device request: {}", e.getMessage(), e);
-        }
-    }
-    
-    /**
-     * 处理删除设备请求
-     * 对应Python版本的deal_del_device方法
-     * 主题:/mps/del_device
-     * 
-     * Python处理流程:
-     * 1. 解析payload获取dev_id字段
-     * 2. 验证dev_id是否存在
-     * 3. 检查设备是否在设备缓存中
-     * 4. 从设备缓存中删除设备:g_dev_map.pop(dev_id)
-     */
-    // @MqttSubscriber(topic = "/mps/del_device", qos = 1, desc = "删除设备") - 已替换为Spring Integration MQTT
-    public void handleDeleteDevice(String topic, Message<?> message) {
-        try {
-            String payload = message.getPayload().toString();
-            Map<String, Object> messageData = JsonUtil.parseMap(payload);
-            
-            String devId = (String) messageData.get("dev_id");
-            if (devId == null) {
-                log.warn("Invalid delete device message, missing dev_id: {}", payload);
-                return;
-            }
-            
-            log.info("Received delete device request: {}", devId);
-            
-            // 委托给应用层服务处理
-            deviceCommandService.handleDeleteDevice(devId);
-            
-        } catch (Exception e) {
-            log.error("Error handling delete device request: {}", e.getMessage(), e);
-        }
-    }
-    
-    /**
-     * 处理跌倒事件确认
-     * 对应Python版本的deal_fall_event_ack方法
-     * 主题:/mps/fall_event/ack
-     * 
-     * Python处理流程:
-     * 1. 解析payload获取dev_id字段
-     * 2. 验证dev_id是否存在
-     * 3. 检查设备是否在设备缓存中
-     * 4. 检查设备是否已经确认过(避免重复确认)
-     * 5. 设置设备告警确认状态:device.set_alarm_ack(True)
-     * 6. 更新确认时间:device.last_alarm_ack_time(now)
-     */
-    // @MqttSubscriber(topic = MqttTopics.MPS_FALL_EVENT_ACK, qos = 1, desc = "跌倒事件确认") - 已替换为Spring Integration MQTT
-    public void handleFallEventAck(String topic, Message<?> message) {
-        try {
-            String payload = message.getPayload().toString();
-            Map<String, Object> messageData = JsonUtil.parseMap(payload);
-            
-            String devId = (String) messageData.get("dev_id");
-            if (devId == null) {
-                log.warn("Invalid fall event ack message, missing dev_id: {}", payload);
-                return;
-            }
-            
-            log.info("Received fall event ack: {}", devId);
-            
-            // 委托给应用层服务处理
-            deviceCommandService.handleFallEventAck(devId);
-            
-        } catch (Exception e) {
-            log.error("Error handling fall event ack: {}", e.getMessage(), e);
-        }
-    }
-} 

+ 0 - 159
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/mqtt/subscriber/OpcMessageSubscriber.java

@@ -1,159 +0,0 @@
-package com.hfln.device.infrastructure.mqtt.subscriber;
-
-// import cn.hfln.framework.mqtt.annotation.MqttSubscriber; - 已禁用
-import com.hfln.device.common.util.JsonUtil;
-import com.hfln.device.domain.port.DeviceEventPort;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
-// import org.springframework.stereotype.Component; - 已禁用
-
-import java.util.Map;
-
-/**
- * 运维客户�?OPC)消息订阅�?- 已替换为Spring Integration MQTT方式
- * 负责处理OPC相关的MQTT消息
- * 
- * 对应Python版本的deal_opc_msg函数
- * 支持的主�?
- * 1. /opc/get_alarm_param - 获取告警参数
- * 2. /opc/set_alarm_param - 设置告警参数
- * 
- * @deprecated 已被 OpcMessageHandler 替代,使用Spring Integration MQTT
- */
-// @Component - 禁用此组件,使用新的OpcMessageHandler
-@Slf4j
-public class OpcMessageSubscriber {
-
-    @Autowired
-    @Qualifier("deviceEventServiceImpl")
-    private DeviceEventPort deviceEventPort;
-    
-    /**
-     * 获取告警参数消息处理
-     * 对应Python版本的deal_get_alarm_param方法
-     * 
-     * Python处理流程:
-     * 1. 解析JSON消息: json.loads(msg.payload.decode('utf-8'))
-     * 2. 检查请求类�? "global"(全局参数) �?"toilet"(厕所参数)
-     * 3. 从系统配置读取对应参�? g_sys_conf["alarm_conf"]
-     *    - retention_time: 滞留时间(�?
-     *    - retention_keep_time: 滞留保持时间(�?  
-     *    - retention_alarm_time: 滞留告警时间(�?
-     * 4. 构建响应JSON格式: {"global": {...}} �?{"toilet": {...}}
-     * 5. 发送响�? mqtt_send.report_alarm_param(0, format_json)
-     * 6. 异常处理: 解析失败或其他错误记录日�?     * 
-     * @param topic   MQTT主题
-     * @param payload 消息内容
-     */
-    // @MqttSubscriber(topic = "/opc/get_alarm_param", qos = 1)
-    public void handleGetAlarmParam(String topic, String payload) {
-        log.debug("收到获取告警参数请求: topic={}, payload={}", topic, payload);
-        
-        try {
-            // 解析消息内容
-            Map<String, Object> messageData = JsonUtil.parseMap(payload);
-            
-            // 检查请求类型并处理
-            if (messageData.containsKey("global")) {
-                // 获取全局告警参数
-                log.debug("处理全局告警参数获取请求");
-                deviceEventPort.handleGetGlobalAlarmParam(payload);
-            } else if (messageData.containsKey("toilet")) {
-                // 获取厕所告警参数
-                log.debug("处理厕所告警参数获取请求");
-                deviceEventPort.handleGetToiletAlarmParam(payload);
-            } else {
-                log.warn("无效的告警参数获取请�? {}", payload);
-            }
-        } catch (Exception e) {
-            log.error("处理获取告警参数请求失败: topic={}, payload={}", topic, payload, e);
-        }
-    }
-    
-    /**
-     * 设置告警参数消息处理
-     * 对应Python版本的deal_set_alarm_param方法
-     * 
-     * Python处理流程:
-     * 1. 解析JSON消息获取参数
-     * 2. 根据参数类型处理:
-     *    - "global": 更新全局告警参数到g_sys_conf["alarm_conf"]
-     *    - "toilet": 更新厕所告警参数到g_sys_conf["alarm_conf"]["toilet"]
-     * 3. 更新所有设备的告警配置:
-     *    - 全局参数: dev_mng.update_all_dev_alarm_conf()
-     *    - 厕所参数: dev_mng.update_all_dev_toilet_alarm_conf()
-     * 4. 发送确认响�? mqtt_send.set_alarm_param_ack(code, {})
-     *    - 成功: code=0
-     *    - 失败: code=-1
-     * 5. 参数验证: 无效参数返回错误�?1
-     * 6. 异常处理: JSON解析失败或其他错误记录日�?     * 
-     * @param topic   MQTT主题
-     * @param payload 消息内容
-     */
-    // @MqttSubscriber(topic = "/opc/set_alarm_param", qos = 1)
-    public void handleSetAlarmParam(String topic, String payload) {
-        log.debug("收到设置告警参数请求: topic={}, payload={}", topic, payload);
-        
-        try {
-            // 解析消息内容
-            Map<String, Object> messageData = JsonUtil.parseMap(payload);
-            
-            // 检查参数类型并处理
-            if (messageData.containsKey("global")) {
-                // 设置全局告警参数
-                Map<String, Object> globalParam = (Map<String, Object>) messageData.get("global");
-                log.debug("处理全局告警参数设置请求: {}", globalParam);
-                
-                // 验证必要参数
-                if (validateAlarmParams(globalParam)) {
-                    deviceEventPort.handleSetGlobalAlarmParam(payload);
-                } else {
-                    log.warn("全局告警参数验证失败: {}", globalParam);
-                    deviceEventPort.sendSetAlarmParamAck(-1, "{}");
-                }
-                
-            } else if (messageData.containsKey("toilet")) {
-                // 设置厕所告警参数
-                Map<String, Object> toiletParam = (Map<String, Object>) messageData.get("toilet");
-                log.debug("处理厕所告警参数设置请求: {}", toiletParam);
-                
-                // 验证必要参数
-                if (validateAlarmParams(toiletParam)) {
-                    deviceEventPort.handleSetToiletAlarmParam(payload);
-                } else {
-                    log.warn("厕所告警参数验证失败: {}", toiletParam);
-                    deviceEventPort.sendSetAlarmParamAck(-1, "{}");
-                }
-                
-            } else {
-                log.warn("无效的告警参数设置请求,缺少global或toilet字段: {}", payload);
-                deviceEventPort.sendSetAlarmParamAck(-1, "{}");
-            }
-        } catch (Exception e) {
-            log.error("处理设置告警参数请求失败: topic={}, payload={}", topic, payload, e);
-            try {
-                deviceEventPort.sendSetAlarmParamAck(-1, "{}");
-            } catch (Exception ex) {
-                log.error("发送错误响应失败", ex);
-            }
-        }
-    }
-    
-    /**
-     * 验证告警参数的完整�?     * 检查是否包含必要的字段: retention_time, retention_keep_time, retention_alarm_time
-     * 
-     * @param alarmParams 告警参数Map
-     * @return true if valid, false otherwise
-     */
-    private boolean validateAlarmParams(Map<String, Object> alarmParams) {
-        if (alarmParams == null) {
-            return false;
-        }
-        
-        // 检查必要字段
-        return alarmParams.containsKey("retention_time") &&
-               alarmParams.containsKey("retention_keep_time") &&
-               alarmParams.containsKey("retention_alarm_time");
-    }
-} 

+ 0 - 33
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/po/DevRoom.java

@@ -1,33 +0,0 @@
-package com.hfln.device.infrastructure.po;
-
-import com.baomidou.mybatisplus.annotation.*;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-/**
- * 设备房间表
- */
-@Data
-@EqualsAndHashCode(callSuper = true)
-@TableName("dev_room")
-public class DevRoom extends BasePO {
-    
-    /**
-     * 主键ID
-     */
-    @TableId(type = IdType.ASSIGN_ID)
-    private Long devRoomId;
-    
-    /**
-     * 设备ID
-     */
-    @TableField("dev_id")
-    private String devId;
-    
-    /**
-     * 房间参数
-     */
-    @TableField("room_params")
-    private String roomParams;
-
-} 

+ 0 - 59
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/po/DevTarget.java

@@ -1,59 +0,0 @@
-package com.hfln.device.infrastructure.po;
-
-import com.baomidou.mybatisplus.annotation.*;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-/**
- * 设备目标表
- */
-@Data
-@EqualsAndHashCode(callSuper = true)
-@TableName("dev_target")
-public class DevTarget extends BasePO {
-
-    /**
-     * 主键ID
-     */
-    @TableId(type = IdType.ASSIGN_ID)
-    private Long devTargetId;
-
-    /**
-     * 设备ID
-     */
-    private String devId;
-
-    /**
-     * 姿态
-     */
-    private Byte pose;
-
-    /**
-     * target数组
-     */
-    private String targetPoints;
-
-    /**
-     * 事件类型
-     */
-    private Byte event;
-
-    /**
-     * 是否处理:0-未处理,1-已处理
-     */
-    private Boolean isHandle;
-    
-    /**
-     * 目标常量类
-     */
-    public static class Constants {
-        
-        /**
-         * 目标状态
-         */
-        public static class TargetStatus {
-            public static final int DISABLED = 0;  // 禁用
-            public static final int ENABLED = 1;   // 启用
-        }
-    }
-} 

+ 0 - 30
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/po/GroupFloorPlan.java

@@ -1,30 +0,0 @@
-package com.hfln.device.infrastructure.po;
-
-import com.baomidou.mybatisplus.annotation.*;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-/**
- * 群组平面图表
- */
-@Data
-@EqualsAndHashCode(callSuper = true)
-@TableName("group_floor_plan")
-public class GroupFloorPlan extends BasePO {
-
-    /**
-     * 主键ID(自增)
-     */
-    @TableId(type = IdType.ASSIGN_ID)
-    private Long groupFloorPlanId;
-
-    /**
-     * 群组uuid(唯一约束)
-     */
-    private String groupUuid;
-
-    /**
-     * 平面图地址
-     */
-    private String floorPlanAddr;
-} 

+ 0 - 56
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/po/RecordPlan.java

@@ -1,56 +0,0 @@
-package com.hfln.device.infrastructure.po;
-
-import com.baomidou.mybatisplus.annotation.*;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-import java.time.LocalDate;
-
-/**
- * 录制计划表
- */
-@Data
-@EqualsAndHashCode(callSuper = true)
-@TableName("record_plan")
-public class RecordPlan extends BasePO {
-
-    /**
-     * 主键ID(自增)
-     */
-    @TableId(type = IdType.ASSIGN_ID)
-    private Long recordPlanId;
-
-    /**
-     * dev_info表id
-     */
-    private Long devInfoId;
-
-    /**
-     * 设备id
-     */
-    private String devId;
-
-    /**
-     * 是否启用:0-不启用,1-启用
-     */
-    private Boolean enable;
-
-    /**
-     * 开始日期
-     */
-    private LocalDate startDate;
-    
-    /**
-     * 录制常量类
-     */
-    public static class Constants {
-        
-        /**
-         * 计划状态
-         */
-        public static class PlanStatus {
-            public static final int DISABLED = 0;  // 禁用
-            public static final int ENABLED = 1;   // 启用
-        }
-    }
-} 

+ 0 - 50
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/po/RecordPlanTime.java

@@ -1,50 +0,0 @@
-package com.hfln.device.infrastructure.po;
-
-import com.baomidou.mybatisplus.annotation.*;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-import java.time.LocalTime;
-
-/**
- * 录制计划时间表
- */
-@Data
-@EqualsAndHashCode(callSuper = true)
-@TableName("record_plan_time")
-public class RecordPlanTime extends BasePO {
-
-    /**
-     * 主键ID(自增)
-     */
-    @TableId(type = IdType.ASSIGN_ID)
-    private Long recordPlanTimeId;
-
-    /**
-     * record_plan表id
-     */
-    private Long planId;
-
-    /**
-     * 开始时间
-     */
-    private LocalTime startTime;
-
-    /**
-     * 结束时间
-     */
-    private LocalTime endTime;
-    
-    /**
-     * 时间常量类
-     */
-    public static class Constants {
-        
-        /**
-         * 时间状态
-         */
-        public static class TimeStatus {
-            public static final int DISABLED = 0;  // 禁用
-            public static final int ENABLED = 1;   // 启用
-        }
-    }
-} 

+ 0 - 51
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/po/StatInfo.java

@@ -1,51 +0,0 @@
-package com.hfln.device.infrastructure.po;
-
-import com.baomidou.mybatisplus.annotation.*;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-import java.time.LocalDateTime;
-
-/**
- * 统计信息表
- */
-@Data
-@EqualsAndHashCode(callSuper = true)
-@TableName("stat_info")
-public class StatInfo extends BasePO {
-
-    /**
-     * 主键ID(自增)
-     */
-    @TableId(type = IdType.ASSIGN_ID)
-    private Long statInfoId;
-
-    /**
-     * 设备id
-     */
-    private String devId;
-
-    /**
-     * 设备名称
-     */
-    private String devName;
-
-    /**
-     * dev_info表id
-     */
-    private Long devInfoId;
-
-    /**
-     * 进入时间
-     */
-    private LocalDateTime enterTime;
-
-    /**
-     * 离开时间
-     */
-    private LocalDateTime leaveTime;
-
-    /**
-     * 停留时长(秒)
-     */
-    private Integer stayTime;
-} 

+ 0 - 42
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/po/TblDicItem.java

@@ -1,42 +0,0 @@
-package com.hfln.device.infrastructure.po;
-
-import com.baomidou.mybatisplus.annotation.*;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-/**
- * 字典项表
- */
-@Data
-@EqualsAndHashCode(callSuper = true)
-@TableName("tbl_dic_item")
-public class TblDicItem extends BasePO {
-
-    /**
-     * 主键ID
-     */
-    @TableId(type = IdType.ASSIGN_ID)
-    private Long itemId;
-
-    /**
-     * 字典编码
-     */
-    private String dicCode;
-
-    /**
-     * 字典项名称
-     */
-    private String itemName;
-
-    /**
-     * 字典项值
-     */
-    private String itemValue;
-
-    /**
-     * 排序号
-     */
-    private Integer sort;
-} 
-
-

+ 0 - 50
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/po/TblMenu.java

@@ -1,50 +0,0 @@
-package com.hfln.device.infrastructure.po;
-
-import com.baomidou.mybatisplus.annotation.*;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-/**
- * 菜单表
- */
-@Data
-@EqualsAndHashCode(callSuper = true)
-@TableName("tbl_menu")
-public class TblMenu extends BasePO {
-
-    /**
-     * 主键ID
-     */
-    @TableId(value = "menu_id", type = IdType.ASSIGN_ID)
-    private Long menuId;
-
-    /**
-     * 菜单编码
-     */
-    private String menuCode;
-
-    /**
-     * 菜单名称
-     */
-    private String menuName;
-
-    /**
-     * 父菜单编码
-     */
-    private String parentCode;
-
-    /**
-     * 菜单URL
-     */
-    private String menuUrl;
-
-    /**
-     * 菜单图标
-     */
-    private String menuIcon;
-
-    /**
-     * 排序号
-     */
-    private Integer sort;
-} 

+ 0 - 51
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/po/TblOprLog.java

@@ -1,51 +0,0 @@
-package com.hfln.device.infrastructure.po;
-
-import com.baomidou.mybatisplus.annotation.*;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-import java.time.LocalDateTime;
-
-/**
- * 操作日志表
- */
-@Data
-@EqualsAndHashCode(callSuper = true)
-@TableName("tbl_opr_log")
-public class TblOprLog extends BasePO {
-
-    /**
-     * 主键 ID
-     */
-    @TableId(type = IdType.ASSIGN_ID)
-    private Long oprLogId;
-
-    /**
-     * 用户 ID
-     */
-    private String userId;
-
-    /**
-     * 操作内容
-     */
-    private String operation;
-
-    /**
-     * 操作类型
-     */
-    private String operationType;
-
-    /**
-     * 操作结果
-     */
-    private String operationResult;
-
-    /**
-     * 操作时间
-     */
-    private LocalDateTime operationTime;
-
-    /**
-     * IP 地址
-     */
-    private String ipAddress;
-} 

+ 0 - 46
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/po/TblOrg.java

@@ -1,46 +0,0 @@
-package com.hfln.device.infrastructure.po;
-
-import com.baomidou.mybatisplus.annotation.*;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-/**
- * 组织机构表
- */
-@Data
-@EqualsAndHashCode(callSuper = true)
-@TableName("tbl_org")
-public class TblOrg extends BasePO {
-
-    /**
-     * 主键 ID
-     */
-    @TableId(value = "org_id", type = IdType.ASSIGN_ID)
-    private Long orgId;
-
-    /**
-     * 组织编码
-     */
-    private String orgCode;
-
-    /**
-     * 组织名称
-     */
-    private String orgName;
-
-    /**
-     * 父组织 ID
-     */
-    private Long parentId;
-
-    /**
-     * 组织类型
-     */
-    private String orgType;
-
-    /**
-     * 排序号
-     */
-    private Integer sort;
-
-} 

+ 0 - 40
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/po/TblParameter.java

@@ -1,40 +0,0 @@
-package com.hfln.device.infrastructure.po;
-
-import com.baomidou.mybatisplus.annotation.*;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-/**
- * 参数配置表
- */
-@Data
-@EqualsAndHashCode(callSuper = true)
-@TableName("tbl_parameter")
-public class TblParameter extends BasePO {
-
-    /**
-     * 主键ID
-     */
-    @TableId(type = IdType.ASSIGN_ID)
-    private Long parameterId;
-
-    /**
-     * 参数编码
-     */
-    private String paramCode;
-
-    /**
-     * 参数名称
-     */
-    private String paramName;
-
-    /**
-     * 参数值
-     */
-    private String paramValue;
-
-    /**
-     * 参数描述
-     */
-    private String paramDesc;
-} 

+ 0 - 35
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/po/TblRole.java

@@ -1,35 +0,0 @@
-package com.hfln.device.infrastructure.po;
-
-import com.baomidou.mybatisplus.annotation.*;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-/**
- * 角色表
- */
-@Data
-@EqualsAndHashCode(callSuper = true)
-@TableName("tbl_role")
-public class TblRole extends BasePO {
-
-    /**
-     * 主键 ID
-     */
-    @TableId(type = IdType.ASSIGN_ID)
-    private Long roleId;
-
-    /**
-     * 角色编码
-     */
-    private String roleCode;
-
-    /**
-     * 角色名称
-     */
-    private String roleName;
-
-    /**
-     * 角色描述
-     */
-    private String roleDesc;
-} 

+ 0 - 29
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/po/TblUserRole.java

@@ -1,29 +0,0 @@
-package com.hfln.device.infrastructure.po;
-
-import com.baomidou.mybatisplus.annotation.*;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-/**
- * 用户角色关联表
- */
-@Data
-@EqualsAndHashCode(callSuper = true)
-@TableName("tbl_user_role")
-public class TblUserRole extends BasePO {
-    /**
-     * 主键ID
-     */
-    @TableId(type = IdType.ASSIGN_ID)
-    private Long userRoleId;
-
-    /**
-     * 用户ID
-     */
-    private String userId;
-
-    /**
-     * 角色ID
-     */
-    private String roleId;
-} 

+ 0 - 47
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/po/TblWxpaycert.java

@@ -1,47 +0,0 @@
-package com.hfln.device.infrastructure.po;
-
-import com.baomidou.mybatisplus.annotation.*;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-import java.time.LocalDateTime;
-
-/**
- * 微信支付证书表
- */
-@Data
-@EqualsAndHashCode(callSuper = true)
-@TableName("tbl_wxpaycert")
-public class TblWxpaycert extends BasePO {
-
-    /**
-     * 主键ID
-     */
-    @TableId(type = IdType.ASSIGN_ID)
-    private Long wxpaycertId;
-
-    /**
-     * 证书类型
-     */
-    private String certType;
-
-    /**
-     * 证书内容
-     */
-    private String certContent;
-
-    /**
-     * 证书序列号
-     */
-    private String serialNo;
-
-    /**
-     * 生效时间
-     */
-    private LocalDateTime effectiveTime;
-
-    /**
-     * 过期时间
-     */
-    private LocalDateTime expireTime;
-} 

+ 0 - 83
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/service/impl/MenuServiceImpl.java

@@ -1,83 +0,0 @@
-//package com.hfln.device.infrastructure.service.impl;
-//
-//import com.hfln.device.domain.entity.MenuEntity;
-//import com.hfln.device.domain.tree.TreeSelect;
-//import com.hfln.device.infrastructure.service.MenuService;
-//import org.springframework.stereotype.Service;
-//
-//import java.util.ArrayList;
-//import java.util.List;
-//import java.util.stream.Collectors;
-//
-///**
-// * @BelongsProject: harryDev
-// * @BelongsPackage: com.hfln.device.infrastructure.service.impl
-// * @Author: huangls
-// * @CreateTime: 2023-10-17  16:25
-// * @Description: TODO
-// * @Version: 1.0
-// */
-//@Service
-//public class MenuServiceImpl implements MenuService {
-//    @Override
-//    public List<TreeSelect> buildMenuTreeSelect(List<MenuEntity> menus) {
-//        List<MenuEntity> menuTrees = buildMenuTree(menus);
-//        return menuTrees.stream().map(TreeSelect::new).collect(Collectors.toList());
-//    }
-//
-//    @Override
-//    public List<MenuEntity> buildMenuTree(List<MenuEntity> menus) {
-//        List<MenuEntity> menuList = new ArrayList<>();
-//        List<Long> tempList = menus.stream().map(MenuEntity::getMenuId).collect(Collectors.toList());
-//        for (MenuEntity menu : menus) {
-//            // 濡傛灉鏄《绾ц妭鐐? 閬嶅巻璇ョ埗鑺傜偣鐨勬墍鏈夊瓙鑺傜偣
-//            if (!tempList.contains(menu.getParentId())) {
-//                recursionFn(menus, menu);
-//                menuList.add(menu);
-//            }
-//        }
-//        if (menuList.isEmpty()) {
-//            menuList = menus;
-//        }
-//        return menuList;
-//    }
-//
-//    /**
-//     * 閫掑綊鍒楄〃
-//     *
-//     * @param list 鍒嗙被琛?
-//     * @param t    瀛愯妭鐐?
-//     */
-//    private void recursionFn(List<MenuEntity> list, MenuEntity t) {
-//        // 寰楀埌瀛愯妭鐐瑰垪琛?
-//        List<MenuEntity> childList = getChildList(list, t);
-//        t.setChildren(childList);
-//        for (MenuEntity tChild : childList) {
-//            if (hasChild(list, tChild)) {
-//                recursionFn(list, tChild);
-//            }
-//        }
-//    }
-//
-//    /**
-//     * 寰楀埌瀛愯妭鐐瑰垪琛?
-//     */
-//    private List<MenuEntity> getChildList(List<MenuEntity> list, MenuEntity t) {
-//        List<MenuEntity> tlist = new ArrayList<>();
-//        for (MenuEntity n : list) {
-//            if (n.getParentId().longValue() == t.getMenuId().longValue()) {
-//                tlist.add(n);
-//            }
-//        }
-//        return tlist;
-//    }
-//
-//    /**
-//     * 鍒ゆ柇鏄惁鏈夊瓙鑺傜偣
-//     */
-//    private boolean hasChild(List<MenuEntity> list, MenuEntity t) {
-//        return getChildList(list, t).size() > 0;
-//    }
-//}
-
-