优化算法和故障诊断逻辑

This commit is contained in:
weitang 2025-05-15 17:50:18 +08:00
parent 44576b6147
commit 05ab1e9d4d
8 changed files with 101 additions and 36 deletions

View File

@ -5,8 +5,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yfd.platform.config.ResponseResult;
import com.yfd.platform.modules.algorithm.domain.AlgorithmClass;
import com.yfd.platform.modules.algorithm.domain.AlgorithmParamsRequest;
import com.yfd.platform.modules.algorithm.domain.TreeNode;
import com.yfd.platform.modules.algorithm.service.IAlgorithmClassService;
import com.yfd.platform.modules.basedata.domain.TreeNode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

View File

@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
/**
* <p>
@ -41,4 +42,20 @@ public class AlgorithmDeviceController {
return ResponseResult.error();
}
}
@PostMapping("/getAlgorithmDeviceParams")
@ApiOperation("查询算法部件的参数")
public ResponseResult getAlgorithmDeviceParams(String algorithmId, String componentId) {
List<Map<String, Object>> algorithmDeviceParams = algorithmDeviceService.getAlgorithmDeviceParams(algorithmId
, componentId);
return ResponseResult.successData(algorithmDeviceParams);
}
// @PostMapping("/getAlgorithmDeviceParams")
// @ApiOperation("查询算法部件的参数")
// public ResponseResult getAlgorithmDeviceParams(String algorithmId, String componentId) {
// List<Map<String, Object>> algorithmDeviceParams = algorithmDeviceService.getAlgorithmDeviceParams(algorithmId
// , componentId);
// return ResponseResult.successData(algorithmDeviceParams);
// }
}

View File

@ -0,0 +1,31 @@
package com.yfd.platform.modules.algorithm.domain;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import java.util.ArrayList;
import java.util.List;
/**
* @Date: 2024/4/18 15:10
* @Description:
*/
@Data
@EqualsAndHashCode(callSuper = false)
@AllArgsConstructor
@NoArgsConstructor
public class TreeNode {
private String id;
private String name;
private String parentId;
private List<TreeNode> children = new ArrayList<>();
public TreeNode(String id, String name, String parentId) {
this.id = id;
this.parentId = parentId;
this.name = name;
}
}

View File

@ -3,7 +3,7 @@ package com.yfd.platform.modules.algorithm.service;
import com.yfd.platform.modules.algorithm.domain.AlgorithmClass;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yfd.platform.modules.algorithm.domain.AlgorithmParamsRequest;
import com.yfd.platform.modules.basedata.domain.TreeNode;
import com.yfd.platform.modules.algorithm.domain.TreeNode;
import java.util.List;

View File

@ -4,6 +4,7 @@ import com.yfd.platform.modules.algorithm.domain.AlgorithmDevice;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
import java.util.Map;
/**
* <p>
@ -22,4 +23,6 @@ public interface IAlgorithmDeviceService extends IService<AlgorithmDevice> {
***********************************/
boolean batchAddAlgorithmDevice(List<AlgorithmDevice> algorithmDeviceList);
List<Map<String, Object>> getAlgorithmDeviceParams(String algorithmId, String componentId);
}

View File

