<?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.lz.modules.luck.dao.LuckMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.lz.modules.luck.entity.Luck">
        <id column="id" property="id"/>
        <result column="is_delete" property="isDelete"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="gmt_modified" property="gmtModified"/>
        <result column="name" property="name"/>
        <result column="goods_count" property="goodsCount"/>
        <result column="remark" property="remark"/>
        <result column="finish" property="finish"/>
        <result column="stop_time" property="stopTime"/>
        <result column="start_time" property="startTime"/>
    </resultMap>


    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id AS id, is_delete AS isDelete, gmt_create AS gmtCreate, gmt_modified AS gmtModified, name AS name, goods_count AS goodsCount, remark AS remark, finish AS finish, stop_time AS stopTime, start_time AS startTime
    </sql>




    <select id="selectLuckById" resultType="Luck" >
        select * from luck  where id=#{id} and is_delete = 0 limit 1 
    </select>


    <insert id="insertLuck" parameterType="Luck" useGeneratedKeys="true" keyProperty="id" >
        insert into luck(
            <if test="name != null">name, </if>
            <if test="goodsCount != null">goods_count, </if>
            <if test="remark != null">remark, </if>
            <if test="finish != null">finish, </if>
            <if test="stopTime != null">stop_time, </if>
            <if test="startTime != null">start_time, </if>
            is_delete,
            gmt_create,
            gmt_modified
        )values(
            <if test="name != null">#{ name}, </if>
            <if test="goodsCount != null">#{ goodsCount}, </if>
            <if test="remark != null">#{ remark}, </if>
            <if test="finish != null">#{ finish}, </if>
            <if test="stopTime != null">#{ stopTime}, </if>
            <if test="startTime != null">#{ startTime}, </if>
            0,
            now(),
            now()
        )
    </insert>


    <update id="updateLuckById" parameterType="Luck" >
        update
            luck
        <trim prefix="set" suffixOverrides=",">
            <if test="isDelete != null">is_delete = #{isDelete},</if>
            <if test="gmtCreate != null">gmt_create = #{gmtCreate},</if>
            <if test="name != null">name = #{name},</if>
            <if test="goodsCount != null">goods_count = #{goodsCount},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="finish != null">finish = #{finish},</if>
            <if test="stopTime != null">stop_time = #{stopTime},</if>
            <if test="startTime != null">start_time = #{startTime}</if>                
        </trim>
        ,gmt_modified = now()
        where id = #{id}
    </update>


    <update id="updateCoverLuckById" parameterType="Luck" >
        update
            luck    
        set     
            is_delete = #{isDelete},
            gmt_create = #{gmtCreate},
            name = #{name},
            goods_count = #{goodsCount},
            remark = #{remark},
            finish = #{finish},
            stop_time = #{stopTime},
            start_time = #{startTime}                
        ,gmt_modified = now()
        where id = #{id}
    </update>


    <update id="deleteLuckById" parameterType="java.lang.Long">
        update luck set is_delete = 1, gmt_modified=now() where id=#{id} limit 1
    </update>

    <update id="setLuckFinishById" parameterType="java.lang.Long">
        update luck set finish = 1, gmt_modified=now() where id=#{luckId} limit 1
    </update>

</mapper>

