<?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.xhkjedu.sapi.mapper.research.ResearchMapper">

    <!-- 获取所有教研 -->
    <select id="listResearchs" resultType="com.xhkjedu.sapi.vo.research.ResearchVo">
        SELECT r.researchid,r.researchname,r.researchcover,r.duration,mp4code,r.filesize,r.starttime,r.stoptime,
        r.createid,r.createtime,u.username AS createname,r.readnum,r.researchpath
        FROM t_research r LEFT JOIN t_user u ON r.createid=u.userid
        WHERE r.schoolid=#{schoolid}
        <if test="rorder=='stoptime'">ORDER BY r.stoptime DESC</if>
        <if test="rorder=='readnum'">ORDER BY r.readnum DESC</if>
        <if test="rorder=='createtime'">ORDER BY r.createtime DESC</if>
    </select>

    <!-- 根据id获取教研详细信息 -->
    <select id="getResearchById" resultType="com.xhkjedu.sapi.model.research.TResearch">
        SELECT r.researchid,r.researchname,r.researchcontent,r.researchpath,r.researchcover,r.duration,r.filesize,
        r.starttime,r.stoptime,r.readnum,r.mp4code,
        r.createid,r.createtime,u.username AS createname
        FROM t_research r LEFT JOIN t_user u ON r.createid=u.userid
        WHERE r.researchid=#{researchid} limit 1
    </select>

    <update id="updateReadnum">
        UPDATE t_research SET readnum = readnum+1 WHERE researchid=#{researchid}
    </update>

    <!--修改教研信息-->
    <update id="updateResourch">
        UPDATE t_research SET researchname = #{research.researchname},starttime = #{research.starttime},stoptime =  #{research.stoptime},
        researchcontent = #{research.researchcontent}
        <if test="research.researchcover!='' and research.researchcover!=null">
            ,researchcover=#{research.researchcover}
        </if>
        <if test="research.researchpath!='' and research.researchpath!=null">
            ,researchpath=#{research.researchpath},duration=#{research.duration},filesize=#{research.filesize}
        </if>
         WHERE researchid = #{research.researchid}
    </update>

    <!--修改制定字段-->
    <update id="updateResourceMp4code">
        UPDATE t_research SET researchpath=#{research.researchpath},mp4code=#{research.mp4code} WHERE researchid=#{research.researchid}
    </update>
    <!--获取教研文件-->
    <select id="getResarchpath" resultType="com.xhkjedu.sapi.model.research.TResearch">
        SELECT researchcover,researchpath FROM t_research WHERE researchid=#{researchid}
    </select>
</mapper>
