using Myshipping.Core;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System.Linq;
using System.Threading.Tasks;
using Myshipping.Application.Entity;
using Microsoft.Extensions.Logging;
using Furion.FriendlyException;
using Myshipping.Application.Enum;
namespace Myshipping.Application
{
///
/// 订舱模板服务
///
[ApiDescriptionSettings("Application", Name = "BookingTemplate", Order = 1)]
public class BookingTemplateService : IBookingTemplateService, IDynamicApiController, ITransient
{
private readonly SqlSugarRepository _rep;
private readonly ILogger _logger;
public BookingTemplateService(SqlSugarRepository rep, ILogger logger)
{
_rep = rep;
_logger = logger;
}
///
/// 分页查询订舱模板
///
///
///
[HttpGet("/BookingTemplate/page")]
public async Task Page([FromQuery] QueryBookingTemplateInput input)
{
var entities = await _rep.AsQueryable()
.WhereIF(!string.IsNullOrEmpty(input.Title), u => u.Title.Contains(input.Title))
.WhereIF(input.Type.HasValue, u => u.Type == input.Type)
.ToPagedListAsync(input.PageNo, input.PageSize);
return entities.XnPagedResult();
}
///
/// 增加订舱模板
///
///
///
[HttpPost("/BookingTemplate/add")]
public async Task Add(AddBookingTemplateInput input)
{
var c = _rep.Count(x => x.Type == input.Type && x.Title == input.Title);
if (c > 0)
{
throw Oops.Oh(BookingErrorCode.BOOK101);
}
var entity = input.Adapt();
await _rep.InsertAsync(entity);
}
///
/// 更新订舱模板
///
///
///
[HttpPost("/BookingTemplate/edit")]
public async Task Update(UpdateBookingTemplateInput input)
{
var bt = _rep.FirstOrDefault(x => x.Id == input.Id);
if (bt == null)
{
throw Oops.Oh(BookingErrorCode.BOOK111);
}
bt.Content = input.Content;
bt.Remark = input.Remark;
await _rep.AsUpdateable(bt).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
}
///
/// 删除订舱模板
///
///
///
[HttpPost("/BookingTemplate/delete")]
public async Task Delete(GetBookingTemplateInput input)
{
var entity = await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
await _rep.DeleteAsync(entity);
}
///
/// 获取订舱模板
///
///
///
[HttpGet("/BookingTemplate/detail")]
public async Task Get([FromQuery] GetBookingTemplateInput input)
{
return await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
}
/////
///// 获取订舱模板列表
/////
/////
/////
//[HttpGet("/BookingTemplate/list")]
//public async Task List([FromQuery] QueryBookingTemplateInput input)
//{
// return await _rep.ToListAsync();
//}
}
}