Browse Source

服务查询

master
wenlele 2 years ago
parent
commit
96747f31bc
  1. 88
      api/app/lib/controllers/dataService/index.js
  2. 4
      api/app/lib/controllers/latestMetadata/index.js
  3. 9
      api/app/lib/index.js
  4. 11
      api/app/lib/models/resource_consumption.js
  5. 8
      api/app/lib/models/restful_api_record.js
  6. 16
      api/app/lib/routes/dataService/index.js
  7. 7
      scripts/0.0.9/01_alter_t_restful_api.sql
  8. 78
      web/client/src/sections/dataService/actions/documentLibrary.js
  9. 15
      web/client/src/sections/dataService/actions/example.js
  10. 12
      web/client/src/sections/dataService/actions/index.js
  11. 52
      web/client/src/sections/dataService/actions/ruleLibrary.js
  12. 42
      web/client/src/sections/dataService/actions/serviceManagement.js
  13. 14
      web/client/src/sections/dataService/containers/serviceManagement.js
  14. 31
      web/client/src/sections/metadataManagement/components/releaseModal.js
  15. 7
      web/client/src/utils/webapi.js

88
api/app/lib/controllers/dataService/index.js

@ -0,0 +1,88 @@
'use strict';
const moment = require('moment')
//获取REST服务失败
function getServiceManagement (opts) {
return async function (ctx, next) {
const models = ctx.fs.dc.models;
const { page, limit, keyword } = ctx.query;
try {
let option = {
where: {},
order: [["id", "desc"]],
}
if (keyword) {
option.where.name = { $iLike: `%${keyword}%` }
}
if (limit) {
option.limit = Number(limit)
}
if (page && limit) {
option.offset = Number(page) * Number(limit)
}
let res = await models.RestfulApi.findAndCount(option)
ctx.status = 200;
ctx.body = res
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = { message: '获取REST服务失败' }
}
}
}
//编辑REST服务
function postServiceManagement (opts) {
return async function (ctx, next) {
try {
const models = ctx.fs.dc.models;
const { id, name, endbled } = ctx.request.body;
await models.RestfulApi.update({ name, endbled }, { where: { id: id } })
ctx.status = 204;
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = { message: '编辑REST服务失败' }
}
}
}
//编辑REST服务
function delServiceManagement (opts) {
return async function (ctx, next) {
try {
const models = ctx.fs.dc.models;
const { id } = ctx.params;
await models.RestfulApi.destroy({
where: {
id: id
}
})
ctx.status = 204;
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = { message: '删除REST服务失败' }
}
}
}
module.exports = {
getServiceManagement,
postServiceManagement,
delServiceManagement
}

4
api/app/lib/controllers/latestMetadata/index.js

