fix 人事范围同步控制,餐补消费离职人员处理

This commit is contained in:
2024-04-07 14:58:29 +08:00
parent b9977df4eb
commit babf8a838b
13 changed files with 144 additions and 57 deletions

View File

@@ -1,4 +1,7 @@
namespace Dlhis.Basic.Organization.Response;
using Kurisu.AspNetCore.Utils.Extensions;
using Newtonsoft.Json;
namespace Dlhis.Basic.Organization.Response;
public class WerkPageResponse
{
@@ -43,4 +46,13 @@ public class WerkPageResponse
/// 处理消息
/// </summary>
public string HandleMessage { get; set; }
[JsonIgnore]
public string BackgroundJobKey { get; set; }
/// <summary>
/// 是否允许同步
/// </summary>
public bool AbleSync => BackgroundJobKey.IsEmpty();
}

View File

@@ -22,8 +22,10 @@ namespace Dlhis.Canteen.Order.Services.Implements;
public class OrderService : BaseOrderService, IOrderService
{
public OrderService(ICanteenSettingService canteenSettingService, IDbContext dbContext,
ICurrentUser currentUser, IDevicePermissionApi devicePermissionApi,
public OrderService(ICanteenSettingService canteenSettingService,
IDbContext dbContext,
ICurrentUser currentUser,
IDevicePermissionApi devicePermissionApi,
ILogger<OrderService> logger)
: base(canteenSettingService, dbContext, currentUser, devicePermissionApi, logger)
{

View File

@@ -170,8 +170,21 @@ public class GainfoEntity : SugarBaseEntity
/// <summary>
/// 成本中心
/// </summary>
[SugarColumn(ColumnDescription = "成本中心")]
public string CostId { get; set; }
/// <summary>
/// 入职日期
/// </summary>
[SugarColumn(IsNullable = true, ColumnDescription = "入职日期", ColumnDataType = "date")]
public DateTime? EntryDate { get; set; }
/// <summary>
/// 离职日期
/// </summary>
[SugarColumn(IsNullable = true, ColumnDescription = "离职日期", ColumnDataType = "date")]
public DateTime? ResignationDate { get; set; }
/// <summary>
/// 身份认证用户Id(如果为空匹配code)
/// </summary>

View File

@@ -63,6 +63,10 @@ public class GainfoSapEntity
public string mkt { get; set; }
public string src { get; set; }
public string isowner { get; set; }
/// <summary>
/// 入职日期
/// </summary>
public DateTime createdate { get; set; }
public string PERNR { get; set; }
@@ -81,6 +85,9 @@ public class GainfoSapEntity
public string STELL_NM { get; set; }
/// <summary>
/// 离职日期
/// </summary>
public DateTime? ZLZRQ { get; set; }
public string MASSN { get; set; }

View File

@@ -14,12 +14,11 @@ public enum MealSupplementStatusEnumtype
[Description("待核算")]
Wait = 0,
/// <summary>
/// 成功
/// </summary>
[Description("成功")]
Sucess = 1,
Success = 1,
/// <summary>
/// 处理异常

View File

@@ -38,6 +38,7 @@ public class MealSupplementRecordEntity : MealSupplementRequestRecordEntity
/// <summary>
/// 状态同步
/// </summary>
[SugarColumn(ColumnDataType = "bit")]
public bool Sync { get; set; }
}

View File

@@ -1,10 +0,0 @@
using System.ComponentModel.DataAnnotations;
namespace Dlhis.ScheduledTask.Common.Dto;
public class SapPersonNoRequest
{
[Required]
public string Code { get; set; }
}

View File

@@ -0,0 +1,12 @@
using System.ComponentModel.DataAnnotations;
namespace Dlhis.ScheduledTask.Common.Request;
public class SapNoRequest
{
/// <summary>
/// Code
/// </summary>
[Required(ErrorMessage = "编号不能为空")]
public string Code { get; set; }
}

View File

@@ -1,4 +1,4 @@
using Dlhis.ScheduledTask.Common.Dto;
using Dlhis.ScheduledTask.Common.Request;
namespace Dlhis.ScheduledTask.Common.Services;
@@ -12,5 +12,12 @@ public interface IHangfireService : ISingletonDependency
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
Task CreateSapPersonSyncBackgroundJobAsync(SapPersonNoRequest request);
Task CreateSapPersonSyncBackgroundJobAsync(SapNoRequest request);
/// <summary>
/// 创建sap人事范围同步后台任务
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
Task CreateSapWerkSyncBackgroundJobAsync(SapNoRequest request);
}

View File

@@ -8,7 +8,6 @@ using Dlhis.Sys.Api.Response;
using Dlhis.ScheduledTask.Common.Dto;
using Dlhis.ScheduledTask.Common.Comparers;
using Kurisu.AspNetCore.Utils.Extensions;
using Dlhis.ScheduledTask.Common.Response;
using Dlhis.Basic.Api.Dtos;
namespace Dlhis.ScheduledTask.Common.Services.Implements;
@@ -247,7 +246,7 @@ public class GainfoUpdateService : IGainfoUpdateService
IdNo = item.idno,
Native = item.native,
Gender = item.sex == "F" ? GenderEnumType.Female : GenderEnumType.Male,
Birthday = (DateTime)item.birthday,
Birthday = item.birthday,
Address = item.address,
DepartmentNo = item.appellation,
Nation = item.nation,
@@ -259,6 +258,8 @@ public class GainfoUpdateService : IGainfoUpdateService
Remark = item.remark,
Werks = item.WERKS,
CostId = item.KOSTL,
EntryDate = item.createdate,
ResignationDate = item.ZLZRQ,
Workplace = _tenants.FirstOrDefault(x => x.Name == item.ZZ_GZDJDNM)?.Code ?? item.ZZ_GZDJDNM,
Factory = _tenants.FirstOrDefault(x => x.Name == item.ZZ_GZDCQNM)?.Code ?? item.ZZ_GZDCQNM,
};
@@ -296,6 +297,7 @@ public class GainfoUpdateService : IGainfoUpdateService
.Where(x => x.ename == item.ename)
.ExecuteCommandAsync();
//获取当前在职人员
var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.Code == item.ename).FirstAsync();
if (item.isowner == "T")
{
@@ -316,6 +318,8 @@ public class GainfoUpdateService : IGainfoUpdateService
Degree = item.email,
Werks = item.WERKS,
CostId = item.KOSTL,
EntryDate = item.createdate,
ResignationDate = item.ZLZRQ,
Workplace = workplace,
Factory = factory
})
@@ -332,9 +336,13 @@ public class GainfoUpdateService : IGainfoUpdateService
{
if (gainfo != null)
{
await _dbContext.DeleteReallyAsync(gainfo);
//先写入离职表
gainfo.IdentityUserId = (int)gainfo.Id;
gainfo.Id = 0;
gainfo.ResignationDate = item.ZLZRQ;
await _dbContext.Client.Insertable(gainfo).AS("GainfoLeave").ExecuteCommandAsync();
await _dbContext.DeleteReallyAsync(gainfo);
}
}

