diff --git a/api/app/lib/controllers/model-management/index.js b/api/app/lib/controllers/model-management/index.js new file mode 100644 index 0000000..9d04d6f --- /dev/null +++ b/api/app/lib/controllers/model-management/index.js @@ -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, + +} \ No newline at end of file diff --git a/api/app/lib/routes/model-management/index.js b/api/app/lib/routes/model-management/index.js new file mode 100644 index 0000000..3edd18b --- /dev/null +++ b/api/app/lib/routes/model-management/index.js @@ -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)); + + +}; diff --git a/web/client/src/sections/metadataManagement/actions/index.js b/web/client/src/sections/metadataManagement/actions/index.js index 444af37..aa33c73 100644 --- a/web/client/src/sections/metadataManagement/actions/index.js +++ b/web/client/src/sections/metadataManagement/actions/index.js @@ -1,7 +1,9 @@ 'use strict'; import * as example from './example' +import * as models from './model' export default { ...example, + ...models } \ No newline at end of file diff --git a/web/client/src/sections/metadataManagement/actions/model.js b/web/client/src/sections/metadataManagement/actions/model.js new file mode 100644 index 0000000..5dd01fb --- /dev/null +++ b/web/client/src/sections/metadataManagement/actions/model.js @@ -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 || '模型编辑', + }, + }); +} + diff --git a/web/client/src/utils/webapi.js b/web/client/src/utils/webapi.js index 4e0a78d..d8d1ba3 100644 --- a/web/client/src/utils/webapi.js +++ b/web/client/src/utils/webapi.js @@ -5,7 +5,11 @@ export const ApiTable = { login: 'login', logout: 'logout', validatePhone: 'validate/phone', - + + //元数据管理-模型管理 + getMetaModelList: 'meta/models', + addMetaModel: 'meta/model', + modifyMetaModel: 'meta/model/{id}', }; export const RouteTable = {