<?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="cn.roadm.mapper.SmsCompanyInfoMapper">

    <resultMap type="SmsCompanyInfo" id="SmsCompanyInfoResultMap">
        <id column="id" property="id" />
        <result column="company_name" property="companyName" />
        <result column="company_code" property="companyCode" />
        <result column="business_pic_path" property="businessPicPath" />
        <result column="legal_name" property="legalName" />
        <result column="legal_cert_type" property="legalCertType" />
        <result column="legal_cert_id" property="legalCertId" />
        <result column="legal_identity_card_path" property="legalIdentityCardPath" />
        <result column="agency_name" property="agencyName" />
        <result column="agency_cert_type" property="agencyCertType" />
        <result column="agency_cert_id" property="agencyCertId" />
        <result column="agency_phone" property="agencyPhone" />
        <result column="agency_identity_card_path" property="agencyIdentityCardPath" />
        <result column="remark" property="remark" />
        <result column="lt_agency_name" property="ltAgencyName" />
        <result column="lt_agency_cert_type" property="ltAgencyCertType" />
        <result column="lt_agency_cert_id" property="ltAgencyCertId" />
        <result column="lt_agency_phone" property="ltAgencyPhone" />
        <result column="lt_agency_identity_card_path" property="ltAgencyIdentityCardPath" />
        <result column="dx_agency_name" property="dxAgencyName" />
        <result column="dx_agency_cert_type" property="dxAgencyCertType" />
        <result column="dx_agency_cert_id" property="dxAgencyCertId" />
        <result column="dx_agency_phone" property="dxAgencyPhone" />
        <result column="dx_agency_identity_card_path" property="dxAgencyIdentityCardPath" />
        <result column="yd_agency_name" property="ydAgencyName" />
        <result column="yd_agency_cert_type" property="ydAgencyCertType" />
        <result column="yd_agency_cert_id" property="ydAgencyCertId" />
        <result column="yd_agency_phone" property="ydAgencyPhone" />
        <result column="yd_agency_identity_card_path" property="ydAgencyIdentityCardPath" />
        <result column="submit_uid" property="submitUid"/>
    </resultMap>

    <select id="listPageCompanyInfo" parameterType="SmsCompanyInfo"
            resultMap="SmsCompanyInfoResultMap">
        SELECT
            id, company_name, company_code, business_pic_path, legal_name, legal_cert_type, legal_cert_id, legal_identity_card_path,
            agency_name, agency_cert_type, agency_cert_id, agency_phone, agency_identity_card_path, remark,
            lt_agency_name, lt_agency_cert_type, lt_agency_cert_id, lt_agency_phone, lt_agency_identity_card_path,
            dx_agency_name, dx_agency_cert_type, dx_agency_cert_id, dx_agency_phone, dx_agency_identity_card_path,
            yd_agency_name, yd_agency_cert_type, yd_agency_cert_id, yd_agency_phone, yd_agency_identity_card_path, submit_uid
        FROM sms_company_info
        <where>
            <!-- 公司名称模糊查询 -->
            <if test="companyName != null and companyName != ''">
                AND company_name LIKE CONCAT('%', #{companyName}, '%')
            </if>
            <!-- 统一社会信用代码模糊查询 -->
            <if test="companyCode != null and companyCode != ''">
                AND company_code LIKE CONCAT('%', #{companyCode}, '%')
            </if>
        </where>
        ORDER BY id DESC
    </select>

    <select id="getAllCompanyList" resultMap="SmsCompanyInfoResultMap">
        SELECT
            id, company_name, company_code, business_pic_path, legal_name, legal_cert_type, legal_cert_id, legal_identity_card_path,
            agency_name, agency_cert_type, agency_cert_id, agency_phone, agency_identity_card_path, remark
        FROM sms_company_info
    </select>

    <select id="getAllCompanyInfo" resultType="java.util.HashMap">
        SELECT
            company_code AS `key`,
            company_name AS value
        FROM sms_company_info
        ORDER BY id ASC
    </select>

    <select id="queryAllCompanyCode" resultType="java.lang.String">
        SELECT DISTINCT company_code
        FROM sms_company_info
        WHERE company_code IS NOT NULL
    </select>

    <select id="getCompanyInfoById" parameterType="Integer" resultMap="SmsCompanyInfoResultMap">
        SELECT
            id, company_name, company_code, business_pic_path, legal_name, legal_cert_type, legal_cert_id, legal_identity_card_path,
            agency_name, agency_cert_type, agency_cert_id, agency_phone, agency_identity_card_path, remark,
            lt_agency_name, lt_agency_cert_type, lt_agency_cert_id, lt_agency_phone, lt_agency_identity_card_path,
            dx_agency_name, dx_agency_cert_type, dx_agency_cert_id, dx_agency_phone, dx_agency_identity_card_path,
            yd_agency_name, yd_agency_cert_type, yd_agency_cert_id, yd_agency_phone, yd_agency_identity_card_path
        FROM sms_company_info
        WHERE id = #{id}
    </select>

    <select id="getCompanyInfoByCode" parameterType="java.lang.String" resultMap="SmsCompanyInfoResultMap">
        SELECT
            id, company_name, company_code, business_pic_path, legal_name, legal_cert_type, legal_cert_id, legal_identity_card_path,
            agency_name, agency_cert_type, agency_cert_id, agency_phone, agency_identity_card_path, remark,
            lt_agency_name, lt_agency_cert_type, lt_agency_cert_id, lt_agency_phone, lt_agency_identity_card_path,
            dx_agency_name, dx_agency_cert_type, dx_agency_cert_id, dx_agency_phone, dx_agency_identity_card_path,
            yd_agency_name, yd_agency_cert_type, yd_agency_cert_id, yd_agency_phone, yd_agency_identity_card_path
        FROM sms_company_info
        WHERE company_code = #{code}
    </select>

    <insert id="addCompanyInfo" parameterType="SmsCompanyInfo" useGeneratedKeys="true" keyProperty="id">
        INSERT INTO sms_company_info (
            company_name,
            company_code,
            business_pic_path,
            legal_name,
            legal_cert_type,
            legal_cert_id,
            legal_identity_card_path,
            agency_name,
            agency_cert_type,
            agency_cert_id,
            agency_phone,
            agency_identity_card_path,
            remark,
            lt_agency_name,
            lt_agency_cert_type,
            lt_agency_cert_id,
            lt_agency_phone,
            lt_agency_identity_card_path,
            dx_agency_name,
            dx_agency_cert_type,
            dx_agency_cert_id,
            dx_agency_phone,
            dx_agency_identity_card_path,
            yd_agency_name,
            yd_agency_cert_type,
            yd_agency_cert_id,
            yd_agency_phone,
            yd_agency_identity_card_path,
            submit_uid,
            create_time
        ) VALUES (
                     #{companyName},
                     #{companyCode},
                     #{businessPicPath},
                     #{legalName},
                     #{legalCertType},
                     #{legalCertId},
                     #{legalIdentityCardPath},
                     #{agencyName},
                     #{agencyCertType},
                     #{agencyCertId},
                     #{agencyPhone},
                     #{agencyIdentityCardPath},
                     #{remark},
                     #{ltAgencyName},
                     #{ltAgencyCertType},
                     #{ltAgencyCertId},
                     #{ltAgencyPhone},
                     #{ltAgencyIdentityCardPath},
                     #{dxAgencyName},
                     #{dxAgencyCertType},
                     #{dxAgencyCertId},
                     #{dxAgencyPhone},
                     #{dxAgencyIdentityCardPath},
                     #{ydAgencyName},
                     #{ydAgencyCertType},
                     #{ydAgencyCertId},
                     #{ydAgencyPhone},
                     #{ydAgencyIdentityCardPath},
                    #{submitUid},
                     NOW()
                 )
    </insert>

    <update id="updateCompanyInfo" parameterType="SmsCompanyInfo">
        UPDATE sms_company_info
        <set>
            <if test="companyName != null">
                company_name = #{companyName},
            </if>
            <if test="companyCode != null">
                company_code = #{companyCode},
            </if>
            <if test="businessPicPath != null">
                business_pic_path = #{businessPicPath},
            </if>
            <if test="legalName != null">
                legal_name = #{legalName},
            </if>
            <if test="legalCertType != null">
                legal_cert_type = #{legalCertType},
            </if>
            <if test="legalCertId != null">
                legal_cert_id = #{legalCertId},
            </if>
            <if test="legalIdentityCardPath != null">
                legal_identity_card_path = #{legalIdentityCardPath},
            </if>
            <if test="agencyName != null">
                agency_name = #{agencyName},
            </if>
            <if test="agencyCertType != null">
                agency_cert_type = #{agencyCertType},
            </if>
            <if test="agencyCertId != null">
                agency_cert_id = #{agencyCertId},
            </if>
            <if test="agencyPhone != null">
                agency_phone = #{agencyPhone},
            </if>
            <if test="agencyIdentityCardPath != null">
                agency_identity_card_path = #{agencyIdentityCardPath},
            </if>
            <if test="remark != null">
                remark = #{remark},
            </if>
            <if test="ltAgencyName != null">
                lt_agency_name = #{ltAgencyName},
            </if>
            <if test="ltAgencyCertType != null">
                lt_agency_cert_type = #{ltAgencyCertType},
            </if>
            <if test="ltAgencyCertId != null">
                lt_agency_cert_id = #{ltAgencyCertId},
            </if>
            <if test="ltAgencyPhone != null">
                lt_agency_phone = #{ltAgencyPhone},
            </if>
            <if test="ltAgencyIdentityCardPath != null">
                lt_agency_identity_card_path = #{ltAgencyIdentityCardPath},
            </if>
            <if test="dxAgencyName != null">
                dx_agency_name = #{dxAgencyName},
            </if>
            <if test="dxAgencyCertType != null">
                dx_agency_cert_type = #{dxAgencyCertType},
            </if>
            <if test="dxAgencyCertId != null">
                dx_agency_cert_id = #{dxAgencyCertId},
            </if>
            <if test="dxAgencyPhone != null">
                dx_agency_phone = #{dxAgencyPhone},
            </if>
            <if test="dxAgencyIdentityCardPath != null">
                dx_agency_identity_card_path = #{dxAgencyIdentityCardPath},
            </if>
            <if test="ydAgencyName != null">
                yd_agency_name = #{ydAgencyName},
            </if>
            <if test="ydAgencyCertType != null">
                yd_agency_cert_type = #{ydAgencyCertType},
            </if>
            <if test="ydAgencyCertId != null">
                yd_agency_cert_id = #{ydAgencyCertId},
            </if>
            <if test="ydAgencyPhone != null">
                yd_agency_phone = #{ydAgencyPhone},
            </if>
            <if test="ydAgencyIdentityCardPath != null">
                yd_agency_identity_card_path = #{ydAgencyIdentityCardPath},
            </if>
            update_time = NOW()
        </set>
        WHERE id = #{id}
    </update>

    <delete id="deleteSmsCompanyInfo" parameterType="java.lang.Integer">
        DELETE FROM sms_company_info WHERE id = #{id}
    </delete>
</mapper>