Browse Source

按照 月,年 查询气象数据

develop
王兴琳 11 months ago
parent
commit
3a8774485c
  1. 22
      zc-business/src/main/java/com/zc/business/controller/DcMeteorologicalDetectorController.java
  2. 6
      zc-business/src/main/java/com/zc/business/mapper/DcMeteorologicalDetectorDataMapper.java
  3. 12
      zc-business/src/main/java/com/zc/business/service/IDcMeteorologicalDetectorDataService.java
  4. 25
      zc-business/src/main/java/com/zc/business/service/impl/DcMeteorologicalDetectorDataServiceImpl.java
  5. 113
      zc-business/src/main/resources/mapper/business/DcMeteorologicalDetectorDataMapper.xml

22
zc-business/src/main/java/com/zc/business/controller/DcMeteorologicalDetectorController.java

@ -53,5 +53,25 @@ public class DcMeteorologicalDetectorController extends BaseController {
List<DcMeteorologicalDetectorData> list = dcMeteorologicalDetectorDataService.selectlistVisibility(dcMeteorologicalDetectorData);
return getDataTable(list);
}
@ApiOperation("每小时统计气象设备信息列表")
@GetMapping("/deviceHour")
public TableDataInfo deviceHour(String deviceName,String specificDate)
{
List<Map<String,String>> list = dcMeteorologicalDetectorDataService.selectStatisticsTime(deviceName,specificDate);
return getDataTable(list);
}
@ApiOperation("按月统计每天气象设备信息列表")
@GetMapping("/deviceDay")
public TableDataInfo deviceDay(String deviceName,String specificDate)
{
List<Map<String,String>> list = dcMeteorologicalDetectorDataService.selectStatisticsDay(deviceName,specificDate);
return getDataTable(list);
}
@ApiOperation("按年统计每月气象设备信息列表")
@GetMapping("/deviceYears")
public TableDataInfo deviceYears(String deviceName,String specificDate)
{
List<Map<String,String>> list = dcMeteorologicalDetectorDataService.selectStatisticsYears(deviceName,specificDate);
return getDataTable(list);
}
}

6
zc-business/src/main/java/com/zc/business/mapper/DcMeteorologicalDetectorDataMapper.java

@ -5,6 +5,7 @@ import java.util.Map;
import com.zc.business.domain.DcMeteorologicalDetectorData;
import com.zc.business.domain.MdDeviceData;
import org.apache.ibatis.annotations.Param;
/**
* 气象检测器数据Mapper接口
@ -63,6 +64,7 @@ public interface DcMeteorologicalDetectorDataMapper
int deleteDcMeteorologicalDetectorDataByIds(Long[] ids);
//统计
List<Map<String, String>> selectStatistics(String deviceName);
List<Map<String, String>> selectStatisticsTime(@Param("deviceName") String deviceName ,@Param("specificDate") String specificDate);
List<DcMeteorologicalDetectorData> selectlistAll(DcMeteorologicalDetectorData dcMeteorologicalDetectorData);
@ -74,4 +76,8 @@ public interface DcMeteorologicalDetectorDataMapper
* @return
*/
List<DcMeteorologicalDetectorData> selectDeviceNameList(String deviceName);
List<Map<String, String>> selectStatisticsDay(@Param("deviceName") String deviceName,@Param("specificDate") String specificDate);
List<Map<String, String>> selectStatisticsYears(@Param("deviceName") String deviceName,@Param("specificDate") String specificDate);
}

12
zc-business/src/main/java/com/zc/business/service/IDcMeteorologicalDetectorDataService.java

