feat: 年度数据前后端;去除无用菜单

This commit is contained in:
LokerL 2024-09-27 12:57:07 +08:00
parent 33b459531d
commit 426a1311e3
9 changed files with 289 additions and 13 deletions

View File

@ -19,7 +19,6 @@ import org.springframework.web.bind.annotation.*;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -175,4 +174,22 @@ public class OilStatisticsController extends BaseController {
List<Map<String, Object>> dailyReportDataOverview = oilThDeviceReportService.dailyReportDataOverview(day);
return success(dailyReportDataOverview);
}
@GetMapping("/yearData/getDeviceReportYearList")
public TableDataInfo getDeviceReportYearList(Long deptId, String year, int pageNum, int pageSize) {
Page<Object> page = PageHelper.startPage(pageNum, pageSize);
List<Map<String, Object>> result = thDeviceReportMonthService.selectThDeviceReportYearList(deptId, year);
TableDataInfo rspData = new TableDataInfo();
rspData.setCode(HttpStatus.SUCCESS);
rspData.setRows(result);
rspData.setMsg("查询成功");
rspData.setTotal(page.getTotal());
return rspData;
}
@GetMapping("/yearData/getDeviceReportYearListAll")
public AjaxResult getDeviceReportYearList(Long deptId, String year) {
List<Map<String, Object>> result = thDeviceReportMonthService.selectThDeviceReportYearList(deptId, year);
return success(result);
}
}

View File

@ -28,6 +28,9 @@ public interface ThDeviceReportMonthMapper {
@MapKey("dept_id")
List<Map<String, Object>> selectAvgDsByDeptIdAndDate(@Param("deptId") Long deptId, @Param("startYear") int startYear, @Param("startMonth") int startMonth, @Param("endYear") int endYear, @Param("endMonth") int endMonth);
@MapKey("deptId")
List<Map<String, Object>> selectThDeviceReportYearList(Long deptId, String year);
}

View File

@ -23,4 +23,6 @@ public interface ThDeviceReportMonthService {
int updateThDeviceReportMonth(ThDeviceReportMonth thDeviceReportMonth);
List<Map<String, Object>> selectAvgDsByDeptIdAndDate(Long deptId, String startTime, String endTime);
List<Map<String, Object>> selectThDeviceReportYearList(Long deptId, String year);
}

View File

@ -44,6 +44,11 @@ public class ThDeviceReportMonthServiceImpl implements ThDeviceReportMonthServic
int endMonth = Integer.parseInt(endDate.split("-")[1]);
return camelCaseMapListKey(thDeviceReportMonthMapper.selectAvgDsByDeptIdAndDate(deptId, startYear, startMonth, endYear, endMonth));
}
@Override
public List<Map<String, Object>> selectThDeviceReportYearList(Long deptId, String year) {
return camelCaseMapListKey(thDeviceReportMonthMapper.selectThDeviceReportYearList(deptId, year));
}
}

View File

@ -45,6 +45,30 @@
</select>
<select id="selectThDeviceReportYearList" parameterType="map" resultType="map">
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"
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
WHERE m.dept_id IN (
SELECT dept_id
FROM sys_dept START WITH dept_id = #{deptId}
CONNECT BY PRIOR dept_id = parent_id
)
<if test="year != null and year != ''">
AND m.year = #{year}
</if>
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
</select>
<update
id="updateThDeviceReportMonth"
parameterType="com.ruoyi.project.oil.domain.ThDeviceReportMonth"

View File

@ -0,0 +1,17 @@
import request from '@/utils/request'
export function getDeviceReportYearList(params) {
return request({
url: '/statistics/yearData/getDeviceReportYearList',
params: params,
method: 'get',
})
}
export function getDeviceReportYearListAll(params) {
return request({
url: '/statistics/yearData/getDeviceReportYearListAll',
params: params,
method: 'get',
})
}

View File

@ -9,14 +9,6 @@
<template v-if="device!=='mobile'">
<search id="header-search" class="right-menu-item" />
<el-tooltip content="源码地址" effect="dark" placement="bottom">
<ruo-yi-git id="ruoyi-git" class="right-menu-item hover-effect" />
</el-tooltip>
<el-tooltip content="文档地址" effect="dark" placement="bottom">
<ruo-yi-doc id="ruoyi-doc" class="right-menu-item hover-effect" />
</el-tooltip>
<screenfull id="screenfull" class="right-menu-item hover-effect" />
<el-tooltip content="布局大小" effect="dark" placement="bottom">

View File

