完善 考试流程
This commit is contained in:
parent
549ec66f80
commit
74fe063253
|
|
@ -51,7 +51,7 @@ namespace Learn.Archives.API.Controllers.Dto
|
|||
[ExcelColumnName("班级类型")]
|
||||
public string ClassType { get; set; }
|
||||
/// <summary>
|
||||
/// 学生姓名0.
|
||||
/// 学生姓名
|
||||
/// </summary>
|
||||
[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; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ namespace Learn.Archives.API.Controllers
|
|||
[HttpLogEnable]
|
||||
public async Task<IActionResult> 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<ImportExamInfoError>()
|
||||
.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<ImportExamInfoError>();
|
||||
var insertUserInfo = new List<ExamUserInfo>();
|
||||
|
|
@ -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<School>()
|
||||
.InnerJoin<Classes>((s, c) => c.SchoolId == s.Id)
|
||||
.InnerJoin<Position>((s, c, p) => p.ClassId == c.Id)
|
||||
.InnerJoin<PositionRelation>((s, c, p, pr) => pr.PositionId == p.Id)
|
||||
.InnerJoin<User>((s, c, p, pr, u) => u.Id == pr.UserId)
|
||||
.LeftJoin<Classes>((s, c) => c.SchoolId == s.Id)
|
||||
.LeftJoin<Position>((s, c, p) => p.ClassId == c.Id)
|
||||
.LeftJoin<PositionRelation>((s, c, p, pr) => pr.PositionId == p.Id)
|
||||
.LeftJoin<User>((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<ClassTypeEnum>().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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下载导入成绩模板
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet, ResultIgnore, AllowAnonymous]
|
||||
public IActionResult DwImportTemplate()
|
||||
{
|
||||
List<ImportExamInfo> resultList = new List<ImportExamInfo>() { 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");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除班级考试信息
|
||||
/// </summary>
|
||||
/// <param name="dto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> 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();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Exam>
|
||||
{
|
||||
readonly Repository<Exam> baseService;
|
||||
readonly Repository<ExamClassInfo> examClassInfoService;
|
||||
readonly Repository<ExamUserInfo> examUserInfoService;
|
||||
readonly LiveUserInfo userInfo;
|
||||
public ExamController(Repository<Exam> baseService, LiveUserInfo userInfo) : base(baseService)
|
||||
public ExamController(Repository<Exam> baseService, LiveUserInfo userInfo, Repository<ExamClassInfo> examClassInfoService, Repository<ExamUserInfo> examUserInfoService) : base(baseService)
|
||||
{
|
||||
this.baseService = baseService;
|
||||
this.userInfo = userInfo;
|
||||
this.examClassInfoService = examClassInfoService;
|
||||
this.examUserInfoService = examUserInfoService;
|
||||
}
|
||||
|
||||
public override async Task<bool> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 大驼峰
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
}
|
||||
]
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,11 @@ namespace Learn.Archives.Core.Model.Dto
|
|||
/// 完结记录
|
||||
/// </summary>
|
||||
public string? EndRecord { get; set; }
|
||||
/// <summary>
|
||||
/// 添加完结时间
|
||||
/// </summary>
|
||||
public DateTime? EndRecordTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 执行记录
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -41,6 +41,10 @@ namespace Learn.Archives.Core.Model
|
|||
/// </summary>
|
||||
public decimal ScoreLine { get; set; }
|
||||
/// <summary>
|
||||
/// 资源校平均分
|
||||
/// </summary>
|
||||
public decimal BaseSchoolScore { get; set; }
|
||||
/// <summary>
|
||||
/// 参与班级数量
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
|
|
|
|||
|
|
@ -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
|
|||
/// </summary>
|
||||
public long SchoolId { get; set; }
|
||||
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
public string Grade => GradeHelper.GetGrade(GradeLevel, GradeYear);
|
||||
/// <summary>
|
||||
/// 年级
|
||||
/// </summary>
|
||||
|
|
@ -56,7 +59,7 @@ namespace Learn.Archives.Core.Model
|
|||
public int GradeYear { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 上线人数 考试排名
|
||||
/// 上线率 考试排名
|
||||
/// </summary>
|
||||
public decimal OnLineRanking { get; set; }
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -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; }
|
||||
|
||||
/// <summary>
|
||||
/// 年级
|
||||
/// <para>只读</para>
|
||||
/// </summary>
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
public string Grade => GradeHelper.GetGrade(GradeLevel, GradeYear);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 毕业届
|
||||
/// </summary>
|
||||
|
|
@ -51,6 +60,10 @@ namespace Learn.Archives.Core.Model
|
|||
/// 来自<see cref="User.Id"/>
|
||||
/// </summary>
|
||||
public long UserId { get; set; }
|
||||
/// <summary>
|
||||
/// 用户名称
|
||||
/// </summary>
|
||||
public string UserName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 班级id
|
||||
|
|
|
|||
|
|
@ -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
|
|||
/// 学校名称
|
||||
/// </summary>
|
||||
public string SchoolName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// dto 处理的grade
|
||||
/// </summary>
|
||||
public string? _grade;
|
||||
/// <summary>
|
||||
/// 年级
|
||||
/// </summary>
|
||||
public string Grade { get; set; }
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
public string Grade
|
||||
{
|
||||
get => GradeHelper.GetGrade(GradeLevel, GradeYear);
|
||||
set => _grade = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 年级
|
||||
/// </summary>
|
||||
public int GradeYear { get; set; }
|
||||
public string GradeLevel { get; set; }
|
||||
/// <summary>
|
||||
/// 赴校人员 逗号分隔
|
||||
/// </summary>
|
||||
|
|
|
|||
Loading…
Reference in New Issue