wenlele
2 years ago
16 changed files with 699 additions and 217 deletions
@ -0,0 +1,128 @@ |
|||
'use strict'; |
|||
|
|||
const moment = require('moment') |
|||
|
|||
async function inspection (ctx) { |
|||
try { |
|||
const models = ctx.fs.dc.models; |
|||
const { projectAppId, screenshot = [] } = ctx.request.body |
|||
|
|||
const now = moment().format() |
|||
const storageData = screenshot.map(s => { |
|||
return { |
|||
projectAppId, |
|||
screenshot: [s], |
|||
createTime: now, |
|||
} |
|||
}) |
|||
|
|||
await models.AppInspection.bulkCreate(storageData) |
|||
|
|||
ctx.status = 204; |
|||
} 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; |
|||
const { inspectionId } = ctx.request.body |
|||
const { userId } = ctx.fs.api |
|||
|
|||
await models.AppInspection.update({ |
|||
notedPepUserId: userId, |
|||
notedTime: moment().format() |
|||
}, { |
|||
where: { |
|||
id: inspectionId |
|||
} |
|||
}) |
|||
|
|||
ctx.status = 204; |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: error`); |
|||
ctx.status = 400; |
|||
ctx.body = { |
|||
message: typeof error == 'string' ? error : undefined |
|||
} |
|||
} |
|||
} |
|||
|
|||
async function apiError (ctx) { |
|||
try { |
|||
const models = ctx.fs.dc.models; |
|||
const { projectAppId, alarmContent, router, statusCode } = ctx.request.body |
|||
const now = moment().format() |
|||
|
|||
let storageData = { |
|||
projectAppId, alarmContent, router, statusCode |
|||
} |
|||
const existRes = await models.AppAlarm.findOne({ |
|||
where: { |
|||
projectAppId, alarmContent, router, statusCode, |
|||
confirm: null |
|||
} |
|||
}) |
|||
if (existRes) { |
|||
await models.AppAlarm.update({ |
|||
updateTime: now |
|||
}, { |
|||
where: { |
|||
id: existRes.id |
|||
} |
|||
}) |
|||
} else { |
|||
const existCount = await models.AppAlarm.count({ |
|||
where: { |
|||
|
|||
} |
|||
}) |
|||
storageData.serialNumber = 'WEB' + (existCount < 9 ? '0' + (existCount + 1) : existCount) |
|||
storageData.createTime = now |
|||
await models.AppAlarm.create(storageData) |
|||
} |
|||
|
|||
ctx.status = 200; |
|||
} 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; |
|||
const { confirm, appAlarmId } = ctx.request.body |
|||
|
|||
await models.AppAlarm.update({ |
|||
confirm, |
|||
}, { |
|||
where: { |
|||
id: appAlarmId |
|||
} |
|||
}) |
|||
|
|||
ctx.status = 204; |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: error`); |
|||
ctx.status = 400; |
|||
ctx.body = { |
|||
message: typeof error == 'string' ? error : undefined |
|||
} |
|||
} |
|||
} |
|||
|
|||
module.exports = { |
|||
inspection, |
|||
notedInspection, |
|||
apiError, |
|||
confirmApiError, |
|||
}; |
@ -0,0 +1,157 @@ |
|||
'use strict'; |
|||
|
|||
async function allDeps (ctx) { |
|||
try { |
|||
const models = ctx.fs.dc.models; |
|||
const { redis } = ctx.app |
|||
|
|||
let depRes = await redis.get('allDepartments') |
|||
if (depRes) { |
|||
depRes = JSON.parse(depRes) |
|||
depRes = depRes.departments |
|||
} |
|||
|
|||
ctx.status = 200; |
|||
ctx.body = depRes || [] |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
ctx.status = 400; |
|||
ctx.body = { |
|||
|
|||
} |
|||
} |
|||
} |
|||
|
|||
async function editUser (ctx) { |
|||
try { |
|||
const models = ctx.fs.dc.models; |
|||
const { pepUserId, role = [], correlationProject = [] } = ctx.request.body |
|||
|
|||
const existUserRes = await models.User.findOne({ |
|||
where: { |
|||
pepUserId |
|||
} |
|||
}) |
|||
|
|||
let storageData = { |
|||
pepUserId, |
|||
role, |
|||
correlationProject, |
|||
updateTime: moment().format() |
|||
} |
|||
if (existUserRes) { |
|||
// 存在且传递id 或者 不传id也存在
|
|||
// 修改 update
|
|||
if ( |
|||
role.includes('admin') |
|||
) { |
|||
storageData.role = [...new Set([...existUserRes.role, ...role])] |
|||
storageData.disabled = false |
|||
} |
|||
await models.User.update(storageData, { |
|||
where: { |
|||
pepUserId |
|||
} |
|||
}) |
|||
} else { |
|||
// 新增
|
|||
await models.User.create(storageData) |
|||
} |
|||
|
|||
ctx.status = 200 |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
ctx.status = 400; |
|||
ctx.body = { |
|||
|
|||
} |
|||
} |
|||
} |
|||
|
|||
async function putUser (ctx) { |
|||
try { |
|||
const models = ctx.fs.dc.models; |
|||
const { pomsUserId } = ctx.params |
|||
const { disabled = undefined, deleted = undefined } = ctx.request.body |
|||
const updateData = { |
|||
disabled, |
|||
deleted, |
|||
} |
|||
for (let k in updateData) { |
|||
if (updateData[k] == undefined) { |
|||
delete updateData[k] |
|||
} |
|||
} |
|||
await models.User.update(updateData, { |
|||
where: { |
|||
id: pomsUserId |
|||
} |
|||
}) |
|||
ctx.status = 204 |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
ctx.status = 400; |
|||
ctx.body = { |
|||
|
|||
} |
|||
} |
|||
} |
|||
|
|||
async function user (ctx) { |
|||
try { |
|||
const models = ctx.fs.dc.models; |
|||
const { role, limit, page, } = ctx.query |
|||
|
|||
const excludeField = ['lastInTime', 'inTimes', 'onlineDuration', 'lastInAddress', 'deleted', 'updateTime'] |
|||
|
|||
let findOption = { |
|||
attributes: { |
|||
exclude: excludeField, |
|||
}, |
|||
where: { |
|||
deleted: false, |
|||
}, |
|||
order: [['updateTime', 'DESC']] |
|||
} |
|||
if (role) { |
|||
findOption.where.role = { $contains: [role] } |
|||
} |
|||
if (limit) { |
|||
findOption.limit = limit |
|||
} |
|||
if (page && limit) { |
|||
findOption.offset = page * limit |
|||
} |
|||
|
|||
const userRes = await models.User.findAndCountAll(findOption) |
|||
|
|||
const adminRes = await models.User.findAll({ |
|||
where: { |
|||
role: { $contains: ['admin'] } |
|||
}, |
|||
attributes: { |
|||
exclude: excludeField, |
|||
}, |
|||
order: [['updateTime', 'DESC']] |
|||
}) |
|||
|
|||
ctx.status = 200 |
|||
ctx.body = { |
|||
admin: adminRes, |
|||
users: userRes |
|||
} |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
ctx.status = 400; |
|||
ctx.body = { |
|||
|
|||
} |
|||
} |
|||
} |
|||
|
|||
module.exports = { |
|||
allDeps, |
|||
editUser, |
|||
putUser, |
|||
user, |
|||
}; |
@ -0,0 +1,25 @@ |
|||
'use strict'; |
|||
|
|||
async function appList (ctx) { |
|||
try { |
|||
const models = ctx.fs.dc.models; |
|||
|
|||
const appRes = await models.ProjectApp.findAll({ |
|||
attributes: { |
|||
exclude: ['projectId'] |
|||
} |
|||
}) |
|||
ctx.status = 200; |
|||
ctx.body = appRes |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: error`); |
|||
ctx.status = 400; |
|||
ctx.body = { |
|||
message: typeof error == 'string' ? error : undefined |
|||
} |
|||
} |
|||
} |
|||
|
|||
module.exports = { |
|||
appList |
|||
}; |
@ -0,0 +1,20 @@ |
|||
|
|||
|
|||
'use strict'; |
|||
|
|||
const application = require('../../controllers/alarm/app'); |
|||
|
|||
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['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 }; |
|||
router.post('/alarm/application/api', application.apiError); |
|||
|
|||
app.fs.api.logAttr['POST/alarm/application/api_confirm'] = { content: '确认应用接口错误信息', visible: true }; |
|||
router.post('/alarm/application/api_confirm', application.confirmApiError); |
|||
}; |
@ -0,0 +1,17 @@ |
|||
'use strict'; |
|||
|
|||
const organization = require('../../controllers/organization'); |
|||
|
|||
module.exports = function (app, router, opts) { |
|||
app.fs.api.logAttr['GET/organization/deps'] = { content: '获取全部部门及其下用户', visible: true }; |
|||
router.get('/organization/deps', organization.allDeps); |
|||
|
|||
app.fs.api.logAttr['POST/organization/user'] = { content: '编辑成员', visible: true }; |
|||
router.post('/organization/user', organization.editUser); |
|||
|
|||
app.fs.api.logAttr['PUT/organization/user/:pomsUserId'] = { content: '修改成员状态', visible: true }; |
|||
router.put('/organization/user/:pomsUserId', organization.putUser); |
|||
|
|||
app.fs.api.logAttr['GET/organization/user'] = { content: '获取成员列表', visible: true }; |
|||
router.get('/organization/user', organization.user); |
|||
}; |
@ -0,0 +1,8 @@ |
|||
'use strict'; |
|||
|
|||
const project = require('../../controllers/project'); |
|||
|
|||
module.exports = function (app, router, opts) { |
|||
app.fs.api.logAttr['GET/project/app_list'] = { content: '获取应用列表', visible: true }; |
|||
router.get('/project/app_list', project.appList); |
|||
}; |
Loading…
Reference in new issue