<?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.suelec.trainclass.dao.TrainDao">

    <resultMap type="com.suelec.trainclass.pojo.TrainInfo" id="TrainInfo">
        <id     property="id"        column="id"/>
        <result property="title"      column="title" />
        <result property="content"        column="content"/>
        <result property="code"        column="CODE"/>
        <result property="offerType" column="offer_type"/>
        <result property="url"       column="cover_img_url"/>
        <result property="organizerName"            column="organizer_name"/>
        <result property="beginDate"           column="begin_date"/>
        <result property="endDate"     column="end_date"/>
        <result property="sortTitle"     column="sort_title"/>
        <result property="signedCount"     column="signed_count"/>
        <result property="learnedCount"     column="learned_count"/>
    </resultMap>


    <select id="selectTrainInfo" resultType="TrainInfo" parameterType="java.lang.String">
        SELECT
        c.id,
        c.title,
        c.content,
        c.CODE,
        c.offer_type,
        c.cover_img_url,
        c.organizer_name,
        c.begin_date,
        c.end_date,
        s.sort_title,
        c.signed_count,
        c.learned_count
  FROM
        t_training_class_collection co
        LEFT JOIN t_training_class c ON c.id = co.class_id
        LEFT JOIN t_class_sort_rela r ON r.class_id = c.id
        LEFT JOIN t_trianing_class_sort s ON s.id = r.class_sort_id
  WHERE co.user_id=#{userId} AND co.`status` = 1
    </select>


    <select id="selectTtrainClassList" resultType="TrainInfo">
       SELECT
            a.id,
            a.CODE,
            a.offer_type,
            a.title,
            a.short_title,
            a.training_target,
            a.content,
            a.cover_img_url,
            a.organizer_name,
            a.begin_date,
            a.end_date,
            a.signed_count,
            a.learned_count,
            d.sort_title
        FROM
            t_training_class a
            LEFT JOIN t_user_sign_training_class b ON a.id = b.class_id
            AND b.STATUS = 1
            LEFT JOIN t_class_sort_rela c ON a.id = c.class_id
            LEFT JOIN t_trianing_class_sort d ON c.class_sort_id = d.id
            AND d.`status` = 1
    </select>

    <!--<select id="selectTrainInfo" resultMap="TrainInfo" parameterType="java.lang.String">-->


    <!--</select>-->


</mapper>
