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.
151 lines
5.3 KiB
C#
151 lines
5.3 KiB
C#
using Furion.DependencyInjection;
|
|
using Furion.DynamicApiController;
|
|
using Furion.FriendlyException;
|
|
using Mapster;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Logging;
|
|
using Myshipping.Application.Entity;
|
|
using Myshipping.Core;
|
|
using Myshipping.Core.Service;
|
|
using NPOI.SS.Formula.Functions;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Myshipping.Application.Service
|
|
{
|
|
/// <summary>
|
|
/// 自动订舱模板
|
|
/// </summary>
|
|
[ApiDescriptionSettings("Application", Name = "BookingSoTemplate", Order = 1)]
|
|
public class BookingSoTemplateService : IDynamicApiController, ITransient
|
|
{
|
|
|
|
private readonly ILogger<BookingSlotService> _logger;
|
|
private readonly ISysCacheService _cache;
|
|
private readonly SqlSugarRepository<BookingSoTemplate> _rep;
|
|
|
|
public BookingSoTemplateService(ILogger<BookingSlotService> logger,
|
|
ISysCacheService cache,
|
|
SqlSugarRepository<BookingSoTemplate> rep)
|
|
{
|
|
_logger = logger;
|
|
_cache = cache;
|
|
|
|
_rep = rep;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 分页查询订舱模板
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("/BookingSoTemplate/page")]
|
|
public async Task<SqlSugarPagedList<BookingSoTemplateListOutput>> Page([FromQuery] QueryBookingSoTemplateInput input)
|
|
{
|
|
var query = _rep.AsQueryable().Filter(null, true)
|
|
.Where(x => x.IsDeleted == false)
|
|
.WhereIF(!string.IsNullOrEmpty(input.CustName), u => u.CustName.Contains(input.CustName))
|
|
.WhereIF(!string.IsNullOrEmpty(input.Carrier), u => u.Carrier.Contains(input.Carrier))
|
|
.WhereIF(!string.IsNullOrEmpty(input.TemplateName), u => u.TemplateName.Contains(input.TemplateName))
|
|
.WhereIF(!string.IsNullOrEmpty(input.CarrierId), u => u.CarrierId == input.CarrierId);
|
|
|
|
if (!string.IsNullOrEmpty(input.SortField) || input.MultiSort == null || input.MultiSort.Count == 0)
|
|
{
|
|
query = query.OrderBy(PageInputOrder.OrderBuilder(input.SortField, input.DescSort));
|
|
}
|
|
else
|
|
{
|
|
query = query.OrderBy(PageInputOrder.MultiOrderBuilder(input.MultiSort));
|
|
}
|
|
|
|
var entities = await query.ToPagedListAsync(input.PageNo, input.PageSize);
|
|
return entities.Adapt<SqlSugarPagedList<BookingSoTemplateListOutput>>();
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存订舱模板
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("/BookingSoTemplate/save")]
|
|
public async Task<BookingSoTemplateDetailOutput> Save(BookingSoTemplateSaveInput input)
|
|
{
|
|
BookingSoTemplate model = null;
|
|
|
|
//同一客户,同一船公司,只允许生效一个模板。
|
|
if (input.IsEnable)
|
|
{
|
|
var c = _rep.AsQueryable().Filter(null, true).Count(x => x.IsDeleted == false && x.CustName == input.CustName && x.CarrierId == input.CarrierId && x.IsEnable);
|
|
if (c > 0)
|
|
{
|
|
throw Oops.Bah($"客户:{input.CustName},船司:{input.Carrier} 已存在启用的模板");
|
|
}
|
|
}
|
|
|
|
if (input.Id > 0)
|
|
{
|
|
model = _rep.FirstOrDefault(x => x.Id == input.Id);
|
|
|
|
input.Adapt(model);
|
|
|
|
await _rep.UpdateAsync(model);
|
|
}
|
|
else
|
|
{
|
|
if (_rep.AsQueryable().Filter(null, true).Count(x => x.IsDeleted == false && x.CustName == input.CustName && x.CarrierId == input.CarrierId) > 0)
|
|
{
|
|
throw Oops.Bah($"客户:{input.CustName},船司:{input.Carrier} 已创建过模板");
|
|
}
|
|
|
|
model = input.Adapt<BookingSoTemplate>();
|
|
await _rep.InsertAsync(model);
|
|
}
|
|
|
|
return model.Adapt<BookingSoTemplateDetailOutput>();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 删除订舱模板
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("/BookingSoTemplate/delete")]
|
|
public async Task Delete(long id)
|
|
{
|
|
var entity = await _rep.AsQueryable().Filter(null, true)
|
|
.FirstAsync(u => u.Id == id && u.IsDeleted == false);
|
|
if (entity == null)
|
|
{
|
|
throw Oops.Bah("未找到模板数据");
|
|
}
|
|
entity.IsDeleted = true;
|
|
await _rep.UpdateAsync(entity);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取订舱模板
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("/BookingSoTemplate/detail")]
|
|
public async Task<BookingSoTemplateDetailOutput> Get(long id)
|
|
{
|
|
var model = await _rep.AsQueryable().Filter(null, true)
|
|
.FirstAsync(u => u.Id == id && u.IsDeleted == false);
|
|
if (model == null)
|
|
{
|
|
throw Oops.Bah("未找到模板数据");
|
|
}
|
|
return model.Adapt<BookingSoTemplateDetailOutput>();
|
|
}
|
|
|
|
}
|
|
}
|