|
|
@@ -74,12 +74,17 @@ public class TransactionRecordEventHandler implements HikEventHandler {
|
|
|
}
|
|
|
|
|
|
BigDecimal balance = null;
|
|
|
+ String actualPayment = transactionRecordEvent.getActualPayment();
|
|
|
+ BigDecimal consumeMoney = BigDecimal.ZERO;
|
|
|
+ if(StringUtils.isNotBlank(actualPayment)){
|
|
|
+ balance = new BigDecimal(actualPayment).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP);
|
|
|
+ }
|
|
|
// 这里只能应答成功,如果是业务异常(余额不足、脏数据等)失败,要存入表中,使用定时任务处理失败,所以即使失败的 也要回复成功
|
|
|
// 如果是在线交易的,平台根据流水号判断当前交易记录事件是否为未处理事件,若为未处理事件,则平台进行处理并进行扣费;
|
|
|
// 如果是离线交易记录事件,则平台进行处理并进行扣费;
|
|
|
RemoteConsumeBo remoteBo = getRemoteBo(transactionRecordEventReceive);
|
|
|
remoteBo.setTermNo(termNo);
|
|
|
- R<ErrorInfo> errorInfo = R.fail("处理失败");
|
|
|
+ R<ErrorInfo> errorInfo = R.ok("处理成功");
|
|
|
try {
|
|
|
if (ModeTypeEnum.offLine.getCode().equals(modeType)) {
|
|
|
// 离线交易,调用原始消费记录请求+消费记录入库的接口,如果失败要记录入库
|
|
|
@@ -88,6 +93,7 @@ public class TransactionRecordEventHandler implements HikEventHandler {
|
|
|
RemoteConsumeBo updatedRemoteBo = remoteResultDto.getUpdatedRemoteBo();
|
|
|
if(updatedRemoteBo !=null) {
|
|
|
balance = updatedRemoteBo.getBalance();
|
|
|
+ consumeMoney = updatedRemoteBo.getConsumeMoney();
|
|
|
}
|
|
|
}else{
|
|
|
// 在线交易,调用消费记录入库的接口
|
|
|
@@ -102,10 +108,12 @@ public class TransactionRecordEventHandler implements HikEventHandler {
|
|
|
RemoteConsumeBo updatedRemoteBo = remoteResultDto.getUpdatedRemoteBo();
|
|
|
if(updatedRemoteBo !=null) {
|
|
|
balance = updatedRemoteBo.getBalance();
|
|
|
+ consumeMoney = updatedRemoteBo.getConsumeMoney();
|
|
|
}
|
|
|
}else{
|
|
|
XfConsumeDetailVo consumeDetailVo = vos.get(0);
|
|
|
balance = consumeDetailVo.getCardValue();
|
|
|
+ consumeMoney = consumeDetailVo.getConsumeMoney();
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
@@ -117,14 +125,14 @@ public class TransactionRecordEventHandler implements HikEventHandler {
|
|
|
|
|
|
insertFailedRecordBo(transactionRecordEventReceive, termNo, errorInfo, modeType);
|
|
|
//应答
|
|
|
- return answerEvent(transactionRecordEventReceive,balance);
|
|
|
+ return answerEvent(transactionRecordEventReceive,balance,consumeMoney);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @param info 事件信息
|
|
|
* 应答事件 put /ISAPI/Consume/transactionRecordEventConfirm?format=json 应答TransactionRecordEvent
|
|
|
*/
|
|
|
- public Map<String, Object> answerEvent(TransactionRecordEventReceive info, BigDecimal balance){
|
|
|
+ public Map<String, Object> answerEvent(TransactionRecordEventReceive info, BigDecimal balance, BigDecimal consumeMoney){
|
|
|
TransactionRecordEventConfirmBo confirmBo = new TransactionRecordEventConfirmBo();
|
|
|
|
|
|
TransactionRecordEventDetail transactionDetail = info.getTransactionRecordEvent();
|
|
|
@@ -132,10 +140,12 @@ public class TransactionRecordEventHandler implements HikEventHandler {
|
|
|
confirmBo.setResult("success");
|
|
|
confirmBo.setEmployeeNo(transactionDetail.getEmployeeNoString());
|
|
|
//余额的单位为分
|
|
|
- if(balance == null){
|
|
|
- balance = new BigDecimal("0");
|
|
|
- }
|
|
|
- confirmBo.setBalance(balance.multiply(new BigDecimal("100")).toString().split("\\.")[0]);
|
|
|
+ // 使用 BigDecimal 的 null 安全处理工具类简化逻辑,并避免重复代码
|
|
|
+ BigDecimal newBalance = Optional.ofNullable(balance).orElse(BigDecimal.ZERO);
|
|
|
+ confirmBo.setBalance(newBalance.multiply(BigDecimal.valueOf(100)).setScale(0, RoundingMode.DOWN).toString());
|
|
|
+
|
|
|
+ BigDecimal newConsumeMoney = Optional.ofNullable(consumeMoney).orElse(BigDecimal.ZERO);
|
|
|
+ confirmBo.setActualPayment(newConsumeMoney.multiply(BigDecimal.valueOf(100)).setScale(0, RoundingMode.DOWN).toString());
|
|
|
|
|
|
HashMap<String, Object> map = new HashMap<>(1);
|
|
|
map.put("TransactionRecordEventConfirm", confirmBo);
|