Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1f65ad0f11 | |||
| 18c61c0996 | |||
| 451d246952 | |||
| 15d6c2cda6 | |||
| 5ad6683b81 | |||
| a646844b9a | |||
| 97993827b2 |
+1
-1
@@ -25,7 +25,7 @@ export const DB = {
|
||||
|
||||
export const pgDB = {
|
||||
host: '127.0.0.1', // 服务器地址
|
||||
port: 54321, // 数据库端口号
|
||||
port: 5432, // 数据库端口号
|
||||
username: 'biopro', // 数据库用户名
|
||||
password: 'BioProControlBox', // 数据库密码
|
||||
database: 'postgres' // 数据库名称
|
||||
|
||||
@@ -48,6 +48,16 @@ export const getByParent = async (ctx, next) => {
|
||||
next()
|
||||
}
|
||||
|
||||
export const getAttrByParent = async (ctx, next) => {
|
||||
const type = ctx.params.type
|
||||
const parent = ctx.params.parent
|
||||
const attr = ctx.params.attr
|
||||
const result = await recordingDataMeta.getByAttrParent(type, parent, attr)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getCountByParent = async (ctx, next) => {
|
||||
const type = ctx.params.type
|
||||
const parent = ctx.params.parent
|
||||
|
||||
@@ -61,6 +61,15 @@ export const getByID = async (ctx, next) => {
|
||||
next()
|
||||
}
|
||||
|
||||
export const getExistOrNotByID = async (ctx, next) => {
|
||||
const index = ctx.params.channel
|
||||
const id = ctx.params.id
|
||||
const result = await recordingDataMini.getExistOrNotByID(id, index)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getByIDs = async (ctx, next) => {
|
||||
const index = ctx.params.channel
|
||||
const id = ctx.params.id
|
||||
|
||||
@@ -9,6 +9,7 @@ import * as recordingDataMeta from './file/recording_data_meta'
|
||||
import * as recordingDataRaw from './file/recording_data_raw'
|
||||
import * as recordingDataMini from './file/recording_data_mini'
|
||||
import * as analysis from './analysis'
|
||||
import * as project from './project/project'
|
||||
|
||||
export default {
|
||||
upload,
|
||||
@@ -21,5 +22,6 @@ export default {
|
||||
recordingDataMeta,
|
||||
recordingDataRaw,
|
||||
recordingDataMini,
|
||||
analysis
|
||||
analysis,
|
||||
project
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
import ProjectModal from '../../models/project/project'
|
||||
|
||||
const project = new ProjectModal()
|
||||
|
||||
export const create = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
console.log('create', data)
|
||||
const result = await project.create(data)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const update = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const id = ctx.params.id
|
||||
const result = await project.update(data, id)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const updateByAttr = async (ctx, next) => {
|
||||
const attr = ctx.params.attr
|
||||
const value = ctx.params.value
|
||||
const result = await project.updateByAttr(attr, value)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const clearDeleted = async (ctx, next) => {
|
||||
const result = await project.clearDeleted()
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getByID = async (ctx, next) => {
|
||||
const index = ctx.params.channel
|
||||
const id = ctx.params.id
|
||||
const result = await project.getByID(id, index)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getByAttr = async (ctx, next) => {
|
||||
const attr = ctx.params.attr
|
||||
const value = ctx.params.value
|
||||
const result = await project.getByAttr(attr, value)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getAll = async (ctx, next) => {
|
||||
const result = await project.getAll()
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
+7
-6
@@ -27,6 +27,7 @@ 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.projects = require('./schema/project.model')(sequelize, Sequelize)
|
||||
db.recording_data_metas = require('./schema/recording_data_meta.model')(sequelize, Sequelize)
|
||||
for (let i = 0; i < 32; i++) {
|
||||
db[i + '_recording_data_raws'] = require('./schema/recording_data_raw.model')(sequelize, Sequelize, i)
|
||||
@@ -34,12 +35,12 @@ for (let i = 0; i < 32; i++) {
|
||||
for (let i = 0; i < 32; i++) {
|
||||
db[i + '_recording_data_minis'] = require('./schema/recording_data_mini.model')(sequelize, Sequelize, i)
|
||||
}
|
||||
for (let i = 256; i < 288; i++) {
|
||||
db[i + '_recording_data_raws'] = require('./schema/recording_data_raw.model')(sequelize, Sequelize, i)
|
||||
}
|
||||
for (let i = 256; i < 288; i++) {
|
||||
db[i + '_recording_data_minis'] = require('./schema/recording_data_mini.model')(sequelize, Sequelize, i)
|
||||
}
|
||||
// for (let i = 256; i < 288; i++) {
|
||||
// db[i + '_recording_data_raws'] = require('./schema/recording_data_raw.model')(sequelize, Sequelize, i)
|
||||
// }
|
||||
// for (let i = 256; i < 288; i++) {
|
||||
// db[i + '_recording_data_minis'] = require('./schema/recording_data_mini.model')(sequelize, Sequelize, i)
|
||||
// }
|
||||
|
||||
db.sequelize.sync()
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
module.exports = (sequelize, Sequelize) => {
|
||||
const Project = sequelize.define('project', {
|
||||
name: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
desc: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
task: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {}
|
||||
},
|
||||
device: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {}
|
||||
},
|
||||
uuid: {
|
||||
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 Project
|
||||
}
|
||||
@@ -43,10 +43,6 @@ module.exports = (sequelize, Sequelize, i) => {
|
||||
type: Sequelize.TEXT,
|
||||
defaultValue: ''
|
||||
},
|
||||
sd_data: {
|
||||
type: Sequelize.TEXT,
|
||||
defaultValue: ''
|
||||
},
|
||||
compressed: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: false
|
||||
|
||||
@@ -98,7 +98,28 @@ class RecordingDataMeta {
|
||||
return ret
|
||||
}
|
||||
|
||||
async getCountByParent (type, parent) {
|
||||
async getByAttrParent(type, parent, attr) {
|
||||
const attrList = attr.split('-')
|
||||
const collectionType = type + '::jsonb'
|
||||
const parentOp = {}
|
||||
parentOp[collectionType] = {
|
||||
[Op.contains]: '[' + parent + ']'
|
||||
}
|
||||
const ret = await db.recording_data_metas.findAll(
|
||||
{
|
||||
where: {
|
||||
parent: parentOp
|
||||
},
|
||||
attributes: attrList,
|
||||
order: [
|
||||
['id', 'DESC']
|
||||
],
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getCountByParent(type, parent) {
|
||||
const collectionType = type + '::jsonb'
|
||||
const parentOp = {}
|
||||
parentOp[collectionType] = {
|
||||
|
||||
@@ -31,11 +31,11 @@ class RecordingDataMini {
|
||||
return ret
|
||||
}
|
||||
|
||||
async clearDeleted (index) {
|
||||
async clearDeleted (index, where = { deleted: true }) {
|
||||
const ret = await db[index + '_recording_data_minis'].destroy(
|
||||
{
|
||||
where: {
|
||||
deleted: true
|
||||
...where
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -69,6 +69,17 @@ class RecordingDataMini {
|
||||
return ret
|
||||
}
|
||||
|
||||
async getExistOrNotByID (id, index) {
|
||||
const ret = await db[index + '_recording_data_minis'].findOne(
|
||||
{
|
||||
where: {
|
||||
id: id
|
||||
}
|
||||
}
|
||||
).then(token => !(token.data_mean === ''))
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByIDs (id, index) {
|
||||
const _id = JSON.parse('[' + id + ']')
|
||||
const ret = await db[index + '_recording_data_minis'].findAllWithStream(
|
||||
|
||||
@@ -37,11 +37,11 @@ class RecordingDataRaw {
|
||||
return ret
|
||||
}
|
||||
|
||||
async clearDeleted (index) {
|
||||
async clearDeleted (index, where = { deleted: true }) {
|
||||
const ret = await db[index + '_recording_data_raws'].destroy(
|
||||
{
|
||||
where: {
|
||||
deleted: true
|
||||
...where
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
const db = require('../../db/database')
|
||||
|
||||
// const Op = db.Sequelize.Op
|
||||
|
||||
class ProjectModal {
|
||||
async create (req) {
|
||||
return db.projects.create(req)
|
||||
}
|
||||
|
||||
async update (req, id) {
|
||||
if (id != null) {
|
||||
const ret = await db.projects.update(
|
||||
req,
|
||||
{
|
||||
where: {
|
||||
id: id
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
} else {
|
||||
const ret = await db.projects.update(
|
||||
req,
|
||||
{
|
||||
where: {}
|
||||
}
|
||||
)
|
||||
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.projects.update(
|
||||
req,
|
||||
{
|
||||
where: whereObj
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async clearDeleted () {
|
||||
const ret = await db.projects.destroy(
|
||||
{
|
||||
where: {
|
||||
deleted: true
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByID (id) {
|
||||
const ret = await db.projects.findAll(
|
||||
{
|
||||
where: {
|
||||
id: id
|
||||
}
|
||||
}
|
||||
)
|
||||
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.projects.findAll(
|
||||
{
|
||||
where: whereObj
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getAll () {
|
||||
const ret = await db.projects.findAll({
|
||||
order: [
|
||||
['created_at', 'ASC']
|
||||
]
|
||||
})
|
||||
return ret
|
||||
}
|
||||
}
|
||||
|
||||
export default ProjectModal
|
||||
@@ -39,6 +39,7 @@ export default router
|
||||
.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_attr_by_parent/:type/:parent/:attr', controllers.recordingDataMeta.getAttrByParent)
|
||||
.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)
|
||||
@@ -64,6 +65,7 @@ export default router
|
||||
.post('/api/file/mini/update/:channel/:id', controllers.recordingDataMini.update)
|
||||
.get('/api/file/mini/clear_deleted/:channel/:id', controllers.recordingDataMini.clearDeleted)
|
||||
.get('/api/file/mini/get_by_id/:channel/:id', controllers.recordingDataMini.getByID)
|
||||
.get('/api/file/mini/get_exist_or_not_by_id/:channel/:id', controllers.recordingDataMini.getExistOrNotByID)
|
||||
.get('/api/file/mini/get_by_parent/:channel/:parent', controllers.recordingDataMini.getByParent)
|
||||
.get('/api/file/mini/get_attr_by_id/:channel/:id/:attr', controllers.recordingDataMini.getAttrByID)
|
||||
.get('/api/file/mini/get_attr_by_parent/:channel/:parent/:attr', controllers.recordingDataMini.getAttrByParent)
|
||||
@@ -110,3 +112,13 @@ export default router
|
||||
.post('/api/task/update_by_id/:id', controllers.task.updateByID)
|
||||
// analyze
|
||||
.post('/api/analysis/spike_detect', controllers.analysis.spikeDetect)
|
||||
|
||||
// project
|
||||
.post('/api/project/create', controllers.project.create)
|
||||
.post('/api/project/update/:id', controllers.project.update)
|
||||
.post('/api/project/update_by_attr/:attr/:value', controllers.project.updateByAttr)
|
||||
.post('/api/project/update/all', controllers.project.update)
|
||||
.get('/api/project/clear_deleted/:controller_id', controllers.project.clearDeleted)
|
||||
.get('/api/project/get_by_id/:id', controllers.project.getByID)
|
||||
.get('/api/project/get_by_attr/:attr/:value', controllers.project.getByAttr)
|
||||
.get('/api/project/get/all', controllers.project.getAll)
|
||||
|
||||
Reference in New Issue
Block a user