<?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.demo.mapper.FollowUpDao">
    <resultMap type="com.ruoyi.demo.entity.FollowUpRecord" id="RecoredResult">
        <result property="recordId" column="record_id"/>
        <result property="clueId" column="clue_id"/>
        <result property="followWay" column="follow_way"/>
        <result property="followContent" column="follow_content"/>
        <result property="followPerson" column="follow_person"/>
        <result property="userId" column="user_id"/>
        <result property="followTime" column="follow_time"/>
    </resultMap>
    <delete id="deleteByClueIdAndUserId">
        delete from `bl_follow_up_record`
        <trim prefix="where" prefixOverrides="and">
            <if test="userId != null">
                user_id = #{userId}
            </if>
            and clue_id = #{clueId}
        </trim>
    </delete>
    <select id="searchCountByUserIdAndWay" resultType="java.lang.Integer">
        select count(*) from `bl_follow_up_record`
        <trim prefix="where" prefixOverrides="and">
            <if test="userId != null">
                user_id = #{userId}
            </if>
            and follow_way = #{way}
        </trim>
    </select>
    <select id="searchAllByClueIdAndUserId" resultMap="RecoredResult">
        select * from `bl_follow_up_record`
        <trim prefix="where" prefixOverrides="and">
            <if test="userId != null">
                user_id = #{userId}
            </if>
            and clue_id = #{clueId}
        </trim>
    </select>
    <select id="searchAllByMulti" resultMap="RecoredResult">
        select * from `bl_follow_up_record`
        <trim prefix="where" prefixOverrides="and">
            <if test="userId != null">
                user_id = #{userId}
            </if>
            and clue_id = #{clueId}
            <if test="text != null">
                and (record_id like concat('%',#{text},'%')
                or follow_content like concat('%',#{text},'%')
                or follow_person like concat('%',#{text},'%'))
            </if>
            <if test="startTime != null">
                and #{startTime} <![CDATA[<=]]> follow_time
            </if>
            <if test="endTime != null">
                and follow_time <![CDATA[<=]]> #{endTime}
            </if>
        </trim>
    </select>
    <select id="selectCountByWay" resultType="java.lang.Integer">
        SELECT
            COUNT(*)
        FROM
            `bl_follow_up_record`
        WHERE user_id = #{userId}
          AND follow_way = #{way};
    </select>
</mapper>