@ -1,8 +1,7 @@
import * as XLSX from "xlsx";
export function exportExcel(dom, fileName="导出文件") {
const xlsxParam = { raw: true };//转换成excel时使用原始的格式
export function exportExcel(dom, fileName = "导出文件") {
const xlsxParam = { raw: true }; //转换成excel时使用原始的格式
let table;
if (!dom) {
return;
@ -16,5 +15,24 @@ export function exportExcel(dom, fileName="导出文件") {
let wb = XLSX.utils.table_to_book(table, xlsxParam);
// 生成excel
XLSX.writeFile(wb, `${fileName.endsWith(".xlsx") ? fileName : fileName + ".xlsx"}`);
XLSX.writeFile(
wb,
`${fileName.endsWith(".xlsx") ? fileName : fileName + ".xlsx"}`
);
}
export function dataToExcel({data, fileName = "导出文件", sheetName = "SheetJS", wsCallback=null}) {
const wb = XLSX.utils.book_new();
// 创建一个新的工作表
const ws_name = sheetName;
const ws_data = data;
const ws = XLSX.utils.aoa_to_sheet(ws_data);
if (wsCallback) {
wsCallback(ws);
}
// 将工作表添加到工作簿中
XLSX.utils.book_append_sheet(wb, ws, ws_name);
XLSX.writeFile(wb, `${fileName}.xlsx`);
}

View File

@ -0,0 +1,198 @@
<template>
<div class="year-data">
<el-row :gutter="10">
<el-col :span="6" style="margin-top: 10px; margin-bottom: 10px">
<dept-tree @deptChange="handleDeptChange" :showQuickGroup="true" />
</el-col>
<el-col :span="6" style="margin-top: 10px; margin-bottom: 10px">
<el-date-picker
v-model="year"
type="year"
format="yyyy"
value-format="yyyy"
placeholder="选择年"
@change="handleYearChange"
>
</el-date-picker>
</el-col>
<el-col :span="12">
<div class="export_btn">
<el-button
type="primary"
icon="eel-icon-download"
@click="handleExport"
>导出</el-button
>
</div>
</el-col>
</el-row>
<el-row :gutter="10">
<el-table
:data="tableData"
style="width: 100%"
border
:max-height="tableHeight"
v-loading="loading"
>
<el-table-column prop="gangqu" label="归属港区" />
<el-table-column prop="deptName" label="归属企业" />
<el-table-column prop="sn" label="设备编码" />
<el-table-column prop="year" label="年份" />
<el-table-column prop="avgValue" label="平均值">
<!-- <template slot-scope="scope">
<div @dblclick="changeAvgValue(scope.$index, scope.row)">
<span v-show="!scope.row.enable_edit">{{
scope.row.avgValue
}}</span>
<el-input
:ref="'changeAvgValue' + scope.$index"
@blur="changeAvgValueBlur(scope.$index, scope.row)"
@keyup.enter.native="$event.target.blur"
clearable
v-show="scope.row.enable_edit"
size="mini"
v-model="scope.row.avgValue"
placeholder="请输入内容"
></el-input>
</div>
</template> -->
</el-table-column>
</el-table>
<div class="page-ele">
<el-pagination
layout="sizes, prev, pager, next, total"
:total="total"
:page-size="pageSize"
:page-sizes="[10, 20, 30, 40]"
@current-change="handleCurrentChange"
@size-change="handleSizeChange"
>
</el-pagination>
</div>
</el-row>
</div>
</template>
<script>
import { debounce } from "@/utils";
import moment from "moment";
import {
getDeviceReportYearList,
getDeviceReportYearListAll,
} from "@/api/statistics/yearData.js";
import { dataToExcel } from "@/utils/excel.js";
import to from '@/utils/await-to.js';
export default {
data() {
return {
dept: null,
year: "",
queryDebounce: null,
tableData: [],
total: 0,
pageNum: 1,
pageSize: 10,
loading: false,
};
},
computed: {
tableHeight() {
return window.innerHeight - 300;
},
},
mounted() {
// 2024
this.year = moment().year().toString();
this.queryDebounce = debounce(this.query, 100);
},
methods: {
handleYearChange() {
this.queryDebounce();
},
handleDeptChange(dept) {
this.dept = dept;
this.queryDebounce();
},
handleCurrentChange(val) {
this.pageNum = val;
this.queryDebounce();
},
handleSizeChange(val) {
this.pageSize = val;
this.queryDebounce();
},
query() {
if (!this.dept || !this.year) {
return;
}
this.loading = true;
getDeviceReportYearList({
deptId: this.dept.deptId,
year: this.year,
pageNum: this.pageNum,
pageSize: this.pageSize,
})
.then((res) => {
if (res.code === 200) {
this.tableData = res.rows;
this.total = res.total;
}
})
.finally(() => {
this.loading = false;
});
},
async handleExport() {
const fileName = `${this.dept.deptName} ${this.year}年数据统计`;
const [err, response] = await to(getDeviceReportYearListAll({
deptId: this.dept.deptId,
year: this.year,
}));
if (err) {
console.error(err);
this.$message.error("导出失败");
return;
}
const {data} = response;
dataToExcel({
data: [
[fileName],
["归属港区", "归属企业", "设备编码", "年份", "平均值"],
...data.map((row) => [
row.gangqu,
row.deptName,
row.sn,
row.year,
row.avgValue,
]),
],
fileName,
wsCallback: (ws) => {
if (!ws["!merges"]) ws["!merges"] = [];
ws["!merges"].push({ s: { r: 0, c: 0 }, e: { r: 0, c: 4 } });
},
});
this.$message.success("导出成功");
},
},
};
</script>
<style scoped>
.year-data {
padding: 10px 20px;
}
.export_btn {
margin-top: 10px;
display: flex;
justify-content: flex-end;
}
.page-ele {
margin-top: 10px;
text-align: right;
}
</style>