|
|
|
@ -4,6 +4,7 @@ import com.yau.digitalrmb.institutionidentity.application.InstitutionKeySubject;
|
|
|
|
import com.yau.digitalrmb.institutionidentity.infrastructure.InstitutionIdentifierApplicationEntity;
|
|
|
|
import com.yau.digitalrmb.institutionidentity.infrastructure.InstitutionIdentifierApplicationEntity;
|
|
|
|
import com.yau.digitalrmb.institutionidentity.infrastructure.InstitutionIdentifierApplicationMapper;
|
|
|
|
import com.yau.digitalrmb.institutionidentity.infrastructure.InstitutionIdentifierApplicationMapper;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
|
|
|
import com.yau.digitalrmb.security.context.JwtUser;
|
|
|
|
import com.yau.digitalrmb.shared.api.ErrorCode;
|
|
|
|
import com.yau.digitalrmb.shared.api.ErrorCode;
|
|
|
|
import com.yau.digitalrmb.shared.exception.BusinessException;
|
|
|
|
import com.yau.digitalrmb.shared.exception.BusinessException;
|
|
|
|
import com.yau.digitalrmb.walletopening.domain.BankReceivedApplication;
|
|
|
|
import com.yau.digitalrmb.walletopening.domain.BankReceivedApplication;
|
|
|
|
@ -29,26 +30,45 @@ public class WalletOpeningService {
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private InstitutionIdentifierApplicationMapper institutionIdentifierMapper;
|
|
|
|
private InstitutionIdentifierApplicationMapper institutionIdentifierMapper;
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
@Transactional(readOnly = true)
|
|
|
|
public UserWalletPageResult getPage(InstitutionKeySubject subject) {
|
|
|
|
public UserWalletPageResult getPage(InstitutionKeySubject subject, JwtUser jwtUser) {
|
|
|
|
WalletApplication app = findOrCreate(subject);
|
|
|
|
WalletApplication app = walletRepository.findLatest(subject.getUserId(), subject.getSchoolId(), subject.getClassId())
|
|
|
|
refreshCurrentUserInfo(subject, app);
|
|
|
|
.orElseGet(() -> {
|
|
|
|
|
|
|
|
// 未创建记录时,返回一个只包含JWT用户信息的临时对象,不保存到数据库
|
|
|
|
|
|
|
|
WalletApplication temp = WalletApplication.create(
|
|
|
|
|
|
|
|
subject.getUserId(), subject.getSchoolId(), subject.getClassId(),
|
|
|
|
|
|
|
|
jwtUser.getUserName(), jwtUser.getPhone());
|
|
|
|
|
|
|
|
return temp;
|
|
|
|
|
|
|
|
});
|
|
|
|
return new UserWalletPageResult(app);
|
|
|
|
return new UserWalletPageResult(app);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
@Transactional
|
|
|
|
public FaceRecognitionResult updateFaceRecognition(InstitutionKeySubject subject, int status) {
|
|
|
|
public FaceRecognitionResult updateFaceRecognition(InstitutionKeySubject subject, JwtUser jwtUser, int status) {
|
|
|
|
WalletApplication app = findRequired(subject);
|
|
|
|
WalletApplication app = walletRepository.findLatest(subject.getUserId(), subject.getSchoolId(), subject.getClassId())
|
|
|
|
refreshCurrentUserInfo(subject, app);
|
|
|
|
.orElseGet(() -> {
|
|
|
|
|
|
|
|
// 首次人脸识别时创建记录
|
|
|
|
|
|
|
|
WalletApplication newApp = WalletApplication.create(
|
|
|
|
|
|
|
|
subject.getUserId(), subject.getSchoolId(), subject.getClassId(),
|
|
|
|
|
|
|
|
jwtUser.getUserName(), jwtUser.getPhone());
|
|
|
|
|
|
|
|
return walletRepository.save(newApp);
|
|
|
|
|
|
|
|
});
|
|
|
|
app.updateFaceRecognition(status);
|
|
|
|
app.updateFaceRecognition(status);
|
|
|
|
walletRepository.update(app);
|
|
|
|
walletRepository.update(app);
|
|
|
|
return new FaceRecognitionResult(status);
|
|
|
|
return new FaceRecognitionResult(status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
@Transactional
|
|
|
|
public WalletApplicationMessageResult outputApplication(InstitutionKeySubject subject, WalletApplicationRequest request) {
|
|
|
|
public WalletApplicationMessageResult outputApplication(InstitutionKeySubject subject, JwtUser jwtUser, WalletApplicationRequest request) {
|
|
|
|
WalletApplication app = findRequired(subject);
|
|
|
|
WalletApplication app = walletRepository.findLatest(subject.getUserId(), subject.getSchoolId(), subject.getClassId())
|
|
|
|
refreshCurrentUserInfo(subject, app);
|
|
|
|
.orElseGet(() -> {
|
|
|
|
|
|
|
|
// 首次输出申请报文时创建记录
|
|
|
|
|
|
|
|
WalletApplication newApp = WalletApplication.create(
|
|
|
|
|
|
|
|
subject.getUserId(), subject.getSchoolId(), subject.getClassId(),
|
|
|
|
|
|
|
|
jwtUser.getUserName(), jwtUser.getPhone());
|
|
|
|
|
|
|
|
return walletRepository.save(newApp);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (app.getStatus() != null && app.getStatus().ordinal() >= WalletApplication.Status.OUTPUT.ordinal()) {
|
|
|
|
if (app.getStatus() != null && app.getStatus().ordinal() >= WalletApplication.Status.OUTPUT.ordinal()) {
|
|
|
|
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "申请报文已输出,请勿重复操作");
|
|
|
|
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "申请报文已输出,请勿重复操作");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -58,8 +78,11 @@ public class WalletOpeningService {
|
|
|
|
if (request.getWalletType() == null || request.getWalletType().trim().isEmpty()) {
|
|
|
|
if (request.getWalletType() == null || request.getWalletType().trim().isEmpty()) {
|
|
|
|
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "请选择数字钱包类型");
|
|
|
|
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "请选择数字钱包类型");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 输出申请报文时才存储身份证号、银行卡号等敏感信息
|
|
|
|
app.fillForm(request.getSelectedBank(), request.getWalletType(), request.getInputPhone(),
|
|
|
|
app.fillForm(request.getSelectedBank(), request.getWalletType(), request.getInputPhone(),
|
|
|
|
request.getInputIdNumber(), request.getInputBankCardNumber(), request.getSignaturePhotoPath());
|
|
|
|
request.getInputIdNumber(), request.getInputBankCardNumber(), request.getSignaturePhotoPath(),
|
|
|
|
|
|
|
|
request.getIdNumber(), request.getAccountBank(), request.getBankCardNumber(), request.getAccountBalance());
|
|
|
|
|
|
|
|
|
|
|
|
String applyTime = LocalDateTime.now().format(TIMESTAMP_FORMAT);
|
|
|
|
String applyTime = LocalDateTime.now().format(TIMESTAMP_FORMAT);
|
|
|
|
String applicationId = "APP_" + applyTime;
|
|
|
|
String applicationId = "APP_" + applyTime;
|
|
|
|
@ -72,8 +95,9 @@ public class WalletOpeningService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
@Transactional
|
|
|
|
public WalletSendResult sendApplication(InstitutionKeySubject subject) {
|
|
|
|
public WalletSendResult sendApplication(InstitutionKeySubject subject, JwtUser jwtUser) {
|
|
|
|
WalletApplication app = findRequired(subject);
|
|
|
|
WalletApplication app = walletRepository.findLatest(subject.getUserId(), subject.getSchoolId(), subject.getClassId())
|
|
|
|
|
|
|
|
.orElseThrow(() -> new BusinessException(ErrorCode.RESOURCE_NOT_FOUND, "钱包申请不存在,请先输出申请报文"));
|
|
|
|
if (app.getStatus() == null || app.getStatus().ordinal() < WalletApplication.Status.OUTPUT.ordinal()) {
|
|
|
|
if (app.getStatus() == null || app.getStatus().ordinal() < WalletApplication.Status.OUTPUT.ordinal()) {
|
|
|
|
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "请先输出申请报文");
|
|
|
|
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "请先输出申请报文");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -101,31 +125,6 @@ public class WalletOpeningService {
|
|
|
|
return new WalletSendResult("已提交");
|
|
|
|
return new WalletSendResult("已提交");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private WalletApplication findOrCreate(InstitutionKeySubject subject) {
|
|
|
|
|
|
|
|
return walletRepository.findLatest(subject.getUserId(), subject.getSchoolId(), subject.getClassId())
|
|
|
|
|
|
|
|
.orElseGet(() -> walletRepository.save(
|
|
|
|
|
|
|
|
WalletApplication.newDraft(subject.getUserId(), subject.getSchoolId(), subject.getClassId(),
|
|
|
|
|
|
|
|
subject.getUserName(), subject.getPhone())));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private WalletApplication findRequired(InstitutionKeySubject subject) {
|
|
|
|
|
|
|
|
return walletRepository.findLatest(subject.getUserId(), subject.getSchoolId(), subject.getClassId())
|
|
|
|
|
|
|
|
.orElseThrow(() -> new BusinessException(ErrorCode.RESOURCE_NOT_FOUND, "钱包申请不存在,请先初始化页面"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void refreshCurrentUserInfo(InstitutionKeySubject subject, WalletApplication app) {
|
|
|
|
|
|
|
|
String beforeUserName = app.getUserName();
|
|
|
|
|
|
|
|
String beforePhone = app.getPhone();
|
|
|
|
|
|
|
|
app.refreshTokenUserInfo(subject.getUserName(), subject.getPhone());
|
|
|
|
|
|
|
|
if (!equals(beforeUserName, app.getUserName()) || !equals(beforePhone, app.getPhone())) {
|
|
|
|
|
|
|
|
walletRepository.update(app);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean equals(String left, String right) {
|
|
|
|
|
|
|
|
return left == null ? right == null : left.equals(right);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String resolveOrgCode(InstitutionKeySubject subject) {
|
|
|
|
private String resolveOrgCode(InstitutionKeySubject subject) {
|
|
|
|
InstitutionIdentifierApplicationEntity entity = institutionIdentifierMapper.selectOne(
|
|
|
|
InstitutionIdentifierApplicationEntity entity = institutionIdentifierMapper.selectOne(
|
|
|
|
new LambdaQueryWrapper<InstitutionIdentifierApplicationEntity>()
|
|
|
|
new LambdaQueryWrapper<InstitutionIdentifierApplicationEntity>()
|
|
|
|
|