<?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.hc.business.mapper.ZccmUserStatusMapper">

    <resultMap type="zccmuserStatus" id="UserStatusMap">
        <result property="statusId" column="status_id" jdbcType="INTEGER"/>
        <result property="userId" column="user_id" jdbcType="INTEGER"/>
        <result property="classId" column="class_id" jdbcType="INTEGER"/>
        <result property="orderId" column="order_id" jdbcType="INTEGER"/>
        <result property="status" column="status" jdbcType="INTEGER"/>
    </resultMap>

    <sql id="Base_Column_List">
        status_id,
           user_id,
           class_id,
           order_id,
           `status`
    </sql>

    <select id="queryDtoByUserId" resultType="com.hc.business.dto.ZccmUserStatusClassDto">
        SELECT status_id,
               class_config_id,
               class_name,
               need_paper,
               (bx_hours + xx_hours) as total_hours,
               apply_start_time,
               apply_end_time,
               study_start_time,
               study_end_time,
               paper_start_time,
               paper_end_time,
               cert_start_time,
               cert_end_time,
               user_id,
               paper_id,
               status
        FROM zccm_user_status as ut
                 INNER JOIN zccm_class_config cc on ut.class_id = cc.class_config_id
        WHERE user_id = #{userId}
    </select>

    <select id="queryByUserId" resultMap="UserStatusMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM zccm_user_status
        WHERE user_id = #{userId}
    </select>

    <select id="queryByClassIdAndUserId" resultMap="UserStatusMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM zccm_user_status
        WHERE class_id = #{classId} AND user_id = #{userId}
    </select>

    <select id="queryByClassId" resultType="com.hc.business.model.ZccmUser">
        SELECT
        u.*
        FROM zccm_user u
        INNER JOIN zccm_user_status us on u.user_id = us.user_id
        WHERE us.class_id = #{classId}
    </select>

</mapper>