Compare commits
23 Commits
develop
...
task_config
| Author | SHA1 | Date | |
|---|---|---|---|
| 6a3c35e594 | |||
| a9f030e95f | |||
| 71f84cb25b | |||
| 13996acf5a | |||
| dd3328b96c | |||
| 47fd4d26b0 | |||
| 685e7d2f15 | |||
| edc3859ba7 | |||
| 9848de900b | |||
| b09d39f18f | |||
| 7283498e26 | |||
| 00c508fd78 | |||
| f02be97497 | |||
| 6845d78716 | |||
| 1c8c26ff25 | |||
| d4f9a6f5f4 | |||
| 7ddc9d8220 | |||
| a9114cc05f | |||
| 9cde625d0c | |||
| 9fa91fcd63 | |||
| 27a140df3d | |||
| 20a2b74e9f | |||
| 11e90e1685 |
@@ -0,0 +1,69 @@
|
||||
import TaskModal from '../../models/controller/task'
|
||||
|
||||
const task = new TaskModal()
|
||||
|
||||
export const create = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const result = await task.create(data)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const update = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const result = await task.update(data)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const updateByID = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const id = ctx.params.id
|
||||
const result = await task.updateByID(data, id)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const updateByAttr = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const attr = ctx.params.attr
|
||||
const value = ctx.params.value
|
||||
const result = await task.updateByAttr(data, attr, value)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const clearDeleted = async (ctx, next) => {
|
||||
const result = await task.clearDeleted()
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getByID = async (ctx, next) => {
|
||||
const id = ctx.params.id
|
||||
const result = await task.getByID(id)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getByAttr = async (ctx, next) => {
|
||||
const attr = ctx.params.attr
|
||||
const value = ctx.params.value
|
||||
const result = await task.getByAttr(attr, value)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getAll = async (ctx, next) => {
|
||||
const result = await task.getAll()
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
@@ -42,6 +42,15 @@ export const getByID = async (ctx, next) => {
|
||||
next()
|
||||
}
|
||||
|
||||
export const getByIDs = async (ctx, next) => {
|
||||
const index = ctx.params.channel
|
||||
const id = ctx.params.id
|
||||
const result = await recordingDataRaw.getByIDs(id, index)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getDataByID = async (ctx, next) => {
|
||||
const index = ctx.params.channel
|
||||
const id = ctx.params.id
|
||||
@@ -70,6 +79,16 @@ export const getAttrByID = async (ctx, next) => {
|
||||
next()
|
||||
}
|
||||
|
||||
export const getAttrByIDs = async (ctx, next) => {
|
||||
const index = ctx.params.channel
|
||||
const id = ctx.params.id
|
||||
const attr = ctx.params.attr
|
||||
const result = await recordingDataRaw.getByAttrIDs(id, attr, index)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getAttrByParent = async (ctx, next) => {
|
||||
const index = ctx.params.channel
|
||||
const parent = ctx.params.parent
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import upload from './upload'
|
||||
import * as api from './api'
|
||||
import * as auth from './auth'
|
||||
import * as controller from './product/controller'
|
||||
import * as device from './product/device'
|
||||
import * as collection from './file/collection'
|
||||
import * as task from './controller/task'
|
||||
import * as recordingDataMeta from './file/recording_data_meta'
|
||||
import * as recordingDataRaw from './file/recording_data_raw'
|
||||
import * as recordingDataMini from './file/recording_data_mini'
|
||||
@@ -10,7 +13,10 @@ export default {
|
||||
upload,
|
||||
api,
|
||||
auth,
|
||||
controller,
|
||||
device,
|
||||
collection,
|
||||
task,
|
||||
recordingDataMeta,
|
||||
recordingDataRaw,
|
||||
recordingDataMini
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
import ControllerModal from '../../models/product/controller'
|
||||
|
||||
const controller = new ControllerModal()
|
||||
|
||||
export const create = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const result = await controller.create(data)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const update = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const result = await controller.update(data)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const updateByID = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const id = ctx.params.id
|
||||
const result = await controller.updateByID(data, id)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const updateByAttr = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const attr = ctx.params.attr
|
||||
const value = ctx.params.value
|
||||
const result = await controller.updateByAttr(data, attr, value)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const clearDeleted = async (ctx, next) => {
|
||||
const result = await controller.clearDeleted()
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getByMac = async (ctx, next) => {
|
||||
const mac = ctx.params.mac
|
||||
const result = await controller.getByMac(mac)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getByAttr = async (ctx, next) => {
|
||||
const attr = ctx.params.attr
|
||||
const value = ctx.params.value
|
||||
const result = await controller.getByAttr(attr, value)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getAll = async (ctx, next) => {
|
||||
const result = await controller.getAll()
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
// export const createTest = async (ctx, next) => {
|
||||
// const data = {
|
||||
// name: 'test',
|
||||
// parent: -1,
|
||||
// size: 0
|
||||
// }
|
||||
// const result = await controller.create(data)
|
||||
// ctx.body = result
|
||||
|
||||
// next()
|
||||
// }
|
||||
|
||||
// export const updateTest = async (ctx, next) => {
|
||||
// const data = {
|
||||
// name: 'test121',
|
||||
// parent: -1232,
|
||||
// size: 1243
|
||||
// }
|
||||
// const id = 2
|
||||
// const result = await controller.update(data, id)
|
||||
// ctx.body = result
|
||||
|
||||
// next()
|
||||
// }
|
||||
@@ -0,0 +1,94 @@
|
||||
import DeviceModal from '../../models/product/device'
|
||||
|
||||
const device = new DeviceModal()
|
||||
|
||||
export const create = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const result = await device.create(data)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const update = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const result = await device.update(data)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const updateByID = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const id = ctx.params.id
|
||||
const result = await device.updateByID(data, id)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const updateByAttr = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const attr = ctx.params.attr
|
||||
const value = ctx.params.value
|
||||
const result = await device.updateByAttr(data, attr, value)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const clearDeleted = async (ctx, next) => {
|
||||
const result = await device.clearDeleted()
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getByMac = async (ctx, next) => {
|
||||
const mac = ctx.params.mac
|
||||
const result = await device.getByMac(mac)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getByAttr = async (ctx, next) => {
|
||||
const attr = ctx.params.attr
|
||||
const value = ctx.params.value
|
||||
const result = await device.getByAttr(attr, value)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getAll = async (ctx, next) => {
|
||||
const result = await device.getAll()
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
// export const createTest = async (ctx, next) => {
|
||||
// const data = {
|
||||
// name: 'test',
|
||||
// parent: -1,
|
||||
// size: 0
|
||||
// }
|
||||
// const result = await device.create(data)
|
||||
// ctx.body = result
|
||||
|
||||
// next()
|
||||
// }
|
||||
|
||||
// export const updateTest = async (ctx, next) => {
|
||||
// const data = {
|
||||
// name: 'test121',
|
||||
// parent: -1232,
|
||||
// size: 1243
|
||||
// }
|
||||
// const id = 2
|
||||
// const result = await device.update(data, id)
|
||||
// ctx.body = result
|
||||
|
||||
// next()
|
||||
// }
|
||||
@@ -23,6 +23,9 @@ db.Sequelize = Sequelize
|
||||
db.sequelize = sequelize
|
||||
|
||||
db.tutorials = require('./schema/tutirial.model')(sequelize, Sequelize)
|
||||
db.controllers = require('./schema/controller.model')(sequelize, Sequelize)
|
||||
db.tasks = require('./schema/task.model')(sequelize, Sequelize)
|
||||
db.devices = require('./schema/device.model')(sequelize, Sequelize)
|
||||
db.collections = require('./schema/collection.model')(sequelize, Sequelize)
|
||||
db.recording_data_metas = require('./schema/recording_data_meta.model')(sequelize, Sequelize)
|
||||
for (let i = 0; i < 32; i++) {
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
module.exports = (sequelize, Sequelize) => {
|
||||
const Controller = sequelize.define('controller', {
|
||||
name: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
spec: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
mac_address: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
ip_address: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
configuration: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {}
|
||||
},
|
||||
wifi_name: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
wifi_password: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
mqtt_id: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
mqtt_address: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
api_mqtt_address: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
// group/user: {
|
||||
// admin: [id...],
|
||||
// normal: [id...],
|
||||
// guest: [id...]
|
||||
// }
|
||||
group_auth: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {
|
||||
owner: [],
|
||||
maintainer: [],
|
||||
guest: []
|
||||
}
|
||||
},
|
||||
user_auth: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {
|
||||
owner: [],
|
||||
maintainer: [],
|
||||
guest: []
|
||||
}
|
||||
},
|
||||
device: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {
|
||||
auto_join: [],
|
||||
scanned: []
|
||||
}
|
||||
},
|
||||
device_scanned: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {}
|
||||
},
|
||||
device_auto_join: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {}
|
||||
},
|
||||
// project/task: {
|
||||
// running: [id...],
|
||||
// library: [id...]
|
||||
// }
|
||||
project: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
task: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
// task: {
|
||||
// type: Sequelize.JSONB,
|
||||
// defaultValue: {
|
||||
// running: [],
|
||||
// library: []
|
||||
// }
|
||||
// },
|
||||
software_version: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
status: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
deleted: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: false
|
||||
},
|
||||
created_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
},
|
||||
updated_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
}
|
||||
},
|
||||
{
|
||||
timestamps: false
|
||||
})
|
||||
|
||||
return Controller
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
module.exports = (sequelize, Sequelize) => {
|
||||
const Device = sequelize.define('device', {
|
||||
name: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
mac_address: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
serial_number: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
configuration: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {}
|
||||
},
|
||||
library: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
library_version: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
device_version: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
type: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
battery: {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: 0
|
||||
},
|
||||
temperature: {
|
||||
type: Sequelize.DOUBLE,
|
||||
defaultValue: 0
|
||||
},
|
||||
auto_connect: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: true
|
||||
},
|
||||
connect_priority: {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: 0
|
||||
},
|
||||
connect_time: {
|
||||
type: Sequelize.BIGINT,
|
||||
defaultValue: 0
|
||||
},
|
||||
connect_status: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: 'idle'
|
||||
},
|
||||
connect_id: {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: -1
|
||||
},
|
||||
parameter_set: {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: -1
|
||||
},
|
||||
calibration: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
user_auth: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {
|
||||
owner: [],
|
||||
maintainer: [],
|
||||
guest: []
|
||||
}
|
||||
},
|
||||
deleted: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: false
|
||||
},
|
||||
created_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
},
|
||||
updated_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
}
|
||||
},
|
||||
{
|
||||
timestamps: false
|
||||
})
|
||||
|
||||
return Device
|
||||
}
|
||||
@@ -22,12 +22,12 @@ module.exports = (sequelize, Sequelize) => {
|
||||
defaultValue: ''
|
||||
},
|
||||
size: {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: -1
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: '-1'
|
||||
},
|
||||
time_duration: {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: 0
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: '0'
|
||||
},
|
||||
configuration: {
|
||||
type: Sequelize.JSONB,
|
||||
@@ -79,7 +79,11 @@ module.exports = (sequelize, Sequelize) => {
|
||||
},
|
||||
user_auth: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {}
|
||||
defaultValue: {
|
||||
owner: [],
|
||||
maintainer: [],
|
||||
guest: []
|
||||
}
|
||||
},
|
||||
created_at: {
|
||||
type: Sequelize.DATE,
|
||||
|
||||
@@ -8,8 +8,8 @@ module.exports = (sequelize, Sequelize, i) => {
|
||||
defaultValue: 0
|
||||
},
|
||||
size: {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: -1
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: '-1'
|
||||
},
|
||||
path: {
|
||||
type: Sequelize.STRING,
|
||||
@@ -36,12 +36,12 @@ module.exports = (sequelize, Sequelize, i) => {
|
||||
defaultValue: -1
|
||||
},
|
||||
start_time: {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: -1
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: '-1'
|
||||
},
|
||||
end_time: {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: -1
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: '-1'
|
||||
},
|
||||
data_random: {
|
||||
type: Sequelize.TEXT,
|
||||
|
||||
@@ -8,8 +8,8 @@ module.exports = (sequelize, Sequelize, i) => {
|
||||
defaultValue: 0
|
||||
},
|
||||
size: {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: -1
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: '-1'
|
||||
},
|
||||
path: {
|
||||
type: Sequelize.STRING,
|
||||
@@ -32,12 +32,12 @@ module.exports = (sequelize, Sequelize, i) => {
|
||||
defaultValue: -1
|
||||
},
|
||||
start_time: {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: -1
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: '-1'
|
||||
},
|
||||
end_time: {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: -1
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: '-1'
|
||||
},
|
||||
data: {
|
||||
type: Sequelize.TEXT,
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
module.exports = (sequelize, Sequelize) => {
|
||||
const Scheduler = sequelize.define('scheduler', {
|
||||
name: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
description: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
script: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
configuration: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {}
|
||||
},
|
||||
deleted: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: false
|
||||
},
|
||||
created_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
},
|
||||
updated_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
}
|
||||
},
|
||||
{
|
||||
timestamps: false
|
||||
})
|
||||
|
||||
return Scheduler
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
module.exports = (sequelize, Sequelize) => {
|
||||
const Task = sequelize.define('task', {
|
||||
name: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
describe: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
status: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
device_config: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {}
|
||||
},
|
||||
chart_config: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {}
|
||||
},
|
||||
formula_config: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {}
|
||||
},
|
||||
controller_id: {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: -1
|
||||
},
|
||||
deleted: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: false
|
||||
},
|
||||
created_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
},
|
||||
updated_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
}
|
||||
},
|
||||
{
|
||||
timestamps: false
|
||||
})
|
||||
|
||||
return Task
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
module.exports = (sequelize, Sequelize) => {
|
||||
const User = sequelize.define('user', {
|
||||
account: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
paword: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
name: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
mail: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
configuration: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {}
|
||||
},
|
||||
devices_list: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {
|
||||
owner: [],
|
||||
maintainer: [],
|
||||
guest: []
|
||||
}
|
||||
},
|
||||
controller_list: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {
|
||||
owner: [],
|
||||
maintainer: [],
|
||||
guest: []
|
||||
}
|
||||
},
|
||||
collection_list: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {
|
||||
owner: [],
|
||||
maintainer: [],
|
||||
guest: []
|
||||
}
|
||||
},
|
||||
meta_list: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {
|
||||
owner: [],
|
||||
maintainer: [],
|
||||
guest: []
|
||||
}
|
||||
},
|
||||
deleted: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: false
|
||||
},
|
||||
created_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
},
|
||||
updated_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
}
|
||||
},
|
||||
{
|
||||
timestamps: false
|
||||
})
|
||||
|
||||
return User
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
const db = require('../../db/database')
|
||||
|
||||
// const Op = db.Sequelize.Op
|
||||
|
||||
class TaskModel {
|
||||
async create (req) {
|
||||
console.log(req)
|
||||
return db.tasks.create(req)
|
||||
}
|
||||
|
||||
async update (req) {
|
||||
const ret = await db.tasks.update(
|
||||
req,
|
||||
{
|
||||
where: {}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async updateByID (req, id) {
|
||||
const ret = await db.tasks.update(
|
||||
req,
|
||||
{
|
||||
where: {
|
||||
id: id
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async updateByAttr (req, attr, value) {
|
||||
const whereObj = {}
|
||||
const attrList = attr.split('-')
|
||||
const valueList = value.split('-')
|
||||
attrList.forEach((key, idx) => {
|
||||
whereObj[key] = valueList[idx]
|
||||
})
|
||||
|
||||
const ret = await db.tasks.update(
|
||||
req,
|
||||
{
|
||||
where: whereObj
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async clearDeleted () {
|
||||
const ret = await db.tasks.delete(
|
||||
{
|
||||
where: {
|
||||
deleted: true
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByID (id) {
|
||||
const ret = await db.tasks.findAll(
|
||||
{
|
||||
where: {
|
||||
id: id
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByName (name) {
|
||||
const ret = await db.tasks.findAll(
|
||||
{
|
||||
where: {
|
||||
name: name
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByAttr (attr, value) {
|
||||
const whereObj = {}
|
||||
const attrList = attr.split('-')
|
||||
const valueList = value.split('-')
|
||||
attrList.forEach((key, idx) => {
|
||||
whereObj[key] = valueList[idx]
|
||||
})
|
||||
|
||||
const ret = await db.tasks.findAll(
|
||||
{
|
||||
where: whereObj
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getAll () {
|
||||
const ret = await db.tasks.findAll()
|
||||
return ret
|
||||
}
|
||||
}
|
||||
|
||||
export default TaskModel
|
||||
@@ -58,7 +58,7 @@ class RecordingDataMeta {
|
||||
parent: parentOp
|
||||
},
|
||||
order: [
|
||||
['id', 'ASC']
|
||||
['id', 'DESC']
|
||||
]
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const db = require('../../db/database')
|
||||
const sequelize = require('sequelize')
|
||||
|
||||
class RecordingDataRaw {
|
||||
async create (req, index) {
|
||||
@@ -57,6 +58,19 @@ class RecordingDataRaw {
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByIDs (id, index) {
|
||||
const _id = JSON.parse('[' + id + ']')
|
||||
const ret = await db[index + '_recording_data_raws'].findAllWithStream(
|
||||
{
|
||||
batchSize: 1000,
|
||||
where: {
|
||||
id: _id
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getDataByID (id, index) {
|
||||
const ret = await db[index + '_recording_data_raws'].findAllWithStream(
|
||||
{
|
||||
@@ -85,6 +99,23 @@ class RecordingDataRaw {
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByAttrIDs (id, attr, index) {
|
||||
const attrList = attr.split('-')
|
||||
const _id = JSON.parse('[' + id + ']')
|
||||
const ord = [sequelize.literal(`ARRAY_POSITION(ARRAY[${_id}]::integer[], "id")`)]
|
||||
|
||||
const ret = await db[index + '_recording_data_raws'].findAll(
|
||||
{
|
||||
where: {
|
||||
id: _id
|
||||
},
|
||||
attributes: attrList,
|
||||
order: ord
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByAttrParent (parent, attr, index) {
|
||||
const attrList = attr.split('-')
|
||||
const ret = await db[index + '_recording_data_raws'].findAll(
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
const db = require('../../db/database')
|
||||
|
||||
// const Op = db.Sequelize.Op
|
||||
|
||||
class ControllerModel {
|
||||
async create (req) {
|
||||
console.log(req)
|
||||
return db.controllers.create(req)
|
||||
}
|
||||
|
||||
async update (req) {
|
||||
const ret = await db.controllers.update(
|
||||
req,
|
||||
{
|
||||
where: {}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async updateByID (req, id) {
|
||||
const ret = await db.controllers.update(
|
||||
req,
|
||||
{
|
||||
where: {
|
||||
id: id
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async updateByAttr (req, attr, value) {
|
||||
const whereObj = {}
|
||||
const attrList = attr.split('-')
|
||||
const valueList = value.split('-')
|
||||
attrList.forEach((key, idx) => {
|
||||
whereObj[key] = valueList[idx]
|
||||
})
|
||||
|
||||
const ret = await db.controllers.update(
|
||||
req,
|
||||
{
|
||||
where: whereObj
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async clearDeleted () {
|
||||
const ret = await db.controllers.delete(
|
||||
{
|
||||
where: {
|
||||
deleted: true
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByID (id) {
|
||||
const ret = await db.controllers.findAll(
|
||||
{
|
||||
where: {
|
||||
id: id
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByName (name) {
|
||||
const ret = await db.controllers.findAll(
|
||||
{
|
||||
where: {
|
||||
name: name
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByMac (mac) {
|
||||
const ret = await db.controllers.findAll(
|
||||
{
|
||||
where: {
|
||||
mac_address: mac
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByAttr (attr, value) {
|
||||
const whereObj = {}
|
||||
const attrList = attr.split('-')
|
||||
const valueList = value.split('-')
|
||||
attrList.forEach((key, idx) => {
|
||||
whereObj[key] = valueList[idx]
|
||||
})
|
||||
|
||||
const ret = await db.controllers.findAll(
|
||||
{
|
||||
where: whereObj
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getAll () {
|
||||
const ret = await db.controllers.findAll()
|
||||
return ret
|
||||
}
|
||||
}
|
||||
|
||||
export default ControllerModel
|
||||
@@ -0,0 +1,124 @@
|
||||
const db = require('../../db/database')
|
||||
|
||||
// const Op = db.Sequelize.Op
|
||||
|
||||
class DeviceModel {
|
||||
async create (req) {
|
||||
return db.devices.create({
|
||||
name: req.name,
|
||||
serial_number: req.serial_number,
|
||||
mac_address: req.mac_address,
|
||||
connect_priority: await db.devices.count()
|
||||
})
|
||||
}
|
||||
|
||||
async update (req) {
|
||||
const ret = await db.devices.update(
|
||||
req,
|
||||
{
|
||||
where: {}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async updateByID (req, id) {
|
||||
const ret = await db.devices.update(
|
||||
req,
|
||||
{
|
||||
where: {
|
||||
id: id
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async updateByAttr (req, attr, value) {
|
||||
const whereObj = {}
|
||||
const attrList = attr.split('-')
|
||||
const valueList = value.split('-')
|
||||
attrList.forEach((key, idx) => {
|
||||
whereObj[key] = valueList[idx]
|
||||
})
|
||||
|
||||
const ret = await db.devices.update(
|
||||
req,
|
||||
{
|
||||
where: whereObj
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async clearDeleted () {
|
||||
const ret = await db.devices.destroy(
|
||||
{
|
||||
where: {
|
||||
deleted: true
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByID (id) {
|
||||
const ret = await db.devices.findAll(
|
||||
{
|
||||
where: {
|
||||
id: id
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByName (name) {
|
||||
const ret = await db.devices.findAll(
|
||||
{
|
||||
where: {
|
||||
name: name
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByMac (mac) {
|
||||
const ret = await db.devices.findAll(
|
||||
{
|
||||
where: {
|
||||
mac_address: mac
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByAttr (attr, value) {
|
||||
const attrList = attr.split('-')
|
||||
const valueList = value.split('-')
|
||||
const whereObj = {}
|
||||
attrList.forEach((key, idx) => {
|
||||
whereObj[key] = valueList[idx]
|
||||
})
|
||||
|
||||
const ret = await db.devices.findAll(
|
||||
{
|
||||
where: whereObj
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getAll () {
|
||||
const ret = await db.devices.findAll({
|
||||
order: [
|
||||
['connect_priority', 'ASC']
|
||||
]
|
||||
})
|
||||
return ret
|
||||
}
|
||||
}
|
||||
|
||||
export default DeviceModel
|
||||
@@ -40,9 +40,11 @@ export default router
|
||||
.post('/api/file/raw/update/:channel/:id', controllers.recordingDataRaw.update)
|
||||
.get('/api/file/raw/clear_deleted/:channel/:id', controllers.recordingDataRaw.clearDeleted)
|
||||
.get('/api/file/raw/get_by_id/:channel/:id', controllers.recordingDataRaw.getByID)
|
||||
.get('/api/file/raw/get_by_ids/:channel/:id', controllers.recordingDataRaw.getByIDs)
|
||||
.get('/api/file/raw/get_data_by_id/:channel/:id', controllers.recordingDataRaw.getDataByID)
|
||||
.get('/api/file/raw/get_by_parent/:channel/:parent', controllers.recordingDataRaw.getByParent)
|
||||
.get('/api/file/raw/get_attr_by_id/:channel/:id/:attr', controllers.recordingDataRaw.getAttrByID)
|
||||
.get('/api/file/raw/get_attr_by_ids/:channel/:id/:attr', controllers.recordingDataRaw.getAttrByIDs)
|
||||
.get('/api/file/raw/get_attr_by_parent/:channel/:parent/:attr', controllers.recordingDataRaw.getAttrByParent)
|
||||
|
||||
// mini
|
||||
@@ -55,3 +57,31 @@ export default router
|
||||
.get('/api/file/mini/get_attr_by_parent/:channel/:parent/:attr', controllers.recordingDataMini.getAttrByParent)
|
||||
.get('/api/file/mini/random/get_by_id/:channel/:id', controllers.recordingDataMini.getRandomDataByID)
|
||||
.get('/api/file/mini/mean/get_by_id/:channel/:id', controllers.recordingDataMini.getMeanDataByID)
|
||||
|
||||
// device
|
||||
.post('/api/device/create', controllers.device.create)
|
||||
.post('/api/device/update', controllers.device.update)
|
||||
.post('/api/device/update_by_id/:id', controllers.device.updateByID)
|
||||
.post('/api/device/update_by_attr/:attr/:value', controllers.device.updateByAttr)
|
||||
.get('/api/device/clear_deleted/:id', controllers.device.clearDeleted)
|
||||
.get('/api/device/get_by_mac/:mac', controllers.device.getByMac)
|
||||
.get('/api/device/get_by_attr/:attr/:value', controllers.device.getByAttr)
|
||||
.get('/api/device/get/all', controllers.device.getAll)
|
||||
|
||||
// controller
|
||||
.post('/api/controller/create', controllers.controller.create)
|
||||
.post('/api/controller/update', controllers.controller.update)
|
||||
.post('/api/controller/update_by_id/:id', controllers.controller.updateByID)
|
||||
.post('/api/controller/update_by_attr/:attr/:value', controllers.controller.updateByAttr)
|
||||
.get('/api/controller/get_by_mac/:mac', controllers.controller.getByMac)
|
||||
.get('/api/controller/get_by_attr/:attr/:value', controllers.controller.getByAttr)
|
||||
.get('/api/controller/get/all', controllers.controller.getAll)
|
||||
|
||||
// task
|
||||
.post('/api/task/create', controllers.task.create)
|
||||
.post('/api/task/update', controllers.task.update)
|
||||
.post('/api/task/update_by_id/:id', controllers.task.updateByID)
|
||||
.post('/api/task/update_by_attr/:attr/:value', controllers.task.updateByAttr)
|
||||
.get('/api/task/get_by_id/:id', controllers.task.getByID)
|
||||
.get('/api/task/get_by_attr/:attr/:value', controllers.task.getByAttr)
|
||||
.get('/api/task/get/all', controllers.task.getAll)
|
||||
|
||||
Reference in New Issue
Block a user