<?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.aiCourse.WebAiCourseMapper">

    <select id="getTypeByThemeId"
            parameterType="cn.iocoder.byzs.module.web.controller.admin.aiCourse.vo.WebAiCourseTypeVO"
            resultType="cn.iocoder.byzs.module.web.controller.admin.aiCourse.vo.WebAiCourseTypeVO">
        SELECT
            ct.id as id,
            ct.ct_type as ctType,
            ct.ct_parent_id as ctParentId,
            ct.ct_type_image as ctTypeImage,
            ct.ct_type_sort as ctTypeSort,
            COUNT(ct.id) + SUM(CASE WHEN ac.ac_label = 2 THEN 2 ELSE 0 END) AS sectionCount
        FROM
            ai_course_type ct
                LEFT JOIN ai_course ac ON ct.id = ac.ac_type
        WHERE
            ct.deleted = 0 AND ac.deleted = 0 AND ac.ac_status = 0 AND
            ct.ct_parent_id = #{ctParentId}
        GROUP BY
            id, ctType, ctParentId, ctTypeImage, ctTypeSort
        ORDER BY
            ctTypeSort;
    </select>
</mapper>