|
|
@ -444,7 +444,7 @@ async function copy (ctx) { |
|
|
|
template: mirrorRes.template, |
|
|
|
createUser: userId, |
|
|
|
createTime: timeNow.format(), |
|
|
|
title: data.title, |
|
|
|
title: mirrorRes.title + '-副本', |
|
|
|
showHeader: mirrorRes.showHeader, |
|
|
|
publish: mirrorRes.publish, |
|
|
|
mid: timeNow.format(`ssmmHHDDMMYYYY`) |
|
|
@ -454,35 +454,79 @@ async function copy (ctx) { |
|
|
|
|
|
|
|
const newMirrorId = newMirrorRes.id |
|
|
|
let cameraStorage = {} |
|
|
|
let treeLevelOne = mirrorTrees.filter(mt => mt.level == 1) |
|
|
|
|
|
|
|
const storageTree = (node) => { |
|
|
|
// 重新存一遍树节点
|
|
|
|
const storageTree = async (node, lastNodeStorageId) => { |
|
|
|
for (let n of node) { |
|
|
|
|
|
|
|
// 创建新节点
|
|
|
|
const newTreeNodeStorageRes = await models.MirrorTree.create({ |
|
|
|
name: n.name, |
|
|
|
level: n.level, |
|
|
|
dependence: lastNodeStorageId, |
|
|
|
mirrorId: newMirrorId |
|
|
|
}, { |
|
|
|
transaction |
|
|
|
}) |
|
|
|
// 筛选老节点所下辖的摄像头
|
|
|
|
let corCamera = mirrorCameras.filter((mc) => mc.treeIds.includes(n.id)) |
|
|
|
for (let c of corCamera) { |
|
|
|
// 为摄像头存新的节点id
|
|
|
|
if (cameraStorage[c.cameraId]) { |
|
|
|
cameraStorage[c.cameraId].treeIds.push(newTreeNodeStorageRes.id) |
|
|
|
} else { |
|
|
|
cameraStorage[c.cameraId] = { |
|
|
|
treeIds: [newTreeNodeStorageRes.id], |
|
|
|
filterIds: [] |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
const nextNode = mirrorTrees.filter(mt => mt.dependence == n.id) |
|
|
|
if (nextNode.length) { |
|
|
|
await storageTree(nextNode) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
storageTree(treeLevelOne) |
|
|
|
let treeLevelOne = mirrorTrees.filter(mt => mt.level == 1) |
|
|
|
await storageTree(treeLevelOne, null) |
|
|
|
|
|
|
|
for (let { dataValues: mt } of mirrorTrees) { |
|
|
|
const newTreeNodeStorageRes = await models.MirrorTree.create({ |
|
|
|
name: c.label, |
|
|
|
level: curLevel, |
|
|
|
dependence: lastNodeStorageId, |
|
|
|
mirrorId: mirrorId_ |
|
|
|
// 重新存一遍筛选分组、筛选项
|
|
|
|
for (let { dataValues: g } of mirrorFilterGroups) { |
|
|
|
const newGroupStorageRes = await models.MirrorFilterGroup.create({ |
|
|
|
name: g.name, |
|
|
|
forbidden: g.forbidden, |
|
|
|
mirrorId: newMirrorId |
|
|
|
}, { |
|
|
|
transaction |
|
|
|
}) |
|
|
|
let corCamera = mirrorCameras.filter((mc) => { mc.treeIds.includes(mt.id) }) |
|
|
|
for (let c of corCamera) { |
|
|
|
if (cameraStorage[c.cameraId]) { |
|
|
|
cameraStorage[c.cameraId].treeIds.push(lastNodeStorageId) |
|
|
|
} else { |
|
|
|
cameraStorage[c.cameraId] = { |
|
|
|
treeIds: [lastNodeStorageId], |
|
|
|
filterIds: [] |
|
|
|
for (let { dataValues: f } of g.mirrorFilters) { |
|
|
|
const newFilterStorageRes = await models.MirrorFilter.create({ |
|
|
|
name: f.name, |
|
|
|
groupId: newGroupStorageRes.id |
|
|
|
}, { |
|
|
|
transaction |
|
|
|
}) |
|
|
|
let corCamera = mirrorCameras.filter((mc) => mc.filterIds.includes(f.id)) |
|
|
|
for (let c of corCamera) { |
|
|
|
// 为摄像头存新的节点id
|
|
|
|
if (cameraStorage[c.cameraId]) { |
|
|
|
cameraStorage[c.cameraId].filterIds.push(newFilterStorageRes.id) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
let bulkCreateCameraD = [] |
|
|
|
for (let cid in cameraStorage) { |
|
|
|
bulkCreateCameraD.push({ |
|
|
|
cameraId: cid, |
|
|
|
...cameraStorage[cid], |
|
|
|
mirrorId: newMirrorId |
|
|
|
}) |
|
|
|
} |
|
|
|
if (bulkCreateCameraD.length) { |
|
|
|
await models.MirrorCamera.bulkCreate(bulkCreateCameraD, { |
|
|
|
transaction |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
await transaction.commit(); |
|
|
|