优化算法和故障诊断逻辑(曲线和算法绑定)
This commit is contained in:
parent
d4cbebaaf4
commit
9fabff6be9
@ -54,8 +54,8 @@ public class AlgorithmDeviceController {
|
||||
@PostMapping("/getAlgorithmDeviceCurve")
|
||||
@ApiOperation("查询算法部件的参数曲线")
|
||||
public ResponseResult getAlgorithmDeviceCurve(String algorithmId, String componentId) {
|
||||
Map<String, Object> algorithmDeviceCurve = algorithmDeviceService.getAlgorithmDeviceCurve(algorithmId,
|
||||
List<Map<String, Object>> algorithmDeviceCurveList = algorithmDeviceService.getAlgorithmDeviceCurve(algorithmId,
|
||||
componentId);
|
||||
return ResponseResult.successData(algorithmDeviceCurve);
|
||||
return ResponseResult.successData(algorithmDeviceCurveList);
|
||||
}
|
||||
}
|
||||
|
@ -32,8 +32,16 @@ public class AlgorithmParamsController {
|
||||
|
||||
@GetMapping("/getAlgorithmParamsList")
|
||||
@ApiOperation("查询算法参数")
|
||||
public ResponseResult getAlgorithmParamsList(String algorithmId) {
|
||||
List<Map<String, Object>> algorithmClassList = algorithmParamsService.getAlgorithmParamsList(algorithmId);
|
||||
public ResponseResult getAlgorithmParamsList(String algorithmId,String componentId) {
|
||||
List<Map<String, Object>> algorithmClassList = algorithmParamsService.getAlgorithmParamsList(algorithmId,componentId);
|
||||
return ResponseResult.successData(algorithmClassList);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/getAlgorithmParamsNameList")
|
||||
@ApiOperation("根据算法id过去参数名称")
|
||||
public ResponseResult getAlgorithmParamsNameList(String algorithmId) {
|
||||
List<Map<String, Object>> algorithmClassList = algorithmParamsService.getAlgorithmParamsNameList(algorithmId);
|
||||
return ResponseResult.successData(algorithmClassList);
|
||||
}
|
||||
|
||||
|
@ -17,4 +17,6 @@ import java.util.Map;
|
||||
public interface AlgorithmDeviceMapper extends BaseMapper<AlgorithmDevice> {
|
||||
|
||||
List<Map<String, Object>> getAlgorithmDeviceParams(String algorithmId, String componentId);
|
||||
|
||||
List<Map<String, Object>> getAlgorithmDeviceType(String algorithmId, String componentId);
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ import java.util.Map;
|
||||
*/
|
||||
public interface AlgorithmParamsMapper extends BaseMapper<AlgorithmParams> {
|
||||
|
||||
List<Map<String, Object>> getAlgorithmParamsList(String algorithmId);
|
||||
List<Map<String, Object>> getAlgorithmParamsList(String algorithmId,String componentId);
|
||||
|
||||
List<Map<String, Object>> getAlgorithmParamsNameList(String algorithmId);
|
||||
}
|
||||
|
@ -25,6 +25,6 @@ public interface IAlgorithmDeviceService extends IService<AlgorithmDevice> {
|
||||
|
||||
List<Map<String, Object>> getAlgorithmDeviceParams(String algorithmId, String componentId);
|
||||
|
||||
Map<String, Object> getAlgorithmDeviceCurve(String algorithmId, String componentId);
|
||||
List<Map<String, Object>> getAlgorithmDeviceCurve(String algorithmId, String componentId);
|
||||
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ import java.util.Map;
|
||||
*/
|
||||
public interface IAlgorithmParamsService extends IService<AlgorithmParams> {
|
||||
|
||||
List<Map<String, Object>> getAlgorithmParamsList(String algorithmId);
|
||||
List<Map<String, Object>> getAlgorithmParamsList(String algorithmId,String componentId);
|
||||
|
||||
boolean addAlgorithmParams(AlgorithmParams algorithmParams);
|
||||
|
||||
@ -26,4 +26,6 @@ public interface IAlgorithmParamsService extends IService<AlgorithmParams> {
|
||||
boolean batchUpdateAlgorithmParams(List<AlgorithmParams> algorithmParamsList);
|
||||
|
||||
boolean deleteAlgorithmParams(String id);
|
||||
|
||||
List<Map<String, Object>> getAlgorithmParamsNameList(String algorithmId);
|
||||
}
|
||||
|
@ -5,23 +5,20 @@ import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
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.domain.*;
|
||||
import com.yfd.platform.modules.algorithm.mapper.AlgorithmClassComponentMapper;
|
||||
import com.yfd.platform.modules.algorithm.mapper.AlgorithmClassMapper;
|
||||
import com.yfd.platform.modules.algorithm.service.IAlgorithmClassService;
|
||||
import com.yfd.platform.modules.algorithm.service.IAlgorithmDeviceService;
|
||||
import com.yfd.platform.modules.algorithm.service.IAlgorithmParamsService;
|
||||
import com.yfd.platform.utils.SecurityUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -37,7 +34,8 @@ public class AlgorithmClassServiceImpl extends ServiceImpl<AlgorithmClassMapper,
|
||||
|
||||
@Resource
|
||||
private IAlgorithmParamsService algorithmParamsService;
|
||||
|
||||
@Resource
|
||||
private IAlgorithmDeviceService algorithmDeviceService;
|
||||
@Resource
|
||||
private AlgorithmClassComponentMapper algorithmClassComponentMapper;
|
||||
|
||||
@ -95,16 +93,38 @@ public class AlgorithmClassServiceImpl extends ServiceImpl<AlgorithmClassMapper,
|
||||
String uuid = IdUtil.fastSimpleUUID();
|
||||
algorithmClass.setId(uuid);
|
||||
}
|
||||
// String currentUsername = SecurityUtils.getCurrentUsername();
|
||||
String currentUsername = "admin";
|
||||
String currentUsername = SecurityUtils.getCurrentUsername();
|
||||
this.saveOrUpdate(algorithmClass);
|
||||
List<AlgorithmParams> algorithmParamsList = algorithmParamsRequest.getAlgorithmParamsList();
|
||||
// 获取修改的参数id
|
||||
Set<String> paramIdList =
|
||||
algorithmParamsList.stream().filter(a -> StrUtil.isNotBlank(a.getId())).map(AlgorithmParams::getId).collect(Collectors.toSet());
|
||||
|
||||
// 排除修改的算法参数,删除掉其他算法参数和点位信息
|
||||
|
||||
LambdaQueryWrapper<AlgorithmDevice> deviceQueryWrapper = new LambdaQueryWrapper<>();
|
||||
deviceQueryWrapper.eq(AlgorithmDevice::getAlgorithmId, algorithmClass.getId());
|
||||
if (paramIdList.size() > 0) {
|
||||
deviceQueryWrapper.notIn(AlgorithmDevice::getParamId, paramIdList);
|
||||
}
|
||||
algorithmDeviceService.remove(deviceQueryWrapper);
|
||||
|
||||
LambdaQueryWrapper<AlgorithmParams> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(AlgorithmParams::getAlgorithmId, algorithmClass.getId());
|
||||
if (paramIdList.size() > 0) {
|
||||
queryWrapper.notIn(AlgorithmParams::getId, paramIdList);
|
||||
}
|
||||
algorithmParamsService.remove(queryWrapper);
|
||||
|
||||
algorithmParamsList.forEach(r -> {
|
||||
r.setAlgorithmId(algorithmClass.getId());
|
||||
r.setLastmodifier(currentUsername);
|
||||
r.setLastmodifydate(LocalDateTime.now());
|
||||
});
|
||||
return algorithmParamsService.saveOrUpdateBatch(algorithmParamsList);
|
||||
if (algorithmParamsList.size() > 0) {
|
||||
return algorithmParamsService.saveOrUpdateBatch(algorithmParamsList);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/***********************************
|
||||
|
@ -1,18 +1,28 @@
|
||||
package com.yfd.platform.modules.algorithm.service.impl;
|
||||
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
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;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.yfd.platform.modules.auxcontrol.domain.DeviceSignal;
|
||||
import com.yfd.platform.modules.auxcontrol.domain.DeviceWorkData;
|
||||
import com.yfd.platform.modules.auxcontrol.mapper.DeviceSignalMapper;
|
||||
import com.yfd.platform.modules.auxcontrol.service.IDeviceWorkDataService;
|
||||
import com.yfd.platform.utils.SecurityUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -27,6 +37,10 @@ public class AlgorithmDeviceServiceImpl extends ServiceImpl<AlgorithmDeviceMappe
|
||||
|
||||
@Resource
|
||||
private AlgorithmDeviceMapper algorithmDeviceMapper;
|
||||
@Resource
|
||||
private DeviceSignalMapper deviceSignalMapper;
|
||||
@Resource
|
||||
private IDeviceWorkDataService deviceWorkDataService;
|
||||
|
||||
/**********************************
|
||||
* 用途说明: 批量新增算法分类部件点位关联数据
|
||||
@ -45,11 +59,98 @@ public class AlgorithmDeviceServiceImpl extends ServiceImpl<AlgorithmDeviceMappe
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> getAlgorithmDeviceParams(String algorithmId, String componentId) {
|
||||
return algorithmDeviceMapper.getAlgorithmDeviceParams(algorithmId,componentId);
|
||||
return algorithmDeviceMapper.getAlgorithmDeviceParams(algorithmId, componentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getAlgorithmDeviceCurve(String algorithmId, String componentId) {
|
||||
return null;
|
||||
public List<Map<String, Object>> getAlgorithmDeviceCurve(String algorithmId, String componentId) {
|
||||
List<Map<String, Object>> list = algorithmDeviceMapper.getAlgorithmDeviceType(algorithmId, componentId);
|
||||
Map<String, List<String>> groupedDevices = list.stream()
|
||||
.filter(map -> map.containsKey("sourceType") && map.get("sourceType") != null)
|
||||
.filter(map -> map.containsKey("deviceId") && map.get("deviceId") != null)
|
||||
.collect(Collectors.groupingBy(
|
||||
map -> ((String) map.get("sourceType")).trim(), // 去除前后空格
|
||||
Collectors.mapping(
|
||||
map -> ((String) map.get("deviceId")).trim(),
|
||||
Collectors.toList() // 或 Collectors.toSet() 去重
|
||||
)
|
||||
));
|
||||
List<Map<String, Object>> deviceDataList = new ArrayList<>();
|
||||
List<String> deviceIdList = groupedDevices.get("1");
|
||||
List<String> signalIdList = groupedDevices.get("2");
|
||||
if (deviceIdList != null && deviceIdList.size() > 0) {
|
||||
|
||||
}
|
||||
if (signalIdList != null && signalIdList.size() > 0) {
|
||||
List<DeviceWorkData> deviceWorkDataList = deviceWorkDataService.getHistoricalCurveList(signalIdList);
|
||||
Map<String, List<DeviceWorkData>> collect =
|
||||
deviceWorkDataList.stream().collect(Collectors.groupingBy(DeviceWorkData::getSignalId));
|
||||
for (String signalId : collect.keySet()) {
|
||||
List<DeviceWorkData> deviceWorkDataGroup = collect.get(signalId);
|
||||
Map<String, Object> map = processDeviceData(deviceWorkDataGroup, signalId);
|
||||
deviceDataList.add(map);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return deviceDataList;
|
||||
}
|
||||
|
||||
public Map<String, Object> processDeviceData(List<DeviceWorkData> deviceWorkDataList, String signalId) {
|
||||
// 生成过去60分钟的分钟时间槽
|
||||
LocalDateTime now = LocalDateTime.now().truncatedTo(ChronoUnit.MINUTES);
|
||||
LocalDateTime startTime = now.minusMinutes(59);
|
||||
List<LocalDateTime> minuteSlots = new ArrayList<>();
|
||||
for (int i = 0; i < 60; i++) {
|
||||
minuteSlots.add(startTime.plusMinutes(i));
|
||||
}
|
||||
|
||||
// 按分钟分组数据
|
||||
Map<LocalDateTime, String> minuteDataMap = new HashMap<>();
|
||||
for (DeviceWorkData data : deviceWorkDataList) {
|
||||
LocalDateTime minuteKey = data.getStartTime().truncatedTo(ChronoUnit.MINUTES);
|
||||
minuteDataMap.put(minuteKey, data.getValue());
|
||||
}
|
||||
|
||||
// 构建xAxis和series数据
|
||||
List<String> xAxisData = new ArrayList<>();
|
||||
List<Double> seriesData = new ArrayList<>();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH时mm分");
|
||||
for (LocalDateTime slot : minuteSlots) {
|
||||
xAxisData.add(slot.format(formatter));
|
||||
String value = minuteDataMap.getOrDefault(slot, "0");
|
||||
if (!NumberUtil.isDouble(value)) {
|
||||
value = "0";
|
||||
}
|
||||
seriesData.add(NumberUtil.parseDouble(value));
|
||||
}
|
||||
|
||||
// 构建ECharts数据结构
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
Map<String, Object> xAxis = new HashMap<>();
|
||||
xAxis.put("type", "category");
|
||||
xAxis.put("data", xAxisData);
|
||||
result.put("xAxis", xAxis);
|
||||
|
||||
Map<String, Object> yAxis = new HashMap<>();
|
||||
yAxis.put("type", "value");
|
||||
result.put("yAxis", yAxis);
|
||||
DeviceSignal deviceSignal = deviceSignalMapper.selectById(signalId);
|
||||
String name = deviceSignal == null ? "" : deviceSignal.getSignalName();
|
||||
List<Map<String, Object>> seriesList = new ArrayList<>();
|
||||
Map<String, Object> series = new HashMap<>();
|
||||
series.put("name", name);
|
||||
series.put("type", "line");
|
||||
series.put("data", seriesData);
|
||||
seriesList.add(series);
|
||||
|
||||
// 如果需要多个系列,可以继续添加
|
||||
// 例如复制series并修改name和step
|
||||
|
||||
result.put("series", seriesList);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,8 +25,8 @@ public class AlgorithmParamsServiceImpl extends ServiceImpl<AlgorithmParamsMappe
|
||||
private AlgorithmParamsMapper algorithmParamsMapper;
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> getAlgorithmParamsList(String algorithmId) {
|
||||
return algorithmParamsMapper.getAlgorithmParamsList(algorithmId);
|
||||
public List<Map<String, Object>> getAlgorithmParamsList(String algorithmId,String componentId) {
|
||||
return algorithmParamsMapper.getAlgorithmParamsList(algorithmId,componentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -48,4 +48,9 @@ public class AlgorithmParamsServiceImpl extends ServiceImpl<AlgorithmParamsMappe
|
||||
public boolean deleteAlgorithmParams(String id) {
|
||||
return this.removeById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> getAlgorithmParamsNameList(String algorithmId) {
|
||||
return algorithmParamsMapper.getAlgorithmParamsNameList(algorithmId);
|
||||
}
|
||||
}
|
||||
|
@ -36,5 +36,9 @@ public interface DeviceWorkDataMapper extends BaseMapper<DeviceWorkData> {
|
||||
***********************************/
|
||||
List<DeviceWorkData> getHistoricalCurve(String signalId);
|
||||
|
||||
|
||||
List<Map<String, Object>> getDeviceWorkData(String stationId);
|
||||
|
||||
List<DeviceWorkData> getHistoricalCurveList(List<String> signalIdList);
|
||||
|
||||
}
|
||||
|
@ -46,6 +46,13 @@ public interface IDeviceWorkDataService extends IService<DeviceWorkData> {
|
||||
***********************************/
|
||||
List<DeviceWorkData> getHistoricalCurve(String signalId);
|
||||
|
||||
/**********************************
|
||||
* 用途说明: 查询历史曲线
|
||||
* 参数说明 signalList 信号id集合
|
||||
* 返回值说明: java.util.List<com.yfd.platform.modules.auxcontrol.domain.DeviceWorkData>
|
||||
***********************************/
|
||||
List<DeviceWorkData> getHistoricalCurveList(List<String> signalIdList);
|
||||
|
||||
List<Map<String, Object>> getDeviceWorkData(String stationId);
|
||||
|
||||
}
|
||||
|
@ -94,6 +94,11 @@ public class DeviceWorkDataServiceImpl extends ServiceImpl<DeviceWorkDataMapper,
|
||||
return deviceWorkDataMapper.getHistoricalCurve(signalId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceWorkData> getHistoricalCurveList(List<String> signalIdList) {
|
||||
return deviceWorkDataMapper.getHistoricalCurveList(signalIdList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> getDeviceWorkData(String stationId) {
|
||||
return deviceWorkDataMapper.getDeviceWorkData(stationId);
|
||||
|
@ -20,4 +20,20 @@
|
||||
AND ad.component_id LIKE CONCAT('%',#{componentId},'%')
|
||||
</if>
|
||||
</select>
|
||||
<select id="getAlgorithmDeviceType" resultType="java.util.Map">
|
||||
SELECT
|
||||
ad.device_id,
|
||||
ad.source_type
|
||||
FROM
|
||||
iis_algorithm_params ap
|
||||
INNER JOIN iis_algorithm_device ad ON ap.id = ad.param_id
|
||||
WHERE
|
||||
ap.param_fixed = '0'
|
||||
<if test="algorithmId != null and algorithmId != ''">
|
||||
AND ad.algorithm_id LIKE CONCAT('%',#{algorithmId},'%')
|
||||
</if>
|
||||
<if test="componentId != null and componentId != ''">
|
||||
AND ad.component_id LIKE CONCAT('%',#{componentId},'%')
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
||||
|
@ -21,11 +21,28 @@
|
||||
ap.id
|
||||
FROM
|
||||
iis_algorithm_params ap
|
||||
LEFT JOIN iis_algorithm_device ad ON ap.id = ad.param_id
|
||||
LEFT JOIN iis_algorithm_device ad
|
||||
ON ap.id = ad.param_id
|
||||
<!-- 动态添加 component_id 匹配条件 -->
|
||||
<if test="componentId != null and componentId != ''">
|
||||
AND ad.component_id = #{componentId}
|
||||
</if>
|
||||
WHERE 1=1
|
||||
<if test="algorithmId != null and algorithmId != ''">
|
||||
AND ap.algorithm_id = #{algorithmId}
|
||||
</if>
|
||||
|
||||
</select>
|
||||
<select id="getAlgorithmParamsNameList" resultType="java.util.Map">
|
||||
SELECT
|
||||
id,
|
||||
param_name,
|
||||
param_type,
|
||||
param_unit
|
||||
FROM
|
||||
iis_algorithm_params
|
||||
WHERE 1=1
|
||||
<if test="algorithmId != null and algorithmId != ''">
|
||||
AND algorithm_id = #{algorithmId}
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
||||
|
@ -56,4 +56,22 @@
|
||||
sc.component_name = '微气象设备部件'
|
||||
ORDER BY orderno
|
||||
</select>
|
||||
<select id="getHistoricalCurveList" resultType="com.yfd.platform.modules.auxcontrol.domain.DeviceWorkData">
|
||||
SELECT
|
||||
start_time,
|
||||
`value`,
|
||||
unit,
|
||||
signal_id
|
||||
FROM
|
||||
fk_device_work_data
|
||||
WHERE
|
||||
1=1 and signal_id IN
|
||||
<foreach collection="signalIdList" item="signalId" open="(" separator=","
|
||||
close=")">
|
||||
#{signalId}
|
||||
</foreach>
|
||||
AND start_time >= NOW() - INTERVAL 1 HOUR
|
||||
ORDER BY
|
||||
start_time DESC
|
||||
</select>
|
||||
</mapper>
|
||||
|
Loading…
Reference in New Issue
Block a user