<?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.yanzhu.system.mapper.SysUserUniopenMapper">
    
    <resultMap type="SysUserUniopen" id="SysUserUniopenResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="userName"    column="user_name"    />
        <result property="userNick"    column="user_nick"    />
        <result property="unionid"    column="unionid"    />
        <result property="maOpenId"    column="ma_open_id"    />
        <result property="mpOpenId"    column="mp_open_id"    />
    </resultMap>

    <sql id="selectSysUserUniopenVo">
        select id, user_id, user_name, user_nick, unionid, ma_open_id, mp_open_id from sys_user_uniopen
    </sql>

    <select id="selectSysUserUniopenList" parameterType="SysUserUniopen" resultMap="SysUserUniopenResult">
        <include refid="selectSysUserUniopenVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="userName != null  and userName != ''"> and user_name = #{userName}</if>
            <if test="unionid != null  and unionid != ''"> and unionid = #{unionid}</if>
            <if test="maOpenId != null  and maOpenId != ''"> and ma_open_id = #{maOpenId}</if>
            <if test="mpOpenId != null  and mpOpenId != ''"> and mp_open_id = #{mpOpenId}</if>
        </where>
    </select>
    
    <select id="selectSysUserUniopenById" parameterType="Long" resultMap="SysUserUniopenResult">
        <include refid="selectSysUserUniopenVo"/>
        where id = #{id}
    </select>

    <select id="selectSysUserUniopenByUserId" parameterType="Long" resultMap="SysUserUniopenResult">
        <include refid="selectSysUserUniopenVo"/>
        where user_id = #{userId}
    </select>

    <select id="selectSysUserUniopenByUserName" parameterType="String" resultMap="SysUserUniopenResult">
        <include refid="selectSysUserUniopenVo"/>
        where user_name = #{userName}
    </select>

    <select id="selectSysUserUniopenByUnionid" parameterType="String" resultMap="SysUserUniopenResult">
        <include refid="selectSysUserUniopenVo"/>
        where unionid = #{unionid}
    </select>

    <select id="selectSysUserUniopenByMaOpenId" parameterType="String" resultMap="SysUserUniopenResult">
        <include refid="selectSysUserUniopenVo"/>
        where ma_open_id = #{maOpenId}
    </select>

    <select id="selectSysUserUniopenByMpOpenId" parameterType="String" resultMap="SysUserUniopenResult">
        <include refid="selectSysUserUniopenVo"/>
        where mp_open_id = #{mpOpenId}
    </select>
        
    <insert id="insertSysUserUniopen" parameterType="SysUserUniopen" useGeneratedKeys="true" keyProperty="id">
        insert into sys_user_uniopen
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="userName != null">user_name,</if>
            <if test="userNick != null">user_nick,</if>
            <if test="unionid != null">unionid,</if>
            <if test="maOpenId != null">ma_open_id,</if>
            <if test="mpOpenId != null">mp_open_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="userName != null">#{userName},</if>
            <if test="userNick != null">#{userNick},</if>
            <if test="unionid != null">#{unionid},</if>
            <if test="maOpenId != null">#{maOpenId},</if>
            <if test="mpOpenId != null">#{mpOpenId},</if>
         </trim>
    </insert>

    <update id="updateSysUserUniopen" parameterType="SysUserUniopen">
        update sys_user_uniopen
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="userNick != null">user_nick = #{userNick},</if>
            <if test="unionid != null">unionid = #{unionid},</if>
            <if test="maOpenId != null">ma_open_id = #{maOpenId},</if>
            <if test="mpOpenId != null">mp_open_id = #{mpOpenId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysUserUniopenById" parameterType="Long">
        delete from sys_user_uniopen where id = #{id}
    </delete>

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