diff --git a/api/app/lib/controllers/latestMetadata/index.js b/api/app/lib/controllers/latestMetadata/index.js index 850d4f1..ea65098 100644 --- a/api/app/lib/controllers/latestMetadata/index.js +++ b/api/app/lib/controllers/latestMetadata/index.js @@ -90,9 +90,10 @@ async function delResourceCatalog(ctx) { let databaseInfo = await models.MetadataDatabase.findOne({ where: { catalog: id } }); let fileInfo = await models.MetadataFile.findOne({ where: { catalog: id } }); let restapiInfo = await models.MetadataRestapi.findOne({ where: { catalog: id } }); - if (childResourceCatalogInfo || databaseInfo || fileInfo || restapiInfo) { + let dataSourceInfo = await models.DataSource.findOne({ where: { mountPath: id } }); + if (childResourceCatalogInfo || databaseInfo || fileInfo || restapiInfo || dataSourceInfo) { ctx.status = 400; - ctx.body = { message: '存在关联子类目录或元数据,请删除相关数据,再删除该资源目录' } + ctx.body = { message: '存在关联数据,请删除相关数据,再删除该资源目录' } deletable = false; } if (deletable) { @@ -169,6 +170,8 @@ async function getMetadataFiles(ctx) { const models = ctx.fs.dc.models; const { catalog, limit, offset, keywords, orderBy = 'updateAt', orderDirection = 'desc' } = ctx.query; const where = { catalog: catalog }; + //文件类型关键字查询时需匹配fileName不能为空。 + //因存在编辑时将文件删除,但未重新上传直接点击取消的情况,此时文件已删除不可恢复,数据字段fileName更新为null if (keywords) { where['$or'] = [{ name: { $iLike: `%${keywords}%` } }, { type: { $iLike: `%${keywords}%` }, fileName: { $not: null } }] } @@ -499,8 +502,8 @@ async function getTagMetadata(ctx) { //申请资源 async function postMetadataResourceApplications(ctx) { try { - const { resourceName, applyBy } = ctx.request.body; - if (!resourceName || !applyBy) { + const { resourceName, applyBy, resourceType } = ctx.request.body; + if (!resourceName || !applyBy || !resourceType) { ctx.status = 400; ctx.body = { message: '参数不全,请重新申请资源' } } else { @@ -577,13 +580,12 @@ async function postMetadataFiles(ctx) { } } } - //修改文件元数据 async function putMetadataFiles(ctx) { try { const { id } = ctx.params; const { updateFileName } = ctx.query; - const { catalog, name } = ctx.request.body; + const { catalog, name, type } = ctx.request.body; const models = ctx.fs.dc.models; let metadataFileInfo = await models.MetadataFile.findOne({ where: { id } }); if (metadataFileInfo) { @@ -591,14 +593,19 @@ async function putMetadataFiles(ctx) { await models.MetadataFile.update({ updateAt: moment(), fileName: null }, { where: { id: id } }); ctx.status = 204; } else { - const putOne = await models.MetadataFile.findOne({ where: { id: { $not: id }, catalog: catalog, name: name } }); - if (putOne) { + if (!name || !catalog || !type) { + ctx.body = { message: '参数不全,请重新配置' } ctx.status = 400; - ctx.body = { message: '该元数据名称已存在' } } else { - await models.MetadataFile.update({ updateAt: moment(), ...ctx.request.body }, { where: { id: id } }); - ctx.status = 200; - ctx.body = { message: '修改元数据成功' } + const putOne = await models.MetadataFile.findOne({ where: { id: { $not: id }, catalog: catalog, name: name } }); + if (putOne) { + ctx.status = 400; + ctx.body = { message: '该元数据名称已存在' } + } else { + await models.MetadataFile.update({ updateAt: moment(), ...ctx.request.body }, { where: { id: id } }); + ctx.status = 200; + ctx.body = { message: '修改元数据成功' } + } } } } else { @@ -660,6 +667,118 @@ async function delMetadataFiles(ctx) { ctx.body = { message: '删除元数据失败' } } } + +//新建接口元数据 +async function postMetadataRestapis(ctx) { + try { + const { name, catalog, method, url } = ctx.request.body; + const models = ctx.fs.dc.models; + const postOne = await models.MetadataRestapi.findOne({ + where: { name: name, catalog: catalog } + }); + if (postOne) { + ctx.status = 400; + ctx.body = { message: '该资源目录下元数据名称已存在' } + } else { + if (!name || !catalog || !method || !url) { + ctx.body = { message: '参数不全,请重新配置' } + ctx.status = 400; + } else { + await models.MetadataRestapi.create({ createAt: moment(), ...ctx.request.body }); + ctx.body = { message: '新建元数据成功' } + ctx.status = 200; + } + } + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { + "message": "新建元数据失败" + } + } +} + +//修改接口元数据 +async function putMetadataRestapis(ctx) { + try { + const { id } = ctx.params; + const { catalog, name, method, url } = ctx.request.body; + const models = ctx.fs.dc.models; + let metadataRestapiInfo = await models.MetadataRestapi.findOne({ where: { id } }); + if (metadataRestapiInfo) { + if (!name || !catalog || !method || !url) { + ctx.body = { message: '参数不全,请重新修改' } + ctx.status = 400; + } else { + const putOne = await models.MetadataRestapi.findOne({ where: { id: { $not: id }, catalog: catalog, name: name } }); + if (putOne) { + ctx.status = 400; + ctx.body = { message: '该元数据名称已存在' } + } else { + await models.MetadataRestapi.update({ updateAt: moment(), ...ctx.request.body }, { where: { id: id } }); + ctx.status = 200; + ctx.body = { message: '修改元数据成功' } + } + } + } else { + ctx.status = 400; + ctx.body = { message: '该元数据不存在' } + } + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { + "message": "修改元数据失败" + } + } +} +//删除接口元数据 +async function delMetadataRestapis(ctx) { + const transaction = await ctx.fs.dc.orm.transaction(); + try { + const models = ctx.fs.dc.models; + const { id } = ctx.params; + let metadataRestapiInfo = await models.MetadataRestapi.findOne({ where: { id } }); + if (metadataRestapiInfo) { + let deletable = true; + let tagRestapiInfo = await models.TagRestapi.findOne({ where: { restapi: id } }); + if (tagRestapiInfo) { + ctx.status = 400; + ctx.body = { message: '该元数据已被打标' } + deletable = false; + } else { + let resourceConsumptionInfo = await models.ResourceConsumption.findOne({ + where: { + resourceName: metadataRestapiInfo.name, + resourceType: '接口' + } + }); + if (resourceConsumptionInfo) { + ctx.status = 400; + ctx.body = { message: '该元数据存在资源申请' } + deletable = false; + } + } + if (deletable) { + await models.MetadataRestapi.destroy({ + where: { id: id }, + transaction + }) + await transaction.commit(); + ctx.status = 200; + ctx.body = { message: '删除元数据成功' } + } + } else { + ctx.status = 400; + ctx.body = { message: '该元数据不存在' } + } + } catch (error) { + await transaction.rollback(); + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { message: '删除元数据失败' } + } +} module.exports = { getResourceCatalog, postResourceCatalog, @@ -679,5 +798,8 @@ module.exports = { getMetadataResourceApplications, postMetadataFiles, putMetadataFiles, - delMetadataFiles + delMetadataFiles, + postMetadataRestapis, + putMetadataRestapis, + delMetadataRestapis } \ No newline at end of file diff --git a/api/app/lib/models/metadata_database.js b/api/app/lib/models/metadata_database.js index 71139c8..2d7ddf3 100644 --- a/api/app/lib/models/metadata_database.js +++ b/api/app/lib/models/metadata_database.js @@ -106,7 +106,7 @@ module.exports = dc => { autoIncrement: false }, updateAt: { - type: DataTypes.INTEGER, + type: DataTypes.DATE, allowNull: true, defaultValue: null, comment: "修改时间", diff --git a/api/app/lib/routes/latestMetadata/index.js b/api/app/lib/routes/latestMetadata/index.js index 50e4d4c..01022e1 100644 --- a/api/app/lib/routes/latestMetadata/index.js +++ b/api/app/lib/routes/latestMetadata/index.js @@ -59,4 +59,13 @@ module.exports = function (app, router, opts) { app.fs.api.logAttr['DEL/metadata/files/:id'] = { content: '删除文件元数据', visible: true }; router.delete('/metadata/files/:id', latestMetadata.delMetadataFiles); + + app.fs.api.logAttr['POST/metadata/restapis'] = { content: '新建接口元数据', visible: true }; + router.post('/metadata/restapis', latestMetadata.postMetadataRestapis); + + app.fs.api.logAttr['PUT/metadata/restapis/:id'] = { content: '修改接口元数据', visible: true }; + router.put('/metadata/restapis/:id', latestMetadata.putMetadataRestapis); + + app.fs.api.logAttr['DEL/metadata/restapis/:id'] = { content: '删除接口元数据', visible: true }; + router.delete('/metadata/restapis/:id', latestMetadata.delMetadataRestapis); }; \ No newline at end of file diff --git a/web/client/assets/files/common/readme.txt b/web/client/assets/files/common/readme.txt new file mode 100644 index 0000000..a685d95 --- /dev/null +++ b/web/client/assets/files/common/readme.txt @@ -0,0 +1 @@ +03专项三期文件本地上传默认路径 \ No newline at end of file diff --git a/web/client/src/components/UploadLocal/index.js b/web/client/src/components/UploadLocal/index.js index a275c81..0af35e2 100644 --- a/web/client/src/components/UploadLocal/index.js +++ b/web/client/src/components/UploadLocal/index.js @@ -50,11 +50,10 @@ class Uploads extends Component { if (value) { // this.setState(value); this.setState({ fileList: value }) - } } - componentWillReceiveProps(np) { + UNSAFE_componentWillReceiveProps(np) { const { dispatch, value: thisEditData, onChange } = this.props; const { value: nextEditData } = np; diff --git a/web/client/src/sections/metadataAcquisition/containers/adapter.js b/web/client/src/sections/metadataAcquisition/containers/adapter.js index 5855927..6601978 100644 --- a/web/client/src/sections/metadataAcquisition/containers/adapter.js +++ b/web/client/src/sections/metadataAcquisition/containers/adapter.js @@ -7,7 +7,7 @@ import moment from 'moment'; import { RELATION_DATABASE_TOOL_CONFIG } from '../constants/adapter'; import { useFsRequest, ApiTable } from '$utils'; -const LatestMetadata = (props) => { +const Adapter = (props) => { const { history, actions, dispatch, adapters } = props; const [isModalOpen, setIsModalOpen] = useState(false); const [refreshTree, setRefreshTree] = useState(1); @@ -114,4 +114,4 @@ function mapStateToProps(state) { dataSources: datasources?.data || {}, }; } -export default connect(mapStateToProps)(LatestMetadata) \ No newline at end of file +export default connect(mapStateToProps)(Adapter) \ No newline at end of file diff --git a/web/client/src/sections/metadataManagement/actions/metadata.js b/web/client/src/sections/metadataManagement/actions/metadata.js index e522737..b0ec1b7 100644 --- a/web/client/src/sections/metadataManagement/actions/metadata.js +++ b/web/client/src/sections/metadataManagement/actions/metadata.js @@ -231,3 +231,40 @@ export function delMetadataFiles(id) { } }); } + +export function postMetadataRestapis(data) { + return dispatch => basicAction({ + type: 'post', + data: data, + dispatch: dispatch, + actionType: 'POST_METADATA_RESTAPIS', + url: ApiTable.postMetadataRestapis, + msg: { option: '新建元数据' }, + reducer: {} + }); +} + +export function putMetadataRestapis(id, data) { + return dispatch => basicAction({ + type: 'put', + data: data, + dispatch, + actionType: 'PUT_METADATA_RESTAPIS', + url: ApiTable.putMetadataRestapis.replace('{id}', id), + msg: { + option: '修改元数据', + } + }); +} + +export function delMetadataRestapis(id) { + return dispatch => basicAction({ + type: 'del', + dispatch, + actionType: 'DELETE_METADATA_RESTAPIS', + url: ApiTable.delMetadataRestapis.replace('{id}', id), + msg: { + option: '删除元数据', + } + }); +} diff --git a/web/client/src/sections/metadataManagement/components/metadataDatabaseModal.js b/web/client/src/sections/metadataManagement/components/metadataDatabaseModal.js index d005501..c07a620 100644 --- a/web/client/src/sections/metadataManagement/components/metadataDatabaseModal.js +++ b/web/client/src/sections/metadataManagement/components/metadataDatabaseModal.js @@ -12,7 +12,7 @@ const MetadataDatabaseModal = (props) => { if (onConfirm) { let dataSave = JSON.parse(JSON.stringify(values)); dataSave.attributesParam = {}; - metadataModels.map(m => { + metadataModels.filter(mm => mm.modelType === type).map(m => { dataSave.attributesParam[m.attributeCode] = values[m.attributeCode]; delete dataSave[m.attributeCode]; }) @@ -41,16 +41,18 @@ const MetadataDatabaseModal = (props) => { {m.attributeName.substring(0, 10) + '...'} : m.attributeName} name={m.attributeCode} + key={m.attributeCode} rules={rules}> } else if (m.control === '数字输入框') { const rules = [{ required: !m.nullable, message: `${m.attributeName}不可空` }] let maxValue = ''; - if (m.length) { - while (m.length > 0) { + let length = m.length; + if (length) { + while (length > 0) { maxValue += '9' - m.length--; + length--; } } return { {m.attributeName.substring(0, 10) + '...'} : m.attributeName} name={m.attributeCode} + key={m.attributeCode} rules={rules}> @@ -67,6 +70,7 @@ const MetadataDatabaseModal = (props) => { {m.attributeName.substring(0, 10) + '...'} : m.attributeName} name={m.attributeCode} + key={m.attributeCode} rules={[{ required: !m.nullable, message: `${m.attributeName}不可空` }]}> {