fix permissions and teacher attendance workflows
This commit is contained in:
@@ -64,11 +64,13 @@ export class ScheduleSyncService {
|
||||
* @param dateFrom 起始日期(YYYY-MM-DD),默认今天
|
||||
* @param days 同步天数,默认 30
|
||||
* @param opUserId 钉钉操作人 userId
|
||||
* @param attendanceMachineOnly 是否关闭手机类打卡入口,仅使用考勤机
|
||||
*/
|
||||
async syncAll(
|
||||
dateFrom?: string,
|
||||
days = 30,
|
||||
opUserId = 'manager',
|
||||
attendanceMachineOnly = false,
|
||||
): Promise<ScheduleSyncResult> {
|
||||
const startDate = dateFrom || new Date().toISOString().slice(0, 10);
|
||||
const endDate = this.addDays(startDate, days);
|
||||
@@ -110,20 +112,24 @@ export class ScheduleSyncService {
|
||||
const shiftName = `排课_${startTime}-${endTime}`;
|
||||
try {
|
||||
let shiftId = shiftByName.get(shiftName);
|
||||
if (shiftId === undefined) {
|
||||
shiftId = await this.dingTalkService.upsertShift({
|
||||
name: shiftName,
|
||||
owner: opUserId,
|
||||
sections: [{
|
||||
times: [
|
||||
{ check_type: 'OnDuty', across: 0, check_time: `1970-01-01 ${startTime}:00`, free_check: false },
|
||||
{ check_type: 'OffDuty', across: 0, check_time: `1970-01-01 ${endTime}:00`, free_check: false },
|
||||
],
|
||||
}],
|
||||
setting: { is_flexible: false, serious_late_minutes: -1, absenteeism_late_minutes: -1 },
|
||||
});
|
||||
shiftByName.set(shiftName, shiftId);
|
||||
}
|
||||
const shiftParams = {
|
||||
...(shiftId === undefined ? {} : { id: shiftId }),
|
||||
name: shiftName,
|
||||
owner: opUserId,
|
||||
sections: [{
|
||||
times: [
|
||||
{ check_type: 'OnDuty' as const, across: 0, check_time: `1970-01-01 ${startTime}:00`, free_check: false },
|
||||
{ check_type: 'OffDuty' as const, across: 0, check_time: `1970-01-01 ${endTime}:00`, free_check: false },
|
||||
],
|
||||
}],
|
||||
setting: {
|
||||
is_flexible: false,
|
||||
serious_late_minutes: -1,
|
||||
absenteeism_late_minutes: this.minutesBetween(startTime, endTime),
|
||||
},
|
||||
};
|
||||
shiftId = await this.dingTalkService.upsertShift(shiftParams);
|
||||
shiftByName.set(shiftName, shiftId);
|
||||
timeToShiftId.set(key, shiftId);
|
||||
shiftCount++;
|
||||
} catch (e) {
|
||||
@@ -176,19 +182,25 @@ export class ScheduleSyncService {
|
||||
let attendanceGroupId: number;
|
||||
try {
|
||||
const cached = groupByName.get(groupName);
|
||||
const groupParams = {
|
||||
name: groupName,
|
||||
type: 'TURN' as const,
|
||||
owner: opUserId,
|
||||
members: dingUserIds.map((uid) => ({ role: 'Attendance', type: 'StaffMember' as const, user_id: uid })),
|
||||
shift_ids: [...classShiftIds],
|
||||
enable_emp_select_class: true,
|
||||
disable_check_without_schedule: false,
|
||||
disable_check_when_rest: true,
|
||||
attendance_machine_only: attendanceMachineOnly,
|
||||
};
|
||||
if (cached !== undefined) {
|
||||
attendanceGroupId = cached;
|
||||
} else {
|
||||
attendanceGroupId = await this.dingTalkService.createAttendanceGroup({
|
||||
name: groupName,
|
||||
type: 'TURN',
|
||||
owner: opUserId,
|
||||
members: dingUserIds.map((uid) => ({ role: 'Attendance', type: 'StaffMember', user_id: uid })),
|
||||
shift_ids: [...classShiftIds],
|
||||
enable_emp_select_class: true,
|
||||
disable_check_without_schedule: false,
|
||||
disable_check_when_rest: true,
|
||||
await this.dingTalkService.updateAttendanceGroup({
|
||||
...groupParams,
|
||||
id: attendanceGroupId,
|
||||
});
|
||||
} else {
|
||||
attendanceGroupId = await this.dingTalkService.createAttendanceGroup(groupParams);
|
||||
groupByName.set(groupName, attendanceGroupId);
|
||||
}
|
||||
groupCount++;
|
||||
@@ -317,6 +329,15 @@ export class ScheduleSyncService {
|
||||
return items;
|
||||
}
|
||||
|
||||
private minutesBetween(startTime: string, endTime: string): number {
|
||||
const [startHour, startMinute] = startTime.split(':').map(Number);
|
||||
const [endHour, endMinute] = endTime.split(':').map(Number);
|
||||
const start = startHour * 60 + startMinute;
|
||||
let end = endHour * 60 + endMinute;
|
||||
if (end <= start) end += 24 * 60;
|
||||
return end - start;
|
||||
}
|
||||
|
||||
private addDays(dateStr: string, days: number): string {
|
||||
const d = new Date(dateStr);
|
||||
d.setDate(d.getDate() + days);
|
||||
|
||||
Reference in New Issue
Block a user