Browse Source

feat:fix bugs

dev
zhaobing’ 1 year ago
parent
commit
51d9e69597
  1. 537
      api/app/lib/controllers/monitor/index.js
  2. 2
      web/client/src/sections/install/containers/burr.jsx
  3. 2
      web/client/src/sections/install/containers/interrupt.jsx
  4. 969
      web/client/src/sections/install/containers/trend.jsx

537
api/app/lib/controllers/monitor/index.js

@ -1,32 +1,32 @@
const moment = require('moment') const moment = require('moment')
const fs = require('fs') const fs = require('fs')
async function getStructures(ctx) { async function getStructures(ctx) {
try { try {
const { models } = ctx.fs.dc; const { models } = ctx.fs.dc
const { clickHouse } = ctx.app.fs const { clickHouse } = ctx.app.fs
const { pomsProjectId } = ctx.query const { pomsProjectId } = ctx.query
let bindRes = [] let bindRes = []
//选择全局就是查询所有项目下的结构物,有选择项目就只查询对应项目的结构物 //选择全局就是查询所有项目下的结构物,有选择项目就只查询对应项目的结构物
if (pomsProjectId) { if (pomsProjectId) {
bindRes = await models.ProjectCorrelation.findAll({ where: { id: { $in: pomsProjectId.split(',') } } }) bindRes = await models.ProjectCorrelation.findAll({ where: { id: { $in: pomsProjectId.split(',') } } })
} else { } else {
bindRes = await models.ProjectCorrelation.findAll() bindRes = await models.ProjectCorrelation.findAll()
} }
let anxinProjectIds = new Set() let anxinProjectIds = new Set()
for (let b of bindRes) { for (let b of bindRes) {
if (b.anxinProjectId.length) { if (b.anxinProjectId.length) {
for (let aid of b.anxinProjectId) { for (let aid of b.anxinProjectId) {
anxinProjectIds.add(aid) anxinProjectIds.add(aid)
} }
}
} }
let undelStrucRes = [] }
if (bindRes) { let undelStrucRes = []
undelStrucRes = anxinProjectIds.size ? if (bindRes) {
await clickHouse.anxinyun.query( undelStrucRes = anxinProjectIds.size
` ? await clickHouse.anxinyun
.query(
`
SELECT SELECT
t_structure.id AS strucId, t_structure.id AS strucId,
t_structure.name AS strucName t_structure.name AS strucName
@ -60,261 +60,294 @@ async function getStructures(ctx) {
AND t_structure.external_platform is not null AND t_structure.external_platform is not null
ORDER BY strucId ORDER BY strucId
` `
).toPromise() : )
[] .toPromise()
} : []
// undelStrucRes.push({ strucId: 4036, strucName: '象山港大桥' }) }
// undelStrucRes.push({ strucId: 1, strucName: '象山港大' }) // undelStrucRes.push({ strucId: 4036, strucName: '象山港大桥' })
ctx.status = 200; // undelStrucRes.push({ strucId: 1, strucName: '象山港大' })
ctx.body = undelStrucRes ctx.status = 200
} catch (error) { ctx.body = undelStrucRes
ctx.fs.logger.error(`path: ${ctx.path}, error: error`); } catch (error) {
ctx.status = 400; ctx.fs.logger.error(`path: ${ctx.path}, error: error`)
ctx.body = { ctx.status = 400
message: typeof error == 'string' ? error : undefined ctx.body = {
} message: typeof error == 'string' ? error : undefined,
} }
}
} }
async function getFactors(ctx) { async function getFactors(ctx) {
try { try {
const { models } = ctx.fs.dc; const { models } = ctx.fs.dc
const { clickHouse } = ctx.app.fs const { clickHouse } = ctx.app.fs
const { structId, cacl } = ctx.query const { structId, cacl } = ctx.query
let list = [] let list = []
if (cacl) { if (cacl) {
const factorList = await clickHouse.alarmLocal.query(`select distinct SafetyFactorTypeId, SafetyFactorTypeName from sensors where PlatformStructureId =${structId}`).toPromise() const factorList = await clickHouse.dataAlarm
let fList = factorList.map(m => m.SafetyFactorTypeId) .query(`select SafetyFactorTypeId, SafetyFactorTypeName from sensors where PlatformStructureId = ${structId}`)
list = await clickHouse.alarmLocal.query(`select distinct FactorID, Name,Items,ItemNames from factors where FactorID in (${[...fList, -1].join(',')})`).toPromise() .toPromise()
} else { const project = await clickHouse.dataAlarm
list = await clickHouse.alarmLocal.query(`select distinct SafetyFactorTypeId, SafetyFactorTypeName from sensors where PlatformStructureId =${structId}`).toPromise() .query(`select Project from sensors where PlatformStructureId =${structId} limit 1 `)
} .toPromise()
ctx.body = list
ctx.status = 200 let fList = factorList.map(m => m.SafetyFactorTypeId)
} catch (error) { list = await clickHouse.dataAlarm
ctx.fs.logger.error(`path: ${ctx.path}, error: error`); .query(
ctx.status = 400; `select distinct FactorID, Name,Items,ItemNames from factors
ctx.body = { where FactorID in (${[...fList, -1].join(',')})
message: typeof error == 'string' ? error : undefined and Project = '${[...project, 0][0].Project}'
} `
} )
.toPromise()
} else {
list = await clickHouse.dataAlarm
.query(
`select distinct SafetyFactorTypeId, SafetyFactorTypeName from sensors where PlatformStructureId =${structId}`
)
.toPromise()
}
ctx.body = list
ctx.status = 200
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: error`)
ctx.status = 400
ctx.body = {
message: typeof error == 'string' ? error : undefined,
}
}
} }
//查询设备 //查询设备
async function getSensors(ctx) { async function getSensors(ctx) {
try { try {
const { models } = ctx.fs.dc; const { models } = ctx.fs.dc
const { clickHouse } = ctx.app.fs const { clickHouse } = ctx.app.fs
const { structId, SafetyFactorTypeId } = ctx.query const { structId, SafetyFactorTypeId } = ctx.query
const list = await clickHouse.alarmLocal.query(` const list = await clickHouse.dataAlarm
.query(
`
select distinct SensorId,SensorLocationDescription,Project select distinct SensorId,SensorLocationDescription,Project
from sensors where PlatformStructureId =${structId} from sensors where PlatformStructureId =${structId}
and SafetyFactorTypeId=${SafetyFactorTypeId}`).toPromise() and SafetyFactorTypeId=${SafetyFactorTypeId}`
ctx.body = list )
ctx.status = 200 .toPromise()
} catch (error) { ctx.body = list
ctx.fs.logger.error(`path: ${ctx.path}, error: error`); ctx.status = 200
ctx.status = 400; } catch (error) {
ctx.body = { ctx.fs.logger.error(`path: ${ctx.path}, error: error`)
message: typeof error == 'string' ? error : undefined ctx.status = 400
} ctx.body = {
} message: typeof error == 'string' ? error : undefined,
}
}
} }
//根据设备id和监测因素id查询监测数据 //根据设备id和监测因素id查询监测数据
async function getMonitorData(ctx) { async function getMonitorData(ctx) {
try {
try { const { clickHouse } = ctx.app.fs
const { clickHouse } = ctx.app.fs const { factorId, sensorId, startTime, endTime, toExport } = ctx.query
const { factorId, sensorId, startTime, endTime,toExport } = ctx.query const projectId = sensorId.split('-')[0]
const projectId = sensorId.split('-')[0] const factorsList =
const factorsList = await clickHouse.alarmLocal.query(`SELECT FactorID,Items,ItemNames,ItemUnits FROM factors (await clickHouse.alarmLocal
.query(
`SELECT FactorID,Items,ItemNames,ItemUnits FROM factors
WHERE FactorID=${factorId} AND Project='${projectId}' WHERE FactorID=${factorId} AND Project='${projectId}'
`).toPromise() || [] `
const dataArray = sensorId.split(',') )
const transformedArray = dataArray.map(item => { .toPromise()) || []
return item.replace('-', ':') + '' const dataArray = sensorId.split(',')
}) const transformedArray = dataArray.map(item => {
const id = `(${transformedArray.map(id => `'${id}'`).join(',')})` return item.replace('-', ':') + ''
const monitorData = await clickHouse.alarmLocal.query(`SELECT distinct SensorId,CollectTime,Values FROM themes })
const id = `(${transformedArray.map(id => `'${id}'`).join(',')})`
const monitorData =
(await clickHouse.alarmLocal
.query(
`SELECT distinct SensorId,CollectTime,Values FROM themes
WHERE SensorId in ${id} WHERE SensorId in ${id}
AND CollectTime >= toDate('${startTime}') AND CollectTime >= toDate('${startTime}')
AND CollectTime <= toDate('${endTime}') AND CollectTime <= toDate('${endTime}')
`).toPromise() || [] `
const sensor = await clickHouse.alarmLocal.query(`SELECT distinct ID, SensorId,SensorLocationDescription FROM sensors WHERE ID in ${id}`).toPromise() )
//监测项 .toPromise()) || []
let items = {} const sensor = await clickHouse.alarmLocal
if (factorsList && factorsList.length > 0) { .query(`SELECT distinct ID, SensorId,SensorLocationDescription FROM sensors WHERE ID in ${id}`)
//因素解释 .toPromise()
let factors = [] //监测项
//因素名词 let items = {}
let factorNames = [] if (factorsList && factorsList.length > 0) {
//单位 //因素解释
let c = [] let factors = []
factorsList.map(item => { //因素名词
factors = item.ItemNames.split(',') let factorNames = []
factorNames = item.Items.split(',') //单位
c = item.ItemUnits.split(',') let c = []
factorNames.map((child, index) => { factorsList.map(item => {
items[factorNames[index]] = { name: factors[index], unit: c[index] } factors = item.ItemNames.split(',')
factorNames = item.Items.split(',')
c = item.ItemUnits.split(',')
factorNames.map((child, index) => {
items[factorNames[index]] = { name: factors[index], unit: c[index] }
})
})
}
//设备数据+数据
let sensors = []
let data = []
if (sensor && monitorData && sensor.length && monitorData.length) {
sensor.forEach(item => {
// 过滤与当前传感器相关的数据
const sensorDataArray = monitorData.filter(d => d.SensorId == item.ID)
// 构建最终的传感器数据结构
const sensorDataItem = {
id: item.ID,
name: item.SensorLocationDescription,
data: sensorDataArray.map(d => {
// 根据 item 对象进行映射
const values = {}
itemKeys = Object.keys(items)
itemKeys.forEach((key, index) => {
values[key] = d.Values[index]
}) })
})
}
//设备数据+数据
let sensors = []
let data = []
if (sensor && monitorData && sensor.length && monitorData.length) {
sensor.forEach((item) => {
// 过滤与当前传感器相关的数据
const sensorDataArray = monitorData.filter((d) => d.SensorId == item.ID)
// 构建最终的传感器数据结构
const sensorDataItem = {
id: item.ID,
name: item.SensorLocationDescription,
data: sensorDataArray.map((d) => {
// 根据 item 对象进行映射
const values = {};
itemKeys = Object.keys(items)
itemKeys.forEach((key, index) => {
values[key] = d.Values[index];
});
return {
time: d.CollectTime,
values: values
};
})
};
data.push(sensorDataItem)
})
}
//导出相关
if (toExport) { return {
let arr=items time: d.CollectTime,
let columns = [] values: values,
columns.push({
title: '设备位置',
dataIndex: 'position',
key: 'position',
});
for (let index in arr) {
columns.push({
title: arr[index].name + '(' + arr[index].unit + ')',
dataIndex: index,
sorter: (a, b) => b[index] - a[index],
key: index,
})
};
columns.push({
title: '采集时间',
dataIndex: 'acqTime',
sorter: (a, b) => b['realTime'] - a['realTime'],
key: 'acqTime',
});
//设备
let data1 = []
let themeStations = data
for (let i = 0; i < themeStations.length; i++) {
for (let k = 0; k < themeStations[i].data.length; k++) {
let cdataT = {}
let startT = "";
let endT = "";
let dataTS = themeStations[i].data[k];
cdataT.key = `station-${themeStations[i].id}-${k}`;
cdataT.position = themeStations[i].name;
cdataT.acqTime = moment(dataTS.time).format('YYYY-MM-DD HH:mm:ss');
cdataT.realTime = moment(dataTS.time).valueOf();
if (startT == "") {
startT = dataTS.time;
endT = dataTS.time;
} else {
if (moment(startT) >= moment(dataTS.time))
startT = dataTS.time;
if (moment(endT) <= moment(dataTS.time))
endT = dataTS.time;
}
//动态列的值
for (let themeItem in arr) {
cdataT[themeItem] = dataTS.values[themeItem];
}
data1.push(cdataT)
}
} }
await exportMaterialEnterList(ctx, data1, columns) }),
} }
if(!toExport){ data.push(sensorDataItem)
ctx.body = { items, sensors: data } })
ctx.status = 200 }
} //导出相关
} catch (error) { if (toExport) {
ctx.fs.logger.error(`path: ${ctx.path}, error: error`); let arr = items
ctx.status = 400; let columns = []
ctx.body = { columns.push({
message: typeof error == 'string' ? error : undefined title: '设备位置',
dataIndex: 'position',
key: 'position',
})
for (let index in arr) {
columns.push({
title: arr[index].name + '(' + arr[index].unit + ')',
dataIndex: index,
sorter: (a, b) => b[index] - a[index],
key: index,
})
}
columns.push({
title: '采集时间',
dataIndex: 'acqTime',
sorter: (a, b) => b['realTime'] - a['realTime'],
key: 'acqTime',
})
//设备
let data1 = []
let themeStations = data
for (let i = 0; i < themeStations.length; i++) {
for (let k = 0; k < themeStations[i].data.length; k++) {
let cdataT = {}
let startT = ''
let endT = ''
let dataTS = themeStations[i].data[k]
cdataT.key = `station-${themeStations[i].id}-${k}`
cdataT.position = themeStations[i].name
cdataT.acqTime = moment(dataTS.time).format('YYYY-MM-DD HH:mm:ss')
cdataT.realTime = moment(dataTS.time).valueOf()
if (startT == '') {
startT = dataTS.time
endT = dataTS.time
} else {
if (moment(startT) >= moment(dataTS.time)) startT = dataTS.time
if (moment(endT) <= moment(dataTS.time)) endT = dataTS.time
}
//动态列的值
for (let themeItem in arr) {
cdataT[themeItem] = dataTS.values[themeItem]
}
data1.push(cdataT)
}
} }
} await exportMaterialEnterList(ctx, data1, columns)
}
if (!toExport) {
ctx.body = { items, sensors: data }
ctx.status = 200
}
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: error`)
ctx.status = 400
ctx.body = {
message: typeof error == 'string' ? error : undefined,
}
}
} }
async function exportMaterialEnterList(ctx, data, columns) { async function exportMaterialEnterList(ctx, data, columns) {
try { try {
let header = [] let header = []
columns.forEach(item => { columns.forEach(item => {
header.push({ title: item.title, key: item.key }) header.push({ title: item.title, key: item.key })
}) })
const { utils: { simpleExcelDown } } = ctx.app.fs const {
// let exportData = [] utils: { simpleExcelDown },
// let item={} } = ctx.app.fs
// console.log(dataList[0].dataValues) // let exportData = []
let siteName = '数据监控' // let item={}
// for (let item of data) { // console.log(dataList[0].dataValues)
// for(let child of item){ let siteName = '数据监控'
// if(child!=key){ // for (let item of data) {
// item[child]= // for(let child of item){
// } // if(child!=key){
// } // item[child]=
// // item.outTime = moment(item.outTime).format('YYYY-MM-DD HH:mm:ss'); // }
// // item.branchId = item.siteProcessBranch && item.siteProcessBranch.name ? item.siteProcessBranch.name : '-' // }
// // item.subItemId = item.siteProcessSubItem && item.siteProcessSubItem.name ? item.siteProcessSubItem.name : '-' // // item.outTime = moment(item.outTime).format('YYYY-MM-DD HH:mm:ss');
// // item.type = item.materialItem && item.materialItem.name ? item.materialItem.name : '-' // // item.branchId = item.siteProcessBranch && item.siteProcessBranch.name ? item.siteProcessBranch.name : '-'
// // item.name = item.materialItem && item.materialItem.name ? item.materialItem.name : '-' // // item.subItemId = item.siteProcessSubItem && item.siteProcessSubItem.name ? item.siteProcessSubItem.name : '-'
// // item.model = item.materialItem && item.materialItem.model ? item.materialItem.model : '-' // // item.type = item.materialItem && item.materialItem.name ? item.materialItem.name : '-'
// // item.unit = item.materialItem && item.materialItem.unit ? item.materialItem.unit : '-' // // item.name = item.materialItem && item.materialItem.name ? item.materialItem.name : '-'
// // item.providerId = item.materialProvider && item.materialProvider.name ? item.materialProvider.name : '-' // // item.model = item.materialItem && item.materialItem.model ? item.materialItem.model : '-'
// // item.status = (item.status || item.status == 0) && data[item.status] // // item.unit = item.materialItem && item.materialItem.unit ? item.materialItem.unit : '-'
// exportData.push(item) // // item.providerId = item.materialProvider && item.materialProvider.name ? item.materialProvider.name : '-'
// } // // item.status = (item.status || item.status == 0) && data[item.status]
const fileName = `${siteName}` + '.xls' // exportData.push(item)
const filePath = await simpleExcelDown({ data: data, header, fileName: fileName, needIndexCell: false }) // }
const fileData = fs.readFileSync(filePath) const fileName = `${siteName}` + '.xls'
ctx.status = 200 const filePath = await simpleExcelDown({ data: data, header, fileName: fileName, needIndexCell: false })
ctx.set('Content-Type', 'application/x-xls') const fileData = fs.readFileSync(filePath)
ctx.set('Content-disposition', 'attachment; filename=' + encodeURI(fileName)) ctx.status = 200
ctx.body = fileData ctx.set('Content-Type', 'application/x-xls')
} catch (error) { ctx.set('Content-disposition', 'attachment; filename=' + encodeURI(fileName))
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`) ctx.body = fileData
ctx.status = 400 } catch (error) {
ctx.body = { ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`)
message: typeof error == 'string' ? error : undefined ctx.status = 400
} ctx.body = {
} message: typeof error == 'string' ? error : undefined,
}
}
} }
async function exportFile(ctx) { async function exportFile(ctx) {
try { try {
const { data, columns } = ctx.query const { data, columns } = ctx.query
await exportMaterialEnterList(ctx, data, columns) await exportMaterialEnterList(ctx, data, columns)
} 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,
} }
} }
} }
module.exports = { module.exports = {
getStructures, getFactors, getSensors, getMonitorData, exportFile getStructures,
getFactors,
getSensors,
getMonitorData,
exportFile,
} }

