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; /// /// 公共库 /// [ApiDescriptionSettings(Name = "CommonDB", Order = 1000)] public class CommonDBService : ICommonDBService, IDynamicApiController, ITransient { private readonly SqlSugarRepository _codeCarrierRep; private readonly SqlSugarRepository _mappingCarrierRep; private readonly SqlSugarRepository _codeVesselRep; private readonly SqlSugarRepository _mappingVesselRep; private readonly SqlSugarRepository _codeForwarderRep; private readonly SqlSugarRepository _codeYardRep; private readonly SqlSugarRepository _codePortLoadrRep; private readonly SqlSugarRepository _codePortRep; private readonly SqlSugarRepository _codePackageRep; private readonly SqlSugarRepository _codeServiceRep; private readonly SqlSugarRepository _codeCtnRep; private readonly SqlSugarRepository _mappingCtnRep; private readonly SqlSugarRepository _codeFrtRep; private readonly SqlSugarRepository _mappingFrtRep; private readonly ISysCacheService _sysCacheService; public CommonDBService(SqlSugarRepository codeCarrierRep, SqlSugarRepository codeVesselRep, SqlSugarRepository codeForwarderRep, SqlSugarRepository codeYardRep, SqlSugarRepository codePortLoadrRep, SqlSugarRepository codePortRep, SqlSugarRepository codePackageRep, SqlSugarRepository codeServiceRep, SqlSugarRepository codeCtnRep, SqlSugarRepository codeFrtRep, SqlSugarRepository mappingCarrierRep, SqlSugarRepository mappingVesselRep, SqlSugarRepository mappingCtnRep, SqlSugarRepository mappingFrtRep, ISysCacheService sysCacheService) { _codeCarrierRep = codeCarrierRep; _codeVesselRep = codeVesselRep; _codeForwarderRep = codeForwarderRep; _codeYardRep = codeYardRep; _codePortLoadrRep = codePortLoadrRep; _codePortRep = codePortRep; _codePackageRep = codePackageRep; _codeServiceRep = codeServiceRep; _codeCtnRep = codeCtnRep; _codeFrtRep = codeFrtRep; _mappingCarrierRep = mappingCarrierRep; _mappingVesselRep = mappingVesselRep; _mappingCtnRep = mappingCtnRep; _mappingFrtRep = mappingFrtRep; _sysCacheService = sysCacheService; } #region 船公司 /// /// 获取船公司列表信息 /// [HttpGet("/commondb/carrierlist")] public async Task CarrierList([FromQuery] CodeCnEnQueryDto input) { var list = await _sysCacheService.GetAllCodeCarrier(); 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(); } /// /// 新增船公司信息 /// [HttpPost("/commondb/addcarrier")] public async Task AddCarrier([FromBody] CodeCarrier dto) { var entity = dto.Adapt(); await _codeCarrierRep.InsertAsync(entity); await GetAllCarrier(); } /// /// 获取船公司映射列表信息 /// [HttpGet("/commondb/mappingcarrierlist")] public async Task MappingCarrierList([FromQuery] MappingQueryDto input) { var list = await _sysCacheService.GetAllMappingCarrier(); var queryList = list .WhereIF(!string.IsNullOrEmpty(input.Code), x => x.Code.Contains(input.Code, System.StringComparison.CurrentCultureIgnoreCase)) .WhereIF(!string.IsNullOrEmpty(input.MapCode), x => x.MapCode.Contains(input.MapCode, System.StringComparison.CurrentCultureIgnoreCase)) .WhereIF(!string.IsNullOrEmpty(input.Module), x => x.Module == input.Module) .WhereIF(!string.IsNullOrEmpty(input.MapName), x => x.Code.Contains(input.MapName, System.StringComparison.CurrentCultureIgnoreCase)); return queryList.ToList(); } /// /// 新增编辑船公司映射信息 /// [HttpPost("/commondb/addorupdatemappingcarrier")] public async Task AddOrUpdateMappingCarrier([FromBody] MappingCarrier dto) { var entity = dto.Adapt(); if (string.IsNullOrWhiteSpace(dto.GID)) { await _mappingCarrierRep.InsertAsync(entity); } else { await _mappingCarrierRep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); } await GetAllMappingCarrier(); } #endregion #region 船名 /// /// 获取船名列表信息 /// [HttpGet("/commondb/vessellist")] public async Task VesselList([FromQuery] NameQueryDto input) { //数量太多,不允许查询全部 if (string.IsNullOrEmpty(input.Name) || input.Name.Length < 2) { return new List(); } List list = await _sysCacheService.GetAllCodeVessel(); var queryList = list.WhereIF(!string.IsNullOrEmpty(input.Name), x => x.Name.Contains(input.Name, System.StringComparison.CurrentCultureIgnoreCase)); return queryList.ToList(); } /// /// 新增船名信息 /// [HttpPost("/commondb/addvessel")] public async Task AddVessel([FromBody] CodeVessel dto) { var entity = dto.Adapt(); await _codeVesselRep.InsertAsync(entity); await GetAllVessel(); } /// /// 获取船名映射 /// [HttpGet("/commondb/mappingvessellist")] public async Task MappingVesselList([FromQuery] MappingQueryDto input) { //数量太多,不允许查询全部 if (string.IsNullOrEmpty(input.Module) || input.Module.Length < 1) { return new List(); } List list = await _sysCacheService.GetAllMappingVessel(); var queryList = list.WhereIF(!string.IsNullOrEmpty(input.Module), x => x.Module == input.Module) .WhereIF(!string.IsNullOrEmpty(input.MapName), x => x.Name.Contains(input.MapName, System.StringComparison.CurrentCultureIgnoreCase)); return queryList.ToList(); } /// /// 新增编辑船名映射信息 /// [HttpPost("/commondb/addorupdatevessel")] public async Task AddOrUpdateMappingVessel([FromBody] MappingVessel dto) { var entity = dto.Adapt(); if (string.IsNullOrWhiteSpace(dto.GID)) { await _mappingVesselRep.InsertAsync(entity); } else { await _mappingVesselRep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); } await GetAllMappingVessel(); } #endregion #region 船代 /// /// 获取船代列表信息 /// [HttpGet("/commondb/forwarderlist")] public async Task ForwarderList([FromQuery] NameQueryDto input) { List list = await _sysCacheService.GetAllCodeForwarder(); var queryList = list.WhereIF(!string.IsNullOrEmpty(input.Name), x => x.Name.Contains(input.Name, System.StringComparison.CurrentCultureIgnoreCase)); return queryList.ToList(); } /// /// 新增船代信息 /// [HttpPost("/commondb/addforwarder")] public async Task AddForwarder([FromBody] CodeForwarder dto) { var entity = dto.Adapt(); await _codeForwarderRep.InsertAsync(entity); await GetAllForwarder(); } #endregion #region 场站 /// /// 获取场站列表信息 /// [HttpGet("/commondb/yardlist")] public async Task YardList([FromQuery] NameQueryDto input) { List list = await _sysCacheService.GetAllCodeYard(); var queryList = list.WhereIF(!string.IsNullOrEmpty(input.Name), x => x.Name.Contains(input.Name, System.StringComparison.CurrentCultureIgnoreCase)); return queryList.ToList(); } /// /// 新增场站信息 /// [HttpPost("/commondb/addyard")] public async Task AddYard([FromBody] CodeYard dto) { var entity = dto.Adapt(); await _codeYardRep.InsertAsync(entity); await GetAllYard(); } #endregion #region 起始港 /// /// 获取起始港信息 /// [HttpGet("/commondb/portloadlist")] public async Task PortloadList([FromQuery] NameQueryDto input) { List list = await _sysCacheService.GetAllCodePortLoad(); 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(); } /// /// 新增起始港信息 /// [HttpPost("/commondb/addportload")] public async Task AddPortload([FromBody] CodePortLoad dto) { var entity = dto.Adapt(); await _codePortLoadrRep.InsertAsync(entity); await GetAllPortload(); } #endregion #region 目的港 /// /// 获取目的港信息 /// [HttpGet("/commondb/portlist")] public async Task PortList([FromQuery] NameQueryDto input) { //数量太多,不允许查询全部 if (string.IsNullOrEmpty(input.Name) || input.Name.Length < 2) { return new List(); } List list = await _sysCacheService.GetAllCodePort(); 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(); } /// /// 新增目的港信息 /// [HttpPost("/commondb/addport")] public async Task AddPort([FromBody] CodePort dto) { var entity = dto.Adapt(); await _codePortRep.InsertAsync(entity); await GetAllPort(); } #endregion #region 包装 /// /// 获取包装信息 /// [HttpGet("/commondb/package")] public async Task PackageList([FromQuery] NameQueryDto input) { List list = await _sysCacheService.GetAllCodePackage(); var queryList = list.WhereIF(!string.IsNullOrEmpty(input.Name), x => x.Name.Contains(input.Name, System.StringComparison.CurrentCultureIgnoreCase)); return queryList.ToList(); } /// /// 新增包装信息 /// [HttpPost("/commondb/addpackage")] public async Task AddPackage([FromBody] CodePackage dto) { var entity = dto.Adapt(); await _codePackageRep.InsertAsync(entity); await GetAllPackage(); } #endregion #region 运输条款 /// /// 获取运输条款信息 /// [HttpGet("/commondb/service")] public async Task ServiceList([FromQuery] NameQueryDto input) { List list = await _sysCacheService.GetAllCodeService(); var queryList = list.WhereIF(!string.IsNullOrEmpty(input.Name), x => x.Name.Contains(input.Name, System.StringComparison.CurrentCultureIgnoreCase)); return queryList.ToList(); } /// /// 新增运输条款 /// [HttpPost("/commondb/addservice")] public async Task AddService([FromBody] CodeService dto) { var entity = dto.Adapt(); await _codeServiceRep.InsertAsync(entity); await GetAllService(); } #endregion #region 箱型 /// /// 获取箱型信息 /// [HttpGet("/commondb/ctn")] public async Task CtnList([FromQuery] NameQueryDto input) { List list = await _sysCacheService.GetAllCodeCtn(); var queryList = list.WhereIF(!string.IsNullOrEmpty(input.Name), x => x.Name.Contains(input.Name, System.StringComparison.CurrentCultureIgnoreCase)); return queryList.ToList(); } /// /// 新增箱型 /// [HttpPost("/commondb/addctn")] public async Task AddCtn([FromBody] CodeCtn dto) { var entity = dto.Adapt(); await _codeCtnRep.InsertAsync(entity); await GetAllCtn(); } /// /// 获取箱型映射列表信息 /// [HttpGet("/commondb/mappingctnlist")] public async Task MappingCtnList([FromQuery] MappingQueryDto input) { var list = await _sysCacheService.GetAllMappingCtn(); var queryList = list .WhereIF(!string.IsNullOrEmpty(input.Code), x => x.Code.Contains(input.Code, System.StringComparison.CurrentCultureIgnoreCase)) .WhereIF(!string.IsNullOrEmpty(input.MapCode), x => x.MapCode.Contains(input.MapCode, System.StringComparison.CurrentCultureIgnoreCase)) .WhereIF(!string.IsNullOrEmpty(input.Module), x => x.Module == input.Module) .WhereIF(!string.IsNullOrEmpty(input.MapName), x => x.Code.Contains(input.MapName, System.StringComparison.CurrentCultureIgnoreCase)); return queryList.ToList(); } /// /// 新增编辑箱型映射信息 /// [HttpPost("/commondb/addmappingctn")] public async Task AddOrUpdateMappingCtn([FromBody] MappingCtn dto) { var entity = dto.Adapt(); if (string.IsNullOrWhiteSpace(dto.GID)) { await _mappingCtnRep.InsertAsync(entity); } else { await _mappingCtnRep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); } await GetAllMappingCtn(); } #endregion #region 付费方式 /// /// 付费方式 /// [HttpGet("/commondb/frt")] public async Task FrtList([FromQuery] NameQueryDto input) { List list = await _sysCacheService.GetAllCodeFrt(); 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(); } /// /// 新增付费方式 /// [HttpPost("/commondb/addfrt")] public async Task AddFrt([FromBody] CodeFrt dto) { var entity = dto.Adapt(); await _codeFrtRep.InsertAsync(entity); await GetAllFrt(); } /// /// 获取付费映射列表信息 /// [HttpGet("/commondb/mappingfrtlist")] public async Task MappingFrtList([FromQuery] MappingQueryDto input) { var list = await _sysCacheService.GetAllMappingFrt(); var queryList = list .WhereIF(!string.IsNullOrEmpty(input.Code), x => x.Code.Contains(input.Code, System.StringComparison.CurrentCultureIgnoreCase)) .WhereIF(!string.IsNullOrEmpty(input.MapCode), x => x.MapCode.Contains(input.MapCode, System.StringComparison.CurrentCultureIgnoreCase)) .WhereIF(!string.IsNullOrEmpty(input.Module), x => x.Module == input.Module) .WhereIF(!string.IsNullOrEmpty(input.MapName), x => x.Code.Contains(input.MapName, System.StringComparison.CurrentCultureIgnoreCase)); return queryList.ToList(); } /// /// 新增编辑付费映射信息 /// [HttpPost("/commondb/addmappingfrt")] public async Task AddOrUpdateMappingFrt([FromBody] MappingFrt dto) { var entity = dto.Adapt(); if (string.IsNullOrWhiteSpace(dto.GID)) { await _mappingFrtRep.InsertAsync(entity); } else { await _mappingFrtRep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); } await GetAllMappingFrt(); } #endregion #region 实现接口,获取公共数据并缓存 [NonAction] public async Task> GetAllCarrier() { var list = await _codeCarrierRep.ToListAsync(); await _sysCacheService.SetAllCodeCarrier(list); return list; } [NonAction] public async Task> GetAllMappingCarrier() { var list = await _mappingCarrierRep.ToListAsync(); await _sysCacheService.SetAllMappingCarrier(list); return list; } [NonAction] public async Task> GetAllVessel() { var list = await _codeVesselRep.ToListAsync(); await _sysCacheService.SetAllCodeVessel(list); return list; } [NonAction] public async Task> GetAllMappingVessel() { var list = await _mappingVesselRep.ToListAsync(); await _sysCacheService.SetAllMappingVessel(list); return list; } [NonAction] public async Task> GetAllForwarder() { var list = await _codeForwarderRep.ToListAsync(); await _sysCacheService.SetAllCodeForwarder(list); return list; } [NonAction] public async Task> GetAllYard() { var list = await _codeYardRep.ToListAsync(); await _sysCacheService.SetAllCodeYard(list); return list; } [NonAction] public async Task> GetAllPortload() { var list = await _codePortLoadrRep.ToListAsync(); await _sysCacheService.SetAllCodePortLoad(list); return list; } [NonAction] public async Task> GetAllPort() { var list = await _codePortRep.ToListAsync(); await _sysCacheService.SetAllCodePort(list); return list; } [NonAction] public async Task> GetAllPackage() { var list = await _codePackageRep.ToListAsync(); await _sysCacheService.SetAllCodePackage(list); return list; } [NonAction] public async Task> GetAllService() { var list = await _codeServiceRep.ToListAsync(); await _sysCacheService.SetAllCodeService(list); return list; } [NonAction] public async Task> GetAllCtn() { var list = await _codeCtnRep.ToListAsync(); await _sysCacheService.SetAllCodeCtn(list); return list; } [NonAction] public async Task> GetAllMappingCtn() { var list = await _mappingCtnRep.ToListAsync(); await _sysCacheService.SetAllMappingCtn(list); return list; } [NonAction] public async Task> GetAllFrt() { var list = await _codeFrtRep.ToListAsync(); await _sysCacheService.SetAllCodeFrt(list); return list; } [NonAction] public async Task> GetAllMappingFrt() { var list = await _mappingFrtRep.ToListAsync(); await _sysCacheService.SetAllMappingFrt(list); return list; } #endregion }