<?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.sgbg18.mapper.EmployeeMapper_ztb18326">

    <resultMap type="com.sgbg18.entity.Employee_ztb18326" id="EmployeeMap">
        <result property="empId" column="emp_id" jdbcType="INTEGER"/>
        <result property="empName" column="emp_name" jdbcType="VARCHAR"/>
        <result property="empDepartment" column="emp_department" jdbcType="VARCHAR"/>
        <result property="empBirthday" column="emp_birthday" jdbcType="TIMESTAMP"/>
        <result property="empPhoto" column="emp_photo" jdbcType="VARCHAR"/>
        <result property="empTel" column="emp_tel" jdbcType="VARCHAR"/>
    </resultMap>

    <!--查询单个-->
    <select id="queryById" resultMap="EmployeeMap">
        select
          emp_id, emp_name, emp_department, emp_birthday, emp_photo, emp_tel
        from emp.employee
        where emp_id = #{empId}
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="EmployeeMap">
        select
          emp_id, emp_name, emp_department, emp_birthday, emp_photo, emp_tel
        from emp.employee
        limit #{offset}, #{limit}
    </select>

    <!--通过实体作为筛选条件查询-->
    <select id="queryAll" resultMap="EmployeeMap">
        select
        emp_id, emp_name, emp_department, emp_birthday, emp_photo, emp_tel
        from emp.employee
        <where>
            <if test="empId != null">
                and emp_id = #{empId}
            </if>
            <if test="empName != null and empName != ''">
                and emp_name = #{empName}
            </if>
            <if test="empDepartment != null and empDepartment != ''">
                and emp_department = #{empDepartment}
            </if>
            <if test="empBirthday != null">
                and emp_birthday = #{empBirthday}
            </if>
            <if test="empPhoto != null and empPhoto != ''">
                and emp_photo = #{empPhoto}
            </if>
            <if test="empTel != null and empTel != ''">
                and emp_tel = #{empTel}
            </if>
        </where>
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="empId" useGeneratedKeys="true">
        insert into emp.employee(emp_id,emp_name, emp_department, emp_birthday, emp_photo, emp_tel)
        values (#{empId},#{empName}, #{empDepartment}, #{empBirthday}, #{empPhoto}, #{empTel})
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update emp.employee
        <set>
            <if test="empName != null and empName != ''">
                emp_name = #{empName},
            </if>
            <if test="empDepartment != null and empDepartment != ''">
                emp_department = #{empDepartment},
            </if>
            <if test="empBirthday != null">
                emp_birthday = #{empBirthday},
            </if>
            <if test="empPhoto != null and empPhoto != ''">
                emp_photo = #{empPhoto},
            </if>
            <if test="empTel != null and empTel != ''">
                emp_tel = #{empTel},
            </if>
        </set>
        where emp_id = #{empId}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        delete from emp.employee where emp_id = #{empId}
    </delete>

</mapper>