|
1 | 1 | import type { QueueItem } from '../base/base' |
2 | 2 | import { NotificationEmojiCommand, NotificationModule } from 'commonModule/type/preload/notification' |
3 | | -import { getEmojiPackageContentsByPackageIdsApi } from 'mainModule/api/emoji' |
| 3 | +import { getEmojiPackageContentsByRelationIdsApi } from 'mainModule/api/emoji' |
4 | 4 | import dBServiceEmojiPackageEmoji from 'mainModule/database/services/emoji/package-emoji' |
5 | 5 | import { sendMainNotification } from 'mainModule/ipc/main-to-render' |
6 | 6 | import { BaseBusiness } from '../base/base' |
@@ -46,55 +46,41 @@ class EmojiPackageEmojiBusiness extends BaseBusiness<PackageEmojiSyncItem> { |
46 | 46 | protected async processBatchRequests(items: PackageEmojiSyncItem[]): Promise<void> { |
47 | 47 | // 聚合所有需要同步的relationIds |
48 | 48 | const relationIds = [...new Set(items.flatMap(item => item.relationIds))] |
| 49 | + console.log('package-emoji 开始数据同步', items) |
49 | 50 |
|
50 | 51 | if (relationIds.length === 0) { |
51 | 52 | return |
52 | 53 | } |
53 | 54 |
|
54 | 55 | try { |
55 | | - // 首先尝试从本地数据库获取这些relationId对应的packageId |
56 | | - const existingRelations = await dBServiceEmojiPackageEmoji.getEmojisByRelationIds({ relationIds }) |
| 56 | + // 直接用relationIds获取表情包内容详情 |
| 57 | + const response = await getEmojiPackageContentsByRelationIdsApi({ |
| 58 | + relationIds: relationIds, |
| 59 | + }) |
57 | 60 |
|
58 | | - // 提取packageIds |
59 | | - const packageIds = [...new Set(existingRelations.map(relation => relation.packageId))] |
| 61 | + if (response.result?.contents && response.result.contents.length > 0) { |
| 62 | + // 更新本地数据库 |
| 63 | + const contentRows = response.result.contents.map((contentData: any) => ({ |
| 64 | + relationId: contentData.relationId, |
| 65 | + packageId: contentData.packageId, |
| 66 | + emojiId: contentData.emojiId, |
| 67 | + sortOrder: contentData.sortOrder, |
| 68 | + version: contentData.version, |
| 69 | + createdAt: contentData.createdAt, |
| 70 | + updatedAt: contentData.updatedAt, |
| 71 | + })) |
60 | 72 |
|
61 | | - if (packageIds.length > 0) { |
62 | | - // 根据packageIds获取表情包内容详情 |
63 | | - const response = await getEmojiPackageContentsByPackageIdsApi({ |
64 | | - packageIds: packageIds, |
65 | | - }) |
66 | | - |
67 | | - if (response.result?.contents && response.result.contents.length > 0) { |
68 | | - // 过滤出需要的表情关联数据 |
69 | | - const contents = response.result.contents.filter(content => |
70 | | - relationIds.includes(content.relationId) |
71 | | - ) |
72 | | - |
73 | | - if (contents.length > 0) { |
74 | | - // 更新本地数据库 |
75 | | - const contentRows = contents.map((contentData: any) => ({ |
76 | | - relationId: contentData.relationId, |
77 | | - packageId: contentData.packageId, |
78 | | - emojiId: contentData.emojiId, |
79 | | - sortOrder: contentData.sortOrder, |
80 | | - version: contentData.version, |
81 | | - createdAt: contentData.createdAt, |
82 | | - updatedAt: contentData.updatedAt, |
83 | | - })) |
| 73 | + await dBServiceEmojiPackageEmoji.batchCreate({ relations: contentRows }) |
84 | 74 |
|
85 | | - await dBServiceEmojiPackageEmoji.batchCreate({ relations: contentRows }) |
86 | | - |
87 | | - // 发送通知到render进程,告知表情包内容数据已同步 |
88 | | - sendMainNotification('*', NotificationModule.EMOJI, NotificationEmojiCommand.EMOJI_PACKAGE_CONTENT_UPDATE, { |
89 | | - updatedPackageContents: contentRows.map((content: any) => ({ |
90 | | - relationId: content.relationId, |
91 | | - packageId: content.packageId, |
92 | | - emojiId: content.emojiId, |
93 | | - version: content.version, |
94 | | - })), |
95 | | - }) |
96 | | - } |
97 | | - } |
| 75 | + // 发送通知到render进程,告知表情包内容数据已同步 |
| 76 | + sendMainNotification('*', NotificationModule.EMOJI, NotificationEmojiCommand.EMOJI_PACKAGE_CONTENT_UPDATE, { |
| 77 | + updatedPackageContents: contentRows.map((content: any) => ({ |
| 78 | + relationId: content.relationId, |
| 79 | + packageId: content.packageId, |
| 80 | + emojiId: content.emojiId, |
| 81 | + version: content.version, |
| 82 | + })), |
| 83 | + }) |
98 | 84 | } |
99 | 85 | } catch (error) { |
100 | 86 | console.error('批量同步表情包表情关联失败:', error) |
|
0 commit comments