using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Threading.Tasks; using VOL.Business.IServices; using VOL.Business.IServices.School; using VOL.Business.Services.School; using VOL.Core.Enums; using VOL.Core.Extensions; using VOL.Core.Filters; using VOL.Core.ManageUser; using VOL.Core.Services; using VOL.Core.Utilities; using VOL.Model; using VOL.Model.School.Request; using VOL.Model.School.Response; namespace VOL.WebApi.Controllers.Business { /// /// 学生管理 /// [Route("api/[controller]")] [ApiController] [ApiExplorerSettings(GroupName = "v3")] [TypeFilter(typeof(CustomApiResponseFilter))] public class StudentController : ControllerBase { #region 初始化 private readonly IS_StudentService _studentService; private readonly IFaceDetectService _faceDetectService; public StudentController( IS_StudentService studentService, IFaceDetectService faceDetectService) { _studentService = studentService; _faceDetectService = faceDetectService; } #endregion /// /// 分页获学生列表 /// /// [HttpGet(nameof(GetStudentPageList))] public async Task> GetStudentPageList(StudentPageListParam paramDto) { return await _studentService.GetStudentPageList(paramDto); } /// /// 获取全部学生 /// /// /// [HttpGet(nameof(GetStudentList))] public async Task> GetStudentList(StudentExportParam paramDto) { return await _studentService.GetStudentListBySportsHall(paramDto); } /// /// 新增 /// /// /// [HttpPost(nameof(AddStudent))] public async Task AddStudent([FromBody] AddStudentParam paramDto) { await _studentService.AddStudent(paramDto); return Ok("新增成功"); } /// /// 更新 /// /// /// [HttpPost(nameof(ModifyStudent))] public async Task ModifyStudent([FromBody] AddStudentParam paramDto) { await _studentService.ModifyStudent(paramDto); return Ok("更新成功"); } /// /// 更新学生状态 /// /// /// [HttpPost(nameof(UpdateStudentStatus))] public async Task UpdateStudentStatus([FromBody] UpdateStudentStatusParam paramDto) { await _studentService.UpdateStudentStatus(paramDto); return Ok("更新成功"); } /// /// 更新学生小程序密码 /// /// /// [HttpPost(nameof(UpdateStudentPwd))] public async Task UpdateStudentPwd([FromBody] UpdateStudentPwdParam paramDto) { await _studentService.UpdateStudentPwd(paramDto); return Ok("更新成功"); } /// /// 转班 /// /// /// /// [HttpPost(nameof(ChangeClasses))] public async Task ChangeClasses(string studentNo, int classId) { await _studentService.ChangeClasses(studentNo, classId); return Ok("更新成功"); } /// /// 获取导入学生模板 /// /// [HttpPost(nameof(GetImportStudentsTemplate))] public ActionResult GetImportStudentsTemplate() { var disList = new Dictionary> { { "导入学生模板", new List() } }; var exportColumns = Tool.GetPropertyNames(); var excelBytes = Tool.ExportToExcel(disList, exportColumns); Response.Headers.Add("Content-Disposition", "attachment; filename=ExportedData.xlsx"); Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; return File(excelBytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "导入学生模板"); } /// /// 导入学生 /// /// /// /// [HttpPost(nameof(ImportStudents))] public async Task ImportStudents(IFormFile file) { await _studentService.ImportStudents(file); return Ok("导入成功"); } /// /// 上传学生头像 /// /// /// 年级Id /// 班级Id /// 学生学号 /// [HttpPost(nameof(UploadPhoto))] public async Task UploadPhoto(IFormFile file, int gradeId, int classId, string studentNo, string studentName) { var url = await _studentService.UploadPhoto(file, gradeId, classId, studentNo, studentName); return url; } /// /// 批量上传学生头像 /// /// /// [HttpPost(nameof(BatchUploadPhoto))] public async Task BatchUploadPhoto(IFormFile zipFile) { await _studentService.BatchUploadPhoto(zipFile); return Ok("导入成功"); } /// /// 导出学生列表 /// /// /// [HttpGet(nameof(StudentExport))] public async Task StudentExport(StudentExportParam paramDto) { var rseList = await _studentService.GetStudentList(paramDto); var disList = new Dictionary> { { "学生数据", rseList } }; var exportColumns = Tool.GetPropertyNames(); var excelBytes = Tool.ExportToExcel(disList, exportColumns); Response.Headers.Add("Content-Disposition", "attachment; filename=ExportedData.xlsx"); Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; return File(excelBytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", $"学生数据{DateTime.Now.ToString("yyyyMMddHHmmss")}"); } /// /// 学生整体数据统计 /// /// /// [HttpGet(nameof(StudentWholeDataStats))] public async Task StudentWholeDataStats(StudentDataStatsParam paramDto) { return await _studentService.StudentWholeDataStats(paramDto); } /// /// 各项目平均成绩 /// /// /// [HttpGet(nameof(TestResultAvg))] public async Task> TestResultAvg(StudentCategoryParam paramDto) { return await _studentService.TestResultAvg(paramDto); } /// /// 个人成绩对比 /// /// /// [HttpGet(nameof(TestResultContrast))] public async Task> TestResultContrast(StudentCategoryParam paramDto) { return await _studentService.TestResultContrast(paramDto); } /// /// 成绩趋势 /// /// /// [HttpGet(nameof(ResultTrends))] public async Task ResultTrends(StudentResultTrendsParam paramDto) { return await _studentService.ResultTrends(paramDto); } /// /// 训练记录 /// /// /// [HttpGet(nameof(TrainingRecords))] public async Task> TrainingRecords(StudentTrainingRecordsParam paramDto) { return await _studentService.TrainingRecords(paramDto); } /// /// 体测数据 /// /// /// [HttpGet(nameof(TestRecords))] public async Task> TestRecords(StudentTrainingRecordsParam paramDto) { return await _studentService.TestRecords(paramDto); } /// /// 获取学生名单 /// /// [HttpGet(nameof(GetStudentNamePageList))] public async Task> GetStudentNamePageList(StudentNamePageListParam paramDto) { return await _studentService.GetStudentNamePageList(paramDto); } /// /// 更换班级 /// /// [HttpPost(nameof(ReplaceClasses))] public async Task ReplaceClasses(List studentNoList, int classId) { await _studentService.ReplaceClasses(studentNoList, classId); return Ok("修改成功"); } } }