using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using New_College.IServices;
using New_College.Model;
using New_College.Model.Models;
using New_College.Model.ViewModels.Query;
using New_College.Model.ViewModels.Result;
using SqlSugar;
namespace New_College.Api.Controllers.Front
{
///
///招生计划
///
[Route("api/front/[controller]/[action]")]
[ApiController]
public class EnrollMentPlansController : ControllerBase
{
private readonly IT_EnrollmentPlaneServices t_EnrollmentPlane;
private readonly IT_EnrollmentBatchServices t_EnrollmentBatch;
private readonly ID_PlanMajorDescServices d_PlanMajorDesc;
public EnrollMentPlansController(IT_EnrollmentPlaneServices enrollmentPlaneServices, IT_EnrollmentBatchServices t_EnrollmentBatchServices, ID_PlanMajorDescServices d_PlanMajorDesc)
{
this.t_EnrollmentPlane = enrollmentPlaneServices;
this.t_EnrollmentBatch = t_EnrollmentBatchServices;
this.d_PlanMajorDesc = d_PlanMajorDesc;
}
///
/// 根据院校和专业获取招生计划列表
///
///
///
[HttpGet]
public async Task>> GetEnrollmentPlans([FromQuery] EnrollmentPlanRequest request)
{
try
{
request.Years = request.Years >= 2023 ? 2023 : request.Years;
Expression> whereexp = Expressionable.Create() //创建表达式
.And(c => c.Location == request.Location)
.And(c => c.Years == request.Years)
.AndIF(!string.IsNullOrEmpty(request.BatchName), w => w.BatchName == request.BatchName)
.AndIF(!string.IsNullOrEmpty(request.UniversityName), w => SqlFunc.Contains(w.UniversityName, request.UniversityName))
.AndIF(!string.IsNullOrEmpty(request.MajorName), w => SqlFunc.Contains(w.Major, request.MajorName)).ToExpression();
var pageModel = await this.d_PlanMajorDesc.QueryPage(whereexp, request.PageIndex, request.PageSize);
if (pageModel.dataCount > 0)
{
return new MessageModel>()
{
response = pageModel,
success = true,
msg = "ok",
status = 200
};
}
else
{
return new MessageModel>()
{
msg = "相关信息更新中...",
};
}
//var planinfo = await this.t_EnrollmentPlane.Query(e => e.IsDelete == false && e.Area_Id == request.AreaId && e.Years == request.Years);
//if (planinfo.Any())
//{
// var BatchtypeId = (await this.t_EnrollmentBatch.Query(e => e.Year == request.Years && e.AreaId == request.AreaId && e.Batch_name == request.BatchName)).FirstOrDefault().Id;
// request.PlanId = planinfo.FirstOrDefault().Id;
// request.BatchtypeId = BatchtypeId;
// var result = await this.t_EnrollmentPlane.GetEnrollmentPlans(request);
// return new MessageModel>()
// {
// msg = "success",
// response = result,
// success = true
// };
//}
//else
//{
// return new MessageModel>()
// {
// msg = "相关信息更新中...",
// };
//}
}
catch (Exception ex)
{
return new MessageModel>()
{
msg = ex.Message
};
}
}
}
}