<?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.yida.data.form.apply.mapper.CoreApplyFormFillUserMapper">

    <!-- 查询用户已经填报的数据 -->
    <select id="selectUserFillForm"
            resultType="com.yida.data.customForm.vo.apply.MyApplyFormPageVO">
        SELECT
            f.id,
            f.form_title,
            f.background_img_url,
            f.header_img_url,
            fu.user_id,
            fu.create_date,
            fu.examine_status,
            fu.id as fill_user_id,
            fu.apply_form_data_id
        FROM
            core_apply_form_fill_user fu
        INNER JOIN core_apply_form f ON fu.apply_form_id = f.id
        WHERE
            fu.del_flag = 0
          AND f.del_flag = 0
          AND fu.user_id in
          <foreach collection="userIds" open="(" separator="," close=")" item="userId">
              #{userId}
          </foreach>
          AND f.school_id = #{dto.deptId}
          order by
              fu.create_date desc
    </select>

    <!-- 职工参与审核的填报用户信息 -->
    <select id="findApprovalFormDataFillUserList"
            resultType="com.yida.data.common.core.entity.applyForm.CoreApplyFormFillUser">
        SELECT DISTINCT
            fu.*,
            fur.approval_result currentUserStatus
        FROM
             core_apply_form_fill_user_approval_process_record fur
        INNER JOIN core_apply_form_fill_user fu ON fur.fill_user_id = fu.id
        WHERE
            fu.del_flag = 0
        AND fu.school_id = #{dto.schoolId}
        AND fur.approval_id = #{dto.userId}
        <if test='dto.studentName != null and dto.studentName != ""'>
            AND fu.user_name LIKE CONCAT('%',#{dto.studentName},'%')
        </if>
        AND fu.create_date &gt;= #{dateTime}
    </select>

    <!-- 查询教师审核的表单分页数据 -->
    <select id="selectApprovalUserFillForm"
            resultType="com.yida.data.customForm.vo.apply.ApprovalApplyFormPageVO">
        SELECT
            f.*,
            fu.id AS fill_user_id,
            fu.user_id,
            fu.user_name,
            fu.examine_status,
            fu.create_date as createDate
        FROM
            core_apply_form_fill_user fu
        LEFT JOIN core_apply_form f ON fu.apply_form_id = f.id
        WHERE
            fu.del_flag = 0
          AND f.del_flag = 0
          AND f.school_id = #{dto.schoolId}
        AND fu.id in
        <foreach collection="dto.fillUserIds" open="(" separator="," close=")" item="id">
            #{id}
        </foreach>
    </select>

    <!-- 查询申请表单填报列表数据 -->
    <select id="listApplyFormFillPage"
            resultType="com.yida.data.customForm.vo.apply.ApplyFormFillSelectPageVO">
        SELECT
            u.*,
            f.form_title
        FROM
            core_apply_form_fill_user u
        LEFT JOIN core_apply_form f ON u.apply_form_id = f.id
        WHERE
            f.school_id = #{dto.deptId}
        AND f.del_flag = 0
        AND u.del_flag = 0
        <if test='dto.formTitle != null and dto.formTitle != ""'>
            AND f.form_title LIKE CONCAT( '%', #{dto.formTitle}, '%' )
        </if>
        <if test='dto.userName != null and dto.userName != ""'>
            AND u.user_name LIKE CONCAT( '%', #{dto.userName}, '%' )
        </if>
        <if test='dto.examineStatus != null'>
            AND u.examine_status = #{dto.examineStatus}
        </if>
        ORDER BY
        u.create_date DESC
    </select>

</mapper>
