<?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.zbf.system.mapper.TCallNoticeOrderMapper">

    <resultMap type="TCallNoticeOrder" id="TCallNoticeOrderResult">
            <result property="id"    column="id"    />
            <result property="taskId"    column="task_id"    />
            <result property="taskType"    column="task_type"    />
            <result property="status"    column="status"    />
            <result property="createBy"    column="create_by"    />
            <result property="updateBy"    column="update_by"    />
            <result property="createTime"    column="create_time"    />
            <result property="updateTime"    column="update_time"    />
            <result property="fictitious"    column="fictitious"    />
            <result property="deliveryId"    column="delivery_id"    />
            <result property="providerName"    column="provider_name"    />
            <result property="orderType"    column="order_type"    />
            <result property="deptId"    column="dept_id"    />
    </resultMap>

    <sql id="selectTCallNoticeOrderVo">
        select id, task_id, task_type, status, create_by, update_by, create_time, update_time, fictitious, delivery_id, provider_name, order_type, dept_id from t_call_notice_order
    </sql>

    <select id="selectTCallNoticeOrderList" parameterType="TCallNoticeOrder" resultMap="TCallNoticeOrderResult">
        <include refid="selectTCallNoticeOrderVo"/>
        <where>
            <if test="taskId != null  and taskId != ''"> and task_id = #{taskId}</if>
            <if test="taskType != null  and taskType != ''"> and task_type = #{taskType}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="fictitious != null  and fictitious != ''"> and fictitious = #{fictitious}</if>
            <if test="deliveryId != null  and deliveryId != ''"> and delivery_id = #{deliveryId}</if>
            <if test="providerName != null  and providerName != ''"> and provider_name like concat('%', #{providerName}, '%')</if>
            <if test="orderType != null  and orderType != ''"> and order_type = #{orderType}</if>
        </where>
         order by create_time desc 
    </select>

    <select id="selectTCallNoticeOrderById" parameterType="String" resultMap="TCallNoticeOrderResult">
            <include refid="selectTCallNoticeOrderVo"/>
            where id = #{id}
    </select>

    <insert id="insertTCallNoticeOrder" parameterType="TCallNoticeOrder">
        insert into t_call_notice_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test="id != null">id,</if>
                    <if test="taskId != null">task_id,</if>
                    <if test="taskType != null">task_type,</if>
                    <if test="status != null">status,</if>
                    <if test="createBy != null">create_by,</if>
                    <if test="updateBy != null">update_by,</if>
                    <if test="createTime != null">create_time,</if>
                    <if test="updateTime != null">update_time,</if>
                    <if test="fictitious != null">fictitious,</if>
                    <if test="deliveryId != null">delivery_id,</if>
                    <if test="providerName != null">provider_name,</if>
                    <if test="orderType != null">order_type,</if>
                    <if test="deptId != null">dept_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                    <if test="id != null">#{id},</if>
                    <if test="taskId != null">#{taskId},</if>
                    <if test="taskType != null">#{taskType},</if>
                    <if test="status != null">#{status},</if>
                    <if test="createBy != null">#{createBy},</if>
                    <if test="updateBy != null">#{updateBy},</if>
                    <if test="createTime != null">#{createTime},</if>
                    <if test="updateTime != null">#{updateTime},</if>
                    <if test="fictitious != null">#{fictitious},</if>
                    <if test="deliveryId != null">#{deliveryId},</if>
                    <if test="providerName != null">#{providerName},</if>
                    <if test="orderType != null">#{orderType},</if>
                    <if test="deptId != null">#{deptId},</if>
        </trim>
    </insert>

    <update id="updateTCallNoticeOrder" parameterType="TCallNoticeOrder">
        update t_call_notice_order
        <trim prefix="SET" suffixOverrides=",">
                    <if test="taskId != null">task_id = #{taskId},</if>
                    <if test="taskType != null">task_type = #{taskType},</if>
                    <if test="status != null">status = #{status},</if>
                    <if test="createBy != null">create_by = #{createBy},</if>
                    <if test="updateBy != null">update_by = #{updateBy},</if>
                    <if test="createTime != null">create_time = #{createTime},</if>
                    <if test="updateTime != null">update_time = #{updateTime},</if>
                    <if test="fictitious != null">fictitious = #{fictitious},</if>
                    <if test="deliveryId != null">delivery_id = #{deliveryId},</if>
                    <if test="providerName != null">provider_name = #{providerName},</if>
                    <if test="orderType != null">order_type = #{orderType},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="enableTCallNoticeOrderByIds" parameterType="String">
        update t_call_notice_order set status=0 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    <update id="disabledTCallNoticeOrderByIds" parameterType="String">
        update t_call_notice_order set status=1 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <delete id="deleteTCallNoticeOrderById" parameterType="String">
        delete from t_call_notice_order  where id = #{id}
    </delete>

    <delete id="deleteTCallNoticeOrderByIds" parameterType="String">
        delete from t_call_notice_order where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <update id="updateTaskStatus" parameterType="TCallNoticeOrder">
        update t_call_notice_order 
            set status= '1'
                , update_by = #{updateBy}
                , update_time = #{updateTime}
        <where>
            <if test="taskId != null">and task_id = #{taskId}</if>
            <if test="taskType != null">and task_type = #{taskType}</if>
        </where>
    </update>
</mapper>
