<?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="com.ruoyi.web.modules.technology.mapper.BizOnlineTrainingCourseMapper">

    <sql id="publishedVideoWhere">
        resource_type = '004008'
        and publish_status = 1
        and del_flag = '0'
    </sql>

    <resultMap type="com.ruoyi.web.modules.technology.domain.OnlineTrainingCourseRow" id="OnlineTrainingCourseRowResult">
        <id     property="id"             column="id"/>
        <result property="resourceName"   column="resource_name"/>
        <result property="introduction"   column="introduction"/>
        <result property="courseTopic"    column="course_topic"/>
        <result property="videoFileUrl"   column="video_file_url"/>
        <result property="videoFilePath"  column="video_file_path"/>
        <result property="coverFileUrl"   column="cover_file_url"/>
        <result property="coverFilePath"  column="cover_file_path"/>
        <result property="publishTime"    column="publish_time"/>
        <result property="createTime"     column="create_time"/>
        <result property="updateTime"     column="update_time"/>
    </resultMap>

    <select id="selectOnlineTrainingCourseList" parameterType="com.ruoyi.web.modules.technology.domain.OnlineTrainingCourseQuery"
            resultMap="OnlineTrainingCourseRowResult">
        select id, resource_name, introduction, course_topic, video_file_path, create_time
        from biz_tech_resource
        <where>
            <include refid="publishedVideoWhere"/>
            <if test="courseTitle != null and courseTitle != ''">
                and resource_name like concat('%', #{courseTitle}, '%')
            </if>
            <if test="courseTopic != null and courseTopic != ''">
                and course_topic = #{courseTopic}
            </if>
        </where>
        order by create_time desc, id desc
    </select>

    <select id="selectOnlineTrainingCourseById" parameterType="long" resultMap="OnlineTrainingCourseRowResult">
        select id, resource_name, introduction, course_topic,
               video_file_url, video_file_path, cover_file_url, cover_file_path,
               publish_time, create_time, update_time
        from biz_tech_resource
        where id = #{id}
          and <include refid="publishedVideoWhere"/>
    </select>

    <resultMap type="com.ruoyi.web.modules.category.domain.vo.InformationCategoryItemVo" id="CourseTopicCategoryResult">
        <result property="code" column="category_code"/>
        <result property="name" column="category_name"/>
    </resultMap>

    <select id="selectDistinctCourseTopics" resultMap="CourseTopicCategoryResult">
        select category_code, category_name
        from biz_information_category
        where del_flag = '0'
          and parent_code = '005'
          and category_type = '8'
          and category_code is not null
          and category_code != ''
        order by category_code asc
    </select>
</mapper>
