Browse Source

元素错误信息 pepProjectId 保护

dev
巴林闲侠 3 years ago
parent
commit
8e2bff5640
  1. 2
      api/.vscode/launch.json
  2. 2
      api/app/lib/controllers/alarm/app.js
  3. 5
      api/app/lib/controllers/alarm/data.js
  4. 34
      api/app/lib/controllers/organization/index.js
  5. 2
      api/app/lib/models/user.js
  6. 16
      api/app/lib/utils/dataRange.js
  7. 2
      script/0.0.1/1.init_tables.sql

2
api/.vscode/launch.json

@ -51,7 +51,7 @@
"--clickHousePepEmis pepca8", "--clickHousePepEmis pepca8",
"--clickHouseProjectManage peppm8", "--clickHouseProjectManage peppm8",
"--clickHouseVcmp video_accrss1", "--clickHouseVcmp video_accrss1",
"--clickHouseDataAlarm default123", "--clickHouseDataAlarm default",
] ]
}, },
{ {

2
api/app/lib/controllers/alarm/app.js

@ -278,10 +278,12 @@ async function apiErrorList (ctx) {
for (let lr of listRes.rows) { for (let lr of listRes.rows) {
if (lr.app && lr.app.projectCorrelations) { if (lr.app && lr.app.projectCorrelations) {
for (let p of lr.app.projectCorrelations) { for (let p of lr.app.projectCorrelations) {
if (p.pepProjectId) {
pepProjectIds.add(p.pepProjectId) pepProjectIds.add(p.pepProjectId)
} }
} }
} }
}
if (pepProjectIds.size) { if (pepProjectIds.size) {
projectRes = await clickHouse.projectManage.query(` projectRes = await clickHouse.projectManage.query(`
${pepProjectSql} ${pepProjectSql}

5
api/app/lib/controllers/alarm/data.js

@ -4,13 +4,13 @@ async function list (ctx) {
try { try {
const { models } = ctx.fs.dc; const { models } = ctx.fs.dc;
const { clickHouse } = ctx.app.fs const { clickHouse } = ctx.app.fs
const { utils: { judgeSuper, anxinStrucRange } } = ctx.app.fs const { utils: { judgeSuper, anxinStrucIdRange } } = ctx.app.fs
const { database: anxinyun } = clickHouse.anxinyun.opts.config const { database: anxinyun } = clickHouse.anxinyun.opts.config
const isSuper = judgeSuper(ctx) const isSuper = judgeSuper(ctx)
let anxinStrucIds = null let anxinStrucIds = null
if (!isSuper) { if (!isSuper) {
anxinStrucIds = await anxinStrucRange(ctx) anxinStrucIds = await anxinStrucIdRange(ctx)
} }
const alarmRes = await clickHouse.dataAlarm.query(` const alarmRes = await clickHouse.dataAlarm.query(`
SELECT SELECT
@ -19,6 +19,7 @@ async function list (ctx) {
alarms alarms
LEFT JOIN ${anxinyun}.t_structure LEFT JOIN ${anxinyun}.t_structure
ON ${anxinyun}.t_structure.id = alarms.StructureId ON ${anxinyun}.t_structure.id = alarms.StructureId
${anxinStrucIds ? 'WHERE ' + anxinyun + '.t_structure.id IN (' + anxinStrucIds.join(",") + ')' : ''}
`).toPromise(); `).toPromise();
ctx.status = 200; ctx.status = 200;

34
api/app/lib/controllers/organization/index.js

@ -209,11 +209,43 @@ async function user (ctx) {
}) })
let userIds = new Set() let userIds = new Set()
let pomsProjectIds = new Set()
for (let u of userRes.rows.concat(adminRes)) { for (let u of userRes.rows.concat(adminRes)) {
userIds.add(u.pepUserId) userIds.add(u.pepUserId)
for (let pid of u.correlationProject) {
pomsProjectIds.add(pid)
} }
}
// 查用户所属的项企pep的部门、人员信息
let userPepRes = userIds.size ? let userPepRes = userIds.size ?
await clickHouse.pepEmis.query(`SELECT DISTINCT user.id AS id, "user"."name" AS name, department.name AS depName, department.id AS depId FROM department_user LEFT JOIN user ON department_user.user=user.id LEFT JOIN department ON department.id=department_user.department WHERE user.id IN (${[...userIds].join(',')}) AND department.delete=false`).toPromise() : await clickHouse.pepEmis.query(`
SELECT DISTINCT
user.id AS id, "user"."name" AS name, department.name AS depName, department.id AS depId
FROM department_user
LEFT JOIN user
ON department_user.user=user.id
LEFT JOIN department
ON department.id=department_user.department
WHERE
user.id IN (${[...userIds].join(',')})
AND department.delete=false`
).toPromise() :
[]
let pomsProjectRes = await models.ProjectCorrelation.findAll({
where: {
id: { $in: pomsProjectIds }
}
})
let pepPojectIds = new Set()
for (let pid of pomsProjectRes) {
}
let pepProjectRes = pomsProjectRes.length ?
await clickHouse.pepEmis.query(`
`).toPromise() :
[] []
for (let u of userRes.rows.concat(adminRes)) { for (let u of userRes.rows.concat(adminRes)) {

2
api/app/lib/models/user.js

@ -37,7 +37,7 @@ module.exports = dc => {
type: DataTypes.ARRAY(DataTypes.INTEGER), type: DataTypes.ARRAY(DataTypes.INTEGER),
allowNull: true, allowNull: true,
defaultValue: null, defaultValue: null,
comment: "关联的项目管理的项目id", comment: "关联的poms的项目id",
primaryKey: false, primaryKey: false,
field: "correlation_project", field: "correlation_project",
autoIncrement: false autoIncrement: false

16
api/app/lib/utils/dataRange.js

@ -14,7 +14,7 @@ module.exports = function (app, opts) {
} }
} }
async function anxinStrucRange (ctx) { async function anxinStrucIdRange (ctx) {
try { try {
const { models } = ctx.fs.dc; const { models } = ctx.fs.dc;
const { userInfo = {} } = ctx.fs.api || {}; const { userInfo = {} } = ctx.fs.api || {};
@ -22,15 +22,21 @@ module.exports = function (app, opts) {
const bindRes = await models.ProjectCorrelation.findAll({ const bindRes = await models.ProjectCorrelation.findAll({
where: { where: {
pepProjectId: { $in: correlationProject } id: { $in: correlationProject },
del: false
} }
}) })
return bindRes.reduce((arr, b) => { return [
...bindRes.reduce(
(arr, b) => {
for (let sid of b.anxinProjectId) { for (let sid of b.anxinProjectId) {
arr.add(sid); arr.add(sid);
} }
return arr; return arr;
}, new Set()) },
new Set()
)
]
} catch (error) { } catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
} }
@ -38,6 +44,6 @@ module.exports = function (app, opts) {
return { return {
judgeSuper, judgeSuper,
anxinStrucRange anxinStrucIdRange
} }
} }

2
script/0.0.1/1.init_tables.sql

@ -19,7 +19,7 @@ comment on column "user".pep_user_id is '项企对应用户id';
comment on column "user".role is '角色 也对应权限 admin 管理员 / all 全部角色 / data_analyst 数据分析 / after_sale 售后运维 / resource_manage 资源管理 / customer_service 客户服务'; comment on column "user".role is '角色 也对应权限 admin 管理员 / all 全部角色 / data_analyst 数据分析 / after_sale 售后运维 / resource_manage 资源管理 / customer_service 客户服务';
comment on column "user".correlation_project is '关联的项目管理的项目id'; comment on column "user".correlation_project is '关联的poms的项目id';
comment on column "user".online_duration is '在线时长 单位 s'; comment on column "user".online_duration is '在线时长 单位 s';

Loading…
Cancel
Save