<?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.baseinfo.mapper.BaseEmployeeInfoMapper">

    <resultMap type="BaseEmployeeInfo" id="BaseEmployeeInfoResult">
        <result property="objid"    column="objid"    />
        <result property="empId"    column="emp_id"    />
        <result property="empName"    column="emp_name"    />
        <result property="carNo"    column="car_no"    />
        <result property="deptId"    column="dept_id"    />
        <result property="postId"    column="post_id"    />
        <result property="empStateId"    column="emp_state_id"    />
        <result property="status"    column="status"    />
        <result property="remark"    column="remark"    />
        <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="delFlag"    column="del_flag"    />
        <result property="postName"    column="post_name"    />
        <association property="dept" column="dept_id" javaType="SysDept" resultMap="deptResult"/>
    </resultMap>

    <resultMap id="deptResult" type="SysDept">
        <id property="deptId" column="dept_id"/>
        <result property="parentId" column="parent_id"/>
        <result property="deptName" column="dept_name"/>
        <result property="orderNum" column="order_num"/>
        <result property="leader" column="leader"/>
        <result property="status" column="dept_status"/>
    </resultMap>

    <sql id="selectBaseEmployeeInfoVo">
        select objid, emp_id, emp_name, car_no, dept_id, post_id, emp_state_id, status, remark, create_by, create_time, update_by, update_time, del_flag from base_employee_info
    </sql>

    <select id="selectBaseEmployeeInfoList" parameterType="BaseEmployeeInfo" resultMap="BaseEmployeeInfoResult">
        select t1.objid, t1.emp_id, t1.emp_name, t1.car_no, t1.dept_id, t1.post_id,t2.post_name, emp_state_id, t1.status, t1.remark, t1.create_by, t1.create_time, t1.update_by, t1.update_time, t1.del_flag,t3.dept_name from base_employee_info t1 left join base_post_info t2 on t1.post_id = t2.post_id left join sys_dept t3 on t1.dept_id = t3.dept_id
        <where>
            <if test="empId != null  and empId != ''"> and t1.emp_id = #{empId}</if>
            <if test="empName != null  and empName != ''"> and t1.emp_name like ('%' + #{empName} + '%')</if>
            <if test="carNo != null  and carNo != ''"> and t1.car_no = #{carNo}</if>
            <if test="deptId != null and deptId != ''"> and t1.dept_id = #{deptId}</if>
            <if test="postId != null  and postId != ''"> and t1.post_id = #{postId}</if>
            <if test="empStateId != null  and empStateId != ''"> and t1.emp_state_id = #{empStateId}</if>
            <if test="status != null  and status != ''"> and t1.status = #{status}</if>
        </where>
    </select>

    <select id="selectBaseEmployeeInfoById" parameterType="Long" resultMap="BaseEmployeeInfoResult">
        select t1.objid, t1.emp_id, t1.emp_name, t1.car_no, t1.dept_id, t1.post_id,t2.post_name, emp_state_id, t1.status, t1.remark, t1.create_by, t1.create_time, t1.update_by, t1.update_time, t1.del_flag,t3.dept_name from base_employee_info t1 left join base_post_info t2 on t1.post_id = t2.post_id left join sys_dept t3 on t1.dept_id = t3.dept_id
        where t1.objid = #{objid}
    </select>

    <insert id="insertBaseEmployeeInfo" parameterType="BaseEmployeeInfo">
        insert into base_employee_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="objid != null">objid,</if>
            <if test="empId != null">emp_id,</if>
            <if test="empName != null">emp_name,</if>
            <if test="carNo != null">car_no,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="postId != null">post_id,</if>
            <if test="empStateId != null">emp_state_id,</if>
            <if test="status != null">status,</if>
            <if test="remark != null">remark,</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="delFlag != null">del_flag,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="objid != null">#{objid},</if>
            <if test="empId != null">#{empId},</if>
            <if test="empName != null">#{empName},</if>
            <if test="carNo != null">#{carNo},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="postId != null">#{postId},</if>
            <if test="empStateId != null">#{empStateId},</if>
            <if test="status != null">#{status},</if>
            <if test="remark != null">#{remark},</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="delFlag != null">#{delFlag},</if>
         </trim>
    </insert>

    <update id="updateBaseEmployeeInfo" parameterType="BaseEmployeeInfo">
        update base_employee_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="empId != null">emp_id = #{empId},</if>
            <if test="empName != null">emp_name = #{empName},</if>
            <if test="carNo != null">car_no = #{carNo},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="postId != null">post_id = #{postId},</if>
            <if test="empStateId != null">emp_state_id = #{empStateId},</if>
            <if test="status != null">status = #{status},</if>
            <if test="remark != null">remark = #{remark},</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="delFlag != null">del_flag = #{delFlag},</if>
        </trim>
        where objid = #{objid}
    </update>

    <delete id="deleteBaseEmployeeInfoById" parameterType="Long">
        delete from base_employee_info where objid = #{objid}
    </delete>

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

</mapper>
