<?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.railway.system.mapper.SysScheduledTaskMapper">

    <resultMap id="BaseResultMap" type="com.railway.system.domain.SysScheduledTask">
                <result column="id" property="id"/>
                <result column="name" property="name"/>
                <result column="cron" property="cron"/>
                <result column="open" property="open"/>
    </resultMap>

    <sql id="Base_Column_List">
                id,
                `name`,
                cron,
                `open`
    </sql>

    <insert id="insert" parameterType="com.railway.system.domain.SysScheduledTask">
        <selectKey keyProperty="id" order="BEFORE" resultType="String">
            select replace(uuid(), '-', '') from dual
        </selectKey>
        INSERT INTO sys_scheduled_task
        <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test ='null != name'>
                        `name`,
                    </if>
                    <if test ='null != cron'>
                        cron,
                    </if>
                    <if test ='null != open'>
                        `open`
                    </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                    <if test ='null != name'>
                    #{name},
                    </if>
                    <if test ='null != cron'>
                    #{cron},
                    </if>
                    <if test ='null != open'>
                    #{open}
                    </if>
        </trim>
    </insert>

    <delete id="delete">
        delete from sys_scheduled_task
        WHERE id = #{id}
    </delete>

    <update id="update" parameterType="com.railway.system.domain.SysScheduledTask">
        UPDATE sys_scheduled_task
        <set>
                    <if test ='null != name'>`name` = #{name},</if>
                    <if test ='null != cron'>cron = #{cron},</if>
                    <if test ='null != open'>`open` = #{open}</if>
        </set>
        WHERE id = #{id}
    </update>


    <select id="getInfo" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM sys_scheduled_task
        WHERE id = #{id}
    </select>

    <select id="getInfoByName" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM sys_scheduled_task
        WHERE `name` = #{name}
    </select>

    <select id="getList" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM sys_scheduled_task
        <where>
                <if test="name!=null and name!=''">
                    and `name`=#{name}
                </if>
                <if test="cron!=null and cron!=''">
                    and cron=#{cron}
                </if>
                <if test="open!=null and open!=''">
                    and `open`=#{open}
                </if>
        </where>
    </select>

</mapper>