|
@@ -19,8 +19,7 @@ class SingleRun extends API {
|
|
|
|
|
|
|
|
if ([uuid, session, student_num].some(value => value === '' || value === null || value === undefined))
|
|
if ([uuid, session, student_num].some(value => value === '' || value === null || value === undefined))
|
|
|
return res.json({
|
|
return res.json({
|
|
|
- ...BaseStdResponse.MISSING_PARAMETER,
|
|
|
|
|
- endpoint: 1513126
|
|
|
|
|
|
|
+ ...BaseStdResponse.MISSING_PARAMETER
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
if (!await AccessControl.checkSession(uuid, session))
|
|
if (!await AccessControl.checkSession(uuid, session))
|
|
@@ -35,59 +34,71 @@ class SingleRun extends API {
|
|
|
msg: '当前不在有效乐跑时间范围内。请在7:00~24:00发起乐跑'
|
|
msg: '当前不在有效乐跑时间范围内。请在7:00~24:00发起乐跑'
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- // 检查redis是否存在当天乐跑成功记录
|
|
|
|
|
- const isSuccess = await Redis.get(`lepaoSuccess:${student_num}`)
|
|
|
|
|
- if (isSuccess)
|
|
|
|
|
- return res.json({
|
|
|
|
|
- ...BaseStdResponse.ERR,
|
|
|
|
|
- msg: '该账号当天已乐跑成功!请勿重复乐跑'
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- const isProgress = await Redis.get(`lepaoProgress:${student_num}`)
|
|
|
|
|
- if (isProgress)
|
|
|
|
|
- return res.json({
|
|
|
|
|
- ...BaseStdResponse.ERR,
|
|
|
|
|
- msg: '该账号已进入乐跑任务队列,请等待乐跑完成后再进行乐跑操作'
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 检查redis是否存在当天乐跑成功记录
|
|
|
|
|
+ const isSuccess = await Redis.get(`lepaoSuccess:${student_num}`)
|
|
|
|
|
+ if (isSuccess)
|
|
|
|
|
+ return res.json({
|
|
|
|
|
+ ...BaseStdResponse.ERR,
|
|
|
|
|
+ msg: '该账号当天已乐跑成功!请勿重复乐跑'
|
|
|
|
|
+ })
|
|
|
|
|
|
|
|
- let selectSql = 'SELECT create_user FROM lepao_account WHERE student_num = ?'
|
|
|
|
|
- let selectRows = await db.query(selectSql, [student_num])
|
|
|
|
|
- if (!selectRows || selectRows.length === 0)
|
|
|
|
|
- return res.json({
|
|
|
|
|
- ...BaseStdResponse.ERR,
|
|
|
|
|
- msg: '发起乐跑失败!未找到账户信息'
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ const isProgress = await Redis.get(`lepaoProgress:${student_num}`)
|
|
|
|
|
+ if (isProgress)
|
|
|
|
|
+ return res.json({
|
|
|
|
|
+ ...BaseStdResponse.ERR,
|
|
|
|
|
+ msg: '该账号已进入乐跑任务队列,请等待乐跑完成后再进行乐跑操作'
|
|
|
|
|
+ })
|
|
|
|
|
|
|
|
- if (selectRows[0].create_user !== uuid) {
|
|
|
|
|
- let permission = await AccessControl.getPermission(uuid)
|
|
|
|
|
- if (!permission.includes("admin") && !permission.includes("service"))
|
|
|
|
|
|
|
+ let selectSql = 'SELECT create_user FROM lepao_account WHERE student_num = ?'
|
|
|
|
|
+ let selectRows = await db.query(selectSql, [student_num])
|
|
|
|
|
+ if (!selectRows || selectRows.length === 0)
|
|
|
return res.json({
|
|
return res.json({
|
|
|
...BaseStdResponse.ERR,
|
|
...BaseStdResponse.ERR,
|
|
|
msg: '发起乐跑失败!未找到账户信息'
|
|
msg: '发起乐跑失败!未找到账户信息'
|
|
|
})
|
|
})
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- let sql = 'SELECT token, uid, school_id, state FROM lepao_account WHERE student_num = ?'
|
|
|
|
|
- let rows = await db.query(sql, [student_num])
|
|
|
|
|
- if (!rows || rows.length === 0)
|
|
|
|
|
- return res.json({
|
|
|
|
|
- ...BaseStdResponse.ERR,
|
|
|
|
|
- msg: '发起乐跑失败!未找到对应的账号信息'
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ if (selectRows[0].create_user !== uuid) {
|
|
|
|
|
+ let permission = await AccessControl.getPermission(uuid)
|
|
|
|
|
+ if (!permission.includes("admin") && !permission.includes("service"))
|
|
|
|
|
+ return res.json({
|
|
|
|
|
+ ...BaseStdResponse.ERR,
|
|
|
|
|
+ msg: '发起乐跑失败!未找到账户信息'
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ let sql = 'SELECT token, uid, school_id, state FROM lepao_account WHERE student_num = ?'
|
|
|
|
|
+ let rows = await db.query(sql, [student_num])
|
|
|
|
|
+ if (!rows || rows.length === 0)
|
|
|
|
|
+ return res.json({
|
|
|
|
|
+ ...BaseStdResponse.ERR,
|
|
|
|
|
+ msg: '发起乐跑失败!未找到对应的账号信息'
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ if (rows[0].state !== 1)
|
|
|
|
|
+ return res.json({
|
|
|
|
|
+ ...BaseStdResponse.ERR,
|
|
|
|
|
+ msg: '账号状态为未登录,请使用登录器更新账号信息后乐跑'
|
|
|
|
|
+ })
|
|
|
|
|
|
|
|
- res.json({
|
|
|
|
|
- ...BaseStdResponse.OK
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ res.json({
|
|
|
|
|
+ ...BaseStdResponse.OK
|
|
|
|
|
+ })
|
|
|
|
|
|
|
|
- lepao.beginLepao(selectRows[0].create_user, student_num, rows[0].token, rows[0].uid, rows[0].school_id, rows[0].state)
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ await lepao.beginLepao(selectRows[0].create_user, student_num, rows[0].token, rows[0].uid, rows[0].school_id, rows[0].state)
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ this.logger.error(`后台乐跑任务异常:${err.stack}`)
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- } catch(err) {
|
|
|
|
|
- this.logger.error(`手动乐跑失败!${err.stack}`);
|
|
|
|
|
- res.json({
|
|
|
|
|
- ...BaseStdResponse.ERR,
|
|
|
|
|
- msg: "乐跑失败!数据库异常"
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ this.logger.error(`手动乐跑失败!${err.stack}`)
|
|
|
|
|
+ return res.json({
|
|
|
|
|
+ ...BaseStdResponse.ERR,
|
|
|
|
|
+ msg: "乐跑失败!数据库异常"
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-module.exports.SingleRun = SingleRun;
|
|
|
|
|
|
|
+module.exports.SingleRun = SingleRun
|