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

267 lines
12 KiB
XML

<?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">
<mapper namespace="com.isu.gaswellwatch.dao.DeviceDao">
<resultMap id="DeviceVOMap" type="com.isu.gaswellwatch.vo.DeviceVO">
<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"/>
<association property="deviceType" javaType="com.isu.gaswellwatch.entity.Dictionary" select="getDic"
column="device_type">
</association>
<association property="product" javaType="com.isu.gaswellwatch.entity.Dictionary" select="getDic"
column="product">
</association>
<association property="gasWell" javaType="com.isu.gaswellwatch.entity.GasWell">
<id column="gasWellId" property="id"/>
<result column="gasWellName" property="name"/>
<result column="gasWellBlock" property="blockId"/>
</association>
</resultMap>
<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"/>
<result property="product" column="product"/>
<result property="gasWell" column="gas_well"/>
</resultMap>
<select id="queryGasStationList" resultType="string">
select u.gas_station
from device u
where u.gas_station LIKE CONCAT('%', #{gasStationName}, '%')
order by u.id desc
</select>
<select id="page" resultMap="DeviceVOMap">
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
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="mainPipe!=null and mainPipe!='' ">
and u.gas_station LIKE CONCAT('%(',#{mainPipe},')%')
</if>
<if test="deviceTypeId!=null and deviceTypeId!='' ">
and u.device_type = #{deviceTypeId}
</if>
<if test="product!=null">
and u.product = #{product}
</if>
<if test="blockId!=null and blockId!='' ">
and g.block_id = #{blockId}
</if>
</where>
order by u.id desc
</select>
<select id="getDic" parameterType="java.lang.Long" resultType="com.isu.gaswellwatch.entity.Dictionary">
SELECT d.id, d.type, d.code, d.name, d.value, d.sort
FROM dictionary d
where d.id = #{dicId}
</select>
<select id="getDeviceById" resultMap="DeviceVOMap">
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
where u.id = #{id}
</select>
<select id="historyPage" resultType="com.isu.gaswellwatch.vo.DeviceHistoryVO">
select t.collection_time,t.oil_pressure,t.cas_pressure
<choose>
<when test="deviceProduct!=null and deviceProduct=='knpc'">
,t.pre_pressure,'knpc' as type,t.run_mode,t.status_end_time,t.temperature
,t.humidity,t.well_status,t.plug_status, t.battery_voltage
</when>
<when test="deviceProduct!=null and deviceProduct=='etc'">
,t.pre_pressure,'etc' as type,t.current_status_remaining_time as statusEndTime
,t.controller_current_status as runMode,t.solenoid_valve_status as wellStatus
,t.battery_voltage
</when>
<when test="deviceProduct!=null and deviceProduct=='scss'">
,t.pre_pressure,'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'">
,t.pre_pressure,'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
,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'">
,'mi_weps_plug' as type,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>
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>
<select id="deviceOptLogPage" resultType="com.isu.gaswellwatch.entity.DeviceOptLog">
select t.* from device_opt_log t where t.device_id = #{deviceId}
<if test="startTime!=null and startTime!=''">
and t.create_time &gt;= #{startTime}
</if>
<if test="endTime!=null and endTime!=''">
and t.create_time &lt;= #{endTime}
</if>
order by t.create_time desc
</select>
<select id="getDeviceVOByIds" resultMap="DeviceVOMap">
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
from device u
<where>
<if test="idList!=null and idList.size()>0">
u.id in
<foreach collection="idList" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</if>
</where>
</select>
<select id="getPressureChartData" resultType="com.isu.gaswellwatch.vo.DeviceHistoryVO">
select t.collection_time,t.oil_pressure,t.cas_pressure
<choose>
<when test="deviceProduct!=null and deviceProduct=='knpc'">
,t.pre_pressure,'knpc' as type
</when>
<when test="deviceProduct!=null and deviceProduct=='etc'">
,t.pre_pressure,'etc' as type
</when>
<when test="deviceProduct!=null and deviceProduct=='scss'">
,t.pre_pressure,'scss' as type
</when>
<when test="deviceProduct!=null and deviceProduct=='weps_plug'">
,t.pre_pressure,'weps_plug' as type
</when>
<when test="deviceProduct!=null and deviceProduct=='mi_weps_plug'">
,'mi_weps_plug' as type
</when>
</choose>
from ${tableName} t
<where>
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>
</where>
order by t.collection_time asc
</select>
<select id="getSwitchStatusData" resultType="com.isu.gaswellwatch.vo.DeviceHistoryVO">
select t.collection_time
<choose>
<when test="deviceProduct!=null and deviceProduct=='knpc'">,t.well_status</when>
<when test="deviceProduct!=null and deviceProduct=='etc'">,t.solenoid_valve_status as wellStatus</when>
<when test="deviceProduct!=null and deviceProduct=='scss'">,t.first_solenoid_status as wellStatus</when>
<when test="deviceProduct!=null and deviceProduct=='weps_plug'">
,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'">
,case t.current_status when 0 then 0 else 1 end as wellStatus
</when>
</choose>
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 asc
</select>
<select id="getDeviceHistoryData" resultType="com.isu.gaswellwatch.vo.DeviceHistoryVO">
select t.collection_time,t.oil_pressure,t.cas_pressure
<choose>
<when test="deviceProduct!=null and deviceProduct=='knpc'">
,t.pre_pressure,'knpc' as type,t.run_mode,t.status_end_time,t.temperature,t.humidity
,t.well_status,t.plug_status,t.battery_voltage
</when>
<when test="deviceProduct!=null and deviceProduct=='etc'">
,t.pre_pressure,'etc' as type,t.current_status_remaining_time as statusEndTime
,t.controller_current_status as runMode,t.solenoid_valve_status as wellStatus
,t.battery_voltage
</when>
<when test="deviceProduct!=null and deviceProduct=='scss'">
,t.pre_pressure,'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'">
,t.pre_pressure,'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
,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'">
,'mi_weps_plug' as type,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>
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>
</mapper>