<?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.web.dal.mysql.aiCourseProgress.WebAiCourseProgressMapper">


    <select id="selectProgres" parameterType="cn.iocoder.byzs.module.web.controller.admin.aiCourseProgress.vo.WebAiCourseProgressDO"
            resultType="cn.iocoder.byzs.module.web.controller.admin.aiCourseProgress.vo.WebAiCourseProgressDTO">
        SELECT
            u.nickname as userName,
            CONCAT(LPAD(fl.ct_type_sort, 2, '0'), ' ', fl.ct_type) as kcflName,
            c.course_name as courseName,
            rp.arp_progress as progress,
            rp.arp_type as progressType
        FROM ai_report_progress rpt_id =fl.id
        LEFT JOIN ai_course c ON rp.arp_course_i
        LEFT JOIN ai_course_type fl ON rp.arp_cd = c.id
        LEFT JOIN system_users u ON rp.arp_user_id = u.id
        <where>
            <if test="brpUserId != null">
                and rp.arp_user_id = #{brpUserId}
            </if>
            <if test="brpZtId != null">
                AND rp.arp_zt_id = #{brpZtId}
            </if>
        </where>
    </select>

    <select id="getAiCourseProgressByTypeId"
            parameterType="cn.iocoder.byzs.module.web.controller.admin.aiCourseProgress.vo.WebAiCourseProgressDO"
            resultType="cn.iocoder.byzs.module.web.controller.admin.aiCourseProgress.vo.WebAiCourseProgressDO">

        SELECT
            arp_course_id AS arpCourseId,
            COALESCE(arp_progress / 100, 0) AS arpProgress
        FROM ai_report_progress
        WHERE
            arp_ct_id = #{arpCtId}
          AND arp_user_id = #{arpUserId}
          AND arp_course_config_id IS NULL
    </select>

    <select id="getAiCourseProgressByThemeId"
            parameterType="cn.iocoder.byzs.module.web.controller.admin.aiCourseProgress.vo.WebAiCourseProgressDO"
            resultType="cn.iocoder.byzs.module.web.controller.admin.aiCourseProgress.vo.WebAiCourseProgressDO">
        SELECT
            arp_ct_id AS arpCtId,
            COALESCE(SUM(arp_progress) / 100, 0) AS arpProgress
        FROM ai_report_progress
        WHERE
            arp_zt_id = #{arpZtId}
          AND arp_user_id = #{arpUserId}
          AND arp_course_config_id IS NULL
        GROUP BY arp_ct_id
    </select>
</mapper>