<?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.benyun.mapper.BusinessOpportunitiesDao">
    <resultMap type="com.ruoyi.benyun.entity.BusinessOpportunitiesClue" id="ClueResult">
        <result property="clueId" column="clue_id"/>
        <result property="attentionId" column="attention_id"/>
        <result property="contact" column="contact"/>
        <result property="telephone" column="telephone"/>
        <result property="followUpCount" column="follow_up_count"/>
        <result property="userId" column="user_id"/>
        <result property="createTime" column="create_time"/>
    </resultMap>
    <update id="updateFollowUpCountByClueIdAndUserId">
        UPDATE `bl_business_opportunities_clue`
        SET follow_up_count = #{count}
        <trim prefix="where" prefixOverrides="and">
            <if test="userId != null">
                user_id = #{userId}
            </if>
            and clue_id = #{clueId}
        </trim>
    </update>
    <delete id="deleteByAttentionIdAndUserId">
        delete from `bl_business_opportunities_clue`
        <trim prefix="where" prefixOverrides="and">
            <if test="userId != null">
                user_id = #{userId}
            </if>
            and attention_id = #{attentionId}
        </trim>
    </delete>
    <select id="searchCountByUserId" resultType="java.lang.Integer">
        select count(*) from `bl_business_opportunities_clue`
        <where>
            <if test="userId != null">
                user_id = #{userId}
            </if>
        </where>
    </select>
    <select id="searchByClueIdOrAttentionIdAndUserId" resultMap="ClueResult">
        select * from `bl_business_opportunities_clue`
        <trim prefix="where" prefixOverrides="and">
            <if test="userId != null">
                user_id = #{userId}
            </if>
            <if test="clueId != null">
                and clue_id = #{clueId}
            </if>
            <if test="attentionId != null">
                and attention_id = #{attentionId}
            </if>
        </trim>
    </select>
    <select id="searchAllByMulti" resultMap="ClueResult">
        select * from `bl_business_opportunities_clue`
        <trim prefix="where" prefixOverrides="and">
            <if test="userId != null">
                user_id = #{userId}
            </if>
            <if test="text != null">
                and (contact like concat('%',#{text},'%')
                or telephone like concat('%',#{text},'%'))
            </if>
        </trim>
    </select>
    <select id="selectCount" resultType="java.lang.Integer">
        SELECT
            COUNT(*) count
        FROM
            `bl_business_opportunities_clue`
        WHERE
            user_id = #{userId};
    </select>
</mapper>
