From d43fc31276fb9fc48859fd84f1e4181c418ec991 Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Thu, 15 Sep 2022 17:06:42 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=91=98=E5=88=A4=E9=87=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/alarm/app.js | 86 +++++++++++++++++++ api/app/lib/controllers/organization/index.js | 4 + api/app/lib/index.js | 7 +- api/app/lib/routes/alarm/index.js | 10 ++- api/app/lib/routes/project/index.js | 5 ++ 5 files changed, 109 insertions(+), 3 deletions(-) diff --git a/api/app/lib/controllers/alarm/app.js b/api/app/lib/controllers/alarm/app.js index 7d3f599..58fe6e8 100644 --- a/api/app/lib/controllers/alarm/app.js +++ b/api/app/lib/controllers/alarm/app.js @@ -30,6 +30,73 @@ async function inspection (ctx) { } } +async function inspectionList (ctx) { + try { + const models = ctx.fs.dc.models; + const { clickHouse } = ctx.app.fs + const { timeStart, timeEnd, projectId, appId, noted } = ctx.query + + let findOption = { + where: { + + }, + order: [['id', 'DESC']], + include: [{ + model: models.ProjectApp, + required: Boolean(appId || projectId), + where: appId ? { + id: appId + } : undefined, + include: { + model: models.ProjectCorrelation, + required: Boolean(projectId), + where: projectId ? { + id: projectId + } : undefined, + attributes: { + exclude: ['anxinProjectId', 'createTime', 'createUser'] + } + } + }] + } + if (timeStart && timeEnd) { + findOption.where.createTime = { $between: [moment(timeStart).format(), moment(timeEnd).format()] } + } + if (noted) { + if (noted == 'noted') { + findOption.where.notedTime = { $ne: null } + } else if (noted == 'unnote') { + findOption.where.notedTime = null + } + } + + const inspectionRes = await models.AppInspection.findAll(findOption) + let notedUserIds = new Set() + for (let ins of inspectionRes) { + if (ins.notedPepUserId) { + notedUserIds.add(ins.notedPepUserId) + } + } + let userPepRes = notedUserIds.size ? + await clickHouse.pepEmis.query(`SELECT DISTINCT user.id AS id, "user"."name" AS name FROM user WHERE user.id IN (${[...notedUserIds].join(',')})`).toPromise() : + [] + for (let ins of inspectionRes) { + if (ins.notedPepUserId) { + const corUser = userPepRes.find(up => up.id == ins.notedPepUserId) + ins.dataValues.notedPepUser = corUser ? corUser.name : '' + } + } + ctx.status = 200; + ctx.body = inspectionRes + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: error`); + ctx.status = 400; + ctx.body = { + message: typeof error == 'string' ? error : undefined + } + } +} + async function notedInspection (ctx) { try { const models = ctx.fs.dc.models; @@ -100,6 +167,23 @@ async function apiError (ctx) { } } +async function apiErrorList (ctx) { + try { + const models = ctx.fs.dc.models; + const { clickHouse } = ctx.app.fs + const { } = ctx.query + + ctx.status = 200; + ctx.body = [] + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: error`); + ctx.status = 400; + ctx.body = { + message: typeof error == 'string' ? error : undefined + } + } +} + async function confirmApiError (ctx) { try { const models = ctx.fs.dc.models; @@ -125,7 +209,9 @@ async function confirmApiError (ctx) { module.exports = { inspection, + inspectionList, notedInspection, apiError, + apiErrorList, confirmApiError, }; \ No newline at end of file diff --git a/api/app/lib/controllers/organization/index.js b/api/app/lib/controllers/organization/index.js index 8f5e3d4..ea37a47 100644 --- a/api/app/lib/controllers/organization/index.js +++ b/api/app/lib/controllers/organization/index.js @@ -51,6 +51,10 @@ async function editUser (ctx) { if ( role.includes('admin') ) { + if (existUserRes.role.includes('admin')) { + // 已是管理员 + throw '当前人员已是管理员' + } // 正在修改为管理员 storageData.disabled = true storageData.role = [...new Set([...existUserRes.role, ...role])] diff --git a/api/app/lib/index.js b/api/app/lib/index.js index 2862fce..323a254 100644 --- a/api/app/lib/index.js +++ b/api/app/lib/index.js @@ -55,7 +55,12 @@ module.exports.models = function (dc) { // dc = { orm: Sequelize对象, ORM: Seq }); const { - + AppInspection, ProjectApp, ProjectCorrelation } = dc.models; + AppInspection.belongsTo(ProjectApp, { foreignKey: 'projectAppId', targetKey: 'id' }); + ProjectApp.hasMany(AppInspection, { foreignKey: 'projectAppId', sourceKey: 'id' }); + + ProjectApp.belongsTo(ProjectCorrelation, { foreignKey: 'projectId', targetKey: 'id' }); + ProjectCorrelation.hasMany(ProjectApp, { foreignKey: 'projectId', sourceKey: 'id' }); }; diff --git a/api/app/lib/routes/alarm/index.js b/api/app/lib/routes/alarm/index.js index 50dc0cb..7872086 100644 --- a/api/app/lib/routes/alarm/index.js +++ b/api/app/lib/routes/alarm/index.js @@ -9,12 +9,18 @@ module.exports = function (app, router, opts) { app.fs.api.logAttr['POST/alarm/application/inspection'] = { content: '保存应用巡检信息', visible: true }; router.post('/alarm/application/inspection', application.inspection); + app.fs.api.logAttr['GET/alarm/application/inspection'] = { content: '查询应用巡检信息', visible: true }; + router.get('/alarm/application/inspection', application.inspectionList); + app.fs.api.logAttr['PUT/alarm/application/noted'] = { content: '保存检验状态', visible: true }; router.put('/alarm/application/noted', application.notedInspection); - app.fs.api.logAttr['POST/alarm/application/api'] = { content: '保存应用接口错误信息', visible: true }; + app.fs.api.logAttr['POST/alarm/application/api'] = { content: '保存应用接口/元素错误信息', visible: true }; router.post('/alarm/application/api', application.apiError); - app.fs.api.logAttr['POST/alarm/application/api_confirm'] = { content: '确认应用接口错误信息', visible: true }; + app.fs.api.logAttr['GET/alarm/application/api'] = { content: '查询应用接口/元素错误信息', visible: true }; + router.get('/alarm/application/api', application.apiErrorList); + + app.fs.api.logAttr['POST/alarm/application/api_confirm'] = { content: '确认应用接口/元素错误信息', visible: true }; router.post('/alarm/application/api_confirm', application.confirmApiError); }; diff --git a/api/app/lib/routes/project/index.js b/api/app/lib/routes/project/index.js index 8f980de..8c41c72 100644 --- a/api/app/lib/routes/project/index.js +++ b/api/app/lib/routes/project/index.js @@ -10,4 +10,9 @@ module.exports = function (app, router, opts) { app.fs.api.logAttr['POST/project/bind'] = { content: '绑定安心云、项目管理项目', visible: true }; router.post('/project/bind', projectBind.bindAnxin2pep); + app.fs.api.logAttr['GET/project/anxincloud'] = { content: '获取安心云项目', visible: true }; + router.get('/project/anxincloud', project.projectAnxincloud); + + app.fs.api.logAttr['GET/project/pmanage'] = { content: '获取PEP项目管理项目', visible: true }; + router.get('/project/pmanage', project.projectPManage); }; \ No newline at end of file