<?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.fjhx.customer.mapper.customer.CustomerFollowRecordsMapper">
    <select id="getPage" resultType="com.fjhx.customer.entity.customer.vo.CustomerFollowRecordsVo">
        SELECT t1.*
        FROM ((SELECT id,
                      amount,
                      create_time `date`,
                      NULL AS     contractCode,
                      code,
                      10   AS     type,
                      NULL AS     content,
                      create_user
               FROM bytesailing_sale.sale_quotation sq
               WHERE sq.buy_corporation_id = #{id}
                 and sq.tenant_id = #{tenantId}
                 and sq.del_flag = 0)
              UNION
              (SELECT id,
                      amount,
                      create_time `date`,
                      CODE AS     contractCode,
                      null as     code,
                      20   AS     type,
                      NULL AS     content,
                      create_user
               FROM bytesailing_sale.contract c
               WHERE c.buy_corporation_id = #{id}
                 and c.tenant_id = #{tenantId}
                 and c.del_flag = 0)
              UNION
              (SELECT id,
                      NULL AS amount,
                      `date`,
                      NULL AS contractCode,
                      null as code,
                      30   AS type,
                      content,
                      create_user
               FROM customer_follow_records cfr
               WHERE cfr.customer_id = #{id})) t1
            ${ew.customSqlSegment}
    </select>

</mapper>
