Browse Source

已绑定项目返回删除状态

dev
巴林闲侠 2 years ago
parent
commit
c03192825b
  1. 95
      api/app/lib/controllers/alarm/app.js
  2. 2
      api/app/lib/controllers/project/bind.js
  3. 11
      api/app/lib/controllers/project/index.js
  4. 5
      api/app/lib/index.js
  5. 18
      api/app/lib/models/app_alarm.js
  6. 2
      api/sequelize-automate.config.js
  7. 6
      script/0.0.3/1.alert_app_alarm.sql

95
api/app/lib/controllers/alarm/app.js

@ -178,10 +178,96 @@ async function apiErrorList (ctx) {
try { try {
const models = ctx.fs.dc.models; const models = ctx.fs.dc.models;
const { clickHouse } = ctx.app.fs 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.status = 200;
ctx.body = [] ctx.body = listRes
} catch (error) { } catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400; ctx.status = 400;
@ -194,13 +280,14 @@ async function apiErrorList (ctx) {
async function confirmApiError (ctx) { async function confirmApiError (ctx) {
try { try {
const models = ctx.fs.dc.models; const models = ctx.fs.dc.models;
const { confirm, appAlarmId } = ctx.request.body const { confirm, appAlarmId = [] } = ctx.request.body
await models.AppAlarm.update({ await models.AppAlarm.update({
confirm, confirm,
confirmTime: moment().format()
}, { }, {
where: { where: {
id: appAlarmId id: { $in: appAlarmId }
} }
}) })

2
api/app/lib/controllers/project/bind.js

@ -165,7 +165,7 @@ async function del (ctx) {
del: true del: true
}, { }, {
where: { where: {
id: bindId id: { $in: bindId.split(',') }
} }
}) })

11
api/app/lib/controllers/project/index.js

@ -66,6 +66,7 @@ async function pomsProject (ctx) {
SELECT SELECT
t_pim_project.id AS id, t_pim_project.id AS id,
t_pim_project.project_name AS project_name, 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_construction.construction_status_id AS construction_status_id,
t_pim_project_state.construction_status AS construction_status t_pim_project_state.construction_status AS construction_status
FROM t_pim_project FROM t_pim_project
@ -80,15 +81,17 @@ async function pomsProject (ctx) {
const anxinProjectRes = anxinProjectIds.size ? 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) { for (let p of proRes.rows) {
const corPro = pepProjectRes.find(pp => pp.id == p.pepProjectId) const corPro = pepProjectRes.find(pp => pp.id == p.pepProjectId)
p.dataValues.pepProjectName = corPro.project_name p.dataValues.pepProjectName = corPro.project_name
p.dataValues.pepProjectIsDelete = corPro.isdelete
p.dataValues.constructionStatusId = corPro.construction_status_id p.dataValues.constructionStatusId = corPro.construction_status_id
p.dataValues.constructionStatus = corPro.construction_status p.dataValues.constructionStatus = corPro.construction_status
let nextAnxinProject = anxinProjectRes.filter(ap => p.anxinProjectId.includes(ap.id)) let nextAnxinProject = anxinProjectRes.filter(ap => p.anxinProjectId.includes(ap.id))
p.dataValues.anxinProject = nextAnxinProject p.dataValues.anxinProject = nextAnxinProject
delete p.dataValues.anxinProjectId delete p.dataValues.anxinProjectId
@ -108,8 +111,9 @@ async function projectAnxincloud (ctx) {
try { try {
const models = ctx.fs.dc.models; const models = ctx.fs.dc.models;
const { clickHouse } = ctx.app.fs 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.status = 200;
ctx.body = projectRes ctx.body = projectRes
@ -126,8 +130,9 @@ async function projectPManage (ctx) {
try { try {
const models = ctx.fs.dc.models; const models = ctx.fs.dc.models;
const { clickHouse } = ctx.app.fs 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.status = 200;
ctx.body = projectRes ctx.body = projectRes

5
api/app/lib/index.js

@ -55,7 +55,7 @@ module.exports.models = function (dc) { // dc = { orm: Sequelize对象, ORM: Seq
}); });
const { const {
AppInspection, ProjectApp, ProjectCorrelation AppInspection, ProjectApp, ProjectCorrelation, AppAlarm
} = dc.models; } = dc.models;
AppInspection.belongsTo(ProjectApp, { foreignKey: 'projectAppId', targetKey: 'id' }); 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' }); ProjectApp.belongsTo(ProjectCorrelation, { foreignKey: 'projectId', targetKey: 'id' });
ProjectCorrelation.hasMany(ProjectApp, { foreignKey: 'projectId', sourceKey: 'id' }); ProjectCorrelation.hasMany(ProjectApp, { foreignKey: 'projectId', sourceKey: 'id' });
AppAlarm.belongsTo(ProjectApp, { foreignKey: 'projectAppId', targetKey: 'id' });
ProjectApp.hasMany(AppAlarm, { foreignKey: 'projectAppId', sourceKey: 'id' });
}; };

18
api/app/lib/models/app_alarm.js

@ -108,6 +108,24 @@ module.exports = dc => {
primaryKey: false, primaryKey: false,
field: "screenshot", field: "screenshot",
autoIncrement: false 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", tableName: "app_alarm",

2
api/sequelize-automate.config.js

@ -26,7 +26,7 @@ module.exports = {
dir: './app/lib/models', // 指定输出 models 文件的目录 dir: './app/lib/models', // 指定输出 models 文件的目录
typesDir: 'models', // 指定输出 TypeScript 类型定义的文件目录,只有 TypeScript / Midway 等会有类型定义 typesDir: 'models', // 指定输出 TypeScript 类型定义的文件目录,只有 TypeScript / Midway 等会有类型定义
emptyDir: false, // !!! 谨慎操作 生成 models 之前是否清空 `dir` 以及 `typesDir` 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,则忽略改属性 skipTables: [], // 指定跳过哪些表的 models,如 ['user'];如果为 null,则忽略改属性
tsNoCheck: false, // 是否添加 `@ts-nocheck` 注释到 models 文件中 tsNoCheck: false, // 是否添加 `@ts-nocheck` 注释到 models 文件中
ignorePrefix: [], // 生成的模型名称忽略的前缀,因为 项目中有以下表名是以 t_ 开头的,在实际模型中不需要, 可以添加多个 [ 't_data_', 't_',] ,长度较长的 前缀放前面 ignorePrefix: [], // 生成的模型名称忽略的前缀,因为 项目中有以下表名是以 t_ 开头的,在实际模型中不需要, 可以添加多个 [ 't_data_', 't_',] ,长度较长的 前缀放前面

6
script/0.0.3/1.alert_app_alarm.sql

@ -1,2 +1,4 @@
alter table app_alarm alter TABLE app_alarm add screenshot varchar(1024); alter TABLE app_alarm add confirm_time timestamp
add screenshot varchar(1024); 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 '是否自动恢复';
Loading…
Cancel
Save