tuiwucarrer/Admin.NET/Admin.NET.Application/Service/CePing/BusSpecialRecruitStudents/BusSpecialRecruitStudentsSe...

133 lines
5.4 KiB
C#

using Admin.NET.Core;
using Furion.DatabaseAccessor;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Furion.FriendlyException;
using Mapster;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks;
namespace Admin.NET.Application
{
/// <summary>
/// 特殊批次招生服务
/// </summary>
[ApiDescriptionSettings("测评服务", Name = "BusSpecialRecruitStudents", Order = 100)]
public class BusSpecialRecruitStudentsService : IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<BusSpecialRecruitStudents> _busSpecialRecruitStudentsRep;
/// <summary>
///
/// </summary>
/// <param name="busSpecialRecruitStudentsRep"></param>
public BusSpecialRecruitStudentsService(
SqlSugarRepository<BusSpecialRecruitStudents> busSpecialRecruitStudentsRep
)
{
_busSpecialRecruitStudentsRep = busSpecialRecruitStudentsRep;
}
/// <summary>
/// 分页查询特殊批次招生
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("page")]
[AllowAnonymous]
public async Task<SqlSugarPagedList<BusSpecialRecruitStudentsOutput>> Page([FromQuery] BusSpecialRecruitStudentsInput input)
{
var busSpecialRecruitStudentss = await _busSpecialRecruitStudentsRep.AsQueryable()
.WhereIF(!string.IsNullOrEmpty(input.Title), u => u.Title == input.Title)
.WhereIF(!string.IsNullOrEmpty(input.Pic), u => u.Pic == input.Pic)
.WhereIF(!string.IsNullOrEmpty(input.Summary), u => u.Summary == input.Summary)
.WhereIF(!string.IsNullOrEmpty(input.Url), u => u.Url == input.Url)
//.Where(u => u.Sort == input.Sort)
.OrderBy(u => u.CreateTime, OrderByType.Desc)
.OrderBuilder(input)
.Select(s => new BusSpecialRecruitStudentsOutput()
{
Title = s.Title,
Pic = s.Pic,
Summary = s.Summary,
Url = s.Url,
Ico = s.Ico,
Sort = s.Sort,
Id = s.Id
})
.ToPagedListAsync(input.Page, input.PageSize);
return busSpecialRecruitStudentss;
}
/// <summary>
/// 增加特殊批次招生
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("add")]
public async Task Add(AddBusSpecialRecruitStudentsInput input)
{
var busSpecialRecruitStudents = input.Adapt<BusSpecialRecruitStudents>();
await _busSpecialRecruitStudentsRep.InsertAsync(busSpecialRecruitStudents);
}
/// <summary>
/// 删除特殊批次招生
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("delete")]
public async Task Delete(DeleteBusSpecialRecruitStudentsInput input)
{
var busSpecialRecruitStudents = await _busSpecialRecruitStudentsRep.AsQueryable().FirstAsync(u => u.Id == input.Id);
await _busSpecialRecruitStudentsRep.FakeDeleteAsync(busSpecialRecruitStudents);
}
/// <summary>
/// 更新特殊批次招生
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("edit")]
public async Task Update(UpdateBusSpecialRecruitStudentsInput input)
{
var isExist = await _busSpecialRecruitStudentsRep.AsQueryable().AnyAsync(u => u.Id == input.Id);
if (!isExist) throw Oops.Oh(ErrorCodeEnum.D3000);
var busSpecialRecruitStudents = input.Adapt<BusSpecialRecruitStudents>();
await _busSpecialRecruitStudentsRep.UpdateAsync(busSpecialRecruitStudents);
}
/// <summary>
/// 获取特殊批次招生
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("detail")]
[AllowAnonymous]
public async Task<BusSpecialRecruitStudentsOutput> Get([FromQuery] QueryeBusSpecialRecruitStudentsInput input)
{
return (await _busSpecialRecruitStudentsRep.AsQueryable().FirstAsync(u => u.Id == input.Id)).Adapt<BusSpecialRecruitStudentsOutput>();
}
/// <summary>
/// 获取特殊批次招生列表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("list")]
[AllowAnonymous]
public async Task<List<BusSpecialRecruitStudentsOutput>> List([FromQuery] BusSpecialRecruitStudentsInput input)
{
return await _busSpecialRecruitStudentsRep.AsQueryable().Select<BusSpecialRecruitStudentsOutput>().ToListAsync();
}
}
}