<?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.yudao.module.knowledge.mapper.TTrainMaterialMapper">

    <resultMap type="cn.iocoder.yudao.module.knowledge.entity.TTrainMaterial" id="tTrainMaterialMap">
            <result property="id" column="id"/>
            <result property="order" column="order"/>
            <result property="coursewareId" column="courseware_id"/>
            <result property="teachCode" column="teach_code"/>
    </resultMap>

    <!-- 用于select查询公用抽取的列 -->
    <sql id="columns">
        id,order,courseware_id,teach_code
    </sql>
    <select id="findList" resultMap="tTrainMaterialMap">
        select
        <include refid="columns"/>
        from t_train_material
        <where>
                    <if test="id != null">
                        id = #{id}
                    </if>
                    <if test="order != null">
                        order = #{order}
                    </if>
                    <if test="coursewareId != null">
                        courseware_id = #{coursewareId}
                    </if>
                    <if test="teachCode != null and teachCode != ''">
                            teach_code = #{teachCode}
                    </if>
        </where>
    </select>

    <select id="getMaterials" resultMap="tTrainMaterialMap">
        select
        <include refid="columns"/>
        from t_train_material
        <where>
            <if test="params.coursewareId != null">
                courseware_id = #{params.coursewareId}
            </if>
        </where>
    </select>

    <select id="getOneByTrainId" resultType="cn.iocoder.yudao.module.knowledge.entity.TTrainMaterial">
        select *
        from t_train_material
        where train_id = #{trainId}
         and deleted = 0
    </select>

    <update id="deleteByTrainId"
              parameterType="java.lang.Long">
        update t_train_material set deleted = 1 where train_id = #{id}
    </update>
</mapper>
