fix 提交已经问题处理

This commit is contained in:
2024-08-29 18:28:16 +08:00
parent 275e6e333d
commit 5b55ac01dd
21 changed files with 129 additions and 502 deletions

View File

@@ -18,10 +18,9 @@ public class AppointmentReceiveItemDto
public string Phone { get; set; }
/// <summary>
/// 身份证
/// 证件号/工号
/// </summary>
[StringLength(18, MinimumLength = 18)]
[Required(ErrorMessage = "身份证必填")]
[Required(ErrorMessage = "证件号/工号")]
public string IdNo { get; set; }
/// <summary>

View File

@@ -73,23 +73,19 @@ public class AppointmentReceiveRequest : IValidatableObject
/// </summary>
public bool IsEnterWorkplace { get; set; }
/// <summary>
/// 车间区域
/// </summary>
public string WorkplaceArea { get; set; }
/// <summary>
/// 明细
/// </summary>
[MinLength(1, ErrorMessage = "明细必填")]
public List<AppointmentReceiveItemDto> Items { get; set; }
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if (IsEnterWorkplace)
{
if (Items.Any(x => x.ImageUrl.IsEmpty()))
{
yield return new ValidationResult("社保照片不可为空", new[] { "ImageUrl" });
}
}
if (Start >= End)
{
yield return new ValidationResult("来访时间不能大于等于离开时间", new[] { nameof(Start), nameof(End) });

View File

@@ -1,19 +1,24 @@
using Dlhis.Entity.Basic.Entity;
using Dlhis.Entity.Basic.Enums;
using Dlhis.Entity.Visitor.Entity;
using Dlhis.Entity.Visitor.Enums;
using Dlhis.External.Appointment.Request;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
using Kurisu.AspNetCore.Utils;
using Kurisu.AspNetCore.Utils.Extensions;
using SqlSugar;
namespace Dlhis.External.Appointment.Services.Implements;
public class AppointmentService : IAppointmentService
{
private readonly IDbContext _dbContext;
private readonly RedisCache _redisCache;
public AppointmentService(IDbContext dbContext)
public AppointmentService(IDbContext dbContext, RedisCache redisCache)
{
_dbContext = dbContext;
_redisCache = redisCache;
}
public async Task ReceiveAsync(AppointmentReceiveRequest request)
@@ -23,6 +28,11 @@ public class AppointmentService : IAppointmentService
var id = await _dbContext.InsertReturnIdentityAsync(new VisitorAppointmentEntity
{
Id = 0,
CreatedBy = 0,
CreateTime = default,
ModifiedBy = 0,
ModifiedTime = default,
No = request.No,
Title = request.Title,
Code = request.Code,
@@ -34,55 +44,76 @@ public class AppointmentService : IAppointmentService
Start = request.Start,
End = request.End,
Remark = request.Remark,
IsEnterWorkplace = request.IsEnterWorkplace
IsEnterWorkplace = request.IsEnterWorkplace,
});
foreach (var item in request.Items)
{
var no = await _dbContext.Queryable<GainfoEntity>().Where(x => x.IdNo == item.IdNo).Select(x => x.No).SingleAsync();
var isExternal = no.IsEmpty();
if (isExternal)
var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.IdNo == item.IdNo || x.Code == item.IdNo).SingleAsync();
//外部人员
if (gainfo == null)
{
var gainfoExternal = await _dbContext.Queryable<GainfoExternalEntity>().Where(x => x.IdNo == item.IdNo).FirstAsync();
if (gainfoExternal == null)
gainfo = new GainfoEntity
{
gainfoExternal = new GainfoExternalEntity
{
No = Guid.NewGuid().ToString(),
Code = item.IdNo,
IdNo = item.IdNo,
Name = item.Name,
Company = request.Company,
Phone = item.Phone
};
await _dbContext.InsertAsync(gainfoExternal);
}
else
{
gainfoExternal.Phone = item.Phone;
gainfoExternal.Company = request.Company;
await _dbContext.UpdateAsync(gainfoExternal);
}
no = gainfoExternal.No;
No = Guid.NewGuid().ToString(),
Code = await GetExternalCodeAsync(),
Type = GainfoUserTypeEnumType.External,
IdNo = item.IdNo,
Name = item.Name,
Source = request.Company,
Phone = item.Phone
};
await _dbContext.InsertAsync(gainfo);
}
else
{
if (gainfo.Type == GainfoUserTypeEnumType.External)
{
gainfo.Source = request.Company;
gainfo.Phone = item.Phone;
await _dbContext.UpdateAsync(gainfo);
}
}
(gainfo.Type == GainfoUserTypeEnumType.External && request.IsEnterWorkplace && item.ImageUrl.IsEmpty()).ThrowIfTrue($"{item.Name}的社保照片不可为空");
var detail = new VisitorAppointmentDetailEntity
{
UserNo = no,
UserNo = gainfo.No,
AppointmentId = id,
No = request.No,
IdNo = item.IdNo,
Name = item.Name,
Phone = item.Phone,
Remark = item.Remark,
Status = AppointmentDetailEnumType.Wait,
IsExternal = isExternal,
LicensePlate = item.LicensePlate
};
await _dbContext.InsertAsync(detail);
}
}
private async Task<string> GetExternalCodeAsync()
{
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();
if (entity == null)
{
code = 1;
}
else
{
code = int.Parse(entity.Code.Replace("EXT", "").TrimStart('0')) + 1;
}
return "EXT" + code.ToString().PadLeft(6, '0');
}
}