|
|
@ -19,7 +19,7 @@ async function edit (ctx) { |
|
|
|
name, pushWay, noticeWay, timing |
|
|
|
} |
|
|
|
if (configId) { |
|
|
|
const configRes = await models.CameraStatusConfig.findOne({ |
|
|
|
const configRes = await models.CameraStatusPushConfig.findOne({ |
|
|
|
where: { |
|
|
|
id: configId |
|
|
|
} |
|
|
@ -93,44 +93,10 @@ async function get (ctx) { |
|
|
|
|
|
|
|
const sequelize = ctx.fs.dc.ORM; |
|
|
|
let findOption = { |
|
|
|
attributes: { |
|
|
|
include: [ |
|
|
|
[sequelize.fn('COUNT', sequelize.col('cameraStatusPushMonitors.id')), 'monitorCount'], |
|
|
|
[sequelize.fn('COUNT', sequelize.col('cameraStatusPushLogs.id')), 'logCount'] |
|
|
|
], |
|
|
|
}, |
|
|
|
where: {}, |
|
|
|
order: [ |
|
|
|
[orderBy || 'id', orderDirection || 'DESC'] |
|
|
|
], |
|
|
|
distinct: true, |
|
|
|
subQuery: false, |
|
|
|
group: [ |
|
|
|
'cameraStatusPushConfig.id', |
|
|
|
'cameraStatusPushMonitors.id', |
|
|
|
'cameraStatusPushLogs.id', |
|
|
|
'cameraStatusPushReceivers.id', |
|
|
|
], |
|
|
|
include: [ |
|
|
|
{ |
|
|
|
model: models.CameraStatusPushMonitor, |
|
|
|
attributes: ['cameraId'], |
|
|
|
required: false, |
|
|
|
duplicating: true |
|
|
|
}, |
|
|
|
{ |
|
|
|
model: models.CameraStatusPushLog, |
|
|
|
attributes: [], |
|
|
|
duplicating: false, |
|
|
|
required: false, |
|
|
|
}, |
|
|
|
{ |
|
|
|
model: models.CameraStatusPushReceiver, |
|
|
|
attributes: ['receiver'], |
|
|
|
duplicating: false, |
|
|
|
required: false, |
|
|
|
}, |
|
|
|
], |
|
|
|
] |
|
|
|
} |
|
|
|
if (limit) { |
|
|
|
findOption.limit = limit |
|
|
@ -146,10 +112,65 @@ async function get (ctx) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
const configLimitRes = await models.CameraStatusPushConfig.findAll(findOption) |
|
|
|
|
|
|
|
delete findOption.limit |
|
|
|
delete findOption.offset |
|
|
|
const configIds = configLimitRes.map(c => c.id) |
|
|
|
findOption.where.id = { $in: configIds } |
|
|
|
findOption.attributes = { |
|
|
|
include: [ |
|
|
|
[sequelize.fn('COUNT', sequelize.col('cameraStatusPushMonitors.id')), 'monitorCount'], |
|
|
|
[sequelize.fn('COUNT', sequelize.col('cameraStatusPushLogs.id')), 'logCount'] |
|
|
|
], |
|
|
|
} |
|
|
|
findOption.distinct = true |
|
|
|
findOption.subQuery = false |
|
|
|
findOption.group = [ |
|
|
|
'cameraStatusPushConfig.id', |
|
|
|
'cameraStatusPushMonitors.id', |
|
|
|
'cameraStatusPushLogs.id', |
|
|
|
'cameraStatusPushReceivers.id', |
|
|
|
] |
|
|
|
findOption.order = [ |
|
|
|
[orderBy || 'id', orderDirection || 'DESC'] |
|
|
|
] |
|
|
|
findOption.include = [ |
|
|
|
{ |
|
|
|
model: models.CameraStatusPushMonitor, |
|
|
|
attributes: ['cameraId'], |
|
|
|
required: false, |
|
|
|
duplicating: true, |
|
|
|
}, |
|
|
|
{ |
|
|
|
model: models.CameraStatusPushLog, |
|
|
|
attributes: [], |
|
|
|
duplicating: false, |
|
|
|
required: false, |
|
|
|
}, |
|
|
|
{ |
|
|
|
model: models.CameraStatusPushReceiver, |
|
|
|
attributes: ['receiver'], |
|
|
|
duplicating: false, |
|
|
|
required: false, |
|
|
|
}, |
|
|
|
] |
|
|
|
|
|
|
|
const configRes = await models.CameraStatusPushConfig.findAll(findOption) |
|
|
|
|
|
|
|
delete findOption.attributes |
|
|
|
delete findOption.group |
|
|
|
delete findOption.order |
|
|
|
delete findOption.distinct |
|
|
|
delete findOption.subQuery |
|
|
|
delete findOption.include |
|
|
|
delete findOption.where.id |
|
|
|
const count = await models.CameraStatusPushConfig.count(findOption) |
|
|
|
ctx.status = 200; |
|
|
|
ctx.body = configRes |
|
|
|
ctx.body = { |
|
|
|
count: count, |
|
|
|
rows: configRes |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|
|
|
ctx.status = 400; |
|
|
@ -255,11 +276,11 @@ async function copy (ctx) { |
|
|
|
let copyConfig = JSON.parse(JSON.stringify(configRes.dataValues)) |
|
|
|
let returnConfig = JSON.parse(JSON.stringify(configRes.dataValues)) |
|
|
|
delete copyConfig.id |
|
|
|
delete copyConfig.id |
|
|
|
let cameraStatusPushMonitors = copyConfig.cameraStatusPushMonitors |
|
|
|
let cameraStatusPushReceiver = copyConfig.cameraStatusPushReceivers |
|
|
|
delete copyConfig.cameraStatusPushMonitors |
|
|
|
delete copyConfig.cameraStatusPushReceivers |
|
|
|
copyConfig.name += '-副本' |
|
|
|
copyConfig.createUser = userId |
|
|
|
let newConfig = await models.CameraStatusPushConfig.create(copyConfig, { |
|
|
|
transaction |
|
|
@ -316,6 +337,23 @@ async function pushLog (ctx) { |
|
|
|
order: [['time', 'DESC']], |
|
|
|
}) |
|
|
|
|
|
|
|
let cameraIds = new Set() |
|
|
|
for (let lr of logRes) { |
|
|
|
for (let c of lr.camera) { |
|
|
|
cameraIds.add(c) |
|
|
|
} |
|
|
|
} |
|
|
|
let cameraRes = await models.Camera.findAll({ |
|
|
|
attributes: ['id', 'name'], |
|
|
|
where: { |
|
|
|
id: { $in: Array.from(cameraIds) } |
|
|
|
} |
|
|
|
}) |
|
|
|
for (let lr of logRes) { |
|
|
|
let camera = cameraRes.filter(c => lr.camera.some(lrc => lrc == c.id)) |
|
|
|
lr.camera = camera |
|
|
|
} |
|
|
|
|
|
|
|
ctx.status = 200; |
|
|
|
ctx.body = logRes |
|
|
|
} catch (error) { |
|
|
|