<?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.jeesite.spider.mapper.SpiderMissionMapper">

    <resultMap type="SpiderMission" id="SpiderMissionResult">
        <result property="missionId"    column="mission_id"    />
        <result property="missionName"    column="mission_name"    />
        <result property="spiderConfigId"    column="spider_config_id"    />
        <result property="entryUrls"    column="entry_urls"    />
        <result property="status"    column="status"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="timeCost"    column="time_cost"    />
        <result property="exitWay"    column="exit_way"    />
        <result property="exitWayCount"    column="exit_way_count"    />
        <result property="successNum"    column="success_num"    />
        <result property="cookieStr"    column="cookie_str"    />
        <result property="headerStr"    column="header_str"    />
        <result property="deptId"    column="dept_id"    />
        <result property="userId"    column="user_id"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="loopFlag"    column="loop_flag"    />
        <result property="loopParam"    column="loop_param"    />
        <result property="loopNum"    column="loop_num"    />
    </resultMap>

    <sql id="selectSpiderMissionVo">
        select a.mission_id, a.mission_name, a.spider_config_id, a.entry_urls, a.status, a.start_time, a.end_time, a.time_cost, a.exit_way, a.exit_way_count, a.success_num,a.cookie_str,a.header_str, a.dept_id, a.user_id, a.create_by, a.create_time,a.loop_flag,a.loop_param,a.loop_num
        from spider_mission a
    </sql>

    <select id="selectSpiderMissionList" parameterType="SpiderMission" resultMap="SpiderMissionResult">
        <include refid="selectSpiderMissionVo"/>
        <where>
            <if test="missionName != null  and missionName != ''"> and a.mission_name like concat('%', #{missionName}, '%')</if>
            <if test="status != null  and status != ''"> and a.status = #{status}</if>

            <!-- 数据范围过滤 -->
            ${params.dataScope}

        </where>
    </select>

    <select id="selectSpiderMissionById" parameterType="Long" resultMap="SpiderMissionResult">
        <include refid="selectSpiderMissionVo"/>
        where a.mission_id = #{missionId}
    </select>

    <insert id="insertSpiderMission" parameterType="SpiderMission" useGeneratedKeys="true" keyProperty="missionId">
        insert into spider_mission
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="missionName != null  and missionName != ''">mission_name,</if>
            <if test="spiderConfigId != null ">spider_config_id,</if>
            <if test="entryUrls != null  and entryUrls != ''">entry_urls,</if>
            <if test="status != null ">status,</if>
            <if test="startTime != null ">start_time,</if>
            <if test="endTime != null ">end_time,</if>
            <if test="timeCost != null  and timeCost != ''">time_cost,</if>
            <if test="exitWay != null  and exitWay != ''">exit_way,</if>
            <if test="exitWayCount != null ">exit_way_count,</if>
            <if test="successNum != null ">success_num,</if>
            cookie_str,
            header_str,
            <if test="deptId != null  and deptId != ''">dept_id,</if>
            <if test="userId != null  and userId != ''">user_id,</if>
            <if test="createBy != null  and createBy != ''">create_by,</if>
            <if test="createTime != null ">create_time,</if>
            <if test="loopFlag != null ">loop_flag,</if>
            <if test="loopParam != null ">loop_param,</if>
            <if test="loopNum != null ">loop_num,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="missionName != null  and missionName != ''">#{missionName},</if>
            <if test="spiderConfigId != null ">#{spiderConfigId},</if>
            <if test="entryUrls != null  and entryUrls != ''">#{entryUrls},</if>
            <if test="status != null ">#{status},</if>
            <if test="startTime != null ">#{startTime},</if>
            <if test="endTime != null ">#{endTime},</if>
            <if test="timeCost != null  and timeCost != ''">#{timeCost},</if>
            <if test="exitWay != null  and exitWay != ''">#{exitWay},</if>
            <if test="exitWayCount != null ">#{exitWayCount},</if>
            <if test="successNum != null ">#{successNum},</if>
            #{cookieStr},
            #{headerStr},
            <if test="deptId != null  and deptId != ''">#{deptId},</if>
            <if test="userId != null  and userId != ''">#{userId},</if>
            <if test="createBy != null  and createBy != ''">#{createBy},</if>
            <if test="createTime != null ">#{createTime},</if>
            <if test="loopFlag != null ">#{loopFlag},</if>
            <if test="loopParam != null ">#{loopParam},</if>
            <if test="loopNum != null ">#{loopNum},</if>
         </trim>
    </insert>

    <update id="updateSpiderMission" parameterType="SpiderMission">
        update spider_mission
        <trim prefix="SET" suffixOverrides=",">
            <if test="missionName != null  and missionName != ''">mission_name = #{missionName},</if>
            <if test="spiderConfigId != null ">spider_config_id = #{spiderConfigId},</if>
            <if test="entryUrls != null  and entryUrls != ''">entry_urls = #{entryUrls},</if>
            <if test="status != null ">status = #{status},</if>
            <if test="startTime != null ">start_time = #{startTime},</if>
            <if test="endTime != null ">end_time = #{endTime},</if>
            <if test="timeCost != null  and timeCost != ''">time_cost = #{timeCost},</if>
            <if test="exitWay != null  and exitWay != ''">exit_way = #{exitWay},</if>
            <if test="exitWayCount != null ">exit_way_count = #{exitWayCount},</if>
            <if test="successNum != null ">success_num = #{successNum},</if>
            cookie_str=#{cookieStr},
            header_str=#{headerStr},
            <if test="deptId != null  and deptId != ''">dept_id = #{deptId},</if>
            <if test="userId != null  and userId != ''">user_id = #{userId},</if>
            <if test="createBy != null  and createBy != ''">create_by = #{createBy},</if>
            <if test="createTime != null ">create_time = #{createTime},</if>
            <if test="loopFlag != null ">loop_flag = #{loopFlag},</if>
            <if test="loopParam != null ">loop_param = #{loopParam},</if>
            <if test="loopNum != null ">loop_num = #{loopNum},</if>
        </trim>
        where mission_id = #{missionId}
    </update>

    <delete id="deleteSpiderMissionById" parameterType="Long">
        delete from spider_mission where mission_id = #{missionId}
    </delete>

    <delete id="deleteSpiderMissionByIds" parameterType="String">
        delete from spider_mission where mission_id in
        <foreach item="missionId" collection="array" open="(" separator="," close=")">
            #{missionId}
        </foreach>
    </delete>

</mapper>
