wenlele
1 year ago
14 changed files with 722 additions and 291 deletions
@ -0,0 +1,320 @@ |
|||||
|
'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') |
||||
|
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: '查询维修记录排名失败' |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
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) |
||||
|
}) |
||||
|
} |
||||
|
// 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
|
||||
|
} |
||||
|
}) || [] |
||||
|
//在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 |
||||
|
|
||||
|
} catch (error) { |
||||
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
||||
|
ctx.status = 400; |
||||
|
ctx.body = { |
||||
|
message: '查询设备类型失败' |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
async function getOrganizationsStruc (ctx) { |
||||
|
try { |
||||
|
const { utils: { anxinStrucIdRange } } = ctx.app.fs |
||||
|
const { pepProjectId } = ctx.params |
||||
|
|
||||
|
if (!pepProjectId) { |
||||
|
throw '缺少参数 pepProjectId' |
||||
|
} |
||||
|
let anxinStruc = await anxinStrucIdRange({ |
||||
|
ctx, pepProjectId |
||||
|
}) || [] |
||||
|
ctx.status = 200 |
||||
|
ctx.body = anxinStruc |
||||
|
|
||||
|
} catch (error) { |
||||
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
||||
|
ctx.status = 400; |
||||
|
ctx.body = { |
||||
|
message: '查询设备类型失败' |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
module.exports = { |
||||
|
getOrganizationsStruc, |
||||
|
} |
@ -0,0 +1,16 @@ |
|||||
|
'use strict'; |
||||
|
const network = require('../../controllers/analysis/network'); |
||||
|
|
||||
|
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/systemAvailability'] = { content: '获取系统可用性', visible: true };
|
||||
|
// router.get('/systemAvailability', operationData.getSystemAvailability)
|
||||
|
|
||||
|
// app.fs.api.logAttr['GET/problemType'] = { content: '获取故障类型', visible: true };
|
||||
|
// router.get('/problemType', operationData.getProblemType)
|
||||
|
|
||||
|
// app.fs.api.logAttr['GET/operationsPersonnel'] = { content: '获取运维人员', visible: true };
|
||||
|
// router.get('/operationsPersonnel', operationData.getOperationsPersonnel)
|
||||
|
} |
@ -1,5 +1,5 @@ |
|||||
'use strict'; |
'use strict'; |
||||
const operationData = require('../../controllers/operationData'); |
const operationData = require('../../controllers/analysis/operationData'); |
||||
|
|
||||
module.exports = function (app, router, opts) { |
module.exports = function (app, router, opts) { |
||||
app.fs.api.logAttr['GET/failureTime'] = { content: '获取故障发生时间', visible: true }; |
app.fs.api.logAttr['GET/failureTime'] = { content: '获取故障发生时间', visible: true }; |
@ -1,5 +1,5 @@ |
|||||
'use strict'; |
'use strict'; |
||||
const problemData = require('../../controllers/problemData'); |
const problemData = require('../../controllers/analysis/problemData'); |
||||
|
|
||||
module.exports = function (app, router, opts) { |
module.exports = function (app, router, opts) { |
||||
app.fs.api.logAttr['GET/maintenceRecordRank'] = { content: '获取维修记录排名', visible: true }; |
app.fs.api.logAttr['GET/maintenceRecordRank'] = { content: '获取维修记录排名', visible: true }; |
@ -0,0 +1,50 @@ |
|||||
|
'use strict'; |
||||
|
|
||||
|
import { ApiTable, basicAction } from '$utils' |
||||
|
|
||||
|
|
||||
|
export function getOrganizationsStruc (id) { |
||||
|
return dispatch => basicAction({ |
||||
|
type: 'get', |
||||
|
dispatch: dispatch, |
||||
|
actionType: 'GET_ORGANIZATIONS_STRUC', |
||||
|
url: `${ApiTable.organizationsStruc.replace('{pepProjectId}', id)}`, |
||||
|
msg: { error: '获取项目下的结构物信息失败' }, |
||||
|
reducer: { name: 'organizationsStruc' } |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
// export function getSystemAvailability() {
|
||||
|
// return dispatch => basicAction({
|
||||
|
// type: 'get',
|
||||
|
// dispatch: dispatch,
|
||||
|
// actionType: 'GET_SYSTEM_AVAILABILITY',
|
||||
|
// url: ApiTable.getSystemAvailability,
|
||||
|
// msg: { error: '获取可用性分析' },
|
||||
|
// reducer: { name: 'systemAvailability' }
|
||||
|
// })
|
||||
|
// }
|
||||
|
|
||||
|
|
||||
|
// export function getProblemType() {
|
||||
|
// return dispatch => basicAction({
|
||||
|
// type: 'get',
|
||||
|
// dispatch: dispatch,
|
||||
|
// actionType: 'GET_PROBLEM_TYPE',
|
||||
|
// url: ApiTable.getProblemType,
|
||||
|
// msg: { error: '获取故障类型' },
|
||||
|
// reducer: { name: 'probleType' }
|
||||
|
// })
|
||||
|
// }
|
||||
|
|
||||
|
|
||||
|
// export function getOperationsPersonnel() {
|
||||
|
// return dispatch => basicAction({
|
||||
|
// type: 'get',
|
||||
|
// dispatch: dispatch,
|
||||
|
// actionType: 'GET_OPERATIONS_PERSONNEL',
|
||||
|
// url: ApiTable.getOperationsPersonnel,
|
||||
|
// msg: { error: '获取故障类型' },
|
||||
|
// reducer: { name: 'operationsPersonnel' }
|
||||
|
// })
|
||||
|
// }
|
@ -1,253 +1,254 @@ |
|||||
import React, { useEffect, useState } from 'react'; |
import React, { useEffect, useState } from 'react'; |
||||
import { connect } from 'react-redux'; |
import { connect } from 'react-redux'; |
||||
import { Button, Table, Popconfirm, Pagination,Select,Input,Switch,Notification,Progress } from '@douyinfe/semi-ui'; |
import { Button, Table, Popconfirm, Pagination, Select, Input, Switch, Notification, Progress } from '@douyinfe/semi-ui'; |
||||
import moment from 'moment' |
import moment from 'moment' |
||||
import FirmwareListModal from '../components/firmwareListModal'; |
import FirmwareListModal from '../components/firmwareListModal'; |
||||
|
|
||||
|
|
||||
const DeviceManagement = (props) => { |
const DeviceManagement = (props) => { |
||||
const {actions,dispatch,pepProjectId,user}=props |
const { actions, dispatch, pepProjectId, user } = props |
||||
const {firmwareUpgrade}=actions |
const { firmwareUpgrade } = actions |
||||
const [updataButtonDisabled,setUpdataButtonDisabled]=useState(true)//批量升级的按钮的显示与隐藏 |
const [updataButtonDisabled, setUpdataButtonDisabled] = useState(true)//批量升级的按钮的显示与隐藏 |
||||
const [firmwareModalVis,setFirmwareModalVis]=useState(false) |
const [firmwareModalVis, setFirmwareModalVis] = useState(false) |
||||
const [strucAndDeviceType,setStrucAndDeviceType]=useState([])// |
const [strucAndDeviceType, setStrucAndDeviceType] = useState([])// |
||||
const [struc,setStruc]=useState([])// |
const [struc, setStruc] = useState([])// |
||||
const [deviceType,setDeviceType]=useState([])//设备类型的optionList |
const [deviceType, setDeviceType] = useState([])//设备类型的optionList |
||||
const [data,setData]=useState([])//列表数据 |
const [data, setData] = useState([])//列表数据 |
||||
const [thingIds,setThingIds]=useState([])//结构物id数组 |
const [thingIds, setThingIds] = useState([])//结构物id数组 |
||||
const [defaultVal,setDefaultVal]=useState('')//设备类型id |
const [defaultVal, setDefaultVal] = useState('')//设备类型id |
||||
const [thingId,setThingId]=useState()//单个结构物id |
const [thingId, setThingId] = useState()//单个结构物id |
||||
const [searchVal,setSearchVal]=useState()//搜索框值 |
const [searchVal, setSearchVal] = useState()//搜索框值 |
||||
const [recordRow,setRecordRow]=useState() |
const [recordRow, setRecordRow] = useState() |
||||
const [selectedRows,setSelectedRows]=useState([])//选择的key |
const [selectedRows, setSelectedRows] = useState([])//选择的key |
||||
const [selectdR,setSelectedR]=useState([])//选择行 |
const [selectdR, setSelectedR] = useState([])//选择行 |
||||
const [vData,setVData]=useState([])//版本信息 |
const [vData, setVData] = useState([])//版本信息 |
||||
const [id,setId]=useState()//初始化展示的结构物 |
const [id, setId] = useState()//初始化展示的结构物 |
||||
const getData=(data)=>{ |
const getData = (data) => { |
||||
dispatch(firmwareUpgrade.getThingMessages(data)).then((res)=>{ |
dispatch(firmwareUpgrade.getThingMessages(data)).then((res) => { |
||||
if(res.success) { |
if (res.success) { |
||||
setData(res.payload.data) |
setData(res.payload.data) |
||||
} |
} |
||||
|
|
||||
}) |
|
||||
|
|
||||
} |
|
||||
useEffect(()=>{ |
|
||||
//结构物和设备类型 |
|
||||
dispatch(firmwareUpgrade.getStruc({pepProjectId})).then((res)=>{ |
|
||||
if(res.success) { |
|
||||
setStrucAndDeviceType( res.payload.data) |
|
||||
setStruc( res.payload.data?.map(item=>{ |
|
||||
return {label:item.strucName,value:item.thingId} |
|
||||
})) |
|
||||
setThingIds(res.payload.data?.map(item=>item.thingId)?.join(',')||'') |
|
||||
} |
|
||||
|
|
||||
}) |
|
||||
// console.log('xxxx111',user) |
|
||||
dispatch(firmwareUpgrade.getFirmware()).then(res=>{ |
|
||||
if(res.success) setVData(res.payload.data) |
|
||||
}) |
|
||||
},[]) |
|
||||
useEffect(()=>{ |
|
||||
if(thingIds&&thingIds.length){ |
|
||||
const data={thingIds:thingIds.split(',')[0]||'000'}//给一个初始化的值 |
|
||||
setId(thingIds.split(',')[0]) |
|
||||
getData(data) |
|
||||
} |
|
||||
},[thingIds]) |
|
||||
|
|
||||
const structChange =value => { |
|
||||
setId(value) |
|
||||
clearSelectedRows() |
|
||||
setUpdataButtonDisabled(true) |
|
||||
const deviceTypeList= strucAndDeviceType?.find(item=>item.thingId==value)?.deviceType?.map(child=>{ |
|
||||
return { |
|
||||
label:child.model, |
|
||||
value:child.id |
|
||||
} |
|
||||
})||[] |
|
||||
setDefaultVal('') |
|
||||
// console.log('event',deviceTypeList) |
|
||||
setDeviceType(deviceTypeList) |
|
||||
setThingId(value) |
|
||||
const data={thingIds:value,device_meta_id:defaultVal} |
|
||||
getData(data) |
|
||||
|
|
||||
}; |
|
||||
const deviceTypeChange=value=>{ |
|
||||
setUpdataButtonDisabled(true) |
|
||||
clearSelectedRows() |
|
||||
setDefaultVal(value) |
|
||||
const data={thingIds:thingId,device_meta_id:value} |
|
||||
getData(data) |
|
||||
// console.log(value,'event') |
|
||||
} |
|
||||
//清除结构物的逻辑 |
|
||||
const clearHandler=()=>{ |
|
||||
setUpdataButtonDisabled(true) |
|
||||
clearSelectedRows() |
|
||||
const data={thingIds} |
|
||||
getData(data) |
|
||||
|
|
||||
} |
|
||||
//清楚设备类型的逻辑 |
|
||||
const cleartypeHandler=()=>{ |
|
||||
setUpdataButtonDisabled(true) |
|
||||
clearSelectedRows() |
|
||||
setDefaultVal(null) |
|
||||
const data={thingIds:thingId} |
|
||||
getData(data) |
|
||||
} |
|
||||
//搜索按钮的逻辑 |
|
||||
const searchHandler=()=>{ |
|
||||
if(!thingId&&!defaultVal){ |
|
||||
const data={thingIds} |
|
||||
getData(data) |
|
||||
}else{ |
|
||||
const data={thingIds:thingId,device_meta_id:defaultVal,searchVal} |
|
||||
getData(data) |
|
||||
} |
|
||||
} |
|
||||
const clearSelectedRows = () => { |
|
||||
setSelectedRows([]); |
|
||||
}; |
|
||||
const rowSelection = { |
|
||||
selectedRowKeys: selectedRows, // 已选择的行的 keys |
|
||||
getCheckboxProps: record => ({ |
|
||||
name: record.name, |
|
||||
}), |
|
||||
|
|
||||
// onSelect: (record, selected) => { |
|
||||
// console.log(`select row: ${selected}`, record); |
|
||||
// }, |
|
||||
onSelectAll: (selected, selectedRows) => { |
|
||||
setUpdataButtonDisabled(!selectedRows.every(item=>selectedRows[0]?.deviceType===item.deviceType&&item.switchStatus)) |
|
||||
}, |
|
||||
onChange: (selectedRowKeys, selectedRows) => { |
|
||||
setSelectedR(selectedRows) |
|
||||
setSelectedRows(selectedRowKeys) |
|
||||
// console.log('xxxx',selectedRows) |
|
||||
//选择之后,清空选择 |
|
||||
if(selectedRows&&selectedRows.length===0){ |
|
||||
setUpdataButtonDisabled(true) |
|
||||
} |
|
||||
//选择很多的时候,如果有设备型号不对应的情况 |
|
||||
if(selectedRows&&selectedRows.length>0){ |
|
||||
setUpdataButtonDisabled(!selectedRows.every(item=>selectedRows[0].deviceType===item.deviceType&&item.switchStatus)) |
|
||||
} |
|
||||
|
|
||||
|
|
||||
}, |
|
||||
}; |
|
||||
|
|
||||
|
|
||||
|
|
||||
let columns=[{ |
|
||||
title: '序号', |
|
||||
render: (t, r, i) => { |
|
||||
return i + 1; |
|
||||
} |
|
||||
},{ |
|
||||
title: '设备名称', |
|
||||
dataIndex: 'deviceName' |
|
||||
},{ |
|
||||
title: '设备型号', |
|
||||
dataIndex: 'deviceType' |
|
||||
}, |
|
||||
{ |
|
||||
title: '固件名称', |
|
||||
dataIndex: 'firmwareName' |
|
||||
}, |
|
||||
{ |
|
||||
title: '固件版本号', |
|
||||
dataIndex: 'firmwareNo' |
|
||||
}, |
|
||||
{ |
|
||||
title: '升级状态', |
|
||||
render:(_,record)=>{ |
|
||||
return record.status!=='未升级'&&record.status!=='升级成功'?<Progress percent={parseFloat(record.updatePercentage||0)} showInfo></Progress>:record.status |
|
||||
} |
|
||||
}, |
|
||||
{ |
|
||||
title: '升级开关状态', |
|
||||
dataIndex: 'switchStatus' , |
|
||||
render:(_,record)=>{ |
|
||||
return <Switch disabled defaultChecked={record.switchStatus}></Switch> |
|
||||
} |
|
||||
}, |
|
||||
{ |
|
||||
title: '操作', |
|
||||
render:(_,record)=>{ |
|
||||
return <div> |
|
||||
<Button type="secondary" onClick={()=>{ |
|
||||
if(record.switchStatus){ |
|
||||
setFirmwareModalVis(true) |
|
||||
setRecordRow([record]) |
|
||||
}else{ |
|
||||
Notification.info({ |
|
||||
title: '提示', |
|
||||
content: '请到安心云平台打开升级开关后进行升级。', |
|
||||
duration: 3, |
|
||||
}) |
|
||||
} |
|
||||
if(record.status!=='未升级'&&record.status!=='升级成功'){ |
|
||||
Notification.info({ |
|
||||
title: '提示', |
|
||||
content: '该设备仍在升级中,请在完成升级后再操作。', |
|
||||
duration: 3, |
|
||||
}) |
|
||||
} |
|
||||
}}>固件升级</Button> |
|
||||
</div> |
|
||||
} |
|
||||
} |
|
||||
] |
|
||||
return <><div style={{ background: '#FFFFFF', margin: '8px 12px', padding: '20px 20px 0px 20px' }}> |
|
||||
<div style={{ display: 'flex', alignItems: 'center' }}> |
|
||||
<div style={{ display: 'flex', alignItems: 'center',marginRight:30 }}> |
|
||||
<div style={{ width: 0, height: 20, borderLeft: '3px solid #005ABD', borderTop: '3px solid transparent', borderBottom: '3px solid transparent' }}></div> |
|
||||
<div style={{ fontFamily: "YouSheBiaoTiHei", fontSize: 24, color: '#101531', marginLeft: 8 }}>设备管理</div> |
|
||||
<div style={{ marginLeft: 6, fontSize: 12, color: '#969799', fontFamily: "DINExp", }}>Device Management</div> |
|
||||
</div> |
|
||||
<Select placeholder='请选择结构物' optionList={struc} filter showClear |
|
||||
onChange={structChange} |
|
||||
onClear={clearHandler} |
|
||||
value={id} // 设置默认值为第一个选项的值 |
|
||||
style={{ width:300,marginRight:10}}> |
|
||||
</Select> |
|
||||
<Select placeholder='请选择设备型号' value={defaultVal} optionList={deviceType} |
|
||||
onClear={cleartypeHandler} |
|
||||
onChange={deviceTypeChange} |
|
||||
filter |
|
||||
showClear |
|
||||
style={{ width:300,marginRight:10}}></Select> |
|
||||
<Button style={{marginRight:10}} type="secondary" disabled={updataButtonDisabled} onClick={()=>{ |
|
||||
setFirmwareModalVis(true); |
|
||||
setRecordRow(selectdR) |
|
||||
}}>固件升级</Button> |
|
||||
<Input placeholder='请输入设备名称' style={{ width:300,marginRight:10}} onChange={(e)=>{setSearchVal(e)}}></Input> |
|
||||
<Button style={{marginRight:10}} type="secondary" theme='solid' |
|
||||
onClick={searchHandler} |
|
||||
>查询</Button> |
|
||||
|
|
||||
|
}) |
||||
|
|
||||
|
} |
||||
|
useEffect(() => { |
||||
|
//结构物和设备类型 |
||||
|
dispatch(firmwareUpgrade.getStruc({ pepProjectId })).then((res) => { |
||||
|
if (res.success) { |
||||
|
setStrucAndDeviceType(res.payload.data) |
||||
|
setStruc(res.payload.data?.map(item => { |
||||
|
return { label: item.strucName, value: item.thingId } |
||||
|
})) |
||||
|
setThingIds(res.payload.data?.map(item => item.thingId)?.join(',') || '') |
||||
|
} |
||||
|
|
||||
|
}) |
||||
|
// console.log('xxxx111',user) |
||||
|
dispatch(firmwareUpgrade.getFirmware()).then(res => { |
||||
|
if (res.success) setVData(res.payload.data) |
||||
|
}) |
||||
|
}, [pepProjectId]) |
||||
|
useEffect(() => { |
||||
|
if (thingIds && thingIds.length) { |
||||
|
const data = { thingIds: thingIds.split(',')[0] || '000' }//给一个初始化的值 |
||||
|
setId(thingIds.split(',')[0]) |
||||
|
getData(data) |
||||
|
} |
||||
|
}, [thingIds]) |
||||
|
|
||||
|
const structChange = value => { |
||||
|
setId(value) |
||||
|
clearSelectedRows() |
||||
|
setUpdataButtonDisabled(true) |
||||
|
const deviceTypeList = strucAndDeviceType?.find(item => item.thingId == value)?.deviceType?.map(child => { |
||||
|
return { |
||||
|
label: child.model, |
||||
|
value: child.id |
||||
|
} |
||||
|
}) || [] |
||||
|
setDefaultVal('') |
||||
|
// console.log('event',deviceTypeList) |
||||
|
setDeviceType(deviceTypeList) |
||||
|
setThingId(value) |
||||
|
const data = { thingIds: value, device_meta_id: defaultVal } |
||||
|
getData(data) |
||||
|
|
||||
|
}; |
||||
|
const deviceTypeChange = value => { |
||||
|
setUpdataButtonDisabled(true) |
||||
|
clearSelectedRows() |
||||
|
setDefaultVal(value) |
||||
|
const data = { thingIds: thingId, device_meta_id: value } |
||||
|
getData(data) |
||||
|
// console.log(value,'event') |
||||
|
} |
||||
|
//清除结构物的逻辑 |
||||
|
const clearHandler = () => { |
||||
|
setUpdataButtonDisabled(true) |
||||
|
clearSelectedRows() |
||||
|
const data = { thingIds } |
||||
|
getData(data) |
||||
|
|
||||
|
} |
||||
|
//清楚设备类型的逻辑 |
||||
|
const cleartypeHandler = () => { |
||||
|
setUpdataButtonDisabled(true) |
||||
|
clearSelectedRows() |
||||
|
setDefaultVal(null) |
||||
|
const data = { thingIds: thingId } |
||||
|
getData(data) |
||||
|
} |
||||
|
//搜索按钮的逻辑 |
||||
|
const searchHandler = () => { |
||||
|
if (!thingId && !defaultVal) { |
||||
|
const data = { thingIds } |
||||
|
getData(data) |
||||
|
} else { |
||||
|
const data = { thingIds: thingId, device_meta_id: defaultVal, searchVal } |
||||
|
getData(data) |
||||
|
} |
||||
|
} |
||||
|
const clearSelectedRows = () => { |
||||
|
setSelectedRows([]); |
||||
|
}; |
||||
|
const rowSelection = { |
||||
|
selectedRowKeys: selectedRows, // 已选择的行的 keys |
||||
|
getCheckboxProps: record => ({ |
||||
|
name: record.name, |
||||
|
}), |
||||
|
|
||||
|
// onSelect: (record, selected) => { |
||||
|
// console.log(`select row: ${selected}`, record); |
||||
|
// }, |
||||
|
onSelectAll: (selected, selectedRows) => { |
||||
|
setUpdataButtonDisabled(!selectedRows.every(item => selectedRows[0]?.deviceType === item.deviceType && item.switchStatus)) |
||||
|
}, |
||||
|
onChange: (selectedRowKeys, selectedRows) => { |
||||
|
setSelectedR(selectedRows) |
||||
|
setSelectedRows(selectedRowKeys) |
||||
|
// console.log('xxxx',selectedRows) |
||||
|
//选择之后,清空选择 |
||||
|
if (selectedRows && selectedRows.length === 0) { |
||||
|
setUpdataButtonDisabled(true) |
||||
|
} |
||||
|
//选择很多的时候,如果有设备型号不对应的情况 |
||||
|
if (selectedRows && selectedRows.length > 0) { |
||||
|
setUpdataButtonDisabled(!selectedRows.every(item => selectedRows[0].deviceType === item.deviceType && item.switchStatus)) |
||||
|
} |
||||
|
|
||||
|
|
||||
|
}, |
||||
|
}; |
||||
|
|
||||
|
|
||||
|
|
||||
|
let columns = [{ |
||||
|
title: '序号', |
||||
|
render: (t, r, i) => { |
||||
|
return i + 1; |
||||
|
} |
||||
|
}, { |
||||
|
title: '设备名称', |
||||
|
dataIndex: 'deviceName' |
||||
|
}, { |
||||
|
title: '设备型号', |
||||
|
dataIndex: 'deviceType' |
||||
|
}, |
||||
|
{ |
||||
|
title: '固件名称', |
||||
|
dataIndex: 'firmwareName' |
||||
|
}, |
||||
|
{ |
||||
|
title: '固件版本号', |
||||
|
dataIndex: 'firmwareNo' |
||||
|
}, |
||||
|
{ |
||||
|
title: '升级状态', |
||||
|
render: (_, record) => { |
||||
|
return record.status !== '未升级' && record.status !== '升级成功' ? <Progress percent={parseFloat(record.updatePercentage || 0)} showInfo></Progress> : record.status |
||||
|
} |
||||
|
}, |
||||
|
{ |
||||
|
title: '升级开关状态', |
||||
|
dataIndex: 'switchStatus', |
||||
|
render: (_, record) => { |
||||
|
return <Switch disabled defaultChecked={record.switchStatus}></Switch> |
||||
|
} |
||||
|
}, |
||||
|
{ |
||||
|
title: '操作', |
||||
|
render: (_, record) => { |
||||
|
return <div> |
||||
|
<Button type="secondary" onClick={() => { |
||||
|
if (record.switchStatus) { |
||||
|
setFirmwareModalVis(true) |
||||
|
setRecordRow([record]) |
||||
|
} else { |
||||
|
Notification.info({ |
||||
|
title: '提示', |
||||
|
content: '请到安心云平台打开升级开关后进行升级。', |
||||
|
duration: 3, |
||||
|
}) |
||||
|
} |
||||
|
if (record.status !== '未升级' && record.status !== '升级成功') { |
||||
|
Notification.info({ |
||||
|
title: '提示', |
||||
|
content: '该设备仍在升级中,请在完成升级后再操作。', |
||||
|
duration: 3, |
||||
|
}) |
||||
|
} |
||||
|
}}>固件升级</Button> |
||||
|
</div> |
||||
|
} |
||||
|
} |
||||
|
] |
||||
|
return <><div style={{ background: '#FFFFFF', margin: '8px 12px', padding: '20px 20px 0px 20px' }}> |
||||
|
<div style={{ display: 'flex', alignItems: 'center' }}> |
||||
|
<div style={{ display: 'flex', alignItems: 'center', marginRight: 30 }}> |
||||
|
<div style={{ width: 0, height: 20, borderLeft: '3px solid #005ABD', borderTop: '3px solid transparent', borderBottom: '3px solid transparent' }}></div> |
||||
|
<div style={{ fontFamily: "YouSheBiaoTiHei", fontSize: 24, color: '#101531', marginLeft: 8 }}>设备管理</div> |
||||
|
<div style={{ marginLeft: 6, fontSize: 12, color: '#969799', fontFamily: "DINExp", }}>Device Management</div> |
||||
|
</div> |
||||
|
<Select placeholder='请选择结构物' optionList={struc} filter showClear |
||||
|
onChange={structChange} |
||||
|
onClear={clearHandler} |
||||
|
value={id} // 设置默认值为第一个选项的值 |
||||
|
style={{ width: 300, marginRight: 10 }}> |
||||
|
</Select> |
||||
|
<Select placeholder='请选择设备型号' value={defaultVal} optionList={deviceType} |
||||
|
onClear={cleartypeHandler} |
||||
|
onChange={deviceTypeChange} |
||||
|
filter |
||||
|
showClear |
||||
|
style={{ width: 300, marginRight: 10 }}></Select> |
||||
|
<Button style={{ marginRight: 10 }} type="secondary" disabled={updataButtonDisabled} onClick={() => { |
||||
|
setFirmwareModalVis(true); |
||||
|
setRecordRow(selectdR) |
||||
|
}}>固件升级</Button> |
||||
|
<Input placeholder='请输入设备名称' style={{ width: 300, marginRight: 10 }} onChange={(e) => { setSearchVal(e) }}></Input> |
||||
|
<Button style={{ marginRight: 10 }} type="secondary" theme='solid' |
||||
|
onClick={searchHandler} |
||||
|
>查询</Button> |
||||
|
|
||||
|
</div> |
||||
|
<div style={{ marginTop: 10 }}> |
||||
|
<Table columns={columns} rowSelection={rowSelection} dataSource={data}></Table> |
||||
|
<FirmwareListModal vData={vData} versionData={data} modalVis={firmwareModalVis} recordRow={recordRow} onCancel={() => { setFirmwareModalVis(false); setRecordRow(null) }}></FirmwareListModal> |
||||
|
</div> |
||||
</div> |
</div> |
||||
<div style={{marginTop:10}}> |
</> |
||||
<Table columns={columns} rowSelection={rowSelection} dataSource={data}></Table> |
|
||||
<FirmwareListModal vData={vData} versionData={data} modalVis={firmwareModalVis} recordRow={recordRow} onCancel={()=>{setFirmwareModalVis(false);setRecordRow(null)}}></FirmwareListModal> |
|
||||
</div> |
|
||||
</div> |
|
||||
</> |
|
||||
} |
} |
||||
|
|
||||
function mapStateToProps (state) { |
function mapStateToProps (state) { |
||||
const { auth, global, getPush } = state; |
const { auth, global, getPush } = state; |
||||
return { |
console.log(222, global); |
||||
loading: getPush.isRequesting, |
return { |
||||
user: auth.user, |
loading: getPush.isRequesting, |
||||
actions: global.actions, |
user: auth.user, |
||||
pepProjectId:global.pepProjectId |
actions: global.actions, |
||||
}; |
pepProjectId: global.pepProjectId |
||||
} |
}; |
||||
|
} |
||||
export default connect(mapStateToProps)(DeviceManagement); |
|
||||
|
export default connect(mapStateToProps)(DeviceManagement); |
Loading…
Reference in new issue