From 00d0adfef1ed0dac27ce1ee9a2ce42d089714950 Mon Sep 17 00:00:00 2001 From: wenlele Date: Tue, 2 Jan 2024 13:23:53 +0800 Subject: [PATCH] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/project/index.js | 119 ++++++++++++------ api/app/lib/schedule/alarms_push.js | 7 +- .../sections/service/components/pushModal.jsx | 2 +- 3 files changed, 87 insertions(+), 41 deletions(-) diff --git a/api/app/lib/controllers/project/index.js b/api/app/lib/controllers/project/index.js index ef5ae20..ce6a052 100644 --- a/api/app/lib/controllers/project/index.js +++ b/api/app/lib/controllers/project/index.js @@ -282,6 +282,7 @@ async function strucWithPomsProject (ctx) { SELECT t_structure.id AS strucId, t_structure.name AS strucName, + t_structure.external_platform AS externalPlatform, t_factor.id AS factorId, t_factor.name AS factorName, t_factor.proto AS factorProto, @@ -323,57 +324,97 @@ async function strucWithPomsProject (ctx) { ` ).toPromise() : [] - for (let s of undelStrucRes) { + for await (let s of undelStrucRes) { let corStrut = undelStruc.find(us => us.id == s.strucId) - if (!corStrut) { - let nextFacor = [] - if (s.factorId) { - let nextFactorItem = [] - if (s.factorItemId) { - nextFactorItem.push({ - id: s.factorItemId, - name: s.factorItemName, - }) - } - nextFacor.push({ - id: s.factorId, - name: s.factorName, - proto: s.factorProto, - item: nextFactorItem, + if (s.externalPlatform) { + if (!corStrut) { + const factorList = await clickHouse.dataAlarm + .query(`select SafetyFactorTypeId, SafetyFactorTypeName from sensors where PlatformStructureId = ${s.strucId}`) + .toPromise() + const project = await clickHouse.dataAlarm + .query(`select Project from sensors where PlatformStructureId =${s.strucId} limit 1 `) + .toPromise() + + let fList = factorList.map(m => m.SafetyFactorTypeId) + let list = await clickHouse.dataAlarm + .query( + `select distinct FactorID, Name,Items,ItemNames from factors + where FactorID in (${[...fList, -1].join(',')}) + and Project = '${[...project, 0][0].Project}' + ` + ) + .toPromise() || [] + + let nextFacor = [] + list.map(d => { + if (d.Name) { + nextFacor.push({ + id: d.FactorID, + name: d.Name, + // proto: s.factorProto, + item: d.ItemNames && d.ItemNames.split(',').map(item => ({ id: item, name: item })) || [], + }) + } + }) + undelStruc.push({ + id: s.strucId, + name: s.strucName, + factor: nextFacor }) } - undelStruc.push({ - id: s.strucId, - name: s.strucName, - factor: nextFacor - }) } else { - if (s.factorId) { - let corFactor = corStrut.factor.find(v => v.id == s.factorId) - let nextFactorItem = null - if (s.factorItemId) { - nextFactorItem = { - id: s.factorItemId, - name: s.factorItemName, - } - } - if (corFactor) { - if (!corFactor.item.some(fi => fi.id == s.factorItemId) && nextFactorItem) { - corFactor.item.push(nextFactorItem) + + if (!corStrut) { + let nextFacor = [] + if (s.factorId) { + let nextFactorItem = [] + if (s.factorItemId) { + nextFactorItem.push({ + id: s.factorItemId, + name: s.factorItemName, + }) } - } else { - corStrut.factor.push({ + nextFacor.push({ id: s.factorId, name: s.factorName, proto: s.factorProto, - item: nextFactorItem ? [{ + item: nextFactorItem, + }) + } + undelStruc.push({ + id: s.strucId, + name: s.strucName, + factor: nextFacor + }) + } else { + if (s.factorId) { + let corFactor = corStrut.factor.find(v => v.id == s.factorId) + let nextFactorItem = null + if (s.factorItemId) { + nextFactorItem = { id: s.factorItemId, name: s.factorItemName, - }] : [], - }) + } + } + if (corFactor) { + if (!corFactor.item.some(fi => fi.id == s.factorItemId) && nextFactorItem) { + corFactor.item.push(nextFactorItem) + } + } else { + corStrut.factor.push({ + id: s.factorId, + name: s.factorName, + proto: s.factorProto, + item: nextFactorItem ? [{ + id: s.factorItemId, + name: s.factorItemName, + }] : [], + }) + } } } } + } } @@ -432,7 +473,7 @@ async function getStructureStation (ctx) { let attention = `AND positionCaseInsensitive(toString(t_sensor.labels), '${trait}') > 0` console.log(111, trait, attention); - + const sensor = strucId.length ? await clickHouse.anxinyun.query( ` diff --git a/api/app/lib/schedule/alarms_push.js b/api/app/lib/schedule/alarms_push.js index d380a16..aecac27 100644 --- a/api/app/lib/schedule/alarms_push.js +++ b/api/app/lib/schedule/alarms_push.js @@ -247,6 +247,7 @@ module.exports = function (app, opts) { let emailSubTitle = '' let dataAlarmOption = [] + let dataAlarmOptionLocal=[] let dataAlarmGroupOption = [] let dataAlarmSubType = [] let dataAlarms = [] @@ -287,6 +288,7 @@ module.exports = function (app, opts) { } else if (c.tactics == 'continue' || c.tactics == 'abnormal_rate') { // 新增的应该是上一个时间节点到上上个节点之间 dataAlarmOption.push(`StartTime <= '${pointTime}'`); + dataAlarmOptionLocal.push(`StartTime <= '${pointTime}'`); appAlarmWhereOption.createTime = { $lte: pointTime } videoAlarmWhereOption.push(`camera_status_alarm.create_time <= '${pointTime}'`) // 新增的应该是上一个时间节点到上上个节点之间 @@ -541,6 +543,7 @@ module.exports = function (app, opts) { if (c.alarmSubType && dataAlarmSubType_.length) { dataAlarmSubType_.push(-1) dataAlarmOption.push(`AlarmGroupUnit IN (${dataAlarmSubType_.join(',')})`) + dataAlarmOptionLocal.push(`AlarmGroupUnit IN (${dataAlarmSubType_.join(',')})`) } //安心云 dataAlarms = @@ -1295,13 +1298,15 @@ module.exports = function (app, opts) { FROM alarms WHERE + AlarmGroup IN (1,4,5) + AND alarms.StructureId In (${[...dataAlarmG1StructureId, ...dataAlarmStructureId, -1].join(',') // 3025 }) AND alarms.State < 3 - ${dataAlarmOption.length ? ' AND ' + dataAlarmOption.join(' AND ') : ''} + ${dataAlarmOptionLocal.length ? ' AND ' + dataAlarmOptionLocal.join(' AND ') : ''} ` ).toPromise() || [] diff --git a/web/client/src/sections/service/components/pushModal.jsx b/web/client/src/sections/service/components/pushModal.jsx index 0605280..6b05885 100644 --- a/web/client/src/sections/service/components/pushModal.jsx +++ b/web/client/src/sections/service/components/pushModal.jsx @@ -346,7 +346,7 @@ function pushModal (props) { key={u.name + index} field={'factor' + u.id} style={{ width: 695 }} - initValue={editObj?.pomsStrucFactorId ? editObj?.pomsStrucFactorId[u.id] : (factorItem || [])} + initValue={editObj?.pomsStrucFactorId ? (editObj?.pomsStrucFactorId[u.id]?.filter(d => factorItem.includes(d)) || []) : (factorItem || [])} direction='horizontal' showClear >