refactor(iot): 优化设备和事件相关接口

- 移除了 DeviceController 中未使用的导入- 更新了 EventController 中的事件日志分页接口,使用路径变量
- 在 RecordDataServiceImpl 中增加了对设备下无事件的异常处理
- 移除了 DeviceServiceImpl 中的冗余空行
This commit is contained in:
zhuangtianxiang 2025-03-21 11:26:45 +08:00
parent 049e91db82
commit 4aa7567b93
4 changed files with 6 additions and 8 deletions

View File

@ -15,14 +15,11 @@ import com.zsc.edu.gateway.modules.iot.device.vo.DeviceVo;
import com.zsc.edu.gateway.modules.iot.record.entity.RecordData;
import com.zsc.edu.gateway.modules.iot.record.service.RecordDataService;
import com.zsc.edu.gateway.modules.operationLog.entity.OperationLogAnnotation;
import jakarta.annotation.Resource;
import lombok.AllArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import java.util.List;

View File

@ -240,4 +240,4 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceRepository, Device> imp
device.setOnline(!device.getOnline());
return baseMapper.updateById(device);
}
}
}

View File

@ -1,5 +1,6 @@
package com.zsc.edu.gateway.modules.iot.record.service.impl;
import com.alibaba.fastjson2.JSONException;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
@ -106,7 +107,7 @@ public class RecordDataServiceImpl extends ServiceImpl<RecordDataRepository, Rec
// 获取产品下的所有事件
List<Event> events = eventRepository.selectByProductId(device.getProductId(), true);
if (events.isEmpty()) {
return; // 如果没有事件直接返回
throw new JSONException("该设备下事件并未启用!或者该设备下无定义事件!");
}
// 遍历每个事件

View File

@ -74,12 +74,12 @@ public class EventController {
* @param page 分页参数
* @return Page<Device> 事件分页数据
*/
@GetMapping("/log")
@GetMapping("/{clientId}/log")
@PreAuthorize("hasAuthority('iot:event:query')")
public IPage<EventLog> eventLogPage(Page<EventLog> page, String clientId) {
public IPage<EventLog> eventLogPage(Page<EventLog> page, @PathVariable("clientId") String clientId) {
return eventLogRepository.selectPage(page, new LambdaQueryWrapper<EventLog>().eq(EventLog::getRecordId, clientId));
}
//TODO 详情接口
/**
* 删除事件