|
@@ -19,6 +19,7 @@ import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
@@ -28,7 +29,9 @@ import javax.validation.Valid;
|
|
|
import java.io.IOException;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.temporal.TemporalAdjusters;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
|
|
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
|
@@ -47,6 +50,44 @@ public class SmsTemplateController {
|
|
|
@Resource
|
|
|
private AdminUserService adminUserService;
|
|
|
|
|
|
+ @Scheduled(cron = "0 0 9 * * ?") // 每天9点执行
|
|
|
+ @Operation(summary = "定时给家长发送未打卡短信")
|
|
|
+ public void sendSmsToParentScheduled(){
|
|
|
+ sendSmsToParent();
|
|
|
+ }
|
|
|
+
|
|
|
+ //TODO发送短信
|
|
|
+ @PostMapping("/send-sms-toParent")
|
|
|
+ @Operation(summary = "给家长发送短信")
|
|
|
+ public void sendSmsToParent() {
|
|
|
+ UserPageReqVO reqVO =new UserPageReqVO();
|
|
|
+ reqVO.setUserType("1");//在校生
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
+ LocalDate startDate = today.minusDays(3);//前天
|
|
|
+ StudentAttendancePageReqVO attendanceReqVO =new StudentAttendancePageReqVO();
|
|
|
+ attendanceReqVO.setDateRange(startDate,today);
|
|
|
+
|
|
|
+ List<AdminUserDO> studentList =adminUserService.getUserList(reqVO);
|
|
|
+ for (AdminUserDO student :studentList) {
|
|
|
+ if (student.getUserNumber()!=null) {
|
|
|
+ attendanceReqVO.setUserNumber(student.getUserNumber());
|
|
|
+ List<StudentAttendanceDO> attendanceList = studentAttendanceService.getStudentAttendanceErrorList(attendanceReqVO);
|
|
|
+ Map<String, Object> templateParams = new HashMap<>();
|
|
|
+ templateParams.put("studentName", student.getNickname());
|
|
|
+ if (attendanceList.size() > 3) {
|
|
|
+ smsSendService.sendSingleSmsToAdmin(student.getParentMobile(), null, "student-attendance-warning", templateParams);
|
|
|
+ }
|
|
|
+ //每处理一个暂停0.2ss
|
|
|
+ try {
|
|
|
+ Thread.sleep(200); // 暂停0.2秒(200毫秒)
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
@PostMapping("/create")
|
|
|
@Operation(summary = "创建短信模板")
|
|
@@ -110,24 +151,30 @@ public class SmsTemplateController {
|
|
|
sendReqVO.getTemplateCode(), sendReqVO.getTemplateParams()));
|
|
|
}
|
|
|
|
|
|
- //TODO发送短信
|
|
|
- @PostMapping("/send-sms-toParent")
|
|
|
- @Operation(summary = "给家长发送短信")
|
|
|
- public void sendSmsV(@Valid @RequestBody SmsTemplateSendReqVO sendReqVO) {
|
|
|
+ @PostMapping("/test-parent")
|
|
|
+ @Operation(summary = "测试给家长发送短信")
|
|
|
+ public void test() {
|
|
|
UserPageReqVO reqVO =new UserPageReqVO();
|
|
|
reqVO.setUserType("1");//在校生
|
|
|
LocalDate today = LocalDate.now();
|
|
|
LocalDate startDate = today.minusDays(3);//前天
|
|
|
StudentAttendancePageReqVO attendanceReqVO =new StudentAttendancePageReqVO();
|
|
|
attendanceReqVO.setDateRange(startDate,today);
|
|
|
-
|
|
|
List<AdminUserDO> studentList =adminUserService.getUserList(reqVO);
|
|
|
- for (AdminUserDO student :studentList){
|
|
|
- attendanceReqVO.setUserNumber(student.getUserNumber());
|
|
|
- attendanceReqVO.setClockInStatus("1");//只招未打卡的
|
|
|
- List<StudentAttendanceDO> attendanceList= studentAttendanceService.getStudentAttendanceList(attendanceReqVO);
|
|
|
- if(attendanceList.size()>3){
|
|
|
- smsSendService.sendSingleSmsToAdmin(student.getParentMobile(), null, sendReqVO.getTemplateCode(), sendReqVO.getTemplateParams());
|
|
|
+ for (AdminUserDO student :studentList) {
|
|
|
+ if (student.getUserNumber()!=null) {
|
|
|
+ attendanceReqVO.setUserNumber(student.getUserNumber());
|
|
|
+ List<StudentAttendanceDO> attendanceList = studentAttendanceService.getStudentAttendanceErrorList(attendanceReqVO);
|
|
|
+ Map<String, Object> templateParams = new HashMap<>();
|
|
|
+ templateParams.put("studentName", student.getNickname());
|
|
|
+ if (attendanceList.size()>3) {
|
|
|
+ smsSendService.sendSingleSmsToAdmin("13697999947", null, "student-attendance-warning", templateParams);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ Thread.sleep(100); // 暂停1秒(1000毫秒)
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|