新增: 按设备查询和批量修改 ROI 绑定算法参数 API
This commit is contained in:
@@ -39,4 +39,12 @@ public class AiRoiAlgoBind {
|
||||
|
||||
@Schema(description = "更新时间")
|
||||
private String updateTime;
|
||||
|
||||
// ---- 以下为关联查询字段,非表字段 ----
|
||||
|
||||
@Schema(description = "设备ID(关联查询)")
|
||||
private String deviceId;
|
||||
|
||||
@Schema(description = "ROI名称(关联查询)")
|
||||
private String roiName;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.genersoft.iot.vmp.aiot.controller;
|
||||
|
||||
import com.genersoft.iot.vmp.aiot.bean.AiAlgorithm;
|
||||
import com.genersoft.iot.vmp.aiot.bean.AiRoiAlgoBind;
|
||||
import com.genersoft.iot.vmp.aiot.service.IAiAlgorithmService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -8,6 +9,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -20,10 +22,27 @@ public class AiAlgorithmController {
|
||||
@Autowired
|
||||
private IAiAlgorithmService algorithmService;
|
||||
|
||||
@Operation(summary = "查询算法列表")
|
||||
@Operation(summary = "查询算法列表(可选按设备覆盖参数)")
|
||||
@GetMapping("/list")
|
||||
public List<AiAlgorithm> queryList() {
|
||||
return algorithmService.queryAll();
|
||||
public List<AiAlgorithm> queryList(@RequestParam(required = false) String deviceId) {
|
||||
List<AiAlgorithm> algorithms = algorithmService.queryAll();
|
||||
if (deviceId != null && !deviceId.isEmpty()) {
|
||||
List<AiRoiAlgoBind> binds = algorithmService.queryBindsByDevice(deviceId);
|
||||
// 按 algo_code 分组,取第一个绑定的 params 作为该设备的"实际参数"
|
||||
Map<String, String> deviceParams = new HashMap<>();
|
||||
for (AiRoiAlgoBind bind : binds) {
|
||||
if (!deviceParams.containsKey(bind.getAlgoCode()) && bind.getParams() != null) {
|
||||
deviceParams.put(bind.getAlgoCode(), bind.getParams());
|
||||
}
|
||||
}
|
||||
for (AiAlgorithm algo : algorithms) {
|
||||
String dp = deviceParams.get(algo.getAlgoCode());
|
||||
if (dp != null) {
|
||||
algo.setGlobalParams(dp); // 用设备实际参数覆盖展示
|
||||
}
|
||||
}
|
||||
}
|
||||
return algorithms;
|
||||
}
|
||||
|
||||
@Operation(summary = "启用/禁用算法")
|
||||
@@ -44,4 +63,19 @@ public class AiAlgorithmController {
|
||||
String globalParams = body.get("globalParams");
|
||||
algorithmService.saveGlobalParams(algoCode, globalParams);
|
||||
}
|
||||
|
||||
@Operation(summary = "查询设备下所有ROI算法绑定")
|
||||
@GetMapping("/device-binds/{deviceId}")
|
||||
public List<AiRoiAlgoBind> queryDeviceBinds(@PathVariable String deviceId) {
|
||||
return algorithmService.queryBindsByDevice(deviceId);
|
||||
}
|
||||
|
||||
@Operation(summary = "批量更新设备下某算法的参数")
|
||||
@PostMapping("/device-binds/{deviceId}/{algoCode}")
|
||||
public void updateDeviceAlgoParams(@PathVariable String deviceId,
|
||||
@PathVariable String algoCode,
|
||||
@RequestBody Map<String, String> body) {
|
||||
String params = body.get("params");
|
||||
algorithmService.updateDeviceAlgoParams(deviceId, algoCode, params);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,4 +45,18 @@ public interface AiRoiAlgoBindMapper {
|
||||
|
||||
@Select("SELECT * FROM wvp_ai_roi_algo_bind ORDER BY priority DESC, id")
|
||||
List<AiRoiAlgoBind> queryAll();
|
||||
|
||||
@Select("SELECT b.*, r.device_id, r.name AS roi_name FROM wvp_ai_roi_algo_bind b " +
|
||||
"LEFT JOIN wvp_ai_roi r ON b.roi_id = r.roi_id " +
|
||||
"WHERE r.device_id = #{deviceId} ORDER BY b.priority DESC, b.id")
|
||||
List<AiRoiAlgoBind> queryByDeviceId(@Param("deviceId") String deviceId);
|
||||
|
||||
@Update("UPDATE wvp_ai_roi_algo_bind b " +
|
||||
"INNER JOIN wvp_ai_roi r ON b.roi_id = r.roi_id " +
|
||||
"SET b.params = #{params}, b.update_time = #{updateTime} " +
|
||||
"WHERE r.device_id = #{deviceId} AND b.algo_code = #{algoCode}")
|
||||
int updateParamsByDeviceAndAlgo(@Param("deviceId") String deviceId,
|
||||
@Param("algoCode") String algoCode,
|
||||
@Param("params") String params,
|
||||
@Param("updateTime") String updateTime);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.genersoft.iot.vmp.aiot.service;
|
||||
|
||||
import com.genersoft.iot.vmp.aiot.bean.AiAlgorithm;
|
||||
import com.genersoft.iot.vmp.aiot.bean.AiRoiAlgoBind;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -15,4 +16,8 @@ public interface IAiAlgorithmService {
|
||||
void syncFromEdge();
|
||||
|
||||
void saveGlobalParams(String algoCode, String globalParams);
|
||||
|
||||
List<AiRoiAlgoBind> queryBindsByDevice(String deviceId);
|
||||
|
||||
void updateDeviceAlgoParams(String deviceId, String algoCode, String params);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package com.genersoft.iot.vmp.aiot.service.impl;
|
||||
|
||||
import com.genersoft.iot.vmp.aiot.bean.AiAlgorithm;
|
||||
import com.genersoft.iot.vmp.aiot.bean.AiRoiAlgoBind;
|
||||
import com.genersoft.iot.vmp.aiot.config.AiServiceConfig;
|
||||
import com.genersoft.iot.vmp.aiot.dao.AiAlgorithmMapper;
|
||||
import com.genersoft.iot.vmp.aiot.dao.AiRoiAlgoBindMapper;
|
||||
import com.genersoft.iot.vmp.aiot.service.IAiAlgorithmService;
|
||||
import com.genersoft.iot.vmp.aiot.service.IAiConfigLogService;
|
||||
import com.genersoft.iot.vmp.aiot.service.IAiConfigService;
|
||||
import com.genersoft.iot.vmp.aiot.service.IAiRedisConfigService;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -25,6 +28,9 @@ public class AiAlgorithmServiceImpl implements IAiAlgorithmService {
|
||||
@Autowired
|
||||
private AiAlgorithmMapper algorithmMapper;
|
||||
|
||||
@Autowired
|
||||
private AiRoiAlgoBindMapper roiAlgoBindMapper;
|
||||
|
||||
@Autowired
|
||||
private AiServiceConfig aiServiceConfig;
|
||||
|
||||
@@ -34,6 +40,9 @@ public class AiAlgorithmServiceImpl implements IAiAlgorithmService {
|
||||
@Autowired
|
||||
private IAiConfigService configService;
|
||||
|
||||
@Autowired
|
||||
private IAiRedisConfigService redisConfigService;
|
||||
|
||||
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
/**
|
||||
@@ -176,4 +185,24 @@ public class AiAlgorithmServiceImpl implements IAiAlgorithmService {
|
||||
log.warn("[AI算法] 全局参数推送失败(参数已保存): {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AiRoiAlgoBind> queryBindsByDevice(String deviceId) {
|
||||
return roiAlgoBindMapper.queryByDeviceId(deviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDeviceAlgoParams(String deviceId, String algoCode, String params) {
|
||||
String now = LocalDateTime.now().format(FORMATTER);
|
||||
int updated = roiAlgoBindMapper.updateParamsByDeviceAndAlgo(deviceId, algoCode, params, now);
|
||||
log.info("[AI算法] 批量更新设备算法参数: deviceId={}, algoCode={}, 影响行数={}", deviceId, algoCode, updated);
|
||||
|
||||
// 更新后推送该设备配置到边缘端
|
||||
try {
|
||||
redisConfigService.writeDeviceAggregatedConfig(deviceId, "UPDATE");
|
||||
log.info("[AI算法] 设备参数变更已推送到边缘端: deviceId={}", deviceId);
|
||||
} catch (Exception e) {
|
||||
log.warn("[AI算法] 设备参数推送失败(参数已保存): {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user