|
@@ -2,11 +2,18 @@ package com.etotem.cfc.controller.mind;
|
|
|
|
|
|
|
|
import com.etotem.cfc.common.Result;
|
|
import com.etotem.cfc.common.Result;
|
|
|
import com.etotem.cfc.dto.EmotionAlertVO;
|
|
import com.etotem.cfc.dto.EmotionAlertVO;
|
|
|
|
|
+import com.etotem.cfc.entity.Child;
|
|
|
|
|
+import com.etotem.cfc.entity.EmotionAlert;
|
|
|
|
|
+import com.etotem.cfc.entity.User;
|
|
|
|
|
+import com.etotem.cfc.mapper.ChildMapper;
|
|
|
|
|
+import com.etotem.cfc.mapper.EmotionAlertMapper;
|
|
|
|
|
+import com.etotem.cfc.mapper.UserMapper;
|
|
|
import com.etotem.cfc.service.EmotionAlertService;
|
|
import com.etotem.cfc.service.EmotionAlertService;
|
|
|
import com.etotem.cfc.service.MentalHealthScreenService;
|
|
import com.etotem.cfc.service.MentalHealthScreenService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RequestAttribute;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
@@ -25,12 +32,25 @@ public class EmotionAlertController {
|
|
|
@Resource
|
|
@Resource
|
|
|
private EmotionAlertService emotionAlertService;
|
|
private EmotionAlertService emotionAlertService;
|
|
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private EmotionAlertMapper emotionAlertMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private ChildMapper childMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private UserMapper userMapper;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 获取活跃告警列表
|
|
* 获取活跃告警列表
|
|
|
*/
|
|
*/
|
|
|
@PostMapping("/active")
|
|
@PostMapping("/active")
|
|
|
public Result<?> active(@RequestBody Map<String, Object> params) {
|
|
public Result<?> active(@RequestBody Map<String, Object> params) {
|
|
|
- Long childId = Long.valueOf(params.get("childId").toString());
|
|
|
|
|
|
|
+ Object childIdObj = params.get("childId");
|
|
|
|
|
+ if (childIdObj == null) {
|
|
|
|
|
+ return Result.error("参数缺失:childId");
|
|
|
|
|
+ }
|
|
|
|
|
+ Long childId = Long.valueOf(childIdObj.toString());
|
|
|
List<EmotionAlertVO> alerts = mentalHealthScreenService.getActiveAlerts(childId);
|
|
List<EmotionAlertVO> alerts = mentalHealthScreenService.getActiveAlerts(childId);
|
|
|
return Result.success(alerts);
|
|
return Result.success(alerts);
|
|
|
}
|
|
}
|
|
@@ -40,17 +60,55 @@ public class EmotionAlertController {
|
|
|
*/
|
|
*/
|
|
|
@PostMapping("/checkin-alerts")
|
|
@PostMapping("/checkin-alerts")
|
|
|
public Result<?> checkinAlerts(@RequestBody Map<String, Object> params) {
|
|
public Result<?> checkinAlerts(@RequestBody Map<String, Object> params) {
|
|
|
- Long childId = Long.valueOf(params.get("childId").toString());
|
|
|
|
|
|
|
+ Object childIdObj = params.get("childId");
|
|
|
|
|
+ if (childIdObj == null) {
|
|
|
|
|
+ return Result.error("参数缺失:childId");
|
|
|
|
|
+ }
|
|
|
|
|
+ Long childId = Long.valueOf(childIdObj.toString());
|
|
|
List<EmotionAlertVO> alerts = emotionAlertService.getActiveAlerts(childId);
|
|
List<EmotionAlertVO> alerts = emotionAlertService.getActiveAlerts(childId);
|
|
|
return Result.success(alerts);
|
|
return Result.success(alerts);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 管理员获取所有告警列表
|
|
|
|
|
+ */
|
|
|
|
|
+ @PostMapping("/admin/list")
|
|
|
|
|
+ public Result<?> adminList(@RequestBody Map<String, Object> params) {
|
|
|
|
|
+ Integer page = params.get("page") == null ? 1 : Integer.valueOf(params.get("page").toString());
|
|
|
|
|
+ Integer size = params.get("size") == null ? 20 : Integer.valueOf(params.get("size").toString());
|
|
|
|
|
+ Boolean resolved = params.containsKey("resolved") ? Boolean.valueOf(params.get("resolved").toString()) : null;
|
|
|
|
|
+ return Result.success(emotionAlertService.getAdminAlerts(page, size, resolved));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 标记告警已处理
|
|
* 标记告警已处理
|
|
|
*/
|
|
*/
|
|
|
@PostMapping("/resolve")
|
|
@PostMapping("/resolve")
|
|
|
- public Result<?> resolve(@RequestBody Map<String, Object> params) {
|
|
|
|
|
- Long alertId = Long.valueOf(params.get("alertId").toString());
|
|
|
|
|
|
|
+ public Result<?> resolve(@RequestAttribute("userId") Long userId,
|
|
|
|
|
+ @RequestBody Map<String, Object> params) {
|
|
|
|
|
+ Object alertIdObj = params.get("alertId");
|
|
|
|
|
+ if (alertIdObj == null) {
|
|
|
|
|
+ return Result.error("参数缺失:alertId");
|
|
|
|
|
+ }
|
|
|
|
|
+ Long alertId = Long.valueOf(alertIdObj.toString());
|
|
|
|
|
+
|
|
|
|
|
+ EmotionAlert alert = emotionAlertMapper.selectById(alertId);
|
|
|
|
|
+ if (alert == null) {
|
|
|
|
|
+ return Result.error("告警不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Child child = childMapper.selectById(alert.getChildId());
|
|
|
|
|
+ if (child == null) {
|
|
|
|
|
+ return Result.error("孩子不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ User user = userMapper.selectById(userId);
|
|
|
|
|
+ if (user == null || user.getFamilyId() == null) {
|
|
|
|
|
+ return Result.error("无权操作该告警");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!user.getFamilyId().equals(child.getFamilyId())) {
|
|
|
|
|
+ return Result.error("无权操作该告警");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
String source = params.containsKey("source") ? params.get("source").toString() : "screening";
|
|
String source = params.containsKey("source") ? params.get("source").toString() : "screening";
|
|
|
if ("checkin".equals(source)) {
|
|
if ("checkin".equals(source)) {
|
|
|
emotionAlertService.resolveAlert(alertId);
|
|
emotionAlertService.resolveAlert(alertId);
|