feat 照片上传sap

This commit is contained in:
2024-07-17 16:48:30 +08:00
parent aeda215b38
commit a5a6c7a515
13 changed files with 160 additions and 87 deletions

View File

@@ -22,13 +22,4 @@ public interface IDevicePermissionApi
/// <returns></returns> /// <returns></returns>
[Post("/api/devicepermissions/re-permission")] [Post("/api/devicepermissions/re-permission")]
Task<DefaultApiResult<int>> RePermissionUsersInfoAsync(PermissionUsersInfoDto beforeDto); Task<DefaultApiResult<int>> RePermissionUsersInfoAsync(PermissionUsersInfoDto beforeDto);
/// <summary>
/// 任务生成
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Post("/api/devicepermissions/assignment-generate")]
Task<DefaultApiResult> GeneratePermissionsAsync(GeneratePermissionIdRequest request);
} }

View File

@@ -4,6 +4,8 @@ using Dlhis.Basic.Organization.Response;
using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Basic.Entity;
using Dlhis.Entity.Basic.Enums; using Dlhis.Entity.Basic.Enums;
using Dlhis.Entity.Device.Enums; using Dlhis.Entity.Device.Enums;
using Dlhis.Scheduled.Api;
using Dlhis.Scheduled.Api.Request;
using Kurisu.AspNetCore.Authentication.Abstractions; using Kurisu.AspNetCore.Authentication.Abstractions;
using Kurisu.AspNetCore.CustomClass; using Kurisu.AspNetCore.CustomClass;
using Kurisu.AspNetCore.DataAccess.Extensions; using Kurisu.AspNetCore.DataAccess.Extensions;
@@ -22,6 +24,7 @@ public class GainfoFaceService : IGainfoFaceService
private readonly ILogger<GainfoFaceService> _logger; private readonly ILogger<GainfoFaceService> _logger;
private readonly IConfiguration _configuration; private readonly IConfiguration _configuration;
private readonly ICurrentUser _currentUser; private readonly ICurrentUser _currentUser;
private readonly IHangfireApi _hangfireApi;
private readonly IDevicePermissionService _devicePermissionService; private readonly IDevicePermissionService _devicePermissionService;
private readonly IDataProtectionProvider _dataProtectionProvider; private readonly IDataProtectionProvider _dataProtectionProvider;
@@ -30,6 +33,7 @@ public class GainfoFaceService : IGainfoFaceService
ILogger<GainfoFaceService> logger, ILogger<GainfoFaceService> logger,
IConfiguration configuration, IConfiguration configuration,
ICurrentUser currentUser, ICurrentUser currentUser,
IHangfireApi hangfireApi,
IDevicePermissionService devicePermissionService, IDevicePermissionService devicePermissionService,
IDataProtectionProvider dataProtectionProvider) IDataProtectionProvider dataProtectionProvider)
{ {
@@ -39,6 +43,7 @@ public class GainfoFaceService : IGainfoFaceService
_logger = logger; _logger = logger;
_configuration = configuration; _configuration = configuration;
_currentUser = currentUser; _currentUser = currentUser;
_hangfireApi = hangfireApi;
_devicePermissionService = devicePermissionService; _devicePermissionService = devicePermissionService;
_dataProtectionProvider = dataProtectionProvider; _dataProtectionProvider = dataProtectionProvider;
} }
@@ -216,9 +221,21 @@ public class GainfoFaceService : IGainfoFaceService
await _faceDbContext.UpdateAsync(face); await _faceDbContext.UpdateAsync(face);
} }
var prefix = gainfo.Factory == "501" ? "jschuneng" : "jingke"; try
var url = $"https://pay.aizhuhotel.com/{prefix}/api/face"; {
await _hangfireApi.SyncFaceToSapAsync(new FaceUploadToSapRequest
{
UserCode = face.UserCode,
Base64 = face.Face
});
}
catch (Exception e)
{
_logger.LogError(e, "上传face数据到sap失败:{message}", e.Message);
}
// var prefix = gainfo.Factory == "501" ? "jschuneng" : "jingke";
// var url = $"https://pay.aizhuhotel.com/{prefix}/api/face";
//生成任务 //生成任务
await _devicePermissionService.GenerateDeviceTasksAsync(gainfo.No, taskType); await _devicePermissionService.GenerateDeviceTasksAsync(gainfo.No, taskType);

View File

@@ -0,0 +1,14 @@
using Kurisu.AspNetCore.DataAccess.SqlSugar;
using SqlSugar;
namespace Dlhis.Entity.Sap;
[SugarTable(TableName = "SapDataSync")]
public class SapDataSyncEntity : SugarBaseEntity
{
public string Key { get; set; }
public string Type { get; set; }
public bool IsSync { get; set; }
}

View File

