237 lines
6.5 KiB
C++
237 lines
6.5 KiB
C++
|
|
#ifndef ATTENDANCE_SYSTEM_APP_HPP
|
|||
|
|
#define ATTENDANCE_SYSTEM_APP_HPP
|
|||
|
|
|
|||
|
|
#include <string>
|
|||
|
|
#include <vector>
|
|||
|
|
#include <map>
|
|||
|
|
#include <cstdint>
|
|||
|
|
#include <ctime>
|
|||
|
|
|
|||
|
|
// ============================================================
|
|||
|
|
// 枚举定义
|
|||
|
|
// ============================================================
|
|||
|
|
|
|||
|
|
/// 打卡方式
|
|||
|
|
enum class CheckinMethod {
|
|||
|
|
FACE, // 人脸识别
|
|||
|
|
GPS, // GPS定位
|
|||
|
|
CARD // 工牌刷卡
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/// 打卡状态
|
|||
|
|
enum class CheckinStatus {
|
|||
|
|
SUCCESS,
|
|||
|
|
FAILED
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/// 考勤状态
|
|||
|
|
enum class AttendanceStatus {
|
|||
|
|
NORMAL,
|
|||
|
|
LATE,
|
|||
|
|
EARLY,
|
|||
|
|
ABSENT,
|
|||
|
|
OVERTIME
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/// 预警类型
|
|||
|
|
enum class AlertType {
|
|||
|
|
UNCHECKED, // 未打卡
|
|||
|
|
EARLY, // 早退
|
|||
|
|
LATE, // 迟到
|
|||
|
|
MISSING // 连续缺勤
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/// 报表维度
|
|||
|
|
enum class ReportDimension {
|
|||
|
|
MONTH,
|
|||
|
|
DEPT,
|
|||
|
|
PROJECT
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/// 导出格式
|
|||
|
|
enum class ExportFormat {
|
|||
|
|
EXCEL,
|
|||
|
|
PDF
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/// 系统角色
|
|||
|
|
enum class SystemRole {
|
|||
|
|
SUPER_ADMIN,
|
|||
|
|
HR_MANAGER,
|
|||
|
|
DEPT_MANAGER
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/// 数据同步类型
|
|||
|
|
enum class SyncDataType {
|
|||
|
|
EMPLOYEE,
|
|||
|
|
SCHEDULE,
|
|||
|
|
ATTENDANCE
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/// 同步状态
|
|||
|
|
enum class SyncStatus {
|
|||
|
|
SUCCESS,
|
|||
|
|
FAILED,
|
|||
|
|
PENDING
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// ============================================================
|
|||
|
|
// 数据结构定义
|
|||
|
|
// ============================================================
|
|||
|
|
|
|||
|
|
/// 经纬度坐标
|
|||
|
|
struct GeoLocation {
|
|||
|
|
double lat = 0.0;
|
|||
|
|
double lng = 0.0;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/// 打卡记录 (Check-in Record)
|
|||
|
|
struct CheckinRecord {
|
|||
|
|
std::string recordId; // 打卡记录编号
|
|||
|
|
std::string employeeId; // 员工编号
|
|||
|
|
CheckinMethod method; // 打卡方式
|
|||
|
|
int64_t timestamp; // 13位Unix时间戳(毫秒)
|
|||
|
|
GeoLocation location; // 地理位置
|
|||
|
|
std::vector<uint8_t> faceFeature; // 人脸特征码(加密后)
|
|||
|
|
CheckinStatus status; // 打卡状态
|
|||
|
|
|
|||
|
|
CheckinRecord()
|
|||
|
|
: method(CheckinMethod::FACE), timestamp(0), status(CheckinStatus::SUCCESS) {}
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/// 班次定义
|
|||
|
|
struct ShiftRule {
|
|||
|
|
std::string shiftName; // 班次名称
|
|||
|
|
int startHour = 9; // 开始小时
|
|||
|
|
int startMinute = 0; // 开始分钟
|
|||
|
|
int endHour = 18; // 结束小时
|
|||
|
|
int endMinute = 0; // 结束分钟
|
|||
|
|
int breakDuration = 60; // 休息时长(分钟)
|
|||
|
|
int overtimeThreshold = 30; // 加班判定阈值(分钟)
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/// 排班规则 (Schedule Rule)
|
|||
|
|
struct ScheduleRule {
|
|||
|
|
std::string deptId; // 部门编号
|
|||
|
|
std::vector<ShiftRule> rules; // 班次列表
|
|||
|
|
std::string version; // 规则版本号
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/// 考勤结果 (Attendance Result)
|
|||
|
|
struct AttendanceResult {
|
|||
|
|
std::string employeeId; // 员工编号
|
|||
|
|
std::string date; // 日期 YYYY-MM-DD
|
|||
|
|
int64_t actualInTime = 0; // 实际签到时间戳
|
|||
|
|
int64_t actualOutTime = 0; // 实际签退时间戳
|
|||
|
|
int scheduledInHour = 9; // 应签到小时
|
|||
|
|
int scheduledInMin = 0; // 应签到分钟
|
|||
|
|
int scheduledOutHour = 18; // 应签退小时
|
|||
|
|
int scheduledOutMin = 0; // 应签退分钟
|
|||
|
|
int lateMinutes = 0; // 迟到分钟数
|
|||
|
|
int earlyLeaveMinutes = 0; // 早退分钟数
|
|||
|
|
bool absent = false; // 是否缺勤
|
|||
|
|
float overtimeHours = 0.0f; // 加班小时数
|
|||
|
|
AttendanceStatus status; // 考勤状态
|
|||
|
|
|
|||
|
|
AttendanceResult() : status(AttendanceStatus::NORMAL) {}
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/// 异常预警 (Alert Notification)
|
|||
|
|
struct AlertNotification {
|
|||
|
|
AlertType alertType; // 预警类型
|
|||
|
|
std::string employeeId; // 员工编号
|
|||
|
|
int64_t time; // 预警时间戳
|
|||
|
|
std::string reason; // 原因描述
|
|||
|
|
std::vector<std::string> notifiedChannels; // 已通知渠道
|
|||
|
|
|
|||
|
|
AlertNotification() : alertType(AlertType::UNCHECKED), time(0) {}
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/// 报表请求参数
|
|||
|
|
struct ReportRequest {
|
|||
|
|
ReportDimension dimension; // 报表维度
|
|||
|
|
std::string startDate; // 开始日期 YYYY-MM-DD
|
|||
|
|
std::string endDate; // 结束日期 YYYY-MM-DD
|
|||
|
|
ExportFormat format; // 导出格式
|
|||
|
|
std::string deptId; // 部门ID(仅DEPT维度)
|
|||
|
|
|
|||
|
|
ReportRequest()
|
|||
|
|
: dimension(ReportDimension::MONTH), format(ExportFormat::EXCEL) {}
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/// 报表响应
|
|||
|
|
struct ReportResponse {
|
|||
|
|
std::string reportUrl; // 报表下载链接
|
|||
|
|
int64_t fileSize = 0; // 文件大小(字节)
|
|||
|
|
bool success = false;
|
|||
|
|
std::string message;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/// 系统用户
|
|||
|
|
struct SystemUser {
|
|||
|
|
std::string userId;
|
|||
|
|
std::string username;
|
|||
|
|
SystemRole role;
|
|||
|
|
std::vector<std::string> permissions; // 权限集合
|
|||
|
|
std::string departmentId;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/// 外部同步请求
|
|||
|
|
struct SyncRequest {
|
|||
|
|
std::string authToken;
|
|||
|
|
SyncDataType dataType;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/// 外部同步响应
|
|||
|
|
struct SyncResponse {
|
|||
|
|
SyncStatus syncStatus;
|
|||
|
|
std::string errorMsg;
|
|||
|
|
|
|||
|
|
SyncResponse() : syncStatus(SyncStatus::SUCCESS) {}
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// ============================================================
|
|||
|
|
// 核心功能函数声明
|
|||
|
|
// ============================================================
|
|||
|
|
|
|||
|
|
/// 将 CheckinMethod 枚举转换为字符串
|
|||
|
|
std::string checkinMethodToString(CheckinMethod method);
|
|||
|
|
|
|||
|
|
/// 将 AttendanceStatus 枚举转换为字符串
|
|||
|
|
std::string attendanceStatusToString(AttendanceStatus status);
|
|||
|
|
|
|||
|
|
/// 将 AlertType 枚举转换为字符串
|
|||
|
|
std::string alertTypeToString(AlertType type);
|
|||
|
|
|
|||
|
|
/// 生成唯一记录ID (基于时间戳+随机数)
|
|||
|
|
std::string generateRecordId();
|
|||
|
|
|
|||
|
|
/// 验证JWT令牌(简化模拟)
|
|||
|
|
bool validateToken(const std::string& token);
|
|||
|
|
|
|||
|
|
/// 验证打卡权限
|
|||
|
|
bool checkCheckinPermission(const std::string& employeeId, CheckinMethod method);
|
|||
|
|
|
|||
|
|
/// 记录打卡(核心业务函数)
|
|||
|
|
CheckinRecord processCheckin(const std::string& employeeId, CheckinMethod method,
|
|||
|
|
int64_t timestamp, const GeoLocation& location,
|
|||
|
|
const std::vector<uint8_t>& faceFeature);
|
|||
|
|
|
|||
|
|
/// 判定考勤结果
|
|||
|
|
AttendanceResult calculateAttendance(const CheckinRecord& record,
|
|||
|
|
const ShiftRule& shiftRule);
|
|||
|
|
|
|||
|
|
/// 检测异常并生成预警
|
|||
|
|
AlertNotification detectAnomaly(const AttendanceResult& result);
|
|||
|
|
|
|||
|
|
/// 生成报表(模拟)
|
|||
|
|
ReportResponse generateReport(const ReportRequest& request);
|
|||
|
|
|
|||
|
|
/// 加密人脸特征(哈希+盐值模拟)
|
|||
|
|
std::vector<uint8_t> encryptFaceFeature(const std::vector<uint8_t>& feature);
|
|||
|
|
|
|||
|
|
/// 运行演示场景(主菜单)
|
|||
|
|
void runDemo();
|
|||
|
|
|
|||
|
|
#endif // ATTENDANCE_SYSTEM_APP_HPP
|