add 消费处理完成
This commit is contained in:
@@ -3,7 +3,7 @@ using Dlhis.ScheduledTask.Common.Response;
|
||||
|
||||
namespace Dlhis.ScheduledTask.Common.Services;
|
||||
|
||||
public interface IJinkoJIPService : ISingletonDependency
|
||||
public interface IJinkoJipService : ISingletonDependency
|
||||
{
|
||||
Task<UploadAttendanceResponse> UploadAttendancesAsync(List<UploadAttendanceRequest> requests);
|
||||
|
||||
|
||||
36
Src/Dlhis.ScheduledTask/Common/Services/IJinkoJipService.cs
Normal file
36
Src/Dlhis.ScheduledTask/Common/Services/IJinkoJipService.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using Dlhis.ScheduledTask.Common.Request;
|
||||
using Dlhis.ScheduledTask.Common.Response;
|
||||
|
||||
namespace Dlhis.ScheduledTask.Common.Services;
|
||||
|
||||
public interface IJinkoJipService : ISingletonDependency
|
||||
{
|
||||
Task<UploadAttendanceResponse> UploadAttendancesAsync(List<UploadAttendanceRequest> requests);
|
||||
|
||||
Task<string> SyncMealSupplementRecordsAsync(List<SyncMealSupplementRecordRequest> requests);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取出差信息
|
||||
/// </summary>
|
||||
/// <param name="begin"></param>
|
||||
/// <param name="end"></param>
|
||||
/// <param name="fatory"></param>
|
||||
/// <returns></returns>
|
||||
Task<SapBusinessTripInfoResponse> GetTravelInfosByFactoryAsync(DateTime begin, DateTime end, string fatory);
|
||||
|
||||
/// <summary>
|
||||
/// 获取出差信息
|
||||
/// </summary>
|
||||
/// <param name="begin"></param>
|
||||
/// <param name="end"></param>
|
||||
/// <param name="userCode"></param>
|
||||
/// <returns></returns>
|
||||
Task<SapBusinessTripInfoResponse> GetTravelInfosByUserCodeAsync(DateTime begin, DateTime end, string userCode);
|
||||
|
||||
|
||||
Task<SapFaceSyncResponse> SyncFaceToSapAsync(string userCode, string base64);
|
||||
|
||||
|
||||
string IssueToken();
|
||||
}
|
||||
@@ -12,9 +12,9 @@ public class HangfireService : IHangfireService
|
||||
{
|
||||
private readonly RedisCache _redisCache;
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly IJinkoJIPService _jinkoJipService;
|
||||
private readonly IJinkoJipService _jinkoJipService;
|
||||
|
||||
public HangfireService(RedisCache redisCache, IDbContext dbContext, IJinkoJIPService jinkoJipService)
|
||||
public HangfireService(RedisCache redisCache, IDbContext dbContext, IJinkoJipService jinkoJipService)
|
||||
{
|
||||
_redisCache = redisCache;
|
||||
_dbContext = dbContext;
|
||||
|
||||
@@ -10,13 +10,13 @@ using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Dlhis.ScheduledTask.Common.Services.Implements;
|
||||
|
||||
public class JinkoJIPService : IJinkoJIPService
|
||||
public class JinkoJipService : IJinkoJipService
|
||||
{
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly ILogger<JinkoJIPService> _logger;
|
||||
private readonly ILogger<JinkoJipService> _logger;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
public JinkoJIPService(IHttpClientFactory httpClientFactory, ILogger<JinkoJIPService> logger, IConfiguration configuration)
|
||||
public JinkoJipService(IHttpClientFactory httpClientFactory, ILogger<JinkoJipService> logger, IConfiguration configuration)
|
||||
{
|
||||
_httpClientFactory = httpClientFactory;
|
||||
_logger = logger;
|
||||
|
||||
@@ -0,0 +1,213 @@
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
using Dlhis.ScheduledTask.Common.Request;
|
||||
using Dlhis.ScheduledTask.Common.Response;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Dlhis.ScheduledTask.Common.Services.Implements;
|
||||
|
||||
public class JinkoJipService : IJinkoJipService
|
||||
{
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly ILogger<JinkoJipService> _logger;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
public JinkoJipService(IHttpClientFactory httpClientFactory, ILogger<JinkoJipService> logger, IConfiguration configuration)
|
||||
{
|
||||
_httpClientFactory = httpClientFactory;
|
||||
_logger = logger;
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
private HttpClient GetHttpClient()
|
||||
{
|
||||
var httpClient = _httpClientFactory.CreateClient();
|
||||
httpClient.BaseAddress = new Uri(_configuration.GetSection("JinkoOptions:Jip:BaseUrl").Value);
|
||||
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", IssueToken());
|
||||
|
||||
return httpClient;
|
||||
}
|
||||
|
||||
public async Task<UploadAttendanceResponse> UploadAttendancesAsync(List<UploadAttendanceRequest> requests)
|
||||
{
|
||||
var requestUrl = "/JIP/HCM/HCM_SWIPE_DATA_SAVE";
|
||||
|
||||
var body = new
|
||||
{
|
||||
T_DATA = requests,
|
||||
};
|
||||
|
||||
var json = body.ToJson();
|
||||
|
||||
//_logger.LogInformation("上传考勤记录请求:{json}", json);
|
||||
|
||||
var content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
var response = await GetHttpClient().PostAsync(requestUrl, content);
|
||||
var responseJson = await response.Content.ReadAsStringAsync();
|
||||
|
||||
_logger.LogInformation("上传考勤记录响应:{json}", responseJson);
|
||||
|
||||
try
|
||||
{
|
||||
return responseJson.ToObject<UploadAttendanceResponse>();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return new UploadAttendanceResponse
|
||||
{
|
||||
OLX = "99",
|
||||
OMS = "接口响应数据异常,无法反序列化"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task<string> SyncMealSupplementRecordsAsync(List<SyncMealSupplementRecordRequest> requests)
|
||||
{
|
||||
var requestUrl = "/JIP/DHR/DHR_DL_CALLBACK";
|
||||
|
||||
var json = requests.ToJson(Kurisu.AspNetCore.Utils.Extensions.JsonExtensions.DefaultSetting);
|
||||
|
||||
var content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
var response = await GetHttpClient().PostAsync(requestUrl, content);
|
||||
var responseJson = await response.Content.ReadAsStringAsync();
|
||||
|
||||
_logger.LogInformation("餐补状态同步响应:{json}", responseJson);
|
||||
|
||||
var jobj = JObject.Parse(responseJson);
|
||||
if (jobj.TryGetValue("exp", out var exp))
|
||||
{
|
||||
true.ThrowIfTrue(exp.Value<string>());
|
||||
}
|
||||
|
||||
if (jobj.TryGetValue("message", out var message) && !jobj.ContainsKey("code"))
|
||||
{
|
||||
true.ThrowIfTrue(message.Value<string>());
|
||||
}
|
||||
|
||||
(jobj.GetValue("code").Value<int>() != 200).ThrowIfTrue(jobj.GetValue("message").Value<string>());
|
||||
|
||||
return responseJson;
|
||||
}
|
||||
|
||||
|
||||
public async Task<SapBusinessTripInfoResponse> GetTravelInfosByFactoryAsync(DateTime begin, DateTime end, string factory)
|
||||
{
|
||||
const string apiUrl = "/JIP/HCM/HCM_TRAVELINFO";
|
||||
|
||||
var beginDay = begin.ToString("yyyyMMdd");
|
||||
var endDay = end.ToString("yyyyMMdd");
|
||||
|
||||
var obj = new
|
||||
{
|
||||
I_PAGE = 1,
|
||||
I_LINE = 500,
|
||||
IV_BEGDA = beginDay,
|
||||
IV_ENDDA = endDay,
|
||||
IT_CCMDD = new List<object>
|
||||
{
|
||||
new
|
||||
{
|
||||
IV_CCMDD = factory
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var body = obj.ToJson();
|
||||
|
||||
var content = new StringContent(body, Encoding.UTF8, "application/json");
|
||||
var response = await GetHttpClient().PostAsync(apiUrl, content);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var jsonResponse = await response.Content.ReadAsStringAsync();
|
||||
return jsonResponse.ToObject<SapBusinessTripInfoResponse>();
|
||||
}
|
||||
|
||||
public async Task<SapBusinessTripInfoResponse> GetTravelInfosByUserCodeAsync(DateTime begin, DateTime end, string userCode)
|
||||
{
|
||||
const string apiUrl = "/JIP/HCM/HCM_TRAVELINFO";
|
||||
|
||||
var beginDay = begin.ToString("yyyyMMdd");
|
||||
var endDay = end.ToString("yyyyMMdd");
|
||||
|
||||
//IV_GONGH IV_ORGID
|
||||
//IT_2002GH
|
||||
var obj = new
|
||||
{
|
||||
IV_BEGDA = beginDay,
|
||||
IV_ENDDA = endDay,
|
||||
IT_2002GH = new List<object>
|
||||
{
|
||||
new
|
||||
{
|
||||
IV_GONGH = userCode
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var body = obj.ToJson();
|
||||
|
||||
var content = new StringContent(body, Encoding.UTF8, "application/json");
|
||||
var response = await GetHttpClient().PostAsync(apiUrl, content);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var jsonResponse = await response.Content.ReadAsStringAsync();
|
||||
return jsonResponse.ToObject<SapBusinessTripInfoResponse>();
|
||||
}
|
||||
|
||||
public async Task<SapFaceSyncResponse> SyncFaceToSapAsync(string userCode, string base64)
|
||||
{
|
||||
const string apiUrl = "/JIP/HCM/HCM_I_PHOTO";
|
||||
var obj = new
|
||||
{
|
||||
I_WORKCODE = userCode,
|
||||
I_PHOTO_STR = base64
|
||||
};
|
||||
|
||||
var body = obj.ToJson();
|
||||
|
||||
var content = new StringContent(body, Encoding.UTF8, "application/json");
|
||||
var response = await GetHttpClient().PostAsync(apiUrl, content);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var jsonResponse = await response.Content.ReadAsStringAsync();
|
||||
return jsonResponse.ToObject<SapFaceSyncResponse>();
|
||||
}
|
||||
|
||||
|
||||
public string IssueToken()
|
||||
{
|
||||
var jwtKey = _configuration.GetSection("JinkoOptions:Jip:Key").Value;
|
||||
var jwtSecret = _configuration.GetSection("JinkoOptions:Jip:Secret").Value;
|
||||
const int min = 5;
|
||||
|
||||
var now = DateTime.Now.AddMinutes(-min);
|
||||
var expires = DateTime.Now.AddMinutes(min);
|
||||
|
||||
var claims = new List<Claim>
|
||||
{
|
||||
new(JwtRegisteredClaimNames.Nbf, $"{new DateTimeOffset(now).ToUnixTimeSeconds()}"),
|
||||
new(JwtRegisteredClaimNames.Exp, $"{new DateTimeOffset(expires).ToUnixTimeSeconds()}"),
|
||||
new(JwtRegisteredClaimNames.Iss, jwtKey),
|
||||
};
|
||||
|
||||
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtSecret));
|
||||
var descriptor = new SecurityTokenDescriptor
|
||||
{
|
||||
Subject = new ClaimsIdentity(claims),
|
||||
Issuer = jwtKey,
|
||||
IssuedAt = now,
|
||||
NotBefore = now,
|
||||
Expires = expires,
|
||||
SigningCredentials = new SigningCredentials(key, SecurityAlgorithms.HmacSha256)
|
||||
};
|
||||
|
||||
var jwtHandler = new JwtSecurityTokenHandler();
|
||||
var securityToken = jwtHandler.CreateToken(descriptor);
|
||||
return jwtHandler.WriteToken(securityToken);
|
||||
}
|
||||
}
|
||||
@@ -15,12 +15,12 @@ namespace Dlhis.ScheduledTask.Common.Services.Implements;
|
||||
|
||||
public class SapBusinessTripService : ISapBusinessTripService
|
||||
{
|
||||
private readonly IJinkoJIPService _jinkoJipService;
|
||||
private readonly IJinkoJipService _jinkoJipService;
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly IDevicePermissionApi _devicePermissionApi;
|
||||
private readonly ILogger<SapBusinessTripService> _logger;
|
||||
|
||||
public SapBusinessTripService(IJinkoJIPService jinkoJipService, IDbContext dbContext, IDevicePermissionApi devicePermissionApi, ILogger<SapBusinessTripService> logger)
|
||||
public SapBusinessTripService(IJinkoJipService jinkoJipService, IDbContext dbContext, IDevicePermissionApi devicePermissionApi, ILogger<SapBusinessTripService> logger)
|
||||
{
|
||||
_jinkoJipService = jinkoJipService;
|
||||
_dbContext = dbContext;
|
||||
|
||||
Reference in New Issue
Block a user