<?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.cool.store.mapper.AuditStatusMapper">
    <resultMap id="BaseResultMap" type="com.cool.store.entity.AuditStatusDO">
        <id column="id" jdbcType="BIGINT" property="id" />
        <result column="line_id" jdbcType="BIGINT" property="lineId" />
        <result column="interview_id" jdbcType="BIGINT" property="interviewId" />
        <result column="audit_id" jdbcType="BIGINT" property="auditId" />
        <result column="audit_status" jdbcType="TINYINT" property="auditStatus" />
        <result column="audit_user_id" jdbcType="BIGINT" property="auditUserId" />
        <result column="audit_user_name" jdbcType="VARCHAR" property="auditUserName" />
        <result column="create_time" jdbcType="BIGINT" property="lineId" />
        <result column="update_time" jdbcType="BIGINT" property="lineId" />
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
        <result column="audit_stage" jdbcType="TINYINT" property="auditStage" />
    </resultMap>

    <sql id="Base_Column_List">
        id,
        line_id,
        interview_id,
        audit_id,
        audit_status,
        audit_user_id,
        audit_user_name,
        create_time,
        update_time,
        audit_stage
    </sql>
    <select id="checkList" resultType="com.cool.store.response.CheckListResponse">
        SELECT
        a.id AS checkId,
        a.line_id as lineId,
        a.interview_id as interviewId,
        a.audit_status as checkStatus,
        a.audit_stage,
        a.audit_user_id,
        a.audit_user_name as checkUser,
        a.create_time,
        a.update_time AS checkTime,
        l.id AS line_id,
        l.partner_id,
        l.region_id AS line_region_id,
        l.mobile AS mobile,
        l.username as interviewName,
        l.sex,
        l.want_shop_area_id as wantRegion,
        l.live_address,
        l.workflow_stage,
        l.workflow_sub_stage,
        l.workflow_sub_stage_status,
        l.want_shop_num,
        l.select_site_num,
        l.prepare_shop_num,
        l.open_shop_num,
        l.line_source,
        l.investment_manager as investmentId,
        l.development_manager,
        l.first_interviewer,
        l.second_interviewer,
        l.user_portrait,
        l.join_status,
        l.line_status,
        l.create_time AS line_create_time,
        l.update_time AS line_update_time,
        l.create_user_id,
        l.update_user_id,
        l.deleted,
        l.partner_num,
        i.id AS interview_id,
        i.interview_date,
        i.start_time,
        i.end_time,
        i.join_interview_status,
        i.actual_start_time,
        i.actual_end_time,
        i.room_id,
        i.room_password,
        i.interviewer_user_id as intervieweeId,
        i.room_status,
        i.interview_status,
        i.interview_type,
        i.video_url,
        i.audit_id AS interview_audit_id,
        i.calendars_event_id,
        i.deleted AS interview_deleted,
        i.create_time AS interview_create_time,
        i.update_time AS interview_update_time,
        lai.create_time AS intervieweePassTime
        FROM
        xfsg_audit_status a
        LEFT JOIN
        xfsg_line_info l ON a.line_id = l.id
        LEFT JOIN
        xfsg_line_interview i ON a.interview_id = i.id
        LEFT JOIN
        xfsg_line_audit_info lai ON lai.id = i.audit_id
        <where>
            <if test="keyWord != null and keyWord != ''">
                AND (
                l.username like CONCAT('%',#{keyWord},'%')
                OR l.mobile like CONCAT('%',#{keyWord},'%')
                )
            </if>
            <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
                AND lai.create_time BETWEEN  #{startTime} AND #{endTime}
            </if>
            <if test="region != null and region != ''">
                and l.want_shop_area_id in (select id from xfsg_open_area_info where area_path like concat(#{region}, '%'))
            </if>
            <if test="checkStatus != null">
                AND a.audit_status = #{checkStatus}
            </if>
            <if test="checkStage != null">
                AND a.audit_stage = #{checkStage}
            </if>
        </where>

    </select>

</mapper>