<?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.yonge.cooleshow.biz.dal.mapper.CustomerServiceBatchSendingMapper">

	 
    
    <!-- 表字段 -->
    <sql id="baseColumns">
         t.id_ AS id
        , t.target_group_ AS targetGroup
        , t.send_subject_ AS sendSubject
        , t.send_number_ AS sendNumber
        , t.receive_number_ AS receiveNumber
        , t.receive_type_ AS receiveType
        , t.send_type_ AS sendType
        , t.send_status_ AS sendStatus
        , t.send_time_ AS sendTime
        , t.send_end_time_ AS sendEndTime
        , t.condition_ AS `condition`
        , t.title_ AS title
        , t.text_message_ AS textMessage
        , t.img_message_ AS imgMessage
        , t.img_url_ AS imgUrl
        , t.sender_id_ AS senderId
        , t.send_flag_ AS sendFlag
        , t.create_by_ AS createBy
        , t.create_time_ AS createTime
    </sql>
    
    <select id="selectPage" resultType="com.yonge.cooleshow.biz.dal.wrapper.im.CustomerServiceBatchSendingWrapper$CustomerServiceBatchSending">
		SELECT         
        	<include refid="baseColumns" />
		FROM customer_service_batch_sending t
		<where>
            <if test="param.keyword != null">
                AND t.id_ = #{param.keyword}
            </if>
		    <if test="param.sendSubject != null">
                AND FIND_IN_SET(#{param.sendSubject}, t.send_subject_)
            </if>
		    <if test="param.targetGroup != null">
                AND FIND_IN_SET(#{param.targetGroup}, t.target_group_)
            </if>
		    <if test="param.sendType != null">
                AND t.send_type_ = #{param.sendType}
            </if>
		    <if test="param.sendStatus != null">
                AND t.send_status_ = #{param.sendStatus}
            </if>
            <if test="param.startTime != null and param.endTime != null">
                AND (#{param.startTime} &lt;= t.create_time_ AND t.create_time_ &lt;= #{param.endTime})
            </if>
		    <if test="param.sendStartTime != null and param.sendEndTime != null">
                AND (#{param.sendStartTime} &lt;= t.send_time_ AND t.send_time_ &lt;= #{param.sendEndTime})
            </if>
        </where>
        ORDER BY t.id_ DESC
	</select>

    <!--客服消息接收者-->
    <select id="selectMessageReceives"
            resultType="com.yonge.cooleshow.biz.dal.wrapper.im.CustomerService$MessageReceives">
        SELECT t1.id_ AS userId, t1.username_ FROM sys_user t1
        <if test="param.clientType != null">
            <if test="param.clientType.code == 'TEACHER'"> LEFT JOIN teacher t2 ON (t1.id_ = t2.user_id_)</if>
            <if test="param.clientType.code == 'STUDENT'"> LEFT JOIN student t2 ON (t1.id_ = t2.user_id_ and t2.hide_flag_ = 0)</if>
        </if>
        <where>
            <if test="param.subjectIds != null">
                AND (<foreach collection="param.subjectIds" separator="OR" item="item"> FIND_IN_SET(#{item}, t2.subject_id_) </foreach>)
            </if>
            <if test="param.tenantFlag != null">
                <if test="param.tenantFlag == 1">
                    AND t2.tenant_id_  != -1
                </if>
                <if test="param.tenantFlag == 0">
                    AND t2.tenant_id_ = -1
                </if>
            </if>
        </where>
    </select>
    <!--客服消息接收者-->

</mapper>