• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * @file Describe the file
3 * Copyright (c) 2023 Huawei Device Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import HashSet from '@ohos.util.HashSet';
18
19import AlertsUpdateJudger from '../AlertsUpdateJudger';
20
21import { CalendarsColumns } from '@ohos/datastructure/src/main/ets/calendars/CalendarsColumns';
22import { EventColumns } from '@ohos/datastructure/src/main/ets/events/EventColumns';
23import { InstancesColumns } from '@ohos/datastructure/src/main/ets/instances/InstancesColumns';
24import { RemindersColumns } from '@ohos/datastructure/src/main/ets/reminders/RemindersColumns';
25import relationalStore from '@ohos.data.relationalStore';
26
27/**
28 * 在数据表 插入或更新 场景下判断是否需要刷新 alerts
29 *
30 * @since 2022-09-09
31 */
32export default class InsertOrUpdateAlertsUpdateJudgerImpl implements AlertsUpdateJudger {
33  // 新增或者修改数据的场景下,是否改变了这四张表的相关字段
34  tableNameMap = new Map<string, string[]>();
35
36  constructor() {
37    this.tableNameMap.set(CalendarsColumns.TABLE_NAME, ['', ''])
38    this.tableNameMap.set(EventColumns.TABLE_NAME, ['', '']);
39    this.tableNameMap.set(InstancesColumns.TABLE_NAME, ['', '']);
40    this.tableNameMap.set(RemindersColumns.TABLE_NAME, ['', '']);
41  }
42
43  isNeedToUpdateAlerts(tableName: string, values: relationalStore.ValuesBucket) {
44    if (this.tableNameMap.has(tableName)) {
45      let rowArray: string[] | undefined = this.tableNameMap.get(tableName);
46      let keys: string[] = Object.keys(values);
47      let hashSet = new HashSet<string>();
48      if (rowArray === null || rowArray === undefined) {
49        return false;
50      }
51      if (keys === null || keys === undefined) {
52        return false;
53      }
54
55      // 判断对应表中有无相关字段增加
56      rowArray.forEach((str) => {
57        hashSet.add(str);
58      })
59      keys.forEach((str) => {
60        hashSet.add(str);
61      })
62      if (rowArray.length + keys.length > hashSet.length) {
63        return true;
64      }
65    }
66    return false;
67  }
68}
69