Skip to content

Commit

Permalink
Merge pull request #15 from graywenn/fix/attendanceIssues
Browse files Browse the repository at this point in the history
fixed attendance issues
  • Loading branch information
greywen authored Jul 27, 2022
2 parents 226a0dd + 19f6355 commit 2f65f63
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 4 deletions.
24 changes: 23 additions & 1 deletion src/apis/dingTalkApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ import {
IDingTalkUserResult,
IGetReportSimplelistParams,
IGetReportSimplelistResult,
IGetUserLeaveStatusBodyData,
IGetUserLeaveStatusResult,
IReportSimpleListResult,
IReportTemplate,
IReportTemplateResult,
IUserAttendance,
IUserAttendanceResult,
} from '@interfaces/dingTalk';
import * as moment from 'moment';
Expand Down Expand Up @@ -183,7 +186,7 @@ export default class DingTalkApi {
body: JSON.stringify(bodyData),
},
).then((res): Promise<IUserAttendanceResult> => res.json());
return res.result;
return res.result as IUserAttendance;
}

/**
Expand Down Expand Up @@ -262,4 +265,23 @@ export default class DingTalkApi {
).then((res): Promise<IGetReportSimplelistResult> => 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<IGetUserLeaveStatusResult> => res.json());
return res;
}
}
4 changes: 3 additions & 1 deletion src/constants/dingTalk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export enum AttendanceState {
'J' = 7,
'L' = 8,
'A' = 9,
'Anomalous' = 10,
}

export enum AttendanceCheckType {
Expand All @@ -36,9 +37,10 @@ export enum AttendanceCheckType {
}

export enum TimeResultType {
'Normal' = 'Normal', //正常
'Normal' = 'Normal', //正常打卡
'Late' = 'Late', // 迟到
'Early' = 'Early', // 早退
'NotSigned' = 'NotSigned', // 没有打卡
}

export enum GroupId {
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/dingTalk/attendance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
24 changes: 24 additions & 0 deletions src/interfaces/dingTalk/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,27 @@ interface Datalist {

export type IGetReportSimplelistResult =
IDingTalkBaseResult<IGetReportSimplelistResultData>;

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<IGetUserLeaveStatusResultData>;
19 changes: 18 additions & 1 deletion src/services/attendance.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 2f65f63

Please sign in to comment.