<?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.ruoyi.system.mapper.TFacilityMapper">
    
    <resultMap type="TFacility" id="TFacilityResult">
        <result property="id"    column="id"    />
        <result property="kind"    column="kind"    />
        <result property="code"    column="code"    />
        <result property="telno"    column="telno"    />
        <result property="comCode"    column="com_code"    />
        <result property="createTime"    column="createtime"    />
        <result property="status"    column="status"    />
        <result property="iccid"    column="iccid"    />
        <result property="puk"    column="puk"    />
    </resultMap>

    <sql id="selectTFacilityVo">
        select id, kind, code, telno, com_code, createtime, status, iccid, puk from t_facility
    </sql>

    <select id="selectTFacilityList" parameterType="TFacility" resultMap="TFacilityResult">
        <include refid="selectTFacilityVo"/>
        <where>  
            <if test="kind != null "> and kind = #{kind}</if>
            <if test="code != null  and code != ''"> and code = #{code}</if>
            <if test="telno != null  and telno != ''"> and telno = #{telno}</if>
            <if test="comCode != null  and comCode != ''"> and com_code = #{comCode}</if>
            <if test="createTime != null "> and createtime = #{createTime}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="iccid != null "> and iccid = #{iccid}</if>
            <if test="puk != null "> and puk = #{puk}</if>
        </where>
    </select>
    
    <select id="selectTFacilityById" parameterType="Long" resultMap="TFacilityResult">
        <include refid="selectTFacilityVo"/>
        where id = #{id}
    </select>
 	<select id="selectTFacilityByCode" resultMap="TFacilityResult">
        <include refid="selectTFacilityVo"/>
        where code = #{code}
    </select>
    <select id="selectTDeviceListListByDeviceId" parameterType="string" resultMap="TFacilityResult">
        <include refid="selectTFacilityVo"/>
        where code = #{code}
    </select>

    <insert id="insertTFacility" parameterType="TFacility" useGeneratedKeys="true" keyProperty="id">
        insert into t_facility
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="kind != null">kind,</if>
            <if test="code != null">code,</if>
            <if test="telno != null">telno,</if>
            <if test="comCode != null">com_code,</if>
            <if test="createTime != null">createtime,</if>
            <if test="status != null">status,</if>
            <if test="iccid != null">iccid,</if>
            <if test="puk != null">puk,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="kind != null">#{kind},</if>
            <if test="code != null">#{code},</if>
            <if test="telno != null">#{telno},</if>
            <if test="comCode != null">#{comCode},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="status != null">#{status},</if>
            <if test="iccid != null">#{iccid},</if>
            <if test="puk != null">#{puk},</if>
         </trim>
    </insert>

    <update id="updateTFacility" parameterType="TFacility">
        update t_facility
        <trim prefix="SET" suffixOverrides=",">
            <if test="kind != null">kind = #{kind},</if>
            <if test="code != null">code = #{code},</if>
            <if test="telno != null">telno = #{telno},</if>
            <if test="comCode != null">com_code = #{comCode},</if>
            <if test="createTime != null">createtime = #{createTime},</if>
            <if test="status != null">status = #{status},</if>
            <if test="iccid != null">iccid = #{iccid},</if>
            <if test="puk != null">puk = #{puk},</if>
        </trim>
        where id = #{id}
    </update>
    <update id="updateTFacilityByDeviceCode" parameterType="TFacility">
        update t_facility
        <trim prefix="SET" suffixOverrides=",">
            <if test="kind != null">kind = #{kind},</if>
            <if test="telno != null">telno = #{telno},</if>
            <if test="comCode != null">com_code = #{comCode},</if>
            <if test="createTime != null">createtime = #{createTime},</if>
            <if test="status != null">status = #{status},</if>
            <if test="iccid != null">iccid = #{iccid},</if>
            <if test="puk != null">puk = #{puk},</if>
        </trim>
        where code = #{code}
    </update>

    <delete id="deleteTFacilityById" parameterType="Long">
        delete from t_facility where id = #{id}
    </delete>

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