Procházet zdrojové kódy

1.4邮件输出word

Crazy před 2 týdny
rodič
revize
f0b3127ba5

+ 32 - 33
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java

@@ -245,15 +245,10 @@ public class MailTemplateController {
                         studentAttendanceService.getStudentAttendanceListForTeacher(attendanceReqVO),
                         StudentAttendanceCollegeTemplateVO.class
                 );
-                List<StudentAttendanceCollegeTemplateVO> errorList
-                        = studentAttendanceService.getStudentAttendanceErrorListForTeacher(attendanceReqVO)
-                        .stream()
-                        .map(studentAttendance -> {
-                            StudentAttendanceCollegeTemplateVO vo = BeanUtils.toBean(studentAttendance, StudentAttendanceCollegeTemplateVO.class);
-                            vo.setClockInTime("未打卡");
-                            return vo;
-                        })
-                        .collect(Collectors.toList());
+                List<StudentAttendanceCollegeErrorTemplateVO> errorList = BeanUtils.toBean(
+                        studentAttendanceService.getStudentAttendanceErrorListForTeacher(attendanceReqVO),
+                        StudentAttendanceCollegeErrorTemplateVO.class);
+
 
 //                List<StudentAttendanceCollegeTemplateVO> excusedList = studentAttendanceService.getStudentAttendanceExcusedListForTeacher(attendanceReqVO)
 //                        .stream()
