<?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.MemberInfoMapper">
    
    <resultMap type="MemberInfo" id="MemberInfoResult">
        <result property="memberId"    column="member_id"    />
        <result property="userId"    column="user_id"    />
        <result property="name"    column="name"    />
        <result property="card"    column="card"    />
        <result property="boundary"    column="boundary"    />
        <result property="partyAffiliation"    column="party_affiliation"    />
        <result property="phonenumber"    column="phonenumber"    />
        <result property="avatar"    column="avatar"    />
        <result property="unit"    column="unit"    />
        <result property="studio"    column="studio"    />
        <result property="score"    column="score"    />
        <result property="ranking"    column="ranking"    />
        <result property="grade"    column="grade"    />
        <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"    />
    </resultMap>

    <sql id="selectMemberInfoVo">
        select member_id, user_id, name, card, boundary, party_affiliation, phonenumber, avatar, unit, studio,score,ranking,grade, del_flag, create_by, create_time, update_by, update_time, remark from member_info
    </sql>

    <select id="selectMemberInfoList" parameterType="MemberInfo" resultMap="MemberInfoResult">
        <include refid="selectMemberInfoVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="card != null  and card != ''"> and card = #{card}</if>
            <if test="boundary != null  and boundary != ''"> and boundary = #{boundary}</if>
            <if test="partyAffiliation != null  and partyAffiliation != ''"> and party_affiliation = #{partyAffiliation}</if>
            <if test="phonenumber != null  and phonenumber != ''"> and phonenumber = #{phonenumber}</if>
            <if test="avatar != null  and avatar != ''"> and avatar = #{avatar}</if>
            <if test="unit != null  and unit != ''"> and unit = #{unit}</if>
            <if test="studio != null  and studio != ''"> and studio = #{studio}</if>
            <if test="score != null  and score != ''"> and score = #{score}</if>
            <if test="ranking != null  and ranking != ''"> and ranking = #{ranking}</if>
            <if test="grade != null  and grade != ''"> and find_in_set(#{grade}, grade)</if>
        </where>
    </select>
    
    <select id="selectMemberInfoByMemberId" parameterType="Long" resultMap="MemberInfoResult">
        <include refid="selectMemberInfoVo"/>
        where member_id = #{memberId}
    </select>
        
    <insert id="insertMemberInfo" parameterType="MemberInfo" useGeneratedKeys="true" keyProperty="memberId">
        insert into member_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="card != null and card != ''">card,</if>
            <if test="boundary != null">boundary,</if>
            <if test="partyAffiliation != null">party_affiliation,</if>
            <if test="phonenumber != null">phonenumber,</if>
            <if test="avatar != null">avatar,</if>
            <if test="unit != null">unit,</if>
            <if test="studio != null">studio,</if>
            <if test="score != null">score,</if>
            <if test="ranking != null">ranking,</if>
            <if test="grade != null">grade,</if>
            <if test="delFlag != null">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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="card != null and card != ''">#{card},</if>
            <if test="boundary != null">#{boundary},</if>
            <if test="partyAffiliation != null">#{partyAffiliation},</if>
            <if test="phonenumber != null">#{phonenumber},</if>
            <if test="avatar != null">#{avatar},</if>
            <if test="unit != null">#{unit},</if>
            <if test="studio != null">#{studio},</if>
            <if test="score != null">#{score},</if>
            <if test="ranking != null">#{ranking},</if>
            <if test="grade != null">#{grade},</if>
            <if test="delFlag != null">#{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>
         </trim>
    </insert>

    <update id="updateMemberInfo" parameterType="MemberInfo">
        update member_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="card != null and card != ''">card = #{card},</if>
            <if test="boundary != null">boundary = #{boundary},</if>
            <if test="partyAffiliation != null">party_affiliation = #{partyAffiliation},</if>
            <if test="phonenumber != null">phonenumber = #{phonenumber},</if>
            <if test="avatar != null">avatar = #{avatar},</if>
            <if test="unit != null">unit = #{unit},</if>
            <if test="studio != null">studio = #{studio},</if>
            <if test="score != null and score != ''">score = #{score},</if>
            <if test="ranking != null and ranking != ''">ranking = #{ranking},</if>
            <if test="grade != null and grade != ''">grade = #{grade},</if>
            <if test="delFlag != null">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>
        </trim>
        where member_id = #{memberId}
    </update>

    <delete id="deleteMemberInfoByMemberId" parameterType="Long">
        delete from member_info where member_id = #{memberId}
    </delete>

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