Browse Source

EM推送配置项目多选

dev
巴林闲侠 2 years ago
parent
commit
f5ba9687f7
  1. 45
      api/app/lib/controllers/control/data.js
  2. 4
      api/app/lib/index.js
  3. 2
      api/app/lib/models/email_send_log.js
  4. 2
      api/app/lib/models/latest_dynamic_list.js
  5. 8
      api/app/lib/schedule/alarms_push.js
  6. 6
      script/0.11/schema/1.alter_email_send_log.sql
  7. 34
      web/client/index.html
  8. 66
      web/client/src/sections/control/containers/control.jsx

45
api/app/lib/controllers/control/data.js

@ -2,7 +2,7 @@
const moment = require('moment');
//BI分析-数据
async function getDataAlarmsAggDay(ctx) {
async function getDataAlarmsAggDay (ctx) {
try {
const { utils: { anxinStrucIdRange } } = ctx.app.fs
const { pepProjectId } = ctx.query
@ -12,10 +12,8 @@ async function getDataAlarmsAggDay(ctx) {
ctx, pepProjectId
})
let whereOption = []
// ! 1 开发临时增加
if (anxinStruc.length) {
const anxinStrucIds = anxinStruc.map(a => a.strucId)
// ! 开发临时注释
whereOption.push(`alarms.StructureId IN (${anxinStrucIds.join(",")})`)
let start = moment().add(-1, 'year').format('YYYY-MM-DD HH:mm:ss');//最近一年
@ -41,7 +39,7 @@ async function getDataAlarmsAggDay(ctx) {
}
}
async function queryAlarm(ctx, alarmQueryOptionStr, type) {
async function queryAlarm (ctx, alarmQueryOptionStr, type) {
const { clickHouse } = ctx.app.fs
try {
const alarmRes = await clickHouse.dataAlarm.query(`
@ -76,7 +74,7 @@ async function queryAlarm(ctx, alarmQueryOptionStr, type) {
}
//BI分析-应用异常
async function getAppAlarmsAggDay(ctx) {
async function getAppAlarmsAggDay (ctx) {
try {
const models = ctx.fs.dc.models;
const { utils: { pomsProjectRange } } = ctx.app.fs
@ -129,7 +127,7 @@ async function getAppAlarmsAggDay(ctx) {
}
//BI分析-视频异常
async function getVideoAlarmsAggDay(ctx) {
async function getVideoAlarmsAggDay (ctx) {
try {
const { clickHouse, utils: { anxinStrucIdRange } } = ctx.app.fs
const { database: anxinyun } = clickHouse.anxinyun.opts.config
@ -246,7 +244,7 @@ async function getVideoAlarmsAggDay(ctx) {
}
//BI分析-问题处置效率分析
async function getAlarmsHandleStatistics(ctx) {
async function getAlarmsHandleStatistics (ctx) {
try {
const { projectCorrelationId } = ctx.query
const models = ctx.fs.dc.models;
@ -266,7 +264,7 @@ async function getAlarmsHandleStatistics(ctx) {
}
}
//最新动态
async function getLatestDynamic(ctx) {
async function getLatestDynamic (ctx) {
try {
const { models } = ctx.fs.dc;
const { limit, page, projectCorrelationId, types } = ctx.query;
@ -303,9 +301,9 @@ async function getLatestDynamic(ctx) {
});
//查项目名称 查用户名
let pepPojectIds = new Set(), notedUserIds = new Set();
let pepPojectIds = new Set(), notedUserIds = new Set(), emailSendPomsProjectIds = new Set();
for (let p of news) {
if(p.projectCorrelation && p.projectCorrelation.pepProjectId){
if (p.projectCorrelation && p.projectCorrelation.pepProjectId) {
pepPojectIds.add(p.projectCorrelation.pepProjectId);
}
@ -313,11 +311,28 @@ async function getLatestDynamic(ctx) {
p.emailSendLog.toPepUserIds.map(u => {
notedUserIds.add(u);//通知 接收人
})
p.emailSendLog.projectCorrelationId.forEach(pid => emailSendPomsProjectIds.add(pid))
}
if (p.alarmConfirmLog && p.alarmConfirmLog.pepUserId) {
notedUserIds.add(p.alarmConfirmLog.pepUserId);//确认 操作者
}
}
// EM 推送的特殊处理
// 查找对应的 projectCorrelation
const emailLogProjectCorrelationRes =
emailSendPomsProjectIds.size ?
await models.ProjectCorrelation.findAll({
where: {
id: { $in: [...emailSendPomsProjectIds] }
}
}) : []
for (let { dataValues: p } of emailLogProjectCorrelationRes) {
if (p.pepProjectId) {
pepPojectIds.add(p.pepProjectId)
}
}
let pepProjects = pepPojectIds.size ? await clickHouse.projectManage.query(`
SELECT id, project_name FROM t_pim_project WHERE id IN (${[...pepPojectIds].join(',')},-1)
`).toPromise() : [];
@ -339,7 +354,15 @@ async function getLatestDynamic(ctx) {
if (d.emailSendId) {
notice.push({
userName: userPepRes.filter(u => d.emailSendLog.toPepUserIds.indexOf(u.id) != -1),
projectName,
projectName: d.emailSendLog.projectCorrelationId.map(p => {
let projectName = ''
if (p.pepProjectId) {
projectName = pepProjects.find(pp => pp.id == p.pepProjectId).project_name
} else {
projectName = p.name
}
return projectName
}).join('、'),
...d.emailSendLog.dataValues
});
}

4
api/app/lib/index.js

@ -77,8 +77,8 @@ module.exports.models = function (dc) { // dc = { orm: Sequelize对象, ORM: Seq
AppAlarm.belongsTo(App, { foreignKey: 'projectAppId', targetKey: 'id' });
App.hasMany(AppAlarm, { foreignKey: 'projectAppId', sourceKey: 'id' });
AlarmPushConfig.belongsTo(ProjectCorrelation, { foreignKey: 'pomsProjectId', targetKey: 'id' });
ProjectCorrelation.hasMany(AlarmPushConfig, { foreignKey: 'pomsProjectId', sourceKey: 'id' });
// AlarmPushConfig.belongsTo(ProjectCorrelation, { foreignKey: 'pomsProjectId', targetKey: 'id' });
// ProjectCorrelation.hasMany(AlarmPushConfig, { foreignKey: 'pomsProjectId', sourceKey: 'id' });
AlarmAppearRecord.belongsTo(ProjectCorrelation, { foreignKey: 'projectCorrelationId', targetKey: 'id' });
ProjectCorrelation.hasMany(AlarmAppearRecord, { foreignKey: 'projectCorrelationId', sourceKey: 'id' });

2
api/app/lib/models/email_send_log.js

@ -53,7 +53,7 @@ module.exports = dc => {
autoIncrement: false
},
projectCorrelationId: {
type: DataTypes.INTEGER,
type: DataTypes.ARRAY(DataTypes.INTEGER),
allowNull: false,
defaultValue: null,
comment: null,

2
api/app/lib/models/latest_dynamic_list.js

@ -54,7 +54,7 @@ module.exports = dc => {
},
projectCorrelationId: {
type: DataTypes.INTEGER,
allowNull: false,
allowNull: true,
defaultValue: null,
comment: null,
primaryKey: false,

8
api/app/lib/schedule/alarms_push.js

@ -60,7 +60,7 @@ module.exports = function (app, opts) {
for (let { dataValues: c } of configListRes) {
if (c.tacticsParams && c.tactics) {
// pomsProjectId 是个数组 []
const { projectCorrelation, strucId, pomsProjectId, } = c
const { strucId, pomsProjectId, } = c
const { interval, deviceProportion } = c.tacticsParams
if (
@ -248,7 +248,7 @@ module.exports = function (app, opts) {
if (c.alarmSubType) dataAlarmSubType = dataAlarmSubType.concat(c.alarmSubType['strategy_hit'])
}
if (c.alarmType.includes('video_exception')) {
let videoAlarmSubType = c.alarmSubType ? c.alarmSubType['data_exception'] : []
let videoAlarmSubType = c.alarmSubType ? c.alarmSubType['video_exception'] : []
if (videoAlarmSubType.length == 1) videoAlarmSubType.push(-1)
videoAlarms = searchStrucIds.length && videoAlarmSubType.length ? await clickHouse.vcmp.query(
`
@ -734,6 +734,7 @@ module.exports = function (app, opts) {
}
return arr
}, [])
// !开发测试用的数据
// emails = ['1650192445@qq.com']
if (emails.length) {
await pushByEmail({
@ -758,12 +759,11 @@ module.exports = function (app, opts) {
let dynamic = {
time: r.dataValues.time,
emailSendId: r.dataValues.id,
projectCorrelationId: r.dataValues.projectCorrelationId,
// projectCorrelationId: r.dataValues.projectCorrelationId,
type: 2//通知
}
await models.LatestDynamicList.create(dynamic);
//消息推送到前端
await sendNoticeToWeb(receiverId, dataToSave);
}

6
script/0.11/schema/1.alter_email_send_log.sql

@ -0,0 +1,6 @@
ALTER TABLE email_send_log ALTER COLUMN project_correlation_id TYPE INTEGER []
USING CASE
WHEN project_correlation_id is NULL
then NULL
ELSE array [project_correlation_id]
END ::INTEGER [];

34
web/client/index.html

@ -2,26 +2,26 @@
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="minimum-scale=1, initial-scale=1, width=device-width" />
<meta charset="UTF-8">
<meta name="viewport" content="minimum-scale=1, initial-scale=1, width=device-width" />
<link rel="shortcut icon" href="/assets/images/favicon.ico">
<link rel="shortcut icon" href="/assets/images/favicon.ico">
<script charset="UTF-8" id="LA_COLLECT" src="//sdk.51.la/js-sdk-pro.min.js"></script>
<script>LA.init({ id: "Jo4eTlZVqgx3uwqm", ck: "Jo4eTlZVqgx3uwqm" })</script>
<script charset="UTF-8" id="LA_COLLECT" src="//sdk.51.la/js-sdk-pro.min.js"></script>
<script>LA.init({ id: "Jo4eTlZVqgx3uwqm", ck: "Jo4eTlZVqgx3uwqm" })</script>
<script
src="https://lf1-cdn-tos.bytegoofy.com/obj/iconpark/icons_19077_11.559b91c217b8ddc76c0c4b1397d84d48.es5.js"></script>
</head >
<script
src="https://lf1-cdn-tos.bytegoofy.com/obj/iconpark/icons_19077_11.559b91c217b8ddc76c0c4b1397d84d48.es5.js"></script>
</head>
<body>
<div id='PomsApp' style="height: 100%;"></div>
<body>
<div id='PomsApp' style="height: 100%;"></div>
<!-- Webpack -->
<script type="text/javascript" src="http://localhost:5601/client/build/app.js"></script>
<!-- Webpack -->
<script type="text/javascript" src="http://localhost:5601/client/build/app.js"></script>
<!-- Vite -->
<!-- <script type="module">
<!-- Vite -->
<!-- <script type="module">
import RefreshRuntime from "http://localhost:5602/@react-refresh"
RefreshRuntime.injectIntoGlobalHook(window)
window.$RefreshReg$ = () => { }
@ -30,9 +30,9 @@
const global = window
</script>
<script type="module" src="http://localhost:5002/src/index.jsx"></script> -->
<!-- Vite End -->
<!-- Vite End -->
<script>
<script>
//过滤掉一些无用的警告、没有价值的报错
//代理console.warn方法
@ -48,7 +48,7 @@
// _consoleWarn(...rest);
// }
// };
</script>
</script>
</body>
</html>

66
web/client/src/sections/control/containers/control.jsx

@ -8,7 +8,6 @@ import repairFQA from '../../means/containers/repairFQA';
import { Setup, OutHidden } from "$components";
import ReactECharts from 'echarts-for-react';
import moment from "moment";
import { log } from 'ezuikit-js';
let newScrollbar;
let overviewScrollbar;
@ -43,7 +42,7 @@ const Control = ({ dispatch, actions, user, history, loading, socket, pepProject
const [videoBI, setVideoBI] = useState([]); //BI-
const [appBI, setAppBI] = useState([]); //BI-
const [efficiencyBI, setEfficiencyBI] = useState({}); //BI-
const [query, setQuery] = useState({ limit: 10, page: 0, projectCorrelationId: '', types: '1' }); //
const [query, setQuery] = useState({ limit: 23, page: 0, projectCorrelationId: '', types: '1' }); //
const [querydata1, setQueryData1] = useState([]); //
const [long, setLong] = useState(''); //
const [pomsList, setPomsList] = useState([]); //
@ -184,7 +183,7 @@ const Control = ({ dispatch, actions, user, history, loading, socket, pepProject
newest.sort((a, b) => (moment(a.time).isBefore(b.time) ? 1 : -1))
querydata.current = [...newest, ...querydata.current]
setQueryData1([...querydata.current])
}
}, [socketData])
useEffect(() => {
@ -398,6 +397,7 @@ const Control = ({ dispatch, actions, user, history, loading, socket, pepProject
}))
}
if (exhibition?.current?.dynamic?.find(v => v.key == 'notice')) {
// EM
res.payload.data?.notice?.map(v => data.push({
seed: 'notice',
time: v.time,
@ -444,14 +444,26 @@ const Control = ({ dispatch, actions, user, history, loading, socket, pepProject
const line = document.getElementById("line")
const news = document.getElementById("news")
if (line && news) {
news.onscroll = () => {
news.onscroll = (e) => {
e.stopPropagation();
if ((line.clientHeight - 578) < news.scrollTop + 10) {
setQuery({ ...query, page: query.page + 1 })
if (exhibition?.current?.dynamic?.length > 0) {
dispatch(control.getLatestDynamic({ ...query, projectCorrelationId: pepProjectId, page: query.page + 1 })).then(res => {
news.scrollTop = news.scrollTop - 640
// news.scrollTop = news.scrollTop - 640
let data = querydata.current
if (res.success) {
let returnJudge = true
for (let k in res.payload.data) {
if (res.payload.data[k].length) {
returnJudge = false
break
}
}
if (returnJudge) {
return
}
if (exhibition?.current?.dynamic?.find(v => v.key == 'discovery')) {
res.payload.data?.appear?.map(v => data.push({
seed: 'discovery',
@ -503,9 +515,6 @@ const Control = ({ dispatch, actions, user, history, loading, socket, pepProject
const domProject = document.getElementById("news");
if (domProject) {
// newScrollbar = new PerfectScrollbar("#news", {
// suppressScrollX: true,
// });
if (domProject && newScrollbar) {
newScrollbar.update();
}
@ -513,9 +522,6 @@ const Control = ({ dispatch, actions, user, history, loading, socket, pepProject
const pomsList = document.getElementById("pomsList");
if (pomsList) {
// pomsListScrollbar = new PerfectScrollbar("#pomsList", {
// suppressScrollX: true,
// });
if (pomsList && pomsListScrollbar) {
pomsListScrollbar.update();
}
@ -523,9 +529,6 @@ const Control = ({ dispatch, actions, user, history, loading, socket, pepProject
const domProject1 = document.getElementById("overviewCalc");
if (domProject1) {
// overviewScrollbar = new PerfectScrollbar("#overviewCalc", {
// suppressScrollY: true,
// });
if (domProject1 && overviewScrollbar) {
overviewScrollbar.update();
}
@ -533,9 +536,6 @@ const Control = ({ dispatch, actions, user, history, loading, socket, pepProject
const domProject2 = document.getElementById("member");
if (domProject2) {
// memberScrollbar = new PerfectScrollbar("#member", {
// suppressScrollX: true,
// });
if (domProject2 && memberScrollbar) {
memberScrollbar.update();
}
@ -543,9 +543,6 @@ const Control = ({ dispatch, actions, user, history, loading, socket, pepProject
const domProject3 = document.getElementById("equipment");
if (domProject3) {
// equipmentScrollbar = new PerfectScrollbar("#equipment", {
// suppressScrollX: true,
// });
if (domProject3 && equipmentScrollbar) {
equipmentScrollbar.update();
}
@ -553,9 +550,6 @@ const Control = ({ dispatch, actions, user, history, loading, socket, pepProject
const domProject4 = document.getElementById("web");
if (domProject4) {
// webScrollbar = new PerfectScrollbar("#web", {
// suppressScrollX: true,
// })
if (domProject4 && webScrollbar) {
webScrollbar.update();
}
@ -563,9 +557,6 @@ const Control = ({ dispatch, actions, user, history, loading, socket, pepProject
const domProject5 = document.getElementById("problems");
if (domProject5) {
// problemsScrollbar = new PerfectScrollbar("#problems", {
// suppressScrollX: true,
// });
if (domProject5 && problemsScrollbar) {
problemsScrollbar.update();
}
@ -573,17 +564,11 @@ const Control = ({ dispatch, actions, user, history, loading, socket, pepProject
const domProject6 = document.getElementById("alarm");
if (domProject6) {
// alarmScrollbar = new PerfectScrollbar("#alarm", {
// suppressScrollY: true,
// });
if (domProject6 && alarmScrollbar) {
alarmScrollbar.update();
}
}
// ACTION
// dispatch(actions.example.getMembers(user.orgId))
})
const consoleToollink = () => {
@ -625,8 +610,6 @@ const Control = ({ dispatch, actions, user, history, loading, socket, pepProject
let Select = {
overall: ['workbench', 'statistical', 'analyse', 'dynamic', 'tool'],
workbench: ['project', 'data', 'app', 'device'],
@ -672,8 +655,6 @@ const Control = ({ dispatch, actions, user, history, loading, socket, pepProject
{ name: 'BI分析模块', sort: 3, key: 'analyse', },
{ name: '最新动态', sort: 4, key: 'dynamic', },
{ name: '我常用的工具', sort: 5, key: 'tool', },
]
useEffect(() => {
@ -1245,8 +1226,8 @@ const Control = ({ dispatch, actions, user, history, loading, socket, pepProject
}} />
</div>
</div>
<div id='news' style={{ height: 578, position: 'relative', marginTop: 10, }}>
<div id='line' style={{ width: '100%' }}>
<div id='news' style={{ height: 578, position: 'relative', marginTop: 10, overscrollBehavior: 'contain', }}>
<div id='line' style={{ width: '100%', }}>
<Timeline mode="center" style={{ marginLeft: '-56px', width: 400 }}>
{querydata.current?.map((v, index) => {
let title = ''
@ -1256,8 +1237,13 @@ const Control = ({ dispatch, actions, user, history, loading, socket, pepProject
title = v.userName ? (v.userName + '确认并关闭' + v.project + '【' + v.sources + '】' + v.type + '的问题') :
v.project + '【' + v.sources + '】' + v.type + '已恢复'
} else {
title = '【信鸽-' + v.alarmPushConfig + '】已邮件通知' +
v.userName?.map((u, i) => (i > 0 ? ',' + u : u)) + '【' + v.project + '】【' +
title =
'【信鸽-' + v.alarmPushConfig + '】已邮件通知'
+
v.userName?.map((u, i) => (i > 0 ? ',' + u : u))
+ '【' + v.project
+ '】【'
+
(v.tactics == 'immediately' ?
'发现在' + v.interval + '分钟内,有告警源新增' :
(v.tactics == 'continue' ? '告警源持续产生时间超过' + v.interval + '分钟' : '异常设备数量达到项目或结构物内设备总数量的' +

Loading…
Cancel
Save