<?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.ho.flow.mapper.WorkOrderPlanMapper">

    <sql id="Base_Column_List">
        id
        ,user_id,group_id,
        date_type,`day`,exec_day,effect_date,
        expire_date,order_type,plan_title,
        `desc`
    </sql>

    <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultType="com.ho.flow.entity.WorkOrderPlan">
        select
        <include refid="Base_Column_List"/>
        from work_order_plan
        where id = #{id,jdbcType=INTEGER}
    </select>

    <select id="selectAll" resultType="com.ho.flow.entity.WorkOrderPlan">
        select
        <include refid="Base_Column_List"/>
        from work_order_plan
        order by effect_date desc
    </select>
    <select id="selectByGroupId" resultType="com.ho.flow.entity.WorkOrderPlan">
        select
        <include refid="Base_Column_List"/>
        from work_order_plan
        <where>
            <if test="groupId != null">
                group_id = #{groupId}
            </if>
        </where>
    </select>


    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
        delete
        from work_order_plan
        where id = #{id,jdbcType=INTEGER}
    </delete>
    <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.ho.flow.entity.WorkOrderPlan"
            useGeneratedKeys="true">
        insert into work_order_plan
        ( user_id, group_id
        , date_type, `day`, exec_day, effect_date
        , expire_date, order_type, plan_title
        , `desc`)
        values ( #{jdbcType=INTEGER}, #{userId,jdbcType=VARCHAR}, #{groupId,jdbcType=INTEGER}
               , #{dateType,jdbcType=VARCHAR}, #{day,jdbcType=INTEGER}, #{execDay,jdbcType=INTEGER}
               , #{effectDate,jdbcType=TIMESTAMP}
               , #{expireDate,jdbcType=TIMESTAMP}, #{orderType,jdbcType=INTEGER}, #{planTitle,jdbcType=VARCHAR}
               , #{desc,jdbcType=VARCHAR})
    </insert>
    <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.ho.flow.entity.WorkOrderPlan"
            useGeneratedKeys="true">
        insert into work_order_plan
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="groupId != null">group_id,</if>
            <if test="dateType != null">date_type,</if>
            <if test="day != null">`day`,</if>
            <if test="execDay != null">exec_day,</if>
            <if test="effectDate != null">effect_date,</if>
            <if test="expireDate != null">expire_date,</if>
            <if test="orderType != null">order_type,</if>
            <if test="planTitle != null">plan_title,</if>
            <if test="desc != null">`desc`,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId,jdbcType=VARCHAR},</if>
            <if test="groupId != null">#{groupId,jdbcType=INTEGER},</if>
            <if test="dateType != null">#{dateType,jdbcType=VARCHAR},</if>
            <if test="day != null">#{day,jdbcType=INTEGER},</if>
            <if test="execDay != null">#{execDay,jdbcType=INTEGER},</if>
            <if test="effectDate != null">#{effectDate,jdbcType=TIMESTAMP},</if>
            <if test="expireDate != null">#{expireDate,jdbcType=TIMESTAMP},</if>
            <if test="orderType != null">#{orderType,jdbcType=INTEGER},</if>
            <if test="planTitle != null">#{planTitle,jdbcType=VARCHAR},</if>
            <if test="desc != null">#{desc,jdbcType=VARCHAR},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.ho.flow.entity.WorkOrderPlan">
        update work_order_plan
        <set>
            <if test="userId != null">
                user_id = #{userId,jdbcType=VARCHAR},
            </if>
            <if test="groupId != null">
                group_id = #{groupId,jdbcType=INTEGER},
            </if>
            <if test="dateType != null">
                date_type = #{dateType,jdbcType=VARCHAR},
            </if>
            <if test="day != null">
                `day` = #{day,jdbcType=INTEGER},
            </if>
            <if test="execDay != null">
                exec_day = #{execDay,jdbcType=INTEGER},
            </if>
            <if test="effectDate != null">
                effect_date = #{effectDate,jdbcType=TIMESTAMP},
            </if>
            <if test="expireDate != null">
                expire_date = #{expireDate,jdbcType=TIMESTAMP},
            </if>
            <if test="orderType != null">
                order_type = #{orderType,jdbcType=INTEGER},
            </if>
            <if test="planTitle != null">
                plan_title = #{planTitle,jdbcType=VARCHAR},
            </if>
            <if test="desc != null">
                `desc` = #{desc,jdbcType=VARCHAR},
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.ho.flow.entity.WorkOrderPlan">
        update work_order_plan
        set user_id     = #{userId,jdbcType=VARCHAR},
            group_id    = #{groupId,jdbcType=INTEGER},
            date_type   = #{dateType,jdbcType=VARCHAR},
            `day`       = #{day,jdbcType=INTEGER},
            exec_day    = #{execDay,jdbcType=INTEGER},
            effect_date = #{effectDate,jdbcType=TIMESTAMP},
            expire_date = #{expireDate,jdbcType=TIMESTAMP},
            order_type  = #{orderType,jdbcType=INTEGER},
            plan_title  = #{planTitle,jdbcType=VARCHAR},
            `desc`      = #{desc,jdbcType=VARCHAR}
        where id = #{id,jdbcType=INTEGER}
    </update>
</mapper>
