<?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.ktg.iscs.mapper.IsLocksetMapper">

    <resultMap type="IsLockset" id="IsLocksetResult">
        <result property="locksetId"    column="lockset_id"    />
        <result property="locksetCode"    column="lockset_code"    />
        <result property="locksetName"    column="lockset_name"    />
        <result property="locksetTypeId"    column="lockset_type_id"    />
        <result property="materialsId"    column="materials_id"    />
        <result property="locksetNfc"    column="lockset_nfc"    />
        <result property="locksetRfid"    column="lockset_rfid"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="remark"    column="remark"    />
        <result property="locksetSpec"    column="lockset_spec"    />
    </resultMap>

    <sql id="selectIsLocksetVo">
        select lockset_id, lockset_code, lockset_name, lockset_type_id, materials_id, lockset_nfc, lockset_rfid, del_flag, create_by, create_time, update_time, update_by, remark from is_lockset
    </sql>

    <select id="selectIsLocksetList" parameterType="IsLockset" resultMap="IsLocksetResult">
        <include refid="selectIsLocksetVo"/>
        <where>
            <if test="locksetCode != null  and locksetCode != ''"> and lockset_code = #{locksetCode}</if>
            <if test="locksetName != null  and locksetName != ''"> and lockset_name like concat('%', #{locksetName}, '%')</if>
            <if test="locksetTypeId != null "> and lockset_type_id = #{locksetTypeId}</if>
            <if test="materialsId != null "> and materials_id = #{materialsId}</if>
            <if test="locksetNfc != null  and locksetNfc != ''"> and lockset_nfc = #{locksetNfc}</if>
            <if test="locksetRfid != null "> and lockset_rfid = #{locksetRfid}</if>
        </where>
    </select>

    <select id="selectIsLocksetByLocksetId" parameterType="Long" resultMap="IsLocksetResult">
        <include refid="selectIsLocksetVo"/>
        where lockset_id = #{locksetId}
    </select>

    <insert id="insertIsLockset" parameterType="IsLockset" useGeneratedKeys="true" keyProperty="locksetId">
        insert into is_lockset
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="locksetCode != null and locksetCode != ''">lockset_code,</if>
            <if test="locksetName != null and locksetName != ''">lockset_name,</if>
            <if test="locksetTypeId != null">lockset_type_id,</if>
            <if test="materialsId != null">materials_id,</if>
            <if test="locksetNfc != null">lockset_nfc,</if>
            <if test="locksetRfid != null">lockset_rfid,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="remark != null and remark != ''">remark,</if>
            <if test="locksetSpec != null and locksetSpec != ''">lockset_spec,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="locksetCode != null and locksetCode != ''">#{locksetCode},</if>
            <if test="locksetName != null and locksetName != ''">#{locksetName},</if>
            <if test="locksetTypeId != null">#{locksetTypeId},</if>
            <if test="materialsId != null">#{materialsId},</if>
            <if test="locksetNfc != null">#{locksetNfc},</if>
            <if test="locksetRfid != null">#{locksetRfid},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="remark != null and remark != ''">#{remark},</if>
            <if test="locksetSpec != null and locksetSpec != ''">#{locksetSpec},</if>
         </trim>
    </insert>

    <update id="updateIsLockset" parameterType="IsLockset">
        update is_lockset
        <trim prefix="SET" suffixOverrides=",">
            <if test="locksetCode != null and locksetCode != ''">lockset_code = #{locksetCode},</if>
            <if test="locksetName != null and locksetName != ''">lockset_name = #{locksetName},</if>
            <if test="locksetTypeId != null">lockset_type_id = #{locksetTypeId},</if>
            <if test="materialsId != null">materials_id = #{materialsId},</if>
            <if test="locksetNfc != null">lockset_nfc = #{locksetNfc},</if>
            <if test="locksetRfid != null">lockset_rfid = #{locksetRfid},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="remark != null and remark != ''">remark = #{remark},</if>
            <if test="locksetSpec != null and locksetSpec != ''">lockset_spec = #{locksetSpec},</if>
        </trim>
        where lockset_id = #{locksetId}
    </update>

    <delete id="deleteIsLocksetByLocksetId" parameterType="Long">
        delete from is_lockset where lockset_id = #{locksetId}
    </delete>

    <delete id="deleteIsLocksetByLocksetIds" parameterType="String">
        delete from is_lockset where lockset_id in
        <foreach item="locksetId" collection="array" open="(" separator="," close=")">
            #{locksetId}
        </foreach>
    </delete>

    <select id="getIsLocksetPage" resultType="com.ktg.iscs.domain.vo.lockset.IsLocksetVO">
        SELECT
        l.*,
        lt.lockset_type_name,
        m.materials_name
        FROM
        is_lockset l
        LEFT JOIN is_lockset_type lt ON l.lockset_type_id = lt.lockset_type_id
        LEFT JOIN is_materials m ON l.materials_id = m.materials_id
        <where>
            <if test="isLockset.locksetCode != null and isLockset.locksetCode.trim != ''">
                and l.lockset_code like concat('%',#{isLockset.locksetCode},'%')
            </if>
            <if test="isLockset.locksetName != null and isLockset.locksetName.trim != ''">
                and l.lockset_name like concat('%',#{isLockset.locksetName},'%')
            </if>
            <if test="isLockset.locksetTypeId != null">
                and l.lockset_type_id = #{isLockset.locksetTypeId}
            </if>
        </where>
        ORDER BY
        l.lockset_id DESC
    </select>

</mapper>
