|
@@ -22,6 +22,8 @@ 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.apache.poi.xwpf.usermodel.*;
|
|
|
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblWidth;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
@@ -29,6 +31,7 @@ import org.springframework.web.bind.annotation.*;
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.validation.Valid;
|
|
|
import java.io.*;
|
|
|
+import java.math.BigInteger;
|
|
|
import java.time.DayOfWeek;
|
|
|
import java.time.LocalDate;
|
|
|
import java.util.*;
|
|
@@ -36,6 +39,7 @@ 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;
|
|
|
+import static org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalJc.CENTER;
|
|
|
|
|
|
@Tag(name = "管理后台 - 邮件模版")
|
|
|
@RestController
|
|
@@ -442,7 +446,7 @@ public class MailTemplateController {
|
|
|
public void ceshiSendExcelMail(@RequestParam("email") String email) throws IOException {
|
|
|
|
|
|
// 获取导师
|
|
|
- Set<Long> collegeIdList = permissionService.getUserListByRoleId(114L);
|
|
|
+ Set<Long> collegeIdList = permissionService.getUserListByRoleId(113L);
|
|
|
List<AdminUserDO> TeacherList = adminUserService.getUserList(collegeIdList);
|
|
|
|
|
|
StudentAttendancePageReqVO pageReqVO = new StudentAttendancePageReqVO();
|
|
@@ -450,17 +454,19 @@ public class MailTemplateController {
|
|
|
|
|
|
LocalDate yesterday = LocalDate.now().minusDays(1);
|
|
|
if (TeacherList != null && !TeacherList.isEmpty()) {
|
|
|
- for (AdminUserDO teacher : TeacherList) {
|
|
|
+// for (AdminUserDO teacher : TeacherList) {
|
|
|
|
|
|
pageReqVO.setDate(yesterday);
|
|
|
- pageReqVO.setDeptId(teacher.getDeptId());
|
|
|
+// if (!(teacher.getDeptId() == null || teacher.getDeptId() == 0)) {
|
|
|
+// pageReqVO.setDeptId(teacher.getDeptId());
|
|
|
+// }
|
|
|
|
|
|
- List<StudentAttendanceSupervisorTemplateVO> normalList = BeanUtils.toBean(
|
|
|
- studentAttendanceService.getStudentAttendanceListForTeacher(pageReqVO),
|
|
|
- StudentAttendanceSupervisorTemplateVO.class
|
|
|
- );
|
|
|
+// List<StudentAttendanceSupervisorTemplateVO> normalList = BeanUtils.toBean(
|
|
|
+// studentAttendanceService.getStudentAttendanceListForTeacher(pageReqVO),
|
|
|
+// StudentAttendanceSupervisorTemplateVO.class
|
|
|
+// );
|
|
|
|
|
|
- List<StudentAttendanceSupervisorTemplateVO> errorList = studentAttendanceService.getStudentAttendanceErrorListForTeacher(pageReqVO)
|
|
|
+ List<StudentAttendanceSupervisorTemplateVO> errorList = studentAttendanceService.getStudentAttendanceErrorListForTeacher(pageReqVO.setSupervisorId(590L))
|
|
|
.stream()
|
|
|
.map(studentAttendance -> {
|
|
|
StudentAttendanceSupervisorTemplateVO vo = BeanUtils.toBean(studentAttendance, StudentAttendanceSupervisorTemplateVO.class);
|
|
@@ -478,32 +484,122 @@ public class MailTemplateController {
|
|
|
// })
|
|
|
// .collect(Collectors.toList());
|
|
|
|
|
|
- // 创建 ByteArrayOutputStream 用来存储 Excel 文件数据
|
|
|
+ // 创建 ByteArrayOutputStream 用来存储 Word 文件数据
|
|
|
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();
|
|
|
+// 创建 Word 文档
|
|
|
+ XWPFDocument document = new XWPFDocument();
|
|
|
+
|
|
|
+ XWPFParagraph title = document.createParagraph();
|
|
|
+ XWPFRun titleRun = title.createRun();
|
|
|
+ titleRun.setText("测绘地理信息学院研究生考勤情况日报告");
|
|
|
+ titleRun.setBold(true);
|
|
|
+ titleRun.setFontSize(16);
|
|
|
+ title.setAlignment(ParagraphAlignment.CENTER); // 设置标题居中
|
|
|
+ title.setSpacingAfter(100);
|
|
|
+
|
|
|
+
|
|
|
+ XWPFParagraph teacherInfo = document.createParagraph();
|
|
|
+ XWPFRun teacherInfoRun = teacherInfo.createRun();
|
|
|
+// teacherInfoRun.setText("尊敬的" + teacher.getNickname() + "导师(家长):");
|
|
|
+ teacherInfoRun.setText("尊敬的" + "何宏昌" + "导师(家长):");
|
|
|
+ teacherInfoRun.setFontSize(14);
|
|
|
+ teacherInfoRun.setBold(true);
|
|
|
+ teacherInfo.setAlignment(ParagraphAlignment.LEFT);
|
|
|
+ teacherInfoRun.setUnderline(UnderlinePatterns.SINGLE);
|
|
|
+ teacherInfo.setSpacingAfter(100);
|
|
|
+
|
|
|
+ XWPFParagraph dateInfo = document.createParagraph();
|
|
|
+ XWPFRun dateInfoRun = dateInfo.createRun();
|
|
|
+ dateInfoRun.setText(" 您所指导的研究生 " + yesterday.getYear() + " 年 " + yesterday.getMonthValue() + " 月 " + yesterday.getDayOfMonth() + " 日 考勤情况如下:");
|
|
|
+ dateInfoRun.setFontSize(14);
|
|
|
+ dateInfoRun.setBold(true);
|
|
|
+ dateInfo.setAlignment(ParagraphAlignment.LEFT);
|
|
|
+ dateInfo.setSpacingAfter(60);
|
|
|
+
|
|
|
+ XWPFParagraph listTitle = document.createParagraph();
|
|
|
+ XWPFRun listTitleRun = listTitle.createRun();
|
|
|
+ listTitleRun.setText("未打卡同学清单");
|
|
|
+ listTitleRun.setBold(true);
|
|
|
+ listTitleRun.setFontSize(14);
|
|
|
+ listTitle.setAlignment(ParagraphAlignment.CENTER);
|
|
|
+ listTitle.setSpacingAfter(50);
|
|
|
+
|
|
|
+ XWPFTable tableError = document.createTable();
|
|
|
+ //设置表格样式
|
|
|
+// tableError.getCTTbl().getTblPr().set
|
|
|
+
|
|
|
+ tableError.setWidth(XWPFTable.DEFAULT_PERCENTAGE_WIDTH);
|
|
|
+
|
|
|
+ XWPFTableRow headerRowError = tableError.getRow(0);
|
|
|
+ headerRowError.getCell(0).setText("序号");
|
|
|
+ headerRowError.addNewTableCell().setText("学生姓名");
|
|
|
+ headerRowError.addNewTableCell().setText("学生学号");
|
|
|
+ headerRowError.addNewTableCell().setText("所在实验室房号");
|
|
|
+ headerRowError.addNewTableCell().setText("备注");
|
|
|
+
|
|
|
+ // 设置表头字体大小和加粗
|
|
|
+ for (XWPFTableCell cell : headerRowError.getTableCells()) {
|
|
|
+ XWPFRun run = cell.addParagraph().createRun();
|
|
|
+ run.setText(cell.getText());
|
|
|
+ run.setFontSize(14); // 设置字体大小为14
|
|
|
+ run.setBold(true); // 设置字体加粗
|
|
|
+ }
|
|
|
|
|
|
- excelWriter.write(normalList, writeSheetNormal);
|
|
|
- excelWriter.write(errorList, writeSheetError);
|
|
|
-// excelWriter.write(excusedList, writeSheetExcused);
|
|
|
+ int sequenceNumber = 1; // 序号初始化
|
|
|
+ for (StudentAttendanceSupervisorTemplateVO vo : errorList) {
|
|
|
+
|
|
|
+ XWPFTableRow row = tableError.createRow();
|
|
|
+ // 填充数据
|
|
|
+ row.getCell(0).setText(String.valueOf(sequenceNumber++));
|
|
|
+ row.getCell(1).setText(vo.getStudentName());
|
|
|
+ row.getCell(2).setText(vo.getUserNumber());
|
|
|
+ row.getCell(3).setText(vo.getDeptName());
|
|
|
+ row.getCell(4).setText(vo.getRemark()); //
|
|
|
+
|
|
|
+ // 设置内容字体大小
|
|
|
+ for (XWPFTableCell cell : row.getTableCells()) {
|
|
|
+ XWPFRun run = cell.addParagraph().createRun();
|
|
|
+ run.setText(cell.getText());
|
|
|
+ run.setFontSize(12); // 设置字体大小为12
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- // 创建附件 Map
|
|
|
- Map<String, InputStream> attachments = new HashMap<>();
|
|
|
+ XWPFParagraph notice = document.createParagraph();
|
|
|
+ XWPFRun noticeRun = notice.createRun();
|
|
|
+ noticeRun.setText("特此通知,请您及时检查学生在校情况。");
|
|
|
+ noticeRun.setFontSize(14);
|
|
|
+ noticeRun.setBold(true);
|
|
|
+ notice.setAlignment(ParagraphAlignment.LEFT);
|
|
|
+ notice.setSpacingBefore(100);
|
|
|
+
|
|
|
+ XWPFParagraph committee = document.createParagraph();
|
|
|
+ XWPFRun committeeRun = committee.createRun();
|
|
|
+ committeeRun.setText("测绘地理信息学院研究生管理委员会");
|
|
|
+ committeeRun.setFontSize(14);
|
|
|
+ committeeRun.setBold(true);
|
|
|
+ committee.setAlignment(ParagraphAlignment.RIGHT);
|
|
|
+ committee.setSpacingBefore(1000);
|
|
|
+
|
|
|
+ document.write(byteArrayOutputStream);
|
|
|
|
|
|
- attachments.put(yesterday+"_"+teacher.getDeptName()+"考勤信息.xlsx", new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
|
|
|
+ Map<String, InputStream> attachments = new HashMap<>();
|
|
|
+// String fileName = String.format("%s考勤信息.docx", (teacher.getDeptId()==null||teacher.getDeptId()==0?"":teacher.getDeptName())+yesterday);
|
|
|
+ String fileName = String.format("%s考勤信息.docx", yesterday);
|
|
|
+ attachments.put(fileName, new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
|
|
|
|
|
|
// 发送邮件
|
|
|
- if (teacher.getEmail() != null) {
|
|
|
+// if (teacher.getEmail() != null) {
|
|
|
mailSendService.sendSingleMailToMemberWithAttachments(email, null, "attendance-list-excel", templateParams, attachments);
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
+ // 每次推送后等待1s
|
|
|
+ try {
|
|
|
+ Thread.sleep(1000); // 1s
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+// }
|
|
|
+// }
|
|
|
}
|
|
|
|
|
|
@PostMapping("/ceshiExcelToCollege")
|
|
@@ -579,4 +675,5 @@ public class MailTemplateController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
}
|