<?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.ruoyi.sim.mapper.TaskMapper">

    <resultMap type="Task" id="TaskResult">
        <result property="taskId" column="task_id"/>
        <result property="simType" column="sim_type"/>
        <result property="taskType" column="task_type"/>
        <result property="name" column="name"/>
        <result property="createByUserId" column="create_by_user_id"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectTaskVo">
        select task_id,
               sim_type,
               task_type,
               name,
               create_by_user_id,
               create_by,
               create_time,
               update_by,
               update_time,
               remark
        from sim_task
    </sql>

    <select id="selectTaskList" parameterType="Task" resultMap="TaskResult">
        <include refid="selectTaskVo"/>
        <where>
            <if test="simType != null  and simType != ''">and sim_type = #{simType}</if>
            <if test="taskType != null  and taskType != ''">and task_type = #{taskType}</if>
            <if test="name != null  and name != ''">and name like concat('%', #{name}, '%')</if>
            <if test="createByUserId != null ">and create_by_user_id = #{createByUserId}</if>
        </where>
    </select>

    <select id="selectTaskByTaskId" parameterType="Long" resultMap="TaskResult">
        <include refid="selectTaskVo"/>
        where task_id = #{taskId}
    </select>

    <insert id="insertTask" parameterType="Task">
        <selectKey keyProperty="taskId" order="AFTER" resultType="java.lang.Long">
            select LAST_INSERT_ID()
        </selectKey>
        insert into sim_task
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="taskId != null">task_id,</if>
            <if test="simType != null">sim_type,</if>
            <if test="taskType != null">task_type,</if>
            <if test="name != null">name,</if>
            <if test="createByUserId != null">create_by_user_id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="taskId != null">#{taskId},</if>
            <if test="simType != null">#{simType},</if>
            <if test="taskType != null">#{taskType},</if>
            <if test="name != null">#{name},</if>
            <if test="createByUserId != null">#{createByUserId},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateTask" parameterType="Task">
        update sim_task
        <trim prefix="SET" suffixOverrides=",">
            <if test="simType != null">sim_type = #{simType},</if>
            <if test="taskType != null">task_type = #{taskType},</if>
            <if test="name != null">name = #{name},</if>
            <if test="createByUserId != null">create_by_user_id = #{createByUserId},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where task_id = #{taskId}
    </update>

    <delete id="deleteTaskByTaskId" parameterType="Long">
        delete
        from sim_task
        where task_id = #{taskId}
    </delete>

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