<?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.check.mapper.CheckProjectItemMapper">

    <resultMap type="CheckProjectItem" id="CheckProjectItemResult">
        <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="sourceId" column="source_id"/>
        <result property="projectCode" column="project_code"/>
        <result property="type" column="type"/>
        <result property="projectName" column="project_name"/>
        <result property="categoryCodeOne" column="category_code_one"/>
        <result property="categoryNameOne" column="category_name_one"/>
        <result property="categoryCodeTwo" column="category_code_two"/>
        <result property="categoryNameTwo" column="category_name_two"/>
        <result property="score" column="score"/>
        <result property="scoreLevel" column="score_level"/>
        <result property="typeDesc" column="type_desc"/>
        <result property="scoreLevelDesc" column="score_level_desc"/>
        <result property="remark" column="remark"/>
        <result property="inspectionContent" column="inspection_content"/>
        <result property="scoreTotal" column="score_total"/>
        <result property="evaluationType" column="evaluation_type"/>
        <result property="evaluationTypeDesc" column="evaluation_type_desc"/>
        <result property="correctionUserId" column="correction_user_id"/>
        <result property="correctionUserName" column="correction_user_name"/>
        <result property="rectificationDeadline" column="rectification_deadline"/>
        <result property="correctionStatus" column="correction_status"/>
        <result property="correctionStatusDesc" column="correction_status_desc"/>
        <result property="problemDescription" column="problem_description"/>
        <result property="attachmentId" column="attachment_id"/>
        <result property="attachmentUrl" column="attachment_url"/>
        <result property="attachmentName" column="attachment_name"/>
        <result property="rewardSuggestion" column="reward_suggestion"/>
    </resultMap>

    <sql id="selectCheckProjectItemVo">
        select tenant_id,
               revision,
               create_by,
               create_time,
               update_by,
               update_time,
               id,
               source_id,
               project_code,
               type,
               project_name,
               category_code_one,
               category_name_one,
               category_code_two,
               category_name_two,
               score,
               score_level,
               type_desc,
               score_level_desc,
               remark,
               inspection_content,
               score_total,
               evaluation_type,
               evaluation_type_desc,
               correction_user_id,
               correction_user_name,
               rectification_deadline,
               correction_status,
               correction_status_desc,
               problem_description,
               attachment_id,
               attachment_url,
               attachment_name,
               reward_suggestion
        from check_project_item
    </sql>

    <select id="selectCheckProjectItemList" parameterType="CheckProjectItem" resultMap="CheckProjectItemResult">
        <include refid="selectCheckProjectItemVo"/>
        <where>
            <if test="tenantId != null  and tenantId != ''">and tenant_id = #{tenantId}</if>
            <if test="revision != null ">and revision = #{revision}</if>
            <if test="sourceId != null ">and source_id = #{sourceId}</if>
            <if test="projectCode != null  and projectCode != ''">and project_code = #{projectCode}</if>
            <if test="type != null  and type != ''">and type = #{type}</if>
            <if test="projectName != null  and projectName != ''">and project_name like concat('%', #{projectName},
                '%')
            </if>
            <if test="categoryCodeOne != null  and categoryCodeOne != ''">and category_code_one = #{categoryCodeOne}
            </if>
            <if test="categoryNameOne != null  and categoryNameOne != ''">and category_name_one = #{categoryNameOne}
            </if>
            <if test="categoryCodeTwo != null  and categoryCodeTwo != ''">and category_code_two = #{categoryCodeTwo}
            </if>
            <if test="categoryNameTwo != null  and categoryNameTwo != ''">and category_name_two = #{categoryNameTwo}
            </if>
            <if test="score != null ">and score = #{score}</if>
            <if test="scoreLevel != null  and scoreLevel != ''">and score_level = #{scoreLevel}</if>
            <if test="typeDesc != null  and typeDesc != ''">and type_desc = #{typeDesc}</if>
            <if test="scoreLevelDesc != null  and scoreLevelDesc != ''">and score_level_desc = #{scoreLevelDesc}</if>
            <if test="inspectionContent != null  and inspectionContent != ''">and inspection_content =
                #{inspectionContent}
            </if>
            <if test="scoreTotal != null ">and score_total = #{scoreTotal}</if>
            <if test="evaluationType != null  and evaluationType != ''">and evaluation_type = #{evaluationType}</if>
            <if test="evaluationTypeDesc != null  and evaluationTypeDesc != ''">and evaluation_type_desc =
                #{evaluationTypeDesc}
            </if>
            <if test="correctionUserId != null ">and correction_user_id = #{correctionUserId}</if>
            <if test="correctionUserName != null  and correctionUserName != ''">and correction_user_name like
                concat('%', #{correctionUserName}, '%')
            </if>
            <if test="rectificationDeadline != null ">and rectification_deadline = #{rectificationDeadline}</if>
            <if test="correctionStatus != null  and correctionStatus != ''">and correction_status =
                #{correctionStatus}
            </if>
            <if test="correctionStatusDesc != null  and correctionStatusDesc != ''">and correction_status_desc =
                #{correctionStatusDesc}
            </if>
            <if test="problemDescription != null  and problemDescription != ''">and problem_description =
                #{problemDescription}
            </if>
            <if test="attachmentId != null  and attachmentId != ''">and attachment_id = #{attachmentId}</if>
            <if test="attachmentUrl != null  and attachmentUrl != ''">and attachment_url = #{attachmentUrl}</if>
            <if test="attachmentName != null  and attachmentName != ''">and attachment_name like concat('%',
                #{attachmentName}, '%')
            </if>
            <if test="rewardSuggestion != null  and rewardSuggestion != ''">and reward_suggestion =
                #{rewardSuggestion}
            </if>
        </where>
        order by create_time desc
    </select>

    <select id="selectCheckProjectItemById" parameterType="Long" resultMap="CheckProjectItemResult">
        <include refid="selectCheckProjectItemVo"/>
        where id = #{id}
    </select>

    <insert id="insertCheckProjectItem" parameterType="CheckProjectItem" useGeneratedKeys="true" keyProperty="id">
        insert into check_project_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="sourceId != null">source_id,</if>
            <if test="projectCode != null and projectCode != ''">project_code,</if>
            <if test="type != null and type != ''">type,</if>
            <if test="projectName != null and projectName != ''">project_name,</if>
            <if test="categoryCodeOne != null and categoryCodeOne != ''">category_code_one,</if>
            <if test="categoryNameOne != null and categoryNameOne != ''">category_name_one,</if>
            <if test="categoryCodeTwo != null and categoryCodeTwo != ''">category_code_two,</if>
            <if test="categoryNameTwo != null and categoryNameTwo != ''">category_name_two,</if>
            <if test="score != null">score,</if>
            <if test="scoreLevel != null">score_level,</if>
            <if test="typeDesc != null and typeDesc != ''">type_desc,</if>
            <if test="scoreLevelDesc != null">score_level_desc,</if>
            <if test="remark != null">remark,</if>
            <if test="inspectionContent != null">inspection_content,</if>
            <if test="scoreTotal != null">score_total,</if>
            <if test="evaluationType != null and evaluationType != ''">evaluation_type,</if>
            <if test="evaluationTypeDesc != null and evaluationTypeDesc != ''">evaluation_type_desc,</if>
            <if test="correctionUserId != null">correction_user_id,</if>
            <if test="correctionUserName != null">correction_user_name,</if>
            <if test="rectificationDeadline != null">rectification_deadline,</if>
            <if test="correctionStatus != null">correction_status,</if>
            <if test="correctionStatusDesc != null">correction_status_desc,</if>
            <if test="problemDescription != null">problem_description,</if>
            <if test="attachmentId != null">attachment_id,</if>
            <if test="attachmentUrl != null">attachment_url,</if>
            <if test="attachmentName != null">attachment_name,</if>
            <if test="rewardSuggestion != null">reward_suggestion,</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="sourceId != null">#{sourceId},</if>
            <if test="projectCode != null and projectCode != ''">#{projectCode},</if>
            <if test="type != null and type != ''">#{type},</if>
            <if test="projectName != null and projectName != ''">#{projectName},</if>
            <if test="categoryCodeOne != null and categoryCodeOne != ''">#{categoryCodeOne},</if>
            <if test="categoryNameOne != null and categoryNameOne != ''">#{categoryNameOne},</if>
            <if test="categoryCodeTwo != null and categoryCodeTwo != ''">#{categoryCodeTwo},</if>
            <if test="categoryNameTwo != null and categoryNameTwo != ''">#{categoryNameTwo},</if>
            <if test="score != null">#{score},</if>
            <if test="scoreLevel != null">#{scoreLevel},</if>
            <if test="typeDesc != null and typeDesc != ''">#{typeDesc},</if>
            <if test="scoreLevelDesc != null">#{scoreLevelDesc},</if>
            <if test="remark != null">#{remark},</if>
            <if test="inspectionContent != null">#{inspectionContent},</if>
            <if test="scoreTotal != null">#{scoreTotal},</if>
            <if test="evaluationType != null and evaluationType != ''">#{evaluationType},</if>
            <if test="evaluationTypeDesc != null and evaluationTypeDesc != ''">#{evaluationTypeDesc},</if>
            <if test="correctionUserId != null">#{correctionUserId},</if>
            <if test="correctionUserName != null">#{correctionUserName},</if>
            <if test="rectificationDeadline != null">#{rectificationDeadline},</if>
            <if test="correctionStatus != null">#{correctionStatus},</if>
            <if test="correctionStatusDesc != null">#{correctionStatusDesc},</if>
            <if test="problemDescription != null">#{problemDescription},</if>
            <if test="attachmentId != null">#{attachmentId},</if>
            <if test="attachmentUrl != null">#{attachmentUrl},</if>
            <if test="attachmentName != null">#{attachmentName},</if>
            <if test="rewardSuggestion != null">#{rewardSuggestion},</if>
        </trim>
    </insert>

    <update id="updateCheckProjectItem" parameterType="CheckProjectItem">
        update check_project_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="sourceId != null">source_id = #{sourceId},</if>
            <if test="projectCode != null and projectCode != ''">project_code = #{projectCode},</if>
            <if test="type != null and type != ''">type = #{type},</if>
            <if test="projectName != null and projectName != ''">project_name = #{projectName},</if>
            <if test="categoryCodeOne != null and categoryCodeOne != ''">category_code_one = #{categoryCodeOne},</if>
            <if test="categoryNameOne != null and categoryNameOne != ''">category_name_one = #{categoryNameOne},</if>
            <if test="categoryCodeTwo != null and categoryCodeTwo != ''">category_code_two = #{categoryCodeTwo},</if>
            <if test="categoryNameTwo != null and categoryNameTwo != ''">category_name_two = #{categoryNameTwo},</if>
            <if test="score != null">score = #{score},</if>
            <if test="scoreLevel != null">score_level = #{scoreLevel},</if>
            <if test="typeDesc != null and typeDesc != ''">type_desc = #{typeDesc},</if>
            <if test="scoreLevelDesc != null">score_level_desc = #{scoreLevelDesc},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="inspectionContent != null">inspection_content = #{inspectionContent},</if>
            <if test="scoreTotal != null">score_total = #{scoreTotal},</if>
            <if test="evaluationType != null and evaluationType != ''">evaluation_type = #{evaluationType},</if>
            <if test="evaluationTypeDesc != null and evaluationTypeDesc != ''">evaluation_type_desc =
                #{evaluationTypeDesc},
            </if>
            <if test="correctionUserId != null">correction_user_id = #{correctionUserId},</if>
            <if test="correctionUserName != null">correction_user_name = #{correctionUserName},</if>
            <if test="rectificationDeadline != null">rectification_deadline = #{rectificationDeadline},</if>
            <if test="correctionStatus != null">correction_status = #{correctionStatus},</if>
            <if test="correctionStatusDesc != null">correction_status_desc = #{correctionStatusDesc},</if>
            <if test="problemDescription != null">problem_description = #{problemDescription},</if>
            <if test="attachmentId != null">attachment_id = #{attachmentId},</if>
            <if test="attachmentUrl != null">attachment_url = #{attachmentUrl},</if>
            <if test="attachmentName != null">attachment_name = #{attachmentName},</if>
            <if test="rewardSuggestion != null">reward_suggestion = #{rewardSuggestion},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCheckProjectItemById" parameterType="Long">
        delete
        from check_project_item
        where id = #{id}
    </delete>

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