<?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.docus.server.reportmanager.mapper.CollectTaskMapper">
    <insert id="moveCancel">
        INSERT INTO  `docus_archivefile`.`af_collect_task_cancel`
        SELECT * FROM `docus_archivefile`.`af_collect_task`
        WHERE  `id` in
        <foreach collection="ids" item="id" separator="," open="(" close=")">
            #{id}
        </foreach>
    </insert>
    <update id="cancel">
        UPDATE `docus_archivefile`.`af_collect_task`
        SET `state` = '4'
        WHERE `id` in
        <foreach collection="ids" item="id" separator="," open="(" close=")">
            #{id}
        </foreach>
    </update>
    <update id="updateTaskForRecollect">
        UPDATE `docus_archivefile`.`af_collect_task`
        SET `state` = #{state},
            `C9`='1',
            `recollect_name`=#{operator},
            `sync_time`=now(),
            `recollect_time`=now()
        WHERE `id` in
        <foreach collection="taskIds" item="taskId" separator="," open="(" close=")">
            #{taskId}
        </foreach>
    </update>
    <delete id="del">
        DELETE FROM  `docus_archivefile`.`af_collect_task`
        WHERE `id` in
        <foreach collection="ids" item="id" separator="," open="(" close=")">
            #{id}
        </foreach>
    </delete>

    <select id="getTasks" resultType="com.docus.server.reportmanager.entity.AfCollectTask">
        SELECT
        id,
        patient_id as patientId,
        af_archive_detail_id,
        C1,C2,C4,C6,C7,C8
        FROM
        `docus_archivefile`.`af_collect_task`
        <where>
            <if test="task.sysflag !=null and task.sysflag != ''">
                and sysflag=#{task.sysflag}
            </if>
            <if test="task.patientId !=null and task.patientId != ''">
                and patient_id=#{task.patientId}
            </if>
            <if test="task.C1 !=null and task.C1 != ''">
                and C1=#{task.C1}
            </if>
            <if test="task.C2 !=null and task.C2 != ''">
                and C2=#{task.C2}
            </if>
            <if test="task.C4 !=null and task.C4 != ''">
                and C4=#{task.C4}
            </if>
            <if test="task.C6 !=null and task.C6 != ''">
                and C6=#{task.C6}
            </if>
            <if test="task.C7 !=null and task.C7 != ''">
                and C7=#{task.C7}
            </if>
            <if test="task.C8 !=null and task.C8 != ''">
                and C8=#{task.C8}
            </if>
        </where>
    </select>
    <select id="getCollectionState" resultType="java.lang.String">
        SELECT
            collectionstate
        FROM
            `docus_archivefile`.`af_system_config`
        LIMIT 1
    </select>
</mapper>
