- 完善学生Excel导入的文件、行数据和重复学号校验,并返回实际导入数量 - 调整学生导出字段名称与排列顺序,移除学籍号字段 - 规范单张及ZIP批量人脸导入校验,限制格式、大小、数量和解压总量 - 批量人脸导入返回总数、成功数、失败数及详细失败原因 - 新增作业按作业、班级、完成状态等条件批量导出,每名学生一条记录
358 lines
12 KiB
C#
358 lines
12 KiB
C#
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
|
|
{
|
|
/// <summary>
|
|
/// 学生管理
|
|
/// </summary>
|
|
[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
|
|
|
|
/// <summary>
|
|
/// 分页获学生列表
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet(nameof(GetStudentPageList))]
|
|
public async Task<PageDataDto<StudentPageListModel>> GetStudentPageList(StudentPageListParam paramDto)
|
|
{
|
|
return await _studentService.GetStudentPageList(paramDto);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取全部学生
|
|
/// </summary>
|
|
/// <param name="paramDto"></param>
|
|
/// <returns></returns>
|
|
[HttpGet(nameof(GetStudentList))]
|
|
public async Task<List<StudentPageListModel>> GetStudentList(StudentExportParam paramDto)
|
|
{
|
|
return await _studentService.GetStudentListBySportsHall(paramDto);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 新增
|
|
/// </summary>
|
|
/// <param name="paramDto"></param>
|
|
/// <returns></returns>
|
|
|
|
[HttpPost(nameof(AddStudent))]
|
|
public async Task<ActionResult> AddStudent([FromBody] AddStudentParam paramDto)
|
|
{
|
|
await _studentService.AddStudent(paramDto);
|
|
return Ok("新增成功");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新
|
|
/// </summary>
|
|
/// <param name="paramDto"></param>
|
|
/// <returns></returns>
|
|
[HttpPost(nameof(ModifyStudent))]
|
|
public async Task<ActionResult> ModifyStudent([FromBody] AddStudentParam paramDto)
|
|
{
|
|
await _studentService.ModifyStudent(paramDto);
|
|
return Ok("更新成功");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新学生状态
|
|
/// </summary>
|
|
/// <param name="paramDto"></param>
|
|
/// <returns></returns>
|
|
[HttpPost(nameof(UpdateStudentStatus))]
|
|
public async Task<ActionResult> UpdateStudentStatus([FromBody] UpdateStudentStatusParam paramDto)
|
|
{
|
|
await _studentService.UpdateStudentStatus(paramDto);
|
|
return Ok("更新成功");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新学生小程序密码
|
|
/// </summary>
|
|
/// <param name="paramDto"></param>
|
|
/// <returns></returns>
|
|
[HttpPost(nameof(UpdateStudentPwd))]
|
|
public async Task<ActionResult> UpdateStudentPwd([FromBody] UpdateStudentPwdParam paramDto)
|
|
{
|
|
await _studentService.UpdateStudentPwd(paramDto);
|
|
|
|
return Ok("更新成功");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 批量删除当前学校学生
|
|
/// </summary>
|
|
/// <param name="ids">学生Id列表</param>
|
|
[HttpPost(nameof(BatchDeleteStudents))]
|
|
public async Task<ActionResult> BatchDeleteStudents([FromBody] List<int> ids)
|
|
{
|
|
var deletedCount = await _studentService.BatchDeleteStudents(ids);
|
|
return Ok($"成功删除{deletedCount}名学生");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 转班
|
|
/// </summary>
|
|
/// <param name="studentNo"></param>
|
|
/// <param name="classId"></param>
|
|
/// <returns></returns>
|
|
[HttpPost(nameof(ChangeClasses))]
|
|
public async Task<ActionResult> ChangeClasses(string studentNo, int classId)
|
|
{
|
|
await _studentService.ChangeClasses(studentNo, classId);
|
|
return Ok("更新成功");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取导入学生模板
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost(nameof(GetImportStudentsTemplate))]
|
|
public ActionResult GetImportStudentsTemplate()
|
|
{
|
|
var disList = new Dictionary<string, List<ImportStudentParam>>
|
|
{
|
|
{ "导入学生模板", new List<ImportStudentParam>() }
|
|
};
|
|
|
|
var exportColumns = Tool.GetPropertyNames<ImportStudentParam>();
|
|
|
|
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", "导入学生模板");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 导入学生
|
|
/// </summary>
|
|
/// <param name="file"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="Exception"></exception>
|
|
[HttpPost(nameof(ImportStudents))]
|
|
public async Task<ActionResult> ImportStudents([FromForm] IFormFile file)
|
|
{
|
|
var importedCount = await _studentService.ImportStudents(file);
|
|
return Ok($"成功导入{importedCount}名学生");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 上传学生头像
|
|
/// </summary>
|
|
/// <param name="file"></param>
|
|
/// <param name="gradeId">年级Id</param>
|
|
/// <param name="classId">班级Id</param>
|
|
/// <param name="studentNo">学生学号</param>
|
|
/// <returns></returns>
|
|
[HttpPost(nameof(UploadPhoto))]
|
|
|
|
public async Task<string> UploadPhoto(IFormFile file, int gradeId, int classId, string studentNo, string studentName)
|
|
{
|
|
var url = await _studentService.UploadPhoto(file, gradeId, classId, studentNo, studentName);
|
|
|
|
return url;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 批量上传学生头像
|
|
/// </summary>
|
|
/// <param name="files"></param>
|
|
/// <returns></returns>
|
|
[HttpPost(nameof(BatchUploadPhoto))]
|
|
public async Task<ActionResult> BatchUploadPhoto([FromForm] IFormFile zipFile)
|
|
{
|
|
var result = await _studentService.BatchUploadPhoto(zipFile);
|
|
return Ok(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 导出学生列表
|
|
/// </summary>
|
|
/// <param name="paramDto"></param>
|
|
/// <returns></returns>
|
|
[HttpGet(nameof(StudentExport))]
|
|
public async Task<ActionResult> StudentExport(StudentExportParam paramDto)
|
|
{
|
|
var rseList = await _studentService.GetStudentList(paramDto);
|
|
|
|
var disList = new Dictionary<string, List<StudentPageListModel>>
|
|
{
|
|
{ "学生数据", rseList }
|
|
};
|
|
|
|
var exportColumns = new List<string>
|
|
{
|
|
nameof(StudentPageListModel.StudentNo),
|
|
nameof(StudentPageListModel.StudentName),
|
|
nameof(StudentPageListModel.SexString),
|
|
nameof(StudentPageListModel.GradeName),
|
|
nameof(StudentPageListModel.ClassName),
|
|
nameof(StudentPageListModel.Age),
|
|
nameof(StudentPageListModel.HeartRateFrontNo),
|
|
nameof(StudentPageListModel.HeartRateId),
|
|
nameof(StudentPageListModel.RopeSkipQRCode),
|
|
nameof(StudentPageListModel.Photo),
|
|
nameof(StudentPageListModel.StudentStatusString),
|
|
nameof(StudentPageListModel.OrderNo)
|
|
};
|
|
|
|
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")}");
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 学生整体数据统计
|
|
/// </summary>
|
|
/// <param name="paramDto"></param>
|
|
/// <returns></returns>
|
|
[HttpGet(nameof(StudentWholeDataStats))]
|
|
public async Task<StudentDataStatsModel> StudentWholeDataStats(StudentDataStatsParam paramDto)
|
|
{
|
|
return await _studentService.StudentWholeDataStats(paramDto);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 各项目平均成绩
|
|
/// </summary>
|
|
/// <param name="paramDto"></param>
|
|
/// <returns></returns>
|
|
[HttpGet(nameof(TestResultAvg))]
|
|
public async Task<Dictionary<string, float>> TestResultAvg(StudentCategoryParam paramDto)
|
|
{
|
|
return await _studentService.TestResultAvg(paramDto);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 个人成绩对比
|
|
/// </summary>
|
|
/// <param name="paramDto"></param>
|
|
/// <returns></returns>
|
|
[HttpGet(nameof(TestResultContrast))]
|
|
public async Task<Dictionary<string, float>> TestResultContrast(StudentCategoryParam paramDto)
|
|
{
|
|
return await _studentService.TestResultContrast(paramDto);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 成绩趋势
|
|
/// </summary>
|
|
/// <param name="paramDto"></param>
|
|
/// <returns></returns>
|
|
[HttpGet(nameof(ResultTrends))]
|
|
public async Task<VariousSportsProportion> ResultTrends(StudentResultTrendsParam paramDto)
|
|
{
|
|
return await _studentService.ResultTrends(paramDto);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 训练记录
|
|
/// </summary>
|
|
/// <param name="paramDto"></param>
|
|
/// <returns></returns>
|
|
[HttpGet(nameof(TrainingRecords))]
|
|
public async Task<PageDataDto<StudentTrainingRecordsModel>> TrainingRecords(StudentTrainingRecordsParam paramDto)
|
|
{
|
|
return await _studentService.TrainingRecords(paramDto);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 体测数据
|
|
/// </summary>
|
|
/// <param name="paramDto"></param>
|
|
/// <returns></returns>
|
|
[HttpGet(nameof(TestRecords))]
|
|
public async Task<PageDataDto<StudentTestRecordsModel>> TestRecords(StudentTrainingRecordsParam paramDto)
|
|
{
|
|
return await _studentService.TestRecords(paramDto);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取学生名单
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet(nameof(GetStudentNamePageList))]
|
|
public async Task<List<StudentNamePageListModel>> GetStudentNamePageList(StudentNamePageListParam paramDto)
|
|
{
|
|
return await _studentService.GetStudentNamePageList(paramDto);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更换班级
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost(nameof(ReplaceClasses))]
|
|
public async Task<ActionResult> ReplaceClasses(List<string> studentNoList, int classId)
|
|
{
|
|
await _studentService.ReplaceClasses(studentNoList, classId);
|
|
return Ok("修改成功");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取当前学校一键升学状态
|
|
/// </summary>
|
|
[HttpGet(nameof(GetPromotionStatus))]
|
|
public async Task<StudentPromotionStatusModel> GetPromotionStatus()
|
|
{
|
|
return await _studentService.GetPromotionStatus();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 当前学校学生一键升学
|
|
/// </summary>
|
|
[HttpPost(nameof(PromoteStudents))]
|
|
public async Task<StudentPromotionStatusModel> PromoteStudents()
|
|
{
|
|
return await _studentService.PromoteStudents();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 撤回当前学校最近一次升学
|
|
/// </summary>
|
|
[HttpPost(nameof(UndoPromotion))]
|
|
public async Task<StudentPromotionStatusModel> UndoPromotion()
|
|
{
|
|
return await _studentService.UndoPromotion();
|
|
}
|
|
}
|
|
}
|