fix 餐补处理
This commit is contained in:
@@ -12,6 +12,11 @@ public class DishesMenusBookingSettingResponse
|
||||
/// </summary>
|
||||
public DateTime Deadline { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 允许发起订餐
|
||||
/// </summary>
|
||||
public bool AbleBooking => Deadline > ServerTime;
|
||||
|
||||
/// <summary>
|
||||
/// 支付方式
|
||||
/// </summary>
|
||||
|
||||
@@ -752,14 +752,6 @@ public class BalanceService : IBalanceService
|
||||
.Select<BalanceRecordByUserResponse>()
|
||||
.ToPageListAsync(request);
|
||||
|
||||
page.Data.Add(new BalanceRecordByUserResponse
|
||||
{
|
||||
Amount = 20,
|
||||
CostDateTime = DateTime.Now.Date,
|
||||
Remark = "2024-03-21 餐补",
|
||||
No = "129876578"
|
||||
});
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
using Dlhis.Entity.Common;
|
||||
using Kurisu.SqlSugar.Services;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Dlhis.ScheduledTask.CommonJobs;
|
||||
|
||||
public class DelApiLogTaskJob
|
||||
public class DelApiLogTaskJob
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly Logger<DelApiLogTaskJob> _logger;
|
||||
@@ -19,32 +18,13 @@ namespace Dlhis.ScheduledTask.CommonJobs;
|
||||
{
|
||||
try
|
||||
{
|
||||
DateTime now = DateTime.Now;
|
||||
DateTime todayStart = now.Date;
|
||||
DateTime threeDaysAgoStart = todayStart.AddDays(-7);
|
||||
|
||||
var logs = await _dbContext.ChangeDb("log")
|
||||
.Queryable<ApiLogEntity>()
|
||||
.Where(x => x._ts >= threeDaysAgoStart && x._ts <= now)
|
||||
.Select(x => x.Id)
|
||||
.ToListAsync();
|
||||
|
||||
var lst = new List<ApiLogEntity>();
|
||||
foreach (var id in logs)
|
||||
{
|
||||
var entity = new ApiLogEntity
|
||||
{
|
||||
Id = id,
|
||||
};
|
||||
lst.Add(entity);
|
||||
}
|
||||
await _dbContext.ChangeDb("log").DeleteReallyAsync(lst);
|
||||
DateTime before = DateTime.Now.Date.AddDays(-7);
|
||||
await _dbContext.ChangeDb("log").Client.Deleteable<ApiLogEntity>().Where(x => x._ts <= before).ExecuteCommandAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "删除日志异常:{message}", ex.Message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
143
Src/Dlhis.ScheduledTask/CommonJobs/MealSupplementHandlerJob.cs
Normal file
143
Src/Dlhis.ScheduledTask/CommonJobs/MealSupplementHandlerJob.cs
Normal file
@@ -0,0 +1,143 @@
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Basic.Enums;
|
||||
using Dlhis.Entity.Canteen.Entities;
|
||||
using Dlhis.ScheduledTask.SyncSapInfo;
|
||||
using Dlhis.ScheduledTask.SyncSapInfo.Services;
|
||||
using Kurisu.AspNetCore.UnifyResultAndValidation;
|
||||
using Kurisu.Core.DataAccess.Entity;
|
||||
using Kurisu.SqlSugar.Services;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Dlhis.ScheduledTask.CommonJobs;
|
||||
|
||||
public class MealSupplementHandlerJob
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly ILogger<MealSupplementHandlerJob> _logger;
|
||||
private readonly IJinkoJIPService _jinkoJIPService;
|
||||
|
||||
public MealSupplementHandlerJob(IDbContext dbContext, ILogger<MealSupplementHandlerJob> logger, IJinkoJIPService jinkoJIPService)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_logger = logger;
|
||||
_jinkoJIPService = jinkoJIPService;
|
||||
}
|
||||
|
||||
public async Task RunAsync()
|
||||
{
|
||||
_dbContext.Client.QueryFilter.ClearAndBackup<ITenantId>();
|
||||
try
|
||||
{
|
||||
//查询待处理餐补
|
||||
var mealSupplements = await _dbContext.Queryable<MealSupplementRecordEntity>()
|
||||
.Where(x => (x.Status == MealSupplementStatusEnumtype.Wait || x.Status == MealSupplementStatusEnumtype.Error) && !x.Sync)
|
||||
.ToListAsync();
|
||||
|
||||
foreach (var item in mealSupplements)
|
||||
{
|
||||
GainfoMealEntity mealUser = null;
|
||||
var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.Code == item.Code).SingleAsync();
|
||||
//档案不存在
|
||||
if (gainfo == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
mealUser = await _dbContext.Queryable<GainfoMealEntity>().Where(x => x.UserNo == gainfo.No).SingleAsync();
|
||||
if (mealUser == null)
|
||||
{
|
||||
mealUser = new GainfoMealEntity
|
||||
{
|
||||
Balance = 0,
|
||||
BalanceOfRecharge = 0,
|
||||
BalanceOfSubsidies = 0,
|
||||
UserNo = gainfo.No,
|
||||
UserCode = gainfo.Code,
|
||||
Version = 0,
|
||||
TenantId = gainfo.Factory,
|
||||
};
|
||||
|
||||
await _dbContext.InsertAsync(mealUser);
|
||||
}
|
||||
}
|
||||
|
||||
await SetMealSupplementAsync(mealUser, item);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_dbContext.Client.QueryFilter.Restore();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SetMealSupplementAsync(GainfoMealEntity mealUser, MealSupplementRecordEntity mealSupplement)
|
||||
{
|
||||
await _dbContext.Client.Ado.BeginTranAsync();
|
||||
try
|
||||
{
|
||||
await ContinueUpdateAsync(async () =>
|
||||
{
|
||||
mealUser = await _dbContext.Queryable<GainfoMealEntity>().Where(x => x.UserCode == mealUser.UserCode).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.Id == mealUser.Id && x.Version == mealUser.Version)
|
||||
.ExecuteCommandAsync();
|
||||
|
||||
if (effect <= 0)
|
||||
{
|
||||
throw new VersionExceptions("餐补写入错误");
|
||||
}
|
||||
|
||||
}, 5);
|
||||
|
||||
mealSupplement.Status = MealSupplementStatusEnumtype.Sucess;
|
||||
mealSupplement.Sync = true;
|
||||
await _dbContext.UpdateAsync(mealSupplement);
|
||||
|
||||
//FAIL SUCCESS
|
||||
await _jinkoJIPService.SyncMealSupplementRecordsAsync(new List<SyncMealSupplementRecordRequest>
|
||||
{
|
||||
new()
|
||||
{
|
||||
UniqueId = mealSupplement.UniqueId,
|
||||
Status = "SUCCESS",
|
||||
Msg = "操作成功"
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
mealSupplement.Status = MealSupplementStatusEnumtype.Error;
|
||||
mealSupplement.Result = ex.Message;
|
||||
await _dbContext.UpdateAsync(mealSupplement);
|
||||
|
||||
await _dbContext.Client.Ado.RollbackTranAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ContinueUpdateAsync(Func<Task> func, int retry, string errorMessage = null)
|
||||
{
|
||||
for (int i = 0; i < retry; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
await func();
|
||||
return;
|
||||
}
|
||||
catch (Exception ex) when (ex is VersionExceptions)
|
||||
{
|
||||
_logger.LogWarning(ex, ex.Message);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
throw new UserFriendlyException(errorMessage ?? "操作失败,请重试");
|
||||
}
|
||||
}
|
||||
@@ -64,10 +64,17 @@ public class JobPack : BaseAppPack
|
||||
{
|
||||
TimeZone = TimeZoneInfo.Local
|
||||
});
|
||||
|
||||
//删除前三天前的日志
|
||||
RecurringJob.AddOrUpdate<DelApiLogTaskJob>("DelApiLogTask", s => s.RunAsync(), "0 0 */7 * *", new RecurringJobOptions
|
||||
{
|
||||
TimeZone = TimeZoneInfo.Local
|
||||
});
|
||||
|
||||
//处理餐补
|
||||
RecurringJob.AddOrUpdate<MealSupplementHandlerJob>("MealSupplementHandler", s => s.RunAsync(), "0/60 * * * * ?", new RecurringJobOptions
|
||||
{
|
||||
TimeZone = TimeZoneInfo.Local
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
using Dlhis.ScheduledTask.SyncSapInfo.Response;
|
||||
|
||||
namespace Dlhis.ScheduledTask.SyncSapInfo.Services
|
||||
namespace Dlhis.ScheduledTask.SyncSapInfo.Services;
|
||||
|
||||
public interface IJinkoJIPService : ISingletonDependency
|
||||
{
|
||||
public interface IJinkoJIPService : ISingletonDependency
|
||||
{
|
||||
Task<UploadAttendanceResponse> UploadAttendancesAsync(List<UploadAttendanceRequest> requests);
|
||||
}
|
||||
|
||||
Task SyncMealSupplementRecordsAsync(List<SyncMealSupplementRecordRequest> requests);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Text;
|
||||
using Dlhis.ScheduledTask.SyncSapInfo.Response;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Dlhis.ScheduledTask.SyncSapInfo.Services.Implements;
|
||||
|
||||
@@ -35,6 +36,8 @@ public class JinkoJIPService : IJinkoJIPService
|
||||
|
||||
public async Task<UploadAttendanceResponse> UploadAttendancesAsync(List<UploadAttendanceRequest> requests)
|
||||
{
|
||||
var requestUrl = "/JIP/HCM/HCM_SWIPE_DATA_SAVE";
|
||||
|
||||
var body = new
|
||||
{
|
||||
T_DATA = requests,
|
||||
@@ -45,7 +48,7 @@ public class JinkoJIPService : IJinkoJIPService
|
||||
//_logger.LogInformation("上传考勤记录请求:{json}", json);
|
||||
|
||||
var content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
var response = await GetHttpClient().PostAsync("/JIP/HCM/HCM_SWIPE_DATA_SAVE", content);
|
||||
var response = await GetHttpClient().PostAsync(requestUrl, content);
|
||||
var responseJson = await response.Content.ReadAsStringAsync();
|
||||
|
||||
_logger.LogInformation("上传考勤记录响应:{json}", responseJson);
|
||||
@@ -55,7 +58,26 @@ public class JinkoJIPService : IJinkoJIPService
|
||||
}
|
||||
|
||||
|
||||
//************************************************************************************************************************************************/
|
||||
public async Task SyncMealSupplementRecordsAsync(List<SyncMealSupplementRecordRequest> requests)
|
||||
{
|
||||
var requestUrl = "/JIP/DHR/DHR_DL_CALLBACK";
|
||||
|
||||
var json = requests.ToJson();
|
||||
|
||||
var content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
var response = await GetHttpClient().PostAsync(requestUrl, content);
|
||||
var responseJson = await response.Content.ReadAsStringAsync();
|
||||
|
||||
var jobj = JObject.Parse(responseJson);
|
||||
|
||||
jobj.ContainsKey("exp").ThrowIfTrue(jobj.GetValue("exp").Value<string>());
|
||||
jobj.ContainsKey("message").ThrowIfTrue(jobj.GetValue("message").Value<string>());
|
||||
|
||||
(jobj.GetValue("code").Value<int>() != 200).ThrowIfTrue(jobj.GetValue("message").Value<string>());
|
||||
}
|
||||
|
||||
|
||||
//********************************************************************* help methods ***************************************************************************/
|
||||
|
||||
|
||||
private static string IssueJwt(string jwtKey, string jwtSecret, int mins)
|
||||
@@ -65,9 +87,9 @@ public class JinkoJIPService : IJinkoJIPService
|
||||
|
||||
var claims = new List<Claim>
|
||||
{
|
||||
new Claim(JwtRegisteredClaimNames.Nbf,$"{new DateTimeOffset(now).ToUnixTimeSeconds()}"),
|
||||
new Claim(JwtRegisteredClaimNames.Exp,$"{new DateTimeOffset(expires).ToUnixTimeSeconds()}"),
|
||||
new Claim(JwtRegisteredClaimNames.Iss,jwtKey),
|
||||
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));
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace Dlhis.ScheduledTask.SyncSapInfo;
|
||||
|
||||
public class SyncMealSupplementRecordRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 唯一id
|
||||
/// </summary>
|
||||
public string UniqueId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// FAIL SUCCESS
|
||||
/// </summary>
|
||||
public string Status { get; set; }
|
||||
|
||||
|
||||
public string Msg { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user