<?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.mmc.iuav.user.dao.CompanyAuthDao">

    <!--    <resultMap id="companyAuthResultMAp" type="com.mmc.iuav.user.entity.CompanyAuthDO">-->
    <!--        <id column="id" property="id"/>-->
    <!--        <result property="authStatus" column="auth_status"/>-->
    <!--        <result property="userAccountId" column="user_account_id"/>-->
    <!--        <result property="companyName" column="company_name"/>-->
    <!--        <result property="creditCode" column="credit_code"/>-->
    <!--        <result property="licenseImg" column="license_img"/>-->
    <!--    </resultMap>-->

    <insert id="addCompanyAuth" parameterType="com.mmc.iuav.user.entity.CompanyAuthDO"
            keyProperty="id" useGeneratedKeys="true">
        insert into company_auth(user_account_id, company_name, credit_code, license_img, auth_status, create_time)
        values (#{userAccountId}, #{companyName}, #{creditCode}, #{licenseImg}, #{authStatus}, NOW())
    </insert>

    <!--    <select id="getCompanyAuth" resultMap="companyAuthResultMAp">-->
    <!--        select id,user_account_id,company_name,credit_code,license_img,auth_status-->
    <!--        from company_auth where user_account_id = #{userAccountId}-->
    <!--    </select>-->

    <select id="getCompanyAuth" resultType="com.mmc.iuav.user.entity.CompanyAuthDO">
        SELECT cm.id,
               cm.user_account_id,
               cm.company_info_id,
               cm.is_leader,
               cm.create_time,
               ci.company_name,
               ci.credit_code,
               ci.license_img
        FROM company_member cm
                 LEFT JOIN company_info ci ON ci.id = cm.company_info_id
        WHERE ci.is_deleted = 0 and cm.user_account_id = #{userAccountId}
    </select>
</mapper>
