From e99e7a01eee25da9f1457a54b8fa9a812661c08f Mon Sep 17 00:00:00 2001 From: liguoyang Date: Fri, 16 Aug 2024 22:00:56 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E6=9A=82=E6=97=B6=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/AppointmentAreaService.cs | 326 +++++++++--------- .../Services/Implements/AppointmentService.cs | 258 +++++++------- 2 files changed, 292 insertions(+), 292 deletions(-) diff --git a/Src/Dlhis.Visitor/Appointment/Services/Implements/AppointmentAreaService.cs b/Src/Dlhis.Visitor/Appointment/Services/Implements/AppointmentAreaService.cs index 467a11eb..9df6f8e6 100644 --- a/Src/Dlhis.Visitor/Appointment/Services/Implements/AppointmentAreaService.cs +++ b/Src/Dlhis.Visitor/Appointment/Services/Implements/AppointmentAreaService.cs @@ -1,163 +1,163 @@ -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 Dlhis.Visitor.Appointment.Request; -using Dlhis.Visitor.Appointment.Response; -using Kurisu.AspNetCore.DataAccess.Dto; -using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions; -using Kurisu.AspNetCore.DataAccess.SqlSugar.Services; -using Kurisu.AspNetCore.Utils.Extensions; -using Mapster; - -namespace Dlhis.Visitor.Appointment.Services.Implements; - -public class AppointmentAreaService : IAppointmentAreaService -{ - private readonly IDbContext _dbContext; - - public AppointmentAreaService(IDbContext dbContext) - { - _dbContext = dbContext; - } - - public async Task> GetPageAsync(PageDto request) - { - return await _dbContext.Queryable() - .Select() - .ToPageListAsync(request); - } - - - public async Task SaveAsync(AppointmentAreaSaveRequest request) - { - await CheckCustomCodeDuplicateAsync(request); - - if (!request.Id.HasValue) - { - var entity = request.Adapt(); - entity.Type = request.Type; - entity.CustomCode = request.CustomCode; - - await _dbContext.InsertAsync(entity); - } - else - { - var entity = await _dbContext.Queryable().Where(x => x.Id == request.Id).SingleAsync(); - entity.ThrowIfNull("预约区域不存在"); - - request.Adapt(entity); - - await _dbContext.UpdateAsync(entity); - } - } - - - public async Task DeleteAsync(long id) - { - var entity = await _dbContext.Queryable().Where(x => x.Id == id).SingleAsync(); - await _dbContext.DeleteAsync(entity); - } - - - public async Task AssignAsync(AppointmentAreaAssignRequest request) - { - var userNos = await _dbContext.Queryable() - .LeftJoin((x, y) => x.No == y.No) - .Where(x => x.Status == AppointmentDetailEnumType.Arrived) - .Where((x, y) => y.AreaCustomCode == request.CustomCode) - .Select(x => x.UserNo) - .ToListAsync(); - - //通过人 - var deviceCodes = await _dbContext.Queryable() - .Where(x => x.CustomCode == request.CustomCode).Select(x => x.DeviceCode).ToListAsync(); - - var userPermissions = userNos.ToDictionary(x => x, _ => deviceCodes.ToList()); - - await _dbContext.Client.Deleteable() - .Where(x => x.CustomCode == request.CustomCode) - .ExecuteCommandAsync(); - - var data = request.DeviceCodes.Select(x => new AppointmentAreaAssignmentEntity - { - CustomCode = request.CustomCode, - DeviceCode = x - }).ToList(); - - await _dbContext.InsertAsync(data); - - - deviceCodes = await _dbContext.Queryable() - .Where(x => x.CustomCode == request.CustomCode).Select(x => x.DeviceCode).ToListAsync(); - - var devices = await _dbContext.Queryable().Where(x => deviceCodes.Contains(x.Code)).ToListAsync(); - - var userCurrentPermissions = userNos.ToDictionary(x => x, _ => deviceCodes.ToList()); - - var tasks = new List(); - foreach (var userNo in userNos) - { - var before = userPermissions[userNo]; - var current = userCurrentPermissions[userNo]; - - //被删除 - var deletedItems = before.Where(x => !current.Contains(x)).ToList(); - //新增 - var addItems = current.Where(x => !before.Contains(x)).ToList(); - - if (!deletedItems.Any() && !addItems.Any()) - { - continue; - } - - tasks.AddRange(deletedItems.Select(x => new DeviceTaskEntity - { - Type = DeviceTaskEnumType.Delete, - DeviceType = DeviceTypeEnumType.Door, - UserNo = userNo, - DeviceUniqueNo = devices.First(item => item.Code == x).UniqueNo, - Status = DeviceTaskStatusEnumType.Wait, - Version = 0, - CancellationId = 0, - Source = DeviceTaskSourceEnumType.Appointment, - Priority = 99 - })); - - tasks.AddRange(addItems.Select(x => new DeviceTaskEntity - { - Type = DeviceTaskEnumType.Add, - DeviceType = DeviceTypeEnumType.Door, - UserNo = userNo, - DeviceUniqueNo = devices.First(item => item.Code == x).UniqueNo, - Status = DeviceTaskStatusEnumType.Wait, - Version = 0, - CancellationId = 0, - Source = DeviceTaskSourceEnumType.Appointment, - Priority = 99 - })); - } - - await _dbContext.InsertAsync(tasks); - } - - - //********************************************************* help methods *************************************************************** - - - /// - /// 检查编码重复 - /// - /// - /// - private async Task CheckCustomCodeDuplicateAsync(AppointmentAreaSaveRequest request) - { - var exists = await _dbContext.Queryable() - .Where(x => x.CustomCode == request.CustomCode) - .WhereIF(request.Id.HasValue, x => x.Id == request.Id) - .AnyAsync(); - - exists.ThrowIfTrue("重复区域编码,请检查"); - } -} \ No newline at end of file +// 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 Dlhis.Visitor.Appointment.Request; +// using Dlhis.Visitor.Appointment.Response; +// using Kurisu.AspNetCore.DataAccess.Dto; +// using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions; +// using Kurisu.AspNetCore.DataAccess.SqlSugar.Services; +// using Kurisu.AspNetCore.Utils.Extensions; +// using Mapster; +// +// namespace Dlhis.Visitor.Appointment.Services.Implements; +// +// public class AppointmentAreaService : IAppointmentAreaService +// { +// private readonly IDbContext _dbContext; +// +// public AppointmentAreaService(IDbContext dbContext) +// { +// _dbContext = dbContext; +// } +// +// public async Task> GetPageAsync(PageDto request) +// { +// return await _dbContext.Queryable() +// .Select() +// .ToPageListAsync(request); +// } +// +// +// public async Task SaveAsync(AppointmentAreaSaveRequest request) +// { +// await CheckCustomCodeDuplicateAsync(request); +// +// if (!request.Id.HasValue) +// { +// var entity = request.Adapt(); +// entity.Type = request.Type; +// entity.CustomCode = request.CustomCode; +// +// await _dbContext.InsertAsync(entity); +// } +// else +// { +// var entity = await _dbContext.Queryable().Where(x => x.Id == request.Id).SingleAsync(); +// entity.ThrowIfNull("预约区域不存在"); +// +// request.Adapt(entity); +// +// await _dbContext.UpdateAsync(entity); +// } +// } +// +// +// public async Task DeleteAsync(long id) +// { +// var entity = await _dbContext.Queryable().Where(x => x.Id == id).SingleAsync(); +// await _dbContext.DeleteAsync(entity); +// } +// +// +// public async Task AssignAsync(AppointmentAreaAssignRequest request) +// { +// var userNos = await _dbContext.Queryable() +// .LeftJoin((x, y) => x.No == y.No) +// .Where(x => x.Status == AppointmentDetailEnumType.Arrived) +// .Where((x, y) => y.AreaCustomCode == request.CustomCode) +// .Select(x => x.UserNo) +// .ToListAsync(); +// +// //通过人 +// var deviceCodes = await _dbContext.Queryable() +// .Where(x => x.CustomCode == request.CustomCode).Select(x => x.DeviceCode).ToListAsync(); +// +// var userPermissions = userNos.ToDictionary(x => x, _ => deviceCodes.ToList()); +// +// await _dbContext.Client.Deleteable() +// .Where(x => x.CustomCode == request.CustomCode) +// .ExecuteCommandAsync(); +// +// var data = request.DeviceCodes.Select(x => new AppointmentAreaAssignmentEntity +// { +// CustomCode = request.CustomCode, +// DeviceCode = x +// }).ToList(); +// +// await _dbContext.InsertAsync(data); +// +// +// deviceCodes = await _dbContext.Queryable() +// .Where(x => x.CustomCode == request.CustomCode).Select(x => x.DeviceCode).ToListAsync(); +// +// var devices = await _dbContext.Queryable().Where(x => deviceCodes.Contains(x.Code)).ToListAsync(); +// +// var userCurrentPermissions = userNos.ToDictionary(x => x, _ => deviceCodes.ToList()); +// +// var tasks = new List(); +// foreach (var userNo in userNos) +// { +// var before = userPermissions[userNo]; +// var current = userCurrentPermissions[userNo]; +// +// //被删除 +// var deletedItems = before.Where(x => !current.Contains(x)).ToList(); +// //新增 +// var addItems = current.Where(x => !before.Contains(x)).ToList(); +// +// if (!deletedItems.Any() && !addItems.Any()) +// { +// continue; +// } +// +// tasks.AddRange(deletedItems.Select(x => new DeviceTaskEntity +// { +// Type = DeviceTaskEnumType.Delete, +// DeviceType = DeviceTypeEnumType.Door, +// UserNo = userNo, +// DeviceUniqueNo = devices.First(item => item.Code == x).UniqueNo, +// Status = DeviceTaskStatusEnumType.Wait, +// Version = 0, +// CancellationId = 0, +// Source = DeviceTaskSourceEnumType.Appointment, +// Priority = 99 +// })); +// +// tasks.AddRange(addItems.Select(x => new DeviceTaskEntity +// { +// Type = DeviceTaskEnumType.Add, +// DeviceType = DeviceTypeEnumType.Door, +// UserNo = userNo, +// DeviceUniqueNo = devices.First(item => item.Code == x).UniqueNo, +// Status = DeviceTaskStatusEnumType.Wait, +// Version = 0, +// CancellationId = 0, +// Source = DeviceTaskSourceEnumType.Appointment, +// Priority = 99 +// })); +// } +// +// await _dbContext.InsertAsync(tasks); +// } +// +// +// //********************************************************* help methods *************************************************************** +// +// +// /// +// /// 检查编码重复 +// /// +// /// +// /// +// private async Task CheckCustomCodeDuplicateAsync(AppointmentAreaSaveRequest request) +// { +// var exists = await _dbContext.Queryable() +// .Where(x => x.CustomCode == request.CustomCode) +// .WhereIF(request.Id.HasValue, x => x.Id == request.Id) +// .AnyAsync(); +// +// exists.ThrowIfTrue("重复区域编码,请检查"); +// } +// } \ No newline at end of file diff --git a/Src/Dlhis.Visitor/Appointment/Services/Implements/AppointmentService.cs b/Src/Dlhis.Visitor/Appointment/Services/Implements/AppointmentService.cs index 345fcba3..2522ebb1 100644 --- a/Src/Dlhis.Visitor/Appointment/Services/Implements/AppointmentService.cs +++ b/Src/Dlhis.Visitor/Appointment/Services/Implements/AppointmentService.cs @@ -1,129 +1,129 @@ -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 Dlhis.Visitor.Appointment.Request; -using Dlhis.Visitor.Appointment.Response; -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.Visitor.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> GetPageAsync(AppointmentPageRequest request) - { - return await _dbContext.Queryable() - .WhereIF(request.SearchDateTimePeriod?.Start.HasValue == true && request.SearchDateTimePeriod?.End.HasValue == true, - x => x.ApplyTime >= request.SearchDateTimePeriod.Start && x.ApplyTime <= request.SearchDateTimePeriod.End) - .WhereIF(request.Search.IsPresent(), x => x.Code == request.Search || x.Name == request.Search) - .Select() - .ToPageListAsync(request); - } - - public async Task> GetAppointmentDetailsByIdAsync(long id) - { - return await _dbContext.Queryable() - .Where(x => x.AppointmentId == id) - .Select() - .ToListAsync(); - } - - public async Task ConfirmAsync(AppointmentConfirmRequest request) - { - var detail = await _dbContext.Queryable().Where(x => x.Id == request.Id).SingleAsync(); - detail.ThrowIfNull("预约信息不存在"); - - var mst = await _dbContext.Queryable().Where(x => x.Id == detail.AppointmentId).SingleAsync(); - - //当前分配的设备codes - var deviceCodes = await _dbContext.Queryable() - .Where(x => x.CustomCode == mst.AreaCustomCode) - .Select(x => x.DeviceCode) - .ToListAsync(); - - var deviceUniqueNos = await _dbContext.Queryable().Where(x => deviceCodes.Contains(x.Code)).Select(x => x.UniqueNo).ToListAsync(); - - var userNo = detail.IsExternal - ? await _dbContext.Queryable().Where(x => x.IdNo == detail.IdNo).Select(x => x.No).FirstAsync() - : await _dbContext.Queryable().Where(x => x.IdNo == detail.IdNo).Select(x => x.No).FirstAsync(); - - await _dbContext.InsertAsync(deviceUniqueNos.Select(x => new DeviceTaskEntity - { - CancellationId = 0, - DeviceType = DeviceTypeEnumType.Door, - DeviceUniqueNo = x, - Status = DeviceTaskStatusEnumType.Wait, - UserNo = userNo, - Type = DeviceTaskEnumType.Add, - Priority = 100, - Source = DeviceTaskSourceEnumType.Appointment, - Version = 0 - }).ToList()); - - detail.Status = AppointmentDetailEnumType.Arrived; - await _dbContext.UpdateAsync(detail); - } - - - //********************************************************** 用户操作 ******************************************************************* - - public async Task GetTodayByIdNoAsync(string idNo) - { - var protector = _dataProtectionProvider.CreateProtector("gainfo:external:idno"); - try - { - idNo = protector.Unprotect(idNo); - } - catch (Exception) - { - throw new UserFriendlyException("凭证有误"); - } - - var detail = await _dbContext.Queryable() - .Where(x => x.IdNo == idNo) - .Where(x => SqlFunc.DateIsSame(x.Start, DateTime.Today, DateType.Day)) - .OrderBy(x => x.Start) - .Select() - .FirstAsync(); - - return detail; - } - - public async Task> 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() - .Where(x => x.IdNo == request.IdNo) - .OrderBy(x => x.Start) - .Select() - .ToPageListAsync(request); - - return page; - } -} \ No newline at end of file +// 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 Dlhis.Visitor.Appointment.Request; +// using Dlhis.Visitor.Appointment.Response; +// 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.Visitor.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> GetPageAsync(AppointmentPageRequest request) +// { +// return await _dbContext.Queryable() +// .WhereIF(request.SearchDateTimePeriod?.Start.HasValue == true && request.SearchDateTimePeriod?.End.HasValue == true, +// x => x.ApplyTime >= request.SearchDateTimePeriod.Start && x.ApplyTime <= request.SearchDateTimePeriod.End) +// .WhereIF(request.Search.IsPresent(), x => x.Code == request.Search || x.Name == request.Search) +// .Select() +// .ToPageListAsync(request); +// } +// +// public async Task> GetAppointmentDetailsByIdAsync(long id) +// { +// return await _dbContext.Queryable() +// .Where(x => x.AppointmentId == id) +// .Select() +// .ToListAsync(); +// } +// +// public async Task ConfirmAsync(AppointmentConfirmRequest request) +// { +// var detail = await _dbContext.Queryable().Where(x => x.Id == request.Id).SingleAsync(); +// detail.ThrowIfNull("预约信息不存在"); +// +// var mst = await _dbContext.Queryable().Where(x => x.Id == detail.AppointmentId).SingleAsync(); +// +// //当前分配的设备codes +// var deviceCodes = await _dbContext.Queryable() +// .Where(x => x.CustomCode == mst.AreaCustomCode) +// .Select(x => x.DeviceCode) +// .ToListAsync(); +// +// var deviceUniqueNos = await _dbContext.Queryable().Where(x => deviceCodes.Contains(x.Code)).Select(x => x.UniqueNo).ToListAsync(); +// +// var userNo = detail.IsExternal +// ? await _dbContext.Queryable().Where(x => x.IdNo == detail.IdNo).Select(x => x.No).FirstAsync() +// : await _dbContext.Queryable().Where(x => x.IdNo == detail.IdNo).Select(x => x.No).FirstAsync(); +// +// await _dbContext.InsertAsync(deviceUniqueNos.Select(x => new DeviceTaskEntity +// { +// CancellationId = 0, +// DeviceType = DeviceTypeEnumType.Door, +// DeviceUniqueNo = x, +// Status = DeviceTaskStatusEnumType.Wait, +// UserNo = userNo, +// Type = DeviceTaskEnumType.Add, +// Priority = 100, +// Source = DeviceTaskSourceEnumType.Appointment, +// Version = 0 +// }).ToList()); +// +// detail.Status = AppointmentDetailEnumType.Arrived; +// await _dbContext.UpdateAsync(detail); +// } +// +// +// //********************************************************** 用户操作 ******************************************************************* +// +// public async Task GetTodayByIdNoAsync(string idNo) +// { +// var protector = _dataProtectionProvider.CreateProtector("gainfo:external:idno"); +// try +// { +// idNo = protector.Unprotect(idNo); +// } +// catch (Exception) +// { +// throw new UserFriendlyException("凭证有误"); +// } +// +// var detail = await _dbContext.Queryable() +// .Where(x => x.IdNo == idNo) +// .Where(x => SqlFunc.DateIsSame(x.Start, DateTime.Today, DateType.Day)) +// .OrderBy(x => x.Start) +// .Select() +// .FirstAsync(); +// +// return detail; +// } +// +// public async Task> 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() +// .Where(x => x.IdNo == request.IdNo) +// .OrderBy(x => x.Start) +// .Select() +// .ToPageListAsync(request); +// +// return page; +// } +// } \ No newline at end of file