<?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.CphGoodAuditMapper">
    
    <resultMap type="CphGoodAudit" id="CphGoodAuditResult">
        <result property="id"    column="id"    />
        <result property="applyId"    column="apply_id"    />
        <result property="fdyNo"    column="fdy_no"    />
        <result property="fdyStatus"    column="fdy_status"    />
        <result property="fdyComment"    column="fdy_comment"    />
        <result property="fdyTime"    column="fdy_time"    />
        <result property="deptNo"    column="dept_no"    />
        <result property="deptStatus"    column="dept_status"    />
        <result property="deptComment"    column="dept_comment"    />
        <result property="deptTime"    column="dept_time"    />
        <result property="finalNo"    column="final_no"    />
        <result property="finalStatus"    column="final_status"    />
        <result property="finalComment"    column="final_comment"    />
        <result property="finalTime"    column="final_time"    />
        <result property="status"    column="status"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectCphGoodAuditVo">
        select id, apply_id, fdy_no, fdy_status, fdy_comment, fdy_time, dept_no, dept_status, dept_comment, dept_time, final_no, final_status, final_comment, final_time, status, del_flag, create_by, create_time, update_by, update_time from cph_good_audit
    </sql>

    <select id="selectCphGoodAuditList" parameterType="CphGoodAudit" resultMap="CphGoodAuditResult">
        <include refid="selectCphGoodAuditVo"/>
        <where>  
            <if test="applyId != null "> and apply_id = #{applyId}</if>
            <if test="fdyNo != null  and fdyNo != ''"> and fdy_no = #{fdyNo}</if>
            <if test="fdyStatus != null  and fdyStatus != ''"> and fdy_status = #{fdyStatus}</if>
            <if test="fdyComment != null  and fdyComment != ''"> and fdy_comment = #{fdyComment}</if>
            <if test="fdyTime != null "> and fdy_time = #{fdyTime}</if>
            <if test="deptNo != null  and deptNo != ''"> and dept_no = #{deptNo}</if>
            <if test="deptStatus != null  and deptStatus != ''"> and dept_status = #{deptStatus}</if>
            <if test="deptComment != null  and deptComment != ''"> and dept_comment = #{deptComment}</if>
            <if test="deptTime != null "> and dept_time = #{deptTime}</if>
            <if test="finalNo != null  and finalNo != ''"> and final_no = #{finalNo}</if>
            <if test="finalStatus != null  and finalStatus != ''"> and final_status = #{finalStatus}</if>
            <if test="finalComment != null  and finalComment != ''"> and final_comment = #{finalComment}</if>
            <if test="finalTime != null "> and final_time = #{finalTime}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
        </where>
    </select>

    <select id="fdyCountUnAudit" resultType="Map">
        select count(1) as count_audit
        from cph_good_apply as a
                 left join srs_student as b on a.stu_no = b.stu_no
                 left join srs_class as c on b.class_id = c.class_id
                 left join cph_teacher as d on c.teacher_id = d.teacher_id
        where d.employee_id = #{tNo} and a.apply_status = 1
    </select>

    <select id="xwCountUnAudit" resultType="Map">
        select count(1) as count_audit
        from cph_good_apply as a
                 left join srs_student as b on a.stu_no = 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
        where d.college_id = #{deptId} and a.apply_status = 2
    </select>

    <select id="jwcCountUnAudit" resultType="Map">
        select count(1) as count_audit from cph_good_apply as a
        where a.apply_status = 3
    </select>
    
    <select id="selectCphGoodAuditById" parameterType="Long" resultMap="CphGoodAuditResult">
        <include refid="selectCphGoodAuditVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertCphGoodAudit" parameterType="CphGoodAudit" useGeneratedKeys="true" keyProperty="id">
        insert into cph_good_audit
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="applyId != null">apply_id,</if>
            <if test="fdyNo != null">fdy_no,</if>
            <if test="fdyStatus != null">fdy_status,</if>
            <if test="fdyComment != null">fdy_comment,</if>
            <if test="fdyTime != null">fdy_time,</if>
            <if test="deptNo != null">dept_no,</if>
            <if test="deptStatus != null">dept_status,</if>
            <if test="deptComment != null">dept_comment,</if>
            <if test="deptTime != null">dept_time,</if>
            <if test="finalNo != null">final_no,</if>
            <if test="finalStatus != null">final_status,</if>
            <if test="finalComment != null">final_comment,</if>
            <if test="finalTime != null">final_time,</if>
            <if test="status != null">status,</if>
            <if test="delFlag != null and delFlag != ''">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="applyId != null">#{applyId},</if>
            <if test="fdyNo != null">#{fdyNo},</if>
            <if test="fdyStatus != null">#{fdyStatus},</if>
            <if test="fdyComment != null">#{fdyComment},</if>
            <if test="fdyTime != null">#{fdyTime},</if>
            <if test="deptNo != null">#{deptNo},</if>
            <if test="deptStatus != null">#{deptStatus},</if>
            <if test="deptComment != null">#{deptComment},</if>
            <if test="deptTime != null">#{deptTime},</if>
            <if test="finalNo != null">#{finalNo},</if>
            <if test="finalStatus != null">#{finalStatus},</if>
            <if test="finalComment != null">#{finalComment},</if>
            <if test="finalTime != null">#{finalTime},</if>
            <if test="status != null">#{status},</if>
            <if test="delFlag != null and delFlag != ''">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateCphGoodAudit" parameterType="CphGoodAudit">
        update cph_good_audit
        <trim prefix="SET" suffixOverrides=",">
            <if test="applyId != null">apply_id = #{applyId},</if>
            <if test="fdyNo != null">fdy_no = #{fdyNo},</if>
            <if test="fdyStatus != null">fdy_status = #{fdyStatus},</if>
            <if test="fdyComment != null">fdy_comment = #{fdyComment},</if>
            <if test="fdyTime != null">fdy_time = #{fdyTime},</if>
            <if test="deptNo != null">dept_no = #{deptNo},</if>
            <if test="deptStatus != null">dept_status = #{deptStatus},</if>
            <if test="deptComment != null">dept_comment = #{deptComment},</if>
            <if test="deptTime != null">dept_time = #{deptTime},</if>
            <if test="finalNo != null">final_no = #{finalNo},</if>
            <if test="finalStatus != null">final_status = #{finalStatus},</if>
            <if test="finalComment != null">final_comment = #{finalComment},</if>
            <if test="finalTime != null">final_time = #{finalTime},</if>
            <if test="status != null">status = #{status},</if>
            <if test="delFlag != null and delFlag != ''">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCphGoodAuditById" parameterType="Long">
        delete from cph_good_audit where id = #{id}
    </delete>

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

    <delete id="deleteCphGoodAuditByApplyId" parameterType="Long">
        delete from cph_good_audit where apply_id = #{id}
    </delete>

</mapper>