diff --git a/api/app/lib/controllers/control/toolLink.js b/api/app/lib/controllers/control/toolLink.js index 1c8e4d9..c61abbc 100644 --- a/api/app/lib/controllers/control/toolLink.js +++ b/api/app/lib/controllers/control/toolLink.js @@ -138,61 +138,44 @@ async function count (ctx) { const dataAlarm = await clickHouse.dataAlarm.query(` SELECT - AlarmId,State,StartTime + AlarmId,State,StartTime,AlarmGroup FROM alarms WHERE alarms.StructureId IN (${anxinStrucIds.join(",")}) `).toPromise(); - //数据告警总数 - const alarm = await clickHouse.dataAlarm.query(` - SELECT - count(alarms.AlarmId) AS count - FROM - alarms - WHERE - alarms.StructureId IN (${anxinStrucIds.join(",")}) - `).toPromise(); - - const confirmedAlarm = dataAlarm // TODO: 开发临时注释 .filter(ar => ar.State && ar.State > 2) .map(ar => "'" + ar.AlarmId + "'") //剩余数据告警 - const alarmSurplus = dataAlarm.filter(ar => ar.State && ar.State < 3).length || 0 + const dataSurplus = dataAlarm.filter(ar => ar.State && ar.State < 3 && ar.AlarmGroup < 4).length || 0 + //剩余设备告警 + const toolSurplus = dataAlarm.filter(ar => ar.State && ar.State < 3 && ar.AlarmGroup > 3).length || 0 //今日新增数据告警 - const alarmNewAdd = await clickHouse.dataAlarm.query(` - SELECT - count(alarms.StartTime) AS count - FROM - alarms - WHERE - alarms.StructureId IN (${anxinStrucIds.join(",")}) - AND - alarms.StartTime >= '${moment().startOf('day').format('YYYY-MM-DD HH:mm:ss')}' - AND - alarms.StartTime <= '${moment().endOf('day').format('YYYY-MM-DD HH:mm:ss')}' - - `).toPromise(); + const dataNewAdd = dataAlarm.filter(r => moment(moment().startOf('day').format('YYYY-MM-DD HH:mm:ss')).isBefore(r.StartTime) && moment(r.createTime).isBefore(moment().endOf('day').format('YYYY-MM-DD HH:mm:ss')) && r.AlarmGroup < 4).length || 0 + const toolNewAdd = dataAlarm.filter(r => moment(moment().startOf('day').format('YYYY-MM-DD HH:mm:ss')).isBefore(r.StartTime) && moment(r.createTime).isBefore(moment().endOf('day').format('YYYY-MM-DD HH:mm:ss')) && r.AlarmGroup > 3).length || 0 //今日确认数据告警 - const alarmConfirme = confirmedAlarm.length ? + const dataConfirme = confirmedAlarm.length ? await clickHouse.dataAlarm.query(` SELECT - max(Time) AS Time, AlarmId , max(Content) AS Content + max(Time) AS Time, AlarmId , max(Content) AS Content, + alarms.AlarmGroup AS AlarmGroup FROM alarm_details + LEFT JOIN alarms + ON alarm_details.AlarmId=alarms.AlarmId WHERE AlarmId IN (${confirmedAlarm.join(',')}) AND alarm_details.Time >= '${moment().startOf('day').format('YYYY-MM-DD HH:mm:ss')}' AND alarm_details.Time <= '${moment().endOf('day').format('YYYY-MM-DD HH:mm:ss')}' - GROUP BY AlarmId + GROUP BY AlarmId,AlarmGroup `).toPromise() : []; @@ -229,9 +212,6 @@ async function count (ctx) { //今日确认应用告警 const appConfirme = listRes.rows.filter(r => moment(moment().startOf('day').format('YYYY-MM-DD HH:mm:ss')).isBefore(r.confirmTime) && moment(r.confirmTime).isBefore(moment().endOf('day').format('YYYY-MM-DD HH:mm:ss'))).length || 0 - - - const alarmRes = anxinStrucIds.length ? await clickHouse.vcmp.query( ` SELECT @@ -327,7 +307,6 @@ async function count (ctx) { } } - //剩余视频告警 const videoSurplus = returnD.filter(r => !r.confirmTime).length || 0 //今日新增视频告警 @@ -335,28 +314,36 @@ async function count (ctx) { //今日确认视频告警 const videoConfirme = returnD.filter(r => moment(moment().startOf('day').format('YYYY-MM-DD HH:mm:ss')).isBefore(r.confirmTime) && moment(r.confirmTime).isBefore(moment().endOf('day').format('YYYY-MM-DD HH:mm:ss'))).length || 0 - + let findOptions = { + where: { + del: false + }, + attributes: [] + } + if (!userInfo.role.includes('SuperAdmin') && !userInfo.role.includes('admin')) { + findOptions.where.id = { $in: userInfo.correlationProject } + } + const projects = await models.ProjectCorrelation.findAndCountAll(findOptions) ctx.status = 200; ctx.body = { - dataAlarm: { - alarm: dataAlarm.filter(r => r.State < 3).length || 0, - alarmSurplus: alarmSurplus, - alarmNewAdd: alarmNewAdd[0].count || 0, - alarmConfirme: alarmConfirme.length || 0, - }, - videoAlarm: { - video: returnD.filter(r => !r.confirmTime).length || 0, - videoSurplus: videoSurplus, - videoNewAdd: videoNewAdd, - videoConfirme: videoConfirme, - }, - appAlarm: { - app: listRes.rows.filter(r => !r.confirmTime).length || 0, - appSurplus: appSurplus, - appNewAdd: appNewAdd, - appConfirme: appConfirme, - } + + dataSurplus: dataSurplus + videoSurplus, + dataNewAdd: dataNewAdd + videoNewAdd, + dataConfirme: appConfirme + dataConfirme.filter(r => r.AlarmGroup < 4).length, + + + toolSurplus: toolSurplus, + toolNewAdd: toolNewAdd, + toolConfirme: dataConfirme.filter(r => r.AlarmGroup > 3).length, + + + appSurplus: appSurplus, + appNewAdd: appNewAdd, + appConfirme: appConfirme, + + projects: projects.count, + } } else { ctx.body = { diff --git a/web/client/src/sections/control/containers/control.jsx b/web/client/src/sections/control/containers/control.jsx index 9f54ede..ed5b649 100644 --- a/web/client/src/sections/control/containers/control.jsx +++ b/web/client/src/sections/control/containers/control.jsx @@ -18,7 +18,7 @@ let alarmScrollbar; const Control = (props) => { - const { dispatch, actions, user, loading, socket } = props + const { dispatch, actions, user, loading, socket ,pepProjectId} = props const { control } = actions const stationList = [ 'url(/assets/images/console/lan_1.png)', @@ -63,11 +63,10 @@ const Control = (props) => { }, []) useEffect(() => { - dispatch(control.geteteConsoleCount({})).then(res => { - console.log(res); + dispatch(control.geteteConsoleCount({pepProjectId:pepProjectId})).then(res => { if (res.success) setWorkData(res.payload.data) }) - }, []) + }, [pepProjectId]) useEffect(() => { newScrollbar = new PerfectScrollbar("#news", { @@ -145,13 +144,17 @@ const Control = (props) => { } let listAll = [ - { name: '关注的项目', sort: 1, key: 'project', data: 1, img: 'url(/assets/images/console/lan_1.png)' }, - { name: '数据告警', sort: 2, key: 'data', data: workData?.dataAlarm?.alarm || 0, img: 'url(/assets/images/console/lv_1.png)' }, - { name: '应用告警', sort: 2, key: 'app', data: workData?.appAlarm?.alarm || 0, img: 'url(/assets/images/console/hong_1.png)' }, - { name: '设备告警', sort: 2, key: 'device', data: workData?.dataAlarm?.alarm || 0, img: 'url(/assets/images/console/hong_1.png)' }, + { name: '关注的项目', sort: 1, key: 'project', data: workData?.projects, img: 'url(/assets/images/console/lan_1.png)' }, + { name: '数据告警', sort: 2, key: 'data', data: workData?.dataSurplus, img: 'url(/assets/images/console/lv_1.png)' }, + { name: '应用告警', sort: 2, key: 'app', data: workData?.appSurplus, img: 'url(/assets/images/console/hong_1.png)' }, + { name: '设备告警', sort: 2, key: 'device', data: workData?.toolSurplus, img: 'url(/assets/images/console/hong_1.png)' }, ] + console.log(workData); + console.log(listAll); - + useEffect(() => { + attribute('workbench') + }, [workData]) const attribute = (title) => { let take = localStorage.getItem(title) @@ -214,7 +217,7 @@ const Control = (props) => { 剩余问题: