| | |
| | | import com.ruoyi.basic.pojo.CustomerReturnVisit; |
| | | import com.ruoyi.basic.service.CustomerReturnVisitService; |
| | | import com.ruoyi.framework.redis.RedisCache; |
| | | import com.ruoyi.project.system.domain.SysUserClient; |
| | | import com.ruoyi.project.system.service.SysUserClientService; |
| | | import com.ruoyi.project.system.service.impl.UnipushService; |
| | | |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | |
| | | |
| | | private final CustomerReturnVisitService customerReturnVisitService; |
| | | |
| | | private final UnipushService unipushService; |
| | | |
| | | private final SysUserClientService userClientService; |
| | | |
| | | @SuppressWarnings("unchecked") |
| | | @Scheduled(fixedDelay = 60000) |
| | |
| | | } |
| | | } |
| | | |
| | | @SuppressWarnings("unchecked") |
| | | private void processReminder(Long returnVisitId) { |
| | | CustomerReturnVisit returnVisit = customerReturnVisitService.getById(returnVisitId); |
| | | if (returnVisit == null || returnVisit.getIsEnabled() == 0 || returnVisit.getIsCompleted() == 1) { |
| | | return; |
| | | } |
| | | SysUserClient client = userClientService.getById(returnVisit.getRemindUserId()); |
| | | if (client == null || client.getCid() == null) { |
| | | log.warn("用户未绑定CID, 无法发送Unipush推送: userId={}", returnVisit.getRemindUserId()); |
| | | return; |
| | | } |
| | | |
| | | try { |
| | | unipushService.sendReturnVisitReminder(returnVisitId, client.getCid(), returnVisit.getContent(), returnVisit.getCustomerPrivatePoolId()); |
| | | // 标记已处理(推送功能已禁用) |
| | | CustomerReturnVisit updateObj = new CustomerReturnVisit(); |
| | | updateObj.setId(returnVisitId); |
| | | updateObj.setIsCompleted(1); |
| | | customerReturnVisitService.updateById(updateObj); |
| | | |
| | | log.info("回访提醒已通过 Unipush 发送: ID={}", returnVisitId); |
| | | log.info("回访提醒已处理(推送功能已禁用): ID={}", returnVisitId); |
| | | } catch (Exception e) { |
| | | log.error("发送回访提醒失败,重新加入队列: ID={}", returnVisitId, e); |
| | | long retryTime = System.currentTimeMillis() + 60000; |
| | | redisCache.redisTemplate.opsForZSet().add(REMINDER_QUEUE_KEY, returnVisitId, retryTime); |
| | | log.error("处理回访提醒失败: ID={}", returnVisitId, e); |
| | | } |
| | | } |
| | | } |