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

    <resultMap type="IsLockType" id="IsLockTypeResult">
        <result property="lockTypeId"    column="lock_type_id"    />
        <result property="lockTypeCode"    column="lock_type_code"    />
        <result property="lockTypeName"    column="lock_type_name"    />
        <result property="lockTypeDescription"    column="lock_type_description"    />
        <result property="lockTypeIcon"    column="lock_type_icon"    />
        <result property="lockTypeImg"    column="lock_type_img"    />
        <result property="hardwareTypeId"    column="hardware_type_id"    />
        <result property="remark"    column="remark"    />
        <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="parentTypeId"    column="parent_type_id"    />
        <result property="ancestors"    column="ancestors"    />
        <result property="lockTypeSpec"    column="lock_type_spec"    />
    </resultMap>

    <sql id="selectIsLockTypeVo">
        select * from is_lock_type
    </sql>

    <select id="selectIsLockTypeList" parameterType="IsLockType" resultMap="IsLockTypeResult">
        <include refid="selectIsLockTypeVo"/>
        <where>
            <if test="lockTypeCode != null  and lockTypeCode != ''"> and lock_type_code = #{lockTypeCode}</if>
            <if test="lockTypeName != null  and lockTypeName != ''"> and lock_type_name like concat('%', #{lockTypeName}, '%')</if>
            <if test="lockTypeDescription != null  and lockTypeDescription != ''"> and lock_type_description = #{lockTypeDescription}</if>
            <if test="lockTypeIcon != null  and lockTypeIcon != ''"> and lock_type_icon = #{lockTypeIcon}</if>
            <if test="lockTypeImg != null  and lockTypeImg != ''"> and lock_type_img = #{lockTypeImg}</if>
            <if test="hardwareTypeId != null "> and hardware_type_id = #{hardwareTypeId}</if>
        </where>
    </select>

    <select id="selectIsLockTypeByLockTypeId" parameterType="Long" resultMap="IsLockTypeResult">
        <include refid="selectIsLockTypeVo"/>
        where lock_type_id = #{lockTypeId}
    </select>

    <insert id="insertIsLockType" parameterType="IsLockType" useGeneratedKeys="true" keyProperty="lockTypeId">
        insert into is_lock_type
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="lockTypeCode != null and lockTypeCode != ''">lock_type_code,</if>
            <if test="lockTypeName != null and lockTypeName != ''">lock_type_name,</if>
            <if test="lockTypeDescription != null">lock_type_description,</if>
            <if test="lockTypeIcon != null">lock_type_icon,</if>
            <if test="lockTypeImg != null">lock_type_img,</if>
            <if test="hardwareTypeId != null">hardware_type_id,</if>
            <if test="remark != null">remark,</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="parentTypeId != null">parent_type_id,</if>
            <if test="ancestors != null and ancestors != ''">ancestors,</if>
            <if test="lockTypeSpec != null and lockTypeSpec != ''">lock_type_spec,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="lockTypeCode != null and lockTypeCode != ''">#{lockTypeCode},</if>
            <if test="lockTypeName != null and lockTypeName != ''">#{lockTypeName},</if>
            <if test="lockTypeDescription != null">#{lockTypeDescription},</if>
            <if test="lockTypeIcon != null">#{lockTypeIcon},</if>
            <if test="lockTypeImg != null">#{lockTypeImg},</if>
            <if test="hardwareTypeId != null">#{hardwareTypeId},</if>
            <if test="remark != null">#{remark},</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="parentTypeId != null">#{parentTypeId},</if>
            <if test="ancestors != null and ancestors != ''">#{ancestors},</if>
            <if test="lockTypeSpec != null and lockTypeSpec != ''">#{lockTypeSpec},</if>
         </trim>
    </insert>

    <update id="updateIsLockType" parameterType="IsLockType">
        update is_lock_type
        <trim prefix="SET" suffixOverrides=",">
            <if test="lockTypeCode != null and lockTypeCode != ''">lock_type_code = #{lockTypeCode},</if>
            <if test="lockTypeName != null and lockTypeName != ''">lock_type_name = #{lockTypeName},</if>
            <if test="lockTypeDescription != null">lock_type_description = #{lockTypeDescription},</if>
            <if test="lockTypeIcon != null">lock_type_icon = #{lockTypeIcon},</if>
            <if test="lockTypeImg != null">lock_type_img = #{lockTypeImg},</if>
            <if test="hardwareTypeId != null">hardware_type_id = #{hardwareTypeId},</if>
            <if test="remark != null">remark = #{remark},</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="parentTypeId != null">parent_type_id = #{parentTypeId},</if>
            <if test="ancestors != null and ancestors != ''">ancestors = #{ancestors},</if>
            <if test="lockTypeSpec != null and lockTypeSpec != ''">lock_type_spec = #{lockTypeSpec},</if>
        </trim>
        where lock_type_id = #{lockTypeId}
    </update>

    <delete id="deleteIsLockTypeByLockTypeId" parameterType="Long">
        delete from is_lock_type where lock_type_id = #{lockTypeId}
    </delete>

    <delete id="deleteIsLockTypeByLockTypeIds" parameterType="String">
        delete from is_lock_type where lock_type_id in
        <foreach item="lockTypeId" collection="array" open="(" separator="," close=")">
            #{lockTypeId}
        </foreach>
    </delete>

    <select id="getIsLockTypePage" resultType="com.ktg.iscs.domain.vo.lockType.IsLockTypeVO">
        SELECT
            l.*,
            h.hardware_type_name
        FROM
            is_lock_type l
            LEFT JOIN is_hardware_type h ON l.hardware_type_id = h.id
        <where>
            <if test="isLockType.lockTypeCode != null and isLockType.lockTypeCode.trim != ''">
                and l.lock_type_code like concat('%',#{isLockType.lockTypeCode},'%')
            </if>
            <if test="isLockType.lockTypeName != null and isLockType.lockTypeName.trim != ''">
                and l.lock_type_name like concat('%',#{isLockType.lockTypeName},'%')
            </if>
        </where>
        ORDER BY
        l.lock_type_id asc
    </select>


</mapper>
