Browse Source

导出通用接口 30%

release_0.0.2
yuan_yi 2 years ago
parent
commit
e175e6ade5
  1. 59
      code/VideoAccess-VCMP/api/app/lib/controllers/nvr/index.js

59
code/VideoAccess-VCMP/api/app/lib/controllers/nvr/index.js

@ -44,8 +44,8 @@ async function edit (ctx, next) {
}
async function get (ctx) {
const models = ctx.fs.dc.models;
try {
const models = ctx.fs.dc.models;
const { userId, token } = ctx.fs.api
const { limit, page, orderBy, orderDirection, keyword, venderId } = ctx.query
let findOption = {
@ -85,7 +85,9 @@ async function get (ctx) {
const cameraIds = cameraRes.map(c => c.id)
// 查在安心云绑定的数据
const axbindCameraRes = await ctx.app.fs.axyRequest.get('vcmp/camera/project', { query: { token, cameraId: cameraIds.join(',') } })
const axbindCameraRes = cameraIds.length ?
await ctx.app.fs.axyRequest.get('vcmp/camera/project', { query: { token, cameraId: cameraIds.join(',') } })
: []
for (let { dataValues: n } of nvrRes) {
const corCameras = cameraRes.filter(c => c.nvrId == n.id)
@ -140,7 +142,7 @@ async function del (ctx, next) {
nvrId,
}
})
if(cameraIds.length){
if (cameraIds.length) {
await ctx.app.fs.axyRequest.delete('vcmp/camera/project', { query: { token, cameraId: cameraIds.join(',') } })
}
@ -219,9 +221,60 @@ async function detail (ctx) {
}
}
async function nvrExport (ctx) {
try {
const { userId, token } = ctx.fs.api
const nvrRes = await models.Nvr.findAll({
where: {
createUserId: userId,
}
})
const nvrIds = nvrRes.map(r => r.id)
const cameraRes = await models.Camera.findAll({
where: {
nvrId: { $in: nvrIds }
}
})
const cameraIds = cameraRes.map(c => c.id)
// 查在安心云绑定的数据
const axbindCameraRes =
cameraIds.length ?
await ctx.app.fs.axyRequest.get('vcmp/camera/project', { query: { token, cameraId: cameraIds.join(',') } })
: []
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))
if (corBind.length) {
n.station = []
for (let c of corBind) {
n.station = n.station.concat(c.stations)
}
} else {
n.station = []
}
}
const filePath = ''
const fileData = fs.readFileSync(filePath);
let fileName = filePath.split('/').pop()
ctx.status = 200;
ctx.set('Content-Type', 'application/x-xls');
ctx.set('Content-disposition', 'attachment; filename=' + encodeURI(fileName));
ctx.body = fileData;
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {}
}
}
module.exports = {
edit,
get,
del,
detail,
nvrExport,
};
Loading…
Cancel
Save