53 lines
1.7 KiB

3 years ago
const schedule = require('node-schedule');
const moment = require('moment')
module.exports = function (app, opts) {
const freshYingshiState = schedule.scheduleJob(
3 years ago
// '* * 4 * * *',
'*/8 * * * * *',
3 years ago
async () => {
3 years ago
try {
const { models } = app.fs.dc
const { varifyYingshiBelongSecretBySerialNo, token4yingshi } = app.fs.utils
const secretRes = await models.SecretYingshi.findAll()
for (let s of secretRes) {
const tokenYingshi = await token4yingshi(s.dataValues)
// 查询所有设备
let pageStart = 0
let deviceList = []
while (pageStart >= 0) {
const deviceRes = await app.fs.yingshiRequest.post('lapp/device/list', {
query: {
accessToken: tokenYingshi,
pageStart,
pageSize: 50
}
})
if (deviceRes.code == 200) {
if (deviceRes.data.length) {
deviceList = deviceList.concat.apply(deviceList, deviceRes.data)
pageStart++
} else {
pageStart = -1
}
}
}
console.log(deviceList);
}
3 years ago
// const await models.UserToken.destroy({
// where: {
// expired: { $lt: now }
// }
// })
3 years ago
} catch (error) {
app.fs.logger.error(`sechedule: freshYingshiState, error: ${error}`);
}
});
return {
freshYingshiState
3 years ago
}
}