Prechádzať zdrojové kódy

feat(mind): auto-create follow_up record when crisis alert is resolved

- Add FollowUpMapper and ChildMapper dependencies
- Auto-create FollowUp with 7-day due date and high priority on alert resolution
- Query familyId from Child table for follow_up association
Xiaogang Liao 2 mesiacov pred
rodič
commit
01c436cdd2

+ 34 - 0
cfc-backend/src/main/java/com/etotem/cfc/service/MentalHealthScreenService.java

@@ -4,9 +4,13 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.etotem.cfc.dto.EmotionAlertVO;
 import com.etotem.cfc.dto.ScreenResultVO;
 import com.etotem.cfc.dto.ScreenSubmitDTO;
+import com.etotem.cfc.entity.Child;
 import com.etotem.cfc.entity.EmotionAlert;
+import com.etotem.cfc.entity.FollowUp;
 import com.etotem.cfc.entity.MentalHealthScreen;
+import com.etotem.cfc.mapper.ChildMapper;
 import com.etotem.cfc.mapper.EmotionAlertMapper;
+import com.etotem.cfc.mapper.FollowUpMapper;
 import com.etotem.cfc.mapper.MentalHealthScreenMapper;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -28,6 +32,12 @@ public class MentalHealthScreenService {
     @Resource
     private EmotionAlertMapper emotionAlertMapper;
 
+    @Resource
+    private FollowUpMapper followUpMapper;
+
+    @Resource
+    private ChildMapper childMapper;
+
     @Resource
     private WechatAlertTemplateService wechatAlertTemplateService;
 
@@ -186,6 +196,30 @@ public class MentalHealthScreenService {
             alert.setResolved(true);
             alert.setResolvedAt(new Date());
             emotionAlertMapper.updateById(alert);
+
+            // Auto-create follow_up record
+            try {
+                FollowUp followUp = new FollowUp();
+                followUp.setChildId(alert.getChildId());
+                Child child = childMapper.selectById(alert.getChildId());
+                if (child != null && child.getFamilyId() != null) {
+                    followUp.setFamilyId(child.getFamilyId());
+                }
+                followUp.setDescription("情绪/心理危机告警已处理,待7天后复核");
+                followUp.setStatus("pending");
+                followUp.setPriority("high");
+
+                Calendar cal = Calendar.getInstance();
+                cal.add(Calendar.DAY_OF_YEAR, 7);
+                followUp.setDueDate(cal.getTime());
+
+                followUp.setCreatedAt(new Date());
+
+                followUpMapper.insert(followUp);
+                log.info("告警解决后自动生成follow_up: childId={}, alertId={}", alert.getChildId(), alertId);
+            } catch (Exception e) {
+                log.error("创建follow_up失败: {}", e.getMessage());
+            }
         }
     }