diff --git a/api/app/lib/controllers/device/index.js b/api/app/lib/controllers/device/index.js index 0765c2f..a84fb43 100644 --- a/api/app/lib/controllers/device/index.js +++ b/api/app/lib/controllers/device/index.js @@ -119,10 +119,17 @@ function editDevice(opts) { function deleteDevice(opts) { return async function (ctx, next) { + let message = '删除设备失败' try { const models = ctx.fs.dc.models; const { id } = ctx.params; if (id) { + let exitPointDevice = await models.PointDevice.findOne({ where: { deviceId: { $in: id.split(',') } } }) + if (exitPointDevice) { + message = '该设备已绑定点位 无法删除!' + throw new Error(message) + } + await models.Device.destroy({ where: { id: { $in: id.split(',') } @@ -137,7 +144,7 @@ function deleteDevice(opts) { } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; - ctx.body = { message: '删除设备失败' } + ctx.body = { message: message } } } }