|
@@ -3,11 +3,13 @@ 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;
|
|
@@ -18,6 +20,9 @@ import cn.iocoder.yudao.module.system.service.mail.MailTemplateService;
|
|
|
import cn.iocoder.yudao.module.system.service.permission.PermissionService;
|
|
|
import cn.iocoder.yudao.module.system.service.studentAttendance.StudentAttendanceService;
|
|
|
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.excel.ExcelWriter;
|
|
|
+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;
|
|
@@ -27,6 +32,7 @@ import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.validation.Valid;
|
|
|
+import java.io.*;
|
|
|
import java.time.DayOfWeek;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.temporal.TemporalAdjusters;
|
|
@@ -53,7 +59,7 @@ public class MailTemplateController {
|
|
|
@Resource
|
|
|
private PermissionService permissionService;
|
|
|
|
|
|
- @Scheduled(cron = "0 30 22 * * ?") // 每天晚上 22:30
|
|
|
+ @Scheduled(cron = "0 30 8 * * ?") // 每天晚上 22:30
|
|
|
@Operation(summary = "定时发送邮件给导师")
|
|
|
public void sendMailToTeacherScheduled() {
|
|
|
// 创建结果对象并设置属性
|
|
@@ -62,11 +68,16 @@ public class MailTemplateController {
|
|
|
List<AdminUserDO> TeacherList = adminUserService.getUserList(reqVO);
|
|
|
StudentAttendancePageReqVO pageReqVO =new StudentAttendancePageReqVO();
|
|
|
Map<String, Object> templateParams =new HashMap<>();//模板参数设置
|
|
|
- // 获取当前这天
|
|
|
- LocalDate today = LocalDate.now();
|
|
|
+ // 获取前一天
|
|
|
+ LocalDate yesterday = LocalDate.now().minusDays(1);
|
|
|
+ // 检查昨天是否是周日
|
|
|
+ if (yesterday.getDayOfWeek() == DayOfWeek.MONDAY) {
|
|
|
+ return; // 直接返回,不推送周日的
|
|
|
+ }
|
|
|
+
|
|
|
if ( TeacherList!=null&& !TeacherList.isEmpty()) {
|
|
|
for (AdminUserDO teacher : TeacherList) {
|
|
|
- pageReqVO.setDate(today);
|
|
|
+ pageReqVO.setDate(yesterday);
|
|
|
List<StudentAttendanceEmailVO> normalList = BeanUtils.toBean(
|
|
|
studentAttendanceService.getStudentAttendanceListForTeacher(pageReqVO.setDeptId(String.valueOf(teacher.getDeptId()))),
|
|
|
StudentAttendanceEmailVO.class
|
|
@@ -118,16 +129,14 @@ public class MailTemplateController {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- @Scheduled(cron = "0 30 22 * * ?") // 每天晚上 22:30
|
|
|
+ @Scheduled(cron = "0 30 8 * * ?") // 每天晚上 22:30
|
|
|
@Operation(summary = "定时发送邮件给学院")
|
|
|
public void sendMailToCollegeScheduled() {
|
|
|
testCollege();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
@PostMapping("/create")
|
|
|
@Operation(summary = "创建邮件模版")
|
|
|
@PreAuthorize("@ss.hasPermission('system:mail-template:create')")
|
|
@@ -195,11 +204,17 @@ public class MailTemplateController {
|
|
|
List<AdminUserDO> TeacherList = adminUserService.getUserList(reqVO);
|
|
|
StudentAttendancePageReqVO pageReqVO =new StudentAttendancePageReqVO();
|
|
|
Map<String, Object> templateParams =new HashMap<>();//模板参数设置
|
|
|
- // 获取当前这天
|
|
|
- LocalDate today = LocalDate.now();
|
|
|
+
|
|
|
+ // 获取前一天
|
|
|
+ LocalDate yesterday = LocalDate.now().minusDays(1);
|
|
|
+ // 检查昨天是否是周日
|
|
|
+// if (yesterday.getDayOfWeek() == DayOfWeek.SUNDAY) {
|
|
|
+// return; // 直接返回,不推送周日的
|
|
|
+// }
|
|
|
+
|
|
|
if ( TeacherList!=null&& !TeacherList.isEmpty()) {
|
|
|
for (AdminUserDO teacher : TeacherList) {
|
|
|
- pageReqVO.setDate(today);
|
|
|
+ pageReqVO.setDate(yesterday);
|
|
|
List<StudentAttendanceEmailVO> normalList = BeanUtils.toBean(
|
|
|
studentAttendanceService.getStudentAttendanceListForTeacher(pageReqVO.setDeptId(String.valueOf(teacher.getDeptId()))),
|
|
|
StudentAttendanceEmailVO.class
|
|
@@ -274,11 +289,16 @@ public class MailTemplateController {
|
|
|
|
|
|
Map<String, Object> templateParams =new HashMap<>();//模板参数设置
|
|
|
|
|
|
- // 获取当前这天
|
|
|
- LocalDate today = LocalDate.now();
|
|
|
- if ( collegeList!=null && !collegeList.isEmpty()) {
|
|
|
+ // 获取前一天
|
|
|
+ LocalDate yesterday = LocalDate.now().minusDays(1);
|
|
|
+// // 检查昨天是否是周日
|
|
|
+// if (yesterday.getDayOfWeek() == DayOfWeek.SUNDAY) {
|
|
|
+// return; // 直接返回,不推送周日的
|
|
|
+// }
|
|
|
+
|
|
|
+ if ( !collegeList.isEmpty()) {
|
|
|
for (AdminUserDO college : collegeList) {
|
|
|
- attendanceReqVO.setDate(today);
|
|
|
+ attendanceReqVO.setDate(yesterday);
|
|
|
List<StudentAttendanceEmailVO> normalList = BeanUtils.toBean(
|
|
|
studentAttendanceService.getStudentAttendanceListForTeacher(attendanceReqVO),
|
|
|
StudentAttendanceEmailVO.class
|
|
@@ -336,7 +356,111 @@ 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);
|
|
|
+ StudentAttendancePageReqVO pageReqVO = new StudentAttendancePageReqVO();
|
|
|
+ Map<String, Object> templateParams = new HashMap<>(); // 模板参数设置
|
|
|
+
|
|
|
+ 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(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
|
|
|
+ );
|
|
|
+ // 输出 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
|
|
|
+ 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()));
|
|
|
+
|
|
|
+ // 发送邮件,包含附件
|
|
|
+ if (teacher.getEmail() != null) {
|
|
|
+ mailSendService.sendSingleMailToMemberWithAttachments(teacher.getEmail(), null, "attendance-list-excel", templateParams, attachments);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/CeshiSendExcel")
|
|
|
+ @Operation(summary = "测试发送Excel")
|
|
|
+ public void CeshiSendExcelMail() 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<>(); // 模板参数设置
|
|
|
+
|
|
|
+ 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
|
|
|
+ );
|
|
|
+ // 输出单个Excel文件,包含多个Sheet
|
|
|
+ try (ExcelWriter excelWriter = EasyExcel.write("attendance.xlsx", StudentAttendanceTemplateVO.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<>();
|
|
|
+ try (FileInputStream fileInputStream = new FileInputStream("attendance.xlsx")) {
|
|
|
+ attachments.put("考勤信息.xlsx", fileInputStream);
|
|
|
+ }
|
|
|
|
|
|
+ // 发送邮件,包含附件
|
|
|
+ if (teacher.getEmail() != null) {
|
|
|
+ mailSendService.sendSingleMailToMemberWithAttachments(teacher.getEmail(), null, "attendance-list-excel", templateParams, attachments);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
}
|