Browse Source

✨ feat: 乐跑记录返回进度

Pchen. 1 month ago
parent
commit
a99ab975c7

+ 1 - 1
apis/Lepao/Record/Admin/GetLepaoRecords.js

@@ -147,7 +147,7 @@ class AdminGetLepaoRecords extends API {
 
         res.json({
             ...BaseStdResponse.OK,
-            data: rows.map(enrichLepaoRecordRow),
+            data: await Promise.all(rows.map(enrichLepaoRecordRow)),
             pagination: {
                 current,
                 pagesize,

+ 1 - 1
apis/Lepao/Record/GetLepaoRecords.js

@@ -127,7 +127,7 @@ class GetLepaoRecords extends API {
 
         res.json({
             ...BaseStdResponse.OK,
-            data: rows.map(enrichLepaoRecordRow),
+            data: await Promise.all(rows.map(enrichLepaoRecordRow)),
             pagination: {
                 current,
                 pagesize,

+ 2 - 1
lib/Lepao/Worker.js

@@ -282,7 +282,7 @@ class Worker {
     initHandlers() {
         this.register('lepao.startRun', async (req, ctx) => {
             const traceId = ctx.traceId
-            const maxPathRetry = 20
+            const maxPathRetry = 5
             let pathRetry = 0
             let userData = null
             let recordDbId = null
@@ -386,6 +386,7 @@ class Worker {
                         }
                         jkesEnd = await runJkesRecord({
                             token: req.token,
+                            recordDbId,
                             pathPoints: rawData,
                             distanceM,
                             paceSecPerKm: pace,

+ 4 - 4
plugin/jkes/formatRecordRow.js

@@ -10,10 +10,10 @@ async function getLepaoSchedule(recordId) {
  * 将 lepao_record.result(JKES end 接口 info)解析为列表/详情用的摘要字段
  */
 async function enrichLepaoRecordRow(row) {
-    const out = { ...row }
-    if (row.result && row.result.id && row.state === 0) {
-        const schedule = await getLepaoSchedule(row.result.id)
-        out.schedule = schedule
+    let out = { ...row }
+    if (row.id && row.state === 0) {
+        const schedule = await getLepaoSchedule(row.id)
+        out['lepao_schedule'] = schedule
     }
     let jkes = null
     try {

+ 3 - 1
plugin/jkes/runRecord.js

@@ -286,6 +286,7 @@ async function runJkesRecord(opts) {
     const s = getJkesSettings()
     const {
         token,
+        recordDbId,
         pathPoints: rawPoints,
         distanceM,
         paceSecPerKm,
@@ -400,7 +401,7 @@ async function runJkesRecord(opts) {
 
         await flushCalcThroughDeviceTime(tEnd)
 
-        await Redis.set(jkesRedisKeys.lepaoSchedule(recordId), JSON.stringify({current: c, total: chunks.length}), { EX: 60 * 60 * 3 })
+        await Redis.set(jkesRedisKeys.lepaoSchedule(recordDbId), JSON.stringify({current: c, total: chunks.length}), { EX: 60 * 60 * 3 })
 
         const intraMs = Math.max(0, tEnd - tStart)
         if (intraMs > 0) {
@@ -413,6 +414,7 @@ async function runJkesRecord(opts) {
     await postJson(`/health/runRecord/pause/${recordId}`, {})
     const endJson = await postJson(`/health/runRecord/end/${recordId}`, {})
     log(`ID:${recordId} 跑步已结束`)
+    await Redis.del(jkesRedisKeys.lepaoSchedule(recordId))
     return { recordId, endJson, runStartMs, uploadedPayloadPoints }
 }