fix: switch DingTalk attendance API from getcolumnval to listRecord
This commit is contained in:
@@ -392,18 +392,17 @@ export class DingTalkService {
|
||||
if (!this.configured) throw new Error('DingTalk not configured');
|
||||
const token = await this.getAccessToken();
|
||||
|
||||
const columnIdList = ['1','2','3','4','5','6','8','9'];
|
||||
const dateFrom = params.startDate.includes(' ') ? params.startDate : `${params.startDate} 00:00:00`;
|
||||
const dateTo = params.endDate.includes(' ') ? params.endDate : `${params.endDate} 23:59:59`;
|
||||
|
||||
const body: Record<string, unknown> = {
|
||||
column_id_list: columnIdList.join(','),
|
||||
from_date: params.startDate,
|
||||
to_date: params.endDate,
|
||||
offset: params.offset ?? 0,
|
||||
limit: params.limit ?? 50,
|
||||
checkDateFrom: dateFrom,
|
||||
checkDateTo: dateTo,
|
||||
};
|
||||
if (params.userIds?.length) body.userid_list = params.userIds.join(',');
|
||||
if (params.userIds?.length) body.userIds = params.userIds;
|
||||
|
||||
const res = await fetch(
|
||||
`https://oapi.dingtalk.com/topapi/attendance/getcolumnval?access_token=${token}`,
|
||||
`https://oapi.dingtalk.com/attendance/listRecord?access_token=${token}`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
@@ -412,14 +411,26 @@ export class DingTalkService {
|
||||
);
|
||||
const data = await res.json() as {
|
||||
errcode: number; errmsg: string;
|
||||
result: { hasMore: boolean; column_vals?: Array<{ column_vals: string[] }> };
|
||||
recordresult?: Array<{
|
||||
id: number; userId: string; workDate: number;
|
||||
userCheckTime: number; sourceType: string;
|
||||
checkType?: string; timeResult?: string;
|
||||
locationResult?: string; locationMethod?: string;
|
||||
userAddress?: string; userLongitude?: number; userLatitude?: number;
|
||||
}>;
|
||||
};
|
||||
if (data.errcode !== 0) throw new Error(`钉钉考勤获取失败: ${data.errmsg}`);
|
||||
|
||||
return (data.result?.column_vals ?? []).map((col) => {
|
||||
const v = col.column_vals ?? [];
|
||||
return { userId: v[0]??'', workDate: v[1]??'', timeResult: v[2]??'', locationResult: v[3]??'', planCheckTime: v[4]??'', actualCheckTime: v[5]??'', checkId: v[7]??'', checkType: v[8]??'' };
|
||||
});
|
||||
return (data.recordresult ?? []).map((r) => ({
|
||||
userId: r.userId,
|
||||
workDate: new Date(r.workDate).toISOString().slice(0, 10),
|
||||
timeResult: r.timeResult ?? r.sourceType ?? '',
|
||||
locationResult: r.locationResult ?? r.locationMethod ?? r.userAddress ?? '',
|
||||
planCheckTime: '',
|
||||
actualCheckTime: new Date(r.userCheckTime).toISOString(),
|
||||
checkId: String(r.id),
|
||||
checkType: r.checkType ?? r.sourceType ?? '',
|
||||
}));
|
||||
}
|
||||
|
||||
private delay(requestIndex: number): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user