|
@@ -4,18 +4,35 @@ 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.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.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;
|
|
|
import cn.iocoder.yudao.module.system.service.mail.MailTemplateService;
|
|
|
+import cn.iocoder.yudao.module.system.service.studentAttendance.StudentAttendanceService;
|
|
|
+import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.validation.Valid;
|
|
|
+import java.time.DayOfWeek;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.temporal.TemporalAdjusters;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
|
|
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
|
@@ -29,6 +46,68 @@ public class MailTemplateController {
|
|
|
private MailTemplateService mailTempleService;
|
|
|
@Resource
|
|
|
private MailSendService mailSendService;
|
|
|
+ @Resource
|
|
|
+ private AdminUserService adminUserService;
|
|
|
+ @Resource
|
|
|
+ private StudentAttendanceService studentAttendanceService;
|
|
|
+ @Resource
|
|
|
+ private DeptService deptService;
|
|
|
+
|
|
|
+ @Scheduled(cron = "0 30 22 * * ?") // 每天晚上 22:30
|
|
|
+ @Operation(summary = "定时发送邮件给导师")
|
|
|
+ public void sendMailToFamilyScheduled() {
|
|
|
+ // 创建结果对象并设置属性
|
|
|
+ UserPageReqVO reqVO = new UserPageReqVO();
|
|
|
+ reqVO.setUserType("2");
|
|
|
+ List<AdminUserDO> TeacherList = adminUserService.getUserPage(reqVO).getList();
|
|
|
+ StudentAttendancePageReqVO pageReqVO =new StudentAttendancePageReqVO();
|
|
|
+ Map<String, Object> templateParams =new HashMap<>();//模板参数设置
|
|
|
+ // 获取当前这天
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
+ for (AdminUserDO teacher : TeacherList) {
|
|
|
+ pageReqVO.setDate(today);
|
|
|
+ List<StudentAttendanceEmailVO> normalList = BeanUtils.toBean(
|
|
|
+ studentAttendanceService.getStudentAttendancePage(pageReqVO.setDeptId(String.valueOf(teacher.getDeptId()))).getList(),
|
|
|
+ StudentAttendanceEmailVO.class
|
|
|
+ );
|
|
|
+ List<StudentAttendanceEmailVO> errorList = BeanUtils.toBean(
|
|
|
+ studentAttendanceService.getStudentAttendanceErrorPage(pageReqVO.setDeptId(String.valueOf(teacher.getDeptId()))).getList(),
|
|
|
+ StudentAttendanceEmailVO.class
|
|
|
+ );
|
|
|
+
|
|
|
+ StringBuilder normalListBuilder = new StringBuilder();
|
|
|
+ for (StudentAttendanceEmailVO attendance : normalList) {
|
|
|
+ normalListBuilder.append("学生id: ").append(attendance.getId())
|
|
|
+ .append(", 学生姓名: ").append(attendance.getStudentName())
|
|
|
+ .append(", 学生学号: ").append(attendance.getUserNumber() != null ? attendance.getUserNumber() : "无")
|
|
|
+ .append(", 工作间名称: ").append(deptService.getDept(Long.valueOf(attendance.getDeptId())).getName()) // 这里需要映射为实际工作间名称
|
|
|
+ .append(", 日期: ").append(attendance.getDate())
|
|
|
+ .append(", 打卡时间: ").append(attendance.getClockInTime() != null ? attendance.getClockInTime() : "未打卡")
|
|
|
+ .append(", 创建时间: ").append(attendance.getCreateTime())
|
|
|
+ .append("<br/>");
|
|
|
+ }
|
|
|
+
|
|
|
+ StringBuilder errorListBuilder = new StringBuilder();
|
|
|
+ for (StudentAttendanceEmailVO attendance : errorList) {
|
|
|
+ errorListBuilder.append("学生id: ").append(attendance.getId())
|
|
|
+ .append(", 学生姓名: ").append(attendance.getStudentName())
|
|
|
+ .append(", 学生学号: ").append(attendance.getUserNumber() != null ? attendance.getUserNumber() : "无")
|
|
|
+ .append(", 工作间名称: ").append(deptService.getDept(Long.valueOf(attendance.getDeptId())).getName())
|
|
|
+ .append(", 日期: ").append(attendance.getDate())
|
|
|
+ .append(", 打卡时间: ").append(attendance.getClockInTime() != null ? attendance.getClockInTime() : "未打卡")
|
|
|
+ .append(", 创建时间: ").append(attendance.getCreateTime())
|
|
|
+ .append("<br/>");
|
|
|
+ }
|
|
|
+
|
|
|
+ templateParams.put("normalList", normalListBuilder.toString());
|
|
|
+ templateParams.put("errorList", errorListBuilder.toString());
|
|
|
+
|
|
|
+ mailSendService.sendSingleMailToMember(teacher.getEmail(), teacher.getId(),"attendance-list", templateParams);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
@PostMapping("/create")
|
|
|
@Operation(summary = "创建邮件模版")
|
|
@@ -86,4 +165,59 @@ public class MailTemplateController {
|
|
|
sendReqVO.getTemplateCode(), sendReqVO.getTemplateParams()));
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @PostMapping("/test")
|
|
|
+ @Operation(summary = "发送邮件给导师测试")
|
|
|
+ public void test() {
|
|
|
+ // 创建结果对象并设置属性
|
|
|
+ UserPageReqVO reqVO = new UserPageReqVO();
|
|
|
+ reqVO.setUserType("2");
|
|
|
+ List<AdminUserDO> TeacherList = adminUserService.getUserPage(reqVO).getList();//所有老师
|
|
|
+ StudentAttendancePageReqVO pageReqVO =new StudentAttendancePageReqVO();
|
|
|
+ // 获取当前这天
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
+ Map<String, Object> templateParams =new HashMap<>();//模板参数设置
|
|
|
+ for (AdminUserDO teacher : TeacherList) {
|
|
|
+ pageReqVO.setDate(today);
|
|
|
+ List<StudentAttendanceEmailVO> normalList = BeanUtils.toBean(
|
|
|
+ studentAttendanceService.getStudentAttendancePage(pageReqVO.setDeptId(String.valueOf(teacher.getDeptId()))).getList(),
|
|
|
+ StudentAttendanceEmailVO.class
|
|
|
+ );
|
|
|
+ List<StudentAttendanceEmailVO> errorList = BeanUtils.toBean(
|
|
|
+ studentAttendanceService.getStudentAttendanceErrorPage(pageReqVO.setDeptId(String.valueOf(teacher.getDeptId()))).getList(),
|
|
|
+ StudentAttendanceEmailVO.class
|
|
|
+ );
|
|
|
+
|
|
|
+ StringBuilder normalListBuilder = new StringBuilder();
|
|
|
+ for (StudentAttendanceEmailVO attendance : normalList) {
|
|
|
+ normalListBuilder.append("学生id: ").append(attendance.getId())
|
|
|
+ .append(", 学生姓名: ").append(attendance.getStudentName())
|
|
|
+ .append(", 学生学号: ").append(attendance.getUserNumber() != null ? attendance.getUserNumber() : "无")
|
|
|
+ .append(", 工作间名称: ").append(deptService.getDept(Long.valueOf(attendance.getDeptId())).getName())
|
|
|
+ .append(", 日期: ").append(attendance.getDate())
|
|
|
+ .append(", 打卡时间: ").append(attendance.getClockInTime() != null ? attendance.getClockInTime() : "未打卡")
|
|
|
+ .append(", 创建时间: ").append(attendance.getCreateTime())
|
|
|
+ .append("<br/>");
|
|
|
+ }
|
|
|
+
|
|
|
+ StringBuilder errorListBuilder = new StringBuilder();
|
|
|
+ for (StudentAttendanceEmailVO attendance : errorList) {
|
|
|
+ errorListBuilder.append("学生id: ").append(attendance.getId())
|
|
|
+ .append(", 学生姓名: ").append(attendance.getStudentName())
|
|
|
+ .append(", 学生学号: ").append(attendance.getUserNumber() != null ? attendance.getUserNumber() : "无")
|
|
|
+ .append(", 工作间名称: ").append(deptService.getDept(Long.valueOf(attendance.getDeptId())).getName())
|
|
|
+ .append(", 日期: ").append(attendance.getDate())
|
|
|
+ .append(", 打卡时间: ").append(attendance.getClockInTime() != null ? attendance.getClockInTime() : "未打卡")
|
|
|
+ .append(", 创建时间: ").append(attendance.getCreateTime())
|
|
|
+ .append("<br/>");
|
|
|
+ }
|
|
|
+
|
|
|
+ templateParams.put("normalList", normalListBuilder.toString());
|
|
|
+ templateParams.put("errorList", errorListBuilder.toString());
|
|
|
+
|
|
|
+ mailSendService.sendSingleMailToMember("2653015384@qq.com", teacher.getId(), "attendance-list", templateParams);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|