diff --git a/src/apis/dingTalkApi.ts b/src/apis/dingTalkApi.ts index 53609f8..fb66f94 100644 --- a/src/apis/dingTalkApi.ts +++ b/src/apis/dingTalkApi.ts @@ -10,9 +10,12 @@ import { IDingTalkUserResult, IGetReportSimplelistParams, IGetReportSimplelistResult, + IGetUserLeaveStatusBodyData, + IGetUserLeaveStatusResult, IReportSimpleListResult, IReportTemplate, IReportTemplateResult, + IUserAttendance, IUserAttendanceResult, } from '@interfaces/dingTalk'; import * as moment from 'moment'; @@ -183,7 +186,7 @@ export default class DingTalkApi { body: JSON.stringify(bodyData), }, ).then((res): Promise => res.json()); - return res.result; + return res.result as IUserAttendance; } /** @@ -262,4 +265,23 @@ export default class DingTalkApi { ).then((res): Promise => res.json()); return res; } + + /** + * 获取用户请假状态 + * @param bodyData + * @returns + */ + async getLeaveStatus(bodyData: IGetUserLeaveStatusBodyData) { + bodyData.offset = 0; + bodyData.size = 20; + const token = await this.getDingTalkAccessToken(); + const res = await fetch( + `${this.apiUrl}/topapi/attendance/getleavestatus?access_token=${token}`, + { + method: 'POST', + body: JSON.stringify(bodyData), + }, + ).then((res): Promise => res.json()); + return res; + } } diff --git a/src/constants/dingTalk.ts b/src/constants/dingTalk.ts index 9b066fe..a36d37c 100644 --- a/src/constants/dingTalk.ts +++ b/src/constants/dingTalk.ts @@ -28,6 +28,7 @@ export enum AttendanceState { 'J' = 7, 'L' = 8, 'A' = 9, + 'Anomalous' = 10, } export enum AttendanceCheckType { @@ -36,9 +37,10 @@ export enum AttendanceCheckType { } export enum TimeResultType { - 'Normal' = 'Normal', //正常 + 'Normal' = 'Normal', //正常打卡 'Late' = 'Late', // 迟到 'Early' = 'Early', // 早退 + 'NotSigned' = 'NotSigned', // 没有打卡 } export enum GroupId { diff --git a/src/interfaces/dingTalk/attendance.ts b/src/interfaces/dingTalk/attendance.ts index 8bc9af4..faa042d 100644 --- a/src/interfaces/dingTalk/attendance.ts +++ b/src/interfaces/dingTalk/attendance.ts @@ -40,7 +40,7 @@ export interface IAttendanceListResult { export interface IUserAttendanceRecordResult { check_type: AttendanceCheckType; plan_check_time: string; - user_check_time: string; + user_check_time: number; time_result: TimeResultType; userId: string; } diff --git a/src/interfaces/dingTalk/report.ts b/src/interfaces/dingTalk/report.ts index 4d3f3ba..2622e92 100644 --- a/src/interfaces/dingTalk/report.ts +++ b/src/interfaces/dingTalk/report.ts @@ -106,3 +106,27 @@ interface Datalist { export type IGetReportSimplelistResult = IDingTalkBaseResult; + +export interface IGetUserLeaveStatusBodyData { + userid_list: string; + start_time: number; + end_time: number; + offset?: number; + size?: number; +} + +export interface IGetUserLeaveStatusResultData { + has_more: boolean; + leave_status: [ + { + duration_percent: number; + duration_unit: string; + end_time: number; + start_time: number; + userid: string; + }, + ]; +} + +export type IGetUserLeaveStatusResult = + IDingTalkBaseResult; diff --git a/src/services/attendance.service.ts b/src/services/attendance.service.ts index b05a0ae..da95696 100644 --- a/src/services/attendance.service.ts +++ b/src/services/attendance.service.ts @@ -135,6 +135,11 @@ export class AttendanceService { return (await this.getLeaveTimeByMinutes()) >= 7.5 * 60; } + // 是否请假一天 + private async whetherLeave() { + return (await this.getLeaveTimeByMinutes()) > 0; + } + private async getLeaveTimeByMinutes() { const leaveType = [ AttendanceState.C, @@ -161,7 +166,7 @@ export class AttendanceService { const { date } = this.findNextNotHolodayDate( moment(this.tiems.start).format('YYYY-MM-DD'), ); - const startTime = moment(this.tiems.start).format('YYYY-MM-DD 09:00:01'); + const startTime = moment(this.tiems.start).format('YYYY-MM-DD 00:00:01'); const endTime = moment(date).format('YYYY-MM-DD 08:59:59'); const reports = await this.dingTalkApi.getReports( startTime, @@ -279,6 +284,18 @@ export class AttendanceService { _attendance.value += Math.abs(subTime); } } + // 没打卡没请假视为异常需要人工审核 + const whetherLeave = await this.whetherLeave(); + const notSigned = + attendance.attendance_result_list.filter((x) => { + return x.time_result === TimeResultType.NotSigned; + }).length >= 2; + + if (notSigned && !whetherLeave) { + _attendance.state = AttendanceState.Anomalous; + _attendance.value = null; + } + this.attendances.push({ state: _attendance.state, value: _attendance.state === AttendanceState.O ? null : _attendance.value,