Browse Source

查询气象检测器数据 优化

develop
王兴琳 3 months ago
parent
commit
e5903c2c3e
  1. 41
      zc-business/src/main/java/com/zc/business/service/impl/DcMeteorologicalDetectorDataServiceImpl.java
  2. 39
      zc-business/src/main/resources/mapper/business/DcMeteorologicalDetectorDataMapper.xml

41
zc-business/src/main/java/com/zc/business/service/impl/DcMeteorologicalDetectorDataServiceImpl.java

@ -1,6 +1,7 @@
package com.zc.business.service.impl;
import com.ruoyi.common.utils.DateUtils;
import com.zc.business.domain.DcDevice;
import com.zc.business.domain.DcMeteorologicalDetectorData;
import com.zc.business.enums.UniversalEnum;
import com.zc.business.mapper.DcMeteorologicalDetectorDataMapper;
@ -8,8 +9,10 @@ import com.zc.business.service.IDcMeteorologicalDetectorDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* 气象检测器数据Service业务层处理
@ -22,7 +25,8 @@ public class DcMeteorologicalDetectorDataServiceImpl implements IDcMeteorologica
{
@Autowired
private DcMeteorologicalDetectorDataMapper dcMeteorologicalDetectorDataMapper;
@Resource
private DcDeviceServiceImpl dcDeviceServiceImpl;
/**
* 查询气象检测器数据
@ -113,7 +117,36 @@ public class DcMeteorologicalDetectorDataServiceImpl implements IDcMeteorologica
@Override
public List<DcMeteorologicalDetectorData> selectlistAll(DcMeteorologicalDetectorData dcMeteorologicalDetectorData) {
return dcMeteorologicalDetectorDataMapper.selectlistAll(dcMeteorologicalDetectorData);
Map<String,Object> parameter =new HashMap<>();
parameter.put("deviceType","3");
List<DcDevice> dcDevices = dcDeviceServiceImpl.devicePileNumberQueryDevice(parameter);
Map<String, DcDevice> deviceStateMap = dcDevices.stream()
.filter(Objects::nonNull) // DcDevice 对象不为空
.collect(Collectors.toMap(
DcDevice::getIotDeviceId,
Function.identity(),
(existing, replacement) -> existing) // 重复键,默认保留第一个值
);
List<DcMeteorologicalDetectorData> dcMeteorologicalDetectorDataList = dcMeteorologicalDetectorDataMapper.selectlistAll(dcMeteorologicalDetectorData);
// 遍历气象检测数据并设置对应的设备状态和桩号
for (DcMeteorologicalDetectorData data : dcMeteorologicalDetectorDataList) {
String iotDeviceId = data.getIotDeviceId();
if (deviceStateMap.containsKey(iotDeviceId)) {
DcDevice device = deviceStateMap.get(iotDeviceId);
// 设置设备状态
data.setDeviceState(device.getDeviceState());
// 设置桩号
data.setStakeMark(device.getStakeMark());
}
}
// 按照桩号排序
List<DcMeteorologicalDetectorData> sortedList = dcMeteorologicalDetectorDataList.stream()
.sorted(Comparator.comparing(DcMeteorologicalDetectorData::getStakeMark))
.collect(Collectors.toList());
return sortedList;
}
@Override

39
zc-business/src/main/resources/mapper/business/DcMeteorologicalDetectorDataMapper.xml

@ -200,27 +200,32 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectlistAll" parameterType="com.zc.business.domain.DcMeteorologicalDetectorData" resultMap="DcMeteorologicalDetectorDataResult">
SELECT
d.iot_device_id, d.stake_mark, d.direction, d.device_name, d.device_state,
m.iot_device_id,
m.device_name,
m.create_time,
m.rainfall, m.visibility_type, m.visibility, m.atmospheric_pressure,
m.temperature, m.humidity, m.wind_direction, m.wind_speed,
m.precipitation_type, m.wet_slippery_coefficient,
m.remote_road_surface_temperature, m.remote_road_surface_status,
m.rainfall,
m.visibility_type,
m.visibility,
m.atmospheric_pressure,
m.temperature,
m.humidity,
m.wind_direction,
m.wind_speed,
m.precipitation_type,
m.wet_slippery_coefficient,
m.remote_road_surface_temperature,
m.remote_road_surface_status,
m.water_film_ice_snow_value
FROM
dc_device d
LEFT JOIN
dc_meteorological_detector_data m
ON
d.iot_device_id = m.iot_device_id
AND m.create_time = (
SELECT MAX(create_time)
FROM dc_meteorological_detector_data m2
WHERE m2.iot_device_id = d.iot_device_id
)
WHERE
d.device_type = 3
ORDER BY d.stake_mark ASC;
JOIN (
SELECT
iot_device_id, MAX(create_time) AS max_create_time
FROM
dc_meteorological_detector_data
GROUP BY
iot_device_id
) latest ON m.iot_device_id = latest.iot_device_id AND m.create_time = latest.max_create_time;
</select>
<select id="selectDeviceNameList" parameterType="com.zc.business.domain.DcMeteorologicalDetectorData" resultMap="DcMeteorologicalDetectorDataResult">
SELECT

Loading…
Cancel
Save