feat: 添加数据统计-月度数据-港区对比功能

This commit is contained in:
LokerL 2024-11-08 10:25:51 +08:00
parent f01fb04289
commit 1cbfa43044
9 changed files with 312 additions and 2 deletions

View File

@ -155,10 +155,27 @@ public class OilStatisticsController extends BaseController {
resultMap.put("preMonthDs", preMonthDs);
resultMap.put("lastYearDs", lastYearDs);
return success(resultMap);
}
}
@GetMapping("/monthData/dataDetailGangQuCompare")
public AjaxResult dataDetailGangQuCompare(Long deptId, String month) {
// 本月ds均值
List<Map<String, Object>> currentMonthDs = oilThDeviceReportService.monthReportDataOverviewGangQuCompare(deptId, month);
// 上月ds均值
List<Map<String, Object>> preMonthDs = oilThDeviceReportService.monthReportDataOverviewGangQuCompare(deptId, getPreviousMonth(month));
// 去年同月ds均值
List<Map<String, Object>> lastYearDs = oilThDeviceReportService.monthReportDataOverviewGangQuCompare(deptId, getLastYearMonth(month));
Map<String, Object> resultMap = new HashMap<>();
resultMap.put("currentMonthDs", currentMonthDs);
resultMap.put("preMonthDs", preMonthDs);
resultMap.put("lastYearDs", lastYearDs);
return success(resultMap);
}
/**
* 获取去年同月
*
* @param month 2024-09
* @return 2023-09
*/

View File

