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;
using System.ComponentModel;
using System.Collections.Generic;
using System.IO;
using MiniExcelLibs;
using NPOI.HSSF.UserModel;
using Myshipping.Core.Helper;
using NPOI.SS.UserModel;
using Furion;
using System;
using System.Web;
using System.Text;
using Myshipping.Application.ConfigOption;
using Myshipping.Core.Service;
using Myshipping.Application.Service.BookingSlot.Dto;
using NPOI.SS.Formula.Functions;
namespace Myshipping.Application
{
///
/// 订舱舱位
///
[ApiDescriptionSettings("Application", Name = "BookingSlot", Order = 1)]
public class BookingSlotService : IDynamicApiController, ITransient
{
private readonly SqlSugarRepository _repBase;
private readonly SqlSugarRepository _repCtn;
private readonly SqlSugarRepository _repStock;
private readonly ILogger _logger;
private readonly ISysCacheService _cache;
public BookingSlotService(SqlSugarRepository repBase,
SqlSugarRepository repCtn,
SqlSugarRepository repStock,
ILogger logger,
ISysCacheService cache)
{
_repBase = repBase;
_repCtn = repCtn;
_repStock = repStock;
_logger = logger;
_cache = cache;
}
#region 舱位
///
/// 分页查询订舱舱位
///
///
///
[HttpGet("/BookingSlot/page")]
public async Task Page([FromQuery] BookingSlotBasePageInput input)
{
var entities = await _repBase.AsQueryable()
.WhereIF(!string.IsNullOrEmpty(input.SLOT_BOOKING_NO), u => u.SLOT_BOOKING_NO.Contains(input.SLOT_BOOKING_NO))
.WhereIF(!string.IsNullOrEmpty(input.VESSEL), u => u.VESSEL.Contains(input.VESSEL))
.WhereIF(!string.IsNullOrEmpty(input.VOYNO), u => u.VOYNO.Contains(input.VOYNO))
.WhereIF(!string.IsNullOrEmpty(input.PORTLOAD), u => u.PORTLOAD.Contains(input.PORTLOAD))
.WhereIF(!string.IsNullOrEmpty(input.PORTDISCHARGE), u => u.PORTLOAD.Contains(input.PORTLOAD))
.WhereIF(!string.IsNullOrEmpty(input.CARRIER), u => u.CARRIER.Contains(input.CARRIER))
.WhereIF(!string.IsNullOrEmpty(input.LANENAME), u => u.LANENAME.Contains(input.LANENAME))
.WhereIF(!string.IsNullOrEmpty(input.CARRIAGE_TYPE), u => u.CARRIAGE_TYPE == input.CARRIAGE_TYPE)
.WhereIF(!string.IsNullOrEmpty(input.BOOKING_SLOT_TYPE), u => u.BOOKING_SLOT_TYPE == input.BOOKING_SLOT_TYPE)
.WhereIF(!string.IsNullOrEmpty(input.CTN_STAT), u => u.CTN_STAT.Contains(input.CTN_STAT))
.WhereIF(!string.IsNullOrEmpty(input.VGM_RLT_STAT), u => u.VGM_RLT_STAT == input.VGM_RLT_STAT)
.WhereIF(!string.IsNullOrEmpty(input.SI_RLT_STAT), u => u.SI_RLT_STAT == input.SI_RLT_STAT)
.WhereIF(input.ETD_START.HasValue, u => u.ETD >= input.ETD_START.Value)
.WhereIF(input.ETD_END.HasValue, u => u.ETD < input.ETD_END.Value.AddDays(1))
.WhereIF(input.ETA_START.HasValue, u => u.ETA >= input.ETA_START.Value)
.WhereIF(input.ETA_END.HasValue, u => u.ETA < input.ETA_END.Value.AddDays(1))
.ToPagedListAsync(input.PageNo, input.PageSize);
var result = entities.Adapt>();
return result.XnPagedResult();
}
///
/// 保存订舱舱位
///
///
///
[HttpPost("/BookingSlot/save")]
public async Task Save(BookingSlotBaseSaveDto input)
{
BookingSlotBase model = null;
if (input.Id > 0)
{
model = _repBase.FirstOrDefault(x => x.Id == input.Id);
input.Adapt(model);
await _repBase.UpdateAsync(model);
await _repCtn.DeleteAsync(x => x.SLOT_ID == model.Id);
foreach (var ctn in input.CtnList)
{
var newCtn = ctn.Adapt();
newCtn.SLOT_ID = model.Id;
await _repCtn.InsertAsync(newCtn);
}
}
else
{
model = input.Adapt();
await _repBase.InsertAsync(model);
foreach (var ctn in input.CtnList)
{
var newCtn = ctn.Adapt();
newCtn.SLOT_ID = model.Id;
await _repCtn.InsertAsync(newCtn);
}
}
return await Detail(model.Id);
}
///
/// 删除订舱舱位
///
///
///
[HttpPost("/BookingSlot/delete")]
public async Task Delete(long id)
{
var entity = await _repBase.FirstOrDefaultAsync(u => u.Id == id);
entity.IsDeleted = true;
await _repBase.UpdateAsync(entity);
var ctns = await _repCtn.Where(x => x.SLOT_ID == id).ToListAsync();
foreach (var item in ctns)
{
item.IsDeleted = true;
}
await _repCtn.UpdateAsync(ctns);
}
///
/// 获取订舱舱位
///
///
///
[HttpGet("/BookingSlot/detail")]
public async Task Detail(long id)
{
var slotBase = await _repBase.FirstOrDefaultAsync(u => u.Id == id);
var ctns = await _repCtn.Where(x => x.SLOT_ID == id).ToListAsync();
var rtn = slotBase.Adapt();
rtn.CtnList = ctns.Adapt>();
return rtn;
}
#endregion
#region 库存
/////
///// 库存查询
/////
/////
/////
//[HttpGet("/BookingSlot/pageStock")]
//public async Task PageStock([FromQuery] BookingSlotBasePageInput input)
//{
// var query = await _repStock.AsQueryable()
// .ToListAsync();
//}
#endregion
}
}