zhaobing
12 months ago
14 changed files with 1045 additions and 212 deletions
@ -0,0 +1,162 @@ |
|||||
|
async function findPatrolRecords(ctx) { |
||||
|
const models = ctx.fs.dc.models; |
||||
|
const sequelize = ctx.fs.dc.orm; |
||||
|
try { |
||||
|
const { projectId } = ctx.query |
||||
|
let generalInclude = [ |
||||
|
{ model: models.PatrolRecordIssueHandle }, |
||||
|
] |
||||
|
const rslt = await models.PatrolRecord.findAll({ |
||||
|
where: { projectId: { $in: projectId.split(',') }, alarm: true }, |
||||
|
include: generalInclude, |
||||
|
}) |
||||
|
const res = rslt.reduce((acc, record) => { |
||||
|
const pointId = record.pointId |
||||
|
const inspectionTime = record.inspectionTime |
||||
|
const obj = acc.find(r => r.pointId === pointId); |
||||
|
if (!obj) { |
||||
|
acc.push(record) |
||||
|
} else if (obj && inspectionTime > record.inspectionTime) { |
||||
|
record.findIndex(r => r.pointId === pointId) |
||||
|
acc.splice(index, 1) |
||||
|
acc.push(record) |
||||
|
} |
||||
|
return acc; |
||||
|
}, []); |
||||
|
ctx.body = res |
||||
|
ctx.status = 200 |
||||
|
} catch (error) { |
||||
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
||||
|
ctx.status = 400; |
||||
|
ctx.body = { message: '运行监控的列表' } |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
async function getProjectPoints(ctx) { |
||||
|
let rslt = null |
||||
|
try { |
||||
|
const { projectId } = ctx.query |
||||
|
const models = ctx.fs.dc.models; |
||||
|
rslt = await models.Point.findAll({ |
||||
|
attributes: ['id', 'name', 'equipmentNo', 'equipmentModel'], |
||||
|
where: { projectId: { $in: projectId.split(',') } } |
||||
|
}) |
||||
|
ctx.status = 200; |
||||
|
ctx.body = rslt; |
||||
|
} catch (err) { |
||||
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${err}`); |
||||
|
ctx.status = 400; |
||||
|
ctx.body = { |
||||
|
name: 'FindError', |
||||
|
message: '获取结构物点位列表失败' |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
async function getDeployPoints(ctx) { |
||||
|
let rslt = null; |
||||
|
try { |
||||
|
const { pictureId } = ctx.query; |
||||
|
const models = ctx.fs.dc.models; |
||||
|
const heatmap = await models.ProjectGraph.findOne({ where: { id: { $in: pictureId.split(',') } } }) |
||||
|
if (heatmap) { |
||||
|
rslt = await models.ProjectPointsDeploy.findAll({ |
||||
|
where: { graphId: { $in: pictureId.split(',') } } |
||||
|
}) |
||||
|
ctx.status = 200; |
||||
|
ctx.body = rslt; |
||||
|
} else { |
||||
|
throw new Error('pictureId not found'); |
||||
|
} |
||||
|
} catch (err) { |
||||
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${err}`); |
||||
|
ctx.status = 400; |
||||
|
ctx.body = { |
||||
|
name: 'FindError', |
||||
|
message: '获取结构物平面图测点布设失败' |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
async function findSingleGraph(ctx, next) { |
||||
|
const models = ctx.fs.dc.models; |
||||
|
let error = { name: 'FindSingleError', message: '查询单一数据失败' }; |
||||
|
let rslt = null; |
||||
|
const { projectId,subType } = ctx.query; |
||||
|
try { |
||||
|
rslt = await ctx.fs.dc.models.Project.findAll({ |
||||
|
where: { id: { $in: projectId.split(',') },subType}, attributes: ['id', 'sub_type',], |
||||
|
include: [{ |
||||
|
model: models.ProjectGraph |
||||
|
} |
||||
|
] |
||||
|
}); |
||||
|
|
||||
|
error = null; |
||||
|
} catch (err) { |
||||
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${err}`); |
||||
|
} |
||||
|
if (error) { |
||||
|
ctx.status = 400; |
||||
|
ctx.body = error; |
||||
|
} else { |
||||
|
ctx.status = 200; |
||||
|
ctx.body = rslt; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
async function findProjects(ctx, next) { |
||||
|
let rslt = {} |
||||
|
const { projectId } = ctx.query; |
||||
|
try { |
||||
|
rslt = await ctx.fs.dc.models.Project.findAll({ |
||||
|
where: { id: { $in: projectId.split(',') } } |
||||
|
}) |
||||
|
ctx.status = 200; |
||||
|
ctx.body = rslt; |
||||
|
|
||||
|
} catch (error) { |
||||
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
||||
|
ctx.status = 400; |
||||
|
ctx.body = { message: '运行监控的列表' } |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
async function findNewestRecord(ctx, next) { |
||||
|
const models = ctx.fs.dc.models; |
||||
|
const { pointId } = ctx.query; |
||||
|
const sequelize = ctx.fs.dc.orm; |
||||
|
try{ |
||||
|
const rs=await sequelize.query(` |
||||
|
SELECT p.* |
||||
|
FROM ( |
||||
|
SELECT id,point_id,alarm,points,inspection_time, ROW_NUMBER() OVER (PARTITION BY point_id ORDER BY inspection_time DESC) AS row_num |
||||
|
FROM patrol_record |
||||
|
WHERE point_id in (${pointId}) |
||||
|
) AS p |
||||
|
WHERE p.row_num = 1; |
||||
|
`)
|
||||
|
|
||||
|
ctx.status = 200 |
||||
|
ctx.body = rs[0]; |
||||
|
}catch(error){ |
||||
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
||||
|
ctx.status = 400; |
||||
|
ctx.body = { message: '查询巡检最新记录失败' } |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
module.exports = { |
||||
|
findPatrolRecords, |
||||
|
getProjectPoints, |
||||
|
getDeployPoints, |
||||
|
findSingleGraph, |
||||
|
findProjects, |
||||
|
findNewestRecord |
||||
|
} |
@ -0,0 +1,26 @@ |
|||||
|
'use strict'; |
||||
|
const run = require('../../controllers/bigScreen/run'); |
||||
|
|
||||
|
module.exports = function (app, router, opts) { |
||||
|
|
||||
|
|
||||
|
app.fs.api.logAttr['GET/bigScreen/patrol/record'] = { content: '', visible: false }; |
||||
|
router.get('/bigScreen/patrol/record',run.findPatrolRecords) |
||||
|
|
||||
|
|
||||
|
app.fs.api.logAttr['GET/bigScreen/picture/deploy/points'] = { content: '获取点位布设信息', visible: false }; |
||||
|
router.get('bigScreen//picture/deploy/points', run.getDeployPoints); |
||||
|
|
||||
|
app.fs.api.logAttr['GET/bigScreen/project/all/points'] = { content: '获取结构物点位列表', visible: false }; |
||||
|
router.get('/bigScreen/project/all/points', run.getProjectPoints); |
||||
|
|
||||
|
app.fs.api.logAttr['GET/bigScreen/project/planarGraph'] = { content: '获取结构物平面图数据', visible: false }; |
||||
|
router.get('/bigScreen/project/planarGraph', run.findSingleGraph); |
||||
|
|
||||
|
app.fs.api.logAttr['GET/bigScreen/projects'] = { content: '获取结构物', visible: false }; |
||||
|
router.get('/bigScreen/projects', run.findProjects) |
||||
|
|
||||
|
app.fs.api.logAttr['GET/bigScreen/newestRecord'] = { content: '获取最新巡检记录', visible: false }; |
||||
|
router.get('/bigScreen/newestRecord', run.findNewestRecord) |
||||
|
|
||||
|
} |
@ -1,6 +1,7 @@ |
|||||
'use strict'; |
'use strict'; |
||||
import leader from './leader' |
import leader from './leader' |
||||
|
import run from './run' |
||||
export default { |
export default { |
||||
...leader, |
...leader,...run |
||||
|
|
||||
} |
} |
@ -0,0 +1,103 @@ |
|||||
|
'use strict'; |
||||
|
import { basicAction } from '@peace/utils' |
||||
|
import { ApiTable } from '$utils' |
||||
|
|
||||
|
export function getSubSystemPatrolAbout(query) { |
||||
|
return dispatch => basicAction({ |
||||
|
type: 'get', |
||||
|
query, |
||||
|
dispatch: dispatch, |
||||
|
actionType: 'GET_SUB_STYSTEM_PATROL_ABOUT', |
||||
|
url: `${ApiTable.getSubSystemPatrolAbout}`, |
||||
|
msg: { error: '获取巡检记录数' }, |
||||
|
reducer: { name: 'subSystemPatrols'} |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
export function records(query) { |
||||
|
return (dispatch) => basicAction({ |
||||
|
type: 'get', |
||||
|
dispatch, |
||||
|
query, |
||||
|
actionType: 'GET_PATROL_RECORD_LIST', |
||||
|
url: `${ApiTable.getRecord}`, |
||||
|
msg: { error: '获取巡检记录失败', }, |
||||
|
reducer: { name: 'record' } |
||||
|
}); |
||||
|
} |
||||
|
export function getProjectGraph(query) { |
||||
|
return (dispatch) => basicAction({ |
||||
|
type: 'get', |
||||
|
dispatch, |
||||
|
query, |
||||
|
actionType: 'GET_PROJECT_PLANAR_GRAPH', |
||||
|
url: ApiTable.getProjectGraph, |
||||
|
msg: { option: '获取结构物平面图' }, |
||||
|
reducer: { name: 'projectGraph' } |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
export function getProjectPoints(query) { |
||||
|
return (dispatch) => basicAction({ |
||||
|
type: 'get', |
||||
|
dispatch, |
||||
|
query, |
||||
|
actionType: 'GET_PROJECT_ALL_POINTS', |
||||
|
url: ApiTable.getProjectPoints, |
||||
|
msg: { option: '获取结构物所有点位' }, |
||||
|
reducer: { name: 'projectAllPoints' } |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
export function getDeployPoints(query) { |
||||
|
return (dispatch) => basicAction({ |
||||
|
type: 'get', |
||||
|
dispatch, |
||||
|
query, |
||||
|
actionType: 'GET_PROJECT_DEPLOY_POINTS', |
||||
|
url: ApiTable.getDeployPoints, |
||||
|
msg: { option: '获取结构物平面图测点分布' }, |
||||
|
reducer: { name: 'projectDeployPoints' } |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
export function getProjects(query) { |
||||
|
return (dispatch) => basicAction({ |
||||
|
type: 'get', |
||||
|
dispatch, |
||||
|
query, |
||||
|
actionType: 'GET_PROJECTS', |
||||
|
url: ApiTable.getProjects, |
||||
|
msg: { option: '获取结构物' }, |
||||
|
reducer: { name: 'projects' } |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
export function findNewestRecord(query) { |
||||
|
return (dispatch) => basicAction({ |
||||
|
type: 'get', |
||||
|
dispatch, |
||||
|
query, |
||||
|
actionType: 'FIND_NEWEST_RECORD', |
||||
|
url: ApiTable.findNewestRecord, |
||||
|
msg: { option: '获取点位最新巡检记录' }, |
||||
|
reducer: { name: 'newestRecords' } |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
export default{ |
||||
|
getSubSystemPatrolAbout, |
||||
|
getDeployPoints, |
||||
|
getProjectPoints, |
||||
|
getProjects, |
||||
|
records, |
||||
|
getProjectGraph, |
||||
|
getDeployPoints, |
||||
|
findNewestRecord |
||||
|
|
||||
|
} |
Loading…
Reference in new issue