<?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.ycwl.basic.mapper.PrintTaskMapper">
    <insert id="insertTask">
        insert into print_task(printer_id, mp_id, paper, status, printer_name, url, width, height, create_time)
        values (#{printerId}, #{mpId}, #{paper}, 0, #{printerName}, #{url}, #{width}, #{height}, NOW())
    </insert>

    <select id="queryByCondition" resultType="com.ycwl.basic.model.pc.printer.entity.PrintTaskEntity">
        select id, printer_id, status, printer_name, url, width, height, mp_id, paper, create_time, update_time
        from print_task
        where 1=1
        <if test="printerId != null">
            and printer_id = #{printerId}
        </if>
        <if test="status != null">
            and status = #{status}
        </if>
        order by create_time desc
    </select>

    <update id="updateStatus">
        update print_task
        set status = #{status}, update_time = NOW()
        where id = #{id}
    </update>

    <update id="updateStatusAndPrinter">
        update print_task
        <set>
            status = #{status},
            <if test="printerName != null and printerName != ''">
                printer_name = #{printerName},
            </if>
            update_time = NOW()
        </set>
        where id = #{id}
    </update>

    <select id="queryPendingReviewTasks" resultType="com.ycwl.basic.model.pc.printer.entity.PrintTaskEntity">
        select id, printer_id, status, printer_name, url, width, height, mp_id, paper, create_time, update_time
        from print_task
        where status = 4
        <if test="printerId != null">
            and printer_id = #{printerId}
        </if>
        order by create_time desc
    </select>

    <update id="updateTaskUrl">
        update print_task
        set url = #{url}, update_time = NOW()
        where id = #{id} and status = 4
    </update>

    <update id="batchUpdateStatus">
        update print_task
        set status = #{status}, update_time = NOW()
        where id in
        <foreach collection="ids" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
</mapper>