@@ -268,14 +263,18 @@ public class MailTemplateController {
                 ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
 
                 // 写入 Excel 文件
-                try (ExcelWriter excelWriter = EasyExcel.write(byteArrayOutputStream, StudentAttendanceCollegeTemplateVO.class).build()) {
-                    WriteSheet writeSheetNormal = EasyExcel.writerSheet("正常打卡信息").build();
-                    WriteSheet writeSheetError = EasyExcel.writerSheet("未打卡信息").build();
-//                    WriteSheet writeSheetExcused = EasyExcel.writerSheet("请假信息").build();
-                    excelWriter.write(errorList, writeSheetError);
-                    excelWriter.write(normalList, writeSheetNormal);
-
-//                    excelWriter.write(excusedList, writeSheetExcused);
+                try (ExcelWriter excelWriter = EasyExcel.write(byteArrayOutputStream).build()) {
+                    WriteSheet writeSheetNormal = EasyExcel.writerSheet("正常打卡信息")
+                            .head(StudentAttendanceCollegeTemplateVO.class)  // 指定模板类
+                            .build();
+
+                    WriteSheet writeSheetError = EasyExcel.writerSheet("未打卡信息")
+                            .head(StudentAttendanceCollegeErrorTemplateVO.class)  // 指定模板类
+                            .build();
+                    // 将各个 List 数据写入不同的 Sheet 中
+                    excelWriter.write(normalList, writeSheetNormal);  // 写入正常打卡数据
+                    excelWriter.write(errorList, writeSheetError);    // 写入未打卡数据
+
                 }
 
                 // 附件
@@ -571,18 +570,15 @@ public class MailTemplateController {
             for (AdminUserDO college : collegeList) {
 
                 attendanceReqVO.setDate(yesterday);
+
                 List<StudentAttendanceCollegeTemplateVO> normalList = BeanUtils.toBean(
                         studentAttendanceService.getStudentAttendanceListForTeacher(attendanceReqVO),
                         StudentAttendanceCollegeTemplateVO.class
                 );
-                List<StudentAttendanceCollegeTemplateVO> errorList = studentAttendanceService.getStudentAttendanceErrorListForTeacher(attendanceReqVO)
-                        .stream()
-                        .map(studentAttendance -> {
-                            StudentAttendanceCollegeTemplateVO vo = BeanUtils.toBean(studentAttendance, StudentAttendanceCollegeTemplateVO.class);
-                            vo.setClockInTime("未打卡");
-                            return vo;
-                        })
-                        .collect(Collectors.toList());
+
+                List<StudentAttendanceCollegeErrorTemplateVO> errorList = BeanUtils.toBean(
+                        studentAttendanceService.getStudentAttendanceErrorListForTeacher(attendanceReqVO),
+                        StudentAttendanceCollegeErrorTemplateVO.class);
 
 //                List<StudentAttendanceCollegeTemplateVO> excusedList = studentAttendanceService.getStudentAttendanceExcusedListForTeacher(attendanceReqVO)
 //                        .stream()
@@ -597,15 +593,18 @@ public class MailTemplateController {
                 ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
 
                 // 写入 Excel 文件
-                try (ExcelWriter excelWriter = EasyExcel.write(byteArrayOutputStream, StudentAttendanceCollegeTemplateVO.class).build()) {
-                    WriteSheet writeSheetNormal = EasyExcel.writerSheet("正常打卡信息").build();
-                    WriteSheet writeSheetError = EasyExcel.writerSheet("未打卡信息").build();
-//                    WriteSheet writeSheetExcused = EasyExcel.writerSheet("请假信息").build();
-
+                try (ExcelWriter excelWriter = EasyExcel.write(byteArrayOutputStream).build()) {
+                    WriteSheet writeSheetNormal = EasyExcel.writerSheet("正常打卡信息")
+                            .head(StudentAttendanceCollegeTemplateVO.class)  // 指定模板类
+                            .build();
+
+                    WriteSheet writeSheetError = EasyExcel.writerSheet("未打卡信息")
+                            .head(StudentAttendanceCollegeErrorTemplateVO.class)  // 指定模板类
+                            .build();
                     // 将各个 List 数据写入不同的 Sheet 中
-                    excelWriter.write(normalList, writeSheetNormal);
-                    excelWriter.write(errorList, writeSheetError);
-//                    excelWriter.write(excusedList, writeSheetExcused);
+                    excelWriter.write(normalList, writeSheetNormal);  // 写入正常打卡数据
+                    excelWriter.write(errorList, writeSheetError);    // 写入未打卡数据
+
                 }
 
                 Map<String, InputStream> attachments = new HashMap<>();

+ 56 - 0
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/StudentAttendanceCollegeErrorTemplateVO.java

@@ -0,0 +1,56 @@
+package cn.iocoder.yudao.module.system.controller.admin.mail.vo.template;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.alibaba.excel.annotation.write.style.ColumnWidth;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+@Schema(description = "管理后台 - 邮件学生考勤信息模版的Response VO")
+@Data
+public class StudentAttendanceCollegeErrorTemplateVO {
+
+
+    @Schema(description = "学生名字")
+    @ColumnWidth(20)
+    @ExcelProperty(value = "学生名字")
+    private String studentName;
+
+    @Schema(description = "学生学号")
+    @ColumnWidth(20)
+    @ExcelProperty(value = "学生学号")
+    private String userNumber;
+
+    @Schema(description = "工作间名称")
+    @ColumnWidth(20)
+    @ExcelProperty(value = "工作间名称")
+    private String deptName;
+
+    @Schema(description = "导师名称")
+    @ColumnWidth(20)
+    @ExcelProperty(value = "导师名称")
+    private String supervisor;
+
+    @Schema(description = "日期")
+    @ColumnWidth(20)
+    @ExcelProperty(value = "日期")
+    private String date;
+
+    @Schema(description = "备注")
+    @ColumnWidth(20)
+    @ExcelProperty(value = "备注")
+    private String remark;
+
+    public String getDeptName() {
+        return deptName == null ? "无" : deptName;
+    }
+
+    public void setDeptName(String deptName) {
+        this.deptName = deptName;
+    }
+
+    public String getSupervisor() {
+        return supervisor == null ? "无" : supervisor;
+    }
+
+
+}

+ 6 - 1
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/StudentAttendanceCollegeTemplateVO.java

@@ -1,10 +1,14 @@
 package cn.iocoder.yudao.module.system.controller.admin.mail.vo.template;
 
 import com.alibaba.excel.annotation.ExcelProperty;
+import com.alibaba.excel.annotation.format.DateTimeFormat;
 import com.alibaba.excel.annotation.write.style.ColumnWidth;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
 
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+
 @Schema(description = "管理后台 - 邮件学生考勤信息模版的Response VO")
 @Data
 public class StudentAttendanceCollegeTemplateVO {
@@ -38,7 +42,8 @@ public class StudentAttendanceCollegeTemplateVO {
     @Schema(description = "打卡时间")
     @ColumnWidth(20)
     @ExcelProperty(value = "打卡时间")
-    private String clockInTime;
+    @DateTimeFormat("yyyy-MM-dd HH:mm:ss")  // 添加日期格式化注解
+    private LocalDateTime clockInTime;
 
     public String getDeptName() {
         return deptName == null ? "无" : deptName;

+ 0 - 12
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/StudentAttendanceSupervisorTemplateVO.java

@@ -14,33 +14,21 @@ public class StudentAttendanceSupervisorTemplateVO {
 
 
     @Schema(description = "学生名字")
-    @ColumnWidth(20)
-    @ExcelProperty(value = "学生名字")
     private String studentName;
 
     @Schema(description = "学生学号")
-    @ColumnWidth(20)
-    @ExcelProperty(value = "学生学号")
     private String userNumber;
 
     @Schema(description = "工作间名称")
-    @ColumnWidth(20)
-    @ExcelProperty(value = "工作间名称")
     private String deptName;
 
     @Schema(description = "日期")
-    @ColumnWidth(20)
-    @ExcelProperty(value = "日期")
     private String date;
 
     @Schema(description = "打卡时间")
-    @ColumnWidth(20)
-    @ExcelProperty(value = "打卡时间")
     private LocalDateTime clockInTime;
 
     @Schema(description = "备注")
-    @ColumnWidth(20)
-    @ExcelProperty(value = "打卡时间")
     private String remark;
 
     // Getter 方法,直接返回格式化后的字符串