001/include/alert.hpp

106 lines
3.8 KiB
C++

#ifndef ATTENDANCE_SYSTEM_ALERT_HPP
#define ATTENDANCE_SYSTEM_ALERT_HPP
#include <string>
#include <ctime>
#include <vector>
namespace AttendanceSystem {
// 异常类型枚举
enum class AlertType {
NO_CHECK_IN, // 未打卡
CHECK_IN_TIME_DEVIATION, // 打卡时间偏离
CONTINUOUS_ABSENCE, // 连续缺勤
LOCATION_OUT_OF_RANGE, // 位置超出范围
MULTIPLE_CHECK_INS // 多次打卡(可能作弊)
};
// 通知渠道枚举
enum class NotificationChannel {
IN_APP_MESSAGE, // 站内消息
SMS, // 短信
EMAIL // 邮件
};
class AlertEvent {
public:
AlertEvent();
AlertEvent(const std::string& eventId, const std::string& employeeId,
AlertType alertType, time_t time, const std::string& reason = "");
// Getter方法
std::string getEventId() const { return eventId_; }
std::string getEmployeeId() const { return employeeId_; }
AlertType getAlertType() const { return alertType_; }
time_t getTime() const { return time_; }
std::string getReason() const { return reason_; }
std::vector<NotificationChannel> getNotifiedChannels() const { return notifiedChannels_; }
bool isHandled() const { return handled_; }
time_t getHandleTime() const { return handleTime_; }
std::string getHandlerId() const { return handlerId_; }
std::string getHandleRemarks() const { return handleRemarks_; }
// Setter方法
void setEventId(const std::string& id) { eventId_ = id; }
void setEmployeeId(const std::string& empId) { employeeId_ = empId; }
void setAlertType(AlertType type) { alertType_ = type; }
void setTime(time_t time) { time_ = time; }
void setReason(const std::string& reason) { reason_ = reason; }
void setNotifiedChannels(const std::vector<NotificationChannel>& channels) {
notifiedChannels_ = channels;
}
void setHandled(bool handled) { handled_ = handled; }
void setHandleTime(time_t time) { handleTime_ = time; }
void setHandlerId(const std::string& handlerId) { handlerId_ = handlerId; }
void setHandleRemarks(const std::string& remarks) { handleRemarks_ = remarks; }
// 添加通知渠道
void addNotificationChannel(NotificationChannel channel);
// 移除通知渠道
void removeNotificationChannel(NotificationChannel channel);
// 检查是否已通过指定渠道通知
bool isNotifiedByChannel(NotificationChannel channel) const;
// 验证事件是否有效
bool isValid() const;
// 获取异常类型字符串
std::string getAlertTypeString() const;
// 获取通知渠道字符串
std::string getNotificationChannelsString() const;
// 获取格式化时间字符串
std::string getFormattedTime() const;
// 显示异常事件
void display() const;
// 处理异常事件
void handle(const std::string& handlerId, const std::string& remarks = "");
// 判断是否为严重异常
bool isCritical() const;
// 判断是否需要立即处理
bool needsImmediateAttention() const;
private:
std::string eventId_; // 事件ID
std::string employeeId_; // 员工ID
AlertType alertType_; // 异常类型
time_t time_; // 发生时间
std::string reason_; // 原因说明
std::vector<NotificationChannel> notifiedChannels_; // 已通知渠道
bool handled_; // 是否已处理
time_t handleTime_; // 处理时间
std::string handlerId_; // 处理人ID
std::string handleRemarks_; // 处理备注
};
} // namespace AttendanceSystem
#endif // ATTENDANCE_SYSTEM_ALERT_HPP