<?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.securitycontrol.background.mapper.DutyPlanMapper">

    <!--新增/修改值班计划-->

    <insert id="replaceDutyPlan">
        replace into  tb_duty_plan
            <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="createDay != null and createDay != ''">create_day,</if>
                <if test="type != null and type != ''">type,</if>
                <if test="mon != null and mon != ''">mon,</if>
                <if test="tue != null and tue!=''">tue,</if>
                <if test="wed != null and wed!=''">wed,</if>
                <if test="thu != null and thu!=''">thu,</if>
                <if test="fri != null and fri!=''">fri,</if>
                <if test="sat != null and sat!=''">sat,</if>
                <if test="sun != null and sun!=''">sun,</if>
                update_time
            </trim>
            <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="createDay != null and createDay != ''">#{createDay},</if>
                <if test="type != null and type != ''">#{type},</if>
                <if test="mon != null and mon != ''">#{mon},</if>
                <if test="tue != null and tue!=''">#{tue},</if>
                <if test="wed != null and wed!=''">#{wed},</if>
                <if test="thu != null and thu!=''">#{thu},</if>
                <if test="fri != null and fri!=''">#{fri},</if>
                <if test="sat != null and sat!=''">#{sat},</if>
                <if test="sun != null and sun!=''">#{sun},</if>
                now()
            </trim>

    </insert>

    <!--获取值班计划列表-->
    <select id="getDutyPlan" resultType="com.securitycontrol.entity.background.vo.DutyPlanVo">
        SELECT
        tdp.create_day as createDay,
        tdp.type as type,
        tdp.mon as mon,
        tdp.tue as tue,
        tdp.wed as wed,
        tdp.thu as thu,
        tdp.fri as fri,
        tdp.sat as sat,
        tdp.sun as sun
        FROM tb_duty_plan tdp
       where   tdp.del_flag=0
                <if test="createDay !=null and createDay!=''">
                    AND tdp.create_day=#{createDay}
                </if>
                <if test="type !=null and type!=''">
                    AND tdp.type=#{type}
                </if>

        ORDER by create_time

    </select>
</mapper>