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 = "BusScaleQuestions", Order = 100)] public class BusScaleQuestionsService : IDynamicApiController, ITransient { private readonly SqlSugarRepository _busScaleQuestionsRep; private readonly SqlSugarRepository _busScaleRep; private readonly UserManager _userManager; public BusScaleQuestionsService( SqlSugarRepository busScaleRep, SqlSugarRepository busScaleQuestionsRep, UserManager userManager ) { _busScaleRep = busScaleRep; _busScaleQuestionsRep = busScaleQuestionsRep; _userManager = userManager; } /// /// 分页查询量表试题 /// /// /// [HttpGet("page")] public async Task> Page([FromQuery] BusScaleQuestionsInput input) { var busScaleQuestionss = await _busScaleQuestionsRep.AsQueryable() .WhereIF(input.ScaleId > 0, u => u.ScaleId == input.ScaleId) .WhereIF(!string.IsNullOrEmpty(input.Context), u => u.Context == input.Context) //.Where(u => u.Sort == input.Sort) .OrderBy(u => u.CreateTime, OrderByType.Desc) .OrderBuilder(input) .Select(s => new BusScaleQuestionsOutput() { Context = s.Context, Sort = s.Sort, Id = s.Id }) .ToPagedListAsync(input.Page, input.PageSize); return busScaleQuestionss; } /// /// 增加量表试题 /// /// /// [HttpPost("add")] public async Task Add(AddBusScaleQuestionsInput input) { var busScaleQuestions = input.Adapt(); await _busScaleQuestionsRep.InsertAsync(busScaleQuestions); } /// /// 批量导入量表数据 /// /// /// [HttpPost("Buadd")] public async Task BuAdd(BusAddScaleQuestionsInput input) { var busScaleQuestions = new List(); input.Contexts.ForEach(c => { busScaleQuestions.Add(new BusScaleQuestions() { Context = c.Contexts, CreateTime = DateTime.Now, CreateUserId = _userManager.UserId, CreateUserName = _userManager.Account, ScaleId = input.ScaleId, Sort = c.Sort }); }); await _busScaleQuestionsRep.InsertRangeAsync(busScaleQuestions); } /// /// 删除量表试题 /// /// /// [HttpPost("delete")] public async Task Delete(DeleteBusScaleQuestionsInput input) { var busScaleQuestions = await _busScaleQuestionsRep.AsQueryable().FirstAsync(u => u.Id == input.Id); await _busScaleQuestionsRep.FakeDeleteAsync(busScaleQuestions); } /// /// 更新量表试题 /// /// /// [HttpPost("edit")] public async Task Update(UpdateBusScaleQuestionsInput input) { var isExist = await _busScaleQuestionsRep.AsQueryable().AnyAsync(u => u.Id == input.Id); if (!isExist) throw Oops.Oh(ErrorCodeEnum.D3000); var busScaleQuestions = input.Adapt(); await _busScaleQuestionsRep.UpdateAsync(busScaleQuestions); } /// /// 获取量表试题 /// /// /// [HttpGet("detail")] public async Task Get([FromQuery] QueryeBusScaleQuestionsInput input) { return (await _busScaleQuestionsRep.AsQueryable().FirstAsync(u => u.Id == input.Id)).Adapt(); } /// /// 获取量表试题列表 /// /// /// [HttpGet("list")] public async Task> List([FromQuery] BusScaleQuestionsInput input) { return await _busScaleQuestionsRep.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 }); } } }