|
|
@ -1,4 +1,5 @@ |
|
|
|
'use strict'; |
|
|
|
const fs = require('fs'); |
|
|
|
const moment = require('moment') |
|
|
|
|
|
|
|
async function edit (ctx, next) { |
|
|
@ -82,17 +83,29 @@ async function get (ctx) { |
|
|
|
nvrId: { $in: nvrIds } |
|
|
|
} |
|
|
|
}) |
|
|
|
const cameraIds = cameraRes.map(c => c.id) |
|
|
|
let createUserIds = new Set() |
|
|
|
let cameraIds = [] |
|
|
|
for (let c of cameraRes) { |
|
|
|
cameraIds.push(c.id) |
|
|
|
createUserIds.add(c.createUserId) |
|
|
|
} |
|
|
|
|
|
|
|
// 查在安心云绑定的数据
|
|
|
|
const axbindCameraRes = cameraIds.length ? |
|
|
|
await ctx.app.fs.axyRequest.get('vcmp/camera/project', { query: { token, cameraId: cameraIds.join(',') } }) |
|
|
|
: [] |
|
|
|
|
|
|
|
// 查用户信息
|
|
|
|
const createUserRes = await ctx.app.fs.authRequest.get(`user/${[...createUserIds].join(',') || -1}/message`, { query: { token } }) |
|
|
|
|
|
|
|
for (let { dataValues: n } of nvrRes) { |
|
|
|
const corCameras = cameraRes.filter(c => c.nvrId == n.id) |
|
|
|
const corBind = axbindCameraRes.filter(b => corCameras.some(c => c.id == b.cameraId)) |
|
|
|
const corCreateUser = createUserRes.find(u => u.id == n.createUserId) |
|
|
|
|
|
|
|
n.createUser = { |
|
|
|
name: corCreateUser ? corCreateUser.username : '' |
|
|
|
} |
|
|
|
if (corBind.length) { |
|
|
|
n.station = [] |
|
|
|
for (let c of corBind) { |
|
|
@ -223,12 +236,52 @@ async function detail (ctx) { |
|
|
|
|
|
|
|
async function nvrExport (ctx) { |
|
|
|
try { |
|
|
|
const { models } = ctx.fs.dc |
|
|
|
const { userId, token } = ctx.fs.api |
|
|
|
const { utils: { simpleExcelDown } } = ctx.app.fs |
|
|
|
|
|
|
|
const header = [{ |
|
|
|
title: "设备名称", |
|
|
|
key: "name", |
|
|
|
}, { |
|
|
|
title: "SIP地址", |
|
|
|
key: "sip", |
|
|
|
}, { |
|
|
|
title: "设备厂家", |
|
|
|
key: "vender", |
|
|
|
}, { |
|
|
|
title: "添加账号", |
|
|
|
key: "createUser", |
|
|
|
}, { |
|
|
|
title: "通道数", |
|
|
|
key: "channelCount", |
|
|
|
}, { |
|
|
|
title: "端口", |
|
|
|
key: "port", |
|
|
|
}, { |
|
|
|
title: "设备状态", |
|
|
|
key: "state", |
|
|
|
}, { |
|
|
|
title: "创建时间", |
|
|
|
key: "createTime", |
|
|
|
}, { |
|
|
|
title: "项目名称", |
|
|
|
key: "projectName", |
|
|
|
}, { |
|
|
|
title: "pcode", |
|
|
|
key: "pcode", |
|
|
|
}, { |
|
|
|
title: "结构物", |
|
|
|
key: "structure", |
|
|
|
},]; |
|
|
|
|
|
|
|
const nvrRes = await models.Nvr.findAll({ |
|
|
|
where: { |
|
|
|
createUserId: userId, |
|
|
|
} |
|
|
|
}, |
|
|
|
include: [{ |
|
|
|
model: models.Vender |
|
|
|
}] |
|
|
|
}) |
|
|
|
const nvrIds = nvrRes.map(r => r.id) |
|
|
|
const cameraRes = await models.Camera.findAll({ |
|
|
@ -236,7 +289,12 @@ async function nvrExport (ctx) { |
|
|
|
nvrId: { $in: nvrIds } |
|
|
|
} |
|
|
|
}) |
|
|
|
const cameraIds = cameraRes.map(c => c.id) |
|
|
|
let createUserIds = new Set() |
|
|
|
let cameraIds = [] |
|
|
|
for (let c of cameraRes) { |
|
|
|
cameraIds.push(c.id) |
|
|
|
createUserIds.add(c.createUserId) |
|
|
|
} |
|
|
|
|
|
|
|
// 查在安心云绑定的数据
|
|
|
|
const axbindCameraRes = |
|
|
@ -244,20 +302,44 @@ async function nvrExport (ctx) { |
|
|
|
await ctx.app.fs.axyRequest.get('vcmp/camera/project', { query: { token, cameraId: cameraIds.join(',') } }) |
|
|
|
: [] |
|
|
|
|
|
|
|
// 查用户信息
|
|
|
|
const createUserRes = await ctx.app.fs.authRequest.get(`user/${[...createUserIds].join(',') || -1}/message`, { query: { token } }) |
|
|
|
|
|
|
|
let exportData = [] |
|
|
|
for (let { dataValues: n } of nvrRes) { |
|
|
|
const corCameras = cameraRes.filter(c => c.nvrId == n.id) |
|
|
|
const corBind = axbindCameraRes.filter(b => corCameras.some(c => c.id == b.cameraId)) |
|
|
|
const corCreateUser = createUserRes.find(u => u.id == n.createUserId) |
|
|
|
|
|
|
|
n.createUser = { |
|
|
|
name: corCreateUser ? corCreateUser.username : '' |
|
|
|
} |
|
|
|
|
|
|
|
n.vender = n.vender ? n.vender.name : '' |
|
|
|
n.createTime = moment(n.createTime).format('YYYY-MM-DD HH:mm:ss') |
|
|
|
|
|
|
|
let projectName = new Set(), |
|
|
|
pcode = new Set(), |
|
|
|
structure = new Set(); |
|
|
|
if (corBind.length) { |
|
|
|
n.station = [] |
|
|
|
for (let c of corBind) { |
|
|
|
n.station = n.station.concat(c.stations) |
|
|
|
for (let station of c.stations) { |
|
|
|
structure.add(station.structure.name) |
|
|
|
for (let project of station.structure.projects) { |
|
|
|
projectName.add(project.name) |
|
|
|
pcode.add(project.url) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
n.station = [] |
|
|
|
} |
|
|
|
n.projectName = [...projectName].join(',') |
|
|
|
n.pcode = [...pcode].join(',') |
|
|
|
n.structure = [...structure].join(',') |
|
|
|
|
|
|
|
exportData.push(n) |
|
|
|
} |
|
|
|
|
|
|
|
const filePath = '' |
|
|
|
const filePath = await simpleExcelDown({ data: exportData, header, fileName: `NVR信息列表_${userId}_${moment().format('YYYYMMDDHHmmss')}` }) |
|
|
|
const fileData = fs.readFileSync(filePath); |
|
|
|
let fileName = filePath.split('/').pop() |
|
|
|
ctx.status = 200; |
|
|
|