🐞 fix: 修复查询BUG;报表中心添加导出功能
修复:月度均值报表和报表中心不再查询全部后代节点,仅查询本身和直接子节点;新增:报表中心导出为excel
This commit is contained in:
parent
44ab2dc9fd
commit
511d8dd2c6
|
@ -49,13 +49,13 @@
|
|||
|
||||
<select id="selectAllDeviceListByDeptId" parameterType="long" resultMap="BaseResultMap">
|
||||
WITH dept_hierarchy (dept_id) AS (
|
||||
SELECT dept_id
|
||||
FROM sys_dept
|
||||
WHERE dept_id = #{deptId}
|
||||
UNION ALL
|
||||
SELECT d.dept_id
|
||||
FROM sys_dept d
|
||||
INNER JOIN dept_hierarchy dh ON d.parent_id = dh.dept_id
|
||||
SELECT dept_id
|
||||
FROM sys_dept
|
||||
WHERE dept_id = #{deptId}
|
||||
UNION ALL
|
||||
SELECT d.dept_id
|
||||
FROM sys_dept d
|
||||
INNER JOIN dept_hierarchy dh ON d.parent_id = dh.dept_id
|
||||
)
|
||||
<include refid="Base_Column_List"/>
|
||||
INNER JOIN dept_hierarchy dh ON d.dept_id = dh.dept_id
|
||||
|
|
|
@ -59,96 +59,67 @@
|
|||
</select>
|
||||
|
||||
<select id="selectAvgDsByMonth" parameterType="map" resultType="map">
|
||||
SELECT
|
||||
TO_CHAR(d.report_time, 'YYYY-MM') AS month,
|
||||
ROUND(AVG(TO_NUMBER(d.ds)), 8) AS avg_ds
|
||||
FROM
|
||||
th_device_report d
|
||||
WHERE
|
||||
d.sn IN (
|
||||
SELECT
|
||||
d.sn
|
||||
FROM
|
||||
th_device d
|
||||
LEFT JOIN sys_dept p ON d.dept_id = p.dept_id
|
||||
WHERE
|
||||
d.dept_id IN (
|
||||
SELECT dept_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 <= ADD_MONTHS(TO_DATE(#{endMonth}, 'YYYY-MM'), 1)
|
||||
GROUP BY
|
||||
TO_CHAR(d.report_time, 'YYYY-MM')
|
||||
ORDER BY
|
||||
month
|
||||
SELECT TO_CHAR(d.report_time, 'YYYY-MM') AS month,
|
||||
ROUND(AVG(TO_NUMBER(d.ds)), 8) AS avg_ds
|
||||
FROM th_device_report d
|
||||
WHERE d.sn IN (SELECT d.sn
|
||||
FROM th_device d
|
||||
LEFT JOIN sys_dept p ON d.dept_id = p.dept_id
|
||||
WHERE d.dept_id IN (SELECT dept_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 <= ADD_MONTHS(TO_DATE(#{endMonth}, 'YYYY-MM'), 1)
|
||||
GROUP BY TO_CHAR(d.report_time, 'YYYY-MM')
|
||||
ORDER BY month
|
||||
</select>
|
||||
|
||||
<select id="selectDeviceAvgByMonth" parameterType="map" resultType="map">
|
||||
SELECT d.sn,
|
||||
td.name,
|
||||
td.address,
|
||||
td.longitude,
|
||||
td.latitude,
|
||||
p.dept_name,
|
||||
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.gbz)), 8) AS avg_gbz
|
||||
td.name,
|
||||
td.address,
|
||||
td.longitude,
|
||||
td.latitude,
|
||||
p.dept_name,
|
||||
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.gbz)), 8) AS avg_gbz
|
||||
FROM th_device_report d
|
||||
LEFT JOIN th_device td ON d.sn = td.sn
|
||||
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)
|
||||
AND d.report_time >= TO_DATE(#{startMonth}, 'YYYY-MM')
|
||||
AND d.report_time <= ADD_MONTHS(TO_DATE(#{endMonth}, 'YYYY-MM'), 1)
|
||||
LEFT JOIN th_device td ON d.sn = td.sn
|
||||
LEFT JOIN sys_dept p ON td.dept_id = p.dept_id
|
||||
WHERE td.dept_id IN (SELECT dept_id FROM sys_dept WHERE dept_id = #{deptId} OR parent_id = #{deptId})
|
||||
AND d.report_time >= TO_DATE(#{startMonth}, 'YYYY-MM')
|
||||
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
|
||||
ORDER BY p.dept_name
|
||||
</select>
|
||||
|
||||
<select id="selectDeptAvgByMonth" parameterType="map" resultType="map">
|
||||
SELECT p.dept_name,
|
||||
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.gbz)), 8) AS avg_gbz
|
||||
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.gbz)), 8) AS avg_gbz
|
||||
FROM th_device_report d
|
||||
LEFT JOIN th_device td ON d.sn = td.sn
|
||||
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)
|
||||
AND TO_CHAR(d.report_time, 'YYYY-MM') = #{month}
|
||||
LEFT JOIN th_device td ON d.sn = td.sn
|
||||
LEFT JOIN sys_dept p ON td.dept_id = p.dept_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}
|
||||
GROUP BY p.dept_name
|
||||
ORDER BY p.dept_name
|
||||
</select>
|
||||
|
||||
<select id="selectAllAvgByMonth" parameterType="map" resultType="map">
|
||||
SELECT
|
||||
TO_CHAR(d.report_time, 'YYYY-MM') AS month,
|
||||
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.gbz)), 8) AS avg_gbz
|
||||
FROM
|
||||
th_device_report d
|
||||
WHERE
|
||||
d.sn IN (
|
||||
SELECT
|
||||
td.sn
|
||||
FROM
|
||||
th_device td
|
||||
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
|
||||
)
|
||||
)
|
||||
AND TO_CHAR(d.report_time, 'YYYY-MM') = #{month}
|
||||
GROUP BY
|
||||
TO_CHAR(d.report_time, 'YYYY-MM')
|
||||
SELECT TO_CHAR(d.report_time, 'YYYY-MM') AS month,
|
||||
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.gbz)), 8) AS avg_gbz
|
||||
FROM th_device_report d
|
||||
WHERE d.sn IN (SELECT td.sn
|
||||
FROM th_device td
|
||||
LEFT JOIN sys_dept p ON td.dept_id = p.dept_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}
|
||||
GROUP BY TO_CHAR(d.report_time, 'YYYY-MM')
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
@ -63,7 +63,8 @@
|
|||
"vue-meta": "2.4.0",
|
||||
"vue-router": "3.4.9",
|
||||
"vuedraggable": "2.24.3",
|
||||
"vuex": "3.6.0"
|
||||
"vuex": "3.6.0",
|
||||
"xlsx": "^0.18.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vue/cli-plugin-babel": "4.4.6",
|
||||
|
|
|
@ -15,6 +15,9 @@
|
|||
>
|
||||
</el-date-picker>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-button type="primary" icon="eel-icon-download" @click="exportToExcel">导出</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<div class="report-center__header ">
|
||||
|
@ -84,6 +87,7 @@
|
|||
<script>
|
||||
import DeptTree from "@/components/DeptTree/index.vue";
|
||||
import { reportCenterApi } from "@/api/statistics/reportCenter.js";
|
||||
import * as XLSX from "xlsx";
|
||||
import to from "@/utils/await-to.js";
|
||||
export default {
|
||||
name: "ReportCenter",
|
||||
|
@ -93,6 +97,7 @@ export default {
|
|||
data() {
|
||||
return {
|
||||
month: "",
|
||||
dept: {},
|
||||
deptId: "",
|
||||
tableData1: [],
|
||||
tableData2: [],
|
||||
|
@ -115,6 +120,7 @@ export default {
|
|||
this.month = `${year}-${month < 10 ? "0" + month : month}`;
|
||||
},
|
||||
handleDeptChange(dept) {
|
||||
this.dept = dept;
|
||||
this.deptId = dept.deptId;
|
||||
this.getReportCenterData();
|
||||
},
|
||||
|
@ -145,7 +151,6 @@ export default {
|
|||
this.$message.error(err);
|
||||
return;
|
||||
}
|
||||
console.log(res);
|
||||
const { currMonth: cm, lastMonth: lm, deptAvg } = res.data;
|
||||
const currMonth = Object.assign({}, cm[0]);
|
||||
const lastMonth = Object.assign({}, lm[0]);
|
||||
|
@ -170,7 +175,31 @@ export default {
|
|||
|
||||
this.tableData1 = [currMonth, lastMonth, changeRate];
|
||||
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