<?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.ym.mec.biz.dal.dao.TenantPreJoinDao">
    <resultMap id="BaseResultMap" type="com.ym.mec.biz.dal.entity.TenantPreJoin">
        <id column="id_" jdbcType="INTEGER" property="id"/>
        <result column="tsign_name_" jdbcType="VARCHAR" property="tsignName"/>
        <result column="name_" jdbcType="VARCHAR" property="name"/>
        <result column="area_id_" jdbcType="INTEGER" property="areaId"/>
        <result column="area_name_" jdbcType="VARCHAR" property="areaName"/>
        <result column="email_" jdbcType="VARCHAR" property="email"/>
        <result column="customer_service_phone_" jdbcType="VARCHAR" property="customerServicePhone"/>
        <result column="tsign_code_" jdbcType="VARCHAR" property="tsignCode"/>
        <result column="address_" jdbcType="VARCHAR" property="address"/>
        <result column="remark_" jdbcType="VARCHAR" property="remark"/>
        <result column="enterprise_liable_name_" jdbcType="VARCHAR" property="enterpriseLiableName"/>
        <result column="enterprise_liable_phone_" jdbcType="VARCHAR" property="enterpriseLiablePhone"/>
        <result column="legal_person_id_front_pic_" jdbcType="VARCHAR" property="legalPersonIdFrontPic"/>
        <result column="legal_person_id_reverse_pic_" jdbcType="VARCHAR" property="legalPersonIdReversePic"/>
        <result column="contacts_" jdbcType="VARCHAR" property="contacts"/>
        <result column="phone_" jdbcType="VARCHAR" property="phone"/>
        <result column="tsign_pic_" jdbcType="VARCHAR" property="tsignPic"/>
        <result column="tax_register_pic_" jdbcType="VARCHAR" property="taxRegisterPic"/>
        <result column="company_account_info_pic_" jdbcType="VARCHAR" property="companyAccountInfoPic"/>
        <result column="logo_" jdbcType="VARCHAR" property="logo"/>
        <result column="corporate_chops_" jdbcType="VARCHAR" property="corporateChops"/>
        <result column="corporate_finance_chops_" jdbcType="VARCHAR" property="corporateFinanceChops"/>
        <result column="state_" jdbcType="INTEGER" property="state"/>
        <result column="created_time_" jdbcType="TIMESTAMP" property="createdTime"/>
        <result column="province_id_" jdbcType="INTEGER" property="provinceId"/>
        <result column="province_name_" jdbcType="VARCHAR" property="provinceName"/>
        <result column="current_has_school_num_" property="currentHasSchoolNum"/>
        <result column="student_num_" property="studentNum"/>
    </resultMap>

    <sql id="Base_Column_List">
        id_
        , tsign_name_, name_, area_id_, area_name_, email_, customer_service_phone_
        , tsign_code_, address_, remark_, enterprise_liable_name_, enterprise_liable_phone_, legal_person_id_front_pic_
        , legal_person_id_reverse_pic_, contacts_, phone_, tsign_pic_, tax_register_pic_, company_account_info_pic_
        , logo_, corporate_chops_, corporate_finance_chops_, state_, created_time_, province_id_,
        province_name_,student_num_,current_has_school_num_
    </sql>

    <insert id="insertBatch" keyColumn="id_" keyProperty="id" useGeneratedKeys="true"
            parameterType="com.ym.mec.biz.dal.entity.TenantPreJoin">
        insert into tenant_pre_join(tsign_name_, name_, area_id_, area_name_, email_, customer_service_phone_,
        tsign_code_, address_, remark_, enterprise_liable_name_, enterprise_liable_phone_, legal_person_id_front_pic_,
        legal_person_id_reverse_pic_, contacts_, phone_, tsign_pic_, tax_register_pic_, company_account_info_pic_,
        logo_, corporate_chops_, corporate_finance_chops_, state_, created_time_, province_id_, province_name_,student_num_,current_has_school_num_)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.tsignName}, #{entity.name}, #{entity.areaId}, #{entity.areaName}, #{entity.email},
            #{entity.customerServicePhone}, #{entity.tsignCode}, #{entity.address}, #{entity.remark},
            #{entity.enterpriseLiableName}, #{entity.enterpriseLiablePhone}, #{entity.legalPersonIdFrontPic},
            #{entity.legalPersonIdReversePic}, #{entity.contacts}, #{entity.phone}, #{entity.tsignPic},
            #{entity.taxRegisterPic}, #{entity.companyAccountInfoPic}, #{entity.logo}, #{entity.corporateChops},
            #{entity.corporateFinanceChops}, #{entity.state}, #{entity.createdTime}, #{entity.provinceId},
            #{entity.provinceName},#{entity.studentNum},#{entity.currentHasSchoolNum})
        </foreach>
    </insert>

    <resultMap id="TenantPreJoinVo" type="com.ym.mec.biz.dal.vo.TenantPreJoinVo" extends="BaseResultMap">
        <result property="recommenderName" column="real_name_"/>
    </resultMap>
    <select id="queryPage" parameterType="map" resultMap="TenantPreJoinVo">
        SELECT a.id_,
        a.tsign_name_,
        a.name_,
        a.area_id_,
        a.area_name_,
        a.email_,
        a.customer_service_phone_,
        a.tsign_code_,
        a.address_,
        a.remark_,
        a.enterprise_liable_name_,
        a.enterprise_liable_phone_,
        a.legal_person_id_front_pic_,
        a.legal_person_id_reverse_pic_,
        a.contacts_,
        a.phone_,
        a.tsign_pic_,
        a.tax_register_pic_,
        a.company_account_info_pic_,
        a.logo_,
        a.corporate_chops_,
        a.corporate_finance_chops_,
        a.state_,
        a.created_time_,
        a.province_id_,
        a.province_name_,
        a.recommender_,
        a.student_num_,
        a.current_has_school_num_,
        b.real_name_
        FROM tenant_pre_join as a
        left join sys_user as b on a.recommender_ = b.id_
        <where>
            <if test="param.recommender != null">
                AND a.recommender_ = #{param.recommender}
            </if>
            <if test="param.state != null">
                AND state_ = #{param.state}
            </if>
            <if test="param.startTime != null">
                AND created_time_ <![CDATA[ >= ]]> #{param.startTime}
            </if>
            <if test="param.endTime != null">
                AND created_time_ <![CDATA[ <= ]]> #{param.endTime}
            </if>
            <if test="param.search != null ">
                AND (tsign_name_ LIKE CONCAT('%', #{param.search},'%')
                OR enterprise_liable_name_ LIKE CONCAT('%', #{param.search},'%')
                OR contacts_ LIKE CONCAT('%', #{param.search},'%'))
            </if>
        </where>
    </select>
</mapper>
