<?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.TDeviceInfoMapper">
    
    <resultMap type="TDeviceInfo" id="TDeviceInfoResult">
        <result property="id"    column="id"    />
        <result property="deviceName"    column="device_name"    />
        <result property="deviceCode"    column="device_code"    />
        <result property="deviceStatus"    column="device_status"    />
        <result property="deviceType"    column="device_type"    />
        <result property="tagNumber"    column="tag_number"    />
        <result property="deviceGrade"    column="device_grade"    />
        <result property="installLocation"    column="install_location"    />
        <result property="isSpecial"    column="is_special"    />
        <result property="responsiblePerson"    column="responsible_person"    />
        <result property="responsiblePhone"    column="responsible_phone"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isDel"    column="is_del"    />
        <result property="remarks"    column="remarks"    />
    </resultMap>

    <sql id="selectTDeviceInfoVo">
        select id, device_name, device_code, device_status, device_type, tag_number, device_grade, install_location, is_special, responsible_person, responsible_phone, create_time, update_time, is_del, remarks from t_device_info
    </sql>

    <select id="selectTDeviceInfoList" parameterType="TDeviceInfo" resultMap="TDeviceInfoResult">
        <include refid="selectTDeviceInfoVo"/>
        <where>  is_del = '0'
            <if test="deviceName != null  and deviceName != ''"> and device_name like concat('%', #{deviceName}, '%')</if>
            <if test="deviceCode != null  and deviceCode != ''"> and device_code like concat('%', #{deviceCode}, '%')</if>
            <if test="deviceStatus != null  and deviceStatus != ''"> and device_status = #{deviceStatus}</if>
            <if test="deviceType != null  and deviceType != ''"> and device_type = #{deviceType}</if>
            <if test="tagNumber != null  and tagNumber != ''"> and tag_number = #{tagNumber}</if>
            <if test="deviceGrade != null  and deviceGrade != ''"> and device_grade = #{deviceGrade}</if>
            <if test="isSpecial != null  and isSpecial != ''"> and is_special = #{isSpecial}</if>
            <if test="responsiblePhone != null  and responsiblePhone != ''"> and responsible_phone = #{responsiblePhone}</if>
            <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
                AND date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
            </if>
            <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
                AND date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
            </if>
        </where>
    </select>
    
    <select id="selectTDeviceInfoById" parameterType="Long" resultMap="TDeviceInfoResult">
        <include refid="selectTDeviceInfoVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTDeviceInfo" parameterType="TDeviceInfo" useGeneratedKeys="true" keyProperty="id">
        insert into t_device_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deviceName != null">device_name,</if>
            <if test="deviceCode != null">device_code,</if>
            <if test="deviceStatus != null">device_status,</if>
            <if test="deviceType != null">device_type,</if>
            <if test="tagNumber != null">tag_number,</if>
            <if test="deviceGrade != null">device_grade,</if>
            <if test="installLocation != null">install_location,</if>
            <if test="isSpecial != null">is_special,</if>
            <if test="responsiblePerson != null">responsible_person,</if>
            <if test="responsiblePhone != null">responsible_phone,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="isDel != null">is_del,</if>
            <if test="remarks != null">remarks,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deviceName != null">#{deviceName},</if>
            <if test="deviceCode != null">#{deviceCode},</if>
            <if test="deviceStatus != null">#{deviceStatus},</if>
            <if test="deviceType != null">#{deviceType},</if>
            <if test="tagNumber != null">#{tagNumber},</if>
            <if test="deviceGrade != null">#{deviceGrade},</if>
            <if test="installLocation != null">#{installLocation},</if>
            <if test="isSpecial != null">#{isSpecial},</if>
            <if test="responsiblePerson != null">#{responsiblePerson},</if>
            <if test="responsiblePhone != null">#{responsiblePhone},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="remarks != null">#{remarks},</if>
         </trim>
    </insert>

    <update id="updateTDeviceInfo" parameterType="TDeviceInfo">
        update t_device_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceName != null">device_name = #{deviceName},</if>
            <if test="deviceCode != null">device_code = #{deviceCode},</if>
            <if test="deviceStatus != null">device_status = #{deviceStatus},</if>
            <if test="deviceType != null">device_type = #{deviceType},</if>
            <if test="tagNumber != null">tag_number = #{tagNumber},</if>
            <if test="deviceGrade != null">device_grade = #{deviceGrade},</if>
            <if test="installLocation != null">install_location = #{installLocation},</if>
            <if test="isSpecial != null">is_special = #{isSpecial},</if>
            <if test="responsiblePerson != null">responsible_person = #{responsiblePerson},</if>
            <if test="responsiblePhone != null">responsible_phone = #{responsiblePhone},</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>
            <if test="remarks != null">is_del = #{remarks},</if>
        </trim>
        where device_code = #{deviceCode} and is_del = '0'
    </update>

    <delete id="deleteTDeviceInfoById" parameterType="Long">
        delete from t_device_info where id = #{id}
    </delete>

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