package cn.pluss.platform.mapper;

import cn.pluss.platform.entity.UserAccount;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;

@Mapper
public interface UserAccountMapper  extends BaseMapper<UserAccount> {


    @Select(value = "select user_id AS userId,freeze_balance AS freezeBalance,balance,out_balance AS outBalance,create_time AS createTime,update_time AS updateTime from tb_pluss_user_account where user_id=#{userId}")
    UserAccount selectUserByUserId(@Param("userId")Integer userId,Integer t);

    @Select(value = "select user_id AS userId,freeze_balance AS freezeBalance,balance,out_balance AS outBalance,create_time AS createTime,update_time AS updateTime from tb_pluss_user_account where user_id=#{userId} for update")
    UserAccount selectUserByUserId(@Param("userId")Integer userId);

    @Update(value = "update tb_pluss_user_account set freeze_balance=freeze_balance+#{amount} where user_id=#{userId}")
    Integer updateFreezon(@Param("userId") Integer userId, @Param("amount") BigDecimal amount);

    @Update(value = "update tb_pluss_user_account set balance=balance+#{amount} where user_id=#{userId}")
    Integer updateBanlance(@Param("userId") Integer userId, @Param("amount") BigDecimal amount);
}
