<?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.younike.system.mapper.MerchantServerTimeMapper">

    <resultMap type="ServerTimesVO" id="ServerTimeResult">
        <result property="serverId"    column="server_id"    />
        <result property="stopOrder"    column="stop_order"    />
        <result property="allowEdit"    column="allow_edit"    />
        <result property="serverGrap"    column="server_grap"    />
        <result property="loginIp"    column="login_ip"    />
        <result property="loginDate"    column="login_date"    />
        <result property="delFlag"    column="del_flag"    />
        <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="column1"    column="column1"    />
        <result property="column2"    column="column2"    />
        <result property="column3"    column="column3"    />
        <result property="hoursFrom"    column="hours_from"    />
        <result property="weeks"    column="weeks"    />
        <result property="hoursEnd"    column="hours_end"    />
        <result property="sectionId"    column="section_id"    />
    </resultMap>

    <sql id="selectServerTimeVo">
        select
            st.server_id, stop_order, allow_edit, server_grap, login_ip, login_date,
            st.del_flag,
            st.create_by,
            st.create_time,
            st.update_by,
            st.update_time,
            st.column1, st.column2, st.column3,
            sts.weeks,
            sts.hours_from,
            sts.hours_end,
            sts.section_id
            from server_time st
            left join server_time_section sts on sts.server_id= st.server_id
    </sql>

    <select id="selectServerTimeList" parameterType="ServerTime" resultMap="ServerTimeResult">
        <include refid="selectServerTimeVo"/>
        <where>
            <if test="stopOrder != null "> and stop_order = #{stopOrder}</if>
            <if test="allowEdit != null "> and allow_edit = #{allowEdit}</if>
            <if test="serverGrap != null "> and server_grap = #{serverGrap}</if>
            <if test="loginIp != null  and loginIp != ''"> and login_ip = #{loginIp}</if>
            <if test="loginDate != null "> and login_date = #{loginDate}</if>
            <if test="column1 != null  and column1 != ''"> and st.column1 = #{column1}</if>
            <if test="column2 != null  and column2 != ''"> and st.column2 = #{column2}</if>
            <if test="column3 != null  and column3 != ''"> and st.column3 = #{column3}</if>
            <if test="serverId != null  and serverId != ''"> and st.server_id = #{serverId}</if>
        </where>
    </select>

    <select id="selectServerTimeByServerId" parameterType="Long" resultMap="ServerTimeResult">
        <include refid="selectServerTimeVo"/>
        where st.server_id = #{serverId}
    </select>

    <insert id="insertServerTime" parameterType="ServerTime" useGeneratedKeys="true" keyProperty="serverId">
        insert into server_time
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="stopOrder != null">stop_order,</if>
            <if test="allowEdit != null">allow_edit,</if>
            <if test="serverGrap != null">server_grap,</if>
            <if test="loginIp != null">login_ip,</if>
            <if test="loginDate != null">login_date,</if>
            <if test="delFlag != null">del_flag,</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="column1 != null">column1,</if>
            <if test="column2 != null">column2,</if>
            <if test="column3 != null">column3,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="stopOrder != null">#{stopOrder},</if>
            <if test="allowEdit != null">#{allowEdit},</if>
            <if test="serverGrap != null">#{serverGrap},</if>
            <if test="loginIp != null">#{loginIp},</if>
            <if test="loginDate != null">#{loginDate},</if>
            <if test="delFlag != null">#{delFlag},</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="column1 != null">#{column1},</if>
            <if test="column2 != null">#{column2},</if>
            <if test="column3 != null">#{column3},</if>
        </trim>
    </insert>

    <update id="updateServerTime" parameterType="ServerTimeVo">
        update server_time
        <trim prefix="SET" suffixOverrides=",">
            <if test="stopOrder != null">stop_order = #{stopOrder},</if>
            <if test="allowEdit != null">allow_edit = #{allowEdit},</if>
            <if test="serverGrap != null">server_grap = #{serverGrap},</if>
            <if test="loginIp != null">login_ip = #{loginIp},</if>
            <if test="loginDate != null">login_date = #{loginDate},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</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="column1 != null">column1 = #{column1},</if>
            <if test="column2 != null">column2 = #{column2},</if>
            <if test="column3 != null">column3 = #{column3},</if>
        </trim>
        where server_id = #{serverId}
    </update>

    <delete id="deleteServerTimeByServerId" parameterType="Long">
        delete from server_time where server_id = #{serverId}
    </delete>

    <delete id="deleteServerTimeByServerIds" parameterType="String">
        delete from server_time where server_id in
        <foreach item="serverId" collection="array" open="(" separator="," close=")">
            #{serverId}
        </foreach>
    </delete>
    <insert id="insertServerTimeCustom" parameterType="ServerTime" useGeneratedKeys="true" keyProperty="serverId">
        insert into server_time
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="serverId != null">server_id,</if>
            <if test="stopOrder != null">stop_order,</if>
            <if test="allowEdit != null">allow_edit,</if>
            <if test="serverGrap != null">server_grap,</if>
            <if test="loginIp != null">login_ip,</if>
            <if test="loginDate != null">login_date,</if>
            <if test="delFlag != null">del_flag,</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="column1 != null">column1,</if>
            <if test="column2 != null">column2,</if>
            <if test="column3 != null">column3,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="serverId != null">#{serverId},</if>
            <if test="stopOrder != null">#{stopOrder},</if>
            <if test="allowEdit != null">#{allowEdit},</if>
            <if test="serverGrap != null">#{serverGrap},</if>
            <if test="loginIp != null">#{loginIp},</if>
            <if test="loginDate != null">#{loginDate},</if>
            <if test="delFlag != null">#{delFlag},</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="column1 != null">#{column1},</if>
            <if test="column2 != null">#{column2},</if>
            <if test="column3 != null">#{column3},</if>
        </trim>
    </insert>

</mapper>
