fix 访客增加检查数据参数
This commit is contained in:
@@ -57,4 +57,7 @@ public class VisitorAppointmentReceiveRequest
|
||||
/// </summary>
|
||||
[MinLength(1, ErrorMessage = "明细必填")]
|
||||
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)
|
||||
{
|
||||
if (request.Factory == "501")
|
||||
{
|
||||
await ReSendTo501Async(request);
|
||||
return;
|
||||
}
|
||||
var invalids = new[] { GainfoUserTypeEnumType.Normal, GainfoUserTypeEnumType.SecurityWhite };
|
||||
|
||||
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 mst = new VisitorAppointmentEntity
|
||||
if (request.OnlyCheck)
|
||||
{
|
||||
No = request.No,
|
||||
Title = request.Title,
|
||||
Code = request.Code,
|
||||
Source = request.Source,
|
||||
Date = request.Date,
|
||||
Factory = request.Factory,
|
||||
Reason = request.Reason,
|
||||
Remark = request.Remark,
|
||||
};
|
||||
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();
|
||||
|
||||
await _dbContext.InsertAsync(mst);
|
||||
errors.ThrowIfExists($"内部人员无法发起门岗预约({errors.Join(",")})");
|
||||
|
||||
var invalids = new[] { GainfoUserTypeEnumType.Normal, GainfoUserTypeEnumType.SecurityWhite };
|
||||
|
||||
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)
|
||||
foreach (var item in request.Items)
|
||||
{
|
||||
throw new UserFriendlyException($"门岗区域{item.ApplyDoorArea}无效");
|
||||
}
|
||||
item.IdNo = item.IdNo.Trim();
|
||||
|
||||
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
|
||||
if (item.IsEnterDoorArea && areas.Where(x => x.Type == AppointmentAreaEnumType.Door)
|
||||
.Select(x => x.CustomCode)
|
||||
.Contains(item.ApplyDoorArea) == false)
|
||||
{
|
||||
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 = 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);
|
||||
throw new UserFriendlyException($"门岗区域{item.ApplyDoorArea}无效");
|
||||
}
|
||||
//else if (gainfo.Type == GainfoUserTypeEnumType.Outsource)
|
||||
//{
|
||||
// throw new UserFriendlyException($"访客类型有误!,请检查{gainfo.Name},{gainfo.IdNo}");
|
||||
//}
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
}
|
||||
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,
|
||||
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
|
||||
Title = request.Title,
|
||||
Code = request.Code,
|
||||
Source = request.Source,
|
||||
Date = request.Date,
|
||||
Factory = request.Factory,
|
||||
Reason = request.Reason,
|
||||
Remark = request.Remark,
|
||||
};
|
||||
|
||||
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