Browse Source

批量录入摄像头

dev_trial
巴林闲侠 2 years ago
parent
commit
bc9ea4cb10
  1. 17
      code/VideoAccess-VCMP/script/1.3.6/data/1_update_status_code_data/.vscode/launch.json
  2. 78
      code/VideoAccess-VCMP/script/1.3.6/data/1_update_status_code_data/index.js
  3. 17
      code/VideoAccess-VCMP/script/1.3.6/data/1_update_status_code_data/package.json
  4. BIN
      code/VideoAccess-VCMP/script/1.3.6/data/1_update_status_code_data/摄像头信息对接.xlsx

17
code/VideoAccess-VCMP/script/1.3.6/data/1_update_status_code_data/.vscode/launch.json

@ -0,0 +1,17 @@
{
// 使 IntelliSense
//
// 访: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "启动程序",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}\\index.js"
}
]
}

78
code/VideoAccess-VCMP/script/1.3.6/data/1_update_status_code_data/index.js

@ -0,0 +1,78 @@
try {
const { Pool, Client } = require('pg')
const XLSX = require('xlsx')
const path = require('path')
const moment = require('moment')
// 连接数据库
const pool = new Pool({
user: 'postgres',
host: '10.8.30.32',
database: 'video_access',
password: '123',
port: 5432,
})
const fun = async () => {
// note: we don't try/catch this because if connecting throws an exception
// we don't need to dispose of the client (it will be undefined)
const client = await pool.connect()
try {
await client.query('BEGIN')
// 读取数据文件
let workbook = XLSX.readFile(path.join(__dirname, '摄像头信息对接.xlsx'))
let firstSheetName = workbook.SheetNames[0];
let worksheet = workbook.Sheets[firstSheetName];
let res = XLSX.utils.sheet_to_json(worksheet);
// console.log(res);
const yingshiSecretRes = await client.query(`SELECT * FROM secret_yingshi WHERE key='88c43faadfd545baaaadbb1a84a060d5'`)
console.log(yingshiSecretRes);
let secretRes = null
if (yingshiSecretRes && yingshiSecretRes.rows && yingshiSecretRes.rows.length) {
secretRes = yingshiSecretRes.rows[0]
} else {
throw '没有目标 SECRET'
}
for (let d of res) {
console.log(`处理${d['设备序列号']} ${d['通道号']} USER ${d['userid']}`);
let gbRes = await client.query(`SELECT * FROM "gbCamera" WHERE ipctype=$1 AND streamid=$2`, ['yingshi', d['设备序列号']])
let gb = null
if (gbRes.rows.length) {
gb = gbRes.rows[0]
} else {
console.log(`GB 里没查到`)
continue
}
let cameraRes = await client.query(`SELECT * FROM camera WHERE type=$1 AND serial_no=$2 AND create_user_id=$3 AND channel_no=$4`, ['yingshi', d['设备序列号'], d['userid'], d['通道号']]);
let cameraRows = cameraRes.rows
if (cameraRows.length) {
console.log(`添加过了`);
} else {
await client.query(`INSERT INTO "camera" (type, name, serial_no, cloud_control, high_definition, voice, longitude,latitude, forbidden, create_time, delete, create_user_id, yingshi_secret_id, gb_id, channel_no, kind_id) VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16)`, ['yingshi', gb.name || null, d['设备序列号'], false, true, false, 115.88, 28.54, false, moment().format('YYYY-MM-DD HH:mm:ss'), false, d['userid'], secretRes.id, gb.id, d['通道号'], 1]);
}
}
// await client.query('ROLLBACK')
await client.query('COMMIT')
console.log('执行完毕~')
} catch (e) {
await client.query('ROLLBACK')
console.log('执行错误~')
throw e
} finally {
client.release();
}
}
fun()
} catch (error) {
console.error(error)
}

17
code/VideoAccess-VCMP/script/1.3.6/data/1_update_status_code_data/package.json

@ -0,0 +1,17 @@
{
"name": "appkey-generator",
"version": "1.0.0",
"description": "tool",
"main": "index.js",
"scripts": {
"test": "mocha",
"start": "set NODE_ENV=development&&node index"
},
"author": "liu",
"license": "ISC",
"dependencies": {
"moment": "^2.29.4",
"pg": "^7.18.2",
"xlsx": "^0.17.1"
}
}

BIN
code/VideoAccess-VCMP/script/1.3.6/data/1_update_status_code_data/摄像头信息对接.xlsx

Binary file not shown.
Loading…
Cancel
Save