fix 访客预约代码调整
This commit is contained in:
@@ -0,0 +1,145 @@
|
||||
using Dlhis.Basic.Appointment.Request;
|
||||
using Dlhis.Basic.Appointment.Response;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Dlhis.Entity.Visitor.Entity;
|
||||
using Dlhis.Entity.Visitor.Enums;
|
||||
using Kurisu.AspNetCore.CustomClass;
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Microsoft.AspNetCore.DataProtection;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Dlhis.Basic.Appointment.Services.Implements;
|
||||
|
||||
public class AppointmentService : IAppointmentService
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly IDataProtectionProvider _dataProtectionProvider;
|
||||
|
||||
public AppointmentService(IDbContext dbContext, IDataProtectionProvider dataProtectionProvider)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_dataProtectionProvider = dataProtectionProvider;
|
||||
}
|
||||
|
||||
public async Task<Pagination<AppointmentPageResponse>> GetPageAsync(AppointmentPageRequest request)
|
||||
{
|
||||
return await _dbContext.Queryable<VisitorAppointmentEntity>()
|
||||
.WhereIF(request.SearchDateTimePeriod.HasValue(),
|
||||
x => x.Date >= request.SearchDateTimePeriod.Start && x.Date <= request.SearchDateTimePeriod.End)
|
||||
.WhereIF(request.Search.IsPresent(), x => x.Code == request.Search)
|
||||
.Select<AppointmentPageResponse>()
|
||||
.ToPageListAsync(request);
|
||||
}
|
||||
|
||||
public async Task<List<AppointmentDetailResponse>> GetAppointmentDetailsByIdAsync(string no)
|
||||
{
|
||||
return await _dbContext.Queryable<VisitorAppointmentDetailEntity>()
|
||||
.Where(x => x.No == no)
|
||||
.Select<AppointmentDetailResponse>()
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task ConfirmAsync(AppointmentConfirmRequest request)
|
||||
{
|
||||
var detail = await _dbContext.Queryable<VisitorAppointmentDetailEntity>().Where(x => x.Id == request.Id).SingleAsync();
|
||||
detail.ThrowIfNull("预约信息不存在");
|
||||
|
||||
var areaCodes = GetValidAreaCodes(detail);
|
||||
var existsAreaCodes = await _dbContext.Queryable<AppointmentAreaEntity>().Where(x => areaCodes.Contains(x.CustomCode)).Select(x => x.CustomCode).ToListAsync();
|
||||
|
||||
//当前分配的设备codes
|
||||
var deviceCodes = await _dbContext.Queryable<AppointmentAreaAssignmentEntity>()
|
||||
.Where(x => existsAreaCodes.Contains(x.CustomCode))
|
||||
.Select(x => x.DeviceCode)
|
||||
.ToListAsync();
|
||||
|
||||
var deviceUniqueNos = await _dbContext.Queryable<DeviceEntity>().Where(x => deviceCodes.Contains(x.Code)).Select(x => new { x.UniqueNo, x.TenantId }).ToListAsync();
|
||||
|
||||
await _dbContext.InsertAsync(deviceUniqueNos.Select(x => new DeviceTaskEntity
|
||||
{
|
||||
DeviceType = DeviceTypeEnumType.Door,
|
||||
DeviceUniqueNo = x.UniqueNo,
|
||||
Status = DeviceTaskStatusEnumType.Wait,
|
||||
UserNo = detail.UserNo,
|
||||
Type = DeviceTaskEnumType.Add,
|
||||
Priority = 100,
|
||||
TenantId = x.TenantId,
|
||||
Source = DeviceTaskSourceEnumType.Appointment,
|
||||
Version = 0,
|
||||
}).ToList());
|
||||
|
||||
detail.DoorStatus = VisitorAppointmentDetailStatusEnumType.Arrived;
|
||||
detail.WorkplaceStatus = VisitorAppointmentDetailStatusEnumType.Arrived;
|
||||
detail.ArrivedTime = DateTime.Now;
|
||||
await _dbContext.UpdateAsync(detail);
|
||||
}
|
||||
|
||||
|
||||
private static IEnumerable<string> GetValidAreaCodes(VisitorAppointmentDetailEntity detail)
|
||||
{
|
||||
if (detail.IsEnterDoorArea)
|
||||
{
|
||||
yield return detail.ApplyDoorArea;
|
||||
}
|
||||
|
||||
if (detail.IsEnterWorkplace)
|
||||
{
|
||||
foreach (var item in detail.ApplyWorkplaceAreas)
|
||||
{
|
||||
yield return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//********************************************************** 用户操作 *******************************************************************
|
||||
|
||||
|
||||
public async Task<AppointmentDetailResponse> GetTodayByIdNoAsync(string idNo)
|
||||
{
|
||||
var protector = _dataProtectionProvider.CreateProtector("gainfo:external:idno");
|
||||
try
|
||||
{
|
||||
idNo = protector.Unprotect(idNo);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw new UserFriendlyException("凭证有误");
|
||||
}
|
||||
|
||||
var now = DateTime.Now;
|
||||
return await _dbContext.Queryable<VisitorAppointmentDetailEntity>()
|
||||
.LeftJoin<GainfoEntity>((x, ga) => ga.IdNo == idNo)
|
||||
.Where((x, ga) => ga.IdNo == idNo)
|
||||
.Where(x => (x.IsEnterDoorArea && SqlFunc.DateIsSame(x.DoorStart, now)) || (x.IsEnterWorkplace && SqlFunc.DateIsSame(x.WorkplaceStart, now)))
|
||||
.Select<AppointmentDetailResponse>()
|
||||
.SingleAsync();
|
||||
}
|
||||
|
||||
public async Task<Pagination<AppointmentDetailResponse>> GetRecordPageByIdNoAsync([FromQuery] AppointmentIdNoPageRequest request)
|
||||
{
|
||||
var protector = _dataProtectionProvider.CreateProtector("gainfo:external:idno");
|
||||
try
|
||||
{
|
||||
request.IdNo = protector.Unprotect(request.IdNo);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw new UserFriendlyException("凭证有误");
|
||||
}
|
||||
|
||||
var page = await _dbContext.Queryable<VisitorAppointmentDetailEntity>()
|
||||
.LeftJoin<GainfoEntity>((x, ga) => x.UserNo == ga.No)
|
||||
.Where((x, ga) => ga.IdNo == request.IdNo)
|
||||
.OrderBy(x => x.CreateTime)
|
||||
.Select<AppointmentDetailResponse>()
|
||||
.ToPageListAsync(request);
|
||||
|
||||
return page;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user