从多个service层调用不同的方法,处理可能造成发生事务的处理,手动抛出异常
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
/*** 资金调拨单*/@PostMapping(value = "transfer")@Transactionalpublic String transfer(Integer resource_dept_id, Integer target_dept_id,BigDecimal amount, String remark) {Transfer transfer = new Transfer();transfer.setAmount(amount);transfer.setRemark(remark);transfer.setResourceDeptId(resource_dept_id);try {transfer.setTargetDeptId(target_dept_id);//部门减钱Boolean b1 = balanceService.updata(transfer.getResourceDeptId(),new Integer(0), transfer.getAmount());//部门价钱Boolean b2 = balanceService.updata(transfer.getTargetDeptId(),new Integer(1), transfer.getAmount());//记录明细Boolean b3 = transferService.upData(transfer);if (b1 && b2 && b3)return "资金调拨成功。";else throw new CheckedException("false");} catch (CheckedException e) {TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();return "请检查参数";}}
