• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef CLONE_RESTORE_ANALYSIS_TOTAL_H
17 #define CLONE_RESTORE_ANALYSIS_TOTAL_H
18 
19 #include <string>
20 
21 #include "backup_const.h"
22 #include "media_backup_report_data_type.h"
23 #include "rdb_store.h"
24 
25 namespace OHOS::Media {
26 class CloneRestoreAnalysisTotal {
27 public:
28     void Init(const std::string &type, int32_t pageSize, std::shared_ptr<NativeRdb::RdbStore> mediaRdb,
29         std::shared_ptr<NativeRdb::RdbStore> mediaLibraryRdb);
30     int32_t GetTotalNumber();
31     void GetInfos(const std::unordered_map<int32_t, PhotoInfo> &photoInfoMap);
32     void SetPlaceHoldersAndParamsByFileIdOld(std::string &placeHolders, std::vector<NativeRdb::ValueObject> &params);
33     void SetPlaceHoldersAndParamsByFileIdNew(std::string &placeHolders, std::vector<NativeRdb::ValueObject> &params);
34     size_t FindIndexByFileIdOld(int32_t fileIdOld);
35     int32_t GetFileIdNewByIndex(size_t index);
36     void UpdateRestoreStatusAsDuplicateByIndex(size_t index);
37     void UpdateRestoreStatusAsFailed();
38     void UpdateDatabase();
39     void SetRestoreTaskInfo(RestoreTaskInfo &info);
40 
41 private:
42     enum AnalysisStatus : int32_t {
43         UNANALYZED = 0
44     };
45     enum RestoreStatus : int32_t {
46         SUCCESS = 0,
47         DUPLICATE,
48         FAILED
49     };
50     struct AnalysisTotalInfo {
51         int32_t fileIdOld {-1};
52         int32_t fileIdNew {-1};
53         int32_t status {AnalysisStatus::UNANALYZED};
54         int32_t restoreStatus {RestoreStatus::SUCCESS};
55     };
56 
57     std::unordered_map<int32_t, std::vector<std::string>> GetStatusFileIdsMap();
58     int32_t UpdateDatabaseByStatus(int32_t status, const std::vector<std::string> &fileIds);
59 
60 private:
61     int32_t lastId_ {0};
62     int32_t pageSize_ {0};
63     int32_t totalCnt_{0};
64     int32_t successCnt_{0};
65     int32_t failedCnt_{0};
66     int32_t duplicateCnt_{0};
67     std::string type_;
68     std::shared_ptr<NativeRdb::RdbStore> mediaRdb_;
69     std::shared_ptr<NativeRdb::RdbStore> mediaLibraryRdb_;
70     std::vector<AnalysisTotalInfo> analysisTotalInfos_;
71 };
72 } // namespace OHOS::Media
73 #endif // CLONE_RESTORE_ANALYSIS_TOTAL_H