<?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.zhongzheng.modules.recruit.mapper.RecruitCompanyMapper">

    <resultMap type="com.zhongzheng.modules.recruit.domain.RecruitCompany" id="RecruitCompanyResult">
        <result property="companyId" column="company_id"/>
        <result property="companyName" column="company_name"/>
        <result property="companyTypeId" column="company_type_id"/>
        <result property="companySizeId" column="company_size_id"/>
        <result property="industryTypeId" column="industry_type_id"/>
        <result property="industryTypeName" column="industry_type_name"/>
        <result property="companyIntroduce" column="company_introduce"/>
        <result property="logoUrl" column="logo_url"/>
        <result property="licenseUrl" column="license_url"/>
        <result property="societyCode" column="society_code"/>
        <result property="province" column="province"/>
        <result property="city" column="city"/>
        <result property="district" column="district"/>
        <result property="address" column="address"/>
        <result property="companyPh" column="company_ph"/>
        <result property="linkMan" column="link_man"/>
        <result property="postBox" column="post_box"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="status" column="status"/>
        <result property="tenantId" column="tenant_id"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.recruit.vo.RecruitCompanyVo" id="RecruitCompanyVoResult">
        <result property="companyId" column="company_id"/>
        <result property="companyName" column="company_name"/>
        <result property="companyTypeId" column="company_type_id"/>
        <result property="companySizeId" column="company_size_id"/>
        <result property="industryTypeId" column="industry_type_id"/>
        <result property="industryTypeName" column="industry_type_name"/>
        <result property="companyIntroduce" column="company_introduce"/>
        <result property="logoUrl" column="logo_url"/>
        <result property="licenseUrl" column="license_url"/>
        <result property="societyCode" column="society_code"/>
        <result property="province" column="province"/>
        <result property="city" column="city"/>
        <result property="district" column="district"/>
        <result property="address" column="address"/>
        <result property="companyPh" column="company_ph"/>
        <result property="linkMan" column="link_man"/>
        <result property="postBox" column="post_box"/>
        <result property="status" column="status"/>
        <result property="tenantId" column="tenant_id"/>
    </resultMap>

    <select id="selectIndustry" resultType="Long" parameterType="map">
        select trade_id FROM recruit_company_trade where trade_name=#{industry} LIMIT 1
    </select>

    <select id="selectCompanyList" resultMap="RecruitCompanyVoResult" parameterType="com.zhongzheng.modules.recruit.bo.RecruitCompanyQueryBo">
        SELECT
            tenant_id,
            create_time,
            update_time,
            status,
            tenant_name AS company_name,
            company_type_id,
            company_size_id,
            industry_type_id,
            industry_type_name,
            company_introduce,
            logo_url,
            license_url,
            society_code,
            province,
            city,
            district,
            address,
            company_ph,
            link_man,
            post_box
        FROM
            sys_tenant
        where status=1 and tenant_id = #{tenantId} limit 1
    </select>

    <update id="updateSysTent" parameterType="com.zhongzheng.modules.recruit.domain.RecruitCompany" >
        UPDATE sys_tenant
        <trim prefix="set" suffixOverrides=",">
            <if test="status!=null">status=#{status},</if>
            <if test="companyName!=null">tenant_name=#{companyName},</if>
            <if test="companyTypeId!=null">company_type_id=#{companyTypeId},</if>
            <if test="companySizeId!=null">company_size_id=#{companySizeId},</if>
            <if test="industryTypeId!=null">industry_type_id=#{industryTypeId},</if>
            <if test="industryTypeName!=null">industry_type_name=#{industryTypeName},</if>
            <if test="companyIntroduce!=null">company_introduce=#{companyIntroduce},</if>
            <if test="logoUrl!=null">logo_url=#{logoUrl},</if>
            <if test="licenseUrl!=null">license_url=#{licenseUrl},</if>
            <if test="societyCode!=null">society_code=#{societyCode},</if>
            <if test="province!=null">province=#{province},</if>
            <if test="city!=null">city=#{city},</if>
            <if test="address!=null">address=#{address},</if>
            <if test="companyPh!=null">company_ph=#{companyPh},</if>
            <if test="linkMan!=null">link_man=#{linkMan},</if>
            <if test="postBox!=null">post_box=#{postBox},</if>
            <if test="district!=null">district=#{district},</if>
            <if test="updateTime!=null">update_time=#{updateTime},</if>
            <if test="createTime!=null">create_time=#{createTime},</if>
        </trim>
        WHERE tenant_id=#{tenantId}
    </update>


    <select id="selectLimt" resultMap="RecruitCompanyVoResult" parameterType="com.zhongzheng.modules.recruit.bo.RecruitCompanyQueryBo">
        SELECT * FROM v_tenant_company where status = 1
            <if test="status!=null">and status=#{status}</if>
            <if test="companyId!=null">and company_id=#{companyId} </if>
            <if test="companyName!=null">and tenant_name like concat('%', #{companyName}, '%')</if>
            <if test="companyTypeId!=null">and company_type_id=#{companyTypeId}</if>
            <if test="companySizeId!=null">and company_size_id=#{companySizeId}</if>
            <if test="industryTypeId!=null">and industry_type_id=#{industryTypeId}</if>
            <if test="industryTypeName!=null">and industry_type_name=#{industryTypeName}</if>
            <if test="companyIntroduce!=null">and company_introduce=#{companyIntroduce}</if>
            <if test="logoUrl!=null">and logo_url=#{logoUrl}</if>
            <if test="licenseUrl!=null">and license_url=#{licenseUrl}</if>
            <if test="societyCode!=null">and society_code=#{societyCode}</if>
            <if test="province!=null">and province=#{province}</if>
            <if test="city!=null">and city=#{city}</if>
            <if test="address!=null">and address=#{address}</if>
            <if test="companyPh!=null">and company_ph=#{companyPh}</if>
            <if test="linkMan!=null">and link_man=#{linkMan}</if>
            <if test="postBox!=null">and post_box=#{postBox}</if>
            <if test="district!=null">and district=#{district}</if>
            <if test="updateTime!=null">and update_time=#{updateTime}</if>
            <if test="createTime!=null">and create_time=#{createTime}</if>
        <if test="sizeIds != null and sizeIds.size()!=0 ">
            AND company_size_id in
            <foreach collection="sizeIds" item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="typeIds != null and typeIds.size()!=0 ">
            AND company_type_id in
            <foreach collection="typeIds" item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
    </select>

</mapper>