<?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.comprehensive.mapper.SrsZxjApprovalRecordMapper">

    <resultMap type="SrsZxjApprovalRecord" id="SrsZxjApprovalRecordResult">
        <result property="id"    column="id"    />
        <result property="step"    column="step"    />
        <result property="operator"    column="operator"    />
        <result property="status"    column="status"    />
        <result property="createTime"    column="create_time"    />
        <result property="remark"    column="remark"    />
        <result property="applyId"    column="apply_id"    />
        <result property="applyName" column="applyName"/>
        <result property="deptName" column="deptName"/>
        <result property="majorName" column="majorName"/>
        <result property="className" column="className"/>
     </resultMap>

    <sql id="selectSrsZxjApprovalRecordVo">
        select id, step, operator, status, create_time, remark, apply_id from srs_zxj_approval_record
    </sql>

    <select id="selectSrsZxjApprovalRecordList" parameterType="SrsZxjApprovalRecord" resultMap="SrsZxjApprovalRecordResult">
        <include refid="selectSrsZxjApprovalRecordVo"/>
        <where>
            <if test="step != null "> and step = #{step}</if>
            <if test="operator != null  and operator != ''"> and operator = #{operator}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="applyId != null "> and apply_id = #{applyId}</if>
        </where>
    </select>

    <select id="selectSrsZxjApprovalRecordById" parameterType="Long" resultMap="SrsZxjApprovalRecordResult">
        <include refid="selectSrsZxjApprovalRecordVo"/>
        where id = #{id}
    </select>

    <insert id="insertSrsZxjApprovalRecord" parameterType="SrsZxjApprovalRecord" useGeneratedKeys="true" keyProperty="id">
        insert into srs_zxj_approval_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="step != null">step,</if>
            <if test="operator != null">operator,</if>
            <if test="status != null">status,</if>
            <if test="createTime != null">create_time,</if>
            <if test="remark != null">remark,</if>
            <if test="applyId != null">apply_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="step != null">#{step},</if>
            <if test="operator != null">#{operator},</if>
            <if test="status != null">#{status},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="applyId != null">#{applyId},</if>
         </trim>
    </insert>

    <update id="updateSrsZxjApprovalRecord" parameterType="SrsZxjApprovalRecord">
        update srs_zxj_approval_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="step != null">step = #{step},</if>
            <if test="operator != null">operator = #{operator},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="applyId != null">apply_id = #{applyId},</if>
        </trim>
        where id = #{id}
    </update>
<!--    审核记录-->
    <select id="listView" parameterType="CphSearch" resultMap="SrsZxjApprovalRecordResult">
        select r.*, a.xm as applyName ,c.class_name as className,d.major_name as majorName,dept.dept_name as deptName
        from srs_zxj_apply as a
        left join srs_student as b on a.xh = b.stu_no
        left join srs_class as c on b.class_id = c.class_id
        left join srs_majors as d on c.major_id = d.major_id
        left join sys_dept as dept on d.college_id = dept.dept_id
        left join cph_teacher as e on c.teacher_id = e.teacher_id
        right join srs_zxj_approval_record as r on r.apply_id = a.id
        where
            r.step != 0 and r.step != 1
            and a.step != 0
            <if test="step != null "> and r.step = #{step}</if>
            <if test="tNo != null "> and e.employee_id = #{tNo}</if>
            <if test="deptId != null "> and d.college_id = #{deptId}</if>
            <if test="stuNo != null "> and a.xh = #{stuNo}</if>
            <if test="operator != null ">and r.operator like concat('%',#{operator},'%')</if>
            <if test="status != null"> and r.status = #{status}</if>

        order by a.id desc
    </select>
    <delete id="deleteSrsZxjApprovalRecordById" parameterType="Long">
        delete from srs_zxj_approval_record where id = #{id}
    </delete>

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

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