| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- <?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.cyksj.mapper.corp.CorpUserFollowRelationMapper">
- <select id="selectCorpCustomers" resultType="java.lang.String">
- select group_concat(cf.name)
- from (select id
- from corp_user
- where unionid = #{unionid} limit 1) cu
- inner join corp_user_auth ca on ca.corp_user_id = cu.id and wx_corp_id = #{wxCorpId}
- inner join corp_user_follow_relation cfr on cfr.corp_user_id = ca.external_userid
- inner join corp_follow cf on cf.userid = cfr.follow_id and cf.wx_corp_id = #{wxCorpId}
- </select>
- <select id="selectCorpUserFollowRelationByTagIds" resultType="com.cyksj.model.dto.CorpUserFollowRelationDto">
- select cufr.corp_user_id,
- any_value(cufr.follow_id) as follow_id,
- any_value(cu.user_id) as user_id
- from (select
- relation_id from `corp_user_tag`
- where tag_id in
- <foreach collection="list" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>) cut left join `corp_user_follow_relation` cufr on cufr.id = cut.relation_id
- left join `corp_user_auth` ca on ca.external_userid = cufr.corp_user_id
- left join `corp_user` cu on cu.id = ca.corp_user_id
- where cufr.wx_corp_id = #{wxCorpId}
- <if test="joinStartTime != null">
- and cu.created_time >= #{joinStartTime}
- </if>
- <if test="joinEndTime != null">
- and cu.created_time < #{joinEndTime}
- </if>
- <choose>
- <when test="userScope == 2">
- and cu.user_id != 0
- </when>
- <when test="userScope == 3">
- and cu.user_id = 0
- </when>
- </choose>
- <choose>
- <when test="consumerScope == 2">
- and exists (select id from order_don o where o.user_id != 0 and o.user_id = cu.user_id and status not in
- ('close','noPayment','refund') limit 1)
- </when>
- <when test="consumerScope == 3">
- and not exists (select id from order_don o where o.user_id != 0 and o.user_id = cu.user_id and status
- not in
- ('close','noPayment','refund') limit 1)
- </when>
- </choose>
- and ca.wx_corp_id = #{wxCorpId}
- <if test="followIds != null and followIds.size() > 0">
- and cufr.follow_id in
- <foreach collection="followIds" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- </if>
- group by cufr.corp_user_id
- </select>
- <select id="selectCorpUserFollowRelation" resultType="com.cyksj.model.dto.CorpUserFollowRelationDto">
- select cufr.corp_user_id,
- any_value(cufr.follow_id) as follow_id,
- any_value(cu.user_id) as user_id
- from `corp_user_follow_relation` cufr left join `corp_user_auth` ca on ca.external_userid = cufr.corp_user_id
- left join `corp_user` cu on cu.id = ca.corp_user_id
- where cufr.wx_corp_id = #{wxCorpId}
- and ca.wx_corp_id = #{wxCorpId}
- <if test="followIds != null and followIds.size() > 0">
- and cufr.follow_id in
- <foreach collection="followIds" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- </if>
- group by cufr.corp_user_id
- </select>
- <select id="selectCorpUserNotUnderTagIds" resultType="com.cyksj.model.dto.CorpUserFollowRelationDto">
- select cufr.corp_user_id,
- any_value(cufr.follow_id) as follow_id,
- any_value(cu.user_id) as user_id
- from corp_user cu inner join corp_user_auth ca on ca.corp_user_id = cu.id
- and ca.wx_corp_id = #{wxCorpId}
- <if test="joinStartTime != null">
- and cu.created_time >= #{joinStartTime}
- </if>
- <if test="joinEndTime != null">
- and cu.created_time < #{joinEndTime}
- </if>
- <choose>
- <when test="userScope == 2">
- and cu.user_id != 0
- </when>
- <when test="userScope == 3">
- and cu.user_id = 0
- </when>
- </choose>
- <choose>
- <when test="consumerScope == 2">
- and exists (select id from order_don o where o.user_id != 0 and o.user_id = cu.user_id and status not in
- ('close','noPayment','refund') limit 1)
- </when>
- <when test="consumerScope == 3">
- and not exists (select id from order_don o where o.user_id != 0 and o.user_id = cu.user_id and status
- not in
- ('close','noPayment','refund') limit 1)
- </when>
- </choose>
- inner join corp_user_follow_relation cufr on cufr.corp_user_id = ca.external_userid
- and cufr.wx_corp_id = #{wxCorpId}
- <if test="followIds != null and followIds.size() > 0">
- and cufr.follow_id in
- <foreach collection="followIds" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- </if>
- <if test="list != null and list.size() > 0">
- and not exists (select s.corp_user_id from (select corp_user_id from corp_user_follow_relation cufr inner
- join `corp_user_tag` ct on ct.relation_id = cufr.id and ct.tag_id in
- <foreach collection="list" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- group by cufr.corp_user_id) s where s.corp_user_id = cufr.corp_user_id limit 1)
- </if>
- group by cufr.corp_user_id
- </select>
- <select id="getCorpUserFollowRelation" resultType="com.cyksj.model.entity.CorpUserFollowRelation">
- select cufr.*
- from (select id
- from corp_user
- where unionid = #{unionId} limit 1) cu
- inner join corp_user_auth ca on ca.corp_user_id = cu.id
- inner join corp_user_follow_relation cufr on cufr.corp_user_id = ca.external_userid
- where cufr.follow_id = #{followId} limit 1
- </select>
- <select id="selectNumOfCorpuserByFollowId" resultType="java.lang.Integer">
- select count(distinct corp_user_id) from corp_user_follow_relation cufr where cufr.follow_id = #{followId} and status = 1
- </select>
- </mapper>
|