Compare commits

...

14 Commits

Author SHA1 Message Date
peterlu14 632d65c057 [update] new route update_by_id & update_by_mac and device calibration column type varchar(255) to TEXT and update_at update 2021-08-27 17:45:52 +08:00
TommyXin e013b9dd63 get collectiong if controller ID is null (for old version) 2021-08-24 00:29:31 +08:00
TommyXin 6a85c88fb7 controller id 2021-08-20 18:22:41 +08:00
TommyXin bc687cc2de collection add controller id 2021-08-20 18:15:19 +08:00
TommyXin 4cbc3873f7 change controller api update path 2021-08-20 17:50:32 +08:00
TommyXin 5a1577db80 update mini batch 2021-08-09 23:32:05 +08:00
TommyXin f62c99c73a batch update raw&mini 2021-08-09 07:39:17 +08:00
TommyXin ac8c52b75b delete meta include subfile 2021-08-09 01:45:51 +08:00
TommyXin e240ff24b2 get meta by customer order 2021-08-07 20:29:12 +08:00
TommyXin 9fa0fd5322 meta get by attr 2021-08-07 19:51:33 +08:00
TommyXin 567855b7e5 [collection] update 2021-08-07 17:44:01 +08:00
TommyXin 8613369885 [meta] add get meta by attr&limit 2021-08-06 20:22:41 +08:00
peterlu14 88e5f0c155 [update] add route get meta all 2021-07-13 18:05:25 +08:00
TommyXin d7a3a06039 Merge branch 'task_config' 2021-07-01 21:49:31 +08:00
16 changed files with 377 additions and 67 deletions
+6 -3
View File
@@ -20,7 +20,8 @@ export const update = async (ctx, next) => {
}
export const clearDeleted = async (ctx, next) => {
const result = await collection.clearDeleted()
const controllerID = ctx.params.controller_id
const result = await collection.clearDeleted(controllerID)
ctx.body = result
next()
@@ -36,7 +37,8 @@ export const getByID = async (ctx, next) => {
export const getByName = async (ctx, next) => {
const name = ctx.params.name
const result = await collection.getByName(name)
const controllerID = ctx.params.controller_id
const result = await collection.getByName(name, controllerID)
ctx.body = result
next()
@@ -62,7 +64,8 @@ export const getByParentName = async (ctx, next) => {
}
export const getAll = async (ctx, next) => {
const result = await collection.getAll()
const controllerID = ctx.params.controller_id
const result = await collection.getAll(controllerID)
ctx.body = result
next()
@@ -6,6 +6,7 @@ const recordingDataMeta = new RecordingDataMeta()
export const create = async (ctx, next) => {
const data = ctx.request.body
console.log(auth.CheckAuth(ctx))
// console.log(data)
// console.log(ctx.request.header.authorization)
const result = await recordingDataMeta.create(data)
// console.log(result)
@@ -47,6 +48,40 @@ export const getByParent = async (ctx, next) => {
next()
}
export const getCountByParent = async (ctx, next) => {
const type = ctx.params.type
const parent = ctx.params.parent
const result = await recordingDataMeta.getCountByParent(type, parent)
ctx.body = result
next()
}
export const getByParentWithLimit = async (ctx, next) => {
const type = ctx.params.type
const parent = ctx.params.parent
const limit = ctx.params.limit
const offset = ctx.params.offset
const order = ctx.params.order
const result = await recordingDataMeta.getByParentWithLimit(type, parent, limit, offset, order)
ctx.body = result
next()
}
export const getByAttrsParentWithLimit = async (ctx, next) => {
const type = ctx.params.type
const parent = ctx.params.parent
const limit = ctx.params.limit
const offset = ctx.params.offset
const order = ctx.params.order
const attr = ctx.params.attr
const result = await recordingDataMeta.getByAttrsParentWithLimit(type, parent, limit, offset, order, attr)
ctx.body = result
next()
}
export const getByUUID = async (ctx, next) => {
const uuid = ctx.params.uuid
const result = await recordingDataMeta.getByUUID(uuid)
@@ -25,6 +25,16 @@ export const update = async (ctx, next) => {
next()
}
export const updateByIDs = async (ctx, next) => {
const index = ctx.params.channel
const data = ctx.request.body
const id = ctx.params.id
const result = await recordingDataMini.updateByIDs(data, id, index)
ctx.body = result
next()
}
// export const get = async (ctx, next) => {
// const index = ctx.params.channel
// const id = ctx.params.id
@@ -51,6 +61,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 recordingDataMini.getByIDs(id, index)
ctx.body = result
next()
}
export const getMeanDataByID = async (ctx, next) => {
const index = ctx.params.channel
const id = ctx.params.id
@@ -25,6 +25,16 @@ export const update = async (ctx, next) => {
next()
}
export const updateByIDs = async (ctx, next) => {
const index = ctx.params.channel
const data = ctx.request.body
const id = ctx.params.id
const result = await recordingDataRaw.updateByIDs(data, id, index)
ctx.body = result
next()
}
export const clearDeleted = async (ctx, next) => {
const index = ctx.params.channel
const result = await recordingDataRaw.clearDeleted(index)
+2 -1
View File
@@ -12,7 +12,8 @@ export const create = async (ctx, next) => {
export const update = async (ctx, next) => {
const data = ctx.request.body
const result = await controller.update(data)
const id = ctx.params.id
const result = await controller.update(data, id)
ctx.body = result
next()
+9
View File
@@ -27,6 +27,15 @@ export const updateByID = async (ctx, next) => {
next()
}
export const updateByMac = async (ctx, next) => {
const data = ctx.request.body
const mac = ctx.params.mac
const result = await device.updateByMac(data, mac)
ctx.body = result
next()
}
export const updateByAttr = async (ctx, next) => {
const data = ctx.request.body
const attr = ctx.params.attr
+4
View File
@@ -7,6 +7,10 @@ module.exports = (sequelize, Sequelize) => {
type: Sequelize.JSONB,
defaultValue: {}
},
controller_id: {
type: Sequelize.INTEGER,
defaultValue: -1
},
size: {
type: Sequelize.INTEGER,
defaultValue: -1
+10 -9
View File
@@ -40,6 +40,10 @@ module.exports = (sequelize, Sequelize) => {
type: Sequelize.STRING,
defaultValue: ''
},
root: {
type: Sequelize.INTEGER,
defaultValue: -1
},
// group/user: {
// admin: [id...],
// normal: [id...],
@@ -63,18 +67,15 @@ module.exports = (sequelize, Sequelize) => {
},
device: {
type: Sequelize.JSONB,
defaultValue: {
auto_join: [],
scanned: []
}
defaultValue: {}
},
device_scanned: {
type: Sequelize.JSONB,
defaultValue: {}
type: Sequelize.ARRAY(Sequelize.STRING),
defaultValue: []
},
device_auto_join: {
type: Sequelize.JSONB,
defaultValue: {}
device_connected: {
type: Sequelize.ARRAY(Sequelize.STRING),
defaultValue: []
},
// project/task: {
// running: [id...],
+7 -3
View File
@@ -55,11 +55,15 @@ module.exports = (sequelize, Sequelize) => {
defaultValue: -1
},
parameter_set: {
type: Sequelize.INTEGER,
defaultValue: -1
type: Sequelize.JSONB,
defaultValue: {}
},
running: {
type: Sequelize.BOOLEAN,
defaultValue: false
},
calibration: {
type: Sequelize.STRING,
type: Sequelize.TEXT,
defaultValue: ''
},
user_auth: {
+52 -21
View File
@@ -4,11 +4,7 @@ const Op = db.Sequelize.Op
class CollectionModel {
async create (req) {
return db.collections.create({
name: req.name,
parent: req.parent,
size: req.size
})
return db.collections.create(req)
}
async update (req, id) {
@@ -23,14 +19,26 @@ class CollectionModel {
return ret
}
async clearDeleted () {
const ret = await db.collections.delete(
{
where: {
deleted: true
async clearDeleted (controllerID) {
let ret
if (controllerID == null) {
ret = await db.collections.destroy(
{
where: {
deleted: true
}
}
}
)
)
} else {
ret = await db.collections.destroy(
{
where: {
controller_id: controllerID,
deleted: true
}
}
)
}
return ret
}
@@ -45,14 +53,26 @@ class CollectionModel {
return ret
}
async getByName (name) {
const ret = await db.collections.findAll(
{
where: {
name: name
async getByName (name, controllerID) {
let ret
if (controllerID == null) {
ret = await db.collections.findAll(
{
where: {
name: name
}
}
}
)
)
} else {
ret = await db.collections.findAll(
{
where: {
controller_id: controllerID,
name: name
}
}
)
}
return ret
}
@@ -100,8 +120,19 @@ class CollectionModel {
return ret
}
async getAll () {
const ret = await db.collections.findAll()
async getAll (controllerID) {
let ret
if (controllerID == null) {
ret = await db.collections.findAll()
} else {
ret = await db.collections.findAll(
{
where: {
controller_id: controllerID
}
}
)
}
return ret
}
}
+95 -1
View File
@@ -1,4 +1,10 @@
import RecordingDataRaw from './recording_data_raw'
import RecordingDataMini from './recording_data_mini'
const db = require('../../db/database')
// const RecordingDataMini = require('./recording_data_mini')
const recordingDataRaw = new RecordingDataRaw()
const recordingDataMini = new RecordingDataMini()
const Op = db.Sequelize.Op
@@ -36,7 +42,34 @@ class RecordingDataMeta {
}
async clearDeleted () {
const ret = await db.recording_data_metas.destroy(
let ret = await db.recording_data_metas.findAll(
{
attributes: [
'id',
'raw_data',
'mini_data'
],
where: {
deleted: true
}
}
)
for (let i = 0; i < ret.length; i++) {
const meta = ret[i]
for (const channel in meta.raw_data) {
if (meta.raw_data[channel] != null) {
await recordingDataRaw.updateByIDs({ deleted: true }, meta.raw_data[channel], channel)
recordingDataRaw.clearDeleted(channel)
}
if (meta.mini_data[channel] != null) {
await recordingDataMini.updateByIDs({ deleted: true }, meta.mini_data[channel]['10'], channel)
await recordingDataMini.updateByIDs({ deleted: true }, meta.mini_data[channel]['100'], channel)
await recordingDataMini.updateByIDs({ deleted: true }, meta.mini_data[channel]['100'], channel)
recordingDataMini.clearDeleted(channel)
}
}
}
ret = await db.recording_data_metas.destroy(
{
where: {
deleted: true
@@ -65,6 +98,67 @@ class RecordingDataMeta {
return ret
}
async getCountByParent (type, parent) {
const collectionType = type + '::jsonb'
const parentOp = {}
parentOp[collectionType] = {
[Op.contains]: '[' + parent + ']'
}
const ret = await db.recording_data_metas.count(
{
where: {
parent: parentOp
}
}
)
return ret
}
async getByParentWithLimit (type, parent, limit, offset, order) {
const collectionType = type + '::jsonb'
const parentOp = {}
parentOp[collectionType] = {
[Op.contains]: '[' + parent + ']'
}
const ret = await db.recording_data_metas.findAndCountAll(
{
where: {
parent: parentOp
},
order: [
['id', order]
],
limit: limit,
offset: offset
}
)
return ret
}
async getByAttrsParentWithLimit (type, parent, limit, offset, order, attr) {
const attrList = attr.split('-')
const orderList = order.split('-')
const collectionType = type + '::jsonb'
const parentOp = {}
parentOp[collectionType] = {
[Op.contains]: '[' + parent + ']'
}
const ret = await db.recording_data_metas.findAndCountAll(
{
where: {
parent: parentOp
},
attributes: attrList,
order: [
[orderList[0], orderList[1]]
],
limit: limit,
offset: offset
}
)
return ret
}
async getByID (id) {
const ret = await db.recording_data_metas.findAll(
{
+25
View File
@@ -19,6 +19,18 @@ class RecordingDataMini {
return ret
}
async updateByIDs (req, id, index) {
const ret = await db[index + '_recording_data_minis'].update(
req,
{
where: {
id: id
}
}
)
return ret
}
async clearDeleted (index) {
const ret = await db[index + '_recording_data_minis'].destroy(
{
@@ -57,6 +69,19 @@ class RecordingDataMini {
return ret
}
async getByIDs (id, index) {
const _id = JSON.parse('[' + id + ']')
const ret = await db[index + '_recording_data_minis'].findAllWithStream(
{
batchSize: 1000,
where: {
id: _id
}
}
)
return ret
}
async getMeanDataByID (id, index) {
const ret = await db[index + '_recording_data_minis'].findAllWithStream(
{
+12
View File
@@ -20,6 +20,18 @@ class RecordingDataRaw {
return ret
}
async updateByIDs (req, id, index) {
const ret = await db[index + '_recording_data_raws'].update(
req,
{
where: {
id: id
}
}
)
return ret
}
async clearDeleted (index) {
const ret = await db[index + '_recording_data_raws'].destroy(
{
+23 -9
View File
@@ -8,17 +8,31 @@ class ControllerModel {
return db.controllers.create(req)
}
async update (req) {
const ret = await db.controllers.update(
req,
{
where: {}
}
)
return ret
async update (req, id) {
req.updated_at = db.Sequelize.literal('CURRENT_TIMESTAMP')
if (id != null) {
const ret = await db.controllers.update(
req,
{
where: {
id: id
}
}
)
return ret
} else {
const ret = await db.controllers.update(
req,
{
where: {}
}
)
return ret
}
}
async updateByID (req, id) {
req.updated_at = db.Sequelize.literal('CURRENT_TIMESTAMP')
const ret = await db.controllers.update(
req,
{
@@ -37,7 +51,7 @@ class ControllerModel {
attrList.forEach((key, idx) => {
whereObj[key] = valueList[idx]
})
req.updated_at = db.Sequelize.literal('CURRENT_TIMESTAMP')
const ret = await db.controllers.update(
req,
{
+35 -8
View File
@@ -12,17 +12,31 @@ class DeviceModel {
})
}
async update (req) {
const ret = await db.devices.update(
req,
{
where: {}
}
)
return ret
async update (req, id) {
req.updated_at = db.Sequelize.literal('CURRENT_TIMESTAMP')
if (id != null) {
const ret = await db.devices.update(
req,
{
where: {
id: id
}
}
)
return ret
} else {
const ret = await db.devices.update(
req,
{
where: {}
}
)
return ret
}
}
async updateByID (req, id) {
req.updated_at = db.Sequelize.literal('CURRENT_TIMESTAMP')
const ret = await db.devices.update(
req,
{
@@ -34,6 +48,19 @@ class DeviceModel {
return ret
}
async updateByMac (req, mac) {
req.updated_at = db.Sequelize.literal('CURRENT_TIMESTAMP')
const ret = await db.devices.update(
req,
{
where: {
mac_address: mac
}
}
)
return ret
}
async updateByAttr (req, attr, value) {
const whereObj = {}
const attrList = attr.split('-')
+33 -12
View File
@@ -17,23 +17,34 @@ export default router
.get('/public/auth/get_cookie', controllers.auth.getCookie)
// collection
.post('/api/collection/create', controllers.collection.create)
.get('/api/collection/get_by_id/:id', controllers.collection.getByID)
.get('/api/collection/get_by_name/:name', controllers.collection.getByName)
.get('/api/collection/get_by_parent/:type/:parent', controllers.collection.getByParent)
.get('/api/collection/get_by_parent_name/:type/:parent/:name', controllers.collection.getByParentName)
.get('/api/collection/get/all', controllers.collection.getAll)
.post('/api/file/collection/create', controllers.collection.create)
.post('/api/file/collection/update/:id', controllers.collection.update)
.get('/api/file/collection/clear_deleted/:controller_id', controllers.collection.clearDeleted)
.get('/api/file/collection/get_by_id/:id', controllers.collection.getByID)
.get('/api/file/collection/get_by_name/:name/:controller_id', controllers.collection.getByName)
.get('/api/file/collection/get_by_parent/:type/:parent', controllers.collection.getByParent)
.get('/api/file/collection/get_by_parent_name/:type/:parent/:name', controllers.collection.getByParentName)
.get('/api/file/collection/get/all/:controller_id', controllers.collection.getAll)
.get('/api/file/collection/get_by_name/:name', controllers.collection.getByName)
.get('/api/file/collection/get/all', controllers.collection.getAll)
.get('/api/file/collection/clear_deleted/', controllers.collection.clearDeleted)
// meta
.post('/api/file/meta/create', controllers.recordingDataMeta.create)
.post('/api/file/meta/update/:id', controllers.recordingDataMeta.update)
.get('/api/file/meta/clear_deleted/:id', controllers.recordingDataMeta.clearDeleted)
.get('/api/file/meta/clear_deleted/', controllers.recordingDataMeta.clearDeleted)
.get('/api/file/meta/get_by_name/:name', controllers.recordingDataMeta.getByName)
.get('/api/file/meta/get_by_uuid/:uuid', controllers.recordingDataMeta.getByUUID)
.get('/api/file/meta/get_by_id/:id', controllers.recordingDataMeta.getByID)
.get('/api/file/meta/get_by_path/:path', controllers.recordingDataMeta.getByPath)
.get('/api/file/meta/get_by_parent/:type/:parent', controllers.recordingDataMeta.getByParent)
.get('/api/file/meta/get_count_by_parent/:type/:parent', controllers.recordingDataMeta.getCountByParent)
.get('/api/file/meta/get_by_parent_with_limit/:type/:parent/:limit/:offset/:order', controllers.recordingDataMeta.getByParentWithLimit)
.get('/api/file/meta/get_by_attr_parent_with_limit/:type/:parent/:limit/:offset/:order/:attr', controllers.recordingDataMeta.getByAttrsParentWithLimit)
.get('/api/file/meta/get_or_create_by_path/:path', controllers.recordingDataMeta.getOrCreateByPath)
.get('/api/file/meta/get/all', controllers.recordingDataMeta.getAll)
// raw
.post('/api/file/raw/create/:channel', controllers.recordingDataRaw.create)
@@ -60,28 +71,38 @@ export default router
// device
.post('/api/device/create', controllers.device.create)
.post('/api/device/update', controllers.device.update)
.post('/api/device/update/all', controllers.device.update)
.post('/api/device/update_by_id/:id', controllers.device.updateByID)
.post('/api/device/update_by_mac/:mac', controllers.device.updateByMac)
.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)
.post('/api/device/update_by_id/:id', controllers.device.updateByID)
.post('/api/device/update', controllers.device.update)
// 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/:id', controllers.controller.update)
.post('/api/controller/update/all', controllers.controller.update)
.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)
.post('/api/controller/update_by_id/:id', controllers.controller.updateByID)
.post('/api/controller/update', controllers.controller.update)
// 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/:id', controllers.task.update)
.post('/api/task/update_by_attr/:attr/:value', controllers.task.updateByAttr)
.post('/api/task/update/all', controllers.task.update)
.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)
.post('/api/task/update', controllers.task.update)
.post('/api/task/update_by_id/:id', controllers.task.updateByID)