<?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.ZccmQrAccessoryMapper">

    <resultMap type="zccmQrAccessory" id="ZccmQrAccessoryMap">
        <result property="qrId" column="qr_id" jdbcType="INTEGER"/>
        <result property="courseId" column="course_id" jdbcType="INTEGER"/>
        <result property="qrIndex" column="qr_index" jdbcType="INTEGER"/>
        <result property="qrType" column="qr_type" jdbcType="INTEGER"/>
        <result property="chapterId" column="chapter_id" jdbcType="INTEGER"/>
        <result property="fileName" column="file_name" jdbcType="VARCHAR"/>
        <result property="fileUrl" column="file_url" jdbcType="VARCHAR"/>
        <result property="qrUrl" column="qr_url" jdbcType="VARCHAR"/>
    </resultMap>
    
    <sql id ="Base_Column_List">
           qr_id,
           course_id,
           qr_index,
           qr_type,
           chapter_id,
           file_name,
           file_url,
           qr_url,
    </sql>

    <select id="queryByAll" resultType="com.hc.business.dto.ZccmQrAccessoryDto">
        SELECT cc.*,c.course_name as courseName,d.chapter_name chapterName
        FROM zccm_qr_accessory as cc
        Left JOIN zccm_course as c on cc.course_id = c.course_id
        Left JOIN zccm_course_chapter d on cc.chapter_id = d.course_chapter_id
        <where>
            <if test="courseId!=null">
                AND cc.course_id = #{courseId}
            </if>
            <if test="qrIndex!=null">
                AND cc.qr_index = #{qrIndex}
            </if>
            <if test="chapterId!=null">
                AND cc.chapter_id = #{chapterId}
            </if>
            <if test="qrType!=null">
                AND cc.qr_type = #{qrType}
            </if>
            <if test="fileName!=null and fileName!=''">
                AND cc.file_name LIKE "%"#{fileName}"%"
            </if>
        </where>
        ORDER BY cc.chapter_id,course_id,qr_index
    </select>
</mapper>
