<?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="cn.iocoder.byzs.module.aicourse.dal.mysql.aiCourseConfig.AiCourseConfigMapper">


    <select id="selectAiCourseConfigPage" parameterType="cn.iocoder.byzs.module.aicourse.controller.admin.aiCourseConfig.vo.AiCourseConfigPageReqVO" resultType="cn.iocoder.byzs.module.aicourse.controller.admin.aiCourseConfig.vo.AiCourseConfigPageReqVO">
        SELECT cc.id, cc.cc_course_id as ccCourseId,c.tenant_id as tenantId,
                cc_quest_source as ccQuestSource,
                cc_quest_content as ccQuestContent,
                cc_quest_option as ccQuestOption,
                cc_ai_answer as ccAiAnswer,
                cc_answer as ccAnswer, cc.cc_quest_id as ccQuestId, cc.cc_time as ccTime, cc.cc_answer_judge as ccAnswerJudge,
               c.ac_name as courseName,
               cc_ai_quest_tip as ccAiQuestTip
        FROM ai_course_config cc
        LEFT JOIN ai_course c ON cc.cc_course_id = c.id
        <where>
                c.deleted = 0 and cc.deleted = 0
            <if test="ccCourseId != null and ccCourseId != ''">
                AND cc.cc_course_id  = #{ccCourseId}
            </if>
            <if test="ccQuestContent != null and ccQuestContent != ''">
                AND cc.cc_quest_content LIKE CONCAT('%', #{ccQuestContent}, '%')
            </if>
            <if test="ccTime != null and ccTime != ''">
                AND cc.cc_time LIKE CONCAT('%', #{ccTime}, '%')
            </if>
            <if test="ccAnswerJudge != null and ccAnswerJudge != ''">
                AND cc.cc_answer_judge = #{ccAnswerJudge}
            </if>
        </where>
        <if test="pageSize != null and pageSize != -1">
            limit #{pageNo}, #{pageSize}
        </if>
    </select>
    <select id="selectAiCourseConfigCount" parameterType="cn.iocoder.byzs.module.aicourse.controller.admin.aiCourseConfig.vo.AiCourseConfigPageReqVO" resultType="java.lang.Integer">
        SELECT count(*)
        FROM ai_course_config cc
        LEFT JOIN ai_course c ON cc.cc_course_id = c.id
        <where>
            c.deleted = 0 and cc.deleted = 0
            <if test="ccCourseId != null and ccCourseId != ''">
                AND cc.cc_course_id  = #{ccCourseId}
            </if>
            <if test="ccQuestContent != null and ccQuestContent != ''">
                AND cc.cc_quest_content LIKE CONCAT('%', #{ccQuestContent}, '%')
            </if>
            <if test="ccTime != null and ccTime != ''">
                AND cc.cc_time LIKE CONCAT('%', #{ccTime}, '%')
            </if>
            <if test="ccAnswerJudge != null and ccAnswerJudge != ''">
                AND cc.cc_answer_judge = #{ccAnswerJudge}
            </if>
        </where>
    </select>
    <select id="getAiCourseConfigQuestionByCourseIds" parameterType="java.util.List"
            resultType="cn.iocoder.byzs.module.aicourse.controller.admin.aiCourseConfig.vo.AiCourseConfigRespVO">
        SELECT cc.id, cc.cc_course_id as ccCourseId,c.tenant_id as tenantId,
                cc_quest_source as ccQuestSource,
                cc_quest_content as ccQuestContent,
                cc_quest_option as ccQuestOption,
                cc_ai_answer as ccAiAnswer,
                cc_answer as ccAnswer, cc.cc_quest_id as ccQuestId, cc.cc_time as ccTime, cc.cc_answer_judge as ccAnswerJudge,
               c.ac_name as courseName,
               cc_ai_quest_tip as ccAiQuestTip
        FROM ai_course_config cc
        LEFT JOIN ai_course c ON cc.cc_course_id = c.id
        WHERE cc.cc_course_id IN
        <foreach collection="ccCourseIds" item="courseId" open="(" close=")" separator=",">
            #{courseId}
        </foreach>
        AND c.deleted = 0 and cc.deleted = 0
    </select>
</mapper>