From 6e492595f8187fcfb6c0da7beb8aebe4ee4f82eb Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Wed, 21 Feb 2024 11:09:38 +0800 Subject: [PATCH 1/6] =?UTF-8?q?feat=20=E4=BA=8C=E7=BA=A7=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E6=9B=B4=E6=94=B9=E5=8F=8A=E8=AE=BE=E5=A4=87=E4=BA=BA=E5=91=98?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Device/Controllers/DevicesController.cs | 30 ++++ .../Device/Request/AttendanceTotalRequest.cs | 8 ++ .../Request/DeviceOnlineAndofflineRequest.cs | 9 ++ .../Device/Services/IDeviceService.cs | 7 + .../Services/Implements/DeviceService.cs | 58 ++++++++ .../Controllers/GainfosController.cs | 31 +++++ .../Organization/Request/WeekNumberRequest.cs | 8 ++ .../Response/GainfoGainfoNumbersResponse.cs | 9 ++ .../Organization/Services/IGainfoService.cs | 7 + .../Services/Implements/GainfoService.cs | 130 ++++++++++++++++++ Src/Dlhis.Sys/Menu/Services/IMenuService.cs | 2 +- .../Menu/Services/Implements/MenuService.cs | 20 ++- 12 files changed, 314 insertions(+), 5 deletions(-) create mode 100644 Src/Dlhis.Basic/Device/Request/AttendanceTotalRequest.cs create mode 100644 Src/Dlhis.Basic/Device/Request/DeviceOnlineAndofflineRequest.cs create mode 100644 Src/Dlhis.Basic/Organization/Request/WeekNumberRequest.cs create mode 100644 Src/Dlhis.Basic/Organization/Response/GainfoGainfoNumbersResponse.cs diff --git a/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs b/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs index dc903205..6dfcd3f3 100644 --- a/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs +++ b/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs @@ -162,4 +162,34 @@ public class DevicesController : ControllerBase { return await _deviceService.GetAttendanceDevicesAsync(); } + + /// + /// 获取考勤设备总数 + /// + /// + [HttpGet("attendancestotal")] + public async Task> GetAttendanceTotalAsync([FromQuery]AttendanceTotalRequest request) + { + return await _deviceService.GetAttendanceTotalAsync(request); + } + + /// + /// 获取考勤在线/离线设备数 + /// + /// + [HttpGet("attendancesoffline")] + public async Task> GetAttendanceOfflineAsync([FromQuery] DeviceOnlineAndofflineRequest request) + { + return await _deviceService.GetAttendanceOfflineAsync(request); + } + + /// + /// 获取近期30天新增设备数 + /// + /// + [HttpGet("recentnumbers")] + public async Task> GetRecentNumbersAsync() + { + return await _deviceService.GetRecentNumbersAsync(); + } } diff --git a/Src/Dlhis.Basic/Device/Request/AttendanceTotalRequest.cs b/Src/Dlhis.Basic/Device/Request/AttendanceTotalRequest.cs new file mode 100644 index 00000000..df7fa9fa --- /dev/null +++ b/Src/Dlhis.Basic/Device/Request/AttendanceTotalRequest.cs @@ -0,0 +1,8 @@ +using Kurisu.Core.DataAccess.Dto; + +namespace Dlhis.Basic.Device.Request +{ + public class AttendanceTotalRequest : PageDto + { + } +} diff --git a/Src/Dlhis.Basic/Device/Request/DeviceOnlineAndofflineRequest.cs b/Src/Dlhis.Basic/Device/Request/DeviceOnlineAndofflineRequest.cs new file mode 100644 index 00000000..14b9b1b5 --- /dev/null +++ b/Src/Dlhis.Basic/Device/Request/DeviceOnlineAndofflineRequest.cs @@ -0,0 +1,9 @@ +using Kurisu.Core.DataAccess.Dto; + +namespace Dlhis.Basic.Device.Request +{ + public class DeviceOnlineAndofflineRequest :PageDto + { + public bool IsOnAndOff { get; set; } + } +} diff --git a/Src/Dlhis.Basic/Device/Services/IDeviceService.cs b/Src/Dlhis.Basic/Device/Services/IDeviceService.cs index 095effcb..9d346d3e 100644 --- a/Src/Dlhis.Basic/Device/Services/IDeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/IDeviceService.cs @@ -1,6 +1,7 @@ using Dlhis.Basic.Device.Request; using Dlhis.Basic.Device.Response; using Kurisu.Core.DataAccess.Dto; +using Microsoft.AspNetCore.Mvc; namespace Dlhis.Basic.Device.Services; @@ -15,4 +16,10 @@ public interface IDeviceService : IScopeDependency Task GetDeviceByNoAsync(DeviceByNoRequest request); Task> GetAttendanceDevicesAsync(); + + Task> GetAttendanceTotalAsync(AttendanceTotalRequest request); + + Task> GetAttendanceOfflineAsync(DeviceOnlineAndofflineRequest request); + + Task> GetRecentNumbersAsync(); } diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs index d398e296..9d61dd71 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs @@ -10,6 +10,7 @@ using Kurisu.SqlSugar.Attributes; using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Services; using Mapster; +using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -194,5 +195,62 @@ public class DeviceService : IDeviceService return devices.Where(x => x.Funcs.Contains(DeviceFuncEnumType.Attendance)).ToList(); } + + public async Task> GetAttendanceTotalAsync(AttendanceTotalRequest request) + { + var page = await _dbContext.Queryable() + .LeftJoin((d, dt) => d.TemplateCode == dt.Code) + .Where(d => d.Type == DeviceTypeEnumType.Attendance) + .Select((d, dt) => new DevicePageResponse + { + FuncsStr = d.Funcs.ToString(), + Brand = dt.Brand, + Type = d.Type, + + }, true) + .ToPageListAsync(request); + + return page; + } + + public async Task> GetAttendanceOfflineAsync(DeviceOnlineAndofflineRequest request) + { + var page = await _dbContext.Queryable() + .LeftJoin((d, dt) => d.TemplateCode == dt.Code) + .Where(d => d.Type == DeviceTypeEnumType.Attendance && d.Enable == request.IsOnAndOff) + .Select((d, dt) => new DevicePageResponse + { + FuncsStr = d.Funcs.ToString(), + Brand = dt.Brand, + Type = d.Type, + + }, true) + .ToPageListAsync(request); + + return page; + } + + public async Task> GetRecentNumbersAsync() + { + //获取近30天并转化为"yyyy-MM-dd"集合 + DateTime currentDate = DateTime.Now; + List times = new List(); + for (int i = 0; i < 30; i++) + { + DateTime date = currentDate.AddDays(-i); + string dateString = date.ToString("yyyy-MM-dd"); + times.Add(dateString); + } + + var devices = await _dbContext.Queryable().ToListAsync(); + + var dic = new Dictionary(); + times.ForEach(time => + { + var count = devices.Where(x => x.CreateTime.ToString("yyyy-MM-dd") == time).Count(); + dic[time] = count; + }); + return dic; + } } diff --git a/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs b/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs index 667ab402..fc98f815 100644 --- a/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs +++ b/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs @@ -2,6 +2,7 @@ using Dlhis.Basic.Organization.Request; using Dlhis.Basic.Organization.Response; using Dlhis.Basic.Organization.Services; +using Dlhis.Entity.Basic.Entity; using Kurisu.AspNetCore.MVC; using Kurisu.Core.DataAccess.Dto; using Microsoft.AspNetCore.Authorization; @@ -156,5 +157,35 @@ public class GainfosController : ControllerBase { return await _gainfoService.GetGainfoDetailTaskAsync(request); } + + /// + /// 获取近七天入职人数及列表 + /// + /// + [HttpGet("weeknumber")] + public async Task>> GetWeekNumberAsync([FromQuery] WeekNumberRequest request) + { + return await _gainfoService.GetWeekNumberAsync(request); + } + + /// + /// 获取近七天离职人数及列表 + /// + /// + [HttpGet("weeknumberdimission")] + public async Task>> GetDimissionWeekNumberAsync([FromQuery] WeekNumberRequest request) + { + return await _gainfoService.GetDimissionWeekNumberAsync(request); + } + + /// + /// 获取基地在职、离职、考勤数 + /// + /// + [HttpGet("gainfonumbers")] + public async Task GetGainfoNumbersAsync(string Werks) + { + return await _gainfoService.GetGainfoNumbersAsync(Werks); + } } diff --git a/Src/Dlhis.Basic/Organization/Request/WeekNumberRequest.cs b/Src/Dlhis.Basic/Organization/Request/WeekNumberRequest.cs new file mode 100644 index 00000000..6bd60bc9 --- /dev/null +++ b/Src/Dlhis.Basic/Organization/Request/WeekNumberRequest.cs @@ -0,0 +1,8 @@ +using Kurisu.Core.DataAccess.Dto; + +namespace Dlhis.Basic.Organization.Request +{ + public class WeekNumberRequest : PageDto + { + } +} diff --git a/Src/Dlhis.Basic/Organization/Response/GainfoGainfoNumbersResponse.cs b/Src/Dlhis.Basic/Organization/Response/GainfoGainfoNumbersResponse.cs new file mode 100644 index 00000000..182a22cb --- /dev/null +++ b/Src/Dlhis.Basic/Organization/Response/GainfoGainfoNumbersResponse.cs @@ -0,0 +1,9 @@ +namespace Dlhis.Basic.Organization.Response +{ + public class GainfoGainfoNumbersResponse + { + public int OnlineNumber { get; set; } + public int OfflineNumber { get; set; } + public int AttendanceNumber{ get; set; } + } +} diff --git a/Src/Dlhis.Basic/Organization/Services/IGainfoService.cs b/Src/Dlhis.Basic/Organization/Services/IGainfoService.cs index 51949307..59e285f9 100644 --- a/Src/Dlhis.Basic/Organization/Services/IGainfoService.cs +++ b/Src/Dlhis.Basic/Organization/Services/IGainfoService.cs @@ -1,5 +1,6 @@ using Dlhis.Basic.Organization.Request; using Dlhis.Basic.Organization.Response; +using Dlhis.Entity.Basic.Entity; using Kurisu.Core.DataAccess.Dto; using Microsoft.AspNetCore.Mvc; @@ -30,4 +31,10 @@ public interface IGainfoService : IScopeDependency Task> GetGainfoListTaskAsync(GainfoListRequest request); Task GetGainfoDetailTaskAsync(GainfoDetailRequest request); + + Task>> GetWeekNumberAsync(WeekNumberRequest request); + + Task>> GetDimissionWeekNumberAsync([FromQuery] WeekNumberRequest request); + + Task GetGainfoNumbersAsync(string Werks); } diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs index 7a5506f2..233bdd70 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs @@ -377,6 +377,136 @@ public class GainfoService : IGainfoService return info; } + public async Task>> GetWeekNumberAsync(WeekNumberRequest request) + { + //获取近7天并转化为"yyyy-MM-dd"集合 + DateTime currentDate = DateTime.Now; + List times = new List(); + for (int i = 0; i < 7; i++) + { + DateTime date = currentDate.AddDays(-i); + string dateString = date.ToString("yyyy-MM-dd"); + times.Add(dateString); + } + + var dic = new Dictionary>(); + + foreach (var time in times) + { + var infos = await _gainfoStore.Queryable(GainfoStatusEnumType.Working) + .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") + .Where(ga => ga.CreateTime.ToString("yyyy-MM-dd") == time) + .Select((ga, de, type, posi, type2, type3) => new GainfoDetailResponse + { + No = ga.No, + SapNo = ga.SapNo, + Name = ga.Name, + Code = ga.Code, + DepartmentName = de.Name, + IdClass = ga.IdClass, + IdNo = ga.IdNo, + Gender = ga.Gender, + NativeName = type.Display, + Address = ga.Address, + Birthday = ga.Birthday, + Phone = ga.Phone, + Position = ga.Position, + Grade = posi.Grade, + Degree = ga.Degree, + Werks = ga.Werks, + CostId = ga.CostId, + Marital = ga.Marital, + CountryName = type2.Display, + NationName = type3.Display, + IsActive = ga.Employed == "Active" ? true : false, + }).ToPageListAsync(request); + //var infos = await _gainfoStore.Queryable(GainfoStatusEnumType.Working) + // .Where(ga => ga.CreateTime.ToString("yyyy-MM-dd") == time) + // .ToPageListAsync(request); + dic[time] = infos; + } + return dic; + } + + public async Task>> GetDimissionWeekNumberAsync([FromQuery] WeekNumberRequest request) + { + //获取近7天并转化为"yyyy-MM-dd"集合 + DateTime currentDate = DateTime.Now; + List times = new List(); + for (int i = 0; i < 7; i++) + { + DateTime date = currentDate.AddDays(-i); + string dateString = date.ToString("yyyy-MM-dd"); + times.Add(dateString); + } + + var dic = new Dictionary>(); + foreach (var time in times) + { + var infos = await _gainfoStore.Queryable(GainfoStatusEnumType.Leave) + .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") + .Where(ga => ga.CreateTime.ToString("yyyy-MM-dd") == time) + .Select((ga, de, type, posi, type2, type3) => new GainfoDetailResponse + { + No = ga.No, + SapNo = ga.SapNo, + Name = ga.Name, + Code = ga.Code, + DepartmentName = de.Name, + IdClass = ga.IdClass, + IdNo = ga.IdNo, + Gender = ga.Gender, + NativeName = type.Display, + Address = ga.Address, + Birthday = ga.Birthday, + Phone = ga.Phone, + Position = ga.Position, + Grade = posi.Grade, + Degree = ga.Degree, + Werks = ga.Werks, + CostId = ga.CostId, + Marital = ga.Marital, + CountryName = type2.Display, + NationName = type3.Display, + IsActive = ga.Employed == "Active" ? true : false, + }).ToPageListAsync(request); + dic[time] = infos; + } + return dic; + } + + public async Task GetGainfoNumbersAsync(string Werks) + { + //在职人数 + var onlineNumber = await _gainfoStore.Queryable(GainfoStatusEnumType.Working) + .Where(ga => ga.Werks == Werks) + .CountAsync(); + + //离职人数 + var offlineNumber = await _gainfoStore.Queryable(GainfoStatusEnumType.Leave) + .Where(ga => ga.Werks == Werks) + .CountAsync(); + + //考勤总人数 + var attendanceNumber = onlineNumber + offlineNumber; + + var res = new GainfoGainfoNumbersResponse + { + OnlineNumber = onlineNumber, + OfflineNumber = offlineNumber, + AttendanceNumber = attendanceNumber + }; + return res; + } + //-------------------------------------------help methods ------------------------------------------------ /// diff --git a/Src/Dlhis.Sys/Menu/Services/IMenuService.cs b/Src/Dlhis.Sys/Menu/Services/IMenuService.cs index 94a29d5c..79f47c66 100644 --- a/Src/Dlhis.Sys/Menu/Services/IMenuService.cs +++ b/Src/Dlhis.Sys/Menu/Services/IMenuService.cs @@ -9,7 +9,7 @@ public interface IMenuService : IScopeDependency { Task> GetListAsync(PlatformEnumType platform); - Task SaveMenuAsync(SaveMenuRequest request); + Task SaveMenuAsync(SaveMenuRequest request); Task AssignmentAsync(MenuPermissionAssignmentRequest request); diff --git a/Src/Dlhis.Sys/Menu/Services/Implements/MenuService.cs b/Src/Dlhis.Sys/Menu/Services/Implements/MenuService.cs index 6abefa92..b6c8601d 100644 --- a/Src/Dlhis.Sys/Menu/Services/Implements/MenuService.cs +++ b/Src/Dlhis.Sys/Menu/Services/Implements/MenuService.cs @@ -42,7 +42,7 @@ public class MenuService : IMenuService } [Transactional] - public async Task SaveMenuAsync(SaveMenuRequest request) + public async Task SaveMenuAsync(SaveMenuRequest request) { await CheckAsync(request); @@ -50,6 +50,7 @@ public class MenuService : IMenuService { var entity = request.Adapt(); await _dbContext.InsertAsync(entity); + return entity.Code; } else { @@ -59,6 +60,7 @@ public class MenuService : IMenuService request.Adapt(entity); await _dbContext.UpdateAsync(entity); + return entity.Code; } } @@ -187,9 +189,10 @@ public class MenuService : IMenuService foreach (var item in request) { - await SaveMenuAsync(item); + var code = await SaveMenuAsync(item); if (item.Items?.Any() == true) { + item.Items.ForEach(x => x.PCode = code); await RecursionSaveNextAsync(item.Items); } } @@ -199,9 +202,11 @@ public class MenuService : IMenuService { foreach (var item in menus) { - await SaveMenuAsync(item); + var code = await SaveMenuAsync(item); + if (item.Items?.Any() == true) { + item.Items.ForEach(x => x.PCode = code); await RecursionSaveNextAsync(item.Items); } } @@ -221,6 +226,7 @@ public class MenuService : IMenuService private async Task CheckAsync(SaveMenuRequest request) { + //检查重复code var exists = await _dbContext.Queryable() .Where(x => x.Code == request.Code) @@ -248,7 +254,11 @@ public class MenuService : IMenuService if (request.MenuType == MenuEnumType.Folder) { - request.PCode = null; + //request.PCode = null; + if (string.IsNullOrEmpty(request.PCode)) + { + request.PCode = null; + } } else if (request.MenuType == MenuEnumType.Menu) { @@ -300,4 +310,6 @@ public class MenuService : IMenuService await _dbContext.UpdateAsync(permissions); } } + + } \ No newline at end of file From 7f7afb251cac548885ada70b056621fcea65cc52 Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Wed, 21 Feb 2024 11:44:55 +0800 Subject: [PATCH 2/6] =?UTF-8?q?fix=20=E8=AE=BE=E5=A4=87=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=92=8C=E4=BA=BA=E5=91=98=E6=95=B0=E6=8D=AE=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/GainfosController.cs | 17 ++++-- .../Organization/Services/IGainfoService.cs | 6 +- .../Services/Implements/GainfoService.cs | 60 +++++++++++++++---- 3 files changed, 63 insertions(+), 20 deletions(-) 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; + } + } } From a46151abfdf70a587be3e5f4419c9ab856186b85 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Wed, 21 Feb 2024 12:06:10 +0800 Subject: [PATCH 3/6] fix db setting --- Src/Dlhis.Basic/appsettings.json | 6 +++--- Src/Dlhis.Canteen/appsettings.json | 4 ++-- Src/Dlhis.Common/appsettings.json | 4 ++-- Src/Dlhis.ScheduledTask/appsettings.json | 8 ++++---- Src/Dlhis.Sys/appsettings.json | 6 +++--- Src/Dlhis.User/appsettings.json | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Src/Dlhis.Basic/appsettings.json b/Src/Dlhis.Basic/appsettings.json index 8df2fbfb..6c35cbca 100644 --- a/Src/Dlhis.Basic/appsettings.json +++ b/Src/Dlhis.Basic/appsettings.json @@ -15,9 +15,9 @@ "Limit": 7200 }, "SqlSugarOptions": { - "DefaultConnectionString": "server=10.27.21.22;port=3306;userid=root;password=dlhis123;database=yikatong;charset=utf8mb4;", + "DefaultConnectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=yikatong;charset=utf8mb4;", "SlaveConnectionString": [], - "FaceConnectionString": "server=10.27.21.20;port=3306;userid=root;password=dlhis123;database=face;charset=utf8mb4;", + "FaceConnectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=face;charset=utf8mb4;", "Timeout": 30, "SlowSqlTime": 1, "EnableSqlLog": false @@ -68,7 +68,7 @@ { "Name": "MySQL", "Args": { - "connectionString": "server=10.27.21.22;port=3306;userid=root;password=dlhis123;database=log;charset=utf8mb4;", + "connectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=log;charset=utf8mb4;", "tableName": "Logs", "autoCreateSqlTable": true } diff --git a/Src/Dlhis.Canteen/appsettings.json b/Src/Dlhis.Canteen/appsettings.json index 57e5193a..d322419a 100644 --- a/Src/Dlhis.Canteen/appsettings.json +++ b/Src/Dlhis.Canteen/appsettings.json @@ -10,7 +10,7 @@ "CommonRequestUrl": "http://common" }, "SqlSugarOptions": { - "DefaultConnectionString": "server=10.27.21.22;port=3306;userid=root;password=dlhis123;database=yikatong;charset=utf8mb4;", + "DefaultConnectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=yikatong;charset=utf8mb4;", "SlaveConnectionString": [], "Timeout": 30, "SlowSqlTime": 1, @@ -62,7 +62,7 @@ { "Name": "MySQL", "Args": { - "connectionString": "server=10.27.21.22;port=3306;userid=root;password=dlhis123;database=log;charset=utf8mb4;", + "connectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=log;charset=utf8mb4;", "tableName": "Logs", "autoCreateSqlTable": true } diff --git a/Src/Dlhis.Common/appsettings.json b/Src/Dlhis.Common/appsettings.json index a08dbf50..5dffea5e 100644 --- a/Src/Dlhis.Common/appsettings.json +++ b/Src/Dlhis.Common/appsettings.json @@ -6,7 +6,7 @@ } }, "SqlSugarOptions": { - "DefaultConnectionString": "server=10.27.21.22;port=3306;userid=root;password=dlhis123;database=yikatong;charset=utf8mb4;", + "DefaultConnectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=yikatong;charset=utf8mb4;", "SlaveConnectionString": [], "Timeout": 30, "SlowSqlTime": 1, @@ -70,7 +70,7 @@ { "Name": "MySQL", "Args": { - "connectionString": "server=10.27.21.22;port=3306;userid=root;password=dlhis123;database=log;charset=utf8mb4;", + "connectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=log;charset=utf8mb4;", "tableName": "Logs", "autoCreateSqlTable": true } diff --git a/Src/Dlhis.ScheduledTask/appsettings.json b/Src/Dlhis.ScheduledTask/appsettings.json index 7e6db3ba..3ba4c3a5 100644 --- a/Src/Dlhis.ScheduledTask/appsettings.json +++ b/Src/Dlhis.ScheduledTask/appsettings.json @@ -6,15 +6,15 @@ } }, "SqlSugarOptions": { - "DefaultConnectionString": "server=10.27.21.22;port=3306;userid=root;password=dlhis123;database=yikatong;charset=utf8mb4;", + "DefaultConnectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=yikatong;charset=utf8mb4;", "SlaveConnectionString": [], - "FaceConnectionString": "server=10.27.21.20;port=3306;userid=root;password=dlhis123;database=face;charset=utf8mb4;", + "FaceConnectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=face;charset=utf8mb4;", "Timeout": 30, "SlowSqlTime": 1, "EnableSqlLog": false }, "ConnectionStrings": { - "HangfireConnection": "server=10.27.21.22;port=3306;userid=root;password=dlhis123;database=hangfire;default command timeout=100;Connection Timeout=30;Charset=utf8mb4;Allow User Variables=true;IgnoreCommandTransaction=true" + "HangfireConnection": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=hangfire;default command timeout=100;Connection Timeout=30;Charset=utf8mb4;Allow User Variables=true;IgnoreCommandTransaction=true" }, "FaceUrlOptions": { "Url": "https://yikatong.isawesome.cn/api/basic/gainfos/face?token=", @@ -76,7 +76,7 @@ { "Name": "MySQL", "Args": { - "connectionString": "server=10.27.21.22;port=3306;userid=root;password=dlhis123;database=log;charset=utf8mb4;", + "connectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=log;charset=utf8mb4;", "tableName": "Logs", "autoCreateSqlTable": true } diff --git a/Src/Dlhis.Sys/appsettings.json b/Src/Dlhis.Sys/appsettings.json index bd70241f..0c250034 100644 --- a/Src/Dlhis.Sys/appsettings.json +++ b/Src/Dlhis.Sys/appsettings.json @@ -11,8 +11,8 @@ "SysRequestUrl": "http://sys" }, "SqlSugarOptions": { - "DefaultConnectionString": "server=10.27.21.22;port=3306;userid=root;password=dlhis123;database=yikatong;charset=utf8mb4;", - "IdentityConnectionString": "server=10.27.21.22;port=3306;userid=root;password=dlhis123;database=identity;charset=utf8mb4;", + "DefaultConnectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=yikatong;charset=utf8mb4;", + "IdentityConnectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=identity;charset=utf8mb4;", "SlaveConnectionString": [], "Timeout": 30, "SlowSqlTime": 1, @@ -64,7 +64,7 @@ { "Name": "MySQL", "Args": { - "connectionString": "server=10.27.21.22;port=3306;userid=root;password=dlhis123;database=log;charset=utf8mb4;", + "connectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=log;charset=utf8mb4;", "tableName": "Logs", "autoCreateSqlTable": true } diff --git a/Src/Dlhis.User/appsettings.json b/Src/Dlhis.User/appsettings.json index 6a2c9dd4..6a7495bd 100644 --- a/Src/Dlhis.User/appsettings.json +++ b/Src/Dlhis.User/appsettings.json @@ -8,7 +8,7 @@ "AllowedHosts": "*", "SqlSugarOptions": { - "DefaultConnectionString": "server=10.27.21.22;port=3306;userid=root;password=dlhis123;database=identity;charset=utf8mb4;", + "DefaultConnectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=identity;charset=utf8mb4;", "SlaveConnectionString": [], "Timeout": 30, "SlowSqlTime": 1, From ef60f1dffc58423d1edafce592d2fcc01587fa2c Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Wed, 21 Feb 2024 14:59:23 +0800 Subject: [PATCH 4/6] =?UTF-8?q?feat=20=E8=8E=B7=E5=8F=96=E6=9C=AC=E5=9F=BA?= =?UTF-8?q?=E5=9C=B0=E7=AE=A1=E7=90=86=E5=91=98=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Device/Controllers/DevicesController.cs | 14 ++++++- .../Device/Response/DeviceNumberResponse.cs | 20 ++++++++++ .../Device/Services/IDeviceService.cs | 2 + .../Services/Implements/DeviceService.cs | 16 ++++++++ .../Controllers/GainfosController.cs | 13 +++++++ .../Organization/Services/IGainfoService.cs | 2 + .../Services/Implements/GainfoService.cs | 38 +++++++++++++++++++ 7 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 Src/Dlhis.Basic/Device/Response/DeviceNumberResponse.cs diff --git a/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs b/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs index 6dfcd3f3..cfc4a1dd 100644 --- a/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs +++ b/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs @@ -164,7 +164,17 @@ public class DevicesController : ControllerBase } /// - /// 获取考勤设备总数 + /// 获取考勤设备在线、离线及总数 + /// + /// + [HttpGet("devicesnumber")] + public async Task GetDeviceNumberAsync() + { + return await _deviceService.GetDeviceNumberAsync(); + } + + /// + /// 获取考勤设备详情列表 /// /// [HttpGet("attendancestotal")] @@ -174,7 +184,7 @@ public class DevicesController : ControllerBase } /// - /// 获取考勤在线/离线设备数 + /// 获取考勤在线/离线设备详情列表 /// /// [HttpGet("attendancesoffline")] diff --git a/Src/Dlhis.Basic/Device/Response/DeviceNumberResponse.cs b/Src/Dlhis.Basic/Device/Response/DeviceNumberResponse.cs new file mode 100644 index 00000000..925e9e98 --- /dev/null +++ b/Src/Dlhis.Basic/Device/Response/DeviceNumberResponse.cs @@ -0,0 +1,20 @@ +namespace Dlhis.Basic.Device.Response +{ + public class DeviceNumberResponse + { + /// + ///在线 + /// + public int OnlineNumber { get; set; } + + /// + /// 离线 + /// + public int OfflineNumber { get; set; } + + /// + /// 总数 + /// + public int TotalNumber { get; set; } + } +} diff --git a/Src/Dlhis.Basic/Device/Services/IDeviceService.cs b/Src/Dlhis.Basic/Device/Services/IDeviceService.cs index 9d346d3e..745702d4 100644 --- a/Src/Dlhis.Basic/Device/Services/IDeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/IDeviceService.cs @@ -17,6 +17,8 @@ public interface IDeviceService : IScopeDependency Task> GetAttendanceDevicesAsync(); + Task GetDeviceNumberAsync(); + Task> GetAttendanceTotalAsync(AttendanceTotalRequest request); Task> GetAttendanceOfflineAsync(DeviceOnlineAndofflineRequest request); diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs index 9d61dd71..28b2f66c 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs @@ -196,6 +196,22 @@ public class DeviceService : IDeviceService return devices.Where(x => x.Funcs.Contains(DeviceFuncEnumType.Attendance)).ToList(); } + public async Task GetDeviceNumberAsync() + { + var devices = await _dbContext.Queryable() + .Where(x => x.Type == DeviceTypeEnumType.Attendance) + .ToListAsync(); + var onlineNumber = devices.Where(x => x.Enable).Count(); + var offlineNumber = devices.Where(x => x.Enable == false).Count(); + var res = new DeviceNumberResponse + { + OnlineNumber = onlineNumber, + OfflineNumber = offlineNumber, + TotalNumber = devices.Count() + }; + return res; + } + public async Task> GetAttendanceTotalAsync(AttendanceTotalRequest request) { var page = await _dbContext.Queryable() diff --git a/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs b/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs index 2f1ee735..b6c09d43 100644 --- a/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs +++ b/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs @@ -196,5 +196,18 @@ public class GainfosController : ControllerBase return await _gainfoService.GetGainfoNumbersAsync(token); } + + /// + /// 获取本基地管理员列表 + /// + /// + /// + [HttpGet("administrator")] + public async Task> GetAdministratorAsync([FromQuery] WeekNumberRequest request) + { + // 从请求头中获取 Token + string token = HttpContext.Request.Headers["Authorization"].ToString().Replace("Bearer ", ""); + return await _gainfoService.GetAdministratorAsync(request,token); + } } diff --git a/Src/Dlhis.Basic/Organization/Services/IGainfoService.cs b/Src/Dlhis.Basic/Organization/Services/IGainfoService.cs index 56456bed..7bb8f0fc 100644 --- a/Src/Dlhis.Basic/Organization/Services/IGainfoService.cs +++ b/Src/Dlhis.Basic/Organization/Services/IGainfoService.cs @@ -37,4 +37,6 @@ public interface IGainfoService : IScopeDependency Task>> GetDimissionWeekNumberAsync([FromQuery] WeekNumberRequest request, string token); Task GetGainfoNumbersAsync(string token); + + Task> GetAdministratorAsync(WeekNumberRequest request,string token); } diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs index 2acfff75..ce14552e 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs @@ -514,6 +514,44 @@ public class GainfoService : IGainfoService return res; } + public async Task> GetAdministratorAsync( WeekNumberRequest request, string token) + { + var werks = GetClaimValueFromToken(token, "tenant"); + var info = await _gainfoStore.Queryable(GainfoStatusEnumType.Working) + .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") + .Where(ga => ga.Werks == werks && ga.IdentityUserId != 0) + .Select((ga, de, type, posi, type2, type3) => new GainfoDetailResponse + { + No = ga.No, + SapNo = ga.SapNo, + Name = ga.Name, + Code = ga.Code, + DepartmentName = de.Name, + IdClass = ga.IdClass, + IdNo = ga.IdNo, + Gender = ga.Gender, + NativeName = type.Display, + Address = ga.Address, + Birthday = ga.Birthday, + Phone = ga.Phone, + Position = ga.Position, + Grade = posi.Grade, + Degree = ga.Degree, + Werks = ga.Werks, + CostId = ga.CostId, + Marital = ga.Marital, + CountryName = type2.Display, + NationName = type3.Display, + IsActive = ga.Employed == "Active" ? true : false, + }).ToPageListAsync(request); + + return info; + } + //-------------------------------------------help methods ------------------------------------------------ /// From 5b40cfbd390f93747b3cf903b9b50e561100b473 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Wed, 21 Feb 2024 15:15:12 +0800 Subject: [PATCH 5/6] =?UTF-8?q?fix=20sap-api=E5=87=AD=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Implements/JinkoSapService.cs | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/Src/Dlhis.ScheduledTask/SyncSapInfo/Services/Implements/JinkoSapService.cs b/Src/Dlhis.ScheduledTask/SyncSapInfo/Services/Implements/JinkoSapService.cs index 7e2eac25..62ebf1f6 100644 --- a/Src/Dlhis.ScheduledTask/SyncSapInfo/Services/Implements/JinkoSapService.cs +++ b/Src/Dlhis.ScheduledTask/SyncSapInfo/Services/Implements/JinkoSapService.cs @@ -1,4 +1,6 @@ -using System.Text; +using System.Net.Http.Headers; +using System.Net.Http; +using System.Text; using Dlhis.ScheduledTask.SyncSapInfo.Dto; using Dlhis.ScheduledTask.SyncSapInfo.Response; using Dlhis.Sys.Api; @@ -8,22 +10,33 @@ namespace Dlhis.ScheduledTask.SyncSapInfo.Services.Implements; public class JinkoSapService : IJinkoSapService { - private readonly HttpClient _httpClient; private readonly ILogger _logger; + private readonly IHttpClientFactory _httpClientFactory; private readonly ITenantApi _tenantApi; public JinkoSapService(IHttpClientFactory httpClientFactory, ILogger logger, ITenantApi tenantApi) { - _httpClient = httpClientFactory.CreateClient("jinko:sap"); _logger = logger; + _httpClientFactory = httpClientFactory; _tenantApi = tenantApi; } + private HttpClient GetHttpClient() + { + var httpClient = _httpClientFactory.CreateClient("jinko:sap"); + httpClient.Timeout = TimeSpan.FromMinutes(10); + var credentials = string.Format("{0}:{1}", "EHS_USER", "y3R1hd2h*RICAC"); + var headerValue = Convert.ToBase64String(Encoding.UTF8.GetBytes(credentials)); + httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", headerValue); + + return httpClient; + } + public async Task GetSapOrganizationsAsync() { string apiUrl = "http://sappidap.jinkosolar.cn:51000/RESTAdapter/Rest/EHR_ORGANIZATION/"; - var response = await _httpClient.PostAsync(apiUrl, new StringContent("{}", Encoding.UTF8, "application/json")); + var response = await GetHttpClient().PostAsync(apiUrl, new StringContent("{}", Encoding.UTF8, "application/json")); response.EnsureSuccessStatusCode(); string responseJson = await response.Content.ReadAsStringAsync(); @@ -36,7 +49,7 @@ public class JinkoSapService : IJinkoSapService { string apiUrl = "http://sappidap.jinkosolar.cn:51000/RESTAdapter/Rest/EHR_POSITION/"; - var response = await _httpClient.PostAsync(apiUrl, new StringContent("{}", Encoding.UTF8, "application/json")); + var response = await GetHttpClient().PostAsync(apiUrl, new StringContent("{}", Encoding.UTF8, "application/json")); response.EnsureSuccessStatusCode(); string responseJson = await response.Content.ReadAsStringAsync(); @@ -75,7 +88,7 @@ public class JinkoSapService : IJinkoSapService }; var content = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json"); - var response = await _httpClient.PostAsync(apiUrl, content); + var response = await GetHttpClient().PostAsync(apiUrl, content); response.EnsureSuccessStatusCode(); var jsonResponse = await response.Content.ReadAsStringAsync(); From 495c2f9897e4904be7554d40507f110d6b4db9e4 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Wed, 21 Feb 2024 15:16:44 +0800 Subject: [PATCH 6/6] =?UTF-8?q?fix=20baseUrl=E5=92=8C=E4=BD=9C=E7=94=A8?= =?UTF-8?q?=E5=9F=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SyncSapInfo/Services/IJinkoSapService.cs | 2 +- .../SyncSapInfo/Services/Implements/JinkoSapService.cs | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Src/Dlhis.ScheduledTask/SyncSapInfo/Services/IJinkoSapService.cs b/Src/Dlhis.ScheduledTask/SyncSapInfo/Services/IJinkoSapService.cs index bd654f02..80bf045a 100644 --- a/Src/Dlhis.ScheduledTask/SyncSapInfo/Services/IJinkoSapService.cs +++ b/Src/Dlhis.ScheduledTask/SyncSapInfo/Services/IJinkoSapService.cs @@ -2,7 +2,7 @@ namespace Dlhis.ScheduledTask.SyncSapInfo.Services; -public interface IJinkoSapService : IScopeDependency +public interface IJinkoSapService : ISingletonDependency { Task GetSapOrganizationsAsync(); diff --git a/Src/Dlhis.ScheduledTask/SyncSapInfo/Services/Implements/JinkoSapService.cs b/Src/Dlhis.ScheduledTask/SyncSapInfo/Services/Implements/JinkoSapService.cs index 62ebf1f6..e1abe780 100644 --- a/Src/Dlhis.ScheduledTask/SyncSapInfo/Services/Implements/JinkoSapService.cs +++ b/Src/Dlhis.ScheduledTask/SyncSapInfo/Services/Implements/JinkoSapService.cs @@ -1,5 +1,4 @@ using System.Net.Http.Headers; -using System.Net.Http; using System.Text; using Dlhis.ScheduledTask.SyncSapInfo.Dto; using Dlhis.ScheduledTask.SyncSapInfo.Response; @@ -24,6 +23,8 @@ public class JinkoSapService : IJinkoSapService private HttpClient GetHttpClient() { var httpClient = _httpClientFactory.CreateClient("jinko:sap"); + //http://sappidap.jinkosolar.cn:51000 + httpClient.BaseAddress = new Uri("http://sappipap01.jinkosolar.cn:50100"); httpClient.Timeout = TimeSpan.FromMinutes(10); var credentials = string.Format("{0}:{1}", "EHS_USER", "y3R1hd2h*RICAC"); var headerValue = Convert.ToBase64String(Encoding.UTF8.GetBytes(credentials)); @@ -34,7 +35,7 @@ public class JinkoSapService : IJinkoSapService public async Task GetSapOrganizationsAsync() { - string apiUrl = "http://sappidap.jinkosolar.cn:51000/RESTAdapter/Rest/EHR_ORGANIZATION/"; + string apiUrl = "/RESTAdapter/Rest/EHR_ORGANIZATION/"; var response = await GetHttpClient().PostAsync(apiUrl, new StringContent("{}", Encoding.UTF8, "application/json")); response.EnsureSuccessStatusCode(); @@ -47,7 +48,7 @@ public class JinkoSapService : IJinkoSapService public async Task GetPositionsAsync() { - string apiUrl = "http://sappidap.jinkosolar.cn:51000/RESTAdapter/Rest/EHR_POSITION/"; + string apiUrl = "/RESTAdapter/Rest/EHR_POSITION/"; var response = await GetHttpClient().PostAsync(apiUrl, new StringContent("{}", Encoding.UTF8, "application/json")); response.EnsureSuccessStatusCode(); @@ -61,7 +62,7 @@ public class JinkoSapService : IJinkoSapService public async Task GetPersonsAsync() { - var apiUrl = "http://sappipap01.jinkosolar.cn:50100/RESTAdapter/Rest/EHR_PERSONNEL/"; + var apiUrl = "/RESTAdapter/Rest/EHR_PERSONNEL/"; var tenantResult = await _tenantApi.GetTenantsInternalAsync(); var tenants = tenantResult.Data;