guoziyun hace 9 meses
padre
commit
4e34eefebf
Se han modificado 2 ficheros con 39 adiciones y 31 borrados
  1. 17 15
      oms/dist/services/cron-jobs/done-rate.js
  2. 22 16
      oms/services/cron-jobs/done-rate.ts

+ 17 - 15
oms/dist/services/cron-jobs/done-rate.js

@@ -129,21 +129,23 @@ async function run() {
                     const newTotalDoneCount = (currentArt.totalDoneCount || 0) + doneRateDoc.doneCount;
                     // 重新计算总完成率
                     const newCompletionRate = newTotalStartCount > 0 ? (newTotalDoneCount / newTotalStartCount) * 100 : 0;
-                    // **【新增】** 更新本地 Art 文档
-                    // 不更新本地art了
-                    // await artService.updateArt(artworkId.toString(), {
-                    //   totalStartCount: newTotalStartCount,
-                    //   totalDoneCount: newTotalDoneCount,
-                    //   completionRate: newCompletionRate,
-                    // });
-                    // updatedLocalArtworksCount++;
-                    // **【新增】** 同步更新远程 Art 文档
-                    const remoteArtDoc = await RemoteArt.findById(artworkId);
-                    if (remoteArtDoc) {
-                        remoteArtDoc.totalStartCount = newTotalStartCount;
-                        remoteArtDoc.totalDoneCount = newTotalDoneCount;
-                        remoteArtDoc.completionRate = newCompletionRate;
-                        await remoteArtDoc.save();
+                    // 更新本地 Art 文档
+                    await artService_1.default.updateArt(artworkId.toString(), {
+                        totalStartCount: newTotalStartCount,
+                        totalDoneCount: newTotalDoneCount,
+                        completionRate: newCompletionRate,
+                    });
+                    updatedLocalArtworksCount++;
+                    // 同步更新远程 Art 文档
+                    const remoteUpdateResult = await RemoteArt.findByIdAndUpdate(artworkId, {
+                        $set: {
+                            totalStartCount: newTotalStartCount,
+                            totalDoneCount: newTotalDoneCount,
+                            completionRate: newCompletionRate,
+                        },
+                    }, { new: true } // 返回更新后的文档
+                    );
+                    if (remoteUpdateResult) {
                         updatedRemoteArtworksCount++;
                     }
                     else {

+ 22 - 16
oms/services/cron-jobs/done-rate.ts

@@ -162,22 +162,28 @@ async function run(): Promise<string> {
           // 重新计算总完成率
           const newCompletionRate = newTotalStartCount > 0 ? (newTotalDoneCount / newTotalStartCount) * 100 : 0;
 
-          // **【新增】** 更新本地 Art 文档
-          // 不更新本地art了
-          // await artService.updateArt(artworkId.toString(), {
-          //   totalStartCount: newTotalStartCount,
-          //   totalDoneCount: newTotalDoneCount,
-          //   completionRate: newCompletionRate,
-          // });
-          // updatedLocalArtworksCount++;
-
-          // **【新增】** 同步更新远程 Art 文档
-          const remoteArtDoc = await RemoteArt.findById(artworkId);
-          if (remoteArtDoc) {
-            remoteArtDoc.totalStartCount = newTotalStartCount;
-            remoteArtDoc.totalDoneCount = newTotalDoneCount;
-            remoteArtDoc.completionRate = newCompletionRate;
-            await remoteArtDoc.save();
+          // 更新本地 Art 文档
+          await artService.updateArt(artworkId.toString(), {
+            totalStartCount: newTotalStartCount,
+            totalDoneCount: newTotalDoneCount,
+            completionRate: newCompletionRate,
+          });
+          updatedLocalArtworksCount++;
+
+          // 同步更新远程 Art 文档
+          const remoteUpdateResult = await RemoteArt.findByIdAndUpdate(
+            artworkId,
+            {
+              $set: {
+                totalStartCount: newTotalStartCount,
+                totalDoneCount: newTotalDoneCount,
+                completionRate: newCompletionRate,
+              },
+            },
+            { new: true } // 返回更新后的文档
+          );
+
+          if (remoteUpdateResult) {
             updatedRemoteArtworksCount++;
           } else {
             console.warn(`[DoneRate Cron] Remote Art document with ID ${artworkId} not found. Skipping remote update.`);