From fb97f83e39a0995fb70326c492a0bcd37af5e300 Mon Sep 17 00:00:00 2001
From: liujie <1793218484@qq.com>
Date: 星期三, 12 十一月 2025 17:45:57 +0800
Subject: [PATCH] Merge branch 'master' of http://120.76.84.145:10101/gitblit/r/java/mobile_community

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/task/TaskUtil.java |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 48 insertions(+), 0 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/task/TaskUtil.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/task/TaskUtil.java
index 0cde4a5..be14b68 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/task/TaskUtil.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/task/TaskUtil.java
@@ -1,7 +1,21 @@
 package com.ruoyi.web.controller.task;
 
 
+import com.ruoyi.system.model.TOldster;
+import com.ruoyi.system.model.TOldsterWarning;
+import com.ruoyi.system.model.TOtherConfig;
+import com.ruoyi.system.service.TOldsterService;
+import com.ruoyi.system.service.TOldsterWarningService;
+import com.ruoyi.system.service.TOtherConfigService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
+
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * @author xiaochen
@@ -10,6 +24,40 @@
 @Component
 public class TaskUtil {
 
+    @Autowired
+    private TOldsterService oldsterService;
+    @Autowired
+    private TOldsterWarningService oldsterWarningService;
+    @Autowired
+    private TOtherConfigService otherConfigService;
 
+    /**
+     * 每日0点定时任务
+     */
+    @Scheduled(cron = "0 0 0 * * ?")
+    public void generateOldsterWarning(){
+
+        // 查询所有老人信息
+        List<TOldster> oldsterList = oldsterService.list();
+        // 查询预警阈值
+        TOtherConfig otherConfig = otherConfigService.getById(1);
+        Integer elderlyAge = otherConfig.getElderlyAge();
+        Integer days = otherConfig.getDays();
+        List<TOldsterWarning> oldsterWarningList = new ArrayList<>();
+        for (TOldster oldster : oldsterList) {
+            LocalDate birthDate = oldster.getBirthDate();
+            // 判断年龄是否与elderlyAge是否为同一年
+            if(birthDate.plusYears(elderlyAge).getYear() == LocalDate.now().getYear() && birthDate.plusYears(elderlyAge).minusDays(days).isEqual(LocalDate.now())){
+                // 添加预警信息
+                TOldsterWarning oldsterWarning = new TOldsterWarning();
+                oldsterWarning.setOldsterId(oldster.getId());
+                oldsterWarning.setWarningTime(LocalDateTime.now());
+                oldsterWarningList.add(oldsterWarning);
+            }
+        }
+        if(!CollectionUtils.isEmpty(oldsterWarningList)){
+            oldsterWarningService.saveBatch(oldsterWarningList);
+        }
+    }
 
 }

--
Gitblit v1.7.1