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

377 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 SqlSugarRepository<CodeFrt> _codeFrtRep;
2 years ago
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,
SqlSugarRepository<CodeFrt> codeFrtRep,
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;
_codeFrtRep = codeFrtRep;
2 years ago
_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();
}
/// <summary>
/// 付费方式
/// </summary>
[HttpGet("/commondb/frt")]
public async Task<dynamic> FrtList([FromQuery] NameQueryDto input)
{
List<CodeFrt> list = await GetAllFrt();
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();
}
2 years ago
#region 实现接口,获取公共数据并缓存
[NonAction]
2 years ago
public async Task<List<CodeCarrier>> GetAllCarrier()
{
var list = await _sysCacheService.GetAllCodeCarrier();
if (list != null && list.Count > 0)
2 years ago
{
return list;
2 years ago
}
else
{
list = await _codeCarrierRep.ToListAsync();
await _sysCacheService.SetAllCodeCarrier(list);
2 years ago
return list;
2 years ago
}
2 years ago
}
2 years ago
[NonAction]
2 years ago
public async Task<List<CodeVessel>> GetAllVessel()
{
var list = await _sysCacheService.GetAllCodeVessel();
if (list != null && list.Count > 0)
2 years ago
{
return list;
2 years ago
}
else
{
list = await _codeVesselRep.ToListAsync();
await _sysCacheService.SetAllCodeVessel(list);
2 years ago
return list;
}
}
2 years ago
[NonAction]
2 years ago
public async Task<List<CodeForwarder>> GetAllForwarder()
{
var list = await _sysCacheService.GetAllCodeForwarder();
if (list != null && list.Count > 0)
2 years ago
{
return list;
2 years ago
}
else
{
list = await _codeForwarderRep.ToListAsync();
await _sysCacheService.SetAllCodeForwarder(list);
2 years ago
return list;
}
}
[NonAction]
2 years ago
public async Task<List<CodeYard>> GetAllYard()
{
var list = await _sysCacheService.GetAllCodeYard();
if (list != null && list.Count > 0)
2 years ago
{
return list;
2 years ago
}
else
{
list = await _codeYardRep.ToListAsync();
await _sysCacheService.SetAllCodeYard(list);
2 years ago
return list;
}
}
[NonAction]
2 years ago
public async Task<List<CodePortLoad>> GetAllPortload()
{
var list = await _sysCacheService.GetAllCodePortLoad();
if (list != null && list.Count > 0)
2 years ago
{
return list;
2 years ago
}
else
{
list = await _codePortLoadrRep.ToListAsync();
await _sysCacheService.SetAllCodePortLoad(list);
2 years ago
return list;
}
}
[NonAction]
2 years ago
public async Task<List<CodePort>> GetAllPort()
{
var list = await _sysCacheService.GetAllCodePort();
if (list != null && list.Count > 0)
2 years ago
{
return list;
2 years ago
}
else
{
list = await _codePortRep.ToListAsync();
await _sysCacheService.SetAllCodePort(list);
2 years ago
return list;
}
}
[NonAction]
2 years ago
public async Task<List<CodePackage>> GetAllPackage()
{
var list = await _sysCacheService.GetAllCodePackage();
if (list != null && list.Count > 0)
2 years ago
{
return list;
2 years ago
}
else
{
list = await _codePackageRep.ToListAsync();
await _sysCacheService.SetAllCodePackage(list);
2 years ago
return list;
}
}
[NonAction]
2 years ago
public async Task<List<CodeService>> GetAllService()
{
var list = await _sysCacheService.GetAllCodeService();
if (list != null && list.Count > 0)
2 years ago
{
return list;
2 years ago
}
else
{
list = await _codeServiceRep.ToListAsync();
await _sysCacheService.SetAllCodeService(list);
2 years ago
return list;
}
2 years ago
}
2 years ago
[NonAction]
2 years ago
public async Task<List<CodeCtn>> GetAllCtn()
{
var list = await _sysCacheService.GetAllCodeCtn();
if (list != null && list.Count > 0)
2 years ago
{
return list;
2 years ago
}
else
{
list = await _codeCtnRep.ToListAsync();
await _sysCacheService.SetAllCodeCtn(list);
2 years ago
return list;
}
}
[NonAction]
public async Task<List<CodeFrt>> GetAllFrt()
{
var list = await _sysCacheService.GetAllCodeFrt();
if (list != null && list.Count > 0)
{
return list;
}
else
{
list = await _codeFrtRep.ToListAsync();
await _sysCacheService.SetAllCodeFrt(list);
return list;
}
}
2 years ago
#endregion
2 years ago
}