Browse Source

管理员判重

dev
巴林闲侠 2 years ago
parent
commit
d43fc31276
  1. 86
      api/app/lib/controllers/alarm/app.js
  2. 4
      api/app/lib/controllers/organization/index.js
  3. 7
      api/app/lib/index.js
  4. 10
      api/app/lib/routes/alarm/index.js
  5. 5
      api/app/lib/routes/project/index.js

86
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,
};

4
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])]

7
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' });
};

10
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);
};

5
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);
};
Loading…
Cancel
Save