You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
110 lines
2.7 KiB
110 lines
2.7 KiB
'use strict';
|
|
const moment = require('moment')
|
|
|
|
|
|
async function getOrganizationsStruc (ctx) {
|
|
try {
|
|
const { utils: { anxinStrucIdRange } } = ctx.app.fs
|
|
const { pepProjectId } = ctx.params
|
|
|
|
if (!pepProjectId) {
|
|
throw '缺少参数 pepProjectId'
|
|
}
|
|
let anxinStruc = await anxinStrucIdRange({
|
|
ctx, pepProjectId
|
|
}) || []
|
|
ctx.status = 200
|
|
ctx.body = anxinStruc
|
|
|
|
} catch (error) {
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
|
|
ctx.status = 400;
|
|
ctx.body = {
|
|
message: '获取项目下的结构物信息失败'
|
|
}
|
|
}
|
|
}
|
|
|
|
async function getThingsDeploy (ctx) {
|
|
let error = { name: 'FindError', message: '获取设备部署信息失败' };
|
|
let rslt = null, errStatus = null;
|
|
let { iotaThingId } = ctx.params;
|
|
|
|
try {
|
|
if (!iotaThingId) {
|
|
throw '缺少参数 iotaThingId'
|
|
}
|
|
let iotaResponse = await ctx.app.fs.iotRequest.get(`things/${iotaThingId}/deploys`)
|
|
rslt = JSON.parse(iotaResponse)
|
|
error = null;
|
|
|
|
} catch (err) {
|
|
errStatus = err.status
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${err}`);
|
|
}
|
|
if (error) {
|
|
if (errStatus == 404) {
|
|
ctx.status = 200;
|
|
ctx.body = {
|
|
'instances': null
|
|
};
|
|
} else {
|
|
ctx.status = errStatus;
|
|
ctx.body = error;
|
|
}
|
|
} else {
|
|
ctx.status = 200;
|
|
ctx.body = rslt
|
|
}
|
|
}
|
|
|
|
async function getDeviceMetaDeployed (ctx) {
|
|
let error = { name: 'FindError', message: '设备部署原型获取失败' };
|
|
let rslt = null;
|
|
const { iotaThingId } = ctx.params;
|
|
try {
|
|
if (!iotaThingId) {
|
|
throw '缺少参数 iotaThingId'
|
|
}
|
|
let iotaResponse = await ctx.app.fs.iotRequest.get(`meta/things/${iotaThingId}/devices`);
|
|
|
|
ctx.status = 200;
|
|
ctx.body = JSON.parse(iotaResponse);
|
|
} catch (err) {
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${err}`);
|
|
}
|
|
};
|
|
|
|
async function iotaLinkStatus (ctx, next) {
|
|
let error = { name: 'CreateError', message: '命令下发失败' };
|
|
const { iotaThingId } = ctx.params;
|
|
let rslt = null;
|
|
|
|
try {
|
|
if (!iotaThingId) {
|
|
throw '缺少参数 iotaThingId'
|
|
}
|
|
let iotaResponse = await ctx.app.fs.iotRequest.get(`metrics/things/${iotaThingId}/devices/link_status`);
|
|
rslt = JSON.parse(iotaResponse);
|
|
error = null;
|
|
} catch (err) {
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${err}`);
|
|
}
|
|
|
|
if (error) {
|
|
ctx.status = 400;
|
|
ctx.body = error;
|
|
} else {
|
|
ctx.status = 200;
|
|
ctx.body = rslt;
|
|
}
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
getOrganizationsStruc,
|
|
getThingsDeploy,
|
|
getDeviceMetaDeployed,
|
|
iotaLinkStatus,
|
|
}
|