diff --git a/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs b/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs index dc903205..cfc4a1dd 100644 --- a/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs +++ b/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs @@ -162,4 +162,44 @@ public class DevicesController : ControllerBase { return await _deviceService.GetAttendanceDevicesAsync(); } + + /// + /// 获取考勤设备在线、离线及总数 + /// + /// + [HttpGet("devicesnumber")] + public async Task GetDeviceNumberAsync() + { + return await _deviceService.GetDeviceNumberAsync(); + } + + /// + /// 获取考勤设备详情列表 + /// + /// + [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/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 095effcb..745702d4 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,12 @@ public interface IDeviceService : IScopeDependency Task GetDeviceByNoAsync(DeviceByNoRequest request); Task> GetAttendanceDevicesAsync(); + + Task GetDeviceNumberAsync(); + + 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..28b2f66c 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,78 @@ 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() + .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..b6c09d43 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,57 @@ public class GainfosController : ControllerBase { return await _gainfoService.GetGainfoDetailTaskAsync(request); } + + /// + /// 获取近七天入职人数及列表 + /// + /// + [HttpGet("weeknumber")] + public async Task>> GetWeekNumberAsync([FromQuery] WeekNumberRequest request) + { + // 从请求头中获取 Token + string token = HttpContext.Request.Headers["Authorization"].ToString().Replace("Bearer ", ""); + + return await _gainfoService.GetWeekNumberAsync(request,token); + } + + /// + /// 获取近七天离职人数及列表 + /// + /// + [HttpGet("weeknumberdimission")] + public async Task>> GetDimissionWeekNumberAsync([FromQuery] WeekNumberRequest request) + { + // 从请求头中获取 Token + string token = HttpContext.Request.Headers["Authorization"].ToString().Replace("Bearer ", ""); + + return await _gainfoService.GetDimissionWeekNumberAsync(request,token); + } + + /// + /// 获取基地在职、离职、考勤数 + /// + /// + [HttpGet("gainfonumbers")] + public async Task GetGainfoNumbersAsync() + { + // 从请求头中获取 Token + string token = HttpContext.Request.Headers["Authorization"].ToString().Replace("Bearer ", ""); + + 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/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..7bb8f0fc 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,12 @@ public interface IGainfoService : IScopeDependency Task> GetGainfoListTaskAsync(GainfoListRequest request); Task GetGainfoDetailTaskAsync(GainfoDetailRequest request); + + Task>> GetWeekNumberAsync(WeekNumberRequest request, string token); + + 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 7a5506f2..ce14552e 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,6 +378,180 @@ public class GainfoService : IGainfoService return info; } + 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(); + 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 && ga.Werks == werks) + .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(WeekNumberRequest request, string token) + { + var werks = GetClaimValueFromToken(token, "tenant"); + + //获取近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 && ga.Werks == werks) + .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 token) + { + var werks = GetClaimValueFromToken(token, "tenant"); + + //在职人数 + 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; + } + + 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 ------------------------------------------------ /// @@ -415,4 +590,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; + } + } } 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 7e2eac25..e1abe780 100644 --- a/Src/Dlhis.ScheduledTask/SyncSapInfo/Services/Implements/JinkoSapService.cs +++ b/Src/Dlhis.ScheduledTask/SyncSapInfo/Services/Implements/JinkoSapService.cs @@ -1,4 +1,5 @@ -using System.Text; +using System.Net.Http.Headers; +using System.Text; using Dlhis.ScheduledTask.SyncSapInfo.Dto; using Dlhis.ScheduledTask.SyncSapInfo.Response; using Dlhis.Sys.Api; @@ -8,22 +9,35 @@ 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"); + //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)); + httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", headerValue); + + return httpClient; + } + public async Task GetSapOrganizationsAsync() { - string apiUrl = "http://sappidap.jinkosolar.cn:51000/RESTAdapter/Rest/EHR_ORGANIZATION/"; + string apiUrl = "/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(); @@ -34,9 +48,9 @@ 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 _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(); @@ -48,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; @@ -75,7 +89,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(); 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 4a0c7fca..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,8 +189,10 @@ public class MenuService : IMenuService foreach (var item in request) { + var code = await SaveMenuAsync(item); if (item.Items?.Any() == true) { + item.Items.ForEach(x => x.PCode = code); await RecursionSaveNextAsync(item.Items); } } @@ -198,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); } } @@ -220,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) @@ -247,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) { @@ -299,4 +310,6 @@ public class MenuService : IMenuService await _dbContext.UpdateAsync(permissions); } } + + } \ No newline at end of file