<?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.system.mapper.PersonResourcesMapper">

    <resultMap type="PersonResources" id="PersonResourcesResult">
        <result property="resourcesId"    column="resources_id"    />
        <result property="resourcesName"    column="resources_name"    />
        <result property="sourceId"    column="source_id"    />
        <result property="category"    column="category"    />
        <result property="chapterId"    column="chapter_id"    />
        <result property="edition"    column="edition"    />
        <result property="knowledgeBasicId"    column="knowledge_basic_id"    />
        <result property="resourcesUrl"    column="resources_url"    />
        <result property="type"    column="type"    />
        <result property="linkWay"    column="link_way"    />
        <result property="bookId"    column="book_id"    />
        <result property="schoolId"    column="school_id"    />
        <result property="subjectId"    column="subject_id"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="province"    column="province"    />
        <result property="createId"    column="create_id"    />
        <result property="city"    column="city"    />
        <result property="createTime"    column="create_time"    />
        <result property="county"    column="county"    />
        <result property="remark"    column="remark"    />
        <result property="fileSize"    column="file_size"    />
        <result property="coursewareType"    column="courseware_type"    />
        <result property="videoId"    column="video_id"    />
        <result property="updateTime"    column="update_time"    />
        
    </resultMap>

    <sql id="selectPersonResourcesVo">
        select resources_id, resources_name, source_id, category, courseware_type, chapter_id, edition, knowledge_basic_id, resources_url, type, link_way, book_id, school_id, subject_id, del_flag, province, create_id, city, create_time, county, remark, file_size from test_person_resources
    </sql>

    <select id="selectPersonResourcesList" parameterType="PersonResources" resultMap="PersonResourcesResult">
        <include refid="selectPersonResourcesVo"/>
        where 1=1
            <if test="resourcesName != null  and resourcesName != ''"> and resources_name like concat('%', #{resourcesName}, '%')</if>
            <if test="sourceId != null  and sourceId != ''"> and source_id = #{sourceId}</if>
            <if test="category != null  and category != ''"> and category = #{category}</if>
            <if test="chapterId != null "> and chapter_id = #{chapterId}</if>
            <if test="edition != null "> and edition = #{edition}</if>
            <if test="knowledgeBasicId != null "> and knowledge_basic_id = #{knowledgeBasicId}</if>
            <if test="resourcesUrl != null  and resourcesUrl != ''"> and resources_url = #{resourcesUrl}</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="linkWay != null  and linkWay != ''"> and link_way = #{linkWay}</if>
            <if test="bookId != null "> and book_id = #{bookId}</if>
            <if test="schoolId != null "> and school_id = #{schoolId}</if>
            <if test="subjectId != null "> and subject_id = #{subjectId}</if>
            <if test="delFlag != null  and delFlag != ''"> and del_flag = #{delFlag}</if>
            <if test="province != null "> and province = #{province}</if>
            <if test="createId != null "> and create_id = #{createId}</if>
            <if test="city != null "> and city = #{city}</if>
            <if test="county != null "> and county = #{county}</if>
            <if test="fileSize != null "> and file_size = #{fileSize}</if>
            <if test="coursewareType != null  and coursewareType != '' "> and courseware_type = #{coursewareType}</if>
            <if test="sourceIds != null and sourceIds.size()>0 ">
                and source_id in <foreach item="id" collection="sourceIds" open="(" separator="," close=")">#{id}</foreach>
            </if>
        order by resources_id desc
    </select>

    <select id="selectPersonResourcesById" parameterType="Long" resultMap="PersonResourcesResult">
        <include refid="selectPersonResourcesVo"/>
        where resources_id = #{resourcesId}
    </select>

    <insert id="insertPersonResources" parameterType="PersonResources" useGeneratedKeys="true" keyProperty="resourcesId">
        insert into test_person_resources
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="resourcesName != null and resourcesName != ''">resources_name,</if>
            <if test="sourceId != null">source_id,</if>
            <if test="category != null and category != ''">category,</if>
            <if test="chapterId != null">chapter_id,</if>
            <if test="edition != null">edition,</if>
            <if test="knowledgeBasicId != null">knowledge_basic_id,</if>
            <if test="resourcesUrl != null">resources_url,</if>
            <if test="type != null">type,</if>
            <if test="linkWay != null">link_way,</if>
            <if test="bookId != null">book_id,</if>
            <if test="schoolId != null">school_id,</if>
            <if test="subjectId != null">subject_id,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="province != null">province,</if>
            <if test="createId != null">create_id,</if>
            <if test="city != null">city,</if>
            <if test="createTime != null">create_time,</if>
            <if test="county != null">county,</if>
            <if test="remark != null">remark,</if>
            <if test="fileSize != null">file_size,</if>
            <if test= "coursewareType != null  and coursewareType != '' ">courseware_type,</if>
            <if test="videoId != null">video_id,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="resourcesName != null and resourcesName != ''">#{resourcesName},</if>
            <if test="sourceId != null">#{sourceId},</if>
            <if test="category != null and category != ''">#{category},</if>
            <if test="chapterId != null">#{chapterId},</if>
            <if test="edition != null">#{edition},</if>
            <if test="knowledgeBasicId != null">#{knowledgeBasicId},</if>
            <if test="resourcesUrl != null">#{resourcesUrl},</if>
            <if test="type != null">#{type},</if>
            <if test="linkWay != null">#{linkWay},</if>
            <if test="bookId != null">#{bookId},</if>
            <if test="schoolId != null">#{schoolId},</if>
            <if test="subjectId != null">#{subjectId},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="province != null">#{province},</if>
            <if test="createId != null">#{createId},</if>
            <if test="city != null">#{city},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="county != null">#{county},</if>
            <if test="remark != null">#{remark},</if>
            <if test="fileSize != null">#{fileSize},</if>
            <if test="coursewareType != null  and coursewareType != '' ">#{coursewareType},</if>
            <if test="videoId != null">#{videoId},</if>
            <if test="updateTime != null">#{updateTime},</if>
            
        </trim>
    </insert>

    <update id="updatePersonResources" parameterType="PersonResources">
        update test_person_resources
        <trim prefix="SET" suffixOverrides=",">
            <if test="resourcesName != null and resourcesName != ''">resources_name = #{resourcesName},</if>
            <if test="sourceId != null">source_id = #{sourceId},</if>
            <if test="category != null and category != ''">category = #{category},</if>
            <if test="chapterId != null">chapter_id = #{chapterId},</if>
            <if test="edition != null">edition = #{edition},</if>
            <if test="knowledgeBasicId != null">knowledge_basic_id = #{knowledgeBasicId},</if>
            <if test="resourcesUrl != null">resources_url = #{resourcesUrl},</if>
            <if test="type != null">type = #{type},</if>
            <if test="linkWay != null">link_way = #{linkWay},</if>
            <if test="bookId != null">book_id = #{bookId},</if>
            <if test="schoolId != null">school_id = #{schoolId},</if>
            <if test="subjectId != null">subject_id = #{subjectId},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="province != null">province = #{province},</if>
            <if test="createId != null">create_id = #{createId},</if>
            <if test="city != null">city = #{city},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="county != null">county = #{county},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="fileSize != null">file_size = #{fileSize},</if>
            <if test="coursewareType != null  and coursewareType != '' ">courseware_type = #{coursewareType},</if>
            <if test="videoId != null">video_id = #{videoId},</if>
            <if test="updateTime != null">update_time=#{updateTime},</if>
            
        </trim>
        where resources_id = #{resourcesId}
    </update>

    <delete id="deletePersonResourcesById" parameterType="Long">
        delete from test_person_resources where resources_id = #{resourcesId}
    </delete>

    <delete id="deletePersonResourcesByIds" parameterType="String">
        delete from test_person_resources where resources_id in
        <foreach item="resourcesId" collection="array" open="(" separator="," close=")">
            #{resourcesId}
        </foreach>
    </delete>
</mapper>