From 456692865ca228e21f357f385bfafe4cae875bdc Mon Sep 17 00:00:00 2001 From: wenlele Date: Tue, 28 Nov 2023 14:14:51 +0800 Subject: [PATCH] iotRequest --- api/.vscode/launch.json | 3 +- api/app/lib/controllers/analysis/network.js | 301 ++---------------- api/app/lib/routes/analysis/network.js | 5 + .../src/sections/analysis/actions/network.js | 15 + .../sections/analysis/containers/network.jsx | 2 +- .../sections/analysis/containers/treeShow.jsx | 13 +- web/client/src/utils/webapi.js | 2 +- 7 files changed, 51 insertions(+), 290 deletions(-) diff --git a/api/.vscode/launch.json b/api/.vscode/launch.json index 36dfe13..565ecb2 100644 --- a/api/.vscode/launch.json +++ b/api/.vscode/launch.json @@ -28,7 +28,8 @@ "-c https://camundatest.anxinyun.cn", "-r fs-workflow", // "-e http://10.8.30.60:5601", - "--iotaProxy http://10.8.30.157:17007", + // "--iotaProxy http://10.8.30.157:17007", + "--iotaProxy http://iotaproxy.anxinyun.cn", //商用 // "--redisHost localhost", "--redisPort 6379", diff --git a/api/app/lib/controllers/analysis/network.js b/api/app/lib/controllers/analysis/network.js index 18c9e0c..f6fdd9e 100644 --- a/api/app/lib/controllers/analysis/network.js +++ b/api/app/lib/controllers/analysis/network.js @@ -1,314 +1,48 @@ 'use strict'; const moment = require('moment') -async function getMaintenceRecordRank (ctx) { - const sequelize = ctx.fs.dc.orm - const Sequelize = ctx.fs.dc.ORM; - const { clickHouse } = ctx.app.fs - const models = ctx.fs.dc.models - const { startTime, endTime } = ctx.query - console.log(startTime, endTime, ctx.query, '1212312') +async function getOrganizationsStruc (ctx) { try { - const res = await sequelize.query(` - SELECT emrp.project_id,count(1) -FROM equipment_maintenance_record - RIGHT JOIN equipment_maintenance_record_project emrp - on equipment_maintenance_record.id = emrp.equipment_maintenance_record_id - where report_time BETWEEN :startTime AND :endTime -GROUP BY emrp.project_id - ` - , { - replacements: { - startTime: moment(startTime).format('YYYY-MM-DD HH:mm:ss'), - endTime: moment(endTime).format('YYYY-MM-DD HH:mm:ss ') - } - //, type: sequelize.QueryTypes.SELECT - } - ) - //查询equipment_maintenance_record返回的结果[{project_id: 22, count: 1}] - let projectList = [] - //存project的id - let projectIdList = [] - // console.log('resssss', res) - if (res.length > 0) { - res[0].forEach((item) => { - projectList.push({ project_id: item.project_id, count: Number(item.count) }) - projectIdList.push(item.project_id) - }) - } - const projectNameList = await models.ProjectCorrelation.findAll({ - attributes: - ['id', 'name'], - where: { - id: { $in: projectIdList }, - name: { - [Sequelize.Op.not]: null//有name的结果 - } - // del: false - } - }) || [] - //在ProjectCorrelation中查不到名字,去clickHouse中去查 - const projectNameList1 = await models.ProjectCorrelation.findAll({ - attributes: - ['id', 'name', 'pepProjectId'], - where: { - id: { $in: projectIdList }, - name: { - [Sequelize.Op.eq]: null//无name的结果 - } - // del: false - } - }) - //存放需要去查询clickHouse的id - let idList = new Set() - if (projectNameList1.length) { - projectNameList1.forEach((item) => { - idList.add(item.pepProjectId) - }) - } - //pepProject名称 - const projectManageName = idList.size ? await clickHouse.projectManage.query(` - SELECT id,project_name FROM t_pim_project - WHERE id IN (${[...idList].join(',')}, -1) - `).toPromise() : [] - // if (projectList.length) { - // projectList.forEach((item) => { - // projectManageName - // }) - // } - //存的是{id,projectName} - let project = [] - if (projectNameList1.length && projectManageName.length) { - projectManageName.forEach((item) => { - const pepObj = projectNameList1.find((item1) => { return item1.pepProjectId === item.id }) - project.push({ id: pepObj.id, projectName: item.project_name }) - }) - } - const resAll = project.concat(projectNameList) - let mergedArray = [] - if (resAll.length && projectList) { - mergedArray = projectList.map(obj1 => { - const matchingObj = resAll.find(obj2 => obj2.id === obj1.project_id); - return { id: obj1.project_id, pepProjectId: matchingObj.id, projectName: matchingObj.projectName || matchingObj.dataValues.name, count: obj1.count }; - }); - } - // console.log('ididididid', resAll) - // console.log('ididididid', project) - // console.log('ididididid', projectManageName) - // console.log('ididididid', projectNameList) - // console.log('ididididid', projectList) - - ctx.status = 200 - ctx.body = mergedArray - } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - ctx.status = 400; - ctx.body = { - message: '查询维修记录排名失败' - } - } -} - + const { utils: { anxinStrucIdRange } } = ctx.app.fs + const { pepProjectId } = ctx.params -async function getMaintenceTotal (ctx) { - const sequelize = ctx.fs.dc.orm - const Sequelize = ctx.fs.dc.ORM; - const { clickHouse } = ctx.app.fs - const models = ctx.fs.dc.models - const { startTime, endTime } = ctx.query - try { - //所有维修记录 - const res = await sequelize.query(` - SELECT emrp.project_id, - count(case when record.status in ('维修中','待维修','维修完成') then record.id end) incomplete, - count(case when record.status in ('维修完成') then record.id end) completed - FROM equipment_maintenance_record record - RIGHT JOIN equipment_maintenance_record_project emrp - on record.id = emrp.equipment_maintenance_record_id - where report_time BETWEEN :startTime AND :endTime - GROUP BY emrp.project_id - ` - , { - replacements: { - startTime: moment(startTime).format('YYYY-MM-DD HH:mm:ss '), - endTime: moment(endTime).format('YYYY-MM-DD HH:mm:ss ') - } - //, type: sequelize.QueryTypes.SELECT - } - ) - //查询equipment_maintenance_record返回的结果[{project_id: 22,status:'' count: 1}] - let projectList = [] - //存project的id - let projectIdList = new Set() - // console.log('resssss', res) - if (res.length > 0) { - res[0].forEach((item) => { - projectList.push({ project_id: item.project_id, 'incomplete': Number(item.incomplete), completed: Number(item.completed) }) - projectIdList.add(item.project_id) - }) + if (!pepProjectId) { + throw '缺少参数 pepProjectId' } - // const result = projectList.reduce((acc, curr) => { - // if (curr.status === '待维修' || curr.status === '维修中') { - // const existingItem = acc.find(item => item.project_id === curr.project_id && item.status === '异常数'); - // if (existingItem) { - // existingItem.count += curr.count; - // } else { - // acc.push({ project_id: curr.project_id, status: '异常数', count: curr.count }); - // } - // } else if (curr.status === '维修完成') { - // const existingItem = acc.find(item => item.project_id === curr.project_id && item.status === '维修数'); - // if (existingItem) { - // existingItem.count += curr.count; - // } else { - // acc.push({ project_id: curr.project_id, status: '维修数', count: curr.count }); - // } - // } - // return acc; - // }, []) - //console.log('resssssresult', result) - const projectNameList = await models.ProjectCorrelation.findAll({ - attributes: - ['id', 'name'], - where: { - id: { $in: [...projectIdList] }, - name: { - [Sequelize.Op.not]: null//有name的结果 - } - // del: false - } + let anxinStruc = await anxinStrucIdRange({ + ctx, pepProjectId }) || [] - //在ProjectCorrelation中查不到名字,去clickHouse中去查 - const projectNameList1 = await models.ProjectCorrelation.findAll({ - attributes: - ['id', 'name', 'pepProjectId'], - where: { - id: { $in: [...projectIdList] }, - name: { - [Sequelize.Op.eq]: null//无name的结果 - } - // del: false - } - }) - //存放需要去查询clickHouse的id - let idList = new Set() - if (projectNameList1.length) { - projectNameList1.forEach((item) => { - idList.add(item.pepProjectId) - }) - } - //pepProject名称 - const projectManageName = idList.size ? await clickHouse.projectManage.query(` - SELECT id,project_name FROM t_pim_project - WHERE id IN (${[...idList].join(',')}, -1) - `).toPromise() : [] - let project = [] - if (projectNameList1.length && projectManageName.length) { - projectManageName.forEach((item) => { - const pepObj = projectNameList1.find((item1) => { return item1.pepProjectId === item.id }) - project.push({ id: pepObj.id, projectName: item.project_name }) - }) - } - //pg的数据和clcikHouse的数据(名字)合并 - const resAll = project.concat(projectNameList) - let mergedArray = [] - if (resAll.length && projectList) { - mergedArray = projectList.map(obj1 => { - const matchingObj = resAll.find(obj2 => obj2.id === obj1.project_id) - return { - id: obj1.project_id, incomplete: obj1.incomplete, completed: obj1.completed, pepProjectId: matchingObj.id, - projectName: matchingObj.projectName || matchingObj.dataValues.name - } - }); - } - - // console.log('ididididid', resAll) - // console.log('ididididid', project) - // console.log('ididididid', projectManageName) - // console.log('ididididid', projectNameList) - // console.log('ididididid', projectList) - ctx.status = 200 - ctx.body = mergedArray - } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - ctx.status = 400; - ctx.body = { - message: '查询维修记录统计失败' - } - } - - -} -async function getEquipmentCategory (ctx) { - const { startTime, endTime } = ctx.query - const Sequelize = ctx.fs.dc.ORM - const models = ctx.fs.dc.models - try { - const res = await models.EquipmentMaintenanceRecord.findAll({ - attributes: [ - 'equipment_category', - [Sequelize.fn('COUNT', Sequelize.col('equipment_category')), 'count'] - ], - where: { reportTime: { $between: [moment(startTime).format('YYYY-MM-DD HH:mm:ss '), moment(endTime).format('YYYY-MM-DD HH:mm:ss ')] } }, - group: ['equipment_category'] - }) - ctx.status = 200 - ctx.body = res - - } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - ctx.status = 400; - ctx.body = { - message: '查询设备类型失败' - } - } -} - - -async function getStatus (ctx) { - const { startTime, endTime } = ctx.query - const Sequelize = ctx.fs.dc.ORM - const models = ctx.fs.dc.models - try { - const res = await models.EquipmentMaintenanceRecord.findAll({ - attributes: [ - 'status', - [Sequelize.fn('COUNT', Sequelize.col('status')), 'count'] - ], - where: { reportTime: { $between: [moment(startTime).format('YYYY-MM-DD HH:mm:ss '), moment(endTime).format('YYYY-MM-DD HH:mm:ss ')] } }, - group: ['status'] - }) ctx.status = 200 - ctx.body = res + ctx.body = anxinStruc } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = { - message: '查询设备类型失败' + message: '获取项目下的结构物信息失败' } } } -async function getOrganizationsStruc (ctx) { +async function getThingsDeploy (ctx) { try { const { utils: { anxinStrucIdRange } } = ctx.app.fs - const { pepProjectId } = ctx.params + const { thingId } = ctx.params - if (!pepProjectId) { - throw '缺少参数 pepProjectId' + if (!thingId) { + throw '缺少参数 thingId' } - let anxinStruc = await anxinStrucIdRange({ - ctx, pepProjectId - }) || [] + let iotaResponse = await ctx.app.fs.iotRequest.get(`/things/${thingId}/deploys`) || {} + ctx.status = 200 - ctx.body = anxinStruc + ctx.body = iotaResponse.body } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = { - message: '查询设备类型失败' + message: '获取设备部署信息失败' } } } @@ -317,4 +51,5 @@ async function getOrganizationsStruc (ctx) { module.exports = { getOrganizationsStruc, + getThingsDeploy, } \ No newline at end of file diff --git a/api/app/lib/routes/analysis/network.js b/api/app/lib/routes/analysis/network.js index b252af9..a038608 100644 --- a/api/app/lib/routes/analysis/network.js +++ b/api/app/lib/routes/analysis/network.js @@ -5,6 +5,11 @@ module.exports = function (app, router, opts) { app.fs.api.logAttr['GET/organizations/:pepProjectId/struc'] = { content: '获取项目下的结构物信息', visible: true }; router.get('/organizations/:pepProjectId/struc', network.getOrganizationsStruc) + app.fs.api.logAttr['GET/things/:thingId/deploy'] = { content: '获取设备部署信息', visible: true }; + router.get('/things/:thingId/deploy', network.getThingsDeploy) + + + // app.fs.api.logAttr['GET/systemAvailability'] = { content: '获取系统可用性', visible: true }; // router.get('/systemAvailability', operationData.getSystemAvailability) diff --git a/web/client/src/sections/analysis/actions/network.js b/web/client/src/sections/analysis/actions/network.js index bd6edc6..0e4e47b 100644 --- a/web/client/src/sections/analysis/actions/network.js +++ b/web/client/src/sections/analysis/actions/network.js @@ -14,6 +14,21 @@ export function getOrganizationsStruc (id) { }) } + +export function getThingsDeploy (id) { + return dispatch => basicAction({ + type: 'get', + dispatch: dispatch, + actionType: 'GET_THINGS_DEPLOY', + url: `${ApiTable.thingsDeploy.replace('{thingId}', id)}`, + msg: { error: '获取设备部署信息失败' }, + reducer: { name: 'thingsDeploy' } + }) +} + + + + // export function getSystemAvailability() { // return dispatch => basicAction({ // type: 'get', diff --git a/web/client/src/sections/analysis/containers/network.jsx b/web/client/src/sections/analysis/containers/network.jsx index fa06301..aae0771 100644 --- a/web/client/src/sections/analysis/containers/network.jsx +++ b/web/client/src/sections/analysis/containers/network.jsx @@ -154,7 +154,7 @@ const Network = ({ } > - {show == 'tree' && } + {show == 'tree' && } {show == 'table' && } diff --git a/web/client/src/sections/analysis/containers/treeShow.jsx b/web/client/src/sections/analysis/containers/treeShow.jsx index e0a3f72..b589bbc 100644 --- a/web/client/src/sections/analysis/containers/treeShow.jsx +++ b/web/client/src/sections/analysis/containers/treeShow.jsx @@ -6,15 +6,20 @@ import { Spin, Card, CardGroup, Form, Button } from '@douyinfe/semi-ui'; -const Network = (props) => { - const { dispatch, actions, user, clientHeight } = props +const Network = ({ dispatch, actions, user, clientHeight, thingId }) => { + + const { analysis } = actions const form = useRef(); //表单 useEffect(() => { - - }, []) + if (thingId) { + dispatch(analysis.getThingsDeploy(thingId)) + + } + + }, [thingId]) return ( diff --git a/web/client/src/utils/webapi.js b/web/client/src/utils/webapi.js index c568224..576abf6 100644 --- a/web/client/src/utils/webapi.js +++ b/web/client/src/utils/webapi.js @@ -153,7 +153,7 @@ export const ApiTable = { //分析-一图统揽 organizationsStruc: 'organizations/{pepProjectId}/struc', //获取项目下的结构物信息 - + thingsDeploy: 'things/{thingId}/deploy',//获取设备部署信息-组网数据 respondRecord: 'respond-record', //待办工单