123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <?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.dayou.mapper.CustomerLinkmanMapper">
- <!-- 通用查询映射结果 -->
- <resultMap id="BaseResultMap" type="com.dayou.entity.CustomerLinkman">
- <result column="id" property="id" />
- <result column="deleted" property="deleted" />
- <result column="created" property="created" />
- <result column="modified" property="modified" />
- <result column="cc_id" property="ccId" />
- <result column="name" property="name" />
- <result column="mobile" property="mobile" />
- <result column="phone" property="phone" />
- <result column="sex" property="sex" />
- <result column="id_no" property="idNo" />
- <result column="wechat_no" property="wechatNo" />
- <result column="qq_no" property="qqNo" />
- <result column="school" property="school" />
- <result column="industry" property="industry" />
- <result column="department" property="department" />
- <result column="duty" property="duty" />
- <result column="terminal" property="terminal" />
- <result column="client_manager_id" property="clientManagerId" />
- <result column="description" property="description" />
- </resultMap>
- <!-- 通用查询结果列 -->
- <sql id="Base_Column_List">
- id,
- deleted,
- created,
- modified,
- cc_id, name, mobile, phone, sex, id_no, wechat_no, qq_no, school, industry, department, duty, terminal, client_manager_id, description
- </sql>
- <sql id="customerPersonalQuerySql">
- SELECT linkman.id AS id,
- linkman.name AS name,
- linkman.mobile AS mobile,
- linkman.phone AS phone,
- linkman.sex AS sex,
- linkman.id_no AS idNo,
- linkman.wechat_no AS wechatNo,
- linkman.qq_no AS qqNo,
- linkman.department AS department,
- linkman.duty AS duty,
- user.name AS clientManager,
- linkman.terminal AS terminal,
- COALESCE(vol.cnt, 0) AS orderVolume,
- COALESCE(vol.revenue, 0) AS estimatedRevenue,
- linkman.created AS created
- FROM customer_linkman AS linkman
- LEFT JOIN user ON user.id = linkman.client_manager_id
- /* 先算 来单量 与 评估值 再一次性 JOIN */
- LEFT JOIN (SELECT clientele_contact_id,
- SUM(cnt) AS cnt,
- SUM(revenue) AS revenue
- FROM (
- /* assets */
- SELECT assets.clientele_contact_id,
- COUNT(*) AS cnt,
- COALESCE(SUM(order_fund.real_amount), 0) AS revenue
- FROM assets
- LEFT JOIN order_fund
- ON order_fund.business_type = 'ASSET_BUSINESS'
- AND order_fund.deleted = 0
- AND order_fund.business_id = assets.id
- WHERE assets.deleted = 0
- AND clientele_type = '个人'
- GROUP BY assets.clientele_contact_id
- UNION ALL
- /* major */
- SELECT major.clientele_contact_id,
- COUNT(*),
- COALESCE(SUM(order_fund.real_amount), 0)
- FROM major
- LEFT JOIN order_fund
- ON order_fund.business_type = 'MAJOR_BUSINESS'
- AND order_fund.deleted = 0
- AND order_fund.business_id = major.id
- WHERE major.deleted = 0
- AND clientele_type = '个人'
- GROUP BY major.clientele_contact_id
- UNION ALL
- /* personal */
- SELECT personal.clientele_contact_id,
- COUNT(*),
- COALESCE(SUM(order_fund.real_amount), 0)
- FROM personal
- LEFT JOIN order_fund
- ON order_fund.business_type = 'PERSONAL_BUSINESS'
- AND order_fund.deleted = 0
- AND order_fund.business_id = personal.id
- WHERE personal.deleted = 0
- AND clientele_type = '个人'
- GROUP BY personal.clientele_contact_id) AS t
- GROUP BY clientele_contact_id) AS vol ON vol.clientele_contact_id = linkman.id
- WHERE linkman.cc_id = 1
- <if test="dto != null">
- <if test="dto.keyword != null">
- AND (
- linkman.name LIKE CONCAT('%',#{dto.keyword},'%') OR
- linkman.mobile LIKE CONCAT('%',#{dto.keyword},'%') OR
- linkman.phone LIKE CONCAT('%',#{dto.keyword},'%') OR
- linkman.wechat_no LIKE CONCAT('%',#{dto.keyword},'%') OR
- linkman.qq_no LIKE CONCAT('%',#{dto.keyword},'%')
- )
- </if>
- <if test="dto.terminal != null">
- AND linkman.terminal = #{dto.terminal}
- </if>
- <if test="dto.clientManagerId != null">
- AND linkman.client_manager_id = #{dto.clientManagerId}
- </if>
- </if>
- ORDER BY COALESCE(vol.revenue, 0) DESC
- </sql>
- <!--分页查询个人客户列表-->
- <select id="getCustomerPersonalPage" resultType="com.dayou.vo.CustomerPersonalVO">
- <include refid="customerPersonalQuerySql" />
- </select>
- <!--导出个人客户列表-->
- <select id="exportCustomerPersonalPage" resultType="com.dayou.vo.CustomerPersonalVO">
- <include refid="customerPersonalQuerySql" />
- </select>
- </mapper>
|