126 lines
4.7 KiB
C#
126 lines
4.7 KiB
C#
using Admin.NET.Core;
|
|
using Furion.DatabaseAccessor;
|
|
using Furion.DependencyInjection;
|
|
using Furion.DynamicApiController;
|
|
using Furion.FriendlyException;
|
|
using Mapster;
|
|
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 = "BusStudyYears", Order = 100)]
|
|
public class BusStudyYearsService : IDynamicApiController, ITransient
|
|
{
|
|
private readonly SqlSugarRepository<BusStudyYears> _busStudyYearsRep;
|
|
private readonly UserManager _userManager;
|
|
public BusStudyYearsService(
|
|
SqlSugarRepository<BusStudyYears> busStudyYearsRep,
|
|
UserManager userManager
|
|
)
|
|
{
|
|
_busStudyYearsRep = busStudyYearsRep;
|
|
_userManager = userManager;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 分页查询学年表
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("page")]
|
|
public async Task<SqlSugarPagedList<BusStudyYearsOutput>> Page([FromQuery] BusStudyYearsInput input)
|
|
{
|
|
var busStudyYearss = await _busStudyYearsRep.AsQueryable()
|
|
.WhereIF(!string.IsNullOrEmpty(input.Name), u => u.Name == input.Name)
|
|
//.Where(u => u.StartDays == input.StartDays)
|
|
//.Where(u => u.EndDays == input.EndDays)
|
|
//.Where(u => u.Status == input.Status)
|
|
//.Where(u => u.Sort == input.Sort)
|
|
.Where(u => u.TenantId == _userManager.TenantId)
|
|
.OrderBy(u => u.CreateTime, OrderByType.Desc)
|
|
.OrderBuilder(input)
|
|
.Select(s=>new BusStudyYearsOutput() {
|
|
Name=s.Name,
|
|
StartDays=s.StartDays,
|
|
EndDays=s.EndDays,
|
|
Status=s.Status,
|
|
Sort=s.Sort,
|
|
TenantId=s.TenantId.Value,
|
|
Id=s.Id
|
|
})
|
|
.ToPagedListAsync(input.Page, input.PageSize);
|
|
|
|
return busStudyYearss;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 增加学年表
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("add")]
|
|
public async Task Add(AddBusStudyYearsInput input)
|
|
{
|
|
var busStudyYears = input.Adapt<BusStudyYears>();
|
|
await _busStudyYearsRep.InsertAsync(busStudyYears);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除学年表
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("delete")]
|
|
public async Task Delete(DeleteBusStudyYearsInput input)
|
|
{
|
|
var busStudyYears = await _busStudyYearsRep.AsQueryable().FirstAsync(u => u.Id == input.Id);
|
|
await _busStudyYearsRep.FakeDeleteAsync(busStudyYears);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新学年表
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("edit")]
|
|
public async Task Update(UpdateBusStudyYearsInput input)
|
|
{
|
|
var isExist = await _busStudyYearsRep.AsQueryable().AnyAsync(u => u.Id == input.Id);
|
|
if (!isExist) throw Oops.Oh(ErrorCodeEnum.D3000);
|
|
|
|
var busStudyYears = input.Adapt<BusStudyYears>();
|
|
await _busStudyYearsRep.UpdateAsync(busStudyYears);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取学年表
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("detail")]
|
|
public async Task<BusStudyYearsOutput> Get([FromQuery] QueryeBusStudyYearsInput input)
|
|
{
|
|
return (await _busStudyYearsRep.AsQueryable().FirstAsync(u => u.Id == input.Id)).Adapt<BusStudyYearsOutput>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取学年表列表
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("list")]
|
|
public async Task<List<BusStudyYearsOutput>> List([FromQuery] BusStudyYearsInput input)
|
|
{
|
|
return await _busStudyYearsRep.AsQueryable().Select<BusStudyYearsOutput>().ToListAsync();
|
|
}
|
|
|
|
}
|
|
}
|