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 { /// /// 学生量表结果表服务 /// [ApiDescriptionSettings("测评服务", Name = "BusStudentScaleResults", Order = 100)] public class BusStudentScaleResultsService : IDynamicApiController, ITransient { private readonly SqlSugarRepository _busStudentScaleResultsRep; private readonly SqlSugarRepository _busScaleRep; private readonly UserManager _userManager; public BusStudentScaleResultsService( SqlSugarRepository busScaleRep, SqlSugarRepository busStudentScaleResultsRep, UserManager userManager ) { _busScaleRep = busScaleRep; _busStudentScaleResultsRep = busStudentScaleResultsRep; _userManager = userManager; } /// /// 分页查询学生量表结果表 /// /// /// [HttpGet("page")] public async Task> 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; } /// /// 增加学生量表结果表 /// /// /// [HttpPost("add")] public async Task Add(AddBusStudentScaleResultsInput input) { var busStudentScaleResults = input.Adapt(); await _busStudentScaleResultsRep.InsertAsync(busStudentScaleResults); } /// /// 删除学生量表结果表 /// /// /// [HttpPost("delete")] public async Task Delete(DeleteBusStudentScaleResultsInput input) { var busStudentScaleResults = await _busStudentScaleResultsRep.AsQueryable().FirstAsync(u => u.Id == input.Id); await _busStudentScaleResultsRep.FakeDeleteAsync(busStudentScaleResults); } /// /// 更新学生量表结果表 /// /// /// [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(); await _busStudentScaleResultsRep.UpdateAsync(busStudentScaleResults); } /// /// 获取学生量表结果表 /// /// /// [HttpGet("detail")] public async Task Get([FromQuery] QueryeBusStudentScaleResultsInput input) { return (await _busStudentScaleResultsRep.AsQueryable().FirstAsync(u => u.Id == input.Id)).Adapt(); } /// /// 获取学生量表结果表列表 /// /// /// [HttpGet("list")] public async Task> List([FromQuery] BusStudentScaleResultsInput input) { return await _busStudentScaleResultsRep.AsQueryable().Select().ToListAsync(); } /// /// 获取BusScale列表 /// /// [HttpGet("fkBusScale")] public async Task FkBusScaleList() { var list = await _busScaleRep.AsQueryable().ToListAsync(); return list.Select(e => new { Code = e.Id, Name = e.Name }); } } }