zlwu hace 1 año
padre
commit
a3d3fccd33

+ 10 - 1
backend/ruoyi-modules/ruoyi-xg/src/main/java/org/dromara/xg/domain/vo/XgStudentStatisticsVo.java

@@ -1,5 +1,6 @@
 package org.dromara.xg.domain.vo;
 package org.dromara.xg.domain.vo;
 
 
+import cn.idev.excel.annotation.ExcelProperty;
 import lombok.Data;
 import lombok.Data;
 import java.util.List;
 import java.util.List;
 
 
@@ -69,48 +70,56 @@ public class XgStudentStatisticsVo {
     @Data
     @Data
     public static class StatisticsDetailData {
     public static class StatisticsDetailData {
         /**
         /**
-         * ID
+         * ID (不导出到Excel)
          */
          */
         private Long id;
         private Long id;
 
 
         /**
         /**
          * 名称
          * 名称
          */
          */
+        @ExcelProperty(value = "名称")
         private String name;
         private String name;
 
 
         /**
         /**
          * 上级名称(如学院下的专业名称显示学院名)
          * 上级名称(如学院下的专业名称显示学院名)
          */
          */
+        @ExcelProperty(value = "上级")
         private String parentName;
         private String parentName;
 
 
         /**
         /**
          * 宿舍扣分总数
          * 宿舍扣分总数
          */
          */
+        @ExcelProperty(value = "宿舍扣分总数")
         private Integer dormDeductionCount;
         private Integer dormDeductionCount;
 
 
         /**
         /**
          * 宿舍违纪记录总数
          * 宿舍违纪记录总数
          */
          */
+        @ExcelProperty(value = "宿舍违纪记录总数")
         private Integer dormViolationCount;
         private Integer dormViolationCount;
 
 
         /**
         /**
          * 宿舍违纪记录扣分总数
          * 宿舍违纪记录扣分总数
          */
          */
+        @ExcelProperty(value = "宿舍违纪记录扣分总数")
         private Double dormViolationDeduction;
         private Double dormViolationDeduction;
 
 
         /**
         /**
          * 教学区违纪记录总数
          * 教学区违纪记录总数
          */
          */
+        @ExcelProperty(value = "教学区违纪记录总数")
         private Integer teachingViolationCount;
         private Integer teachingViolationCount;
 
 
         /**
         /**
          * 教学区违纪记录扣分总数
          * 教学区违纪记录扣分总数
          */
          */
+        @ExcelProperty(value = "教学区违纪记录扣分总数")
         private Double teachingViolationDeduction;
         private Double teachingViolationDeduction;
 
 
         /**
         /**
          * 合计扣分
          * 合计扣分
          */
          */
+        @ExcelProperty(value = "违纪合计扣分")
         private Double totalDeduction;
         private Double totalDeduction;
     }
     }
 
 

+ 34 - 1
web/src/views/xg/studentStatistics/index.vue

@@ -99,6 +99,7 @@
       <template #header>
       <template #header>
         <div class="card-header">
         <div class="card-header">
           <span>明细数据</span>
           <span>明细数据</span>
+          <el-button type="success" icon="Download" @click="handleExport" :loading="exportLoading">导出Excel</el-button>
         </div>
         </div>
       </template>
       </template>
       <el-table :data="statisticsData.detailData" style="width: 100%" border>
       <el-table :data="statisticsData.detailData" style="width: 100%" border>
@@ -286,9 +287,41 @@ const resetQuery = () => {
 
 
 /** 导出按钮操作 */
 /** 导出按钮操作 */
 const handleExport = async () => {
 const handleExport = async () => {
+  if (!statisticsData.value) {
+    ElMessage.warning('暂无数据可导出');
+    return;
+  }
+
   exportLoading.value = true;
   exportLoading.value = true;
   try {
   try {
-    await exportStatistics(queryParams);
+    const response = await exportStatistics(queryParams);
+
+    let blobData: Blob;
+    if (response instanceof Blob) {
+      blobData = response;
+    } else if (response.data instanceof Blob) {
+      blobData = response.data;
+    } else {
+      throw new Error('无效的响应数据格式');
+    }
+
+    // 创建下载链接
+    const url = window.URL.createObjectURL(blobData);
+    const link = document.createElement('a');
+    link.href = url;
+
+    // 生成文件名
+    const now = new Date();
+    const dateStr = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')}`;
+    const timeStr = `${String(now.getHours()).padStart(2, '0')}_${String(now.getMinutes()).padStart(2, '0')}_${String(now.getSeconds()).padStart(2, '0')}`;
+    link.download = `学生统计数据_${dateStr}_${timeStr}.xlsx`;
+
+    link.style.display = 'none';
+    document.body.appendChild(link);
+    link.click();
+    document.body.removeChild(link);
+    window.URL.revokeObjectURL(url);
+
     ElMessage.success('导出成功');
     ElMessage.success('导出成功');
   } catch (error) {
   } catch (error) {
     console.error('导出失败:', error);
     console.error('导出失败:', error);