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.
227 lines
8.4 KiB
C#
227 lines
8.4 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;
|
|
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;
|
|
|
|
namespace Myshipping.Application
|
|
{
|
|
/// <summary>
|
|
/// 船司与场站、订舱代理等对应关系
|
|
/// </summary>
|
|
[ApiDescriptionSettings("Application", Name = "BookingCarrierRelation", Order = 1)]
|
|
public class BookingCarrierRelationService : IDynamicApiController, ITransient
|
|
{
|
|
private readonly SqlSugarRepository<BookingCarrierYardRelation> _repCarrierYard;
|
|
private readonly SqlSugarRepository<BookingCarrierAgentRelation> _repCarrierAgent;
|
|
private readonly ILogger<BookingCarrierRelationService> _logger;
|
|
private readonly ISysCacheService _cache;
|
|
|
|
public BookingCarrierRelationService(SqlSugarRepository<BookingCarrierYardRelation> repCarrierYard,
|
|
SqlSugarRepository<BookingCarrierAgentRelation> repCarrierAgent,
|
|
ILogger<BookingCarrierRelationService> logger, ISysCacheService cache)
|
|
{
|
|
_repCarrierYard = repCarrierYard;
|
|
_repCarrierAgent = repCarrierAgent;
|
|
_logger = logger;
|
|
_cache = cache;
|
|
}
|
|
|
|
#region 船司场站对应关系
|
|
/// <summary>
|
|
/// 分页查询船司场站对应关系
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("/BookingCarrierRelation/pageYard")]
|
|
public async Task<SqlSugarPagedList<CarrierYardRelationSaveOutput>> PageYard([FromQuery] CarrierYardRelationQueryInput input)
|
|
{
|
|
var entities = await _repCarrierYard.AsQueryable()
|
|
.WhereIF(!string.IsNullOrEmpty(input.CarrierCode), u => u.CarrierCode.Contains(input.CarrierCode))
|
|
.WhereIF(!string.IsNullOrEmpty(input.Carrier), u => u.Carrier.Contains(input.Carrier))
|
|
.WhereIF(!string.IsNullOrEmpty(input.YardCode), u => u.YardCode.Contains(input.YardCode))
|
|
.WhereIF(!string.IsNullOrEmpty(input.Yard), u => u.Yard.Contains(input.Yard))
|
|
.ToPagedListAsync(input.PageNo, input.PageSize);
|
|
var rtn = entities.Adapt<SqlSugarPagedList<CarrierYardRelationSaveOutput>>();
|
|
return rtn;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存船司场站对应关系
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("/BookingCarrierRelation/saveYard")]
|
|
public async Task<long> SaveYard(CarrierYardRelationSaveInput input)
|
|
{
|
|
BookingCarrierYardRelation model = null;
|
|
if (input.Id > 0)
|
|
{
|
|
if (_repCarrierYard.Count(x => x.Carrier == input.Carrier && x.Yard == input.Yard && x.Id != input.Id) > 0)
|
|
{
|
|
throw Oops.Bah($"已存在相同代码:{input.Carrier} {input.Yard}");
|
|
}
|
|
|
|
model = _repCarrierYard.FirstOrDefault(x => x.Id == input.Id);
|
|
|
|
input.Adapt(model);
|
|
|
|
await _repCarrierYard.UpdateAsync(model);
|
|
}
|
|
else
|
|
{
|
|
if (_repCarrierYard.Count(x => x.Carrier == input.Carrier && x.Yard == input.Yard && x.Id != input.Id) > 0)
|
|
{
|
|
throw Oops.Bah($"已存在相同代码:{input.Carrier} {input.Yard}");
|
|
}
|
|
|
|
model = input.Adapt<BookingCarrierYardRelation>();
|
|
await _repCarrierYard.InsertAsync(model);
|
|
}
|
|
|
|
return model.Id;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 删除船司场站对应关系
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("/BookingCarrierRelation/deleteYard")]
|
|
public async Task DeleteYard(long id)
|
|
{
|
|
var entity = await _repCarrierYard.FirstOrDefaultAsync(u => u.Id == id);
|
|
entity.IsDeleted = true;
|
|
await _repCarrierYard.UpdateAsync(entity);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据船司代码获取可以选择的场站
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet("/BookingCarrierRelation/ListYardByCarrier")]
|
|
public async Task<dynamic> ListYardByCarrier(string carrierCode)
|
|
{
|
|
return await _repCarrierYard.AsQueryable()
|
|
.Where(u => u.CarrierCode == carrierCode)
|
|
.Select(x => new
|
|
{
|
|
x.Yard,
|
|
x.YardCode
|
|
})
|
|
.ToListAsync();
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 船司订舱代理对应关系
|
|
/// <summary>
|
|
/// 分页查询船司订舱代理对应关系
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("/BookingCarrierRelation/pageAgent")]
|
|
public async Task<SqlSugarPagedList<CarrierAgentRelationSaveOutput>> PageAgent([FromQuery] CarrierAgentRelationQueryInput input)
|
|
{
|
|
var entities = await _repCarrierAgent.AsQueryable()
|
|
.WhereIF(!string.IsNullOrEmpty(input.CarrierCode), u => u.CarrierCode.Contains(input.CarrierCode))
|
|
.WhereIF(!string.IsNullOrEmpty(input.Carrier), u => u.Carrier.Contains(input.Carrier))
|
|
.WhereIF(!string.IsNullOrEmpty(input.AgentCode), u => u.AgentCode.Contains(input.AgentCode))
|
|
.WhereIF(!string.IsNullOrEmpty(input.Agent), u => u.Agent.Contains(input.Agent))
|
|
.ToPagedListAsync(input.PageNo, input.PageSize);
|
|
var rtn = entities.Adapt<SqlSugarPagedList<CarrierAgentRelationSaveOutput>>();
|
|
return rtn;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存船司订舱代理对应关系
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("/BookingCarrierRelation/saveAgent")]
|
|
public async Task<long> SaveAgent(CarrierAgentRelationSaveInput input)
|
|
{
|
|
BookingCarrierAgentRelation model = null;
|
|
if (input.Id > 0)
|
|
{
|
|
if (_repCarrierAgent.Count(x => x.Carrier == input.Carrier && x.Agent == input.Agent && x.Id != input.Id) > 0)
|
|
{
|
|
throw Oops.Bah($"已存在相同代码:{input.Carrier} {input.Agent}");
|
|
}
|
|
|
|
model = _repCarrierAgent.FirstOrDefault(x => x.Id == input.Id);
|
|
|
|
input.Adapt(model);
|
|
|
|
await _repCarrierAgent.UpdateAsync(model);
|
|
}
|
|
else
|
|
{
|
|
if (_repCarrierAgent.Count(x => x.Carrier == input.Carrier && x.Agent == input.Agent && x.Id != input.Id) > 0)
|
|
{
|
|
throw Oops.Bah($"已存在相同代码:{input.Carrier} {input.Agent}");
|
|
}
|
|
|
|
model = input.Adapt<BookingCarrierAgentRelation>();
|
|
await _repCarrierAgent.InsertAsync(model);
|
|
}
|
|
|
|
return model.Id;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 删除船司订舱代理对应关系
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("/BookingCarrierRelation/deleteAgent")]
|
|
public async Task DeleteAgent(long id)
|
|
{
|
|
var entity = await _repCarrierAgent.FirstOrDefaultAsync(u => u.Id == id);
|
|
entity.IsDeleted = true;
|
|
await _repCarrierAgent.UpdateAsync(entity);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 根据船司代码获取可以选择的订舱代理
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet("/BookingCarrierRelation/ListAgentByCarrier")]
|
|
public async Task<dynamic> ListAgentByCarrier(string carrierCode)
|
|
{
|
|
return await _repCarrierAgent.AsQueryable()
|
|
.Where(u => u.CarrierCode == carrierCode)
|
|
.Select(x => new
|
|
{
|
|
x.Agent,
|
|
x.AgentCode
|
|
})
|
|
.ToListAsync();
|
|
}
|
|
#endregion
|
|
}
|
|
}
|