<?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.ruoyi.system.mapper.AttendanceTimeMapper">
    
    <resultMap type="AttendanceTime" id="AttendanceTimeResult">
        <result property="id"    column="id"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="deptId"    column="dept_id"    />
        <result property="deptName"    column="dept_name"    />
        <result property="submitTime"    column="submit_time"    />
    </resultMap>

    <sql id="selectAttendanceTimeVo">
        select id, start_time, end_time, dept_id, dept_name, submit_time from attendance_time
    </sql>

    <select id="selectAttendanceTimeList" parameterType="AttendanceTime" resultMap="AttendanceTimeResult">
        <include refid="selectAttendanceTimeVo"/>
        <where>  
            <if test="startTime != null "> and start_time = #{startTime}</if>
            <if test="endTime != null "> and end_time = #{endTime}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="deptName != null  and deptName != ''"> and dept_name like concat('%', #{deptName}, '%')</if>
            <if test="submitTime != null "> and submit_time = #{submitTime}</if>
        </where>
    </select>
    
    <select id="selectAttendanceTimeById" parameterType="Long" resultMap="AttendanceTimeResult">
        <include refid="selectAttendanceTimeVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertAttendanceTime" parameterType="AttendanceTime" useGeneratedKeys="true" keyProperty="id">
        insert into attendance_time
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="deptName != null">dept_name,</if>
            <if test="submitTime != null">submit_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="deptName != null">#{deptName},</if>
            <if test="submitTime != null">#{submitTime},</if>
         </trim>
    </insert>

    <update id="updateAttendanceTime" parameterType="AttendanceTime">
        update attendance_time
        <trim prefix="SET" suffixOverrides=",">
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="deptName != null">dept_name = #{deptName},</if>
            <if test="submitTime != null">submit_time = #{submitTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAttendanceTimeById" parameterType="Long">
        delete from attendance_time where id = #{id}
    </delete>

    <delete id="deleteAttendanceTimeByIds" parameterType="String">
        delete from attendance_time where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>