diff --git a/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs b/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs index fc98f815..2f1ee735 100644 --- a/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs +++ b/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs @@ -165,7 +165,10 @@ public class GainfosController : ControllerBase [HttpGet("weeknumber")] public async Task>> GetWeekNumberAsync([FromQuery] WeekNumberRequest request) { - return await _gainfoService.GetWeekNumberAsync(request); + // 从请求头中获取 Token + string token = HttpContext.Request.Headers["Authorization"].ToString().Replace("Bearer ", ""); + + return await _gainfoService.GetWeekNumberAsync(request,token); } /// @@ -175,7 +178,10 @@ public class GainfosController : ControllerBase [HttpGet("weeknumberdimission")] public async Task>> GetDimissionWeekNumberAsync([FromQuery] WeekNumberRequest request) { - return await _gainfoService.GetDimissionWeekNumberAsync(request); + // 从请求头中获取 Token + string token = HttpContext.Request.Headers["Authorization"].ToString().Replace("Bearer ", ""); + + return await _gainfoService.GetDimissionWeekNumberAsync(request,token); } /// @@ -183,9 +189,12 @@ public class GainfosController : ControllerBase /// /// [HttpGet("gainfonumbers")] - public async Task GetGainfoNumbersAsync(string Werks) + public async Task GetGainfoNumbersAsync() { - return await _gainfoService.GetGainfoNumbersAsync(Werks); + // 从请求头中获取 Token + string token = HttpContext.Request.Headers["Authorization"].ToString().Replace("Bearer ", ""); + + return await _gainfoService.GetGainfoNumbersAsync(token); } } diff --git a/Src/Dlhis.Basic/Organization/Services/IGainfoService.cs b/Src/Dlhis.Basic/Organization/Services/IGainfoService.cs index 59e285f9..56456bed 100644 --- a/Src/Dlhis.Basic/Organization/Services/IGainfoService.cs +++ b/Src/Dlhis.Basic/Organization/Services/IGainfoService.cs @@ -32,9 +32,9 @@ public interface IGainfoService : IScopeDependency Task GetGainfoDetailTaskAsync(GainfoDetailRequest request); - Task>> GetWeekNumberAsync(WeekNumberRequest request); + Task>> GetWeekNumberAsync(WeekNumberRequest request, string token); - Task>> GetDimissionWeekNumberAsync([FromQuery] WeekNumberRequest request); + Task>> GetDimissionWeekNumberAsync([FromQuery] WeekNumberRequest request, string token); - Task GetGainfoNumbersAsync(string Werks); + Task GetGainfoNumbersAsync(string token); } diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs index 233bdd70..2acfff75 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs @@ -16,6 +16,7 @@ using Kurisu.SqlSugar.Services; using Mapster; using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Mvc; +using System.IdentityModel.Tokens.Jwt; namespace Dlhis.Basic.Organization.Services.Implements; @@ -313,7 +314,7 @@ public class GainfoService : IGainfoService /// /// /// - public async Task> GetGainfoListTaskAsync( GainfoListRequest request) + public async Task> GetGainfoListTaskAsync(GainfoListRequest request) { var page = await _gainfoStore.Queryable(request.Status) .LeftJoin((ga, de) => ga.DepartmentNo == de.No) @@ -345,12 +346,12 @@ public class GainfoService : IGainfoService { var info = await _gainfoStore.Queryable(request.Status) .LeftJoin((ga, de) => ga.DepartmentNo == de.No) - .LeftJoin((ga,de,type) => ga.Native == type.Code && type.Type == "native") - .LeftJoin((ga, de, type,posi) => ga.Position == posi.Name) - .LeftJoin((ga, de, type, posi,type2) => ga.CountryNo == type2.Code && type2.Type == "country") - .LeftJoin((ga, de, type, posi, type2,type3) => ga.Nation == type3.Code && type3.Type == "nation") + .LeftJoin((ga, de, type) => ga.Native == type.Code && type.Type == "native") + .LeftJoin((ga, de, type, posi) => ga.Position == posi.Name) + .LeftJoin((ga, de, type, posi, type2) => ga.CountryNo == type2.Code && type2.Type == "country") + .LeftJoin((ga, de, type, posi, type2, type3) => ga.Nation == type3.Code && type3.Type == "nation") .Where(ga => ga.No == request.No) - .Select((ga, de,type,posi,type2, type3) => new GainfoDetailResponse + .Select((ga, de, type, posi, type2, type3) => new GainfoDetailResponse { No = ga.No, SapNo = ga.SapNo, @@ -377,8 +378,10 @@ public class GainfoService : IGainfoService return info; } - public async Task>> GetWeekNumberAsync(WeekNumberRequest request) + public async Task>> GetWeekNumberAsync(WeekNumberRequest request, string token) { + var werks = GetClaimValueFromToken(token, "tenant"); + //获取近7天并转化为"yyyy-MM-dd"集合 DateTime currentDate = DateTime.Now; List times = new List(); @@ -399,7 +402,7 @@ public class GainfoService : IGainfoService .LeftJoin((ga, de, type, posi) => ga.Position == posi.Name) .LeftJoin((ga, de, type, posi, type2) => ga.CountryNo == type2.Code && type2.Type == "country") .LeftJoin((ga, de, type, posi, type2, type3) => ga.Nation == type3.Code && type3.Type == "nation") - .Where(ga => ga.CreateTime.ToString("yyyy-MM-dd") == time) + .Where(ga => ga.CreateTime.ToString("yyyy-MM-dd") == time && ga.Werks == werks) .Select((ga, de, type, posi, type2, type3) => new GainfoDetailResponse { No = ga.No, @@ -432,8 +435,10 @@ public class GainfoService : IGainfoService return dic; } - public async Task>> GetDimissionWeekNumberAsync([FromQuery] WeekNumberRequest request) + public async Task>> GetDimissionWeekNumberAsync(WeekNumberRequest request, string token) { + var werks = GetClaimValueFromToken(token, "tenant"); + //获取近7天并转化为"yyyy-MM-dd"集合 DateTime currentDate = DateTime.Now; List times = new List(); @@ -453,7 +458,7 @@ public class GainfoService : IGainfoService .LeftJoin((ga, de, type, posi) => ga.Position == posi.Name) .LeftJoin((ga, de, type, posi, type2) => ga.CountryNo == type2.Code && type2.Type == "country") .LeftJoin((ga, de, type, posi, type2, type3) => ga.Nation == type3.Code && type3.Type == "nation") - .Where(ga => ga.CreateTime.ToString("yyyy-MM-dd") == time) + .Where(ga => ga.CreateTime.ToString("yyyy-MM-dd") == time && ga.Werks == werks) .Select((ga, de, type, posi, type2, type3) => new GainfoDetailResponse { No = ga.No, @@ -483,16 +488,18 @@ public class GainfoService : IGainfoService return dic; } - public async Task GetGainfoNumbersAsync(string Werks) + public async Task GetGainfoNumbersAsync(string token) { + var werks = GetClaimValueFromToken(token, "tenant"); + //在职人数 var onlineNumber = await _gainfoStore.Queryable(GainfoStatusEnumType.Working) - .Where(ga => ga.Werks == Werks) + .Where(ga => ga.Werks == werks) .CountAsync(); //离职人数 var offlineNumber = await _gainfoStore.Queryable(GainfoStatusEnumType.Leave) - .Where(ga => ga.Werks == Werks) + .Where(ga => ga.Werks == werks) .CountAsync(); //考勤总人数 @@ -545,4 +552,31 @@ public class GainfoService : IGainfoService } } } + + /// + /// 解析token + /// + /// + /// + /// + /// + private string GetClaimValueFromToken(string token, string claimType) + { + try + { + var handler = new JwtSecurityTokenHandler(); + var jsonToken = handler.ReadToken(token) as JwtSecurityToken; + + if (jsonToken == null) + throw new Exception("Invalid JWT Token"); + + var claimValue = jsonToken.Claims.FirstOrDefault(c => c.Type == claimType)?.Value; + + return claimValue; + } + catch (Exception ex) + { + return null; + } + } }