소스 검색

物品 详情 --> 增加类型父类Id

LEIYI 6 달 전
부모
커밋
9f6fe88560

+ 0 - 1
OASystem/OASystem.Api/Controllers/AuthController.cs

@@ -112,7 +112,6 @@ namespace OASystem.API.Controllers
 
                 if (expDt >= createZebraTime)  //超时重新获取token
                 {
-                    //authorToken = await GeneralMethod.GetToken(_config, dto.Number, uId,uName, createZebraTime);
                     authorToken = await JwtHelper.IssueJwtAsync(new TokenModelJwt() { UserId = uId, UserName = uName, Role = role }); //
                 }
 

+ 19 - 3
OASystem/OASystem.Api/Controllers/PersonnelModuleController.cs

@@ -1,6 +1,7 @@
 using Aliyun.Credentials.Utils;
 using Aspose.Cells;
 using FluentValidation;
+using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.SignalR;
 using Microsoft.IdentityModel.Tokens;
 using NPOI.POIFS.Crypt.Dsig;
@@ -10,6 +11,7 @@ using OASystem.API.OAMethodLib.Hub.Hubs;
 using OASystem.API.OAMethodLib.QiYeWeChatAPI;
 using OASystem.API.OAMethodLib.QiYeWeChatAPI.AppNotice;
 using OASystem.API.OAMethodLib.Quartz.Business;
+using OASystem.API.OAMethodLib.SignalR.Hubs;
 using OASystem.Domain.Dtos.Groups;
 using OASystem.Domain.Dtos.PersonnelModule;
 using OASystem.Domain.Entities.Groups;
@@ -25,6 +27,7 @@ using System.Data;
 using System.Diagnostics;
 using System.Globalization;
 using System.IO;
