<?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.common.mapper.DeviceCollectTaskMapper">

    <resultMap id="BaseResultMap" type="com.common.entity.DeviceCollectTask">
        <id column="id" property="id" />
        <result column="created_at" property="createdAt" />
        <result column="updated_at" property="updatedAt" />
        <result column="deleted_at" property="deletedAt" />
        <result column="device_id" property="deviceId" />
        <result column="method" property="method" />
        <result column="task_name" property="taskName" />
        <result column="first_time" property="firstTime" />
        <result column="last_success_time" property="lastSuccessTime" />
        <result column="last_failed_time" property="lastFailedTime" />
        <result column="detail_id" property="detailId" />
        <result column="epm" property="epm" />
        <result column="epm_peak" property="epmPeak" />
        <result column="process_architecture" property="processArchitecture" />
        <result column="task_count" property="taskCount" />
        <result column="recent_discover_time" property="recentDiscoverTime" />
        <result column="epm_upper_limit" property="epmUpperLimit" />
    </resultMap>

    <sql id="Base_Column_List">
        id, created_at, updated_at, deleted_at, device_id, method, task_name,
        first_time, last_success_time, last_failed_time, detail_id, epm, epm_peak,
        process_architecture, task_count, recent_discover_time, epm_upper_limit
    </sql>

    <!-- 多条件组合查询 -->
    <select id="selectByCondition" parameterType="com.common.entity.DeviceCollectTask" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List" />
        FROM device_collect_task
        <where>
            <if test="deviceId != null">
                AND device_id = #{deviceId}
            </if>
            <if test="method != null">
                AND method = #{method}
            </if>
            <if test="taskName != null and taskName != ''">
                AND task_name LIKE CONCAT('%', #{taskName}, '%')
            </if>
            <if test="detailId != null">
                AND detail_id = #{detailId}
            </if>
            <if test="processArchitecture != null">
                AND process_architecture = #{processArchitecture}
            </if>
            <if test="epmUpperLimit != null">
                AND epm_upper_limit = #{epmUpperLimit}
            </if>
            <!-- 时间范围查询 -->
            <if test="firstTime != null">
                AND first_time >= #{firstTime}
            </if>
            <if test="lastSuccessTime != null">
                AND last_success_time >= #{lastSuccessTime}
            </if>
        </where>
        ORDER BY updated_at DESC
    </select>

</mapper>