diff --git a/Myshipping.Application/Entity/BookingExcelTemplate.cs b/Myshipping.Application/Entity/BookingExcelTemplate.cs index ef40c6ca..37fa3d20 100644 --- a/Myshipping.Application/Entity/BookingExcelTemplate.cs +++ b/Myshipping.Application/Entity/BookingExcelTemplate.cs @@ -14,7 +14,7 @@ namespace Myshipping.Application.Entity /// /// 父键 /// - public long Pid { get; set; } + public long PId { get; set; } /// /// 字段名称 /// diff --git a/Myshipping.Application/Myshipping.Application.xml b/Myshipping.Application/Myshipping.Application.xml index 60cc216d..aba82a82 100644 --- a/Myshipping.Application/Myshipping.Application.xml +++ b/Myshipping.Application/Myshipping.Application.xml @@ -2395,7 +2395,7 @@ 订舱状态 - + 父键 @@ -9975,6 +9975,19 @@ + + + 同步船期 + + + + + + + 测试用 + + + 订舱客户同步 diff --git a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs index 57a8447c..c3a9a2b1 100644 --- a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs +++ b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs @@ -1735,7 +1735,7 @@ namespace Myshipping.Application var excelwork = new HSSFWorkbook(result); var sheet = excelwork.GetSheetAt(0); var order = await _rep.AsQueryable().Where(x => x.Id == bookingId).FirstAsync(); - var entity = await _excelrep.AsQueryable().Where(x => x.Pid == templateId).OrderBy(x => x.Row).ToListAsync(); + var entity = await _excelrep.AsQueryable().Where(x => x.PId == templateId).OrderBy(x => x.Row).ToListAsync(); //单元格样式 var cellStyle = NpoiExcelExportHelper._.CreateStyle(excelwork, HorizontalAlignment.Center, VerticalAlignment.Center, 10, true, 0); for (int _row = 0; _row < entity.Max(x => x.Row); _row++) diff --git a/Myshipping.Application/Service/BookingPrintTemplate/BookingPrintTemplateService.cs b/Myshipping.Application/Service/BookingPrintTemplate/BookingPrintTemplateService.cs index 7b7c7a00..680eecb2 100644 --- a/Myshipping.Application/Service/BookingPrintTemplate/BookingPrintTemplateService.cs +++ b/Myshipping.Application/Service/BookingPrintTemplate/BookingPrintTemplateService.cs @@ -448,11 +448,11 @@ namespace Myshipping.Application { - await _excelrep.DeleteAsync(x => x.Pid == dto.Pid); + await _excelrep.DeleteAsync(x => x.PId == dto.Pid); foreach (var item in dto.children) { var entity = item.Adapt(); - + entity.PId = dto.Pid; await _excelrep.InsertAsync(entity); } } @@ -464,7 +464,7 @@ namespace Myshipping.Application [HttpGet("/BookingTemplate/BookingExcelTemplateList")] public async Task BookingExcelTemplateList(long Id) { - return await _excelrep.AsQueryable().Where(x => x.Pid == Id).ToListAsync(); + return await _excelrep.AsQueryable().Where(x => x.PId == Id).ToListAsync(); } } diff --git a/Myshipping.Application/Service/DataSync/DataSyncService.cs b/Myshipping.Application/Service/DataSync/DataSyncService.cs index a3bdbeb1..f32b1b2e 100644 --- a/Myshipping.Application/Service/DataSync/DataSyncService.cs +++ b/Myshipping.Application/Service/DataSync/DataSyncService.cs @@ -72,7 +72,7 @@ namespace Myshipping.Application /// /// /// - [HttpPost("/DataSync/SyncCustomer"),ApiUser(ApiCode="")] + [HttpPost("/DataSync/SyncCustomer"),ApiUser(ApiCode= "SyncCustomer")] public async Task SyncCustomer(DjyCustomerSyncDto model) { @@ -111,8 +111,8 @@ namespace Myshipping.Application /// /// /// - [HttpPost("/DataSync/SyncVesselInfo"), ApiUser] - public async Task SyncVesselInfo(DjyVesselInfoDto model) + [HttpPost("/DataSync/SyncVesselDate"), ApiUser(ApiCode = "SyncVesselDate")] + public async Task SyncVesselDate(DjyVesselInfoDto model) { if (string.IsNullOrWhiteSpace(model.Vessel)|| string.IsNullOrWhiteSpace(model.CARRIERID)) @@ -142,7 +142,11 @@ namespace Myshipping.Application #endregion #region 其他 - [HttpGet("/DataSync/Test"), ApiUser] + /// + /// 测试用 + /// + /// + [HttpGet("/DataSync/Test"), ApiUser(ApiCode = "Test")] public async Task Test() { return $"当前用户:{UserManager.UserId} {UserManager.Name} ,当前租户:{UserManager.TENANT_ID} {UserManager.TENANT_NAME},管理员类型:{(UserManager.IsSuperAdmin ? "超级管理员" : (UserManager.IsTenantAdmin ? "租户管理员" : "普通用户"))}"; diff --git a/Myshipping.Core/Attributes/ApiUserAttribute.cs b/Myshipping.Core/Attributes/ApiUserAttribute.cs index 8d0bb588..81ae44e9 100644 --- a/Myshipping.Core/Attributes/ApiUserAttribute.cs +++ b/Myshipping.Core/Attributes/ApiUserAttribute.cs @@ -8,5 +8,5 @@ namespace Myshipping.Core; [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Property)] public class ApiUserAttribute : Attribute { - + public string ApiCode { get; set; } } diff --git a/Myshipping.Core/Filter/ApiUserFilter.cs b/Myshipping.Core/Filter/ApiUserFilter.cs index 210c8f6e..d31b50c2 100644 --- a/Myshipping.Core/Filter/ApiUserFilter.cs +++ b/Myshipping.Core/Filter/ApiUserFilter.cs @@ -1,4 +1,6 @@ using Furion; +using Furion.FriendlyException; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.AspNetCore.Mvc.Filters; @@ -12,25 +14,48 @@ using System.Threading.Tasks; namespace Myshipping.Core { + /// + /// API接口调用用户鉴权Filter + /// public class ApiUserFilter : IAsyncActionFilter { public Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { var actionDescriptor = context.ActionDescriptor as ControllerActionDescriptor; - foreach (var metadata in actionDescriptor.EndpointMetadata) + var attrAllowAnonymous = actionDescriptor.EndpointMetadata.FirstOrDefault(x => x.GetType() == typeof(AllowAnonymousAttribute)); + var attrApiUser = actionDescriptor.EndpointMetadata.FirstOrDefault(x => x.GetType() == typeof(ApiUserAttribute)); + if (attrAllowAnonymous != null && attrApiUser != null) { - if (metadata.GetType() == typeof(ApiUserAttribute)) + var apiUser = attrApiUser as ApiUserAttribute; + if (context.HttpContext.Request.Headers.ContainsKey(CommonConst.API_USER_HEADER_KEY) + && context.HttpContext.Request.Headers.ContainsKey(CommonConst.API_USER_HEADER_SECRET)) { - //if (context.HttpContext.Request.Headers.ContainsKey(CommonConst.API_USER_HEADER_KEY) - //&& context.HttpContext.Request.Headers.ContainsKey(CommonConst.API_USER_HEADER_SECRET)) + var key = context.HttpContext.Request.Headers[CommonConst.API_USER_HEADER_KEY].ToString(); + var secret = context.HttpContext.Request.Headers[CommonConst.API_USER_HEADER_SECRET].ToString(); + + var httpContext = App.GetService().HttpContext; + + var repApiAuth = App.GetService>(); + var repTenant = App.GetService>(); + var repUser = App.GetService>(); + + //未设置ApiCode时,使用方法名称 + if (string.IsNullOrEmpty(apiUser.ApiCode)) { - var httpContext = App.GetService().HttpContext; + apiUser.ApiCode = actionDescriptor.MethodInfo.Name; + } - var repTenant = App.GetService>(); - var repUser = App.GetService>(); + var auth = repApiAuth.AsQueryable().Filter(null, true).First(x => + x.ApiCode == apiUser.ApiCode + && x.ApiKey == key + && x.ApiSecret == secret + && x.IsDeleted == false + && x.IsDisable == false); - var tenant = repTenant.AsQueryable().Filter(null, true).First(x => x.Id == 142307070918780L); - var user = repUser.AsQueryable().Filter(null, true).First(x => x.Id == 142307070910551L); + if (auth != null && (!auth.ExpireDate.HasValue || auth.ExpireDate > DateTime.Now)) + { + var tenant = repTenant.AsQueryable().Filter(null, true).First(x => x.Id == auth.TenantId); + var user = repUser.AsQueryable().Filter(null, true).First(x => x.Id == auth.UserId); ClaimsIdentity identity = new ClaimsIdentity("AuthenticationTypes.Federation"); identity.AddClaim(new Claim(type: ClaimConst.CLAINM_USERID, value: user.Id.ToString())); @@ -42,9 +67,10 @@ namespace Myshipping.Core identity.AddClaim(new Claim(type: ClaimConst.TENANT_NAME, value: tenant.Name)); ClaimsPrincipal claimsPrincipal = new ClaimsPrincipal(identity); httpContext.User = claimsPrincipal; + return next(); } - } + throw Oops.Oh("无权调用!请检查授权或联系管理员。"); } return next(); diff --git a/Myshipping.Core/Myshipping.Core.xml b/Myshipping.Core/Myshipping.Core.xml index 539b294e..5080a8f3 100644 --- a/Myshipping.Core/Myshipping.Core.xml +++ b/Myshipping.Core/Myshipping.Core.xml @@ -5365,6 +5365,11 @@ 文件名 返回合法的文件名 + + + API接口调用用户鉴权Filter + + 全局异常处理 @@ -9386,16 +9391,6 @@ 接口名称 - - - 接口KEY - - - - - 接口秘钥 - - 有效截止日期 diff --git a/Myshipping.Core/Service/DjyApiAuth/DjyApiAuthService.cs b/Myshipping.Core/Service/DjyApiAuth/DjyApiAuthService.cs index f2a5c522..3986ecd4 100644 --- a/Myshipping.Core/Service/DjyApiAuth/DjyApiAuthService.cs +++ b/Myshipping.Core/Service/DjyApiAuth/DjyApiAuthService.cs @@ -8,6 +8,8 @@ using System.Linq; using System.Threading.Tasks; using Myshipping.Core.Entity; using Microsoft.Extensions.Logging; +using System; +using Furion.DataEncryption; namespace Myshipping.Core.Service { @@ -53,9 +55,11 @@ namespace Myshipping.Core.Service public async Task Save(SaveDjyApiAuthInput input) { DjyApiAuth entity = null; - if (input.Id > 0) + if (input.Id == 0) { entity = input.Adapt(); + entity.ApiKey = Guid.NewGuid().ToString().Replace("-", "").ToLower(); + entity.ApiSecret = DESCEncryption.Encrypt(Guid.NewGuid().ToString(), "132456").ToLower(); await _rep.InsertAsync(entity); } else diff --git a/Myshipping.Core/Service/DjyApiAuth/Dto/DjyApiAuthInput.cs b/Myshipping.Core/Service/DjyApiAuth/Dto/DjyApiAuthInput.cs index cc0331f7..6924e9f1 100644 --- a/Myshipping.Core/Service/DjyApiAuth/Dto/DjyApiAuthInput.cs +++ b/Myshipping.Core/Service/DjyApiAuth/Dto/DjyApiAuthInput.cs @@ -19,15 +19,15 @@ namespace Myshipping.Core.Service /// public virtual string ApiName { get; set; } - /// - /// 接口KEY - /// - public virtual string ApiKey { get; set; } - - /// - /// 接口秘钥 - /// - public virtual string ApiSecret { get; set; } + ///// + ///// 接口KEY + ///// + //public virtual string ApiKey { get; set; } + + ///// + ///// 接口秘钥 + ///// + //public virtual string ApiSecret { get; set; } /// /// 有效截止日期 diff --git a/Myshipping.Core/Service/DjyVesselInfo/DjyVesselInfoService.cs b/Myshipping.Core/Service/DjyVesselInfo/DjyVesselInfoService.cs index e2feaca3..1983ec90 100644 --- a/Myshipping.Core/Service/DjyVesselInfo/DjyVesselInfoService.cs +++ b/Myshipping.Core/Service/DjyVesselInfo/DjyVesselInfoService.cs @@ -96,7 +96,7 @@ namespace Myshipping.Core.Service //获取船名 List list = await _sysCacheService.GetAllCodeVessel(); - var tlist = await _rep.AsQueryable().Filter(null, true).WhereIF(!string.IsNullOrWhiteSpace(KeyWord), x => x.Vessel.StartsWith(KeyWord)). + var tlist = await _rep.AsQueryable().Filter(null, true).WhereIF(!string.IsNullOrWhiteSpace(KeyWord), x => x.Vessel.StartsWith(KeyWord.ToUpper())). Where(x => x.CARRIERID == CarrierID && x.ETD > DateTime.Now.AddDays(-7) && x.TenantId == UserManager.TENANT_ID). Select(x => new { @@ -109,7 +109,7 @@ namespace Myshipping.Core.Service ToListAsync(); var ves = tlist.Select(x => x.Vessel).ToList(); - var all = list.WhereIF(!string.IsNullOrWhiteSpace(KeyWord), x => x.Name.StartsWith(KeyWord)). + var all = list.WhereIF(!string.IsNullOrWhiteSpace(KeyWord), x => x.Name.StartsWith(KeyWord.ToUpper())). Select(x => new {