<?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.ruoyi.busi.mapper.BusiSubscribeMapper">

    <resultMap type="BusiSubscribe" id="BusiSubscribeResult">
        <result property="id"    column="id"    />
        <result property="jsonObj"    column="json_obj"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="creator"    column="creator"    />
        <result property="updater"    column="updater"    />
        <result property="delFlag"    column="del_flag"    />
    </resultMap>

    <sql id="selectBusiSubscribeVo">
        select id, json_obj, create_time, update_time, creator, updater, del_flag from dl_busi_subscribe
    </sql>
    <select id="getOkUser" resultType="com.alibaba.fastjson2.JSONObject"
            parameterType="com.ruoyi.busi.vo.SubscribeDataObj">
        SELECT
            distinct su.wx_open_id as wxOpenId,
             sub.keywords_list as keywordsList,
             '0' as allOk
        FROM
            dl_busi_subscribe sub
        inner join sys_user su on sub.user_id = su.user_id and su.wx_open_id is not null
        where sub.new_notice = '1' and sub.del_flag ='0'
          -- 领域
          and (sub.blogger_type_code = '-1'
            <if test="bloggerTypeCode != null and bloggerTypeCode.length>0">
            <foreach item="item" index="index" collection="bloggerTypeCode"
                     open="(" separator="or" close=")">
                sub.blogger_type_code like concat('%',#{item},'%')
            </foreach>
             </if>
            )
          -- 平台
        and (sub.platform_code = '-1' or sub.platform_code like concat('%',#{platformCode},'%'))
        -- 结算方式
        and (sub.settle_type_code = '-1' or sub.settle_type_code like concat('%',#{settleTypeCode},'%'))
        -- 粉丝限制
        and (sub.fans_limit = '0' or sub.fans_limit is null
                 or (sub.fans_limit = '1' and sub.fans_up <![CDATA[<= ]]> #{fansUp} and sub.fans_down <![CDATA[>= ]]>   #{fansDown}))
        -- 收费限制
        and (sub.fee_limit = '0' or sub.fee_limit is null
                 or (sub.fee_limit = '1' and sub.fee_up <![CDATA[<= ]]> #{feeUp} and sub.fee_down <![CDATA[>= ]]>   #{feeDown}))
        union
        SELECT
        distinct su.wx_open_id as wxOpenId,
        '' as keywordsList,
        '1' as allOk
        FROM
        dl_busi_subscribe sub
        inner join sys_user su on sub.user_id = su.user_id and su.wx_open_id is not null
        inner join dl_busi_user_love love on love.user_id = sub.user_id and love.love_user_id = #{loveUserId}
        where sub.new_notice = '1' and sub.del_flag ='0' and sub.fork_notice = '1'


    </select>


</mapper>
