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 = "BusFeedback", Order = 100)] public class BusFeedbackService : IDynamicApiController, ITransient { private readonly SqlSugarRepository _busFeedbackRep; private readonly SqlSugarRepository _busStudentsRep; public BusFeedbackService( SqlSugarRepository busFeedbackRep, SqlSugarRepository busStudentsRep ) { _busFeedbackRep = busFeedbackRep; _busStudentsRep = busStudentsRep; } /// /// 分页查询意见反馈表 /// /// /// [HttpGet("page")] public async Task> Page([FromQuery] BusFeedbackInput input) { var busFeedbacks = await _busFeedbackRep.AsQueryable() .Where(u => u.Type == input.Type) //.Where(u => u.FamilyId == input.FamilyId) .WhereIF(!string.IsNullOrEmpty(input.Context), u => u.Context == input.Context) .OrderBy(u => u.CreateTime, OrderByType.Desc) .OrderBuilder(input) .Select(s => new BusFeedbackOutput() { Type = s.Type, FamilyId = s.FamilyId, Context = s.Context, Id = s.Id }).ToPagedListAsync(input.Page, input.PageSize); return busFeedbacks; } /// /// 增加意见反馈表 /// /// /// [HttpPost("add")] public async Task Add(AddBusFeedbackInput input) { var framilyInfo = await _busStudentsRep.AsQueryable().FirstAsync(c => c.Uuid == input.UuId); var busFeedback = input.Adapt(); busFeedback.FamilyId = framilyInfo.Id; await _busFeedbackRep.InsertAsync(busFeedback); } /// /// 删除意见反馈表 /// /// /// [HttpPost("delete")] public async Task Delete(DeleteBusFeedbackInput input) { var busFeedback = await _busFeedbackRep.AsQueryable().FirstAsync(u => u.Id == input.Id); await _busFeedbackRep.FakeDeleteAsync(busFeedback); } /// /// 更新意见反馈表 /// /// /// [HttpPost("edit")] public async Task Update(UpdateBusFeedbackInput input) { var isExist = await _busFeedbackRep.AsQueryable().AnyAsync(u => u.Id == input.Id); if (!isExist) throw Oops.Oh(ErrorCodeEnum.D3000); var busFeedback = input.Adapt(); await _busFeedbackRep.UpdateAsync(busFeedback); } /// /// 获取意见反馈表 /// /// /// [HttpGet("detail")] public async Task Get([FromQuery] QueryeBusFeedbackInput input) { return (await _busFeedbackRep.AsQueryable().FirstAsync(u => u.Id == input.Id)).Adapt(); } /// /// 获取意见反馈表列表 /// /// /// [HttpGet("list")] public async Task> List([FromQuery] BusFeedbackInput input) { return await _busFeedbackRep.AsQueryable().Select().ToListAsync(); } } }