有一个投资返现的逻辑,导致一个集合里面个别人的投资记录出现多次返现,一直找不到原因,请问怎么写比较规范
private void grantActivityGift(Integer loanId, Loan loan, LoanType type, List<LoanTender> tenderList, Member p2p, BankAccount p2pAccount) throws Exception {
Map<String, Object> remake = new HashMap<>(2);
for (LoanTender tender : tenderList) {
/**
* 注册红包返现给出借人
*/
ActivityGift activityGift = daoHelper.findByCondition(ActivityGift.class, Cnd.where("tenderid", "=", tender.id)
.and("typeid", "<=", ActivityGift.TYPE_XNTJ)
.and("mid", "=", tender.mid)
.and("used", "=", 0)
.and("flag", "=", 1));
BankAccount tenderAccount = daoHelper.findByCondition(BankAccount.class, Cnd.where("mid", "=", tender.mid));
if (!Common.isEmpty(activityGift)) {
//调用标的转账
remake.clear();
remake.put("message", "红包返现");
remake.put("to", tenderAccount.getAccountId());
remake.put("from", p2pAccount.getAccountId());
//平台账户直接转账到 出借人 账户 可用到可用,商户不能冻结
bankService.doTransferBmu(loan.code, tender.mid, p2p.id, activityGift.amount, Account.REWARD_ACTIVITY, Account.CTYPE_OUTPUT, BankTransferFlow.B_TYPE_8, remake);
//更新出借人账户
bankService.updateAccount(FuiouBankService.ACCOUNT_TYPE_0, activityGift.amount, tender.mid, p2pAccount.getAccountId(), tenderAccount.getAccountId(), remake, Account.REWARD_ACTIVITY, Account.CTYPE_INCOME, true);
//更新平台账户
bankService.updateAccount(FuiouBankService.ACCOUNT_TYPE_4, activityGift.amount, p2p.id, p2pAccount.getAccountId(), tenderAccount.getAccountId(), remake, Account.REWARD_ACTIVITY, Account.CTYPE_OUTPUT, true);
//更新红包状态为已返还
daoHelper.update(ActivityGift.class, Chain.make("used", 1), Cnd.where("id", "=", activityGift.id).and("used", "=", 0));
}
/**
* 检查新手体验标中的钱是否赎回,发放新手体验标收益金
*/
Record xsbAmount = daoHelper.getRecord("SELECT xl.amount FROM xstyb_lxxx xl JOIN xsb_tender xt ON xt.mid = xl.mid where xl.mid = " + tender.mid + " AND xt.type = 0 AND xt.`status` = 1");
if (xsbAmount != null) {
remake.clear();
remake.put("message", "发放体验金利息");
remake.put("to", tenderAccount.getAccountId());
remake.put("from", p2pAccount.getAccountId());
//更改出借人账户资金余额
bankService.doTransferBmu(loan.code, tender.mid, p2p.id, xsbAmount.getDouble("amount"), Account.ACTION_TYJ_COLLECT, Account.CTYPE_INCOME, BankTransferFlow.B_TYPE_8, remake);
//更改出借人账户
bankService.updateAccount(FuiouBankService.ACCOUNT_TYPE_7, xsbAmount.getDouble("amount"), tender.mid, p2pAccount.getAccountId(), tenderAccount.getAccountId(), remake, Account.ACTION_TYJ_COLLECT, Account.CTYPE_INCOME, true);
//更改平台账户
bankService.updateAccount(FuiouBankService.ACCOUNT_TYPE_4, xsbAmount.getDouble("amount"), p2p.id, p2pAccount.getAccountId(), tenderAccount.getAccountId(), remake, Account.ACTION_TYJ_COLLECT, Account.CTYPE_OUTPUT, true);
//更新体验金利息状态为已发放
daoHelper.update(NewcomerTender.class, Chain.make("redeem_amount", xsbAmount.getDouble("amount")).add("type", 1), Cnd.where("mid", "=", tender.mid));
}
/**
* 五月出借返现活动,不是新手标和体验标
*/
if (type.dayloanflag != LoanType.LOAN_TYPE_XSB && type.dayloanflag != LoanType.LOAN_TYPE_NEW) {
fiveActivity(loanId, loan, type, p2p, p2pAccount, tender, tenderAccount);
}
}
}
就是下面整个返现出现这样的问题,上面返回红包没有出现
private void grantActivityGift(Integer loanId, Loan loan, LoanType type, List<LoanTender> tenderList, Member p2p, BankAccount p2pAccount) throws Exception {
Map<String, Object> remake = new HashMap<>(2);
for (LoanTender tender : tenderList) {
/**
* 注册红包返现给出借人
*/
ActivityGift activityGift = daoHelper.findByCondition(ActivityGift.class, Cnd.where("tenderid", "=", tender.id)
.and("typeid", "<=", ActivityGift.TYPE_XNTJ)
.and("mid", "=", tender.mid)
.and("used", "=", 0)
.and("flag", "=", 1));
BankAccount tenderAccount = daoHelper.findByCondition(BankAccount.class, Cnd.where("mid", "=", tender.mid));
if (!Common.isEmpty(activityGift)) {
//调用标的转账
remake.clear();
remake.put("message", "红包返现");
remake.put("to", tenderAccount.getAccountId());
remake.put("from", p2pAccount.getAccountId());
//平台账户直接转账到 出借人 账户 可用到可用,商户不能冻结
bankService.doTransferBmu(loan.code, tender.mid, p2p.id, activityGift.amount, Account.REWARD_ACTIVITY, Account.CTYPE_OUTPUT, BankTransferFlow.B_TYPE_8, remake);
//更新出借人账户
bankService.updateAccount(FuiouBankService.ACCOUNT_TYPE_0, activityGift.amount, tender.mid, p2pAccount.getAccountId(), tenderAccount.getAccountId(), remake, Account.REWARD_ACTIVITY, Account.CTYPE_INCOME, true);
//更新平台账户
bankService.updateAccount(FuiouBankService.ACCOUNT_TYPE_4, activityGift.amount, p2p.id, p2pAccount.getAccountId(), tenderAccount.getAccountId(), remake, Account.REWARD_ACTIVITY, Account.CTYPE_OUTPUT, true);
//更新红包状态为已返还
daoHelper.update(ActivityGift.class, Chain.make("used", 1), Cnd.where("id", "=", activityGift.id).and("used", "=", 0));
}
/**
* 检查新手体验标中的钱是否赎回,发放新手体验标收益金
*/
Record xsbAmount = daoHelper.getRecord("SELECT xl.amount FROM xstyb_lxxx xl JOIN xsb_tender xt ON xt.mid = xl.mid where xl.mid = " + tender.mid + " AND xt.type = 0 AND xt.`status` = 1");
if (xsbAmount != null) {
remake.clear();
remake.put("message", "发放体验金利息");
remake.put("to", tenderAccount.getAccountId());
remake.put("from", p2pAccount.getAccountId());
//更改出借人账户资金余额
bankService.doTransferBmu(loan.code, tender.mid, p2p.id, xsbAmount.getDouble("amount"), Account.ACTION_TYJ_COLLECT, Account.CTYPE_INCOME, BankTransferFlow.B_TYPE_8, remake);
//更改出借人账户
bankService.updateAccount(FuiouBankService.ACCOUNT_TYPE_7, xsbAmount.getDouble("amount"), tender.mid, p2pAccount.getAccountId(), tenderAccount.getAccountId(), remake, Account.ACTION_TYJ_COLLECT, Account.CTYPE_INCOME, true);
//更改平台账户
bankService.updateAccount(FuiouBankService.ACCOUNT_TYPE_4, xsbAmount.getDouble("amount"), p2p.id, p2pAccount.getAccountId(), tenderAccount.getAccountId(), remake, Account.ACTION_TYJ_COLLECT, Account.CTYPE_OUTPUT, true);
//更新体验金利息状态为已发放
daoHelper.update(NewcomerTender.class, Chain.make("redeem_amount", xsbAmount.getDouble("amount")).add("type", 1), Cnd.where("mid", "=", tender.mid));
}
/**
* 五月出借返现活动,不是新手标和体验标
*/
if (type.dayloanflag != LoanType.LOAN_TYPE_XSB && type.dayloanflag != LoanType.LOAN_TYPE_NEW) {
fiveActivity(loanId, loan, type, p2p, p2pAccount, tender, tenderAccount);
}
}
}