From 74fe063253caf622610577052239acd815fdc585 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=B0=8F=E8=82=A5=E7=BE=8A?= <1048382248@qq.com>
Date: Tue, 19 Aug 2025 18:41:00 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=20=E8=80=83=E8=AF=95?=
=?UTF-8?q?=E6=B5=81=E7=A8=8B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Controllers/Dto/ExamClassInfoDto.cs | 8 +-
.../Controllers/ExamClassInfoController.cs | 88 ++++++++++++++++---
.../Controllers/ExamController.cs | 21 ++++-
.../Controllers/SchoolBusinessController.cs | 7 ++
Learn.Archives.API/Program.cs | 2 +
Learn.Archives.API/appsettings.json | 5 +-
.../Common/Expand/SqlSugarExpand.cs | 3 +-
Learn.Archives.Core/Common/Repository.cs | 4 +-
.../Model/Dto/SchoolBusinessDto.cs | 5 ++
Learn.Archives.Core/Model/Exam.cs | 4 +
Learn.Archives.Core/Model/ExamClassInfo.cs | 5 +-
Learn.Archives.Core/Model/ExamUserInfo.cs | 13 +++
Learn.Archives.Core/Model/SchoolBusiness.cs | 19 +++-
13 files changed, 161 insertions(+), 23 deletions(-)
diff --git a/Learn.Archives.API/Controllers/Dto/ExamClassInfoDto.cs b/Learn.Archives.API/Controllers/Dto/ExamClassInfoDto.cs
index aca79be..9434ef5 100644
--- a/Learn.Archives.API/Controllers/Dto/ExamClassInfoDto.cs
+++ b/Learn.Archives.API/Controllers/Dto/ExamClassInfoDto.cs
@@ -51,7 +51,7 @@ namespace Learn.Archives.API.Controllers.Dto
[ExcelColumnName("班级类型")]
public string ClassType { get; set; }
///
- /// 学生姓名0.
+ /// 学生姓名
///
[ExcelColumnName("学生姓名")]
public string Student { get; set; }
@@ -118,4 +118,10 @@ namespace Learn.Archives.API.Controllers.Dto
[ExcelColumnName("赋分后总分")]
public decimal 赋分后总分 { get; set; }
}
+
+ public class RestartEntryDto
+ {
+ public long ClassId { get; set; }
+ public long ExamId { get; set; }
+ }
}
diff --git a/Learn.Archives.API/Controllers/ExamClassInfoController.cs b/Learn.Archives.API/Controllers/ExamClassInfoController.cs
index badd468..3c5d3cf 100644
--- a/Learn.Archives.API/Controllers/ExamClassInfoController.cs
+++ b/Learn.Archives.API/Controllers/ExamClassInfoController.cs
@@ -58,6 +58,7 @@ namespace Learn.Archives.API.Controllers
[HttpLogEnable]
public async Task Import(ImportDto dto)
{
+
var exam = await examService.GetByIdAsync(dto.eId);
var fl = dto.File!=null? dto .File: accessor.HttpContext?.Request.Form.Files[0];
if (exam == null || fl == null) Oh.ModelError("为传入有效的数据");
@@ -69,10 +70,12 @@ namespace Learn.Archives.API.Controllers
{
await fl.CopyToAsync(stream);
dataList = stream.Query()
- .Where(s => string.IsNullOrEmpty(s.Student));
+ .Where(s => !string.IsNullOrEmpty(s.Student));
}
if (dataList == null || dataList.Count() == 0)
Oh.ModelError("导入失败:无有效数据");
+
+ //todo
//处理数据
var errorExcelInfo = new List();
var insertUserInfo = new List();
@@ -89,21 +92,21 @@ namespace Learn.Archives.API.Controllers
c.GradeLevel == gradeInfo.GradeLevel &&
c.GraduationYear == gradeInfo.GradeYear && !c.DeleteState).ToArrayAsync();
var userDic = await db.Queryable()
- .InnerJoin((s, c) => c.SchoolId == s.Id)
- .InnerJoin((s, c, p) => p.ClassId == c.Id)
- .InnerJoin((s, c, p, pr) => pr.PositionId == p.Id)
- .InnerJoin((s, c, p, pr, u) => u.Id == pr.UserId)
+ .LeftJoin((s, c) => c.SchoolId == s.Id)
+ .LeftJoin((s, c, p) => p.ClassId == c.Id)
+ .LeftJoin((s, c, p, pr) => pr.PositionId == p.Id)
+ .LeftJoin((s, c, p, pr, u) => u.Id == pr.UserId)
.Where((s, c, p, pr, u) =>
s.Id == school.Id &&
c.GradeLevel == gradeInfo.GradeLevel &&
c.GraduationYear == gradeInfo.GradeYear &&
s.Enable && p.Enable && pr.Enable &&
- p.DeleteState != false && c.DeleteState != false && u.DeleteState != false && s.DeleteState != false)
+ !p.DeleteState && !c.DeleteState && !u.DeleteState && !s.DeleteState)
.Select((s, c, p, pr, u) => new
{
Name = c.Name + c.Type.ToString() + u.RealName,
u.Id,
- }).ToDictionaryAsync(s => s.Id, s => s.Name);
+ }).ToDictionaryAsync(s => s.Name, s => s.Id);
//处理学生成绩数据
var userList = dataList.Select(s =>
{
@@ -118,7 +121,7 @@ namespace Learn.Archives.API.Controllers
var grade = GradeHelper.GetStudentGradeBaseByGrade(s.Grade);
var sub = ImportExamInfoSubjectDic(s);
var name = s.Class + s.ClassType.ToEnum().GetHashCode() + s.Student;
- if (userDic.ContainsKey(name))
+ if (!userDic.ContainsKey(name))
{
s.Error = "未能匹配到年级班级下对应的学生";
errorExcelInfo.Add(s);
@@ -133,6 +136,7 @@ namespace Learn.Archives.API.Controllers
GradeLevel = grade.GradeLevel,
TestPaperType = exam.TestPaperType,
UserId = (long)userDic[name],
+ UserName = s.Student,
ClassId = classInfo.Id,
SchoolId = classInfo.SchoolId,
Type = exam.Type,
@@ -143,7 +147,7 @@ namespace Learn.Archives.API.Controllers
}).ToList();
insertUserInfo.AddRange(userList);
-
+ insertUserInfo = insertUserInfo.Where(s => s != null).ToList();
foreach (var classUserArr in insertUserInfo.GroupBy(s => s.ClassId))
{
var classInfo = classArr.First(s => s.Id == classUserArr.Key);
@@ -180,7 +184,7 @@ namespace Learn.Archives.API.Controllers
//总分平均分
eCInfo.Average = avgTotal / eCInfo.PeopleCount;
//计算上线率
- eCInfo.OnLineRate = eCInfo.OnLineCount / eCInfo.PeopleCount;
+ eCInfo.OnLineRate = (decimal)eCInfo.OnLineCount / (decimal)eCInfo.PeopleCount;
//处理学生班级排名
var i = 0;
foreach (var item in classUserArr.OrderByDescending(s => s.AssignScore)
@@ -218,12 +222,70 @@ namespace Learn.Archives.API.Controllers
//写入数据库
var baseDB = baseService.Context;
baseDB.Ado.BeginTran();
- await db.Insertable(insertUserInfo).ExecuteCommandAsync();
- await db.Insertable(insertClassInfo).ExecuteCommandAsync();
- baseDB.Ado.CommitTran();
+ try
+ {
+ await baseDB.Insertable(insertUserInfo).ExecuteCommandAsync();
+ await baseDB.Insertable(insertClassInfo).ExecuteCommandAsync();
+ baseDB.Ado.CommitTran();
+
+ }
+ catch (Exception ex)
+ {
+ baseDB.Ado.RollbackTran();
+ Oh.ModelError($"导入失败:写入数据时候出现了异常 [{ex.Message}] !");
+ }
return Ok();
}
+ ///
+ /// 下载导入成绩模板
+ ///
+ ///
+ [HttpGet, ResultIgnore, AllowAnonymous]
+ public IActionResult DwImportTemplate()
+ {
+ List resultList = new List() { new ImportExamInfo()
+ {
+ School="例子学校",
+ Class="测试班级",
+ ClassType="普通班级",
+ Grade="高2028",
+ Student="学生姓名",
+ 语文=80.5m,
+ 化学=80.5m,
+ 数学=80m,
+ 历史 = 80m,
+ 地理 = 80m,
+ 政治 = 80m,
+ 物理 = 80m,
+ 生物 = 80m,
+ 英语 = 80.5m,
+ 赋分后总分=721.5m
+ } };
+ return File(resultList.ExportExcel(), "application/ms-excel");
+ }
+
+ ///
+ /// 删除班级考试信息
+ ///
+ ///
+ ///
+ [HttpPost]
+ public async Task DeleteExamInfo(RestartEntryDto dto)
+ {
+ if (dto.ClassId == 0 || dto.ExamId == 0)
+ Oh.ModelError("传入了异常参数");
+ var exam = examService.GetById(dto.ExamId);
+ if (exam is null)
+ Oh.ModelError("传入了无效的考试");
+ var dCount = await baseService.AsDeleteable().Where(s => s.ClassId == dto.ClassId)
+ .ExecuteCommandAsync();
+ var dCount1 = await examUserInfoService.AsDeleteable().Where(s => s.ClassId == dto.ClassId)
+ .ExecuteCommandAsync();
+ return Ok();
+
+ }
+
}
}
diff --git a/Learn.Archives.API/Controllers/ExamController.cs b/Learn.Archives.API/Controllers/ExamController.cs
index a263464..fa86d17 100644
--- a/Learn.Archives.API/Controllers/ExamController.cs
+++ b/Learn.Archives.API/Controllers/ExamController.cs
@@ -1,4 +1,5 @@
-using Learn.Archives.API.Controllers.Dto;
+using AlibabaCloud.SDK.Vod20170321.Models;
+using Learn.Archives.API.Controllers.Dto;
using Learn.Archives.API.Expand;
using Learn.Archives.Core.Common;
using Learn.Archives.Core.Model;
@@ -16,11 +17,27 @@ namespace Learn.Archives.API.Controllers
public class ExamController : BackController
{
readonly Repository baseService;
+ readonly Repository examClassInfoService;
+ readonly Repository examUserInfoService;
readonly LiveUserInfo userInfo;
- public ExamController(Repository baseService, LiveUserInfo userInfo) : base(baseService)
+ public ExamController(Repository baseService, LiveUserInfo userInfo, Repository examClassInfoService, Repository examUserInfoService) : base(baseService)
{
this.baseService = baseService;
this.userInfo = userInfo;
+ this.examClassInfoService = examClassInfoService;
+ this.examUserInfoService = examUserInfoService;
+ }
+
+ public override async Task Del([FromBody] params long[] ids)
+ {
+ if (ids.Length > 1)
+ Oh.ModelError("同时只允许删除一场考试");
+ var id= ids.First();
+ var dCount = await examClassInfoService.AsDeleteable().Where(s => s.ExamId == id)
+ .ExecuteCommandAsync();
+ var dCount1 = await examUserInfoService.AsDeleteable().Where(s => s.ExamId == id)
+ .ExecuteCommandAsync();
+ return await base.Del(ids);
}
}
}
diff --git a/Learn.Archives.API/Controllers/SchoolBusinessController.cs b/Learn.Archives.API/Controllers/SchoolBusinessController.cs
index fc7fc4f..c4a0ff8 100644
--- a/Learn.Archives.API/Controllers/SchoolBusinessController.cs
+++ b/Learn.Archives.API/Controllers/SchoolBusinessController.cs
@@ -9,6 +9,7 @@ using SqlSugar;
using System.Diagnostics;
using System.Security.Claims;
using UserCenter.Model;
+using UserCenter.Model.Common;
namespace Learn.Archives.API.Controllers
{
@@ -56,6 +57,12 @@ namespace Learn.Archives.API.Controllers
{
if (model.SolutionRecord != null && model.SolutionRecord.SolutionEnd == true)
model.SolutionEnd = true;
+ if (!string.IsNullOrEmpty(model._grade))
+ {
+ var g = GradeHelper.GetStudentGradeBaseByGrade(model._grade);
+ model.GradeLevel = g.GradeLevel;
+ model.GradeYear = g.GradeYear;
+ }
return base.Edit(model);
}
diff --git a/Learn.Archives.API/Program.cs b/Learn.Archives.API/Program.cs
index d21200e..605742e 100644
--- a/Learn.Archives.API/Program.cs
+++ b/Learn.Archives.API/Program.cs
@@ -6,6 +6,7 @@ using Learn.Archives.Core.Common.Expand;
using Mapster;
using System.Text.Json;
using Learn.Archives.API.Expand;
+using System.ComponentModel;
var builder = WebApplication.CreateBuilder(args);
@@ -24,6 +25,7 @@ builder.Services.AddControllers(options =>
})
.AddJsonOptions(options =>
{
+
options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All);//תʱʹUnicode
options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;// ĬСշ null շ
});
diff --git a/Learn.Archives.API/appsettings.json b/Learn.Archives.API/appsettings.json
index d148e6b..6701092 100644
--- a/Learn.Archives.API/appsettings.json
+++ b/Learn.Archives.API/appsettings.json
@@ -12,7 +12,7 @@
"ConnectionString": "127.0.0.1:6379,password=Woshiren123,defaultDatabase=10"
},
"DB": {
- "ConnectionString": "AllowLoadLocalInfile=true;Server=192.168.2.9;User ID=root;Password=qwe123!@#;Port=3306;Database=learn.archives;CharSet=utf8mb4;pooling=true;SslMode=None",
+ "ConnectionString": "AllowLoadLocalInfile=true;Server=192.168.2.9;User ID=root;Password=qwe123!@#;Port=3306;Database=learn.archives;CharSet=utf8mb4;pooling=true;SslMode=None;",
"SqlType": "MySql",
"UpdateTable": true
},
@@ -25,7 +25,8 @@
"OtherDBArr": [
{
"ConfigId": 1001, //用户中心
- "ConnectionString": "AllowLoadLocalInfile=true;Server=192.168.2.9;User ID=root;Password=qwe123!@#;Port=3306;Database=usercenter;CharSet=utf8mb4;pooling=true;SslMode=None",
+ //"ConnectionString": "AllowLoadLocalInfile=true;Server=192.168.2.9;User ID=root;Password=qwe123!@#;Port=3306;Database=usercenter;CharSet=utf8mb4;pooling=true;SslMode=None;",
+ "ConnectionString": "AllowLoadLocalInfile=true;Server=58.17.132.2;User ID=marking;Password=qwe123!@#;Port=3306;Database=usercenter;CharSet=utf8mb4;Port=43306;pooling=true;SslMode=None;",
"SqlType": "MySql"
}
]
diff --git a/Learn.Archives.Core/Common/Expand/SqlSugarExpand.cs b/Learn.Archives.Core/Common/Expand/SqlSugarExpand.cs
index c0ca350..85b6696 100644
--- a/Learn.Archives.Core/Common/Expand/SqlSugarExpand.cs
+++ b/Learn.Archives.Core/Common/Expand/SqlSugarExpand.cs
@@ -43,7 +43,8 @@ namespace Learn.Archives.Core.Common.Expand
DbType = s.SqlType,
IsAutoCloseConnection = true
}));
- services.AddTransient(typeof(Repository<>));
+ services.AddScoped(typeof(Repository<>));
+ //services.AddTransient(typeof(Repository<>));
//注入SqlSugar 主库
services.AddSqlSugar(dbList);
diff --git a/Learn.Archives.Core/Common/Repository.cs b/Learn.Archives.Core/Common/Repository.cs
index cc0f719..586c91c 100644
--- a/Learn.Archives.Core/Common/Repository.cs
+++ b/Learn.Archives.Core/Common/Repository.cs
@@ -21,9 +21,9 @@ namespace Learn.Archives.Core.Common
{
var t = typeof(T);
if (AppCommon.DbMatserType.Contains(t))
- base.Context = DbScoped.Sugar;
+ base.Context = DbScoped.SugarScope;
else if (AppCommon.UserCenterType.Contains(t))
- base.Context = DbScoped.Sugar.GetConnectionScope(1001);
+ base.Context = DbScoped.SugarScope.GetConnectionScope(1001);
SqlSugarExpand.SetDbAop(base.Context);
}
}
diff --git a/Learn.Archives.Core/Model/Dto/SchoolBusinessDto.cs b/Learn.Archives.Core/Model/Dto/SchoolBusinessDto.cs
index 1f8cb18..cde4b35 100644
--- a/Learn.Archives.Core/Model/Dto/SchoolBusinessDto.cs
+++ b/Learn.Archives.Core/Model/Dto/SchoolBusinessDto.cs
@@ -24,6 +24,11 @@ namespace Learn.Archives.Core.Model.Dto
/// 完结记录
///
public string? EndRecord { get; set; }
+ ///
+ /// 添加完结时间
+ ///
+ public DateTime? EndRecordTime { get; set; }
+
///
/// 执行记录
///
diff --git a/Learn.Archives.Core/Model/Exam.cs b/Learn.Archives.Core/Model/Exam.cs
index 0ec852c..8aa2725 100644
--- a/Learn.Archives.Core/Model/Exam.cs
+++ b/Learn.Archives.Core/Model/Exam.cs
@@ -41,6 +41,10 @@ namespace Learn.Archives.Core.Model
///
public decimal ScoreLine { get; set; }
///
+ /// 资源校平均分
+ ///
+ public decimal BaseSchoolScore { get; set; }
+ ///
/// 参与班级数量
///
[SugarColumn(IsNullable = true)]
diff --git a/Learn.Archives.Core/Model/ExamClassInfo.cs b/Learn.Archives.Core/Model/ExamClassInfo.cs
index 51625d9..02a60ed 100644
--- a/Learn.Archives.Core/Model/ExamClassInfo.cs
+++ b/Learn.Archives.Core/Model/ExamClassInfo.cs
@@ -5,6 +5,7 @@ using System.ComponentModel.DataAnnotations;
using System.Net;
using System.Text.Json;
using UserCenter.Model;
+using UserCenter.Model.Common;
using UserCenter.Model.Enum;
using UserCenter.Model.Interface;
@@ -46,6 +47,8 @@ namespace Learn.Archives.Core.Model
///
public long SchoolId { get; set; }
+ [SugarColumn(IsIgnore = true)]
+ public string Grade => GradeHelper.GetGrade(GradeLevel, GradeYear);
///
/// 年级
///
@@ -56,7 +59,7 @@ namespace Learn.Archives.Core.Model
public int GradeYear { get; set; }
///
- /// 上线人数 考试排名
+ /// 上线率 考试排名
///
public decimal OnLineRanking { get; set; }
///
diff --git a/Learn.Archives.Core/Model/ExamUserInfo.cs b/Learn.Archives.Core/Model/ExamUserInfo.cs
index 7eaf8d8..ef1dad6 100644
--- a/Learn.Archives.Core/Model/ExamUserInfo.cs
+++ b/Learn.Archives.Core/Model/ExamUserInfo.cs
@@ -5,6 +5,7 @@ using System.ComponentModel.DataAnnotations;
using System.Net;
using System.Text.Json;
using UserCenter.Model;
+using UserCenter.Model.Common;
using UserCenter.Model.Enum;
using UserCenter.Model.Interface;
@@ -27,6 +28,14 @@ namespace Learn.Archives.Core.Model
[SugarColumn(Length = 20)]
public string ExamName { get; set; }
+ ///
+ /// 年级
+ /// 只读
+ ///
+ [SugarColumn(IsIgnore = true)]
+ public string Grade => GradeHelper.GetGrade(GradeLevel, GradeYear);
+
+
///
/// 毕业届
///
@@ -51,6 +60,10 @@ namespace Learn.Archives.Core.Model
/// 来自
///
public long UserId { get; set; }
+ ///
+ /// 用户名称
+ ///
+ public string UserName { get; set; }
///
/// 班级id
diff --git a/Learn.Archives.Core/Model/SchoolBusiness.cs b/Learn.Archives.Core/Model/SchoolBusiness.cs
index a851428..bddd5b2 100644
--- a/Learn.Archives.Core/Model/SchoolBusiness.cs
+++ b/Learn.Archives.Core/Model/SchoolBusiness.cs
@@ -5,6 +5,7 @@ using System.ComponentModel.DataAnnotations;
using System.Net;
using System.Text.Json;
using UserCenter.Model;
+using UserCenter.Model.Common;
using UserCenter.Model.Enum;
namespace Learn.Archives.Core.Model
@@ -23,10 +24,26 @@ namespace Learn.Archives.Core.Model
/// 学校名称
///
public string SchoolName { get; set; }
+
+ ///
+ /// dto 处理的grade
+ ///
+ public string? _grade;
///
/// 年级
///
- public string Grade { get; set; }
+ [SugarColumn(IsIgnore = true)]
+ public string Grade
+ {
+ get => GradeHelper.GetGrade(GradeLevel, GradeYear);
+ set => _grade = value;
+ }
+
+ ///
+ /// 年级
+ ///
+ public int GradeYear { get; set; }
+ public string GradeLevel { get; set; }
///
/// 赴校人员 逗号分隔
///