CorpUserFollowRelationMapper.xml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. <choose>
  27. <when test="userScope == 2">
  28. and cu.user_id != 0
  29. </when>
  30. <when test="userScope == 3">
  31. and cu.user_id = 0
  32. </when>
  33. </choose>
  34. and ca.wx_corp_id = #{wxCorpId}
  35. <if test="followIds != null and followIds.size() > 0">
  36. and cufr.follow_id in
  37. <foreach collection="followIds" item="item" open="(" separator="," close=")">
  38. #{item}
  39. </foreach>
  40. </if>
  41. group by cufr.corp_user_id
  42. </select>
  43. <select id="selectCorpUserFollowRelation" resultType="com.cyksj.model.dto.CorpUserFollowRelationDto">
  44. select cufr.corp_user_id,
  45. any_value(cufr.follow_id) as follow_id,
  46. any_value(cu.user_id) as user_id
  47. from `corp_user_follow_relation` cufr left join `corp_user_auth` ca on ca.external_userid = cufr.corp_user_id
  48. left join `corp_user` cu on cu.id = ca.corp_user_id
  49. where cufr.wx_corp_id = #{wxCorpId}
  50. and ca.wx_corp_id = #{wxCorpId}
  51. <if test="followIds != null and followIds.size() > 0">
  52. and cufr.follow_id in
  53. <foreach collection="followIds" item="item" open="(" separator="," close=")">
  54. #{item}
  55. </foreach>
  56. </if>
  57. group by cufr.corp_user_id
  58. </select>
  59. <select id="selectCorpUserNotUnderTagIds" resultType="com.cyksj.model.dto.CorpUserFollowRelationDto">
  60. select cufr.corp_user_id,
  61. any_value(cufr.follow_id) as follow_id,
  62. any_value(cu.user_id) as user_id
  63. from corp_user cu inner join corp_user_auth ca on ca.corp_user_id = cu.id
  64. and ca.wx_corp_id = #{wxCorpId}
  65. <choose>
  66. <when test="userScope == 2">
  67. and cu.user_id != 0
  68. </when>
  69. <when test="userScope == 3">
  70. and cu.user_id = 0
  71. </when>
  72. </choose>
  73. inner join corp_user_follow_relation cufr on cufr.corp_user_id = ca.external_userid
  74. and cufr.wx_corp_id = #{wxCorpId}
  75. <if test="followIds != null and followIds.size() > 0">
  76. and cufr.follow_id in
  77. <foreach collection="followIds" item="item" open="(" separator="," close=")">
  78. #{item}
  79. </foreach>
  80. </if>
  81. <if test="list != null and list.size() > 0">
  82. and not exists (select s.corp_user_id from (select corp_user_id from corp_user_follow_relation cufr inner
  83. join `corp_user_tag` ct on ct.relation_id = cufr.id and ct.tag_id in
  84. <foreach collection="list" item="item" open="(" separator="," close=")">
  85. #{item}
  86. </foreach>
  87. group by cufr.corp_user_id) s where s.corp_user_id = cufr.corp_user_id limit 1)
  88. </if>
  89. group by cufr.corp_user_id
  90. </select>
  91. </mapper>