<?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.yijia.system.mapper.SysAgentMapper">

    <resultMap type="SysAgent" id="SysAgentResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="groupId"    column="group_id"    />
    </resultMap>

    <sql id="selectSysAgentVo">
        select id, user_id, group_id from sys_agent
    </sql>

    <select id="selectSysAgentList" parameterType="SysAgent" resultMap="SysAgentResult">
        <include refid="selectSysAgentVo"/>
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="groupId != null "> and group_id = #{groupId}</if>
        </where>
    </select>

    <select id="selectSysAgent" parameterType="SysAgent" resultMap="SysAgentResult">
        <include refid="selectSysAgentVo"/>
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="groupId != null "> and group_id = #{groupId}</if>
        </where>
    </select>
    <select id="selectSysAgentById" parameterType="Integer" resultMap="SysAgentResult">
        <include refid="selectSysAgentVo"/>
        where id = #{id}
    </select>

    <insert id="insertSysAgent" parameterType="SysAgent" useGeneratedKeys="true" keyProperty="id">
        insert into sys_agent
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="groupId != null">group_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="groupId != null">#{groupId},</if>
         </trim>
    </insert>

    <update id="updateSysAgent" parameterType="SysAgent">
        update sys_agent
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="groupId != null">group_id = #{groupId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysAgentById" parameterType="Integer">
        delete from sys_agent where id = #{id}
    </delete>

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

    <delete id="deleteSysAgent" parameterType="SysAgent">
        delete from sys_agent
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="groupId != null "> and group_id = #{groupId}</if>
        </where>
    </delete>

</mapper>
