fix 设备数据和人员数据修改

This commit is contained in:
cheche
2024-02-21 11:44:55 +08:00
parent 6e492595f8
commit 7f7afb251c
3 changed files with 63 additions and 20 deletions

View File

@@ -165,7 +165,10 @@ public class GainfosController : ControllerBase
[HttpGet("weeknumber")]
public async Task<Dictionary<string, Pagination<GainfoDetailResponse>>> 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);
}
/// <summary>
@@ -175,7 +178,10 @@ public class GainfosController : ControllerBase
[HttpGet("weeknumberdimission")]
public async Task<Dictionary<string, Pagination<GainfoDetailResponse>>> 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);
}
/// <summary>
@@ -183,9 +189,12 @@ public class GainfosController : ControllerBase
/// </summary>
/// <returns></returns>
[HttpGet("gainfonumbers")]
public async Task<GainfoGainfoNumbersResponse> GetGainfoNumbersAsync(string Werks)
public async Task<GainfoGainfoNumbersResponse> GetGainfoNumbersAsync()
{
return await _gainfoService.GetGainfoNumbersAsync(Werks);
// 从请求头中获取 Token
string token = HttpContext.Request.Headers["Authorization"].ToString().Replace("Bearer ", "");
return await _gainfoService.GetGainfoNumbersAsync(token);
}
}

View File

@@ -32,9 +32,9 @@ public interface IGainfoService : IScopeDependency
Task<GainfoDetailResponse> GetGainfoDetailTaskAsync(GainfoDetailRequest request);
Task<Dictionary<string, Pagination<GainfoDetailResponse>>> GetWeekNumberAsync(WeekNumberRequest request);
Task<Dictionary<string, Pagination<GainfoDetailResponse>>> GetWeekNumberAsync(WeekNumberRequest request, string token);
Task<Dictionary<string, Pagination<GainfoDetailResponse>>> GetDimissionWeekNumberAsync([FromQuery] WeekNumberRequest request);
Task<Dictionary<string, Pagination<GainfoDetailResponse>>> GetDimissionWeekNumberAsync([FromQuery] WeekNumberRequest request, string token);
Task<GainfoGainfoNumbersResponse> GetGainfoNumbersAsync(string Werks);
Task<GainfoGainfoNumbersResponse> GetGainfoNumbersAsync(string token);
}

View File

@@ -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
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public async Task<Pagination<GainfoListResponse>> GetGainfoListTaskAsync( GainfoListRequest request)
public async Task<Pagination<GainfoListResponse>> GetGainfoListTaskAsync(GainfoListRequest request)
{
var page = await _gainfoStore.Queryable(request.Status)
.LeftJoin<DepartmentEntity>((ga, de) => ga.DepartmentNo == de.No)
@@ -345,12 +346,12 @@ public class GainfoService : IGainfoService
{
var info = await _gainfoStore.Queryable(request.Status)
.LeftJoin<DepartmentEntity>((ga, de) => ga.DepartmentNo == de.No)
.LeftJoin<BasicTypeEntity>((ga,de,type) => ga.Native == type.Code && type.Type == "native")
.LeftJoin<PositionEntity>((ga, de, type,posi) => ga.Position == posi.Name)
.LeftJoin<BasicTypeEntity>((ga, de, type, posi,type2) => ga.CountryNo == type2.Code && type2.Type == "country")
.LeftJoin<BasicTypeEntity>((ga, de, type, posi, type2,type3) => ga.Nation == type3.Code && type3.Type == "nation")
.LeftJoin<BasicTypeEntity>((ga, de, type) => ga.Native == type.Code && type.Type == "native")
.LeftJoin<PositionEntity>((ga, de, type, posi) => ga.Position == posi.Name)
.LeftJoin<BasicTypeEntity>((ga, de, type, posi, type2) => ga.CountryNo == type2.Code && type2.Type == "country")
.LeftJoin<BasicTypeEntity>((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<Dictionary<string, Pagination<GainfoDetailResponse>>> GetWeekNumberAsync(WeekNumberRequest request)
public async Task<Dictionary<string, Pagination<GainfoDetailResponse>>> GetWeekNumberAsync(WeekNumberRequest request, string token)
{
var werks = GetClaimValueFromToken(token, "tenant");
//获取近7天并转化为"yyyy-MM-dd"集合
DateTime currentDate = DateTime.Now;
List<string> times = new List<string>();
@@ -399,7 +402,7 @@ public class GainfoService : IGainfoService
.LeftJoin<PositionEntity>((ga, de, type, posi) => ga.Position == posi.Name)
.LeftJoin<BasicTypeEntity>((ga, de, type, posi, type2) => ga.CountryNo == type2.Code && type2.Type == "country")
.LeftJoin<BasicTypeEntity>((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<Dictionary<string, Pagination<GainfoDetailResponse>>> GetDimissionWeekNumberAsync([FromQuery] WeekNumberRequest request)
public async Task<Dictionary<string, Pagination<GainfoDetailResponse>>> GetDimissionWeekNumberAsync(WeekNumberRequest request, string token)
{
var werks = GetClaimValueFromToken(token, "tenant");
//获取近7天并转化为"yyyy-MM-dd"集合
DateTime currentDate = DateTime.Now;
List<string> times = new List<string>();
@@ -453,7 +458,7 @@ public class GainfoService : IGainfoService
.LeftJoin<PositionEntity>((ga, de, type, posi) => ga.Position == posi.Name)
.LeftJoin<BasicTypeEntity>((ga, de, type, posi, type2) => ga.CountryNo == type2.Code && type2.Type == "country")
.LeftJoin<BasicTypeEntity>((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<GainfoGainfoNumbersResponse> GetGainfoNumbersAsync(string Werks)
public async Task<GainfoGainfoNumbersResponse> 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
}
}
}
/// <summary>
/// 解析token
/// </summary>
/// <param name="token"></param>
/// <param name="claimType"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
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;
}
}
}