task_auto_plan/include/app.hpp

147 lines
4.4 KiB
C++
Raw Normal View History

2026-04-25 08:10:44 +00:00
/**
* @file app.hpp
* @brief
*
*
* - SRS-ATT_F-001:
* - SRS-ATT_F-002:
* - SRS-ATT_F-003:
* - SRS-ATT_F-004:
* - SRS-ATT_F-005:
*/
#ifndef APP_HPP
#define APP_HPP
2026-04-25 03:15:03 +00:00
#include <string>
#include <vector>
#include <map>
#include <ctime>
2026-04-25 08:10:44 +00:00
// ---------- 数据结构 ----------
2026-04-25 03:15:03 +00:00
2026-04-25 08:10:44 +00:00
// 打卡请求SRS-ATT_F-001 输入)
struct PunchRequest {
std::string employeeId; // 员工唯一标识
std::string terminalType; // 终端类型MOBILE / WEB / MACHINE
std::string deviceId; // 设备标识
std::time_t timestamp; // 打卡时间戳(降级模式下仅缓存此字段)
double latitude; // 纬度(可选)
double longitude; // 经度(可选)
2026-04-25 03:15:03 +00:00
};
2026-04-25 08:10:44 +00:00
// 打卡结果响应SRS-ATT_F-001 输出)
struct PunchResponse {
bool success;
std::string message;
std::time_t serverTime;
2026-04-25 03:15:03 +00:00
};
2026-04-25 08:10:44 +00:00
// 考勤规则配置SRS-ATT_F-002 输入)
struct AttendanceRule {
2026-04-25 03:15:03 +00:00
std::string department;
2026-04-25 08:10:44 +00:00
std::string shift; // 班次
int startHour; // 上班时间(小时)
int startMinute;
int endHour; // 下班时间(小时)
int endMinute;
int lateThreshold; // 迟到容忍分钟数
int earlyLeaveThreshold; // 早退容忍分钟数
std::vector<std::string> holidays; // 节假日列表
2026-04-25 03:15:03 +00:00
};
2026-04-25 08:10:44 +00:00
// 原始打卡记录SRS-ATT_F-002 输入)
struct RawRecord {
std::string employeeId;
std::time_t punchTime;
std::string terminalType;
2026-04-25 03:15:03 +00:00
};
2026-04-25 08:10:44 +00:00
// 核算结果SRS-ATT_F-002 输出SRS-ATT_F-003 输入)
struct CalculationResult {
2026-04-25 03:15:03 +00:00
std::string employeeId;
2026-04-25 08:10:44 +00:00
std::time_t date;
enum Status { NORMAL, LATE, EARLY_LEAVE, ABSENT, MISSING_CARD };
Status status;
std::string shiftName;
std::time_t actualArrival;
std::time_t actualDeparture;
2026-04-25 03:15:03 +00:00
};
2026-04-25 08:10:44 +00:00
// 预警通知SRS-ATT_F-003 输出)
struct WarningNotification {
2026-04-25 03:15:03 +00:00
std::string employeeId;
2026-04-25 08:10:44 +00:00
std::string managerId; // 管理员ID严重异常时填充
CalculationResult::Status anomalyType;
std::string message;
long long sendTimestamp;
2026-04-25 03:15:03 +00:00
};
2026-04-25 08:10:44 +00:00
// 报表查询条件SRS-ATT_F-004 输入)
struct ReportQuery {
std::string department;
std::string employeeId; // 可选,若为空则查部门
std::time_t startDate;
std::time_t endDate;
enum Format { EXCEL, PDF, ONLINE };
Format format;
2026-04-25 03:15:03 +00:00
};
2026-04-25 08:10:44 +00:00
// 统计报表文件SRS-ATT_F-004 输出)
struct ReportFile {
std::string fileName;
2026-04-25 03:15:03 +00:00
std::string downloadUrl;
2026-04-25 08:10:44 +00:00
std::vector<char> rawData; // 二进制数据
2026-04-25 03:15:03 +00:00
};
2026-04-25 08:10:44 +00:00
// 第三方同步请求SRS-ATT_F-005 输入)
struct ThirdPartySyncRequest {
std::string apiKey; // 鉴权密钥
std::string systemType; // HR / OA / DoorAccess
std::vector<RawRecord> records; // 需要同步的打卡记录
2026-04-25 03:15:03 +00:00
};
2026-04-25 08:10:44 +00:00
// 考勤同步数据SRS-ATT_F-005 输出)
struct SyncResponse {
bool success;
int syncedCount;
int failedCount;
std::string message;
};
2026-04-25 03:15:03 +00:00
2026-04-25 08:10:44 +00:00
// ---------- 业务接口 ----------
class AttendanceSystem {
2026-04-25 03:15:03 +00:00
public:
2026-04-25 08:10:44 +00:00
AttendanceSystem();
~AttendanceSystem();
2026-04-25 03:15:03 +00:00
2026-04-25 08:10:44 +00:00
// SRS-ATT_F-001: 处理打卡请求移动端、Web端、考勤机
PunchResponse processPunch(const PunchRequest& req);
2026-04-25 03:15:03 +00:00
2026-04-25 08:10:44 +00:00
// SRS-ATT_F-002: 自动核算考勤数据(定时/事件触发)
void autoCalculateAttendance();
2026-04-25 03:15:03 +00:00
2026-04-25 08:10:44 +00:00
// SRS-ATT_F-003: 异常预警通知
void sendWarningForAnomaly(const CalculationResult& result);
2026-04-25 03:15:03 +00:00
2026-04-25 08:10:44 +00:00
// SRS-ATT_F-004: 生成并导出报表
ReportFile generateReport(const ReportQuery& query);
// SRS-ATT_F-005: 与第三方系统同步数据
SyncResponse syncWithThirdParty(const ThirdPartySyncRequest& request);
private:
// 辅助函数
bool validateEmployee(const std::string& employeeId);
AttendanceRule getRuleForEmployee(const std::string& employeeId);
void storeRawRecord(const RawRecord& rec);
void storeCalculationResult(const CalculationResult& res);
std::vector<RawRecord> fetchUncalculatedRecords();
CalculationResult calculateSingleRecord(const RawRecord& rec, const AttendanceRule& rule);
void logWarningSend(const WarningNotification& notif);
std::vector<std::string> getManagersForEmployee(const std::string& employeeId);
bool authenticateThirdParty(const std::string& apiKey);
};
2026-04-25 03:15:03 +00:00
2026-04-25 08:10:44 +00:00
#endif // APP_HPP