<?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.younike.system.mapper.AgentMapper">

    <resultMap type="com.younike.system.domain.Agent" id="AgentResult">
        <result property="agentId"    column="agent_id"    />
        <result property="agentIndex"    column="agent_index"    />
        <result property="agentName"    column="agent_name"    />
        <result property="agentContactName"    column="agent_contact_name"    />
        <result property="agentContactPhone"    column="agent_contact_phone"    />
        <result property="commissionRate"    column="commission_rate"    />
        <result property="wxAccount"    column="wx_account"    />
        <result property="aliAccount"    column="ali_account"    />
        <result property="delFlag"    column="del_flag"    />
        <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="remark"    column="remark"    />
        <result property="column1"    column="column1"    />
        <result property="column2"    column="column2"    />
        <result property="column3"    column="column3"    />
    </resultMap>

    <sql id="selectAgentVo">
        select agent_id, agent_index, agent_name, agent_contact_name, agent_contact_phone, commission_rate, wx_account, ali_account, del_flag, create_by, create_time, update_by, update_time, remark, column1, column2, column3 from agent
    </sql>

    <select id="selectAgentList" parameterType="com.younike.system.domain.Agent" resultMap="AgentResult">
        <include refid="selectAgentVo"/>
        <where>
            del_flag = '0'
            <if test="agentIndex != null  and agentIndex != ''"> and agent_index like concat('%', #{agentIndex}, '%' )</if>
            <if test="agentName != null  and agentName != ''"> and agent_name like concat('%', #{agentName}, '%')</if>
            <if test="agentContactName != null  and agentContactName != ''"> and agent_contact_name like concat('%', #{agentContactName}, '%')</if>
            <if test="agentContactPhone != null  and agentContactPhone != ''"> and agent_contact_phone like concat('%',#{agentContactPhone},'%')</if>
            <if test="wxAccount != null  and wxAccount != ''"> and wx_account = #{wxAccount}</if>
            <if test="aliAccount != null  and aliAccount != ''"> and ali_account = #{aliAccount}</if>
            <if test="column1 != null  and column1 != ''"> and column1 = #{column1}</if>
            <if test="column2 != null  and column2 != ''"> and column2 = #{column2}</if>
            <if test="column3 != null  and column3 != ''"> and column3 = #{column3}</if>
             order by create_time desc
        </where>
    </select>

    <select id="selectAgentByAgentId" parameterType="Long" resultMap="AgentResult">
        <include refid="selectAgentVo"/>
        where agent_id = #{agentId}
    </select>

    <insert id="insertAgent" parameterType="com.younike.system.domain.Agent" useGeneratedKeys="true" keyProperty="agentId">
        insert into agent
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="agentIndex != null and agentIndex != ''">agent_index,</if>
            <if test="agentName != null and agentName != ''">agent_name,</if>
            <if test="agentContactName != null and agentContactName != ''">agent_contact_name,</if>
            <if test="agentContactPhone != null and agentContactPhone != ''">agent_contact_phone,</if>
            <if test="commissionRate != null and commissionRate != ''">commission_rate,</if>
            <if test="wxAccount != null and wxAccount != ''">wx_account,</if>
            <if test="aliAccount != null and aliAccount != ''">ali_account,</if>
            <if test="delFlag != null and delFlag != ''">del_flag,</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="remark != null">remark,</if>
            <if test="column1 != null">column1,</if>
            <if test="column2 != null">column2,</if>
            <if test="column3 != null">column3,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="agentIndex != null and agentIndex != ''">#{agentIndex},</if>
            <if test="agentName != null and agentName != ''">#{agentName},</if>
            <if test="agentContactName != null and agentContactName != ''">#{agentContactName},</if>
            <if test="agentContactPhone != null and agentContactPhone != ''">#{agentContactPhone},</if>
            <if test="commissionRate != null and commissionRate != ''">#{commissionRate},</if>
            <if test="wxAccount != null and wxAccount != ''">#{wxAccount},</if>
            <if test="aliAccount != null and aliAccount != ''">#{aliAccount},</if>
            <if test="delFlag != null and delFlag != ''">#{delFlag},</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="remark != null">#{remark},</if>
            <if test="column1 != null">#{column1},</if>
            <if test="column2 != null">#{column2},</if>
            <if test="column3 != null">#{column3},</if>
         </trim>
    </insert>

    <update id="updateAgent" parameterType="com.younike.system.domain.Agent">
        update agent
        <trim prefix="SET" suffixOverrides=",">
            <if test="agentIndex != null and agentIndex != ''">agent_index = #{agentIndex},</if>
            <if test="agentName != null and agentName != ''">agent_name = #{agentName},</if>
            <if test="agentContactName != null">agent_contact_name = #{agentContactName},</if>
            <if test="agentContactPhone != null and agentContactPhone != ''">agent_contact_phone = #{agentContactPhone},</if>
            <if test="commissionRate != null and commissionRate != ''">commission_rate = #{commissionRate},</if>
            <if test="wxAccount != null and wxAccount != ''">wx_account = #{wxAccount},</if>
            <if test="aliAccount != null and aliAccount != ''">ali_account = #{aliAccount},</if>
            <if test="delFlag != null and delFlag != ''">del_flag = #{delFlag},</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="remark != null">remark = #{remark},</if>
            <if test="column1 != null">column1 = #{column1},</if>
            <if test="column2 != null">column2 = #{column2},</if>
            <if test="column3 != null">column3 = #{column3},</if>
        </trim>
        where agent_id = #{agentId}
    </update>

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

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