@@ -16,7 +16,8 @@ public interface IHangfireApi
[Post("api/hangfire/sap/person/no")] [Post("api/hangfire/sap/person/no")]
Task<DefaultApiResult> SyncSapPersonAsync(SapNoRequest request); Task<DefaultApiResult> SyncSapPersonAsync(SapNoRequest request);
[Auth]
[Post("api/hangfire/assignment-generate")]
Task<DefaultApiResult> GeneratePermissionsAsync(GeneratePermissionIdRequest request); [Post("api/hangfire/sap/face")]
Task<DefaultApiResult> SyncFaceToSapAsync(FaceUploadToSapRequest request);
} }

View File

@@ -0,0 +1,7 @@
namespace Dlhis.Scheduled.Api.Request;
public class FaceUploadToSapRequest
{
public string UserCode { get; set; }
public string Base64 { get; set; }
}

View File

@@ -0,0 +1,11 @@
namespace Dlhis.ScheduledTask.Common.Response;
public class SapFaceSyncResponse
{
/// <summary>
/// S 成功
/// </summary>
public string OLX { get; set; }
public string OMS { get; set; }
}

View File

@@ -1,5 +1,6 @@
using Dlhis.Basic.Api.Request; using Dlhis.Basic.Api.Request;
using Dlhis.ScheduledTask.Common.Request; using Dlhis.ScheduledTask.Common.Request;
using Dlhis.ScheduledTask.TaskAssignment.Request;
namespace Dlhis.ScheduledTask.Common.Services; namespace Dlhis.ScheduledTask.Common.Services;
@@ -23,5 +24,5 @@ public interface IHangfireService : IScopeDependency
Task CreateSapWerkSyncBackgroundJobAsync(SapNoRequest request); Task CreateSapWerkSyncBackgroundJobAsync(SapNoRequest request);
void GeneratePermissions(GeneratePermissionIdRequest request); Task FaceUploadToSapAsync(FaceUploadToSapRequest request);
} }

View File

@@ -19,8 +19,18 @@ public interface IJinkoJIPService : ISingletonDependency
/// <returns></returns> /// <returns></returns>
Task<SapBusinessTripInfoResponse> GetTravelInfosByDepartmentsAsync(DateTime begin, DateTime end, List<string> departmentNos); Task<SapBusinessTripInfoResponse> GetTravelInfosByDepartmentsAsync(DateTime begin, DateTime end, List<string> departmentNos);
/// <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<SapBusinessTripInfoResponse> GetTravelInfosByUserCodeAsync(DateTime begin, DateTime end, string userCode);
Task<SapFaceSyncResponse> SyncFaceToSapAsync(string userCode, string base64);
string IssueToken(); string IssueToken();
} }

View File

@@ -1,7 +1,6 @@
using Dlhis.Basic.Api; using Dlhis.Entity.Basic.Entity;
using Dlhis.Basic.Api.Request;
using Dlhis.Entity.Basic.Entity;
using Dlhis.ScheduledTask.Common.Request; using Dlhis.ScheduledTask.Common.Request;
using Dlhis.ScheduledTask.TaskAssignment.Request;
using Hangfire; using Hangfire;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services; using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
using Kurisu.AspNetCore.Utils; using Kurisu.AspNetCore.Utils;
@@ -13,11 +12,13 @@ public class HangfireService : IHangfireService
{ {
private readonly RedisCache _redisCache; private readonly RedisCache _redisCache;
private readonly IDbContext _dbContext; private readonly IDbContext _dbContext;
private readonly IJinkoJIPService _jinkoJipService;
public HangfireService(RedisCache redisCache, IDbContext dbContext) public HangfireService(RedisCache redisCache, IDbContext dbContext, IJinkoJIPService jinkoJipService)
{ {
_redisCache = redisCache; _redisCache = redisCache;
_dbContext = dbContext; _dbContext = dbContext;
_jinkoJipService = jinkoJipService;
} }
public async Task CreateSapPersonSyncBackgroundJobAsync(SapNoRequest request) public async Task CreateSapPersonSyncBackgroundJobAsync(SapNoRequest request)
@@ -47,9 +48,8 @@ public class HangfireService : IHangfireService
} }
} }
/// <inheritdoc /> public async Task FaceUploadToSapAsync(FaceUploadToSapRequest request)
public void GeneratePermissions(GeneratePermissionIdRequest request)
{ {
BackgroundJob.Enqueue<IDevicePermissionApi>(x => x.GeneratePermissionsAsync(request)); await _jinkoJipService.SyncFaceToSapAsync(request.UserCode, request.Base64);
} }
} }

View File

