<?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.ScoreUserMapper">

    <resultMap type="ScoreUser" id="ScoreUserResult">
        <result property="userId"    column="user_id"    />
        <result property="openId"    column="open_id"    />
        <result property="nickName"    column="nick_name"    />
        <result property="avatars"    column="avatars"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectScoreUserVo">
        select user_id, open_id, nick_name, avatars, create_time, update_time from score_user
    </sql>

    <select id="selectScoreUserList" parameterType="ScoreUser" resultMap="ScoreUserResult">
        <include refid="selectScoreUserVo"/>
        <where>
            <if test="openId != null "> and open_id = #{openId}</if>
            <if test="nickName != null  and nickName != ''"> and nick_name like concat('%', #{nickName}, '%')</if>
            <if test="avatars != null  and avatars != ''"> and avatars = #{avatars}</if>
        </where>
    </select>

    <select id="selectScoreUserByUserId" parameterType="Long" resultMap="ScoreUserResult">
        <include refid="selectScoreUserVo"/>
        where user_id = #{userId}
    </select>
    <select id="selectScoreUserByOpenId"  resultMap="ScoreUserResult">
        <include refid="selectScoreUserVo"/>
        where open_id = #{openId}
    </select>

    <insert id="insertScoreUser" parameterType="ScoreUser" useGeneratedKeys="true" keyProperty="userId">
        insert into score_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="openId != null">open_id,</if>
            <if test="nickName != null">nick_name,</if>
            <if test="avatars != null">avatars,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="openId != null">#{openId},</if>
            <if test="nickName != null">#{nickName},</if>
            <if test="avatars != null">#{avatars},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateScoreUser" parameterType="ScoreUser">
        update score_user
        <trim prefix="SET" suffixOverrides=",">
            <if test="openId != null">open_id = #{openId},</if>
            <if test="nickName != null">nick_name = #{nickName},</if>
            <if test="avatars != null">avatars = #{avatars},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where user_id = #{userId}
    </update>

    <delete id="deleteScoreUserByUserId" parameterType="Long">
        delete from score_user where user_id = #{userId}
    </delete>

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