<?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.xxfc.platform.user.behavior.mapper.CustomerBehaviorNotesMapper">

    <!-- 可根据自己的需求，是否要使用 -->
    <resultMap type="com.xxfc.platform.user.behavior.entity.CustomerBehaviorNotes" id="customerBehaviorNotesMap">
        <result property="id" column="id"/>
        <result property="customerId" column="customer_id"/>
        <result property="customerType" column="customer_type"/>
        <result property="type" column="type"/>
        <result property="typeId" column="type_id"/>
        <result property="crtTime" column="crt_time"/>
        <result property="requestId" column="request_id"/>
    </resultMap>

    <select id="selectByActivityIdAndTime" resultMap="customerBehaviorNotesMap">
        select * from `customer_behavior_notes` where `type_id`=#{activityId}
        <if test="startTime != null and endTime !=null">
            and `crt_time` between #{startTime} and #{endTime}
        </if>
        <if test="startTime != null and endTime == null">
            and <![CDATA[`crt_time` >= #{startTime}]]>
        </if>
        <if test="endTime != null and startTime == null">
            and <![CDATA[ `crt_time` <= #{endTime}]]>
        </if>
    </select>

    <select id="selectAppVvisitsByTypeAndTime" resultType="long">
        select count(id) from `customer_behavior_notes` where `type`=#{code}
        <if test="startTime != null != null and endTime !=null">
            and `crt_time` between #{startTime} and #{endTime}
        </if>
        <if test="startTime != null and endTime == null">
            and <![CDATA[`crt_time` >= #{startTime}]]>
        </if>
        <if test="endTime != null and startTime == null">
            and <![CDATA[ `crt_time` <= #{endTime}]]>
        </if>
    </select>

    <select id="selectAllByTypeIdsAndTime" resultMap="customerBehaviorNotesMap">
        select * from  `customer_behavior_notes` where `type_id` in
        <foreach collection="bizIds" item="bizId" open="(" close=")" separator=",">
            #{bizId}
        </foreach>
        <if test="startTime != null != null and endTime !=null">
            and `crt_time` between #{startTime} and #{endTime}
        </if>
        <if test="startTime != null and endTime == null">
            and <![CDATA[`crt_time` >= #{startTime}]]>
        </if>
        <if test="endTime != null and startTime == null">
            and <![CDATA[ `crt_time` <= #{endTime}]]>
        </if>
        and `type` in(0,1,2,3)
    </select>
</mapper>