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,73 @@
|
||||
package com.viewsh.module.ops.controller.area;
|
||||
|
||||
import com.viewsh.framework.common.pojo.CommonResult;
|
||||
import com.viewsh.framework.common.util.object.BeanUtils;
|
||||
import com.viewsh.module.ops.api.area.AreaDeviceDTO;
|
||||
import com.viewsh.module.ops.api.area.DeviceRelationDTO;
|
||||
import com.viewsh.module.ops.dal.dataobject.area.OpsAreaDeviceRelationDO;
|
||||
import com.viewsh.module.ops.service.area.AreaDeviceService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.viewsh.framework.common.pojo.CommonResult.success;
|
||||
|
||||
/**
|
||||
* 区域设备关联 Controller
|
||||
* <p>
|
||||
* 提供 RPC 接口供其他模块(如 IoT 模块)查询区域设备关联关系
|
||||
*
|
||||
* @author lzh
|
||||
*/
|
||||
@Tag(name = "RPC 服务 - 区域设备关联")
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/ops-api/area-device")
|
||||
@Validated
|
||||
public class AreaDeviceController {
|
||||
|
||||
@Resource
|
||||
private AreaDeviceService areaDeviceService;
|
||||
|
||||
@GetMapping("/{areaId}/badges")
|
||||
@Operation(summary = "查询区域的工牌设备列表")
|
||||
public CommonResult<List<AreaDeviceDTO>> getBadgesByArea(
|
||||
@PathVariable("areaId") Long areaId) {
|
||||
List<OpsAreaDeviceRelationDO> relations = areaDeviceService.listByAreaIdAndType(areaId, "BADGE");
|
||||
return success(BeanUtils.toBean(relations, AreaDeviceDTO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/{areaId}/devices")
|
||||
@Operation(summary = "查询区域设备列表(按类型)")
|
||||
public CommonResult<List<AreaDeviceDTO>> getDevicesByAreaAndType(
|
||||
@PathVariable("areaId") Long areaId,
|
||||
@RequestParam("relationType") String relationType) {
|
||||
List<OpsAreaDeviceRelationDO> relations = areaDeviceService.listByAreaIdAndType(areaId, relationType);
|
||||
return success(BeanUtils.toBean(relations, AreaDeviceDTO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/device/{deviceId}/relation")
|
||||
@Operation(summary = "查询设备的关联关系")
|
||||
public CommonResult<DeviceRelationDTO> getDeviceRelation(
|
||||
@PathVariable("deviceId") Long deviceId) {
|
||||
OpsAreaDeviceRelationDO relation = areaDeviceService.getByDeviceId(deviceId);
|
||||
return success(BeanUtils.toBean(relation, DeviceRelationDTO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/device/{deviceId}/full-relation")
|
||||
@Operation(summary = "查询设备的完整关联关系(包含集成配置)")
|
||||
public CommonResult<DeviceRelationDTO> getDeviceRelationWithConfig(
|
||||
@PathVariable("deviceId") Long deviceId) {
|
||||
OpsAreaDeviceRelationDO relation = areaDeviceService.getByDeviceId(deviceId);
|
||||
DeviceRelationDTO dto = BeanUtils.toBean(relation, DeviceRelationDTO.class);
|
||||
// BeanUtils 会自动复制 configData Map 字段
|
||||
return success(dto);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user