✨ feat: 优化年度数据查询,添加港口和企业层级统计
This commit is contained in:
parent
1cbfa43044
commit
fc3c2bd71c
|
@ -48,15 +48,16 @@
|
|||
<select id="selectThDeviceReportYearList" parameterType="map" resultType="map">
|
||||
select
|
||||
m.sn,
|
||||
m.dept_id,
|
||||
m.year,
|
||||
round(AVG(TO_NUMBER(m.avg_value)), 8) AS avg_value,
|
||||
p.dept_name,
|
||||
p.ancestors,
|
||||
pp.dept_name as "gangqu"
|
||||
p.dept_name as "p",
|
||||
pp.dept_name as "pp",
|
||||
ppp.dept_name as "ppp"
|
||||
from th_device_report_month1 m
|
||||
left join sys_dept p on m.dept_id = p.dept_id
|
||||
left join sys_dept pp on p.parent_id = pp.dept_id
|
||||
left join sys_dept ppp on pp.parent_id = ppp.dept_id
|
||||
WHERE m.dept_id IN (
|
||||
SELECT dept_id
|
||||
FROM sys_dept START WITH dept_id = #{deptId}
|
||||
|
@ -65,8 +66,8 @@
|
|||
<if test="year != null and year != ''">
|
||||
AND m.year = #{year}
|
||||
</if>
|
||||
GROUP BY m.sn, m.dept_id, m.year, p.dept_name, p.ancestors, pp.dept_name
|
||||
ORDER BY m.dept_id, m.year ASC
|
||||
GROUP BY m.sn, m.year, p.dept_name, pp.dept_name, ppp.dept_name
|
||||
ORDER BY ppp.dept_name, pp.dept_name, p.dept_name
|
||||
</select>
|
||||
|
||||
<update
|
||||
|
|
|
@ -31,13 +31,45 @@
|
|||
:data="tableData"
|
||||
style="width: 100%"
|
||||
border
|
||||
:max-height="tableHeight"
|
||||
:span-method="objectSpanMethod"
|
||||
:row-class-name="tableRowClassName"
|
||||
v-loading="loading"
|
||||
>
|
||||
<el-table-column prop="gangqu" label="归属港区" />
|
||||
<el-table-column prop="deptName" label="归属企业" />
|
||||
<el-table-column prop="ppp" label="归属港口">
|
||||
<template slot-scope="{ row }">
|
||||
<div>{{ row.ppp }}</div>
|
||||
<div style="display: flex; gap: 10px">
|
||||
<el-tag>港区数: {{ getChildCount(row, "ppp", "pp") }}</el-tag>
|
||||
<el-tag type="warning"
|
||||
>平均值: {{ calculateChildAvg(row, "ppp") }}</el-tag
|
||||
>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="pp" label="归属港区">
|
||||
<template slot-scope="{ row }">
|
||||
<div>{{ row.pp }}</div>
|
||||
<div style="display: flex; gap: 10px">
|
||||
<el-tag>企业数: {{ getChildCount(row, "pp", "p") }}</el-tag>
|
||||
<el-tag type="warning"
|
||||
>平均值: {{ calculateChildAvg(row, "pp") }}</el-tag
|
||||
>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="p" label="归属企业">
|
||||
<template slot-scope="{ row }">
|
||||
<div>{{ row.p }}</div>
|
||||
<div style="display: flex; gap: 10px">
|
||||
<el-tag>设备数: {{ getChildCount(row, "p", "sn") }}</el-tag>
|
||||
<el-tag type="warning"
|
||||
>平均值: {{ calculateChildAvg(row, "p") }}</el-tag
|
||||
>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="sn" label="设备编码" />
|
||||
<el-table-column prop="year" label="年份" />
|
||||
<!-- <el-table-column prop="year" label="年份" /> -->
|
||||
<el-table-column prop="avgValue" label="平均值">
|
||||
<!-- <template slot-scope="scope">
|
||||
<div @dblclick="changeAvgValue(scope.$index, scope.row)">
|
||||
|
@ -59,7 +91,7 @@
|
|||
</template> -->
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div class="page-ele">
|
||||
<!-- <div class="page-ele">
|
||||
<el-pagination
|
||||
layout="sizes, prev, pager, next, total"
|
||||
:total="total"
|
||||
|
@ -69,7 +101,7 @@
|
|||
@size-change="handleSizeChange"
|
||||
>
|
||||
</el-pagination>
|
||||
</div>
|
||||
</div> -->
|
||||
</el-row>
|
||||
</div>
|
||||
</template>
|
||||
|
@ -102,6 +134,9 @@ export default {
|
|||
tableHeight() {
|
||||
return window.innerHeight - 300;
|
||||
},
|
||||
pppList() {
|
||||
return Array.from(new Set(this.tableData.map((item) => item.ppp)));
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
// 获取当前年份 2024
|
||||
|
@ -109,6 +144,68 @@ export default {
|
|||
this.queryDebounce = debounce(this.query, 100);
|
||||
},
|
||||
methods: {
|
||||
tableRowClassName({ row, rowIndex }) {
|
||||
const classNames = ["default-row", "success-row", "error-row", "warning-row", "info-row"];
|
||||
const index = this.pppList.findIndex((item) => item === row.ppp);
|
||||
if (index === -1) return "info-row";
|
||||
return index > classNames.length - 1 ? classNames[index % classNames.length] : classNames[index];
|
||||
},
|
||||
getChildCount(row, key, childKey) {
|
||||
const childSet = new Set();
|
||||
for (let i = 0; i < this.tableData.length; i++) {
|
||||
if (row[key] === this.tableData[i][key]) {
|
||||
childSet.add(this.tableData[i][childKey]);
|
||||
}
|
||||
}
|
||||
return childSet.size;
|
||||
},
|
||||
calculateChildAvg(row, key) {
|
||||
const childList = [];
|
||||
for (let i = 0; i < this.tableData.length; i++) {
|
||||
if (row[key] === this.tableData[i][key]) {
|
||||
childList.push(this.tableData[i].avgValue);
|
||||
}
|
||||
}
|
||||
// 计算平均值, 保留两位小数
|
||||
return (childList.reduce((a, b) => a + b, 0) / childList.length).toFixed(
|
||||
2
|
||||
);
|
||||
},
|
||||
objectSpanMethod({ row, column, rowIndex, columnIndex }) {
|
||||
const calculateRowSpan = (key) => {
|
||||
const value = row[key];
|
||||
let rowSpan = 1;
|
||||
if (rowIndex === 0) {
|
||||
while (
|
||||
this.tableData[rowIndex + rowSpan] &&
|
||||
this.tableData[rowIndex + rowSpan][key] === value
|
||||
) {
|
||||
rowSpan++;
|
||||
}
|
||||
return { rowspan: rowSpan, colspan: 1 };
|
||||
} else {
|
||||
if (this.tableData[rowIndex - 1][key] === value) {
|
||||
return { rowspan: 0, colspan: 0 };
|
||||
} else {
|
||||
while (
|
||||
this.tableData[rowIndex + rowSpan] &&
|
||||
this.tableData[rowIndex + rowSpan][key] === value
|
||||
) {
|
||||
rowSpan++;
|
||||
}
|
||||
return { rowspan: rowSpan, colspan: 1 };
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (columnIndex === 0) {
|
||||
return calculateRowSpan("ppp");
|
||||
} else if (columnIndex === 1) {
|
||||
return calculateRowSpan("pp");
|
||||
} else if (columnIndex === 2) {
|
||||
return calculateRowSpan("p");
|
||||
}
|
||||
},
|
||||
handleYearChange() {
|
||||
this.queryDebounce();
|
||||
},
|
||||
|
@ -130,16 +227,16 @@ export default {
|
|||
}
|
||||
this.loading = true;
|
||||
|
||||
getDeviceReportYearList({
|
||||
getDeviceReportYearListAll({
|
||||
deptId: this.dept.deptId,
|
||||
year: this.year,
|
||||
pageNum: this.pageNum,
|
||||
pageSize: this.pageSize,
|
||||
// pageNum: this.pageNum,
|
||||
// pageSize: this.pageSize,
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.code === 200) {
|
||||
this.tableData = res.rows;
|
||||
this.total = res.total;
|
||||
this.tableData = res.data;
|
||||
// this.total = res.total;
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
|
@ -161,10 +258,11 @@ export default {
|
|||
dataToExcel({
|
||||
data: [
|
||||
[fileName],
|
||||
["归属港区", "归属企业", "设备编码", "年份", "平均值"],
|
||||
["归属港口", "归属港区", "归属企业", "设备编码", "年份", "平均值"],
|
||||
...data.map((row) => [
|
||||
row.gangqu,
|
||||
row.deptName,
|
||||
row.ppp,
|
||||
row.pp,
|
||||
row.p,
|
||||
row.sn,
|
||||
row.year,
|
||||
row.avgValue,
|
||||
|
|
Loading…
Reference in New Issue