<?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.fs.aiob.mapper.AiobBaiduTaskMapper">

    <resultMap type="AiobBaiduTask" id="AiobBaiduTaskResult">
        <result property="id"    column="id"    />
        <result property="taskId"    column="task_id"    />
        <result property="taskName"    column="task_name"    />
        <result property="robotId"    column="robot_id"    />
        <result property="dialStartDate"    column="dial_start_date"    />
        <result property="dialEndDate"    column="dial_end_date"    />
        <result property="dialStartTime"    column="dial_start_time"    />
        <result property="dialEndTime"    column="dial_end_time"    />
        <result property="forbidDialDate"    column="forbid_dial_date"   />
        <result property="forbidDialTime"    column="forbid_dial_time"    />
        <result property="callerNums"    column="caller_nums"    />
        <result property="lastCallerNums"    column="last_caller_nums"    />
        <result property="blackListStrategy"    column="black_list_strategy"    />
        <result property="finalStrategy"    column="final_strategy"    />
        <result property="callStrategy"    column="call_strategy"    />
        <result property="retryTimes"    column="retry_times"    />
        <result property="retryInterval"    column="retry_interval"    />
        <result property="isSetCapacity"    column="is_set_capacity"    />
        <result property="taskCapacity"    column="task_capacity"    />
        <result property="isOpenEmptyNum"    column="is_open_empty_num"    />
        <result property="isOpenPhoneDown"    column="is_open_phone_down"    />
        <result property="isOpenRepeatFilter"    column="is_open_repeat_filter"    />
        <result property="numTypeFilterList"    column="num_type_filter_list"    />
        <result property="smsStrategyV1"    column="sms_strategy_v1"    />
        <result property="taskDataCallback"    column="task_data_callback"    />
        <result property="callBackUrl"    column="call_back_url"    />
        <result property="callFinishTaskEnd"    column="call_finish_task_end"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectAiobBaiduTaskVo">
        select * from aiob_baidu_task
    </sql>

    <select id="selectAiobBaiduTaskList" parameterType="AiobBaiduTask" resultType="AiobBaiduTask">
        select
            a.*,
        (select count(1) from company_voice_robotic_callees b where a.id = b.robotic_id and b.result = 1 and b.distribute = 0) num
        from aiob_baidu_task a
        <where>
            <if test="taskId != null  and taskId != ''"> and task_id = #{taskId}</if>
            <if test="taskName != null  and taskName != ''"> and task_name like concat('%', #{taskName}, '%')</if>
            <if test="robotId != null  and robotId != ''"> and robot_id = #{robotId}</if>
            <if test="dialStartDate != null "> and dial_start_date = #{dialStartDate}</if>
            <if test="dialEndDate != null "> and dial_end_date = #{dialEndDate}</if>
            <if test="dialStartTime != null "> and dial_start_time = #{dialStartTime}</if>
            <if test="dialEndTime != null "> and dial_end_time = #{dialEndTime}</if>
            <if test="forbidDialDate != null "> and forbid_dial_date = #{forbidDialDate}</if>
            <if test="forbidDialTime != null  and forbidDialTime != ''"> and forbid_dial_time = #{forbidDialTime}</if>
            <if test="callerNums != null  and callerNums != ''"> and caller_nums = #{callerNums}</if>
            <if test="lastCallerNums != null  and lastCallerNums != ''"> and last_caller_nums = #{lastCallerNums}</if>
            <if test="blackListStrategy != null "> and black_list_strategy = #{blackListStrategy}</if>
            <if test="finalStrategy != null "> and final_strategy = #{finalStrategy}</if>
            <if test="callStrategy != null "> and call_strategy = #{callStrategy}</if>
            <if test="retryTimes != null "> and retry_times = #{retryTimes}</if>
            <if test="retryInterval != null "> and retry_interval = #{retryInterval}</if>
            <if test="isSetCapacity != null "> and is_set_capacity = #{isSetCapacity}</if>
            <if test="taskCapacity != null "> and task_capacity = #{taskCapacity}</if>
            <if test="isOpenEmptyNum != null "> and is_open_empty_num = #{isOpenEmptyNum}</if>
            <if test="isOpenPhoneDown != null "> and is_open_phone_down = #{isOpenPhoneDown}</if>
            <if test="isOpenRepeatFilter != null "> and is_open_repeat_filter = #{isOpenRepeatFilter}</if>
            <if test="numTypeFilterList != null  and numTypeFilterList != ''"> and num_type_filter_list = #{numTypeFilterList}</if>
            <if test="smsStrategyV1 != null  and smsStrategyV1 != ''"> and sms_strategy_v1 = #{smsStrategyV1}</if>
            <if test="taskDataCallback != null "> and task_data_callback = #{taskDataCallback}</if>
            <if test="callBackUrl != null  and callBackUrl != ''"> and call_back_url = #{callBackUrl}</if>
            <if test="callFinishTaskEnd != null "> and call_finish_task_end = #{callFinishTaskEnd}</if>
        </where>

        order by a.id desc
    </select>

    <select id="selectAiobBaiduTaskById" parameterType="Long" resultMap="AiobBaiduTaskResult">
        <include refid="selectAiobBaiduTaskVo"/>
        where id = #{id}
    </select>

    <insert id="insertAiobBaiduTask" parameterType="AiobBaiduTask" useGeneratedKeys="true" keyProperty="id">
        insert into aiob_baidu_task
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="taskId != null">task_id,</if>
            <if test="taskName != null">task_name,</if>
            <if test="robotId != null">robot_id,</if>
            <if test="dialStartDate != null">dial_start_date,</if>
            <if test="dialEndDate != null">dial_end_date,</if>
            <if test="dialStartTime != null">dial_start_time,</if>
            <if test="dialEndTime != null">dial_end_time,</if>
            <if test="forbidDialDate != null">forbid_dial_date,</if>
            <if test="forbidDialTime != null">forbid_dial_time,</if>
            <if test="callerNums != null">caller_nums,</if>
            <if test="lastCallerNums != null">last_caller_nums,</if>
            <if test="blackListStrategy != null">black_list_strategy,</if>
            <if test="finalStrategy != null">final_strategy,</if>
            <if test="callStrategy != null">call_strategy,</if>
            <if test="retryTimes != null">retry_times,</if>
            <if test="retryInterval != null">retry_interval,</if>
            <if test="isSetCapacity != null">is_set_capacity,</if>
            <if test="taskCapacity != null">task_capacity,</if>
            <if test="isOpenEmptyNum != null">is_open_empty_num,</if>
            <if test="isOpenPhoneDown != null">is_open_phone_down,</if>
            <if test="isOpenRepeatFilter != null">is_open_repeat_filter,</if>
            <if test="numTypeFilterList != null">num_type_filter_list,</if>
            <if test="smsStrategyV1 != null">sms_strategy_v1,</if>
            <if test="taskDataCallback != null">task_data_callback,</if>
            <if test="callBackUrl != null">call_back_url,</if>
            <if test="callFinishTaskEnd != null">call_finish_task_end,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="taskId != null">#{taskId},</if>
            <if test="taskName != null">#{taskName},</if>
            <if test="robotId != null">#{robotId},</if>
            <if test="dialStartDate != null">#{dialStartDate},</if>
            <if test="dialEndDate != null">#{dialEndDate},</if>
            <if test="dialStartTime != null">#{dialStartTime},</if>
            <if test="dialEndTime != null">#{dialEndTime},</if>
            <if test="forbidDialDate != null">#{forbidDialDate},</if>
            <if test="forbidDialTime != null">#{forbidDialTime},</if>
            <if test="callerNums != null">#{callerNums},</if>
            <if test="lastCallerNums != null">#{lastCallerNums},</if>
            <if test="blackListStrategy != null">#{blackListStrategy},</if>
            <if test="finalStrategy != null">#{finalStrategy},</if>
            <if test="callStrategy != null">#{callStrategy},</if>
            <if test="retryTimes != null">#{retryTimes},</if>
            <if test="retryInterval != null">#{retryInterval},</if>
            <if test="isSetCapacity != null">#{isSetCapacity},</if>
            <if test="taskCapacity != null">#{taskCapacity},</if>
            <if test="isOpenEmptyNum != null">#{isOpenEmptyNum},</if>
            <if test="isOpenPhoneDown != null">#{isOpenPhoneDown},</if>
            <if test="isOpenRepeatFilter != null">#{isOpenRepeatFilter},</if>
            <if test="numTypeFilterList != null">#{numTypeFilterList},</if>
            <if test="smsStrategyV1 != null">#{smsStrategyV1},</if>
            <if test="taskDataCallback != null">#{taskDataCallback},</if>
            <if test="callBackUrl != null">#{callBackUrl},</if>
            <if test="callFinishTaskEnd != null">#{callFinishTaskEnd},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateAiobBaiduTask" parameterType="AiobBaiduTask">
        update aiob_baidu_task
        <trim prefix="SET" suffixOverrides=",">
            <if test="taskId != null">task_id = #{taskId},</if>
            <if test="taskName != null">task_name = #{taskName},</if>
            <if test="robotId != null">robot_id = #{robotId},</if>
            <if test="dialStartDate != null">dial_start_date = #{dialStartDate},</if>
            <if test="dialEndDate != null">dial_end_date = #{dialEndDate},</if>
            <if test="dialStartTime != null">dial_start_time = #{dialStartTime},</if>
            <if test="dialEndTime != null">dial_end_time = #{dialEndTime},</if>
            <if test="forbidDialDate != null">forbid_dial_date = #{forbidDialDate},</if>
            <if test="forbidDialTime != null">forbid_dial_time = #{forbidDialTime},</if>
            <if test="callerNums != null">caller_nums = #{callerNums},</if>
            <if test="lastCallerNums != null">last_caller_nums = #{lastCallerNums},</if>
            <if test="blackListStrategy != null">black_list_strategy = #{blackListStrategy},</if>
            <if test="finalStrategy != null">final_strategy = #{finalStrategy},</if>
            <if test="callStrategy != null">call_strategy = #{callStrategy},</if>
            <if test="retryTimes != null">retry_times = #{retryTimes},</if>
            <if test="retryInterval != null">retry_interval = #{retryInterval},</if>
            <if test="isSetCapacity != null">is_set_capacity = #{isSetCapacity},</if>
            <if test="taskCapacity != null">task_capacity = #{taskCapacity},</if>
            <if test="isOpenEmptyNum != null">is_open_empty_num = #{isOpenEmptyNum},</if>
            <if test="isOpenPhoneDown != null">is_open_phone_down = #{isOpenPhoneDown},</if>
            <if test="isOpenRepeatFilter != null">is_open_repeat_filter = #{isOpenRepeatFilter},</if>
            <if test="numTypeFilterList != null">num_type_filter_list = #{numTypeFilterList},</if>
            <if test="smsStrategyV1 != null">sms_strategy_v1 = #{smsStrategyV1},</if>
            <if test="taskDataCallback != null">task_data_callback = #{taskDataCallback},</if>
            <if test="callBackUrl != null">call_back_url = #{callBackUrl},</if>
            <if test="callFinishTaskEnd != null">call_finish_task_end = #{callFinishTaskEnd},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAiobBaiduTaskById" parameterType="Long">
        delete from aiob_baidu_task where id = #{id}
    </delete>

    <delete id="deleteAiobBaiduTaskByIds" parameterType="String">
        delete from aiob_baidu_task where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
