You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
BookingHeChuan/Myshipping.Application/Service/BookingTemplate/BookingTemplateService.cs

119 lines
3.9 KiB
C#

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;
2 years ago
using Myshipping.Application.Enum;
namespace Myshipping.Application
{
/// <summary>
/// 订舱模板服务
/// </summary>
[ApiDescriptionSettings("Application", Name = "BookingTemplate", Order = 1)]
public class BookingTemplateService : IBookingTemplateService, IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<BookingTemplate> _rep;
private readonly ILogger<BookingTemplate> _logger;
public BookingTemplateService(SqlSugarRepository<BookingTemplate> rep, ILogger<BookingTemplate> logger)
{
_rep = rep;
_logger = logger;
}
/// <summary>
/// 分页查询订舱模板
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("/BookingTemplate/page")]
public async Task<dynamic> Page([FromQuery] QueryBookingTemplateInput input)
{
var entities = await _rep.AsQueryable()
.Where(m => m.CreatedUserId == UserManager.UserId)
.WhereIF(!string.IsNullOrEmpty(input.Title), u => u.Title.Contains(input.Title))
.WhereIF(!string.IsNullOrEmpty(input.Type), u =>u.Type.Contains(input.Type))
.ToPagedListAsync(input.PageNo, input.PageSize);
return entities.XnPagedResult();
}
/// <summary>
/// 增加订舱模板
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/BookingTemplate/add")]
public async Task Add(AddBookingTemplateInput input)
{
2 years ago
//var c = _rep.Count(x => x.Type.Contains(input.Type) && x.Title == input.Title);
//if (c > 0)
//{
// throw Oops.Oh(BookingErrorCode.BOOK101);
//}
var entity = input.Adapt<BookingTemplate>();
await _rep.InsertAsync(entity);
}
/// <summary>
/// 更新订舱模板
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/BookingTemplate/edit")]
public async Task Update(UpdateBookingTemplateInput input)
{
var bt = _rep.FirstOrDefault(x => x.Id == input.Id);
if (bt == null)
{
2 years ago
throw Oops.Oh(BookingErrorCode.BOOK111);
}
input.Adapt(bt);
await _rep.AsUpdateable(bt).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
}
/// <summary>
/// 删除订舱模板
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/BookingTemplate/delete")]
public async Task Delete(GetBookingTemplateInput input)
{
var entity = await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
await _rep.DeleteAsync(entity);
}
/// <summary>
/// 获取订舱模板
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("/BookingTemplate/detail")]
public async Task<BookingTemplate> Get([FromQuery] GetBookingTemplateInput input)
{
return await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
}
///// <summary>
///// 获取订舱模板列表
///// </summary>
///// <param name="input"></param>
///// <returns></returns>
//[HttpGet("/BookingTemplate/list")]
//public async Task<dynamic> List([FromQuery] QueryBookingTemplateInput input)
//{
// return await _rep.ToListAsync();
//}
}
}