@ -4,18 +4,15 @@ import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yfd.platform.modules.algorithm.domain.AlgorithmClass;
import com.yfd.platform.modules.algorithm.domain.AlgorithmParams;
import com.yfd.platform.modules.algorithm.domain.AlgorithmParamsRequest;
import com.yfd.platform.modules.algorithm.domain.TreeNode;
import com.yfd.platform.modules.algorithm.mapper.AlgorithmClassComponentMapper;
import com.yfd.platform.modules.algorithm.mapper.AlgorithmClassMapper;
import com.yfd.platform.modules.algorithm.mapper.AlgorithmParamsMapper;
import com.yfd.platform.modules.algorithm.service.IAlgorithmClassService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yfd.platform.modules.algorithm.service.IAlgorithmParamsService;
import com.yfd.platform.modules.basedata.domain.TreeNode;
import com.yfd.platform.utils.SecurityUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -132,13 +129,11 @@ public class AlgorithmClassServiceImpl extends ServiceImpl<AlgorithmClassMapper,
* 返回值说明: java.util.List<com.yfd.platform.modules.basedata.domain.TreeNode>
***********************************/
public List<TreeNode> buildSignalTree(List<Map<String, Object>> dataList) {
// 存储所有节点使用ID作为键
Map<String, TreeNode> nodeMap = new HashMap<>();
// 存储最终返回的根节点列表
List<TreeNode> roots = new ArrayList<>();
// 遍历原始数据
for (Map<String, Object> data : dataList) {
// 1. 解析各层级信息根据实际字段名称调整
// 解析字段根据实际字段名称调整
String stationCode = (String) data.get("stationCode");
String stationName = (String) data.get("stationName");
String algorithmId = (String) data.get("algorithmId");
@ -146,33 +141,34 @@ public class AlgorithmClassServiceImpl extends ServiceImpl<AlgorithmClassMapper,
String componentId = (String) data.get("componentId");
String componentName = (String) data.get("componentName");
TreeNode stationNode = nodeMap.computeIfAbsent(stationCode,
k -> {
TreeNode node = new TreeNode(stationCode, stationName);
roots.add(node); // 将变电站作为根节点
// 1. 处理变电站节点根节点
TreeNode stationNode = nodeMap.computeIfAbsent(stationCode, k -> {
TreeNode node = new TreeNode(stationCode, stationName,null);
roots.add(node); // 添加为根节点
return node;
});
if (StrUtil.isNotBlank(algorithmId)) {
// 2. 处理算法节点第二层
// 使用复合键stationKey + ":" + algorithmId 确保唯一性
String algorithmKey = stationCode + ":" + algorithmId;
TreeNode algorithmNode = nodeMap.computeIfAbsent(algorithmKey, k -> {
TreeNode node = new TreeNode(algorithmId, algorithmClassName,stationCode);
stationNode.getChildren().add(node); // 挂载到变电站节点下
return node;
});
if (StrUtil.isNotBlank(componentId)) {
// 3. 处理组件节点第三层
// 使用复合键algorithmKey + ":" + componentId 确保唯一性
String componentKey = algorithmKey + ":" + componentId;
nodeMap.computeIfAbsent(componentKey, k -> {
TreeNode node = new TreeNode(componentId, componentName,algorithmId);
algorithmNode.getChildren().add(node); // 挂载到算法节点下
return node;
});
if (StrUtil.isNotBlank(algorithmId)) {
// 处理变电站层级
TreeNode areaNode = nodeMap.computeIfAbsent(algorithmId,
k -> {
TreeNode node = new TreeNode(algorithmId, algorithmClassName);
stationNode.getChildren().add(node); // 将变电站作为根节点
return node;
});
// 处理区域层级
if (StrUtil.isNotBlank(componentId)) {
nodeMap.computeIfAbsent(componentId,
k -> {
TreeNode node = new TreeNode(componentId, componentName);
areaNode.getChildren().add(node);
return node;
});
}
}
}
return roots;
}

View File

@ -1,5 +1,7 @@
package com.yfd.platform.modules.algorithm.service.impl;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yfd.platform.modules.algorithm.domain.AlgorithmDevice;
import com.yfd.platform.modules.algorithm.mapper.AlgorithmDeviceMapper;
import com.yfd.platform.modules.algorithm.service.IAlgorithmDeviceService;
@ -9,6 +11,7 @@ import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
/**
* <p>
@ -35,4 +38,12 @@ public class AlgorithmDeviceServiceImpl extends ServiceImpl<AlgorithmDeviceMappe
});
return this.saveOrUpdateBatch(algorithmDeviceList);
}
@Override
public List<Map<String, Object>> getAlgorithmDeviceParams(String algorithmId, String componentId) {
LambdaQueryWrapper<AlgorithmDevice> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(StrUtil.isNotBlank(algorithmId), AlgorithmDevice::getAlgorithmId, algorithmId);
queryWrapper.eq(StrUtil.isNotBlank(componentId), AlgorithmDevice::getComponentId, componentId).select(AlgorithmDevice::getDeviceName, AlgorithmDevice::getDeviceId, AlgorithmDevice::getParamValue);
return this.listMaps(queryWrapper);
}
}

View File

@ -4,11 +4,18 @@
<select id="getAlgorithmComponentList" resultType="java.util.Map">
SELECT
acc.*,ac.algorithm_class_name
acc.id,
acc.algorithm_id,
acc.station_code,
acc.station_name,
acc.component_id,
CONCAT( acc.main_device_name, '-', acc.component_name ) component_name,
ac.algorithm_class_name
FROM
iis_algorithm_class ac
INNER JOIN iis_algorithm_class_component acc ON ac.id = acc.algorithm_id
WHERE 1=1
WHERE
1 =1
<if test="algorithmClassName != null and algorithmClassName != ''">
AND ac.algorithm_class_name LIKE CONCAT('%',#{algorithmClassName},'%')
</if>