feat(aiot): 新增边缘设备分页/统计端点,修复 backfill 类型转换错误
- AiEdgeDeviceController 新增 /page、/get、/statistics 端点供前端直调 - AiEdgeDeviceMapper 新增 queryPage、countByStatus、countAll 方法 - AiEdgeDeviceServiceImpl 使用 PageHelper 实现分页查询和统计 - 修复 backfill-device-id 的 String→Integer ClassCastException: renameDeviceId 改为 renameByDeviceId,用 device_id 定位行 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -142,7 +142,7 @@ public class AiConfigController {
|
|||||||
// 将第一个设备改名为 "edge"
|
// 将第一个设备改名为 "edge"
|
||||||
AiEdgeDevice first = devices.get(0);
|
AiEdgeDevice first = devices.get(0);
|
||||||
String oldId = first.getDeviceId();
|
String oldId = first.getDeviceId();
|
||||||
edgeDeviceMapper.renameDeviceId(first.getId(), targetDeviceId);
|
edgeDeviceMapper.renameByDeviceId(oldId, targetDeviceId);
|
||||||
result.put("device_action", "renamed");
|
result.put("device_action", "renamed");
|
||||||
result.put("old_device_id", oldId);
|
result.put("old_device_id", oldId);
|
||||||
log.info("[AiConfig] 已将设备 {} 改名为 {}", oldId, targetDeviceId);
|
log.info("[AiConfig] 已将设备 {} 改名为 {}", oldId, targetDeviceId);
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package com.genersoft.iot.vmp.aiot.controller;
|
|||||||
|
|
||||||
import com.genersoft.iot.vmp.aiot.bean.AiEdgeDevice;
|
import com.genersoft.iot.vmp.aiot.bean.AiEdgeDevice;
|
||||||
import com.genersoft.iot.vmp.aiot.service.IAiEdgeDeviceService;
|
import com.genersoft.iot.vmp.aiot.service.IAiEdgeDeviceService;
|
||||||
|
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
||||||
|
import com.github.pagehelper.PageInfo;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -9,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
@@ -30,4 +33,27 @@ public class AiEdgeDeviceController {
|
|||||||
public AiEdgeDevice queryDetail(@PathVariable String deviceId) {
|
public AiEdgeDevice queryDetail(@PathVariable String deviceId) {
|
||||||
return edgeDeviceService.queryByDeviceId(deviceId);
|
return edgeDeviceService.queryByDeviceId(deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "边缘设备分页查询")
|
||||||
|
@GetMapping("/page")
|
||||||
|
public WVPResult<PageInfo<AiEdgeDevice>> queryPage(
|
||||||
|
@RequestParam(defaultValue = "1") int pageNo,
|
||||||
|
@RequestParam(defaultValue = "20") int pageSize,
|
||||||
|
@RequestParam(required = false) String status) {
|
||||||
|
PageInfo<AiEdgeDevice> pageInfo = edgeDeviceService.queryPage(pageNo, pageSize, status);
|
||||||
|
return WVPResult.success(pageInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "按设备ID查询")
|
||||||
|
@GetMapping("/get")
|
||||||
|
public WVPResult<AiEdgeDevice> queryByParam(@RequestParam String deviceId) {
|
||||||
|
AiEdgeDevice device = edgeDeviceService.queryByDeviceId(deviceId);
|
||||||
|
return WVPResult.success(device);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "设备统计")
|
||||||
|
@GetMapping("/statistics")
|
||||||
|
public WVPResult<Map<String, Object>> statistics() {
|
||||||
|
return WVPResult.success(edgeDeviceService.getStatistics());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,4 +36,21 @@ public interface AiEdgeDeviceMapper {
|
|||||||
|
|
||||||
@Update("UPDATE wvp_ai_edge_device SET device_id=#{newDeviceId} WHERE id=#{id}")
|
@Update("UPDATE wvp_ai_edge_device SET device_id=#{newDeviceId} WHERE id=#{id}")
|
||||||
int renameDeviceId(@Param("id") Integer id, @Param("newDeviceId") String newDeviceId);
|
int renameDeviceId(@Param("id") Integer id, @Param("newDeviceId") String newDeviceId);
|
||||||
|
|
||||||
|
@Update("UPDATE wvp_ai_edge_device SET device_id=#{newDeviceId} WHERE device_id=#{oldDeviceId}")
|
||||||
|
int renameByDeviceId(@Param("oldDeviceId") String oldDeviceId, @Param("newDeviceId") String newDeviceId);
|
||||||
|
|
||||||
|
@Select({"<script>" +
|
||||||
|
"SELECT * FROM wvp_ai_edge_device " +
|
||||||
|
"WHERE 1=1 " +
|
||||||
|
"<if test='status != null'> AND status=#{status}</if> " +
|
||||||
|
"ORDER BY updated_at DESC" +
|
||||||
|
"</script>"})
|
||||||
|
List<AiEdgeDevice> queryPage(@Param("status") String status);
|
||||||
|
|
||||||
|
@Select("SELECT COUNT(*) FROM wvp_ai_edge_device WHERE status=#{status}")
|
||||||
|
int countByStatus(@Param("status") String status);
|
||||||
|
|
||||||
|
@Select("SELECT COUNT(*) FROM wvp_ai_edge_device")
|
||||||
|
int countAll();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
package com.genersoft.iot.vmp.aiot.service;
|
package com.genersoft.iot.vmp.aiot.service;
|
||||||
|
|
||||||
import com.genersoft.iot.vmp.aiot.bean.AiEdgeDevice;
|
import com.genersoft.iot.vmp.aiot.bean.AiEdgeDevice;
|
||||||
|
import com.github.pagehelper.PageInfo;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public interface IAiEdgeDeviceService {
|
public interface IAiEdgeDeviceService {
|
||||||
|
|
||||||
@@ -13,4 +15,8 @@ public interface IAiEdgeDeviceService {
|
|||||||
List<AiEdgeDevice> queryAll();
|
List<AiEdgeDevice> queryAll();
|
||||||
|
|
||||||
void checkOffline();
|
void checkOffline();
|
||||||
|
|
||||||
|
PageInfo<AiEdgeDevice> queryPage(int page, int count, String status);
|
||||||
|
|
||||||
|
Map<String, Object> getStatistics();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import com.alibaba.fastjson2.JSONObject;
|
|||||||
import com.genersoft.iot.vmp.aiot.bean.AiEdgeDevice;
|
import com.genersoft.iot.vmp.aiot.bean.AiEdgeDevice;
|
||||||
import com.genersoft.iot.vmp.aiot.dao.AiEdgeDeviceMapper;
|
import com.genersoft.iot.vmp.aiot.dao.AiEdgeDeviceMapper;
|
||||||
import com.genersoft.iot.vmp.aiot.service.IAiEdgeDeviceService;
|
import com.genersoft.iot.vmp.aiot.service.IAiEdgeDeviceService;
|
||||||
|
import com.github.pagehelper.PageHelper;
|
||||||
|
import com.github.pagehelper.PageInfo;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
@@ -12,7 +14,9 @@ import org.springframework.stereotype.Service;
|
|||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@@ -82,4 +86,20 @@ public class AiEdgeDeviceServiceImpl implements IAiEdgeDeviceService {
|
|||||||
log.warn("[AiEdgeDevice] 标记{}台设备为离线", count);
|
log.warn("[AiEdgeDevice] 标记{}台设备为离线", count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageInfo<AiEdgeDevice> queryPage(int page, int count, String status) {
|
||||||
|
PageHelper.startPage(page, count);
|
||||||
|
List<AiEdgeDevice> list = deviceMapper.queryPage(status);
|
||||||
|
return new PageInfo<>(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> getStatistics() {
|
||||||
|
Map<String, Object> stats = new HashMap<>();
|
||||||
|
stats.put("total", deviceMapper.countAll());
|
||||||
|
stats.put("online", deviceMapper.countByStatus("online"));
|
||||||
|
stats.put("offline", deviceMapper.countByStatus("offline"));
|
||||||
|
return stats;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user