View File

@@ -1,21 +1,26 @@
using Dlhis.ScheduledTask.Common.Dto;
using Dlhis.Entity.Basic.Entity;
using Dlhis.ScheduledTask.Common.Request;
using Hangfire;
using Kurisu.AspNetCore.Utils;
using Kurisu.AspNetCore.Utils.Extensions;
using Kurisu.SqlSugar.Services;
namespace Dlhis.ScheduledTask.Common.Services.Implements;
public class HangfireService : IHangfireService
{
private readonly RedisCache _redisCache;
private readonly IDbContext _dbContext;
public HangfireService(RedisCache redisCache)
public HangfireService(RedisCache redisCache, IDbContext dbContext)
{
_redisCache = redisCache;
_dbContext = dbContext;
}
public async Task CreateSapPersonSyncBackgroundJobAsync(SapPersonNoRequest request)
public async Task CreateSapPersonSyncBackgroundJobAsync(SapNoRequest request)
{
var jobKey = $"hangfire:background:{request.Code}";
var jobKey = $"hangfire:background:person:{request.Code}";
using var handler = await _redisCache.LockAsync(jobKey);
if (handler.Acquired)
@@ -23,4 +28,20 @@ public class HangfireService : IHangfireService
BackgroundJob.Enqueue<IGainfoUpdateService>(x => x.TodoByCodeAsync(request.Code));
}
}
public async Task CreateSapWerkSyncBackgroundJobAsync(SapNoRequest request)
{
var jobKey = $"hangfire:background:werk:{request.Code}";
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));
}
}
}

