<?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.blockly.dal.mysql.blockly.BlocklyMapper">

    <sql id="selectBlocklyList">
        FROM blockly_course c
        LEFT JOIN blockly_course_type ct ON c.bc_type = ct.id
        <where>
            c.deleted = 0
            <if test="bcName != null and bcName != ''">
                AND c.bc_name LIKE CONCAT('%', #{bcName}, '%')
            </if>
            <if test="bcStatus!= null and bcStatus!= ''">
                AND c.bc_status = #{bcStatus}
            </if>
            <if test="bcType!= null and bcType!= ''">
                AND c.bc_type = #{bcType}
            </if>
            <if test="bcLabel!= null and bcLabel!= ''">
                AND c.bc_label = #{bcLabel}
            </if>
            <if test="bcContentType!= null and bcContentType!= ''">
                AND c.bc_content_type = #{bcContentType}
            </if>
            <if test="bcIsInspect!= null and bcIsInspect!= ''">
                AND c.bc_is_inspect = #{bcIsInspect}
            </if>
        </where>
        ORDER BY ct.ct_type_sort, c.bc_order
    </sql>
    <select id="selectBlocklyPageCount" parameterType="cn.iocoder.byzs.module.blockly.controller.admin.blockly.vo.BlocklyPageReqVO"
            resultType="int">
        SELECT COUNT(*)
        <include refid="selectBlocklyList"/>
    </select>
    <select id="selectBlocklyPage" parameterType="cn.iocoder.byzs.module.blockly.controller.admin.blockly.vo.BlocklyPageReqVO"
            resultType="cn.iocoder.byzs.module.blockly.controller.admin.blockly.vo.BlocklyPageReqVO">
        SELECT c.tenant_id as tenantId,c.id, c.bc_name bcName,
               c.bc_content_type bcContentType, c.bc_content bcContent,
               c.blockly_info blocklyInfo, c.blockly_user_image blocklyUserImage,
               c.blockly_tile_size blocklyTileSize, c.blockly_background blocklyBackground,
               c.blockly_walkable_points blocklyWalkablePoints,
               c.blockly_special_blocks blocklySpecialBlocks,
               c.bc_is_inspect bcIsInspect, c.bc_label bcLabel, c.bc_order bcOrder, c.bc_status bcStatus,
               ct.ct_type bcTypeName
        <include refid="selectBlocklyList"/>
        <if test="pageSize != null and pageSize != -1">
            limit #{pageNo}, #{pageSize}
        </if>
    </select>
    <select id="selectBlocklyList" parameterType="cn.iocoder.byzs.module.blockly.controller.admin.blockly.vo.BlocklyPageReqVO"
            resultType="cn.iocoder.byzs.module.blockly.controller.admin.blockly.vo.BlocklyPageReqVO">
        SELECT c.tenant_id as tenantId,c.id, c.bc_name bcName, c.bc_type bcType,
               c.bc_content_type bcContentType, c.bc_content bcContent,
               c.blockly_info blocklyInfo, c.blockly_user_image blocklyUserImage,
               c.blockly_tile_size blocklyTileSize, c.blockly_background blocklyBackground,
               c.blockly_walkable_points blocklyWalkablePoints,
               c.blockly_special_blocks blocklySpecialBlocks,
               c.bc_is_inspect bcIsInspect, c.bc_label bcLabel, c.bc_order bcOrder, c.bc_status bcStatus,
               ct.ct_type bcTypeName, c.blockly_route_list blocklyRouteList
        <include refid="selectBlocklyList"/>
    </select>
</mapper>