巴林闲侠 2 years ago
parent
commit
8a70e9e31c
  1. 8
      api/app/lib/controllers/project/bind.js
  2. 52
      api/app/lib/controllers/project/index.js
  3. 2
      api/app/lib/models/project_correlation.js
  4. 3
      api/app/lib/routes/project/index.js
  5. 3
      api/config.js
  6. 4
      script/0.0.3/2.alter table project_correlation.sql
  7. 2
      web/client/src/layout/actions/global.js
  8. 4
      web/client/src/layout/reducers/global.js
  9. 16
      web/config.js
  10. 5
      web/package.json
  11. 93
      web/routes/attachment/index.js

8
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;

52
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,
};

2
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",

3
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);
};

3
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

4
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;

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

4
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;

16
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,// 静态信息

5
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"
}
}
}

93
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);
}
};

Loading…
Cancel
Save