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

    <resultMap type="BaseProject" id="BaseProjectResult">
        <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="id" column="id"/>
        <result property="name" column="name"/>
        <result property="categoryCode" column="category_code"/>
        <result property="checkStandard" column="check_standard"/>
        <result property="checkMethod" column="check_method"/>
        <result property="importance" column="importance"/>
        <result property="status" column="status"/>
        <result property="categoryName" column="category_name"/>
        <result property="remark" column="remark"/>
        <result property="code" column="code"/>
        <result property="importanceDesc" column="importance_desc"/>
        <result property="checkLevel" column="check_level"/>
    </resultMap>

    <sql id="selectBaseProjectVo">
        select tenant_id,
               revision,
               create_by,
               create_time,
               update_by,
               update_time,
               id,
               name,
               category_code,
               check_standard,
               check_method,
               importance,
               status,
               category_name,
               remark,
               code,
               importance_desc,
               check_level
        from base_project
    </sql>

    <select id="selectBaseProjectList" parameterType="BaseProject" resultMap="BaseProjectResult">
        <include refid="selectBaseProjectVo"/>
        <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="checkStandard != null  and checkStandard != ''">and check_standard = #{checkStandard}</if>
            <if test="checkMethod != null  and checkMethod != ''">and check_method = #{checkMethod}</if>
            <if test="importance != null  and importance != ''">and importance = #{importance}</if>
            <if test="status != null ">and status = #{status}</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="importanceDesc != null  and importanceDesc != ''">and importance_desc = #{importanceDesc}</if>
            <if test="checkLevel != null  and checkLevel != ''">and check_level = #{checkLevel}</if>
        </where>
    </select>

    <select id="selectBaseProjectById" parameterType="Long" resultMap="BaseProjectResult">
        <include refid="selectBaseProjectVo"/>
        where id = #{id}
    </select>

    <insert id="insertBaseProject" parameterType="BaseProject" useGeneratedKeys="true" keyProperty="id">
        insert into base_project
        <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="checkStandard != null">check_standard,</if>
            <if test="checkMethod != null">check_method,</if>
            <if test="importance != null and importance != ''">importance,</if>
            <if test="status != null">status,</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="importanceDesc != null and importanceDesc != ''">importance_desc,</if>
            <if test="checkLevel != null">check_level,</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="checkStandard != null">#{checkStandard},</if>
            <if test="checkMethod != null">#{checkMethod},</if>
            <if test="importance != null and importance != ''">#{importance},</if>
            <if test="status != null">#{status},</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="importanceDesc != null and importanceDesc != ''">#{importanceDesc},</if>
            <if test="checkLevel != null">#{checkLevel},</if>
        </trim>
    </insert>

    <update id="updateBaseProject" parameterType="BaseProject">
        update base_project
        <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="checkStandard != null">check_standard = #{checkStandard},</if>
            <if test="checkMethod != null">check_method = #{checkMethod},</if>
            <if test="importance != null and importance != ''">importance = #{importance},</if>
            <if test="status != null">status = #{status},</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="importanceDesc != null and importanceDesc != ''">importance_desc = #{importanceDesc},</if>
            <if test="checkLevel != null">check_level = #{checkLevel},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBaseProjectById" parameterType="Long">
        delete
        from base_project
        where id = #{id}
    </delete>

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

    <select id="listByCheckLevel" resultType="com.sundot.airport.system.domain.vo.CheckProjectItemVo">
        select m.code  categoryCodeOne,
               m.name  categoryNameOne,
               d.code  categoryCodeTwo,
               d.name  categoryNameTwo,
               bp.code projectCode,
               bp.name projectName
        from base_check_category m
                 inner join base_check_category d on m.id = d.parent_id
                 inner join base_project bp on d.code = bp.category_code
        where find_in_set(#{checkLevel}, bp.check_level) > 0
    </select>
</mapper>