# Conflicts:
#	Myshipping.Application/Myshipping.Application.xml
optimize
wet 2 years ago
commit 4e4092b78e

@ -14,7 +14,7 @@ namespace Myshipping.Application.Entity
/// <summary> /// <summary>
/// 父键 /// 父键
/// </summary> /// </summary>
public long Pid { get; set; } public long PId { get; set; }
/// <summary> /// <summary>
/// 字段名称 /// 字段名称
/// </summary> /// </summary>

@ -2395,7 +2395,7 @@
订舱状态 订舱状态
</summary> </summary>
</member> </member>
<member name="P:Myshipping.Application.Entity.BookingExcelTemplate.Pid"> <member name="P:Myshipping.Application.Entity.BookingExcelTemplate.PId">
<summary> <summary>
父键 父键
</summary> </summary>
@ -9975,6 +9975,19 @@
<param name="model"></param> <param name="model"></param>
<returns></returns> <returns></returns>
</member> </member>
<member name="M:Myshipping.Application.DataSyncService.SyncVesselDate(Myshipping.Application.Entity.DjyVesselInfoDto)">
<summary>
同步船期
</summary>
<param name="model"></param>
<returns></returns>
</member>
<member name="M:Myshipping.Application.DataSyncService.Test">
<summary>
测试用
</summary>
<returns></returns>
</member>
<member name="T:Myshipping.Application.DjyCustomerSyncDto"> <member name="T:Myshipping.Application.DjyCustomerSyncDto">
<summary> <summary>
订舱客户同步 订舱客户同步

@ -1735,7 +1735,7 @@ namespace Myshipping.Application
var excelwork = new HSSFWorkbook(result); var excelwork = new HSSFWorkbook(result);
var sheet = excelwork.GetSheetAt(0); var sheet = excelwork.GetSheetAt(0);
var order = await _rep.AsQueryable().Where(x => x.Id == bookingId).FirstAsync(); 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); var cellStyle = NpoiExcelExportHelper._.CreateStyle(excelwork, HorizontalAlignment.Center, VerticalAlignment.Center, 10, true, 0);
for (int _row = 0; _row < entity.Max(x => x.Row); _row++) for (int _row = 0; _row < entity.Max(x => x.Row); _row++)

@ -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) foreach (var item in dto.children)
{ {
var entity = item.Adapt<BookingExcelTemplate>(); var entity = item.Adapt<BookingExcelTemplate>();
entity.PId = dto.Pid;
await _excelrep.InsertAsync(entity); await _excelrep.InsertAsync(entity);
} }
} }
@ -464,7 +464,7 @@ namespace Myshipping.Application
[HttpGet("/BookingTemplate/BookingExcelTemplateList")] [HttpGet("/BookingTemplate/BookingExcelTemplateList")]
public async Task<dynamic> BookingExcelTemplateList(long Id) public async Task<dynamic> BookingExcelTemplateList(long Id)
{ {
return await _excelrep.AsQueryable().Where(x => x.Pid == Id).ToListAsync(); return await _excelrep.AsQueryable().Where(x => x.PId == Id).ToListAsync();
} }
} }

@ -72,7 +72,7 @@ namespace Myshipping.Application
/// </summary> /// </summary>
/// <param name="model"></param> /// <param name="model"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost("/DataSync/SyncCustomer"),ApiUser(ApiCode="")] [HttpPost("/DataSync/SyncCustomer"),ApiUser(ApiCode= "SyncCustomer")]
public async Task<long> SyncCustomer(DjyCustomerSyncDto model) public async Task<long> SyncCustomer(DjyCustomerSyncDto model)
{ {
@ -111,8 +111,8 @@ namespace Myshipping.Application
/// </summary> /// </summary>
/// <param name="model"></param> /// <param name="model"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost("/DataSync/SyncVesselInfo"), ApiUser] [HttpPost("/DataSync/SyncVesselDate"), ApiUser(ApiCode = "SyncVesselDate")]
public async Task<long> SyncVesselInfo(DjyVesselInfoDto model) public async Task<long> SyncVesselDate(DjyVesselInfoDto model)
{ {
if (string.IsNullOrWhiteSpace(model.Vessel)|| string.IsNullOrWhiteSpace(model.CARRIERID)) if (string.IsNullOrWhiteSpace(model.Vessel)|| string.IsNullOrWhiteSpace(model.CARRIERID))
@ -142,7 +142,11 @@ namespace Myshipping.Application
#endregion #endregion
#region 其他 #region 其他
[HttpGet("/DataSync/Test"), ApiUser] /// <summary>
/// 测试用
/// </summary>
/// <returns></returns>
[HttpGet("/DataSync/Test"), ApiUser(ApiCode = "Test")]
public async Task<string> Test() public async Task<string> Test()
{ {
return $"当前用户:{UserManager.UserId} {UserManager.Name} ,当前租户:{UserManager.TENANT_ID} {UserManager.TENANT_NAME},管理员类型:{(UserManager.IsSuperAdmin ? "" : (UserManager.IsTenantAdmin ? "" : ""))}"; return $"当前用户:{UserManager.UserId} {UserManager.Name} ,当前租户:{UserManager.TENANT_ID} {UserManager.TENANT_NAME},管理员类型:{(UserManager.IsSuperAdmin ? "" : (UserManager.IsTenantAdmin ? "" : ""))}";

@ -8,5 +8,5 @@ namespace Myshipping.Core;
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Property)] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Property)]
public class ApiUserAttribute : Attribute public class ApiUserAttribute : Attribute
{ {
public string ApiCode { get; set; }
} }

@ -1,4 +1,6 @@
using Furion; using Furion;
using Furion.FriendlyException;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.Filters;
@ -12,25 +14,48 @@ using System.Threading.Tasks;
namespace Myshipping.Core namespace Myshipping.Core
{ {
/// <summary>
/// API接口调用用户鉴权Filter
/// </summary>
public class ApiUserFilter : IAsyncActionFilter public class ApiUserFilter : IAsyncActionFilter
{ {
public Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) public Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{ {
var actionDescriptor = context.ActionDescriptor as ControllerActionDescriptor; 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)
//if (context.HttpContext.Request.Headers.ContainsKey(CommonConst.API_USER_HEADER_KEY) && context.HttpContext.Request.Headers.ContainsKey(CommonConst.API_USER_HEADER_SECRET))
//&& 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<IHttpContextAccessor>().HttpContext; var httpContext = App.GetService<IHttpContextAccessor>().HttpContext;
var repApiAuth = App.GetService<SqlSugarRepository<DjyApiAuth>>();
var repTenant = App.GetService<SqlSugarRepository<SysTenant>>(); var repTenant = App.GetService<SqlSugarRepository<SysTenant>>();
var repUser = App.GetService<SqlSugarRepository<SysUser>>(); var repUser = App.GetService<SqlSugarRepository<SysUser>>();
var tenant = repTenant.AsQueryable().Filter(null, true).First(x => x.Id == 142307070918780L); //未设置ApiCode时使用方法名称
var user = repUser.AsQueryable().Filter(null, true).First(x => x.Id == 142307070910551L); if (string.IsNullOrEmpty(apiUser.ApiCode))
{
apiUser.ApiCode = actionDescriptor.MethodInfo.Name;
}
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);
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"); ClaimsIdentity identity = new ClaimsIdentity("AuthenticationTypes.Federation");
identity.AddClaim(new Claim(type: ClaimConst.CLAINM_USERID, value: user.Id.ToString())); 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)); identity.AddClaim(new Claim(type: ClaimConst.TENANT_NAME, value: tenant.Name));
ClaimsPrincipal claimsPrincipal = new ClaimsPrincipal(identity); ClaimsPrincipal claimsPrincipal = new ClaimsPrincipal(identity);
httpContext.User = claimsPrincipal; httpContext.User = claimsPrincipal;
return next();
} }
} }
throw Oops.Oh("无权调用!请检查授权或联系管理员。");
} }
return next(); return next();

