@ray-js/lamp-schedule-core 1.0.0-beta-4 → 1.0.0-beta-5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -128,11 +128,12 @@ function convertToTimeRanges(schedules) {
|
|
|
128
128
|
const isCrossDay = endMinutes < startMinutes;
|
|
129
129
|
|
|
130
130
|
// 如果定时状态为关闭,则设置星期,忽略冲突判断
|
|
131
|
-
const dayOfWeek =
|
|
131
|
+
const dayOfWeek = daysOfWeek[isCrossDay ? (week + 1) % 7 : week];
|
|
132
132
|
return [{
|
|
133
133
|
id: schedule.id,
|
|
134
134
|
type: schedule.type,
|
|
135
135
|
dayOfWeek: dayOfWeek,
|
|
136
|
+
status: schedule.data.status,
|
|
136
137
|
startMinutes,
|
|
137
138
|
endMinutes,
|
|
138
139
|
originalSchedule: schedule,
|
|
@@ -157,17 +158,12 @@ function convertToTimeRanges(schedules) {
|
|
|
157
158
|
const start = parseTimeToMinutes(startTimeStr);
|
|
158
159
|
const end = parseTimeToMinutes(endTimeStr);
|
|
159
160
|
const isCrossDay = end < start;
|
|
160
|
-
|
|
161
|
-
// 如果定时状态为关闭,则设置星期,忽略冲突判断
|
|
162
|
-
if (!schedule.data.status) {
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
161
|
// 添加当前星期的时间范围
|
|
167
162
|
result.push({
|
|
168
163
|
id: schedule.id,
|
|
169
164
|
type: schedule.type,
|
|
170
165
|
dayOfWeek: day,
|
|
166
|
+
status: schedule.data.status,
|
|
171
167
|
startMinutes: start,
|
|
172
168
|
endMinutes: end,
|
|
173
169
|
originalSchedule: schedule,
|
|
@@ -186,6 +182,7 @@ function convertToTimeRanges(schedules) {
|
|
|
186
182
|
id: schedule.id,
|
|
187
183
|
type: schedule.type,
|
|
188
184
|
dayOfWeek: nextDay,
|
|
185
|
+
status: schedule.data.status,
|
|
189
186
|
startMinutes: 0,
|
|
190
187
|
// 从午夜开始
|
|
191
188
|
endMinutes: end,
|
|
@@ -263,11 +260,11 @@ export function checkConflicts(scheduleList, currentSchedule) {
|
|
|
263
260
|
const currentPreId = current === null || current === void 0 || (_current$originalSche = current.originalSchedule) === null || _current$originalSche === void 0 ? void 0 : _current$originalSche.prevId;
|
|
264
261
|
const currentId = current === null || current === void 0 || (_current$originalSche2 = current.originalSchedule) === null || _current$originalSche2 === void 0 ? void 0 : _current$originalSche2.id;
|
|
265
262
|
const otherId = other.id;
|
|
266
|
-
// 如果当前定时自身修改 且 与自身冲突 则忽略
|
|
267
|
-
if (currentPreId && currentId ===
|
|
263
|
+
// 如果当前定时自身修改 且 与自身冲突 并且其他定时不等于当前定时id 则忽略
|
|
264
|
+
if (currentPreId && currentId === currentPreId && otherId !== currentId) {
|
|
268
265
|
return;
|
|
269
266
|
}
|
|
270
|
-
if (current.dayOfWeek && current.dayOfWeek === other.dayOfWeek && rule.isConflict(current, other)) {
|
|
267
|
+
if (current.dayOfWeek && current.status && other.status && current.dayOfWeek === other.dayOfWeek && rule.isConflict(current, other)) {
|
|
271
268
|
conflicts.push({
|
|
272
269
|
current: current.originalSchedule,
|
|
273
270
|
other: other.originalSchedule
|
|
@@ -2,6 +2,7 @@ import "core-js/modules/esnext.iterator.constructor.js";
|
|
|
2
2
|
import "core-js/modules/esnext.iterator.for-each.js";
|
|
3
3
|
import "core-js/modules/esnext.iterator.map.js";
|
|
4
4
|
import dayjs from 'dayjs';
|
|
5
|
+
import { objectToId } from '../utils/objectToId';
|
|
5
6
|
import { getBackwardOffsetTimeByHourMins, getPreOffsetTimeByHourMins, getTimerStrByMinutes } from '../utils/time';
|
|
6
7
|
import { EScheduleFunctionType } from '../types';
|
|
7
8
|
import { scheduleLogger } from '../utils/ScheduleLogger';
|
|
@@ -18,15 +19,16 @@ const numAddZero = num => {
|
|
|
18
19
|
export const timerDataToSchedule = data => {
|
|
19
20
|
var _data$status;
|
|
20
21
|
scheduleLogger.debug('timerDataToSchedule:', data);
|
|
22
|
+
const _data = {
|
|
23
|
+
status: (_data$status = data.status) !== null && _data$status !== void 0 ? _data$status : false,
|
|
24
|
+
weeks: data.loops.split('').map(item => Number(item)),
|
|
25
|
+
startTime: data.time,
|
|
26
|
+
endTime: data.time
|
|
27
|
+
};
|
|
21
28
|
return {
|
|
22
|
-
id: `${EScheduleFunctionType.TIMER}_
|
|
29
|
+
id: objectToId(_data, `${EScheduleFunctionType.TIMER}_`),
|
|
23
30
|
type: EScheduleFunctionType.TIMER,
|
|
24
|
-
data:
|
|
25
|
-
status: (_data$status = data.status) !== null && _data$status !== void 0 ? _data$status : false,
|
|
26
|
-
weeks: data.loops.split('').map(item => Number(item)),
|
|
27
|
-
startTime: data.time,
|
|
28
|
-
endTime: data.time
|
|
29
|
-
}
|
|
31
|
+
data: _data
|
|
30
32
|
};
|
|
31
33
|
};
|
|
32
34
|
|
|
@@ -51,15 +53,16 @@ export const wakeUpNodeToSchedule = data => {
|
|
|
51
53
|
const startTime = getPreOffsetTimeByHourMins(data.hour, data.minute, data.step * 5 || 0);
|
|
52
54
|
const endTime = getBackwardOffsetTimeByHourMins(data.hour, data.minute, data.duration * 5);
|
|
53
55
|
scheduleLogger.debug('wakeUpNodeToSchedule:', data);
|
|
56
|
+
const _data = {
|
|
57
|
+
status: data.onOff,
|
|
58
|
+
weeks: data.loops.split('').map(item => Number(item)),
|
|
59
|
+
startTime,
|
|
60
|
+
endTime
|
|
61
|
+
};
|
|
54
62
|
return {
|
|
55
|
-
id: `${EScheduleFunctionType.WAKEUP}_
|
|
63
|
+
id: objectToId(_data, `${EScheduleFunctionType.WAKEUP}_`),
|
|
56
64
|
type: EScheduleFunctionType.WAKEUP,
|
|
57
|
-
data:
|
|
58
|
-
status: data.onOff,
|
|
59
|
-
weeks: data.loops.split('').map(item => Number(item)),
|
|
60
|
-
startTime,
|
|
61
|
-
endTime
|
|
62
|
-
}
|
|
65
|
+
data: _data
|
|
63
66
|
};
|
|
64
67
|
};
|
|
65
68
|
|
|
@@ -83,15 +86,16 @@ export const wakeUpDataToScheduleList = data => {
|
|
|
83
86
|
export const sleepNodeToSchedule = data => {
|
|
84
87
|
const startTime = getPreOffsetTimeByHourMins(data.hour, data.minute, data.step * 5);
|
|
85
88
|
scheduleLogger.debug('sleepNodeToSchedule:', data);
|
|
89
|
+
const _data = {
|
|
90
|
+
status: data.onOff,
|
|
91
|
+
weeks: data.loops.split('').map(item => Number(item)),
|
|
92
|
+
startTime,
|
|
93
|
+
endTime: data.time
|
|
94
|
+
};
|
|
86
95
|
return {
|
|
87
|
-
id: `${EScheduleFunctionType.SLEEP}_
|
|
96
|
+
id: objectToId(_data, `${EScheduleFunctionType.SLEEP}_`),
|
|
88
97
|
type: EScheduleFunctionType.SLEEP,
|
|
89
|
-
data:
|
|
90
|
-
status: data.onOff,
|
|
91
|
-
weeks: data.loops.split('').map(item => Number(item)),
|
|
92
|
-
startTime,
|
|
93
|
-
endTime: data.time
|
|
94
|
-
}
|
|
98
|
+
data: _data
|
|
95
99
|
};
|
|
96
100
|
};
|
|
97
101
|
|
|
@@ -155,15 +159,16 @@ export const randomNodeToSchedule = data => {
|
|
|
155
159
|
} = data;
|
|
156
160
|
const startTimeStr = getTimerStrByMinutes(startTime);
|
|
157
161
|
const endTimeStr = getTimerStrByMinutes(endTime);
|
|
162
|
+
const _data = {
|
|
163
|
+
status: data.onOff,
|
|
164
|
+
weeks: data.loops.split('').map(item => Number(item)),
|
|
165
|
+
startTime: startTimeStr,
|
|
166
|
+
endTime: endTimeStr
|
|
167
|
+
};
|
|
158
168
|
return {
|
|
159
|
-
id: `${EScheduleFunctionType.RANDOM}_
|
|
169
|
+
id: objectToId(_data, `${EScheduleFunctionType.RANDOM}_`),
|
|
160
170
|
type: EScheduleFunctionType.RANDOM,
|
|
161
|
-
data:
|
|
162
|
-
status: data.onOff,
|
|
163
|
-
weeks: data.loops.split('').map(item => Number(item)),
|
|
164
|
-
startTime: startTimeStr,
|
|
165
|
-
endTime: endTimeStr
|
|
166
|
-
}
|
|
171
|
+
data: _data
|
|
167
172
|
};
|
|
168
173
|
};
|
|
169
174
|
|
|
@@ -191,15 +196,16 @@ export const cycleNodeToSchedule = data => {
|
|
|
191
196
|
} = data;
|
|
192
197
|
const startTimeStr = getTimerStrByMinutes(startTime);
|
|
193
198
|
const endTimeStr = getTimerStrByMinutes(endTime);
|
|
199
|
+
const _data = {
|
|
200
|
+
status: data.onOff,
|
|
201
|
+
weeks: data.loops.split('').map(item => Number(item)),
|
|
202
|
+
startTime: startTimeStr,
|
|
203
|
+
endTime: endTimeStr
|
|
204
|
+
};
|
|
194
205
|
return {
|
|
195
|
-
id: `${EScheduleFunctionType.CYCLE}_
|
|
206
|
+
id: objectToId(_data, `${EScheduleFunctionType.CYCLE}_`),
|
|
196
207
|
type: EScheduleFunctionType.CYCLE,
|
|
197
|
-
data:
|
|
198
|
-
status: data.onOff,
|
|
199
|
-
weeks: data.loops.split('').map(item => Number(item)),
|
|
200
|
-
startTime: startTimeStr,
|
|
201
|
-
endTime: endTimeStr
|
|
202
|
-
}
|
|
208
|
+
data: _data
|
|
203
209
|
};
|
|
204
210
|
};
|
|
205
211
|
|
package/lib/conflict/type.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const objectToId: (obj: any, prefix?: string) => string;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import "core-js/modules/esnext.iterator.constructor.js";
|
|
2
|
+
import "core-js/modules/esnext.iterator.for-each.js";
|
|
3
|
+
import "core-js/modules/esnext.iterator.map.js";
|
|
4
|
+
export const objectToId = function (obj) {
|
|
5
|
+
let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
6
|
+
// 递归排序对象键以确保一致性
|
|
7
|
+
function sortObjectKeys(obj) {
|
|
8
|
+
if (obj === null || typeof obj !== 'object') return obj;
|
|
9
|
+
if (Array.isArray(obj)) {
|
|
10
|
+
return obj.map(sortObjectKeys);
|
|
11
|
+
}
|
|
12
|
+
const sortedKeys = Object.keys(obj).sort();
|
|
13
|
+
const sortedObj = {};
|
|
14
|
+
sortedKeys.forEach(key => {
|
|
15
|
+
sortedObj[key] = sortObjectKeys(obj[key]);
|
|
16
|
+
});
|
|
17
|
+
return sortedObj;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// 转换为字符串
|
|
21
|
+
const sortedObj = sortObjectKeys(obj);
|
|
22
|
+
const str = JSON.stringify(sortedObj);
|
|
23
|
+
|
|
24
|
+
// 简单哈希算法
|
|
25
|
+
let hash = 5381;
|
|
26
|
+
for (let i = 0; i < str.length; i++) {
|
|
27
|
+
hash = (hash << 5) + hash + str.charCodeAt(i);
|
|
28
|
+
hash = hash & hash; // 转换为32位整数
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// 转换为正数并生成字符串
|
|
32
|
+
return prefix + Math.abs(hash).toString(36);
|
|
33
|
+
};
|