Compare commits
6
Commits
27cad42d45
...
c1822d5b91
No files matched your search
@@ -117,6 +117,10 @@ public sealed class AcademicCalendarController(
|
||||
{
|
||||
return Problem("无法获取节假日数据,请检查网络后重试。", statusCode: StatusCodes.Status502BadGateway);
|
||||
}
|
||||
catch (OperationCanceledException) when (!cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
return Problem("无法获取节假日数据,请检查网络后重试。", statusCode: StatusCodes.Status502BadGateway);
|
||||
}
|
||||
catch (InvalidOperationException exception)
|
||||
{
|
||||
return ValidationProblem(exception.Message);
|
||||
@@ -132,6 +136,7 @@ public sealed class AcademicCalendarController(
|
||||
HolidayCnYear source;
|
||||
try { source = await holidayCnClient.GetYearAsync(request.Year, cancellationToken); }
|
||||
catch (HttpRequestException) { return Problem("无法获取节假日数据,请检查网络后重试。", statusCode: StatusCodes.Status502BadGateway); }
|
||||
catch (OperationCanceledException) when (!cancellationToken.IsCancellationRequested) { return Problem("无法获取节假日数据,请检查网络后重试。", statusCode: StatusCodes.Status502BadGateway); }
|
||||
catch (InvalidOperationException exception) { return ValidationProblem(exception.Message); }
|
||||
|
||||
var existing = await db.AcademicCalendarEvents.Where(item => item.AcademicTermId == request.AcademicTermId && item.Source == AcademicCalendarEventSource.HolidayCn && item.SourceYear == request.Year).ToListAsync(cancellationToken);
|
||||
|
||||
@@ -1208,7 +1208,11 @@ public sealed partial class ApprovalsController(
|
||||
var holidays = await db.AcademicCalendarEvents.AsNoTracking()
|
||||
.Where(x => x.IsEnabled && x.Source == AcademicCalendarEventSource.HolidayCn && x.IsOffDay != null)
|
||||
.ToListAsync(ct);
|
||||
pageItems = pageItems.Select(x => x with { DeadlineUtc = ApprovalTimeliness.DeadlineUtc(x.Time, holidays) }).ToArray();
|
||||
pageItems = pageItems.Select(x =>
|
||||
{
|
||||
var deadline = ApprovalTimeliness.DeadlineUtc(x.Time, holidays);
|
||||
return x with { DeadlineUtc = deadline, MissingHolidayYears = ApprovalTimeliness.MissingHolidayYears(x.Time, deadline, holidays) };
|
||||
}).ToArray();
|
||||
}
|
||||
return Ok(new ApprovalPendingResult(pageItems, total, page, pageSize, counts, timelinessEnabled));
|
||||
}
|
||||
@@ -2013,7 +2017,7 @@ public sealed partial class ApprovalsController(
|
||||
ApprovalsErrorKeys.TryGetValue(detail, out var key) ? SharedResourceText.Get(localizer, key) : detail;
|
||||
}
|
||||
|
||||
public sealed record ApprovalItem(Guid Id, string Type, string Label, string Title, string Desc, DateTime Time, string College, string? Stage = null, Guid? SecondaryId = null, DateTime? DeadlineUtc = null);
|
||||
public sealed record ApprovalItem(Guid Id, string Type, string Label, string Title, string Desc, DateTime Time, string College, string? Stage = null, Guid? SecondaryId = null, DateTime? DeadlineUtc = null, int[]? MissingHolidayYears = null);
|
||||
public sealed class ApprovalReviewedItem
|
||||
{
|
||||
public Guid Id { get; init; }
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
using System.Text.Json;
|
||||
using Jiaowu.Api.Domain.Academic;
|
||||
using Jiaowu.Api.Domain.Identity;
|
||||
using Jiaowu.Api.Infrastructure.Auth;
|
||||
using Jiaowu.Api.Infrastructure.Caching;
|
||||
using Jiaowu.Api.Infrastructure.Persistence;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Jiaowu.Api.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Route("api/student-identity-changes")]
|
||||
public sealed class StudentIdentityChangesController(AppDbContext db, ICurrentUserDataScope scope, IAppCache cache) : ControllerBase
|
||||
{
|
||||
private const string Managers = SystemRoles.SuperAdmin + "," + SystemRoles.AcademicAdmin + "," + SystemRoles.CollegeAdmin;
|
||||
|
||||
[HttpGet("mine")]
|
||||
[Authorize(Roles = SystemRoles.Student)]
|
||||
public async Task<IActionResult> Mine(CancellationToken ct)
|
||||
{
|
||||
var items = await db.StudentIdentityChanges.AsNoTracking()
|
||||
.Where(x => x.Student!.UserId == scope.Current.UserId)
|
||||
.OrderByDescending(x => x.CreatedAt).Take(50).ToListAsync(ct);
|
||||
return Ok(items.Select(Format));
|
||||
}
|
||||
|
||||
[HttpGet("pending")]
|
||||
[Authorize(Roles = Managers)]
|
||||
public async Task<IActionResult> Pending(CancellationToken ct)
|
||||
{
|
||||
var current = scope.Current;
|
||||
var query = db.StudentIdentityChanges.AsNoTracking().Include(x => x.Student)!
|
||||
.ThenInclude(x => x!.AdministrativeClass)!.ThenInclude(x => x!.Major)
|
||||
.Where(x => x.Status == ApprovalStatus.Submitted);
|
||||
if (current.Scope != DataScope.All)
|
||||
{
|
||||
if (current.Scope != DataScope.College || current.RestrictedCollegeId is null) return Forbid();
|
||||
query = query.Where(x => x.Student!.AdministrativeClass!.Major!.CollegeId == current.RestrictedCollegeId);
|
||||
}
|
||||
var items = await query.OrderBy(x => x.CreatedAt).Take(200).ToListAsync(ct);
|
||||
return Ok(items.Select(x => new { x.Id, x.CreatedAt, studentName = x.Student!.Name,
|
||||
studentNumber = x.Student.StudentNumber, className = x.Student.AdministrativeClass!.Name,
|
||||
changes = Parse(x.ChangesJson) }));
|
||||
}
|
||||
|
||||
[HttpPost("{id:guid}/review")]
|
||||
[Authorize(Roles = Managers)]
|
||||
public async Task<IActionResult> Review(Guid id, IdentityReviewRequest request, CancellationToken ct)
|
||||
{
|
||||
if (!request.Approved && string.IsNullOrWhiteSpace(request.Comment))
|
||||
return BadRequest(new { message = "驳回时请填写审核意见。" });
|
||||
var item = await db.StudentIdentityChanges.Include(x => x.Student)!
|
||||
.ThenInclude(x => x!.AdministrativeClass)!.ThenInclude(x => x!.Major)
|
||||
.SingleOrDefaultAsync(x => x.Id == id, ct);
|
||||
if (item is null) return NotFound();
|
||||
if (!scope.Current.CanAccessCollege(item.Student!.AdministrativeClass!.Major!.CollegeId)) return Forbid();
|
||||
if (item.Status != ApprovalStatus.Submitted) return Conflict(new { message = "申请已处理。" });
|
||||
var student = item.Student;
|
||||
if (request.Approved)
|
||||
{
|
||||
if (student.IsArchived) return Conflict(new { message = "学生档案已归档,无法通过申请。" });
|
||||
var changes = Parse(item.ChangesJson);
|
||||
var current = IdentitySnapshot.FromStudent(student);
|
||||
var values = new Dictionary<string, string?> {
|
||||
["Gender"] = current.Gender.ToString(), ["DateOfBirth"] = current.DateOfBirth?.ToString("yyyy-MM-dd"),
|
||||
["IdCardNumber"] = current.IdCardNumber, ["Nationality"] = current.Nationality,
|
||||
["Ethnicity"] = current.Ethnicity, ["PoliticalStatus"] = current.PoliticalStatus, ["NativePlace"] = current.NativePlace,
|
||||
["SpecialTags"] = current.SpecialTags, ["SpecialNeeds"] = current.SpecialNeeds
|
||||
};
|
||||
if (changes.Any(x => !values.TryGetValue(x.Field, out var value) || value != x.OldValue))
|
||||
return Conflict(new { message = "档案中的相关信息已发生变化,请驳回后由学生重新提交。" });
|
||||
foreach (var change in changes)
|
||||
switch (change.Field)
|
||||
{
|
||||
case "Gender": student.Gender = Enum.Parse<Gender>(change.NewValue!); break;
|
||||
case "DateOfBirth": student.DateOfBirth = change.NewValue is null ? null : DateOnly.ParseExact(change.NewValue, "yyyy-MM-dd"); break;
|
||||
case "IdCardNumber": student.IdCardNumber = change.NewValue; break;
|
||||
case "Nationality": student.Nationality = change.NewValue; break;
|
||||
case "Ethnicity": student.Ethnicity = change.NewValue; break;
|
||||
case "PoliticalStatus": student.PoliticalStatus = change.NewValue; break;
|
||||
case "NativePlace": student.NativePlace = change.NewValue; break;
|
||||
case "SpecialTags": student.SpecialTags = change.NewValue; break;
|
||||
case "SpecialNeeds": student.SpecialNeeds = change.NewValue; break;
|
||||
default: return Conflict(new { message = "申请包含未知字段,无法审核。" });
|
||||
}
|
||||
}
|
||||
item.Status = request.Approved ? ApprovalStatus.Approved : ApprovalStatus.Rejected;
|
||||
item.PendingSlot = null;
|
||||
item.ReviewComment = request.Comment?.Trim();
|
||||
item.ReviewedAt = DateTime.UtcNow;
|
||||
item.ReviewedByUserId = scope.Current.UserId;
|
||||
try { await db.SaveChangesAsync(ct); }
|
||||
catch (DbUpdateConcurrencyException) { return Conflict(new { message = "申请或档案已发生变化,请刷新后重试。" }); }
|
||||
if (request.Approved) await cache.RemoveByTagAsync(AppCacheTags.Analytics, ct);
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
private static List<IdentityValueChange> Parse(string json) => JsonSerializer.Deserialize<List<IdentityValueChange>>(json) ?? [];
|
||||
private static object Format(StudentIdentityChange item) => new { item.Id, item.CreatedAt, item.Status,
|
||||
item.ReviewComment, item.ReviewedAt, changes = Parse(item.ChangesJson) };
|
||||
}
|
||||
|
||||
public sealed record IdentityReviewRequest(bool Approved, [property: System.ComponentModel.DataAnnotations.MaxLength(1000)] string? Comment);
|
||||
Loaded 3 of 29 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user