From 0b67c773a4a9012c2cf8a7dc55347ef59c21b015 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?old=E6=98=93?= <156663459@qq.com> Date: Mon, 8 Jan 2024 16:48:35 +0800 Subject: [PATCH] feat:bug fixed --- .../Back/PlanMajorScoreLineController.cs | 46 ++++- New_College.Api/New_College.Model.xml | 10 ++ New_College.Api/New_College.xml | 7 + New_College.Common/Excel/ExcelProUtil.cs | 159 ++++++++++++++++++ New_College.Common/Excel/ExcelUtil.cs | 3 + .../Helper/MajorPlanScoreTool.cs | 6 +- .../ViewModels/PlanMajorScoreLineViewModel.cs | 16 ++ .../ViewModels/Query/VolunteerTableQuery.cs | 1 + .../ViewModels/Result/VolunteerTableResult.cs | 4 + .../BASE/T_EnrollmentPlanedescRepository.cs | 5 +- .../T_EnrollmentPlanedescServices.cs | 6 +- 11 files changed, 255 insertions(+), 8 deletions(-) create mode 100644 New_College.Common/Excel/ExcelProUtil.cs diff --git a/New_College.Api/Controllers/Back/PlanMajorScoreLineController.cs b/New_College.Api/Controllers/Back/PlanMajorScoreLineController.cs index e8caff2..e8a6385 100644 --- a/New_College.Api/Controllers/Back/PlanMajorScoreLineController.cs +++ b/New_College.Api/Controllers/Back/PlanMajorScoreLineController.cs @@ -11,6 +11,9 @@ using New_College.Model.ViewModels; using New_College.Services; using System.Linq; using SqlSugar; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using New_College.Common; namespace New_College.Api.Controllers { @@ -28,12 +31,53 @@ namespace New_College.Api.Controllers /// private readonly ID_PlanMajorScoreLineServices _d_PlanMajorScoreLineServices; - public PlanMajorScoreLineController(ID_PlanMajorScoreLineServices D_PlanMajorScoreLineServices) + /// + /// + /// + private readonly ID_ScoreLineServices id_coreLineServices; + public PlanMajorScoreLineController(ID_PlanMajorScoreLineServices D_PlanMajorScoreLineServices, ID_ScoreLineServices _ScoreLineServices) { _d_PlanMajorScoreLineServices = D_PlanMajorScoreLineServices; + id_coreLineServices = _ScoreLineServices; } + + + /// + /// 导入专业最低录取位次表=同步更新专业数据与学校专业分数线(--高考时可通用此功能) + /// + /// + /// + [HttpPost] + public async Task> ImportMajorData(IFormFile file) + { + var _list = new List(); + var list = ExcelProUtil.InputExcel(file); + //1. 查询匹配一分一段表数据 + + + + + + //2. 更新招生计划专业数据 + + + + //3. 更新学校最低专业录取线 + + + + // await _d_PlanMajorScoreLineServices.Add(_list); + return new MessageModel() + { + success = true, + response = true, + status = 200, + msg = "ok" + }; + } + /// /// 获取学校专业分数线 /// diff --git a/New_College.Api/New_College.Model.xml b/New_College.Api/New_College.Model.xml index ab951fc..a56c869 100644 --- a/New_College.Api/New_College.Model.xml +++ b/New_College.Api/New_College.Model.xml @@ -4040,6 +4040,11 @@ 专业组 + + + + + 测评类型 @@ -7025,6 +7030,11 @@ 学校logo + + + + + 办学性质 diff --git a/New_College.Api/New_College.xml b/New_College.Api/New_College.xml index dbbf8a1..79e3c59 100644 --- a/New_College.Api/New_College.xml +++ b/New_College.Api/New_College.xml @@ -163,6 +163,13 @@ 服务器接口,因为是模板生成,所以首字母是大写的,自己可以重构下 + + + 导入专业最低录取位次表=同步更新专业数据与学校专业分数线(--高考时可通用此功能) + + + + 获取学校专业分数线 diff --git a/New_College.Common/Excel/ExcelProUtil.cs b/New_College.Common/Excel/ExcelProUtil.cs new file mode 100644 index 0000000..d4e0d26 --- /dev/null +++ b/New_College.Common/Excel/ExcelProUtil.cs @@ -0,0 +1,159 @@ +using Microsoft.AspNetCore.Http; +using NPOI.SS.UserModel; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace New_College.Common +{ + public class ExcelProUtil where T : new() + { //合法文件扩展名 + private static List extName = new List() { ".xls", ".xlsx" }; + /// + /// 导入Excel内容读取到List中 + /// + /// 导入Execl文件 + /// 指定读取excel工作薄sheet的名称 + /// List + public static List InputExcel(IFormFile file, string sheetName = null) + { + //获取文件后缀名 + string type = Path.GetExtension(file.FileName); + //判断是否导入合法文件 + if (!extName.Contains(type)) + { + return null; + } + //转成为文件流 + MemoryStream ms = new MemoryStream(); + file.CopyTo(ms); + ms.Seek(0, SeekOrigin.Begin); + //实例化T数组 + List list = new List(); + //获取数据 + list = InputExcel(ms, sheetName); + return list; + } + + /// + /// 将Excel文件内容读取到List中 + /// + /// 文件完整路径名 + /// 指定读取excel工作薄sheet的名称 + /// List + public static List InputExcel(string fileName, string sheetName = null) + { + if (!File.Exists(fileName)) + { + return null; + } + //根据指定路径读取文件 + FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); + //实例化T数组 + List list = new List(); + //获取数据 + list = InputExcel(fs, sheetName); + + return list; + } + + /// + /// 将Excel文件内容读取到List中 + /// + /// 文件流 + /// 指定读取excel工作薄sheet的名称 + /// List + private static List InputExcel(Stream fileStream, string sheetName = null) + { + //创建Excel数据结构 + IWorkbook workbook = WorkbookFactory.Create(fileStream); + //如果有指定工作表名称 + ISheet sheet = null; + if (!string.IsNullOrEmpty(sheetName)) + { + sheet = workbook.GetSheet(sheetName); + //如果没有找到指定的sheetName对应的sheet,则尝试获取第一个sheet + if (sheet == null) + { + sheet = workbook.GetSheetAt(0); + } + } + else + { + //如果没有指定的sheetName,则尝试获取第一个sheet + sheet = workbook.GetSheetAt(0); + } + //实例化T数组 + List list = new List(); + if (sheet != null) + { + //一行最后一个cell的编号 即总的列数 + IRow cellNum = sheet.GetRow(0); + int num = cellNum.LastCellNum; + //获取泛型对象T的所有属性 + var propertys = typeof(T).GetProperties(); + //每行转换为单个T对象 + for (int i = 1; i <= sheet.LastRowNum; i++) + { + IRow row = sheet.GetRow(i); + var obj = new T(); + for (int j = 0; j < num; j++) + { + //没有数据的单元格都默认是null + ICell cell = row.GetCell(j); + if (cell != null) + { + var value = row.GetCell(j).ToString(); + string str = (propertys[j].PropertyType).FullName; + if (str == "System.String") + { + propertys[j].SetValue(obj, value, null); + } + else if (str == "System.DateTime") + { + DateTime pdt = Convert.ToDateTime(value, CultureInfo.InvariantCulture); + propertys[j].SetValue(obj, pdt, null); + } + else if (str == "System.Boolean") + { + bool pb = Convert.ToBoolean(value); + propertys[j].SetValue(obj, pb, null); + } + else if (str == "System.Int16") + { + short pi16 = Convert.ToInt16(value); + propertys[j].SetValue(obj, pi16, null); + } + else if (str == "System.Int32") + { + int pi32 = Convert.ToInt32(value); + propertys[j].SetValue(obj, pi32, null); + } + else if (str == "System.Int64") + { + long pi64 = Convert.ToInt64(value); + propertys[j].SetValue(obj, pi64, null); + } + else if (str == "System.Byte") + { + byte pb = Convert.ToByte(value); + propertys[j].SetValue(obj, pb, null); + } + else + { + propertys[j].SetValue(obj, null, null); + } + } + } + list.Add(obj); + } + } + return list; + } + } + +} diff --git a/New_College.Common/Excel/ExcelUtil.cs b/New_College.Common/Excel/ExcelUtil.cs index d220b5f..e1cadd3 100644 --- a/New_College.Common/Excel/ExcelUtil.cs +++ b/New_College.Common/Excel/ExcelUtil.cs @@ -139,5 +139,8 @@ namespace New_College.Common.Excel } return dt; } + + + } } diff --git a/New_College.Common/Helper/MajorPlanScoreTool.cs b/New_College.Common/Helper/MajorPlanScoreTool.cs index 1e5b1e6..bb8a961 100644 --- a/New_College.Common/Helper/MajorPlanScoreTool.cs +++ b/New_College.Common/Helper/MajorPlanScoreTool.cs @@ -10,7 +10,7 @@ namespace New_College.Common /// - /// 冲稳保百分比 + /// 冲稳保百分比(逻辑待调整) /// /// /// @@ -27,7 +27,7 @@ namespace New_College.Common } /// - /// 冲稳保计算 + /// 冲稳保计算(逻辑待调整) /// /// /// @@ -36,7 +36,7 @@ namespace New_College.Common int minscore = requestScore - 15;//最小 int constscore = requestScore;//中位数 int maxscore = requestScore + 15;//最大 - int type = LowScore <= minscore ? 0 : minscore < LowScore && LowScore <= constscore ? 1 : LowScore > constscore && LowScore <= maxscore ? 2 : -1; + int type = LowScore <= minscore ? 0 : minscore < LowScore && LowScore <= constscore ? 1 : LowScore > constscore && LowScore <= maxscore ? 2 : 0; return type; diff --git a/New_College.Model/ViewModels/PlanMajorScoreLineViewModel.cs b/New_College.Model/ViewModels/PlanMajorScoreLineViewModel.cs index b432b55..f8f7f25 100644 --- a/New_College.Model/ViewModels/PlanMajorScoreLineViewModel.cs +++ b/New_College.Model/ViewModels/PlanMajorScoreLineViewModel.cs @@ -85,4 +85,20 @@ namespace New_College.Model.ViewModels } + + + + + /// + /// + /// + public class ImportPlanMajorScoreRequest + { + public string Major { get; set; } + public string UniversityName { get; set; } + public string PlanCount { get; set; } + public string LowScoreRank { get; set; } + } + + } diff --git a/New_College.Model/ViewModels/Query/VolunteerTableQuery.cs b/New_College.Model/ViewModels/Query/VolunteerTableQuery.cs index e889e1f..ec3d317 100644 --- a/New_College.Model/ViewModels/Query/VolunteerTableQuery.cs +++ b/New_College.Model/ViewModels/Query/VolunteerTableQuery.cs @@ -8,6 +8,7 @@ namespace New_College.Model.ViewModels { public int CustomerId { get; set; } + public int? Score { get; set; } public List details { get; set; } } diff --git a/New_College.Model/ViewModels/Result/VolunteerTableResult.cs b/New_College.Model/ViewModels/Result/VolunteerTableResult.cs index df6d3f5..edbb750 100644 --- a/New_College.Model/ViewModels/Result/VolunteerTableResult.cs +++ b/New_College.Model/ViewModels/Result/VolunteerTableResult.cs @@ -101,6 +101,10 @@ namespace New_College.Model.ViewModels /// public string Remark { get; set; } + public int Type { get; set; } + + public int Percentage { get; set; } + } /// diff --git a/New_College.Repository/BASE/T_EnrollmentPlanedescRepository.cs b/New_College.Repository/BASE/T_EnrollmentPlanedescRepository.cs index 26ce622..5254122 100644 --- a/New_College.Repository/BASE/T_EnrollmentPlanedescRepository.cs +++ b/New_College.Repository/BASE/T_EnrollmentPlanedescRepository.cs @@ -97,7 +97,8 @@ namespace New_College.Repository .Select(p => new UniversityEnrollmentPlanResult() { UniversityId = p.UId, - PlanId = p.Id + PlanId = p.Id, + // Scoreline = p.LowScore }) .ToListAsync(); var universitylist = recommendInfo.Select(c => c.UniversityId).Distinct().ToList(); @@ -106,7 +107,7 @@ namespace New_College.Repository response.Add(new UniversityMapMajorItems() { UId = a, - MIds = recommendInfo.Where(e => e.UniversityId == a && e.Scoreline > 0).Select(c => c.PlanId).ToList() + MIds = recommendInfo.Where(e => e.UniversityId == a).Select(c => c.PlanId).ToList() }); }); return new MessageModel>() { response = response }; diff --git a/New_College.Services/T_EnrollmentPlanedescServices.cs b/New_College.Services/T_EnrollmentPlanedescServices.cs index 34be93f..8476adc 100644 --- a/New_College.Services/T_EnrollmentPlanedescServices.cs +++ b/New_College.Services/T_EnrollmentPlanedescServices.cs @@ -1255,7 +1255,7 @@ namespace New_College.Services Syl = nowuniversityinfo.Syl > 0, UniversityId = item.UniversityId, UniversityName = item.UniversityName, - UniversityCode = nowdesc.Any()?nowdesc.FirstOrDefault().EnrollmentCode:"", + UniversityCode = nowdesc.Any() ? nowdesc.FirstOrDefault().EnrollmentCode : "", Province = nowuniversityinfo.Area_Name, Nature = nowuniversityinfo.Nature, Infos = nowdesc.Select(x => new PlanInfo() @@ -1267,7 +1267,9 @@ namespace New_College.Services PlanNum = x.PlanCount, Scoreline = x.LowScore == 0 ? "-" : x.LowScore.ToString(), LowScoreRank = x.LowScoreRank == 0 ? "-" : x.LowScoreRank.ToString(), - YearName = yearName + YearName = yearName, + Type = query.Score.HasValue ? MajorPlanScoreTool.GetPlanScore(x.LowScore, query.Score.Value) : 0,//还缺冲稳保 + Percentage = query.Score.HasValue ? MajorPlanScoreTool.GetPlanPercentage(x.LowScore, query.Score.Value) : 0, }).ToList() }); }