<?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="org.springblade.modules.guosen.userMedal.mapper.UserMedalMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="userMedalResultMap" type="org.springblade.modules.guosen.userMedal.vo.UserMedalVO">
        <result column="id" property="id"/>
        <result column="create_user" property="createUser"/>
        <result column="create_dept" property="createDept"/>
        <result column="create_time" property="createTime"/>
        <result column="update_user" property="updateUser"/>
        <result column="update_time" property="updateTime"/>
        <result column="status" property="status"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="user_id" property="userId"/>
        <result column="medal_id" property="medalId"/>
        <result column="activity_ids" property="activityIds"/>
        <result column="count" property="count"/>


        <!--用户信息-->
        <result column="nick_name" property="nickName"/>
        <result column="avatar" property="avatar"/>
        <result column="phone" property="phone"/>
        <!--勋章信息-->
        <association property="medal" javaType="org.springblade.modules.guosen.medal.entity.Medal">
            <id property="id" column="id"></id>
            <result property="icon" column="icon"/>
            <result property="name" column="name"/>
            <result property="pointsValue" column="points_value"/>
        </association>
    </resultMap>

    <select id="selectUserMedalPage" resultMap="userMedalResultMap">
        select a.*,b.nick_name,b.avatar,b.phone,c.*
        from cyzh_user_medal as a
        left join cyzh_login_user as b on a.user_id = b.id
        left join cyzh_medal as c on a.medal_id = c.id
        where a.is_deleted = 0
        <if test="userMedal !=null and userMedal != ''">
            <if test="userMedal.nickName != null and userMedal.nickName != ''">
                and b.nick_name like concat('%',#{userMedal.nickName},'%')
            </if>
            <if test="userMedal.phone != null and userMedal.phone != ''">
                and b.phone like concat('%',#{userMedal.phone},'%')
            </if>
        </if>
    </select>



</mapper>
