<?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.sundot.airport.system.mapper.BaseSeizeItemMapper">

    <resultMap type="BaseSeizeItem" id="BaseSeizeItemResult">
        <result property="tenantId" column="tenant_id"/>
        <result property="revision" column="revision"/>
        <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="name" column="name"/>
        <result property="categoryCode" column="category_code"/>
        <result property="dangerLevel" column="danger_level"/>
        <result property="id" column="id"/>
        <result property="categoryName" column="category_name"/>
        <result property="remark" column="remark"/>
        <result property="code" column="code"/>
        <result property="dangerLevelDesc" column="danger_level_desc"/>
    </resultMap>

    <sql id="selectBaseSeizeItemVo">
        select tenant_id,
               revision,
               create_by,
               create_time,
               update_by,
               update_time,
               name,
               category_code,
               danger_level,
               id,
               category_name,
               remark,
               code,
               danger_level_desc
        from base_seize_item
    </sql>

    <select id="selectBaseSeizeItemList" parameterType="BaseSeizeItem" resultMap="BaseSeizeItemResult">
        <include refid="selectBaseSeizeItemVo"/>
        <where>
            <if test="tenantId != null  and tenantId != ''">and tenant_id = #{tenantId}</if>
            <if test="revision != null ">and revision = #{revision}</if>
            <if test="name != null  and name != ''">and name like concat('%', #{name}, '%')</if>
            <if test="categoryCode != null  and categoryCode != ''">and category_code = #{categoryCode}</if>
            <if test="dangerLevel != null  and dangerLevel != ''">and danger_level = #{dangerLevel}</if>
            <if test="categoryName != null  and categoryName != ''">and category_name like concat('%', #{categoryName},
                '%')
            </if>
            <if test="code != null  and code != ''">and code = #{code}</if>
            <if test="dangerLevelDesc != null  and dangerLevelDesc != ''">and danger_level_desc = #{dangerLevelDesc}
            </if>
        </where>
        order by create_time desc
    </select>

    <select id="selectBaseSeizeItemById" parameterType="Long" resultMap="BaseSeizeItemResult">
        <include refid="selectBaseSeizeItemVo"/>
        where id = #{id}
    </select>

    <insert id="insertBaseSeizeItem" parameterType="BaseSeizeItem" useGeneratedKeys="true" keyProperty="id">
        insert into base_seize_item
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="tenantId != null">tenant_id,</if>
            <if test="revision != null">revision,</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="name != null and name != ''">name,</if>
            <if test="categoryCode != null and categoryCode != ''">category_code,</if>
            <if test="dangerLevel != null and dangerLevel != ''">danger_level,</if>
            <if test="categoryName != null and categoryName != ''">category_name,</if>
            <if test="remark != null">remark,</if>
            <if test="code != null and code != ''">code,</if>
            <if test="dangerLevelDesc != null and dangerLevelDesc != ''">danger_level_desc,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="tenantId != null">#{tenantId},</if>
            <if test="revision != null">#{revision},</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="name != null and name != ''">#{name},</if>
            <if test="categoryCode != null and categoryCode != ''">#{categoryCode},</if>
            <if test="dangerLevel != null and dangerLevel != ''">#{dangerLevel},</if>
            <if test="categoryName != null and categoryName != ''">#{categoryName},</if>
            <if test="remark != null">#{remark},</if>
            <if test="code != null and code != ''">#{code},</if>
            <if test="dangerLevelDesc != null and dangerLevelDesc != ''">#{dangerLevelDesc},</if>
        </trim>
    </insert>

    <update id="updateBaseSeizeItem" parameterType="BaseSeizeItem">
        update base_seize_item
        <trim prefix="SET" suffixOverrides=",">
            <if test="tenantId != null">tenant_id = #{tenantId},</if>
            <if test="revision != null">revision = #{revision},</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="name != null and name != ''">name = #{name},</if>
            <if test="categoryCode != null and categoryCode != ''">category_code = #{categoryCode},</if>
            <if test="dangerLevel != null and dangerLevel != ''">danger_level = #{dangerLevel},</if>
            <if test="categoryName != null and categoryName != ''">category_name = #{categoryName},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="code != null and code != ''">code = #{code},</if>
            <if test="dangerLevelDesc != null and dangerLevelDesc != ''">danger_level_desc = #{dangerLevelDesc},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBaseSeizeItemById" parameterType="Long">
        delete
        from base_seize_item
        where id = #{id}
    </delete>

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

    <select id="getItemTypeByName" parameterType="String">
        select category_name
        from base_seize_item
        where name = #{name}
    </select>
</mapper>