<?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.xunmei.core.resumption.mapper.ResumptionMapper">
    <update id="updateResumption">
        update t_app_resumption set
                                    modified_id=#{resumption.modifiedId},
                                    modified_name=#{resumption.modifiedName},
                                    update_time=#{resumption.updateTime},
                                    exception_count=#{resumption.exceptionCount},
                                    status=#{resumption.status},
                                    submit_time=#{resumption.submitTime},
                                    start_time=#{resumption.startTime},
                                    end_time=#{resumption.endTime}
        where id = #{resumption.id} and ymd_year = #{resumption.ymd.year} and ymd_quarter = #{resumption.ymd.quarter}

    </update>


    <select id="findDayTaskList" resultType="java.util.Map">
        SELECT
            a.modified_name AS submitBy,
            a.submit_time AS submitTime,
            a.id AS id,
            b.plan_name AS title,
            b.id AS planid,
            b.plan_exec AS planexec,
            plan_start_time AS planstarttime,
            plan_end_time AS planendtime,
            ymd_date,
            STATUS,
            a.type AS type
        FROM
            core_resumption a
                LEFT JOIN core_resumption_plan b ON a.plan_id = b.id
        WHERE
            a.ymd_year =#{year}
          AND a.ymd_quarter =#{quarter}
          AND a.type IN ( 0, 6 )
          AND a.ymd_date =#{dateTime}
          AND a.role_id =#{roleId}
          AND a.org_id =#{orgid}
        ORDER BY
            a.plan_start_time ASC

    </select>
    <select id="findMonthTaskList" resultType="java.util.Map">
        SELECT
            a.modified_name AS submitBy,
            a.submit_time AS submitTime,
            a.id AS id,
            b.plan_name AS title,
            b.id AS planid,
            plan_start_time AS planstarttime,
            plan_end_time AS planendtime,
            ymd_year,
            ymd_month,
            ymd_week,
            STATUS
        FROM
            t_app_resumption a
                LEFT JOIN core_resumption_plan b ON a.plan_id = b.id
        WHERE
            a.ymd_year =#{year}
          AND a.ymd_quarter =#{quarter}
          AND a.type = #{type}
          AND a.ymd_month =#{month}
          AND a.role_id =#{roleId}
          AND a.org_id =#{orgid}
        ORDER BY
            a.plan_start_time ASC
    </select>
    <select id="findYearTaskList" resultType="java.util.Map">
        SELECT
            a.modified_name AS submitBy,
            a.submit_time AS submitTime,
            a.id AS id,
            b.plan_name AS title,
            b.id AS planid,
            plan_start_time AS planstarttime,
            plan_end_time AS planendtime,
            ymd_year,
            ymd_quarter,
            ymd_halfyear,
            STATUS
        FROM
            t_app_resumption a
                LEFT JOIN core_resumption_plan b ON a.plan_id = b.id
        WHERE
            a.ymd_year =#{year}
          AND a.ymd_quarter =#{quarter}
          AND a.type = #{type}
          AND a.role_id =#{roleId}
          AND a.org_id =#{orgid}
        ORDER BY
            a.plan_start_time ASC
    </select>
    <select id="findOneByTaskIdAndDate" resultType="com.xunmei.core.resumption.domain.Resumption">
        select * from core_resumption where id=#{taskid} and ymd_year=#{year} and ymd_quarter=#{quarter}

    </select>
    <select id="findOneByTaskId" resultType="java.util.Map">
        SELECT
            a.modified_name AS submitBy,
            a.submit_time AS submitTime,
            a.id AS id,
            b.plan_name AS title,
            b.id AS planid,
            b.plan_exec AS planexec,
            plan_start_time AS planstarttime,
            plan_end_time AS planendtime,
            ymd_year,
            ymd_quarter,
            ymd_halfyear,
            ymd_month,
            ymd_week,
            STATUS,
            a.type
        FROM
            t_app_resumption a
                LEFT JOIN core_resumption_plan b ON a.plan_id = b.id
        WHERE
            a.id =#{taskId}
          AND a.ymd_year =#{year}
          AND a.ymd_quarter =#{quarter}

    </select>
</mapper>