refactor(iot): 优化设备和事件相关接口
- 移除了 DeviceController 中未使用的导入- 更新了 EventController 中的事件日志分页接口,使用路径变量 - 在 RecordDataServiceImpl 中增加了对设备下无事件的异常处理 - 移除了 DeviceServiceImpl 中的冗余空行
This commit is contained in:
parent
049e91db82
commit
4aa7567b93
@ -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.entity.RecordData;
|
||||||
import com.zsc.edu.gateway.modules.iot.record.service.RecordDataService;
|
import com.zsc.edu.gateway.modules.iot.record.service.RecordDataService;
|
||||||
import com.zsc.edu.gateway.modules.operationLog.entity.OperationLogAnnotation;
|
import com.zsc.edu.gateway.modules.operationLog.entity.OperationLogAnnotation;
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -240,4 +240,4 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceRepository, Device> imp
|
|||||||
device.setOnline(!device.getOnline());
|
device.setOnline(!device.getOnline());
|
||||||
return baseMapper.updateById(device);
|
return baseMapper.updateById(device);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package com.zsc.edu.gateway.modules.iot.record.service.impl;
|
package com.zsc.edu.gateway.modules.iot.record.service.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSONException;
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
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);
|
List<Event> events = eventRepository.selectByProductId(device.getProductId(), true);
|
||||||
if (events.isEmpty()) {
|
if (events.isEmpty()) {
|
||||||
return; // 如果没有事件,直接返回
|
throw new JSONException("该设备下事件并未启用!或者该设备下无定义事件!");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 遍历每个事件
|
// 遍历每个事件
|
||||||
|
@ -74,12 +74,12 @@ public class EventController {
|
|||||||
* @param page 分页参数
|
* @param page 分页参数
|
||||||
* @return Page<Device> 事件分页数据
|
* @return Page<Device> 事件分页数据
|
||||||
*/
|
*/
|
||||||
@GetMapping("/log")
|
@GetMapping("/{clientId}/log")
|
||||||
@PreAuthorize("hasAuthority('iot:event:query')")
|
@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));
|
return eventLogRepository.selectPage(page, new LambdaQueryWrapper<EventLog>().eq(EventLog::getRecordId, clientId));
|
||||||
}
|
}
|
||||||
|
//TODO 详情接口
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除事件
|
* 删除事件
|
||||||
|
Loading…
Reference in New Issue
Block a user