Commit 6a7ec088 by 程裕兵

feat:fix repeat process refund callback and trigger cashier event

parent fd76e201
......@@ -150,26 +150,34 @@ public class RefundServiceImpl implements RefundService {
@Override
public void refundCallback(RefundEvent event) {
StudioCashierRecord record = studioCashierRecordRpService.getById(Long.parseLong(event.getTransNo()))
.orElse(null);
if (null == record) {
return;
}
Long id = Long.parseLong(event.getTransNo());
StudioCashierRecord exist = transactionTemplate.execute(action -> {
StudioCashierRecord record = studioCashierRecordRpService.getByIdForUpdate(id).orElse(null);
if (null == record) {
return null;
}
BrandCashierTransStateEnum originalState = BrandCashierTransStateEnum.valueOf(record.getTransState());
BrandCashierTransStateEnum targetState = RefundConvert.convertTransState(event.getRefundState());
if (targetState == originalState) {
log.warn("repeat process refund callback {}, {}", JSON.toJSONString(event),
JSON.toJSONString(record));
return null;
}
BrandCashierTransStateEnum originalState = BrandCashierTransStateEnum.valueOf(record.getTransState());
BrandCashierTransStateEnum targetState = RefundConvert.convertTransState(event.getRefundState());
if (targetState == originalState) {
StudioCashierRecord toModify = RefundConvert.convertRefund(record, event);
studioCashierRecordRpService.updateById(toModify);
return record;
});
if (null == exist) {
return;
}
StudioCashierRecord toModify = RefundConvert.convertRefund(record, event);
studioCashierRecordRpService.updateById(toModify);
// 发布收银事件
this.triggerCashierEvent(record.getId());
this.triggerCashierEvent(exist.getId());
// 执行后续处理
this.doAfterRefund(event, record);
this.doAfterRefund(event, exist);
}
private void triggerCashierEvent(Long id) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment