<?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.ruoyi.project.business.mapper.TcAccountMapper">
    
    <resultMap type="TcAccount" id="TcAccountResult">
        <result property="accountId"    column="account_id"    />
        <result property="accountNo"    column="account_no"    />
        <result property="accountName"    column="account_name"    />
        <result property="countryId"    column="country_id"    />
        <result property="countryName"    column="countryName"    />
        <result property="area"    column="area"    />
        <result property="areaId"    column="area_id"    />
        <result property="areaName"    column="areaName"    />
        <result property="origin"    column="origin"    />
        <result property="phone"    column="phone"    />
        <result property="email"    column="email"    />
        <result property="address"    column="address"    />
        <result property="sector"    column="sector"    />
        <result property="registeredCapital"    column="registered_capital"    />
        <result property="level"    column="level"    />
        <result property="levelName"    column="levelName"    />
        <result property="startTime"    column="start_time"    />
        <result property="owner"    column="owner"    />
        <result property="ownerName"    column="ownerName"    />
        <result property="ownerAgent"    column="owner_agent"    />
        <result property="ownerAgentName"    column="ownerAgentName"    />
        <result property="status"    column="status"    />
        <result property="statusName"    column="statusName"    />
        <result property="type"    column="type"    />
        <result property="typeName"    column="typeName"    />
        <result property="companyType"    column="company_type"    />
        <result property="companyTypeName"    column="companyTypeName"    />
        <result property="accountDesc"    column="account_desc"    />
        <result property="orderStatus"    column="order_status"    />
        <result property="accountGroup"    column="account_group"    />
        <result property="intentionalProduct"    column="intentional_product"    />
        <result property="intentionalProductName"    column="intentionalProductName"    />
        <result property="segment"    column="segment"    />
        <result property="segmentName"    column="segmentName"    />
        <result property="companyWebsite"    column="company_website"    />
        <result property="background"    column="background"    />
        <result property="beginYear"    column="begin_year"    />
        <result property="permissionChar"    column="permission_char"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="remark"    column="remark"    />
        <result property="file"    column="file"    />
        <result property="agentName"    column="agentName"    />
        <result property="followDesc"    column="follow_desc"    />
        <result property="followTime"    column="follow_time"    />
        <result property="followPerson"    column="follow_person"    />
    </resultMap>

    <resultMap type="TcAccountForRelated" id="TcAccountResultForRelated">
        <result property="accountId"    column="account_id"    />
        <result property="accountNo"    column="account_no"    />
        <result property="accountName"    column="account_name"    />
        <result property="countryId"    column="country_id"    />
        <result property="countryName"    column="country_name"    />
        <result property="areaName"    column="area_name"    />
        <result property="area"    column="area"    />
        <result property="areaId"    column="area_id"    />
        <result property="origin"    column="origin"    />
        <result property="phone"    column="phone"    />
        <result property="email"    column="email"    />
        <result property="address"    column="address"    />
        <result property="sector"    column="sector"    />
        <result property="registeredCapital"    column="registered_capital"    />
        <result property="level"    column="level"    />
        <result property="startTime"    column="start_time"    />
        <result property="owner"    column="owner"    />
        <result property="status"    column="status"    />
        <result property="type"    column="type"    />
        <result property="accountDesc"    column="account_desc"    />
        <result property="orderStatus"    column="order_status"    />
        <result property="accountGroup"    column="account_group"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectTcAccountVo">
        select account_id, account_no, account_name, country_id, area, area_id, origin, phone, email,
               address, sector, registered_capital, level, start_time, owner, owner_agent, status,
               type, company_type, account_desc, order_status, account_group, intentional_product,
               segment, company_website, background, begin_year, permission_char, del_flag,
               create_time, create_by, update_time, update_by, remark
        from tc_account
    </sql>

    <sql id="selectTcAccountList">
        select a.account_id, a.account_no, a.account_name, a.country_id, a.area, a.area_id, a.origin,
               a.phone, a.email, a.address, a.sector, a.registered_capital, a.level, a.start_time,
               a.owner, a.owner_agent, a.status, a.type, a.company_type, a.account_desc, a.order_status,
               a.account_group, a.intentional_product, a.segment, a.company_website, a.background, a.begin_year,
               a.permission_char, a.del_flag, a.create_time, a.create_by, a.update_time, a.update_by, a.remark,
               f.follow_desc, f.follow_time, su.nick_name as follow_person, u.nick_name as ownerName,
               IF(a.owner_agent = 0, 'common.head', ta.agent_name) as ownerAgentName,
               CASE #{language}
                   WHEN 'chinese' THEN c.country_name
                   WHEN 'english' THEN c.country_nameUS
                   WHEN 'russia' THEN c.country_nameRU
                   WHEN 'spanish' THEN c.country_nameES
                   END AS countryName,
               CASE #{language}
                   WHEN 'chinese' THEN area.area_name
                   WHEN 'english' THEN area.area_nameUS
                   WHEN 'russia' THEN area.area_nameRU
                   WHEN 'spanish' THEN area.area_nameES
                   END AS areaName
        from tc_account a
        left join tb_area area on area.area_id = a.area_id
        left join tb_country c on a.country_id = c.country_id
        left join (select business_id, follow_desc, follow_time, create_by from tc_follow
        where follow_type = '1' and del_flag = '0' order by follow_time desc) f on f.business_id = a.account_id
        left join sys_user u on u.user_id = a.owner
        left join sys_user su on su.user_id = f.create_by
        left join tb_agent ta on ta.agent_id = a.owner_agent
        inner join (SELECT p.premession_char FROM (SELECT @premessionStr:= #{permissionChar} p) param , getpremessionview_chars p
        ) permission on permission.premession_char = a.permission_char
    </sql>

    <sql id="selectTcAccountListExport">
        select a.account_id, a.account_no, a.account_name, a.country_id, a.area, a.area_id, a.origin,
               a.phone, a.email, a.address, a.sector, a.registered_capital, a.level, a.start_time,
               a.owner, a.owner_agent, a.status, a.type, a.company_type, a.account_desc, a.order_status,
               a.account_group, a.intentional_product, a.segment, a.company_website, a.background, a.begin_year,
               a.permission_char, a.del_flag, a.create_time, a.create_by, a.update_time, a.update_by, a.remark,
               f.follow_desc, f.follow_time, su.nick_name as follow_person, u.nick_name as ownerName,
               IF(a.owner_agent = 0, (CASE #{language}
                  WHEN 'chinese' THEN '总部'
                  WHEN 'english' THEN 'headquarters'
                  WHEN 'russia' THEN 'Штаб - квартира'
                  WHEN 'spanish' THEN 'Sede' END), agent.agent_name) as ownerAgentName,
               CASE #{language}
                   WHEN 'chinese' THEN c.country_name
                   WHEN 'english' THEN c.country_nameUS
                   WHEN 'russia' THEN c.country_nameRU
                   WHEN 'spanish' THEN c.country_nameES
                   END AS countryName,
               CASE #{language}
                   WHEN 'chinese' THEN ta.area_name
                   WHEN 'english' THEN ta.area_nameUS
                   WHEN 'russia' THEN ta.area_nameRU
                   WHEN 'spanish' THEN ta.area_nameES
                   END AS areaName,
               CASE #{language}
                   WHEN 'chinese' THEN t1.dict_label
                   WHEN 'english' THEN t1.dict_labelUS
                   WHEN 'russia' THEN t1.dict_labelRU
                   WHEN 'spanish' THEN t1.dict_labelES
                   END AS levelName,
               CASE #{language}
                   WHEN 'chinese' THEN t2.dict_label
                   WHEN 'english' THEN t2.dict_labelUS
                   WHEN 'russia' THEN t2.dict_labelRU
                   WHEN 'spanish' THEN t2.dict_labelES
                   END AS typeName,
               CASE #{language}
                   WHEN 'chinese' THEN t3.dict_label
                   WHEN 'english' THEN t3.dict_labelUS
                   WHEN 'russia' THEN t3.dict_labelRU
                   WHEN 'spanish' THEN t3.dict_labelES
                   END AS statusName,
               CASE #{language}
                   WHEN 'chinese' THEN t4.dict_label
                   WHEN 'english' THEN t4.dict_labelUS
                   WHEN 'russia' THEN t4.dict_labelRU
                   WHEN 'spanish' THEN t4.dict_labelES
                   END AS companyTypeName,
               CASE #{language}
                   WHEN 'chinese' THEN t5.dict_label
                   WHEN 'english' THEN t5.dict_labelUS
                   WHEN 'russia' THEN t5.dict_labelRU
                   WHEN 'spanish' THEN t5.dict_labelES
                   END AS intentionalProductName,
               CASE #{language}
                   WHEN 'chinese' THEN t6.dict_label
                   WHEN 'english' THEN t6.dict_labelUS
                   WHEN 'russia' THEN t6.dict_labelRU
                   WHEN 'spanish' THEN t6.dict_labelES
                   END AS segmentName
        from tc_account a
                 left join tb_area ta on ta.area_id = a.area_id
                 left join tb_country c on a.country_id = c.country_id
                 left join (select business_id, follow_desc, follow_time, create_by from tc_follow
                 where follow_type = '1' and del_flag = '0' order by follow_time desc) f on f.business_id = a.account_id
                 left join sys_user u on u.user_id = a.owner
                 left join sys_user su on su.user_id = f.create_by
                 left join tb_agent agent on agent.agent_id = a.owner_agent
                 left join sys_dict_data t1 on t1.dict_type = 'account_level' and a.level = t1.dict_value
                 left join sys_dict_data t2 on t2.dict_type = 'account_type' and a.type = t2.dict_value
                 left join sys_dict_data t3 on t3.dict_type = 'account_status' and a.status = t3.dict_value
                 left join sys_dict_data t4 on t4.dict_type = 'company_type' and a.status = t4.dict_value
                 left join sys_dict_data t5 on t5.dict_type = 'intentional_product' and a.status = t5.dict_value
                 left join sys_dict_data t6 on t6.dict_type = 'project_type' and a.status = t6.dict_value
                 inner join (SELECT p.premession_char FROM (SELECT @premessionStr:= #{permissionChar} p) param , getpremessionview_chars p
        ) permission on permission.premession_char = a.permission_char
    </sql>

    <sql id="whereSql">
        <where>
            <if test="accountNo != null  and accountNo != ''"> and a.account_no like concat('%',#{accountNo},'%') escape '/'</if>
            <if test="accountName != null  and accountName != ''"> and a.account_name like concat('%',#{accountName},'%') escape '/'</if>
            <if test="areaId != null and areaId.size() > 0">
                and a.area_id in
                <foreach collection="areaId" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="countryId != null and countryId.size() > 0">
                and a.country_id in
                <foreach collection="countryId" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="type != null and type.size() > 0">
                and a.type in
                <foreach collection="type" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="level != null and level.size() > 0">
                and a.level in
                <foreach collection="level" item="item" separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
            <if test="companyType != null and companyType.size() > 0">
                and a.company_type in
                <foreach collection="companyType" item="item" separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
            <if test="status != null and status.size() > 0">
                and a.status in
                <foreach collection="status" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="intentionalProduct != null and intentionalProduct.size() > 0">
                and a.intentional_product in
                <foreach collection="intentionalProduct" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="ownerName != null  and ownerName != ''">and u.nick_name like concat('%',#{ownerName},'%') escape '/'</if>
            <if test="segment != null and segment.size() > 0">
                and a.segment in
                <foreach collection="segment" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="ownerAgent != null and ownerAgent.size() > 0">
                and a.owner_agent in
                <foreach collection="ownerAgent" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="loginUserId != null  and loginUserId != ''">
                and (a.permission_char &lt;&gt; #{permission} or a.owner = #{loginUserId})
            </if>
            <if test="ids != null and ids.size() > 0">
                and a.account_id in
                <foreach collection="ids" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
            and a.del_flag = '0'
        </where>
        group by a.account_id
        order by a.account_id desc
    </sql>

    <select id="selectTcAccountList" parameterType="com.ruoyi.project.business.domain.vo.selectParam.AccountParam" resultMap="TcAccountResult">
        <include refid="selectTcAccountList"/>
        <include refid="whereSql"/>
    </select>

    <select id="selectTcAccountListExport" parameterType="com.ruoyi.project.business.domain.vo.selectParam.AccountParam" resultMap="TcAccountResult">
        <include refid="selectTcAccountListExport"/>
        <include refid="whereSql"/>
    </select>

    <select id="selectAccountListByLoginId" parameterType="java.lang.Long" resultMap="TcAccountResultForRelated">
        SELECT
            t1.account_id,
            t1.account_no,
            t1.account_name,
            t1.country_id,
            area,
            origin,
            phone,
            email,
            address,
            sector,
            registered_capital,
            LEVEL,
            start_time,
            OWNER,
            CASE #{language}
                WHEN 'english' THEN tb1.country_nameUS
                WHEN 'russia' THEN tb1.country_nameRU
                WHEN 'spanish' THEN tb1.country_nameES
                ELSE tb1.country_name
            END AS country_name
        FROM
        tc_account t1
        left join tb_country tb1 on tb1.country_id = t1.country_id
        WHERE  t1.del_flag = 0 and t1.OWNER = #{loginId}
    </select>

    <select id="selectAccountListByAccountId" parameterType="TcAccountForRelated" resultMap="TcAccountResultForRelated">
        SELECT
            t1.account_id,
            t1.account_no,
            t1.account_name,
            t1.country_id,
            area,
            t1.area_id,
            origin,
            phone,
            email,
            address,
            sector,
            registered_capital,
            LEVEL,
            start_time,
            OWNER,
            CASE #{language}
                WHEN 'english' THEN tb2.area_nameUS
                WHEN 'russia' THEN tb2.area_nameRU
                WHEN 'spanish' THEN tb2.area_nameES
                ELSE tb2.area_name
            END AS area_name,
            CASE #{language}
                WHEN 'english' THEN tb1.country_nameUS
                WHEN 'russia' THEN tb1.country_nameRU
                WHEN 'spanish' THEN tb1.country_nameES
                ELSE tb1.country_name
            END AS country_name
        FROM
            tc_account t1
            LEFT JOIN tb_country tb1 ON tb1.country_id = t1.country_id
            LEFT JOIN tb_area tb2 ON tb2.area_id = t1.area_id
        WHERE 1 = 1
        <if test="accountId != null  and accountId != ''"> and t1.account_id = #{accountId} </if>
    </select>

    <select id="selectAccountListByQuery" parameterType="TcAccountForRelated" resultMap="TcAccountResultForRelated">
        SELECT
            t1.account_id,
            t1.account_no,
            t1.account_name,
            t1.country_id,
            area,
            origin,
            phone,
            email,
            address,
            sector,
            registered_capital,
            LEVEL,
            start_time,
            OWNER,
            CASE #{language}
                WHEN 'english' THEN tb2.area_nameUS
                WHEN 'russia' THEN tb2.area_nameRU
                WHEN 'spanish' THEN tb2.area_nameES
                ELSE tb2.area_name
            END AS area_name,
            CASE #{language}
                WHEN 'english' THEN tb1.country_nameUS
                WHEN 'russia' THEN tb1.country_nameRU
                WHEN 'spanish' THEN tb1.country_nameES
                ELSE tb1.country_name
            END AS country_name
        FROM
            tc_account t1
            LEFT JOIN tb_country tb1 on tb1.country_id = t1.country_id
            LEFT JOIN tb_area tb2 ON tb2.area_id = t1.area_id
        WHERE  t1.del_flag = 0 and t1.OWNER = #{loginId}
        <if test="query != null  and query != ''">
            and  (
            t1.account_no like concat('%',#{query},'%') or
            t1.account_name like concat('%',#{query},'%') or
            tb1.country_name like concat('%',#{query},'%') or
            tb1.country_nameUS like concat('%',#{query},'%') or
            tb1.country_nameRU like concat('%',#{query},'%') or
            tb1.country_nameES like concat('%',#{query},'%') or
            tb2.area_name like concat('%',#{query},'%') or
            tb2.area_nameUS like concat('%',#{query},'%') or
            tb2.area_nameRU like concat('%',#{query},'%') or
            tb2.area_nameES like concat('%',#{query},'%')
            )
        </if>
    </select>
    
    <select id="selectTcAccountByAccountId" parameterType="Long" resultMap="TcAccountResult">
        select a.*, IF(a.owner_agent = 0, 'common.head', b.agent_name) AS agentName
        from tc_account a
                 left join tb_agent b on b.agent_id = a.owner_agent
        where a.account_id = #{accountId}
    </select>

    <select id="selectCountByAccountName" resultType="java.lang.Integer">
        select count(1) from tc_account where account_name = #{accountName}
        and permission_char = #{permissionChar} and del_flag = '0'
        <if test="accountId != null"> and account_id != #{accountId}</if>
    </select>
    <select id="selectSimpleByCreateTime" resultType="com.ruoyi.project.business.domain.TcAccount">
        select Temp.*
        from (select create_time, permission_char
        from tc_account
        where del_flag = 0
        and create_time BETWEEN #{startDate} AND #{endDate}) Temp
        inner join (SELECT p.premession_char
        FROM (SELECT @premessionStr :=
        #{permissionChar}
        p) param,
        getpremessionview p) permission
        on permission.premession_char = Temp.permission_char
    </select>

    <select id="selectCountByCountryIds" resultType="java.lang.Integer">
        select count(1) from tc_account where del_flag = '0' and country_id in
        <foreach item="countryId" collection="countryIds" open="(" separator="," close=")">
            #{countryId}
        </foreach>
    </select>

    <select id="selectCountByAreaIds" resultType="java.lang.Integer">
        select count(1) from tc_account where del_flag = '0' and area_id in
        <foreach item="areaId" collection="areaIds" open="(" separator="," close=")">
            #{areaId}
        </foreach>
    </select>

    <select id="selectByPermissionChar" resultMap="TcAccountResult">
        <include refid="selectTcAccountVo"/>
        where del_flag = '0' and permission_char = #{permissionChar}
    </select>

    <select id="listRemote" resultMap="TcAccountResult">
        select a.* from tc_account a
        inner join (SELECT p.premession_char FROM (SELECT @premessionStr:= #{permissionChar} p) param , getpremessionview p
        ) permission on permission.premession_char = a.permission_char
        where a.del_flag = '0'
        <if test="query != null  and query != ''">
            and (a.account_no like concat('%',#{query},'%') or a.account_name like concat('%',#{query},'%'))
        </if>
        and a.owner = #{userId}
        order by a.account_id desc
    </select>
    <select id="existUserByAgentIds" resultType="java.lang.Integer">
        select 1 from tc_account where owner_agent in
        <foreach item="agentId" collection="array" open="(" separator="," close=")">
            #{agentId}
        </foreach>
        and del_flag = '0' limit 1
    </select>

    <insert id="insertTcAccount" parameterType="TcAccount" useGeneratedKeys="true" keyProperty="accountId">
        insert into tc_account
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="accountNo != null">account_no,</if>
            <if test="accountName != null">account_name,</if>
            <if test="countryId != null">country_id,</if>
            <if test="area != null">area,</if>
            <if test="areaId != null">area_id,</if>
            <if test="origin != null">origin,</if>
            <if test="phone != null">phone,</if>
            <if test="email != null">email,</if>
            <if test="address != null">address,</if>
            <if test="sector != null">sector,</if>
            <if test="registeredCapital != null">registered_capital,</if>
            <if test="level != null">level,</if>
            <if test="startTime != null">start_time,</if>
            <if test="owner != null">owner,</if>
            <if test="ownerAgent != null">owner_agent,</if>
            <if test="status != null">status,</if>
            <if test="type != null">type,</if>
            <if test="companyType != null">company_type,</if>
            <if test="accountDesc != null">account_desc,</if>
            <if test="orderStatus != null">order_status,</if>
            <if test="accountGroup != null">account_group,</if>
            <if test="intentionalProduct != null">intentional_product,</if>
            <if test="segment != null">segment,</if>
            <if test="companyWebsite != null">company_website,</if>
            <if test="background != null">background,</if>
            <if test="beginYear != null">begin_year,</if>
            <if test="permissionChar != null">permission_char,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="accountNo != null">#{accountNo},</if>
            <if test="accountName != null">#{accountName},</if>
            <if test="countryId != null">#{countryId},</if>
            <if test="area != null">#{area},</if>
            <if test="areaId != null">#{areaId},</if>
            <if test="origin != null">#{origin},</if>
            <if test="phone != null">#{phone},</if>
            <if test="email != null">#{email},</if>
            <if test="address != null">#{address},</if>
            <if test="sector != null">#{sector},</if>
            <if test="registeredCapital != null">#{registeredCapital},</if>
            <if test="level != null">#{level},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="owner != null">#{owner},</if>
            <if test="ownerAgent != null">#{ownerAgent},</if>
            <if test="status != null">#{status},</if>
            <if test="type != null">#{type},</if>
            <if test="companyType != null">#{companyType},</if>
            <if test="accountDesc != null">#{accountDesc},</if>
            <if test="orderStatus != null">#{orderStatus},</if>
            <if test="accountGroup != null">#{accountGroup},</if>
            <if test="intentionalProduct != null">#{intentionalProduct},</if>
            <if test="segment != null">#{segment},</if>
            <if test="companyWebsite != null">#{companyWebsite},</if>
            <if test="background != null">#{background},</if>
            <if test="beginYear != null">#{beginYear},</if>
            <if test="permissionChar != null">#{permissionChar},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <insert id="batchInsertTcAccount" parameterType="java.util.List">
        INSERT INTO tc_account
        (account_no,
        account_name,
        country_id,
        area,
        area_id,
        origin,
        phone,
        email,
        address,
        sector,
        registered_capital,
        level,
        start_time,
        owner,
        owner_agent,
        status,
        type,
        company_type,
        account_desc,
        order_status,
        account_group,
        intentional_product,
        segment,
        company_website,
        background,
        begin_year,
        permission_char,
        del_flag,
        create_time,
        create_by,
        update_time,
        update_by,
        remark)
        values
        <foreach collection="tcAccountList" item="item" index="index" separator=",">
            (#{item.accountNo},
            #{item.accountName},
            #{item.countryId},
            #{item.area},
            #{item.areaId},
            #{item.origin},
            #{item.phone},
            #{item.email},
            #{item.address},
            #{item.sector},
            #{item.registeredCapital},
            #{item.level},
            #{item.startTime},
            #{item.owner},
            #{item.ownerAgent},
            #{item.status},
            #{item.type},
            #{item.companyType},
            #{item.accountDesc},
            #{item.orderStatus},
            #{item.accountGroup},
            #{item.intentionalProduct},
            #{item.segment},
            #{item.companyWebsite},
            #{item.background},
            #{item.beginYear},
            #{item.permissionChar},
            #{item.delFlag},
            #{item.createTime},
            #{item.createBy},
            #{item.updateTime},
            #{item.updateBy},
            #{item.remark})
        </foreach>
    </insert>

    <update id="updateTcAccount" parameterType="TcAccount">
        update tc_account
        <trim prefix="SET" suffixOverrides=",">
            <if test="accountNo != null">account_no = #{accountNo},</if>
            <if test="accountName != null">account_name = #{accountName},</if>
            <if test="countryId != null">country_id = #{countryId},</if>
            <if test="area != null">area = #{area},</if>
            <if test="areaId != null">area_id = #{areaId},</if>
            <if test="origin != null">origin = #{origin},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="email != null">email = #{email},</if>
            <if test="address != null">address = #{address},</if>
            <if test="sector != null">sector = #{sector},</if>
            <if test="registeredCapital != null">registered_capital = #{registeredCapital},</if>
            <if test="level != null">level = #{level},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="owner != null">owner = #{owner},</if>
            <if test="ownerAgent != null">owner_agent = #{ownerAgent},</if>
            <if test="status != null">status = #{status},</if>
            <if test="type != null">type = #{type},</if>
            <if test="companyType != null">company_type = #{companyType},</if>
            <if test="accountDesc != null">account_desc = #{accountDesc},</if>
            <if test="orderStatus != null">order_status = #{orderStatus},</if>
            <if test="accountGroup != null">account_group = #{accountGroup},</if>
            <if test="intentionalProduct != null">intentional_product = #{intentionalProduct},</if>
            <if test="segment != null">segment = #{segment},</if>
            <if test="companyWebsite != null">company_website = #{companyWebsite},</if>
            <if test="background != null">background = #{background},</if>
            <if test="beginYear != null">begin_year = #{beginYear},</if>
            <if test="permissionChar != null">permission_char = #{permissionChar},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where account_id = #{accountId}
    </update>

    <update id="deleteTcAccountByAccountId" parameterType="Long">
        update tc_account set del_flag = '1' where account_id = #{accountId}
    </update>

    <update id="deleteTcAccountByAccountIds" parameterType="String">
        update tc_account set del_flag = '1' where account_id in
        <foreach item="accountId" collection="array" open="(" separator="," close=")">
            #{accountId}
        </foreach>
    </update>
</mapper>