ITPub博客

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

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

作者:ofan 时间:2019-08-21 11:04:13 0 删除 编辑

一个函数内多次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);
    }


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4571/viewspace-3152778/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: C++ 调试堆栈
请登录后发表评论 登录
全部评论

注册时间:2019-08-01

  • 博文量
    159
  • 访问量
    1160