2
web/client/src/sections/install/containers/burr.jsx

@ -274,7 +274,7 @@ const Burr = (props) => {
pageSizeOpts={[10, 20, 30, 40]} pageSizeOpts={[10, 20, 30, 40]}
onChange={(currentPage, pageSize) => { onChange={(currentPage, pageSize) => {
changeQuery( pageSize, currentPage - 1) changeQuery( pageSize, currentPage - 1)
page.current = currentPage - 1 // page.current = currentPage - 1
}} }}
/> />
</div> </div>

2
web/client/src/sections/install/containers/interrupt.jsx

@ -267,7 +267,7 @@ const Interrupt = (props) => {
pageSizeOpts={[10, 20, 30, 40]} pageSizeOpts={[10, 20, 30, 40]}
onChange={(currentPage, pageSize) => { onChange={(currentPage, pageSize) => {
changeQuery( pageSize, currentPage - 1) changeQuery( pageSize, currentPage - 1)
page.current = currentPage - 1 // page.current = currentPage - 1
}} }}
/> />
</div> </div>

969
web/client/src/sections/install/containers/trend.jsx

@ -1,469 +1,548 @@
'use strict'; 'use strict'
import React, { Component, useRef,useState } from 'react'; import React, { Component, useRef, useState } from 'react'
import { connect } from 'react-redux'; import { connect } from 'react-redux'
import { Row, Col, Button, Table, Card, Popconfirm, Tag, Notification, Form, Select,Pagination } from '@douyinfe/semi-ui' import {
import {IconPlus} from "@douyinfe/semi-icons" Row,
import TrendModal from '../components/TrendModal'; Col,
Button,
Table,
Card,
Popconfirm,
Tag,
Notification,
Form,
Select,
Pagination,
} from '@douyinfe/semi-ui'
import { IconPlus } from '@douyinfe/semi-icons'
import TrendModal from '../components/TrendModal'
const Trend = props => {
const { abnParam, factorId, itName, actions, dispatch, sensorId, project, limits, query, changeQuery, limitChange } =
const Trend = (props) => { props
const { abnParam, factorId,itName,actions,dispatch,sensorId,project,limits,query,changeQuery,limitChange } = props const form = useRef()
const form = useRef() const [selectedRowKeys, setSelectedRowKeys] = useState([])
const [selectedRowKeys, setSelectedRowKeys] = useState([]) const [filterFunc, setFilterFunc] = useState({})
const [filterFunc, setFilterFunc] = useState({}) const [modalVisible, setModalVisible] = useState(false)
const [modalVisible, setModalVisible] = useState(false) const [showBatchConfig, setShowBatchConfig] = useState(false)
const [showBatchConfig, setShowBatchConfig] = useState(false) const [timeRange, setTimeRange] = useState('')
const [timeRange, setTimeRange] = useState('') const [bvBatch, setBvBatch] = useState('')
const [bvBatch, setBvBatch] = useState('') const [winSize, setWinSize] = useState('')
const [winSize, setWinSize] = useState('') const [reCoef, setReCoef] = useState('')
const [reCoef, setReCoef] = useState('') const [deValue, setDeValue] = useState('')
const [deValue, setDeValue] = useState('') const [graPoint, setGraPoint] = useState('')
const [graPoint, setGraPoint] = useState('') const [graValue, setGraValue] = useState('')
const [graValue, setGraValue] = useState('') const [modalData, setModalData] = useState(null)
const [modalData, setModalData] = useState(null) const filterSet = { sensorName: null, factorName: null }
const filterSet = { sensorName: null, factorName: null } const { install } = actions
const {install}=actions console.log('query', query)
const onSelectChange = (selectedRowKeys) => { const onSelectChange = selectedRowKeys => {
setSelectedRowKeys(selectedRowKeys) setSelectedRowKeys(selectedRowKeys)
} }
const compareAndEdit = (e, record) => { const compareAndEdit = (e, record) => {
setModalVisible(true) setModalVisible(true)
setModalData(record) setModalData(record)
} }
const modalCancel = e => { const modalCancel = e => {
setModalVisible(false) setModalVisible(false)
}; }
const removeItem = e => { const removeItem = e => {
dispatch(install.deleteAbnParams(e)).then(res=>{ dispatch(install.deleteAbnParams(e)).then(res => {
if(res.success){ if (res.success) {
const id = [factorId, -1].join(',') const id = [factorId, -1].join(',')
changeQuery(10,0) changeQuery(10, 0)
dispatch(install.getAbnParamList({ factorId: id,limit:10, page: 0,type:3})).then(rs=>{ dispatch(install.getAbnParamList({ factorId: id, limit: 10, page: 0, type: 3 })).then(rs => {
if(rs.success){ if (rs.success) {
limitChange(rs.payload.data.count) limitChange(rs.payload.data.count)
} }
})
}
}) })
}
})
}
const handleInputChange = e => {
if (e != null) {
const value = e
let func = (
ep => s =>
s.sensorName.search(ep) > -1
)(value)
filterSet.sensorName = func
func = (
ep => s =>
s.factorName.search(ep) > -1
)(value)
filterSet.factorName = func
} else {
filterSet.sensorName = null
filterSet.factorName = null
} }
const handleInputChange = e => { setFilterFunc(filterSet)
if (e != null) { }
const value = e //or
let func = (ep => (s => (s.sensorName).search(ep) > -1))(value) const onSwitchChange = e => {
filterSet.sensorName = func if (selectedRowKeys.length != 0) {
func = (ep => (s => (s.factorName).search(ep) > -1))(value) let ids = selectedRowKeys.join(',')
filterSet.factorName = func let data = {
} else { enabled: e,
filterSet.sensorName = null use: 'switch',
filterSet.factorName = null }
//
dispatch(install.batchCfgAbnParams(ids, data)).then(res => {
if (res.success) {
const id = [factorId, -1].join(',')
changeQuery(10, 0)
dispatch(install.getAbnParamList({ factorId: id, limit: 10, page: 0, type: 3 })).then(rs => {
if (rs.success) {
limitChange(rs.payload.data.count)
}
})
} }
setFilterFunc(filterSet) })
} }
//or }
const onSwitchChange = (e) => { //
if (selectedRowKeys.length != 0) { const batchDelete = () => {
let ids = selectedRowKeys.join(','); if (selectedRowKeys.length != 0) {
let data = { let ids = selectedRowKeys.join(',')
enabled: e, //
use: 'switch' dispatch(install.deleteAbnParams(ids)).then(res => {
}; if (res.success) {
// const id = [factorId, -1].join(',')
dispatch(install.batchCfgAbnParams(ids,data)).then(res=>{ changeQuery(10, 0)
if(res.success){ dispatch(install.getAbnParamList({ factorId: id, limit: 10, page: 0, type: 3 })).then(rs => {
const id = [factorId, -1].join(',') if (rs.success) {
changeQuery(10,0) limitChange(rs.payload.data.count)
dispatch(install.getAbnParamList({ factorId: id,limit:10, page: 0,type:3})).then(rs=>{ }
if(rs.success){ })
limitChange(rs.payload.data.count)
}
})
}
})
} }
})
} else {
Notification.warning({
content: '您尚未勾选任何参数配置!',
duration: 3,
})
} }
// }
const batchDelete = () => { //
if (selectedRowKeys.length != 0) { const batchSave = () => {
let ids = selectedRowKeys.join(','); form.current.validate().then(value => {
// let dataSource = abnParam.filter(a => a.abnType == 3 && a.factorId == factorId)
dispatch(install.deleteAbnParams(ids)).then(res=>{ if (selectedRowKeys.length != 0) {
if(res.success){ let ids = selectedRowKeys.join(',')
const id = [factorId, -1].join(',') let data = {
changeQuery(10,0) paramJson: {
dispatch(install.getAbnParamList({ factorId: id,limit:10, page: 0,type:3})).then(rs=>{ thr_der: deValue, //
if(rs.success){ win_avg: reCoef, //
limitChange(rs.payload.data.count) win_med: winSize, //
} thr_burr: bvBatch, //
}) thr_grad: graValue, //
} win_grad: graPoint, //
}) days_Last: timeRange, //
} else { },
Notification.warning({ use: 'notSwitch',
content: '您尚未勾选任何参数配置!', }
duration: 3,
}) }
}
//
const batchSave = () => {
form.current.validate().then(value=>{
let dataSource = abnParam.filter(a => a.abnType == 3 && a.factorId == factorId)
if (selectedRowKeys.length != 0) {
let ids = selectedRowKeys.join(',')
let data = {
paramJson: {
"thr_der": deValue, //
"win_avg": reCoef,//
"win_med": winSize,//
"thr_burr": bvBatch,//
"thr_grad": graValue,//
"win_grad": graPoint,//
"days_Last": timeRange//
},
use: 'notSwitch',
};
dispatch(install.batchCfgAbnParams(ids,data)).then(res=>{ dispatch(install.batchCfgAbnParams(ids, data)).then(res => {
if(res.success){ if (res.success) {
const id = [factorId, -1].join(',') const id = [factorId, -1].join(',')
changeQuery(10,0) changeQuery(10, 0)
dispatch(install.getAbnParamList({ factorId: id,limit:10, page: 0,type:3})).then(rs=>{ dispatch(install.getAbnParamList({ factorId: id, limit: 10, page: 0, type: 3 })).then(rs => {
if(rs.success){ if (rs.success) {
limitChange(rs.payload.data.count) limitChange(rs.payload.data.count)
} }
}) })
} }
})
} else if (dataSource.length != 0) {
Notification.warning({
content: '您尚未勾选任何参数配置!',
duration: 3,
})
}
}) })
} else if (dataSource.length != 0) {
Notification.warning({
content: '您尚未勾选任何参数配置!',
duration: 3,
})
}
})
}
const iconClick = () => {
if (!showBatchConfig) {
setShowBatchConfig(true)
} else {
setShowBatchConfig(false)
} }
const iconClick = () => { }
if (!showBatchConfig) { const rangeChange = value => {
setShowBatchConfig(true); setTimeRange(value)
} else { }
setShowBatchConfig(false); const bvValueBatch = value => {
} setBvBatch(value)
} }
const rangeChange = (value) => { const winSizeBatch = value => {
setTimeRange(value) setWinSize(value)
} }
const bvValueBatch = (value) => { const reCoefBatch = value => {
setBvBatch(value) setReCoef(value)
} }
const winSizeBatch = (value) => { const deValueBatch = value => {
setWinSize(value) setDeValue(value)
} }
const reCoefBatch = (value) => { const graPointBatch = value => {
setReCoef(value) setGraPoint(value)
} }
const deValueBatch = (value) => { const graValueBatch = value => {
setDeValue(value) setGraValue(value)
}
const checkInterger = (rule, val) => {
// if(val){
const strRegex = /^[1-9]*[1-9][0-9]*$/
if (strRegex.test(val)) {
return true
} }
const graPointBatch = (value) => { return false
setGraPoint(value) // }
}
const checkPoint = (rule, value) => {
const pattern = /^[1-9]*[1-9][0-9]*$/
if (pattern.test(value) && value != 1) {
return true
} }
const graValueBatch = (value) => { return false
setGraValue(value) }
const checkNumber = (rule, val) => {
const strRegex = /^-?\d+(\.\d+)?$/
if (strRegex.test(val)) {
return true
} }
const checkInterger = (rule, val) => { return false
// if(val){ }
const strRegex = /^[1-9]*[1-9][0-9]*$/
if (strRegex.test(val)) {
return true
}
return false
// }
};
const checkPoint = (rule, value) => {
const pattern = /^[1-9]*[1-9][0-9]*$/;
if (pattern.test(value) && value != 1) {
return true
}
return false
}
const checkNumber = (rule, val) => {
const strRegex = /^-?\d+(\.\d+)?$/
if (strRegex.test(val)) {
return true
}
return false
let dataSource = abnParam.filter(a => a.abnType == 3 && a.factorId == factorId)
const rowSelection = {
selectedRowKeys: selectedRowKeys,
onChange: onSelectChange,
}
let filterData = dataSource
let flag = false
let keyArr = []
let tmpds = []
let dataPush = []
Object.keys(filterFunc).forEach(key => {
const filter = filterFunc[key]
filterData = dataSource
if (filter != null) {
flag = true
filterData = filterData.filter(filter)
if (filterData.length > 0) {
filterData.map(s => {
if (keyArr.indexOf(s.id) == -1) {
keyArr.push(s.id)
dataPush.push(s)
}
})
}
} }
})
let dataSource = abnParam.filter(a => a.abnType == 3 && a.factorId == factorId) tmpds = flag ? dataPush.sort((a, b) => a.id - b.id) : dataSource.sort((a, b) => a.id - b.id)
const rowSelection = { let columns = [
selectedRowKeys: selectedRowKeys, {
onChange: onSelectChange, title: '测点位置',
}; dataIndex: 'sensorName',
let filterData = dataSource; key: 'sensorName',
let flag = false; width: '9%',
let keyArr = []; },
let tmpds = []; {
let dataPush = []; title: '监测项',
Object.keys(filterFunc).forEach(key => { dataIndex: 'factorName',
const filter = filterFunc[key]; key: 'factorName',
filterData = dataSource; width: '10%',
if (filter != null) { render: (text, record) => record.factorName + '/' + itName,
flag = true; },
filterData = filterData.filter(filter) {
if (filterData.length > 0) { title: '分析时段',
filterData.map(s => { dataIndex: 'params',
if (keyArr.indexOf(s.id) == -1) { key: 'params1',
keyArr.push(s.id); width: '9%',
dataPush.push(s); render: text => text.days_Last + '个月',
} },
}) {
} title: '毛刺阈值',
} dataIndex: 'params',
}) key: 'params2',
tmpds = flag ? dataPush.sort((a, b) => a.id - b.id) : dataSource.sort((a, b) => a.id - b.id); width: '9%',
let columns = [ render: text => text.thr_burr,
{ },
title: "测点位置", {
dataIndex: "sensorName", title: '窗口数',
key: "sensorName", dataIndex: 'params',
width: '9%' key: 'params3',
}, width: '9%',
{ render: text => text.win_med,
title: "监测项", },
dataIndex: "factorName", {
key: "factorName", title: '回归系数',
width: '10%', dataIndex: 'params',
render: (text, record) => ( key: 'params4',
record.factorName + "/" + itName width: '9%',
), render: text => text.win_avg,
}, },
{ {
title: "分析时段", title: '导数阈值',
dataIndex: "params", dataIndex: 'params',
key: "params1", key: 'params5',
width: '9%', width: '9%',
render: text => text.days_Last + "个月" render: text => text.thr_der,
}, },
{ {
title: "毛刺阈值", title: '渐变点个数',
dataIndex: "params", dataIndex: 'params',
key: "params2", key: 'params6',
width: '9%', width: '9%',
render: text => text.thr_burr render: text => text.win_grad,
}, },
{ {
title: "窗口数", title: '渐变阈值',
dataIndex: "params", dataIndex: 'params',
key: "params3", key: 'params7',
width: '9%', width: '9%',
render: text => text.win_med render: text => text.thr_grad,
}, },
{ {
title: "回归系数", title: '启用状态',
dataIndex: "params", dataIndex: 'enabled',
key: "params4", key: 'enabled',
width: '9%', width: '9%',
render: text => text.win_avg render: (text, record) => (record.enabled ? <Tag color='blue'>已启用</Tag> : <Tag>已禁用</Tag>),
}, },
{ {
title: "导数阈值", title: '操作',
dataIndex: "params", key: 'action',
key: "params5", width: '9%',
width: '9%', render: (text, record) => (
render: text => text.thr_der <span>
}, <Button theme='borderless' type='primary' onClick={e => compareAndEdit(e, record)}>
{ 编辑
title: "渐变点个数", </Button>
dataIndex: "params", <span className='ant-divider'></span>
key: "params6", <Popconfirm
width: '9%', title='确认删除该参数配置?'
render: text => text.win_grad id={record.id}
}, onConfirm={() => {
{ removeItem(record.id)
title: "渐变阈值",
dataIndex: "params",
key: "params7",
width: '9%',
render: text => text.thr_grad
},
{
title: "启用状态",
dataIndex: "enabled",
key: "enabled",
width: '9%',
render: (text, record) => (
record.enabled ? <Tag color="blue">已启用</Tag> : <Tag>已禁用</Tag>
)
},
{
title: "操作",
key: "action",
width: '9%',
render: (text, record) => (
<span>
<Button theme='borderless' type='primary' onClick={(e) => compareAndEdit(e, record)}>编辑</Button>
<span className="ant-divider"></span>
<Popconfirm title="确认删除该参数配置?" id={record.id} onConfirm={() => { removeItem(record.id) }}>
<Button theme='borderless' type='danger' >删除</Button>
</Popconfirm>
</span>
),
}
]
return (<Card style={{ marginTop: 15 }}>
<Form style={{ marginBottom: 15 }} labelPosition='left' getFormApi={formApi => {
form.current = formApi
}}> }}>
<Row style={{ display: 'flex',alignItems:'center'}}> <Button theme='borderless' type='danger'>
<Col span={5}> 删除
<Form.Input field='keywords' noLabel={true} style={{ marginBottom: 0, width: '95%' }} placeholder="关键词:测点位置、监测因素" onChange={handleInputChange}> </Button>
</Form.Input> </Popconfirm>
</Col> </span>
<Col span={2}> ),
<Form.Switch label='是否启用' field='switch' style={{ marginBottom: 0 }} checked onChange={onSwitchChange} > },
</Form.Switch> ]
</Col> return (
<Col span={2}> <Card style={{ marginTop: 15 }}>
<Popconfirm style={{ marginBottom: 0 }} title="确认批量删除选中的参数配置?" onConfirm={batchDelete}> <Form
<Button style={{ fontSize: 13 }} theme='solid' type='danger'>批量删除</Button> style={{ marginBottom: 15 }}
</Popconfirm> labelPosition='left'
</Col> getFormApi={formApi => {
<Col span={2}> form.current = formApi
<IconPlus style={{ paddingTop: 9 }} onClick={iconClick} /> }}>
</Col> <Row style={{ display: 'flex', alignItems: 'center' }}>
</Row> <Col span={5}>
{showBatchConfig ? <Form.Input
<Row style={{ display: 'flex',alignItems:'center',marginTop: 10}}> field='keywords'
<Col span={3}> noLabel={true}
<Form.Select showSearch filter noLabel={true} field="timeRange" onChange={rangeChange} style={{ marginBottom: 0, width: '95%' }}
placeholder="请选择分析时长" style={{ width: '93%', marginBottom: 0 }}> placeholder='关键词:测点位置、监测因素'
<Select.Option value="1">1个月</Select.Option> onChange={handleInputChange}></Form.Input>
<Select.Option value="2">2个月</Select.Option> </Col>
<Select.Option value="3">3个月</Select.Option> <Col span={2}>
</Form.Select> <Form.Switch
</Col> label='是否启用'
<Col span={3}> field='switch'
<Form.Input style={{ marginBottom: 0, width: '93%' }} style={{ marginBottom: 0 }}
field='bv' checked
noLabel={true} onChange={onSwitchChange}></Form.Switch>
placeholder="毛刺阈值:数字" </Col>
onChange={e => bvValueBatch(e)} <Col span={2}>
rules={[{ <Popconfirm style={{ marginBottom: 0 }} title='确认批量删除选中的参数配置?' onConfirm={batchDelete}>
required: true, message: "请输入正整数", validator: checkInterger <Button style={{ fontSize: 13 }} theme='solid' type='danger'>
}]} trigger='blur'/> 批量删除
</Col> </Button>
<Col span={3}> </Popconfirm>
<Form.Input </Col>
style={{ marginBottom: 0, width: '93%' }} <Col span={2}>
field='ws' <IconPlus style={{ paddingTop: 9 }} onClick={iconClick} />
placeholder="滑动中值:正值" </Col>
noLabel={true} </Row>
rules={[{ {showBatchConfig ? (
required: true, message: "请输入正整数", validator: checkInterger <Row style={{ display: 'flex', alignItems: 'center', marginTop: 10 }}>
}]} <Col span={3}>
onChange={e => winSizeBatch(e)} <Form.Select
trigger='blur'/> showSearch
</Col> filter
<Col span={3}> noLabel={true}
<Form.Input field='timeRange'
style={{ marginBottom: 0, width: '93%' }} onChange={rangeChange}
field='rc' placeholder='请选择分析时长'
placeholder="滑动均值:正值" style={{ width: '93%', marginBottom: 0 }}>
noLabel={true} rules={[{ <Select.Option value='1'>1个月</Select.Option>
required: true, message: "请输入正整数", validator: checkInterger <Select.Option value='2'>2个月</Select.Option>
}]} <Select.Option value='3'>3个月</Select.Option>
onChange={e => reCoefBatch(e)} </Form.Select>
trigger='blur'/> </Col>
</Col> <Col span={3}>
<Col span={3}> <Form.Input
<Form.Input style={{ marginBottom: 0, width: '93%' }}
style={{ marginBottom: 0, width: '93%' }} field='bv'
field='dv' noLabel={true}
placeholder="导数阈值:数字" placeholder='毛刺阈值:数字'
noLabel={true} onChange={e => bvValueBatch(e)}
rules={[{ rules={[
required: true, message: "请输入正整数", validator: checkNumber {
}]} required: true,
onChange={e => deValueBatch(e)} message: '请输入正整数',
trigger='blur'/> validator: checkInterger,
</Col> },
<Col span={3}> ]}
<Form.Input trigger='blur'
style={{ marginBottom: 0, width: '93%' }} />
field='pn' </Col>
placeholder="渐变点个数:正值" <Col span={3}>
noLabel={true} rules={[{ <Form.Input
required: true, message: "请输入正整数", validator: checkPoint style={{ marginBottom: 0, width: '93%' }}
}]} field='ws'
onChange={e => graPointBatch(e)} placeholder='滑动中值:正值'
trigger='blur'/> noLabel={true}
</Col> rules={[
<Col span={3}> {
<Form.Input required: true,
style={{ marginBottom: 0, width: '93%' }} message: '请输入正整数',
field='gv' validator: checkInterger,
placeholder="渐变阈值:数字" },
noLabel={true} rules={[{ ]}
required: true, message: "请输入正整数", validator: checkNumber onChange={e => winSizeBatch(e)}
}]} trigger='blur'
onChange={e => graValueBatch(e)} />
trigger='blur'/> </Col>
</Col> <Col span={3}>
<Col span={2}> <Form.Input
<Button onClick={batchSave} theme='solid' type='primary'>批量保存</Button> style={{ marginBottom: 0, width: '93%' }}
</Col> field='rc'
</Row> : ''} placeholder='滑动均值:正值'
</Form> noLabel={true}
<Table rowSelection={rowSelection} columns={columns} dataSource={tmpds} pagination={false}/> rules={[
<div {
style={{ required: true,
display: "flex", message: '请输入正整数',
justifyContent: "flex-end", validator: checkInterger,
padding: "20px 20px", },
}} ]}
> onChange={e => reCoefBatch(e)}
<span style={{ lineHeight: "30px", fontSize: 13, color: 'rgba(0,90,189,0.8)' }}> trigger='blur'
{limits}条信息 />
</span> </Col>
<Pagination <Col span={3}>
total={limits} <Form.Input
showSizeChanger style={{ marginBottom: 0, width: '93%' }}
currentPage={query.page + 1} field='dv'
pageSizeOpts={[10, 20, 30, 40]} placeholder='导数阈值:数字'
onChange={(currentPage, pageSize) => { noLabel={true}
changeQuery( pageSize, currentPage - 1) rules={[
page.current = currentPage - 1 {
}} required: true,
/> message: '请输入正整数',
</div> validator: checkNumber,
{modalVisible ? <TrendModal },
// structId={structId} ]}
visible={true} onChange={e => deValueBatch(e)}
project={ project} trigger='blur'
closeModal={modalCancel} />
modalData={modalData} </Col>
sensorId={sensorId} <Col span={3}>
factorId={factorId} <Form.Input
style={{ marginBottom: 0, width: '93%' }}
/> : ''} field='pn'
placeholder='渐变点个数:正值'
noLabel={true}
rules={[
{
required: true,
message: '请输入正整数',
validator: checkPoint,
},
]}
onChange={e => graPointBatch(e)}
trigger='blur'
/>
</Col>
<Col span={3}>
<Form.Input
style={{ marginBottom: 0, width: '93%' }}
field='gv'
placeholder='渐变阈值:数字'
noLabel={true}
rules={[
{
required: true,
message: '请输入正整数',
validator: checkNumber,
},
]}
onChange={e => graValueBatch(e)}
trigger='blur'
/>
</Col>
<Col span={2}>
<Button onClick={batchSave} theme='solid' type='primary'>
批量保存
</Button>
</Col>
</Row>
) : (
''
)}
</Form>
<Table rowSelection={rowSelection} columns={columns} dataSource={tmpds} pagination={false} />
<div
style={{
display: 'flex',
justifyContent: 'flex-end',
padding: '20px 20px',
}}>
<span style={{ lineHeight: '30px', fontSize: 13, color: 'rgba(0,90,189,0.8)' }}>{limits}条信息</span>
<Pagination
total={limits}
showSizeChanger
currentPage={query.page + 1}
pageSizeOpts={[10, 20, 30, 40]}
onChange={(currentPage, pageSize) => {
changeQuery(pageSize, currentPage - 1)
// page.current = currentPage - 1
}}
/>
</div>
{modalVisible ? (
<TrendModal
// structId={structId}
visible={true}
project={project}
closeModal={modalCancel}
modalData={modalData}
sensorId={sensorId}
factorId={factorId}
/>
) : (
''
)}
</Card> </Card>
); )
} }
function mapStateToProps(state) { function mapStateToProps(state) {
const { abnParam,global } = state const { abnParam, global } = state
// let isRequesting = abnParamState?.isRequesting; // let isRequesting = abnParamState?.isRequesting;
return { return {
isRequesting: false,// isRequesting: false, //
abnParam: abnParam?.data?.rows || [], abnParam: abnParam?.data?.rows || [],
actions:global.actions actions: global.actions,
} }
} }
export default connect(mapStateToProps)(Trend) export default connect(mapStateToProps)(Trend)

Loading…
Cancel
Save