fix 访客增加检查数据参数
This commit is contained in:
@@ -3,7 +3,7 @@ using Dlhis.External.Appointment.Dto;
|
|||||||
|
|
||||||
namespace Dlhis.External.Appointment.Request;
|
namespace Dlhis.External.Appointment.Request;
|
||||||
|
|
||||||
public class VisitorAppointmentReceiveRequest
|
public class VisitorAppointmentReceiveRequest
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 流水号
|
/// 流水号
|
||||||
@@ -57,4 +57,7 @@ public class VisitorAppointmentReceiveRequest
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[MinLength(1, ErrorMessage = "明细必填")]
|
[MinLength(1, ErrorMessage = "明细必填")]
|
||||||
public List<AppointmentReceiveItemDto> Items { get; set; }
|
public List<AppointmentReceiveItemDto> Items { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
public bool OnlyCheck { get; set; }
|
||||||
}
|
}
|
||||||
@@ -31,140 +31,186 @@ public class AppointmentService : IAppointmentService
|
|||||||
|
|
||||||
public async Task ReceiveAsync(VisitorAppointmentReceiveRequest request)
|
public async Task ReceiveAsync(VisitorAppointmentReceiveRequest request)
|
||||||
{
|
{
|
||||||
if (request.Factory == "501")
|
var invalids = new[] { GainfoUserTypeEnumType.Normal, GainfoUserTypeEnumType.SecurityWhite };
|
||||||
{
|
|
||||||
await ReSendTo501Async(request);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var exists = await _dbContext.Queryable<VisitorAppointmentEntity>().Where(x => x.No == request.No).AnyAsync();
|
var exists = await _dbContext.Queryable<VisitorAppointmentEntity>().Where(x => x.No == request.No).AnyAsync();
|
||||||
exists.ThrowIfTrue("已经存在申请");
|
exists.ThrowIfTrue("已经存在申请,请勿重复提交");
|
||||||
|
|
||||||
var areas = await _dbContext.Queryable<AppointmentAreaEntity>().Where(x => x.TenantId == request.Factory).ToListAsync();
|
var areas = await _dbContext.Queryable<AppointmentAreaEntity>().Where(x => x.TenantId == request.Factory).ToListAsync();
|
||||||
|
|
||||||
var mst = new VisitorAppointmentEntity
|
if (request.OnlyCheck)
|
||||||
{
|
{
|
||||||
No = request.No,
|
var enterDoorAreaIdNos = request.Items.Where(x => x.IsEnterDoorArea).Select(x => x.IdNo).Distinct().ToList();
|
||||||
Title = request.Title,
|
var errors = await _dbContext.Queryable<GainfoEntity>()
|
||||||
Code = request.Code,
|
.Where(x => enterDoorAreaIdNos.Contains(x.IdNo) || enterDoorAreaIdNos.Contains(x.Code))
|
||||||
Source = request.Source,
|
.Where(x => invalids.Contains(x.Type))
|
||||||
Date = request.Date,
|
.Select(x => x.IdNo + x.Name)
|
||||||
Factory = request.Factory,
|
.ToListAsync();
|
||||||
Reason = request.Reason,
|
|
||||||
Remark = request.Remark,
|
|
||||||
};
|
|
||||||
|
|
||||||
await _dbContext.InsertAsync(mst);
|
errors.ThrowIfExists($"内部人员无法发起门岗预约({errors.Join(",")})");
|
||||||
|
|
||||||
var invalids = new[] { GainfoUserTypeEnumType.Normal, GainfoUserTypeEnumType.SecurityWhite };
|
foreach (var item in request.Items)
|
||||||
|
|
||||||
var enterDoorAreaIdNos = request.Items.Where(x => x.IsEnterDoorArea).Select(x => x.IdNo).Distinct().ToList();
|
|
||||||
var errors = await _dbContext.Queryable<GainfoEntity>()
|
|
||||||
.Where(x => enterDoorAreaIdNos.Contains(x.IdNo) || enterDoorAreaIdNos.Contains(x.Code))
|
|
||||||
.Where(x => invalids.Contains(x.Type))
|
|
||||||
.Select(x => x.IdNo + x.Name)
|
|
||||||
.ToListAsync();
|
|
||||||
|
|
||||||
errors.ThrowIfExists($"内部人员无法发起门岗预约({errors.Join(",")})");
|
|
||||||
|
|
||||||
//var idNos = request.Items.Select(x => x.IdNo).Distinct().ToList();
|
|
||||||
//var outsources = await _dbContext.Queryable<GainfoEntity>()
|
|
||||||
// .Where(x => idNos.Contains(x.IdNo) || idNos.Contains(x.Code))
|
|
||||||
// .Where(x => x.Type == GainfoUserTypeEnumType.Outsource)
|
|
||||||
// .Select(x => x.IdNo + x.Name)
|
|
||||||
// .ToListAsync();
|
|
||||||
|
|
||||||
//outsources.ThrowIfExists($"存在外包人员申请,请检查一下人员:{outsources.Join(",")}");
|
|
||||||
|
|
||||||
foreach (var item in request.Items)
|
|
||||||
{
|
|
||||||
item.IdNo = item.IdNo.Trim();
|
|
||||||
|
|
||||||
if (item.IsEnterDoorArea && areas.Where(x => x.Type == AppointmentAreaEnumType.Door)
|
|
||||||
.Select(x => x.CustomCode)
|
|
||||||
.Contains(item.ApplyDoorArea) == false)
|
|
||||||
{
|
{
|
||||||
throw new UserFriendlyException($"门岗区域{item.ApplyDoorArea}无效");
|
item.IdNo = item.IdNo.Trim();
|
||||||
}
|
|
||||||
|
|
||||||
if (item.IsEnterWorkplace &&
|
if (item.IsEnterDoorArea && areas.Where(x => x.Type == AppointmentAreaEnumType.Door)
|
||||||
item.ApplyWorkplaceAreas.All(p => areas.Where(x => x.Type == AppointmentAreaEnumType.Workplace)
|
.Select(x => x.CustomCode)
|
||||||
.Select(x => x.CustomCode)
|
.Contains(item.ApplyDoorArea) == false)
|
||||||
.Contains(p)) == false)
|
|
||||||
{
|
|
||||||
var workplaceAreas = areas.Where(x => x.Type == AppointmentAreaEnumType.Workplace).Select(x => x.CustomCode);
|
|
||||||
var notExistsAreas = item.ApplyWorkplaceAreas.Where(x => !workplaceAreas.Contains(x));
|
|
||||||
throw new UserFriendlyException($"车间区域{notExistsAreas.Join(",")}无效");
|
|
||||||
}
|
|
||||||
|
|
||||||
var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.IdNo == item.IdNo || x.Code == item.IdNo).SingleAsync();
|
|
||||||
//外部人员
|
|
||||||
if (gainfo == null)
|
|
||||||
{
|
|
||||||
gainfo = new GainfoEntity
|
|
||||||
{
|
{
|
||||||
No = Guid.NewGuid().ToString(),
|
throw new UserFriendlyException($"门岗区域{item.ApplyDoorArea}无效");
|
||||||
Code = await GetNextExternalCodeAsync(),
|
|
||||||
Gender = GetGender(item.IdNo),
|
|
||||||
Type = GainfoUserTypeEnumType.External,
|
|
||||||
IdNo = item.IdNo,
|
|
||||||
Name = item.Name,
|
|
||||||
Source = request.Source,
|
|
||||||
Phone = item.Phone,
|
|
||||||
Factory = mst.Factory
|
|
||||||
};
|
|
||||||
await _dbContext.InsertAsync(gainfo);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
(invalids.Contains(gainfo.Type) && item.IsEnterDoorArea).ThrowIfTrue("内部人员无法发起门岗预约");
|
|
||||||
if (gainfo.Type == GainfoUserTypeEnumType.External)
|
|
||||||
{
|
|
||||||
gainfo.Source = request.Source;
|
|
||||||
gainfo.Phone = item.Phone;
|
|
||||||
gainfo.Factory = mst.Factory;
|
|
||||||
|
|
||||||
await _dbContext.UpdateAsync(gainfo);
|
|
||||||
}
|
}
|
||||||
//else if (gainfo.Type == GainfoUserTypeEnumType.Outsource)
|
|
||||||
//{
|
if (item.IsEnterWorkplace &&
|
||||||
// throw new UserFriendlyException($"访客类型有误!,请检查{gainfo.Name},{gainfo.IdNo}");
|
item.ApplyWorkplaceAreas.All(p => areas.Where(x => x.Type == AppointmentAreaEnumType.Workplace)
|
||||||
//}
|
.Select(x => x.CustomCode)
|
||||||
|
.Contains(p)) == false)
|
||||||
|
{
|
||||||
|
var workplaceAreas = areas.Where(x => x.Type == AppointmentAreaEnumType.Workplace).Select(x => x.CustomCode);
|
||||||
|
var notExistsAreas = item.ApplyWorkplaceAreas.Where(x => !workplaceAreas.Contains(x));
|
||||||
|
throw new UserFriendlyException($"车间区域{notExistsAreas.Join(",")}无效");
|
||||||
|
}
|
||||||
|
|
||||||
|
var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.IdNo == item.IdNo || x.Code == item.IdNo).SingleAsync();
|
||||||
|
//外部人员
|
||||||
|
if (gainfo == null)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
(invalids.Contains(gainfo.Type) && item.IsEnterDoorArea).ThrowIfTrue("内部人员无法发起门岗预约");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (request.Factory == "501")
|
||||||
|
{
|
||||||
|
await ReSendTo501Async(request);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var detail = new VisitorAppointmentDetailEntity
|
var mst = new VisitorAppointmentEntity
|
||||||
{
|
{
|
||||||
UserNo = gainfo.No,
|
|
||||||
No = request.No,
|
No = request.No,
|
||||||
IdType = item.IdType,
|
Title = request.Title,
|
||||||
IdNo = item.IdNo,
|
Code = request.Code,
|
||||||
Name = item.Name,
|
Source = request.Source,
|
||||||
Phone = item.Phone,
|
Date = request.Date,
|
||||||
Remark = item.Remark,
|
Factory = request.Factory,
|
||||||
DoorStatus = item.IsEnterDoorArea && areas.Where(x => x.Type == AppointmentAreaEnumType.Door)
|
Reason = request.Reason,
|
||||||
.Select(x => x.CustomCode)
|
Remark = request.Remark,
|
||||||
.Contains(item.ApplyDoorArea)
|
|
||||||
? VisitorAppointmentDetailStatusEnumType.Wait
|
|
||||||
: VisitorAppointmentDetailStatusEnumType.Obsolete,
|
|
||||||
LicensePlate = item.LicensePlate,
|
|
||||||
IsEnterDoorArea = item.IsEnterDoorArea,
|
|
||||||
ApplyDoorArea = item.ApplyDoorArea,
|
|
||||||
DoorStart = item.DoorStart,
|
|
||||||
DoorEnd = item.DoorEnd,
|
|
||||||
IsEnterWorkplace = item.IsEnterWorkplace,
|
|
||||||
WorkplaceStatus = item.IsEnterWorkplace &&
|
|
||||||
item.ApplyWorkplaceAreas.All(p => areas.Where(x => x.Type == AppointmentAreaEnumType.Workplace)
|
|
||||||
.Select(x => x.CustomCode)
|
|
||||||
.Contains(p))
|
|
||||||
? VisitorAppointmentDetailStatusEnumType.Wait
|
|
||||||
: VisitorAppointmentDetailStatusEnumType.Obsolete,
|
|
||||||
ApplyWorkplaceAreas = item.ApplyWorkplaceAreas,
|
|
||||||
WorkplaceStart = item.WorkplaceStart,
|
|
||||||
WorkplaceEnd = item.WorkplaceEnd,
|
|
||||||
ImageUrl = item.ImageUrl
|
|
||||||
};
|
};
|
||||||
|
|
||||||
await _dbContext.InsertAsync(detail);
|
var enterDoorAreaIdNos = request.Items.Where(x => x.IsEnterDoorArea).Select(x => x.IdNo).Distinct().ToList();
|
||||||
|
var errors = await _dbContext.Queryable<GainfoEntity>()
|
||||||
|
.Where(x => enterDoorAreaIdNos.Contains(x.IdNo) || enterDoorAreaIdNos.Contains(x.Code))
|
||||||
|
.Where(x => invalids.Contains(x.Type))
|
||||||
|
.Select(x => x.IdNo + x.Name)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
errors.ThrowIfExists($"内部人员无法发起门岗预约({errors.Join(",")})");
|
||||||
|
|
||||||
|
await _dbContext.InsertAsync(mst);
|
||||||
|
//var idNos = request.Items.Select(x => x.IdNo).Distinct().ToList();
|
||||||
|
//var outsources = await _dbContext.Queryable<GainfoEntity>()
|
||||||
|
// .Where(x => idNos.Contains(x.IdNo) || idNos.Contains(x.Code))
|
||||||
|
// .Where(x => x.Type == GainfoUserTypeEnumType.Outsource)
|
||||||
|
// .Select(x => x.IdNo + x.Name)
|
||||||
|
// .ToListAsync();
|
||||||
|
|
||||||
|
//outsources.ThrowIfExists($"存在外包人员申请,请检查一下人员:{outsources.Join(",")}");
|
||||||
|
|
||||||
|
foreach (var item in request.Items)
|
||||||
|
{
|
||||||
|
item.IdNo = item.IdNo.Trim();
|
||||||
|
|
||||||
|
if (item.IsEnterDoorArea && areas.Where(x => x.Type == AppointmentAreaEnumType.Door)
|
||||||
|
.Select(x => x.CustomCode)
|
||||||
|
.Contains(item.ApplyDoorArea) == false)
|
||||||
|
{
|
||||||
|
throw new UserFriendlyException($"门岗区域{item.ApplyDoorArea}无效");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item.IsEnterWorkplace &&
|
||||||
|
item.ApplyWorkplaceAreas.All(p => areas.Where(x => x.Type == AppointmentAreaEnumType.Workplace)
|
||||||
|
.Select(x => x.CustomCode)
|
||||||
|
.Contains(p)) == false)
|
||||||
|
{
|
||||||
|
var workplaceAreas = areas.Where(x => x.Type == AppointmentAreaEnumType.Workplace).Select(x => x.CustomCode);
|
||||||
|
var notExistsAreas = item.ApplyWorkplaceAreas.Where(x => !workplaceAreas.Contains(x));
|
||||||
|
throw new UserFriendlyException($"车间区域{notExistsAreas.Join(",")}无效");
|
||||||
|
}
|
||||||
|
|
||||||
|
var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.IdNo == item.IdNo || x.Code == item.IdNo).SingleAsync();
|
||||||
|
//外部人员
|
||||||
|
if (gainfo == null)
|
||||||
|
{
|
||||||
|
gainfo = new GainfoEntity
|
||||||
|
{
|
||||||
|
No = Guid.NewGuid().ToString(),
|
||||||
|
Code = await GetNextExternalCodeAsync(),
|
||||||
|
Gender = GetGender(item.IdNo),
|
||||||
|
Type = GainfoUserTypeEnumType.External,
|
||||||
|
IdNo = item.IdNo,
|
||||||
|
Name = item.Name,
|
||||||
|
Source = request.Source,
|
||||||
|
Phone = item.Phone,
|
||||||
|
Factory = request.Factory
|
||||||
|
};
|
||||||
|
await _dbContext.InsertAsync(gainfo);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
(invalids.Contains(gainfo.Type) && item.IsEnterDoorArea).ThrowIfTrue("内部人员无法发起门岗预约");
|
||||||
|
if (gainfo.Type == GainfoUserTypeEnumType.External)
|
||||||
|
{
|
||||||
|
gainfo.Source = request.Source;
|
||||||
|
gainfo.Phone = item.Phone;
|
||||||
|
gainfo.Factory = request.Factory;
|
||||||
|
|
||||||
|
await _dbContext.UpdateAsync(gainfo);
|
||||||
|
}
|
||||||
|
//else if (gainfo.Type == GainfoUserTypeEnumType.Outsource)
|
||||||
|
//{
|
||||||
|
// throw new UserFriendlyException($"访客类型有误!,请检查{gainfo.Name},{gainfo.IdNo}");
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
|
var detail = new VisitorAppointmentDetailEntity
|
||||||
|
{
|
||||||
|
UserNo = gainfo.No,
|
||||||
|
No = request.No,
|
||||||
|
IdType = item.IdType,
|
||||||
|
IdNo = item.IdNo,
|
||||||
|
Name = item.Name,
|
||||||
|
Phone = item.Phone,
|
||||||
|
Remark = item.Remark,
|
||||||
|
DoorStatus = item.IsEnterDoorArea && areas.Where(x => x.Type == AppointmentAreaEnumType.Door)
|
||||||
|
.Select(x => x.CustomCode)
|
||||||
|
.Contains(item.ApplyDoorArea)
|
||||||
|
? VisitorAppointmentDetailStatusEnumType.Wait
|
||||||
|
: VisitorAppointmentDetailStatusEnumType.Obsolete,
|
||||||
|
LicensePlate = item.LicensePlate,
|
||||||
|
IsEnterDoorArea = item.IsEnterDoorArea,
|
||||||
|
ApplyDoorArea = item.ApplyDoorArea,
|
||||||
|
DoorStart = item.DoorStart,
|
||||||
|
DoorEnd = item.DoorEnd,
|
||||||
|
IsEnterWorkplace = item.IsEnterWorkplace,
|
||||||
|
WorkplaceStatus = item.IsEnterWorkplace &&
|
||||||
|
item.ApplyWorkplaceAreas.All(p => areas.Where(x => x.Type == AppointmentAreaEnumType.Workplace)
|
||||||
|
.Select(x => x.CustomCode)
|
||||||
|
.Contains(p))
|
||||||
|
? VisitorAppointmentDetailStatusEnumType.Wait
|
||||||
|
: VisitorAppointmentDetailStatusEnumType.Obsolete,
|
||||||
|
ApplyWorkplaceAreas = item.ApplyWorkplaceAreas,
|
||||||
|
WorkplaceStart = item.WorkplaceStart,
|
||||||
|
WorkplaceEnd = item.WorkplaceEnd,
|
||||||
|
ImageUrl = item.ImageUrl
|
||||||
|
};
|
||||||
|
|
||||||
|
await _dbContext.InsertAsync(detail);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user