<?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.voluntary.mapper.BusiAgentsMapper">

    <resultMap type="BusiAgents" id="BusiAgentsResult">
        <result property="agentId"    column="agent_id"    />
        <result property="agentType"    column="agent_type"    />
        <result property="phonenumber"    column="phonenumber"    />
        <result property="name"    column="name"    />
        <result property="status"    column="status"    />
        <result property="createTime"    column="create_time"    />
        <result property="userId"    column="user_id"    />
    </resultMap>

    <sql id="selectBusiAgentsVo">
        select agent_id, agent_type, phonenumber, name, status, create_time,user_id from b_busi_agents
    </sql>

    <select id="selectBusiAgentsList" parameterType="BusiAgents" resultMap="BusiAgentsResult">
        <include refid="selectBusiAgentsVo"/>
        <where>
            <if test="agentType != null "> and agent_type = #{agentType}</if>
            <if test="phonenumber != null  and phonenumber != ''"> and phonenumber = #{phonenumber}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
        </where>
        order by agent_id desc
    </select>

    <select id="selectBusiAgentsByAgentId" parameterType="Long" resultMap="BusiAgentsResult">
        <include refid="selectBusiAgentsVo"/>
        where agent_id = #{agentId}
    </select>

    <select id="selectBusiAgentsByUserId" parameterType="Long" resultMap="BusiAgentsResult">
        <include refid="selectBusiAgentsVo"/>
        where user_id = #{userId}
    </select>

    <insert id="insertBusiAgents" parameterType="BusiAgents" useGeneratedKeys="true" keyProperty="agentId">
        insert into b_busi_agents
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="agentType != null">agent_type,</if>
            <if test="phonenumber != null">phonenumber,</if>
            <if test="name != null">name,</if>
            <if test="status != null">status,</if>
            <if test="createTime != null">create_time,</if>
            <if test="userId != null">user_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="agentType != null">#{agentType},</if>
            <if test="phonenumber != null">#{phonenumber},</if>
            <if test="name != null">#{name},</if>
            <if test="status != null">#{status},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="userId != null">#{userId},</if>
         </trim>
    </insert>

    <update id="updateBusiAgents" parameterType="BusiAgents">
        update b_busi_agents
        <trim prefix="SET" suffixOverrides=",">
            <if test="agentType != null">agent_type = #{agentType},</if>
            <if test="phonenumber != null">phonenumber = #{phonenumber},</if>
            <if test="name != null">name = #{name},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createTime != null">user_id = #{createTime},</if>
        </trim>
        where agent_id = #{agentId}
    </update>

    <delete id="deleteBusiAgentsByAgentId" parameterType="Long">
        delete from b_busi_agents where agent_id = #{agentId}
    </delete>

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