按需更新。
编程式事务:
@Autowired
TransactionTemplate transactionTemplate;
public String creditApply(MallBaseUserRequest userRequest) {
final String userId = userRequest.getUserId();
final String productId = userRequest.getProductId();
MallUserCreditApplyInfo applyInfo =
mallUserCreditApplyRepository.selectLastCreditInfo(userId, productId, "I");
if (null == applyInfo) {
logger.info("没有状态为I的申请记录,新增一条");
applyInfo =
(MallUserCreditApplyInfo) transactionTemplate.execute(new TransactionCallback() {
@Override
public Object doInTransaction(TransactionStatus transactionStatus) {
MallVerifyUserInfoDO mallVerifyUserInfoDO = mallUserVerifyInfoRepository
.queryUserVerifyInfo(userId, productId, true);
if (null == mallVerifyUserInfoDO || !verifySuccess(mallVerifyUserInfoDO)) {
logger.warn(
"MallUserVerifyServiceImpl - creditApply :Mall User verify progress not valid,"
+ " userId={}.", userId);
throw new SupplyException(SupplyErrorCode.ILLEGAL_STATUS);
}
MallUserCreditApplyInfo mallUserCreditApplyInfo = new MallUserCreditApplyInfo();
BeanUtils.copyProperties(mallVerifyUserInfoDO, mallUserCreditApplyInfo,
"id, sequenceId, status");
String applyId =
mallUserCreditApplyRepository
.createMallUserCreditApplyInfo(mallUserCreditApplyInfo);
return mallUserCreditApplyRepository.queryApplyInfoByApplyId(applyId);
}
});
}
logger.info("begin credit apply, applyId={}", applyInfo.getApplyId());
return mallLoanApplyManager.creditApply(applyInfo);
}