diff --git a/New_College.Api/Controllers/Front/LibraryController.cs b/New_College.Api/Controllers/Front/LibraryController.cs index 92e9711..8bb7dcd 100644 --- a/New_College.Api/Controllers/Front/LibraryController.cs +++ b/New_College.Api/Controllers/Front/LibraryController.cs @@ -644,6 +644,7 @@ namespace New_College.Api.Controllers.Front } + } diff --git a/New_College.Api/Controllers/Front/UniversityRankController.cs b/New_College.Api/Controllers/Front/UniversityRankController.cs index 4107aca..203233e 100644 --- a/New_College.Api/Controllers/Front/UniversityRankController.cs +++ b/New_College.Api/Controllers/Front/UniversityRankController.cs @@ -10,6 +10,9 @@ using System.Collections.Generic; using Microsoft.Graph; using System; using System.Linq; +using SqlSugar; +using New_College.Common.Helper; +using NPOI.OpenXmlFormats.Spreadsheet; namespace New_College.Api.Controllers { @@ -22,10 +25,11 @@ namespace New_College.Api.Controllers public class UniversityRankController : ControllerBase { private readonly ID_UniversityRankRepository _UniversityRankRepository; - public UniversityRankController(ID_UniversityRankRepository d_UniversityRankRepository) + private readonly ID_UniversityServices _UniversityServices; + public UniversityRankController(ID_UniversityRankRepository d_UniversityRankRepository, ID_UniversityServices universityServices) { _UniversityRankRepository = d_UniversityRankRepository; - + _UniversityServices = universityServices; } @@ -39,16 +43,16 @@ namespace New_College.Api.Controllers { if (string.IsNullOrWhiteSpace(single.UniversityName)) { - return new MessageModel> () + return new MessageModel>() { msg = "fail", success = false, status = 200 }; } - string years = (DateTime.Now.Year-1).ToString(); + string years = (DateTime.Now.Year - 1).ToString(); var query = await _UniversityRankRepository.Query(c => c.Year == years && c.UniversityName == single.UniversityName); - return new MessageModel> () + return new MessageModel>() { response = query.Select(c => new SingleUniversityResponseView() { @@ -63,5 +67,35 @@ namespace New_College.Api.Controllers } + /// + /// 获取院校下拉接口 + /// + /// + [HttpGet] + public async Task> GetUniversitySelect() + { + + var query = (await _UniversityServices.Query(e => e.IsDelete == false)).Select(c => new UniversityTreeDto { id = c.Id, name = c.Name.Trim(), url = c.Logo, checkd = false, FirstWord = GetFirstLetterHelper.GetFirstLetterOfChinese(c.Name) }).ToList(); + var str = "ABCDEFGHJKLMNOPQRSTWXYZ"; + var list = new List(); + + for (int i = 0; i < str.Length; i++) + { + if (query.Any(e => e.FirstWord == str[i].ToString())) + { + list.Add(query.Where(e => e.FirstWord == str[i].ToString()).ToList()); + } + } + + + return new MessageModel() + { + response = list, + success = true, + msg = "ok" + + }; + } + } } diff --git a/New_College.Api/New_College.xml b/New_College.Api/New_College.xml index 1a8ac19..67c3201 100644 --- a/New_College.Api/New_College.xml +++ b/New_College.Api/New_College.xml @@ -1106,6 +1106,12 @@ + + + 获取院校下拉接口 + + + 小鹅通 diff --git a/New_College.Common/Helper/GetFirstLetterHelper.cs b/New_College.Common/Helper/GetFirstLetterHelper.cs new file mode 100644 index 0000000..37307a5 --- /dev/null +++ b/New_College.Common/Helper/GetFirstLetterHelper.cs @@ -0,0 +1,31 @@ +using hyjiacan.py4n; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace New_College.Common.Helper +{ + public static class GetFirstLetterHelper + { + + + public static string GetFirstLetterOfChinese(string chinese) + { // 设置拼音输出格式 + PinyinFormat format = PinyinFormat.WITHOUT_TONE | PinyinFormat.LOWERCASE | PinyinFormat.WITH_U_UNICODE; + if (string.IsNullOrWhiteSpace(chinese)) + { + return string.Empty; + } + char china = chinese.Trim()[0]; + // 取指定汉字的唯一或者第一个拼音 + var pinyin =Pinyin4Net.GetFirstPinyin(china, format); + if (pinyin != null && pinyin.Length > 0) + { + return pinyin[0].ToString().ToUpper(); // 取首字母并转为大写 + } + return string.Empty; + } + } +} diff --git a/New_College.Common/New_College.Common.csproj b/New_College.Common/New_College.Common.csproj index dcd62b9..788b6b9 100644 --- a/New_College.Common/New_College.Common.csproj +++ b/New_College.Common/New_College.Common.csproj @@ -13,6 +13,7 @@ + diff --git a/New_College.Model/ViewModels/Result/uniMajorSecond.cs b/New_College.Model/ViewModels/Result/uniMajorSecond.cs index ae0d7bf..23d8503 100644 --- a/New_College.Model/ViewModels/Result/uniMajorSecond.cs +++ b/New_College.Model/ViewModels/Result/uniMajorSecond.cs @@ -9,6 +9,7 @@ namespace New_College.Model.ViewModels public class uniMajorSelect { + public int pid { get; set; } public int Id { get; set; } public string Name { get; set; } public string Code { get; set; } @@ -42,6 +43,7 @@ namespace New_College.Model.ViewModels public string MajorName { get; set; } public int MajorNum { get; set; } + public List majorSelects { get; set; } } diff --git a/New_College.Model/ViewModels/SingleUniversityView.cs b/New_College.Model/ViewModels/SingleUniversityView.cs index 1d9135b..5b0f7e9 100644 --- a/New_College.Model/ViewModels/SingleUniversityView.cs +++ b/New_College.Model/ViewModels/SingleUniversityView.cs @@ -28,4 +28,16 @@ namespace New_College.Model } + public class UniversityTreeDto + { + public int id { get; set; } + public string name { get; set; } + public string url { get; set; } + public bool checkd { get; set; } + + + public string FirstWord { get; set; } + + } + } diff --git a/New_College.Services/D_LongIdMapServices.cs b/New_College.Services/D_LongIdMapServices.cs index 6a67fb9..5b41b1b 100644 --- a/New_College.Services/D_LongIdMapServices.cs +++ b/New_College.Services/D_LongIdMapServices.cs @@ -206,7 +206,7 @@ namespace New_College.Services .ToExpression(); var majorcategories = (await d_MajorCategoryRepository.Query(x => x.Type == query.SchoolLevel && x.IsDelete == false)).Select(x => new uniMajorSelect() { Id = x.Id, Name = x.Name }); ; var majorclasses = (await d_MajorClassRepository.Query(x => x.IsDelete == false)).Select(x => new uniMajorClassSelect() { Id = x.Id, Name = x.Name, TradeId = x.TradeId }); - var majorinfo = (await d_MajorRepository.Query(expression)).Select(s => new uniMajorSelect() { Id = s.CategoryClass_Id, Name = s.Name }).ToList(); + var majorinfo = (await d_MajorRepository.Query(expression)).Select(s => new uniMajorSelect() { pid = s.CategoryClass_Id, Id = s.Id, Name = s.Name }).ToList(); List list = new List() { }; foreach (var item in majorcategories) { @@ -216,7 +216,9 @@ namespace New_College.Services { MajorName = s.Name, SecondId = s.Id, - MajorNum = majorinfo.Count(x => x.Name != s.Name && x.Id == s.Id), + MajorNum = majorinfo.Count(x => x.Name != s.Name && x.pid == s.Id), + majorSelects = majorinfo.Where(x => x.Name != s.Name && x.pid == s.Id).ToList() + }).ToList(); if (scond.Count() > 0)