Browse Source

✨ feat: 跑步记录增加进度展示

Pchen. 1 month ago
parent
commit
77c07283b2
3 changed files with 23 additions and 1 deletions
  1. 13 1
      plugin/jkes/formatRecordRow.js
  2. 6 0
      plugin/jkes/redisKeys.js
  3. 4 0
      plugin/jkes/runRecord.js

+ 13 - 1
plugin/jkes/formatRecordRow.js

@@ -1,8 +1,20 @@
+const Redis = require('../DataBase/Redis.js')
+const jkesRedisKeys = require('./redisKeys.js')
+
+async function getLepaoSchedule(recordId) {
+    const schedule = await Redis.get(jkesRedisKeys.lepaoSchedule(recordId))
+    return schedule ? JSON.parse(schedule) : null
+}
+
 /**
  * 将 lepao_record.result(JKES end 接口 info)解析为列表/详情用的摘要字段
  */
-function enrichLepaoRecordRow(row) {
+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 jkes = null
     try {
         const r =

+ 6 - 0
plugin/jkes/redisKeys.js

@@ -15,6 +15,11 @@ function lepaoProgress(studentNum) {
     return `jkes_lepaoProgress:${studentNum}`
 }
 
+function lepaoSchedule(recordId) {
+    return `jkes_lepaoSchedule:${recordId}`
+}
+
+
 /** @param {number} month1to12 */
 function monthState(studentNum, year, month1to12) {
     const m = String(month1to12).padStart(2, '0')
@@ -33,6 +38,7 @@ module.exports = {
     runnerFlag,
     lepaoSuccess,
     lepaoProgress,
+    lepaoSchedule,
     monthState,
     consume,
     refund

+ 4 - 0
plugin/jkes/runRecord.js

@@ -5,6 +5,8 @@
  */
 const axios = require('axios')
 const https = require('https')
+const Redis = require('../DataBase/Redis.js')
+const jkesRedisKeys = require('./redisKeys.js')
 
 const { getJkesSettings, normalizeApiBase } = require('./jkesSettings')
 const {
@@ -398,6 +400,8 @@ async function runJkesRecord(opts) {
 
         await flushCalcThroughDeviceTime(tEnd)
 
+        await Redis.set(jkesRedisKeys.lepaoSchedule(recordId), JSON.stringify({current: c, total: chunks.length}), { EX: 60 * 60 * 3 })
+
         const intraMs = Math.max(0, tEnd - tStart)
         if (intraMs > 0) {
             await sleep(intraMs)