| | |
| | | package com.tcm.training.admin.points.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.tcm.training.admin.app.notice.service.AppSystemNoticeDispatchCommand; |
| | | import com.tcm.training.admin.app.notice.service.AppSystemNoticeDispatchService; |
| | | import com.tcm.training.admin.app.notice.service.AppSystemNoticeType; |
| | | import com.tcm.training.admin.member.entity.AppUser; |
| | | import com.tcm.training.admin.member.mapper.UserMapper; |
| | | import com.tcm.training.admin.live.entity.Clinic; |
| | |
| | | private final UserMapper userMapper; |
| | | private final ClinicMapper clinicMapper; |
| | | private final PointsLedgerAppService pointsLedgerAppService; |
| | | private final AppSystemNoticeDispatchService appSystemNoticeDispatchService; |
| | | |
| | | public PointsSettlementService(PointsConfigMapper pointsConfigMapper, |
| | | UserPointsAccountMapper userPointsAccountMapper, |
| | |
| | | PointsExchangeOrderItemMapper pointsExchangeOrderItemMapper, |
| | | UserMapper userMapper, |
| | | ClinicMapper clinicMapper, |
| | | PointsLedgerAppService pointsLedgerAppService) { |
| | | PointsLedgerAppService pointsLedgerAppService, |
| | | AppSystemNoticeDispatchService appSystemNoticeDispatchService) { |
| | | this.pointsConfigMapper = pointsConfigMapper; |
| | | this.userPointsAccountMapper = userPointsAccountMapper; |
| | | this.pointsExchangeOrderMapper = pointsExchangeOrderMapper; |
| | |
| | | this.userMapper = userMapper; |
| | | this.clinicMapper = clinicMapper; |
| | | this.pointsLedgerAppService = pointsLedgerAppService; |
| | | this.appSystemNoticeDispatchService = appSystemNoticeDispatchService; |
| | | } |
| | | |
| | | @Scheduled(fixedDelayString = "${app.points.settlement-interval-ms:60000}") |
| | |
| | | order.setTotalPoints(sumPoints(group)); |
| | | order.setStatus(0); |
| | | pointsExchangeOrderMapper.insert(order); |
| | | dispatchGiftOrderCreatedNotice(order, config, group); |
| | | |
| | | for (PointsExchangeOrderItem item : group) { |
| | | item.setOrderId(order.getId()); |
| | |
| | | ); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 在积分兑换汇总订单生成后,通知当前诊所用户尽快处理兑换单。 |
| | | */ |
| | | private void dispatchGiftOrderCreatedNotice(PointsExchangeOrder order, PointsConfig config, List<PointsExchangeOrderItem> group) { |
| | | if (order == null || order.getId() == null || order.getClinicAppUserId() == null) { |
| | | return; |
| | | } |
| | | AppSystemNoticeDispatchCommand command = new AppSystemNoticeDispatchCommand(); |
| | | command.setAppUserId(order.getClinicAppUserId()); |
| | | command.setNoticeTypeCode(AppSystemNoticeType.ORDER_STATUS_UPDATE); |
| | | command.setTitle("订单状态更新"); |
| | | command.setContent("您有新的礼品兑换订单待处理"); |
| | | command.setReferenceType("POINTS_EXCHANGE_ORDER"); |
| | | command.setReferenceId(order.getId()); |
| | | command.setRequireUserSetting(Boolean.TRUE); |
| | | Map<String, String> payload = new LinkedHashMap<String, String>(); |
| | | payload.put("orderId", String.valueOf(order.getId())); |
| | | payload.put("orderNo", defaultText(order.getOrderNo())); |
| | | payload.put("giftName", config == null ? "" : defaultText(config.getGiftName())); |
| | | payload.put("itemCount", String.valueOf(group == null ? 0 : group.size())); |
| | | command.setPayload(payload); |
| | | appSystemNoticeDispatchService.createAndPush(command); |
| | | } |
| | | |
| | | private String buildGroupKey(PointsExchangeOrderItem item) { |
| | |
| | | private String buildSettlementReferenceNo(Long configId) { |
| | | return SETTLEMENT_CLEAR_REFERENCE_PREFIX + (configId == null ? 0L : configId.longValue()); |
| | | } |
| | | |
| | | /** |
| | | * 返回安全文本,避免通知载荷出现空值。 |
| | | */ |
| | | private String defaultText(String value) { |
| | | return value == null ? "" : value; |
| | | } |
| | | } |