tuiwucarrer/Admin.NET/Admin.NET.Application/Service/CePing/BusStudentScaleResults/BusStudentScaleResultsServi...

142 lines
5.5 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 = "BusStudentScaleResults", Order = 100)]
public class BusStudentScaleResultsService : IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<BusStudentScaleResults> _busStudentScaleResultsRep;
private readonly SqlSugarRepository<BusScale> _busScaleRep;
private readonly UserManager _userManager;
public BusStudentScaleResultsService(
SqlSugarRepository<BusScale> busScaleRep,
SqlSugarRepository<BusStudentScaleResults> busStudentScaleResultsRep,
UserManager userManager
)
{
_busScaleRep = busScaleRep;
_busStudentScaleResultsRep = busStudentScaleResultsRep;
_userManager = userManager;
}
/// <summary>
/// 分页查询学生量表结果表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("page")]
public async Task<SqlSugarPagedList<BusStudentScaleResultsOutput>> Page([FromQuery] BusStudentScaleResultsInput input)
{
var busStudentScaleResultss = await _busStudentScaleResultsRep.AsQueryable()
.Where(u => u.SysOauthUserId == input.SysOauthUserId)
.WhereIF(input.ScaleId > 0, u => u.ScaleId == input.ScaleId)
.WhereIF(!string.IsNullOrEmpty(input.Result), u => u.Result == input.Result)
.Where(u => u.TenantId == _userManager.TenantId)
.OrderBy(u => u.CreateTime, OrderByType.Desc)
.OrderBuilder(input)
.Select(s => new BusStudentScaleResultsOutput()
{
SysOauthUserId = s.SysOauthUserId,
ScaleId = s.ScaleId,
Result = s.Result,
TenantId = s.TenantId.Value,
Id = s.Id
})
.ToPagedListAsync(input.Page, input.PageSize);
return busStudentScaleResultss;
}
/// <summary>
/// 增加学生量表结果表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("add")]
public async Task Add(AddBusStudentScaleResultsInput input)
{
var busStudentScaleResults = input.Adapt<BusStudentScaleResults>();
await _busStudentScaleResultsRep.InsertAsync(busStudentScaleResults);
}
/// <summary>
/// 删除学生量表结果表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("delete")]
public async Task Delete(DeleteBusStudentScaleResultsInput input)
{
var busStudentScaleResults = await _busStudentScaleResultsRep.AsQueryable().FirstAsync(u => u.Id == input.Id);
await _busStudentScaleResultsRep.FakeDeleteAsync(busStudentScaleResults);
}
/// <summary>
/// 更新学生量表结果表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("edit")]
public async Task Update(UpdateBusStudentScaleResultsInput input)
{
var isExist = await _busStudentScaleResultsRep.AsQueryable().AnyAsync(u => u.Id == input.Id);
if (!isExist) throw Oops.Oh(ErrorCodeEnum.D3000);
var busStudentScaleResults = input.Adapt<BusStudentScaleResults>();
await _busStudentScaleResultsRep.UpdateAsync(busStudentScaleResults);
}
/// <summary>
/// 获取学生量表结果表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("detail")]
public async Task<BusStudentScaleResultsOutput> Get([FromQuery] QueryeBusStudentScaleResultsInput input)
{
return (await _busStudentScaleResultsRep.AsQueryable().FirstAsync(u => u.Id == input.Id)).Adapt<BusStudentScaleResultsOutput>();
}
/// <summary>
/// 获取学生量表结果表列表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("list")]
public async Task<List<BusStudentScaleResultsOutput>> List([FromQuery] BusStudentScaleResultsInput input)
{
return await _busStudentScaleResultsRep.AsQueryable().Select<BusStudentScaleResultsOutput>().ToListAsync();
}
/// <summary>
/// 获取BusScale列表
/// </summary>
/// <returns></returns>
[HttpGet("fkBusScale")]
public async Task<dynamic> FkBusScaleList()
{
var list = await _busScaleRep.AsQueryable().ToListAsync();
return list.Select(e => new { Code = e.Id, Name = e.Name });
}
}
}