CustomerLinkmanMapper.xml 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.dayou.mapper.CustomerLinkmanMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.dayou.entity.CustomerLinkman">
  6. <result column="id" property="id" />
  7. <result column="deleted" property="deleted" />
  8. <result column="created" property="created" />
  9. <result column="modified" property="modified" />
  10. <result column="cc_id" property="ccId" />
  11. <result column="name" property="name" />
  12. <result column="mobile" property="mobile" />
  13. <result column="phone" property="phone" />
  14. <result column="sex" property="sex" />
  15. <result column="id_no" property="idNo" />
  16. <result column="wechat_no" property="wechatNo" />
  17. <result column="qq_no" property="qqNo" />
  18. <result column="school" property="school" />
  19. <result column="industry" property="industry" />
  20. <result column="department" property="department" />
  21. <result column="duty" property="duty" />
  22. <result column="terminal" property="terminal" />
  23. <result column="client_manager_id" property="clientManagerId" />
  24. <result column="description" property="description" />
  25. </resultMap>
  26. <!-- 通用查询结果列 -->
  27. <sql id="Base_Column_List">
  28. id,
  29. deleted,
  30. created,
  31. modified,
  32. cc_id, name, mobile, phone, sex, id_no, wechat_no, qq_no, school, industry, department, duty, terminal, client_manager_id, description
  33. </sql>
  34. <sql id="customerPersonalQuerySql">
  35. SELECT linkman.id AS id,
  36. linkman.name AS name,
  37. linkman.mobile AS mobile,
  38. linkman.phone AS phone,
  39. linkman.sex AS sex,
  40. linkman.id_no AS idNo,
  41. linkman.wechat_no AS wechatNo,
  42. linkman.qq_no AS qqNo,
  43. linkman.department AS department,
  44. linkman.duty AS duty,
  45. user.name AS clientManager,
  46. linkman.terminal AS terminal,
  47. COALESCE(vol.cnt, 0) AS orderVolume,
  48. COALESCE(vol.revenue, 0) AS estimatedRevenue,
  49. linkman.created AS created
  50. FROM customer_linkman AS linkman
  51. LEFT JOIN user ON user.id = linkman.client_manager_id
  52. /* 先算 来单量 与 评估值 再一次性 JOIN */
  53. LEFT JOIN (SELECT clientele_contact_id,
  54. SUM(cnt) AS cnt,
  55. SUM(revenue) AS revenue
  56. FROM (
  57. /* assets */
  58. SELECT assets.clientele_contact_id,
  59. COUNT(*) AS cnt,
  60. COALESCE(SUM(order_fund.real_amount), 0) AS revenue
  61. FROM assets
  62. LEFT JOIN order_fund
  63. ON order_fund.business_type = 'ASSET_BUSINESS'
  64. AND order_fund.deleted = 0
  65. AND order_fund.business_id = assets.id
  66. WHERE assets.deleted = 0
  67. AND clientele_type = '个人'
  68. GROUP BY assets.clientele_contact_id
  69. UNION ALL
  70. /* major */
  71. SELECT major.clientele_contact_id,
  72. COUNT(*),
  73. COALESCE(SUM(order_fund.real_amount), 0)
  74. FROM major
  75. LEFT JOIN order_fund
  76. ON order_fund.business_type = 'MAJOR_BUSINESS'
  77. AND order_fund.deleted = 0
  78. AND order_fund.business_id = major.id
  79. WHERE major.deleted = 0
  80. AND clientele_type = '个人'
  81. GROUP BY major.clientele_contact_id
  82. UNION ALL
  83. /* personal */
  84. SELECT personal.clientele_contact_id,
  85. COUNT(*),
  86. COALESCE(SUM(order_fund.real_amount), 0)
  87. FROM personal
  88. LEFT JOIN order_fund
  89. ON order_fund.business_type = 'PERSONAL_BUSINESS'
  90. AND order_fund.deleted = 0
  91. AND order_fund.business_id = personal.id
  92. WHERE personal.deleted = 0
  93. AND clientele_type = '个人'
  94. GROUP BY personal.clientele_contact_id) AS t
  95. GROUP BY clientele_contact_id) AS vol ON vol.clientele_contact_id = linkman.id
  96. WHERE linkman.cc_id = 1
  97. <if test="dto != null">
  98. <if test="dto.keyword != null">
  99. AND (
  100. linkman.name LIKE CONCAT('%',#{dto.keyword},'%') OR
  101. linkman.mobile LIKE CONCAT('%',#{dto.keyword},'%') OR
  102. linkman.phone LIKE CONCAT('%',#{dto.keyword},'%') OR
  103. linkman.wechat_no LIKE CONCAT('%',#{dto.keyword},'%') OR
  104. linkman.qq_no LIKE CONCAT('%',#{dto.keyword},'%')
  105. )
  106. </if>
  107. <if test="dto.terminal != null">
  108. AND linkman.terminal = #{dto.terminal}
  109. </if>
  110. <if test="dto.clientManagerId != null">
  111. AND linkman.client_manager_id = #{dto.clientManagerId}
  112. </if>
  113. </if>
  114. ORDER BY COALESCE(vol.revenue, 0) DESC
  115. </sql>
  116. <!--分页查询个人客户列表-->
  117. <select id="getCustomerPersonalPage" resultType="com.dayou.vo.CustomerPersonalVO">
  118. <include refid="customerPersonalQuerySql" />
  119. </select>
  120. <!--导出个人客户列表-->
  121. <select id="exportCustomerPersonalPage" resultType="com.dayou.vo.CustomerPersonalVO">
  122. <include refid="customerPersonalQuerySql" />
  123. </select>
  124. </mapper>