fix 调整查询逻辑
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Dlhis.Basic.Appointment.Request;
|
||||
using Dlhis.Basic.Appointment.Response;
|
||||
using Dlhis.Basic.Appointment.Services;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
@@ -60,6 +60,15 @@ public class AppointmentsController : ControllerBase
|
||||
await _appointmentService.ConfirmAsync(request);
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpPost("face/update")]
|
||||
[Transactional]
|
||||
[IgnoreTenant]
|
||||
public async Task GenerateTaskAndUpdateFaceAsync(AppointmentConfirmRequest request)
|
||||
{
|
||||
await _appointmentService.GenerateTaskAndUpdateFaceAsync(request.Id, request.Base64Image, DeviceTaskEnumType.Update);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据身份证获取当天预约信息
|
||||
/// </summary>
|
||||
|
||||
@@ -6,4 +6,9 @@ public class AppointmentConfirmRequest
|
||||
/// 预约明细id
|
||||
/// </summary>
|
||||
public long Id { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// base64 image
|
||||
/// </summary>
|
||||
public string Base64Image { get; set; }
|
||||
}
|
||||
@@ -4,7 +4,7 @@ using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
|
||||
namespace Dlhis.Basic.Appointment.Request;
|
||||
|
||||
public class AppointmentPageRequest : PageDto , IValidatableObject
|
||||
public class AppointmentPageRequest : PageDto, IValidatableObject
|
||||
{
|
||||
public DateTimePeriod SearchDateTimePeriod { get; set; }
|
||||
|
||||
@@ -15,6 +15,7 @@ public class AppointmentPageRequest : PageDto , IValidatableObject
|
||||
{
|
||||
SearchDateTimePeriod.End = SearchDateTimePeriod.End!.Value.AddDays(1).AddSeconds(-1);
|
||||
}
|
||||
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using Dlhis.Basic.Appointment.Request;
|
||||
using Dlhis.Basic.Appointment.Response;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
@@ -40,4 +41,6 @@ public interface IAppointmentService : IScopeDependency
|
||||
Task<Pagination<AppointmentDetailResponse>> GetRecordPageByIdNoAsync([FromQuery] AppointmentIdNoPageRequest request);
|
||||
|
||||
Task<AppointmentSummaryResponse> GetSummaryAsync(string factory, DateTime start, DateTime end);
|
||||
|
||||
Task GenerateTaskAndUpdateFaceAsync(long detailId, string base64, DeviceTaskEnumType deviceTaskType);
|
||||
}
|
||||
@@ -1,10 +1,13 @@
|
||||
using Dlhis.Basic.Appointment.Request;
|
||||
using Dlhis.Basic.Appointment.Response;
|
||||
using Dlhis.Basic.Organization.Request;
|
||||
using Dlhis.Basic.Organization.Services;
|
||||
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.Authentication.Abstractions;
|
||||
using Kurisu.AspNetCore.CustomClass;
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
|
||||
@@ -20,19 +23,29 @@ public class AppointmentService : IAppointmentService
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly IDataProtectionProvider _dataProtectionProvider;
|
||||
private readonly ICurrentUser _currentUser;
|
||||
private readonly IGainfoFaceService _gainfoFaceService;
|
||||
|
||||
public AppointmentService(IDbContext dbContext, IDataProtectionProvider dataProtectionProvider)
|
||||
public AppointmentService(IDbContext dbContext,
|
||||
IDataProtectionProvider dataProtectionProvider,
|
||||
ICurrentUser currentUser,
|
||||
IGainfoFaceService gainfoFaceService)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_dataProtectionProvider = dataProtectionProvider;
|
||||
_currentUser = currentUser;
|
||||
_gainfoFaceService = gainfoFaceService;
|
||||
}
|
||||
|
||||
public async Task<Pagination<AppointmentPageResponse>> GetPageAsync(AppointmentPageRequest request)
|
||||
{
|
||||
var factory = _currentUser.GetStringTenantId();
|
||||
|
||||
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)
|
||||
.Where(x => x.Factory == factory)
|
||||
.Select<AppointmentPageResponse>()
|
||||
.ToPageListAsync(request);
|
||||
}
|
||||
@@ -50,6 +63,19 @@ public class AppointmentService : IAppointmentService
|
||||
var detail = await _dbContext.Queryable<VisitorAppointmentDetailEntity>().Where(x => x.Id == request.Id).SingleAsync();
|
||||
detail.ThrowIfNull("预约信息不存在");
|
||||
|
||||
detail.DoorStatus = VisitorAppointmentDetailStatusEnumType.Arrived;
|
||||
detail.WorkplaceStatus = VisitorAppointmentDetailStatusEnumType.Arrived;
|
||||
detail.ArrivedTime = DateTime.Now;
|
||||
|
||||
await _dbContext.UpdateAsync(detail);
|
||||
await GenerateTaskAndUpdateFaceAsync(detail.Id, request.Base64Image, DeviceTaskEnumType.Add);
|
||||
}
|
||||
|
||||
public async Task GenerateTaskAndUpdateFaceAsync(long detailId, string base64, DeviceTaskEnumType deviceTaskType)
|
||||
{
|
||||
var detail = await _dbContext.Queryable<VisitorAppointmentDetailEntity>().Where(x => x.Id == detailId).SingleAsync();
|
||||
detail.ThrowIfNull("预约信息不存在");
|
||||
|
||||
var areaCodes = GetValidAreaCodes(detail);
|
||||
var existsAreaCodes = await _dbContext.Queryable<AppointmentAreaEntity>().Where(x => areaCodes.Contains(x.CustomCode)).Select(x => x.CustomCode).ToListAsync();
|
||||
|
||||
@@ -68,17 +94,18 @@ public class AppointmentService : IAppointmentService
|
||||
DeviceUniqueNo = x.UniqueNo,
|
||||
Status = DeviceTaskStatusEnumType.Wait,
|
||||
UserNo = detail.UserNo,
|
||||
Type = DeviceTaskEnumType.Add,
|
||||
Type = deviceTaskType,
|
||||
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);
|
||||
await _gainfoFaceService.UploadExternalFaceAsync(new GainfoUploadFaceRequest
|
||||
{
|
||||
UserNo = detail.IdNo,
|
||||
Face = base64
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -149,7 +176,7 @@ public class AppointmentService : IAppointmentService
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw new UserFriendlyException("凭证有误");
|
||||
//ignore
|
||||
}
|
||||
|
||||
var page = await _dbContext.Queryable<VisitorAppointmentDetailEntity>()
|
||||
@@ -174,14 +201,17 @@ public class AppointmentService : IAppointmentService
|
||||
|
||||
var @in = await _dbContext.Queryable<VisitorAppointmentDetailEntity>()
|
||||
.Where(x => (x.IsEnterDoorArea && ((x.DoorStart >= start && x.DoorStart <= end) || x.DoorEnd >= start && x.DoorEnd <= end)) ||
|
||||
(x.IsEnterWorkplace && ((x.WorkplaceStart >= start && x.WorkplaceStart <= end) || (x.WorkplaceEnd >= start && x.WorkplaceEnd <= end))))
|
||||
(x.IsEnterWorkplace && ((x.WorkplaceStart >= start && x.WorkplaceStart <= end) || (x.WorkplaceEnd >= start && x.WorkplaceEnd <= end)))
|
||||
)
|
||||
.Where(x => (x.IsEnterDoorArea && x.DoorStatus == VisitorAppointmentDetailStatusEnumType.Arrived) || (x.IsEnterWorkplace && x.WorkplaceStatus == VisitorAppointmentDetailStatusEnumType.Arrived))
|
||||
.Where(x => SqlFunc.Subqueryable<VisitorAppointmentEntity>().Where(p => p.Factory == factory).Any())
|
||||
.CountAsync();
|
||||
|
||||
var notIn = await _dbContext.Queryable<VisitorAppointmentDetailEntity>()
|
||||
.Where(x => (x.IsEnterDoorArea && ((x.DoorStart >= start && x.DoorStart <= end) || x.DoorEnd >= start && x.DoorEnd <= end)) ||
|
||||
(x.IsEnterWorkplace && ((x.WorkplaceStart >= start && x.WorkplaceStart <= end) || (x.WorkplaceEnd >= start && x.WorkplaceEnd <= end))))
|
||||
.Where(x => (x.IsEnterDoorArea && x.DoorStatus == VisitorAppointmentDetailStatusEnumType.Leave) || (x.IsEnterWorkplace && x.WorkplaceStatus == VisitorAppointmentDetailStatusEnumType.Leave))
|
||||
(x.IsEnterWorkplace && ((x.WorkplaceStart >= start && x.WorkplaceStart <= end) || (x.WorkplaceEnd >= start && x.WorkplaceEnd <= end)))
|
||||
)
|
||||
.Where(x => (x.IsEnterDoorArea && x.DoorStatus == VisitorAppointmentDetailStatusEnumType.Wait) || (x.IsEnterWorkplace && x.WorkplaceStatus == VisitorAppointmentDetailStatusEnumType.Wait))
|
||||
.Where(x => SqlFunc.Subqueryable<VisitorAppointmentEntity>().Where(p => p.Factory == factory).Any())
|
||||
.CountAsync();
|
||||
|
||||
@@ -189,6 +219,7 @@ public class AppointmentService : IAppointmentService
|
||||
.Where(x => (x.IsEnterDoorArea && x.DoorEnd >= start && x.DoorEnd <= end) ||
|
||||
(x.IsEnterWorkplace && x.WorkplaceEnd >= start && x.WorkplaceEnd <= end)
|
||||
)
|
||||
.Where(x => (x.IsEnterDoorArea && x.DoorStatus == VisitorAppointmentDetailStatusEnumType.Leave) || (x.IsEnterWorkplace && x.WorkplaceStatus == VisitorAppointmentDetailStatusEnumType.Leave))
|
||||
.Where(x => SqlFunc.Subqueryable<VisitorAppointmentEntity>().Where(p => p.Factory == factory).Any())
|
||||
.CountAsync();
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ using Dlhis.Basic.Organization.Api;
|
||||
using Dlhis.Basic.Organization.Api.Request;
|
||||
using Dlhis.Basic.Organization.Request;
|
||||
using Dlhis.Basic.Organization.Response;
|
||||
using Dlhis.Entity.Basic.Dto;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Basic.Enums;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
@@ -104,17 +103,13 @@ public class GainfoFaceService : IGainfoFaceService
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw new UserFriendlyException("凭证有误,无法获取人脸数");
|
||||
//ignore
|
||||
}
|
||||
|
||||
var gainfo = await _gainfoStore.Queryable(GainfoStatusEnumType.External)
|
||||
.Where(x => x.IdNo == request.UserNo)
|
||||
.SingleAsync();
|
||||
|
||||
gainfo ??= await _gainfoStore.Queryable(GainfoStatusEnumType.Working)
|
||||
.Where(x => x.IdNo == request.UserNo)
|
||||
.SingleAsync();
|
||||
|
||||
gainfo.ThrowIfNull("人员信息不存在");
|
||||
|
||||
var face = await _faceDbContext.Queryable<GainfoFaceEntity>().Where(x => x.UserCode == gainfo.Code).SingleAsync();
|
||||
|
||||
@@ -30,6 +30,11 @@ public class GainfoStore : IGainfoStore
|
||||
return _dbContext.Queryable<GainfoEntity>();
|
||||
}
|
||||
|
||||
if (gainfoStatus == GainfoStatusEnumType.External)
|
||||
{
|
||||
return _dbContext.Queryable<GainfoEntity>().Where(x => x.Type == GainfoUserTypeEnumType.External);
|
||||
}
|
||||
|
||||
var tableName = typeof(GainfoEntity).GetCustomAttribute<SugarTable>()!.TableName;
|
||||
return _dbContext.Queryable<GainfoEntity>().AS(tableName + gainfoStatus);
|
||||
}
|
||||
@@ -83,5 +88,4 @@ public class GainfoStore : IGainfoStore
|
||||
|
||||
return tableName;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user