wenlele 1 year ago
parent
commit
0ce092f5c5
  1. 37
      api/app/lib/controllers/project/group.js
  2. 17
      script/3.1/schema/1.create_p_group.sql
  3. 22
      script/3.1/schema/2.create_struc_off.sql
  4. 2
      web/client/src/sections/install/routes.js

37
api/app/lib/controllers/project/group.js

@ -196,7 +196,7 @@ async function groupStatistic (ctx) {
ctx.status = 200; ctx.status = 200;
ctx.body = rslt ctx.body = rslt
} catch (error) { } catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: error`); ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400; ctx.status = 400;
ctx.body = { ctx.body = {
message: typeof error == 'string' ? error : undefined message: typeof error == 'string' ? error : undefined
@ -241,10 +241,19 @@ async function groupStatisticOnline (ctx) {
const strucRes = strucIdArr.length ? await clickHouse.anxinyun.query( const strucRes = strucIdArr.length ? await clickHouse.anxinyun.query(
` `
SELECT * FROM t_structure WHERE id IN (${[...strucIdArr].join(',')}); SELECT name, id FROM t_structure WHERE id IN (${[...strucIdArr].join(',')});
` `
).toPromise() : [] ).toPromise() : []
// 查中断时间
const maxOfflineTimeRes = strucIdArr.length ? await models.StructureOff.findAll({
where: {
structure: { $in: strucIdArr },
state: 0
}
}) : []
// 查在线率
const strucOnlineClient = ctx.app.fs.esclient.strucOnline const strucOnlineClient = ctx.app.fs.esclient.strucOnline
const onlineRes = await strucOnlineClient.search({ const onlineRes = await strucOnlineClient.search({
index: strucOnlineClient.config.index, index: strucOnlineClient.config.index,
@ -264,7 +273,7 @@ async function groupStatisticOnline (ctx) {
{ {
"terms": { "terms": {
"structure": strucIdArr, "structure": strucIdArr,
"structure": [1, 2, 3] // "structure": [1, 2, 3]
} }
} }
] ]
@ -280,10 +289,28 @@ async function groupStatisticOnline (ctx) {
} }
}) })
for (let struc of strucRes) {
let curOnline =
onlineRes.hits.hits
.filter((h) => h._source.structure == struc.id)
// .sort((a, b) => {
// return a._source.collect_time - b._source.collect_time
// })
.map(s => {
return {
...s._source,
rate: s._source.online / s._source.total * 100
}
})
let curOffline = maxOfflineTimeRes.find((o) => o.structure == struc.id)
struc.online = curOnline
struc.offline = curOffline || {}
}
ctx.status = 200; ctx.status = 200;
ctx.body = onlineRes.hits.hits; ctx.body = strucRes;
} catch (error) { } catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: error`); ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400; ctx.status = 400;
ctx.body = { ctx.body = {
message: typeof error == 'string' ? error : undefined message: typeof error == 'string' ? error : undefined

17
script/3.1/schema/1.create_p_group.sql

@ -0,0 +1,17 @@
create table if not exists project_group
(
id serial not null
constraint project_group_pk
primary key,
name varchar(256),
poms_project_ids integer[] not null,
poms_user_id integer not null
constraint project_group_user_id_fk
references "user"
);
comment on column project_group.poms_project_ids is '运维项目id';
create unique index if not exists project_group_id_uindex
on project_group (id);

22
script/3.1/schema/2.create_struc_off.sql

@ -0,0 +1,22 @@
create table if not exists t_structure_off
(
id serial not null
constraint t_structure_off_pk
primary key,
structure integer not null,
offline integer not null,
offtime varchar not null,
state integer not null
);
comment on column t_structure_off.structure is '结构物id';
comment on column t_structure_off.offline is '离线时长(分钟)';
comment on column t_structure_off.offtime is '最后数据时间';
comment on column t_structure_off.state is '数据状态( 0:有效,1:无效)';
create unique index if not exists t_structure_off_id_uindex
on t_structure_off (id);

2
web/client/src/sections/install/routes.js

@ -30,7 +30,7 @@ export default [
component: System, component: System,
breadcrumb: '系统映射', breadcrumb: '系统映射',
}] }]
},, { }, {
path: '/order', path: '/order',
key: 'order', key: 'order',
breadcrumb: '工单管理', breadcrumb: '工单管理',

Loading…
Cancel
Save