@ -64,6 +64,14 @@ public interface IDcMeteorologicalDetectorDataService
//统计当天 没小时温度
List<Map<String,String>> selectStatistics(String deviceName);
/**
* 按时间统计气象设备信息列表
* @param deviceName
* @param specificDate
* @return
*/
List<Map<String,String>> selectStatisticsTime(String deviceName,String specificDate);
List<DcMeteorologicalDetectorData> selectlistAll(DcMeteorologicalDetectorData dcMeteorologicalDetectorData);
List<DcMeteorologicalDetectorData> selectlistVisibility(DcMeteorologicalDetectorData dcMeteorologicalDetectorData);
@ -74,4 +82,8 @@ public interface IDcMeteorologicalDetectorDataService
* @return
*/
List<DcMeteorologicalDetectorData> selectDeviceNameList(String deviceName);
List<Map<String, String>> selectStatisticsDay(String deviceName, String specificDate);
List<Map<String, String>> selectStatisticsYears(String deviceName, String specificDate);
}

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

@ -105,6 +105,15 @@ public class DcMeteorologicalDetectorDataServiceImpl implements IDcMeteorologica
public List<Map<String,String>> selectStatistics(String deviceName) {
return dcMeteorologicalDetectorDataMapper.selectStatistics(deviceName);
}
/**
* 按时间统计气象设备信息列表
* @param deviceName
* @param specificDate
* @return
*/
public List<Map<String,String>> selectStatisticsTime(String deviceName,String specificDate) {
return dcMeteorologicalDetectorDataMapper.selectStatisticsTime(deviceName,specificDate);
}
@Override
public List<DcMeteorologicalDetectorData> selectlistAll(DcMeteorologicalDetectorData dcMeteorologicalDetectorData) {
@ -125,4 +134,20 @@ public class DcMeteorologicalDetectorDataServiceImpl implements IDcMeteorologica
public List<DcMeteorologicalDetectorData> selectDeviceNameList(String deviceName) {
return dcMeteorologicalDetectorDataMapper.selectDeviceNameList(deviceName);
}
@Override
public List<Map<String, String>> selectStatisticsDay(String deviceName, String specificDate) {
if (specificDate==null || specificDate.equals("")){
specificDate=DateUtils.getDate();
}
return dcMeteorologicalDetectorDataMapper.selectStatisticsDay(deviceName,specificDate);
}
@Override
public List<Map<String, String>> selectStatisticsYears(String deviceName, String specificDate) {
if (specificDate==null || specificDate.equals("")){
specificDate=DateUtils.getDate();
}
return dcMeteorologicalDetectorDataMapper.selectStatisticsYears(deviceName,specificDate);
}
}

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

