peng.peng
2 years ago
5 changed files with 199 additions and 1 deletions
@ -0,0 +1,113 @@ |
|||
'use strict'; |
|||
const moment = require('moment') |
|||
|
|||
function getModelManagementList(opts) { |
|||
return async function (ctx, next) { |
|||
|
|||
const models = ctx.fs.dc.models; |
|||
const { page, limit, modelType } = ctx.query; |
|||
const Op = ctx.fs.dc.ORM.Op; |
|||
let errMsg = { message: '获取监察任务失败' } |
|||
try { |
|||
let searchWhere = {} |
|||
let option = { |
|||
where: searchWhere, |
|||
order: [["id", "desc"]], |
|||
} |
|||
|
|||
if (modelType) { |
|||
searchWhere.modelType = modelType; |
|||
} |
|||
|
|||
option.where = searchWhere |
|||
let total = await models.MetaModel.findAll(option); |
|||
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.MetaModel.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 addModelManagement(opts) { |
|||
return async function (ctx, next) { |
|||
|
|||
const models = ctx.fs.dc.models; |
|||
try { |
|||
let rslt = ctx.request.body; |
|||
await models.MetaModel.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 editModelManagement(opts) { |
|||
return async function (ctx, next) { |
|||
|
|||
try { |
|||
const models = ctx.fs.dc.models; |
|||
const { id } = ctx.params; |
|||
const body = ctx.request.body; |
|||
await models.MetaModel.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 deleteModelManagement(opts) { |
|||
return async function (ctx, next) { |
|||
|
|||
try { |
|||
const models = ctx.fs.dc.models; |
|||
const { id } = ctx.params; |
|||
await models.MetaModel.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 = { |
|||
getModelManagementList, |
|||
addModelManagement, |
|||
editModelManagement, |
|||
deleteModelManagement, |
|||
|
|||
} |
@ -0,0 +1,23 @@ |
|||
'use strict'; |
|||
|
|||
const model = require('../../controllers/model-management/index'); |
|||
|
|||
module.exports = function (app, router, opts, AuthCode) { |
|||
|
|||
app.fs.api.logAttr['POST/meta/model'] = { content: '增加模型信息', visible: true }; |
|||
router.post('/meta/model', model.addModelManagement(opts)) |
|||
|
|||
// 修改模型信息
|
|||
app.fs.api.logAttr['PUT/meta/model/:id'] = { content: '修改模型信息', visible: true }; |
|||
router.put('/meta/model/:id', model.editModelManagement(opts)) |
|||
|
|||
// 删除模型信息
|
|||
app.fs.api.logAttr['DEL/meta/model/:id'] = { content: '删除模型信息', visible: true }; |
|||
router.del('/meta/model/:id', model.deleteModelManagement(opts)) |
|||
|
|||
//获取模型信息列表
|
|||
app.fs.api.logAttr['GET/meta/models'] = { content: '获取模型信息列表', visible: true }; |
|||
router.get('/meta/models', model.getModelManagementList(opts)); |
|||
|
|||
|
|||
}; |
@ -1,7 +1,9 @@ |
|||
'use strict'; |
|||
|
|||
import * as example from './example' |
|||
import * as models from './model' |
|||
|
|||
export default { |
|||
...example, |
|||
...models |
|||
} |
@ -0,0 +1,56 @@ |
|||
'use strict'; |
|||
|
|||
import { basicAction } from '@peace/utils' |
|||
import { ApiTable } from '$utils' |
|||
|
|||
export function getMetaModelList(query) { |
|||
return dispatch => basicAction({ |
|||
type: 'get', |
|||
dispatch: dispatch, |
|||
query: query || {}, |
|||
actionType: 'GET_METAMODEL_REPORT', |
|||
url: `${ApiTable.getMetaModelList}`, |
|||
msg: { error: '获取模型列表失败' }, |
|||
reducer: { name: 'rectification' } |
|||
}); |
|||
} |
|||
|
|||
|
|||
export function addMetaModel(params) { |
|||
return (dispatch) => basicAction({ |
|||
type: 'post', |
|||
data: params, |
|||
dispatch, |
|||
actionType: 'ADD_METAMODEL_REPORT', |
|||
url: ApiTable.addMetaModel, |
|||
msg: { |
|||
option: '模型新增', |
|||
}, |
|||
}); |
|||
} |
|||
|
|||
export function deleteMetaModel(id) { |
|||
return (dispatch) => basicAction({ |
|||
type: 'del', |
|||
dispatch, |
|||
actionType: 'DELETE_METAMODEL_REPORT', |
|||
url: ApiTable.modifyMetaModel.replace('{id}', id), |
|||
msg: { |
|||
option: '模型删除', |
|||
}, |
|||
}); |
|||
} |
|||
|
|||
export function modifyMetaModel(id, params, msg) { |
|||
return (dispatch) => basicAction({ |
|||
type: 'put', |
|||
data: params, |
|||
dispatch, |
|||
actionType: 'MODIFY_METAMODEL_REPORT', |
|||
url: ApiTable.modifyMetaModel.replace('{id}', id), |
|||
msg: { |
|||
option: msg || '模型编辑', |
|||
}, |
|||
}); |
|||
} |
|||
|
Loading…
Reference in new issue