using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Newtonsoft.Json; using System.Text; using System.ComponentModel.Design; using YD_WeChatApplet.Api.Dto.Teacher; using YD_WeChatApplet.Api.Services.Impl; using YD_WeChatApplet.Commons.Dto; using YD_WeChatApplet.Commons.Dto.ClassRoomRecord; using YD_WeChatApplet.Commons.Dto.HomeWork; using YD_WeChatApplet.Commons.Dto.Patriarch; using YD_WeChatApplet.Commons.Dto.Resource; using YD_WeChatApplet.Commons.Dto.Teacher; using YD_WeChatApplet.Services; namespace YD_WeChatApplet.Api.Controllers { /// /// 老师端 /// [ApiController] [ApiExplorerSettings(GroupName = "v1")] [Route("[controller]")] public class TeacherController : ControllerBase { private readonly ITeacherService _teacherService; private readonly IHttpClientFactory _httpClientFactory; private readonly IConfiguration _configuration; public TeacherController(ITeacherService teacherService, IHttpClientFactory httpClientFactory, IConfiguration configuration) { _teacherService = teacherService; _httpClientFactory = httpClientFactory; _configuration = configuration; } /// /// 老师个人信息 /// /// [HttpGet("TeacherProfile")] public async Task TeacherProfile() { var res = await _teacherService.TeacherProfile(); return res; } /// /// 修改个人信息 /// /// /// [HttpPost("ModifyTeacherProfile")] public async Task ModifyTeacherProfile([FromBody] TeacherProfileDto paramDto) { await _teacherService.ModifyTeacherProfile(paramDto); return Ok("修改成功"); } /// /// 修改密码 /// /// /// [HttpPost("ModifyTeacherPwd")] public async Task ModifyTeacherPwd([FromBody] ModifyTeacherPwdDto paramDto) { await _teacherService.ModifyTeacherPwd(paramDto); return Ok("修改成功"); } /// /// 项目列表 /// /// /// [HttpGet("CategoryList")] public async Task> CategoryList(int gradeId) { var res = await _teacherService.CategoryList(gradeId); return res; } /// /// 数据统计接口 /// /// /// [HttpGet("DataStatistics")] public async Task DataStatistics([FromQuery] DataStatisticsFilterDto dto) { var res = await _teacherService.DataStatistics(dto); return res; } /// /// 统计接口详情 /// /// /// [HttpGet("DataStatisticsDetails")] public async Task DataStatisticsDetails([FromQuery] DataStatisticsDetailsFilterDto dto) { var res = await _teacherService.DataStatisticsDetails(dto); return res; } /// /// 课堂记录 /// /// /// [HttpGet("ClassRoomRecord")] public async Task> ClassRoomRecord([FromQuery] ClassRoomRecordDto dto) { var res = await _teacherService.ClassRoomRecord(dto); return res; } /// /// 课堂详情 /// /// /// [HttpGet("ClassRoomReportDetails")] public async Task ClassRoomReportDetails(int classRoomId) { var res = await _teacherService.ClassRoomReportDetails(classRoomId); return res; } /// /// 学员课堂报告 /// /// /// [HttpGet("StudentClassRoomReport")] public async Task StudentClassRoomReport([FromQuery] StudentClassRoomReportRequestDto dto) { var res = await _teacherService.StudentClassRoomReport(dto); return res; } /// /// 班级报告 /// /// [HttpGet("ClassReport")] public async Task ClassReport(int classId) { var res = await _teacherService.ClassReport(classId); return res; } /// /// 生成并保存学生体质报告 /// [HttpPost("GeneratePostureReport")] public async Task GeneratePostureReport([FromBody] GeneratePostureReportDto dto) { if (dto?.Input == null || string.IsNullOrWhiteSpace(dto.StudentNo)) throw new Exception("学生和体质信息不能为空"); var studentNo = dto.StudentNo.Trim(); await _teacherService.VerifyPostureStudent(studentNo); dto.Input.StudentId = studentNo; var evaluateUrl = _configuration["PostureEvaluateUrl"] ?? "http://8.153.108.90:10001/api/evaluate"; using var client = _httpClientFactory.CreateClient(); client.Timeout = TimeSpan.FromSeconds(30); using var body = new StringContent(JsonConvert.SerializeObject(dto.Input), Encoding.UTF8, "application/json"); using var response = await client.PostAsync(evaluateUrl, body); if (!response.IsSuccessStatusCode) throw new Exception("体质评价服务暂不可用"); var responseText = await response.Content.ReadAsStringAsync(); var report = JsonConvert.DeserializeObject(responseText); if (report?.Success != true || report.Result == null) throw new Exception("体质评价服务未返回有效报告"); await _teacherService.AddPostureReport(new AddPostureReportDto { StudentNo = studentNo, ReportContent = report }); return report; } /// /// 新增学生体态报告 /// /// 学生学号及 fitcamp365 评价接口的完整成功响应 /// [HttpPost("AddPostureReport")] public async Task AddPostureReport([FromBody] AddPostureReportDto dto) { var reportId = await _teacherService.AddPostureReport(dto); return Ok(new { ReportId = reportId }); } /// /// 根据学生学号获取最新体态报告内容 /// /// 学生学号 /// 报告内容对象 [HttpGet("GetPostureReport")] public async Task GetPostureReport([FromQuery] string studentNo) { return await _teacherService.GetPostureReport(studentNo); } } }