fix 临时调整代码
This commit is contained in:
@@ -8,9 +8,4 @@ internal static class GetHashCodeExtensions
|
||||
if(string.IsNullOrEmpty(o.ToString())) return 0;
|
||||
return o.GetHashCode();
|
||||
}
|
||||
|
||||
public static int SafeGetHashCode(this int o)
|
||||
{
|
||||
return o.GetHashCode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace Dlhis.ScheduledTask.Common.Response
|
||||
{
|
||||
namespace Dlhis.ScheduledTask.Common.Response;
|
||||
|
||||
public class UploadAttendanceResponse
|
||||
{
|
||||
/// <summary>
|
||||
@@ -9,4 +9,3 @@
|
||||
|
||||
public string OMS { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,11 +5,13 @@ namespace Dlhis.ScheduledTask.Common.Services;
|
||||
|
||||
public interface IJinkoJipService : ISingletonDependency
|
||||
{
|
||||
Task<UploadAttendanceResponse> UploadAttendancesAsync(List<UploadAttendanceRequest> requests);
|
||||
|
||||
/// <summary>
|
||||
/// 同步餐补处理结果
|
||||
/// </summary>
|
||||
/// <param name="requests"></param>
|
||||
/// <returns></returns>
|
||||
Task<string> SyncMealSupplementRecordsAsync(List<SyncMealSupplementRecordRequest> requests);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取出差信息
|
||||
/// </summary>
|
||||
@@ -28,9 +30,11 @@ public interface IJinkoJipService : ISingletonDependency
|
||||
/// <returns></returns>
|
||||
Task<SapBusinessTripInfoResponse> GetTravelInfosByUserCodeAsync(DateTime begin, DateTime end, string userCode);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 同步人脸数据到SAP
|
||||
/// </summary>
|
||||
/// <param name="userCode"></param>
|
||||
/// <param name="base64"></param>
|
||||
/// <returns></returns>
|
||||
Task<SapFaceSyncResponse> SyncFaceToSapAsync(string userCode, string base64);
|
||||
|
||||
|
||||
string IssueToken();
|
||||
}
|
||||
@@ -23,41 +23,41 @@ public class HangfireService : IHangfireService
|
||||
|
||||
public async Task CreateSapPersonSyncBackgroundJobAsync(SapNoRequest request)
|
||||
{
|
||||
var jobKey = $"hangfire:background:person:{request.Code}";
|
||||
|
||||
using var handler = await _redisCache.LockAsync(jobKey);
|
||||
if (handler.Acquired)
|
||||
{
|
||||
BackgroundJob.Enqueue<IGainfoUpdateService>(x => x.TodoByCodeAsync(request.Code));
|
||||
}
|
||||
// var jobKey = $"hangfire:background:person:{request.Code}";
|
||||
//
|
||||
// using var handler = await _redisCache.LockAsync(jobKey);
|
||||
// if (handler.Acquired)
|
||||
// {
|
||||
// BackgroundJob.Enqueue<IGainfoUpdateService>(x => x.TodoByCodeAsync(request.Code));
|
||||
// }
|
||||
}
|
||||
|
||||
public async Task CreateSapWerkSyncBackgroundJobAsync(SapNoRequest request)
|
||||
{
|
||||
var jobKey = $"hangfire:background:werk:{request.Code}";
|
||||
|
||||
await using var handler = await _redisCache.LockAsync(jobKey);
|
||||
if (handler.Acquired)
|
||||
{
|
||||
var werkInfo = await _dbContext.Queryable<WerkEntity>().Where(x => x.Werk == request.Code).SingleAsync();
|
||||
werkInfo.ThrowIfNull("人事范围不存在");
|
||||
|
||||
werkInfo.BackgroundJobKey.IsPresent().ThrowIfTrue("任务进行中,无法再次发起同步");
|
||||
|
||||
BackgroundJob.Enqueue<IGainfoUpdateService>(x => x.TodoByWerkAsync(request.Code));
|
||||
}
|
||||
// var jobKey = $"hangfire:background:werk:{request.Code}";
|
||||
//
|
||||
// await using var handler = await _redisCache.LockAsync(jobKey);
|
||||
// if (handler.Acquired)
|
||||
// {
|
||||
// var werkInfo = await _dbContext.Queryable<WerkEntity>().Where(x => x.Werk == request.Code).SingleAsync();
|
||||
// werkInfo.ThrowIfNull("人事范围不存在");
|
||||
//
|
||||
// werkInfo.BackgroundJobKey.IsPresent().ThrowIfTrue("任务进行中,无法再次发起同步");
|
||||
//
|
||||
// BackgroundJob.Enqueue<IGainfoUpdateService>(x => x.TodoByWerkAsync(request.Code));
|
||||
// }
|
||||
}
|
||||
|
||||
public async Task FaceUploadToSapAsync(FaceUploadToSapRequest request)
|
||||
{
|
||||
var response = await _jinkoJipService.SyncFaceToSapAsync(request.UserCode, request.Base64);
|
||||
if (response.OLX == "S")
|
||||
{
|
||||
var faceDbContext = _dbContext.ChangeDb("face");
|
||||
await faceDbContext.Updateable<GainfoFaceEntity>()
|
||||
.SetColumns(x => x.IsSync == true)
|
||||
.Where(x => x.UserCode == request.UserCode)
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
// var response = await _jinkoJipService.SyncFaceToSapAsync(request.UserCode, request.Base64);
|
||||
// if (response.OLX == "S")
|
||||
// {
|
||||
// var faceDbContext = _dbContext.ChangeDb("face");
|
||||
// await faceDbContext.Updateable<GainfoFaceEntity>()
|
||||
// .SetColumns(x => x.IsSync == true)
|
||||
// .Where(x => x.UserCode == request.UserCode)
|
||||
// .ExecuteCommandAsync();
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Net.Http.Headers;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
using Dlhis.Jip.Api.Requests;
|
||||
using Dlhis.ScheduledTask.Common.Request;
|
||||
using Dlhis.ScheduledTask.Common.Response;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Net;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.ScheduledTask.Common.Dto;
|
||||
@@ -22,24 +21,11 @@ public class JinkoSapService : IJinkoSapService
|
||||
_httpClientFactory = httpClientFactory;
|
||||
}
|
||||
|
||||
private HttpClient GetHttpClient()
|
||||
{
|
||||
var httpClient = _httpClientFactory.CreateClient("jinko:sap");
|
||||
httpClient.BaseAddress = new Uri("http://sappipap01.jinkosolar.cn:50100");
|
||||
httpClient.Timeout = TimeSpan.FromMinutes(10);
|
||||
|
||||
const string credentials = $"{"EHS_USER"}:{"y3R1hd2h*RICAC"}";
|
||||
var headerValue = Convert.ToBase64String(Encoding.UTF8.GetBytes(credentials));
|
||||
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", headerValue);
|
||||
|
||||
return httpClient;
|
||||
}
|
||||
|
||||
public async Task<SapOrganizationResponse> GetSapOrganizationsAsync()
|
||||
{
|
||||
const string apiUrl = "/RESTAdapter/Rest/EHR_ORGANIZATION/";
|
||||
|
||||
var response = await GetHttpClient().PostAsync(apiUrl, new StringContent("{}", Encoding.UTF8, "application/json"));
|
||||
var response = await _httpClientFactory.CreateClient("jinko:sap").PostAsync(apiUrl, new StringContent("{}", Encoding.UTF8, "application/json"));
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
string responseJson = await response.Content.ReadAsStringAsync();
|
||||
@@ -52,7 +38,7 @@ public class JinkoSapService : IJinkoSapService
|
||||
{
|
||||
const string apiUrl = "/RESTAdapter/Rest/EHR_POSITION/";
|
||||
|
||||
var response = await GetHttpClient().PostAsync(apiUrl, new StringContent("{}", Encoding.UTF8, "application/json"));
|
||||
var response = await _httpClientFactory.CreateClient("jinko:sap").PostAsync(apiUrl, new StringContent("{}", Encoding.UTF8, "application/json"));
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
string responseJson = await response.Content.ReadAsStringAsync();
|
||||
@@ -89,7 +75,7 @@ public class JinkoSapService : IJinkoSapService
|
||||
};
|
||||
|
||||
var content = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");
|
||||
var response = await GetHttpClient().PostAsync(apiUrl, content);
|
||||
var response = await _httpClientFactory.CreateClient("jinko:sap").PostAsync(apiUrl, content);
|
||||
if (response.StatusCode != HttpStatusCode.OK)
|
||||
{
|
||||
_logger.LogError("获取{Werk}人事范围数据异常:{error}", werk, await response.Content.ReadAsStringAsync());
|
||||
@@ -138,7 +124,7 @@ public class JinkoSapService : IJinkoSapService
|
||||
};
|
||||
|
||||
var content = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");
|
||||
var response = await GetHttpClient().PostAsync(apiUrl, content);
|
||||
var response = await _httpClientFactory.CreateClient("jinko:sap").PostAsync(apiUrl, content);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var jsonResponse = await response.Content.ReadAsStringAsync();
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Dlhis.Basic.Api\Dlhis.Basic.Api.csproj" />
|
||||
<ProjectReference Include="..\Dlhis.Entity\Dlhis.Entity.csproj" />
|
||||
<ProjectReference Include="..\Dlhis.Jip.Api\Dlhis.Jip.Api.csproj" />
|
||||
<ProjectReference Include="..\Dlhis.Sys.Api\Dlhis.Sys.Api.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -49,8 +49,8 @@ public class MealSupplementHandlerJob : BaseJob
|
||||
.Where(x => x.UniqueId == item.UniqueId)
|
||||
.ExecuteCommandAsync();
|
||||
|
||||
//后台任务获取人员
|
||||
BackgroundJob.Enqueue<IGainfoUpdateService>(x => x.TodoByCodeAsync(item.Code));
|
||||
//后台任务获取人员 todo
|
||||
//BackgroundJob.Enqueue<IGainfoUpdateService>(x => x.TodoByCodeAsync(item.Code));
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -17,14 +17,14 @@ public class SyncBusinessTripJob : BaseJob
|
||||
/// <inheritdoc />
|
||||
protected override async Task RunAsync(IServiceProvider serviceProvider)
|
||||
{
|
||||
var sapBusinessTripService = serviceProvider.GetService<ISapBusinessTripService>();
|
||||
|
||||
var identityDbContext = DbContext.ChangeDb("identity");
|
||||
var factories = await identityDbContext.Queryable<TenantEntity>().Where(x => !SqlFunc.IsNullOrEmpty(x.PCode)).ToListAsync();
|
||||
|
||||
foreach (var factory in factories)
|
||||
{
|
||||
await sapBusinessTripService.HandlerBusinessTripsByFactoryAsync(factory.Code);
|
||||
}
|
||||
// var sapBusinessTripService = serviceProvider.GetService<ISapBusinessTripService>();
|
||||
//
|
||||
// var identityDbContext = DbContext.ChangeDb("identity");
|
||||
// var factories = await identityDbContext.Queryable<TenantEntity>().Where(x => !SqlFunc.IsNullOrEmpty(x.PCode)).ToListAsync();
|
||||
//
|
||||
// foreach (var factory in factories)
|
||||
// {
|
||||
// await sapBusinessTripService.HandlerBusinessTripsByFactoryAsync(factory.Code);
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Dlhis.Jip.Api;
|
||||
using Dlhis.Jip.Api.Requests;
|
||||
using Dlhis.ScheduledTask.Attributes;
|
||||
using Dlhis.ScheduledTask.Common.Request;
|
||||
using Dlhis.ScheduledTask.Common.Services;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Dlhis.ScheduledTask.Jobs;
|
||||
@@ -14,11 +14,11 @@ namespace Dlhis.ScheduledTask.Jobs;
|
||||
[RecurringJob(nameof(SyncOriginCardInfoJob), "0 0/1 * * * ?", Name = "上传考勤记录")]
|
||||
public class SyncOriginCardInfoJob : BaseJob
|
||||
{
|
||||
private readonly IJinkoJipService _jinkoJIPService;
|
||||
private readonly IJinkoJipApi _jinkoJipApi;
|
||||
|
||||
public SyncOriginCardInfoJob(IJinkoJipService jinkoJIPService, IServiceProvider serviceProvider) : base(serviceProvider)
|
||||
public SyncOriginCardInfoJob(IJinkoJipApi jinkoJipApi, IServiceProvider serviceProvider) : base(serviceProvider)
|
||||
{
|
||||
_jinkoJIPService = jinkoJIPService;
|
||||
_jinkoJipApi = jinkoJipApi;
|
||||
}
|
||||
|
||||
protected override async Task RunAsync(IServiceProvider serviceProvider)
|
||||
@@ -34,7 +34,7 @@ public class SyncOriginCardInfoJob : BaseJob
|
||||
.Where(x => SqlFunc.Subqueryable<DeviceEntity>()
|
||||
.Where(p => p.UniqueNo == x.DeviceUniqueNo)
|
||||
.Where(p => p.Type == DeviceTypeEnumType.Attendance || (p.Type == DeviceTypeEnumType.Door && p.AsAttendance)).Any())
|
||||
.Select((x, device) => new UploadAttendanceRequest
|
||||
.Select((x, device) => new UploadAttendanceRequestItem
|
||||
{
|
||||
Id = x.Id,
|
||||
RaiseDateTime = x.RaiseDateTime,
|
||||
@@ -52,7 +52,7 @@ public class SyncOriginCardInfoJob : BaseJob
|
||||
try
|
||||
{
|
||||
var ids = items.Select(x => x.Id).ToList();
|
||||
var r = await _jinkoJIPService.UploadAttendancesAsync(items.ToList());
|
||||
var r = await _jinkoJipApi.UploadAttendancesAsync(new UploadAttendanceRequest { Data = items.ToList() });
|
||||
if (r.OLX == "0")
|
||||
{
|
||||
await DbContext.Updateable<DeviceUploadLogEntity>()
|
||||
|
||||
@@ -29,9 +29,10 @@ public class SyncPersonJob : BaseJob
|
||||
continue;
|
||||
}
|
||||
|
||||
var jobKey = BackgroundJob.Enqueue<IGainfoUpdateService>(x => x.TodoByWerkAsync(werk.Werk));
|
||||
werk.BackgroundJobKey = jobKey;
|
||||
await DbContext.UpdateAsync(werk);
|
||||
//todo
|
||||
// var jobKey = BackgroundJob.Enqueue<IGainfoUpdateService>(x => x.TodoByWerkAsync(werk.Werk));
|
||||
// werk.BackgroundJobKey = jobKey;
|
||||
// await DbContext.UpdateAsync(werk);
|
||||
|
||||
Logger.LogInformation("SAP创建人事范围{werk}后台调度任务", werk.Werk);
|
||||
}
|
||||
|
||||
@@ -6,14 +6,14 @@ namespace Dlhis.ScheduledTask.Packs;
|
||||
|
||||
public class JinkoSapHttpClientPack : BaseAppPack
|
||||
{
|
||||
|
||||
public override void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddHttpClient("jinko:sap", (sp, httpClient) =>
|
||||
services.AddHttpClient("jinko:sap", (_, httpClient) =>
|
||||
{
|
||||
httpClient.BaseAddress = new Uri($"http://sappipap01.jinkosolar.cn:50100");
|
||||
httpClient.Timeout = TimeSpan.FromMinutes(10);
|
||||
|
||||
var credentials = $"{"EHS_USER"}:{"y3R1hd2h*RICAC"}";
|
||||
const string credentials = "EHS_USER:y3R1hd2h*RICAC";
|
||||
var headerValue = Convert.ToBase64String(Encoding.UTF8.GetBytes(credentials));
|
||||
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", headerValue);
|
||||
});
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using Dlhis.ScheduledTask.Common.Services;
|
||||
using Kurisu.AspNetCore.Startup;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
|
||||
@@ -21,11 +20,4 @@ public class Startup : DefaultStartup
|
||||
base.ConfigureServices(services);
|
||||
services.AddRedis();
|
||||
}
|
||||
|
||||
public override void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
base.Configure(app, env);
|
||||
|
||||
var token = app.ApplicationServices.GetService<IJinkoJipService>().IssueToken();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user