@ray-js/lamp-schedule-core 1.0.4-beta-2 → 1.0.4-beta-3
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.
- package/lib/conflict/index.d.ts +1 -1
- package/lib/conflict/index.js +8 -1
- package/lib/conflict/scheduleDataManager.d.ts +2 -0
- package/lib/conflict/scheduleDataManager.js +21 -0
- package/lib/conflict/transform.js +11 -7
- package/lib/utils/ScheduleCloudProperty.js +0 -14
- package/lib/utils/dpState.js +1 -1
- package/package.json +1 -1
package/lib/conflict/index.d.ts
CHANGED
package/lib/conflict/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import "core-js/modules/es.json.stringify.js";
|
|
2
3
|
import "core-js/modules/esnext.iterator.constructor.js";
|
|
3
4
|
import "core-js/modules/esnext.iterator.find.js";
|
|
4
5
|
import { scheduleLogger } from '../utils/ScheduleLogger';
|
|
@@ -112,12 +113,18 @@ export class Conflict {
|
|
|
112
113
|
* @param scheduleList - 需要冲突判断的计划数据
|
|
113
114
|
*/
|
|
114
115
|
static init(scheduleList) {
|
|
116
|
+
let forceInit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
115
117
|
if (!Array.isArray(scheduleList)) {
|
|
116
118
|
return;
|
|
117
119
|
}
|
|
118
120
|
const instance = ScheduleDataManager.getInstance();
|
|
119
121
|
const _scheduleList = transScheduleListToConflictList(scheduleList);
|
|
120
122
|
scheduleLogger.debug('Conflict.init scheduleList, _scheduleList:', scheduleList, _scheduleList);
|
|
121
|
-
|
|
123
|
+
if (forceInit) {
|
|
124
|
+
instance.setDataWithClear(_scheduleList);
|
|
125
|
+
} else {
|
|
126
|
+
instance.setData(_scheduleList);
|
|
127
|
+
}
|
|
128
|
+
scheduleLogger.debug('Conflict.init instance.getData()', JSON.stringify(instance.getData()));
|
|
122
129
|
}
|
|
123
130
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { Schedule } from './type';
|
|
2
2
|
export declare class ScheduleDataManager {
|
|
3
|
+
private constructor();
|
|
3
4
|
static instance: ScheduleDataManager;
|
|
4
5
|
static list: Record<string, any>[];
|
|
5
6
|
static getInstance(): ScheduleDataManager;
|
|
6
7
|
getData(): Record<string, any>[];
|
|
8
|
+
setDataWithClear(value: Record<string, any>[] | Record<string, any>): void;
|
|
7
9
|
setData(value: Record<string, any>[] | Record<string, any>): void;
|
|
8
10
|
clearData(): void;
|
|
9
11
|
deleteData(current: Schedule): void;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import "core-js/modules/esnext.iterator.constructor.js";
|
|
2
2
|
import "core-js/modules/esnext.iterator.filter.js";
|
|
3
3
|
import "core-js/modules/esnext.iterator.for-each.js";
|
|
4
|
+
import { scheduleLogger } from '../utils/ScheduleLogger';
|
|
4
5
|
// 统一管理 计划 数据列表,用来判断是否存在冲突
|
|
5
6
|
export class ScheduleDataManager {
|
|
7
|
+
// 私有构造函数,防止外部直接实例化
|
|
8
|
+
// eslint-disable-next-line no-useless-constructor, @typescript-eslint/no-empty-function
|
|
9
|
+
constructor() {}
|
|
6
10
|
static list = [];
|
|
7
11
|
static getInstance() {
|
|
8
12
|
if (!ScheduleDataManager.instance) {
|
|
@@ -11,9 +15,20 @@ export class ScheduleDataManager {
|
|
|
11
15
|
return ScheduleDataManager.instance;
|
|
12
16
|
}
|
|
13
17
|
getData() {
|
|
18
|
+
scheduleLogger.debug('ScheduleDataManager.getData', ScheduleDataManager.list);
|
|
14
19
|
return ScheduleDataManager.list;
|
|
15
20
|
}
|
|
21
|
+
setDataWithClear(value) {
|
|
22
|
+
scheduleLogger.debug('ScheduleDataManager.setDataWithClear pre', value);
|
|
23
|
+
if (!value) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
ScheduleDataManager.list = [];
|
|
27
|
+
this.setData(value);
|
|
28
|
+
scheduleLogger.debug('ScheduleDataManager.setDataWithClear post', ScheduleDataManager.list);
|
|
29
|
+
}
|
|
16
30
|
setData(value) {
|
|
31
|
+
scheduleLogger.debug('ScheduleDataManager.setData pre', value);
|
|
17
32
|
if (!value) {
|
|
18
33
|
return;
|
|
19
34
|
}
|
|
@@ -49,26 +64,32 @@ export class ScheduleDataManager {
|
|
|
49
64
|
const idsToAdd = new Set(itemsMap.keys());
|
|
50
65
|
const filteredList = ScheduleDataManager.list.filter(item => !idsToAdd.has(item.id));
|
|
51
66
|
ScheduleDataManager.list = [...filteredList, ...itemsMap.values()];
|
|
67
|
+
scheduleLogger.debug('ScheduleDataManager.setData post', ScheduleDataManager.list);
|
|
52
68
|
}
|
|
53
69
|
clearData() {
|
|
70
|
+
scheduleLogger.debug('ScheduleDataManager.clearData pre', ScheduleDataManager.list);
|
|
54
71
|
ScheduleDataManager.list = [];
|
|
55
72
|
}
|
|
56
73
|
deleteData(current) {
|
|
57
74
|
if (!current) {
|
|
58
75
|
return;
|
|
59
76
|
}
|
|
77
|
+
scheduleLogger.debug('ScheduleDataManager.deleteData pre', current);
|
|
60
78
|
const index = ScheduleDataManager.list.findIndex(item => item.id === current.id);
|
|
61
79
|
if (index !== -1) {
|
|
62
80
|
ScheduleDataManager.list.splice(index, 1);
|
|
63
81
|
}
|
|
82
|
+
scheduleLogger.debug('ScheduleDataManager.deleteData post', ScheduleDataManager.list);
|
|
64
83
|
}
|
|
65
84
|
|
|
66
85
|
// 添加remove方法作为deleteData的别名,用于测试
|
|
67
86
|
remove(id) {
|
|
68
87
|
const index = ScheduleDataManager.list.findIndex(item => item.id === id);
|
|
88
|
+
scheduleLogger.debug('ScheduleDataManager.remove pre', id, index);
|
|
69
89
|
if (index !== -1) {
|
|
70
90
|
ScheduleDataManager.list.splice(index, 1);
|
|
71
91
|
}
|
|
92
|
+
scheduleLogger.debug('ScheduleDataManager.remove post', ScheduleDataManager.list);
|
|
72
93
|
}
|
|
73
94
|
}
|
|
74
95
|
export default ScheduleDataManager;
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import "core-js/modules/esnext.iterator.constructor.js";
|
|
2
|
+
import "core-js/modules/esnext.iterator.filter.js";
|
|
2
3
|
import "core-js/modules/esnext.iterator.for-each.js";
|
|
3
4
|
import "core-js/modules/esnext.iterator.map.js";
|
|
4
5
|
import dayjs from 'dayjs';
|
|
5
6
|
import { cloneDeep } from 'lodash-es';
|
|
6
7
|
import { objectToId } from '../utils/objectToId';
|
|
7
|
-
import { getBackwardOffsetTimeByHourMins, getPreOffsetTimeByHourMins, getTimerStrByMinutes } from '../utils/time';
|
|
8
|
+
import { getBackwardOffsetTimeByHourMins, getPreOffsetTimeByHourMins, getTimerStrByMinutes, getTimeFormatStrByHourMins } from '../utils/time';
|
|
8
9
|
import { EScheduleFunctionType } from '../types';
|
|
9
10
|
import { scheduleLogger } from '../utils/ScheduleLogger';
|
|
10
|
-
const numAddZero = num => {
|
|
11
|
-
return +num < 10 ? `0${+num}` : +num;
|
|
12
|
-
};
|
|
13
11
|
|
|
14
12
|
/**
|
|
15
13
|
* TTimerDataAdd => Schedule
|
|
@@ -91,12 +89,12 @@ export const wakeUpDataToScheduleList = data => {
|
|
|
91
89
|
*/
|
|
92
90
|
export const sleepNodeToSchedule = data => {
|
|
93
91
|
const startTime = getPreOffsetTimeByHourMins(data.hour, data.minute, data.step * 5);
|
|
94
|
-
|
|
92
|
+
const endTime = data.time || getTimeFormatStrByHourMins(data.hour, data.minute);
|
|
95
93
|
const _data = {
|
|
96
94
|
status: data.onOff,
|
|
97
95
|
weeks: data.loops.split('').map(item => Number(item)),
|
|
98
96
|
startTime,
|
|
99
|
-
endTime
|
|
97
|
+
endTime
|
|
100
98
|
};
|
|
101
99
|
return {
|
|
102
100
|
id: objectToId(_data, `${EScheduleFunctionType.SLEEP}_`),
|
|
@@ -259,5 +257,11 @@ export const transScheduleListToConflictList = foldScheduleList => {
|
|
|
259
257
|
} catch (error) {
|
|
260
258
|
scheduleLogger.error('transScheduleListToConflictList', error);
|
|
261
259
|
}
|
|
262
|
-
return arr
|
|
260
|
+
return arr.filter(item => {
|
|
261
|
+
var _item$data, _item$data2;
|
|
262
|
+
if ((item === null || item === void 0 || (_item$data = item.data) === null || _item$data === void 0 ? void 0 : _item$data.status) === undefined) {
|
|
263
|
+
scheduleLogger.error('transScheduleListToConflictList', item, 'status 为 undefined');
|
|
264
|
+
}
|
|
265
|
+
return (item === null || item === void 0 || (_item$data2 = item.data) === null || _item$data2 === void 0 ? void 0 : _item$data2.status) === true;
|
|
266
|
+
});
|
|
263
267
|
};
|
|
@@ -87,20 +87,6 @@ export const getAll = () => {
|
|
|
87
87
|
groupId
|
|
88
88
|
} = devIdOrGroupIdCache.get();
|
|
89
89
|
return new Promise((resolve, reject) => {
|
|
90
|
-
// 对外使用
|
|
91
|
-
// getGroupProperty({
|
|
92
|
-
// groupId,
|
|
93
|
-
// success(res) {
|
|
94
|
-
// console.warn('getGroupProperty res:', res);
|
|
95
|
-
// resolve({
|
|
96
|
-
// properties: res?.result || res || {},
|
|
97
|
-
// });
|
|
98
|
-
// },
|
|
99
|
-
// fail(err) {
|
|
100
|
-
// console.warn('getGroupProperty err:', err);
|
|
101
|
-
// reject(err);
|
|
102
|
-
// },
|
|
103
|
-
// });
|
|
104
90
|
if (!groupId) {
|
|
105
91
|
getDeviceProperty({
|
|
106
92
|
deviceId: devId,
|
package/lib/utils/dpState.js
CHANGED
|
@@ -22,6 +22,6 @@ export const getAllDpState = () => {
|
|
|
22
22
|
};
|
|
23
23
|
export const initDpState = function () {
|
|
24
24
|
let dpState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
25
|
-
Object.assign(
|
|
25
|
+
Object.assign(__dpState, dpState);
|
|
26
26
|
scheduleLogger.debug('initDpState', __dpState);
|
|
27
27
|
};
|