<?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.blocklyprogress.WebBlocklyProgressMapper">

    <select id="selectProgres" parameterType="cn.iocoder.byzs.module.web.controller.admin.blocklyprogress.vo.WebBlocklyProgressDO"
            resultType="cn.iocoder.byzs.module.web.controller.admin.blocklyprogress.vo.WebBlocklyProgressDTO">
        SELECT
            u.nickname as userName,
            CONCAT(LPAD(fl.ct_type_sort, 2, '0'), ' ', fl.ct_type) as kcflName,
            c.course_name as courseName,
            rp.brp_progress as progress,
            rp.brp_type as progressType
        FROM blockly_report_progress rp
        LEFT JOIN blockly_course_type fl ON rp.brp_ct_id =fl.id
        LEFT JOIN blockly_course c ON rp.brp_course_id = c.id
        LEFT JOIN system_users u ON rp.brp_user_id = u.id
        <where>
            <if test="brpUserId != null">
                and rp.brp_user_id = #{brpUserId}
            </if>
            <if test="brpZtId != null">
                AND rp.brp_zt_id = #{brpZtId}
            </if>
        </where>
    </select>

    <select id="getBlocklyProgressByTypeId"
            parameterType="cn.iocoder.byzs.module.web.controller.admin.blocklyprogress.vo.WebBlocklyProgressDO"
            resultType="cn.iocoder.byzs.module.web.controller.admin.blocklyprogress.vo.WebBlocklyProgressDO">

        SELECT
            brp_course_id AS brpCourseId,
            COALESCE(brp_progress / 100, 0) AS brpProgress
        FROM blockly_report_progress
        WHERE
            brp_ct_id = #{brpCtId}
          AND brp_user_id = #{brpUserId}
          AND brp_course_config_id IS NULL
    </select>

    <select id="getBlocklyProgressByThemeId"
            parameterType="cn.iocoder.byzs.module.web.controller.admin.blocklyprogress.vo.WebBlocklyProgressDO"
            resultType="cn.iocoder.byzs.module.web.controller.admin.blocklyprogress.vo.WebBlocklyProgressDO">
        SELECT
            brp_ct_id AS brpCtId,
            COALESCE(SUM(brp_progress) / 100, 0) AS brpProgress
        FROM blockly_report_progress
        WHERE
            brp_zt_id = #{brpZtId}
          AND brp_user_id = #{brpUserId}
          AND brp_course_config_id IS NULL
        GROUP BY brp_ct_id
    </select>
</mapper>