From 37d97f338c6f1f8f5883f5dea4271b7c3196e606 Mon Sep 17 00:00:00 2001 From: "zangch@mesnac.com" Date: Wed, 7 Jan 2026 17:32:42 +0800 Subject: [PATCH] =?UTF-8?q?feat(record):=20=E6=B7=BB=E5=8A=A0=E6=8C=AF?= =?UTF-8?q?=E5=8A=A8=E8=AE=BE=E5=A4=87=E5=8F=82=E6=95=B0=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在RecordIotenvInstant实体类中添加vibrationParam字段用于振动参数选择 - 修改IRecordIotenvInstantService接口方法,增加vibrationParam参数支持 - 更新Controller层解析振动参数并传递给Service方法 - 在Mapper XML中实现振动设备按选中参数过滤数据的逻辑 - 修改Service实现类支持振动设备单参数过滤和导出 - 优化振动数据有效性判断逻辑,添加参数值范围验证 - 更新导出列选择逻辑,支持振动设备按参数选择导出特定字段 --- .../RecordIotenvInstantController.java | 7 +- .../record/domain/RecordIotenvInstant.java | 3 + .../service/IRecordIotenvInstantService.java | 6 +- .../impl/RecordIotenvInstantServiceImpl.java | 80 ++++++++++++++----- .../ems/record/RecordIotenvInstantMapper.xml | 44 +++++++++- 5 files changed, 113 insertions(+), 27 deletions(-) diff --git a/os-ems/src/main/java/com/os/ems/record/controller/RecordIotenvInstantController.java b/os-ems/src/main/java/com/os/ems/record/controller/RecordIotenvInstantController.java index f34b31c..baee549 100644 --- a/os-ems/src/main/java/com/os/ems/record/controller/RecordIotenvInstantController.java +++ b/os-ems/src/main/java/com/os/ems/record/controller/RecordIotenvInstantController.java @@ -63,12 +63,15 @@ public class RecordIotenvInstantController extends BaseController // 解析设备类型参数(用于动态导出列和数据过滤) Set monitorTypes = parseMonitorTypes(params); + + // 解析振动参数(振动设备可选择导出单个参数) + String vibrationParam = params.get("vibrationParam") != null ? params.get("vibrationParam").toString() : null; // 调用Service层方法查询并过滤数据(支持大数据量导出,无数量限制) - List list = recordIotenvInstantService.selectRecordIotenvInstantListForExportWithFilter(recordIotenvInstant, monitorTypes); + List list = recordIotenvInstantService.selectRecordIotenvInstantListForExportWithFilter(recordIotenvInstant, monitorTypes, vibrationParam); // 根据设备类型动态选择导出列 - String[] includeColumns = recordIotenvInstantService.getExportColumnsByType(monitorTypes); + String[] includeColumns = recordIotenvInstantService.getExportColumnsByType(monitorTypes, vibrationParam); ExcelUtil util = new ExcelUtil(RecordIotenvInstant.class); util.showColumn(includeColumns); util.exportExcel(response, list, "物联网数据"); diff --git a/os-ems/src/main/java/com/os/ems/record/domain/RecordIotenvInstant.java b/os-ems/src/main/java/com/os/ems/record/domain/RecordIotenvInstant.java index 61742bf..ae44d85 100644 --- a/os-ems/src/main/java/com/os/ems/record/domain/RecordIotenvInstant.java +++ b/os-ems/src/main/java/com/os/ems/record/domain/RecordIotenvInstant.java @@ -97,6 +97,9 @@ public class RecordIotenvInstant extends BaseEntity /** 采样间隔(分钟),用于数据抽稀 */ private Integer samplingInterval; + + /** 振动参数选择(用于查询过滤):vibrationSpeed/vibrationDisplacement/vibrationAcceleration/vibrationTemp */ + private String vibrationParam; // // public void setObjid(Long objid) diff --git a/os-ems/src/main/java/com/os/ems/record/service/IRecordIotenvInstantService.java b/os-ems/src/main/java/com/os/ems/record/service/IRecordIotenvInstantService.java index 4a92c6a..48ed6a6 100644 --- a/os-ems/src/main/java/com/os/ems/record/service/IRecordIotenvInstantService.java +++ b/os-ems/src/main/java/com/os/ems/record/service/IRecordIotenvInstantService.java @@ -102,16 +102,18 @@ public interface IRecordIotenvInstantService * * @param recordIotenvInstant 物联网数据 * @param monitorTypes 设备类型集合 + * @param vibrationParam 振动参数(振动设备可选择单个参数导出) * @return 过滤后的物联网数据集合 */ - List selectRecordIotenvInstantListForExportWithFilter(RecordIotenvInstant recordIotenvInstant, Set monitorTypes) throws ParseException; + List selectRecordIotenvInstantListForExportWithFilter(RecordIotenvInstant recordIotenvInstant, Set monitorTypes, String vibrationParam) throws ParseException; /** * 根据设备类型获取导出列 * * @param monitorTypes 设备类型集合 + * @param vibrationParam 振动参数(振动设备可选择单个参数导出) * @return 需要导出的列名数组 */ - String[] getExportColumnsByType(Set monitorTypes); + String[] getExportColumnsByType(Set monitorTypes, String vibrationParam); } diff --git a/os-ems/src/main/java/com/os/ems/record/service/impl/RecordIotenvInstantServiceImpl.java b/os-ems/src/main/java/com/os/ems/record/service/impl/RecordIotenvInstantServiceImpl.java index e7548bb..aae3a53 100644 --- a/os-ems/src/main/java/com/os/ems/record/service/impl/RecordIotenvInstantServiceImpl.java +++ b/os-ems/src/main/java/com/os/ems/record/service/impl/RecordIotenvInstantServiceImpl.java @@ -524,14 +524,15 @@ public class RecordIotenvInstantServiceImpl implements IRecordIotenvInstantServi * * @param recordIotenvInstant 物联网数据 * @param monitorTypes 设备类型集合 + * @param vibrationParam 振动参数(振动设备可选择单个参数导出) * @return 过滤后的物联网数据集合 */ @Override - public List selectRecordIotenvInstantListForExportWithFilter(RecordIotenvInstant recordIotenvInstant, Set monitorTypes) throws ParseException { + public List selectRecordIotenvInstantListForExportWithFilter(RecordIotenvInstant recordIotenvInstant, Set monitorTypes, String vibrationParam) throws ParseException { // 先查询原始数据 List list = selectRecordIotenvInstantListForExport(recordIotenvInstant); // 根据设备类型过滤无效数据 - return filterInvalidData(list, monitorTypes); + return filterInvalidData(list, monitorTypes, vibrationParam); } /** @@ -540,11 +541,14 @@ public class RecordIotenvInstantServiceImpl implements IRecordIotenvInstantServi * type=5: 温度设备 -> 设备编号、设备名称、温度、记录时间 * type=6: 温湿度设备 -> 设备编号、设备名称、温度、湿度、记录时间 * type=7: 噪声设备 -> 设备编号、设备名称、噪声、记录时间 - * type=10: 振动设备 -> 设备编号、设备名称、振动速度、振动位移、振动加速度、振动温度、记录时间 + * type=10: 振动设备 -> 若指定vibrationParam则只导出该参数,否则导出全部振动参数 * 混合类型: 导出所有列 + * + * @param monitorTypes 设备类型集合 + * @param vibrationParam 振动参数(振动设备可选择单个参数导出:vibrationSpeed/vibrationDisplacement/vibrationAcceleration/vibrationTemp) */ @Override - public String[] getExportColumnsByType(Set monitorTypes) { + public String[] getExportColumnsByType(Set monitorTypes, String vibrationParam) { List columns = new ArrayList<>(); // 固定列:设备编号、设备名称 columns.add("monitorCode"); @@ -573,11 +577,15 @@ public class RecordIotenvInstantServiceImpl implements IRecordIotenvInstantServi case 7: // 噪声设备 columns.add("noise"); break; - case 10: // 振动设备 - columns.add("vibrationSpeed"); - columns.add("vibrationDisplacement"); - columns.add("vibrationAcceleration"); - columns.add("vibrationTemp"); + case 10: // 振动设备:若指定vibrationParam则只导出该参数 + if (vibrationParam != null && !vibrationParam.isEmpty()) { + columns.add(vibrationParam); + } else { + columns.add("vibrationSpeed"); + columns.add("vibrationDisplacement"); + columns.add("vibrationAcceleration"); + columns.add("vibrationTemp"); + } break; default: // 其他类型:导出所有列 @@ -600,12 +608,14 @@ public class RecordIotenvInstantServiceImpl implements IRecordIotenvInstantServi /** * 根据设备类型过滤无效数据 * 过滤规则(使用OR关系,满足任一类型的有效性即保留): - * 1. 温度设备(type=5):温度>0且<=79 - * 2. 温湿度设备(type=6):温度或湿度任一>0且<=79 - * 3. 噪声设备(type=7):噪声>0且<=79 - * 4. 振动设备(type=10):振动相关字段任一>0 + * 1. 温度设备(type=5):温度>0且<80 + * 2. 温湿度设备(type=6):温度或湿度任一>0且<80 + * 3. 噪声设备(type=7):噪声>0且<80 + * 4. 振动设备(type=10):若指定vibrationParam则只过滤该参数,否则振动相关字段任一>0且<80 + * + * @param vibrationParam 振动参数(振动设备可选择单个参数过滤) */ - private List filterInvalidData(List list, Set monitorTypes) { + private List filterInvalidData(List list, Set monitorTypes, String vibrationParam) { if (monitorTypes.isEmpty()) { // 未指定类型时,保留有任何有效数据的记录 return list.stream().filter(this::hasValidData).collect(Collectors.toList()); @@ -614,6 +624,10 @@ public class RecordIotenvInstantServiceImpl implements IRecordIotenvInstantServi // 单一类型:严格按该类型过滤 if (monitorTypes.size() == 1) { Integer type = monitorTypes.iterator().next(); + // 振动设备且指定了单个参数时,只过滤该参数 + if (type == 10 && vibrationParam != null && !vibrationParam.isEmpty()) { + return list.stream().filter(record -> isValidVibrationParam(record, vibrationParam)).collect(Collectors.toList()); + } return list.stream().filter(record -> isValidForType(record, type)).collect(Collectors.toList()); } @@ -628,6 +642,28 @@ public class RecordIotenvInstantServiceImpl implements IRecordIotenvInstantServi }).collect(Collectors.toList()); } + /** 判断指定振动参数是否有效:>0且<80 */ + private boolean isValidVibrationParam(RecordIotenvInstant record, String vibrationParam) { + BigDecimal value = null; + switch (vibrationParam) { + case "vibrationSpeed": + value = record.getVibrationSpeed(); + break; + case "vibrationDisplacement": + value = record.getVibrationDisplacement(); + break; + case "vibrationAcceleration": + value = record.getVibrationAcceleration(); + break; + case "vibrationTemp": + value = record.getVibrationTemp(); + break; + default: + return false; + } + return value != null && value.compareTo(BigDecimal.ZERO) > 0 && value.compareTo(new BigDecimal("80")) < 0; + } + /** 判断记录对于指定类型是否有效 */ private boolean isValidForType(RecordIotenvInstant record, Integer type) { switch (type) { @@ -659,12 +695,18 @@ public class RecordIotenvInstantServiceImpl implements IRecordIotenvInstantServi return noise != null && noise.compareTo(BigDecimal.ZERO) > 0 && noise.compareTo(new BigDecimal("79")) <= 0; } - /** 判断是否有有效的振动数据 */ + /** 判断是否有有效的振动数据:>0且<80 */ private boolean hasValidVibrationData(RecordIotenvInstant record) { - return (record.getVibrationSpeed() != null && record.getVibrationSpeed().compareTo(BigDecimal.ZERO) > 0) || - (record.getVibrationDisplacement() != null && record.getVibrationDisplacement().compareTo(BigDecimal.ZERO) > 0) || - (record.getVibrationAcceleration() != null && record.getVibrationAcceleration().compareTo(BigDecimal.ZERO) > 0) || - (record.getVibrationTemp() != null && record.getVibrationTemp().compareTo(BigDecimal.ZERO) > 0); + BigDecimal upperLimit = new BigDecimal("80"); + return isValidVibrationValue(record.getVibrationSpeed(), upperLimit) || + isValidVibrationValue(record.getVibrationDisplacement(), upperLimit) || + isValidVibrationValue(record.getVibrationAcceleration(), upperLimit) || + isValidVibrationValue(record.getVibrationTemp(), upperLimit); + } + + /** 判断振动值是否有效:>0且<80 */ + private boolean isValidVibrationValue(BigDecimal value, BigDecimal upperLimit) { + return value != null && value.compareTo(BigDecimal.ZERO) > 0 && value.compareTo(upperLimit) < 0; } /** 判断记录是否有任何有效数据 */ diff --git a/os-ems/src/main/resources/mapper/ems/record/RecordIotenvInstantMapper.xml b/os-ems/src/main/resources/mapper/ems/record/RecordIotenvInstantMapper.xml index b281635..2fe8d1f 100644 --- a/os-ems/src/main/resources/mapper/ems/record/RecordIotenvInstantMapper.xml +++ b/os-ems/src/main/resources/mapper/ems/record/RecordIotenvInstantMapper.xml @@ -289,8 +289,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" (ebmi.monitor_type = 6 AND (t.temperature > 0 OR t.humidity > 0)) OR -- 噪声设备(type=7):过滤噪声为0的数据 (ebmi.monitor_type = 7 AND t.noise > 0) OR - -- 振动设备(type=10):过滤振动相关字段都为0的数据 - (ebmi.monitor_type = 10 AND (t.vibration_speed > 0 OR t.vibration_displacement > 0 OR t.vibration_acceleration > 0 OR t.vibration_temp > 0)) OR + -- 振动设备(type=10):根据选中参数过滤 + (ebmi.monitor_type = 10 AND ( + + + t.vibration_speed > 0 AND t.vibration_speed < 80 + + + t.vibration_displacement > 0 AND t.vibration_displacement < 80 + + + t.vibration_acceleration > 0 AND t.vibration_acceleration < 80 + + + t.vibration_temp > 0 AND t.vibration_temp < 80 + + + t.vibration_speed > 0 OR t.vibration_displacement > 0 OR t.vibration_acceleration > 0 OR t.vibration_temp > 0 + + + )) OR -- 其他类型设备或无设备信息:保留所有有效数据 (ebmi.monitor_type NOT IN (5, 6, 7, 10) OR ebmi.monitor_type IS NULL) ) @@ -360,8 +378,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" (ebmi.monitor_type = 6 AND (t.temperature > 0 OR t.humidity > 0)) OR -- 噪声设备(type=7):过滤噪声为0的数据 (ebmi.monitor_type = 7 AND t.noise > 0) OR - -- 振动设备(type=10):过滤振动相关字段都为0的数据 - (ebmi.monitor_type = 10 AND (t.vibration_speed > 0 OR t.vibration_displacement > 0 OR t.vibration_acceleration > 0 OR t.vibration_temp > 0)) OR + -- 振动设备(type=10):根据选中参数过滤 + (ebmi.monitor_type = 10 AND ( + + + t.vibration_speed > 0 AND t.vibration_speed < 80 + + + t.vibration_displacement > 0 AND t.vibration_displacement < 80 + + + t.vibration_acceleration > 0 AND t.vibration_acceleration < 80 + + + t.vibration_temp > 0 AND t.vibration_temp < 80 + + + t.vibration_speed > 0 OR t.vibration_displacement > 0 OR t.vibration_acceleration > 0 OR t.vibration_temp > 0 + + + )) OR -- 其他类型设备或无设备信息:保留所有有效数据 (ebmi.monitor_type NOT IN (5, 6, 7, 10) OR ebmi.monitor_type IS NULL) )