feat 获取出差信息

This commit is contained in:
2024-05-22 16:39:55 +08:00
parent 5383410b77
commit 1422d6836c
3 changed files with 135 additions and 13 deletions

View File

@@ -0,0 +1,88 @@
using Newtonsoft.Json;
namespace Dlhis.ScheduledTask.Common.Response
{
public class SapTravelInfoResponse
{
/// <summary>
/// 明细数据
/// </summary>
[JsonProperty("OT_2002")]
public List<SapTravelInfoItem> Items { get; set; }
}
public class SapTravelInfoItem
{
/// <summary>
/// 工号
/// </summary>
[JsonProperty("OV_GONGH")]
public string Code { get; set; }
/// <summary>
/// 姓名
/// </summary>
[JsonProperty("OV_ENAME")]
public string Name { get; set; }
/// <summary>
/// 开始日期
/// </summary>
[JsonProperty("OV_BEGDA")]
public string BeginDate { get; set; }
/// <summary>
/// 结束日期
/// </summary>
[JsonProperty("OV_ENDDA")]
public string EndDate { get; set; }
/// <summary>
/// 开始时间
/// </summary>
[JsonProperty("OV_BEGUZ")]
public DateTime BeginDateTime { get; set; }
/// <summary>
/// 结束时间
/// </summary>
[JsonProperty("OV_ENDUZ")]
public DateTime EndDateTime { get; set; }
/// <summary>
/// 出差类型
/// </summary>
[JsonProperty("OV_AWART")]
public string Type { get; set; }
/// <summary>
/// 出差类型描述
/// </summary>
[JsonProperty("OV_ATEXT")]
public string TypeDesc { get; set; }
/// <summary>
/// 出差时数
/// </summary>
[JsonProperty("OV_STDAZ")]
public int Hour { get; set; }
/// <summary>
/// 出差天数
/// </summary>
[JsonProperty("OV_ABWTG")]
public double Day { get; set; }
/// <summary>
/// 出差目的地
/// </summary>
[JsonProperty("OV_CCMDD")]
public string Destination { get; set; }
/// <summary>
/// 出差目的地描述
/// </summary>
[JsonProperty("OV_CCMDDM")]
public string DestinationDesc { get; set; }
}
}

View File

@@ -11,4 +11,12 @@ public interface IJinkoSapService : IScopeDependency
Task<SapPersonResponse> GetPersonsByWerkAsync(string werk);
Task<SapPersonResponse> GetPersonsByCodeAsync(string code);
}
/// <summary>
/// 获取出差信息
/// </summary>
/// <param name="begin"></param>
/// <param name="end"></param>
/// <returns></returns>
Task<SapTravelInfoResponse> GetTravelInfosAsync(DateTime begin, DateTime end);
}

View File

@@ -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<SapOrganizationResponse> 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<SapPositionResponse> 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<SapPersonResponse> GetPersonsByWerkAsync(string werk)
{
var apiUrl = "/RESTAdapter/Rest/EHR_PERSONNEL/";
const string apiUrl = "/RESTAdapter/Rest/EHR_PERSONNEL/";
var werkInfo = await _dbContext.Queryable<WerkEntity>()
.Where(x => x.Enable)
@@ -74,12 +75,12 @@ public class JinkoSapService : IJinkoSapService
T_WERKS = new
{
item = new List<object>
{
new
{
WERKS = werkInfo.Werk
}
}
{
new
{
WERKS = werkInfo.Werk
}
}
},
T_PERSON = Array.Empty<string>(),
T_PNO = Array.Empty<string>(),
@@ -131,7 +132,7 @@ public class JinkoSapService : IJinkoSapService
public async Task<SapPersonResponse> 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<SapTravelInfoResponse> 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<SapTravelInfoResponse>(jsonResponse);
}
}