<?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.zehong.system.mapper.TTrainStatMapper">

    <resultMap id="trainStatResult" type="TrainStat">
        <result property="trainManageId" column="train_manage_id"/>
        <result property="lessonName"    column="lesson_name"    />
        <result property="trainStartTime"    column="train_start_time"    />
        <result property="trainEndTime"    column="train_end_time"    />
        <result property="mustTestNum"    column="mustTestNum"    />
        <result property="finishTestNum"    column="finishTestNum"    />
    </resultMap>

    <resultMap id="trainStatDetailResult" type="TrainStatDetail">
        <result property="employedPeopleName" column="employed_people_name"/>
        <result property="enterpriseName" column="enterprise_name"/>
        <result property="realityTrainDuration" column="reality_train_duration"/>
        <result property="isComplete" column="isComplete"/>
    </resultMap>

    <select id="trainStatData" parameterType="TrainStat" resultMap="trainStatResult">
        SELECT
          manage.train_manage_id,
          manage.lesson_name,
          manage.train_start_time,
          manage.train_end_time,
          (SELECT count(*) FROM t_train_person WHERE train_manage_id = manage.train_manage_id) AS mustTestNum,
          (SELECT count(*) FROM t_train_person WHERE train_manage_id = manage.train_manage_id AND is_finish = '1') AS finishTestNum
        FROM
            t_train_manage manage
        <where>
            manage.is_del = '0'
            AND manage.train_status = '1'
            <if test="lessonName !='' and lessonName!= null">and manage.lesson_name like concat('%', #{lessonName}, '%')</if>
            <if test="publishBeginTime != null and publishEndTime">and manage.publish_time BETWEEN #{publishBeginTime} AND #{publishEndTime} </if>
        </where>
        ORDER BY manage.publish_time DESC
    </select>

    <select id="trainStatDetail" parameterType="Long" resultMap="trainStatDetailResult">
        SELECT
            sysu.nick_name AS employed_people_name,
            enterprise.enterprise_name,
            SEC_TO_TIME(person.reality_train_duration) AS reality_train_duration,
            (
            CASE person.is_finish
            WHEN '0' THEN
            '未完成'
            WHEN '1' THEN
            '完成'
            END
            ) AS isComplete
        FROM
           t_train_person person
        LEFT JOIN sys_user sysu ON sysu.user_id = person.train_person_id
        LEFT JOIN t_enterprise_info enterprise ON enterprise.enterprise_id = sysu.dept_id AND sysu.dept_id != '-2'
        <where>
            person.train_manage_id = #{trainManageId}
        </where>
    </select>


</mapper>
