<?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.srs.stureg.mapper.SrsStuTodoMapper">
    
    <resultMap type="SrsStuTodo" id="SrsStuTodoResult">
        <result property="id"    column="id"    />
        <result property="stuNo"    column="stu_no"    />
        <result property="taskId"    column="task_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="status"    column="status"    />
        <result property="ksh"    column="ksh"    />
        <result property="taskCode"    column="task_code"    />
    </resultMap>

    <sql id="selectSrsStuTodoVo">
        select id,ksh,task_code, stu_no, task_id, create_time, status from srs_stu_todo
    </sql>


    <select id="selectSrsStuTodoListJoin" parameterType="SrsStuTodo" resultType="com.srs.stureg.domain.VO.SrsStuTodoVo">
        select a.id,a.stu_no,a.ksh,c.`XSXM` as stu_name,a.task_id,b.project_name as task_name,a.`status` ,
        b.start_time,b.end_time,b.url,b.row_rank
        from srs_stu_todo as a
        left join srs_task_list as b on a.task_code = b.task_code
        left join srs_stu_reg as c on a.ksh = c.KSH
        <where>
            <if test="stuNo != null  and stuNo != ''"> and a.stu_no = #{stuNo}</if>
            <if test="ksh != null  and ksh != ''"> and a.ksh = #{ksh}</if>
            <if test="taskId != null "> and a.task_id = #{taskId}</if>
            <if test="status != null  and status != ''"> and a.status = #{status}</if>
        </where>
        order by b.row_rank asc
    </select>

    <select id="selectSrsStuTodoList" parameterType="SrsStuTodo" resultMap="SrsStuTodoResult">
        <include refid="selectSrsStuTodoVo"/>
        <where>
            <if test="stuNo != null  and stuNo != ''"> and stu_no = #{stuNo}</if>
            <if test="taskId != null "> and task_id = #{taskId}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="ksh != null  and ksh != ''"> and ksh = #{ksh}</if>
        </where>
    </select>
    
    <select id="selectSrsStuTodoById" parameterType="Long" resultMap="SrsStuTodoResult">
        <include refid="selectSrsStuTodoVo"/>
        where id = #{id}
    </select>

    <insert id="insertSrsStuTodo" parameterType="SrsStuTodo" useGeneratedKeys="true" keyProperty="id">
        insert into srs_stu_todo
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="stuNo != null">stu_no,</if>
            <if test="taskId != null">task_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="status != null">status,</if>
            <if test="ksh != null">ksh,</if>
            <if test="taskCode != null">task_code,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="stuNo != null">#{stuNo},</if>
            <if test="taskId != null">#{taskId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="status != null">#{status},</if>
            <if test="ksh != null">#{ksh},</if>
            <if test="taskCode != null">#{taskCode},</if>
         </trim>
    </insert>

    <update id="updateSrsStuTodo" parameterType="SrsStuTodo">
        update srs_stu_todo
        <trim prefix="SET" suffixOverrides=",">
            <if test="stuNo != null">stu_no = #{stuNo},</if>
            <if test="taskId != null">task_id = #{taskId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="status != null">status = #{status},</if>
            <if test="ksh != null">ksh = #{ksh},</if>
            <if test="taskCode != null">task_code = #{taskCode},</if>
        </trim>
        where id = #{id}
    </update>


    <delete id="deleteSrsStuTodoById" parameterType="Long">
        delete from srs_stu_todo where id = #{id}
    </delete>

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