package com.kym.mapper.miniapp;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.github.yulichang.base.MPJBaseMapper;
import com.kym.entity.admin.vo.CustomUserVo;
import com.kym.entity.miniapp.User;
import com.kym.entity.miniapp.vo.UserVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 用户表 Mapper 接口
 * </p>
 *
 * @author skyline
 * @since 2023-07-26
 */
@DS("db-miniapp")
public interface UserMapper extends MPJBaseMapper<User> {

    @Select("SELECT \n" +
            "  u.id,\n" +
            "  u.username,\n" +
            "  u.nickname,\n" +
            "  u.openid,\n" +
            "  u.avatar,\n" +
            "  u.gender,\n" +
            "  u.mobile_phone,\n" +
            "  u.last_login_time,\n" +
            "  acc.balance,\n" +
            "  acc.discount_amount,\n" +
            "  (acc.balance - acc.discount_amount) refundable_amount,\n" +
            "  u.status \n" +
            "FROM\n" +
            "  t_user u \n" +
            "  LEFT JOIN t_account acc \n" +
            "    ON u.id = acc.user_id \n" +
            "WHERE u.id = ${userId} ")
    UserVo getMe(Long userId);

    List<CustomUserVo> listUser(@Param("list") List<Long> userId);
}
