首页 新闻 赞助 找找看

一个函数内多次update 资金,每次变化都需要记录交易日志;有什么优化方案?

0
悬赏园豆:20 [待解决问题]

一个函数内多次update 资金,每次变化都需要记录交易日志;
每次资金变化都需要重新查询变化后的Amount。

: 目前想到的解决办法是通过记录每次更新的amount 到内存,在最后一次通过批处理insert。这样解决了多次save日志的操作,但还需要每次查询变化后的资金情况,还有什么其他解决办法没?

 @Transactional(rollbackFor = Exception.class)
  public SuccessOrderDTO doPay(GoodsBean goodsBean) throws Exception {
    try {
        SuccessOrderDTO successOrderDTO = new SuccessOrderDTO();
    
        //支出
       if (userAccountMapper.userAccountByExpend(/**参数省略*/) == 0) {
            throw new BuyException();
        }
        if (createAccountLog(/**参数省略*/) == 0) {
           throw new AuctionException("保存日志失败");
       }


    //收益
    if (userAccountMapper.accountByIncome(/**参数省略*/) == 0) {
        throw new BuyException();
    }

    //日志
    if (createAccountLog(/**参数省略*/) == 0) {
        throw new AuctionException("保存日志失败");
    }
    //日志
    if (createAccountLog(/**参数省略*/) == 0) {
        throw new AuctionException("保存日志失败");
    }
    //日志
    if (createAccountLog(/**参数省略*/) {
        throw new AuctionException("保存日志失败");
    }


    successOrderDTO.setTypeName(csAuctionType.getTypeName());
    successOrderDTO.setGoodsPrice(goodsPrice.toString());
    successOrderDTO.setVouchersNum(csAuctionType.getGiftVoucherNum());
    successOrderDTO.setGoodsName(csAuctionOrder.getGoodsName());
    successOrderDTO.setOrderNo(csAuctionOrder.getOrderNo());
    successOrderDTO.setAuctionUserName(csAuctionOrder.getRefAuctionUserName());
    successOrderDTO.setCreateOrderTime(csAuctionOrder.getCreateTime());
    return successOrderDTO;
} catch (Exception e) {
    log.error("=========Exception============ {} =============", e.getMessage());
    throw e;
}
}
protected int createAccountLog(long id, long rid, long amount) {
        AccountLog accountLog = new AccountLog();
        accountLog.setUserId(id);
        accountLog.setType(rid);
        accountLog.setChangeTime(System.currentTimeMillis());
        //变化资金
        accountLog.setCurrAmount(amount);
        //重新查询变化后的资金情况记录?
        Account account = UserAccountMapper.getUserAccount(id);
        accountLog.setTotalAmount(account.getAmount);
        return accountLogMapper.save(accountLog);
    }
calm01的主页 calm01 | 初学一级 | 园豆:190
提问于:2019-01-19 21:14
< >
分享
所有回答(1)
0

日志操作用AOP。
@Aspect
@after
@before

老渣 | 园豆:210 (菜鸟二级) | 2019-03-08 17:27
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册