+using static OASystem.API.OAMethodLib.JWTHelper;
 
 namespace OASystem.API.Controllers
 {
@@ -54,8 +57,17 @@ namespace OASystem.API.Controllers
         /// <param name="wageSheetRep"></param>
         /// <param name="usersRep"></param>
         /// <param name="mapper"></param>
-        public PersonnelModuleController(IQiYeWeChatApiService qiYeWeChatApiService, WageSheetRepository wageSheetRep, UsersRepository usersRep, IMapper mapper,
-            TaskAllocationRepository taskAllocationRep, IHubContext<ChatHub, IChatClient> hubContext, GoodsRepository goodsRep)
+        /// <param name="taskAllocationRep"></param>
+        /// <param name="hubContext"></param>
+        /// <param name="goodsRep"></param>
+        public PersonnelModuleController(IQiYeWeChatApiService qiYeWeChatApiService,
+                                         WageSheetRepository wageSheetRep,
+                                         UsersRepository usersRep,
+                                         IMapper mapper,
+                                         TaskAllocationRepository taskAllocationRep,
+                                         IHubContext<ChatHub, IChatClient> hubContext,
+                                         GoodsRepository goodsRep
+            )
         {
             _mapper = mapper;
             _usersRep = usersRep;
@@ -73,6 +85,7 @@ namespace OASystem.API.Controllers
             this._taskAllocationRep = taskAllocationRep;
             _hubContext = hubContext;
             _goodsRep = goodsRep;
+
         }
 
         #region 工资表单
@@ -1809,10 +1822,13 @@ namespace OASystem.API.Controllers
         /// 物品 详情
         /// </summary>
         /// <returns></returns>
-        [HttpGet]
+        [HttpGet("id")]
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
         public async Task<IActionResult> GoodsInfo(int portType, int id)
         {
+            //var _currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
+            //if (_currUserInfo == null) return Ok(JsonView(false, "请传入token!"));
+
             if (portType > 1 || portType > 3) return Ok(JsonView(false, MsgTips.Port));
             if (id < 1) return Ok(JsonView(false, MsgTips.Id));
 

+ 6 - 13
OASystem/OASystem.Api/OAMethodLib/JwtHelper.cs

@@ -15,9 +15,8 @@ namespace OASystem.API.OAMethodLib
     {
         public class JwtHelper
         {
+            private readonly static IHttpContextAccessor _httpContext = AutofacIocManager.Instance.GetService<IHttpContextAccessor>();
 
-
-            private readonly static IHttpContextAccessor _httpContextAccessor = AutofacIocManager.Instance.GetService<IHttpContextAccessor>();
             /// <summary>
             /// 颁发JWT字符串
             /// </summary>
@@ -34,17 +33,16 @@ namespace OASystem.API.OAMethodLib
               {
                  /*
                  * 特别重要:
-                   1、这里将用户的部分信息,比如 uid 存到了Claim 中,如果你想知道如何在其他地方将这个 uid从 Token 中取出来,请看下边的SerializeJwt() 方法,或者在整个解决方案,搜索这个方法,看哪里使用了!
+                   1、这里将用户的部分信息,比如 uid 存到了Claim 中,如果你想知道如何在其他地方将这个 uid从 Token 中取出来,请看下边的SerializeJwt() 方法
                    2、你也可以研究下 HttpContext.User.Claims ,具体的你可以看看 Policys/PermissionHandler.cs 类中是如何使用的。
                  */                
 
                 new Claim(JwtRegisteredClaimNames.Jti, tokenModel.UserId.ToString()),
-                //new Claim(JwtRegisteredClaimNames.GivenName, tokenModel.UserName),
-                new Claim("UserName", tokenModel.UserName),
+                new Claim(JwtRegisteredClaimNames.Name, tokenModel.UserName),
                 //new Claim("UserId", tokenModel.UserId.ToString()),
                 new Claim(JwtRegisteredClaimNames.Iat, $"{new DateTimeOffset(DateTime.Now).ToUnixTimeSeconds()}"),
                 new Claim(JwtRegisteredClaimNames.Nbf,$"{new DateTimeOffset(DateTime.Now).ToUnixTimeSeconds()}") ,
-                //这个就是过期时间,目前是过期7200秒,可自定义,注意JWT有自己的缓冲过期时间
+                //过期时间,目前是过期7200秒,可自定义,注意JWT有自己的缓冲过期时间
                 new Claim(JwtRegisteredClaimNames.Exp,$"{new DateTimeOffset(DateTime.Now.AddSeconds(7200)).ToUnixTimeSeconds()}"),
                 new Claim(JwtRegisteredClaimNames.Iss,iss),
                 new Claim(JwtRegisteredClaimNames.Aud,aud),
@@ -67,12 +65,6 @@ namespace OASystem.API.OAMethodLib
                     //,expires:DateTime.Now.AddMinutes(1)
                     );
 
-               // var indentity = new ClaimsIdentity(claims, "FMGJ-OASystem");
-               // var principal = new ClaimsPrincipal(indentity);
-
-               //await _httpContextAccessor.HttpContext?.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal);
-                
-
                 var jwtHandler = new JwtSecurityTokenHandler();
                 var encodedJwt = jwtHandler.WriteToken(jwt);
 
@@ -86,13 +78,14 @@ namespace OASystem.API.OAMethodLib
             /// <returns></returns>
             public static TokenModelJwt SerializeJwt(string jwtStr)
             {
+                if (string.IsNullOrEmpty(jwtStr)) return null;
                 var jwtHandler = new JwtSecurityTokenHandler();
                 JwtSecurityToken jwtToken = jwtHandler.ReadJwtToken(jwtStr);
                 object role,userName;
                 try
                 {
                     jwtToken.Payload.TryGetValue(ClaimTypes.Role, out role);
-                    jwtToken.Payload.TryGetValue("UserName", out userName);
+                    jwtToken.Payload.TryGetValue("name", out userName);
                 }
                 catch (Exception e)
                 {

+ 5 - 4
OASystem/OASystem.Api/Program.cs

@@ -29,8 +29,9 @@ using Microsoft.Extensions.Options;
 using Microsoft.AspNetCore.Identity;
 using static OpenAI.GPT3.ObjectModels.SharedModels.IOpenAiModels;
 using OASystem.API.Middlewares;
+using Microsoft.Extensions.DependencyInjection;
 
-    var builder = WebApplication.CreateBuilder(args);
+var builder = WebApplication.CreateBuilder(args);
 var basePath = AppContext.BaseDirectory;
 
 //引入配置文件
@@ -74,7 +75,7 @@ builder.Services.AddCors(policy =>
 
     policy.AddPolicy("Cors", opt => opt
           .SetIsOriginAllowed(origin => true)//这个必须加
-          //.AllowAnyOrigin()
+                                             //.AllowAnyOrigin()
           .AllowAnyHeader()
           .WithMethods("GET", "POST", "HEAD", "PUT", "DELETE", "OPTIONS")
           .AllowCredentials());//这个一定不能少);
@@ -124,13 +125,13 @@ builder.Services.AddScoped(options =>
         new ConnectionConfig() {
             ConfigId = DBEnum.OA2023DB,
             ConnectionString = _config.GetConnectionString("OA2023DB"),
-            DbType = DbType.SqlServer, 
+            DbType = DbType.SqlServer,
             IsAutoCloseConnection = true },
         new ConnectionConfig()
         {
             ConfigId = DBEnum.OA2014DB,
             ConnectionString = _config.GetConnectionString("OA2014DB"),
-            DbType = DbType.SqlServer, 
+            DbType = DbType.SqlServer,
             IsAutoCloseConnection = true },
     });
 });

+ 1 - 0
OASystem/OASystem.Infrastructure/Repositories/PersonnelModule/GoodsRepository.cs

@@ -132,6 +132,7 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
                                       {
                                           gi.Id,
                                           gi.Name,
+                                          ParentType = sd.STid,
                                           gi.Type,
                                           TypeName = sd.Name,
                                           gi.SQ_Total,