🐞 fix: 修复查询BUG;报表中心添加导出功能
修复:月度均值报表和报表中心不再查询全部后代节点,仅查询本身和直接子节点;新增:报表中心导出为excel
This commit is contained in:
parent
44ab2dc9fd
commit
511d8dd2c6
|
@ -49,13 +49,13 @@
|
||||||
|
|
||||||
<select id="selectAllDeviceListByDeptId" parameterType="long" resultMap="BaseResultMap">
|
<select id="selectAllDeviceListByDeptId" parameterType="long" resultMap="BaseResultMap">
|
||||||
WITH dept_hierarchy (dept_id) AS (
|
WITH dept_hierarchy (dept_id) AS (
|
||||||
SELECT dept_id
|
SELECT dept_id
|
||||||
FROM sys_dept
|
FROM sys_dept
|
||||||
WHERE dept_id = #{deptId}
|
WHERE dept_id = #{deptId}
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT d.dept_id
|
SELECT d.dept_id
|
||||||
FROM sys_dept d
|
FROM sys_dept d
|
||||||
INNER JOIN dept_hierarchy dh ON d.parent_id = dh.dept_id
|
INNER JOIN dept_hierarchy dh ON d.parent_id = dh.dept_id
|
||||||
)
|
)
|
||||||
<include refid="Base_Column_List"/>
|
<include refid="Base_Column_List"/>
|
||||||
INNER JOIN dept_hierarchy dh ON d.dept_id = dh.dept_id
|
INNER JOIN dept_hierarchy dh ON d.dept_id = dh.dept_id
|
||||||
|
|
|
@ -59,96 +59,67 @@
|
||||||
</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 th_device_report d
|
||||||
FROM
|
WHERE d.sn IN (SELECT d.sn
|
||||||
th_device_report d
|
FROM th_device d
|
||||||
WHERE
|
LEFT JOIN sys_dept p ON d.dept_id = p.dept_id
|
||||||
d.sn IN (
|
WHERE d.dept_id IN (SELECT dept_id
|
||||||
SELECT
|
FROM sys_dept START WITH dept_id = #{deptId}
|
||||||
d.sn
|
CONNECT BY PRIOR dept_id = parent_id))
|
||||||
FROM
|
AND d.report_time >= TO_DATE(#{startMonth}, 'YYYY-MM')
|
||||||
th_device d
|
AND d.report_time <= ADD_MONTHS(TO_DATE(#{endMonth}, 'YYYY-MM'), 1)
|
||||||
LEFT JOIN sys_dept p ON d.dept_id = p.dept_id
|
GROUP BY TO_CHAR(d.report_time, 'YYYY-MM')
|
||||||
WHERE
|
ORDER BY month
|
||||||
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>
|
||||||
|
|
||||||
<select id="selectDeviceAvgByMonth" parameterType="map" resultType="map">
|
<select id="selectDeviceAvgByMonth" parameterType="map" resultType="map">
|
||||||
SELECT d.sn,
|
SELECT d.sn,
|
||||||
td.name,
|
td.name,
|
||||||
td.address,
|
td.address,
|
||||||
td.longitude,
|
td.longitude,
|
||||||
td.latitude,
|
td.latitude,
|
||||||
p.dept_name,
|
p.dept_name,
|
||||||
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 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
|
AND d.report_time >= TO_DATE(#{startMonth}, 'YYYY-MM')
|
||||||
START WITH dept_id = #{deptId}
|
AND d.report_time <= ADD_MONTHS(TO_DATE(#{endMonth}, 'YYYY-MM'), 1)
|
||||||
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 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
|
||||||
ORDER BY p.dept_name
|
ORDER BY p.dept_name
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectDeptAvgByMonth" parameterType="map" resultType="map">
|
<select id="selectDeptAvgByMonth" parameterType="map" resultType="map">
|
||||||
SELECT p.dept_name,
|
SELECT p.dept_name,
|
||||||
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 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
|
||||||
AND TO_CHAR(d.report_time, 'YYYY-MM') = #{month}
|
(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
|
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 th_device_report d
|
||||||
FROM
|
WHERE d.sn IN (SELECT td.sn
|
||||||
th_device_report d
|
FROM th_device td
|
||||||
WHERE
|
LEFT JOIN sys_dept p ON td.dept_id = p.dept_id
|
||||||
d.sn IN (
|
WHERE td.dept_id IN (SELECT dept_id FROM sys_dept WHERE dept_id = #{deptId} OR parent_id = #{deptId}))
|
||||||
SELECT
|
AND TO_CHAR(d.report_time, 'YYYY-MM') = #{month}
|
||||||
td.sn
|
GROUP BY TO_CHAR(d.report_time, 'YYYY-MM')
|
||||||
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>
|
</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