192 行
5.3 KiB
TypeScript
192 行
5.3 KiB
TypeScript
import { apiRequestData } from "./http";
|
|
|
|
export type AttendanceCorrectionKind = "missed_punch" | "out" | "overtime";
|
|
export type AttendanceCorrectionStatus = "reviewing" | "approved" | "rejected" | "cancelled";
|
|
export type AttendanceDailyStatus =
|
|
| "normal"
|
|
| "exception"
|
|
| "missing"
|
|
| "leave"
|
|
| "corrected"
|
|
| "overtime"
|
|
| "weekend";
|
|
|
|
export type AttendanceEmployeeSummary = {
|
|
id: string;
|
|
employeeNo: string;
|
|
name: string;
|
|
title?: string | null;
|
|
departmentId: string | null;
|
|
departmentName: string | null;
|
|
};
|
|
|
|
export type WecomCheckinSummary = {
|
|
id: string;
|
|
checkinAt: string | null;
|
|
checkinDate: string | null;
|
|
checkinType: string;
|
|
result: string | null;
|
|
exceptionType: string | null;
|
|
sourceType: string | null;
|
|
};
|
|
|
|
export type AttendanceCorrectionItem = {
|
|
id: string;
|
|
kind: AttendanceCorrectionKind;
|
|
status: AttendanceCorrectionStatus;
|
|
workDate: string | null;
|
|
missedPunchAt: string | null;
|
|
startAt: string | null;
|
|
endAt: string | null;
|
|
reason: string;
|
|
locationSummary: string | null;
|
|
compensationPolicy: string | null;
|
|
owner: AttendanceEmployeeSummary | null;
|
|
createdAt: string | null;
|
|
updatedAt: string | null;
|
|
workflow?: {
|
|
id: string;
|
|
status: string;
|
|
currentStepId: string;
|
|
} | null;
|
|
};
|
|
|
|
export type AttendanceMonthlyDay = {
|
|
date: string;
|
|
status: AttendanceDailyStatus;
|
|
explanation: string;
|
|
firstCheckinAt: string | null;
|
|
lastCheckinAt: string | null;
|
|
checkins: WecomCheckinSummary[];
|
|
corrections: AttendanceCorrectionItem[];
|
|
leaveRequests: Array<{
|
|
id: string;
|
|
leaveTypeName: string;
|
|
requestedDays: number;
|
|
reason: string | null;
|
|
}>;
|
|
};
|
|
|
|
export type AttendanceMonthlyEmployee = {
|
|
employee: AttendanceEmployeeSummary | null;
|
|
days: AttendanceMonthlyDay[];
|
|
};
|
|
|
|
export type AttendanceMonthlyResponse = {
|
|
month: string;
|
|
summary: {
|
|
employeeCount: number;
|
|
workDays: number;
|
|
checkinDays: number;
|
|
missingDays: number;
|
|
approvedCorrectionCount: number;
|
|
};
|
|
employees: AttendanceMonthlyEmployee[];
|
|
};
|
|
|
|
export type WecomCheckinSyncRun = {
|
|
id: string;
|
|
startDate: string | null;
|
|
endDate: string | null;
|
|
status: "running" | "success" | "skipped" | "failed" | string;
|
|
employeeCount: number;
|
|
recordCount: number;
|
|
errorCode: string | null;
|
|
errorMessage: string | null;
|
|
triggeredBy: AttendanceEmployeeSummary | null;
|
|
createdAt: string | null;
|
|
updatedAt: string | null;
|
|
};
|
|
|
|
export type AttendanceCorrectionCreatePayload = {
|
|
kind: AttendanceCorrectionKind;
|
|
workDate: string;
|
|
missedPunchAt?: string;
|
|
startAt?: string;
|
|
endAt?: string;
|
|
reason: string;
|
|
locationSummary?: string;
|
|
compensationPolicy?: string;
|
|
};
|
|
|
|
export async function fetchAttendanceMonthly(params?: { month?: string; employeeId?: string }) {
|
|
const search = new URLSearchParams();
|
|
if (params?.month) search.set("month", params.month);
|
|
if (params?.employeeId) search.set("employeeId", params.employeeId);
|
|
const query = search.toString();
|
|
return apiRequestData<AttendanceMonthlyResponse>(`/api/attendance/monthly${query ? `?${query}` : ""}`);
|
|
}
|
|
|
|
export async function triggerWecomAttendanceSync(payload: {
|
|
startDate: string;
|
|
endDate: string;
|
|
employeeIds?: string[];
|
|
}) {
|
|
return apiRequestData<{
|
|
item: WecomCheckinSyncRun;
|
|
skipped: boolean;
|
|
code: string;
|
|
employeeCount: number;
|
|
boundUserCount: number;
|
|
recordCount: number;
|
|
}>("/api/attendance/wecom/sync", {
|
|
method: "POST",
|
|
body: JSON.stringify(payload),
|
|
});
|
|
}
|
|
|
|
export async function fetchWecomAttendanceSyncRuns(params?: { page?: number; pageSize?: number }) {
|
|
const search = new URLSearchParams();
|
|
if (params?.page) search.set("page", String(params.page));
|
|
if (params?.pageSize) search.set("pageSize", String(params.pageSize));
|
|
const query = search.toString();
|
|
return apiRequestData<{
|
|
page: number;
|
|
pageSize: number;
|
|
total: number;
|
|
items: WecomCheckinSyncRun[];
|
|
}>(`/api/attendance/wecom/sync-runs${query ? `?${query}` : ""}`);
|
|
}
|
|
|
|
export async function createAttendanceCorrection(payload: AttendanceCorrectionCreatePayload) {
|
|
return apiRequestData<{
|
|
item: AttendanceCorrectionItem;
|
|
workflowInstanceId: string;
|
|
currentTaskId: string;
|
|
}>("/api/attendance-corrections", {
|
|
method: "POST",
|
|
body: JSON.stringify(payload),
|
|
});
|
|
}
|
|
|
|
export async function fetchAttendanceCorrections(params?: {
|
|
month?: string;
|
|
employeeId?: string;
|
|
status?: AttendanceCorrectionStatus;
|
|
kind?: AttendanceCorrectionKind;
|
|
page?: number;
|
|
pageSize?: number;
|
|
}) {
|
|
const search = new URLSearchParams();
|
|
if (params?.month) search.set("month", params.month);
|
|
if (params?.employeeId) search.set("employeeId", params.employeeId);
|
|
if (params?.status) search.set("status", params.status);
|
|
if (params?.kind) search.set("kind", params.kind);
|
|
if (params?.page) search.set("page", String(params.page));
|
|
if (params?.pageSize) search.set("pageSize", String(params.pageSize));
|
|
const query = search.toString();
|
|
return apiRequestData<{
|
|
page: number;
|
|
pageSize: number;
|
|
total: number;
|
|
items: AttendanceCorrectionItem[];
|
|
}>(`/api/attendance-corrections${query ? `?${query}` : ""}`);
|
|
}
|
|
|
|
export async function cancelAttendanceCorrection(id: string) {
|
|
return apiRequestData<{ item: AttendanceCorrectionItem }>(`/api/attendance-corrections/${id}/cancel`, {
|
|
method: "POST",
|
|
body: JSON.stringify({}),
|
|
});
|
|
}
|