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

    <resultMap type="IsHardwareType" id="IsHardwareTypeResult">
        <result property="id"    column="id"    />
        <result property="hardwareTypeCode"    column="hardware_type_code"    />
        <result property="hardwareTypeName"    column="hardware_type_name"    />
        <result property="parentTypeId"    column="parent_type_id"    />
        <result property="ancestors"    column="ancestors"    />
        <result property="enableFlag"    column="enable_flag"    />
        <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="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="level"    column="level"    />
    </resultMap>

    <sql id="selectIsHardwareTypeVo">
        select id, hardware_type_code, hardware_type_name, parent_type_id, ancestors, enable_flag, remark, del_flag, create_by, create_time, update_by, update_time, level from is_hardware_type
    </sql>

    <select id="selectIsHardwareTypeList" parameterType="IsHardwareType" resultMap="IsHardwareTypeResult">
        <include refid="selectIsHardwareTypeVo"/>
        <where>
            <if test="hardwareTypeCode != null  and hardwareTypeCode != ''"> and hardware_type_code = #{hardwareTypeCode}</if>
            <if test="hardwareTypeName != null  and hardwareTypeName != ''"> and hardware_type_name like concat('%', #{hardwareTypeName}, '%')</if>
            <if test="parentTypeId != null "> and parent_type_id = #{parentTypeId}</if>
            <if test="ancestors != null  and ancestors != ''"> and ancestors = #{ancestors}</if>
            <if test="enableFlag != null  and enableFlag != ''"> and enable_flag = #{enableFlag}</if>
            <if test="level != null  and level != ''"> and level = #{level}</if>
        </where>
    </select>

    <select id="selectIsHardwareTypeById" parameterType="Long" resultMap="IsHardwareTypeResult">
        <include refid="selectIsHardwareTypeVo"/>
        where id = #{id}
    </select>

    <insert id="insertIsHardwareType" parameterType="IsHardwareType" useGeneratedKeys="true" keyProperty="id">
        insert into is_hardware_type
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="hardwareTypeCode != null and hardwareTypeCode != ''">hardware_type_code,</if>
            <if test="hardwareTypeName != null and hardwareTypeName != ''">hardware_type_name,</if>
            <if test="parentTypeId != null">parent_type_id,</if>
            <if test="ancestors != null and ancestors != ''">ancestors,</if>
            <if test="enableFlag != null and enableFlag != ''">enable_flag,</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="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="level != null">level,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="hardwareTypeCode != null and hardwareTypeCode != ''">#{hardwareTypeCode},</if>
            <if test="hardwareTypeName != null and hardwareTypeName != ''">#{hardwareTypeName},</if>
            <if test="parentTypeId != null">#{parentTypeId},</if>
            <if test="ancestors != null and ancestors != ''">#{ancestors},</if>
            <if test="enableFlag != null and enableFlag != ''">#{enableFlag},</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="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="level != null">#{level},</if>
        </trim>
    </insert>

    <update id="updateIsHardwareType" parameterType="IsHardwareType">
        update is_hardware_type
        <trim prefix="SET" suffixOverrides=",">
            <if test="hardwareTypeCode != null and hardwareTypeCode != ''">hardware_type_code = #{hardwareTypeCode},</if>
            <if test="hardwareTypeName != null and hardwareTypeName != ''">hardware_type_name = #{hardwareTypeName},</if>
            <if test="parentTypeId != null">parent_type_id = #{parentTypeId},</if>
            <if test="ancestors != null and ancestors != ''">ancestors = #{ancestors},</if>
            <if test="enableFlag != null and enableFlag != ''">enable_flag = #{enableFlag},</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="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="level != null">level = #{level},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteIsHardwareTypeById" parameterType="Long">
        delete from is_hardware_type where id = #{id}
    </delete>

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