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.Core/Service/CommonDB/CommonDBService.cs

150 lines
5.7 KiB
C#

2 years ago

using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Furion.FriendlyException;
using Myshipping.Core.Entity;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System.Linq;
using System.Threading.Tasks;
using System.Collections.Generic;
using System;
namespace Myshipping.Core.Service;
/// <summary>
/// 公共库
/// </summary>
[ApiDescriptionSettings(Name = "CommonDB", Order = 1000)]
public class CommonDBService : ICommonDBService, IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<CodeCarrier> _codeCarrierRep;
private readonly SqlSugarRepository<CodeVessel> _codeVesselRep;
private readonly SqlSugarRepository<CodeForwarder> _codeForwarderRep;
private readonly SqlSugarRepository<CodeYard> _codeYardRep;
private readonly SqlSugarRepository<CodePortLoad> _codePortLoadrRep;
private readonly SqlSugarRepository<CodePort> _codePortRep;
private readonly SqlSugarRepository<CodePackage> _codePackageRep;
private readonly SqlSugarRepository<CodeService> _codeServiceRep;
private readonly SqlSugarRepository<CodeCtn> _codeCtnRep;
private readonly ISysCacheService _sysCacheService;
public CommonDBService(SqlSugarRepository<CodeCarrier> codeCarrierRep,
SqlSugarRepository<CodeVessel> codeVesselRep,
SqlSugarRepository<CodeForwarder> codeForwarderRep,
SqlSugarRepository<CodeYard> codeYardRep,
SqlSugarRepository<CodePortLoad> codePortLoadrRep,
SqlSugarRepository<CodePort> codePortRep,
SqlSugarRepository<CodePackage> codePackageRep,
SqlSugarRepository<CodeService> codeServiceRep,
SqlSugarRepository<CodeCtn> codeCtnRep,
ISysCacheService sysCacheService)
{
_codeCarrierRep = codeCarrierRep;
_codeVesselRep = codeVesselRep;
_codeForwarderRep = codeForwarderRep;
_codeYardRep = codeYardRep;
_codePortLoadrRep = codePortLoadrRep;
_codePortRep = codePortRep;
_codePackageRep = codePackageRep;
_codeServiceRep = codeServiceRep;
_codeCtnRep = codeCtnRep;
_sysCacheService = sysCacheService;
}
/// <summary>
/// 获取船公司列表信息
/// </summary>
[HttpGet("/commondb/carrierlist")]
public async Task<dynamic> CarrierList([FromQuery] CodeCnEnQueryDto input)
{
List<CodeCarrier> list = null;
if (_sysCacheService.Exists(CommonConst.CACHE_KEY_COMMON_DB_CARRIER))
{
list = await _sysCacheService.GetAsync<List<CodeCarrier>>(CommonConst.CACHE_KEY_COMMON_DB_CARRIER);
}
else
{
list = await _codeCarrierRep.ToListAsync();
await _sysCacheService.SetTimeoutAsync(CommonConst.CACHE_KEY_COMMON_DB_CARRIER, list, TimeSpan.FromMinutes(5));
}
var queryList = list.WhereIF(!string.IsNullOrEmpty(input.Code), x => x.Code.Contains(input.Code, System.StringComparison.CurrentCultureIgnoreCase))
.WhereIF(!string.IsNullOrEmpty(input.CnName), x => x.Code.Contains(input.CnName))
.WhereIF(!string.IsNullOrEmpty(input.EnName), x => x.Code.Contains(input.EnName, System.StringComparison.CurrentCultureIgnoreCase));
return queryList.ToList();
}
/// <summary>
/// 获取船名列表信息
/// </summary>
[HttpGet("/commondb/vessellist")]
public async Task<dynamic> VesselList([FromQuery] NameQueryDto input)
{
List<CodeVessel> list = null;
if (_sysCacheService.Exists(CommonConst.CACHE_KEY_COMMON_DB_VESSEL))
{
list = await _sysCacheService.GetAsync<List<CodeVessel>>(CommonConst.CACHE_KEY_COMMON_DB_VESSEL);
}
else
{
list = await _codeVesselRep.ToListAsync();
await _sysCacheService.SetTimeoutAsync(CommonConst.CACHE_KEY_COMMON_DB_VESSEL, list, TimeSpan.FromMinutes(5));
}
var queryList = list.WhereIF(!string.IsNullOrEmpty(input.Name), x => x.Name.Contains(input.Name, System.StringComparison.CurrentCultureIgnoreCase));
return queryList.ToList();
}
/// <summary>
/// 获取船代列表信息
/// </summary>
[HttpGet("/commondb/forwarderlist")]
public async Task<dynamic> ForwarderList([FromQuery] NameQueryDto input)
{
List<CodeForwarder> list = null;
if (_sysCacheService.Exists(CommonConst.CACHE_KEY_COMMON_DB_FORWARDER))
{
list = await _sysCacheService.GetAsync<List<CodeForwarder>>(CommonConst.CACHE_KEY_COMMON_DB_FORWARDER);
}
else
{
list = await _codeForwarderRep.ToListAsync();
await _sysCacheService.SetTimeoutAsync(CommonConst.CACHE_KEY_COMMON_DB_FORWARDER, list, TimeSpan.FromMinutes(5));
}
var queryList = list.WhereIF(!string.IsNullOrEmpty(input.Name), x => x.Name.Contains(input.Name, System.StringComparison.CurrentCultureIgnoreCase));
return queryList.ToList();
}
/// <summary>
/// 获取场站列表信息
/// </summary>
[HttpGet("/commondb/yardlist")]
public async Task<dynamic> YardList([FromQuery] NameQueryDto input)
{
List<CodeYard> list = null;
if (_sysCacheService.Exists(CommonConst.CACHE_KEY_COMMON_DB_YARD))
{
list = await _sysCacheService.GetAsync<List<CodeYard>>(CommonConst.CACHE_KEY_COMMON_DB_YARD);
}
else
{
list = await _codeYardRep.ToListAsync();
await _sysCacheService.SetTimeoutAsync(CommonConst.CACHE_KEY_COMMON_DB_YARD, list, TimeSpan.FromMinutes(5));
}
var queryList = list.WhereIF(!string.IsNullOrEmpty(input.Name), x => x.Name.Contains(input.Name, System.StringComparison.CurrentCultureIgnoreCase));
return queryList.ToList();
}
}