<?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.BusinessUserMapper">
    
    <resultMap type="BusinessUser" id="BusinessUserResult">
        <result property="id"    column="id"    />
        <result property="businessId"    column="business_id"    />
        <result property="deptId"    column="dept_id"    />
        <result property="deptName"    column="dept_name"    />
        <result property="absenteeId"    column="absentee_id"    />
        <result property="absenteeName"    column="absentee_name"    />
        <result property="type"    column="type"    />
        <result property="submitTime"    column="submit_time"    />
    </resultMap>

    <sql id="selectBusinessUserVo">
        select id, business_id, dept_id, dept_name, absentee_id, absentee_name,type, submit_time from business_user
    </sql>

    <select id="selectBusinessUserList" parameterType="BusinessUser" resultMap="BusinessUserResult">
        <include refid="selectBusinessUserVo"/>
        <where>  
            <if test="businessId != null "> and business_id = #{businessId}</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="absenteeId != null  and absenteeId != ''"> and absentee_id = #{absenteeId}</if>
            <if test="absenteeName != null  and absenteeName != ''"> and absentee_name like concat('%', #{absenteeName}, '%')</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="submitTime != null "> and submit_time = #{submitTime}</if>
        </where>
    </select>
    
    <select id="selectBusinessUserById" parameterType="Long" resultMap="BusinessUserResult">
        <include refid="selectBusinessUserVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertBusinessUser" parameterType="BusinessUser" useGeneratedKeys="true" keyProperty="id">
        insert into business_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="businessId != null">business_id,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="deptName != null">dept_name,</if>
            <if test="absenteeId != null">absentee_id,</if>
            <if test="absenteeName != null">absentee_name,</if>
            <if test="type != null ">  type ,</if>
            <if test="submitTime != null">submit_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="businessId != null">#{businessId},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="deptName != null">#{deptName},</if>
            <if test="absenteeId != null">#{absenteeId},</if>
            <if test="absenteeName != null">#{absenteeName},</if>
            <if test="type != null "> #{type},</if>
            <if test="submitTime != null">#{submitTime},</if>
         </trim>
    </insert>

    <update id="updateBusinessUser" parameterType="BusinessUser">
        update business_user
        <trim prefix="SET" suffixOverrides=",">
            <if test="businessId != null">business_id = #{businessId},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="deptName != null">dept_name = #{deptName},</if>
            <if test="absenteeId != null">absentee_id = #{absenteeId},</if>
            <if test="absenteeName != null">absentee_name = #{absenteeName},</if>
            <if test="type != null ">  type = #{type},</if>
            <if test="submitTime != null">submit_time = #{submitTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBusinessUserById" parameterType="Long">
        delete from business_user where id = #{id}
    </delete>

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