NewGaoKaoApi/New_College.Api/Controllers/Back/PlanMajorScoreLineControlle...

317 lines
13 KiB
C#

using New_College.IServices;
using New_College.Model;
using New_College.Model.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Linq.Expressions;
using System.Threading.Tasks;
using System.Collections.Generic;
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;
using New_College.Common.Helper;
using System.Security.Cryptography.Xml;
namespace New_College.Api.Controllers
{
/// <summary>
/// 专业分数线
/// </summary>
[Route("api/[controller]/[action]")]
[ApiController]
[Authorize]
public class PlanMajorScoreLineController : ControllerBase
{
/// <summary>
/// 服务器接口,因为是模板生成,所以首字母是大写的,自己可以重构下
/// </summary>
private readonly ID_PlanMajorScoreLineServices _d_PlanMajorScoreLineServices;
private readonly ID_PlanMajorDescServices _d_PlanMajorDescServices;
private readonly ID_UniversityServices _d_UniversityServices;
private readonly ID_QualificationLineServices _d_QualificationLineServices;
/// <summary>
///
/// </summary>
private readonly ID_ScoreLineServices id_coreLineServices;
public PlanMajorScoreLineController(ID_PlanMajorScoreLineServices D_PlanMajorScoreLineServices, ID_ScoreLineServices _ScoreLineServices, ID_PlanMajorDescServices d_PlanMajorDescServices, ID_UniversityServices _UniversityServices, ID_QualificationLineServices d_QualificationLineServices)
{
_d_PlanMajorScoreLineServices = D_PlanMajorScoreLineServices;
id_coreLineServices = _ScoreLineServices;
_d_PlanMajorDescServices = d_PlanMajorDescServices;
_d_UniversityServices = _UniversityServices;
_d_QualificationLineServices = d_QualificationLineServices;
}
/// <summary>
/// 导入各个省份一分一段表数据
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
[HttpPost]
public async Task<MessageModel<bool>> ImportScoreLine(IFormFile file)
{
try
{
var list = ExcelProUtil<ScoreLineRepDto>.InputExcel(file);
var modelist = new List<D_ScoreLine>();
list.ForEach(a =>
{
modelist.Add(new D_ScoreLine()
{
Count = a.Count,
CreateTime = DateTime.Now,
IsDelete = false,
ModifyTime = DateTime.Now,
OrderSort = 0,
Province = a.Province,
Score = a.ScoreRegion,
SumCount = a.SumCountStart,
Type = a.Type,
Years = a.Years
});
});
bool status = await id_coreLineServices.Add(modelist) > 0;
return new MessageModel<bool>()
{
response = status,
success = true
};
}
catch (Exception ex)
{
return new MessageModel<bool>()
{
success = false,
response = false,
msg = ex.Message.ToString()
};
}
}
/// <summary>
/// 导入专业最低录取位次表=同步更新专业数据与学校专业分数线(--高考时可通用此功能)
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
[HttpPost]
public async Task<MessageModel<bool>> ImportMajorData(IFormFile file)
{
var rrr = new List<ScoreLineRepDto>();
var _list = new List<D_PlanMajorScoreLine>();
var list = ExcelProUtil<ImportPlanMajorScoreRequest>.InputExcel(file);
var planmajorlist = await _d_PlanMajorDescServices.Query(c => c.Years == 2023 && c.Location == "山东省" && c.IsDelete == false && c.BatchName.Contains("普通类"));
//1. 查询匹配一分一段表数据
var query = await id_coreLineServices.Query(c => c.Years == "2023" && c.Province == "山东省");
for (int i = 0; i < query.Count(); i++)
{
rrr.Add(new ScoreLineRepDto()
{
Count = query[i].Count,
Province = query[i].Province,
Score = query[i].Score,
Type = query[i].Type,
SumCountStart = i == 0 ? 1 : query[i - 1].SumCount + 1,
SumCountEnd = i == 0 ? query[i].SumCount : query[i].SumCount,
Years = query[i].Years,
});
}
list.OrderBy(c => c.LowScoreRank).ToList().ForEach(a =>
{
_list.Add(new D_PlanMajorScoreLine()
{
IsDelete = false,
Location = "山东省",
Major = a.Major,
CreateTime = DateTime.Now,
ModifyTime = DateTime.Now,
OrderSort = 1,
PlanCount = a.PlanCount,
LowScoreRank = a.LowScoreRank,
Years = 2023,
UniversityName = a.UniversityName,
LowScore = a.LowScoreRank <= 62 ? 697 : rrr.Where(e => e.SumCountStart >= a.LowScoreRank || e.SumCountEnd >= a.LowScoreRank).Any() ? rrr.Where(e => e.SumCountStart >= a.LowScoreRank || e.SumCountEnd >= a.LowScoreRank).FirstOrDefault().Score.ObjToInt() : 0
});
});
_list.ForEach(a =>
{
var isany = planmajorlist.Where(e => e.UniversityName == a.UniversityName).Any();
if (isany)
{
var tmpmodel = planmajorlist.Where(e => e.UniversityName == a.UniversityName && e.Major == a.Major).FirstOrDefault();
a.SelectSubject = tmpmodel.SelectSubject;
a.UId = tmpmodel.UId;
a.FirstType = tmpmodel.FirstType == null ? "" : tmpmodel.FirstType;
a.RootType = tmpmodel.RootType == null ? "" : tmpmodel.RootType;
a.PlanCount = tmpmodel.PlanCount;
}
a.BatchName = a.LowScore < 443 ? "普通类二段" : "普通类一段";
});
//2. 更新招生计划专业数据
//3. 新增学校最低专业录取线
await _d_PlanMajorScoreLineServices.Add(_list);
planmajorlist.ForEach(a =>
{
var achany = _list.Where(e => e.Major == a.Major && e.UId == a.UId).Any();
if (achany)
{
var achanymodel = _list.Where(e => e.Major == a.Major && e.UId == a.UId).FirstOrDefault();
a.LowScore = achanymodel.LowScore;
a.LowScoreRank = achanymodel.LowScoreRank;
}
});
await _d_PlanMajorDescServices.Batchupdate(planmajorlist);
return new MessageModel<bool>()
{
success = true,
response = true,
status = 200,
msg = "ok"
};
}
/// <summary>
/// 更新院校最低分数
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
[HttpPost]
public async Task<MessageModel<bool>> UpdateUniversityScoreData(IFormFile file)
{
var universityinfo = await _d_UniversityServices.Query(w => w.IsDelete == false); //院校信息
var planMajorScoreLine = await _d_PlanMajorScoreLineServices.Query(w => w.IsDelete == false && w.Location == "山东省" && w.Years == 2023);//专业分数
var qualificationLinelist = await _d_QualificationLineServices.Query(w => w.IsDelete == false && w.Location == "山东省" && w.Years == 2023);//院校分数
var mmlist = new List<D_QualificationLine>();
//先循环所有学校 --然后根据学校找到院校最低分数,再通过分数更新院校数据
universityinfo.ForEach(async
u =>
{
var plist = planMajorScoreLine.Where(e => e.UId == u.Id);
//if (qualificationLinelist.Where(e => e.UId == u.Id).Any())
//{
// var tmp = qualificationLinelist.Where(e => e.UId == u.Id).FirstOrDefault();
if (plist.Any())
{
mmlist.Add(new D_QualificationLine()
{
LowScore = plist.Min(m => m.LowScore),
LowScoreRank = plist.Min(m => m.LowScoreRank),
AreaName = u.Area_Name,
BatchName = plist.FirstOrDefault().BatchName,
CreateTime = plist.FirstOrDefault().CreateTime,
EducationType = u.Subject_Level == 0 ? "本科" : "专科",
Location = "山东省",
IsDelete = false,
ModifyTime = plist.FirstOrDefault().ModifyTime,
Nature = u.Nature == 0 ? "公办" : u.Nature == 1 ? "民办" : u.Nature == 2 ? "中外合作办学" : "港澳台",
Ownership = u.Ascription == 1 ? "教育部" : u.Ascription == 2 ? "地方政府" : u.Ascription == 3 ? "其他部委" : "军校",
RecruitCode = int.Parse(u.UniversityCode),
OrderSort = 1,
UniversityName = u.Name,
SubjectType = "综合",
RecruitType = u.Nature <= 1 ? "普通类" : u.Nature == 2 ? "中外合作办学" : "普通类",
UId = u.Id,
Years = plist.FirstOrDefault().Years,
_211 = u.Sff == 1 ? "是" : "否",
_985 = u.Nhef == 1 ? "是" : "否",
_SYL = u.Syl == 1 ? "是" : "否",
});
}
//await _d_QualificationLineServices.Add(tmp);
//}
});
await _d_QualificationLineServices.Add(mmlist);
return new MessageModel<bool>()
{
status = 200,
success = true,
response = true,
};
}
/// <summary>
/// 获取学校专业分数线
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpGet]
public async Task<MessageModel<List<PlanMajorScoreLineResponse>>> Get([FromQuery] PlanMajorScoreLineRequest request)
{
if (request.Uid <= 0)
{
return new MessageModel<List<PlanMajorScoreLineResponse>>()
{
success = false,
msg = "uid必传"
};
}
Expression<Func<D_PlanMajorScoreLine, bool>> expression = Expressionable.Create<D_PlanMajorScoreLine>()
.And(c => c.UId == request.Uid)
.And(c => c.IsDelete == false)
.AndIF(!string.IsNullOrWhiteSpace(request.BatchName), c => c.BatchName == request.BatchName)
.AndIF(request.Year.HasValue && request.Year > 0, c => c.Years == request.Year)
.ToExpression();
var response = (await _d_PlanMajorScoreLineServices.Query(expression))
.Select(c => new PlanMajorScoreLineResponse()
{
BatchName = c.BatchName,
UId = request.Uid,
LowScore = c.LowScore,
LowScoreRank = c.LowScoreRank,
AvgScore = c.AvgScore != "-" ? int.Parse(c.AvgScore) <= c.LowScore ? "-" : c.AvgScore : "-",
Years = c.Years,
FirstType = c.FirstType,
HighScore = c.HighScore,
Major = c.Major,
MajorGroup = c.MajorGroup,
Remark = c.Remark,
SelectSubject = c.SelectSubject,
}).OrderByDescending(c => c.Years).ToList();
return new MessageModel<List<PlanMajorScoreLineResponse>>()
{
msg = "获取成功",
success = true,
response = response
};
}
}
}