<?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.retrieval.mapper.CoreMonitoringRetrievalTaskMapper">

    <resultMap type="com.xunmei.common.core.domain.retrieval.domain.CoreMonitoringRetrievalTask" id="CoreMonitoringRetrievalTaskResult">
                <result property="id" column="id"/>
                <result property="planId" column="plan_id"/>
                <result property="taskName" column="task_name"/>
                <result property="orgId" column="org_id"/>
                <result property="orgPath" column="org_path"/>
                <result property="orgName" column="org_name"/>
                <result property="ymdDate" column="ymd_date"/>
                <result property="ymdYear" column="ymd_year"/>
                <result property="ymdHalfyear" column="ymd_halfyear"/>
                <result property="ymdQuarter" column="ymd_quarter"/>
                <result property="ymdMonth" column="ymd_month"/>
                <result property="ymdWeek" column="ymd_week"/>
                <result property="ymdDay" column="ymd_day"/>
                <result property="cycle" column="cycle"/>
                <result property="planStartTime" column="plan_start_time"/>
                <result property="planEndTime" column="plan_end_time"/>
                <result property="startTime" column="start_time"/>
                <result property="endTime" column="end_time"/>
                <result property="status" column="status"/>
                <result property="roleId" column="role_id"/>
                <result property="retrievalUser" column="retrieval_user"/>
                <result property="orderNum" column="order_num"/>
                <result property="batchNum" column="batch_num"/>
                <result property="submitTime" column="submit_time"/>
                <result property="exceptionCount" column="exception_count"/>
    </resultMap>

    <sql id="selectCoreMonitoringRetrievalTaskVo">
        select id, plan_id, task_name, org_id, org_path, org_name, ymd_date, ymd_year, ymd_halfyear, ymd_quarter, ymd_month, ymd_week, ymd_day, cycle, plan_start_time, plan_end_time, start_time, end_time, status, role_id, retrieval_user, order_num, batch_num, submit_time, exception_count
        from core_monitoring_retrieval_task
    </sql>

    <select id="selectCoreMonitoringRetrievalTaskList" parameterType="com.xunmei.common.core.domain.retrieval.domain.CoreMonitoringRetrievalTask"
            resultMap="CoreMonitoringRetrievalTaskResult">
        <include refid="selectCoreMonitoringRetrievalTaskVo"/>
        <where>
                        <if test="taskName != null  and taskName != ''">
                            and task_name like concat('%', #{taskName}, '%')
                        </if>
                        <if test="cycle != null ">
                            and cycle = #{cycle}
                        </if>
                        <if test="planStartTime != null ">
                            and plan_start_time = #{planStartTime}
                        </if>
                        <if test="planEndTime != null ">
                            and plan_end_time = #{planEndTime}
                        </if>
                        <if test="status != null ">
                            and status = #{status}
                        </if>
        </where>
    </select>

    <select id="selectCoreMonitoringRetrievalTaskById" parameterType="Long"
            resultMap="CoreMonitoringRetrievalTaskResult">
            <include refid="selectCoreMonitoringRetrievalTaskVo"/>
            where id = #{id}
    </select>
    <select id="selectPageList" resultType="com.xunmei.common.core.domain.retrieval.vo.CoreMonitoringRetrievalTaskVo">
        select a.*,b.name as roleName,c.name as retrievalUserName from core_monitoring_retrieval_task a left join sys_role b on a.role_id = b.id left join sys_user c on a.retrieval_user = c.id
        where 1=1
        <if test="coreMonitoringTaskRegistrationDTO.orgId != null ">
            and a.org_id = #{request.orgId}
        </if>
        <if test="request.orgPath != null  and request.orgPath != ''">
            and a.org_path = #{request.orgPath}
        </if>
        <if test="request.taskName != null  and request.taskName != ''">
            and a.task_name like concat('%', #{request.taskName}, '%')
        </if>
        <if test="request.cycle != null ">
            and a.cycle = #{request.cycle}
        </if>
        <if test="request.dateRange != null and request.dateRange.length>0">
            and a.ymd_date >= #{request.dateRange[0]}
            and #{request.dateRange[1]}>=a.ymd_date
        </if>
        <if test="request.status != null ">
            and a.status = #{request.status}
        </if>
        <if test="request.roleId != null ">
            and a.role_id = #{request.roleId}
        </if>
        order by a.ymd_date desc
    </select>
    <select id="selectListApp"
            resultType="com.xunmei.common.core.domain.retrieval.domain.CoreMonitoringRetrievalTask">
        SELECT
            *
        FROM
            core_monitoring_retrieval_task
        WHERE 1=1
        <if test="orgId != null ">
            and org_id = #{orgId}
        </if>
        <if test="status !=null">
            and status =#{status}
        </if>
     <if test="ymdDate !=null">
         and ymdDate like concat('%', #{ymd_date}, '%')
     </if>
    </select>

    <insert id="insertCoreMonitoringRetrievalTask" parameterType="com.xunmei.common.core.domain.retrieval.domain.CoreMonitoringRetrievalTask">
        insert into core_monitoring_retrieval_task
        <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test="id != null">id,
                    </if>
                    <if test="planId != null">plan_id,
                    </if>
                    <if test="taskName != null">task_name,
                    </if>
                    <if test="orgId != null">org_id,
                    </if>
                    <if test="orgPath != null">org_path,
                    </if>
                    <if test="orgName != null">org_name,
                    </if>
                    <if test="ymdDate != null">ymd_date,
                    </if>
                    <if test="ymdYear != null">ymd_year,
                    </if>
                    <if test="ymdHalfyear != null">ymd_halfyear,
                    </if>
                    <if test="ymdQuarter != null">ymd_quarter,
                    </if>
                    <if test="ymdMonth != null">ymd_month,
                    </if>
                    <if test="ymdWeek != null">ymd_week,
                    </if>
                    <if test="ymdDay != null">ymd_day,
                    </if>
                    <if test="cycle != null">cycle,
                    </if>
                    <if test="planStartTime != null">plan_start_time,
                    </if>
                    <if test="planEndTime != null">plan_end_time,
                    </if>
                    <if test="startTime != null">start_time,
                    </if>
                    <if test="endTime != null">end_time,
                    </if>
                    <if test="status != null">status,
                    </if>
                    <if test="roleId != null">role_id,
                    </if>
                    <if test="retrievalUser != null">retrieval_user,
                    </if>
                    <if test="orderNum != null">order_num,
                    </if>
                    <if test="batchNum != null">batch_num,
                    </if>
                    <if test="submitTime != null">submit_time,
                    </if>
                    <if test="exceptionCount != null">exception_count,
                    </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                    <if test="id != null">#{id},
                    </if>
                    <if test="planId != null">#{planId},
                    </if>
                    <if test="taskName != null">#{taskName},
                    </if>
                    <if test="orgId != null">#{orgId},
                    </if>
                    <if test="orgPath != null">#{orgPath},
                    </if>
                    <if test="orgName != null">#{orgName},
                    </if>
                    <if test="ymdDate != null">#{ymdDate},
                    </if>
                    <if test="ymdYear != null">#{ymdYear},
                    </if>
                    <if test="ymdHalfyear != null">#{ymdHalfyear},
                    </if>
                    <if test="ymdQuarter != null">#{ymdQuarter},
                    </if>
                    <if test="ymdMonth != null">#{ymdMonth},
                    </if>
                    <if test="ymdWeek != null">#{ymdWeek},
                    </if>
                    <if test="ymdDay != null">#{ymdDay},
                    </if>
                    <if test="cycle != null">#{cycle},
                    </if>
                    <if test="planStartTime != null">#{planStartTime},
                    </if>
                    <if test="planEndTime != null">#{planEndTime},
                    </if>
                    <if test="startTime != null">#{startTime},
                    </if>
                    <if test="endTime != null">#{endTime},
                    </if>
                    <if test="status != null">#{status},
                    </if>
                    <if test="roleId != null">#{roleId},
                    </if>
                    <if test="retrievalUser != null">#{retrievalUser},
                    </if>
                    <if test="orderNum != null">#{orderNum},
                    </if>
                    <if test="batchNum != null">#{batchNum},
                    </if>
                    <if test="submitTime != null">#{submitTime},
                    </if>
                    <if test="exceptionCount != null">#{exceptionCount},
                    </if>
        </trim>
    </insert>

    <update id="updateCoreMonitoringRetrievalTask" parameterType="com.xunmei.common.core.domain.retrieval.domain.CoreMonitoringRetrievalTask">
        update core_monitoring_retrieval_task
        <trim prefix="SET" suffixOverrides=",">
                    <if test="planId != null">plan_id =
                        #{planId},
                    </if>
                    <if test="taskName != null">task_name =
                        #{taskName},
                    </if>
                    <if test="orgId != null">org_id =
                        #{orgId},
                    </if>
                    <if test="orgPath != null">org_path =
                        #{orgPath},
                    </if>
                    <if test="orgName != null">org_name =
                        #{orgName},
                    </if>
                    <if test="ymdDate != null">ymd_date =
                        #{ymdDate},
                    </if>
                    <if test="ymdYear != null">ymd_year =
                        #{ymdYear},
                    </if>
                    <if test="ymdHalfyear != null">ymd_halfyear =
                        #{ymdHalfyear},
                    </if>
                    <if test="ymdQuarter != null">ymd_quarter =
                        #{ymdQuarter},
                    </if>
                    <if test="ymdMonth != null">ymd_month =
                        #{ymdMonth},
                    </if>
                    <if test="ymdWeek != null">ymd_week =
                        #{ymdWeek},
                    </if>
                    <if test="ymdDay != null">ymd_day =
                        #{ymdDay},
                    </if>
                    <if test="cycle != null">cycle =
                        #{cycle},
                    </if>
                    <if test="planStartTime != null">plan_start_time =
                        #{planStartTime},
                    </if>
                    <if test="planEndTime != null">plan_end_time =
                        #{planEndTime},
                    </if>
                    <if test="startTime != null">start_time =
                        #{startTime},
                    </if>
                    <if test="endTime != null">end_time =
                        #{endTime},
                    </if>
                    <if test="status != null">status =
                        #{status},
                    </if>
                    <if test="roleId != null">role_id =
                        #{roleId},
                    </if>
                    <if test="retrievalUser != null">retrieval_user =
                        #{retrievalUser},
                    </if>
                    <if test="orderNum != null">order_num =
                        #{orderNum},
                    </if>
                    <if test="batchNum != null">batch_num =
                        #{batchNum},
                    </if>
                    <if test="submitTime != null">submit_time =
                        #{submitTime},
                    </if>
                    <if test="exceptionCount != null">exception_count =
                        #{exceptionCount},
                    </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCoreMonitoringRetrievalTaskById" parameterType="Long">
        delete
        from core_monitoring_retrieval_task where id = #{id}
    </delete>

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