<?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.zhongzheng.modules.course.mapper.MajorLabelMapper">

    <resultMap type="com.zhongzheng.modules.course.domain.MajorLabel" id="MajorLabelResult">
        <result property="id" column="id"/>
        <result property="remark" column="remark"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="labelName" column="label_name"/>
        <result property="status" column="status"/>
        <result property="encoder" column="encoder"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.course.vo.MajorLabelVo" id="MajorLabelVoResult">
        <result property="id" column="id"/>
        <result property="remark" column="remark"/>
        <result property="labelName" column="label_name"/>
        <result property="status" column="status"/>
        <result property="encoder" column="encoder"/>
        <result property="num" column="num"/>
        <result property="categoryName" column="category_name"/>
        <result property="majorId" column="major_id"/>
    </resultMap>

    <select id="queryList" parameterType="com.zhongzheng.modules.course.bo.MajorLabelQueryBo"  resultMap="MajorLabelVoResult">
        SELECT
            l.*,
            (SELECT COUNT( 1 ) FROM major r WHERE l.id = r.label_id ) AS num
        FROM
            major_label l
        where 1=1
        <if test="status != null and status.size()!=0 ">
            AND l.status in
            <foreach collection="status" item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="encoder != null and encoder != ''">
            AND l.encoder = #{encoder}
        </if>
        <if test="labelName != null and labelName != ''">
            AND l.label_name = #{labelName}
        </if>

    </select>

    <select id="listMajor" parameterType="com.zhongzheng.modules.course.bo.MajorLabelQueryBo"  resultMap="MajorLabelVoResult">
        SELECT
        l.*,
        m.category_name,
        m.id as major_id
        FROM
        major_label l
        LEFT JOIN major m ON l.id = m.label_id
        WHERE
        1 = 1
        AND l.status =1
        <if test="status != null and status.size()!=0 ">
            AND l.status in
            <foreach collection="status" item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="encoder != null and encoder != ''">
            AND l.encoder = #{encoder}
        </if>
        <if test="labelName != null and labelName != ''">
            AND l.label_name = #{labelName}
        </if>
        <if test="id != null and id != ''">
            AND l.id = #{id}
        </if>
    </select>
</mapper>
