<?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.TSpecialDeviceRecordMapper">
    
    <resultMap type="TSpecialDeviceRecordVo" id="TSpecialDeviceRecordResult">
        <result property="id"    column="id"    />
        <result property="operateCode"    column="operate_code"    />
        <result property="operateType"    column="operate_type"    />
        <result property="deviceCode"    column="device_code"    />
        <result property="deviceName"    column="device_name"    />
        <result property="deviceType"    column="device_type"    />
        <result property="effectiveDate"    column="effective_date"    />
        <result property="recordStatus"    column="record_status"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isDel"    column="is_del"    />
    </resultMap>

    <sql id="selectTSpecialDeviceRecordVo">
        select t.id, t.operate_code, t.operate_type, t.device_code, t.effective_date, t.record_status, t.create_time, t.update_time, t.is_del,
        d.device_name, d.device_type
        from t_special_device_record t
        left join t_device_info d on t.device_id = d.id
    </sql>

    <select id="selectTSpecialDeviceRecordList" parameterType="TSpecialDeviceRecord" resultMap="TSpecialDeviceRecordResult">
        <include refid="selectTSpecialDeviceRecordVo"/>
        <where>  t.is_del = '0'
            <if test="operateCode != null "> and t.operate_code = #{operateCode}</if>
            <if test="operateType != null "> and t.operate_type = #{operateType}</if>
            <if test="deviceCode != null  and deviceCode != ''"> and t.device_code like concat('%', #{deviceCode}, '%')</if>
            <if test="effectiveDate != null "> and t.effective_date = #{effectiveDate}</if>
            <if test="recordStatus != null  and recordStatus != ''"> and t.record_status = #{recordStatus}</if>
            <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
                AND date_format(t.effective_date,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
            </if>
            <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
                AND date_format(t.effective_date,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
            </if>
        </where>
    </select>
    
    <select id="selectTSpecialDeviceRecordById" parameterType="Long" resultMap="TSpecialDeviceRecordResult">
        <include refid="selectTSpecialDeviceRecordVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTSpecialDeviceRecord" parameterType="TSpecialDeviceRecord">
        insert into t_special_device_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="operateCode != null">operate_code,</if>
            <if test="operateType != null">operate_type,</if>
            <if test="deviceCode != null">device_code,</if>
            <if test="deviceId != null">device_id,</if>
            <if test="effectiveDate != null">effective_date,</if>
            <if test="recordStatus != null">record_status,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="isDel != null">is_del,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="operateCode != null">#{operateCode},</if>
            <if test="operateType != null">#{operateType},</if>
            <if test="deviceCode != null">#{deviceCode},</if>
            <if test="deviceId != null">#{deviceId},</if>
            <if test="effectiveDate != null">#{effectiveDate},</if>
            <if test="recordStatus != null">#{recordStatus},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="isDel != null">#{isDel},</if>
         </trim>
    </insert>

    <update id="updateTSpecialDeviceRecord" parameterType="TSpecialDeviceRecord">
        update t_special_device_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="operateType != null">operate_type = #{operateType},</if>
            <if test="deviceCode != null">device_code = #{deviceCode},</if>
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="effectiveDate != null">effective_date = #{effectiveDate},</if>
            <if test="recordStatus != null">record_status = #{recordStatus},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
        </trim>
        where operate_code = #{operateCode}
    </update>

    <delete id="deleteTSpecialDeviceRecordById" parameterType="Long">
        delete from t_special_device_record where id = #{id}
    </delete>

    <delete id="deleteTSpecialDeviceRecordByIds" parameterType="String">
        delete from t_special_device_record where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>