<?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.zcxk.evaluation.dao.EvaluationResultTaskMapper" >


    <resultMap id="evaluationResultTaskDetailsVo" type="com.zcxk.evaluation.vo.EvaluationResultTaskDetailsVo">
        <result property="resultId" column="resultId" jdbcType="INTEGER"/>
        <result property="tenantId" column="TENANT_ID" jdbcType="INTEGER"/>
        <result property="companyOrgId" column="COMPANY_ORG_ID" jdbcType="INTEGER"/>
        <result property="totalCount" column="TOTAL_COUNT" jdbcType="INTEGER"/>
        <result property="completeCount" column="COMPLETE_COUNT" jdbcType="INTEGER"/>
        <result property="noCompleteCount" column="NO_COMPLETE_COUNT" jdbcType="INTEGER"/>
        <result property="delayCompleteCount" column="DELAY_COMPLETE_COUNT" jdbcType="INTEGER"/>
        <result property="completionRate" column="COMPLETION_RATE" jdbcType="INTEGER"/>
        <result property="delayRate" column="DELAY_RATE" jdbcType="INTEGER"/>
        <result property="performanceScore" column="performanceScore" jdbcType="INTEGER"/>
        <result property="evaluationGrade" column="EVALUATION_GRADE" jdbcType="INTEGER"/>
        <result property="year" column="YEAR" jdbcType="INTEGER"/>
        <result property="month" column="MONTH" jdbcType="INTEGER"/>
        <result property="cycle" column="CYCLE" jdbcType="INTEGER"/>
        <result property="delayCompleteCount" column="DELAY_COMPLETE_COUNT" jdbcType="INTEGER"/>
        <result property="dateStart" column="DATE_START" jdbcType="INTEGER"/>
        <result property="dateEnd" column="DATE_END" jdbcType="INTEGER"/>
        <collection property="detailsVoList"  resultMap="detailsVoMap"></collection>
    </resultMap>

    <resultMap id="detailsVoMap" type="com.zcxk.evaluation.vo.EvaluationResultDetailsVo">
        <result property="resultDetailsId" column="resultDetailsId" jdbcType="INTEGER"/>
        <result property="itemName" column="itemName" jdbcType="INTEGER"/>
        <result property="itemScore" column="itemScore" jdbcType="INTEGER"/>
        <result property="score" column="score" jdbcType="INTEGER"/>
        <result property="remarks" column="remarks" jdbcType="INTEGER"/>
    </resultMap>


    <select id="findResultTaskDetail" resultMap="evaluationResultTaskDetailsVo">
        select
            r.id as "resultId",r.`YEAR`, r.`MONTH`,r.`VALUE` as "performanceScore",r.EVALUATION_GRADE,r.COMPANY_ORG_ID,r.TENANT_ID,r.CYCLE,r.DATE_START,DATE_END,
            t.TOTAL_COUNT,t.COMPLETE_COUNT,t.NO_COMPLETE_COUNT,t.DELAY_COMPLETE_COUNT,t.COMPLETION_RATE,t.DELAY_RATE,
            d.ID as "resultDetailsId", d.`VALUE` as "score",
            i.`NAME` as "itemName",i.`VALUE` as "itemScore",i.REMARKS
        from
            sc_evaluation_result r
        INNER JOIN sc_evaluation_result_task t     on t.EVALUATION_RESULT_ID = r.ID
        INNER JOIN sc_evaluation_result_details d  on d.EVALUATION_RESULT_ID = r.ID
        INNER JOIN sc_evaluation_item i            on i.id = d.EVALUATION_ITEM_ID
        where
              r.id = #{evaluationResultId} and r.status = 1 and t.status =1 and d.status = 1 and i.status = 1
    </select>

    <insert id="insertEvaluationResultTask">
        insert sc_evaluation_result_task (TENANT_ID,EVALUATION_RESULT_ID,TOTAL_COUNT,COMPLETE_COUNT,NO_COMPLETE_COUNT,DELAY_COMPLETE_COUNT,COMPLETION_RATE
                ,DELAY_RATE,`STATUS`,DATE_CREATE,CREATE_BY,DATE_UPDATE,UPDATE_BY)
        values
            (#{tenantId}, #{evaluationResultId}, #{totalCount}, #{completeCount}, #{noCompleteCount},
        #{delayCompleteCount}, #{completionRate}, #{delayRate}, #{status}, #{dateCreate},
        #{createBy}, #{dateUpdate}, #{updateBy})
    </insert>
</mapper>