diff --git a/RuoYi-Vue-Oracle/src/main/resources/mybatis/oil/ThDeviceReportMonthMapper.xml b/RuoYi-Vue-Oracle/src/main/resources/mybatis/oil/ThDeviceReportMonthMapper.xml index 6fcf0f6..d4ecd3e 100644 --- a/RuoYi-Vue-Oracle/src/main/resources/mybatis/oil/ThDeviceReportMonthMapper.xml +++ b/RuoYi-Vue-Oracle/src/main/resources/mybatis/oil/ThDeviceReportMonthMapper.xml @@ -48,15 +48,16 @@ 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 @@ AND m.year = #{year} - 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 - - + + + {{ row.ppp }} + + 港区数: {{ getChildCount(row, "ppp", "pp") }} + 平均值: {{ calculateChildAvg(row, "ppp") }} + + + + + + {{ row.pp }} + + 企业数: {{ getChildCount(row, "pp", "p") }} + 平均值: {{ calculateChildAvg(row, "pp") }} + + + + + + {{ row.p }} + + 设备数: {{ getChildCount(row, "p", "sn") }} + 平均值: {{ calculateChildAvg(row, "p") }} + + + - + - + @@ -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,