<?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.ruoyi.system.mapper.ZxAssessmentMapper">
    
    <resultMap type="ZxAssessment" id="ZxAssessmentResult">
        <result property="assessmentId"    column="assessment_id"    />
        <result property="parentId"    column="parent_id"    />
        <result property="ancestors"    column="ancestors"    />
        <result property="assessmentProject"    column="assessment_project"    />
        <result property="assessmentProjectId"    column="assessment_project_id"    />
        <result property="assessmentStandard"    column="assessment_standard"    />
        <result property="assessmentType"    column="assessment_type"    />
        <result property="assessmentTypeId"    column="assessment_type_id"    />
        <result property="assessmentTotal"    column="assessment_total"    />
        <result property="scoreType"    column="score_type"    />
        <result property="assessmentScore"    column="assessment_score"    />
        <result property="assessmentCount"    column="assessment_count"    />
        <result property="assessmentExplain"    column="assessment_explain"    />
        <result property="isUse"    column="is_use"    />
        <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="remark"    column="remark"    />
    </resultMap>

    <sql id="selectZxAssessmentVo">
        select assessment_id, parent_id, ancestors, assessment_project,assessment_project_id,assessment_type_id, assessment_standard, assessment_type, assessment_total, score_type, assessment_score, assessment_count, assessment_explain, is_use, create_by, create_time, update_by, update_time, remark from zx_assessment
    </sql>

    <select id="selectZxAssessmentList" parameterType="ZxAssessment" resultMap="ZxAssessmentResult">
        <include refid="selectZxAssessmentVo"/>
        <where>  
            <if test="parentId != null "> and parent_id = #{parentId}</if>
            <if test="ancestors != null  and ancestors != ''"> and ancestors = #{ancestors}</if>
            <if test="assessmentProject != null  and assessmentProject != ''"> and assessment_project = #{assessmentProject}</if>
            <if test="assessmentProjectId != null  and assessmentProjectId != ''"> and assessment_project_id = #{assessmentProjectId}</if>
            <if test="assessmentStandard != null  and assessmentStandard != ''"> and assessment_standard = #{assessmentStandard}</if>
            <if test="assessmentType != null  and assessmentType != ''"> and assessment_type = #{assessmentType}</if>
            <if test="assessmentTypeId != null  and assessmentTypeId != ''"> and assessment_type_id = #{assessmentTypeId}</if>
            <if test="assessmentTotal != null  and assessmentTotal != ''"> and assessment_total = #{assessmentTotal}</if>
            <if test="scoreType != null  and scoreType != ''"> and score_type = #{scoreType}</if>
            <if test="assessmentScore != null  and assessmentScore != ''"> and assessment_score = #{assessmentScore}</if>
            <if test="assessmentCount != null  and assessmentCount != ''"> and assessment_count = #{assessmentCount}</if>
            <if test="assessmentExplain != null  and assessmentExplain != ''"> and assessment_explain = #{assessmentExplain}</if>
            <if test="isUse != null  and isUse != ''"> and is_use = #{isUse}</if>
        </where>
    </select>
    
    <select id="selectZxAssessmentByAssessmentId" parameterType="Long" resultMap="ZxAssessmentResult">
        <include refid="selectZxAssessmentVo"/>
        where assessment_id = #{assessmentId}
    </select>
    <select id="checkAssessmentProjectUnique" resultMap="ZxAssessmentResult">
        <include refid="selectZxAssessmentVo"/>
        where assessment_type_id = #{assessmentTypeId} and  parent_id = #{parentId} and is_use = 'Y' limit 1
    </select>

    <insert id="insertZxAssessment" parameterType="ZxAssessment" useGeneratedKeys="true" keyProperty="assessmentId">
        insert into zx_assessment
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="parentId != null">parent_id,</if>
            <if test="ancestors != null">ancestors,</if>
            <if test="assessmentProject != null and assessmentProject != ''">assessment_project,</if>
            <if test="assessmentProjectId != null and assessmentProjectId != ''">assessment_project_id,</if>
            <if test="assessmentStandard != null and assessmentStandard != ''">assessment_standard,</if>
            <if test="assessmentType != null and assessmentType != ''">assessment_type,</if>
            <if test="assessmentTypeId != null and assessmentTypeId != ''">assessment_type_id,</if>
            <if test="assessmentTotal != null and assessmentTotal != ''">assessment_total,</if>
            <if test="scoreType != null and scoreType != ''">score_type,</if>
            <if test="assessmentScore != null and assessmentScore != ''">assessment_score,</if>
            <if test="assessmentCount != null and assessmentCount != ''">assessment_count,</if>
            <if test="assessmentExplain != null and assessmentExplain != ''">assessment_explain,</if>
            <if test="isUse != null">is_use,</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="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="parentId != null">#{parentId},</if>
            <if test="ancestors != null">#{ancestors},</if>
            <if test="assessmentProject != null and assessmentProject != ''">#{assessmentProject},</if>
            <if test="assessmentProjectId != null and assessmentProjectId != ''">#{assessmentProjectId},</if>
            <if test="assessmentStandard != null and assessmentStandard != ''">#{assessmentStandard},</if>
            <if test="assessmentType != null and assessmentType != ''">#{assessmentType},</if>
            <if test="assessmentTypeId != null and assessmentTypeId != ''">#{assessmentTypeId},</if>
            <if test="assessmentTotal != null and assessmentTotal != ''">#{assessmentTotal},</if>
            <if test="scoreType != null and scoreType != ''">#{scoreType},</if>
            <if test="assessmentScore != null and assessmentScore != ''">#{assessmentScore},</if>
            <if test="assessmentCount != null and assessmentCount != ''">#{assessmentCount},</if>
            <if test="assessmentExplain != null and assessmentExplain != ''">#{assessmentExplain},</if>
            <if test="isUse != null">#{isUse},</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="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateZxAssessment" parameterType="ZxAssessment">
        update zx_assessment
        <trim prefix="SET" suffixOverrides=",">
            <if test="parentId != null">parent_id = #{parentId},</if>
            <if test="ancestors != null">ancestors = #{ancestors},</if>
            <if test="assessmentProject != null and assessmentProject != ''">assessment_project = #{assessmentProject},</if>
            <if test="assessmentProjectId != null and assessmentProjectId != ''">assessment_project_id = #{assessmentProjectId},</if>
            <if test="assessmentStandard != null and assessmentStandard != ''">assessment_standard = #{assessmentStandard},</if>
            <if test="assessmentType != null and assessmentType != ''">assessment_type = #{assessmentType},</if>
            <if test="assessmentTypeId != null and assessmentTypeId != ''">assessment_type_id = #{assessmentTypeId},</if>
            <if test="assessmentTotal != null and assessmentTotal != ''">assessment_total = #{assessmentTotal},</if>
            <if test="scoreType != null and scoreType != ''">score_type = #{scoreType},</if>
            <if test="assessmentScore != null and assessmentScore != ''">assessment_score = #{assessmentScore},</if>
            <if test="assessmentCount != null and assessmentCount != ''">assessment_count = #{assessmentCount},</if>
            <if test="assessmentExplain != null and assessmentExplain != ''">assessment_explain = #{assessmentExplain},</if>
            <if test="isUse != null">is_use = #{isUse},</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="remark != null">remark = #{remark},</if>
        </trim>
        where assessment_id = #{assessmentId}
    </update>

    <delete id="deleteZxAssessmentByAssessmentId" parameterType="Long">
        delete from zx_assessment where assessment_id = #{assessmentId}
    </delete>

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