|
|
@ -350,76 +350,76 @@ async function getDevicesLlinkStatus (ctx, next) { |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
async function findAlarmsDevice(ctx, next) { |
|
|
|
async function findAlarmsDevice (ctx, next) { |
|
|
|
let error = { name: 'FindError', message: '告警信息获取失败' }; |
|
|
|
let rslt = null; |
|
|
|
const { deviceId } = ctx.params; |
|
|
|
if (deviceId) { |
|
|
|
try { |
|
|
|
const { limit } = ctx.query; |
|
|
|
const client = ctx.app.fs.esclient[ALARM];//准备查询
|
|
|
|
let params = { |
|
|
|
index: client.config.index, |
|
|
|
type: client.config.type, |
|
|
|
size: limit || 5, |
|
|
|
body: { |
|
|
|
"query": { |
|
|
|
"bool": { |
|
|
|
"must": [ |
|
|
|
{ |
|
|
|
"match": { |
|
|
|
"source_id": deviceId |
|
|
|
} |
|
|
|
}, |
|
|
|
{ |
|
|
|
"terms": { |
|
|
|
"state": [] |
|
|
|
} |
|
|
|
} |
|
|
|
] |
|
|
|
} |
|
|
|
}, |
|
|
|
"sort": [ |
|
|
|
{ |
|
|
|
"start_time": { |
|
|
|
"order": "desc" |
|
|
|
try { |
|
|
|
const { limit } = ctx.query; |
|
|
|
const client = ctx.app.fs.esclient[ALARM];//准备查询
|
|
|
|
let params = { |
|
|
|
index: client.config.index, |
|
|
|
type: client.config.type, |
|
|
|
size: limit || 5, |
|
|
|
body: { |
|
|
|
"query": { |
|
|
|
"bool": { |
|
|
|
"must": [ |
|
|
|
{ |
|
|
|
"match": { |
|
|
|
"source_id": deviceId |
|
|
|
} |
|
|
|
} |
|
|
|
] |
|
|
|
} |
|
|
|
} |
|
|
|
let newState = [AlarmState.Creation, AlarmState.CountUpgrade, AlarmState.LevelUpgrade]; |
|
|
|
let historyState = [AlarmState.AutoElimination, AlarmState.ManElimination]; |
|
|
|
params.body.query.bool.must[1].terms.state = newState; |
|
|
|
let newAlarms = await client.search(params);//查询
|
|
|
|
params.body.query.bool.must[1].terms.state = historyState; |
|
|
|
params.size = 9999; |
|
|
|
let historyAlarm = await client.search(params); |
|
|
|
const timer = ctx.app.fs.timer; |
|
|
|
function filterAlarmMsg(oriMsg) { |
|
|
|
let msg = []; |
|
|
|
for (let s of oriMsg) { |
|
|
|
msg.push({ |
|
|
|
alarmContent: s._source.alarm_content, |
|
|
|
alarmCount: s._source.alarm_count, |
|
|
|
startTime: timer.toCSTString(s._source.start_time), |
|
|
|
endTime: timer.toCSTString(s._source.end_time), |
|
|
|
}) |
|
|
|
} |
|
|
|
return msg; |
|
|
|
} |
|
|
|
rslt = { new: filterAlarmMsg(newAlarms.hits.hits), history: filterAlarmMsg(historyAlarm.hits.hits) } |
|
|
|
error = null; |
|
|
|
} catch (err) { |
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${err}`); |
|
|
|
} |
|
|
|
}, |
|
|
|
{ |
|
|
|
"terms": { |
|
|
|
"state": [] |
|
|
|
} |
|
|
|
} |
|
|
|
] |
|
|
|
} |
|
|
|
}, |
|
|
|
"sort": [ |
|
|
|
{ |
|
|
|
"start_time": { |
|
|
|
"order": "desc" |
|
|
|
} |
|
|
|
} |
|
|
|
] |
|
|
|
} |
|
|
|
} |
|
|
|
let newState = [AlarmState.Creation, AlarmState.CountUpgrade, AlarmState.LevelUpgrade]; |
|
|
|
let historyState = [AlarmState.AutoElimination, AlarmState.ManElimination]; |
|
|
|
params.body.query.bool.must[1].terms.state = newState; |
|
|
|
let newAlarms = await client.search(params);//查询
|
|
|
|
params.body.query.bool.must[1].terms.state = historyState; |
|
|
|
params.size = 9999; |
|
|
|
let historyAlarm = await client.search(params); |
|
|
|
const timer = ctx.app.fs.timer; |
|
|
|
function filterAlarmMsg (oriMsg) { |
|
|
|
let msg = []; |
|
|
|
for (let s of oriMsg) { |
|
|
|
msg.push({ |
|
|
|
alarmContent: s._source.alarm_content, |
|
|
|
alarmCount: s._source.alarm_count, |
|
|
|
startTime: timer.toCSTString(s._source.start_time), |
|
|
|
endTime: timer.toCSTString(s._source.end_time), |
|
|
|
}) |
|
|
|
} |
|
|
|
return msg; |
|
|
|
} |
|
|
|
rslt = { new: filterAlarmMsg(newAlarms.hits.hits), history: filterAlarmMsg(historyAlarm.hits.hits) } |
|
|
|
error = null; |
|
|
|
} catch (err) { |
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${err}`); |
|
|
|
} |
|
|
|
} |
|
|
|
if (error) { |
|
|
|
ctx.status = 400; |
|
|
|
ctx.body = error; |
|
|
|
ctx.status = 400; |
|
|
|
ctx.body = error; |
|
|
|
} else { |
|
|
|
ctx.status = 200; |
|
|
|
ctx.body = rslt; |
|
|
|
ctx.status = 200; |
|
|
|
ctx.body = rslt; |
|
|
|
} |
|
|
|
} |
|
|
|
//查询智能
|
|
|
@ -428,32 +428,49 @@ async function createInvoke (ctx, next) { |
|
|
|
const data = ctx.request.body |
|
|
|
let rslt = null, code = null, issuccess = false, text = null; |
|
|
|
if (data) { |
|
|
|
try { |
|
|
|
const models = ctx.fs.dc.models; |
|
|
|
let iotaThingId = data.thingId; |
|
|
|
let structure = await models.Structure.findOne({ where: { iotaThingId } }); |
|
|
|
if (structure) { |
|
|
|
const dataToIota = data; |
|
|
|
let iotaResponse = await ctx.app.fs.iotRequest.post(`/capabilities/invoke`, dataToIota) |
|
|
|
rslt = JSON.parse(iotaResponse) |
|
|
|
error = null; |
|
|
|
} else { |
|
|
|
error = { name: 'NotFound', message: `不存在{iotaThingId=${iotaThingId}}的结构物` }; |
|
|
|
} |
|
|
|
} catch (err) { |
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${err}`); |
|
|
|
} |
|
|
|
try { |
|
|
|
const models = ctx.fs.dc.models; |
|
|
|
let iotaThingId = data.thingId; |
|
|
|
let structure = await models.Structure.findOne({ where: { iotaThingId } }); |
|
|
|
if (structure) { |
|
|
|
const dataToIota = data; |
|
|
|
let iotaResponse = await ctx.app.fs.iotRequest.post(`/capabilities/invoke`, dataToIota) |
|
|
|
rslt = JSON.parse(iotaResponse) |
|
|
|
error = null; |
|
|
|
} else { |
|
|
|
error = { name: 'NotFound', message: `不存在{iotaThingId=${iotaThingId}}的结构物` }; |
|
|
|
} |
|
|
|
} catch (err) { |
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${err}`); |
|
|
|
} |
|
|
|
} |
|
|
|
if (error) { |
|
|
|
ctx.status = 400; |
|
|
|
ctx.body = error; |
|
|
|
ctx.status = 400; |
|
|
|
ctx.body = error; |
|
|
|
} else { |
|
|
|
ctx.status = 200; |
|
|
|
ctx.body = rslt; |
|
|
|
ctx.status = 200; |
|
|
|
ctx.body = rslt; |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
async function getThingStatus (ctx) { |
|
|
|
let res = [] |
|
|
|
try { |
|
|
|
const { thingId } = ctx.query |
|
|
|
let res = await ctx.app.fs.craw.get('thing/status', { query: { thingId } }) |
|
|
|
ctx.status = 200 |
|
|
|
if (res) { |
|
|
|
ctx.body = JSON.parse(res) |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`) |
|
|
|
ctx.status = 200 |
|
|
|
ctx.body = [] |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = { |
|
|
|
getOrganizationsStruc, |
|
|
@ -466,5 +483,6 @@ module.exports = { |
|
|
|
findDevicesCardStatus, |
|
|
|
getDevicesLlinkStatus, |
|
|
|
findAlarmsDevice, |
|
|
|
createInvoke |
|
|
|
createInvoke, |
|
|
|
getThingStatus, |
|
|
|
} |