每日总结
package com.mentalhealth.service;
import com.mentalhealth.entity.Consultant;
import com.mentalhealth.entity.ConsultantDailyPlan;
import com.mentalhealth.repository.ConsultantDailyPlanRepository;
import com.mentalhealth.repository.ConsultantRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
@Service
@RequiredArgsConstructor
public class NotificationService {
private final ConsultantDailyPlanRepository dailyPlanRepository;
private final ConsultantRepository consultantRepository;
// 检查并发送逾期提醒
public void checkAndSendOverdueReminders() {
LocalDate today = LocalDate.now();
// 获取所有咨询师的逾期任务
List<Consultant> consultants = consultantRepository.findAll();
for (Consultant consultant : consultants) {
List<ConsultantDailyPlan> overduePlans = dailyPlanRepository.findOverduePlans(
consultant.getId(), today);
for (ConsultantDailyPlan plan : overduePlans) {
if (shouldSendOverdueReminder(plan)) {
sendNotification(consultant, plan, "OVERDUE");
plan.setReminderCount(plan.getReminderCount() + 1);
plan.setLastReminderTime(LocalDateTime.now());
dailyPlanRepository.save(plan);
}
}
}
}
private boolean shouldSendOverdueReminder(ConsultantDailyPlan plan) {
if (plan.getLastReminderTime() == null) {
return true;
}
// 每6小时提醒一次
return plan.getLastReminderTime().isBefore(LocalDateTime.now().minusHours(6));
}
private void sendNotification(Consultant consultant, ConsultantDailyPlan plan, String type) {
// 实现通知发送逻辑(邮件、短信、站内信等)
System.out.println("发送通知给: " + consultant.getUser().getUsername());
System.out.println("任务: " + plan.getTaskDescription());
System.out.println("类型: " + type);
}
}
package com.mentalhealth.service;
import com.mentalhealth.entity.ConsultationSession;
import com.mentalhealth.repository.ConsultationSessionRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@Service
@Slf4j
@RequiredArgsConstructor
public class PaymentService {
private final ConsultationSessionRepository sessionRepository;
@Transactional
public Map<String, String> createPayment(Long sessionId) {
ConsultationSession session = sessionRepository.findById(sessionId)
.orElseThrow(() -> new RuntimeException("咨询会话不存在"));
// 生成支付订单
String orderId = generateOrderId();
BigDecimal amount = session.getPrice();
// 这里应该调用第三方支付接口
Map<String, String> paymentInfo = new HashMap<>();
paymentInfo.put("orderId", orderId);
paymentInfo.put("amount", amount.toString());
paymentInfo.put("sessionId", sessionId.toString());
paymentInfo.put("paymentUrl", "https://payment.example.com/pay?orderId=" + orderId);
log.info("创建支付订单: {}", paymentInfo);
return paymentInfo;
}
@Transactional
public boolean processPaymentCallback(String orderId, boolean success) {
// 处理支付回调
if (success) {
// 根据orderId找到对应的session并更新状态
// 这里简化处理
log.info("支付成功,订单号: {}", orderId);
return true;
} else {
log.warn("支付失败,订单号: {}", orderId);
return false;
}
}
private String generateOrderId() {
return "MH" + System.currentTimeMillis() + UUID.randomUUID().toString().substring(0, 8);
}
public BigDecimal calculateRefundAmount(ConsultationSession session) {
// 计算退款金额,根据取消时间等因素
return session.getPrice().multiply(new BigDecimal("0.8")); // 退款80%
}
}

浙公网安备 33010602011771号