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

322 lines
11 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,
2 years ago
2 years ago
ISysCacheService sysCacheService)
{
_codeCarrierRep = codeCarrierRep;
_codeVesselRep = codeVesselRep;
_codeForwarderRep = codeForwarderRep;
_codeYardRep = codeYardRep;
_codePortLoadrRep = codePortLoadrRep;
_codePortRep = codePortRep;
_codePackageRep = codePackageRep;
_codeServiceRep = codeServiceRep;
_codeCtnRep = codeCtnRep;
_sysCacheService = sysCacheService;
2 years ago
2 years ago
}
/// <summary>
/// 获取船公司列表信息
/// </summary>
[HttpGet("/commondb/carrierlist")]
public async Task<dynamic> CarrierList([FromQuery] CodeCnEnQueryDto input)
{
2 years ago
var list = await GetAllCarrier();
2 years ago
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)
{
2 years ago
//数量太多,不允许查询全部
if (string.IsNullOrEmpty(input.Name) || input.Name.Length < 2)
{
return new List<CodeVessel>();
}
2 years ago
List<CodeVessel> list = await GetAllVessel();
2 years ago
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)
{
2 years ago
List<CodeForwarder> list = await GetAllForwarder();
2 years ago
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)
{
2 years ago
List<CodeYard> list = await GetAllYard();
2 years ago
var queryList = list.WhereIF(!string.IsNullOrEmpty(input.Name), x => x.Name.Contains(input.Name, System.StringComparison.CurrentCultureIgnoreCase));
return queryList.ToList();
}
2 years ago
/// <summary>
/// 获取起始港信息
/// </summary>
[HttpGet("/commondb/portloadlist")]
public async Task<dynamic> PortloadList([FromQuery] NameQueryDto input)
{
2 years ago
List<CodePortLoad> list = await GetAllPortload();
2 years ago
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>();
}
2 years ago
List<CodePort> list = await GetAllPort();
2 years ago
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)
{
2 years ago
List<CodePackage> list = await GetAllPackage();
2 years ago
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)
{
2 years ago
List<CodeService> list = await GetAllService();
2 years ago
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)
{
2 years ago
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))
2 years ago
{
2 years ago
return await _sysCacheService.GetAsync<List<CodeCarrier>>(CommonConst.CACHE_KEY_COMMON_DB_CARRIER);
2 years ago
}
else
{
2 years ago
var list = await _codeCarrierRep.ToListAsync();
await _sysCacheService.SetTimeoutAsync(CommonConst.CACHE_KEY_COMMON_DB_CARRIER, list, TimeSpan.FromMinutes(5));
return list;
2 years ago
}
2 years ago
}
2 years ago
2 years ago
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;
}
}
2 years ago
2 years ago
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;
}
2 years ago
}
2 years ago
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
2 years ago
}