fast(项目-能源管理): 能源管理-电量统计添加分组查询和电量合计,设备列表塑壳断路器添加父设备选择

This commit is contained in:
fhysy 2024-12-25 14:34:01 +08:00
parent 3ea7f89b34
commit 14126d0793
4 changed files with 119 additions and 39 deletions

View File

@ -140,7 +140,7 @@ export function projectElectricityStatChartYear(query) {
// 查询 电能 列表 // 查询 电能 列表
export function projectElectricityTable(query) { export function projectElectricityTable(query) {
return request({ return request({
url: "/iot/project/monitor/electricityStatLst", url: "/iot/project/monitor/electricityStatList",
method: "get", method: "get",
params: query params: query
}); });

66
src/utils/math.js Normal file
View File

@ -0,0 +1,66 @@
// 使用这些方法,仍然需要注意数值范围、舍入策略和比较运算等方面的问题,根据具体的应用场景进行适当的调整和处理。
const math = {
// 加法运算
add: function (a, b) {
const precision = Math.max(getPrecision(a), getPrecision(b));
const multiplier = Math.pow(10, precision);
const result=(Math.round(a * multiplier) + Math.round(b * multiplier)) / multiplier;
return transferToNumber(result)
},
// 减法运算
subtract: function (a, b) {
return transferToNumber(math.add(a, -b));
},
// 乘法运算
multiply: function (a, b) {
const precision = getPrecision(a) + getPrecision(b);
const multiplier = Math.pow(10, precision);
const result=(Math.round(a * multiplier) * Math.round(b * multiplier)) / (multiplier * multiplier);
return transferToNumber(result)
},
// 除法运算
divide: function (num1, num2) {
var str1 = Number(num1).toString(),
str2 = Number(num2).toString(),
result,
str1Length,
str2Length;
//解决整数没有小数点方法
try {
str1Length = str1.split(".")[1].length;
} catch (error) {
str1Length = 0;
}
try {
str2Length = str2.split(".")[1].length;
} catch (error) {
str2Length = 0;
}
var step = Math.pow(10, Math.max(str1Length, str2Length));
result = (num1 * step) / (num2 * step);
return transferToNumber(result);
},
// 获取浮点数的小数位数
};
function getPrecision(num) {
const str = String(num);
const decimalIndex = str.indexOf(".");
return decimalIndex === -1 ? 0 : str.length - decimalIndex - 1;
}
// 处理出现科学计数法
function transferToNumber(num) {
if (isNaN(num)) {
return num
}
num = '' + num
num = parseFloat(num)
let eformat = num.toExponential() // 转换为标准的科学计数法形式(字符串)
let tmpArray = eformat.match(/\d(?:\.(\d*))?e([+-]\d+)/) // 分离出小数值和指数值
let number = num.toFixed(Math.max(0, (tmpArray[1] || '').length - tmpArray[2]))
return number
}
export default math;

View File

@ -334,7 +334,7 @@
</el-form-item> </el-form-item>
<el-form-item <el-form-item
v-if="form.deviceType === 'MINIATURE_BREAKER' || form.deviceType === 'DOOR_SENSOR'" v-if="form.deviceType === 'MINIATURE_BREAKER' || form.deviceType === 'MOLDED_BREAKER' || form.deviceType === 'DOOR_SENSOR'"
label="父设备:" label="父设备:"
prop="parentId" prop="parentId"
> >

View File

@ -89,7 +89,7 @@
</template> </template>
</el-table-column> </el-table-column>
<el-table-column align="center" label="本月电量" prop="tmReadSum" width="100"> <el-table-column align="center" label="本月电量(度)" prop="tmReadSum" width="100">
<template slot-scope="scope"> <template slot-scope="scope">
<span :title="scope.row.tmReadSum" class="lay-table-textarea"> <span :title="scope.row.tmReadSum" class="lay-table-textarea">
{{ scope.row.tmReadSum || 0 }} {{ scope.row.tmReadSum || 0 }}
@ -97,7 +97,7 @@
</template> </template>
</el-table-column> </el-table-column>
<el-table-column align="center" label="上月电量" prop="lmReadSum" width="100"> <el-table-column align="center" label="上月电量(度)" prop="lmReadSum" width="100">
<template slot-scope="scope"> <template slot-scope="scope">
<span :title="scope.row.lmReadSum" class="lay-table-textarea"> <span :title="scope.row.lmReadSum" class="lay-table-textarea">
{{ scope.row.lmReadSum || 0 }} {{ scope.row.lmReadSum || 0 }}
@ -176,6 +176,7 @@ import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { projectElectricityTable } from "@/api/iot/project_new"; import { projectElectricityTable } from "@/api/iot/project_new";
import { listSpace } from "@/api/iot/space"; import { listSpace } from "@/api/iot/space";
import { getProjectGroupList } from "@/api/tenant/project"; import { getProjectGroupList } from "@/api/tenant/project";
import math from "@/utils/math.js"
export default { export default {
name: "EElectricity", name: "EElectricity",
props: { props: {
@ -243,13 +244,13 @@ export default {
this.getProjectGroupList(); this.getProjectGroupList();
}, },
handleQuery() { handleQuery() {
// this.queryParams.pageNum = 1; this.queryParams.pageNum = 1;
this.queryParams={ // this.queryParams={
spaceId: null, // spaceId: null,
deviceId: '', // deviceId: '',
groupId: null, // groupId: null,
pageNum:1 // pageNum:1
} // }
this.getList(); this.getList();
}, },
handleLinkDevDetails(row) { handleLinkDevDetails(row) {
@ -285,10 +286,11 @@ export default {
// //
getList() { getList() {
var queryParams = JSON.parse(JSON.stringify(this.queryParams)); var queryParams = JSON.parse(JSON.stringify(this.queryParams));
console.log("this.queryParams.groupId",this.queryParams)
projectElectricityTable( projectElectricityTable(
Object.assign(queryParams, { Object.assign(queryParams, {
projectId: this.sourceId, projectId: this.sourceId,
groupId: this.groupId, groupId: this.queryParams.groupId,
time: this.parseTime( time: this.parseTime(
new Date(this.queryTime), new Date(this.queryTime),
"{y}-{m}-01 00:00:00" "{y}-{m}-01 00:00:00"
@ -297,15 +299,27 @@ export default {
timeType: 'month' timeType: 'month'
}) })
).then((res) => { ).then((res) => {
if(res.rows.length>0){ // if(res.rows.length>0){
res.rows[0].tmReadSum = '1.0'; // res.rows[0].tmReadSum = '1.0';
res.rows[1].tmReadSum = '1.0'; // res.rows[1].tmReadSum = '1.0';
res.rows[1].lmReadSum = '2.0'; // res.rows[1].lmReadSum = '2.0';
res.rows[1].tmReadSum = '2.0'; // res.rows[1].tmReadSum = '2.0';
res.rows[1].lmReadSum = '1.0'; // res.rows[1].lmReadSum = '1.0';
// }
if(res.rows && res.rows.length){
this.tableList = res.rows.map(item=>{
return {
...item,
tmReadSum: math.multiply(item.tmReadSum,0.001),
lmReadSum: math.multiply(item.lmReadSum,0.001)
}
});
this.total = res.total;
}else{
this.tableList = [];
this.total = 0;
} }
this.tableList = res.rows;
this.total = res.total;
}); });
}, },
getSummaries(param) { getSummaries(param) {
@ -318,7 +332,7 @@ export default {
} }
// const values = data.map(item => Number(item[column.property])); // const values = data.map(item => Number(item[column.property]));
const values = data.map((item,i)=>{ const values = data.map((item,i)=>{
if(index===2){ if(index===1 || index===2 || index===5 ){
return NaN; return NaN;
}else{ }else{
return Number(item[column.property]); return Number(item[column.property]);
@ -328,7 +342,7 @@ export default {
sums[index] = values.reduce((prev, curr) => { sums[index] = values.reduce((prev, curr) => {
const value = Number(curr); const value = Number(curr);
if (!isNaN(value)) { if (!isNaN(value)) {
return prev + curr; return math.add(prev,curr);
} else { } else {
return prev; return prev;
} }
@ -338,23 +352,23 @@ export default {
sums[index] = ''; sums[index] = '';
} }
}); });
// // //
const lastMonthEnergy = parseFloat(sums[4]) || 0; // const lastMonthEnergy = parseFloat(sums[4]) || 0;
const thisMonthEnergy = parseFloat(sums[3]) || 0; // const thisMonthEnergy = parseFloat(sums[3]) || 0;
// // //
let percentage = 0; // let percentage = 0;
if (lastMonthEnergy !== 0) { // if (lastMonthEnergy !== 0) {
percentage = ((thisMonthEnergy - lastMonthEnergy) / lastMonthEnergy) * 100; // percentage = ((thisMonthEnergy - lastMonthEnergy) / lastMonthEnergy) * 100;
} else { // } else {
if(thisMonthEnergy==0 && lastMonthEnergy==0){ // if(thisMonthEnergy==0 && lastMonthEnergy==0){
percentage = 0; // percentage = 0;
}else if(thisMonthEnergy==0){ // }else if(thisMonthEnergy==0){
percentage = -100; // percentage = -100;
}else if(lastMonthEnergy==0){ // }else if(lastMonthEnergy==0){
percentage = 100; // percentage = 100;
} // }
} // }
sums[5] = percentage.toFixed(2) + '%'; // sums[5] = percentage.toFixed(2) + '%';
return sums; return sums;
} }
}, },