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.
322 lines
11 KiB
C#
322 lines
11 KiB
C#
|
|
|
|
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)
|
|
{
|
|
var list = await GetAllCarrier();
|
|
|
|
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)
|
|
{
|
|
//数量太多,不允许查询全部
|
|
if (string.IsNullOrEmpty(input.Name) || input.Name.Length < 2)
|
|
{
|
|
return new List<CodeVessel>();
|
|
}
|
|
|
|
List<CodeVessel> list = await GetAllVessel();
|
|
|
|
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 = await GetAllForwarder();
|
|
|
|
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 = await GetAllYard();
|
|
|
|
var queryList = list.WhereIF(!string.IsNullOrEmpty(input.Name), x => x.Name.Contains(input.Name, System.StringComparison.CurrentCultureIgnoreCase));
|
|
|
|
return queryList.ToList();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取起始港信息
|
|
/// </summary>
|
|
[HttpGet("/commondb/portloadlist")]
|
|
public async Task<dynamic> PortloadList([FromQuery] NameQueryDto input)
|
|
{
|
|
List<CodePortLoad> list = await GetAllPortload();
|
|
|
|
var queryList = list.WhereIF(!string.IsNullOrEmpty(input.Name), x => x.CnName.Contains(input.Name) || x.EnName.Contains(input.Name, System.StringComparison.CurrentCultureIgnoreCase));
|
|
|
|
return queryList.ToList();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取目的港信息
|
|
/// </summary>
|
|
[HttpGet("/commondb/portlist")]
|
|
public async Task<dynamic> PortList([FromQuery] NameQueryDto input)
|
|
{
|
|
//数量太多,不允许查询全部
|
|
if (string.IsNullOrEmpty(input.Name) || input.Name.Length < 2)
|
|
{
|
|
return new List<CodePortLoad>();
|
|
}
|
|
|
|
List<CodePort> list = await GetAllPort();
|
|
|
|
var queryList = list.WhereIF(!string.IsNullOrEmpty(input.Name), x => x.CnName.Contains(input.Name) || x.EnName.Contains(input.Name, System.StringComparison.CurrentCultureIgnoreCase));
|
|
|
|
return queryList.ToList();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取包装信息
|
|
/// </summary>
|
|
[HttpGet("/commondb/package")]
|
|
public async Task<dynamic> PackageList([FromQuery] NameQueryDto input)
|
|
{
|
|
List<CodePackage> list = await GetAllPackage();
|
|
|
|
var queryList = list.WhereIF(!string.IsNullOrEmpty(input.Name), x => x.Name.Contains(input.Name, System.StringComparison.CurrentCultureIgnoreCase));
|
|
|
|
return queryList.ToList();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取运输条款信息
|
|
/// </summary>
|
|
[HttpGet("/commondb/service")]
|
|
public async Task<dynamic> ServiceList([FromQuery] NameQueryDto input)
|
|
{
|
|
List<CodeService> list = await GetAllService();
|
|
|
|
var queryList = list.WhereIF(!string.IsNullOrEmpty(input.Name), x => x.Name.Contains(input.Name, System.StringComparison.CurrentCultureIgnoreCase));
|
|
|
|
return queryList.ToList();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取箱型信息
|
|
/// </summary>
|
|
[HttpGet("/commondb/ctn")]
|
|
public async Task<dynamic> CtnList([FromQuery] NameQueryDto input)
|
|
{
|
|
List<CodeCtn> list = await GetAllCtn();
|
|
|
|
var queryList = list.WhereIF(!string.IsNullOrEmpty(input.Name), x => x.Name.Contains(input.Name, System.StringComparison.CurrentCultureIgnoreCase));
|
|
|
|
return queryList.ToList();
|
|
}
|
|
|
|
#region 实现接口,获取公共数据并缓存
|
|
public async Task<List<CodeCarrier>> GetAllCarrier()
|
|
{
|
|
if (_sysCacheService.Exists(CommonConst.CACHE_KEY_COMMON_DB_CARRIER))
|
|
{
|
|
return await _sysCacheService.GetAsync<List<CodeCarrier>>(CommonConst.CACHE_KEY_COMMON_DB_CARRIER);
|
|
}
|
|
else
|
|
{
|
|
var list = await _codeCarrierRep.ToListAsync();
|
|
await _sysCacheService.SetTimeoutAsync(CommonConst.CACHE_KEY_COMMON_DB_CARRIER, list, TimeSpan.FromMinutes(5));
|
|
return list;
|
|
}
|
|
}
|
|
|
|
public async Task<List<CodeVessel>> GetAllVessel()
|
|
{
|
|
if (_sysCacheService.Exists(CommonConst.CACHE_KEY_COMMON_DB_VESSEL))
|
|
{
|
|
return await _sysCacheService.GetAsync<List<CodeVessel>>(CommonConst.CACHE_KEY_COMMON_DB_VESSEL);
|
|
}
|
|
else
|
|
{
|
|
var list = await _codeVesselRep.ToListAsync();
|
|
await _sysCacheService.SetTimeoutAsync(CommonConst.CACHE_KEY_COMMON_DB_VESSEL, list, TimeSpan.FromMinutes(5));
|
|
return list;
|
|
}
|
|
}
|
|
|
|
public async Task<List<CodeForwarder>> GetAllForwarder()
|
|
{
|
|
if (_sysCacheService.Exists(CommonConst.CACHE_KEY_COMMON_DB_FORWARDER))
|
|
{
|
|
return await _sysCacheService.GetAsync<List<CodeForwarder>>(CommonConst.CACHE_KEY_COMMON_DB_FORWARDER);
|
|
}
|
|
else
|
|
{
|
|
var list = await _codeForwarderRep.ToListAsync();
|
|
await _sysCacheService.SetTimeoutAsync(CommonConst.CACHE_KEY_COMMON_DB_FORWARDER, list, TimeSpan.FromMinutes(5));
|
|
return list;
|
|
}
|
|
}
|
|
|
|
public async Task<List<CodeYard>> GetAllYard()
|
|
{
|
|
if (_sysCacheService.Exists(CommonConst.CACHE_KEY_COMMON_DB_YARD))
|
|
{
|
|
return await _sysCacheService.GetAsync<List<CodeYard>>(CommonConst.CACHE_KEY_COMMON_DB_YARD);
|
|
}
|
|
else
|
|
{
|
|
var list = await _codeYardRep.ToListAsync();
|
|
await _sysCacheService.SetTimeoutAsync(CommonConst.CACHE_KEY_COMMON_DB_YARD, list, TimeSpan.FromMinutes(5));
|
|
return list;
|
|
}
|
|
}
|
|
|
|
public async Task<List<CodePortLoad>> GetAllPortload()
|
|
{
|
|
if (_sysCacheService.Exists(CommonConst.CACHE_KEY_COMMON_DB_PORTLOAD))
|
|
{
|
|
return await _sysCacheService.GetAsync<List<CodePortLoad>>(CommonConst.CACHE_KEY_COMMON_DB_PORTLOAD);
|
|
}
|
|
else
|
|
{
|
|
var list = await _codePortLoadrRep.ToListAsync();
|
|
await _sysCacheService.SetTimeoutAsync(CommonConst.CACHE_KEY_COMMON_DB_PORTLOAD, list, TimeSpan.FromMinutes(5));
|
|
return list;
|
|
}
|
|
}
|
|
|
|
public async Task<List<CodePort>> GetAllPort()
|
|
{
|
|
if (_sysCacheService.Exists(CommonConst.CACHE_KEY_COMMON_DB_PORT))
|
|
{
|
|
return await _sysCacheService.GetAsync<List<CodePort>>(CommonConst.CACHE_KEY_COMMON_DB_PORT);
|
|
}
|
|
else
|
|
{
|
|
var list = await _codePortRep.ToListAsync();
|
|
await _sysCacheService.SetTimeoutAsync(CommonConst.CACHE_KEY_COMMON_DB_PORT, list, TimeSpan.FromMinutes(5));
|
|
return list;
|
|
}
|
|
}
|
|
|
|
public async Task<List<CodePackage>> GetAllPackage()
|
|
{
|
|
if (_sysCacheService.Exists(CommonConst.CACHE_KEY_COMMON_DB_PACKAGE))
|
|
{
|
|
return await _sysCacheService.GetAsync<List<CodePackage>>(CommonConst.CACHE_KEY_COMMON_DB_PACKAGE);
|
|
}
|
|
else
|
|
{
|
|
var list = await _codePackageRep.ToListAsync();
|
|
await _sysCacheService.SetTimeoutAsync(CommonConst.CACHE_KEY_COMMON_DB_PACKAGE, list, TimeSpan.FromMinutes(5));
|
|
return list;
|
|
}
|
|
}
|
|
|
|
public async Task<List<CodeService>> GetAllService()
|
|
{
|
|
if (_sysCacheService.Exists(CommonConst.CACHE_KEY_COMMON_DB_SERVICE))
|
|
{
|
|
return await _sysCacheService.GetAsync<List<CodeService>>(CommonConst.CACHE_KEY_COMMON_DB_SERVICE);
|
|
}
|
|
else
|
|
{
|
|
var list = await _codeServiceRep.ToListAsync();
|
|
await _sysCacheService.SetTimeoutAsync(CommonConst.CACHE_KEY_COMMON_DB_SERVICE, list, TimeSpan.FromMinutes(5));
|
|
return list;
|
|
}
|
|
}
|
|
|
|
public async Task<List<CodeCtn>> GetAllCtn()
|
|
{
|
|
if (_sysCacheService.Exists(CommonConst.CACHE_KEY_COMMON_DB_CTN))
|
|
{
|
|
return await _sysCacheService.GetAsync<List<CodeCtn>>(CommonConst.CACHE_KEY_COMMON_DB_CTN);
|
|
}
|
|
else
|
|
{
|
|
var list = await _codeCtnRep.ToListAsync();
|
|
await _sysCacheService.SetTimeoutAsync(CommonConst.CACHE_KEY_COMMON_DB_CTN, list, TimeSpan.FromMinutes(5));
|
|
return list;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
}
|