View File

@@ -11,7 +11,7 @@ using Kurisu.AspNetCore.Utils;
using Kurisu.AspNetCore.Utils.Extensions;
using Kurisu.Scheduled;
using Kurisu.Scheduled.Attributes;
using SqlSugar;
using Kurisu.SqlSugar.Extensions;
namespace Dlhis.ScheduledTask.Jobs;
@@ -36,7 +36,8 @@ public class MealSupplementHandlerJob : BaseJob
{
//查询待处理餐补
var mealSupplements = await DbContext.Queryable<MealSupplementRecordEntity>()
.Where(x => (x.Status == MealSupplementStatusEnumtype.Wait || x.Status == MealSupplementStatusEnumtype.Error) && !x.Sync)
.Where(x => x.Status == MealSupplementStatusEnumtype.Wait || x.Status == MealSupplementStatusEnumtype.Error)
.Where(x => !x.Sync)
.ToListAsync();
foreach (var item in mealSupplements)
@@ -46,27 +47,32 @@ public class MealSupplementHandlerJob : BaseJob
//档案不存在
if (gainfo == null)
{
if (await DbContext.Queryable<GainfoEntity>().AS("GainfoLeave").Where(x => x.Code == item.Code).AnyAsync())
gainfo = await DbContext.Queryable<GainfoEntity>().AS("GainfoLeave").Where(x => x.Code == item.Code).SingleAsync();
if (gainfo != null)
{
try
{
var r = await _jinkoJIPService.SyncMealSupplementRecordsAsync(new List<SyncMealSupplementRecordRequest>
//离职数据
if (gainfo.ResignationDate < item.Date)
{
new()
var r = await _jinkoJIPService.SyncMealSupplementRecordsAsync(new List<SyncMealSupplementRecordRequest>
{
UniqueId = item.UniqueId,
Status = "FAIL",
Msg = "人员离职"
}
});
new()
{
UniqueId = item.UniqueId,
Status = "FAIL",
Msg = "人员离职"
}
});
await DbContext.Updateable<MealSupplementRecordEntity>()
.SetColumns(x => x.Result == r)
.SetColumns(x => x.Status == MealSupplementStatusEnumtype.Sucess)
.SetColumns(x => x.Sync == true)
.SetColumns(x => x.ModifiedTime == DateTime.Now)
.Where(x => x.UniqueId == item.UniqueId)
.ExecuteCommandAsync();
await DbContext.Updateable<MealSupplementRecordEntity>()
.SetColumns(x => x.Result == r)
.SetColumns(x => x.Status == MealSupplementStatusEnumtype.Success)
.SetColumns(x => x.Sync == true)
.SetColumns(x => x.ModifiedTime == DateTime.Now)
.Where(x => x.UniqueId == item.UniqueId)
.ExecuteCommandAsync();
}
}
catch
{
@@ -131,16 +137,12 @@ public class MealSupplementHandlerJob : BaseJob
var mealUser = await DbContext.Queryable<GainfoMealEntity>().Where(x => x.UserCode == mealSupplement.Code).FirstAsync();
var b = mealUser.Balance += mealSupplement.Amount;
var effect = await DbContext.Updateable<GainfoMealEntity>()
.SetColumns(x => x.Balance == b)
.SetColumns(x => x.ModifiedTime == DateTime.Now)
.Where(x => x.UserCode == mealUser.UserCode && x.Version == mealUser.Version)
.ExecuteCommandAsync();
await DbContext.Updateable<GainfoMealEntity>()
.SetColumns(x => x.Balance == b)
.SetColumns(x => x.ModifiedTime == DateTime.Now)
.Where(x => x.UserCode == mealUser.UserCode && x.Version == mealUser.Version)
.ExecuteCommandThrowVersionAsync();
if (effect <= 0)
{
throw new VersionExceptions("餐补写入错误");
}
}, 5);
var r = await _jinkoJIPService.SyncMealSupplementRecordsAsync(new List<SyncMealSupplementRecordRequest>
@@ -156,7 +158,7 @@ public class MealSupplementHandlerJob : BaseJob
//更新餐补信息为成功(同步成功)
await DbContext.Updateable<MealSupplementRecordEntity>()
.SetColumns(x => x.Result == r)
.SetColumns(x => x.Status == MealSupplementStatusEnumtype.Sucess)
.SetColumns(x => x.Status == MealSupplementStatusEnumtype.Success)
.SetColumns(x => x.Sync == true)
.SetColumns(x => x.ModifiedTime == DateTime.Now)
.Where(x => x.UniqueId == mealSupplement.UniqueId)
@@ -165,7 +167,7 @@ public class MealSupplementHandlerJob : BaseJob
await DbContext.InsertAsync(new BalanceRecordEntity
{
Amount = mealSupplement.Amount,
//ApplicationType = CanteenApplicaitonTypeEnumType.
ApplicationType = CanteenApplicaitonTypeEnumType.MealSupplement,
Type = BalanceRecordTypeEnumType.In,
BusinessPlaceCode = null,
BusinessShiftCode = null,
@@ -178,13 +180,12 @@ public class MealSupplementHandlerJob : BaseJob
TenantId = mealSupplement.Factory,
Status = BalanceRecordStatusEnumType.Valid,
Source = BalanceRecordSourceEnumType.LocalTenantSubsidies,
Remark = gainfo.Remark,
Remark = mealSupplement.UniqueId + ":" + mealSupplement.Remark,
CostId = gainfo.CostId,
SubsidiesFromMonth = mealSupplement.Date.ToString("yyyyMM"),
OriginTenantId = gainfo.Factory,
Name = gainfo.Name,
IsCostCrossTenant = false,
ApplicationType = CanteenApplicaitonTypeEnumType.MealSupplement,
DepartmentNo = gainfo.DepartmentNo,
DeviceUniqueNo = null,
@@ -240,7 +241,7 @@ public class MealSupplementHandlerJob : BaseJob
//更新餐补信息为成功(同步成功)
await DbContext.Updateable<MealSupplementRecordEntity>()
.SetColumns(x => x.Result == r)
.SetColumns(x => x.Status == MealSupplementStatusEnumtype.Sucess)
.SetColumns(x => x.Status == MealSupplementStatusEnumtype.Success)
.SetColumns(x => x.Sync == true)
.SetColumns(x => x.ModifiedTime == DateTime.Now)
.Where(x => x.UniqueId == mealSupplement.UniqueId)

View File

@@ -1,10 +1,13 @@
using Dlhis.ScheduledTask.Common.Dto;
using Dlhis.ScheduledTask.Common.Request;
using Dlhis.ScheduledTask.Common.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Dlhis.ScheduledTask.TaskAssignment.Controllers;
/// <summary>
/// 调度任务
/// </summary>
[Authorize(Roles = "admin")]
[Route("api/[controller]")]
[ApiController]
@@ -23,7 +26,18 @@ public class HangfireController : ControllerBase
/// <param name="request"></param>
/// <returns></returns>
[HttpPost("sap/person/no")]
public async Task ManuallySync(SapPersonNoRequest request)
public async Task PersonManuallySync(SapNoRequest request)
{
await _hangfireService.CreateSapPersonSyncBackgroundJobAsync(request);
}
/// <summary>
/// 手动启动人事范围同步
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpPost("sap/werk/no")]
public async Task WerkManuallySync(SapNoRequest request)
{
await _hangfireService.CreateSapPersonSyncBackgroundJobAsync(request);
}