@ -5365,6 +5365,11 @@
<param name="fn">文件名</param> <param name="fn">文件名</param>
<returns>返回合法的文件名</returns> <returns>返回合法的文件名</returns>
</member> </member>
<member name="T:Myshipping.Core.ApiUserFilter">
<summary>
API接口调用用户鉴权Filter
</summary>
</member>
<member name="T:Myshipping.Core.LogExceptionHandler"> <member name="T:Myshipping.Core.LogExceptionHandler">
<summary> <summary>
全局异常处理 全局异常处理
@ -9386,16 +9391,6 @@
接口名称 接口名称
</summary> </summary>
</member> </member>
<member name="P:Myshipping.Core.Service.DjyApiAuthInput.ApiKey">
<summary>
接口KEY
</summary>
</member>
<member name="P:Myshipping.Core.Service.DjyApiAuthInput.ApiSecret">
<summary>
接口秘钥
</summary>
</member>
<member name="P:Myshipping.Core.Service.DjyApiAuthInput.ExpireDate"> <member name="P:Myshipping.Core.Service.DjyApiAuthInput.ExpireDate">
<summary> <summary>
有效截止日期 有效截止日期

@ -8,6 +8,8 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Myshipping.Core.Entity; using Myshipping.Core.Entity;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System;
using Furion.DataEncryption;
namespace Myshipping.Core.Service namespace Myshipping.Core.Service
{ {
@ -53,9 +55,11 @@ namespace Myshipping.Core.Service
public async Task<long> Save(SaveDjyApiAuthInput input) public async Task<long> Save(SaveDjyApiAuthInput input)
{ {
DjyApiAuth entity = null; DjyApiAuth entity = null;
if (input.Id > 0) if (input.Id == 0)
{ {
entity = input.Adapt<DjyApiAuth>(); entity = input.Adapt<DjyApiAuth>();
entity.ApiKey = Guid.NewGuid().ToString().Replace("-", "").ToLower();
entity.ApiSecret = DESCEncryption.Encrypt(Guid.NewGuid().ToString(), "132456").ToLower();
await _rep.InsertAsync(entity); await _rep.InsertAsync(entity);
} }
else else

@ -19,15 +19,15 @@ namespace Myshipping.Core.Service
/// </summary> /// </summary>
public virtual string ApiName { get; set; } public virtual string ApiName { get; set; }
/// <summary> ///// <summary>
/// 接口KEY ///// 接口KEY
/// </summary> ///// </summary>
public virtual string ApiKey { get; set; } //public virtual string ApiKey { get; set; }
/// <summary> ///// <summary>
/// 接口秘钥 ///// 接口秘钥
/// </summary> ///// </summary>
public virtual string ApiSecret { get; set; } //public virtual string ApiSecret { get; set; }
/// <summary> /// <summary>
/// 有效截止日期 /// 有效截止日期

@ -96,7 +96,7 @@ namespace Myshipping.Core.Service
//获取船名 //获取船名
List<CodeVessel> list = await _sysCacheService.GetAllCodeVessel(); List<CodeVessel> 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). Where(x => x.CARRIERID == CarrierID && x.ETD > DateTime.Now.AddDays(-7) && x.TenantId == UserManager.TENANT_ID).
Select(x => new Select(x => new
{ {
@ -109,7 +109,7 @@ namespace Myshipping.Core.Service
ToListAsync(); ToListAsync();
var ves = tlist.Select(x => x.Vessel).ToList(); 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 Select(x => new
{ {

Loading…
Cancel
Save