From 4cccc9085b39fe15c88d514bb10cb9585b9b60a6 Mon Sep 17 00:00:00 2001 From: wanghaomei Date: Tue, 21 Mar 2023 11:36:59 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=AE=E7=9A=84=E6=B8=AF=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E8=88=AA=E7=BA=BF=E6=95=B0=E6=8D=AE=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Myshipping.Core/Entity/CommonDB/CodePort.cs | 7 +- Myshipping.Core/Myshipping.Core.xml | 5 + .../Service/CommonDB/CommonDBService.cs | 138 +++++++++++------- 3 files changed, 96 insertions(+), 54 deletions(-) diff --git a/Myshipping.Core/Entity/CommonDB/CodePort.cs b/Myshipping.Core/Entity/CommonDB/CodePort.cs index e3a444b2..d717b4de 100644 --- a/Myshipping.Core/Entity/CommonDB/CodePort.cs +++ b/Myshipping.Core/Entity/CommonDB/CodePort.cs @@ -62,8 +62,11 @@ namespace Myshipping.Core.Entity /// public string Remark { get; set; } - - + /// + /// 航线名称,非数据库列 + /// + [SugarColumn(IsIgnore = false)] + public dynamic LineName { get; set; } } diff --git a/Myshipping.Core/Myshipping.Core.xml b/Myshipping.Core/Myshipping.Core.xml index 2dac93f2..29b98fb1 100644 --- a/Myshipping.Core/Myshipping.Core.xml +++ b/Myshipping.Core/Myshipping.Core.xml @@ -1192,6 +1192,11 @@ 备注 + + + 航线名称,非数据库列 + + 代码 diff --git a/Myshipping.Core/Service/CommonDB/CommonDBService.cs b/Myshipping.Core/Service/CommonDB/CommonDBService.cs index 80820565..fbf106b5 100644 --- a/Myshipping.Core/Service/CommonDB/CommonDBService.cs +++ b/Myshipping.Core/Service/CommonDB/CommonDBService.cs @@ -69,7 +69,7 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie SqlSugarRepository codeIssueTypeRep, SqlSugarRepository commonModuleRep, ILogger logger, - ISysCacheService sysCacheService, + ISysCacheService sysCacheService, SqlSugarRepository codeLaneRep, SqlSugarRepository relaPortCarrierLaneRep, SqlSugarRepository codeCountryRep) @@ -137,14 +137,15 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie entity.CreateUser = UserManager.DjyUserId; await _codeCarrierRep.InsertAsync(entity); } - else { + else + { entity.CreateTime = list.Where(x => x.GID == dto.GID).Select(x => x.CreateTime).FirstOrDefault(); - entity.CreateUser= list.Where(x => x.GID == dto.GID).Select(x => x.CreateUser).FirstOrDefault(); + entity.CreateUser = list.Where(x => x.GID == dto.GID).Select(x => x.CreateUser).FirstOrDefault(); entity.ModifyTime = DateTime.Now; entity.ModifyUser = UserManager.DjyUserId; await _codeCarrierRep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); } - + await GetAllCarrier(); } @@ -179,7 +180,8 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie { var list = await _sysCacheService.GetAllMappingCarrier(); var count = list.Where(x => x.Module == dto.Module && x.Code == dto.Code && x.GID != dto.GID).Count(); - if (count>0) { + if (count > 0) + { throw Oops.Bah(ErrorCode.D1006); } var entity = dto.Adapt(); @@ -216,14 +218,14 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie //数量太多,不允许查询全部 if (string.IsNullOrEmpty(input.KeyWord)) { - return list.Take(10); + return list.Take(10); } var queryList = list.WhereIF(!string.IsNullOrEmpty(input.KeyWord), x => x.Name.Contains(input.KeyWord, System.StringComparison.CurrentCultureIgnoreCase)); if (queryList.Count() > 20) { return queryList.Take(input.Limit).OrderBy(x => x.Sort).ToList(); } - return queryList.OrderBy(x=>x.Sort).Take(10).ToList(); + return queryList.OrderBy(x => x.Sort).Take(10).ToList(); } /// @@ -272,7 +274,7 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie List list = await _sysCacheService.GetAllMappingVessel(); var queryList = list.Where(x => x.Module == input.Module) - + .WhereIF(!string.IsNullOrEmpty(input.KeyWord), x => x.MapName.Contains(input.KeyWord, System.StringComparison.CurrentCultureIgnoreCase) || x.Name.Contains(input.KeyWord, System.StringComparison.CurrentCultureIgnoreCase)); if (queryList.Count() > 20) @@ -291,7 +293,7 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie var list = await _sysCacheService.GetAllMappingVessel(); - var count = list.Where(x => x.Name == dto.Name.Trim()&&x.Module==dto.Module && x.GID != dto.GID).Count(); + var count = list.Where(x => x.Name == dto.Name.Trim() && x.Module == dto.Module && x.GID != dto.GID).Count(); if (count > 0) { throw Oops.Bah(ErrorCode.D1006); @@ -344,7 +346,7 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie public async Task AddForwarder([FromBody] CodeForwarderDto dto) { var list = await _sysCacheService.GetAllCodeForwarder(); - var count = list.Where(x =>x.Code == dto.Code && x.GID != dto.GID).Count(); + var count = list.Where(x => x.Code == dto.Code && x.GID != dto.GID).Count(); if (count > 0) { throw Oops.Bah(ErrorCode.D1006); @@ -357,7 +359,8 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie entity.CreateUser = UserManager.DjyUserId; await _codeForwarderRep.InsertAsync(entity); } - else { + else + { entity.CreateTime = list.Where(x => x.GID == dto.GID).Select(x => x.CreateTime).FirstOrDefault(); entity.CreateUser = list.Where(x => x.GID == dto.GID).Select(x => x.CreateUser).FirstOrDefault(); @@ -366,7 +369,7 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie await _codeForwarderRep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); } - + await GetAllForwarder(); } #endregion @@ -391,7 +394,7 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie { var list = await _sysCacheService.GetAllCodeYard(); - var count = list.Where(x => x.Code == dto.Code && x.GID != dto.GID).Count(); + var count = list.Where(x => x.Code == dto.Code && x.GID != dto.GID).Count(); if (count > 0) { throw Oops.Bah(ErrorCode.D1006); @@ -406,7 +409,8 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie await _codeYardRep.InsertAsync(entity); } - else { + else + { entity.CreateTime = list.Where(x => x.GID == dto.GID).Select(x => x.CreateTime).FirstOrDefault(); entity.CreateUser = list.Where(x => x.GID == dto.GID).Select(x => x.CreateUser).FirstOrDefault(); entity.ModifyTime = DateTime.Now; @@ -414,7 +418,7 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie await _codeYardRep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); } - + await GetAllYard(); } @@ -450,7 +454,7 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie { var list = await _sysCacheService.GetAllMappingYard(); - var count = list.Where(x => x.Code == dto.Code&&x.Module==dto.Module && x.GID != dto.GID).Count(); + var count = list.Where(x => x.Code == dto.Code && x.Module == dto.Module && x.GID != dto.GID).Count(); if (count > 0) { throw Oops.Bah(ErrorCode.D1006); @@ -487,13 +491,13 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie public async Task PortloadList([FromQuery] NameQueryDto input) { List list = await _sysCacheService.GetAllCodePortLoad(); - _logger.LogInformation("起始港1:"+DateTime.Now.ToString()); + _logger.LogInformation("起始港1:" + DateTime.Now.ToString()); var queryList = list.WhereIF(!string.IsNullOrEmpty(input.KeyWord), x => x.Code.Contains(input.KeyWord, System.StringComparison.CurrentCultureIgnoreCase) || x.EnName.Contains(input.KeyWord, System.StringComparison.CurrentCultureIgnoreCase) || - x.CnName.Contains(input.KeyWord, System.StringComparison.CurrentCultureIgnoreCase) || + x.CnName.Contains(input.KeyWord, System.StringComparison.CurrentCultureIgnoreCase) || x.EdiCode.Contains(input.KeyWord, System.StringComparison.CurrentCultureIgnoreCase)); - _logger.LogInformation("起始港2:"+DateTime.Now.ToString()); + _logger.LogInformation("起始港2:" + DateTime.Now.ToString()); if (queryList.Count() > 20) { return queryList.Take(input.Limit).OrderBy(x => x.Sort).ToList(); @@ -520,7 +524,8 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie entity.CreateUser = UserManager.DjyUserId; await _codePortLoadrRep.InsertAsync(entity); } - else { + else + { entity.CreateTime = list.Where(x => x.GID == dto.GID).Select(x => x.CreateTime).FirstOrDefault(); entity.CreateUser = list.Where(x => x.GID == dto.GID).Select(x => x.CreateUser).FirstOrDefault(); @@ -529,7 +534,7 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie await _codePortLoadrRep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); } - + await GetAllPortload(); } @@ -565,7 +570,7 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie public async Task AddOrUpdatePortload([FromBody] MappingPortLoadDto dto) { var list = await _sysCacheService.GetAllMappingPortLoad(); - var count = list.Where(x => x.Code == dto.Code&&x.Module==dto.Module&&x.CarrierCode==dto.CarrierCode && x.GID != dto.GID).Count(); + var count = list.Where(x => x.Code == dto.Code && x.Module == dto.Module && x.CarrierCode == dto.CarrierCode && x.GID != dto.GID).Count(); if (count > 0) { throw Oops.Bah(ErrorCode.D1006); @@ -601,17 +606,42 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie public async Task PortList([FromQuery] NameQueryDto input) { List list = await _sysCacheService.GetAllCodePort(); - if (string.IsNullOrWhiteSpace(input.KeyWord)) { - - return list.Take(10); + var listLineRela = await _sysCacheService.GetAllRelaPortCarrierLane(); + var listLine = await _sysCacheService.GetAllCodeLane(); + List result = null; + if (string.IsNullOrWhiteSpace(input.KeyWord)) + { + result = list.Take(10).ToList(); } - var queryList = list.WhereIF(!string.IsNullOrEmpty(input.KeyWord), x => x.Code.Contains(input.KeyWord, System.StringComparison.CurrentCultureIgnoreCase) - || x.EnName.Contains(input.KeyWord, System.StringComparison.CurrentCultureIgnoreCase) || x.CnName.Contains(input.KeyWord, System.StringComparison.CurrentCultureIgnoreCase) || x.EdiCode.Contains(input.KeyWord, System.StringComparison.CurrentCultureIgnoreCase)); - if (queryList.Count()>20) { - return queryList.Take(input.Limit).OrderBy(x => x.Sort).ToList(); + else + { + var queryList = list.WhereIF(!string.IsNullOrEmpty(input.KeyWord), x => x.Code.Contains(input.KeyWord, System.StringComparison.CurrentCultureIgnoreCase) + || x.EnName.Contains(input.KeyWord, System.StringComparison.CurrentCultureIgnoreCase) || x.CnName.Contains(input.KeyWord, System.StringComparison.CurrentCultureIgnoreCase) || x.EdiCode.Contains(input.KeyWord, System.StringComparison.CurrentCultureIgnoreCase)); + if (queryList.Count() > 20) + { + result = queryList.Take(input.Limit).OrderBy(x => x.Sort).ToList(); + } + else + { + + result = queryList.OrderBy(x => x.Sort).ToList(); + } } - return queryList.OrderBy(x => x.Sort).ToList(); + result.ForEach(x => + { + var query = from line in listLine + join lineRel in listLineRela on line.Code equals lineRel.LaneCode + where lineRel.PortCode == x.Code + select new { line, lineRel }; + x.LineName = query.Select(x => new + { + x.line.CnName, + x.lineRel.CarrierCode + }).ToList(); + }); + + return result; } @@ -636,7 +666,8 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie await _codePortRep.InsertAsync(entity); } - else { + else + { entity.CreateTime = list.Where(x => x.GID == dto.GID).Select(x => x.CreateTime).FirstOrDefault(); entity.CreateUser = list.Where(x => x.GID == dto.GID).Select(x => x.CreateUser).FirstOrDefault(); entity.ModifyTime = DateTime.Now; @@ -644,7 +675,7 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie await _codePortRep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); } - + await GetAllPort(); } /// @@ -679,7 +710,7 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie public async Task AddOrUpdatePort([FromBody] MappingPortDto dto) { var list = await _sysCacheService.GetAllMappingPort(); - var count = list.Where(x => x.Code == dto.Code && x.Module == dto.Module&&x.CarrierCode==dto.CarrierCode && x.GID != dto.GID).Count(); + var count = list.Where(x => x.Code == dto.Code && x.Module == dto.Module && x.CarrierCode == dto.CarrierCode && x.GID != dto.GID).Count(); if (count > 0) { throw Oops.Bah(ErrorCode.D1006); @@ -716,7 +747,7 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie var queryList = list.WhereIF(!string.IsNullOrEmpty(input.KeyWord), x => x.Name.Contains(input.KeyWord, System.StringComparison.CurrentCultureIgnoreCase) || x.Code.Contains(input.KeyWord, System.StringComparison.CurrentCultureIgnoreCase) || x.EdiCode.Contains(input.KeyWord, System.StringComparison.CurrentCultureIgnoreCase)); - return queryList.OrderBy(x=>x.Sort).ToList(); + return queryList.OrderBy(x => x.Sort).ToList(); } /// /// 新增包装信息 @@ -726,7 +757,7 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie { var list = await _sysCacheService.GetAllCodePackage(); var count = list.Where(x => x.Code == dto.Code && x.GID != dto.GID).Count(); - if (count > 0 ) + if (count > 0) { throw Oops.Bah(ErrorCode.D1006); } @@ -782,7 +813,7 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie public async Task AddOrUpdateMappingPackage([FromBody] MappingPackageDto dto) { var list = await _sysCacheService.GetAllMappingPackage(); - var count = list.Where(x => x.Code == dto.Code && x.Module == dto.Module &&x.CarrierCode==dto.CarrierCode && x.GID != dto.GID).Count(); + var count = list.Where(x => x.Code == dto.Code && x.Module == dto.Module && x.CarrierCode == dto.CarrierCode && x.GID != dto.GID).Count(); if (count > 0) { throw Oops.Bah(ErrorCode.D1006); @@ -846,7 +877,8 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie await _codeServiceRep.InsertAsync(entity); } - else { + else + { entity.CreateTime = list.Where(x => x.GID == dto.GID).Select(x => x.CreateTime).FirstOrDefault(); entity.CreateUser = list.Where(x => x.GID == dto.GID).Select(x => x.CreateUser).FirstOrDefault(); @@ -854,7 +886,7 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie entity.ModifyUser = UserManager.DjyUserId; await _codeServiceRep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); } - + await GetAllService(); } @@ -890,7 +922,7 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie public async Task AddOrUpdateMappingService([FromBody] MappingServiceDto dto) { var list = await _sysCacheService.GetAllMappingService(); - var count = list.Where(x => x.Code == dto.Code && x.Module == dto.Module&&x.CarrierCode==dto.CarrierCode && x.GID != dto.GID).Count(); + var count = list.Where(x => x.Code == dto.Code && x.Module == dto.Module && x.CarrierCode == dto.CarrierCode && x.GID != dto.GID).Count(); if (count > 0) { throw Oops.Bah(ErrorCode.D1006); @@ -926,7 +958,7 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie List list = await _sysCacheService.GetAllCodeCtn(); var queryList = list.WhereIF(!string.IsNullOrEmpty(input.KeyWord), x => x.Name.Contains(input.KeyWord, System.StringComparison.CurrentCultureIgnoreCase) || x.Code.Contains(input.KeyWord, System.StringComparison.CurrentCultureIgnoreCase) - || x.EdiCode.Contains(input.KeyWord, System.StringComparison.CurrentCultureIgnoreCase)).OrderByDescending(x=>x.CreateTime); + || x.EdiCode.Contains(input.KeyWord, System.StringComparison.CurrentCultureIgnoreCase)).OrderByDescending(x => x.CreateTime); return queryList.OrderBy(x => x.Sort).ToList(); } @@ -1009,7 +1041,7 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie public async Task AddOrUpdateMappingCtn([FromBody] MappingCtnDto dto) { var list = await _sysCacheService.GetAllMappingCtn(); - var count = list.Where(x => x.Code == dto.Code && x.Module == dto.Module&&x.CarrierCode==dto.CarrierCode && x.GID != dto.GID).Count(); + var count = list.Where(x => x.Code == dto.Code && x.Module == dto.Module && x.CarrierCode == dto.CarrierCode && x.GID != dto.GID).Count(); if (count > 0) { throw Oops.Bah(ErrorCode.D1006); @@ -1077,7 +1109,8 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie entity.CreateUser = UserManager.DjyUserId; await _codeFrtRep.InsertAsync(entity); } - else { + else + { entity.CreateTime = list.Where(x => x.GID == dto.GID).Select(x => x.CreateTime).FirstOrDefault(); entity.CreateUser = list.Where(x => x.GID == dto.GID).Select(x => x.CreateUser).FirstOrDefault(); @@ -1085,7 +1118,7 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie entity.ModifyUser = UserManager.DjyUserId; await _codeFrtRep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); } - + await GetAllFrt(); } @@ -1118,7 +1151,7 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie public async Task AddOrUpdateMappingFrt([FromBody] MappingFrtDto dto) { var list = await _sysCacheService.GetAllMappingFrt(); - var count = list.Where(x => x.Code == dto.Code && x.Module == dto.Module&&x.CarrierCode==dto.CarrierCode &&x.GID!=dto.GID).Count(); + var count = list.Where(x => x.Code == dto.Code && x.Module == dto.Module && x.CarrierCode == dto.CarrierCode && x.GID != dto.GID).Count(); if (count > 0) { throw Oops.Bah(ErrorCode.D1006); @@ -1178,14 +1211,15 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie entity.CreateUser = UserManager.DjyUserId; await _codeIssueTypeRep.InsertAsync(entity); } - else { + else + { entity.CreateTime = list.Where(x => x.GID == dto.GID).Select(x => x.CreateTime).FirstOrDefault(); entity.CreateUser = list.Where(x => x.GID == dto.GID).Select(x => x.CreateUser).FirstOrDefault(); entity.ModifyTime = DateTime.Now; entity.ModifyUser = UserManager.DjyUserId; await _codeIssueTypeRep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); } - + await GetAllCodeIssueType(); } #endregion @@ -1217,7 +1251,7 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie */ var entity = dto.Adapt(); - if(!string.IsNullOrWhiteSpace(entity.GID)) + if (!string.IsNullOrWhiteSpace(entity.GID)) { var model = _codeLaneRep.AsQueryable().InSingle(entity.GID); @@ -1240,9 +1274,9 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie } else { - var model = _codeLaneRep.AsQueryable().First(t=>t.Code == entity.Code); + var model = _codeLaneRep.AsQueryable().First(t => t.Code == entity.Code); - if(model != null) + if (model != null) throw Oops.Bah(ErrorCode.D1006); entity.GID = Guid.NewGuid().ToString(); @@ -1266,7 +1300,7 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie { List list = await _sysCacheService.GetAllCodeLane(); - var queryList = list.WhereIF(!string.IsNullOrEmpty(input.KeyWord), + var queryList = list.WhereIF(!string.IsNullOrEmpty(input.KeyWord), x => (!string.IsNullOrWhiteSpace(x.Code) && x.Code.Contains(input.KeyWord, System.StringComparison.CurrentCultureIgnoreCase)) || (!string.IsNullOrWhiteSpace(x.EnName) && x.EnName.Contains(input.KeyWord, System.StringComparison.CurrentCultureIgnoreCase)) || (!string.IsNullOrWhiteSpace(x.CnName) && x.CnName.Contains(input.KeyWord, System.StringComparison.CurrentCultureIgnoreCase)) @@ -1308,8 +1342,8 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie } else { - var model = _relaPortCarrierLaneRep.AsQueryable().Where(t => t.LaneCode == entity.LaneCode - && t.Module == entity.Module + var model = _relaPortCarrierLaneRep.AsQueryable().Where(t => t.LaneCode == entity.LaneCode + && t.Module == entity.Module && t.CarrierCode == entity.CarrierCode && t.PortCode == entity.PortCode).First();