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

198 lines
7.3 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;
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;
/// <summary>
///
/// </summary>
private readonly ID_ScoreLineServices id_coreLineServices;
public PlanMajorScoreLineController(ID_PlanMajorScoreLineServices D_PlanMajorScoreLineServices, ID_ScoreLineServices _ScoreLineServices, ID_PlanMajorDescServices d_PlanMajorDescServices)
{
_d_PlanMajorScoreLineServices = D_PlanMajorScoreLineServices;
id_coreLineServices = _ScoreLineServices;
_d_PlanMajorDescServices = d_PlanMajorDescServices;
}
/// <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="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)
.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,
Years = c.Years,
FirstType = c.FirstType,
HighScore = c.HighScore,
Major = c.Major,
MajorGroup = c.MajorGroup,
Remark = c.Remark,
SelectSubject = c.SelectSubject,
}).ToList();
return new MessageModel<List<PlanMajorScoreLineResponse>>()
{
msg = "获取成功",
success = true,
response = response
};
}
}
}