|
@@ -3,16 +3,11 @@ package cn.iocoder.yudao.module.system.controller.admin.mail;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
-import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
|
|
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.*;
|
|
|
import cn.iocoder.yudao.module.system.controller.admin.studentAttendance.vo.StudentAttendanceEmailVO;
|
|
|
import cn.iocoder.yudao.module.system.controller.admin.studentAttendance.vo.StudentAttendancePageReqVO;
|
|
|
-import cn.iocoder.yudao.module.system.controller.admin.studentAttendance.vo.StudentAttendanceRespVO;
|
|
|
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserPageReqVO;
|
|
|
-import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.graduateStudentExportExcelVO;
|
|
|
-import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO;
|
|
|
-import cn.iocoder.yudao.module.system.dal.dataobject.studentAttendance.StudentAttendanceDO;
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
|
|
import cn.iocoder.yudao.module.system.service.dept.DeptService;
|
|
|
import cn.iocoder.yudao.module.system.service.mail.MailSendService;
|
|
@@ -26,6 +21,7 @@ import com.alibaba.excel.write.metadata.WriteSheet;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
@@ -35,8 +31,8 @@ import javax.validation.Valid;
|
|
|
import java.io.*;
|
|
|
import java.time.DayOfWeek;
|
|
|
import java.time.LocalDate;
|
|
|
-import java.time.temporal.TemporalAdjusters;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
|
|
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
|
@@ -59,82 +55,26 @@ public class MailTemplateController {
|
|
|
@Resource
|
|
|
private PermissionService permissionService;
|
|
|
|
|
|
- @Scheduled(cron = "0 30 8 * * ?") // 每天晚上 22:30
|
|
|
+ private static final short[] COLUMN_WIDTHS = {20, 20, 20, 20}; // 根据需要设置列宽
|
|
|
+
|
|
|
+ @Scheduled(cron = "0 30 8 * * ?") // 每天早上 8:30发送前一天的
|
|
|
@Operation(summary = "定时发送邮件给导师")
|
|
|
public void sendMailToTeacherScheduled() {
|
|
|
- // 创建结果对象并设置属性
|
|
|
- UserPageReqVO reqVO = new UserPageReqVO();
|
|
|
- reqVO.setUserType("3");//找导师
|
|
|
- List<AdminUserDO> TeacherList = adminUserService.getUserList(reqVO);
|
|
|
- StudentAttendancePageReqVO pageReqVO =new StudentAttendancePageReqVO();
|
|
|
- Map<String, Object> templateParams =new HashMap<>();//模板参数设置
|
|
|
- // 获取前一天
|
|
|
- LocalDate yesterday = LocalDate.now().minusDays(1);
|
|
|
- // 检查昨天是否是周日
|
|
|
- if (yesterday.getDayOfWeek() == DayOfWeek.MONDAY) {
|
|
|
- return; // 直接返回,不推送周日的
|
|
|
- }
|
|
|
-
|
|
|
- if ( TeacherList!=null&& !TeacherList.isEmpty()) {
|
|
|
- for (AdminUserDO teacher : TeacherList) {
|
|
|
- pageReqVO.setDate(yesterday);
|
|
|
- List<StudentAttendanceEmailVO> normalList = BeanUtils.toBean(
|
|
|
- studentAttendanceService.getStudentAttendanceListForTeacher(pageReqVO.setDeptId(String.valueOf(teacher.getDeptId()))),
|
|
|
- StudentAttendanceEmailVO.class
|
|
|
- );
|
|
|
- List<StudentAttendanceEmailVO> errorList = BeanUtils.toBean(
|
|
|
- studentAttendanceService.getStudentAttendanceErrorListForTeacher(pageReqVO.setDeptId(String.valueOf(teacher.getDeptId()))),
|
|
|
- StudentAttendanceEmailVO.class
|
|
|
- );
|
|
|
- List<StudentAttendanceEmailVO> excusedList = BeanUtils.toBean(
|
|
|
- studentAttendanceService.getStudentAttendanceExcusedListForTeacher(pageReqVO.setDeptId(String.valueOf(teacher.getDeptId()))),
|
|
|
- StudentAttendanceEmailVO.class
|
|
|
- );
|
|
|
-
|
|
|
- StringBuilder normalListBuilder = new StringBuilder();
|
|
|
- for (StudentAttendanceEmailVO attendance : normalList) {
|
|
|
- normalListBuilder
|
|
|
- .append(", 学生姓名: ").append(attendance.getStudentName())
|
|
|
- .append(", 学生学号: ").append(attendance.getUserNumber() != null ? attendance.getUserNumber() : "无")
|
|
|
- .append(", 日期: ").append(attendance.getDate())
|
|
|
- .append(", 打卡时间: ").append(attendance.getClockInTime() != null ? attendance.getClockInTime() : "未打卡")
|
|
|
- .append("<br/>");
|
|
|
- }
|
|
|
-
|
|
|
- StringBuilder errorListBuilder = new StringBuilder();
|
|
|
- for (StudentAttendanceEmailVO attendance : errorList) {
|
|
|
- errorListBuilder
|
|
|
- .append(", 学生姓名: ").append(attendance.getStudentName())
|
|
|
- .append(", 学生学号: ").append(attendance.getUserNumber() != null ? attendance.getUserNumber() : "无")
|
|
|
- .append(", 日期: ").append(attendance.getDate())
|
|
|
- .append(", 打卡时间: ").append(attendance.getClockInTime() != null ? attendance.getClockInTime() : "未打卡")
|
|
|
- .append("<br/>");
|
|
|
- }
|
|
|
-
|
|
|
- StringBuilder excusedListBuilder = new StringBuilder();
|
|
|
- for (StudentAttendanceEmailVO attendance : excusedList) {
|
|
|
- excusedListBuilder
|
|
|
- .append(", 学生姓名: ").append(attendance.getStudentName())
|
|
|
- .append(", 学生学号: ").append(attendance.getUserNumber() != null ? attendance.getUserNumber() : "无")
|
|
|
- .append(", 日期: ").append(attendance.getDate())
|
|
|
- .append(", 打卡时间: ").append(attendance.getClockInTime() != null ? attendance.getClockInTime() : "请假")
|
|
|
- .append("<br/>");
|
|
|
- }
|
|
|
-
|
|
|
- templateParams.put("normalList", normalListBuilder.toString());
|
|
|
- templateParams.put("errorList", errorListBuilder.toString());
|
|
|
- templateParams.put("excusedList", excusedListBuilder.toString());
|
|
|
- if (teacher.getEmail() != null) {
|
|
|
- mailSendService.sendSingleMailToMember(teacher.getEmail(), null, "attendance-list", templateParams);
|
|
|
- }
|
|
|
- }
|
|
|
+ try {
|
|
|
+ sendExcelMailToTeacher();
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Scheduled(cron = "0 30 8 * * ?") // 每天晚上 22:30
|
|
|
+ @Scheduled(cron = "0 30 8 * * ?") // 每天早上 8:30发送前一天的
|
|
|
@Operation(summary = "定时发送邮件给学院")
|
|
|
public void sendMailToCollegeScheduled() {
|
|
|
- testCollege();
|
|
|
+ try {
|
|
|
+ sendExcelMailToCollege();
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@PostMapping("/create")
|
|
@@ -193,15 +133,151 @@ public class MailTemplateController {
|
|
|
sendReqVO.getTemplateCode(), sendReqVO.getTemplateParams()));
|
|
|
}
|
|
|
|
|
|
+ @PostMapping("/sendExcelToTeacher")
|
|
|
+ @Operation(summary = "发送Excel给导师")
|
|
|
+ public void sendExcelMailToTeacher() throws IOException {
|
|
|
+ // 获取导师
|
|
|
+ Set<Long> collegeIdList = permissionService.getUserListByRoleId(114L);
|
|
|
+ List<AdminUserDO> TeacherList = adminUserService.getUserList(collegeIdList);
|
|
|
+
|
|
|
+ StudentAttendancePageReqVO pageReqVO = new StudentAttendancePageReqVO();
|
|
|
+ Map<String, Object> templateParams = new HashMap<>(); // 模板参数设置
|
|
|
+
|
|
|
+ // 获取前一天
|
|
|
+ LocalDate yesterday = LocalDate.now().minusDays(1);
|
|
|
+ // // 检查昨天是否是周日
|
|
|
+// if (yesterday.getDayOfWeek() == DayOfWeek.SUNDAY) {
|
|
|
+// return; // 直接返回,不推送周日的
|
|
|
+// }
|
|
|
+ if (TeacherList != null && !TeacherList.isEmpty()) {
|
|
|
+ for (AdminUserDO teacher : TeacherList) {
|
|
|
+ if (teacher.getDeptId() == null || teacher.getDeptId() == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ pageReqVO.setDate(yesterday);
|
|
|
+ pageReqVO.setDeptId(teacher.getDeptId());
|
|
|
+ List<StudentAttendanceSupervisorTemplateVO> normalList = BeanUtils.toBean(
|
|
|
+ studentAttendanceService.getStudentAttendanceListForTeacher(pageReqVO),
|
|
|
+ StudentAttendanceSupervisorTemplateVO.class
|
|
|
+ );
|
|
|
+ List<StudentAttendanceSupervisorTemplateVO> errorList = BeanUtils.toBean(
|
|
|
+ studentAttendanceService.getStudentAttendanceErrorListForTeacher(pageReqVO),
|
|
|
+ StudentAttendanceSupervisorTemplateVO.class
|
|
|
+ );
|
|
|
+ List<StudentAttendanceSupervisorTemplateVO> excusedList = BeanUtils.toBean(
|
|
|
+ studentAttendanceService.getStudentAttendanceExcusedListForTeacher(pageReqVO),
|
|
|
+ StudentAttendanceSupervisorTemplateVO.class
|
|
|
+ );
|
|
|
+ // 创建 ByteArrayOutputStream 用来存储 Excel 文件数据
|
|
|
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
+
|
|
|
+ // 写入 Excel 文件
|
|
|
+ try (ExcelWriter excelWriter = EasyExcel.write(byteArrayOutputStream, StudentAttendanceSupervisorTemplateVO.class).build()) {
|
|
|
+ WriteSheet writeSheetNormal = EasyExcel.writerSheet("正常打卡信息").build();
|
|
|
+ WriteSheet writeSheetError = EasyExcel.writerSheet("未打卡信息").build();
|
|
|
+ WriteSheet writeSheetExcused = EasyExcel.writerSheet("请假信息").build();
|
|
|
+
|
|
|
+ // 将各个 List 数据写入不同的 Sheet 中
|
|
|
+ excelWriter.write(normalList, writeSheetNormal);
|
|
|
+ excelWriter.write(errorList, writeSheetError);
|
|
|
+ excelWriter.write(excusedList, writeSheetExcused);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建附件 Map
|
|
|
+ Map<String, InputStream> attachments = new HashMap<>();
|
|
|
+ // 使用 ByteArrayInputStream 来创建附件
|
|
|
+ attachments.put(yesterday+"_"+teacher.getDeptName()+"考勤信息.xlsx", new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
|
|
|
+
|
|
|
+ // 发送邮件,包含附件
|
|
|
+ if (teacher.getEmail() != null) {
|
|
|
+ mailSendService.sendSingleMailToMemberWithAttachments(teacher.getEmail(), null, "attendance-list-excel", templateParams, attachments);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/sendExcelToCollege")
|
|
|
+ @Operation(summary = "发送Excel给学院")
|
|
|
+ public void sendExcelMailToCollege() throws IOException {
|
|
|
+ UserPageReqVO reqVO = new UserPageReqVO();
|
|
|
+ Set<Long> collegeIdList = permissionService.getUserListByRoleId(114L);
|
|
|
+
|
|
|
+ Set<AdminUserDO> collegeList = new HashSet<>();
|
|
|
+ List<AdminUserDO> collegeList1 = adminUserService.getUserList(collegeIdList);
|
|
|
+ reqVO.setUserType("4");
|
|
|
+ List<AdminUserDO> collegeList2 = adminUserService.getUserList(reqVO);
|
|
|
+
|
|
|
+ collegeList.addAll(collegeList1);
|
|
|
+ collegeList.addAll(collegeList2);
|
|
|
+
|
|
|
+ StudentAttendancePageReqVO attendanceReqVO =new StudentAttendancePageReqVO();
|
|
|
+
|
|
|
+ Map<String, Object> templateParams =new HashMap<>();//模板参数设置
|
|
|
+
|
|
|
+ // 获取前一天
|
|
|
+ LocalDate yesterday = LocalDate.now().minusDays(1);
|
|
|
+ if ( !collegeList.isEmpty()) {
|
|
|
+ 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<StudentAttendanceCollegeTemplateVO> excusedList = studentAttendanceService.getStudentAttendanceExcusedListForTeacher(attendanceReqVO)
|
|
|
+ .stream()
|
|
|
+ .map(studentAttendance -> {
|
|
|
+ StudentAttendanceCollegeTemplateVO vo = BeanUtils.toBean(studentAttendance, StudentAttendanceCollegeTemplateVO.class);
|
|
|
+ vo.setClockInTime("请假");
|
|
|
+ return vo;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 输出 Excel
|
|
|
+ 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(normalList, writeSheetNormal);
|
|
|
+ excelWriter.write(errorList, writeSheetError);
|
|
|
+ excelWriter.write(excusedList, writeSheetExcused);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 附件
|
|
|
+ Map<String, InputStream> attachments = new HashMap<>();
|
|
|
+ // 创建附件
|
|
|
+ attachments.put(yesterday+"_"+"考勤信息.xlsx", new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
|
|
|
+
|
|
|
+ // 发送邮件,包含附件
|
|
|
+ if (college.getEmail() != null) {
|
|
|
+ mailSendService.sendSingleMailToMemberWithAttachments(college.getEmail(), null, "attendance-list-excel", templateParams, attachments);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
@PostMapping("/testTeacher")
|
|
|
- @Operation(summary = "定时发送邮件给导师")
|
|
|
+ @Operation(summary = "测试发送邮件给导师")
|
|
|
public void testTeacher() {
|
|
|
- // 创建结果对象并设置属性
|
|
|
- UserPageReqVO reqVO = new UserPageReqVO();
|
|
|
+ // 获取导师
|
|
|
+ Set<Long> collegeIdList = permissionService.getUserListByRoleId(114L);
|
|
|
+ List<AdminUserDO> TeacherList = adminUserService.getUserList(collegeIdList);
|
|
|
+
|
|
|
|
|
|
- reqVO.setUserType("3");//找导师
|
|
|
- List<AdminUserDO> TeacherList = adminUserService.getUserList(reqVO);
|
|
|
StudentAttendancePageReqVO pageReqVO =new StudentAttendancePageReqVO();
|
|
|
Map<String, Object> templateParams =new HashMap<>();//模板参数设置
|
|
|
|
|
@@ -214,17 +290,21 @@ public class MailTemplateController {
|
|
|
|
|
|
if ( TeacherList!=null&& !TeacherList.isEmpty()) {
|
|
|
for (AdminUserDO teacher : TeacherList) {
|
|
|
+ if (teacher.getDeptId() == null || teacher.getDeptId() == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
pageReqVO.setDate(yesterday);
|
|
|
+ pageReqVO.setDeptId(teacher.getDeptId());
|
|
|
List<StudentAttendanceEmailVO> normalList = BeanUtils.toBean(
|
|
|
- studentAttendanceService.getStudentAttendanceListForTeacher(pageReqVO.setDeptId(String.valueOf(teacher.getDeptId()))),
|
|
|
+ studentAttendanceService.getStudentAttendanceListForTeacher(pageReqVO),
|
|
|
StudentAttendanceEmailVO.class
|
|
|
);
|
|
|
List<StudentAttendanceEmailVO> errorList = BeanUtils.toBean(
|
|
|
- studentAttendanceService.getStudentAttendanceErrorListForTeacher(pageReqVO.setDeptId(String.valueOf(teacher.getDeptId()))),
|
|
|
+ studentAttendanceService.getStudentAttendanceErrorListForTeacher(pageReqVO),
|
|
|
StudentAttendanceEmailVO.class
|
|
|
);
|
|
|
List<StudentAttendanceEmailVO> excusedList = BeanUtils.toBean(
|
|
|
- studentAttendanceService.getStudentAttendanceExcusedListForTeacher(pageReqVO.setDeptId(String.valueOf(teacher.getDeptId()))),
|
|
|
+ studentAttendanceService.getStudentAttendanceExcusedListForTeacher(pageReqVO),
|
|
|
StudentAttendanceEmailVO.class
|
|
|
);
|
|
|
|
|
@@ -270,7 +350,7 @@ public class MailTemplateController {
|
|
|
}
|
|
|
|
|
|
@PostMapping("/testCollege")
|
|
|
- @Operation(summary = "定时发送邮件给学院")
|
|
|
+ @Operation(summary = "测试发送邮件给学院")
|
|
|
public void testCollege() {
|
|
|
UserPageReqVO reqVO = new UserPageReqVO();
|
|
|
Set<Long> collegeIdList = permissionService.getUserListByRoleId(114L);
|
|
@@ -298,6 +378,7 @@ public class MailTemplateController {
|
|
|
|
|
|
if ( !collegeList.isEmpty()) {
|
|
|
for (AdminUserDO college : collegeList) {
|
|
|
+
|
|
|
attendanceReqVO.setDate(yesterday);
|
|
|
List<StudentAttendanceEmailVO> normalList = BeanUtils.toBean(
|
|
|
studentAttendanceService.getStudentAttendanceListForTeacher(attendanceReqVO),
|
|
@@ -358,109 +439,146 @@ public class MailTemplateController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @PostMapping("/SendExcelToTeacher")
|
|
|
- @Operation(summary = "发送Excel给导师")
|
|
|
- public void sendExcelMailToTeacherScheduled() throws IOException {
|
|
|
- // 创建结果对象并设置属性
|
|
|
- UserPageReqVO reqVO = new UserPageReqVO();
|
|
|
- reqVO.setUserType("3"); // 找导师
|
|
|
- List<AdminUserDO> TeacherList = adminUserService.getUserList(reqVO);
|
|
|
+ @PostMapping("/ceshiSendExcelToTeacher")
|
|
|
+ @Operation(summary = "测试发送Excel给老师")
|
|
|
+ public void ceshiSendExcelMail(@RequestParam("email") String email) throws IOException {
|
|
|
+
|
|
|
+ // 获取导师
|
|
|
+ Set<Long> collegeIdList = permissionService.getUserListByRoleId(114L);
|
|
|
+ List<AdminUserDO> TeacherList = adminUserService.getUserList(collegeIdList);
|
|
|
+
|
|
|
StudentAttendancePageReqVO pageReqVO = new StudentAttendancePageReqVO();
|
|
|
Map<String, Object> templateParams = new HashMap<>(); // 模板参数设置
|
|
|
|
|
|
- LocalDate today = LocalDate.now();
|
|
|
+ LocalDate yesterday = LocalDate.now().minusDays(1);
|
|
|
if (TeacherList != null && !TeacherList.isEmpty()) {
|
|
|
for (AdminUserDO teacher : TeacherList) {
|
|
|
- pageReqVO.setDate(today);
|
|
|
- List<StudentAttendanceTemplateVO> normalList = BeanUtils.toBean(
|
|
|
- studentAttendanceService.getStudentAttendanceListForTeacher(pageReqVO.setDeptId(String.valueOf(0))),
|
|
|
- StudentAttendanceTemplateVO.class
|
|
|
- );
|
|
|
- List<StudentAttendanceTemplateVO> errorList = BeanUtils.toBean(
|
|
|
- studentAttendanceService.getStudentAttendanceErrorListForTeacher(pageReqVO.setDeptId(String.valueOf(0))),
|
|
|
- StudentAttendanceTemplateVO.class
|
|
|
- );
|
|
|
- List<StudentAttendanceTemplateVO> excusedList = BeanUtils.toBean(
|
|
|
- studentAttendanceService.getStudentAttendanceExcusedListForTeacher(pageReqVO.setDeptId(String.valueOf(0))),
|
|
|
- StudentAttendanceTemplateVO.class
|
|
|
+
|
|
|
+ pageReqVO.setDate(yesterday);
|
|
|
+ pageReqVO.setDeptId(teacher.getDeptId());
|
|
|
+
|
|
|
+ List<StudentAttendanceSupervisorTemplateVO> normalList = BeanUtils.toBean(
|
|
|
+ studentAttendanceService.getStudentAttendanceListForTeacher(pageReqVO),
|
|
|
+ StudentAttendanceSupervisorTemplateVO.class
|
|
|
);
|
|
|
- // 输出 Excel
|
|
|
- ByteArrayOutputStream normalOutputStream = new ByteArrayOutputStream();
|
|
|
- ByteArrayOutputStream errorOutputStream = new ByteArrayOutputStream();
|
|
|
- ByteArrayOutputStream excusedOutputStream = new ByteArrayOutputStream();
|
|
|
-
|
|
|
- EasyExcel.write(normalOutputStream, StudentAttendanceTemplateVO.class).sheet("正常打卡信息").doWrite(normalList);
|
|
|
- normalOutputStream.close();
|
|
|
- EasyExcel.write(errorOutputStream, StudentAttendanceTemplateVO.class).sheet("未打卡信息").doWrite(errorList);
|
|
|
- errorOutputStream.close();
|
|
|
- EasyExcel.write(excusedOutputStream, StudentAttendanceTemplateVO.class).sheet("请假信息").doWrite(excusedList);
|
|
|
- errorOutputStream.close();
|
|
|
-
|
|
|
- // 构造附件Map
|
|
|
+
|
|
|
+ List<StudentAttendanceSupervisorTemplateVO> errorList = studentAttendanceService.getStudentAttendanceErrorListForTeacher(pageReqVO)
|
|
|
+ .stream()
|
|
|
+ .map(studentAttendance -> {
|
|
|
+ StudentAttendanceSupervisorTemplateVO vo = BeanUtils.toBean(studentAttendance, StudentAttendanceSupervisorTemplateVO.class);
|
|
|
+ vo.setClockInTime("未打卡");
|
|
|
+ return vo;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<StudentAttendanceSupervisorTemplateVO> excusedList = studentAttendanceService.getStudentAttendanceExcusedListForTeacher(pageReqVO)
|
|
|
+ .stream()
|
|
|
+ .map(studentAttendance -> {
|
|
|
+ StudentAttendanceSupervisorTemplateVO vo = BeanUtils.toBean(studentAttendance, StudentAttendanceSupervisorTemplateVO.class);
|
|
|
+ vo.setClockInTime("请假");
|
|
|
+ return vo;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 创建 ByteArrayOutputStream 用来存储 Excel 文件数据
|
|
|
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
+
|
|
|
+ // 写入 Excel 文件
|
|
|
+ try (ExcelWriter excelWriter = EasyExcel.write(byteArrayOutputStream, StudentAttendanceSupervisorTemplateVO.class).build()) {
|
|
|
+
|
|
|
+ WriteSheet writeSheetNormal =EasyExcel.writerSheet("正常打卡信息").build();
|
|
|
+ WriteSheet writeSheetError =EasyExcel.writerSheet("未打卡信息").build();
|
|
|
+ WriteSheet writeSheetExcused =EasyExcel.writerSheet("请假信息").build();
|
|
|
+
|
|
|
+ excelWriter.write(normalList, writeSheetNormal);
|
|
|
+ excelWriter.write(errorList, writeSheetError);
|
|
|
+ excelWriter.write(excusedList, writeSheetExcused);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建附件 Map
|
|
|
Map<String, InputStream> attachments = new HashMap<>();
|
|
|
- attachments.put("正常考勤信息.xlsx", new ByteArrayInputStream(normalOutputStream.toByteArray()));
|
|
|
- attachments.put("未打卡信息.xlsx", new ByteArrayInputStream(normalOutputStream.toByteArray()));
|
|
|
- attachments.put("请假.xlsx", new ByteArrayInputStream(normalOutputStream.toByteArray()));
|
|
|
|
|
|
- // 发送邮件,包含附件
|
|
|
+ attachments.put(yesterday+"_"+teacher.getDeptName()+"考勤信息.xlsx", new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
|
|
|
+
|
|
|
+ // 发送邮件
|
|
|
if (teacher.getEmail() != null) {
|
|
|
- mailSendService.sendSingleMailToMemberWithAttachments(teacher.getEmail(), null, "attendance-list-excel", templateParams, attachments);
|
|
|
+ mailSendService.sendSingleMailToMemberWithAttachments(email, null, "attendance-list-excel", templateParams, attachments);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @PostMapping("/CeshiSendExcel")
|
|
|
- @Operation(summary = "测试发送Excel")
|
|
|
- public void CeshiSendExcelMail() throws IOException {
|
|
|
- // 创建结果对象并设置属性
|
|
|
+ @PostMapping("/ceshiExcelToCollege")
|
|
|
+ @Operation(summary = "测试发送Excel给学院")
|
|
|
+ public void ceshiExcelToCollege(@RequestParam("email") String email) throws IOException {
|
|
|
UserPageReqVO reqVO = new UserPageReqVO();
|
|
|
- reqVO.setUserType("3"); // 找导师
|
|
|
- List<AdminUserDO> TeacherList = adminUserService.getUserList(reqVO);
|
|
|
- StudentAttendancePageReqVO pageReqVO = new StudentAttendancePageReqVO();
|
|
|
- Map<String, Object> templateParams = new HashMap<>(); // 模板参数设置
|
|
|
+ Set<Long> collegeIdList = permissionService.getUserListByRoleId(114L);
|
|
|
|
|
|
- LocalDate today = LocalDate.now();
|
|
|
- if (TeacherList != null && !TeacherList.isEmpty()) {
|
|
|
- for (AdminUserDO teacher : TeacherList) {
|
|
|
- pageReqVO.setDate(today);
|
|
|
- List<StudentAttendanceTemplateVO> normalList = BeanUtils.toBean(
|
|
|
- studentAttendanceService.getStudentAttendanceListForTeacher(pageReqVO.setDeptId(String.valueOf(teacher.getDeptId()))),
|
|
|
- StudentAttendanceTemplateVO.class
|
|
|
- );
|
|
|
- List<StudentAttendanceTemplateVO> errorList = BeanUtils.toBean(
|
|
|
- studentAttendanceService.getStudentAttendanceErrorListForTeacher(pageReqVO.setDeptId(String.valueOf(teacher.getDeptId()))),
|
|
|
- StudentAttendanceTemplateVO.class
|
|
|
- );
|
|
|
- List<StudentAttendanceTemplateVO> excusedList = BeanUtils.toBean(
|
|
|
- studentAttendanceService.getStudentAttendanceExcusedListForTeacher(pageReqVO.setDeptId(String.valueOf(teacher.getDeptId()))),
|
|
|
- StudentAttendanceTemplateVO.class
|
|
|
+ Set<AdminUserDO> collegeList = new HashSet<>();
|
|
|
+ List<AdminUserDO> collegeList1 = adminUserService.getUserList(collegeIdList);
|
|
|
+ reqVO.setUserType("4");
|
|
|
+ List<AdminUserDO> collegeList2 = adminUserService.getUserList(reqVO);
|
|
|
+
|
|
|
+ collegeList.addAll(collegeList1);
|
|
|
+ collegeList.addAll(collegeList2);
|
|
|
+ //找学院
|
|
|
+ StudentAttendancePageReqVO attendanceReqVO =new StudentAttendancePageReqVO();
|
|
|
+
|
|
|
+ Map<String, Object> templateParams =new HashMap<>();//模板参数设置
|
|
|
+
|
|
|
+ // 获取前一天
|
|
|
+ LocalDate yesterday = LocalDate.now().minusDays(1);
|
|
|
+ if ( !collegeList.isEmpty()) {
|
|
|
+ for (AdminUserDO college : collegeList) {
|
|
|
+
|
|
|
+ attendanceReqVO.setDate(yesterday);
|
|
|
+ List<StudentAttendanceCollegeTemplateVO> normalList = BeanUtils.toBean(
|
|
|
+ studentAttendanceService.getStudentAttendanceListForTeacher(attendanceReqVO),
|
|
|
+ StudentAttendanceCollegeTemplateVO.class
|
|
|
);
|
|
|
- // 输出单个Excel文件,包含多个Sheet
|
|
|
- try (ExcelWriter excelWriter = EasyExcel.write("attendance.xlsx", StudentAttendanceTemplateVO.class).build()) {
|
|
|
+ List<StudentAttendanceCollegeTemplateVO> errorList = studentAttendanceService.getStudentAttendanceErrorListForTeacher(attendanceReqVO)
|
|
|
+ .stream()
|
|
|
+ .map(studentAttendance -> {
|
|
|
+ StudentAttendanceCollegeTemplateVO vo = BeanUtils.toBean(studentAttendance, StudentAttendanceCollegeTemplateVO.class);
|
|
|
+ vo.setClockInTime("未打卡");
|
|
|
+ return vo;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<StudentAttendanceCollegeTemplateVO> excusedList = studentAttendanceService.getStudentAttendanceExcusedListForTeacher(attendanceReqVO)
|
|
|
+ .stream()
|
|
|
+ .map(studentAttendance -> {
|
|
|
+ StudentAttendanceCollegeTemplateVO vo = BeanUtils.toBean(studentAttendance, StudentAttendanceCollegeTemplateVO.class);
|
|
|
+ vo.setClockInTime("请假");
|
|
|
+ return vo;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 输出 Excel
|
|
|
+ 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();
|
|
|
|
|
|
+ // 将各个 List 数据写入不同的 Sheet 中
|
|
|
excelWriter.write(normalList, writeSheetNormal);
|
|
|
excelWriter.write(errorList, writeSheetError);
|
|
|
excelWriter.write(excusedList, writeSheetExcused);
|
|
|
}
|
|
|
|
|
|
- // 构造附件Map
|
|
|
Map<String, InputStream> attachments = new HashMap<>();
|
|
|
- try (FileInputStream fileInputStream = new FileInputStream("attendance.xlsx")) {
|
|
|
- attachments.put("考勤信息.xlsx", fileInputStream);
|
|
|
- }
|
|
|
+ // 使用 ByteArrayInputStream 来创建附件
|
|
|
+ attachments.put(yesterday+"_"+"考勤信息.xlsx", new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
|
|
|
|
|
|
// 发送邮件,包含附件
|
|
|
- if (teacher.getEmail() != null) {
|
|
|
- mailSendService.sendSingleMailToMemberWithAttachments(teacher.getEmail(), null, "attendance-list-excel", templateParams, attachments);
|
|
|
+ if (college.getEmail() != null) {
|
|
|
+ mailSendService.sendSingleMailToMemberWithAttachments(email, null, "attendance-list-excel", templateParams, attachments);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
}
|