diff --git a/Src/Dlhis.ScheduledTask/Common/Response/SapTravelInfoResponse.cs b/Src/Dlhis.ScheduledTask/Common/Response/SapTravelInfoResponse.cs new file mode 100644 index 00000000..c706f9bd --- /dev/null +++ b/Src/Dlhis.ScheduledTask/Common/Response/SapTravelInfoResponse.cs @@ -0,0 +1,88 @@ +using Newtonsoft.Json; + +namespace Dlhis.ScheduledTask.Common.Response +{ + public class SapTravelInfoResponse + { + /// + /// 明细数据 + /// + [JsonProperty("OT_2002")] + public List Items { get; set; } + } + + public class SapTravelInfoItem + { + /// + /// 工号 + /// + [JsonProperty("OV_GONGH")] + public string Code { get; set; } + + /// + /// 姓名 + /// + [JsonProperty("OV_ENAME")] + public string Name { get; set; } + + /// + /// 开始日期 + /// + [JsonProperty("OV_BEGDA")] + public string BeginDate { get; set; } + + /// + /// 结束日期 + /// + [JsonProperty("OV_ENDDA")] + public string EndDate { get; set; } + + /// + /// 开始时间 + /// + [JsonProperty("OV_BEGUZ")] + public DateTime BeginDateTime { get; set; } + + /// + /// 结束时间 + /// + [JsonProperty("OV_ENDUZ")] + public DateTime EndDateTime { get; set; } + + /// + /// 出差类型 + /// + [JsonProperty("OV_AWART")] + public string Type { get; set; } + + /// + /// 出差类型描述 + /// + [JsonProperty("OV_ATEXT")] + public string TypeDesc { get; set; } + + /// + /// 出差时数 + /// + [JsonProperty("OV_STDAZ")] + public int Hour { get; set; } + + /// + /// 出差天数 + /// + [JsonProperty("OV_ABWTG")] + public double Day { get; set; } + + /// + /// 出差目的地 + /// + [JsonProperty("OV_CCMDD")] + public string Destination { get; set; } + + /// + /// 出差目的地描述 + /// + [JsonProperty("OV_CCMDDM")] + public string DestinationDesc { get; set; } + } +} \ No newline at end of file diff --git a/Src/Dlhis.ScheduledTask/Common/Services/IJinkoSapService.cs b/Src/Dlhis.ScheduledTask/Common/Services/IJinkoSapService.cs index daae853f..9ed75d5e 100644 --- a/Src/Dlhis.ScheduledTask/Common/Services/IJinkoSapService.cs +++ b/Src/Dlhis.ScheduledTask/Common/Services/IJinkoSapService.cs @@ -11,4 +11,12 @@ public interface IJinkoSapService : IScopeDependency Task GetPersonsByWerkAsync(string werk); Task GetPersonsByCodeAsync(string code); -} + + /// + /// 获取出差信息 + /// + /// + /// + /// + Task GetTravelInfosAsync(DateTime begin, DateTime end); +} \ No newline at end of file diff --git a/Src/Dlhis.ScheduledTask/Common/Services/Implements/JinkoSapService.cs b/Src/Dlhis.ScheduledTask/Common/Services/Implements/JinkoSapService.cs index ca5b9628..11fcd506 100644 --- a/Src/Dlhis.ScheduledTask/Common/Services/Implements/JinkoSapService.cs +++ b/Src/Dlhis.ScheduledTask/Common/Services/Implements/JinkoSapService.cs @@ -3,6 +3,7 @@ using System.Text; using Dlhis.Entity.Basic.Entity; using Dlhis.ScheduledTask.Common.Dto; using Dlhis.ScheduledTask.Common.Response; +using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.SqlSugar.Services; using Newtonsoft.Json; @@ -25,7 +26,7 @@ public class JinkoSapService : IJinkoSapService 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 credentials = $"{"EHS_USER"}:{"y3R1hd2h*RICAC"}"; var headerValue = Convert.ToBase64String(Encoding.UTF8.GetBytes(credentials)); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", headerValue); @@ -34,7 +35,7 @@ public class JinkoSapService : IJinkoSapService public async Task GetSapOrganizationsAsync() { - string apiUrl = "/RESTAdapter/Rest/EHR_ORGANIZATION/"; + const 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 = "/RESTAdapter/Rest/EHR_POSITION/"; + const 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 GetPersonsByWerkAsync(string werk) { - var apiUrl = "/RESTAdapter/Rest/EHR_PERSONNEL/"; + const string apiUrl = "/RESTAdapter/Rest/EHR_PERSONNEL/"; var werkInfo = await _dbContext.Queryable() .Where(x => x.Enable) @@ -74,12 +75,12 @@ public class JinkoSapService : IJinkoSapService T_WERKS = new { item = new List - { - new - { - WERKS = werkInfo.Werk - } - } + { + new + { + WERKS = werkInfo.Werk + } + } }, T_PERSON = Array.Empty(), T_PNO = Array.Empty(), @@ -131,7 +132,7 @@ public class JinkoSapService : IJinkoSapService public async Task GetPersonsByCodeAsync(string code) { - var apiUrl = "/RESTAdapter/Rest/EHR_PERSONNEL/"; + const string apiUrl = "/RESTAdapter/Rest/EHR_PERSONNEL/"; var body = new { @@ -193,4 +194,29 @@ public class JinkoSapService : IJinkoSapService } }; } -} + + + public async Task GetTravelInfosAsync(DateTime begin, DateTime end) + { + const string apiUrl = "/JIP/HCM/HCM_TRAVELINFO"; + + var beginDay = begin.ToString("yyyyMMdd"); + var endDay = end.ToString("yyyyMMdd"); + + var obj = new + { + IV_BEGDA = beginDay, + IV_ENDDA = endDay + }; + + var body = obj.ToJson(); + + var content = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json"); + var response = await GetHttpClient().PostAsync(apiUrl, content); + response.EnsureSuccessStatusCode(); + + var jsonResponse = await response.Content.ReadAsStringAsync(); + + return JsonConvert.DeserializeObject(jsonResponse); + } +} \ No newline at end of file