feat(record): 添加振动设备参数选择导出功能

- 在RecordIotenvInstant实体类中添加vibrationParam字段用于振动参数选择
- 修改IRecordIotenvInstantService接口方法,增加vibrationParam参数支持
- 更新Controller层解析振动参数并传递给Service方法
- 在Mapper XML中实现振动设备按选中参数过滤数据的逻辑
- 修改Service实现类支持振动设备单参数过滤和导出
- 优化振动数据有效性判断逻辑,添加参数值范围验证
- 更新导出列选择逻辑,支持振动设备按参数选择导出特定字段
boardTest
zangch@mesnac.com 2 months ago
parent 89e7092ef2
commit 37d97f338c

@ -63,12 +63,15 @@ public class RecordIotenvInstantController extends BaseController
// 解析设备类型参数(用于动态导出列和数据过滤)
Set<Integer> monitorTypes = parseMonitorTypes(params);
// 解析振动参数(振动设备可选择导出单个参数)
String vibrationParam = params.get("vibrationParam") != null ? params.get("vibrationParam").toString() : null;
// 调用Service层方法查询并过滤数据支持大数据量导出无数量限制
List<RecordIotenvInstant> list = recordIotenvInstantService.selectRecordIotenvInstantListForExportWithFilter(recordIotenvInstant, monitorTypes);
List<RecordIotenvInstant> list = recordIotenvInstantService.selectRecordIotenvInstantListForExportWithFilter(recordIotenvInstant, monitorTypes, vibrationParam);
// 根据设备类型动态选择导出列
String[] includeColumns = recordIotenvInstantService.getExportColumnsByType(monitorTypes);
String[] includeColumns = recordIotenvInstantService.getExportColumnsByType(monitorTypes, vibrationParam);
ExcelUtil<RecordIotenvInstant> util = new ExcelUtil<RecordIotenvInstant>(RecordIotenvInstant.class);
util.showColumn(includeColumns);
util.exportExcel(response, list, "物联网数据");

@ -97,6 +97,9 @@ public class RecordIotenvInstant extends BaseEntity
/** 采样间隔(分钟),用于数据抽稀 */
private Integer samplingInterval;
/** 振动参数选择用于查询过滤vibrationSpeed/vibrationDisplacement/vibrationAcceleration/vibrationTemp */
private String vibrationParam;
//
// public void setObjid(Long objid)

@ -102,16 +102,18 @@ public interface IRecordIotenvInstantService
*
* @param recordIotenvInstant
* @param monitorTypes
* @param vibrationParam
* @return
*/
List<RecordIotenvInstant> selectRecordIotenvInstantListForExportWithFilter(RecordIotenvInstant recordIotenvInstant, Set<Integer> monitorTypes) throws ParseException;
List<RecordIotenvInstant> selectRecordIotenvInstantListForExportWithFilter(RecordIotenvInstant recordIotenvInstant, Set<Integer> monitorTypes, String vibrationParam) throws ParseException;
/**
*
*
* @param monitorTypes
* @param vibrationParam
* @return
*/
String[] getExportColumnsByType(Set<Integer> monitorTypes);
String[] getExportColumnsByType(Set<Integer> monitorTypes, String vibrationParam);
}

@ -524,14 +524,15 @@ public class RecordIotenvInstantServiceImpl implements IRecordIotenvInstantServi
*
* @param recordIotenvInstant
* @param monitorTypes
* @param vibrationParam
* @return
*/
@Override
public List<RecordIotenvInstant> selectRecordIotenvInstantListForExportWithFilter(RecordIotenvInstant recordIotenvInstant, Set<Integer> monitorTypes) throws ParseException {
public List<RecordIotenvInstant> selectRecordIotenvInstantListForExportWithFilter(RecordIotenvInstant recordIotenvInstant, Set<Integer> monitorTypes, String vibrationParam) throws ParseException {
// 先查询原始数据
List<RecordIotenvInstant> 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<Integer> monitorTypes) {
public String[] getExportColumnsByType(Set<Integer> monitorTypes, String vibrationParam) {
List<String> 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<RecordIotenvInstant> filterInvalidData(List<RecordIotenvInstant> list, Set<Integer> monitorTypes) {
private List<RecordIotenvInstant> filterInvalidData(List<RecordIotenvInstant> list, Set<Integer> 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;
}
/** 判断记录是否有任何有效数据 */

@ -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 (
<choose>
<when test="recordIotenvInstant.vibrationParam == 'vibrationSpeed'">
t.vibration_speed > 0 AND t.vibration_speed &lt; 80
</when>
<when test="recordIotenvInstant.vibrationParam == 'vibrationDisplacement'">
t.vibration_displacement > 0 AND t.vibration_displacement &lt; 80
</when>
<when test="recordIotenvInstant.vibrationParam == 'vibrationAcceleration'">
t.vibration_acceleration > 0 AND t.vibration_acceleration &lt; 80
</when>
<when test="recordIotenvInstant.vibrationParam == 'vibrationTemp'">
t.vibration_temp > 0 AND t.vibration_temp &lt; 80
</when>
<otherwise>
t.vibration_speed > 0 OR t.vibration_displacement > 0 OR t.vibration_acceleration > 0 OR t.vibration_temp > 0
</otherwise>
</choose>
)) 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 (
<choose>
<when test="recordIotenvInstant.vibrationParam == 'vibrationSpeed'">
t.vibration_speed > 0 AND t.vibration_speed &lt; 80
</when>
<when test="recordIotenvInstant.vibrationParam == 'vibrationDisplacement'">
t.vibration_displacement > 0 AND t.vibration_displacement &lt; 80
</when>
<when test="recordIotenvInstant.vibrationParam == 'vibrationAcceleration'">
t.vibration_acceleration > 0 AND t.vibration_acceleration &lt; 80
</when>
<when test="recordIotenvInstant.vibrationParam == 'vibrationTemp'">
t.vibration_temp > 0 AND t.vibration_temp &lt; 80
</when>
<otherwise>
t.vibration_speed > 0 OR t.vibration_displacement > 0 OR t.vibration_acceleration > 0 OR t.vibration_temp > 0
</otherwise>
</choose>
)) OR
-- 其他类型设备或无设备信息:保留所有有效数据
(ebmi.monitor_type NOT IN (5, 6, 7, 10) OR ebmi.monitor_type IS NULL)
)

Loading…
Cancel
Save