@ -53,7 +53,7 @@ public class SysSendInfoController extends BaseController {
*/
@Log(title = "发送消息", businessType = BusinessType.UPDATE)
@GetMapping ("/sendMessage")
public AjaxResult sendMessage(SendMessageDTO sendMessageDTO) {
public AjaxResult sendMessage(SendMessageDTO sendMessageDTO) throws Exception {
return success(iSysNoticeService.sendMessage(sendMessageDTO));
}

View File

@ -65,6 +65,9 @@ public interface ThDeviceReportMapper {
@MapKey("month")
List<Map<String, Object>> monthReportDataOverviewDeviceDs(@Param("deptId") Long deptId, @Param("month") String month);
@MapKey("month")
List<Map<String, Object>> monthReportDataOverviewGangQuCompare(@Param("deptId") Long deptId, @Param("month") String month);
/**
* 每日数据
* @param day 日期 2024-08-30

View File

@ -8,6 +8,8 @@ public interface IOilThDeviceReportService {
List<Map<String, Object>> monthReportDataOverviewDeviceDs(Long deptId, String month);
List<Map<String, Object>> monthReportDataOverviewGangQuCompare(Long deptId, String month);
List<Map<String, Object>> dailyReportDataOverview(String day);
List<Map<String, Object>> selectAlarmCountByDeptIdAndDateRange(Long deptId, String beginDate, String endDate);

View File

@ -26,6 +26,11 @@ public class OilThDeviceReportService implements IOilThDeviceReportService {
return camelCaseMapListKey(thDeviceReportMapper.monthReportDataOverviewDeviceDs(deptId, month));
}
@Override
public List<Map<String, Object>> monthReportDataOverviewGangQuCompare(Long deptId, String month) {
return camelCaseMapListKey(thDeviceReportMapper.monthReportDataOverviewGangQuCompare(deptId, month));
}
@Override
public List<Map<String, Object>> dailyReportDataOverview(String day) {
return camelCaseMapListKey(thDeviceReportMapper.dailyReportDataOverview(day));

View File

@ -145,6 +145,29 @@
ORDER BY pp.dept_name, p.dept_name
</select>
<select id="monthReportDataOverviewGangQuCompare" parameterType="map" resultType="map">
SELECT
pp.dept_name as "gang_qu",
ppp.dept_name as "gang_kou",
ROUND(AVG(TO_NUMBER(d.ds)), 8) AS avg_ds
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
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 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 TO_CHAR(d.report_time, 'YYYY-MM') = #{month}
GROUP BY pp.dept_name, ppp.dept_name
ORDER BY ppp.dept_name, pp.dept_name
</select>
<select id="dailyReportDataOverview" parameterType="map" resultType="map">
SELECT TO_CHAR(d.report_time, 'YYYY-MM-DD') AS day,
d.sn,

View File

@ -31,3 +31,11 @@ export function getDataDetail(params) {
method: 'get',
})
}
export function dataDetailGangQuCompare(params) {
return request({
url: '/statistics/monthData/dataDetailGangQuCompare',
params: params,
method: 'get',
})
}

View File

@ -0,0 +1,246 @@
<template>
<div>
<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="dateValue"
type="month"
format="yyyy-MM"
value-format="yyyy-MM"
placeholder="选择月份"
@change="handleDateChange"
>
</el-date-picker>
</el-col>
<el-col :span="12">
<div class="export_btn">
<el-button
type="primary"
icon="eel-icon-download"
@click="exportToExcel"
>导出</el-button
>
</div>
</el-col>
</el-row>
<el-row :gutter="10">
<el-col :span="24">
<el-table :data="tableData" :header-cell-style="headerStyle" :loading="loading" @sort-change="sortChange">
<el-table-column
prop="gangKou"
label="港口"
align="center"
></el-table-column>
<el-table-column
prop="gangQu"
label="港区"
align="center"
></el-table-column>
<el-table-column
prop="currAvgDs"
label="本月均值"
sortable
align="center"
></el-table-column>
<el-table-column
prop="preMonthAvgDs"
label="上月均值"
sortable
align="center"
></el-table-column>
<el-table-column
prop="mom"
label="环比%"
sortable
:sortMethod="sortMomMethod"
align="center"
>
<template slot-scope="scope">
{{ scope.row.mom }}%
</template>
</el-table-column>
<el-table-column
prop="lastYearAvgDs"
label="去年同月均值"
sortable
align="center"
></el-table-column>
<el-table-column
prop="yoy"
label="同比%"
sortable
:sortMethod="sortYoyMethod"
align="center"
>
<template slot-scope="scope">
{{ scope.row.yoy }}%
</template>
</el-table-column>
</el-table>
</el-col>
</el-row>
</div>
</template>
<script>
import * as XLSX from "xlsx";
import { dataDetailGangQuCompare } from "@/api/statistics/monthData.js";
export default {
name: "DataCompare",
data() {
return {
deptId: "",
deptName: "",
dateValue: "",
tableData: [],
loading: false,
headerStyle: {
fontSize: "14px",
backgroundColor: "#f8f8f8",
color: "#333",
},
};
},
created() {
this.initDate();
},
methods: {
initDate() {
const date = new Date();
const year = date.getFullYear();
const month = date.getMonth() + 1;
const monthStr = month < 10 ? `0${month}` : month;
this.dateValue = `${year}-${monthStr}`;
},
handleDeptChange(value) {
this.deptId = value.deptId;
this.deptName = value.deptName;
this.queryData();
},
handleDateChange(value) {
this.queryData();
},
sortMomMethod(a, b) {
return parseFloat(a.mom) - parseFloat(b.mom);
},
sortYoyMethod(a, b) {
return parseFloat(a.yoy) - parseFloat(b.yoy);
},
sortChange({ prop, order }) {
if (order === "ascending") {
this.tableData.sort((a, b) => a[prop] - b[prop]);
} else {
this.tableData.sort((a, b) => b[prop] - a[prop]);
}
},
queryData() {
this.tableData = [];
this.loading = true;
dataDetailGangQuCompare({
deptId: this.deptId,
month: this.dateValue,
}).then((res) => {
if (res.code === 200) {
const { currentMonthDs, lastYearDs, preMonthDs } = res.data;
// const minLength = Math.min(currentMonthDs.length, lastYearDs.length, preMonthDs.length);
//
// const minLength = Math.min(currentMonthDs.length, lastYearDs.length, preMonthDs.length);
// dsds%ds%
// mom % = ( - ) / *100%
// yoy % = ( - ) / *100%
// -
for (let i = 0; i < currentMonthDs.length; i++) {
const dataItem = {};
const currentMonthDsItem = currentMonthDs[i];
dataItem.gangQu = currentMonthDsItem.gangQu;
dataItem.gangKou = currentMonthDsItem.gangKou;
dataItem.currAvgDs = currentMonthDsItem.avgDs;
const lastYearDsItem = lastYearDs.find(
(item) => item.gangQu === currentMonthDsItem.gangQu
);
if (lastYearDsItem) {
dataItem.lastYearAvgDs = lastYearDsItem.avgDs;
dataItem.yoy =
(
((currentMonthDsItem.avgDs - lastYearDsItem.avgDs) /
lastYearDsItem.avgDs) *
100
).toFixed(2);
} else {
dataItem.lastYearAvgDs = 0;
dataItem.yoy = 0;
}
const preMonthDsItem = preMonthDs.find(
(item) => item.gangQu === currentMonthDsItem.gangQu
);
if (preMonthDsItem) {
dataItem.preMonthAvgDs = preMonthDsItem.avgDs;
dataItem.mom =
(
((currentMonthDsItem.avgDs - preMonthDsItem.avgDs) /
preMonthDsItem.avgDs) *
100
).toFixed(2);
} else {
dataItem.preMonthAvgDs = 0;
dataItem.mom = 0;
}
this.tableData.push(dataItem);
}
}
}).finally(() => {
this.loading = false;
});
},
exportToExcel() {
// 簿
const wb = XLSX.utils.book_new();
const filename = `${this.deptName} ${this.dateValue.replace("-", "年") + "月"} 数据详情`;
// //
const ws_name = "SheetJS";
const ws_data = [
[filename],
["港口", "港区", "本月均值", "上月均值", "环比%", "去年同月均值", "同比%"],
...this.tableData.map((row) => [
row.gangKou,
row.gangQu,
row.currAvgDs,
row.preMonthAvgDs,
row.mom,
row.lastYearAvgDs,
row.yoy,
]),
];
const ws = XLSX.utils.aoa_to_sheet(ws_data);
// // 8
if(!ws['!merges']) ws['!merges'] = [];
ws['!merges'].push({s: {r: 0, c: 0}, e: {r: 0, c: 7}});
// // 簿
XLSX.utils.book_append_sheet(wb, ws, ws_name);
XLSX.writeFile(wb, `${filename}.xlsx`);
},
},
};
</script>
<style scoped>
.table-title {
border: 1px solid #ebeef5;
display: flex;
justify-content: center;
align-items: center;
height: 45px;
span {
font-size: 18px;
color: #333;
}
}
.export_btn {
padding: 10px;
display: flex;
justify-content: flex-end;
}
</style>

View File

@ -18,12 +18,14 @@
import CreateReport from "./create-report.vue";
import DataOverview from "./data-overview.vue";
import DataDetail from "./data-detail.vue";
import DataCompare from "./data-compare.vue";
export default {
name: "MonthData",
components: {
CreateReport,
DataOverview,
DataDetail,
DataCompare,
},
data() {
return {
@ -41,6 +43,10 @@ export default {
label: "数据详情",
cpn: "DataDetail",
},
{
label: "港区对比",
cpn: "DataCompare",
},
],
};
},