2025-06-06 16:00:39 +08:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2026-10-13 14:27:08 +08:00
|
|
|
|
using System.Globalization;
|
|
|
|
|
|
using System.Linq;
|
2025-06-06 16:00:39 +08:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using VOL.Business.IServices;
|
|
|
|
|
|
using VOL.Business.Services;
|
|
|
|
|
|
using VOL.Core.Filters;
|
|
|
|
|
|
using VOL.Core.ManageUser;
|
|
|
|
|
|
using VOL.Core.Utilities;
|
|
|
|
|
|
using VOL.Model;
|
|
|
|
|
|
using VOL.Model.Norm.Response;
|
|
|
|
|
|
|
|
|
|
|
|
namespace VOL.WebApi.Controllers.Business
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 体测数据
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
|
[ApiController]
|
|
|
|
|
|
[ApiExplorerSettings(GroupName = "v3")]
|
|
|
|
|
|
[TypeFilter(typeof(CustomApiResponseFilter))]
|
|
|
|
|
|
public class SportsTestResultController : ControllerBase
|
|
|
|
|
|
{
|
|
|
|
|
|
#region 初始化
|
|
|
|
|
|
|
|
|
|
|
|
private readonly IN_SportsTestResultService _sportsTestResultService;
|
|
|
|
|
|
public SportsTestResultController(
|
|
|
|
|
|
IN_SportsTestResultService sportsTestResultService)
|
|
|
|
|
|
{
|
|
|
|
|
|
_sportsTestResultService = sportsTestResultService;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 学生成绩分页
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpGet(nameof(GetSportsTestCategoryPageList))]
|
|
|
|
|
|
public async Task<PageDataDto<StudentsTestDataModel>> GetSportsTestCategoryPageList(StudentsTestDataListParam paramDto)
|
|
|
|
|
|
{
|
|
|
|
|
|
return await _sportsTestResultService.GetSportsTestCategoryPageList(paramDto);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 导入学生体测数据
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="file"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
/// <exception cref="Exception"></exception>
|
|
|
|
|
|
[HttpPost(nameof(ImportStudentsTestData))]
|
|
|
|
|
|
public async Task<ActionResult> ImportStudentsTestData(IFormFile file)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _sportsTestResultService.ImportStudentsTestData(file);
|
|
|
|
|
|
return Ok("导入成功");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 导出
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="paramDto"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpGet(nameof(Export))]
|
|
|
|
|
|
public async Task<ActionResult> Export(StudentsTestDataListParam paramDto)
|
|
|
|
|
|
{
|
|
|
|
|
|
var rseList = await _sportsTestResultService.GetStudentsTestDataList(paramDto);
|
|
|
|
|
|
|
|
|
|
|
|
var disList = new Dictionary<string, List<StudentsTestDataModel>>();
|
|
|
|
|
|
disList.Add("学生成绩", rseList);
|
|
|
|
|
|
|
|
|
|
|
|
var exportColumns = Tool.GetPropertyNames<StudentsTestDataModel>();
|
|
|
|
|
|
|
|
|
|
|
|
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")}");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-13 14:27:08 +08:00
|
|
|
|
[HttpGet(nameof(ExportSummaryOfGrades))]
|
|
|
|
|
|
public async Task<ActionResult> ExportSummaryOfGrades(StudentsTestDataListParam paramDto)
|
|
|
|
|
|
{
|
|
|
|
|
|
var records = await _sportsTestResultService.GetStudentsTestDataList(paramDto);
|
|
|
|
|
|
var rows = records.Select((row, index) => new SummaryOfGradesTestRecordExportModel
|
|
|
|
|
|
{
|
|
|
|
|
|
Index = index + 1,
|
|
|
|
|
|
GradeAndClass = string.Join("-", new[] { row.GradeName, row.ClassName }
|
|
|
|
|
|
.Where(x => !string.IsNullOrWhiteSpace(x))),
|
|
|
|
|
|
StudentName = row.StudentName,
|
|
|
|
|
|
StudentNo = row.StudentNo,
|
|
|
|
|
|
Sex = row.Sex,
|
|
|
|
|
|
CategoryName = row.CategoryName,
|
|
|
|
|
|
TestResult = FormatTestResult(row),
|
|
|
|
|
|
Score = row.Score,
|
|
|
|
|
|
Rank = row.Rank,
|
|
|
|
|
|
ClassRank = row.ClassRank,
|
|
|
|
|
|
ScoreTime = row.ScoreTime.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture)
|
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
var columns = new List<string>
|
|
|
|
|
|
{
|
|
|
|
|
|
nameof(SummaryOfGradesTestRecordExportModel.Index),
|
|
|
|
|
|
nameof(SummaryOfGradesTestRecordExportModel.GradeAndClass),
|
|
|
|
|
|
nameof(SummaryOfGradesTestRecordExportModel.StudentName),
|
|
|
|
|
|
nameof(SummaryOfGradesTestRecordExportModel.StudentNo),
|
|
|
|
|
|
nameof(SummaryOfGradesTestRecordExportModel.Sex),
|
|
|
|
|
|
nameof(SummaryOfGradesTestRecordExportModel.CategoryName),
|
|
|
|
|
|
nameof(SummaryOfGradesTestRecordExportModel.TestResult),
|
|
|
|
|
|
nameof(SummaryOfGradesTestRecordExportModel.Score),
|
|
|
|
|
|
nameof(SummaryOfGradesTestRecordExportModel.Rank),
|
|
|
|
|
|
nameof(SummaryOfGradesTestRecordExportModel.ClassRank),
|
|
|
|
|
|
nameof(SummaryOfGradesTestRecordExportModel.ScoreTime)
|
|
|
|
|
|
};
|
|
|
|
|
|
var bytes = Tool.ExportToExcel(
|
|
|
|
|
|
new Dictionary<string, List<SummaryOfGradesTestRecordExportModel>> { ["体测数据记录"] = rows },
|
|
|
|
|
|
columns, autoFitColumns: false);
|
|
|
|
|
|
return File(bytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
|
|
|
|
$"体测数据记录{DateTime.Now:yyyyMMddHHmmss}.xlsx");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static string FormatTestResult(StudentsTestDataModel row)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (row.CategoryValue != 10 && row.CategoryValue != 11)
|
|
|
|
|
|
return row.Value.ToString("0.##", CultureInfo.InvariantCulture);
|
|
|
|
|
|
|
|
|
|
|
|
// Some historical imports contain millisecond values despite the seconds-based category unit.
|
|
|
|
|
|
var seconds = row.Value >= 10000 ? row.Value / 1000d : row.Value;
|
|
|
|
|
|
var totalSeconds = (int)Math.Round(Math.Max(0, seconds), MidpointRounding.AwayFromZero);
|
|
|
|
|
|
return $"{totalSeconds / 60}分{totalSeconds % 60:D2}秒";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-06 16:00:39 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 新增
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="paramDto"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPost(nameof(Add))]
|
|
|
|
|
|
public async Task<ActionResult> Add([FromBody] List<AddStudentsTestDataParam> paramDto)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _sportsTestResultService.AddStudentsTestData(paramDto);
|
|
|
|
|
|
return Ok("新增成功");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 更新
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="paramDto"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPost(nameof(Modify))]
|
|
|
|
|
|
public async Task<ActionResult> Modify([FromBody] List<AddStudentsTestDataParam> paramDto)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _sportsTestResultService.ModifyStudentsTestData(paramDto);
|
|
|
|
|
|
return Ok("更新成功");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 删除
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="paramDto"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPost(nameof(Delete))]
|
|
|
|
|
|
public async Task<ActionResult> Delete(List<int> ids)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _sportsTestResultService.DeleteStudentsTestData(ids);
|
|
|
|
|
|
return Ok("更新成功");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-10-13 14:27:08 +08:00
|
|
|
|
}
|