From 8490eb11583ffdc586436f165860de5cfc39f915 Mon Sep 17 00:00:00 2001
From: cjl <909710561@qq.com>
Date: Mon, 06 Jan 2025 09:18:29 +0800
Subject: [PATCH] fix:sql查询时间调整

---
 screen-api/src/main/resources/mapper/HistoryHourlyMapper.xml |  163 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 156 insertions(+), 7 deletions(-)

diff --git a/screen-api/src/main/resources/mapper/HistoryHourlyMapper.xml b/screen-api/src/main/resources/mapper/HistoryHourlyMapper.xml
index 90af3f8..3d978ce 100644
--- a/screen-api/src/main/resources/mapper/HistoryHourlyMapper.xml
+++ b/screen-api/src/main/resources/mapper/HistoryHourlyMapper.xml
@@ -2,12 +2,161 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.moral.api.mapper.HistoryHourlyMapper">
 
-    <!-- ������������������������ -->
-    <resultMap id="BaseResultMap" type="com.moral.api.entity.HistoryHourly">
-        <result column="mac" property="mac"/>
-        <result column="time" property="time"/>
-        <result column="value" property="value"/>
-        <result column="version" property="version"/>
-    </resultMap>
+    <select id="selectHourlyData" resultType="java.lang.String">
+        SELECT `value`
+        FROM history_hourly_${timeUnits}
+        WHERE mac = #{mac}
+          AND `time` = #{time}
+    </select>
 
+
+    <select id="selectHourlyListData" parameterType="java.util.List" resultType="java.util.Map">
+        SELECT `value`,`time`
+        FROM history_hourly_${timeUnits}
+        WHERE mac = #{mac}
+          AND `time` BETWEEN  #{startTime} and #{endTime}
+    </select>
+
+
+    <select id="selectDataByMacsAndTime" parameterType="java.util.List" resultType="java.util.Map">
+        select mac, `time`, `value` from history_hourly_${timeUnits}
+        where mac in
+        <foreach collection="list" item="item" index="index" open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        and `time` = #{time}
+    </select>
+
+    <select id="queryLastHourlyMac" resultType="java.lang.String">
+        SELECT `value`
+        FROM history_hourly_${timeUnits}
+        WHERE mac = #{mac}
+          AND `time` = #{time}
+    </select>
+
+
+    <select id="getArea" resultType="com.moral.api.pojo.dto.Wind.WindData">
+        SELECT
+        d.longitude AS longitude,
+        d.latitude AS latitude,d.mac,
+        CASE WHEN
+        h.value->'$.a01007' = 0 THEN 0.1 ELSE h.value->'$.a01007' END AS windSpeed,
+        h.value->'$.a01008' AS windDir
+        FROM history_hourly_${timeUnits} h ,
+        `device` AS d
+        WHERE d.is_delete = '0'
+        and d.mac = h.mac
+        AND d.monitor_point_id IN
+        <foreach item="monitorPointId" collection="monitorPointIds" index="index" open="(" separator="," close=")">
+            #{monitorPointId}
+        </foreach>
+        <if test="macs != null and macs.size!= 0">
+            and h.mac in
+            <foreach collection="macs" item="id" index="index" open="(" close=")" separator=",">
+                #{id}
+            </foreach>
+        </if>
+        AND h.time = #{time}
+    </select>
+
+    <select id="getTVOCByMac" resultType="java.lang.String">
+        select `value` - > '$.${sensor}'
+        from history_hourly_${yearAndMonth}
+        where mac = #{mac}
+          and time =#{time}
+    </select>
+
+
+    <select id="getPressureByMac" resultType="java.lang.String">
+        select `value` - > '$.a01006'
+        from history_hourly_${yearAndMonth}
+        where mac = #{mac}
+          and time =#{time}
+    </select>
+
+
+    <select id="getDataByMac" resultType="java.util.Map">
+        select `value`
+        from history_hourly_${yearAndMonth}
+        where mac = #{mac}
+          and time =#{time}
+    </select>
+
+    <insert id="insertHistoryHourly">
+        INSERT INTO history_hourly_${timeUnits}
+        VALUES (#{mac}, #{time}, #{value}, #{version})
+    </insert>
+
+
+    <insert id="updateHistoryHourly">
+        UPDATE history_hourly_${timeUnits} SET `value` = #{value}
+        where mac =  #{mac} and time = #{time} and version = #{version}
+    </insert>
+
+    <select id="listResult" resultType="com.moral.api.entity.HistoryHourly">
+        SELECT mac,time,value,version FROM history_hourly${table}
+         WHERE 1 =1
+         <if test="macs != null and macs.size!=0">
+             and mac in
+             <foreach collection="macs" item="id" index="index" open="(" close=")" separator=",">
+                 #{id}
+             </foreach>
+         </if>
+         <if test="mac != null and mac != ''">
+            and mac = #{mac}
+         </if>
+
+         and time BETWEEN #{startDate} and #{endDate}
+
+        order by time desc
+    </select>
+
+    <select id="listLikeResult" resultType="com.moral.api.entity.HistoryHourly">
+        SELECT mac,time,value,version FROM history_hourly${table}
+        WHERE 1 =1
+        <if test="macs != null and macs.size!=0">
+            and mac in
+            <foreach collection="macs" item="id" index="index" open="(" close=")" separator=",">
+                #{id}
+            </foreach>
+        </if>
+        <if test="mac != null and mac != ''">
+            and mac = #{mac}
+        </if>
+
+        and time like concat(#{time},'%')
+
+        order by time desc
+    </select>
+
+    <select id="listAvgResult" resultType="com.moral.api.pojo.vo.historyMonthly.HistoryResultVo">
+        select  DATE_FORMAT(time,'%Y-%m-%d %H') time,${type}
+        FROM history_hourly${table} WHERE 1 =1 and
+        time <![CDATA[>=]]> #{startTime}
+        and time <![CDATA[<=]]> #{endTime}
+        and mac in
+        <foreach collection="macs" item="id" index="index" open="(" close=")" separator=",">
+            #{id}
+        </foreach>
+        group by time
+        order by time
+    </select>
+
+    <select id="HistoryMinutelyQuery" resultType="com.moral.api.entity.HistoryMinutely">
+        SELECT mac,time,value,version FROM history_minutely${table}
+        WHERE 1 =1
+        <if test="macs != null and macs.size!=0">
+            and mac in
+            <foreach collection="macs" item="id" index="index" open="(" close=")" separator=",">
+                #{id}
+            </foreach>
+        </if>
+        <if test="mac != null and mac != ''">
+            and mac = #{mac}
+        </if>
+
+        and time BETWEEN #{startDate} and #{endDate}
+
+        order by time desc
+    </select>
 </mapper>
\ No newline at end of file

--
Gitblit v1.8.0