<?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.workstudy.mapper.QgzxMonthAssessMapper">

    <resultMap type="QgzxMonthAssess" id="QgzxMonthAssessResult">
        <result property="id" column="id"/>
        <result property="stuPostId" column="stu_post_id"/>
        <result property="assess" column="assess"/>
        <result property="submitTime" column="submit_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectQgzxMonthAssessVo">
        select id, stu_post_id, assess, submit_time, remark
        from qgzx_month_assess
    </sql>

    <select id="selectQgzxMonthAssessList" parameterType="QgzxMonthAssess" resultMap="QgzxMonthAssessResult">
        <include refid="selectQgzxMonthAssessVo"/>
        <where>
            <if test="stuPostId != null ">and stu_post_id = #{stuPostId}</if>
            <if test="assess != null  and assess != ''">and assess = #{assess}</if>
            <if test="submitTime != null ">and submit_time = #{submitTime}</if>
        </where>
    </select>

    <select id="selectQgzxMonthAssessById" parameterType="Long" resultMap="QgzxMonthAssessResult">
        <include refid="selectQgzxMonthAssessVo"/>
        where id = #{id}
    </select>

    <insert id="insertQgzxMonthAssess" parameterType="QgzxMonthAssess" useGeneratedKeys="true" keyProperty="id">
        insert into qgzx_month_assess
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="stuPostId != null">stu_post_id,</if>
            <if test="assess != null">assess,</if>
            <if test="submitTime != null">submit_time,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="stuPostId != null">#{stuPostId},</if>
            <if test="assess != null">#{assess},</if>
            <if test="submitTime != null">#{submitTime},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateQgzxMonthAssess" parameterType="QgzxMonthAssess">
        update qgzx_month_assess
        <trim prefix="SET" suffixOverrides=",">
            <if test="stuPostId != null">stu_post_id = #{stuPostId},</if>
            <if test="assess != null">assess = #{assess},</if>
            <if test="submitTime != null">submit_time = #{submitTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteQgzxMonthAssessById" parameterType="Long">
        delete
        from qgzx_month_assess
        where id = #{id}
    </delete>

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

    <select id="listView" parameterType="QgzxMonthAssess" resultType="QgzxMonthAssess">
        select a.*,c.stu_no,c.stu_name,d.post_name,e.dept_name
        from qgzx_month_assess as a
        left join qgzx_stu_post as b on a.stu_post_id = b.id
        left join view_stu_info as c on b.stu_no = c.stu_no
        left join qgzx_post as d on b.post_id = d.id
        left join sys_dept as e on d.dept_code = e.dept_code
        <where>
            <if test="stuPostId != null ">and a.stu_post_id = #{stuPostId}</if>
            <if test="assess != null  and assess != ''">and a.assess = #{assess}</if>
            <if test="submitTime != null ">and a.submit_time like concat( date_format(#{submitTime}, '%Y-%m'),'%')</if>
            <if test="zdlsNo != null and zdlsNo != ''">and b.zdls_no = #{zdlsNo}</if>
            <if test="stuNo != null and stuNo != ''">and b.stu_no = #{stuNo}</if>
            <if test="postName != null and postName != ''">and d.post_name like concat('%',#{postName},'%')</if>
            <if test="deptName != null and deptName != ''">and e.dept_name like concat('%',#{deptName},'%')</if>
            <if test="stuName != null and stuName != ''">and c.stu_name like concat('%',#{stuName},'%')</if>
        </where>
        order by a.id desc
    </select>
</mapper>