wenlele 2 years ago
parent
commit
924d3dc71a
  1. 3
      api/.vscode/launch.json
  2. 22
      api/app/lib/controllers/homepage/index.js
  3. 37
      api/app/lib/controllers/metadataSearch/index.js
  4. 2
      api/app/lib/routes/homepage/index.js
  5. 8
      api/config.js
  6. 16
      web/client/src/sections/homePage/components/accessData.js
  7. 14
      web/client/src/sections/resourceRetrieval/containers/retrieval.js

3
api/.vscode/launch.json

@ -18,7 +18,8 @@
"-g postgres://FashionAdmin:123456@10.8.30.39:5432/GovernmentDataResourceCenter", "-g postgres://FashionAdmin:123456@10.8.30.39:5432/GovernmentDataResourceCenter",
// "-g postgres://FashionAdmin:123456@10.8.30.156:5432/gdrcenter", // "-g postgres://FashionAdmin:123456@10.8.30.156:5432/gdrcenter",
"-b http://10.8.30.161:31420", "-b http://10.8.30.161:31420",
"-s http://10.8.30.161:32258" "-s http://10.8.30.161:32258",
"-d postgres/example/10.8.30.160/30432",
] ]
}, },
{ {

22
api/app/lib/controllers/homepage/index.js

@ -209,6 +209,24 @@ function getRestfulInfo(opts) {
} }
} }
function getAccessData(opts) {
return async function (ctx, next) {
const models = ctx.fs.dc.models;
try {
const projects = '1,2,3,4,5,6,7,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38'
const url = 'https://statistics.anxinyun.cn/statistic?projects=' + projects
let res = await request.get(url)
ctx.status = 200;
ctx.body = { res: res.body || {}, projects };
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = { message: '获取预警列表失败' }
}
}
}
function getQualityCheckAlarm(opts) { function getQualityCheckAlarm(opts) {
return async function (ctx, next) { return async function (ctx, next) {
const models = ctx.fs.dc.models; const models = ctx.fs.dc.models;
@ -225,11 +243,11 @@ function getQualityCheckAlarm(opts) {
} }
} }
module.exports = { module.exports = {
getNodeResources, getNodeResources,
getDataTotalTop5, getDataTotalTop5,
getClusterInfo, getClusterInfo,
getRestfulInfo, getRestfulInfo,
getQualityCheckAlarm getQualityCheckAlarm,
getAccessData
} }

37
api/app/lib/controllers/metadataSearch/index.js

@ -70,27 +70,42 @@ function searchMeta(opts) {
// 下载表数据 // 下载表数据
function getTableData(opts) { function getTableData(opts) {
return async function (ctx, next) { return async function (ctx, next) {
const models = ctx.fs.dc.models;
try { try {
const models = ctx.fs.dc.models;
const { id } = ctx.query; const { id } = ctx.query;
const metaData = await models.MetadataDatabase.findOne({ where: { id: id } }) const metaData = await models.MetadataDatabase.findOne({ where: { id: id } })
let rslt = [], metaDataChildren = [] let rslt = [], metaDataChildren = []
if (metaData && metaData.datasourceConfig) { const { dbConfig } = opts;
metaDataChildren = await models.MetadataDatabase.findAll({ where: { parent: id, type: '字段' } }) metaDataChildren = await models.MetadataDatabase.findAll({ where: { parent: id, type: '字段' } })
if (metaData.datasourceConfig) {
let { user, host, database, password, port } = metaData.datasourceConfig; let { user, host, database, password, port } = metaData.datasourceConfig;
const pool = new Pool({ const pool = new Pool({ user: user, host: host, database: database, password: password, port: port })
user: user,
host: host,
database: database,
password: password,
port: port,
})
const client = await pool.connect() const client = await pool.connect()
const tableName = metaData.name; const tableName = metaData.name;
const ress = await client.query(`SELECT * from "${tableName}"`, []) const ress = await client.query(`SELECT * from "${tableName}"`, [])
rslt = ress.rows rslt = ress.rows
} else {
let databaseFind = await models.MetadataDatabase.findOne({ where: { id: metaData.parent, type: '库' } })
if (databaseFind) {
let dbconfigObj = {
user: dbConfig.split('/')[0],
host: dbConfig.split('/')[2],
database: databaseFind.code,
password: dbConfig.split('/')[1],
port: dbConfig.split('/')[3],
}
let { user, host, database, password, port } = dbconfigObj;
const pool = new Pool({ user: user, host: host, database: database, password: password, port: port })
const client = await pool.connect()
const tableName = metaData.name;
const ress = await client.query(`SELECT * from "${tableName}"`, [])
rslt = ress.rows
} else {
rslt = []
}
} }
ctx.status = 200; ctx.status = 200;
@ -98,7 +113,7 @@ function getTableData(opts) {
} catch (error) { } catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 200; ctx.status = 200;
ctx.body = { message: '连接失败' } ctx.body = { message: '连接失败', rslt: [], metaDataChildren: [] }
} }
} }
} }

2
api/app/lib/routes/homepage/index.js

@ -19,4 +19,6 @@ module.exports = function (app, router, opts, AuthCode) {
app.fs.api.logAttr['GET/homepage/alarms'] = { content: '获取预警列表', visible: true }; app.fs.api.logAttr['GET/homepage/alarms'] = { content: '获取预警列表', visible: true };
router.get('/homepage/alarms', backups.getQualityCheckAlarm(opts)) router.get('/homepage/alarms', backups.getQualityCheckAlarm(opts))
app.fs.api.logAttr['GET/homepage/accessdata'] = { content: '获取接入数据统计', visible: true };
router.get('/homepage/accessdata', backups.getAccessData(opts))
}; };

8
api/config.js

@ -12,6 +12,7 @@ args.option(['p', 'port'], '启动端口');
args.option(['g', 'pg'], 'postgre 服务 URL'); args.option(['g', 'pg'], 'postgre 服务 URL');
args.option(['b', 'backups'], '后端数据库备份恢复接口地址'); args.option(['b', 'backups'], '后端数据库备份恢复接口地址');
args.option(['s', 'kubesphere'], 'kubesphere地址'); args.option(['s', 'kubesphere'], 'kubesphere地址');
args.option(['d', 'dbconfig'], '后台同步数据库host示例:postgres/example/10.8.30.160/30432 格式:用户名/密码/host/port');
const flags = args.parse(process.argv); const flags = args.parse(process.argv);
@ -25,8 +26,9 @@ const QINIU_SK = process.env.ANXINCLOUD_QINIU_SECRETKEY || flags.qnsk;
const BACKUPS_URL = process.env.BACKUPS_URL || flags.backups; const BACKUPS_URL = process.env.BACKUPS_URL || flags.backups;
const KUBESPHERE_URL = process.env.KUBESPHERE_URL || flags.kubesphere; const KUBESPHERE_URL = process.env.KUBESPHERE_URL || flags.kubesphere;
const DATABASE_CONFIG = process.env.DATABASE_HOST || flags.dbconfig;//同步数据库配置
if (!DB || !BACKUPS_URL || !KUBESPHERE_URL) { if (!DB || !BACKUPS_URL || !KUBESPHERE_URL || !DATABASE_CONFIG) {
console.log('缺少启动参数,异常退出'); console.log('缺少启动参数,异常退出');
args.showHelp(); args.showHelp();
process.exit(-1); process.exit(-1);
@ -72,7 +74,9 @@ const product = {
}, },
pssaRequest: [], pssaRequest: [],
backupsUrl: BACKUPS_URL, backupsUrl: BACKUPS_URL,
k8s: KUBESPHERE_URL k8s: KUBESPHERE_URL,
dbConfig: DATABASE_CONFIG,
} }
} }
], ],

