CorpUserFollowRelationMapper.xml 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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.cyksj.mapper.corp.CorpUserFollowRelationMapper">
  4. <select id="selectCorpCustomers" resultType="java.lang.String">
  5. select group_concat(cf.name)
  6. from (select id
  7. from corp_user
  8. where unionid = #{unionid} limit 1) cu
  9. inner join corp_user_auth ca on ca.corp_user_id = cu.id and wx_corp_id = #{wxCorpId}
  10. inner join corp_user_follow_relation cfr on cfr.corp_user_id = ca.external_userid
  11. inner join corp_follow cf on cf.userid = cfr.follow_id and cf.wx_corp_id = #{wxCorpId}
  12. </select>
  13. <select id="selectCorpUserFollowRelationByTagIds" resultType="com.cyksj.model.dto.CorpUserFollowRelationDto">
  14. select cufr.corp_user_id,
  15. any_value(cufr.follow_id) as follow_id,
  16. any_value(cu.user_id) as user_id
  17. from (select
  18. relation_id from `corp_user_tag`
  19. where tag_id in
  20. <foreach collection="list" item="item" open="(" separator="," close=")">
  21. #{item}
  22. </foreach>) cut left join `corp_user_follow_relation` cufr on cufr.id = cut.relation_id
  23. left join `corp_user_auth` ca on ca.external_userid = cufr.corp_user_id
  24. left join `corp_user` cu on cu.id = ca.corp_user_id
  25. where cufr.wx_corp_id = #{wxCorpId}
  26. <if test="joinStartTime != null">
  27. and cu.created_time >= #{joinStartTime}
  28. </if>
  29. <if test="joinEndTime != null">
  30. and cu.created_time &lt; #{joinEndTime}
  31. </if>
  32. <choose>
  33. <when test="userScope == 2">
  34. and cu.user_id != 0
  35. </when>
  36. <when test="userScope == 3">
  37. and cu.user_id = 0
  38. </when>
  39. </choose>
  40. <choose>
  41. <when test="consumerScope == 2">
  42. and exists (select id from order_don o where o.user_id != 0 and o.user_id = cu.user_id and status not in
  43. ('close','noPayment','refund') limit 1)
  44. </when>
  45. <when test="consumerScope == 3">
  46. and not exists (select id from order_don o where o.user_id != 0 and o.user_id = cu.user_id and status
  47. not in
  48. ('close','noPayment','refund') limit 1)
  49. </when>
  50. </choose>
  51. and ca.wx_corp_id = #{wxCorpId}
  52. <if test="followIds != null and followIds.size() > 0">
  53. and cufr.follow_id in
  54. <foreach collection="followIds" item="item" open="(" separator="," close=")">
  55. #{item}
  56. </foreach>
  57. </if>
  58. group by cufr.corp_user_id
  59. </select>
  60. <select id="selectCorpUserFollowRelation" resultType="com.cyksj.model.dto.CorpUserFollowRelationDto">
  61. select cufr.corp_user_id,
  62. any_value(cufr.follow_id) as follow_id,
  63. any_value(cu.user_id) as user_id
  64. from `corp_user_follow_relation` cufr left join `corp_user_auth` ca on ca.external_userid = cufr.corp_user_id
  65. left join `corp_user` cu on cu.id = ca.corp_user_id
  66. where cufr.wx_corp_id = #{wxCorpId}
  67. and ca.wx_corp_id = #{wxCorpId}
  68. <if test="followIds != null and followIds.size() > 0">
  69. and cufr.follow_id in
  70. <foreach collection="followIds" item="item" open="(" separator="," close=")">
  71. #{item}
  72. </foreach>
  73. </if>
  74. group by cufr.corp_user_id
  75. </select>
  76. <select id="selectCorpUserNotUnderTagIds" resultType="com.cyksj.model.dto.CorpUserFollowRelationDto">
  77. select cufr.corp_user_id,
  78. any_value(cufr.follow_id) as follow_id,
  79. any_value(cu.user_id) as user_id
  80. from corp_user cu inner join corp_user_auth ca on ca.corp_user_id = cu.id
  81. and ca.wx_corp_id = #{wxCorpId}
  82. <if test="joinStartTime != null">
  83. and cu.created_time >= #{joinStartTime}
  84. </if>
  85. <if test="joinEndTime != null">
  86. and cu.created_time &lt; #{joinEndTime}
  87. </if>
  88. <choose>
  89. <when test="userScope == 2">
  90. and cu.user_id != 0
  91. </when>
  92. <when test="userScope == 3">
  93. and cu.user_id = 0
  94. </when>
  95. </choose>
  96. <choose>
  97. <when test="consumerScope == 2">
  98. and exists (select id from order_don o where o.user_id != 0 and o.user_id = cu.user_id and status not in
  99. ('close','noPayment','refund') limit 1)
  100. </when>
  101. <when test="consumerScope == 3">
  102. and not exists (select id from order_don o where o.user_id != 0 and o.user_id = cu.user_id and status
  103. not in
  104. ('close','noPayment','refund') limit 1)
  105. </when>
  106. </choose>
  107. inner join corp_user_follow_relation cufr on cufr.corp_user_id = ca.external_userid
  108. and cufr.wx_corp_id = #{wxCorpId}
  109. <if test="followIds != null and followIds.size() > 0">
  110. and cufr.follow_id in
  111. <foreach collection="followIds" item="item" open="(" separator="," close=")">
  112. #{item}
  113. </foreach>
  114. </if>
  115. <if test="list != null and list.size() > 0">
  116. and not exists (select s.corp_user_id from (select corp_user_id from corp_user_follow_relation cufr inner
  117. join `corp_user_tag` ct on ct.relation_id = cufr.id and ct.tag_id in
  118. <foreach collection="list" item="item" open="(" separator="," close=")">
  119. #{item}
  120. </foreach>
  121. group by cufr.corp_user_id) s where s.corp_user_id = cufr.corp_user_id limit 1)
  122. </if>
  123. group by cufr.corp_user_id
  124. </select>
  125. <select id="getCorpUserFollowRelation" resultType="com.cyksj.model.entity.CorpUserFollowRelation">
  126. select cufr.*
  127. from (select id
  128. from corp_user
  129. where unionid = #{unionId} limit 1) cu
  130. inner join corp_user_auth ca on ca.corp_user_id = cu.id
  131. inner join corp_user_follow_relation cufr on cufr.corp_user_id = ca.external_userid
  132. where cufr.follow_id = #{followId} limit 1
  133. </select>
  134. <select id="selectNumOfCorpuserByFollowId" resultType="java.lang.Integer">
  135. select count(distinct corp_user_id) from corp_user_follow_relation cufr where cufr.follow_id = #{followId} and status = 1
  136. </select>
  137. </mapper>