package com.game.business.mapper;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.game.business.domain.AppUser;
import com.game.business.vo.ApiUserInfoVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.data.cache.CacheByNativeSql;
import org.springframework.data.cache.CacheMethod;
import org.springframework.data.cache.CacheType;

/**
 * app用户Mapper接口
 *
 * @author game
 * @date 2024-06-18
 */
public interface AppUserMapper extends BaseMapper<AppUser> {
    /**
     * 查询app用户
     *
     * @param userid app用户主键
     * @return app用户
     */
    public AppUser selectAppUserByUserid(Long userid);

    /**
     * 查询app用户列表
     *
     * @param appUser app用户
     * @return app用户集合
     */
    public List<AppUser> selectAppUserList(AppUser appUser);

    /**
     * 新增app用户
     *
     * @param appUser app用户
     * @return 结果
     */
    public int insertAppUser(AppUser appUser);

    /**
     * 修改app用户
     *
     * @param appUser app用户
     * @return 结果
     */
    public int updateAppUser(AppUser appUser);

    /**
     * 删除app用户
     *
     * @param userid app用户主键
     * @return 结果
     */
    public int deleteAppUserByUserid(Long userid);

    /**
     * 批量删除app用户
     *
     * @param userids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteAppUserByUserids(Long[] userids);

    Long nextId();

    @Select("select * from app_user where pid = 0 and agent_flag = 1")
    public List<AppUser> selectTeamUserList();

    /**
     * 更新用户钱包
     * */
    public int updateUserMoney(AppUser appUser);

    @Select("select"
            + " (select grade_icon from app_grade ug where ug.grade = au.user_grade AND ug.type = 1 ) user_grade_img,"
            + " (select grade_icon from app_grade wg where wg.grade = au.wealth_grade AND wg.type = 2 ) wealth_grade_img,"
            + " (select grade_icon from app_grade ag where ag.grade = au.anchor_grade AND ag.type = 3 ) anchor_grade_img,"
            + " (select grade_icon from app_grade ng where ng.grade = au.noble_grade AND ng.type = 4 ) noble_grade_img,"
            + " (select grade_icon from app_grade cg where cg.grade = au.charm_grade AND cg.type = 5 ) charm_grade_img,"
            + " (select name from app_grade ng where ng.grade = au.noble_grade AND ng.type = 4 ) noble_name,"
            + " (select avatar_frame from app_grade ng where ng.grade = au.noble_grade AND ng.type = 4 ) noble_avatar_frame,"
            + " (select medal_logo from app_medal am where am.lv = au.noble_grade AND am.type = 4 ) noble_medal,"

            /******* 上面是关联其它表 ************/
            + "LENGTH(mobile) as mobile_length,"// 不查手机号，防止手机号泄露
            + "TIMESTAMPDIFF(YEAR, birthday, CURDATE()) age,"
            + "if(manager_id = 0 AND pid = 0 AND agent_id = 0, 1, 2) is_pid,"
            + "if(total_charge > 0, 1, 0) is_first_recharge,"

            + "mobile,"// 以后要删掉的
            /******* 上面是计算出来了 ************/

            + "userid as user_id,username,avatar,sex,birthday,live_thumb,role,height,weight,sanwei,vocation,charm_point,"
            + "constellation,address,signature,province,city,lng,lat,group_id,coin,coin_cash,votes,goodnum,user_type,pid,manager_id,"
            + "manager_co_id,agent_id,user_grade,anchor_grade,wealth_grade,noble_grade,charm_grade,video_coin,voice_coin,"
            + "create_time,poster,read_short_video_number,is_svip,iszombiep,iszombie,head_no,ooo_two_classify_id,"
            + "whether_enable_positioning_show,hide_distance,is_youth_model,is_push,is_tone,charge_show,devote_show,gift_global_broadcast,"
            + "join_room_show,broad_cast,is_not_disturb,status,is_anchor_auth,online_status,user_set_online_status,consumption,"
            + "live_status,ooo_live_status,voice_status, last_off_line_time, room_id, gs_room_type, gs_room_id,"
            + "diamond_coin,diamond_coin_total,diamond_coin_cash,agent_flag,fund_password"
            + " from app_user as au where au.userid=#{userId}")
    ApiUserInfoVo getUserInfo(@Param("userId") long userId);

    Map<String, BigDecimal> getUserCount(Long userId);
}