From 49b6aa6e82ed7f712fb18f3a60ad784744ee3d5e Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 7 May 2024 15:06:54 +0800 Subject: [PATCH 01/15] =?UTF-8?q?fix=20=E8=B7=AF=E7=94=B1=E5=89=8D?= =?UTF-8?q?=E7=BC=80=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.InfoCheck/Controllers/FaceController.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Src/Dlhis.InfoCheck/Controllers/FaceController.cs b/Src/Dlhis.InfoCheck/Controllers/FaceController.cs index 030057cd..93b25d21 100644 --- a/Src/Dlhis.InfoCheck/Controllers/FaceController.cs +++ b/Src/Dlhis.InfoCheck/Controllers/FaceController.cs @@ -16,7 +16,7 @@ namespace Dlhis.InfoCheck.Controllers; /// [Authorize] [ApiController] -[Route("[controller]")] +[Route("api/[controller]")] public class FaceController : ControllerBase { /// @@ -101,4 +101,4 @@ public class FaceController : ControllerBase IsSelf = isSelf }; } -} +} \ No newline at end of file From e5e190114354fbf5ef02f74a46e958fec7692332 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 7 May 2024 15:17:23 +0800 Subject: [PATCH 02/15] =?UTF-8?q?fix=20linux=E4=BE=9D=E8=B5=96=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.InfoCheck/Dlhis.InfoCheck.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/Src/Dlhis.InfoCheck/Dlhis.InfoCheck.csproj b/Src/Dlhis.InfoCheck/Dlhis.InfoCheck.csproj index cad3976a..50761189 100644 --- a/Src/Dlhis.InfoCheck/Dlhis.InfoCheck.csproj +++ b/Src/Dlhis.InfoCheck/Dlhis.InfoCheck.csproj @@ -13,6 +13,7 @@ + From 98b7ec90beb887ebbd77ef0272a07faf979a7015 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 7 May 2024 18:10:43 +0800 Subject: [PATCH 03/15] =?UTF-8?q?fix=20=E4=BE=9D=E8=B5=96=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.InfoCheck/Controllers/FaceController.cs | 8 +++----- Src/Dlhis.InfoCheck/Dlhis.InfoCheck.csproj | 6 +++--- Src/Dlhis.InfoCheck/Properties/launchSettings.json | 9 +++++++++ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Src/Dlhis.InfoCheck/Controllers/FaceController.cs b/Src/Dlhis.InfoCheck/Controllers/FaceController.cs index 93b25d21..0223f4d7 100644 --- a/Src/Dlhis.InfoCheck/Controllers/FaceController.cs +++ b/Src/Dlhis.InfoCheck/Controllers/FaceController.cs @@ -79,11 +79,9 @@ public class FaceController : ControllerBase using var secondStream = new MemoryStream(secondBase64Bytes); using var secondBitmap = SKBitmap.Decode(secondStream); - using var recognizer = new FaceRecognizer(new FaceRecognizeConfig - { - //¶ÔӦãÐֵ FaceType.Normal£º0.62¡¢FaceType.Mask£º0.4¡¢FaceType.Light£º0.55 - FaceType = FaceType.Normal - }); + //¶ÔӦãÐֵ FaceType.Normal£º0.62¡¢FaceType.Mask£º0.4¡¢FaceType.Light£º0.55 + //FaceType = FaceType.Normal, + using var recognizer = new FaceRecognizer(); using var faceDetector = new FaceDetector(); using var faceMark = new FaceLandmarker(); diff --git a/Src/Dlhis.InfoCheck/Dlhis.InfoCheck.csproj b/Src/Dlhis.InfoCheck/Dlhis.InfoCheck.csproj index 50761189..8c8ffec5 100644 --- a/Src/Dlhis.InfoCheck/Dlhis.InfoCheck.csproj +++ b/Src/Dlhis.InfoCheck/Dlhis.InfoCheck.csproj @@ -12,12 +12,12 @@ - - + + - + diff --git a/Src/Dlhis.InfoCheck/Properties/launchSettings.json b/Src/Dlhis.InfoCheck/Properties/launchSettings.json index 49b1f9a2..11b15235 100644 --- a/Src/Dlhis.InfoCheck/Properties/launchSettings.json +++ b/Src/Dlhis.InfoCheck/Properties/launchSettings.json @@ -24,6 +24,15 @@ "ASPNETCORE_URLS": "http://+:80" }, "publishAllPorts": true + }, + "WSL": { + "commandName": "WSL2", + "launchUrl": "http://localhost:5048/weatherforecast", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development", + "ASPNETCORE_URLS": "http://localhost:5048" + }, + "distributionName": "" } }, "$schema": "https://json.schemastore.org/launchsettings.json", From 6b2978dc37dcfc55b1d26140ca6a5eaae3f06ace Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 7 May 2024 18:31:30 +0800 Subject: [PATCH 04/15] =?UTF-8?q?fix=20=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.InfoCheck/Dlhis.InfoCheck.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/Src/Dlhis.InfoCheck/Dlhis.InfoCheck.csproj b/Src/Dlhis.InfoCheck/Dlhis.InfoCheck.csproj index 8c8ffec5..6595699d 100644 --- a/Src/Dlhis.InfoCheck/Dlhis.InfoCheck.csproj +++ b/Src/Dlhis.InfoCheck/Dlhis.InfoCheck.csproj @@ -12,7 +12,6 @@ - From f3dec0ccdfbdc32bd50c4bfed7f37bf0633833a2 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 7 May 2024 18:50:33 +0800 Subject: [PATCH 05/15] =?UTF-8?q?fix=20=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.InfoCheck/Dlhis.InfoCheck.csproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Src/Dlhis.InfoCheck/Dlhis.InfoCheck.csproj b/Src/Dlhis.InfoCheck/Dlhis.InfoCheck.csproj index 6595699d..0c4f6b20 100644 --- a/Src/Dlhis.InfoCheck/Dlhis.InfoCheck.csproj +++ b/Src/Dlhis.InfoCheck/Dlhis.InfoCheck.csproj @@ -12,7 +12,9 @@ + + From 4046d54b2a0c6b2ec2e27812acf4871cf4f1fdd4 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 9 May 2024 10:51:39 +0800 Subject: [PATCH 06/15] fix . --- Src/Dlhis.InfoCheck/Dlhis.InfoCheck.csproj | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Src/Dlhis.InfoCheck/Dlhis.InfoCheck.csproj b/Src/Dlhis.InfoCheck/Dlhis.InfoCheck.csproj index 0c4f6b20..e60f1e4e 100644 --- a/Src/Dlhis.InfoCheck/Dlhis.InfoCheck.csproj +++ b/Src/Dlhis.InfoCheck/Dlhis.InfoCheck.csproj @@ -11,10 +11,7 @@ - - - - + From 4e8f50b544f948fb48f8496374842ae117d34225 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 9 May 2024 11:21:56 +0800 Subject: [PATCH 07/15] =?UTF-8?q?fix=20docker=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.InfoCheck/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/Dlhis.InfoCheck/Dockerfile b/Src/Dlhis.InfoCheck/Dockerfile index c9f9f586..5ef26083 100644 --- a/Src/Dlhis.InfoCheck/Dockerfile +++ b/Src/Dlhis.InfoCheck/Dockerfile @@ -1,6 +1,6 @@ #See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. -FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base +FROM 192.168.199.115/library/aspnet:6.0 AS base WORKDIR /app EXPOSE 80 From 56ac694d85316e793d90a3ee33c93408fba1145b Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 9 May 2024 11:24:20 +0800 Subject: [PATCH 08/15] fix . --- Src/Dlhis.InfoCheck/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/Dlhis.InfoCheck/Dockerfile b/Src/Dlhis.InfoCheck/Dockerfile index 5ef26083..80cfe4d0 100644 --- a/Src/Dlhis.InfoCheck/Dockerfile +++ b/Src/Dlhis.InfoCheck/Dockerfile @@ -1,6 +1,6 @@ #See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. -FROM 192.168.199.115/library/aspnet:6.0 AS base +FROM 192.168.199.124/library/aspnet:6.0 AS base WORKDIR /app EXPOSE 80 From 234a5d29844cbcc150fe084ee645aa37db5e9b2a Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 21 May 2024 17:07:28 +0800 Subject: [PATCH 09/15] =?UTF-8?q?fix=20=E8=AE=BF=E5=AE=A2=E9=A2=84?= =?UTF-8?q?=E7=BA=A6=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entity/VisitorAppointmentDetailEntity.cs | 8 +- ...oller.cs => AppointmentAreasController.cs} | 8 +- .../Controllers/AppointmentsController.cs | 19 +- .../Request/AppointmentConfirmRequest.cs | 3 + ...aService.cs => IAppointmentAreaService.cs} | 6 +- .../Implements/AppointmentAreaService.cs | 163 ++++++++++++++++++ .../Services/Implements/AppointmentService.cs | 46 ++--- .../Implements/ApponintmentAreaService.cs | 93 ---------- 8 files changed, 216 insertions(+), 130 deletions(-) rename Src/Dlhis.Visitor/Appointment/Controllers/{ApponintmentAreasController.cs => AppointmentAreasController.cs} (87%) rename Src/Dlhis.Visitor/Appointment/Services/{IApponintmentAreaService.cs => IAppointmentAreaService.cs} (86%) create mode 100644 Src/Dlhis.Visitor/Appointment/Services/Implements/AppointmentAreaService.cs delete mode 100644 Src/Dlhis.Visitor/Appointment/Services/Implements/ApponintmentAreaService.cs 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("重复区域编码,请检查"); - } -} From 03f732c412c8f8a3f69c8a1b4bbcdbd3ee56c7dd Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 21 May 2024 17:09:54 +0800 Subject: [PATCH 10/15] =?UTF-8?q?fix=20=E8=AE=BE=E5=A4=87=E6=96=B9?= =?UTF-8?q?=E5=90=91,=E4=BB=A3=E7=A0=81=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Device/Request/DeviceSaveRequest.cs | 4 +- .../Device/Response/DevicePageResponse.cs | 2 +- .../Implements/DeviceConnectService.cs | 16 ++-- .../Implements/DevicePermissionService.cs | 84 +++++++++---------- Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs | 4 +- .../Device/Entities/DeviceTaskEntity.cs | 8 +- .../Enums/DeviceDeployDirectionEnumType.cs | 22 +++++ .../Device/Enums/DeviceTaskSourceEnumType.cs | 16 ++++ .../Sys/Enums/AssignTypeEnumType.cs | 4 +- 9 files changed, 98 insertions(+), 62 deletions(-) create mode 100644 Src/Dlhis.Entity/Device/Enums/DeviceDeployDirectionEnumType.cs create mode 100644 Src/Dlhis.Entity/Device/Enums/DeviceTaskSourceEnumType.cs diff --git a/Src/Dlhis.Basic/Device/Request/DeviceSaveRequest.cs b/Src/Dlhis.Basic/Device/Request/DeviceSaveRequest.cs index 7dce3210..be1d08ae 100644 --- a/Src/Dlhis.Basic/Device/Request/DeviceSaveRequest.cs +++ b/Src/Dlhis.Basic/Device/Request/DeviceSaveRequest.cs @@ -56,9 +56,9 @@ public class DeviceSaveRequest : IValidatableObject public string DeployPosition { get; set; } /// - /// 部署方向 + /// 部署方向 DeviceDeployDirectionEnumType /// - public string DeployDirection { get; set; } + public DeviceDeployDirectionEnumType? DeployDirection { get; set; } /// /// 连接信息 diff --git a/Src/Dlhis.Basic/Device/Response/DevicePageResponse.cs b/Src/Dlhis.Basic/Device/Response/DevicePageResponse.cs index 88f05f43..20d413df 100644 --- a/Src/Dlhis.Basic/Device/Response/DevicePageResponse.cs +++ b/Src/Dlhis.Basic/Device/Response/DevicePageResponse.cs @@ -66,7 +66,7 @@ public class DevicePageResponse /// /// 部署方向 /// - public string DeployDirection { get; set; } + public DeviceDeployDirectionEnumType? DeployDirection { get; set; } /// /// 模板code diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceConnectService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceConnectService.cs index cf295760..ce4487f4 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceConnectService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceConnectService.cs @@ -71,7 +71,7 @@ public class DeviceConnectService : IDeviceConnectService if (request.BusinessPlaceCode.HasValue) { var businessPlace = await _dbContext.Queryable().Where(x => x.Code == request.BusinessPlaceCode).FirstAsync(); - businessPlace.ThrowIfNull("营业点不存在,无法设置到设备注册信息中"); + businessPlace.ThrowIfNull("营业点不存在,无法设置到设备注册信息中"); } //更新营业点信息 @@ -98,8 +98,8 @@ public class DeviceConnectService : IDeviceConnectService var ipInfo = request.ConnectionInfo.ToObject(); //超时时间 - var CancellationTokenSource = new CancellationTokenSource(300); - await new TcpClient().ConnectAsync(IPAddress.Parse(ipInfo.IP), ipInfo.Port, CancellationTokenSource.Token); + var cancellationTokenSource = new CancellationTokenSource(300); + await new TcpClient().ConnectAsync(IPAddress.Parse(ipInfo.IP), ipInfo.Port, cancellationTokenSource.Token); return true; } @@ -123,8 +123,8 @@ public class DeviceConnectService : IDeviceConnectService private async Task GetEnableDeviceAsync(string uniqueNo, bool checkExists = true, string deployPlace = "", string tenantId = "") { var device = await _dbContext.Queryable() - .Where(x => x.UniqueNo == uniqueNo) - .FirstAsync(); + .Where(x => x.UniqueNo == uniqueNo) + .FirstAsync(); if (checkExists) { @@ -135,7 +135,7 @@ public class DeviceConnectService : IDeviceConnectService { if (device == null) { - device = new DeviceEntity() + device = new DeviceEntity { Code = Guid.NewGuid(), ConnectionInfo = string.Empty, @@ -146,7 +146,7 @@ public class DeviceConnectService : IDeviceConnectService Funcs = new List(), DeployPlace = deployPlace, HeartbeatInterval = 0, - DeployDirection = string.Empty, + DeployDirection = null, Enable = true, DeployPosition = string.Empty, CreatedBy = 1, @@ -161,4 +161,4 @@ public class DeviceConnectService : IDeviceConnectService return device; } -} +} \ No newline at end of file diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs index 7a36922d..1599fae0 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs @@ -1,13 +1,11 @@ using Dlhis.Basic.Device.Dtos; using Dlhis.Basic.Device.Request; -using Dlhis.Basic.Device.Response; using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Device.Entities; using Dlhis.Entity.Device.Enums; using Dlhis.Entity.Sys.Entities; using Dlhis.Entity.Sys.Enums; using Kurisu.AspNetCore.Utils.Extensions; -using Kurisu.Core.DataAccess.Dto; using Kurisu.Core.DataAccess.Entity; using Kurisu.Core.User.Abstractions; using Kurisu.SqlSugar.Services; @@ -26,38 +24,36 @@ public class DevicePermissionService : IDevicePermissionService _currentUser = currentUser; } - public async Task AssignAsync(DevicePermissionSaveReuqest reuqest) + public async Task AssignAsync(DevicePermissionSaveReuqest request) { + var tenantId = request.AssignType == AssignTypeEnumType.Department ? request.TenantId : _currentUser.GetStringTenantId(); + await GenerateDeviceTasksAsync(async () => { - var tenantId = reuqest.AssignType == AssignTypeEnumType.Department ? reuqest.TenantId : _currentUser.GetStringTenantId(); - //删除当前匹配的基地权限 var p = await _dbContext.Queryable() - .Where(x => x.AssignType == reuqest.AssignType) - .Where(x => x.AssignValue == reuqest.AssignValue) - .Where(x => x.UniqueType == reuqest.UniqueType) - .Where(x => x.TenantId == tenantId) - .ToListAsync(); + .Where(x => x.AssignType == request.AssignType) + .Where(x => x.AssignValue == request.AssignValue) + .Where(x => x.UniqueType == request.UniqueType) + .Where(x => x.TenantId == tenantId) + .ToListAsync(); await _dbContext.DeleteReallyAsync(p); //保存配置的权限 - if (reuqest.Codes.IsPresent()) + if (request.Codes.IsPresent()) { - var devicePermissions = reuqest.Codes.Select(code => new DevicePermissionEntity + var devicePermissions = request.Codes.Select(code => new DevicePermissionEntity { - AssignType = reuqest.AssignType, - AssignValue = reuqest.AssignValue, - UniqueType = reuqest.UniqueType, + AssignType = request.AssignType, + AssignValue = request.AssignValue, + UniqueType = request.UniqueType, UniqueValue = code, TenantId = tenantId - }) - .ToList(); + }).ToList(); await _dbContext.InsertAsync(devicePermissions); } - }, null); } @@ -277,8 +273,7 @@ public class DevicePermissionService : IDevicePermissionService CancellationId = 0, Version = 0, TenantId = x.TenantId - }) - .ToList(); + }).ToList(); await _dbContext.InsertAsync(tasks); } @@ -288,11 +283,11 @@ public class DevicePermissionService : IDevicePermissionService var all = await GetAssignDeviceCodesAsync(userNo); return await _dbContext.Queryable() - .Where(x => x.Enable) - .Where(x => x.Type == DeviceTypeEnumType.Meal) - .Where(x => all.Contains(x.Code)) - .Select(x => x.UniqueNo) - .ToListAsync(); + .Where(x => x.Enable) + .Where(x => x.Type == DeviceTypeEnumType.Meal) + .Where(x => all.Contains(x.Code)) + .Select(x => x.UniqueNo) + .ToListAsync(); } @@ -307,7 +302,7 @@ public class DevicePermissionService : IDevicePermissionService var deviceRegistries = await _dbContext.Queryable().Where(x => !SqlFunc.IsNullOrEmpty(x.BusinessPlaceCode)).ToListAsync(); var gainfo = await _dbContext.Queryable().Where(x => x.No == userNo).SingleAsync() - ?? await _dbContext.Queryable().AS("GainfoLeave").Where(x => x.No == userNo).SingleAsync(); + ?? await _dbContext.Queryable().AS("GainfoLeave").Where(x => x.No == userNo).SingleAsync(); var gainfoGroups = await _dbContext.Queryable().ToListAsync(); var devicePermissions = await _dbContext.Queryable().ToListAsync(); @@ -349,8 +344,8 @@ public class DevicePermissionService : IDevicePermissionService } private static List GetAssignCodesInternal( - List devicePermissions, List deviceGroups, - DeviceAssignmentTypeEnumType uniqueType, AssignTypeEnumType assignType, string assignValue) + List devicePermissions, List deviceGroups, + DeviceAssignmentTypeEnumType uniqueType, AssignTypeEnumType assignType, string assignValue) { var tenantDevicePermissions = devicePermissions .Where(x => x.UniqueType == uniqueType) @@ -365,10 +360,7 @@ public class DevicePermissionService : IDevicePermissionService { //开始递归处理 var tops = deviceGroups.Where(x => !x.PCode.HasValue).ToList(); - tops.ForEach(x => - { - RecursionGetNext(x, deviceGroups, tenantDevicePermissions, tenantDevicePermissions.SelectMany(item => item.Codes).Contains(x.Code)); - }); + tops.ForEach(x => { RecursionGetNext(x, deviceGroups, tenantDevicePermissions, tenantDevicePermissions.SelectMany(item => item.Codes).Contains(x.Code)); }); } return tenantDevicePermissions.GroupBy(x => x.Tenant).Select(x => @@ -391,6 +383,7 @@ public class DevicePermissionService : IDevicePermissionService { result.Add(new UserTenantDeviceCodeDto { Tenant = item.TenantId, Codes = new List { item.Code } }); } + RecursionGetNext(item, deviceGroups, result, result.SelectMany(x => x.Codes).Contains(item.Code)); } } @@ -435,7 +428,7 @@ public class DevicePermissionService : IDevicePermissionService List deviceGroupRelationships, List deviceRegistries, List devices - ) + ) { var userNo = gainfo.No; var deviceDtos = new List(); @@ -492,18 +485,18 @@ public class DevicePermissionService : IDevicePermissionService Codes = x.Select(item => item.DeviceCode).Distinct().ToList() }); - var placeGroup = deviceRegistries.Where(x => businessPlaceCodes.Contains(x.BusinessPlaceCode!.Value)).GroupBy(x => x.TenantId) - .Select(x => - { - var currentDeviceUniqueNos = x.Select(item => item.DeviceUniqueNo).ToList(); + var placeGroup = deviceRegistries.Where(x => businessPlaceCodes.Contains(x.BusinessPlaceCode!.Value)) + .GroupBy(x => x.TenantId) + .Select(x => + { + var currentDeviceUniqueNos = x.Select(item => item.DeviceUniqueNo).ToList(); - return new UserTenantDeviceCodeDto - { - Tenant = x.Key, - Codes = devices.Where(d => currentDeviceUniqueNos.Contains(d.UniqueNo)).Select(d => d.Code).Distinct().ToList() - }; - }) - .ToList(); + return new UserTenantDeviceCodeDto + { + Tenant = x.Key, + Codes = devices.Where(d => currentDeviceUniqueNos.Contains(d.UniqueNo)).Select(d => d.Code).Distinct().ToList() + }; + }).ToList(); deviceDtos.AddRange(deviceCodesByGroup); deviceDtos.AddRange(placeGroup); @@ -512,7 +505,6 @@ public class DevicePermissionService : IDevicePermissionService { Tenant = x.Key, Codes = x.SelectMany(item => item.Codes).Distinct().ToList() - }).ToList(); } -} +} \ No newline at end of file diff --git a/Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs b/Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs index ed046e71..92a6dd54 100644 --- a/Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs +++ b/Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs @@ -65,8 +65,8 @@ public class DeviceEntity : SugarBaseEntity, ITenantId /// /// 部署方向 /// - [SugarColumn(ColumnDescription = "部署方向")] - public string DeployDirection { get; set; } + [SugarColumn(ColumnDescription = "部署方向", ColumnDataType = "varchar(50)", SqlParameterDbType = typeof(EnumToStringConvert))] + public DeviceDeployDirectionEnumType? DeployDirection { get; set; } /// /// 模板code diff --git a/Src/Dlhis.Entity/Device/Entities/DeviceTaskEntity.cs b/Src/Dlhis.Entity/Device/Entities/DeviceTaskEntity.cs index 56af07d6..60b50883 100644 --- a/Src/Dlhis.Entity/Device/Entities/DeviceTaskEntity.cs +++ b/Src/Dlhis.Entity/Device/Entities/DeviceTaskEntity.cs @@ -65,6 +65,12 @@ public class DeviceTaskEntity : SugarBaseEntity, ITenantId, IVersion [SugarColumn(DefaultValue = "0")] public long CancellationId { get; set; } = 0; + /// + /// 任务来源 + /// + [SugarColumn(IsNullable = true, ColumnDataType = "varchar(50)", SqlParameterDbType = typeof(EnumToStringConvert))] + public DeviceTaskSourceEnumType? Source { get; set; } + /// /// 优先级 /// @@ -73,4 +79,4 @@ public class DeviceTaskEntity : SugarBaseEntity, ITenantId, IVersion public string TenantId { get; set; } -} +} \ No newline at end of file diff --git a/Src/Dlhis.Entity/Device/Enums/DeviceDeployDirectionEnumType.cs b/Src/Dlhis.Entity/Device/Enums/DeviceDeployDirectionEnumType.cs new file mode 100644 index 00000000..0a26e8c4 --- /dev/null +++ b/Src/Dlhis.Entity/Device/Enums/DeviceDeployDirectionEnumType.cs @@ -0,0 +1,22 @@ +using System.ComponentModel; + +namespace Dlhis.Entity.Device.Enums; + +/// +/// 设备部署方向 +/// +[Description("设备部署方向")] +public enum DeviceDeployDirectionEnumType +{ + /// + /// 进 + /// + [Description("进")] + Entry = 10, + + /// + /// 出 + /// + [Description("出")] + Exit = 20 +} \ No newline at end of file diff --git a/Src/Dlhis.Entity/Device/Enums/DeviceTaskSourceEnumType.cs b/Src/Dlhis.Entity/Device/Enums/DeviceTaskSourceEnumType.cs new file mode 100644 index 00000000..58cab179 --- /dev/null +++ b/Src/Dlhis.Entity/Device/Enums/DeviceTaskSourceEnumType.cs @@ -0,0 +1,16 @@ +using System.ComponentModel; + +namespace Dlhis.Entity.Device.Enums; + +/// +/// 设备任务来源 +/// +[Description("设备任务来源")] +public enum DeviceTaskSourceEnumType +{ + /// + /// 预约 + /// + [Description("预约")] + Appointment = 10, +} \ No newline at end of file diff --git a/Src/Dlhis.Entity/Sys/Enums/AssignTypeEnumType.cs b/Src/Dlhis.Entity/Sys/Enums/AssignTypeEnumType.cs index c4dcdf1b..5a1c4ffd 100644 --- a/Src/Dlhis.Entity/Sys/Enums/AssignTypeEnumType.cs +++ b/Src/Dlhis.Entity/Sys/Enums/AssignTypeEnumType.cs @@ -36,5 +36,5 @@ public enum AssignTypeEnumType /// 租户/基地 /// [Description("租户/基地")] - Tenant = 5, -} + Tenant = 5 +} \ No newline at end of file From 99aa2a71a288b2bd2840b12f88b9620b32b973c3 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Wed, 22 May 2024 16:39:08 +0800 Subject: [PATCH 11/15] =?UTF-8?q?feat=20=E9=A4=90=E8=A1=A5=E4=BD=99?= =?UTF-8?q?=E9=A2=9D=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MealSupplementsRecordController.cs | 13 ++- .../MealSupplementInitImportRequest.cs | 15 ++++ .../Request/MealSupplementRecordMyRequest.cs | 7 +- .../Services/IMealSupplementRecordService.cs | 2 + .../Implements/MealSupplementRecordService.cs | 83 +++++++++++++++++-- 5 files changed, 112 insertions(+), 8 deletions(-) create mode 100644 Src/Dlhis.Canteen/MealSupplementRecord/Request/MealSupplementInitImportRequest.cs diff --git a/Src/Dlhis.Canteen/MealSupplementRecord/Controller/MealSupplementsRecordController.cs b/Src/Dlhis.Canteen/MealSupplementRecord/Controller/MealSupplementsRecordController.cs index 173cff3b..fcf64442 100644 --- a/Src/Dlhis.Canteen/MealSupplementRecord/Controller/MealSupplementsRecordController.cs +++ b/Src/Dlhis.Canteen/MealSupplementRecord/Controller/MealSupplementsRecordController.cs @@ -1,6 +1,7 @@ using Dlhis.Canteen.MealSupplementRecord.Request; using Dlhis.Canteen.MealSupplementRecord.Response; using Dlhis.Canteen.MealSupplementRecord.Services; +using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop; using Kurisu.Core.DataAccess.Dto; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -44,4 +45,14 @@ public class MealSupplementsRecordController { return await _mealSupplementRecordService.GetMyMealSupplementRecords(request); } -} + + /// + /// 期初餐补余额导入 + /// + [HttpPost("init/import")] + [Transactional] + public async Task InitImportAsync(List requests) + { + await _mealSupplementRecordService.InitImportAsync(requests); + } +} \ No newline at end of file diff --git a/Src/Dlhis.Canteen/MealSupplementRecord/Request/MealSupplementInitImportRequest.cs b/Src/Dlhis.Canteen/MealSupplementRecord/Request/MealSupplementInitImportRequest.cs new file mode 100644 index 00000000..efe33828 --- /dev/null +++ b/Src/Dlhis.Canteen/MealSupplementRecord/Request/MealSupplementInitImportRequest.cs @@ -0,0 +1,15 @@ +using System.ComponentModel.DataAnnotations; + +namespace Dlhis.Canteen.MealSupplementRecord.Request; + +public class MealSupplementInitImportRequest +{ + [Required(ErrorMessage = "工号不能为空")] + public string Code { get; set; } + + /// + /// 余额 + /// + [Range(1, int.MaxValue, ErrorMessage = "余额有误")] + public decimal Balance { get; set; } +} \ No newline at end of file diff --git a/Src/Dlhis.Canteen/MealSupplementRecord/Request/MealSupplementRecordMyRequest.cs b/Src/Dlhis.Canteen/MealSupplementRecord/Request/MealSupplementRecordMyRequest.cs index b5bf1d15..38cbf6ca 100644 --- a/Src/Dlhis.Canteen/MealSupplementRecord/Request/MealSupplementRecordMyRequest.cs +++ b/Src/Dlhis.Canteen/MealSupplementRecord/Request/MealSupplementRecordMyRequest.cs @@ -9,8 +9,11 @@ public class MealSupplementRecordMyRequest : IValidatableObject public IEnumerable Validate(ValidationContext validationContext) { - SearchDateTimePeriod.End = SearchDateTimePeriod.End.Value.AddDays(1).AddSeconds(-1); + if (SearchDateTimePeriod.End.HasValue) + { + SearchDateTimePeriod.End = SearchDateTimePeriod.End.Value.AddDays(1).AddSeconds(-1); + } yield break; } -} +} \ No newline at end of file diff --git a/Src/Dlhis.Canteen/MealSupplementRecord/Services/IMealSupplementRecordService.cs b/Src/Dlhis.Canteen/MealSupplementRecord/Services/IMealSupplementRecordService.cs index a14785b9..0ca74ff9 100644 --- a/Src/Dlhis.Canteen/MealSupplementRecord/Services/IMealSupplementRecordService.cs +++ b/Src/Dlhis.Canteen/MealSupplementRecord/Services/IMealSupplementRecordService.cs @@ -9,4 +9,6 @@ public interface IMealSupplementRecordService : IScopeDependency Task> GetPageAsync(MealSupplementRecordRequest request); Task GetMyMealSupplementRecords(MealSupplementRecordMyRequest request); + + Task InitImportAsync(List requests); } diff --git a/Src/Dlhis.Canteen/MealSupplementRecord/Services/Implements/MealSupplementRecordService.cs b/Src/Dlhis.Canteen/MealSupplementRecord/Services/Implements/MealSupplementRecordService.cs index 1cb3ec82..35b8c7ba 100644 --- a/Src/Dlhis.Canteen/MealSupplementRecord/Services/Implements/MealSupplementRecordService.cs +++ b/Src/Dlhis.Canteen/MealSupplementRecord/Services/Implements/MealSupplementRecordService.cs @@ -3,7 +3,9 @@ using Dlhis.Canteen.MealSupplementRecord.Response; using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Basic.Enums; using Dlhis.Entity.Canteen.Entities; +using Dlhis.Entity.Canteen.Enums; using Dlhis.Sys.Api; +using Kurisu.AspNetCore.Utils; using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.DataAccess.Dto; using Kurisu.Core.User.Abstractions; @@ -15,7 +17,6 @@ namespace Dlhis.Canteen.MealSupplementRecord.Services.Implements; public class MealSupplementRecordService : IMealSupplementRecordService { - private readonly IDbContext _dbContext; private readonly ICurrentUser _currentUser; private readonly ITenantApi _tenantApi; @@ -36,8 +37,8 @@ public class MealSupplementRecordService : IMealSupplementRecordService .WhereIF(request.Workplace.IsPresent(), x => x.Workplace == request.Workplace) .WhereIF(request.Factory.IsPresent(), x => x.Factory == request.Factory) .WhereIF(request.DateTimePeriod?.Start.HasValue == true - && request.DateTimePeriod?.End.HasValue == true, - x => x.Date >= request.DateTimePeriod.Start && x.Date <= request.DateTimePeriod.End) + && request.DateTimePeriod?.End.HasValue == true, + x => x.Date >= request.DateTimePeriod.Start && x.Date <= request.DateTimePeriod.End) .WhereIF(request.Search.IsPresent(), (x, ga) => x.Code == request.Search || ga.Name == request.Search) .Select((x, ga) => new MealSupplementRecordResponse { @@ -70,7 +71,6 @@ public class MealSupplementRecordService : IMealSupplementRecordService } catch (Exception) { - } @@ -110,4 +110,77 @@ public class MealSupplementRecordService : IMealSupplementRecordService Items = data, }; } -} + + public async Task InitImportAsync(List requests) + { + var today = DateTime.Now.Date; + foreach (var request in requests) + { + var gainfo = await _dbContext.Queryable().Where(x => x.Code == request.Code).FirstAsync(); + if (gainfo == null) + { + continue; + } + + await CommonHelper.RetryAsync(async () => + { + var mealUser = await _dbContext.Queryable().Where(x => x.UserCode == request.Code).FirstAsync(); + if (mealUser == null) + { + mealUser = new GainfoMealEntity + { + UserNo = gainfo.No, + UserCode = gainfo.Code, + Balance = 0, + BalanceOfRecharge = 0, + BalanceOfSubsidies = 0, + Version = 0 + }; + + await _dbContext.InsertAsync(mealUser); + } + + var b = mealUser.Balance += request.Balance; + + await _dbContext.Updateable() + .SetColumns(x => x.Version == x.Version + 1) + .SetColumns(x => x.Balance == b) + .SetColumns(x => x.ModifiedTime == DateTime.Now) + .Where(x => x.UserCode == mealUser.UserCode && x.Version == mealUser.Version) + .ExecuteCommandThrowVersionAsync(); + }, 5); + + await _dbContext.InsertAsync(new BalanceRecordEntity + { + Amount = request.Balance, + ApplicationType = CanteenApplicaitonTypeEnumType.MealSupplement, + Type = BalanceRecordTypeEnumType.In, + BusinessPlaceCode = null, + BusinessShiftCode = null, + ShiftType = null, + CostDate = today, + CostDateTime = DateTime.Now, + UserNo = gainfo.No, + No = SnowFlakeHelper.Instance.NextId().ToString(), + UserCode = gainfo.Code, + TenantId = gainfo.Factory, + Status = BalanceRecordStatusEnumType.Valid, + Source = BalanceRecordSourceEnumType.LocalTenantSubsidies, + Remark = "期初导入", + CostId = gainfo.CostId, + SubsidiesFromMonth = today.ToString("yyyyMM"), + OriginTenantId = gainfo.Factory, + Werks = gainfo.Werks, + Name = gainfo.Name, + IsCostCrossTenant = false, + DepartmentNo = gainfo.DepartmentNo, + DeviceUniqueNo = null, + + CreatedBy = 1, + CreateTime = DateTime.Now, + ModifiedBy = 1, + ModifiedTime = DateTime.Now, + }); + } + } +} \ No newline at end of file From 8773c06c86ce3b4733fda865afac9ce9a204a037 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Wed, 22 May 2024 16:39:55 +0800 Subject: [PATCH 12/15] =?UTF-8?q?feat=20=E8=8E=B7=E5=8F=96=E5=87=BA?= =?UTF-8?q?=E5=B7=AE=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Common/Response/SapTravelInfoResponse.cs | 88 +++++++++++++++++++ .../Common/Services/IJinkoSapService.cs | 10 ++- .../Services/Implements/JinkoSapService.cs | 50 ++++++++--- 3 files changed, 135 insertions(+), 13 deletions(-) create mode 100644 Src/Dlhis.ScheduledTask/Common/Response/SapTravelInfoResponse.cs diff --git a/Src/Dlhis.ScheduledTask/Common/Response/SapTravelInfoResponse.cs b/Src/Dlhis.ScheduledTask/Common/Response/SapTravelInfoResponse.cs new file mode 100644 index 00000000..c706f9bd --- /dev/null +++ b/Src/Dlhis.ScheduledTask/Common/Response/SapTravelInfoResponse.cs @@ -0,0 +1,88 @@ +using Newtonsoft.Json; + +namespace Dlhis.ScheduledTask.Common.Response +{ + public class SapTravelInfoResponse + { + /// + /// 明细数据 + /// + [JsonProperty("OT_2002")] + public List Items { get; set; } + } + + public class SapTravelInfoItem + { + /// + /// 工号 + /// + [JsonProperty("OV_GONGH")] + public string Code { get; set; } + + /// + /// 姓名 + /// + [JsonProperty("OV_ENAME")] + public string Name { get; set; } + + /// + /// 开始日期 + /// + [JsonProperty("OV_BEGDA")] + public string BeginDate { get; set; } + + /// + /// 结束日期 + /// + [JsonProperty("OV_ENDDA")] + public string EndDate { get; set; } + + /// + /// 开始时间 + /// + [JsonProperty("OV_BEGUZ")] + public DateTime BeginDateTime { get; set; } + + /// + /// 结束时间 + /// + [JsonProperty("OV_ENDUZ")] + public DateTime EndDateTime { get; set; } + + /// + /// 出差类型 + /// + [JsonProperty("OV_AWART")] + public string Type { get; set; } + + /// + /// 出差类型描述 + /// + [JsonProperty("OV_ATEXT")] + public string TypeDesc { get; set; } + + /// + /// 出差时数 + /// + [JsonProperty("OV_STDAZ")] + public int Hour { get; set; } + + /// + /// 出差天数 + /// + [JsonProperty("OV_ABWTG")] + public double Day { get; set; } + + /// + /// 出差目的地 + /// + [JsonProperty("OV_CCMDD")] + public string Destination { get; set; } + + /// + /// 出差目的地描述 + /// + [JsonProperty("OV_CCMDDM")] + public string DestinationDesc { get; set; } + } +} \ No newline at end of file diff --git a/Src/Dlhis.ScheduledTask/Common/Services/IJinkoSapService.cs b/Src/Dlhis.ScheduledTask/Common/Services/IJinkoSapService.cs index daae853f..9ed75d5e 100644 --- a/Src/Dlhis.ScheduledTask/Common/Services/IJinkoSapService.cs +++ b/Src/Dlhis.ScheduledTask/Common/Services/IJinkoSapService.cs @@ -11,4 +11,12 @@ public interface IJinkoSapService : IScopeDependency Task GetPersonsByWerkAsync(string werk); Task GetPersonsByCodeAsync(string code); -} + + /// + /// 获取出差信息 + /// + /// + /// + /// + Task GetTravelInfosAsync(DateTime begin, DateTime end); +} \ No newline at end of file diff --git a/Src/Dlhis.ScheduledTask/Common/Services/Implements/JinkoSapService.cs b/Src/Dlhis.ScheduledTask/Common/Services/Implements/JinkoSapService.cs index ca5b9628..11fcd506 100644 --- a/Src/Dlhis.ScheduledTask/Common/Services/Implements/JinkoSapService.cs +++ b/Src/Dlhis.ScheduledTask/Common/Services/Implements/JinkoSapService.cs @@ -3,6 +3,7 @@ using System.Text; using Dlhis.Entity.Basic.Entity; using Dlhis.ScheduledTask.Common.Dto; using Dlhis.ScheduledTask.Common.Response; +using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.SqlSugar.Services; using Newtonsoft.Json; @@ -25,7 +26,7 @@ public class JinkoSapService : IJinkoSapService httpClient.BaseAddress = new Uri("http://sappipap01.jinkosolar.cn:50100"); httpClient.Timeout = TimeSpan.FromMinutes(10); - var credentials = string.Format("{0}:{1}", "EHS_USER", "y3R1hd2h*RICAC"); + var credentials = $"{"EHS_USER"}:{"y3R1hd2h*RICAC"}"; var headerValue = Convert.ToBase64String(Encoding.UTF8.GetBytes(credentials)); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", headerValue); @@ -34,7 +35,7 @@ public class JinkoSapService : IJinkoSapService public async Task GetSapOrganizationsAsync() { - string apiUrl = "/RESTAdapter/Rest/EHR_ORGANIZATION/"; + const string apiUrl = "/RESTAdapter/Rest/EHR_ORGANIZATION/"; var response = await GetHttpClient().PostAsync(apiUrl, new StringContent("{}", Encoding.UTF8, "application/json")); response.EnsureSuccessStatusCode(); @@ -47,7 +48,7 @@ public class JinkoSapService : IJinkoSapService public async Task GetPositionsAsync() { - string apiUrl = "/RESTAdapter/Rest/EHR_POSITION/"; + const string apiUrl = "/RESTAdapter/Rest/EHR_POSITION/"; var response = await GetHttpClient().PostAsync(apiUrl, new StringContent("{}", Encoding.UTF8, "application/json")); response.EnsureSuccessStatusCode(); @@ -61,7 +62,7 @@ public class JinkoSapService : IJinkoSapService public async Task GetPersonsByWerkAsync(string werk) { - var apiUrl = "/RESTAdapter/Rest/EHR_PERSONNEL/"; + const string apiUrl = "/RESTAdapter/Rest/EHR_PERSONNEL/"; var werkInfo = await _dbContext.Queryable() .Where(x => x.Enable) @@ -74,12 +75,12 @@ public class JinkoSapService : IJinkoSapService T_WERKS = new { item = new List - { - new - { - WERKS = werkInfo.Werk - } - } + { + new + { + WERKS = werkInfo.Werk + } + } }, T_PERSON = Array.Empty(), T_PNO = Array.Empty(), @@ -131,7 +132,7 @@ public class JinkoSapService : IJinkoSapService public async Task GetPersonsByCodeAsync(string code) { - var apiUrl = "/RESTAdapter/Rest/EHR_PERSONNEL/"; + const string apiUrl = "/RESTAdapter/Rest/EHR_PERSONNEL/"; var body = new { @@ -193,4 +194,29 @@ public class JinkoSapService : IJinkoSapService } }; } -} + + + public async Task GetTravelInfosAsync(DateTime begin, DateTime end) + { + const string apiUrl = "/JIP/HCM/HCM_TRAVELINFO"; + + var beginDay = begin.ToString("yyyyMMdd"); + var endDay = end.ToString("yyyyMMdd"); + + var obj = new + { + IV_BEGDA = beginDay, + IV_ENDDA = endDay + }; + + var body = obj.ToJson(); + + var content = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json"); + var response = await GetHttpClient().PostAsync(apiUrl, content); + response.EnsureSuccessStatusCode(); + + var jsonResponse = await response.Content.ReadAsStringAsync(); + + return JsonConvert.DeserializeObject(jsonResponse); + } +} \ No newline at end of file From 74a6b71a3aca8a301d340997c4392751f13bbb3e Mon Sep 17 00:00:00 2001 From: liguoyang Date: Wed, 22 May 2024 16:44:45 +0800 Subject: [PATCH 13/15] =?UTF-8?q?fix=20=E4=BC=98=E5=8C=96=E4=BA=BA?= =?UTF-8?q?=E5=91=98=E5=88=97=E8=A1=A8=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Order/Controllers/OrdersController.cs | 2 +- .../Order/Services/IOrderService.cs | 6 +-- Src/Dlhis.Entity/Sys/Entities/RoleEntity.cs | 2 + .../Identity/Controllers/RolesController.cs | 6 +-- .../Identity/Controllers/TenantsController.cs | 2 +- .../Identity/Controllers/UsersController.cs | 4 +- .../Identity/Request/RoleSaveRequest.cs | 5 ++- .../Identity/Request/UserPageRequest.cs | 6 ++- .../{RoleRespone.cs => RoleResponse.cs} | 13 +++++- .../Identity/Services/IRoleService.cs | 6 +-- .../Services/Implements/RoleService.cs | 45 +++++++++---------- .../Services/Implements/TenantService.cs | 43 +++++++++--------- .../Services/Implements/UserService.cs | 24 ++++++---- .../Services/Implements/UserTenantService.cs | 9 ++-- 14 files changed, 96 insertions(+), 77 deletions(-) rename Src/Dlhis.Sys/Identity/Response/{RoleRespone.cs => RoleResponse.cs} (52%) diff --git a/Src/Dlhis.Canteen/Order/Controllers/OrdersController.cs b/Src/Dlhis.Canteen/Order/Controllers/OrdersController.cs index 36f6654f..5afd5d6f 100644 --- a/Src/Dlhis.Canteen/Order/Controllers/OrdersController.cs +++ b/Src/Dlhis.Canteen/Order/Controllers/OrdersController.cs @@ -8,7 +8,7 @@ using Kurisu.Core.Result; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -namespace Dlhis.Canteen.Dishes.Controllers; +namespace Dlhis.Canteen.Order.Controllers; /// /// 订单 diff --git a/Src/Dlhis.Canteen/Order/Services/IOrderService.cs b/Src/Dlhis.Canteen/Order/Services/IOrderService.cs index fc96866f..48923d36 100644 --- a/Src/Dlhis.Canteen/Order/Services/IOrderService.cs +++ b/Src/Dlhis.Canteen/Order/Services/IOrderService.cs @@ -7,10 +7,8 @@ namespace Dlhis.Canteen.Order.Services; public interface IOrderService : IScopeDependency { - Task> AddAsync(OrderAddRequest request); - - + Task ReCalcOfflineAsync(ReCalcOfflineRequest request); Task UpdateOffline(UpdateOfflineRequest outRequest); @@ -23,4 +21,4 @@ public interface IOrderService : IScopeDependency Task> DeviceConsume(OrderAddRequest request); Task> GetOrdersAggregationAsync(PageDto page); -} +} \ No newline at end of file diff --git a/Src/Dlhis.Entity/Sys/Entities/RoleEntity.cs b/Src/Dlhis.Entity/Sys/Entities/RoleEntity.cs index f9a7afa6..d78c470c 100644 --- a/Src/Dlhis.Entity/Sys/Entities/RoleEntity.cs +++ b/Src/Dlhis.Entity/Sys/Entities/RoleEntity.cs @@ -17,5 +17,7 @@ public class RoleEntity public string NormalizedName { get; set; } + public string Description { get; set; } + public Guid ConcurrencyStamp { get; set; } } diff --git a/Src/Dlhis.Sys/Identity/Controllers/RolesController.cs b/Src/Dlhis.Sys/Identity/Controllers/RolesController.cs index cd65a44d..ebd9446a 100644 --- a/Src/Dlhis.Sys/Identity/Controllers/RolesController.cs +++ b/Src/Dlhis.Sys/Identity/Controllers/RolesController.cs @@ -29,7 +29,7 @@ public class RolesController : ControllerBase /// [Authorize(Roles = "admin")] [HttpGet("page")] - public async Task> GetPageAsync([FromQuery] RolePageRequest request) + public async Task> GetPageAsync([FromQuery] RolePageRequest request) { return await _roleService.GetPageAsync(request); } @@ -40,7 +40,7 @@ public class RolesController : ControllerBase /// [Authorize(Roles = "admin")] [HttpGet("list")] - public async Task> GetListAsync() + public async Task> GetListAsync() { return await _roleService.GetListAsync(); } @@ -85,7 +85,7 @@ public class RolesController : ControllerBase /// /// [HttpGet("my")] - public async Task GetMyRoleAsync(int? userId) + public async Task GetMyRoleAsync(int? userId) { return await _roleService.GetMyRoleAsync(userId); } diff --git a/Src/Dlhis.Sys/Identity/Controllers/TenantsController.cs b/Src/Dlhis.Sys/Identity/Controllers/TenantsController.cs index 6015e096..f7c16948 100644 --- a/Src/Dlhis.Sys/Identity/Controllers/TenantsController.cs +++ b/Src/Dlhis.Sys/Identity/Controllers/TenantsController.cs @@ -92,4 +92,4 @@ public class TenantsController : ControllerBase { return await _tenantService.GetMyTenantsAsync(); } -} +} \ No newline at end of file diff --git a/Src/Dlhis.Sys/Identity/Controllers/UsersController.cs b/Src/Dlhis.Sys/Identity/Controllers/UsersController.cs index c3f4ffa5..d11a2293 100644 --- a/Src/Dlhis.Sys/Identity/Controllers/UsersController.cs +++ b/Src/Dlhis.Sys/Identity/Controllers/UsersController.cs @@ -26,7 +26,7 @@ public class UsersController : ControllerBase /// /// /// - [Authorize(Roles = "admin")] + [Authorize(Roles = "admin,tenant-admin")] [HttpGet("page")] public async Task> GetPageAsync([FromQuery] UserPageRequest request) { @@ -64,7 +64,7 @@ public class UsersController : ControllerBase } /// - /// + /// 创建用户 /// /// /// diff --git a/Src/Dlhis.Sys/Identity/Request/RoleSaveRequest.cs b/Src/Dlhis.Sys/Identity/Request/RoleSaveRequest.cs index 843bc8c5..52f6eda7 100644 --- a/Src/Dlhis.Sys/Identity/Request/RoleSaveRequest.cs +++ b/Src/Dlhis.Sys/Identity/Request/RoleSaveRequest.cs @@ -6,6 +6,9 @@ public class RoleSaveRequest { public int? Id { get; set; } - [Required(ErrorMessage = "角色名不能为空")] + [Required(ErrorMessage = "角色标识不能为空")] public string Name { get; set; } + + [Required(ErrorMessage = "描述不能为空")] + public string Description { get; set; } } diff --git a/Src/Dlhis.Sys/Identity/Request/UserPageRequest.cs b/Src/Dlhis.Sys/Identity/Request/UserPageRequest.cs index 3184123a..02136a5d 100644 --- a/Src/Dlhis.Sys/Identity/Request/UserPageRequest.cs +++ b/Src/Dlhis.Sys/Identity/Request/UserPageRequest.cs @@ -4,4 +4,8 @@ namespace Dlhis.Sys.Identity.Request; public class UserPageRequest : PageDto { -} + /// + /// 操作员 + /// + public bool IsOperator { get; set; } +} \ No newline at end of file diff --git a/Src/Dlhis.Sys/Identity/Response/RoleRespone.cs b/Src/Dlhis.Sys/Identity/Response/RoleResponse.cs similarity index 52% rename from Src/Dlhis.Sys/Identity/Response/RoleRespone.cs rename to Src/Dlhis.Sys/Identity/Response/RoleResponse.cs index 03cd8c23..7c90a410 100644 --- a/Src/Dlhis.Sys/Identity/Response/RoleRespone.cs +++ b/Src/Dlhis.Sys/Identity/Response/RoleResponse.cs @@ -1,13 +1,24 @@ namespace Dlhis.Sys.Identity.Response; -public class RoleRespone +public class RoleResponse { public int Id { get; set; } + /// + /// 名称 + /// public string Name { get; set; } + /// + /// 标准化名称 + /// public string NormalizedName { get; set; } + /// + /// 描述 + /// + public string Description { get; set; } + /// /// 是否可编辑 /// diff --git a/Src/Dlhis.Sys/Identity/Services/IRoleService.cs b/Src/Dlhis.Sys/Identity/Services/IRoleService.cs index 8b02ba23..4cb1dba1 100644 --- a/Src/Dlhis.Sys/Identity/Services/IRoleService.cs +++ b/Src/Dlhis.Sys/Identity/Services/IRoleService.cs @@ -6,13 +6,13 @@ namespace Dlhis.User.Identity.Services; public interface IRoleService : IScopeDependency { - Task> GetPageAsync(RolePageRequest request); + Task> GetPageAsync(RolePageRequest request); - Task> GetListAsync(); + Task> GetListAsync(); Task SaveRoleAsync(RoleSaveRequest request); - Task GetMyRoleAsync(int? userId); + Task GetMyRoleAsync(int? userId); Task RemoveRoleAsync(RoleRemoveRequest request); diff --git a/Src/Dlhis.Sys/Identity/Services/Implements/RoleService.cs b/Src/Dlhis.Sys/Identity/Services/Implements/RoleService.cs index 58909bc5..c8248594 100644 --- a/Src/Dlhis.Sys/Identity/Services/Implements/RoleService.cs +++ b/Src/Dlhis.Sys/Identity/Services/Implements/RoleService.cs @@ -2,8 +2,6 @@ using Dlhis.Sys.Identity.Request; using Dlhis.Sys.Identity.Response; using Dlhis.User.Identity.Services; -using Kurisu.AspNetCore.Scope; -using Kurisu.AspNetCore.UnifyResultAndValidation; using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.CustomClass; using Kurisu.Core.DataAccess.Dto; @@ -24,29 +22,24 @@ public class RoleService : IRoleService _dbContext = dbContext.ChangeDb("identity"); } - public async Task> GetPageAsync(RolePageRequest request) + public async Task> GetPageAsync(RolePageRequest request) { return await _dbContext.Queryable() - .WhereIF(request.Search.IsPresent(), x => x.Name.Contains(request.Search) || x.NormalizedName.Contains(request.Search)) - .Where(x => x.Name != "admin") - .Select() - .ToPageListAsync(request); + .WhereIF(request.Search.IsPresent(), x => x.Name.Contains(request.Search) || x.NormalizedName.Contains(request.Search)) + .Where(x => x.Name != "admin") + .Select() + .ToPageListAsync(request); } - public async Task GetMyRoleAsync(int? userId) + public async Task GetMyRoleAsync(int? userId) { userId ??= _currentUser.GetIntSubjectId(); return await _dbContext.Queryable() - .LeftJoin((x, r) => x.RoleId == r.Id) - .Where(x => x.UserId == userId) - .Select((x, r) => new RoleRespone - { - Id = r.Id, - Name = r.Name, - NormalizedName = r.NormalizedName, - }) - .FirstAsync(); + .LeftJoin((x, r) => x.RoleId == r.Id) + .Where(x => x.UserId == userId) + .Select() + .FirstAsync(); } public async Task SaveRoleAsync(RoleSaveRequest request) @@ -59,6 +52,7 @@ public class RoleService : IRoleService { Name = request.Name, NormalizedName = request.Name.ToUpperInvariant(), + Description = request.Description, ConcurrencyStamp = Guid.NewGuid(), }); } @@ -69,6 +63,7 @@ public class RoleService : IRoleService entity.Name = request.Name; entity.NormalizedName = request.Name.ToUpperInvariant(); + entity.Description = request.Description; entity.ConcurrencyStamp = Guid.NewGuid(); await _dbContext.UpdateAsync(entity); @@ -107,9 +102,9 @@ public class RoleService : IRoleService else { await _dbContext.Updateable() - .SetColumns(x => x.RoleId == request.RoleId) - .Where(x => x.UserId == request.UserId) - .ExecuteCommandAsync(); + .SetColumns(x => x.RoleId == request.RoleId) + .Where(x => x.UserId == request.UserId) + .ExecuteCommandAsync(); } } else @@ -127,12 +122,12 @@ public class RoleService : IRoleService await _dbContext.DeleteReallyAsync(role); } - public async Task> GetListAsync() + public async Task> GetListAsync() { return await _dbContext.Queryable() - .Where(x => x.Name != "admin") - .Select() - .ToListAsync(); + .Where(x => x.Name != "admin") + .Select() + .ToListAsync(); } @@ -148,4 +143,4 @@ public class RoleService : IRoleService exists.ThrowIfTrue($"重复角色名称{request.Name}"); } -} +} \ No newline at end of file diff --git a/Src/Dlhis.Sys/Identity/Services/Implements/TenantService.cs b/Src/Dlhis.Sys/Identity/Services/Implements/TenantService.cs index f8e51a11..9cda48e0 100644 --- a/Src/Dlhis.Sys/Identity/Services/Implements/TenantService.cs +++ b/Src/Dlhis.Sys/Identity/Services/Implements/TenantService.cs @@ -23,16 +23,16 @@ public class TenantService : ITenantService public async Task> GetPageAsync(TenantPageRequest request) { return await _dbContext.Queryable() - .WhereIF(request.Search.IsPresent(), (tenant) => tenant.Name.Contains(request.Search)) - .Select() - .ToPageListAsync(request); + .WhereIF(request.Search.IsPresent(), (tenant) => tenant.Name.Contains(request.Search)) + .Select() + .ToPageListAsync(request); } public async Task> GetListAsync() { return await _dbContext.Queryable() - .Select() - .ToListAsync(); + .Select() + .ToListAsync(); } public async Task GetTenantByCode(string code) @@ -73,16 +73,16 @@ public class TenantService : ITenantService var tenantId = _currentUser.GetStringTenantId(); var myTenants = await _dbContext.Queryable() - .LeftJoin((ut, t) => ut.TenantCode == t.Code) - .Where(ut => ut.UserId == userId) - .Select((ut, t) => new TenantResponse - { - Id = t.Id, - PCode = t.PCode, - Code = t.Code, - Name = t.Name, - }) - .ToListAsync(); + .LeftJoin((ut, t) => ut.TenantCode == t.Code) + .Where(ut => ut.UserId == userId) + .Select((ut, t) => new TenantResponse + { + Id = t.Id, + PCode = t.PCode, + Code = t.Code, + Name = t.Name, + }) + .ToListAsync(); var currentTenant = myTenants.FirstOrDefault(x => x.Code == tenantId); var otherTenants = myTenants.Where(x => x.Code != tenantId); @@ -100,17 +100,16 @@ public class TenantService : ITenantService public async Task> GetTreeAsync() { var tenants = await _dbContext.Queryable() - .Select() - .ToListAsync(); + .Select() + .ToListAsync(); var tops = tenants.Where(x => x.PCode.IsEmpty()).ToList(); - foreach (var item in tops) - { - RecursionGetNext(item, tenants); - } + tops.ForEach(item => RecursionGetNext(item, tenants)); + return tops; } + //****************************************************************** help methods ***************************************************************************** private static void RecursionGetNext(TenantTreeResponse current, List data) { @@ -121,4 +120,4 @@ public class TenantService : ITenantService RecursionGetNext(item, data); } } -} +} \ No newline at end of file diff --git a/Src/Dlhis.Sys/Identity/Services/Implements/UserService.cs b/Src/Dlhis.Sys/Identity/Services/Implements/UserService.cs index 35b2d6fa..3381e7d7 100644 --- a/Src/Dlhis.Sys/Identity/Services/Implements/UserService.cs +++ b/Src/Dlhis.Sys/Identity/Services/Implements/UserService.cs @@ -3,40 +3,49 @@ using Dlhis.Sys.Identity.Request; using Dlhis.Sys.Identity.Response; using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.DataAccess.Dto; +using Kurisu.Core.User.Abstractions; using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Services; using Microsoft.AspNetCore.Identity; +using SqlSugar; namespace Dlhis.Sys.Identity.Services.Implements; public class UserService : IUserService { + private readonly ICurrentUser _currentUser; private readonly IDbContext _dbContext; - public UserService(IDbContext dbContext) + public UserService(IDbContext dbContext, ICurrentUser currentUser) { + _currentUser = currentUser; _dbContext = dbContext.ChangeDb("identity"); } public async Task> GetPageAsync(UserPageRequest request) { + var tenant = _currentUser.GetStringTenantId(); + var page = await _dbContext.Queryable() .LeftJoin((x, ur) => x.Id == ur.UserId) .LeftJoin((x, ur, r) => ur.RoleId == r.Id) .LeftJoin((x, ur, r, c) => x.Id == c.UserId && c.ClaimType == "preferred_username") + .LeftJoin((x, ur, r, c, cc) => x.Id == c.UserId && c.ClaimType == "tenant") .Where(x => x.UserName != "admin") + .Where((x, ur, r, c, cc) => cc.ClaimValue == tenant) + .WhereIF(request.IsOperator, (x, ur, r, c) => !SqlFunc.IsNullOrEmpty(r.Name)) + .WhereIF(!request.IsOperator, (x, ur, r, c) => SqlFunc.IsNullOrEmpty(r.Name)) .WhereIF(request.Search.IsPresent(), (x, ur, r, c) => x.UserName == request.Search - || x.Email == request.Search - || x.PhoneNumber == request.Search - || c.ClaimValue == request.Search + || x.Email == request.Search + || x.PhoneNumber == request.Search + || c.ClaimValue == request.Search ) - .Select((x, ur, r, c) => new UserResponse + .Select((x, ur, r, c, cc) => new UserResponse { Id = x.Id, RoleId = ur.RoleId, Role = r.Name, OperatorName = c.ClaimValue, - }, true) .ToPageListAsync(request); @@ -74,7 +83,6 @@ public class UserService : IUserService RoleId = ur.RoleId, Role = r.Name, OperatorName = c.ClaimValue, - }, true) .FirstAsync(); @@ -124,4 +132,4 @@ public class UserService : IUserService }); } } -} +} \ No newline at end of file diff --git a/Src/Dlhis.Sys/Identity/Services/Implements/UserTenantService.cs b/Src/Dlhis.Sys/Identity/Services/Implements/UserTenantService.cs index 6dbaffe5..3b10b794 100644 --- a/Src/Dlhis.Sys/Identity/Services/Implements/UserTenantService.cs +++ b/Src/Dlhis.Sys/Identity/Services/Implements/UserTenantService.cs @@ -31,10 +31,9 @@ public class UserTenantService : IUserTenantService await _dbContext.DeleteReallyAsync(userTenants); await _dbContext.InsertAsync(request.TenantCodes.Select(x => new UserTenantEntity - { - UserId = request.UserId, - TenantCode = x - }) - .ToList()); + { + UserId = request.UserId, + TenantCode = x + }).ToList()); } } \ No newline at end of file From 75f9edb1fa9a8d4dfc4047f984b67229c707c64f Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 23 May 2024 14:45:41 +0800 Subject: [PATCH 14/15] =?UTF-8?q?fix=20=E7=94=A8=E6=88=B7=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=9F=A5=E8=AF=A2=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Sys/Identity/Request/UserCreateRequest.cs | 6 +++--- Src/Dlhis.Sys/Identity/Services/Implements/UserService.cs | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Src/Dlhis.Sys/Identity/Request/UserCreateRequest.cs b/Src/Dlhis.Sys/Identity/Request/UserCreateRequest.cs index 4ed87938..3d08abd0 100644 --- a/Src/Dlhis.Sys/Identity/Request/UserCreateRequest.cs +++ b/Src/Dlhis.Sys/Identity/Request/UserCreateRequest.cs @@ -20,11 +20,11 @@ public class UserCreateRequest /// /// 厂区 /// - [Required] - public string Tenant { get; set; } + [MinLength(1, ErrorMessage = "请明确厂区")] + public List Tenants { get; set; } /// /// 名称 /// public string Name { get; set; } -} +} \ No newline at end of file diff --git a/Src/Dlhis.Sys/Identity/Services/Implements/UserService.cs b/Src/Dlhis.Sys/Identity/Services/Implements/UserService.cs index 3381e7d7..c1bb80ce 100644 --- a/Src/Dlhis.Sys/Identity/Services/Implements/UserService.cs +++ b/Src/Dlhis.Sys/Identity/Services/Implements/UserService.cs @@ -30,7 +30,7 @@ public class UserService : IUserService .LeftJoin((x, ur) => x.Id == ur.UserId) .LeftJoin((x, ur, r) => ur.RoleId == r.Id) .LeftJoin((x, ur, r, c) => x.Id == c.UserId && c.ClaimType == "preferred_username") - .LeftJoin((x, ur, r, c, cc) => x.Id == c.UserId && c.ClaimType == "tenant") + .LeftJoin((x, ur, r, c, cc) => x.Id == cc.UserId && cc.ClaimType == "tenant") .Where(x => x.UserName != "admin") .Where((x, ur, r, c, cc) => cc.ClaimValue == tenant) .WhereIF(request.IsOperator, (x, ur, r, c) => !SqlFunc.IsNullOrEmpty(r.Name)) @@ -116,11 +116,11 @@ public class UserService : IUserService var id = (int)await _dbContext.InsertReturnIdentityAsync(user); - await _dbContext.InsertAsync(new UserTenantEntity + await _dbContext.InsertAsync(request.Tenants.Select(x => new UserTenantEntity { - TenantCode = request.Tenant, + TenantCode = x, UserId = id - }); + }).ToList()); if (request.Name.IsPresent()) { From 3d3d17c7998a2d3a0e414574e2c681e837b6415a Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 23 May 2024 14:49:00 +0800 Subject: [PATCH 15/15] =?UTF-8?q?fix=20=E6=98=AF=E5=90=A6=E4=BD=9C?= =?UTF-8?q?=E4=B8=BA=E8=80=83=E5=8B=A4=E5=88=86=E9=A1=B5=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Device/Response/DevicePageResponse.cs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Src/Dlhis.Basic/Device/Response/DevicePageResponse.cs b/Src/Dlhis.Basic/Device/Response/DevicePageResponse.cs index 20d413df..497d66f8 100644 --- a/Src/Dlhis.Basic/Device/Response/DevicePageResponse.cs +++ b/Src/Dlhis.Basic/Device/Response/DevicePageResponse.cs @@ -84,6 +84,12 @@ public class DevicePageResponse /// public bool Enable { get; set; } + + /// + /// 是否作为考勤 + /// + public bool AsAttendance { get; set; } + //*********************************************************附加信息**************************************************************/ @@ -101,13 +107,11 @@ public class DevicePageResponse { if (!LastHeartbeatTime.HasValue) return false; - else - { - if (HeartbeatInterval <= 0) - return true; - else - return LastHeartbeatTime.Value.AddSeconds(HeartbeatInterval * 3) >= DateTime.Now; - } + + if (HeartbeatInterval <= 0) + return true; + + return LastHeartbeatTime.Value.AddSeconds(HeartbeatInterval * 3) >= DateTime.Now; } }