<?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.storlead.sales.mapper.customer.BusinessMapper">

        <!-- 通用查询映射结果 -->
        <resultMap id="BaseResultMap" type="com.storlead.sales.pojo.entity.customer.BusinessEntity">
                    <id column="id" property="id" />
                    <id column="title" property="title" />
                <result column="create_time" property="createTime" />
                <result column="update_time" property="updateTime" />
                <result column="is_delete" property="isDelete" />
                <result column="enabled" property="enabled" />
                <result column="create_by" property="createBy" />
                <result column="owner_by" property="ownerBy" />
                <result column="update_by" property="updateBy" />
                <result column="sort" property="sort" />
                    <result column="customer_id" property="customerId" />
                    <result column="liaison_id" property="liaisonId" />
                    <result column="estimated_sales_amount" property="estimatedSalesAmount" />
                    <result column="expected_signing_date" property="expectedSigningDate" />
                    <result column="sales_phase_dict_value" property="salesPhaseDictValue" />
                    <result column="business_type_dict_value" property="businessTypeDictValue" />
                    <result column="transaction_probability_dict_value" property="transactionProbabilityDictValue" />
                    <result column="sources_of_business_dict_value" property="sourcesOfBusinessDictValue" />
                    <result column="geted_date" property="getedDate" />
                    <result column="remark" property="remark" />
        </resultMap>

        <!-- 通用查询结果列 -->
        <sql id="Base_Column_List">
                create_time,
                update_time,
                is_delete,
                enabled,
                create_by,
                owner_by,
                update_by,
                sort,
            id, customer_id, liaison_id, estimated_sales_amount, expected_signing_date, sales_phase_dict_value, business_type_dict_value, transaction_probability_dict_value, sources_of_business_dict_value, geted_date, remark
        </sql>
    <update id="replaceCollaborator">
        UPDATE business
        SET collaborator = TRIM(BOTH ',' FROM REPLACE(
                CONCAT(',', IFNULL(collaborator, ''), ','),
                CONCAT(',', #{customer.oldOwnerBy}, ','),
                CONCAT(',', #{customer.newOwnerBy}, ',')
            ))
        WHERE stage != '4'
           AND FIND_IN_SET(#{customer.oldOwnerBy}, IFNULL(collaborator, '')) > 0
    </update>

</mapper>
