From 34d9307df9870510f9204659ddf9f5389012cd4d Mon Sep 17 00:00:00 2001
From: cjl <909710561@qq.com>
Date: Mon, 17 Jun 2024 15:57:37 +0800
Subject: [PATCH] fix:sql查询时间调整
---
screen-api/src/main/resources/mapper/DeviceMapper.xml | 256 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 254 insertions(+), 2 deletions(-)
diff --git a/screen-api/src/main/resources/mapper/DeviceMapper.xml b/screen-api/src/main/resources/mapper/DeviceMapper.xml
index 9108824..64c99ba 100644
--- a/screen-api/src/main/resources/mapper/DeviceMapper.xml
+++ b/screen-api/src/main/resources/mapper/DeviceMapper.xml
@@ -26,6 +26,7 @@
<result column="is_delete" property="isDelete"/>
<result column="extend" property="extend"/>
<result column="town_code" property="townCode"/>
+ <result column="dev_num" property="devNum"/>
</resultMap>
<!--���������������������������-->
@@ -38,8 +39,259 @@
<foreach collection="macs" item="mac" index="index" open="(" close=")" separator=",">
#{mac}
</foreach>
- AND `time` <![CDATA[>=]]> #{start}
- AND `time` <![CDATA[<]]> #{end}
+ AND DATE_FORMAT(`time`,'%Y-%m-%d %H') <![CDATA[>=]]> #{start}
+ AND DATE_FORMAT(`time`,'%Y-%m-%d %H') <![CDATA[<]]> #{end}
ORDER BY `time`
</select>
+ <select id="deviceList" resultType="java.util.Map">
+ SELECT
+ t.latitude as latitude,
+ t.longitude as longitude,
+ t.mac as mac,
+ t.state,(hf.value ->> #{type} )+0 as ${sensorCode}
+ FROM
+ device t
+ inner JOIN monitor_point p on p.id = t.monitor_point_id and p.is_delete = 0
+ and p.organization_id in (
+ SELECT id FROM (
+ SELECT id, parent_id, name FROM organization WHERE id = #{organizationId}
+ UNION ALL
+ SELECT i.id, i.parent_id, i.name
+ FROM organization i
+ INNER JOIN (
+ SELECT * FROM (
+ SELECT id, parent_id, name FROM organization WHERE id = #{organizationId}
+ UNION ALL
+ SELECT id, parent_id, name FROM organization WHERE parent_id = #{organizationId}
+ ) t1
+ ) t2 ON i.parent_id = t2.id
+ where i.is_delete = 0
+ ) t3
+ )
+ <if test="region != null">
+ and p.${region} = #{regionCode}
+ </if>
+ <if test="endHourlyTime !=null and endHourlyTime != ''">
+ left join history_hourly_${times} hf on hf.time =#{endHourlyTime} and t.mac = hf.mac
+ </if>
+ <if test="endHourlyTime ==null">
+ left join history_five_minutely_${times} hf on hf.time = (select max(time) from history_five_minutely_${times} LIMIT 1
+ ) and t.mac = hf.mac
+ </if>
+
+
+ WHERE
+ t.state <![CDATA[ <> ]]> '0' and t.is_delete = 0
+ order by t.id desc
+ </select>
+
+ <select id="deviceIdList" resultType="java.lang.Integer">
+ SELECT
+ t.id
+ FROM
+ device t
+ INNER JOIN monitor_point p ON p.id = t.monitor_point_id
+ AND p.is_delete = 0
+ AND p.organization_id IN (
+ SELECT
+ id
+ FROM
+ (
+ SELECT
+ id,
+ parent_id,
+ NAME
+ FROM
+ organization
+ WHERE
+ id = #{organizationId} UNION ALL
+ SELECT
+ i.id,
+ i.parent_id,
+ i.NAME
+ FROM
+ organization i
+ INNER JOIN (
+ SELECT
+ *
+ FROM
+ (
+ SELECT
+ id,
+ parent_id,
+ NAME
+ FROM
+ organization
+ WHERE
+ id = #{organizationId} UNION ALL
+ SELECT
+ id,
+ parent_id,
+ NAME
+ FROM
+ organization
+ WHERE
+ parent_id = #{organizationId}
+ ) t1
+ ) t2 ON i.parent_id = t2.id
+ WHERE
+ i.is_delete = 0
+ ) t3
+ )
+ WHERE
+ t.is_delete = 0
+ </select>
+
+ <select id="deviceOrgIdList" resultType="java.lang.Integer">
+ SELECT
+ id
+ FROM
+ (
+ SELECT
+ id,
+ parent_id,
+ NAME
+ FROM
+ organization
+ WHERE
+ id = #{organizationId} UNION ALL
+ SELECT
+ i.id,
+ i.parent_id,
+ i.NAME
+ FROM
+ organization i
+ INNER JOIN (
+ SELECT
+ *
+ FROM
+ (
+ SELECT
+ id,
+ parent_id,
+ NAME
+ FROM
+ organization
+ WHERE
+ id = #{organizationId} UNION ALL
+ SELECT
+ id,
+ parent_id,
+ NAME
+ FROM
+ organization
+ WHERE
+ parent_id = #{organizationId}
+ ) t1
+ ) t2 ON i.parent_id = t2.id
+ WHERE
+ i.is_delete = 0
+ ) t3
+ </select>
+ <select id="deviceMacs" resultType="java.lang.String">
+ select mac from device where organization_id = #{organizationId} order by id desc
+
+ </select>
+
+ <select id="getDevices" resultType="com.moral.api.pojo.vo.device.AppDeviceVo">
+ SELECT d.id,d.`name`,d.mac,d.special_type FROM device as d
+ where 1=1
+ <if test="organizationId !=null">
+ AND organization_id = #{organizationId}
+ </if>
+ and mac LIKE "%"#{mac}"%" or `name` like "%"#{mac}"%" AND is_delete = 0
+ union
+ SELECT sd.id,sd.`name`,sd.mac,sd.special_type FROM special_device as sd
+ WHERE 1=1
+ <if test="organizationId !=null">
+ AND organization_id = #{organizationId}
+ </if>
+ and mac LIKE "%"#{mac}"%" AND is_delete = 0
+ </select>
+
+
+ <select id="getHeatMap" resultType="com.moral.api.pojo.dto.dataDisplay.HeatMapDTO">
+ SELECT
+ d.mac as mac,
+ d.latitude as lat,
+ d.longitude as lng,
+ d.name as name,
+ (hd.value ->> #{type} ) as count,
+ hd.time
+ FROM
+ device as d
+ inner JOIN organization o on o.id = d.organization_id and o.is_delete = 0
+ <if test="organizationIds != null and organizationIds.size !=0">
+ and organization_id in
+ <foreach collection="organizationIds" item="id" index="index" open="(" close=")" separator=",">
+ #{id}
+ </foreach>
+ </if>
+ <if test="tableName !=null">
+ RIGHT join history_hourly${tableName} hd on hd.time = #{start} and d.mac = hd.mac
+ </if>
+ <if test="tableName ==null ">
+ RIGHT join history_daily hd on hd.time = #{start} and d.mac = hd.mac
+ </if>
+ WHERE
+ d.is_delete = 0
+ order by d.mac
+ </select>
+
+
+ <select id="getHeatMapV1" resultType="com.moral.api.pojo.dto.dataDisplay.HeatMapDTO">
+ SELECT
+ d.mac as mac,
+ d.latitude as lat,
+ d.longitude as lng,
+ d.name as name,
+ (hd.value ->> #{type} ) as count,
+ hd.time,
+ dm.group_id AS groupId
+ FROM
+ device as d
+ inner JOIN organization o on o.id = d.organization_id and o.is_delete = 0
+ <if test="organizationIds != null and organizationIds.size !=0">
+ and organization_id in
+ <foreach collection="organizationIds" item="id" index="index" open="(" close=")" separator=",">
+ #{id}
+ </foreach>
+ </if>
+ left JOIN device_map_hierarchy as dm on d.id = dm.device_id
+ <if test="tableName !=null">
+ left join history_hourly${tableName} hd on hd.time = #{start} and d.mac = hd.mac
+ </if>
+ <if test="tableName ==null ">
+ left join history_daily hd on hd.time = #{start} and d.mac = hd.mac
+ </if>
+ WHERE
+ d.is_delete = 0
+ order by d.mac
+ </select>
+
+
+ <select id="getPage" resultType="com.moral.api.vo.OnlineRateVo">
+ select d.name,d.state,d.mac from device as d where organization_id=#{organizationId}
+ </select>
+
+
+ <select id="getLists" resultType="com.moral.api.vo.OnlineRateVo">
+ select d.name,d.state,d.mac from device as d where is_delete=0
+ <if test="macs != null and macs.size !=0">
+ and mac in
+ <foreach collection="macs" item="mac" index="index" open="(" close=")" separator=",">
+ #{mac}
+ </foreach>
+ </if>
+ <if test="state !=null and state == 0" >
+ and state=#{state}
+ </if>
+ <if test="state !=null and state != 0">
+ and state<![CDATA[>=]]>#{state}
+ </if>
+ </select>
+
+ <select id="getListVo" resultType="com.moral.api.pojo.vo.device.DeviceVO">
+ select * from device where monitor_point_id=#{monitorPointId} and is_delete=0
+ </select>
</mapper>
\ No newline at end of file
--
Gitblit v1.8.0