16
web/client/src/sections/homePage/components/accessData.js

@ -1,19 +1,27 @@
import React, { useEffect, useState } from 'react' import React, { useEffect, useState } from 'react'
import Box from './public/table-card'; import Box from './public/table-card';
import { useFsRequest } from '$utils';
import { mathRound } from './util'
function AccessData(props) { function AccessData(props) {
const { data: accessdata = [] } = useFsRequest({
url: 'homepage/accessdata',
pollingInterval: 1000 * 60,
cacheKey: 'accessdata',
});
const renderBody = () => { const renderBody = () => {
return <div className='access_data'> return <div className='access_data'>
<div className='_img'></div> <div className='_img'></div>
<div className='data_unit'> <div className='data_unit'>
数据单位<div className='data_number'>256</div> 数据单位<div className='data_number'>{!accessdata?.projects ? '-' : accessdata?.projects?.split(',')?.length}</div>
</div> </div>
<div className='data_today'> <div className='data_today'>
今日数据<div className='data_number'>256</div> 今日数据<div className='data_number'>{!accessdata?.res?.stat?.today ? '-' : accessdata?.res?.stat?.today > 1000 ? mathRound(accessdata?.res?.stat?.today) : accessdata?.res?.stat?.today}</div>{accessdata?.res?.stat?.today > 1000 ? '' : ''}
</div> </div>
<div className='data_total'> <div className='data_total'>
数据总量<div className='data_number'>256</div> 数据总量<div className='data_number'>{accessdata?.res?.stat?.datas ? Math.round(accessdata?.res?.stat?.datas / 10000) : '-'}</div>
</div> </div>
</div> </div>
} }

14
web/client/src/sections/resourceRetrieval/containers/retrieval.js

@ -104,9 +104,12 @@ function Retrieval(props) {
workBook.Sheets[key]['!cols'] = [{ wpx: 50 }, { wpx: 150 }, { wpx: 180 }, { wpx: 230 }, { wpx: 230 }, { wpx: 230 }] workBook.Sheets[key]['!cols'] = [{ wpx: 50 }, { wpx: 150 }, { wpx: 180 }, { wpx: 230 }, { wpx: 230 }, { wpx: 230 }]
}) })
workBook.SheetNames = [sheetName]; workBook.SheetNames = [sheetName];
}
// 将workBook写入文件 // 将workBook写入文件
xlsx.writeFile(workBook, `${metaData?.name}-data.xlsx`); xlsx.writeFile(workBook, `${metaData?.name}-data.xlsx`);
} else {
message.info('当前资源暂无数据!')
}
} }
const renderIcon = (type) => { const renderIcon = (type) => {
@ -161,13 +164,10 @@ function Retrieval(props) {
window.open('/assets/files/common/' + s.fileName) window.open('/assets/files/common/' + s.fileName)
} }
} else { } else {
if (s.datasourceConfig) { setSearchDataId(null)
setTimeout(() => {
setSearchDataId(s.id) setSearchDataId(s.id)
if (tableData?.rslt && tableData?.metaDataChildren) handleTableExport() }, 10);
} else {
message.warning('数据源信息读取失败,无法下载元数据!')
}
} }
} }

Loading…
Cancel
Save