Browse Source

申请资源下载

master
wenlele 1 year ago
parent
commit
82c604781a
  1. 6
      api/app/lib/controllers/resourceConsumption/index.js
  2. 2
      api/app/lib/index.js
  3. 6
      api/app/lib/routes/latestMetadata/index.js
  4. BIN
      web/client/assets/files/common/1698915773497_5.jpg
  5. 13
      web/client/src/sections/resourceConsumption/actions/approve.js
  6. 156
      web/client/src/sections/resourceConsumption/containers/myApplication.js

6
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'],

2
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' });
};

6
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,

BIN
web/client/assets/files/common/1698915773497_5.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 MiB

13
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: '' }
});
}

156
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 && <Button type="link" onClick={async () => {
console.log(record);
if (record?.resourceType == '文件') {
const suffix = record?.metadataFile?.fileName?.substring(record?.metadataFile?.fileName?.length - 3, record?.metadataFile?.fileName?.length)
if (suffix == 'png' || suffix == 'jpg') {
downloadImg(record?.metadataFile.fileName)
} else {
window.open('/assets/files/common/' + record?.metadataFile.fileName)
}
} else if (record?.resourceType == '库表') {
setKeywords(record?.resourceName)
setSearchDataId(null)
setTimeout(() => {
setSearchDataId(record.metadataDatabase?.id)
}, 10);
} else if (record?.resourceType == '数据服务') {
dispatch(resourceConsumption.getRestData({
url: record?.restfulApi?.url,
token: record?.token
})).then(res => {
if (res.success) {
let restData = res.payload.data?.rows
if (restData.length > 0) {
restTableExport(record?.resourceName, restData)
} else {
message.info('当前资源暂无数据!')
}
}
})
}
}}>下载</Button>
}
}];
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,

Loading…
Cancel
Save