refactor(ops,iot): 重构区域设备关联模块并添加Redis缓存
主要变更:
1. 将 ops_area_device_relation 表所有权移至 Ops 模块
- 新增 OpsAreaDeviceRelationDO、Mapper、Service、Controller
- 新增 AreaDeviceApi Feign 接口供其他模块调用
- ���除 IoT 模块中的旧 DO 和 Mapper
2. 实现 Redis JSON 缓存(IoT 可读)
- 统一缓存 Key: ops:area:device:{deviceId}
- 统一缓存 Key: ops:area:{areaId}:type:{relationType}
- TTL: 30分钟,空值缓存: 1分钟
3. IoT 模块通过 Feign 调用 Ops
- 优先读 Redis 缓存,未命中时调用 Ops API
- 缓存由 Ops 模块统一管理
4. 删除 IoT 模块废弃文件
- OpsAreaDeviceRelationDO.java
- OpsAreaDeviceRelationMapper.java
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
package com.viewsh.module.ops.api.area;
|
||||
|
||||
import com.viewsh.framework.common.pojo.CommonResult;
|
||||
import com.viewsh.module.ops.enums.ApiConstants;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 区域设备关联 API
|
||||
* <p>
|
||||
* 提供 RPC 接口供其他模块(如 IoT 模块)查询区域设备关联关系
|
||||
* <p>
|
||||
* 支持功能:
|
||||
* - 查询区域的工牌设备列表
|
||||
* - 查询设备的关联关系
|
||||
* - 按类型查询区域设备
|
||||
*
|
||||
* @author lzh
|
||||
*/
|
||||
@FeignClient(name = ApiConstants.NAME) // TODO 芋艿:fallbackFactory =
|
||||
@Tag(name = "RPC 服务 - 区域设备关联")
|
||||
public interface AreaDeviceApi {
|
||||
|
||||
String PREFIX = ApiConstants.PREFIX + "/area-device";
|
||||
|
||||
// ==================== 按区域查询 ====================
|
||||
|
||||
@GetMapping(PREFIX + "/{areaId}/badges")
|
||||
@Operation(summary = "查询区域的工牌设备列表")
|
||||
CommonResult<List<AreaDeviceDTO>> getBadgesByArea(
|
||||
@Parameter(description = "区域ID", required = true, example = "1302")
|
||||
@PathVariable("areaId") Long areaId
|
||||
);
|
||||
|
||||
@GetMapping(PREFIX + "/{areaId}/devices")
|
||||
@Operation(summary = "查询区域设备列表(按类型)")
|
||||
CommonResult<List<AreaDeviceDTO>> getDevicesByAreaAndType(
|
||||
@Parameter(description = "区域ID", required = true, example = "1302")
|
||||
@PathVariable("areaId") Long areaId,
|
||||
@Parameter(description = "关联类型(BADGE/TRAFFIC_COUNTER/BEACON)", required = true, example = "BADGE")
|
||||
@RequestParam("relationType") String relationType
|
||||
);
|
||||
|
||||
// ==================== 按设备查询 ====================
|
||||
|
||||
@GetMapping(PREFIX + "/device/{deviceId}/relation")
|
||||
@Operation(summary = "查询设备的关联关系")
|
||||
CommonResult<DeviceRelationDTO> getDeviceRelation(
|
||||
@Parameter(description = "设备ID", required = true, example = "34")
|
||||
@PathVariable("deviceId") Long deviceId
|
||||
);
|
||||
|
||||
@GetMapping(PREFIX + "/device/{deviceId}/full-relation")
|
||||
@Operation(summary = "查询设备的完整关联关系(包含集成配置)")
|
||||
CommonResult<DeviceRelationDTO> getDeviceRelationWithConfig(
|
||||
@Parameter(description = "设备ID", required = true, example = "34")
|
||||
@PathVariable("deviceId") Long deviceId
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.viewsh.module.ops.api.area;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 区域设备 DTO
|
||||
* <p>
|
||||
* 表示运营区域与 IoT 设备的关联关系
|
||||
*
|
||||
* @author lzh
|
||||
*/
|
||||
@Schema(description = "区域设备关联")
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class AreaDeviceDTO {
|
||||
|
||||
@Schema(description = "设备ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "34")
|
||||
private Long deviceId;
|
||||
|
||||
@Schema(description = "设备Key", example = "09207457042")
|
||||
private String deviceKey;
|
||||
|
||||
@Schema(description = "产品ID", example = "19")
|
||||
private Long productId;
|
||||
|
||||
@Schema(description = "产品Key", example = "AOQwO9pJWKgfFTk4")
|
||||
private String productKey;
|
||||
|
||||
@Schema(description = "区域ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1302")
|
||||
private Long areaId;
|
||||
|
||||
@Schema(description = "关联类型", example = "BADGE")
|
||||
private String relationType;
|
||||
|
||||
@Schema(description = "是否启用", example = "true")
|
||||
private Boolean enabled;
|
||||
|
||||
@Schema(description = "集成配置(JSON)")
|
||||
private Map<String, Object> configData;
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.viewsh.module.ops.api.area;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 设备关联 DTO
|
||||
* <p>
|
||||
* 表示设备的区域关联关系
|
||||
*
|
||||
* @author lzh
|
||||
*/
|
||||
@Schema(description = "设备关联关系")
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class DeviceRelationDTO {
|
||||
|
||||
@Schema(description = "设备ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "34")
|
||||
private Long deviceId;
|
||||
|
||||
@Schema(description = "设备Key", example = "09207457042")
|
||||
private String deviceKey;
|
||||
|
||||
@Schema(description = "产品ID", example = "19")
|
||||
private Long productId;
|
||||
|
||||
@Schema(description = "产品Key", example = "AOQwO9pJWKgfFTk4")
|
||||
private String productKey;
|
||||
|
||||
@Schema(description = "区域ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1302")
|
||||
private Long areaId;
|
||||
|
||||
@Schema(description = "关联类型", example = "BADGE")
|
||||
private String relationType;
|
||||
|
||||
@Schema(description = "是否启用", example = "true")
|
||||
private Boolean enabled;
|
||||
|
||||
@Schema(description = "集成配置(JSON)")
|
||||
private Map<String, Object> configData;
|
||||
}
|
||||
@@ -9,6 +9,13 @@ import com.viewsh.framework.common.enums.RpcConstants;
|
||||
*/
|
||||
public class ApiConstants {
|
||||
|
||||
/**
|
||||
* 服务名
|
||||
*
|
||||
* 注意,需要保证和 spring.application.name 保持一致
|
||||
*/
|
||||
public static final String NAME = "ops-server";
|
||||
|
||||
public static final String PREFIX = RpcConstants.RPC_API_PREFIX + "/ops";
|
||||
|
||||
public static final String VERSION = "1.0.0";
|
||||
|
||||
Reference in New Issue
Block a user