package com.wzj.soopin.member.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wzj.soopin.member.domain.bo.MemberAccountBO;
import com.wzj.soopin.member.domain.po.MemberAccount;
import com.wzj.soopin.member.domain.vo.MemberAccountVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;

/**
 * 会员账户表Mapper接口
 *
 * @author zcc
 */
@Mapper
public interface MemberAccountMapper extends BaseMapper<MemberAccount> {
    IPage<MemberAccountVO> selectAccountWithMember(Page<?> page, @Param("bo") MemberAccountBO bo);

    @Select("SELECT wallet \n" +
        "FROM ums_account \n" +
        "WHERE member_id = #{memberId};")
    BigDecimal getMoneyBalanceByMemberId(Long memberId);

    @Select("UPDATE ums_account \n" +
        "SET wallet = #{afterBalance} \n" +
        "WHERE member_id = #{senderId};")
    void updateMoneyBalance(Long senderId, BigDecimal afterBalance);

    @Select("SELECT COUNT(*) FROM ums_member")
    Object getCount();
}

