TDeviceAlarmMapper.xml 7.24 KB
Newer Older
yaqizhang's avatar
yaqizhang committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
<?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.zehong.system.mapper.TDeviceAlarmMapper">
    
    <resultMap type="TDeviceAlarm" id="TDeviceAlarmResult">
        <result property="alarmId"    column="alarm_id"    />
        <result property="deviceId"    column="device_id"    />
        <result property="deviceType"    column="device_type"    />
        <result property="orderId"    column="order_id"    />
        <result property="alarmType"    column="alarm_type"    />
        <result property="alarmValue"    column="alarm_value"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="dealStatus"    column="deal_status"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectTDeviceAlarmVo">
        select alarm_id, device_id, device_type, order_id, alarm_type, alarm_value, start_time, end_time, deal_status, update_time, create_time from t_device_alarm
    </sql>

    <select id="selectTDeviceAlarmList" parameterType="DeviceAlarmForm" resultMap="TDeviceAlarmResult">
        <include refid="selectTDeviceAlarmVo"/>
        <where>
            <if test="startTime1 != null "> and start_time &gt;= #{startTime1}</if>
            <if test="endTime1 != null "> and start_time &lt;= #{endTime1}</if>
            <if test="alarmType != null  and alarmType != ''"> and alarm_type = #{alarmType}</if>
            <if test="dealStatus != null  and dealStatus != ''"> and deal_status = #{dealStatus}</if>
        </where>
        ORDER BY create_time DESC 
    </select>

    <select id="selectTDeviceAlarmByPipeCode" parameterType="DeviceAlarmForm" resultMap="TDeviceAlarmResult">
        select t.alarm_id, t.device_id, t.device_type, t.order_id, t.alarm_type, t.alarm_value, t.start_time, t.end_time, t.deal_status, t.update_time, t.create_time
        from t_device_alarm t
        left join t_pipe p on t.device_id = p.pipe_id
        <where>
            <if test="deviceCode != null "> and p.pipe_code like concat('%',#{deviceCode},'%')</if>
            <if test="startTime1 != null "> and t.start_time &gt;= #{startTime1}</if>
            <if test="endTime1 != null "> and t.start_time &lt;= #{endTime1}</if>
            <if test="alarmType != null  and alarmType != ''"> and t.alarm_type = #{alarmType}</if>
            <if test="dealStatus != null  and dealStatus != ''"> and t.deal_status = #{dealStatus}</if>
        </where>
        ORDER BY create_time DESC
    </select>

    <select id="selectTDeviceAlarmByDeviceCode" parameterType="DeviceAlarmForm" resultMap="TDeviceAlarmResult">
        select t.alarm_id, t.device_id, t.device_type, t.order_id, t.alarm_type, t.alarm_value, t.start_time, t.end_time, t.deal_status, t.update_time, t.create_time
        from t_device_alarm t
        left join t_device_info d on t.device_id = d.device_id
        <where>
            <if test="deviceCode != null "> and d.device_code like concat('%',#{deviceCode},'%')</if>
            <if test="startTime1 != null "> and t.start_time &gt;= #{startTime1}</if>
            <if test="endTime1 != null "> and t.start_time &lt;= #{endTime1}</if>
            <if test="alarmType != null  and alarmType != ''"> and t.alarm_type = #{alarmType}</if>
            <if test="dealStatus != null  and dealStatus != ''"> and t.deal_status = #{dealStatus}</if>
        </where>
        ORDER BY create_time DESC
    </select>

    <select id="selectTDeviceAlarmById" parameterType="int" resultMap="TDeviceAlarmResult">
        <include refid="selectTDeviceAlarmVo"/>
        where alarm_id = #{alarmId}
    </select>
        
    <insert id="insertTDeviceAlarm" parameterType="TDeviceAlarm" useGeneratedKeys="true" keyProperty="alarmId">
        insert into t_device_alarm
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deviceId != null">device_id,</if>
            <if test="deviceType != null">device_type,</if>
            <if test="orderId != null">order_id,</if>
            <if test="alarmType != null">alarm_type,</if>
            <if test="alarmValue != null">alarm_value,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="dealStatus != null">deal_status,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deviceId != null">#{deviceId},</if>
            <if test="deviceType != null">#{deviceType},</if>
            <if test="orderId != null">#{orderId},</if>
            <if test="alarmType != null">#{alarmType},</if>
            <if test="alarmValue != null">#{alarmValue},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="dealStatus != null">#{dealStatus},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateTDeviceAlarm" parameterType="TDeviceAlarm">
        update t_device_alarm
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="deviceType != null">device_type = #{deviceType},</if>
            <if test="orderId != null">order_id = #{orderId},</if>
            <if test="alarmType != null">alarm_type = #{alarmType},</if>
            <if test="alarmValue != null">alarm_value = #{alarmValue},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="dealStatus != null">deal_status = #{dealStatus},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where alarm_id = #{alarmId}
    </update>

    <delete id="deleteTDeviceAlarmById" parameterType="Long">
        delete from t_device_alarm where alarm_id = #{alarmId}
    </delete>

    <delete id="deleteTDeviceAlarmByIds" parameterType="String">
        delete from t_device_alarm where alarm_id in 
        <foreach item="alarmId" collection="array" open="(" separator="," close=")">
            #{alarmId}
        </foreach>
    </delete>

    <select id="selectAlarmDevice" resultMap="TDeviceAlarmResult">
        SELECT
            alarm_id,
            device_id,
            device_type,
            order_id,
            alarm_type,
            alarm_value,
            start_time,
            end_time,
            deal_status,
            update_time,
            create_time
        FROM
            t_device_alarm
        WHERE
          end_time IS NULL

    </select>
    <select id="selectAddressByOrderId" resultType="java.lang.String">
        SELECT IFNULL(d.device_addr,"") AS address FROM t_device_alarm t
        LEFT JOIN t_device_info d ON t.device_id = d.device_id
        WHERE order_id = #{orderId}
    </select>
</mapper>