<?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.supServer.project.mapper.BizCompanyInfoMapper">

    <resultMap type="com.supServer.project.entity.BizCompanyInfo" id="BizCompanyInfoResult">
        <id     property="id"       column="id"      />
        <result property="userId"       column="user_id"      />
        <result property="companyName"     column="company_name"    />
        <result property="creditCode"     	column="credit_code"    />
        <result property="legalPerson" 	column="legal_person"        />
        <result property="registeredCapital"  		column="registered_capital"  />
        <result property="registeredDate" 		column="registered_date"/>
        <result property="registeredAddress"       	column="registered_address"       />
        <result property="addressDetail"     column="address_detail"     />
        <result property="briefing"     column="briefing"       />
        <result property="licenseUrl"     column="license_url"       />
        <result property="cardUrl"   column="card_url"  />
        <result property="type"   column="type"  />
        <result property="fileUrl" column="file_url" />
        <result property="source" column="source" />
        <result property="createTime"   column="create_time"  />
        <result property="updateTime"   column="update_time"  />
    </resultMap>

    <insert id="insertCompany" parameterType="com.supServer.project.entity.BizCompanyInfo">
        insert into biz_company_info(user_id,company_name,credit_code,legal_person,registered_capital,registered_date,registered_address,
                                     address_detail,briefing,license_url,card_url,cat_id,file_url,file_name,source,create_time,update_time,contacts,phone
        )
        values (#{userId},#{companyName},#{creditCode},#{legalPerson},#{registeredCapital},#{registeredDate},#{registeredAddress},#{addressDetail},
                #{briefing},#{licenseUrl},#{cardUrl},#{catId},#{fileUrl},#{fileName},#{source},NOW(),NOW(),#{contacts},#{phone})
    </insert>

    <select id="information" resultType="com.supServer.project.entity.dto.CompanyAuthenticationDto">
        SELECT
            bci.company_name,sui.phone,sui.user_name,sui.sex,sui.email,bci.credit_code,bci.legal_person,bci.registered_capital,
            bci.registered_date,bci.registered_address,bci.address_detail,bci.license_url,bci.card_url,bci.cat_id
        FROM
            sup_user_info sui
        left join biz_company_info bci on sui.user_id = bci.user_id
        WHERE
            sui.phone = #{phone}
    </select>

    <select id="selectBycode" resultType="java.lang.Integer">
        select bv.review_status
        from biz_company_info bci
        left join biz_verify bv on bci.credit_code=bv.credit_code
        where bci.credit_code=#{creditCode}
        and bv.status=3
        order by bv.update_time desc
        limit 1
    </select>

    <select id="selectCompanyInfo" resultType="com.supServer.project.entity.BizCompanyInfo">
        select bci.*
        from biz_company_info bci
        where bci.credit_code=#{creditCode}
    </select>


    <update id="updateCompany" parameterType="com.supServer.project.entity.BizCompanyInfo">
        update biz_company_info
        <set>
            update_time = now(),
            <if test="companyName != null and companyName !=''">company_name = #{companyName},</if>
            <if test="creditCode != null and creditCode !=''">credit_code = #{creditCode},</if>
            <if test="legalPerson != null and legalPerson !=''">legal_person = #{legalPerson},</if>
            <if test="registeredCapital != null and registeredCapital !=''">registered_capital = #{registeredCapital},</if>
            <if test="registeredDate != null ">registered_date = #{registeredDate},</if>
            <if test="registeredAddress != null and registeredAddress !=''">registered_address = #{registeredAddress},</if>
            <if test="addressDetail != null and addressDetail !=''">address_detail = #{addressDetail},</if>
            <if test="briefing != null and briefing !=''">briefing = #{briefing},</if>
            <if test="licenseUrl != null and licenseUrl !=''">license_url = #{licenseUrl},</if>
            <if test="cardUrl != null and cardUrl !=''">card_url = #{cardUrl},</if>
            <if test="catId != null and catId !=''">cat_id = #{catId},</if>
            <if test="fileUrl != null and fileUrl !=''">file_url = #{fileUrl},</if>
            <if test="fileName != null and fileName !=''">file_name = #{fileName},</if>
            <if test="source != null and source !=''">source = #{source},</if>
            <if test="contacts != null and contacts !=''">contacts = #{contacts},</if>
            <if test="phone != null and phone !=''">phone = #{phone},</if>
        </set>
        where id = #{id}
    </update>

    <select id="seleceById" resultType="com.supServer.project.entity.vo.AttestationVo">
        select
        sui.user_id as userId,sui.user_name as userName,sui.phone,sui.sex,sui.email,
        bci.company_name as companyName,bci.credit_code as creditCode,bci.legal_person as legalPerson,
        bci.registered_capital as registeredCapital,bci.registered_date as registeredDate,
        bci.registered_address as registeredAddress,bci.address_detail as addressDetail,bci.license_url as licenseUrl,
        bci.card_url as cardUrl,bci.cat_id as catId,bci.file_url as fileUrl,bci.file_name as fileName
        from biz_company_info bci
        left join sup_user_info sui on bci.user_id=sui.user_id
        where bci.user_id=#{userId}
    </select>


</mapper>