<?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.IsLocksetTypeMapper">

    <resultMap type="IsLocksetType" id="IsLocksetTypeResult">
        <result property="locksetTypeId"    column="lockset_type_id"    />
        <result property="locksetTypeCode"    column="lockset_type_code"    />
        <result property="locksetTypeName"    column="lockset_type_name"    />
        <result property="locksetTypeDescription"    column="lockset_type_description"    />
        <result property="locksetTypeIcon"    column="lockset_type_icon"    />
        <result property="locksetTypeImg"    column="lockset_type_img"    />
        <result property="materialsTypeId"    column="materials_type_id"    />
        <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="parentTypeId"    column="parent_type_id"    />
        <result property="ancestors"    column="ancestors"    />
        <result property="locksetTypeSpec"    column="lockset_type_spec"    />
    </resultMap>

    <sql id="selectIsLocksetTypeVo">
        select * from is_lockset_type
    </sql>

    <select id="selectIsLocksetTypeList" parameterType="IsLocksetType" resultMap="IsLocksetTypeResult">
        <include refid="selectIsLocksetTypeVo"/>
        <where>
            <if test="locksetTypeCode != null  and locksetTypeCode != ''"> and lockset_type_code = #{locksetTypeCode}</if>
            <if test="locksetTypeName != null  and locksetTypeName != ''"> and lockset_type_name like concat('%', #{locksetTypeName}, '%')</if>
            <if test="locksetTypeDescription != null  and locksetTypeDescription != ''"> and lockset_type_description = #{locksetTypeDescription}</if>
            <if test="locksetTypeIcon != null  and locksetTypeIcon != ''"> and lockset_type_icon = #{locksetTypeIcon}</if>
            <if test="locksetTypeImg != null  and locksetTypeImg != ''"> and lockset_type_img = #{locksetTypeImg}</if>
            <if test="materialsTypeId != null "> and materials_type_id = #{materialsTypeId}</if>
        </where>
    </select>

    <select id="selectIsLocksetTypeByLocksetTypeId" parameterType="Long" resultMap="IsLocksetTypeResult">
        <include refid="selectIsLocksetTypeVo"/>
        where lockset_type_id = #{locksetTypeId}
    </select>

    <insert id="insertIsLocksetType" parameterType="IsLocksetType" useGeneratedKeys="true" keyProperty="locksetTypeId">
        insert into is_lockset_type
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="locksetTypeCode != null and locksetTypeCode != ''">lockset_type_code,</if>
            <if test="locksetTypeName != null and locksetTypeName != ''">lockset_type_name,</if>
            <if test="locksetTypeDescription != null">lockset_type_description,</if>
            <if test="locksetTypeIcon != null">lockset_type_icon,</if>
            <if test="locksetTypeImg != null">lockset_type_img,</if>
            <if test="materialsTypeId != null">materials_type_id,</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">remark,</if>
            <if test="parentTypeId != null">parent_type_id,</if>
            <if test="ancestors != null and ancestors != ''">ancestors,</if>
            <if test="locksetTypeSpec != null and locksetTypeSpec != ''">lockset_type_spec,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="locksetTypeCode != null and locksetTypeCode != ''">#{locksetTypeCode},</if>
            <if test="locksetTypeName != null and locksetTypeName != ''">#{locksetTypeName},</if>
            <if test="locksetTypeDescription != null">#{locksetTypeDescription},</if>
            <if test="locksetTypeIcon != null">#{locksetTypeIcon},</if>
            <if test="locksetTypeImg != null">#{locksetTypeImg},</if>
            <if test="materialsTypeId != null">#{materialsTypeId},</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">#{remark},</if>
            <if test="parentTypeId != null">#{parentTypeId},</if>
            <if test="ancestors != null and ancestors != ''">#{ancestors},</if>
            <if test="locksetTypeSpec != null and locksetTypeSpec != ''">#{locksetTypeSpec},</if>
         </trim>
    </insert>

    <update id="updateIsLocksetType" parameterType="IsLocksetType">
        update is_lockset_type
        <trim prefix="SET" suffixOverrides=",">
            <if test="locksetTypeCode != null and locksetTypeCode != ''">lockset_type_code = #{locksetTypeCode},</if>
            <if test="locksetTypeName != null and locksetTypeName != ''">lockset_type_name = #{locksetTypeName},</if>
            <if test="locksetTypeDescription != null">lockset_type_description = #{locksetTypeDescription},</if>
            <if test="locksetTypeIcon != null">lockset_type_icon = #{locksetTypeIcon},</if>
            <if test="locksetTypeImg != null">lockset_type_img = #{locksetTypeImg},</if>
            <if test="materialsTypeId != null">materials_type_id = #{materialsTypeId},</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">remark = #{remark},</if>
            <if test="parentTypeId != null">parent_type_id = #{parentTypeId},</if>
            <if test="ancestors != null and ancestors != ''">ancestors = #{ancestors},</if>
            <if test="locksetTypeSpec != null and locksetTypeSpec != ''">lockset_type_spec = #{locksetTypeSpec},</if>
        </trim>
        where lockset_type_id = #{locksetTypeId}
    </update>

    <delete id="deleteIsLocksetTypeByLocksetTypeId" parameterType="Long">
        delete from is_lockset_type where lockset_type_id = #{locksetTypeId}
    </delete>

    <delete id="deleteIsLocksetTypeByLocksetTypeIds" parameterType="String">
        delete from is_lockset_type where lockset_type_id in
        <foreach item="locksetTypeId" collection="array" open="(" separator="," close=")">
            #{locksetTypeId}
        </foreach>
    </delete>

    <select id="getIsLocksetTypePage" resultType="com.ktg.iscs.domain.vo.locksetType.IsLocksetTypeVO">
        SELECT
        l.*,
        m.materials_type_name
        FROM
        is_lockset_type l
        LEFT JOIN is_materials_type m ON l.materials_type_id = m.materials_type_id
        <where>
            <if test="isLocksetType.locksetTypeCode != null and isLocksetType.locksetTypeCode.trim != ''">
                and l.lockset_type_code like concat('%',#{isLocksetType.locksetTypeCode},'%')
            </if>
            <if test="isLocksetType.locksetTypeName != null and isLocksetType.locksetTypeName.trim != ''">
                and l.lockset_type_name like concat('%',#{isLocksetType.locksetTypeName},'%')
            </if>
        </where>
        ORDER BY
        l.lockset_type_id asc
    </select>

</mapper>
