feat 处理已知禅道
This commit is contained in:
@@ -4,5 +4,16 @@ namespace Dlhis.External.Appointment.Services;
|
||||
|
||||
public interface IAppointmentService : IScopeDependency
|
||||
{
|
||||
/// <summary>
|
||||
/// 接收申请
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
Task ReceiveAsync(VisitorAppointmentReceiveRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// 获取下一位外部人员工号
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<string> GetNextExternalCodeAsync();
|
||||
}
|
||||
@@ -7,7 +7,6 @@ using Kurisu.AspNetCore.Cache;
|
||||
using Kurisu.AspNetCore.CustomClass;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Dlhis.External.Appointment.Services.Implements;
|
||||
|
||||
@@ -70,7 +69,7 @@ public class AppointmentService : IAppointmentService
|
||||
gainfo = new GainfoEntity
|
||||
{
|
||||
No = Guid.NewGuid().ToString(),
|
||||
Code = await GetExternalCodeAsync(),
|
||||
Code = await GetNextExternalCodeAsync(),
|
||||
Gender = GetGender(item.IdNo),
|
||||
Type = GainfoUserTypeEnumType.External,
|
||||
IdNo = item.IdNo,
|
||||
@@ -131,7 +130,7 @@ public class AppointmentService : IAppointmentService
|
||||
}
|
||||
}
|
||||
|
||||
private GenderEnumType GetGender(string idNo)
|
||||
private static GenderEnumType GetGender(string idNo)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -142,31 +141,40 @@ public class AppointmentService : IAppointmentService
|
||||
: GenderEnumType.Male;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception)
|
||||
{
|
||||
//ignore
|
||||
}
|
||||
|
||||
return GenderEnumType.Unknown;
|
||||
}
|
||||
|
||||
private async Task<string> GetExternalCodeAsync()
|
||||
public async Task<string> GetNextExternalCodeAsync()
|
||||
{
|
||||
await using var handler = await _redisCache.LockAsync("gainfo:external:code-generate", expiry: TimeSpan.FromSeconds(3), retryInterval: TimeSpan.FromSeconds(1), retryCount: 3);
|
||||
handler.Acquired.ThrowIfFalse("生成虚拟工号失败");
|
||||
|
||||
int code;
|
||||
var entity = await _dbContext.Queryable<GainfoEntity>()
|
||||
.Where(x => x.Type == GainfoUserTypeEnumType.External && x.Code.StartsWith("EXT"))
|
||||
.OrderBy(x => x.Id, OrderByType.Desc)
|
||||
.FirstAsync();
|
||||
|
||||
var entity = await _dbContext.Queryable<BasicTypeEntity>().Where(x => x.Type == "gainfoExternalMaxNum").SingleAsync();
|
||||
if (entity == null)
|
||||
{
|
||||
code = 1;
|
||||
await _dbContext.InsertAsync(new BasicTypeEntity
|
||||
{
|
||||
Type = "gainfoExternalMaxNum",
|
||||
Code = "1",
|
||||
Display = "外部人员序号",
|
||||
DisplayEn = "外部人员序号",
|
||||
Remark = string.Empty,
|
||||
Sequence = 1
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
code = int.Parse(entity.Code.Replace("EXT", "").TrimStart('0')) + 1;
|
||||
code = int.Parse(entity.Code) + 1;
|
||||
entity.Code = code.ToString();
|
||||
await _dbContext.UpdateAsync(entity);
|
||||
}
|
||||
|
||||
return "EXT" + code.ToString().PadLeft(6, '0');
|
||||
|
||||
Reference in New Issue
Block a user