gasWellWatch/src/main/resources/mapper/DeviceDao.xml

228 lines
10 KiB
XML
Raw Normal View History

2024-11-25 01:04:53 +08:00
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
2024-11-25 15:48:00 +08:00
<mapper namespace="com.isu.gaswellwatch.dao.DeviceDao">
2024-11-25 01:04:53 +08:00
2024-11-25 15:48:00 +08:00
<resultMap id="DeviceVOMap" type="com.isu.gaswellwatch.vo.DeviceVO">
2024-11-25 01:04:53 +08:00
<id column="id" property="id"/>
<result column="code" property="code"/>
<result column="gas_station" property="gasStation"/>
<result column="gateway_sn" property="gatewaySn"/>
<result column="details" property="details"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
2025-02-19 14:56:14 +08:00
<association property="deviceType" javaType="com.isu.gaswellwatch.entity.Dictionary" select="getDic"
column="device_type">
2024-11-25 01:04:53 +08:00
</association>
2025-02-19 14:56:14 +08:00
<association property="product" javaType="com.isu.gaswellwatch.entity.Dictionary" select="getDic"
column="product">
2024-11-25 01:04:53 +08:00
</association>
2025-02-19 14:56:14 +08:00
<association property="gasWell" javaType="com.isu.gaswellwatch.entity.GasWell">
2024-11-25 01:04:53 +08:00
<id column="gasWellId" property="id"/>
<result column="gasWellName" property="name"/>
2024-11-26 18:46:34 +08:00
<result column="gasWellBlock" property="blockId"/>
2024-11-25 01:04:53 +08:00
</association>
</resultMap>
2024-11-25 15:48:00 +08:00
<resultMap id="DeviceMap" type="com.isu.gaswellwatch.entity.Device" autoMapping="true">
<id column="id" property="id"/>
<result column="code" property="code"/>
<result column="gas_station" property="gasStation"/>
<result column="gateway_sn" property="gatewaySn"/>
<result column="details" property="details"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
<result property="deviceType" column="device_type"/>
2025-02-19 14:56:14 +08:00
<result property="product" column="product"/>
<result property="gasWell" column="gas_well"/>
2024-11-25 15:48:00 +08:00
</resultMap>
<select id="page" resultMap="DeviceVOMap">
2025-02-19 14:56:14 +08:00
select u.id, u.device_type, u.code, u.gas_station, u.product, u.gateway_sn,
2024-11-25 15:48:00 +08:00
u.gas_well, u.details, u.create_time, u.update_time,g.name as gasWellName,g.id as gasWellId
2024-11-25 01:04:53 +08:00
from device u left join gas_well g on u.gas_well = g.id
<where>
<if test="gasWellName!=null and gasWellName!='' ">
and g.name LIKE CONCAT('%',#{gasWellName},'%')
</if>
<if test="gasStationName!=null and gasStationName!='' ">
and u.gas_station LIKE CONCAT('%',#{gasStationName},'%')
</if>
<if test="deviceTypeId!=null and deviceTypeId!='' ">
and u.device_type = #{deviceTypeId}
</if>
2024-12-27 15:24:41 +08:00
<if test="product!=null">
and u.product = #{product}
</if>
2024-11-28 16:38:54 +08:00
<if test="blockId!=null and blockId!='' ">
and g.block_id = #{blockId}
</if>
2024-11-25 01:04:53 +08:00
</where>
order by u.id desc
</select>
<select id="getDic" parameterType="java.lang.Long" resultType="com.isu.gaswellwatch.entity.Dictionary">
2025-02-19 14:56:14 +08:00
SELECT d.id, d.type, d.code, d.name, d.value, d.sort
FROM dictionary d
where d.id = #{dicId}
2024-11-25 01:04:53 +08:00
</select>
2024-11-25 15:48:00 +08:00
<select id="getDeviceById" resultMap="DeviceVOMap">
2025-02-19 14:56:14 +08:00
select u.id,
u.device_type,
u.code,
u.gas_station,
u.product,
u.gateway_sn,
u.gas_well,
u.details,
u.create_time,
u.update_time,
g.name as gasWellName,
g.id as gasWellId,
g.block_id as gasWellBlock
from device u
left join gas_well g on u.gas_well = g.id
2024-11-25 15:48:00 +08:00
where u.id = #{id}
</select>
<select id="historyPage" resultType="com.isu.gaswellwatch.vo.DeviceHistoryVO">
2024-12-11 17:55:13 +08:00
select t.collection_time,t.oil_pressure,t.cas_pressure,t.pre_pressure
<choose>
<when test="deviceProduct!=null and deviceProduct=='knpc'">
,'knpc' as type,t.run_mode,t.status_end_time,t.temperature,t.humidity,t.well_status,t.plug_status
</when>
<when test="deviceProduct!=null and deviceProduct=='etc'">
,'etc' as type,t.current_status_remaining_time as statusEndTime
,t.controller_current_status as runMode,t.solenoid_valve_status as wellStatus
</when>
<when test="deviceProduct!=null and deviceProduct=='scss'">
,'scss' as type,t.ctl_model as runMode,t.remaining_time_action as statusEndTime
,t.solar_voltage,t.first_solenoid_status as wellStatus
</when>
<when test="deviceProduct!=null and deviceProduct=='weps_plug'">
2025-02-24 09:20:29 +08:00
,'weps_plug' as type, t.run_mode as runMode
,case t.solenoid_valve_status when 2 then t.open_well_remaining_time
when 1 then t.close_well_remaining_time else null end as statusEndTime
2025-02-24 09:20:29 +08:00
,case t.solenoid_valve_status when 2 then 1 when 1 then 0 else null end as wellStatus
</when>
<when test="deviceProduct!=null and deviceProduct=='mi_weps_plug'">
,t.produce_mode as runMode,t.remaining_time as statusEndTime
,case t.current_status when 0 then 0 else 1 end as wellStatus
,t.current_status as plugStatus
</when>
</choose>
2024-12-08 21:18:38 +08:00
from ${tableName} t
<where>
2025-02-19 14:56:14 +08:00
t.device_id = #{deviceId}
<if test="startTime!=null">
and t.collection_time &gt;= #{startTime}
</if>
<if test="endTime!=null">
and t.collection_time &lt;= #{endTime}
</if>
2024-12-08 21:18:38 +08:00
</where>
2025-02-19 14:56:14 +08:00
order by t.collection_time desc
</select>
2024-11-26 18:46:34 +08:00
<select id="deviceOptLogPage" resultType="com.isu.gaswellwatch.entity.DeviceOptLog">
select t.* from device_opt_log t where t.device_id = #{deviceId}
2024-12-11 02:08:20 +08:00
<if test="startTime!=null and startTime!=''">
2024-11-26 18:46:34 +08:00
and t.create_time &gt;= #{startTime}
</if>
2024-12-11 02:08:20 +08:00
<if test="endTime!=null and endTime!=''">
2024-11-26 18:46:34 +08:00
and t.create_time &lt;= #{endTime}
</if>
order by t.create_time desc
</select>
2024-11-28 01:30:00 +08:00
<select id="getDeviceVOByIds" resultMap="DeviceVOMap">
2025-02-19 14:56:14 +08:00
select u.id, u.device_type, u.code, u.gas_station, u.product, u.gateway_sn,
u.gas_well, u.details, u.create_time, u.update_time
2024-11-28 01:30:00 +08:00
from device u
2024-12-27 15:24:41 +08:00
<where>
<if test="idList!=null and idList.size()>0">
u.id in
2025-02-19 14:56:14 +08:00
<foreach collection="idList" item="id" open="(" separator="," close=")">
#{id}
</foreach>
2024-12-27 15:24:41 +08:00
</if>
</where>
2024-11-28 01:30:00 +08:00
</select>
2024-12-10 21:17:08 +08:00
<select id="getPressureChartData" resultType="com.isu.gaswellwatch.vo.DeviceHistoryVO">
2024-12-31 17:45:30 +08:00
select t.collection_time,t.oil_pressure,t.cas_pressure,t.pre_pressure
2024-12-10 21:17:08 +08:00
from ${tableName} t
<where>
2025-02-19 14:56:14 +08:00
t.device_id = #{deviceId}
<if test="startTime!=null and startTime!=''">
and t.collection_time &gt;= #{startTime}
</if>
<if test="endTime!=null and endTime!=''">
and t.collection_time &lt;= #{endTime}
</if>
2024-12-10 21:17:08 +08:00
</where>
2025-02-19 14:56:14 +08:00
order by t.collection_time asc
2024-12-10 21:17:08 +08:00
</select>
<select id="getSwitchStatusData" resultType="com.isu.gaswellwatch.vo.DeviceHistoryVO">
select t.collection_time
<if test="deviceProduct!=null and deviceProduct=='knpc'">,t.well_status</if>
<if test="deviceProduct!=null and deviceProduct=='etc'">,t.solenoid_valve_status as wellStatus</if>
<if test="deviceProduct!=null and deviceProduct=='scss'">,t.first_solenoid_status as wellStatus</if>
from ${tableName} t
<where>
t.device_id = #{deviceId}
2024-12-12 14:52:02 +08:00
<if test="startTime!=null">
2024-12-10 21:17:08 +08:00
and t.collection_time &gt;= #{startTime}
</if>
2024-12-12 14:52:02 +08:00
<if test="endTime!=null">
2024-12-10 21:17:08 +08:00
and t.collection_time &lt;= #{endTime}
</if>
</where>
order by t.collection_time asc
</select>
2024-12-12 14:52:02 +08:00
<select id="getDeviceHistoryData" resultType="com.isu.gaswellwatch.vo.DeviceHistoryVO">
select t.collection_time,t.oil_pressure,t.cas_pressure,t.pre_pressure
2025-02-21 13:53:37 +08:00
<choose>
<when test="deviceProduct!=null and deviceProduct=='knpc'">
,'knpc' as type,t.run_mode,t.status_end_time,t.temperature,t.humidity,t.well_status,t.plug_status
</when>
<when test="deviceProduct!=null and deviceProduct=='etc'">
,'etc' as type,t.current_status_remaining_time as statusEndTime
,t.controller_current_status as runMode,t.solenoid_valve_status as wellStatus
</when>
<when test="deviceProduct!=null and deviceProduct=='scss'">
,'scss' as type,t.ctl_model as runMode,t.remaining_time_action as statusEndTime
,t.solar_voltage,t.first_solenoid_status as wellStatus
</when>
<when test="deviceProduct!=null and deviceProduct=='weps_plug'">
2025-02-24 09:20:29 +08:00
,'weps_plug' as type, t.run_mode as runMode
2025-02-21 13:53:37 +08:00
,case t.solenoid_valve_status when 2 then t.open_well_remaining_time
when 1 then t.close_well_remaining_time else null end as statusEndTime
2025-02-24 09:20:29 +08:00
,case t.solenoid_valve_status when 2 then 1 when 1 then 0 else null end as wellStatus
</when>
<when test="deviceProduct!=null and deviceProduct=='mi_weps_plug'">
,t.produce_mode as runMode,t.remaining_time as statusEndTime
,case t.current_status when 0 then 0 else 1 end as wellStatus
,t.current_status as plugStatus
2025-02-21 13:53:37 +08:00
</when>
</choose>
2024-12-12 14:52:02 +08:00
from ${tableName} t
<where>
t.device_id = #{deviceId}
<if test="startTime!=null">
and t.collection_time &gt;= #{startTime}
</if>
<if test="endTime!=null">
and t.collection_time &lt;= #{endTime}
</if>
</where>
order by t.collection_time desc
</select>
2024-11-25 01:04:53 +08:00
</mapper>