liujiangyong
1 year ago
11 changed files with 154 additions and 26 deletions
@ -0,0 +1,55 @@ |
|||
'use strict'; |
|||
const moment = require('moment'); |
|||
|
|||
let axyTokenCache = { |
|||
token: null, |
|||
orgId: null, |
|||
expireTime: null // 过期时间
|
|||
} |
|||
|
|||
const getAnxinyunToken = async function (ctx, opts) { |
|||
try { |
|||
if (!axyTokenCache.token || moment() > moment(axyTokenCache.expireTime)) { |
|||
if (opts.axyPumpProject.split('/').length === 3) { |
|||
const dataToAxy = { |
|||
p: opts.axyPumpProject.split('/')[0], |
|||
username: opts.axyPumpProject.split('/')[1], |
|||
password: opts.axyPumpProject.split('/')[2], |
|||
}; |
|||
const axyResponse = await ctx.app.fs.anxinyun.post('project/login', { data: dataToAxy }); |
|||
if (axyResponse.authorized) { |
|||
axyTokenCache.token = axyResponse.token; |
|||
axyTokenCache.orgId = axyResponse.orgId; |
|||
axyTokenCache.expireTime = moment().add(20, 'hour').format('YYYY-MM-DD HH:mm:ss'); |
|||
} |
|||
} |
|||
} |
|||
return axyTokenCache; |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`sechedule: laborAttendance, error: ${error}`); |
|||
} |
|||
} |
|||
|
|||
function getPumpStatus(opts) { |
|||
return async function (ctx, next) { |
|||
try { |
|||
const { structId } = ctx.params; |
|||
let authData = await getAnxinyunToken(ctx, opts); |
|||
const factors = await ctx.app.fs.anxinyun.get(`structures/${structId}/factors?token=${authData.token}`); |
|||
const pumpFactorId = factors.find(f => f.name === '泵站水泵').id; |
|||
const stationsRes = await ctx.app.fs.anxinyun.get(`structures/${structId}/stations?factorId=${pumpFactorId}&token=${authData.token}`); |
|||
const stations = stationsRes[0].groups[0].stations.map(s => s.id).join(); |
|||
const statusList = await ctx.app.fs.anxinyun.get(`stations/theme/data?stations=${stations}&startTime=${moment().startOf('day').format('YYYY-MM-DD HH:mm:ss')}&endTime=${moment().endOf('day').format('YYYY-MM-DD HH:mm:ss')}&limit=1&token=${authData.token}`); |
|||
ctx.status = 200; |
|||
ctx.body = statusList; |
|||
} catch (err) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${err}`); |
|||
ctx.status = 400; |
|||
ctx.body = { name: 'FindError', message: '获取安心云数据失败' }; |
|||
} |
|||
} |
|||
} |
|||
|
|||
module.exports = { |
|||
getPumpStatus, |
|||
} |
@ -0,0 +1,9 @@ |
|||
'use strict'; |
|||
|
|||
const pump = require('../../controllers/superScreen/pump'); |
|||
|
|||
module.exports = function (app, router, opts, AuthCode) { |
|||
// 获取水泵状态
|
|||
app.fs.api.logAttr['GET/pumpStatus/:structId'] = { content: '获取水泵状态', visible: true }; |
|||
router.get('/pumpStatus/:structId', pump.getPumpStatus(opts)); |
|||
}; |
@ -1,22 +1,22 @@ |
|||
export const SHUI_ZHAN = [ |
|||
{ name: '莲塘渡槽', location: [115.95219, 28.5429711], }, |
|||
{ name: '雄溪站', location: [115.908888, 28.5337351], structId: 2945 }, |
|||
{ name: '雄溪站', location: [115.908888, 28.5337351], }, |
|||
{ name: '塔田站', location: [115.916979, 28.5319411], }, |
|||
{ name: '万寿湖站', location: [115.929167, 28.5222881], }, |
|||
{ name: '张坊站', location: [115.9092, 28.5049421], }, |
|||
{ name: '东山站', location: [115.887528, 28.4872531], }, |
|||
{ name: '东山站', location: [115.887528, 28.4872531], structId: 3592 }, |
|||
{ name: '河外泵站', location: [115.889888, 28.4856311], }, |
|||
{ name: '三山站', location: [115.888521, 28.4726391], }, |
|||
{ name: '三山站', location: [115.888521, 28.4726391], structId: 3599 }, |
|||
{ name: '内湖电排站', location: [115.891311, 28.4692441], }, |
|||
{ name: '沥山站', location: [115.897692, 28.5616881], }, |
|||
{ name: '象湖站', location: [115.894774, 28.5789311], }, |
|||
{ name: '姚塘站', location: [115.863709, 28.579954], }, |
|||
{ name: '河下站', location: [115.844769, 28.5602231], }, |
|||
{ name: '霞山站', location: [115.841465, 28.5508371], }, |
|||
{ name: '石岐站', location: [115.838675, 28.5507611], }, |
|||
{ name: '石岐站', location: [115.838675, 28.5507611], structId: 3598 }, |
|||
{ name: '清湖站', location: [115.838418, 28.5378311], }, |
|||
{ name: '虎山站', location: [115.843673, 28.5366861], }, |
|||
{ name: '新八月湖站', location: [115.880322, 28.6076911], }, |
|||
{ name: '新八月湖站', location: [115.880322, 28.6076911], structId: 3569 }, |
|||
// { name: '八月湖站', location: [115.868392, 28.6091981], },
|
|||
{ name: '河口电排站', location: [115.924659, 28.52865] }, |
|||
] |
Loading…
Reference in new issue