You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

199 lines
6.9 KiB

  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.iformall.mapper.WxCUserFromMapper">
  4. <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxCUserFrom">
  5. <id column="id" jdbcType="BIGINT" property="id" />
  6. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" />
  7. <result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId"/>
  8. <result column="c_user_id" jdbcType="BIGINT" property="cUserId" />
  9. <result column="user_nick_name" jdbcType="VARCHAR" property="userNickName" />
  10. <result column="user_phone" jdbcType="VARCHAR" property="userPhone" />
  11. <result column="scene" jdbcType="VARCHAR" property="scene"/>
  12. <result column="scene_address" jdbcType="VARCHAR" property="sceneAddress"/>
  13. <result column="scene_address_desc" jdbcType="VARCHAR" property="sceneAddressDesc" />
  14. <result column="from_type" jdbcType="INTEGER" property="fromType" />
  15. <result column="from_id" jdbcType="BIGINT" property="fromId" />
  16. <result column="from_name" jdbcType="VARCHAR" property="fromName" />
  17. <result column="is_new_user" jdbcType="INTEGER" property="isNewUser" />
  18. <result column="share_user_type" jdbcType="INTEGER" property="shareUserType" />
  19. <result column="share_user" jdbcType="BIGINT" property="shareUser" />
  20. <result column="share_user_name" jdbcType="VARCHAR" property="shareUserName" />
  21. <result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
  22. <result column="plat" jdbcType="INTEGER" property="plat" />
  23. </resultMap>
  24. <sql id="allColumns">
  25. wcuf.`id`,wcuf.`tenant_id`,wcuf.`parent_tenant_id`,wcuf.`c_user_id`,wcuf.`scene`,wcuf.`scene_address`,
  26. wcuf.`from_type`,wcuf.`from_id`,wcuf.`is_new_user`,wcuf.`share_user_type`,wcuf.`share_user`,wcuf.`create_date`,
  27. wcuf.`plat`
  28. </sql>
  29. <sql id="dynamicWhereConditions">
  30. where 1 = 1
  31. <if test=" null != id ">
  32. and wcuf.`id` = #{id}
  33. </if>
  34. <if test=" null != tenantId and '' != tenantId">
  35. and wcuf.`tenant_id` = #{tenantId}
  36. </if>
  37. <if test=" null != parentTenantId and '' != parentTenantId">
  38. and wcuf.`parent_tenant_id` = #{parentTenantId}
  39. </if>
  40. <if test=" null != cUserId ">
  41. and wcuf.`c_user_id` = #{cUserId}
  42. </if>
  43. <if test=" null != scene and '' != scene">
  44. and wcuf.`scene` = #{scene}
  45. </if>
  46. <if test=" null != sceneAddress and '' != sceneAddress">
  47. and wcuf.`scene_address` = #{sceneAddress}
  48. </if>
  49. <if test=" null != fromType ">
  50. and wcuf.`from_type` = #{fromType}
  51. </if>
  52. <if test=" null != fromId ">
  53. and wcuf.`from_id` = #{fromId}
  54. </if>
  55. <!--<if test=" null != isNewUser ">
  56. and wcuf.`is_new_user` = #{isNewUser}
  57. </if>-->
  58. <if test=" null != shareUserType ">
  59. and wcuf.`share_user_type` = #{shareUserType}
  60. </if>
  61. <if test=" null != shareUser ">
  62. and wcuf.`share_user` = #{shareUser}
  63. </if>
  64. <if test=" null != startDate ">
  65. and wcuf.`create_date` &gt;= #{startDate}
  66. </if>
  67. <if test=" null != endDate">
  68. and wcuf.`create_date` &lt;= #{endDate}
  69. </if>
  70. <if test=" null != plat">
  71. and wcuf.`plat` = #{plat}
  72. </if>
  73. <if test=" null != ids ">
  74. and wcuf.id in
  75. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  76. #{idItem}
  77. </foreach>
  78. </if>
  79. </sql>
  80. <select id="findList" parameterType="com.iformall.domain.po.WxCUserFrom" resultMap="BaseResultMap">
  81. select <include refid="allColumns" />
  82. ,wcu.nick_name user_nick_name
  83. ,wcu.phone user_phone
  84. ,wuc.description scene_address_desc
  85. from wx_c_user_from wcuf
  86. left join wx_c_user wcu on wcu.id = wcuf.c_user_id
  87. left join wx_user_channel wuc on wuc.scene_address = wcuf.scene_address
  88. <include refid="dynamicWhereConditions" />
  89. <if test=" null != isNewUser and isNewUser == 1">
  90. and wcuf.`is_new_user` = 1
  91. </if>
  92. <if test=" null != isNewUser and isNewUser == 0 ">
  93. and wcuf.c_user_id not in (select c_user_id from wx_c_user_from wcuf <include refid="dynamicWhereConditions" /> and wcuf.`is_new_user` = 1)
  94. </if>
  95. order by wcuf.`create_date` desc
  96. <if test=" null != begin ">
  97. limit #{begin}, #{limit}
  98. </if>
  99. </select>
  100. <select id="visits" parameterType="com.iformall.domain.vo.WxCUserFromVo" resultType="com.iformall.domain.vo.WxCUserFromVo">
  101. select a.from_id fromId,a.from_type fromType,a.from_name fromName,a.from_phone fromPhone,IFNULL(a.visits,0) visits,IFNULL(b.reach_user,0) reachUser,IFNULL(c.new_user,0) newUser
  102. from (
  103. select wcuf.from_id,wcuf.from_type,
  104. <if test=" fromType == 2 ">wcubi.nick_name from_name,wcubi.phone from_phone,</if>
  105. <if test=" fromType == 5 ">wm.name from_name,wm.link_phone from_phone,</if>
  106. count(*) visits
  107. from wx_c_user_from wcuf
  108. <if test=" fromType == 2 ">left join wx_c_user_basic_info wcubi on wcuf.from_type = 2 and wcubi.id = wcuf.from_id</if>
  109. <if test=" fromType == 5 ">left join wx_merchant wm on wcuf.from_type = 5 and wm.id = wcuf.from_id</if>
  110. where wcuf.from_type = #{fromType}
  111. <if test=" null != tenantId and '' != tenantId">
  112. and wcuf.`tenant_id` = #{tenantId}
  113. </if>
  114. <if test=" null != parentTenantId and '' != parentTenantId">
  115. and wcuf.`parent_tenant_id` = #{parentTenantId}
  116. </if>
  117. <if test=" null != startDate ">
  118. and wcuf.`create_date` &gt;= #{startDate}
  119. </if>
  120. <if test=" null != endDate">
  121. and wcuf.`create_date` &lt;= #{endDate}
  122. </if>
  123. group by wcuf.from_id
  124. ) a
  125. left join (
  126. select wcuf.from_id,
  127. count(DISTINCT wcuf.c_user_id) reach_user
  128. from wx_c_user_from wcuf
  129. where wcuf.from_type = #{fromType}
  130. <if test=" null != tenantId and '' != tenantId">
  131. and wcuf.`tenant_id` = #{tenantId}
  132. </if>
  133. <if test=" null != parentTenantId and '' != parentTenantId">
  134. and wcuf.`parent_tenant_id` = #{parentTenantId}
  135. </if>
  136. <if test=" null != startDate ">
  137. and wcuf.`create_date` &gt;= #{startDate}
  138. </if>
  139. <if test=" null != endDate">
  140. and wcuf.`create_date` &lt;= #{endDate}
  141. </if>
  142. group by wcuf.from_id
  143. ) b on b.from_id = a.from_id
  144. left join (
  145. select wcuf.from_id,
  146. count(DISTINCT wcuf.c_user_id) new_user
  147. from wx_c_user_from wcuf
  148. where wcuf.from_type = #{fromType}
  149. and wcuf.is_new_user = 1
  150. <if test=" null != tenantId and '' != tenantId">
  151. and wcuf.`tenant_id` = #{tenantId}
  152. </if>
  153. <if test=" null != parentTenantId and '' != parentTenantId">
  154. and wcuf.`parent_tenant_id` = #{parentTenantId}
  155. </if>
  156. <if test=" null != startDate ">
  157. and wcuf.`create_date` &gt;= #{startDate}
  158. </if>
  159. <if test=" null != endDate">
  160. and wcuf.`create_date` &lt;= #{endDate}
  161. </if>
  162. group by wcuf.from_id
  163. ) c on c.from_id = a.from_id
  164. order by a.visits desc
  165. <if test=" null != begin ">
  166. limit #{begin}, #{limit}
  167. </if>
  168. </select>
  169. <select id="findfirstFromId" parameterType="com.iformall.domain.po.WxCUserFrom" resultType="Long">
  170. select wcuf.`from_id`
  171. from wx_c_user_from wcuf
  172. <include refid="dynamicWhereConditions" />
  173. <if test=" null != isNewUser and isNewUser == 1">
  174. and wcuf.`is_new_user` = 1
  175. </if>
  176. order by wcuf.`create_date`
  177. limit 1
  178. </select>
  179. </mapper>