feat: 优化年度数据查询,添加港口和企业层级统计

This commit is contained in:
LokerL 2024-11-08 11:15:05 +08:00
parent 1cbfa43044
commit fc3c2bd71c
2 changed files with 118 additions and 19 deletions

View File

@ -48,15 +48,16 @@
<select id="selectThDeviceReportYearList" parameterType="map" resultType="map"> <select id="selectThDeviceReportYearList" parameterType="map" resultType="map">
select select
m.sn, m.sn,
m.dept_id,
m.year, m.year,
round(AVG(TO_NUMBER(m.avg_value)), 8) AS avg_value, round(AVG(TO_NUMBER(m.avg_value)), 8) AS avg_value,
p.dept_name, p.dept_name,
p.ancestors, p.dept_name as "p",
pp.dept_name as "gangqu" pp.dept_name as "pp",
ppp.dept_name as "ppp"
from th_device_report_month1 m from th_device_report_month1 m
left join sys_dept p on m.dept_id = p.dept_id 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 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 ( WHERE m.dept_id IN (
SELECT dept_id SELECT dept_id
FROM sys_dept START WITH dept_id = #{deptId} FROM sys_dept START WITH dept_id = #{deptId}
@ -65,8 +66,8 @@
<if test="year != null and year != ''"> <if test="year != null and year != ''">
AND m.year = #{year} AND m.year = #{year}
</if> </if>
GROUP BY m.sn, m.dept_id, m.year, p.dept_name, p.ancestors, pp.dept_name GROUP BY m.sn, m.year, p.dept_name, pp.dept_name, ppp.dept_name
ORDER BY m.dept_id, m.year ASC ORDER BY ppp.dept_name, pp.dept_name, p.dept_name
</select> </select>
<update <update

View File

@ -31,13 +31,45 @@
:data="tableData" :data="tableData"
style="width: 100%" style="width: 100%"
border border
:max-height="tableHeight" :span-method="objectSpanMethod"
:row-class-name="tableRowClassName"
v-loading="loading" v-loading="loading"
> >
<el-table-column prop="gangqu" label="归属港区" /> <el-table-column prop="ppp" label="归属港口">
<el-table-column prop="deptName" 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="sn" label="设备编码" />
<el-table-column prop="year" label="年份" /> <!-- <el-table-column prop="year" label="年份" /> -->
<el-table-column prop="avgValue" label="平均值"> <el-table-column prop="avgValue" label="平均值">
<!-- <template slot-scope="scope"> <!-- <template slot-scope="scope">
<div @dblclick="changeAvgValue(scope.$index, scope.row)"> <div @dblclick="changeAvgValue(scope.$index, scope.row)">
@ -59,7 +91,7 @@
</template> --> </template> -->
</el-table-column> </el-table-column>
</el-table> </el-table>
<div class="page-ele"> <!-- <div class="page-ele">
<el-pagination <el-pagination
layout="sizes, prev, pager, next, total" layout="sizes, prev, pager, next, total"
:total="total" :total="total"
@ -69,7 +101,7 @@
@size-change="handleSizeChange" @size-change="handleSizeChange"
> >
</el-pagination> </el-pagination>
</div> </div> -->
</el-row> </el-row>
</div> </div>
</template> </template>
@ -102,6 +134,9 @@ export default {
tableHeight() { tableHeight() {
return window.innerHeight - 300; return window.innerHeight - 300;
}, },
pppList() {
return Array.from(new Set(this.tableData.map((item) => item.ppp)));
},
}, },
mounted() { mounted() {
// 2024 // 2024
@ -109,6 +144,68 @@ export default {
this.queryDebounce = debounce(this.query, 100); this.queryDebounce = debounce(this.query, 100);
}, },
methods: { 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() { handleYearChange() {
this.queryDebounce(); this.queryDebounce();
}, },
@ -130,16 +227,16 @@ export default {
} }
this.loading = true; this.loading = true;
getDeviceReportYearList({ getDeviceReportYearListAll({
deptId: this.dept.deptId, deptId: this.dept.deptId,
year: this.year, year: this.year,
pageNum: this.pageNum, // pageNum: this.pageNum,
pageSize: this.pageSize, // pageSize: this.pageSize,
}) })
.then((res) => { .then((res) => {
if (res.code === 200) { if (res.code === 200) {
this.tableData = res.rows; this.tableData = res.data;
this.total = res.total; // this.total = res.total;
} }
}) })
.finally(() => { .finally(() => {
@ -161,10 +258,11 @@ export default {
dataToExcel({ dataToExcel({
data: [ data: [
[fileName], [fileName],
["归属港区", "归属企业", "设备编码", "年份", "平均值"], ["归属港口", "归属港区", "归属企业", "设备编码", "年份", "平均值"],
...data.map((row) => [ ...data.map((row) => [
row.gangqu, row.ppp,
row.deptName, row.pp,
row.p,
row.sn, row.sn,
row.year, row.year,
row.avgValue, row.avgValue,