diff --git a/api/app/lib/controllers/resourceConsumption/index.js b/api/app/lib/controllers/resourceConsumption/index.js index 7f76a13..09af903 100644 --- a/api/app/lib/controllers/resourceConsumption/index.js +++ b/api/app/lib/controllers/resourceConsumption/index.js @@ -23,6 +23,10 @@ function getApproveList(opts) { model: models.User, as: 'approveUser', attributes: ['id', 'name'] + }, { + model: models.MetadataFile, + as: 'metadataFile', + attributes: ['id', 'fileName'] }, { model: models.MetadataDatabase, @@ -38,7 +42,7 @@ function getApproveList(opts) { }, { model: models.RestfulApi, - attributes: ['id', 'name'], + // attributes: ['id', 'name'], include: [{ model: models.ResourceCatalog, attributes: ['id', 'name'], diff --git a/api/app/lib/index.js b/api/app/lib/index.js index 9c0f409..f7367ab 100644 --- a/api/app/lib/index.js +++ b/api/app/lib/index.js @@ -112,4 +112,6 @@ module.exports.models = function (dc) { RestfulApi.belongsTo(ResourceCatalog, { foreignKey: 'catalog', targetKey: 'id' }); ResourceCatalog.belongsTo(Organization, { foreignKey: 'orgId', targetKey: 'id' }); + + ResourceConsumption.belongsTo(MetadataFile, { foreignKey: 'resourceId', targetKey: 'id' }); }; diff --git a/api/app/lib/routes/latestMetadata/index.js b/api/app/lib/routes/latestMetadata/index.js index 0f192f0..31b0ee7 100644 --- a/api/app/lib/routes/latestMetadata/index.js +++ b/api/app/lib/routes/latestMetadata/index.js @@ -107,7 +107,7 @@ module.exports = function (app, router, opts) { tokens = s.token } }) - if (tokens && tokens == token) { + if (tokens && (tokens == token || tokens == token[1] || tokens == token[0])) { if (findOne.enabled) { const pool = new Pool({ user: ctx.fs.dc.orm.config.username, @@ -175,7 +175,7 @@ module.exports = function (app, router, opts) { } }); - + async function release (apps, opts) { @@ -208,7 +208,7 @@ module.exports = function (app, router, opts) { } }) - if (tokens && tokens == token) { + if (tokens && (tokens == token || tokens == token[1] || tokens == token[0])) { if (findOne.enabled) { const pool = new Pool({ user: ctx.fs.dc.orm.config.username, diff --git a/web/client/assets/files/common/1698915773497_5.jpg b/web/client/assets/files/common/1698915773497_5.jpg new file mode 100644 index 0000000..900b37d Binary files /dev/null and b/web/client/assets/files/common/1698915773497_5.jpg differ diff --git a/web/client/src/sections/resourceConsumption/actions/approve.js b/web/client/src/sections/resourceConsumption/actions/approve.js index 9f21dbd..c22606b 100644 --- a/web/client/src/sections/resourceConsumption/actions/approve.js +++ b/web/client/src/sections/resourceConsumption/actions/approve.js @@ -27,3 +27,16 @@ export function postApprove (data = {}) { reducer: { name: '' } }); } + + +export function getRestData (query = {}) { + return dispatch => basicAction({ + type: 'get', + query, + dispatch: dispatch, + actionType: 'GET_REST_DATA', + url: query?.url, + msg: { error: '获取rest服务请求数据失败' }, + reducer: { name: '' } + }); +} diff --git a/web/client/src/sections/resourceConsumption/containers/myApplication.js b/web/client/src/sections/resourceConsumption/containers/myApplication.js index e69b23a..56a9c02 100644 --- a/web/client/src/sections/resourceConsumption/containers/myApplication.js +++ b/web/client/src/sections/resourceConsumption/containers/myApplication.js @@ -1,20 +1,25 @@ import React, { useEffect, useState } from 'react' import { connect } from 'react-redux'; import moment from 'moment'; +import { useFsRequest, ApiTable } from '$utils'; import ApproveModal from '../components/approveModal'; +import { downloadImg, markRedKeywords } from '../../resourceRetrieval/utils/index' +import { Tabs, Form, Input, DatePicker, Button, Table, Select, message } from 'antd'; +import xlsx from 'xlsx'; -import { Tabs, Form, Input, DatePicker, Button, Table, Select } from 'antd'; -import { v1 } from 'uuid'; - -function MyApplication({ loading, clientHeight, actions, dispatch, user }) { +function MyApplication ({ loading, clientHeight, actions, dispatch, user }) { const { resourceConsumption } = actions const [query, setQuery] = useState({ page: 0, limit: 10 }); const [proTableList, setProTableList] = useState({ rows: [], count: 0 }); const [formData, setFormData] = useState({}) + const [searchDataId, setSearchDataId] = useState(null) + const [keywords, setKeywords] = useState() + + useEffect(() => { resourceData() @@ -30,6 +35,71 @@ function MyApplication({ loading, clientHeight, actions, dispatch, user }) { }) } + //检索元数据 + const { data: tableData = {} } = useFsRequest({ + url: 'meta/table/data', + query: { + id: searchDataId + }, + refreshDeps: [searchDataId], + ready: !!searchDataId, + }); + + //检索元数据 + const { data: result = {} } = useFsRequest({ + url: ApiTable.searchMetadata, + query: { + keywords: keywords + }, + refreshDeps: [keywords], + ready: !!keywords + }); + + + useEffect(() => { + if (tableData?.rslt && tableData?.metaDataChildren) handleTableExport() + }, [tableData]) + + const handleTableExport = () => { + const metaData = result?.rows?.find(s => s.id == searchDataId) + if (!metaData) return; + let excelTitle = tableData?.metaDataChildren.map(s => { + return { k: s, v: s } + }); + let workBook = { + SheetNames: [], //sheet名称 + Sheets: {} //根据SheetNames名称顺序依次添加每个sheet数据 + }; + if (tableData?.rslt && tableData?.rslt?.length > 0) { + let sheetName = '元数据列表'; + let sheetDataMap = new Map(); + let sheetData = [excelTitle]; + let index = 1; + tableData?.rslt.map(data => { + const arr = [] + tableData?.metaDataChildren.map(s => { + arr.push( + { k: s, v: JSON.stringify(data[s]) }, + ); + }); + sheetData.push(arr) + index = index + 1; + }) + + sheetDataMap.set(sheetName, sheetData); + sheetDataMap.forEach((values, key) => { + // 写入excel + workBook.Sheets[key] = xlsx.utils.aoa_to_sheet(values); + workBook.Sheets[key]['!cols'] = [{ wpx: 50 }, { wpx: 150 }, { wpx: 180 }, { wpx: 230 }, { wpx: 230 }, { wpx: 230 }] + }) + workBook.SheetNames = [sheetName]; + // 将workBook写入文件 + xlsx.writeFile(workBook, `${metaData?.name}-data.xlsx`); + } else { + message.info('当前资源暂无数据!') + } + + } const columns = [{ title: '资源名称', @@ -80,8 +150,84 @@ function MyApplication({ loading, clientHeight, actions, dispatch, user }) { compare: (a, b) => moment(b?.approveAt).valueOf() - moment(a?.approveAt).valueOf(), // multiple: 2, }, + }, { + title: '操作', + dataIndex: 'action', + render: (text, record) => { + return record?.token && + } }]; + const restTableExport = (name, data = []) => { + let dataKey = Object.keys(data[0])||[] + + let excelTitle = dataKey.map(s => { + return { k: s, v: s } + }); + let workBook = { + SheetNames: [], //sheet名称 + Sheets: {} //根据SheetNames名称顺序依次添加每个sheet数据 + }; + + let sheetName = '元数据列表'; + let sheetDataMap = new Map(); + let sheetData = [excelTitle]; + let index = 1; + data.map(data => { + const arr = [] + dataKey.map(s => { + arr.push( + { k: s, v: JSON.stringify(data[s]) }, + ); + }); + sheetData.push(arr) + index = index + 1; + }) + + sheetDataMap.set(sheetName, sheetData); + sheetDataMap.forEach((values, key) => { + // 写入excel + workBook.Sheets[key] = xlsx.utils.aoa_to_sheet(values); + workBook.Sheets[key]['!cols'] = [{ wpx: 50 }, { wpx: 150 }, { wpx: 180 }, { wpx: 230 }, { wpx: 230 }, { wpx: 230 }] + }) + workBook.SheetNames = [sheetName]; + // 将workBook写入文件 + xlsx.writeFile(workBook, `${name}-data.xlsx`); + } + return <> @@ -143,7 +289,7 @@ function MyApplication({ loading, clientHeight, actions, dispatch, user }) { } -function mapStateToProps(state) { +function mapStateToProps (state) { const { global, auth, resourceCatalog } = state; return { user: auth.user,