@ -37,6 +37,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="date" column="date" />
<result property="avgTemperature" column="avg_temperature" />
<result property="avgVisibility" column="avg_visibility" />
<result property="month" column="month" />
</resultMap>
<sql id="selectDcMeteorologicalDetectorDataVo">
select id, iot_device_id, rainfall, visibility_type, visibility, atmospheric_pressure, temperature, humidity, wind_direction, wind_speed, precipitation_type, wet_slippery_coefficient,remote_road_surface_temperature, remote_road_surface_status, water_film_ice_snow_value,create_time,stake_mark,device_name,direction from dc_meteorological_detector_data
@ -156,23 +157,54 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
COALESCE(ROUND(AVG(dc.visibility), 2), 0) AS avg_visibility
FROM
(
SELECT 0 AS time_slot UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4
UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9
UNION ALL SELECT 10 UNION ALL SELECT 11 UNION ALL SELECT 12 UNION ALL SELECT 13
UNION ALL SELECT 14 UNION ALL SELECT 15 UNION ALL SELECT 16 UNION ALL SELECT 17
UNION ALL SELECT 18 UNION ALL SELECT 19 UNION ALL SELECT 20 UNION ALL SELECT 21
UNION ALL SELECT 22 UNION ALL SELECT 23
SELECT 0 AS time_slot UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4
UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9
UNION ALL SELECT 10 UNION ALL SELECT 11 UNION ALL SELECT 12 UNION ALL SELECT 13
UNION ALL SELECT 14 UNION ALL SELECT 15 UNION ALL SELECT 16 UNION ALL SELECT 17
UNION ALL SELECT 18 UNION ALL SELECT 19 UNION ALL SELECT 20 UNION ALL SELECT 21
UNION ALL SELECT 22 UNION ALL SELECT 23
) AS h
LEFT JOIN
LEFT JOIN
dc_meteorological_detector_data dc
ON
DATE(dc.create_time) = CURDATE()
AND HOUR(dc.create_time) = h.time_slot
AND dc.device_name = #{deviceName}
ON
DATE(dc.create_time) = CURDATE()
AND HOUR(dc.create_time) = h.time_slot
AND dc.device_name = #{deviceName}
GROUP BY
h.time_slot,
date;
</select>
<select id="selectStatisticsTime" resultMap="countMap" resultType="map">
SELECT
h.time_slot,
DATE(dc.create_time) AS date,
COALESCE(ROUND(AVG(dc.temperature), 2), 0) AS avg_temperature,
COALESCE(ROUND(AVG(dc.visibility), 2), 0) AS avg_visibility
FROM
(
SELECT 0 AS time_slot UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4
UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9
UNION ALL SELECT 10 UNION ALL SELECT 11 UNION ALL SELECT 12 UNION ALL SELECT 13
UNION ALL SELECT 14 UNION ALL SELECT 15 UNION ALL SELECT 16 UNION ALL SELECT 17
UNION ALL SELECT 18 UNION ALL SELECT 19 UNION ALL SELECT 20 UNION ALL SELECT 21
UNION ALL SELECT 22 UNION ALL SELECT 23
) AS h
LEFT JOIN
dc_meteorological_detector_data dc
ON
<if test="specificDate != null and specificDate !=''">
DATE(dc.create_time) = #{specificDate}
</if>
<if test="specificDate == null or specificDate=='' ">
DATE(dc.create_time) = CURDATE()
</if>
AND HOUR(dc.create_time) = h.time_slot
AND dc.device_name = #{deviceName}
GROUP BY
h.time_slot,
date;
</select>
<select id="selectlistAll" parameterType="com.zc.business.domain.DcMeteorologicalDetectorData" resultMap="DcMeteorologicalDetectorDataResult">
SELECT
@ -255,4 +287,63 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
AND DATE(m.create_time) = CURDATE()
</where>
</select>
<select id="selectStatisticsDay" resultMap="countMap" resultType="map">
WITH RECURSIVE dates_in_month AS (
SELECT DATE_FORMAT(STR_TO_DATE(#{specificDate}, '%Y-%m-%d'), '%Y-%m-01') AS date
UNION ALL
SELECT DATE_ADD(date, INTERVAL 1 DAY)
FROM dates_in_month
<where>
date &lt; LAST_DAY(#{specificDate})
</where>
)
SELECT
d.date,
COALESCE(ROUND(AVG(dc.temperature), 2), 0) AS avg_temperature,
COALESCE(ROUND(AVG(dc.visibility), 2), 0) AS avg_visibility
FROM
dates_in_month d
LEFT JOIN
dc_meteorological_detector_data dc
ON
DATE(dc.create_time) = d.date
AND dc.device_name = #{deviceName}
GROUP BY
d.date
ORDER BY
d.date ASC;
</select>
<select id="selectStatisticsYears" resultMap="countMap" resultType="map">
WITH RECURSIVE months_of_year AS (
SELECT 1 AS month
UNION ALL
SELECT month + 1
FROM months_of_year
<where>
month &lt; 12
</where>
),
monthly_data AS (
SELECT
DATE_FORMAT(CONCAT(YEAR(#{specificDate}), '-', LPAD(month, 2, '0'), '-01'), '%Y-%m') AS month,
ROUND(AVG(COALESCE(dc.temperature, 0)), 2) AS avg_temperature,
ROUND(AVG(COALESCE(dc.visibility, 0)), 2) AS avg_visibility
FROM
months_of_year
LEFT JOIN dc_meteorological_detector_data dc
ON YEAR(dc.create_time) = YEAR(#{specificDate})
AND MONTH(dc.create_time) = months_of_year.month
AND dc.device_name = #{deviceName}
GROUP BY
month
)
SELECT * FROM monthly_data order by monthly_data.month asc ;
</select>
</mapper>
Loading…
Cancel
Save