@ -837,13 +837,13 @@ async function publishingServices (ctx) {
const { method, url } = data
const postOne = await models.MetadataRestapi.findOne({ where: { method: method, url: url } });
const postOne = await models.RestfulApi.findOne({ where: { method: method, url: url } });
if (postOne) {
message = '路由和请求方式重复'
throw ''
}
await models.MetadataRestapi.create(data)
await models.RestfulApi.create(data)
ctx.body = { message: '发布REST服务成功' }
ctx.status = 200;

9
api/app/lib/index.js

@ -57,7 +57,7 @@ module.exports.models = function (dc) {
const {
DataSource, AcquisitionTask, Adapter, User, MetadataDatabase, MetadataFile, MetadataRestapi, AcquisitionLog, ResourceCatalog,
BusinessMetadataDatabase, BusinessMetadataFile, BusinessMetadataRestapi, ResourceConsumption, BusinessRule, StandardDoc, DbStatistics
, RestfulApi, RestfulApiRecord
, RestfulApi, RestfulApiRecord,
} = dc.models;
AcquisitionTask.belongsTo(DataSource, { foreignKey: 'dataSourceId', targetKey: 'id' });
@ -88,13 +88,16 @@ module.exports.models = function (dc) {
BusinessMetadataRestapi.belongsTo(User, { foreignKey: 'createBy', targetKey: 'id' });
ResourceConsumption.belongsTo(User, { foreignKey: 'applyBy', targetKey: 'id', as: "applyUser" });
// ResourceConsumption.belongsTo(RestfulApi, { foreignKey: 'restServiceId', targetKey: 'id',});
ResourceConsumption.belongsTo(User, { foreignKey: 'approveBy', targetKey: 'id', as: 'approveUser' });
BusinessRule.belongsTo(StandardDoc, { foreignKey: 'ruleBasis', targetKey: 'id' });
StandardDoc.hasMany(BusinessRule, { foreignKey: 'ruleBasis', targetKey: 'id' });
DbStatistics.belongsTo(DataSource, { foreignKey: 'sourceId', targetKey: 'id' });
DataSource.hasMany(DbStatistics, { foreignKey: 'sourceId', sourceKey: 'id' });
DataSource.hasMany(DbStatistics, { foreignKey: 'sourceId', sourceKey: 'id' })
RestfulApiRecord.belongsTo(RestfulApi, { foreignKey: 'restServiceId', targetKey: 'id' });
RestfulApi.belongsTo(RestfulApiRecord, { foreignKey: 'restServiceId', targetKey: 'id' });
};

11
api/app/lib/models/resource_consumption.js

@ -122,7 +122,16 @@ module.exports = dc => {
primaryKey: false,
field: "token",
autoIncrement: false
}
},
restServiceId: {
type: DataTypes.INTEGER,
allowNull: true,
defaultValue: null,
comment: "rest服务id",
primaryKey: false,
field: "rest_service_id",
autoIncrement: false
},
}, {
tableName: "t_resource_consumption",
comment: "",

8
api/app/lib/models/restful_api_record.js

@ -16,13 +16,13 @@ module.exports = dc => {
autoIncrement: true,
unique: "t_restful_api_record_id_uindex"
},
name: {
type: DataTypes.STRING,
restServiceId: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: null,
comment: "接口名称",
comment: "rest服务Id",
primaryKey: false,
field: "name",
field: "rest_service_id",
autoIncrement: false
},
visitTime: {

16
api/app/lib/routes/dataService/index.js

@ -0,0 +1,16 @@
'use strict';
const model = require('../../controllers/dataService/index');
module.exports = function (app, router, opts, AuthCode) {
app.fs.api.logAttr['GET/service-management'] = { content: '获取REST服务', visible: true };
router.get('/service-management', model.getServiceManagement(opts));
app.fs.api.logAttr['POST/service-management'] = { content: '编辑REST服务', visible: true };
router.post('/service-management', model.postServiceManagement(opts))
app.fs.api.logAttr['DEL/service-management/:id'] = { content: '删除REST服务', visible: true };
router.del('/service-management/:id', model.delServiceManagement(opts))
};

7
scripts/0.0.9/01_alter_t_restful_api.sql

@ -63,3 +63,10 @@ alter table t_restful_api_record
primary key (id);
alter table t_resource_consumption
add rest_service_id int;
comment on column t_resource_consumption.rest_service_id is 'rest服务id';

78
web/client/src/sections/dataService/actions/documentLibrary.js

@ -1,78 +0,0 @@
'use strict';
import { basicAction } from '@peace/utils'
import { ApiTable } from '$utils'
export function getStandardDocFolders (query = {}) {
return dispatch => basicAction({
type: 'get',
query,
dispatch: dispatch,
actionType: 'GET_STANDARD_DOC_FOLDERS',
url: `${ApiTable.standardDocFolders}`,
msg: { error: '获取标准文档目录列表失败' },
reducer: { name: '' }
});
}
export function postStandardDocFolders (data = {}) {
return dispatch => basicAction({
type: 'post',
data,
dispatch: dispatch,
actionType: 'POST_STANDARD_DOC_FOLDERS',
url: `${ApiTable.standardDocFolders}`,
msg: { option: '标准文档目录新增' },
reducer: { name: '' }
});
}
export function postStandardDocs (data = {}) {
return dispatch => basicAction({
type: 'post',
data,
dispatch: dispatch,
actionType: 'POST_STANDARD_DOCS',
url: `${ApiTable.standardDocs}`,
msg: { option: '新增标准文档' },
reducer: { name: '' }
});
}
export function getStandardDocs (query = {}) {
return dispatch => basicAction({
type: 'get',
query,
dispatch: dispatch,
actionType: 'GET_STANDARD_DOCS',
url: `${ApiTable.standardDocs}`,
msg: { error: '获取标准文档列表失败' },
reducer: { name: '' }
});
}
export function postFolderFile (data) {
return dispatch => basicAction({
type: 'post',
data,
dispatch: dispatch,
actionType: 'POST_FOLDER_FILE',
url: ApiTable.postFolderFile,
msg: { option: '删除文件夹或文件' },
reducer: { name: '' }
});
}
export function fetchFiles (data = {}) {
return dispatch => basicAction({
type: 'post',
data,
dispatch: dispatch,
actionType: 'POST_FETCH_FILES',
url: `${ApiTable.fetchFiles}`,
msg: { error: '获取文件夹下文件失败' },
reducer: { name: '' }
});
}

15
web/client/src/sections/dataService/actions/example.js

@ -1,15 +0,0 @@
'use strict';
import { basicAction } from '@peace/utils'
import { ApiTable } from '$utils'
// export function getMembers(orgId) {
// return dispatch => basicAction({
// type: 'get',
// dispatch: dispatch,
// actionType: 'GET_MEMBERS',
// url: `${ApiTable.getEnterprisesMembers.replace('{enterpriseId}', orgId)}`,
// msg: { error: '获取用户列表失败' },
// reducer: { name: 'members' }
// });
// }

12
web/client/src/sections/dataService/actions/index.js

@ -1,11 +1,11 @@
'use strict';
import * as example from './example'
import * as documentLibrary from './documentLibrary'
import * as ruleLibrary from './ruleLibrary'
import * as serviceManagement from './serviceManagement'
export default {
...example,
...documentLibrary,
...ruleLibrary,
...serviceManagement,
}

52
web/client/src/sections/dataService/actions/ruleLibrary.js

@ -1,52 +0,0 @@
'use strict';
import { basicAction } from '@peace/utils'
import { ApiTable } from '$utils'
export function postBusinessRules (data = {}) {
let reminder = data?.id ? '修改业务规则' : '新增业务规则'
return dispatch => basicAction({
type: 'post',
data,
dispatch: dispatch,
actionType: 'POST_BUSINESS_RULES',
url: `${ApiTable.businessRules}`,
msg: { option: reminder },
reducer: { name: '' }
});
}
export function getBusinessRules (query = {}) {
return dispatch => basicAction({
type: 'get',
query,
dispatch: dispatch,
actionType: 'GET_BUSINESS_RULES',
url: `${ApiTable.businessRules}`,
msg: { error: '查询业务规则列表失败' },
reducer: { name: '' }
});
}
export function delBusinessRules (id) {
return dispatch => basicAction({
type: 'del',
dispatch: dispatch,
actionType: 'del_BUSINESS_RULES',
url: `${ApiTable.delBusinessRules.replace('{id}', id)}`,
msg: { option: '删除业务规则' },
reducer: { name: '' }
});
}
export function getRegularBasis (query = {}) {
return dispatch => basicAction({
type: 'get',
query,
dispatch: dispatch,
actionType: 'GET_REGULAR_BASIS',
url: `${ApiTable.regularBasis}`,
msg: { error: '查询规则依据列表失败' },
reducer: { name: '' }
});
}

42
web/client/src/sections/dataService/actions/serviceManagement.js

@ -0,0 +1,42 @@
'use strict';
import { basicAction } from '@peace/utils'
import { ApiTable } from '$utils'
export function getServiceManagement (query = {}) {
return dispatch => basicAction({
type: 'get',
query,
dispatch: dispatch,
actionType: 'GET_SERVICE_MANAGEMENT',
url: `${ApiTable.serviceManagement}`,
msg: { error: '获取REST服务失败' },
reducer: { name: '' }
});
}
export function postServiceManagement (data = {}) {
return dispatch => basicAction({
type: 'post',
data,
dispatch: dispatch,
actionType: 'POST_SERVICE_MANAGEMENT',
url: `${ApiTable.serviceManagement}`,
msg: { option: '编辑REST服务' },
reducer: { name: '' }
});
}
export function delServiceManagement (id) {
return dispatch => basicAction({
type: 'del',
dispatch: dispatch,
actionType: 'del_SERVICE_MANAGEMENT',
url: `${ApiTable.delServiceManagement.replace('{id}', id)}`,
msg: { option: '删除REST服务' },
reducer: { name: '' }
});
}

14
web/client/src/sections/dataService/containers/serviceManagement.js

@ -23,7 +23,7 @@ function ServiceManagement ({ loading, clientHeight, actions, dispatch, }) {
const [treeList, setTreeLista] = useState([])
useEffect(() => {
resourceData()
// dispatch(dataQuality.getRegularBasis()).then(res => {
// dispatch(dataQuality.getServiceManagement()).then(res => {
// if (res.success) {
// setTreeLista(res.payload.data)
// }
@ -32,13 +32,13 @@ function ServiceManagement ({ loading, clientHeight, actions, dispatch, }) {
let resourceData = (data) => {
// let params = data || query
// dispatch(dataService.getBusinessRules({ keyword: keyword, ...params, })).then(res => {
// if (res.success) {
// setTableList({ rows: res.payload.data?.rows, count: res.payload.data?.count })
let params = data || query
dispatch(dataService.getServiceManagement({ keyword: keyword, ...params, })).then(res => {
if (res.success) {
setTableList({ rows: res.payload.data?.rows, count: res.payload.data?.count })
// }
// })
}
})
}
const columns = [{

31
web/client/src/sections/metadataManagement/components/releaseModal.js

@ -125,6 +125,7 @@ const ReleaseModal = ({ actions, dispatch, onConfirm, onCancel, editData = {} })
style={{ width: 200, marginRight: 10 }} value={f.value}
placeholder="请输入值"
onChange={v => {
console.log(v);
fromData?.splice(index, 1, { field: f.field, condition: f.condition, value: v?.target?.value })
setFromData([...fromData])
}}
@ -149,10 +150,11 @@ const ReleaseModal = ({ actions, dispatch, onConfirm, onCancel, editData = {} })
onClick={() => {
let whereOption = []
let integrity = true
console.log(fromData);
fromData.map(u => {
if (integrity) {
if (u.field && u.condition && u.value) {
whereOption.push(`${editData?.code}.${u.field} ${u.condition} ${"'" + (u.condition == 'LIKE' ? ('%' + u.value + '%') : u.value) + "'"}`);
whereOption.push(`${editData?.code}.${u.field} ${u.condition} ${(u.condition == 'IN' ? "" : "'") + (u.condition == 'LIKE' ? ('%' + u.value + '%') : u.value) + (u.condition == 'IN' ? "" : "'")}`);
} else if (!u.field && !u.condition && !u.value) {
} else {
integrity = false
@ -185,12 +187,13 @@ const ReleaseModal = ({ actions, dispatch, onConfirm, onCancel, editData = {} })
}}
defaultValue={"GET"}
options={[{ value: "GET", label: "GET" },
{ value: "POST", label: "POST" },
{ value: "PUT", label: "PUT" },
{ value: "DEL", label: "DEL" },]}
// { value: "POST", label: "POST" },
// { value: "PUT", label: "PUT" },
// { value: "DEL", label: "DEL" },
]}
allowClear
/>
<Input style={{ width: 180, marginLeft: 20 }} placeholder='请输入' onClick={() => {
<Input style={{ width: 180, marginLeft: 20 }} placeholder='请输入' onChange={e => {
setInterfaceUrl(e.target.value)
}} />
</div>
@ -245,15 +248,21 @@ const ReleaseModal = ({ actions, dispatch, onConfirm, onCancel, editData = {} })
duration: 1,
content: '缺少SQL语句,请生成SQL',
});
}
dispatch(metadataManagement.publishingServices({})).then(res => {
} else {
dispatch(metadataManagement.publishingServices({
table: database?.code,
fields: editData?.code,
conditions: fromData,
name: interfaceName,
method: interfaceMode,
url: interfaceUrl,
enabled: true,
})).then(res => {
if (res.success) {
onCancel()
}
})
}
}}>完成 </Button> : ""}
<Button style={{ marginLeft: 10 }} onClick={() => onCancel()}>取消</Button>
</div>

7
web/client/src/utils/webapi.js

@ -108,7 +108,12 @@ export const ApiTable = {
getBackupsList: 'meta/backups',
addBackups: 'meta/backups',
modifyBackups: 'meta/backups/{id}',
restoreBackups: 'backups/restore'
restoreBackups: 'backups/restore',
//REST服务
serviceManagement: 'service-management',
delServiceManagement: 'service-management/{id}',
};
export const RouteTable = {

Loading…
Cancel
Save