From 59ca5889c768adf551754b683a2773f48be27780 Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Wed, 22 Feb 2023 10:13:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=B7=A1=E6=A3=80=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/patrolManage/patrolTemplate.js | 7 +++++-- api/app/lib/index.js | 3 +++ .../src/sections/patrolManage/containers/patrolTemplate.js | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/api/app/lib/controllers/patrolManage/patrolTemplate.js b/api/app/lib/controllers/patrolManage/patrolTemplate.js index fbeda4b..8f6d33a 100644 --- a/api/app/lib/controllers/patrolManage/patrolTemplate.js +++ b/api/app/lib/controllers/patrolManage/patrolTemplate.js @@ -12,6 +12,9 @@ async function getPatrolTemplate (ctx, next) { attributes: ['id', 'name'], }, { model: models.CheckItems, + }, { + model: models.PatrolPlan, + attributes: ['name'], }] }; if (limit) { @@ -129,11 +132,11 @@ async function delPatrolTemplate (ctx, next) { const { id } = ctx.params; const record = await models.PatrolPlan.findOne({ - where: { patrolTemplateId: id } + where: { templateId: id } }); if (record) { - errMsg = '不能删除有巡检记录的模板'; + errMsg = '不能删除已绑定巡检计划的模板'; throw errMsg; } diff --git a/api/app/lib/index.js b/api/app/lib/index.js index 4b465c3..66039c4 100644 --- a/api/app/lib/index.js +++ b/api/app/lib/index.js @@ -61,6 +61,9 @@ module.exports.models = function (dc) { // dc = { orm: Sequelize对象, ORM: Seq UserResource.belongsTo(User, { foreignKey: 'userId', targetKey: 'id' }); User.hasMany(UserResource, { foreignKey: 'userId', sourceKey: 'id' }); + PatrolPlan.belongsTo(PatrolTemplate, { foreignKey: 'templateId', targetKey: 'id' }); + PatrolTemplate.hasMany(PatrolPlan, { foreignKey: 'templateId', sourceKey: 'id' }); + PatrolTemplate.belongsTo(User, { foreignKey: 'createUserId', targetKey: 'id' }); User.hasMany(PatrolTemplate, { foreignKey: 'createUserId', sourceKey: 'id' }); diff --git a/web/client/src/sections/patrolManage/containers/patrolTemplate.js b/web/client/src/sections/patrolManage/containers/patrolTemplate.js index 5338668..c0e25b5 100644 --- a/web/client/src/sections/patrolManage/containers/patrolTemplate.js +++ b/web/client/src/sections/patrolManage/containers/patrolTemplate.js @@ -62,7 +62,7 @@ function PatrolTemplate (props) { } }) }}> - + },