|
|
@ -57,30 +57,37 @@ class MaintenanceTimeslot extends BeanModel {
|
|
|
|
|
|
|
|
|
|
|
|
return await this.handleRecurringType(maintenance, minDate, (startDateTime) => {
|
|
|
|
return await this.handleRecurringType(maintenance, minDate, (startDateTime) => {
|
|
|
|
return startDateTime.add(maintenance.interval_day, "day");
|
|
|
|
return startDateTime.add(maintenance.interval_day, "day");
|
|
|
|
|
|
|
|
}, () => {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
} else if (maintenance.strategy === "recurring-weekday") {
|
|
|
|
} else if (maintenance.strategy === "recurring-weekday") {
|
|
|
|
let dayOfWeekList = maintenance.getDayOfWeekList();
|
|
|
|
let dayOfWeekList = maintenance.getDayOfWeekList();
|
|
|
|
|
|
|
|
log.debug("timeslot", dayOfWeekList);
|
|
|
|
|
|
|
|
|
|
|
|
if (dayOfWeekList.length <= 0) {
|
|
|
|
if (dayOfWeekList.length <= 0) {
|
|
|
|
log.debug("timeslot", "No weekdays selected?");
|
|
|
|
log.debug("timeslot", "No weekdays selected?");
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return await this.handleRecurringType(maintenance, minDate, (startDateTime) => {
|
|
|
|
const isValid = (startDateTime) => {
|
|
|
|
while (true) {
|
|
|
|
|
|
|
|
startDateTime = startDateTime.add(1, "day");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.debug("timeslot", "nextDateTime: " + startDateTime);
|
|
|
|
log.debug("timeslot", "nextDateTime: " + startDateTime);
|
|
|
|
|
|
|
|
|
|
|
|
let day = startDateTime.local().day();
|
|
|
|
let day = startDateTime.local().day();
|
|
|
|
log.debug("timeslot", "nextDateTime.day(): " + day);
|
|
|
|
log.debug("timeslot", "nextDateTime.day(): " + day);
|
|
|
|
|
|
|
|
|
|
|
|
if (dayOfWeekList.includes(day)) {
|
|
|
|
return dayOfWeekList.includes(day);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return await this.handleRecurringType(maintenance, minDate, (startDateTime) => {
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
|
|
|
|
startDateTime = startDateTime.add(1, "day");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isValid(startDateTime)) {
|
|
|
|
return startDateTime;
|
|
|
|
return startDateTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, isValid);
|
|
|
|
|
|
|
|
|
|
|
|
} else if (maintenance.strategy === "recurring-day-of-month") {
|
|
|
|
} else if (maintenance.strategy === "recurring-day-of-month") {
|
|
|
|
let dayOfMonthList = maintenance.getDayOfMonthList();
|
|
|
|
let dayOfMonthList = maintenance.getDayOfMonthList();
|
|
|
@ -89,11 +96,7 @@ class MaintenanceTimeslot extends BeanModel {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return await this.handleRecurringType(maintenance, minDate, (startDateTime) => {
|
|
|
|
const isValid = (startDateTime) => {
|
|
|
|
while (true) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
startDateTime = startDateTime.add(1, "day");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let day = parseInt(startDateTime.local().format("D"));
|
|
|
|
let day = parseInt(startDateTime.local().format("D"));
|
|
|
|
|
|
|
|
|
|
|
|
log.debug("timeslot", "day: " + day);
|
|
|
|
log.debug("timeslot", "day: " + day);
|
|
|
@ -113,12 +116,18 @@ class MaintenanceTimeslot extends BeanModel {
|
|
|
|
lastDayList.push(daysInMonth - i + 1);
|
|
|
|
lastDayList.push(daysInMonth - i + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.debug("timeslot", "lastDayList: " + lastDayList);
|
|
|
|
log.debug("timeslot", lastDayList);
|
|
|
|
if (lastDayList.includes(day)) {
|
|
|
|
return lastDayList.includes(day);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return await this.handleRecurringType(maintenance, minDate, (startDateTime) => {
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
|
|
|
|
startDateTime = startDateTime.add(1, "day");
|
|
|
|
|
|
|
|
if (isValid(startDateTime)) {
|
|
|
|
return startDateTime;
|
|
|
|
return startDateTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, isValid);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
throw new Error("Unknown maintenance strategy");
|
|
|
|
throw new Error("Unknown maintenance strategy");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -128,10 +137,11 @@ class MaintenanceTimeslot extends BeanModel {
|
|
|
|
* Generate a next timeslot for all recurring types
|
|
|
|
* Generate a next timeslot for all recurring types
|
|
|
|
* @param maintenance
|
|
|
|
* @param maintenance
|
|
|
|
* @param minDate
|
|
|
|
* @param minDate
|
|
|
|
* @param nextDayCallback The logic how to get the next possible day
|
|
|
|
* @param {function} nextDayCallback The logic how to get the next possible day
|
|
|
|
|
|
|
|
* @param {function} isValidCallback Check the day whether is matched the current strategy
|
|
|
|
* @returns {Promise<null|MaintenanceTimeslot>}
|
|
|
|
* @returns {Promise<null|MaintenanceTimeslot>}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
static async handleRecurringType(maintenance, minDate, nextDayCallback) {
|
|
|
|
static async handleRecurringType(maintenance, minDate, nextDayCallback, isValidCallback) {
|
|
|
|
let bean = R.dispense("maintenance_timeslot");
|
|
|
|
let bean = R.dispense("maintenance_timeslot");
|
|
|
|
|
|
|
|
|
|
|
|
let duration = maintenance.getDuration();
|
|
|
|
let duration = maintenance.getDuration();
|
|
|
@ -157,13 +167,14 @@ class MaintenanceTimeslot extends BeanModel {
|
|
|
|
|
|
|
|
|
|
|
|
// If minDate is set, the endDateTime must be bigger than it.
|
|
|
|
// If minDate is set, the endDateTime must be bigger than it.
|
|
|
|
// And the endDateTime must be bigger current time
|
|
|
|
// And the endDateTime must be bigger current time
|
|
|
|
|
|
|
|
// Is valid under current recurring strategy
|
|
|
|
if (
|
|
|
|
if (
|
|
|
|
(!minDate || endDateTime.diff(minDate) > 0) &&
|
|
|
|
(!minDate || endDateTime.diff(minDate) > 0) &&
|
|
|
|
endDateTime.diff(dayjs()) > 0
|
|
|
|
endDateTime.diff(dayjs()) > 0 &&
|
|
|
|
|
|
|
|
isValidCallback(startDateTime)
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
startDateTime = nextDayCallback(startDateTime);
|
|
|
|
startDateTime = nextDayCallback(startDateTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|