peng.peng
2 years ago
5 changed files with 242 additions and 33 deletions
@ -0,0 +1,118 @@ |
|||
'use strict'; |
|||
function getBackupsList(opts) { |
|||
return async function (ctx, next) { |
|||
|
|||
const models = ctx.fs.dc.models; |
|||
const { page, limit, name } = ctx.query; |
|||
const Op = ctx.fs.dc.ORM.Op; |
|||
let errMsg = { message: '获取数据备份失败' } |
|||
try { |
|||
let searchWhere = { |
|||
username: { $not: 'SuperAdmin' } |
|||
} |
|||
let option = { |
|||
where: searchWhere, |
|||
order: [["id", "desc"]], |
|||
attributes: { exclude: ['password'] }, |
|||
} |
|||
|
|||
if (name) { |
|||
searchWhere.note = { $like: '%' + name + '%' }; |
|||
} |
|||
|
|||
|
|||
option.where = searchWhere |
|||
let limit_ = limit || 10; |
|||
let page_ = page || 1; |
|||
let offset = (page_ - 1) * limit_; |
|||
if (limit && page) { |
|||
option.limit = limit_ |
|||
option.offset = offset |
|||
} |
|||
|
|||
const res = await models.Backups.findAndCount(option); |
|||
ctx.status = 200; |
|||
ctx.body = res; |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
ctx.status = 400; |
|||
ctx.body = errMsg |
|||
} |
|||
} |
|||
} |
|||
|
|||
// 新增数据备份
|
|||
function addBackups(opts) { |
|||
return async function (ctx, next) { |
|||
|
|||
const models = ctx.fs.dc.models; |
|||
try { |
|||
let rslt = ctx.request.body; |
|||
await models.Backups.create(Object.assign({}, rslt)) |
|||
ctx.status = 204; |
|||
ctx.body = { message: '新建数据备份成功' } |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
ctx.status = 400; |
|||
ctx.body = { message: '新建数据备份失败' } |
|||
} |
|||
} |
|||
} |
|||
|
|||
// 修改数据备份
|
|||
function editBackups(opts) { |
|||
return async function (ctx, next) { |
|||
|
|||
try { |
|||
const models = ctx.fs.dc.models; |
|||
const { id } = ctx.params; |
|||
const body = ctx.request.body; |
|||
|
|||
|
|||
await models.Backups.update( |
|||
body, |
|||
{ where: { id: id, } } |
|||
) |
|||
ctx.status = 204; |
|||
ctx.body = { message: '修改数据备份成功' } |
|||
|
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
ctx.status = 400; |
|||
ctx.body = { message: '修改数据备份失败' } |
|||
} |
|||
} |
|||
} |
|||
|
|||
// 删除数据备份
|
|||
function deleteBackups(opts) { |
|||
return async function (ctx, next) { |
|||
|
|||
try { |
|||
const models = ctx.fs.dc.models; |
|||
const { id } = ctx.params; |
|||
|
|||
await models.Backups.destroy({ |
|||
where: { |
|||
id: id |
|||
} |
|||
}) |
|||
ctx.status = 204; |
|||
ctx.body = { message: '删除数据备份成功' } |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
ctx.status = 400; |
|||
ctx.body = { message: '删除数据备份失败' } |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
module.exports = { |
|||
getBackupsList, |
|||
addBackups, |
|||
editBackups, |
|||
deleteBackups, |
|||
|
|||
} |
@ -0,0 +1,89 @@ |
|||
/* eslint-disable*/ |
|||
|
|||
'use strict'; |
|||
|
|||
module.exports = dc => { |
|||
const DataTypes = dc.ORM; |
|||
const sequelize = dc.orm; |
|||
const Backups = sequelize.define("backups", { |
|||
id: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: true, |
|||
field: "id", |
|||
autoIncrement: true, |
|||
unique: "backups_id_uindex" |
|||
}, |
|||
note: { |
|||
type: DataTypes.STRING, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: "备注信息", |
|||
primaryKey: false, |
|||
field: "note", |
|||
autoIncrement: false |
|||
}, |
|||
databases: { |
|||
type: DataTypes.JSONB, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "databases", |
|||
autoIncrement: false |
|||
}, |
|||
size: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "size", |
|||
autoIncrement: false |
|||
}, |
|||
createTime: { |
|||
type: DataTypes.DATE, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "create_time", |
|||
autoIncrement: false |
|||
}, |
|||
completeTime: { |
|||
type: DataTypes.DATE, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: "备份完成时间", |
|||
primaryKey: false, |
|||
field: "complete_time", |
|||
autoIncrement: false |
|||
}, |
|||
state: { |
|||
type: user - defined, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "state", |
|||
autoIncrement: false |
|||
}, |
|||
source: { |
|||
type: DataTypes.TEXT, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: "备份文件路径", |
|||
primaryKey: false, |
|||
field: "source", |
|||
autoIncrement: false |
|||
} |
|||
}, { |
|||
tableName: "backups", |
|||
comment: "", |
|||
indexes: [] |
|||
}); |
|||
dc.models.Backups = Backups; |
|||
return Backups; |
|||
}; |
@ -0,0 +1,23 @@ |
|||
'use strict'; |
|||
|
|||
const backups = require('../../controllers/backups/index'); |
|||
|
|||
module.exports = function (app, router, opts, AuthCode) { |
|||
|
|||
app.fs.api.logAttr['POST/meta/backups'] = { content: '增加数据备份', visible: true }; |
|||
router.post('/meta/backups', backups.addUser(opts)) |
|||
|
|||
// 修改数据备份信息
|
|||
app.fs.api.logAttr['PUT/meta/backups/:id'] = { content: '修改数据备份信息', visible: true }; |
|||
router.put('/meta/backups/:id', backups.editUser(opts)) |
|||
|
|||
// 删除数据备份信息
|
|||
app.fs.api.logAttr['DEL/meta/backups/:id'] = { content: '删除数据备份信息', visible: true }; |
|||
router.del('/meta/backups/:id', backups.deleteUser(opts)) |
|||
|
|||
//获取数据备份信息列表
|
|||
app.fs.api.logAttr['GET/meta/backupss'] = { content: '获取数据备份信息列表', visible: true }; |
|||
router.get('/meta/backupss', backups.getUserList(opts)); |
|||
|
|||
|
|||
}; |
@ -1,5 +1,5 @@ |
|||
'use strict'; |
|||
|
|||
import Restore from './restore'; |
|||
import Restore from './backupTask'; |
|||
|
|||
export { Restore }; |
|||
|
Loading…
Reference in new issue