tuiwucarrer/Admin.NET/Admin.NET.Application/Service/CePing/BusFeedback/BusFeedbackService.cs

123 lines
4.2 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 = "BusFeedback", Order = 100)]
public class BusFeedbackService : IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<BusFeedback> _busFeedbackRep;
private readonly SqlSugarRepository<BusStudentsFramily> _busStudentsRep;
public BusFeedbackService(
SqlSugarRepository<BusFeedback> busFeedbackRep, SqlSugarRepository<BusStudentsFramily> busStudentsRep
)
{
_busFeedbackRep = busFeedbackRep;
_busStudentsRep = busStudentsRep;
}
/// <summary>
/// 分页查询意见反馈表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("page")]
public async Task<SqlSugarPagedList<BusFeedbackOutput>> 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;
}
/// <summary>
/// 增加意见反馈表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("add")]
public async Task Add(AddBusFeedbackInput input)
{
var framilyInfo = await _busStudentsRep.AsQueryable().FirstAsync(c => c.Uuid == input.UuId);
var busFeedback = input.Adapt<BusFeedback>();
busFeedback.FamilyId = framilyInfo.Id;
await _busFeedbackRep.InsertAsync(busFeedback);
}
/// <summary>
/// 删除意见反馈表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("delete")]
public async Task Delete(DeleteBusFeedbackInput input)
{
var busFeedback = await _busFeedbackRep.AsQueryable().FirstAsync(u => u.Id == input.Id);
await _busFeedbackRep.FakeDeleteAsync(busFeedback);
}
/// <summary>
/// 更新意见反馈表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[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<BusFeedback>();
await _busFeedbackRep.UpdateAsync(busFeedback);
}
/// <summary>
/// 获取意见反馈表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("detail")]
public async Task<BusFeedbackOutput> Get([FromQuery] QueryeBusFeedbackInput input)
{
return (await _busFeedbackRep.AsQueryable().FirstAsync(u => u.Id == input.Id)).Adapt<BusFeedbackOutput>();
}
/// <summary>
/// 获取意见反馈表列表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("list")]
public async Task<List<BusFeedbackOutput>> List([FromQuery] BusFeedbackInput input)
{
return await _busFeedbackRep.AsQueryable().Select<BusFeedbackOutput>().ToListAsync();
}
}
}