@ -0,0 +1,51 @@
|
||||
package com.campus.water.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import jakarta.persistence.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 维修人员通知实体
|
||||
* 存储派单、系统通知等消息
|
||||
*/
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name = "notification")
|
||||
public class Notification {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
/** 维修人员ID */
|
||||
@Column(name = "repairman_id", nullable = false, length = 50)
|
||||
private String repairmanId;
|
||||
|
||||
/** 关联工单ID */
|
||||
@Column(name = "order_id", length = 50)
|
||||
private String orderId;
|
||||
|
||||
/** 通知内容 */
|
||||
@Column(name = "content", nullable = false, length = 500)
|
||||
private String content;
|
||||
|
||||
/** 是否已读(默认未读) */
|
||||
@Column(name = "is_read")
|
||||
private boolean isRead = false;
|
||||
|
||||
/** 创建时间 */
|
||||
@Column(name = "created_time", nullable = false)
|
||||
private LocalDateTime createdTime = LocalDateTime.now();
|
||||
|
||||
/** 通知类型 */
|
||||
@Enumerated(EnumType.STRING)
|
||||
@Column(name = "type", nullable = false, length = 20)
|
||||
private NotificationType type;
|
||||
|
||||
/** 通知类型枚举 */
|
||||
public enum NotificationType {
|
||||
ORDER_ASSIGNED, // 派单通知
|
||||
ORDER_GRABBED, // 抢单通知
|
||||
ORDER_REJECTED, // 拒单通知
|
||||
SYSTEM // 系统通知
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
package com.campus.water.service;
|
||||
|
||||
import com.campus.water.entity.Notification;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 维修人员通知服务接口
|
||||
*/
|
||||
public interface NotificationService {
|
||||
/**
|
||||
* 发送派单通知
|
||||
* @param repairmanId 维修人员ID
|
||||
* @param orderId 工单ID
|
||||
* @param content 通知内容
|
||||
*/
|
||||
void sendOrderAssignedNotification(String repairmanId, String orderId, String content);
|
||||
|
||||
/**
|
||||
* 获取维修人员未读通知
|
||||
* @param repairmanId 维修人员ID
|
||||
* @return 未读通知列表
|
||||
*/
|
||||
List<Notification> getUnreadNotifications(String repairmanId);
|
||||
|
||||
/**
|
||||
* 获取维修人员所有通知
|
||||
* @param repairmanId 维修人员ID
|
||||
* @return 所有通知列表
|
||||
*/
|
||||
List<Notification> getAllNotifications(String repairmanId);
|
||||
|
||||
/**
|
||||
* 标记通知为已读
|
||||
* @param notificationId 通知ID
|
||||
*/
|
||||
void markAsRead(Long notificationId);
|
||||
}
|
||||
@ -0,0 +1,59 @@
|
||||
package com.campus.water.service.impl;
|
||||
|
||||
import com.campus.water.entity.Notification;
|
||||
import com.campus.water.mapper.NotificationRepository;
|
||||
import com.campus.water.service.NotificationService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 通知服务实现类
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class NotificationServiceImpl implements NotificationService {
|
||||
|
||||
private final NotificationRepository notificationRepository;
|
||||
|
||||
/**
|
||||
* 发送派单通知
|
||||
*/
|
||||
@Override
|
||||
public void sendOrderAssignedNotification(String repairmanId, String orderId, String content) {
|
||||
Notification notification = new Notification();
|
||||
notification.setRepairmanId(repairmanId);
|
||||
notification.setOrderId(orderId);
|
||||
notification.setContent(content);
|
||||
notification.setType(Notification.NotificationType.ORDER_ASSIGNED);
|
||||
notificationRepository.save(notification);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取未读通知
|
||||
*/
|
||||
@Override
|
||||
public List<Notification> getUnreadNotifications(String repairmanId) {
|
||||
return notificationRepository.findByRepairmanIdAndIsReadFalseOrderByCreatedTimeDesc(repairmanId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有通知
|
||||
*/
|
||||
@Override
|
||||
public List<Notification> getAllNotifications(String repairmanId) {
|
||||
return notificationRepository.findByRepairmanIdOrderByCreatedTimeDesc(repairmanId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 标记通知为已读
|
||||
*/
|
||||
@Override
|
||||
public void markAsRead(Long notificationId) {
|
||||
notificationRepository.findById(notificationId).ifPresent(notification -> {
|
||||
notification.setRead(true);
|
||||
notificationRepository.save(notification);
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue