diff --git a/Src/Dlhis.Entity/Visitor/Entity/VisitorAppointmentDetailEntity.cs b/Src/Dlhis.Entity/Visitor/Entity/VisitorAppointmentDetailEntity.cs
index 48f6a32b..ccbd5dbc 100644
--- a/Src/Dlhis.Entity/Visitor/Entity/VisitorAppointmentDetailEntity.cs
+++ b/Src/Dlhis.Entity/Visitor/Entity/VisitorAppointmentDetailEntity.cs
@@ -14,6 +14,12 @@ public class VisitorAppointmentDetailEntity : SugarBaseEntity
[SugarColumn(IsNullable = false, ColumnDescription = "父id")]
public long AppointmentId { get; set; }
+ ///
+ /// no
+ ///
+ [SugarColumn(IsNullable = false, ColumnDescription = "用户no")]
+ public string UserNo { get; set; }
+
///
/// 流水号
///
@@ -70,4 +76,4 @@ public class VisitorAppointmentDetailEntity : SugarBaseEntity
///
[SugarColumn(IsNullable = true, ColumnDescription = "备注")]
public string Remark { get; set; }
-}
+}
\ No newline at end of file
diff --git a/Src/Dlhis.Visitor/Appointment/Controllers/ApponintmentAreasController.cs b/Src/Dlhis.Visitor/Appointment/Controllers/AppointmentAreasController.cs
similarity index 87%
rename from Src/Dlhis.Visitor/Appointment/Controllers/ApponintmentAreasController.cs
rename to Src/Dlhis.Visitor/Appointment/Controllers/AppointmentAreasController.cs
index f2392cbb..fd465573 100644
--- a/Src/Dlhis.Visitor/Appointment/Controllers/ApponintmentAreasController.cs
+++ b/Src/Dlhis.Visitor/Appointment/Controllers/AppointmentAreasController.cs
@@ -1,6 +1,7 @@
using Dlhis.Visitor.Appointment.Request;
using Dlhis.Visitor.Appointment.Response;
using Dlhis.Visitor.Appointment.Services;
+using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop;
using Kurisu.Core.DataAccess.Dto;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
@@ -13,11 +14,11 @@ namespace Dlhis.Visitor.Appointment.Controllers;
[Authorize]
[Route("api/[controller]")]
[ApiController]
-public class ApponintmentAreasController : ControllerBase
+public class AppointmentAreasController : ControllerBase
{
- private readonly IApponintmentAreaService _apponintmentAreaService;
+ private readonly IAppointmentAreaService _apponintmentAreaService;
- public ApponintmentAreasController(IApponintmentAreaService apponintmentAreaService)
+ public AppointmentAreasController(IAppointmentAreaService apponintmentAreaService)
{
_apponintmentAreaService = apponintmentAreaService;
}
@@ -61,6 +62,7 @@ public class ApponintmentAreasController : ControllerBase
///
///
[HttpPost("assign")]
+ [Transactional]
public async Task AssignAsync(AppointmentAreaAssignRequest request)
{
await _apponintmentAreaService.AssignAsync(request);
diff --git a/Src/Dlhis.Visitor/Appointment/Controllers/AppointmentsController.cs b/Src/Dlhis.Visitor/Appointment/Controllers/AppointmentsController.cs
index 5923bd8c..0f4ff10b 100644
--- a/Src/Dlhis.Visitor/Appointment/Controllers/AppointmentsController.cs
+++ b/Src/Dlhis.Visitor/Appointment/Controllers/AppointmentsController.cs
@@ -10,7 +10,7 @@ using Microsoft.AspNetCore.Mvc;
namespace Dlhis.Visitor.Appointment.Controllers;
///
-/// ԤԼ
+/// 预约
///
[Authorize]
[ApiController]
@@ -25,7 +25,7 @@ public class AppointmentsController : ControllerBase
}
///
- /// ½ÓÊÜԤԼдÈë
+ /// 接受预约申请
///
///
///
@@ -39,7 +39,7 @@ public class AppointmentsController : ControllerBase
}
///
- /// ԤԼ·Öҳ
+ /// 预约申请分页
///
///
///
@@ -50,7 +50,7 @@ public class AppointmentsController : ControllerBase
}
///
- /// ȷÈϵ½´ï
+ /// 确认到达
///
///
///
@@ -61,7 +61,7 @@ public class AppointmentsController : ControllerBase
}
///
- /// ¸ù¾ÝÉí·Ý֤»ñȡµ±Ìì·ÿÍԤԼ
+ /// 根据身份证获取当天预约信息
///
///
///
@@ -69,12 +69,17 @@ public class AppointmentsController : ControllerBase
[HttpGet("today")]
public async Task GetTodayByIdNoAsync(
[FromQuery]
- [StringLength(18, MinimumLength = 18, ErrorMessage = "Éí·Ý֤´íÎó")]
- [Required(ErrorMessage = "Éí·Ý֤²»¿ÉΪ¿Õ")]string idNo)
+ [StringLength(18, MinimumLength = 18, ErrorMessage = "身份证有误")]
+ [Required(ErrorMessage = "身份证有误")]string idNo)
{
return await _appointmentService.GetTodayByIdNoAsync(idNo);
}
+ ///
+ /// 根据身份证获取预约信息分页
+ ///
+ ///
+ ///
[AllowAnonymous]
[HttpGet("idno/page")]
public async Task> GetRecordPageByIdNoAsync([FromQuery] AppointmentIdNoPageRequest request)
diff --git a/Src/Dlhis.Visitor/Appointment/Request/AppointmentConfirmRequest.cs b/Src/Dlhis.Visitor/Appointment/Request/AppointmentConfirmRequest.cs
index 240e79d2..c3cf17e5 100644
--- a/Src/Dlhis.Visitor/Appointment/Request/AppointmentConfirmRequest.cs
+++ b/Src/Dlhis.Visitor/Appointment/Request/AppointmentConfirmRequest.cs
@@ -2,5 +2,8 @@
public class AppointmentConfirmRequest
{
+ ///
+ /// 预约明细id
+ ///
public long Id { get; set; }
}
diff --git a/Src/Dlhis.Visitor/Appointment/Services/IApponintmentAreaService.cs b/Src/Dlhis.Visitor/Appointment/Services/IAppointmentAreaService.cs
similarity index 86%
rename from Src/Dlhis.Visitor/Appointment/Services/IApponintmentAreaService.cs
rename to Src/Dlhis.Visitor/Appointment/Services/IAppointmentAreaService.cs
index 71804a2d..82763945 100644
--- a/Src/Dlhis.Visitor/Appointment/Services/IApponintmentAreaService.cs
+++ b/Src/Dlhis.Visitor/Appointment/Services/IAppointmentAreaService.cs
@@ -4,14 +4,10 @@ using Kurisu.Core.DataAccess.Dto;
namespace Dlhis.Visitor.Appointment.Services;
-public interface IApponintmentAreaService : IScopeDependency
+public interface IAppointmentAreaService : IScopeDependency
{
Task> GetPageAsync(PageDto request);
-
Task SaveAsync(AppointmentAreaSaveRequest request);
-
Task DeleteAsync(long id);
-
-
Task AssignAsync(AppointmentAreaAssignRequest request);
}
\ No newline at end of file
diff --git a/Src/Dlhis.Visitor/Appointment/Services/Implements/AppointmentAreaService.cs b/Src/Dlhis.Visitor/Appointment/Services/Implements/AppointmentAreaService.cs
new file mode 100644
index 00000000..b3422518
--- /dev/null
+++ b/Src/Dlhis.Visitor/Appointment/Services/Implements/AppointmentAreaService.cs
@@ -0,0 +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.Utils.Extensions;
+using Kurisu.Core.DataAccess.Dto;
+using Kurisu.SqlSugar.Extensions;
+using Kurisu.SqlSugar.Services;
+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.FlowId == y.FlowId)
+ .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 3942964b..bfe29160 100644
--- a/Src/Dlhis.Visitor/Appointment/Services/Implements/AppointmentService.cs
+++ b/Src/Dlhis.Visitor/Appointment/Services/Implements/AppointmentService.cs
@@ -39,15 +39,12 @@ public class AppointmentService : IAppointmentService
area.ThrowIfNull("预约区域不存在");
var where = LinqExpressionExtensions.False();
- request.Items.ForEach(item =>
- {
- where = where.Or(x => !(x.End < request.Start || x.Start > request.End)).And(x => x.IdNo == item.IdNo);
- });
+ request.Items.ForEach(item => { where = where.Or(x => !(x.End < request.Start || x.Start > request.End)).And(x => x.IdNo == item.IdNo); });
var existsDetails = await _dbContext.Queryable()
- .Where(where)
- .Where(x => x.Status == AppointmentDetailEnumType.Wait || x.Status == AppointmentDetailEnumType.Arrived)
- .ToListAsync();
+ .Where(where)
+ .Where(x => x.Status == AppointmentDetailEnumType.Wait || x.Status == AppointmentDetailEnumType.Arrived)
+ .ToListAsync();
existsDetails.ThrowIfExists($"{existsDetails.Select(x => x.Name).Join(",")}存在预约时间冲突,请检查");
@@ -65,7 +62,8 @@ public class AppointmentService : IAppointmentService
foreach (var item in request.Items)
{
- var isExternal = !await _dbContext.Queryable().Where(x => x.IdNo == item.IdNo).AnyAsync();
+ var no = await _dbContext.Queryable().Where(x => x.IdNo == item.IdNo).Select(x => x.No).SingleAsync();
+ var isExternal = no.IsEmpty();
if (isExternal)
{
var gainfoExternal = await _dbContext.Queryable().Where(x => x.IdNo == item.IdNo).FirstAsync();
@@ -89,10 +87,13 @@ public class AppointmentService : IAppointmentService
await _dbContext.UpdateAsync(gainfoExternal);
}
+
+ no = gainfoExternal.No;
}
var detail = new VisitorAppointmentDetailEntity
{
+ UserNo = no,
AppointmentId = id,
FlowId = request.FlowId,
Start = request.Start,
@@ -113,7 +114,7 @@ public class AppointmentService : IAppointmentService
{
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)
+ 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);
@@ -132,7 +133,9 @@ public class AppointmentService : IAppointmentService
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).FirstAsync();
+ 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)
@@ -153,7 +156,8 @@ public class AppointmentService : IAppointmentService
UserNo = userNo,
Type = DeviceTaskEnumType.Add,
Priority = 100,
- Version = 0,
+ Source = DeviceTaskSourceEnumType.Appointment,
+ Version = 0
}).ToList());
detail.Status = AppointmentDetailEnumType.Arrived;
@@ -176,11 +180,11 @@ public class AppointmentService : IAppointmentService
}
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();
+ .Where(x => x.IdNo == idNo)
+ .Where(x => SqlFunc.DateIsSame(x.Start, DateTime.Today, DateType.Day))
+ .OrderBy(x => x.Start)
+ .Select()
+ .FirstAsync();
return detail;
}
@@ -198,11 +202,11 @@ public class AppointmentService : IAppointmentService
}
var page = await _dbContext.Queryable()
- .Where(x => x.IdNo == request.IdNo)
- .OrderBy(x => x.Start)
- .Select()
- .ToPageListAsync(request);
+ .Where(x => x.IdNo == request.IdNo)
+ .OrderBy(x => x.Start)
+ .Select()
+ .ToPageListAsync(request);
return page;
}
-}
+}
\ No newline at end of file
diff --git a/Src/Dlhis.Visitor/Appointment/Services/Implements/ApponintmentAreaService.cs b/Src/Dlhis.Visitor/Appointment/Services/Implements/ApponintmentAreaService.cs
deleted file mode 100644
index b67159aa..00000000
--- a/Src/Dlhis.Visitor/Appointment/Services/Implements/ApponintmentAreaService.cs
+++ /dev/null
@@ -1,93 +0,0 @@
-using Dlhis.Entity.Visitor.Entity;
-using Dlhis.Visitor.Appointment.Request;
-using Dlhis.Visitor.Appointment.Response;
-using Kurisu.AspNetCore.Utils.Extensions;
-using Kurisu.Core.DataAccess.Dto;
-using Kurisu.SqlSugar.Extensions;
-using Kurisu.SqlSugar.Services;
-using Mapster;
-
-namespace Dlhis.Visitor.Appointment.Services.Implements;
-
-public class ApponintmentAreaService : IApponintmentAreaService
-{
- private readonly IDbContext _dbContext;
-
- public ApponintmentAreaService(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)
- {
- 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);
- }
-
-
- //********************************************************* 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("重复区域编码,请检查");
- }
-}