diff --git a/api/app/lib/controllers/alarm/app.js b/api/app/lib/controllers/alarm/app.js index edbaf63..e21b6aa 100644 --- a/api/app/lib/controllers/alarm/app.js +++ b/api/app/lib/controllers/alarm/app.js @@ -178,10 +178,96 @@ async function apiErrorList (ctx) { try { const models = ctx.fs.dc.models; const { clickHouse } = ctx.app.fs - const { } = ctx.query + const { keyword, errType, confirmState, sustainTimeStart, sustainTimeEnd, limit, page } = ctx.query + + const pepProjectSql = ` + SELECT + t_pim_project.id AS id, + t_pim_project.project_name AS project_name, + t_pim_project_construction.construction_status_id AS construction_status_id, + t_pim_project_state.construction_status AS construction_status + FROM t_pim_project + LEFT JOIN t_pim_project_construction + ON t_pim_project.id = t_pim_project_construction.project_id + LEFT JOIN t_pim_project_state + ON t_pim_project_construction.construction_status_id = t_pim_project_state.id + ` + + let findOption = { + where: { + $or: [] + }, + include: [{ + model: models.ProjectApp, + where: { + + }, + include: [{ + model: models.ProjectCorrelation, + where: { + + } + }] + }] + } + if (keyword) { + const projectRes = await clickHouse.projectManage.query(` + ${pepProjectSql} + WHERE project_name LIKE '%${keyword}%'` + ).toPromise() + if (projectRes.length) { + findOption.where.$or.push( + { + '$projectApp.projectCorrelation.pep_project_id$': { + $in: projectRes.map(p => p.id) + }, + '$projectApp.name$':{$like:`%${keyword}%`} + } + ) + } + } + + if (errType) { + if (errType = 'element') { + findOption.where.screenshot = null + } else { + findOption.where.statusCode = errType + } + } + if (confirmState) { + if (confirmState == 'confirmd') { + findOption.where.confirmTime = { $ne: null } + } else if (confirmState == 'unconfirmed') { + findOption.where.confirmTime = null + } + } + if (sustainTimeStart && sustainTimeEnd) { + findOption.where.$or = findOption.where.$or.concat([ + { + createTime: { $between: [moment(sustainTimeStart).format(), moment(sustainTimeEnd).format()] }, + }, + { + updateTime: { $between: [moment(sustainTimeStart).format(), moment(sustainTimeEnd).format()] } + }, + { + createTime: { $lte: moment(sustainTimeStart).format() }, + updateTime: { $gte: moment(sustainTimeEnd).format() }, + } + ]) + } + if (limit) { + findOption.limit = limit + } + if (page && limit) { + findOption.offset = page * limit + } + const listRes = await models.AppAlarm.findAndCountAll(findOption) + if (!keyword) { + // 没有关键字筛选 查询关联的项目信息 + } ctx.status = 200; - ctx.body = [] + ctx.body = listRes } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; @@ -194,13 +280,14 @@ async function apiErrorList (ctx) { async function confirmApiError (ctx) { try { const models = ctx.fs.dc.models; - const { confirm, appAlarmId } = ctx.request.body + const { confirm, appAlarmId = [] } = ctx.request.body await models.AppAlarm.update({ confirm, + confirmTime: moment().format() }, { where: { - id: appAlarmId + id: { $in: appAlarmId } } }) diff --git a/api/app/lib/controllers/project/bind.js b/api/app/lib/controllers/project/bind.js index 8dc1fc0..3a86e08 100644 --- a/api/app/lib/controllers/project/bind.js +++ b/api/app/lib/controllers/project/bind.js @@ -165,7 +165,7 @@ async function del (ctx) { del: true }, { where: { - id: bindId + id: { $in: bindId.split(',') } } }) diff --git a/api/app/lib/controllers/project/index.js b/api/app/lib/controllers/project/index.js index 82ee2f5..571bb47 100644 --- a/api/app/lib/controllers/project/index.js +++ b/api/app/lib/controllers/project/index.js @@ -66,6 +66,7 @@ async function pomsProject (ctx) { SELECT t_pim_project.id AS id, t_pim_project.project_name AS project_name, + t_pim_project.isdelete AS isdelete, t_pim_project_construction.construction_status_id AS construction_status_id, t_pim_project_state.construction_status AS construction_status FROM t_pim_project @@ -80,15 +81,17 @@ async function pomsProject (ctx) { const anxinProjectRes = anxinProjectIds.size ? - await clickHouse.anxinyun.query(`SELECT id,"name" FROM t_project WHERE id IN (${[...anxinProjectIds].join(',')})`).toPromise() : + await clickHouse.anxinyun.query(`SELECT id,"name",project_state AS projectState FROM t_project WHERE id IN (${[...anxinProjectIds].join(',')})`).toPromise() : [] for (let p of proRes.rows) { const corPro = pepProjectRes.find(pp => pp.id == p.pepProjectId) p.dataValues.pepProjectName = corPro.project_name + p.dataValues.pepProjectIsDelete = corPro.isdelete p.dataValues.constructionStatusId = corPro.construction_status_id p.dataValues.constructionStatus = corPro.construction_status + let nextAnxinProject = anxinProjectRes.filter(ap => p.anxinProjectId.includes(ap.id)) p.dataValues.anxinProject = nextAnxinProject delete p.dataValues.anxinProjectId @@ -108,8 +111,9 @@ async function projectAnxincloud (ctx) { try { const models = ctx.fs.dc.models; const { clickHouse } = ctx.app.fs + const { includeDelete } = ctx.query - const projectRes = await clickHouse.anxinyun.query(`SELECT * FROM t_project WHERE project_state = 4 ORDER BY id DESC`).toPromise() + const projectRes = await clickHouse.anxinyun.query(`SELECT * FROM t_project WHERE project_state = 4 ${includeDelete == 1 ? 'OR project_state = -1' : ''} ORDER BY id DESC`).toPromise() ctx.status = 200; ctx.body = projectRes @@ -126,8 +130,9 @@ async function projectPManage (ctx) { try { const models = ctx.fs.dc.models; const { clickHouse } = ctx.app.fs + const { includeDelete } = ctx.query - const projectRes = await clickHouse.projectManage.query(`SELECT id, project_name FROM t_pim_project WHERE isdelete=0 ORDER BY id DESC`).toPromise() + const projectRes = await clickHouse.projectManage.query(`SELECT id, project_name, isdelete FROM t_pim_project WHERE isdelete=0 ${includeDelete == 1 ? 'OR isdelete=1' : ''} ORDER BY id DESC`).toPromise() ctx.status = 200; ctx.body = projectRes diff --git a/api/app/lib/index.js b/api/app/lib/index.js index 323a254..201f946 100644 --- a/api/app/lib/index.js +++ b/api/app/lib/index.js @@ -55,7 +55,7 @@ module.exports.models = function (dc) { // dc = { orm: Sequelize对象, ORM: Seq }); const { - AppInspection, ProjectApp, ProjectCorrelation + AppInspection, ProjectApp, ProjectCorrelation, AppAlarm } = dc.models; AppInspection.belongsTo(ProjectApp, { foreignKey: 'projectAppId', targetKey: 'id' }); @@ -63,4 +63,7 @@ module.exports.models = function (dc) { // dc = { orm: Sequelize对象, ORM: Seq ProjectApp.belongsTo(ProjectCorrelation, { foreignKey: 'projectId', targetKey: 'id' }); ProjectCorrelation.hasMany(ProjectApp, { foreignKey: 'projectId', sourceKey: 'id' }); + + AppAlarm.belongsTo(ProjectApp, { foreignKey: 'projectAppId', targetKey: 'id' }); + ProjectApp.hasMany(AppAlarm, { foreignKey: 'projectAppId', sourceKey: 'id' }); }; diff --git a/api/app/lib/models/app_alarm.js b/api/app/lib/models/app_alarm.js index fb958c7..38082f9 100644 --- a/api/app/lib/models/app_alarm.js +++ b/api/app/lib/models/app_alarm.js @@ -108,6 +108,24 @@ module.exports = dc => { primaryKey: false, field: "screenshot", autoIncrement: false + }, + confirmTime: { + type: DataTypes.DATE, + allowNull: true, + defaultValue: null, + comment: "确认时间", + primaryKey: false, + field: "confirm_time", + autoIncrement: false + }, + confirmAuto: { + type: DataTypes.BOOLEAN, + allowNull: true, + defaultValue: null, + comment: "是否自动恢复", + primaryKey: false, + field: "confirm_auto", + autoIncrement: false } }, { tableName: "app_alarm", diff --git a/api/sequelize-automate.config.js b/api/sequelize-automate.config.js index 69d5cbe..e34d53b 100644 --- a/api/sequelize-automate.config.js +++ b/api/sequelize-automate.config.js @@ -26,7 +26,7 @@ module.exports = { dir: './app/lib/models', // 指定输出 models 文件的目录 typesDir: 'models', // 指定输出 TypeScript 类型定义的文件目录,只有 TypeScript / Midway 等会有类型定义 emptyDir: false, // !!! 谨慎操作 生成 models 之前是否清空 `dir` 以及 `typesDir` - tables: ['project_correlation'], // 指定生成哪些表的 models,如 ['user', 'user_post'];如果为 null,则忽略改属性 + tables: ['app_alarm'], // 指定生成哪些表的 models,如 ['user', 'user_post'];如果为 null,则忽略改属性 skipTables: [], // 指定跳过哪些表的 models,如 ['user'];如果为 null,则忽略改属性 tsNoCheck: false, // 是否添加 `@ts-nocheck` 注释到 models 文件中 ignorePrefix: [], // 生成的模型名称忽略的前缀,因为 项目中有以下表名是以 t_ 开头的,在实际模型中不需要, 可以添加多个 [ 't_data_', 't_',] ,长度较长的 前缀放前面 diff --git a/script/0.0.3/1.alert_app_alarm.sql b/script/0.0.3/1.alert_app_alarm.sql index 0bee93d..90057e1 100644 --- a/script/0.0.3/1.alert_app_alarm.sql +++ b/script/0.0.3/1.alert_app_alarm.sql @@ -1,2 +1,4 @@ -alter table app_alarm - add screenshot varchar(1024); \ No newline at end of file +alter TABLE app_alarm add screenshot varchar(1024); alter TABLE app_alarm add confirm_time timestamp +WITH time zone; comment +ON column app_alarm.confirm_time is '确认时间'; alter TABLE app_alarm add confirm_auto bool default false; comment +ON column app_alarm.confirm_auto is '是否自动恢复'; \ No newline at end of file