diff --git a/api/app/lib/controllers/project/bind.js b/api/app/lib/controllers/project/bind.js index f6a4bbd..ba46239 100644 --- a/api/app/lib/controllers/project/bind.js +++ b/api/app/lib/controllers/project/bind.js @@ -4,7 +4,13 @@ async function bindAnxin2pep (ctx) { try { const models = ctx.fs.dc.models; const { clickHouse } = ctx.app.fs - const { name } = ctx.request.body + const { bindId, name, pepProjectId, anxinProjectId = [], } = ctx.request.body + + + + if(bindId){ + + } ctx.status = 20; diff --git a/api/app/lib/controllers/project/index.js b/api/app/lib/controllers/project/index.js index 85062af..6c0c3f5 100644 --- a/api/app/lib/controllers/project/index.js +++ b/api/app/lib/controllers/project/index.js @@ -20,6 +20,57 @@ async function appList (ctx) { } } +async function pomsProject (ctx) { + try { + const models = ctx.fs.dc.models; + const { clickHouse } = ctx.app.fs + const { userId } = ctx.fs.api + + const proRes = await models.ProjectCorrelation.findAll({ + where: {}, + include: { + model: models.ProjectApp, + attributes: { + exclude: ['projectId'] + } + } + }) + + let pepProjectIds = new Set() + let anxinProjectIds = new Set() + for (let p of proRes) { + pepProjectIds.add(p.pepProjectId) + for (let ap of p.anxinProjectId) { + anxinProjectIds.add(ap) + } + } + const pepProjectRes = pepProjectIds.size ? + await clickHouse.projectManage.query(`SELECT id, project_name FROM t_pim_project WHERE id IN (${[...pepProjectIds].join(',')})`).toPromise() : + [] + + const anxinProjectRes = anxinProjectIds.size ? + await clickHouse.anxinyun.query(`SELECT id,"name" FROM t_project WHERE id IN (${[...anxinProjectIds].join(',')})`).toPromise() : + [] + + + for (let p of proRes) { + const corPro = pepProjectRes.find(pp => pp.id == p.pepProjectId) + p.dataValues.pepProjectName = corPro.project_name + let nextAnxinProject = anxinProjectRes.filter(ap => p.anxinProjectId.includes(ap.id)) + p.dataValues.anxinProject = nextAnxinProject + delete p.dataValues.anxinProjectId + } + ctx.status = 200; + ctx.body = proRes + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: error`); + ctx.status = 400; + ctx.body = { + message: typeof error == 'string' ? error : undefined + } + } +} + async function projectAnxincloud (ctx) { try { const models = ctx.fs.dc.models; @@ -60,4 +111,5 @@ module.exports = { appList, projectAnxincloud, projectPManage, + pomsProject, }; \ No newline at end of file diff --git a/api/app/lib/models/project_correlation.js b/api/app/lib/models/project_correlation.js index 7f72375..3576554 100644 --- a/api/app/lib/models/project_correlation.js +++ b/api/app/lib/models/project_correlation.js @@ -25,7 +25,7 @@ module.exports = dc => { autoIncrement: false }, pepProjectId: { - type: DataTypes.ARRAY(DataTypes.INTEGER), + type: DataTypes.INTEGER, allowNull: false, defaultValue: null, comment: "项目管理的项目id", diff --git a/api/app/lib/routes/project/index.js b/api/app/lib/routes/project/index.js index 8c41c72..ec27061 100644 --- a/api/app/lib/routes/project/index.js +++ b/api/app/lib/routes/project/index.js @@ -15,4 +15,7 @@ module.exports = function (app, router, opts) { app.fs.api.logAttr['GET/project/pmanage'] = { content: '获取PEP项目管理项目', visible: true }; router.get('/project/pmanage', project.projectPManage); + + app.fs.api.logAttr['GET/project/poms'] = { content: '获取已绑定项目', visible: true }; + router.get('/project/poms', project.pomsProject); }; \ No newline at end of file diff --git a/api/config.js b/api/config.js index d64fa33..0133b80 100644 --- a/api/config.js +++ b/api/config.js @@ -163,9 +163,6 @@ const product = { }, { name: 'projectManage', db: CLICKHOUST_PROJECT_MANAGE - }, { - name: 'anxinyun', - db: CLICKHOUST_ANXINCLOUD }, { name: 'vcmp', db: CLICKHOUST_VCMP diff --git a/script/0.0.3/2.alter table project_correlation.sql b/script/0.0.3/2.alter table project_correlation.sql new file mode 100644 index 0000000..f6cb8b9 --- /dev/null +++ b/script/0.0.3/2.alter table project_correlation.sql @@ -0,0 +1,4 @@ +alter table project_correlation drop column pep_project_id; + +alter table project_correlation + add pep_project_id int not null; \ No newline at end of file diff --git a/web/client/src/layout/actions/global.js b/web/client/src/layout/actions/global.js index 5f0c4e3..4d019aa 100644 --- a/web/client/src/layout/actions/global.js +++ b/web/client/src/layout/actions/global.js @@ -38,8 +38,6 @@ export function initApiRoot () { type: INIT_API_ROOT, payload: { apiRoot: res.root, - iotAuthWeb: res.iotAuthWeb, - iotVideoServer: res.iotVideoServer } }) }); diff --git a/web/client/src/layout/reducers/global.js b/web/client/src/layout/reducers/global.js index 1385fb9..8187eb7 100644 --- a/web/client/src/layout/reducers/global.js +++ b/web/client/src/layout/reducers/global.js @@ -11,8 +11,6 @@ function global (state = { clientHeight: 768, clientWidth: 1024, apiRoot: '', - iotAuthWeb: '', - iotVideoServer: '', }, action) { const payload = action.payload; switch (action.type) { @@ -32,8 +30,6 @@ function global (state = { case INIT_API_ROOT: return Immutable.fromJS(state).merge({ apiRoot: payload.apiRoot, - iotAuthWeb: payload.iotAuthWeb, - iotVideoServer: payload.iotVideoServer, }).toJS(); default: return state; diff --git a/web/config.js b/web/config.js index 2337703..6a6cb58 100644 --- a/web/config.js +++ b/web/config.js @@ -15,6 +15,11 @@ args.option(['u', 'api-url'], 'webapi的URL'); args.option('apiPomsUrl', 'webapi的URL 外网可访问'); args.option('apiAnxinyunUrl', '安心云 api'); args.option('apiEmisUrl', '企业管理 api'); +// 七牛 +args.option('qnak', 'qiniuAccessKey'); +args.option('qnsk', 'qiniuSecretKey'); +args.option('qnbkt', 'qiniuBucket'); +args.option('qndmn', 'qiniuDomain'); const flags = args.parse(process.argv); @@ -23,14 +28,17 @@ const API_POMS_URL = process.env.API_POMS_URL || flags.apiPomsUrl; const API_EMIS_URL = process.env.API_EMIS_URL || flags.apiEmisUrl; const API_ANXINYUN_URL = process.env.API_ANXINYUN_URL || flags.apiAnxinyunUrl; +// 七牛 const ANXINCLOUD_QINIU_AK = process.env.ANXINCLOUD_QINIU_AK || flags.qnak; const ANXINCLOUD_QINIU_SK = process.env.ANXINCLOUD_QINIU_SK || flags.qnsk; const ANXINCLOUD_QINIU_BUCKET_RESOURCE = process.env.ANXINCLOUD_QINIU_BUCKET_RESOURCE || flags.qnbkt; const ANXINCLOUD_QINIU_DOMAIN_QNDMN_RESOURCE = process.env.ANXINCLOUD_QINIU_DOMAIN_QNDMN_RESOURCE || flags.qndmn; -if (!API_URL || !API_ANXINYUN_URL || !ANXINCLOUD_QINIU_AK || !ANXINCLOUD_QINIU_SK || !ANXINCLOUD_QINIU_BUCKET_RESOURCE - || !ANXINCLOUD_QINIU_DOMAIN_QNDMN_RESOURCE) { +if ( + !API_URL + || !API_ANXINYUN_URL + || !ANXINCLOUD_QINIU_AK || !ANXINCLOUD_QINIU_SK || !ANXINCLOUD_QINIU_BUCKET_RESOURCE || !ANXINCLOUD_QINIU_DOMAIN_QNDMN_RESOURCE) { console.log('缺少启动参数,异常退出'); args.showHelp(); process.exit(-1); @@ -74,6 +82,10 @@ const product = { opts: { apiUrl: API_POMS_URL, staticRoot: './client', + qiniu: { + fetchUrl: '/_file-server', + domain: ANXINCLOUD_QINIU_DOMAIN_QNDMN_RESOURCE + }, } }, { entry: require('./client').entry,// 静态信息 diff --git a/web/package.json b/web/package.json index 1ed7077..bb30932 100644 --- a/web/package.json +++ b/web/package.json @@ -7,7 +7,7 @@ "test": "mocha", "start-vite": "cross-env NODE_ENV=developmentVite npm run start-params", "start": "cross-env NODE_ENV=development npm run start-params", - "start-params": "node server -p 5600 -u http://localhost:4600 --apiPomsUrl http://localhost:4600 --apiAnxinyunUrl http://10.8.30.112:4100 --apiEmisUrl http://10.8.30.112:14000", + "start-params": "node server -p 5600 -u http://localhost:4600 --apiPomsUrl http://localhost:4600 --apiAnxinyunUrl http://10.8.30.112:4100 --apiEmisUrl http://10.8.30.112:14000 --qnak XuDgkao6cL0HidoMAPnA5OB10Mc_Ew08mpIfRJK5 --qnsk yewcieZLzKZuDfig0wLZ9if9jKp2P_1jd3CMJPSa --qnbkt dev-highways4good --qndmn http://rhvqdivo5.hn-bkt.clouddn.com", "deploy": "export NODE_ENV=production&& npm run build && node server", "build-dev": "cross-env NODE_ENV=development&&webpack --config webpack.config.js", "build": "cross-env NODE_ENV=production&&webpack --config webpack.config.prod.js" @@ -49,7 +49,6 @@ "dependencies": { "@douyinfe/semi-ui": "^2.8.0", "@douyinfe/semi-webpack-plugin": "^2.13.0", - "@fs/attachment": "^1.0.0", "@micro-zoe/micro-app": "^1.0.0-alpha.1", "@peace/utils": "^0.0.64", "@semi-bot/semi-theme-fscamera": "^1.0.0", @@ -80,4 +79,4 @@ "webpack-dev-server": "^3.11.2", "webpack-hot-middleware": "^2.25.0" } -} +} \ No newline at end of file diff --git a/web/routes/attachment/index.js b/web/routes/attachment/index.js index 6c02488..f8ac67d 100644 --- a/web/routes/attachment/index.js +++ b/web/routes/attachment/index.js @@ -19,98 +19,35 @@ module.exports = { entry: function (app, router, opts) { const getApiRoot = async function (ctx) { - const { apiUrl, iotAuthWeb, iotVideoServer } = opts; + const { apiUrl, } = opts; ctx.status = 200; ctx.body = { root: apiUrl, - iotAuthWeb, - iotVideoServer }; }; let download = async function (ctx, next) { const { fetchUrl } = opts.qiniu; if (ctx.path && ctx.path.includes(fetchUrl)) { - try { - const { filename } = ctx.request.query; - const fkey = decodeURI(ctx.path.slice(fetchUrl.length + 1)).replace(/\.json$/, '.js'); - const publicDownloadUrl = await app.fs.attachment.download(fkey); - ctx.status = 200; - if (filename) ctx.attachment(filename); - ctx.body = request.get(publicDownloadUrl); - } catch (err) { - ctx.fs.logger.error(err); - ctx.status = 404; - ctx.body = { error: 'file not found.' } - } - } else { - await next(); - } - } - - let upload = async function (ctx, next) { - try { - const { files } = await parse(ctx.req); - const file = files[0]; - const extname = path.extname(file.filename).toLowerCase(); - const fileType = ctx.query.type || "image"; - const fileFolder = ctx.query.fileFolder || 'common'; - if (ext[fileType].indexOf(extname) < 0) { - ctx.status = 400; - ctx.body = JSON.stringify({ name: 'UploadFailed', message: '文件格式无效' }); - return; + try { + const { filename } = ctx.request.query; + const fkey = decodeURI(ctx.path.slice(fetchUrl.length + 1)).replace(/\.json$/, '.js'); + const publicDownloadUrl = await app.fs.attachment.download(fkey); + ctx.status = 200; + if (filename) ctx.attachment(filename); + ctx.body = request.get(publicDownloadUrl); + } catch (err) { + ctx.fs.logger.error(err); + ctx.status = 404; + ctx.body = { error: 'file not found.' } } - const date = new Date().toLocaleDateString(); - const time = new Date().getTime(); - let fileName = time + '_' + file.filename; - let saveFile = path.join(__dirname, '../../', `/client/assets/files/${fileFolder}`, fileName); - const pathUrl = `./client/assets/files/${fileFolder}`; - - const res1 = fs.existsSync(`./client/assets/files/${fileFolder}`); - !res1 && fs.mkdirSync(`./client/assets/files/${fileFolder}`); - const res = fs.existsSync(pathUrl); - !res && fs.mkdirSync(pathUrl); - let stream = fs.createWriteStream(saveFile); - fs.createReadStream(file.path).pipe(stream); - stream.on('error', function (err) { - app.fs.logger.log('error', '[Upload Heatmap]', err); - }); - ctx.status = 200; - ctx.body = { filename: path.join(`/assets/files/${fileFolder}`, fileName), name: 'UploadSuccess', message: '上传成功' }; - } catch (err) { - ctx.status = 500; - ctx.fs.logger.error(err); - ctx.body = { err: 'upload error.' }; - } - } - - let remove = async function (ctx, next) { - try { - const fkeys = ctx.request.body; - let removeUrl = path.join(__dirname, '../../', './client', fkeys.url); - const res = fs.existsSync(removeUrl); - if (!res) { - ctx.status = 400; - ctx.body = JSON.stringify({ name: 'DeleteFailed', message: '文件地址不存在' }); - return; - } - fs.unlink(removeUrl, function (error) { - if (error) { - console.log(error); - } - }) - ctx.status = 200; - ctx.body = { name: 'DeleteSuccess.', message: '删除成功' }; - } catch (err) { - ctx.status = 500; - ctx.fs.logger.error(err); - ctx.body = { err: 'upload cleanup error.' }; + } else { + await next(); } } + router.use(download); router.get('/api/root', getApiRoot); - router.post('/_upload/new', upload); - router.delete('/_upload/cleanup', remove); } };