@@ -158,6 +158,25 @@ public class JinkoJIPService : IJinkoJIPService
return jsonResponse.ToObject<SapBusinessTripInfoResponse>(); 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() public string IssueToken()
{ {

View File

@@ -0,0 +1,51 @@
using Dlhis.Entity.Basic.Entity;
using Dlhis.Entity.Sap;
using Dlhis.ScheduledTask.Attributes;
using Dlhis.ScheduledTask.Common.Services;
namespace Dlhis.ScheduledTask.Jobs;
[RecurringJob(nameof(SyncFaceJob), "0 0/15 * * * ?", Name = "face数据同步sap")]
public class SyncFaceJob : BaseJob
{
private readonly IJinkoJIPService _jinkoJipService;
/// <inheritdoc />
public SyncFaceJob(IServiceProvider serviceProvider, IJinkoJIPService jinkoJipService) : base(serviceProvider)
{
_jinkoJipService = jinkoJipService;
}
/// <inheritdoc />
protected override async Task RunAsync(IServiceProvider serviceProvider)
{
var faceDbContext = DbContext.ChangeDb("face");
var existsData = await DbContext.Queryable<SapDataSyncEntity>().Where(x => x.IsSync).Select(x => x.Key).ToListAsync();
var userFaces = await faceDbContext.Queryable<GainfoFaceEntity>()
.Where(x => !existsData.Contains(x.UserCode))
.ToPageListAsync(1, 5000);
foreach (var data in userFaces)
{
try
{
var response = await _jinkoJipService.SyncFaceToSapAsync(data.UserCode, data.Face);
if (response.OLX == "S")
{
await DbContext.InsertAsync(new SapDataSyncEntity
{
Key = data.UserCode,
Type = "Face",
IsSync = true
});
}
}
catch (Exception e)
{
Logger.LogError(e, "上传face数据失败:{message}", e.Message);
}
}
}
}

View File

@@ -1,14 +1,9 @@
using Dlhis.Basic.Api.Request; using Dlhis.ScheduledTask.Common.Request;
using Dlhis.Entity.Basic.Entity;
using Dlhis.Entity.Canteen.Entities;
using Dlhis.Entity.Canteen.Enums;
using Dlhis.ScheduledTask.Common.Request;
using Dlhis.ScheduledTask.Common.Services; using Dlhis.ScheduledTask.Common.Services;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop; using Dlhis.ScheduledTask.TaskAssignment.Request;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services; using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using SqlSugar;
namespace Dlhis.ScheduledTask.TaskAssignment.Controllers; namespace Dlhis.ScheduledTask.TaskAssignment.Controllers;
@@ -52,61 +47,10 @@ public class HangfireController : ControllerBase
await _hangfireService.CreateSapWerkSyncBackgroundJobAsync(request); await _hangfireService.CreateSapWerkSyncBackgroundJobAsync(request);
} }
[AllowAnonymous]
[HttpPost("assignment-generate")] [HttpPost("sap/face")]
public void GeneratePermissionsAsync(GeneratePermissionIdRequest request) public async Task FaceUploadToSapAsync(FaceUploadToSapRequest request)
{ {
_hangfireService.GeneratePermissions(request); await _hangfireService.FaceUploadToSapAsync(request);
}
[IgnoreTenant]
[HttpPost("recalc")]
public async Task ReCalc()
{
// select UserCode,Remark, count(1) count from balancerecord
// where Status = 'Valid'
// and TenantId !='1201'
// and IsDeleted = false
// group by UserCode,Remark
// having ifnull(Remark,'')!='' and count > 1 and Remark !='用户取消' and Remark !='正常发放';
var ls = await _dbContext.Queryable<BalanceRecordEntity>().Where(x => x.Status == BalanceRecordStatusEnumType.Valid)
.Select(x => new { x.UserCode, x.Remark, count = SqlFunc.AggregateCount(x.Id) })
.GroupBy(x => new { x.UserCode, x.Remark })
.Having(x => SqlFunc.IsNull(x.Remark, "") != "" && SqlFunc.AggregateCount(1) > 1 && x.Remark != "用户取消" && x.Remark != "正常发放")
.ToListAsync();
foreach (var row in ls)
{
var data = await _dbContext.Queryable<BalanceRecordEntity>()
.Where(x => x.UserCode == row.UserCode)
.Where(x => x.ApplicationType == CanteenApplicationTypeEnumType.MealSupplement)
.Where(x => x.Remark == row.Remark)
.ToListAsync();
if (data.Count <= 1)
{
continue;
}
var f = data.First();
var others = data.Where(x => x.Id != f.Id).ToList();
others.ForEach(x => x.Status = BalanceRecordStatusEnumType.Obsolute);
await _dbContext.UpdateAsync(others);
var sum = await _dbContext.Queryable<BalanceRecordEntity>().Where(x => x.UserCode == f.UserCode)
.Where(x => x.Status == BalanceRecordStatusEnumType.Valid)
.SumAsync(x => x.Amount);
var mealInfo = await _dbContext.Queryable<GainfoMealEntity>().Where(x => x.UserCode == f.UserCode).SingleAsync();
await _dbContext.Updateable<GainfoMealEntity>()
.SetColumns(x => x.Balance == sum)
.SetColumns(x => x.Version == x.Version + 1)
.SetColumns(x => x.ModifiedTime == DateTime.Now)
.Where(x => x.UserCode == f.UserCode && x.Version == mealInfo.Version)
.ExecuteCommandAsync();
}
} }
} }

View File

@@ -0,0 +1,7 @@
namespace Dlhis.ScheduledTask.TaskAssignment.Request;
public class FaceUploadToSapRequest
{
public string UserCode { get; set; }
public string Base64 { get; set; }
}