Search in sources :

Example 1 with UserAccountInfo

use of com.amusing.start.user.pojo.UserAccountInfo in project amusing-project by m-lvqingyu.

the class AccountServiceImpl method init.

@Override
public Boolean init(String userId) {
    String autoId = userAccountInfoMapper.checkAmountIsExist(userId);
    if (StringUtils.isNotEmpty(autoId)) {
        return UserConstant.TRUE;
    }
    long currentTime = System.currentTimeMillis();
    UserAccountInfo accountInfo = UserAccountInfo.builder().userId(userId).mainAmount(BigDecimal.ZERO).giveAmount(BigDecimal.ZERO).frozenAmount(BigDecimal.ZERO).vipLevel(UserConstant.ZERO).createBy(userId).createTime(currentTime).updateBy(userId).updateTime(currentTime).build();
    Integer result = null;
    try {
        result = userAccountInfoMapper.insertSelective(accountInfo);
    } catch (Exception e) {
        log.error("[user]-initAccount err! userId:{}, msg:{}", userId, Throwables.getStackTraceAsString(e));
    }
    return result == null ? UserConstant.FALSE : UserConstant.TRUE;
}
Also used : UserAccountInfo(com.amusing.start.user.pojo.UserAccountInfo)

Example 2 with UserAccountInfo

use of com.amusing.start.user.pojo.UserAccountInfo in project amusing-project by m-lvqingyu.

the class AccountServiceImpl method giveSettlement.

@Override
public Boolean giveSettlement(String userId, BigDecimal amount) {
    // 根据用户ID,获取其副账户余额,获取不到则抛出异常
    UserAccountInfo info = userAccountInfoMapper.selectByUserId(userId);
    if (info == null) {
        return UserConstant.FALSE;
    }
    BigDecimal giveAmount = info.getGiveAmount();
    if (giveAmount == null || amount.compareTo(giveAmount) < UserConstant.ZERO) {
        return UserConstant.FALSE;
    }
    // 更新用户副账户余额,更新失败抛出异常
    Integer result = null;
    try {
        result = userAccountInfoMapper.updateGiveAccount(userId, giveAmount, amount);
    } catch (Exception e) {
        log.error("[user]-updateGiveAccount err! userId:{}, amount:{}, msg:{}", userId, amount, Throwables.getStackTraceAsString(e));
    }
    return result == null ? UserConstant.FALSE : UserConstant.TRUE;
}
Also used : UserAccountInfo(com.amusing.start.user.pojo.UserAccountInfo) BigDecimal(java.math.BigDecimal)

Example 3 with UserAccountInfo

use of com.amusing.start.user.pojo.UserAccountInfo in project amusing-project by m-lvqingyu.

the class AccountServiceImpl method account.

@Override
public UserAccountOutput account(String userId) {
    UserAccountOutput output = new UserAccountOutput();
    UserAccountInfo info = userAccountInfoMapper.selectByUserId(userId);
    Optional.ofNullable(info).ifPresent(i -> {
        BeanUtils.copyProperties(info, output);
    });
    return output;
}
Also used : UserAccountOutput(com.amusing.start.client.output.UserAccountOutput) UserAccountInfo(com.amusing.start.user.pojo.UserAccountInfo)

Example 4 with UserAccountInfo

use of com.amusing.start.user.pojo.UserAccountInfo in project amusing-project by m-lvqingyu.

the class AccountServiceImpl method mainSettlement.

@Transactional(rollbackFor = Exception.class)
@Override
public Boolean mainSettlement(String userId, BigDecimal amount) {
    // 根据用户ID,获取其主账户余额,获取不到则抛出异常
    UserAccountInfo info = userAccountInfoMapper.selectByUserId(userId);
    if (info == null) {
        return UserConstant.FALSE;
    }
    BigDecimal mainAmount = info.getMainAmount();
    if (mainAmount == null || amount.compareTo(mainAmount) > UserConstant.ZERO) {
        return UserConstant.FALSE;
    }
    // 更新用户主账户余额,更新失败抛出异常
    Integer result = null;
    try {
        result = userAccountInfoMapper.updateMainAccount(userId, mainAmount, amount);
    } catch (Exception e) {
        log.error("[user]-updateMainAccount err! userId:{}, amount:{}, msg:{}", userId, amount, Throwables.getStackTraceAsString(e));
    }
    return result == null ? UserConstant.FALSE : UserConstant.TRUE;
}
Also used : UserAccountInfo(com.amusing.start.user.pojo.UserAccountInfo) BigDecimal(java.math.BigDecimal) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

UserAccountInfo (com.amusing.start.user.pojo.UserAccountInfo)4 BigDecimal (java.math.BigDecimal)2 UserAccountOutput (com.amusing.start.client.output.UserAccountOutput)1 Transactional (org.springframework.transaction.annotation.Transactional)1