package com.zxyj.controller.guide; import com.zxyj.common.Result; import com.zxyj.entity.AssessmentMaterial; import com.zxyj.entity.FamilyAssessmentConfig; import com.zxyj.service.AssessmentService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @Tag(name = "成长规划师测评", description = "成长规划师管理家庭DAN测评") @RestController @RequestMapping("/api/guide/assessment") public class GuideAssessmentController { @Resource private AssessmentService assessmentService; @Operation(summary = "获取可用测评资料") @PostMapping("/materials") public Result> getMaterials() { List list = assessmentService.getMaterialList(); return Result.success(list); } @Operation(summary = "为家庭启用测评") @PostMapping("/family/enable") public Result enableFamilyAssessment( @RequestAttribute("userId") Long teacherId, @RequestBody Map body) { Long familyId = Long.valueOf(body.get("familyId").toString()); Long materialId = body.get("materialId") != null ? Long.valueOf(body.get("materialId").toString()) : null; Integer remindMonths = body.get("remindMonths") != null ? Integer.valueOf(body.get("remindMonths").toString()) : 12; if (familyId == null) { return Result.error("家庭ID不能为空"); } AssessmentMaterial material = assessmentService.getActiveMaterial(); if (material != null && materialId == null) { materialId = material.getId(); } boolean success = assessmentService.enableFamilyAssessment(familyId, materialId, remindMonths, teacherId); return Result.success(success); } @Operation(summary = "关闭家庭测评") @DeleteMapping("/family/{familyId}") public Result disableFamilyAssessment(@PathVariable Long familyId) { boolean success = assessmentService.disableFamilyAssessment(familyId); return Result.success(success); } @Operation(summary = "获取所有家庭测评配置") @PostMapping("/families") public Result>> getFamilyConfigs() { List configs = assessmentService.getFamiliesByTeacher(null); List> result = configs.stream().map(config -> { Map map = new HashMap<>(); map.put("id", config.getId()); map.put("familyId", config.getFamilyId()); map.put("materialId", config.getMaterialId()); map.put("remindMonths", config.getRemindMonths()); map.put("lastRemindAt", config.getLastRemindAt()); map.put("nextRemindAt", config.getNextRemindAt()); map.put("isEnabled", config.getIsEnabled()); if (config.getMaterialId() != null) { AssessmentMaterial material = assessmentService.getById(config.getMaterialId()); if (material != null) { map.put("materialTitle", material.getTitle()); map.put("materialContent", material.getContent()); } } return map; }).collect(Collectors.toList()); return Result.success(result); } @Operation(summary = "获取家庭测评配置") @PostMapping("/family/{familyId}") public Result> getFamilyConfig(@PathVariable Long familyId) { FamilyAssessmentConfig config = assessmentService.getFamilyConfig(familyId); if (config == null) { return Result.success(null); } Map result = new HashMap<>(); result.put("id", config.getId()); result.put("familyId", config.getFamilyId()); result.put("materialId", config.getMaterialId()); result.put("remindMonths", config.getRemindMonths()); result.put("lastRemindAt", config.getLastRemindAt()); result.put("nextRemindAt", config.getNextRemindAt()); result.put("isEnabled", config.getIsEnabled()); if (config.getMaterialId() != null) { AssessmentMaterial material = assessmentService.getById(config.getMaterialId()); if (material != null) { result.put("materialTitle", material.getTitle()); result.put("materialContent", material.getContent()); } } return Result.success(result); } }