🐞 fix: 修复查询BUG;报表中心添加导出功能
修复:月度均值报表和报表中心不再查询全部后代节点,仅查询本身和直接子节点;新增:报表中心导出为excel
This commit is contained in:
parent
44ab2dc9fd
commit
511d8dd2c6
|
@ -59,32 +59,19 @@
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectAvgDsByMonth" parameterType="map" resultType="map">
|
<select id="selectAvgDsByMonth" parameterType="map" resultType="map">
|
||||||
SELECT
|
SELECT TO_CHAR(d.report_time, 'YYYY-MM') AS month,
|
||||||
TO_CHAR(d.report_time, 'YYYY-MM') AS month,
|
|
||||||
ROUND(AVG(TO_NUMBER(d.ds)), 8) AS avg_ds
|
ROUND(AVG(TO_NUMBER(d.ds)), 8) AS avg_ds
|
||||||
FROM
|
FROM th_device_report d
|
||||||
th_device_report d
|
WHERE d.sn IN (SELECT d.sn
|
||||||
WHERE
|
FROM th_device d
|
||||||
d.sn IN (
|
|
||||||
SELECT
|
|
||||||
d.sn
|
|
||||||
FROM
|
|
||||||
th_device d
|
|
||||||
LEFT JOIN sys_dept p ON d.dept_id = p.dept_id
|
LEFT JOIN sys_dept p ON d.dept_id = p.dept_id
|
||||||
WHERE
|
WHERE d.dept_id IN (SELECT dept_id
|
||||||
d.dept_id IN (
|
FROM sys_dept START WITH dept_id = #{deptId}
|
||||||
SELECT dept_id
|
CONNECT BY PRIOR dept_id = parent_id))
|
||||||
FROM sys_dept
|
|
||||||
START WITH dept_id = #{deptId}
|
|
||||||
CONNECT BY PRIOR dept_id = parent_id
|
|
||||||
)
|
|
||||||
)
|
|
||||||
AND d.report_time >= TO_DATE(#{startMonth}, 'YYYY-MM')
|
AND d.report_time >= TO_DATE(#{startMonth}, 'YYYY-MM')
|
||||||
AND d.report_time <= ADD_MONTHS(TO_DATE(#{endMonth}, 'YYYY-MM'), 1)
|
AND d.report_time <= ADD_MONTHS(TO_DATE(#{endMonth}, 'YYYY-MM'), 1)
|
||||||
GROUP BY
|
GROUP BY TO_CHAR(d.report_time, 'YYYY-MM')
|
||||||
TO_CHAR(d.report_time, 'YYYY-MM')
|
ORDER BY month
|
||||||
ORDER BY
|
|
||||||
month
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectDeviceAvgByMonth" parameterType="map" resultType="map">
|
<select id="selectDeviceAvgByMonth" parameterType="map" resultType="map">
|
||||||
|
@ -100,10 +87,7 @@
|
||||||
FROM th_device_report d
|
FROM th_device_report d
|
||||||
LEFT JOIN th_device td ON d.sn = td.sn
|
LEFT JOIN th_device td ON d.sn = td.sn
|
||||||
LEFT JOIN sys_dept p ON td.dept_id = p.dept_id
|
LEFT JOIN sys_dept p ON td.dept_id = p.dept_id
|
||||||
WHERE td.dept_id IN (SELECT dept_id
|
WHERE td.dept_id IN (SELECT dept_id FROM sys_dept WHERE dept_id = #{deptId} OR parent_id = #{deptId})
|
||||||
FROM sys_dept
|
|
||||||
START WITH dept_id = #{deptId}
|
|
||||||
CONNECT BY PRIOR dept_id = parent_id)
|
|
||||||
AND d.report_time >= TO_DATE(#{startMonth}, 'YYYY-MM')
|
AND d.report_time >= TO_DATE(#{startMonth}, 'YYYY-MM')
|
||||||
AND d.report_time <= ADD_MONTHS(TO_DATE(#{endMonth}, 'YYYY-MM'), 1)
|
AND d.report_time <= ADD_MONTHS(TO_DATE(#{endMonth}, 'YYYY-MM'), 1)
|
||||||
GROUP BY d.sn, p.dept_name, td.name, td.address, td.longitude, td.latitude
|
GROUP BY d.sn, p.dept_name, td.name, td.address, td.longitude, td.latitude
|
||||||
|
@ -118,37 +102,24 @@
|
||||||
FROM th_device_report d
|
FROM th_device_report d
|
||||||
LEFT JOIN th_device td ON d.sn = td.sn
|
LEFT JOIN th_device td ON d.sn = td.sn
|
||||||
LEFT JOIN sys_dept p ON td.dept_id = p.dept_id
|
LEFT JOIN sys_dept p ON td.dept_id = p.dept_id
|
||||||
WHERE td.dept_id IN (SELECT dept_id FROM sys_dept START WITH dept_id = #{deptId} CONNECT BY PRIOR dept_id = parent_id)
|
WHERE td.dept_id IN
|
||||||
|
(SELECT dept_id FROM sys_dept WHERE dept_id = #{deptId} OR parent_id = #{deptId})
|
||||||
AND TO_CHAR(d.report_time, 'YYYY-MM') = #{month}
|
AND TO_CHAR(d.report_time, 'YYYY-MM') = #{month}
|
||||||
GROUP BY p.dept_name
|
GROUP BY p.dept_name
|
||||||
ORDER BY p.dept_name
|
ORDER BY p.dept_name
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectAllAvgByMonth" parameterType="map" resultType="map">
|
<select id="selectAllAvgByMonth" parameterType="map" resultType="map">
|
||||||
SELECT
|
SELECT TO_CHAR(d.report_time, 'YYYY-MM') AS month,
|
||||||
TO_CHAR(d.report_time, 'YYYY-MM') AS month,
|
|
||||||
ROUND(AVG(TO_NUMBER(d.ds)), 8) AS avg_ds,
|
ROUND(AVG(TO_NUMBER(d.ds)), 8) AS avg_ds,
|
||||||
ROUND(AVG(TO_NUMBER(d.dbz)), 8) AS avg_dbz,
|
ROUND(AVG(TO_NUMBER(d.dbz)), 8) AS avg_dbz,
|
||||||
ROUND(AVG(TO_NUMBER(d.gbz)), 8) AS avg_gbz
|
ROUND(AVG(TO_NUMBER(d.gbz)), 8) AS avg_gbz
|
||||||
FROM
|
FROM th_device_report d
|
||||||
th_device_report d
|
WHERE d.sn IN (SELECT td.sn
|
||||||
WHERE
|
FROM th_device td
|
||||||
d.sn IN (
|
|
||||||
SELECT
|
|
||||||
td.sn
|
|
||||||
FROM
|
|
||||||
th_device td
|
|
||||||
LEFT JOIN sys_dept p ON td.dept_id = p.dept_id
|
LEFT JOIN sys_dept p ON td.dept_id = p.dept_id
|
||||||
WHERE
|
WHERE td.dept_id IN (SELECT dept_id FROM sys_dept WHERE dept_id = #{deptId} OR parent_id = #{deptId}))
|
||||||
td.dept_id IN (
|
|
||||||
SELECT dept_id
|
|
||||||
FROM sys_dept
|
|
||||||
START WITH dept_id = #{deptId}
|
|
||||||
CONNECT BY PRIOR dept_id = parent_id
|
|
||||||
)
|
|
||||||
)
|
|
||||||
AND TO_CHAR(d.report_time, 'YYYY-MM') = #{month}
|
AND TO_CHAR(d.report_time, 'YYYY-MM') = #{month}
|
||||||
GROUP BY
|
GROUP BY TO_CHAR(d.report_time, 'YYYY-MM')
|
||||||
TO_CHAR(d.report_time, 'YYYY-MM')
|
|
||||||
</select>
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
@ -63,7 +63,8 @@
|
||||||
"vue-meta": "2.4.0",
|
"vue-meta": "2.4.0",
|
||||||
"vue-router": "3.4.9",
|
"vue-router": "3.4.9",
|
||||||
"vuedraggable": "2.24.3",
|
"vuedraggable": "2.24.3",
|
||||||
"vuex": "3.6.0"
|
"vuex": "3.6.0",
|
||||||
|
"xlsx": "^0.18.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@vue/cli-plugin-babel": "4.4.6",
|
"@vue/cli-plugin-babel": "4.4.6",
|
||||||
|
|
|
@ -15,6 +15,9 @@
|
||||||
>
|
>
|
||||||
</el-date-picker>
|
</el-date-picker>
|
||||||
</el-col>
|
</el-col>
|
||||||
|
<el-col :span="12">
|
||||||
|
<el-button type="primary" icon="eel-icon-download" @click="exportToExcel">导出</el-button>
|
||||||
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
<el-row>
|
<el-row>
|
||||||
<div class="report-center__header ">
|
<div class="report-center__header ">
|
||||||
|
@ -84,6 +87,7 @@
|
||||||
<script>
|
<script>
|
||||||
import DeptTree from "@/components/DeptTree/index.vue";
|
import DeptTree from "@/components/DeptTree/index.vue";
|
||||||
import { reportCenterApi } from "@/api/statistics/reportCenter.js";
|
import { reportCenterApi } from "@/api/statistics/reportCenter.js";
|
||||||
|
import * as XLSX from "xlsx";
|
||||||
import to from "@/utils/await-to.js";
|
import to from "@/utils/await-to.js";
|
||||||
export default {
|
export default {
|
||||||
name: "ReportCenter",
|
name: "ReportCenter",
|
||||||
|
@ -93,6 +97,7 @@ export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
month: "",
|
month: "",
|
||||||
|
dept: {},
|
||||||
deptId: "",
|
deptId: "",
|
||||||
tableData1: [],
|
tableData1: [],
|
||||||
tableData2: [],
|
tableData2: [],
|
||||||
|
@ -115,6 +120,7 @@ export default {
|
||||||
this.month = `${year}-${month < 10 ? "0" + month : month}`;
|
this.month = `${year}-${month < 10 ? "0" + month : month}`;
|
||||||
},
|
},
|
||||||
handleDeptChange(dept) {
|
handleDeptChange(dept) {
|
||||||
|
this.dept = dept;
|
||||||
this.deptId = dept.deptId;
|
this.deptId = dept.deptId;
|
||||||
this.getReportCenterData();
|
this.getReportCenterData();
|
||||||
},
|
},
|
||||||
|
@ -145,7 +151,6 @@ export default {
|
||||||
this.$message.error(err);
|
this.$message.error(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log(res);
|
|
||||||
const { currMonth: cm, lastMonth: lm, deptAvg } = res.data;
|
const { currMonth: cm, lastMonth: lm, deptAvg } = res.data;
|
||||||
const currMonth = Object.assign({}, cm[0]);
|
const currMonth = Object.assign({}, cm[0]);
|
||||||
const lastMonth = Object.assign({}, lm[0]);
|
const lastMonth = Object.assign({}, lm[0]);
|
||||||
|
@ -170,7 +175,31 @@ export default {
|
||||||
|
|
||||||
this.tableData1 = [currMonth, lastMonth, changeRate];
|
this.tableData1 = [currMonth, lastMonth, changeRate];
|
||||||
this.tableData2 = deptAvg;
|
this.tableData2 = deptAvg;
|
||||||
console.log(this.tableData1);
|
},
|
||||||
|
exportToExcel() {
|
||||||
|
this.$message.success("导出成功");
|
||||||
|
// 创建一个新的工作簿
|
||||||
|
const wb = XLSX.utils.book_new();
|
||||||
|
const filename = `${this.dept.deptName} ${this.month.replace("-", "年") + "月"}`;
|
||||||
|
// 创建一个新的工作表
|
||||||
|
const ws_name = "SheetJS";
|
||||||
|
const ws_data = [
|
||||||
|
[filename],
|
||||||
|
["名称", "读数", "低报值", "高报值"],
|
||||||
|
...this.tableData1.map(row => [this.getTableFirstColumnName(row), row.avg_ds, row.avg_dbz, row.avg_gbz]),
|
||||||
|
["部门名", "读数", "低报值", "高报值"],
|
||||||
|
...this.tableData2.map(row => [row.dept_name, row.avg_ds, row.avg_dbz, row.avg_gbz])
|
||||||
|
];
|
||||||
|
const ws = XLSX.utils.aoa_to_sheet(ws_data);
|
||||||
|
|
||||||
|
// 合并第一行的前四个单元格
|
||||||
|
if(!ws['!merges']) ws['!merges'] = [];
|
||||||
|
ws['!merges'].push({s: {r: 0, c: 0}, e: {r: 0, c: 3}});
|
||||||
|
|
||||||
|
// 将工作表添加到工作簿中
|
||||||
|
XLSX.utils.book_append_sheet(wb, ws, ws_name);
|
||||||
|
|
||||||
|
XLSX.writeFile(wb, `${filename}.xlsx`);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue