From 6d2d62d62886edc9ebd3c0c17ebbd433bf9c7e63 Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Thu, 22 Feb 2024 10:12:04 +0800 Subject: [PATCH 001/146] =?UTF-8?q?feat=20=E8=8E=B7=E5=8F=96api=E6=97=A5?= =?UTF-8?q?=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Device/Controllers/DevicesController.cs | 13 +++- .../Device/Request/ApiLogRequest.cs | 14 +++++ .../Device/Response/ApiLogResponse.cs | 49 +++++++++++++++ .../Device/Response/RecentNumberResponse.cs | 9 +++ .../Device/Services/IDeviceService.cs | 5 +- .../Services/Implements/DeviceService.cs | 35 +++++++++-- Src/Dlhis.Basic/Program.cs | 4 +- Src/Dlhis.Basic/appsettings.json | 1 + Src/Dlhis.Entity/Basic/Entity/ApiLogEntity.cs | 61 +++++++++++++++++++ .../Basic/Enums/ApiLogEnumType.cs | 24 ++++++++ .../Controllers/DeviceUploadLogsController.cs | 4 +- .../Services/IDeviceUploadLogService.cs | 4 +- .../Implements/DeviceUploadLogService.cs | 8 ++- 13 files changed, 220 insertions(+), 11 deletions(-) create mode 100644 Src/Dlhis.Basic/Device/Request/ApiLogRequest.cs create mode 100644 Src/Dlhis.Basic/Device/Response/ApiLogResponse.cs create mode 100644 Src/Dlhis.Basic/Device/Response/RecentNumberResponse.cs create mode 100644 Src/Dlhis.Entity/Basic/Entity/ApiLogEntity.cs create mode 100644 Src/Dlhis.Entity/Basic/Enums/ApiLogEnumType.cs diff --git a/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs b/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs index 74e3ca8b..accdbbb3 100644 --- a/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs +++ b/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs @@ -1,6 +1,7 @@ using Dlhis.Basic.Device.Request; using Dlhis.Basic.Device.Response; using Dlhis.Basic.Device.Services; +using Dlhis.Entity.Basic.Entity; using Kurisu.Core.DataAccess.Dto; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -198,8 +199,18 @@ public class DevicesController : ControllerBase /// /// [HttpGet("recentnumbers")] - public async Task> GetRecentNumbersAsync() + public async Task> GetRecentNumbersAsync() { return await _deviceService.GetRecentNumbersAsync(); } + + /// + /// 获取api日志 + /// + /// + [HttpGet("logs")] + public async Task> GetLogsAsync([FromQuery]ApiLogRequest request) + { + return await _deviceService.GetLogsAsync(request); + } } diff --git a/Src/Dlhis.Basic/Device/Request/ApiLogRequest.cs b/Src/Dlhis.Basic/Device/Request/ApiLogRequest.cs new file mode 100644 index 00000000..484b5983 --- /dev/null +++ b/Src/Dlhis.Basic/Device/Request/ApiLogRequest.cs @@ -0,0 +1,14 @@ +using Dlhis.Entity.Basic.Enums; +using Kurisu.Core.DataAccess.Dto; +using System.ComponentModel.DataAnnotations; + +namespace Dlhis.Basic.Device.Request +{ + public class ApiLogRequest :PageDto + { + public string message { get; set; } + + [EnumDataType(typeof(ApiLogEnumType)),] + public ApiLogEnumType? Type { get; set; } + } +} diff --git a/Src/Dlhis.Basic/Device/Response/ApiLogResponse.cs b/Src/Dlhis.Basic/Device/Response/ApiLogResponse.cs new file mode 100644 index 00000000..f2a3f501 --- /dev/null +++ b/Src/Dlhis.Basic/Device/Response/ApiLogResponse.cs @@ -0,0 +1,49 @@ +using SqlSugar; + +namespace Dlhis.Basic.Device.Response +{ + public class ApiLogResponse + { + /// + /// 时间 + /// + [SugarColumn(ColumnDescription = "时间")] + public string Timestamp { get; set; } + + /// + /// 级别 + /// + [SugarColumn(ColumnDescription = "级别")] + public string Level { get; set; } + + /// + /// 模板 + /// + [SugarColumn(ColumnDescription = "模板")] + public string Template { get; set; } + + /// + /// 消息内容 + /// + [SugarColumn(ColumnDescription = "消息内容")] + public string Message { get; set; } + + /// + /// 异常内容 + /// + [SugarColumn(ColumnDescription = "异常内容")] + public string Exception { get; set; } + + /// + /// 属性 + /// + [SugarColumn(ColumnDescription = "属性")] + public string Properties { get; set; } + + /// + /// 时间 + /// + [SugarColumn(ColumnDescription = "时间")] + public DateTime _ts { get; set; } + } +} diff --git a/Src/Dlhis.Basic/Device/Response/RecentNumberResponse.cs b/Src/Dlhis.Basic/Device/Response/RecentNumberResponse.cs new file mode 100644 index 00000000..ce0de9ea --- /dev/null +++ b/Src/Dlhis.Basic/Device/Response/RecentNumberResponse.cs @@ -0,0 +1,9 @@ +namespace Dlhis.Basic.Device.Response +{ + public class RecentNumberResponse + { + public string Date { get; set; } + + public int Num { get; set; } + } +} diff --git a/Src/Dlhis.Basic/Device/Services/IDeviceService.cs b/Src/Dlhis.Basic/Device/Services/IDeviceService.cs index 745702d4..889fb755 100644 --- a/Src/Dlhis.Basic/Device/Services/IDeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/IDeviceService.cs @@ -1,5 +1,6 @@ using Dlhis.Basic.Device.Request; using Dlhis.Basic.Device.Response; +using Dlhis.Entity.Basic.Entity; using Kurisu.Core.DataAccess.Dto; using Microsoft.AspNetCore.Mvc; @@ -23,5 +24,7 @@ public interface IDeviceService : IScopeDependency Task> GetAttendanceOfflineAsync(DeviceOnlineAndofflineRequest request); - Task> GetRecentNumbersAsync(); + Task> GetRecentNumbersAsync(); + + Task> GetLogsAsync(ApiLogRequest request); } diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs index 28b2f66c..fe0257a7 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs @@ -3,6 +3,7 @@ using Dlhis.Basic.Device.Response; using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Device.Entities; using Dlhis.Entity.Device.Enums; +using Kurisu.AspNetCore.Scope; using Kurisu.AspNetCore.UnifyResultAndValidation; using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.DataAccess.Dto; @@ -246,7 +247,7 @@ public class DeviceService : IDeviceService return page; } - public async Task> GetRecentNumbersAsync() + public async Task> GetRecentNumbersAsync() { //获取近30天并转化为"yyyy-MM-dd"集合 DateTime currentDate = DateTime.Now; @@ -260,13 +261,39 @@ public class DeviceService : IDeviceService var devices = await _dbContext.Queryable().ToListAsync(); - var dic = new Dictionary(); + var list = new List(); times.ForEach(time => { var count = devices.Where(x => x.CreateTime.ToString("yyyy-MM-dd") == time).Count(); - dic[time] = count; + var res = new RecentNumberResponse + { + Date = time, + Num = count, + }; + list.Add(res); + }); + return list; + } + + public async Task> GetLogsAsync(ApiLogRequest request) + { + var level = request.Type.ToString(); + return await Scoped.Request.Value.CreateAsync(async (sp) => + { + var configuration = sp.GetService(); + var logConnectionString = configuration.GetSection("SqlSugarOptions:LogConnectionString").Value; + + //todo 切换连接字符串 + var dbContext = sp.GetService(); + dbContext.Client.CurrentConnectionConfig.ConnectionString = logConnectionString; + var logs = await dbContext.Queryable() + .WhereIF(!request.message.IsEmpty(), x => x.Message.Contains(request.message)) + .WhereIF(!level.IsEmpty(),x => x.Level == level) + .Select() + .ToPageListAsync(request); + return logs; + }); - return dic; } } diff --git a/Src/Dlhis.Basic/Program.cs b/Src/Dlhis.Basic/Program.cs index 48192332..0ebc0761 100644 --- a/Src/Dlhis.Basic/Program.cs +++ b/Src/Dlhis.Basic/Program.cs @@ -24,9 +24,9 @@ public class Startup : DefaultStartup base.ConfigureServices(services); //todo - var redis = ConnectionMultiplexer.Connect($"10.27.21.15:30050,defaultDatabase:1,password=dlhis123"); + /*var redis = ConnectionMultiplexer.Connect($"10.27.21.15:30050,defaultDatabase:1,password=dlhis123"); services.AddDataProtection() .SetApplicationName("basic") - .PersistKeysToStackExchangeRedis(redis, "DataProtection-Keys"); + .PersistKeysToStackExchangeRedis(redis, "DataProtection-Keys");*/ } } \ No newline at end of file diff --git a/Src/Dlhis.Basic/appsettings.json b/Src/Dlhis.Basic/appsettings.json index 6c35cbca..f40f7fef 100644 --- a/Src/Dlhis.Basic/appsettings.json +++ b/Src/Dlhis.Basic/appsettings.json @@ -18,6 +18,7 @@ "DefaultConnectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=yikatong;charset=utf8mb4;", "SlaveConnectionString": [], "FaceConnectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=face;charset=utf8mb4;", + "LogConnectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=log;charset=utf8mb4;", "Timeout": 30, "SlowSqlTime": 1, "EnableSqlLog": false diff --git a/Src/Dlhis.Entity/Basic/Entity/ApiLogEntity.cs b/Src/Dlhis.Entity/Basic/Entity/ApiLogEntity.cs new file mode 100644 index 00000000..889cbd8c --- /dev/null +++ b/Src/Dlhis.Entity/Basic/Entity/ApiLogEntity.cs @@ -0,0 +1,61 @@ +using Kurisu.Core.DataAccess.Entity; +using Kurisu.SqlSugar; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Dlhis.Entity.Basic.Entity +{ + /// + /// api日志表 + /// + [SugarTable(TableName = "Logs", TableDescription = "api日志表")] + public class ApiLogEntity + { + /// + /// 时间 + /// + [SugarColumn(ColumnDescription = "时间")] + public string Timestamp { get; set; } + + /// + /// 级别 + /// + [SugarColumn(ColumnDescription = "级别")] + public string Level { get; set; } + + /// + /// 模板 + /// + [SugarColumn(ColumnDescription = "模板")] + public string Template { get; set; } + + /// + /// 消息内容 + /// + [SugarColumn(ColumnDescription = "消息内容")] + public string Message { get; set; } + + /// + /// 异常内容 + /// + [SugarColumn(ColumnDescription = "异常内容")] + public string Exception { get; set; } + + /// + /// 属性 + /// + [SugarColumn(ColumnDescription = "属性")] + public string Properties { get; set; } + + /// + /// 时间 + /// + [SugarColumn(ColumnDescription = "时间")] + public DateTime _ts { get; set; } + + } +} diff --git a/Src/Dlhis.Entity/Basic/Enums/ApiLogEnumType.cs b/Src/Dlhis.Entity/Basic/Enums/ApiLogEnumType.cs new file mode 100644 index 00000000..a65befdd --- /dev/null +++ b/Src/Dlhis.Entity/Basic/Enums/ApiLogEnumType.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Dlhis.Entity.Basic.Enums +{ + /// + /// api日志状态 + /// + [Description("api日志状态")] + public enum ApiLogEnumType + { + Information = 1, + + Warning = 2, + + Error = 3, + + Fatal = 4, + } +} diff --git a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Controllers/DeviceUploadLogsController.cs b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Controllers/DeviceUploadLogsController.cs index b9e57664..7a487c2d 100644 --- a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Controllers/DeviceUploadLogsController.cs +++ b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Controllers/DeviceUploadLogsController.cs @@ -1,4 +1,5 @@ -using Dlhis.ScheduledTask.DeviceUploadLog.Request; +using Dlhis.Entity.Basic.Entity; +using Dlhis.ScheduledTask.DeviceUploadLog.Request; using Dlhis.ScheduledTask.DeviceUploadLog.Response; using Dlhis.ScheduledTask.DeviceUploadLog.Services; using Kurisu.Core.DataAccess.Dto; @@ -54,4 +55,5 @@ public class DeviceUploadLogsController : ControllerBase { await _deviceUploadLogService.UploadLogsAsync(requests); } + } diff --git a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/IDeviceUploadLogService.cs b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/IDeviceUploadLogService.cs index 8a6285e2..fa2fed08 100644 --- a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/IDeviceUploadLogService.cs +++ b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/IDeviceUploadLogService.cs @@ -1,4 +1,5 @@ -using Dlhis.ScheduledTask.DeviceUploadLog.Request; +using Dlhis.Entity.Basic.Entity; +using Dlhis.ScheduledTask.DeviceUploadLog.Request; using Dlhis.ScheduledTask.DeviceUploadLog.Response; using Kurisu.Core.DataAccess.Dto; @@ -11,4 +12,5 @@ public interface IDeviceUploadLogService : IScopeDependency Task UploadLogAsync(DeviceUploadLogUploadRequest request); Task UploadLogsAsync(List requests); + } diff --git a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs index e479e4df..0577b046 100644 --- a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs +++ b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs @@ -1,13 +1,18 @@ -using System.Linq.Expressions; +using System.Configuration; +using System.Linq.Expressions; using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Device.Entities; using Dlhis.ScheduledTask.DeviceUploadLog.Request; using Dlhis.ScheduledTask.DeviceUploadLog.Response; +using Kurisu.AspNetCore.Scope; using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.DataAccess.Dto; using Kurisu.SqlSugar.Attributes; using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Services; +using Microsoft.AspNetCore.DataProtection; +using Microsoft.AspNetCore.Mvc; +using NetTaste; using SqlSugar; namespace Dlhis.ScheduledTask.DeviceUploadLog.Services.Implements; @@ -101,4 +106,5 @@ public class DeviceUploadLogService : IDeviceUploadLogService await _dbContext.InsertAsync(records); } + } From 951e1659f9e0d0136aea91da9b0d7d198b0867d2 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 22 Feb 2024 13:11:17 +0800 Subject: [PATCH 002/146] =?UTF-8?q?feat=20=E8=A7=92=E8=89=B2=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Entity/Sys/Entities/RoleEntity.cs | 2 +- .../Sys/Entities/UserRoleEntity.cs | 13 ++ .../Identity/Controllers/RolesController.cs | 52 +++++- .../Identity/Request/AssignRoleRequest.cs | 8 + .../Identity/Request/RoleRemoveRequest.cs | 6 + .../Identity/Request/RoleSaveRequest.cs | 11 ++ .../Identity/Services/IRoleService.cs | 8 + .../Services/Implements/RoleService.cs | 157 +++++++++++++++++- 8 files changed, 247 insertions(+), 10 deletions(-) create mode 100644 Src/Dlhis.Entity/Sys/Entities/UserRoleEntity.cs create mode 100644 Src/Dlhis.Sys/Identity/Request/AssignRoleRequest.cs create mode 100644 Src/Dlhis.Sys/Identity/Request/RoleRemoveRequest.cs create mode 100644 Src/Dlhis.Sys/Identity/Request/RoleSaveRequest.cs diff --git a/Src/Dlhis.Entity/Sys/Entities/RoleEntity.cs b/Src/Dlhis.Entity/Sys/Entities/RoleEntity.cs index 610770db..f9a7afa6 100644 --- a/Src/Dlhis.Entity/Sys/Entities/RoleEntity.cs +++ b/Src/Dlhis.Entity/Sys/Entities/RoleEntity.cs @@ -17,5 +17,5 @@ public class RoleEntity public string NormalizedName { get; set; } - public string ConcurrencyStamp { get; set; } + public Guid ConcurrencyStamp { get; set; } } diff --git a/Src/Dlhis.Entity/Sys/Entities/UserRoleEntity.cs b/Src/Dlhis.Entity/Sys/Entities/UserRoleEntity.cs new file mode 100644 index 00000000..8fe6a3cf --- /dev/null +++ b/Src/Dlhis.Entity/Sys/Entities/UserRoleEntity.cs @@ -0,0 +1,13 @@ +using Microsoft.Extensions.DependencyInjection; +using SqlSugar; + +namespace Dlhis.Entity.Sys.Entities; + +[SkipScan] +[SugarTable(TableName = "UserRoles")] +public class UserRoleEntity +{ + public int UserId { get; set; } + + public int RoleId { get; set; } +} diff --git a/Src/Dlhis.Sys/Identity/Controllers/RolesController.cs b/Src/Dlhis.Sys/Identity/Controllers/RolesController.cs index ae0ba399..8fa618fc 100644 --- a/Src/Dlhis.Sys/Identity/Controllers/RolesController.cs +++ b/Src/Dlhis.Sys/Identity/Controllers/RolesController.cs @@ -10,7 +10,7 @@ namespace Dlhis.Sys.Identity.Controllers; /// /// 角色 /// -[Authorize(Roles = "admin")] +[Authorize] [Route("api/[controller]")] [ApiController] public class RolesController : ControllerBase @@ -27,9 +27,55 @@ public class RolesController : ControllerBase /// /// /// - [HttpGet] - public async Task> GetPageAsync(RolePageRequest request) + [Authorize(Roles = "admin")] + [HttpGet("page")] + public async Task> GetPageAsync([FromQuery] RolePageRequest request) { return await _roleService.GetPageAsync(request); } + + /// + /// 分配角色 + /// + /// + /// + [Authorize(Roles = "admin")] + [HttpPost("assign")] + public async Task AssignRole(AssignRoleRequest request) + { + await _roleService.AssignRoleAsync(request); + } + + /// + /// 保存角色 + /// + /// + [Authorize(Roles = "admin")] + [HttpPost("save")] + public async Task SaveRole(RoleSaveRequest request) + { + await _roleService.SaveRoleAsync(request); + } + + /// + /// 移除角色 + /// + /// + /// + [Authorize(Roles = "admin")] + [HttpPost("delete")] + public async Task RemoveRole(RoleRemoveRequest request) + { + await _roleService.RemoveRoleAsync(request); + } + + /// + /// 我的角色 + /// + /// + [HttpGet("my")] + public async Task GetMyRoleAsync() + { + return await _roleService.GetMyRoleAsync(); + } } diff --git a/Src/Dlhis.Sys/Identity/Request/AssignRoleRequest.cs b/Src/Dlhis.Sys/Identity/Request/AssignRoleRequest.cs new file mode 100644 index 00000000..c66d25c5 --- /dev/null +++ b/Src/Dlhis.Sys/Identity/Request/AssignRoleRequest.cs @@ -0,0 +1,8 @@ +namespace Dlhis.Sys.Identity.Request; + +public class AssignRoleRequest +{ + public int UserId { get; set; } + + public int? RoleId { get; set; } +} diff --git a/Src/Dlhis.Sys/Identity/Request/RoleRemoveRequest.cs b/Src/Dlhis.Sys/Identity/Request/RoleRemoveRequest.cs new file mode 100644 index 00000000..ade423a8 --- /dev/null +++ b/Src/Dlhis.Sys/Identity/Request/RoleRemoveRequest.cs @@ -0,0 +1,6 @@ +namespace Dlhis.Sys.Identity.Request; + +public class RoleRemoveRequest +{ + public int Id { get; set; } +} diff --git a/Src/Dlhis.Sys/Identity/Request/RoleSaveRequest.cs b/Src/Dlhis.Sys/Identity/Request/RoleSaveRequest.cs new file mode 100644 index 00000000..843bc8c5 --- /dev/null +++ b/Src/Dlhis.Sys/Identity/Request/RoleSaveRequest.cs @@ -0,0 +1,11 @@ +using System.ComponentModel.DataAnnotations; + +namespace Dlhis.Sys.Identity.Request; + +public class RoleSaveRequest +{ + public int? Id { get; set; } + + [Required(ErrorMessage = "角色名不能为空")] + public string Name { get; set; } +} diff --git a/Src/Dlhis.Sys/Identity/Services/IRoleService.cs b/Src/Dlhis.Sys/Identity/Services/IRoleService.cs index 41af7fd6..eb101cc1 100644 --- a/Src/Dlhis.Sys/Identity/Services/IRoleService.cs +++ b/Src/Dlhis.Sys/Identity/Services/IRoleService.cs @@ -7,4 +7,12 @@ namespace Dlhis.User.Identity.Services; public interface IRoleService : IScopeDependency { Task> GetPageAsync(RolePageRequest request); + + Task SaveRoleAsync(RoleSaveRequest request); + + Task GetMyRoleAsync(); + + Task RemoveRoleAsync(RoleRemoveRequest request); + + Task AssignRoleAsync(AssignRoleRequest request); } diff --git a/Src/Dlhis.Sys/Identity/Services/Implements/RoleService.cs b/Src/Dlhis.Sys/Identity/Services/Implements/RoleService.cs index 8768d181..399b1d7f 100644 --- a/Src/Dlhis.Sys/Identity/Services/Implements/RoleService.cs +++ b/Src/Dlhis.Sys/Identity/Services/Implements/RoleService.cs @@ -2,8 +2,11 @@ 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.DataAccess.Dto; +using Kurisu.Core.User.Abstractions; using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Services; @@ -11,20 +14,162 @@ namespace Dlhis.Sys.Identity.Services.Implements; public class RoleService : IRoleService { - private readonly IDbContext _dbContext; + private readonly IConfiguration _configuration; + private readonly ICurrentUser _currentUser; - public RoleService(IDbContext dbContext, IConfiguration configuration) + public RoleService(IConfiguration configuration, ICurrentUser currentUser) { - var identityConnection = configuration.GetSection("SqlSugarOptions:IdentityConnectionString").Value; - dbContext.Client.CurrentConnectionConfig.ConnectionString = identityConnection; - _dbContext = dbContext; + _configuration = configuration; + _currentUser = currentUser; } public async Task> GetPageAsync(RolePageRequest request) { - return await _dbContext.Queryable() + return await Scoped.Request.Value.CreateAsync(async sp => + { + var dbContext = sp.GetService(); + var identityConnection = _configuration.GetSection("SqlSugarOptions:IdentityConnectionString").Value; + dbContext.Client.CurrentConnectionConfig.ConnectionString = identityConnection; + + + return await dbContext.Queryable() .WhereIF(request.Search.IsPresent(), x => x.Name.Contains(request.Search) || x.NormalizedName.Contains(request.Search)) .Select() .ToPageListAsync(request); + }); + } + + public async Task GetMyRoleAsync() + { + var userId = _currentUser.GetIntSubjectId(); + + return await Scoped.Request.Value.CreateAsync(async sp => + { + var dbContext = sp.GetService(); + var identityConnection = _configuration.GetSection("SqlSugarOptions:IdentityConnectionString").Value; + dbContext.Client.CurrentConnectionConfig.ConnectionString = identityConnection; + + + 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(); + }); + } + + public async Task SaveRoleAsync(RoleSaveRequest request) + { + await Scoped.Request.Value.CreateAsync(async sp => + { + var dbContext = sp.GetService(); + var identityConnection = _configuration.GetSection("SqlSugarOptions:IdentityConnectionString").Value; + dbContext.Client.CurrentConnectionConfig.ConnectionString = identityConnection; + + + await CheckDuplicateNameAsync(dbContext, request); + + if (!request.Id.HasValue) + { + await dbContext.InsertAsync(new RoleEntity + { + Name = request.Name, + NormalizedName = request.Name.ToUpperInvariant(), + ConcurrencyStamp = Guid.NewGuid(), + }); + } + else + { + var entity = await dbContext.Queryable().Where(x => x.Id == request.Id).FirstAsync(); + entity.ThrowIfNull("角色不存在"); + + entity.Name = request.Name; + entity.NormalizedName = request.Name.ToUpperInvariant(); + entity.ConcurrencyStamp = Guid.NewGuid(); + + await dbContext.UpdateAsync(entity); + } + }); + } + + + private async Task CheckDuplicateNameAsync(IDbContext db, RoleSaveRequest request) + { + var exists = await db.Queryable() + .WhereIF(request.Id.HasValue, x => x.Id != request.Id) + .Where(x => x.Name == request.Name) + .AnyAsync(); + + exists.ThrowIfTrue($"重复角色名称{request.Name}"); + } + + public async Task AssignRoleAsync(AssignRoleRequest request) + { + var myUserId = _currentUser.GetIntSubjectId(); + + await Scoped.Request.Value.CreateAsync(async sp => + { + //不能被其他人修改 + if (request.UserId == 1 && request.UserId != myUserId) + { + throw new UserFriendlyException("无法修改admin角色"); + } + + var dbContext = sp.GetService(); + var identityConnection = _configuration.GetSection("SqlSugarOptions:IdentityConnectionString").Value; + dbContext.Client.CurrentConnectionConfig.ConnectionString = identityConnection; + + var existsUser = await dbContext.Queryable().Where(x => x.Id == request.UserId).AnyAsync(); + existsUser.ThrowIfFalse("分配的用户不存在"); + + var userRole = await dbContext.Queryable().Where(x => x.UserId == request.UserId).FirstAsync(); + + if (request.RoleId.HasValue) + { + var existsRole = await dbContext.Queryable().Where(x => x.Id == request.RoleId).AnyAsync(); + existsUser.ThrowIfFalse("分配的角色不存在"); + + if (userRole == null) + { + await dbContext.InsertAsync(new UserRoleEntity + { + UserId = request.UserId, + RoleId = request.RoleId.Value, + }); + } + else + { + await dbContext.Updateable() + .SetColumns(x => x.RoleId == request.RoleId) + .Where(x => x.UserId == request.UserId) + .ExecuteCommandAsync(); + } + } + else + { + await dbContext.DeleteReallyAsync(userRole); + } + }); + } + + public async Task RemoveRoleAsync(RoleRemoveRequest request) + { + await Scoped.Request.Value.CreateAsync(async sp => + { + var dbContext = sp.GetService(); + var identityConnection = _configuration.GetSection("SqlSugarOptions:IdentityConnectionString").Value; + dbContext.Client.CurrentConnectionConfig.ConnectionString = identityConnection; + + var role = await dbContext.Queryable().FirstAsync(x => x.Id == request.Id); + role.ThrowIfNull("角色不存在"); + + //删除角色,自动删除UserRoles对应关系 + await dbContext.DeleteReallyAsync(role); + }); } } From e55a6793a74910b7ff25115418538e9815903b8d Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 22 Feb 2024 14:01:19 +0800 Subject: [PATCH 003/146] =?UTF-8?q?fix=20=E8=90=A5=E4=B8=9A=E7=82=B9?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E6=9E=9A=E4=B8=BE=E5=92=8C=E8=80=83=E5=8B=A4?= =?UTF-8?q?summary?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Basic/Dlhis.Basic.csproj | 4 + .../Controllers/SummariesController.cs | 29 +++++ Src/Dlhis.Basic/Summary/Dto/TrendDto.cs | 8 ++ .../Response/AttendanceDetailSummary.cs | 21 ++++ .../Response/AttendanceDeviceSummary.cs | 26 +++++ .../Response/AttendanceSummaryResponse.cs | 9 ++ .../Summary/Response/GainfoTrendResponse.cs | 10 ++ .../Summary/Services/ISummaryService.cs | 8 ++ .../Services/Implements/SummaryService.cs | 106 ++++++++++++++++++ .../CanteenBusinessPlaceCatalogEnumType.cs | 7 +- 10 files changed, 227 insertions(+), 1 deletion(-) create mode 100644 Src/Dlhis.Basic/Summary/Controllers/SummariesController.cs create mode 100644 Src/Dlhis.Basic/Summary/Dto/TrendDto.cs create mode 100644 Src/Dlhis.Basic/Summary/Response/AttendanceDetailSummary.cs create mode 100644 Src/Dlhis.Basic/Summary/Response/AttendanceDeviceSummary.cs create mode 100644 Src/Dlhis.Basic/Summary/Response/AttendanceSummaryResponse.cs create mode 100644 Src/Dlhis.Basic/Summary/Response/GainfoTrendResponse.cs create mode 100644 Src/Dlhis.Basic/Summary/Services/ISummaryService.cs create mode 100644 Src/Dlhis.Basic/Summary/Services/Implements/SummaryService.cs diff --git a/Src/Dlhis.Basic/Dlhis.Basic.csproj b/Src/Dlhis.Basic/Dlhis.Basic.csproj index 6dc23042..1b0c0da7 100644 --- a/Src/Dlhis.Basic/Dlhis.Basic.csproj +++ b/Src/Dlhis.Basic/Dlhis.Basic.csproj @@ -28,4 +28,8 @@ + + + + diff --git a/Src/Dlhis.Basic/Summary/Controllers/SummariesController.cs b/Src/Dlhis.Basic/Summary/Controllers/SummariesController.cs new file mode 100644 index 00000000..0f7f9fb0 --- /dev/null +++ b/Src/Dlhis.Basic/Summary/Controllers/SummariesController.cs @@ -0,0 +1,29 @@ +using Dlhis.Basic.Summary.Response; +using Dlhis.Basic.Summary.Services; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; + +namespace Dlhis.Basic.Summary.Controllers; + +[Authorize] +[Route("api/[controller]")] +[ApiController] +public class SummariesController : ControllerBase +{ + private readonly ISummaryService _summaryService; + + public SummariesController(ISummaryService summaryService) + { + _summaryService = summaryService; + } + + /// + /// 考勤首页 + /// + /// + [HttpGet("attendance-summary")] + public async Task GetKaoQingSummary() + { + return await _summaryService.GetAttendanceSummaryAsync(); + } +} diff --git a/Src/Dlhis.Basic/Summary/Dto/TrendDto.cs b/Src/Dlhis.Basic/Summary/Dto/TrendDto.cs new file mode 100644 index 00000000..2d2d046d --- /dev/null +++ b/Src/Dlhis.Basic/Summary/Dto/TrendDto.cs @@ -0,0 +1,8 @@ +namespace Dlhis.Basic.Summary.Dto; + +public class TrendDto +{ + public DateTime Date { get; set; } + + public int Count { get; set; } +} diff --git a/Src/Dlhis.Basic/Summary/Response/AttendanceDetailSummary.cs b/Src/Dlhis.Basic/Summary/Response/AttendanceDetailSummary.cs new file mode 100644 index 00000000..f4f9c24a --- /dev/null +++ b/Src/Dlhis.Basic/Summary/Response/AttendanceDetailSummary.cs @@ -0,0 +1,21 @@ +using Dlhis.Basic.Summary.Dto; + +namespace Dlhis.Basic.Summary.Response; + +public class AttendanceDetailSummary +{ + /// + /// 在职人数 + /// + public int Employed { get; set; } + + /// + /// 非在职人数 + /// + public int Unemployed { get; set; } + + /// + /// 人员趋势 7天 + /// + public GainfoTrendResponse GainfoTrend { get; set; } +} diff --git a/Src/Dlhis.Basic/Summary/Response/AttendanceDeviceSummary.cs b/Src/Dlhis.Basic/Summary/Response/AttendanceDeviceSummary.cs new file mode 100644 index 00000000..c0ebc007 --- /dev/null +++ b/Src/Dlhis.Basic/Summary/Response/AttendanceDeviceSummary.cs @@ -0,0 +1,26 @@ +using Dlhis.Basic.Summary.Dto; + +namespace Dlhis.Basic.Summary.Response; + +public class AttendanceDeviceSummary +{ + /// + /// 总数 + /// + public int Total { get; set; } + + /// + /// 在线数 + /// + public int OnlineCount { get; set; } + + /// + /// 启用数 + /// + public int EnableCount { get; set; } + + /// + /// 新增设备趋势 30天内 + /// + public List Trend { get; set; } +} diff --git a/Src/Dlhis.Basic/Summary/Response/AttendanceSummaryResponse.cs b/Src/Dlhis.Basic/Summary/Response/AttendanceSummaryResponse.cs new file mode 100644 index 00000000..ab930d60 --- /dev/null +++ b/Src/Dlhis.Basic/Summary/Response/AttendanceSummaryResponse.cs @@ -0,0 +1,9 @@ +namespace Dlhis.Basic.Summary.Response +{ + public class AttendanceSummaryResponse + { + public AttendanceDeviceSummary DeviceSummary { get; set; } + + public AttendanceDetailSummary AttendanceDetailSummary { get; set; } + } +} diff --git a/Src/Dlhis.Basic/Summary/Response/GainfoTrendResponse.cs b/Src/Dlhis.Basic/Summary/Response/GainfoTrendResponse.cs new file mode 100644 index 00000000..4050c983 --- /dev/null +++ b/Src/Dlhis.Basic/Summary/Response/GainfoTrendResponse.cs @@ -0,0 +1,10 @@ +using Dlhis.Basic.Summary.Dto; + +namespace Dlhis.Basic.Summary.Response +{ + public class GainfoTrendResponse + { + public List EmployedTrend { get; set; } + public List UnemployedTrend { get; set; } + } +} diff --git a/Src/Dlhis.Basic/Summary/Services/ISummaryService.cs b/Src/Dlhis.Basic/Summary/Services/ISummaryService.cs new file mode 100644 index 00000000..775379d2 --- /dev/null +++ b/Src/Dlhis.Basic/Summary/Services/ISummaryService.cs @@ -0,0 +1,8 @@ +using Dlhis.Basic.Summary.Response; + +namespace Dlhis.Basic.Summary.Services; + +public interface ISummaryService : IScopeDependency +{ + Task GetAttendanceSummaryAsync(); +} diff --git a/Src/Dlhis.Basic/Summary/Services/Implements/SummaryService.cs b/Src/Dlhis.Basic/Summary/Services/Implements/SummaryService.cs new file mode 100644 index 00000000..ad4f3e1e --- /dev/null +++ b/Src/Dlhis.Basic/Summary/Services/Implements/SummaryService.cs @@ -0,0 +1,106 @@ +using Dlhis.Basic.Organization.Services; +using Dlhis.Basic.Summary.Dto; +using Dlhis.Basic.Summary.Response; +using Dlhis.Entity.Basic.Entity; +using Dlhis.Entity.Basic.Enums; +using Dlhis.Entity.Device.Entities; +using Kurisu.SqlSugar.Services; + +namespace Dlhis.Basic.Summary.Services.Implements; + +public class SummaryService : ISummaryService +{ + private readonly IDbContext _dbContext; + private readonly IGainfoStore _gainfoStore; + + public SummaryService(IDbContext dbContext, IGainfoStore gainfoStore) + { + _dbContext = dbContext; + _gainfoStore = gainfoStore; + } + + public async Task GetAttendanceSummaryAsync() + { + var now = DateTime.Now; + + var currentDay = DateTime.Today.AddDays(1).AddSeconds(-1); + var before30Day = DateTime.Today.AddDays(-29); + var before7Day = DateTime.Today.AddDays(-6); + + var devices = await _dbContext.Queryable().ToListAsync(); + var deviceUniqueNos = devices.Select(x => x.UniqueNo).ToList(); + + var deviceRegistries = await _dbContext.Queryable() + .LeftJoin((x, d) => x.DeviceUniqueNo == d.UniqueNo) + .Where(x => deviceUniqueNos.Contains(x.DeviceUniqueNo)) + .Select((x, d) => new + { + d.HeartbeatInterval, + x.LastHeartbeatTime + }) + .ToListAsync(); + + var workingGainfos = await _gainfoStore.Queryable(GainfoStatusEnumType.Working).ToListAsync(); + var leaveGainfos = await _gainfoStore.Queryable(GainfoStatusEnumType.Leave).ToListAsync(); + + return new AttendanceSummaryResponse + { + DeviceSummary = new AttendanceDeviceSummary + { + Total = devices.Count, + EnableCount = devices.Where(x => x.Enable).Count(), + OnlineCount = deviceRegistries.Where(x => + { + if (x.HeartbeatInterval <= 0) + { + return false; + } + + return x.LastHeartbeatTime.AddSeconds(x.HeartbeatInterval * 3) >= now; + + }).Count(), + Trend = FixTrend(devices.Where(x => x.CreateTime >= before30Day && x.CreateTime <= currentDay) + .GroupBy(x => x.CreateTime.Date) + .Select(x => new TrendDto { Date = x.Key, Count = x.Count() }), before30Day, currentDay) + }, + AttendanceDetailSummary = new AttendanceDetailSummary + { + Employed = workingGainfos.Count, + Unemployed = leaveGainfos.Count, + GainfoTrend = new GainfoTrendResponse + { + EmployedTrend = FixTrend(workingGainfos.Where(x => x.CreateTime >= before7Day && x.CreateTime <= currentDay) + .GroupBy(x => x.CreateTime.Date) + .Select(x => new TrendDto { Date = x.Key, Count = x.Count() }), before7Day, currentDay), + UnemployedTrend = FixTrend(leaveGainfos.Where(x => x.CreateTime >= before7Day && x.CreateTime <= currentDay) + .GroupBy(x => x.CreateTime.Date) + .Select(x => new TrendDto { Date = x.Key, Count = x.Count() }), before7Day, currentDay), + } + } + }; + } + + private static List FixTrend(IEnumerable dtos, DateTime start, DateTime end) + { + var result = dtos.ToList(); + + start = start.Date; + end = end.Date; + + var currentDate = start; + while (currentDate <= end) + { + if (result.Any(x => x.Date == currentDate)) + { + currentDate = currentDate.AddDays(1); + continue; + } + + result.Add(new TrendDto { Date = currentDate, Count = 0 }); + + currentDate = currentDate.AddDays(1); + } + + return result; + } +} diff --git a/Src/Dlhis.Entity/Canteen/Enums/CanteenBusinessPlaceCatalogEnumType.cs b/Src/Dlhis.Entity/Canteen/Enums/CanteenBusinessPlaceCatalogEnumType.cs index 9f0c4f97..80724371 100644 --- a/Src/Dlhis.Entity/Canteen/Enums/CanteenBusinessPlaceCatalogEnumType.cs +++ b/Src/Dlhis.Entity/Canteen/Enums/CanteenBusinessPlaceCatalogEnumType.cs @@ -20,10 +20,15 @@ public enum CanteenBusinessPlaceCatalogEnumType [Description("食堂")] Cafeteria = 2, - /// /// 超市 /// [Description("超市")] Supermarket = 3, + + /// + /// 水吧 + /// + [Description("水吧")] + Bar = 4, } \ No newline at end of file From b5d6ec8366c8ccbfaf3a9929afd386ad4bc017ce Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Thu, 22 Feb 2024 14:04:01 +0800 Subject: [PATCH 004/146] =?UTF-8?q?feat=20=E6=9F=A5=E8=AF=A2=E6=B6=88?= =?UTF-8?q?=E8=B4=B9=E6=9C=BA=E6=80=BB=E6=95=B0=E3=80=81=E7=A6=BB=E7=BA=BF?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E6=95=B0=E9=87=8F=E3=80=81=E8=90=A5=E4=B8=9A?= =?UTF-8?q?=E7=82=B9=E6=95=B0=E9=87=8F=E3=80=81=E5=8F=AF=E6=B6=88=E8=B4=B9?= =?UTF-8?q?=E4=BA=BA=E6=95=B0=E3=80=81=E4=BA=BA=E5=9D=87=E6=97=A5=E6=B6=88?= =?UTF-8?q?=E8=B4=B9=E9=A2=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Device/Response/ApiLogResponse.cs | 7 ---- .../Device/Services/IDeviceService.cs | 1 + .../Order/Controllers/BalancesController.cs | 10 +++++ .../Order/Response/ConsumeNumberResponse.cs | 30 +++++++++++++++ .../Order/Services/IBalanceService.cs | 2 + .../Services/Implements/BalanceService.cs | 38 +++++++++++++++++++ 6 files changed, 81 insertions(+), 7 deletions(-) create mode 100644 Src/Dlhis.Canteen/Order/Response/ConsumeNumberResponse.cs diff --git a/Src/Dlhis.Basic/Device/Response/ApiLogResponse.cs b/Src/Dlhis.Basic/Device/Response/ApiLogResponse.cs index f2a3f501..3d51efae 100644 --- a/Src/Dlhis.Basic/Device/Response/ApiLogResponse.cs +++ b/Src/Dlhis.Basic/Device/Response/ApiLogResponse.cs @@ -7,43 +7,36 @@ namespace Dlhis.Basic.Device.Response /// /// 时间 /// - [SugarColumn(ColumnDescription = "时间")] public string Timestamp { get; set; } /// /// 级别 /// - [SugarColumn(ColumnDescription = "级别")] public string Level { get; set; } /// /// 模板 /// - [SugarColumn(ColumnDescription = "模板")] public string Template { get; set; } /// /// 消息内容 /// - [SugarColumn(ColumnDescription = "消息内容")] public string Message { get; set; } /// /// 异常内容 /// - [SugarColumn(ColumnDescription = "异常内容")] public string Exception { get; set; } /// /// 属性 /// - [SugarColumn(ColumnDescription = "属性")] public string Properties { get; set; } /// /// 时间 /// - [SugarColumn(ColumnDescription = "时间")] public DateTime _ts { get; set; } } } diff --git a/Src/Dlhis.Basic/Device/Services/IDeviceService.cs b/Src/Dlhis.Basic/Device/Services/IDeviceService.cs index 889fb755..8af87410 100644 --- a/Src/Dlhis.Basic/Device/Services/IDeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/IDeviceService.cs @@ -27,4 +27,5 @@ public interface IDeviceService : IScopeDependency Task> GetRecentNumbersAsync(); Task> GetLogsAsync(ApiLogRequest request); + } diff --git a/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs b/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs index c2fbc53b..608fbfbc 100644 --- a/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs +++ b/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs @@ -132,4 +132,14 @@ public class BalancesController : ControllerBase { return await _balanceService.BalanceRecordAnalysisAsync(request); } + + /// + /// 获取消费机总数、离线设备数量、营业点数量、可消费人数、人均日消费额 + /// + /// + [HttpGet("consumenumbers")] + public async Task GetConsumeNumberAsync() + { + return await _balanceService.GetConsumeNumberAsync(); + } } diff --git a/Src/Dlhis.Canteen/Order/Response/ConsumeNumberResponse.cs b/Src/Dlhis.Canteen/Order/Response/ConsumeNumberResponse.cs new file mode 100644 index 00000000..609b1a68 --- /dev/null +++ b/Src/Dlhis.Canteen/Order/Response/ConsumeNumberResponse.cs @@ -0,0 +1,30 @@ +namespace Dlhis.Canteen.Order.Response +{ + public class ConsumeNumberResponse + { + /// + /// 消费机总数 + /// + public int Total { get; set; } + + /// + /// 消费机离线数 + /// + public int OffNumber { get; set; } + + /// + /// 营业点总数 + /// + public int PlaceNumber { get; set; } + + /// + /// 可消费人数 + /// + public int ConsumerableNumber { get; set; } + + /// + /// 人均日消费额 + /// + public int DailyNumber { get; set; } + } +} diff --git a/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs b/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs index 8a12f2c4..6c78934d 100644 --- a/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs @@ -23,4 +23,6 @@ public interface IBalanceService : IScopeDependency Task> BalanceRecordSummaryByTidAsync(BalanceRecordSummaryRequest request); Task> BalanceRecordAnalysisAsync(BalanceRecordAnalysisRequest request); + + Task GetConsumeNumberAsync(); } diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs index eb6d36e4..256e9caf 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs @@ -547,6 +547,44 @@ public class BalanceService : IBalanceService }, 5); } + public async Task GetConsumeNumberAsync() + { + var devices = await _dbContext.Queryable() + .Where(x => x.Type == DeviceTypeEnumType.Meal) + .ToListAsync(); + + var offCount = devices.Where(x => x.Enable == false).Count(); + + var places = await _dbContext.Queryable() + .ToListAsync(); + + var time = DateTime.Now.ToString("yyyy-MM-dd"); + //所有消费数据 + var bs = await _dbContext.Queryable() + .Where(x => x.Type == BalanceRecordTypeEnumType.Out) + .ToListAsync(); + //可消费人数 + var consumerable = bs.Select(x => x.UserCode).Distinct().Count(); + + //当日消费数据 + var monthbs = bs + .Where(x => x.CostDateTime.ToString("yyyy-MM-dd") == time); + //当日消费额 + var monthlySpending = monthbs.Sum(x => x.Amount); + //当日消费人数 + var monthlyCount = monthbs.Select(x => x.UserCode).Distinct().Count(); + var res = new ConsumeNumberResponse + { + Total = devices.Count(), + OffNumber = offCount, + PlaceNumber = places.Count(), + ConsumerableNumber = consumerable, + DailyNumber = monthlyCount != 0 ? (int)Math.Ceiling(monthlySpending / monthlyCount) : 0 + }; + return res; + + } + //************************************************************** help methods ****************************************************************** From 170b6a1202886f1ad3d24cbe7580ad37ec960883 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 22 Feb 2024 14:30:03 +0800 Subject: [PATCH 005/146] =?UTF-8?q?feat=20=E5=88=9B=E5=BB=BA=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E9=BB=98=E8=AE=A4=E5=88=86=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/GainfosController.cs | 6 +- .../Response/GainfoPageResponse.cs | 8 +- .../Services/Implements/GainfoService.cs | 6 +- Src/Dlhis.Basic/Packs/SqlSugarPack.cs | 14 +- .../Basic/Entity/GainfoGroupEntity.cs | 25 ++- .../Device/Entities/DeviceGroupEntity.cs | 1 - .../CommonJobs/CreateDefinitelyGroupJob.cs | 163 ++++++++++++++++++ Src/Dlhis.ScheduledTask/Packs/JobPack.cs | 9 +- 8 files changed, 212 insertions(+), 20 deletions(-) create mode 100644 Src/Dlhis.ScheduledTask/CommonJobs/CreateDefinitelyGroupJob.cs diff --git a/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs b/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs index b6c09d43..33e9307f 100644 --- a/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs +++ b/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs @@ -2,12 +2,10 @@ using Dlhis.Basic.Organization.Request; using Dlhis.Basic.Organization.Response; using Dlhis.Basic.Organization.Services; -using Dlhis.Entity.Basic.Entity; using Kurisu.AspNetCore.MVC; using Kurisu.Core.DataAccess.Dto; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Org.BouncyCastle.Asn1.Ocsp; namespace Dlhis.Basic.MealUser.Controllers; @@ -142,7 +140,7 @@ public class GainfosController : ControllerBase /// /// /// - [HttpGet("gainfolist")] + [HttpGet("list")] public async Task> GetGainfoListTaskAsync([FromQuery]GainfoListRequest request) { return await _gainfoService.GetGainfoListTaskAsync(request); @@ -152,7 +150,7 @@ public class GainfosController : ControllerBase /// /// /// - [HttpGet("gainfodetail")] + [HttpGet("detail")] public async Task GetGainfoDetailTaskAsync([FromQuery] GainfoDetailRequest request) { return await _gainfoService.GetGainfoDetailTaskAsync(request); diff --git a/Src/Dlhis.Basic/Organization/Response/GainfoPageResponse.cs b/Src/Dlhis.Basic/Organization/Response/GainfoPageResponse.cs index df112cee..cb3c563c 100644 --- a/Src/Dlhis.Basic/Organization/Response/GainfoPageResponse.cs +++ b/Src/Dlhis.Basic/Organization/Response/GainfoPageResponse.cs @@ -1,4 +1,7 @@ -namespace Dlhis.Basic.Organization.Response; +using Dlhis.Entity.Basic.Enums; +using Kurisu.AspNetCore.Utils.Extensions; + +namespace Dlhis.Basic.Organization.Response; public class GainfoPageResponse { @@ -52,7 +55,8 @@ public class GainfoPageResponse /// /// 性别 /// - public string Gender { get; set; } + public GenderEnumType Gender { get; set; } + public string GenderDesc => Gender.GetDescription(); /// /// 生日 diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs index ce14552e..78753d46 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs @@ -53,9 +53,9 @@ public class GainfoService : IGainfoService var tenant = _currentUser.GetStringTenantId(); var page = await _gainfoStore.Queryable(request.Status) - .WhereIF(request.DepartmentNos?.Any() == true, gainfo => request.DepartmentNos.Contains(gainfo.DepartmentNo)) + .WhereIF(request.DepartmentNos.IsPresent(), gainfo => request.DepartmentNos.Contains(gainfo.DepartmentNo)) .WhereIF(request.Search.IsPresent(), gainfo => - gainfo.Name.Contains(request.Search) + gainfo.Name.Contains(request.Search) || gainfo.Code.Contains(request.Search)) .Where(gainfo => gainfo.Werks == tenant) .Select() @@ -561,7 +561,7 @@ public class GainfoService : IGainfoService /// private async Task> GetRecursionDepartmentNosAsync(List departmentNos) { - if (departmentNos == null || departmentNos.Count == 0) + if (departmentNos.IsEmpty()) { return new List(); } diff --git a/Src/Dlhis.Basic/Packs/SqlSugarPack.cs b/Src/Dlhis.Basic/Packs/SqlSugarPack.cs index f481ce85..d4467cae 100644 --- a/Src/Dlhis.Basic/Packs/SqlSugarPack.cs +++ b/Src/Dlhis.Basic/Packs/SqlSugarPack.cs @@ -17,14 +17,14 @@ public class SqlSugarPack : BaseAppPack public override void Configure(IApplicationBuilder app, IWebHostEnvironment env) { - //using var scope = app.ApplicationServices.CreateScope(); - //var db = scope.ServiceProvider.GetService(); - //var tables = App.ActiveTyps.Where(x => x.IsDefined(typeof(SugarTable), false)) - // .Where(x => !x.IsDefined(typeof(SkipScanAttribute), false)) - // .ToArray(); + using var scope = app.ApplicationServices.CreateScope(); + var db = scope.ServiceProvider.GetService(); + var tables = App.ActiveTyps.Where(x => x.IsDefined(typeof(SugarTable), false)) + .Where(x => !x.IsDefined(typeof(SkipScanAttribute), false)) + .ToArray(); - //db.DbMaintenance.CreateDatabase(); - //db.CodeFirst.InitTables(tables); + db.DbMaintenance.CreateDatabase(); + db.CodeFirst.InitTables(tables); //using var scopeFace = app.ApplicationServices.CreateScope(); //var dbFace = scopeFace.ServiceProvider.GetService(); diff --git a/Src/Dlhis.Entity/Basic/Entity/GainfoGroupEntity.cs b/Src/Dlhis.Entity/Basic/Entity/GainfoGroupEntity.cs index 2243b9e5..b7e533c0 100644 --- a/Src/Dlhis.Entity/Basic/Entity/GainfoGroupEntity.cs +++ b/Src/Dlhis.Entity/Basic/Entity/GainfoGroupEntity.cs @@ -1,4 +1,5 @@ -using Kurisu.SqlSugar; +using Kurisu.Core.DataAccess.Entity; +using Kurisu.SqlSugar; using SqlSugar; namespace Dlhis.Entity.Basic.Entity; @@ -7,8 +8,13 @@ namespace Dlhis.Entity.Basic.Entity; /// 档案组 /// [SugarTable(TableName = "GainfoGroup", TableDescription = "档案组")] -public class GainfoGroupEntity : SugarBaseEntity +public class GainfoGroupEntity : SugarBaseEntity, ITenantId { + /// + /// 父级Code + /// + public Guid? PCode { get; set; } + /// /// 分组code /// @@ -26,4 +32,19 @@ public class GainfoGroupEntity : SugarBaseEntity /// [SugarColumn(ColumnDescription = "备注")] public string Remark { get; set; } + + /// + /// 是否默认分组 + /// + [SugarColumn(ColumnDescription = "是否默认分组")] + public bool IsDefault { get; set; } + + /// + /// 是否可编辑 + /// + [SugarColumn(ColumnDescription = "是否可编辑")] + public bool Editable { get; set; } + + + public string TenantId { get; set; } } diff --git a/Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs b/Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs index 3c06d72e..6d037b6a 100644 --- a/Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs +++ b/Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs @@ -12,7 +12,6 @@ namespace Dlhis.Entity.Device.Entities; [SugarTable(TableName = "DeviceGroup", TableDescription = "设备组")] public class DeviceGroupEntity : SugarBaseEntity, ITenantId, ISoftDeleted { - /// /// 设备组功能类型 /// diff --git a/Src/Dlhis.ScheduledTask/CommonJobs/CreateDefinitelyGroupJob.cs b/Src/Dlhis.ScheduledTask/CommonJobs/CreateDefinitelyGroupJob.cs new file mode 100644 index 00000000..9390c884 --- /dev/null +++ b/Src/Dlhis.ScheduledTask/CommonJobs/CreateDefinitelyGroupJob.cs @@ -0,0 +1,163 @@ +using Dlhis.Entity.Basic.Entity; +using Dlhis.Entity.Device.Entities; +using Dlhis.Entity.Device.Enums; +using Dlhis.Sys.Api; +using Kurisu.Core.DataAccess.Entity; +using Kurisu.SqlSugar.Services; + +namespace Dlhis.ScheduledTask.CommonJobs; + +public class CreateDefinitelyGroupJob +{ + private readonly ILogger _logger; + private readonly ITenantApi _tenantApi; + private readonly IDbContext _dbContext; + + public CreateDefinitelyGroupJob(ILogger logger, ITenantApi tenantApi, IDbContext dbContext) + { + _logger = logger; + _tenantApi = tenantApi; + _dbContext = dbContext; + } + + public async Task RunAsync() + { + _dbContext.Client.QueryFilter.ClearAndBackup(); + try + { + var tenantResult = await _tenantApi.GetTenantsInternalAsync(); + var tenants = tenantResult.Data; + + foreach (var tenant in tenants) + { + if (!await _dbContext.Queryable().Where(x => x.TenantId == tenant.Code).AnyAsync(x => x.IsDefault)) + { + + var customGroup = new GainfoGroupEntity + { + PCode = null, + Code = Guid.NewGuid(), + Name = "*自定义人员分组", + IsDefault = true, + Editable = false, + + CreatedBy = 1, + CreateTime = DateTime.Now, + ModifiedBy = 1, + ModifiedTime = DateTime.Now, + TenantId = tenant.Code + }; + await _dbContext.InsertAsync(customGroup); + + + var groups = new[] { "*督查组", "*X3及以上领导组", "*外派人员组" }; + foreach (var group in groups) + { + var grp = new GainfoGroupEntity + { + PCode = null, + Code = Guid.NewGuid(), + Name = group, + IsDefault = false, + Editable = false, + + CreatedBy = 1, + CreateTime = DateTime.Now, + ModifiedBy = 1, + ModifiedTime = DateTime.Now, + TenantId = tenant.Code + }; + + await _dbContext.InsertAsync(grp); + } + } + + //**************************************************************************************************************/ + + if (!await _dbContext.Queryable().Where(x => x.TenantId == tenant.Code).AnyAsync(x => x.Name == "*通用考勤设备组")) + { + await _dbContext.InsertAsync(new DeviceGroupEntity + { + PCode = null, + Code = Guid.NewGuid(), + Type = DeviceTypeEnumType.Attendance, + Name = "*通用考勤设备组", + + CreatedBy = 1, + CreateTime = DateTime.Now, + ModifiedBy = 1, + ModifiedTime = DateTime.Now, + TenantId = tenant.Code, + }); + } + + if (!await _dbContext.Queryable().Where(x => x.TenantId == tenant.Code).AnyAsync(x => x.Name == "*专用考勤设备组")) + { + await _dbContext.InsertAsync(new DeviceGroupEntity + { + PCode = null, + Code = Guid.NewGuid(), + Type = DeviceTypeEnumType.Attendance, + Name = "*专用考勤设备组", + + CreatedBy = 1, + CreateTime = DateTime.Now, + ModifiedBy = 1, + ModifiedTime = DateTime.Now, + TenantId = tenant.Code, + }); + } + + //**************************************************************************************************************/ + + if (!await _dbContext.Queryable().Where(x => x.TenantId == tenant.Code) + .Where(x => x.Type == DeviceTypeEnumType.Door) + .AnyAsync(x => x.Name == "*通用考勤设备组") + ) + { + await _dbContext.InsertAsync(new DeviceGroupEntity + { + PCode = null, + Code = Guid.NewGuid(), + Type = DeviceTypeEnumType.Door, + Name = "*非公共区域", + + CreatedBy = 1, + CreateTime = DateTime.Now, + ModifiedBy = 1, + ModifiedTime = DateTime.Now, + TenantId = tenant.Code, + }); + } + + if (!await _dbContext.Queryable().Where(x => x.TenantId == tenant.Code) + .Where(x => x.Type == DeviceTypeEnumType.Door) + .AnyAsync(x => x.Name == "*专用考勤设备组") + ) + { + await _dbContext.InsertAsync(new DeviceGroupEntity + { + PCode = null, + Code = Guid.NewGuid(), + Type = DeviceTypeEnumType.Door, + Name = "*公共区域", + + CreatedBy = 1, + CreateTime = DateTime.Now, + ModifiedBy = 1, + ModifiedTime = DateTime.Now, + TenantId = tenant.Code, + }); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex, "自动创建系统分组失败:{message}", ex.Message); + } + finally + { + _dbContext.Client.QueryFilter.Restore(); + } + } +} diff --git a/Src/Dlhis.ScheduledTask/Packs/JobPack.cs b/Src/Dlhis.ScheduledTask/Packs/JobPack.cs index 49f75fff..ec5b214d 100644 --- a/Src/Dlhis.ScheduledTask/Packs/JobPack.cs +++ b/Src/Dlhis.ScheduledTask/Packs/JobPack.cs @@ -1,4 +1,5 @@ -using Dlhis.ScheduledTask.SyncSapInfo.Job; +using Dlhis.ScheduledTask.CommonJobs; +using Dlhis.ScheduledTask.SyncSapInfo.Job; using Dlhis.ScheduledTask.TaskAssignment.Job; using Hangfire; using Kurisu.AspNetCore.Startup; @@ -32,5 +33,11 @@ public class JobPack : BaseAppPack { TimeZone = TimeZoneInfo.Local }); + + //创建系统默认分组 + RecurringJob.AddOrUpdate("CreateDefinitelyGroup", s => s.RunAsync(), "0 0 5 * * ?", new RecurringJobOptions + { + TimeZone = TimeZoneInfo.Local + }); } } From 1ccacdf04d87793079bd52050b7e86dfe98e4aae Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 22 Feb 2024 14:46:43 +0800 Subject: [PATCH 006/146] =?UTF-8?q?fix=20=E6=9B=B4=E6=96=B0=E6=B3=A8?= =?UTF-8?q?=E9=87=8A=E5=92=8Crole-list?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Identity/Controllers/RolesController.cs | 11 +++++++ .../Identity/Response/RoleRespone.cs | 5 +++ .../Identity/Response/UserResponse.cs | 33 +++++++++++++++++++ .../Identity/Services/IRoleService.cs | 2 ++ .../Services/Implements/RoleService.cs | 16 +++++++++ 5 files changed, 67 insertions(+) diff --git a/Src/Dlhis.Sys/Identity/Controllers/RolesController.cs b/Src/Dlhis.Sys/Identity/Controllers/RolesController.cs index 8fa618fc..0924f7c3 100644 --- a/Src/Dlhis.Sys/Identity/Controllers/RolesController.cs +++ b/Src/Dlhis.Sys/Identity/Controllers/RolesController.cs @@ -34,6 +34,17 @@ public class RolesController : ControllerBase return await _roleService.GetPageAsync(request); } + /// + /// 角色列表 + /// + /// + [Authorize(Roles = "admin")] + [HttpGet("list")] + public async Task> GetListAsync() + { + return await _roleService.GetListAsync(); + } + /// /// 分配角色 /// diff --git a/Src/Dlhis.Sys/Identity/Response/RoleRespone.cs b/Src/Dlhis.Sys/Identity/Response/RoleRespone.cs index 0b233448..03cd8c23 100644 --- a/Src/Dlhis.Sys/Identity/Response/RoleRespone.cs +++ b/Src/Dlhis.Sys/Identity/Response/RoleRespone.cs @@ -7,4 +7,9 @@ public class RoleRespone public string Name { get; set; } public string NormalizedName { get; set; } + + /// + /// 是否可编辑 + /// + public bool Editable => Id > 5; } diff --git a/Src/Dlhis.Sys/Identity/Response/UserResponse.cs b/Src/Dlhis.Sys/Identity/Response/UserResponse.cs index d11dec11..45ff5c74 100644 --- a/Src/Dlhis.Sys/Identity/Response/UserResponse.cs +++ b/Src/Dlhis.Sys/Identity/Response/UserResponse.cs @@ -4,25 +4,58 @@ public class UserResponse { public int Id { get; set; } + /// + /// 账号名称 + /// public string UserName { get; set; } + /// + /// 规范化账号名称 + /// public string NormalizedUserName { get; set; } + /// + /// 邮件 + /// public string Email { get; set; } + /// + /// 规范化邮件 + /// public string NormalizedEmail { get; set; } + /// + /// 邮件是否已确认 + /// public bool EmailConfirmed { get; set; } + /// + /// 手机号 + /// public string PhoneNumber { get; set; } + /// + /// 手机号是否已确认 + /// public bool PhoneNumberConfirmed { get; set; } + /// + /// 是否开启双因素认证 + /// public bool TwoFactorEnabled { get; set; } + /// + /// 账号锁定结束时间 + /// public DateTime? LockoutEnd { get; set; } + /// + /// 是否开启账号锁定功能 + /// public bool LockoutEnabled { get; set; } + /// + /// 登陆失败次数 + /// public int AccessFailedCount { get; set; } } diff --git a/Src/Dlhis.Sys/Identity/Services/IRoleService.cs b/Src/Dlhis.Sys/Identity/Services/IRoleService.cs index eb101cc1..3b789429 100644 --- a/Src/Dlhis.Sys/Identity/Services/IRoleService.cs +++ b/Src/Dlhis.Sys/Identity/Services/IRoleService.cs @@ -8,6 +8,8 @@ public interface IRoleService : IScopeDependency { Task> GetPageAsync(RolePageRequest request); + Task> GetListAsync(); + Task SaveRoleAsync(RoleSaveRequest request); Task GetMyRoleAsync(); diff --git a/Src/Dlhis.Sys/Identity/Services/Implements/RoleService.cs b/Src/Dlhis.Sys/Identity/Services/Implements/RoleService.cs index 399b1d7f..38cd025a 100644 --- a/Src/Dlhis.Sys/Identity/Services/Implements/RoleService.cs +++ b/Src/Dlhis.Sys/Identity/Services/Implements/RoleService.cs @@ -9,6 +9,7 @@ using Kurisu.Core.DataAccess.Dto; using Kurisu.Core.User.Abstractions; using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Services; +using Org.BouncyCastle.Asn1.Ocsp; namespace Dlhis.Sys.Identity.Services.Implements; @@ -172,4 +173,19 @@ public class RoleService : IRoleService await dbContext.DeleteReallyAsync(role); }); } + + public async Task> GetListAsync() + { + return await Scoped.Request.Value.CreateAsync(async sp => + { + var dbContext = sp.GetService(); + var identityConnection = _configuration.GetSection("SqlSugarOptions:IdentityConnectionString").Value; + dbContext.Client.CurrentConnectionConfig.ConnectionString = identityConnection; + + + return await dbContext.Queryable() + .Select() + .ToListAsync(); + }); + } } From 9f5c2398329285b35b6b3a6b6140aed476b80d9a Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 22 Feb 2024 15:00:21 +0800 Subject: [PATCH 007/146] =?UTF-8?q?fix=20=E8=80=83=E5=8B=A4=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E7=94=9F=E6=88=90=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.ScheduledTask/Packs/JobPack.cs | 2 ++ .../TaskAssignment/Job/CreateGetAttendanceJob.cs | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Src/Dlhis.ScheduledTask/Packs/JobPack.cs b/Src/Dlhis.ScheduledTask/Packs/JobPack.cs index ec5b214d..5bccbd46 100644 --- a/Src/Dlhis.ScheduledTask/Packs/JobPack.cs +++ b/Src/Dlhis.ScheduledTask/Packs/JobPack.cs @@ -24,11 +24,13 @@ public class JobPack : BaseAppPack TimeZone = TimeZoneInfo.Local }); + //创建设备同步时间任务 RecurringJob.AddOrUpdate("SyncServerDateTime", s => s.RunAsync(), "0 0 0/1 * * ?", new RecurringJobOptions { TimeZone = TimeZoneInfo.Local }); + //创建设备获取考勤的任务 RecurringJob.AddOrUpdate("CreateGetAttendance", s => s.RunAsync(), "0 0/1 * * * ?", new RecurringJobOptions { TimeZone = TimeZoneInfo.Local diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateGetAttendanceJob.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateGetAttendanceJob.cs index 90a1703a..2e57474d 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateGetAttendanceJob.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateGetAttendanceJob.cs @@ -23,16 +23,19 @@ public class CreateGetAttendanceJob _dbContext.Client.QueryFilter.ClearAndBackup(); try { - var devices = await _dbContext.Queryable().Where(x => x.Enable).ToListAsync(); - devices = devices.Where(x => x.Funcs.Contains(DeviceFuncEnumType.Attendance)).ToList(); + var devices = await _dbContext.Queryable() + .Where(x => x.Enable) + .Where(x => x.Type == DeviceTypeEnumType.Attendance || (x.Type == DeviceTypeEnumType.Door && x.AsAttendance)) + .ToListAsync(); var ds = devices.Select(x => x.UniqueNo).ToList(); - var b = await _dbContext.Queryable() + var b = await _dbContext.Queryable() .Where(x => ds.Contains(x.DeviceUniqueNo)) .Where(x => x.Type == DeviceTaskEnumType.UploadRecord) .Where(x => x.Status == DeviceTaskStatusEnumType.Process) .AnyAsync(); + if (b) { return; From a08b08fbc159cf23f86c0f6cef2ed4b889a73824 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 22 Feb 2024 15:00:51 +0800 Subject: [PATCH 008/146] =?UTF-8?q?fix=20=E8=AE=BE=E5=A4=87,=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E5=88=86=E7=BB=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/DeviceGroupsController.cs | 6 +++-- .../Device/Request/DeviceGroupPageRequest.cs | 7 ++++- .../Device/Request/DeviceGroupSaveRequest.cs | 3 +-- .../Response/DeviceGroupPageResponse.cs | 26 ++++++++++++++++++- .../Response/DeviceUnderGroupResponse.cs | 10 ++++++- .../Device/Services/IDeviceGroupService.cs | 3 ++- .../Services/Implements/DeviceGroupService.cs | 18 ++++++++++++- Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs | 7 +++++ .../Device/Enums/DeviceTypeEnumType.cs | 6 ----- 9 files changed, 71 insertions(+), 15 deletions(-) diff --git a/Src/Dlhis.Basic/Device/Controllers/DeviceGroupsController.cs b/Src/Dlhis.Basic/Device/Controllers/DeviceGroupsController.cs index bba3ae80..c05c41ba 100644 --- a/Src/Dlhis.Basic/Device/Controllers/DeviceGroupsController.cs +++ b/Src/Dlhis.Basic/Device/Controllers/DeviceGroupsController.cs @@ -1,6 +1,7 @@ using Dlhis.Basic.Device.Request; using Dlhis.Basic.Device.Response; using Dlhis.Basic.Device.Services; +using Dlhis.Entity.Device.Enums; using Kurisu.Core.DataAccess.Dto; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -37,11 +38,12 @@ public class DeviceGroupsController : ControllerBase /// 获取设备组树 /// /// 是否显示设备 + /// 分组类型 /// [HttpGet("tree")] - public async Task> GetTreeAsync(bool showDevices) + public async Task> GetTreeAsync(bool showDevices, DeviceTypeEnumType? type) { - return await _deviceGroupService.GetTreeAsync(showDevices); + return await _deviceGroupService.GetTreeAsync(showDevices, type); } /// diff --git a/Src/Dlhis.Basic/Device/Request/DeviceGroupPageRequest.cs b/Src/Dlhis.Basic/Device/Request/DeviceGroupPageRequest.cs index 419810f2..aee1a3d9 100644 --- a/Src/Dlhis.Basic/Device/Request/DeviceGroupPageRequest.cs +++ b/Src/Dlhis.Basic/Device/Request/DeviceGroupPageRequest.cs @@ -1,7 +1,12 @@ -using Kurisu.Core.DataAccess.Dto; +using Dlhis.Entity.Device.Enums; +using Kurisu.Core.DataAccess.Dto; namespace Dlhis.Basic.Device.Request; public class DeviceGroupPageRequest : PageDto { + /// + /// 分组类型 + /// + public DeviceTypeEnumType? Type { get; set; } } diff --git a/Src/Dlhis.Basic/Device/Request/DeviceGroupSaveRequest.cs b/Src/Dlhis.Basic/Device/Request/DeviceGroupSaveRequest.cs index 35240dac..9cbf1ee9 100644 --- a/Src/Dlhis.Basic/Device/Request/DeviceGroupSaveRequest.cs +++ b/Src/Dlhis.Basic/Device/Request/DeviceGroupSaveRequest.cs @@ -21,7 +21,6 @@ public class DeviceGroupSaveRequest /// /// 分类类型 DeviceTypeEnumType /// - [Required(ErrorMessage = "分类不能为空")] [EnumDataType(typeof(DeviceTypeEnumType))] - public DeviceTypeEnumType Type { get; set; } + public DeviceTypeEnumType? Type { get; set; } } diff --git a/Src/Dlhis.Basic/Device/Response/DeviceGroupPageResponse.cs b/Src/Dlhis.Basic/Device/Response/DeviceGroupPageResponse.cs index 446557ed..8d81e4a4 100644 --- a/Src/Dlhis.Basic/Device/Response/DeviceGroupPageResponse.cs +++ b/Src/Dlhis.Basic/Device/Response/DeviceGroupPageResponse.cs @@ -1,4 +1,7 @@ -namespace Dlhis.Basic.Device.Response; +using Dlhis.Entity.Device.Enums; +using Kurisu.AspNetCore.Utils.Extensions; + +namespace Dlhis.Basic.Device.Response; public class DeviceGroupPageResponse { @@ -11,4 +14,25 @@ public class DeviceGroupPageResponse /// 设备组名称 /// public string Name { get; set; } + + /// + /// 分组类型 + /// + public DeviceTypeEnumType? Type { get; set; } + + /// + /// 分组类型描述 + /// + public string TypeDesc + { + get + { + if (!Type.HasValue) + { + return string.Empty; + } + + return Type.Value.GetDescription(); + } + } } diff --git a/Src/Dlhis.Basic/Device/Response/DeviceUnderGroupResponse.cs b/Src/Dlhis.Basic/Device/Response/DeviceUnderGroupResponse.cs index 806a7d9b..c9d59404 100644 --- a/Src/Dlhis.Basic/Device/Response/DeviceUnderGroupResponse.cs +++ b/Src/Dlhis.Basic/Device/Response/DeviceUnderGroupResponse.cs @@ -1,4 +1,6 @@ -namespace Dlhis.Basic.Device.Response; +using Dlhis.Entity.Device.Enums; + +namespace Dlhis.Basic.Device.Response; public class DeviceUnderGroupResponse { @@ -14,6 +16,12 @@ public class DeviceUnderGroupResponse /// public string Brand { get; set; } + /// + /// 设备类型 + /// + public DeviceTypeEnumType Type { get; set; } + + /// /// 是否启用 /// diff --git a/Src/Dlhis.Basic/Device/Services/IDeviceGroupService.cs b/Src/Dlhis.Basic/Device/Services/IDeviceGroupService.cs index e759376e..13368b4f 100644 --- a/Src/Dlhis.Basic/Device/Services/IDeviceGroupService.cs +++ b/Src/Dlhis.Basic/Device/Services/IDeviceGroupService.cs @@ -1,5 +1,6 @@ using Dlhis.Basic.Device.Request; using Dlhis.Basic.Device.Response; +using Dlhis.Entity.Device.Enums; using Kurisu.Core.DataAccess.Dto; namespace Dlhis.Basic.Device.Services; @@ -8,7 +9,7 @@ public interface IDeviceGroupService : IScopeDependency { Task> GetPageAsync(DeviceGroupPageRequest request); - Task> GetTreeAsync(bool showDevices); + Task> GetTreeAsync(bool showDevices, DeviceTypeEnumType? type); Task SaveAsync(DeviceGroupSaveRequest request); diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs index 3047dc21..04722357 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs @@ -2,6 +2,7 @@ using Dlhis.Basic.Device.Response; using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Device.Entities; +using Dlhis.Entity.Device.Enums; using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.DataAccess.Dto; using Kurisu.SqlSugar.Attributes; @@ -26,13 +27,15 @@ public class DeviceGroupService : IDeviceGroupService { return await _dbContext.Queryable() .WhereIF(request.Search.IsPresent(), x => x.Name.Contains(request.Search)) + .WhereIF(request.Type.HasValue, x => x.Type == request.Type) .Select() .ToPageListAsync(request); } - public async Task> GetTreeAsync(bool showDevices) + public async Task> GetTreeAsync(bool showDevices, DeviceTypeEnumType? type) { var deviceGroups = await _dbContext.Queryable() + .WhereIF(type.HasValue, x => x.Type == type) .Select() .ToListAsync(); @@ -61,6 +64,18 @@ public class DeviceGroupService : IDeviceGroupService { var entity = await _dbContext.Queryable().Where(x => x.Id == request.Id).FirstAsync(); entity.ThrowIfNull("设备组不存在,无法更新"); + + var nextDevices = await GetDevicesAsync(entity.Code); + if (!entity.Type.HasValue) + { + (request.Type.HasValue && nextDevices.Any(x => x.Type != request.Type)).ThrowIfTrue($"分组设备存在非{request.Type.Value.GetDescription()}类型的设备设备"); + } + else + { + (request.Type.HasValue && request.Type != entity.Type && nextDevices.Any()).ThrowIfTrue("分组设备类型不匹配,无法修改类型"); + } + + await _dbContext.UpdateAsync(entity); } } @@ -73,6 +88,7 @@ public class DeviceGroupService : IDeviceGroupService await _dbContext.DeleteAsync(deviceGroup); } + [Transactional] public async Task AssignDevicesAsync(DeviceAssignRequest request) { diff --git a/Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs b/Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs index 6c24630f..6bde31c3 100644 --- a/Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs +++ b/Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs @@ -84,5 +84,12 @@ public class DeviceEntity : SugarBaseEntity, ITenantId [SugarColumn(ColumnDataType = "bit", ColumnDescription = "是否启用")] public bool Enable { get; set; } + + /// + /// 是否作为考勤设备 + /// + [SugarColumn(ColumnDataType = "bit", ColumnDescription = "是否作为考勤设备")] + public bool AsAttendance { get; set; } + public string TenantId { get; set; } } \ No newline at end of file diff --git a/Src/Dlhis.Entity/Device/Enums/DeviceTypeEnumType.cs b/Src/Dlhis.Entity/Device/Enums/DeviceTypeEnumType.cs index 230e6e17..48c2ec70 100644 --- a/Src/Dlhis.Entity/Device/Enums/DeviceTypeEnumType.cs +++ b/Src/Dlhis.Entity/Device/Enums/DeviceTypeEnumType.cs @@ -25,10 +25,4 @@ public enum DeviceTypeEnumType /// [Description("考勤")] Attendance = 3, - - /// - /// 门禁并作为考勤 - /// - [Description("门禁并作为考勤")] - DoorAndAttendance = 4, } From 2d1678de9f6b5e6bf480d7bfb5d2d48e817d055b Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 22 Feb 2024 15:03:31 +0800 Subject: [PATCH 009/146] =?UTF-8?q?fix=20=E4=BD=9C=E4=B8=BA=E8=80=83?= =?UTF-8?q?=E5=8B=A4=E8=AE=BE=E5=A4=87=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Device/Request/DeviceSaveRequest.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Src/Dlhis.Basic/Device/Request/DeviceSaveRequest.cs b/Src/Dlhis.Basic/Device/Request/DeviceSaveRequest.cs index 10b3a65b..96bd0278 100644 --- a/Src/Dlhis.Basic/Device/Request/DeviceSaveRequest.cs +++ b/Src/Dlhis.Basic/Device/Request/DeviceSaveRequest.cs @@ -1,9 +1,10 @@ using System.ComponentModel.DataAnnotations; using Dlhis.Entity.Device.Enums; +using Kurisu.AspNetCore.Utils.Extensions; namespace Dlhis.Basic.Device.Request; -public class DeviceSaveRequest +public class DeviceSaveRequest : IValidatableObject { public long? Id { get; set; } @@ -70,4 +71,17 @@ public class DeviceSaveRequest /// 是否启用 /// public bool Enable { get; set; } + + /// + /// 是否作为考勤设备 + /// + public bool AsAttendance { get; set; } + + public IEnumerable Validate(ValidationContext validationContext) + { + if (Type != DeviceTypeEnumType.Door && AsAttendance) + { + yield return new ValidationResult($"{DeviceTypeEnumType.Door.GetDescription()}才可设置作为考勤设备", new[] { nameof(AsAttendance) }); + } + } } From 40b8e1af6866199a7346b59f4d4f9e130d2de7df Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Thu, 22 Feb 2024 15:12:31 +0800 Subject: [PATCH 010/146] =?UTF-8?q?feat=20=E6=97=A5/=E6=9C=88=E6=B6=88?= =?UTF-8?q?=E8=B4=B9=E8=B5=B0=E5=8A=BF=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Order/Controllers/BalancesController.cs | 20 ++++ .../Order/Request/ConsumptionTrendRequest.cs | 12 +++ .../Response/ConsumptionTrendResponse.cs | 20 ++++ .../Order/Services/IBalanceService.cs | 5 + .../Services/Implements/BalanceService.cs | 100 ++++++++++++++++++ .../Canteen/Enums/ConsumptionTrendEnumType.cs | 24 +++++ 6 files changed, 181 insertions(+) create mode 100644 Src/Dlhis.Canteen/Order/Request/ConsumptionTrendRequest.cs create mode 100644 Src/Dlhis.Canteen/Order/Response/ConsumptionTrendResponse.cs create mode 100644 Src/Dlhis.Entity/Canteen/Enums/ConsumptionTrendEnumType.cs diff --git a/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs b/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs index 608fbfbc..8ed0dd64 100644 --- a/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs +++ b/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs @@ -142,4 +142,24 @@ public class BalancesController : ControllerBase { return await _balanceService.GetConsumeNumberAsync(); } + + /// + /// 消费走势 + /// + /// + [HttpGet("consumptiontrends")] + public async Task> GetConsumptionTrendsAsync([FromQuery] ConsumptionTrendRequest request) + { + return await _balanceService.GetConsumptionTrendsAsync(request); + } + + /// + /// 餐补走势 + /// + /// + [HttpGet("supplementtrend")] + public async Task> GetSupplementTrendsAsync([FromQuery] ConsumptionTrendRequest request) + { + return await _balanceService.GetSupplementTrendsAsync(request); + } } diff --git a/Src/Dlhis.Canteen/Order/Request/ConsumptionTrendRequest.cs b/Src/Dlhis.Canteen/Order/Request/ConsumptionTrendRequest.cs new file mode 100644 index 00000000..7f223506 --- /dev/null +++ b/Src/Dlhis.Canteen/Order/Request/ConsumptionTrendRequest.cs @@ -0,0 +1,12 @@ +using Dlhis.Entity.Canteen.Enums; +using System.ComponentModel.DataAnnotations; + +namespace Dlhis.Canteen.Order.Request +{ + public class ConsumptionTrendRequest + { + [Required] + [EnumDataType(typeof(ConsumptionTrendEnumType))] + public ConsumptionTrendEnumType Type { get; set; } + } +} diff --git a/Src/Dlhis.Canteen/Order/Response/ConsumptionTrendResponse.cs b/Src/Dlhis.Canteen/Order/Response/ConsumptionTrendResponse.cs new file mode 100644 index 00000000..b490dd19 --- /dev/null +++ b/Src/Dlhis.Canteen/Order/Response/ConsumptionTrendResponse.cs @@ -0,0 +1,20 @@ +namespace Dlhis.Canteen.Order.Response +{ + public class ConsumptionTrendResponse + { + /// + /// 时间 + /// + public string DateTime { get; set; } + + /// + /// 当日/月消费总额 + /// + public decimal CurrentAmount { get; set; } + + /// + /// 消费总额 + /// + public decimal TotalAmount { get; set; } + } +} diff --git a/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs b/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs index 6c78934d..8ba54785 100644 --- a/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs @@ -1,6 +1,7 @@ using Dlhis.Canteen.Order.Request; using Dlhis.Canteen.Order.Response; using Kurisu.Core.DataAccess.Dto; +using Microsoft.AspNetCore.Mvc; namespace Dlhis.Canteen.Order.Services; @@ -25,4 +26,8 @@ public interface IBalanceService : IScopeDependency Task> BalanceRecordAnalysisAsync(BalanceRecordAnalysisRequest request); Task GetConsumeNumberAsync(); + + Task> GetConsumptionTrendsAsync(ConsumptionTrendRequest request); + + Task> GetSupplementTrendsAsync(ConsumptionTrendRequest request); } diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs index 256e9caf..08f58d1b 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs @@ -13,7 +13,9 @@ using Kurisu.Core.User.Abstractions; using Kurisu.SqlSugar.Attributes; using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Services; +using Microsoft.AspNetCore.Mvc; using SqlSugar; +using System.Globalization; namespace Dlhis.Canteen.Order.Services.Implements; @@ -584,6 +586,104 @@ public class BalanceService : IBalanceService return res; } + public async Task> GetConsumptionTrendsAsync(ConsumptionTrendRequest request) + { + var bs = await _dbContext.Queryable() + .Where(x => x.Type == BalanceRecordTypeEnumType.Out) + .ToListAsync(); + //消费总额 + var totalAmount = Math.Round(Math.Abs(bs.Sum(x => x.Amount)), 2); + + var list = new List(); + if (request.Type == ConsumptionTrendEnumType.Month) + { + //月与总额对比 + var months = GetMonthsOfYear(); + + foreach (var month in months) + { + var currentAmount = Math.Round(Math.Abs(bs.Where(x => x.CostDateTime.ToString("yyyy-MM") == month) + .Sum(x => x.Amount)), 2); + + var res = new ConsumptionTrendResponse + { + DateTime = month, + CurrentAmount = currentAmount, + TotalAmount = totalAmount + }; + list.Add(res); + } + } + else + { + //日与总额对比 + var days = GetDaysOfMonth(); + + foreach (var day in days) + { + var currentAmount = Math.Round(Math.Abs(bs.Where(x => x.CostDateTime.ToString("yyyy-MM-dd") == day) + .Sum(x => x.Amount)), 2); + + var res = new ConsumptionTrendResponse + { + DateTime = day, + CurrentAmount = currentAmount, + TotalAmount = totalAmount + }; + list.Add(res); + } + } + return list; + } + + public async Task> GetSupplementTrendsAsync(ConsumptionTrendRequest request) + { + //todo + return new List(); + } + + /// + /// 获取当前年所有月 + /// + /// + private List GetMonthsOfYear() + { + List months = new List(); + // 获取当前年份 + int year = DateTime.Now.Year; + // 遍历12个月份并添加到列表中 + for (int month = 1; month <= 12; month++) + { + DateTime monthDate = new DateTime(year, month, 1); + months.Add(monthDate.ToString("yyyy-MM")); + } + return months; + } + + /// + /// 获取当前月所有天 + /// + /// + private List GetDaysOfMonth() + { + List days = new List(); + + // 获取当前年份和月份 + int year = DateTime.Now.Year; + int month = DateTime.Now.Month; + + // 获取当前月份的第一天和最后一天 + DateTime firstDayOfMonth = new DateTime(year, month, 1); + DateTime lastDayOfMonth = firstDayOfMonth.AddMonths(1).AddDays(-1); + + // 遍历当前月的所有日期并添加到列表中 + for (DateTime date = firstDayOfMonth; date <= lastDayOfMonth; date = date.AddDays(1)) + { + days.Add(date.ToString("yyyy-MM-dd")); + } + + return days; + } //************************************************************** help methods ****************************************************************** diff --git a/Src/Dlhis.Entity/Canteen/Enums/ConsumptionTrendEnumType.cs b/Src/Dlhis.Entity/Canteen/Enums/ConsumptionTrendEnumType.cs new file mode 100644 index 00000000..e8573b48 --- /dev/null +++ b/Src/Dlhis.Entity/Canteen/Enums/ConsumptionTrendEnumType.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Dlhis.Entity.Canteen.Enums +{ + public enum ConsumptionTrendEnumType + { + /// + /// 日 + /// + [Description("日")] + Day = 1, + + /// + /// 月 + /// + [Description("月")] + Month = 2, + } +} From 82f942ed134eae315c4c23277dd5c07ad7dbf539 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 22 Feb 2024 15:32:24 +0800 Subject: [PATCH 011/146] =?UTF-8?q?fix=20role,user=E6=9F=A5=E7=9C=8B;=20?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Device/Response/DevicePageResponse.cs | 15 ++++++ .../Services/Implements/DeviceService.cs | 47 ++++++++++++++++++- .../Identity/Controllers/RolesController.cs | 4 +- .../Identity/Response/UserResponse.cs | 6 +++ .../Identity/Services/IRoleService.cs | 2 +- .../Services/Implements/RoleService.cs | 6 +-- .../Services/Implements/UserService.cs | 10 ++-- 7 files changed, 78 insertions(+), 12 deletions(-) diff --git a/Src/Dlhis.Basic/Device/Response/DevicePageResponse.cs b/Src/Dlhis.Basic/Device/Response/DevicePageResponse.cs index 448e34e9..d9d47179 100644 --- a/Src/Dlhis.Basic/Device/Response/DevicePageResponse.cs +++ b/Src/Dlhis.Basic/Device/Response/DevicePageResponse.cs @@ -84,4 +84,19 @@ public class DevicePageResponse /// 是否启用 /// public bool Enable { get; set; } + + /// + /// 是否在线 + /// + public bool IsOnline { get; set; } + + /// + /// 消费总额 + /// + public decimal Amount { get; set; } + + /// + /// 消费人次 + /// + public int UserCount { get; set; } } diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs index fe0257a7..8a7e9bb3 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs @@ -1,6 +1,8 @@ using Dlhis.Basic.Device.Request; using Dlhis.Basic.Device.Response; using Dlhis.Entity.Basic.Entity; +using Dlhis.Entity.Canteen.Entities; +using Dlhis.Entity.Canteen.Enums; using Dlhis.Entity.Device.Entities; using Dlhis.Entity.Device.Enums; using Kurisu.AspNetCore.Scope; @@ -11,7 +13,6 @@ using Kurisu.SqlSugar.Attributes; using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Services; using Mapster; -using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -40,9 +41,51 @@ public class DeviceService : IDeviceService }, true) .ToPageListAsync(request); + var now = DateTime.Now; + var deviceUniqueNos = page.Data.Select(x => x.UniqueNo).ToList(); + + var balanceRecords = await _dbContext.Queryable().Where(x => x.Type == BalanceRecordTypeEnumType.Out) + .Where(x => deviceUniqueNos.Contains(x.DeviceInfo)) + .ToListAsync(); + + var deviceRegistries = await _dbContext.Queryable() + .LeftJoin((x, d) => x.DeviceUniqueNo == d.UniqueNo) + .Where(x => deviceUniqueNos.Contains(x.DeviceUniqueNo)) + .Select((x, d) => new + { + d.HeartbeatInterval, + x.LastHeartbeatTime, + x.DeviceUniqueNo, + }) + .ToListAsync(); + + page.Data.ForEach(device => + { + device.Amount = balanceRecords.Sum(x => x.Amount); + device.UserCount = balanceRecords.DistinctBy(x => x.UserCode).Count(); + + var r = deviceRegistries.FirstOrDefault(x => x.DeviceUniqueNo == device.UniqueNo); + if (r == null) + { + device.IsOnline = false; + } + else + { + if (r.HeartbeatInterval <= 0) + { + device.IsOnline = true; + } + else + { + device.IsOnline = r.LastHeartbeatTime.AddSeconds(r.HeartbeatInterval * 3) >= now; + } + } + }); + return page; } + [Transactional] public async Task SaveAsync(DeviceSaveRequest request) { @@ -288,7 +331,7 @@ public class DeviceService : IDeviceService dbContext.Client.CurrentConnectionConfig.ConnectionString = logConnectionString; var logs = await dbContext.Queryable() .WhereIF(!request.message.IsEmpty(), x => x.Message.Contains(request.message)) - .WhereIF(!level.IsEmpty(),x => x.Level == level) + .WhereIF(!level.IsEmpty(), x => x.Level == level) .Select() .ToPageListAsync(request); return logs; diff --git a/Src/Dlhis.Sys/Identity/Controllers/RolesController.cs b/Src/Dlhis.Sys/Identity/Controllers/RolesController.cs index 0924f7c3..cd65a44d 100644 --- a/Src/Dlhis.Sys/Identity/Controllers/RolesController.cs +++ b/Src/Dlhis.Sys/Identity/Controllers/RolesController.cs @@ -85,8 +85,8 @@ public class RolesController : ControllerBase /// /// [HttpGet("my")] - public async Task GetMyRoleAsync() + public async Task GetMyRoleAsync(int? userId) { - return await _roleService.GetMyRoleAsync(); + return await _roleService.GetMyRoleAsync(userId); } } diff --git a/Src/Dlhis.Sys/Identity/Response/UserResponse.cs b/Src/Dlhis.Sys/Identity/Response/UserResponse.cs index 45ff5c74..15c1fe33 100644 --- a/Src/Dlhis.Sys/Identity/Response/UserResponse.cs +++ b/Src/Dlhis.Sys/Identity/Response/UserResponse.cs @@ -58,4 +58,10 @@ public class UserResponse /// 登陆失败次数 /// public int AccessFailedCount { get; set; } + + + /// + /// 角色 + /// + public string Role { get; set; } } diff --git a/Src/Dlhis.Sys/Identity/Services/IRoleService.cs b/Src/Dlhis.Sys/Identity/Services/IRoleService.cs index 3b789429..8b02ba23 100644 --- a/Src/Dlhis.Sys/Identity/Services/IRoleService.cs +++ b/Src/Dlhis.Sys/Identity/Services/IRoleService.cs @@ -12,7 +12,7 @@ public interface IRoleService : IScopeDependency Task SaveRoleAsync(RoleSaveRequest request); - Task GetMyRoleAsync(); + 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 38cd025a..2702f1a2 100644 --- a/Src/Dlhis.Sys/Identity/Services/Implements/RoleService.cs +++ b/Src/Dlhis.Sys/Identity/Services/Implements/RoleService.cs @@ -9,7 +9,6 @@ using Kurisu.Core.DataAccess.Dto; using Kurisu.Core.User.Abstractions; using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Services; -using Org.BouncyCastle.Asn1.Ocsp; namespace Dlhis.Sys.Identity.Services.Implements; @@ -40,9 +39,9 @@ public class RoleService : IRoleService }); } - public async Task GetMyRoleAsync() + public async Task GetMyRoleAsync(int? userId) { - var userId = _currentUser.GetIntSubjectId(); + userId ??= _currentUser.GetIntSubjectId(); return await Scoped.Request.Value.CreateAsync(async sp => { @@ -50,7 +49,6 @@ public class RoleService : IRoleService var identityConnection = _configuration.GetSection("SqlSugarOptions:IdentityConnectionString").Value; dbContext.Client.CurrentConnectionConfig.ConnectionString = identityConnection; - return await dbContext.Queryable() .LeftJoin((x, r) => x.RoleId == r.Id) .Where(x => x.UserId == userId) diff --git a/Src/Dlhis.Sys/Identity/Services/Implements/UserService.cs b/Src/Dlhis.Sys/Identity/Services/Implements/UserService.cs index f27e0528..63a9b19f 100644 --- a/Src/Dlhis.Sys/Identity/Services/Implements/UserService.cs +++ b/Src/Dlhis.Sys/Identity/Services/Implements/UserService.cs @@ -1,5 +1,4 @@ -using System.Configuration; -using Dlhis.Entity.Sys.Entities; +using Dlhis.Entity.Sys.Entities; using Dlhis.Sys.Identity.Request; using Dlhis.Sys.Identity.Response; using Kurisu.AspNetCore.Utils.Extensions; @@ -23,13 +22,18 @@ public class UserService : IUserService public async Task> GetPageAsync(UserPageRequest request) { return await _dbContext.Queryable() + .LeftJoin((x, ur) => x.Id == ur.UserId) + .LeftJoin((x, ur, r) => ur.RoleId == r.Id) .WhereIF(request.Search.IsPresent(), x => x.UserName.Contains(request.Search) || x.NormalizedUserName.Contains(request.Search) || x.Email.Contains(request.Search) || x.NormalizedEmail.Contains(request.Search) || x.PhoneNumber.Contains(request.Search) ) - .Select() + .Select((x, ur, r) => new UserResponse + { + Id = x.Id + }, true) .ToPageListAsync(request); } From f4acba8c6b428ce44fd19e23c73acb17b2e3496e Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 22 Feb 2024 16:02:19 +0800 Subject: [PATCH 012/146] =?UTF-8?q?fix=20=E7=A7=BB=E9=99=A4=E6=97=A0?= =?UTF-8?q?=E7=94=A8=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/GainfosController.cs | 54 +----------- .../Organization/Request/GainfoSaveRequest.cs | 5 -- .../Response/GainfoDetailResponse.cs | 5 -- .../Response/GainfoListResponse.cs | 87 +++++++++---------- .../Response/GainfoPageResponse.cs | 5 -- .../Organization/Services/IGainfoService.cs | 8 -- .../Services/Implements/GainfoService.cs | 48 +--------- Src/Dlhis.Basic/Packs/SqlSugarPack.cs | 3 +- Src/Dlhis.Entity/Basic/Entity/GainfoEntity.cs | 6 -- 9 files changed, 44 insertions(+), 177 deletions(-) diff --git a/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs b/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs index 33e9307f..39d3405f 100644 --- a/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs +++ b/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs @@ -141,7 +141,7 @@ public class GainfosController : ControllerBase /// /// [HttpGet("list")] - public async Task> GetGainfoListTaskAsync([FromQuery]GainfoListRequest request) + public async Task> GetGainfoListTaskAsync([FromQuery] GainfoListRequest request) { return await _gainfoService.GetGainfoListTaskAsync(request); } @@ -155,57 +155,5 @@ public class GainfosController : ControllerBase { return await _gainfoService.GetGainfoDetailTaskAsync(request); } - - /// - /// 获取近七天入职人数及列表 - /// - /// - [HttpGet("weeknumber")] - public async Task>> GetWeekNumberAsync([FromQuery] WeekNumberRequest request) - { - // 从请求头中获取 Token - string token = HttpContext.Request.Headers["Authorization"].ToString().Replace("Bearer ", ""); - - return await _gainfoService.GetWeekNumberAsync(request,token); - } - - /// - /// 获取近七天离职人数及列表 - /// - /// - [HttpGet("weeknumberdimission")] - public async Task>> GetDimissionWeekNumberAsync([FromQuery] WeekNumberRequest request) - { - // 从请求头中获取 Token - string token = HttpContext.Request.Headers["Authorization"].ToString().Replace("Bearer ", ""); - - return await _gainfoService.GetDimissionWeekNumberAsync(request,token); - } - - /// - /// 获取基地在职、离职、考勤数 - /// - /// - [HttpGet("gainfonumbers")] - public async Task GetGainfoNumbersAsync() - { - // 从请求头中获取 Token - string token = HttpContext.Request.Headers["Authorization"].ToString().Replace("Bearer ", ""); - - return await _gainfoService.GetGainfoNumbersAsync(token); - } - - /// - /// 获取本基地管理员列表 - /// - /// - /// - [HttpGet("administrator")] - public async Task> GetAdministratorAsync([FromQuery] WeekNumberRequest request) - { - // 从请求头中获取 Token - string token = HttpContext.Request.Headers["Authorization"].ToString().Replace("Bearer ", ""); - return await _gainfoService.GetAdministratorAsync(request,token); - } } diff --git a/Src/Dlhis.Basic/Organization/Request/GainfoSaveRequest.cs b/Src/Dlhis.Basic/Organization/Request/GainfoSaveRequest.cs index 54f41fe3..838f621c 100644 --- a/Src/Dlhis.Basic/Organization/Request/GainfoSaveRequest.cs +++ b/Src/Dlhis.Basic/Organization/Request/GainfoSaveRequest.cs @@ -110,11 +110,6 @@ public class GainfoSaveRequest : IValidatableObject /// public string Werks { get; set; } - /// - /// 在职状态 - /// - public string Employed { get; set; } - public IEnumerable Validate(ValidationContext validationContext) { if (GainfoStatus.HasValue && GainfoStatus == GainfoStatusEnumType.Leave) diff --git a/Src/Dlhis.Basic/Organization/Response/GainfoDetailResponse.cs b/Src/Dlhis.Basic/Organization/Response/GainfoDetailResponse.cs index a2472cfe..565d53dc 100644 --- a/Src/Dlhis.Basic/Organization/Response/GainfoDetailResponse.cs +++ b/Src/Dlhis.Basic/Organization/Response/GainfoDetailResponse.cs @@ -105,10 +105,5 @@ namespace Dlhis.Basic.Organization.Response /// 民族代码 /// public string NationName { get; set; } - - /// - /// 是否在职 - /// - public bool IsActive { get; set; } } } diff --git a/Src/Dlhis.Basic/Organization/Response/GainfoListResponse.cs b/Src/Dlhis.Basic/Organization/Response/GainfoListResponse.cs index a826eec0..8e7c6789 100644 --- a/Src/Dlhis.Basic/Organization/Response/GainfoListResponse.cs +++ b/Src/Dlhis.Basic/Organization/Response/GainfoListResponse.cs @@ -1,60 +1,51 @@ using Dlhis.Entity.Basic.Enums; -using SqlSugar; -using SqlSugar.DbConvert; -namespace Dlhis.Basic.Organization.Response +namespace Dlhis.Basic.Organization.Response; + +public class GainfoListResponse { - public class GainfoListResponse - { - /// - /// 档案号 - /// - public string No { get; set; } + /// + /// 档案号 + /// + public string No { get; set; } - /// - /// 姓名 - /// - public string Name { get; set; } + /// + /// 姓名 + /// + public string Name { get; set; } - /// - /// 学工号 - /// - public string Code { get; set; } + /// + /// 学工号 + /// + public string Code { get; set; } - /// - /// 身份证号 - /// - public string IdNo { get; set; } + /// + /// 身份证号 + /// + public string IdNo { get; set; } - /// - /// 性别 - /// - public GenderEnumType Gender { get; set; } + /// + /// 性别 + /// + public GenderEnumType Gender { get; set; } - /// - /// 手机号码 - /// - public string Phone { get; set; } + /// + /// 手机号码 + /// + public string Phone { get; set; } - /// - /// 部门编码 - /// - public string DepartmentNo { get; set; } + /// + /// 部门编码 + /// + public string DepartmentNo { get; set; } - /// - /// 部门名称 - /// - public string DepartmentName { get; set; } + /// + /// 部门名称 + /// + public string DepartmentName { get; set; } - /// - /// 身份证地址 - /// - public string Address { get; set; } - - /// - /// 在职状态 - /// - public string Employed { get; set; } - - } + /// + /// 身份证地址 + /// + public string Address { get; set; } } diff --git a/Src/Dlhis.Basic/Organization/Response/GainfoPageResponse.cs b/Src/Dlhis.Basic/Organization/Response/GainfoPageResponse.cs index cb3c563c..4b8faadd 100644 --- a/Src/Dlhis.Basic/Organization/Response/GainfoPageResponse.cs +++ b/Src/Dlhis.Basic/Organization/Response/GainfoPageResponse.cs @@ -112,9 +112,4 @@ public class GainfoPageResponse /// 人事范围 /// public string Werks { get; set; } - - /// - /// 在职状态 - /// - public string Employed { get; set; } } diff --git a/Src/Dlhis.Basic/Organization/Services/IGainfoService.cs b/Src/Dlhis.Basic/Organization/Services/IGainfoService.cs index 7bb8f0fc..7372f48d 100644 --- a/Src/Dlhis.Basic/Organization/Services/IGainfoService.cs +++ b/Src/Dlhis.Basic/Organization/Services/IGainfoService.cs @@ -31,12 +31,4 @@ public interface IGainfoService : IScopeDependency Task> GetGainfoListTaskAsync(GainfoListRequest request); Task GetGainfoDetailTaskAsync(GainfoDetailRequest request); - - Task>> GetWeekNumberAsync(WeekNumberRequest request, string token); - - Task>> GetDimissionWeekNumberAsync([FromQuery] WeekNumberRequest request, string token); - - Task GetGainfoNumbersAsync(string token); - - Task> GetAdministratorAsync(WeekNumberRequest request,string token); } diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs index 78753d46..f21150bd 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs @@ -333,10 +333,10 @@ public class GainfoService : IGainfoService DepartmentNo = de.No, DepartmentName = de.Name, Address = ga.Address, - Employed = ga.Employed }).ToPageListAsync(request); return page; } + /// /// 档案详情 /// @@ -373,8 +373,8 @@ public class GainfoService : IGainfoService Marital = ga.Marital, CountryName = type2.Display, NationName = type3.Display, - IsActive = ga.Employed == "Active" ? true : false, }).FirstAsync(); + return info; } @@ -425,11 +425,8 @@ public class GainfoService : IGainfoService Marital = ga.Marital, CountryName = type2.Display, NationName = type3.Display, - IsActive = ga.Employed == "Active" ? true : false, }).ToPageListAsync(request); - //var infos = await _gainfoStore.Queryable(GainfoStatusEnumType.Working) - // .Where(ga => ga.CreateTime.ToString("yyyy-MM-dd") == time) - // .ToPageListAsync(request); + dic[time] = infos; } return dic; @@ -481,7 +478,6 @@ public class GainfoService : IGainfoService Marital = ga.Marital, CountryName = type2.Display, NationName = type3.Display, - IsActive = ga.Employed == "Active" ? true : false, }).ToPageListAsync(request); dic[time] = infos; } @@ -514,44 +510,6 @@ public class GainfoService : IGainfoService return res; } - public async Task> GetAdministratorAsync( WeekNumberRequest request, string token) - { - var werks = GetClaimValueFromToken(token, "tenant"); - var info = await _gainfoStore.Queryable(GainfoStatusEnumType.Working) - .LeftJoin((ga, de) => ga.DepartmentNo == de.No) - .LeftJoin((ga, de, type) => ga.Native == type.Code && type.Type == "native") - .LeftJoin((ga, de, type, posi) => ga.Position == posi.Name) - .LeftJoin((ga, de, type, posi, type2) => ga.CountryNo == type2.Code && type2.Type == "country") - .LeftJoin((ga, de, type, posi, type2, type3) => ga.Nation == type3.Code && type3.Type == "nation") - .Where(ga => ga.Werks == werks && ga.IdentityUserId != 0) - .Select((ga, de, type, posi, type2, type3) => new GainfoDetailResponse - { - No = ga.No, - SapNo = ga.SapNo, - Name = ga.Name, - Code = ga.Code, - DepartmentName = de.Name, - IdClass = ga.IdClass, - IdNo = ga.IdNo, - Gender = ga.Gender, - NativeName = type.Display, - Address = ga.Address, - Birthday = ga.Birthday, - Phone = ga.Phone, - Position = ga.Position, - Grade = posi.Grade, - Degree = ga.Degree, - Werks = ga.Werks, - CostId = ga.CostId, - Marital = ga.Marital, - CountryName = type2.Display, - NationName = type3.Display, - IsActive = ga.Employed == "Active" ? true : false, - }).ToPageListAsync(request); - - return info; - } - //-------------------------------------------help methods ------------------------------------------------ /// diff --git a/Src/Dlhis.Basic/Packs/SqlSugarPack.cs b/Src/Dlhis.Basic/Packs/SqlSugarPack.cs index d4467cae..86dc45aa 100644 --- a/Src/Dlhis.Basic/Packs/SqlSugarPack.cs +++ b/Src/Dlhis.Basic/Packs/SqlSugarPack.cs @@ -1,5 +1,4 @@ -using Dlhis.Entity.Basic.Entity; -using Kurisu.AspNetCore; +using Kurisu.AspNetCore; using Kurisu.AspNetCore.Startup; using Kurisu.SqlSugar.Extensions; using SqlSugar; diff --git a/Src/Dlhis.Entity/Basic/Entity/GainfoEntity.cs b/Src/Dlhis.Entity/Basic/Entity/GainfoEntity.cs index 1ddbe206..66ff9e59 100644 --- a/Src/Dlhis.Entity/Basic/Entity/GainfoEntity.cs +++ b/Src/Dlhis.Entity/Basic/Entity/GainfoEntity.cs @@ -148,12 +148,6 @@ public class GainfoEntity : SugarBaseEntity /// public string CostId { get; set; } - /// - /// 在职状态 - /// - [SugarColumn(ColumnDescription = "在职状态")] - public string Employed { get; set; } - /// /// 身份认证用户Id /// From d3c8c211bfa192d12fff1eb155159fab638f6ee0 Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Thu, 22 Feb 2024 16:24:16 +0800 Subject: [PATCH 013/146] =?UTF-8?q?feat=20=E7=94=B5=E5=AD=90=E9=A4=90?= =?UTF-8?q?=E5=88=B8=E7=94=B3=E8=AF=B7/=E4=BD=BF=E7=94=A8=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Order/Controllers/BalancesController.cs | 22 ++++ .../Request/OaEMealVoucherDetailRequest.cs | 12 +++ .../Order/Request/OaEMealVoucherRequest.cs | 14 +++ .../Response/OaEMealVoucherDetailResponse.cs | 65 ++++++++++++ .../Order/Response/OaEMealVoucherResponse.cs | 100 ++++++++++++++++++ .../Order/Services/IBalanceService.cs | 4 + .../Services/Implements/BalanceService.cs | 19 ++++ 7 files changed, 236 insertions(+) create mode 100644 Src/Dlhis.Canteen/Order/Request/OaEMealVoucherDetailRequest.cs create mode 100644 Src/Dlhis.Canteen/Order/Request/OaEMealVoucherRequest.cs create mode 100644 Src/Dlhis.Canteen/Order/Response/OaEMealVoucherDetailResponse.cs create mode 100644 Src/Dlhis.Canteen/Order/Response/OaEMealVoucherResponse.cs diff --git a/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs b/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs index 8ed0dd64..8c306db1 100644 --- a/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs +++ b/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs @@ -162,4 +162,26 @@ public class BalancesController : ControllerBase { return await _balanceService.GetSupplementTrendsAsync(request); } + + /// + /// 电子餐券申请记录查询 + /// + /// + [HttpGet("oaemealvoucher")] + public async Task> GetOaEMealVoucherAsync([FromQuery] OaEMealVoucherRequest request) + { + return await _balanceService.GetOaEMealVoucherAsync(request); + } + + /// + /// 电子餐券使用记录查询 + /// + /// + /// + [HttpGet("oaemealvoucherdetail")] + public async Task> GetOaEMealVoucherDetailAsync([FromQuery] OaEMealVoucherDetailRequest request) + { + return await _balanceService.GetOaEMealVoucherDetailAsync(request); + } + } diff --git a/Src/Dlhis.Canteen/Order/Request/OaEMealVoucherDetailRequest.cs b/Src/Dlhis.Canteen/Order/Request/OaEMealVoucherDetailRequest.cs new file mode 100644 index 00000000..1a4d504b --- /dev/null +++ b/Src/Dlhis.Canteen/Order/Request/OaEMealVoucherDetailRequest.cs @@ -0,0 +1,12 @@ +using Kurisu.Core.DataAccess.Dto; + +namespace Dlhis.Canteen.Order.Request +{ + public class OaEMealVoucherDetailRequest : PageDto + { + /// + /// 餐券id + /// + public long OaEMealVoucherId { get; set; } + } +} diff --git a/Src/Dlhis.Canteen/Order/Request/OaEMealVoucherRequest.cs b/Src/Dlhis.Canteen/Order/Request/OaEMealVoucherRequest.cs new file mode 100644 index 00000000..a77865a7 --- /dev/null +++ b/Src/Dlhis.Canteen/Order/Request/OaEMealVoucherRequest.cs @@ -0,0 +1,14 @@ +using Dlhis.Entity.Canteen.Enums; +using Kurisu.Core.DataAccess.Dto; +using System.ComponentModel.DataAnnotations; + +namespace Dlhis.Canteen.Order.Request +{ + public class OaEMealVoucherRequest : PageDto + { + /// + /// 用户学工号 + /// + public string UserCode { get; set; } + } +} diff --git a/Src/Dlhis.Canteen/Order/Response/OaEMealVoucherDetailResponse.cs b/Src/Dlhis.Canteen/Order/Response/OaEMealVoucherDetailResponse.cs new file mode 100644 index 00000000..d57c1e7e --- /dev/null +++ b/Src/Dlhis.Canteen/Order/Response/OaEMealVoucherDetailResponse.cs @@ -0,0 +1,65 @@ +using SqlSugar; + +namespace Dlhis.Canteen.Order.Response +{ + public class OaEMealVoucherDetailResponse + { + public long Id { get; set; } + + public long VoucherId { get; set; } + + public int Sequence { get; set; } + + public string DinnerType { get; set; } + + /// + /// 身份证 + /// + public string IdNo { get; set; } + + /// + /// 用餐人 + /// + public string Name { get; set; } + + /// + /// 手机号 + /// + public string Phone { get; set; } + + /// + /// 就餐开始 + /// + public DateTime Start { get; set; } + + /// + /// 就餐结束 + /// + public DateTime End { get; set; } + + /// + /// 就餐天数 + /// + public int Days { get; set; } + + /// + /// 金额 + /// + public decimal Amount { get; set; } + + /// + /// 二维码 + /// + public string QrCode { get; set; } + + /// + /// 状态 + /// + public string Status { get; set; } + + /// + /// 信息 + /// + public string Message { get; set; } + } +} diff --git a/Src/Dlhis.Canteen/Order/Response/OaEMealVoucherResponse.cs b/Src/Dlhis.Canteen/Order/Response/OaEMealVoucherResponse.cs new file mode 100644 index 00000000..32ceaeb3 --- /dev/null +++ b/Src/Dlhis.Canteen/Order/Response/OaEMealVoucherResponse.cs @@ -0,0 +1,100 @@ +using SqlSugar; + +namespace Dlhis.Canteen.Order.Response +{ + public class OaEMealVoucherResponse + { + public long Id { get; set; } + + /// + /// 标题 + /// + public string Title { get; set; } + + /// + /// 申请人工号 + /// + public string UserCode { get; set; } + + /// + /// 申请人名称 + /// + public string Name { get; set; } + + /// + /// 基地代码 + /// + public string TenantId { get; set; } + + /// + /// 基地名称 + /// + public string TenantName { get; set; } + + /// + /// 成本中心 + /// + public string CostId { get; set; } + + /// + /// 成本中心名称 + /// + public string CostName { get; set; } + + /// + /// 来宾公司 + /// + public string Company { get; set; } + + /// + /// 联系人 + /// + public string Phone { get; set; } + + /// + /// 来宾人数 + /// + public int Num { get; set; } + + /// + /// 就餐食堂 + /// + public string Canteen { get; set; } + + /// + /// 就餐事由 + /// + public string Reason { get; set; } + + /// + /// 就餐次 + /// + public string CanteenShift { get; set; } + + /// + /// oa流程id + /// + public string OaId { get; set; } + + /// + /// 部门号 + /// + public string DepartmentNo { get; set; } + + /// + /// 部门名称 + /// + public string DepartmentName { get; set; } + + + /// + /// 申请日期 + /// + public DateTime LogDate { get; set; } + + /// + /// 数据创建时间 + /// + public DateTime CreateTime { get; set; } + } +} diff --git a/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs b/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs index 8ba54785..1c02cd6f 100644 --- a/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs @@ -30,4 +30,8 @@ public interface IBalanceService : IScopeDependency Task> GetConsumptionTrendsAsync(ConsumptionTrendRequest request); Task> GetSupplementTrendsAsync(ConsumptionTrendRequest request); + + Task> GetOaEMealVoucherAsync([FromQuery] OaEMealVoucherRequest request); + + Task> GetOaEMealVoucherDetailAsync([FromQuery] OaEMealVoucherDetailRequest request); } diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs index 08f58d1b..9a3f88b0 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs @@ -642,6 +642,25 @@ public class BalanceService : IBalanceService return new List(); } + public async Task> GetOaEMealVoucherAsync(OaEMealVoucherRequest request) + { + var page = await _dbContext.Queryable() + .Where(x => x.UserCode == request.UserCode) + .Select() + .ToPageListAsync(request); + return page; + } + + public async Task> GetOaEMealVoucherDetailAsync(OaEMealVoucherDetailRequest request) + { + var page = await _dbContext.Queryable() + .Where(x => x.VoucherId == request.OaEMealVoucherId) + .Select() + .ToPageListAsync(request); + + return page; + } + /// /// 获取当前年所有月 /// From 2a21e6bd5b42268f841c685c1c1e65ba91ff4628 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 22 Feb 2024 16:36:43 +0800 Subject: [PATCH 014/146] =?UTF-8?q?fix=20=E4=BC=98=E5=8C=96=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.ScheduledTask/SyncSapInfo/Job/SyncPersonJob.cs | 3 +-- .../TaskAssignment/Job/CreateGetAttendanceJob.cs | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Src/Dlhis.ScheduledTask/SyncSapInfo/Job/SyncPersonJob.cs b/Src/Dlhis.ScheduledTask/SyncSapInfo/Job/SyncPersonJob.cs index 4bf792b5..9cdb0089 100644 --- a/Src/Dlhis.ScheduledTask/SyncSapInfo/Job/SyncPersonJob.cs +++ b/Src/Dlhis.ScheduledTask/SyncSapInfo/Job/SyncPersonJob.cs @@ -123,10 +123,10 @@ public class SyncPersonJob //CarNo Remark = item.remark, Werks = item.WERKS, - Employed = item.isowner, }; await _dbContext.InsertAsync(info); } + private async Task UpdatePerson(GainfoSapEntity item) { var gainfo = await _dbContext.Queryable().Where(x => x.IdNo == item.idno).FirstAsync(); @@ -138,7 +138,6 @@ public class SyncPersonJob Position = item.web, Phone = item.phone, DepartmentNo = item.appellation, - Employed = item.isowner, Remark = item.remark, Degree = item.email, Werks = item.WERKS diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateGetAttendanceJob.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateGetAttendanceJob.cs index 2e57474d..34c614ae 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateGetAttendanceJob.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateGetAttendanceJob.cs @@ -33,7 +33,7 @@ public class CreateGetAttendanceJob var b = await _dbContext.Queryable() .Where(x => ds.Contains(x.DeviceUniqueNo)) .Where(x => x.Type == DeviceTaskEnumType.UploadRecord) - .Where(x => x.Status == DeviceTaskStatusEnumType.Process) + .Where(x => x.Status == DeviceTaskStatusEnumType.Process || x.Status == DeviceTaskStatusEnumType.Wait) .AnyAsync(); if (b) From 77d3207bb48d3c2ed9b6c823d2d2b8378283dcf8 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 22 Feb 2024 16:37:35 +0800 Subject: [PATCH 015/146] =?UTF-8?q?fix=20=E8=8E=B7=E5=8F=96=E8=80=83?= =?UTF-8?q?=E5=8B=A4=E4=BA=BA=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Summary/Response/AttendanceDetailSummary.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Src/Dlhis.Basic/Summary/Response/AttendanceDetailSummary.cs b/Src/Dlhis.Basic/Summary/Response/AttendanceDetailSummary.cs index f4f9c24a..a013bb6a 100644 --- a/Src/Dlhis.Basic/Summary/Response/AttendanceDetailSummary.cs +++ b/Src/Dlhis.Basic/Summary/Response/AttendanceDetailSummary.cs @@ -1,9 +1,12 @@ -using Dlhis.Basic.Summary.Dto; - -namespace Dlhis.Basic.Summary.Response; +namespace Dlhis.Basic.Summary.Response; public class AttendanceDetailSummary { + /// + /// 考勤总人数 + /// + public int Total => Employed + Unemployed; + /// /// 在职人数 /// From e3710ad0a5ed73d97b2869e683f41353d714a175 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 22 Feb 2024 16:37:52 +0800 Subject: [PATCH 016/146] =?UTF-8?q?feat=20=E6=89=B9=E9=87=8F=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E4=BA=BA=E8=84=B8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/GainfosController.cs | 11 +++++ .../Organization/Services/IGainfoService.cs | 3 +- .../Services/Implements/GainfoService.cs | 48 +++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs b/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs index 39d3405f..e577baaa 100644 --- a/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs +++ b/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs @@ -100,6 +100,17 @@ public class GainfosController : ControllerBase await _gainfoService.UploadFaceAsync(request); } + /// + /// 批量上传人脸照片 + /// + /// + /// + [HttpPost("faces")] + public async Task UploadFaceAsync(List request) + { + await _gainfoService.UploadFacesAsync(request); + } + /// /// 通过token获取人脸照片,失效或者找不到返回HttpStatus404状态码 /// diff --git a/Src/Dlhis.Basic/Organization/Services/IGainfoService.cs b/Src/Dlhis.Basic/Organization/Services/IGainfoService.cs index 7372f48d..768aa36b 100644 --- a/Src/Dlhis.Basic/Organization/Services/IGainfoService.cs +++ b/Src/Dlhis.Basic/Organization/Services/IGainfoService.cs @@ -1,6 +1,5 @@ using Dlhis.Basic.Organization.Request; using Dlhis.Basic.Organization.Response; -using Dlhis.Entity.Basic.Entity; using Kurisu.Core.DataAccess.Dto; using Microsoft.AspNetCore.Mvc; @@ -22,6 +21,8 @@ public interface IGainfoService : IScopeDependency Task UploadFaceAsync(GainfoUploadFaceRequest request); + Task UploadFacesAsync(List request); + Task GetFaceAsync(string token); Task GetFaceByUserCodeAsync(string userCode); diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs index f21150bd..bfc6e493 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs @@ -255,6 +255,54 @@ public class GainfoService : IGainfoService }); } + public async Task UploadFacesAsync(List requests) + { + foreach (var request in requests) + { + var gainfo = await _gainfoStore.Queryable(GainfoStatusEnumType.Working).Where(x => x.No == request.UserNo).FirstAsync(); + gainfo ??= await _gainfoStore.Queryable(GainfoStatusEnumType.External).Where(x => x.No == request.UserNo).FirstAsync(); + + gainfo.ThrowIfNull("人员档案信息不存在"); + + await Scoped.Request.Value.CreateAsync(async (sp) => + { + var configuration = sp.GetService(); + var faceConnectionString = configuration.GetSection("SqlSugarOptions:FaceConnectionString").Value; + + var dbContext = sp.GetService(); + //todo 切换连接字符串 + dbContext.Client.CurrentConnectionConfig.ConnectionString = faceConnectionString; + var face = await dbContext.Queryable().Where(x => x.UserCode == gainfo.Code).SingleAsync(); + + var taskType = face == null ? DeviceTaskEnumType.Add : DeviceTaskEnumType.Update; + if (face == null) + { + face = new GainfoFaceEntity + { + UserCode = gainfo.Code, + Face = request.Face + }; + + await dbContext.InsertAsync(face); + } + else + { + if (face.Face == request.Face) + { + _logger.LogWarning("相同的人脸照片更新忽略"); + return; + } + + face.Face = request.Face; + await dbContext.UpdateAsync(face); + } + + //生成任务 + await _devicePermissionService.GenerateDeviceTasksAsync(gainfo.No, taskType); + }); + } + } + public async Task GetFaceByUserCodeAsync(string userCode) From 0296f670e9bc15c526ce5c2c6b62a39534c1afd6 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 22 Feb 2024 16:46:07 +0800 Subject: [PATCH 017/146] =?UTF-8?q?fix=20=E6=81=A2=E5=A4=8Dredis=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Basic/Program.cs | 4 ++-- Src/Dlhis.ScheduledTask/Program.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Src/Dlhis.Basic/Program.cs b/Src/Dlhis.Basic/Program.cs index 0ebc0761..966be9f0 100644 --- a/Src/Dlhis.Basic/Program.cs +++ b/Src/Dlhis.Basic/Program.cs @@ -24,9 +24,9 @@ public class Startup : DefaultStartup base.ConfigureServices(services); //todo - /*var redis = ConnectionMultiplexer.Connect($"10.27.21.15:30050,defaultDatabase:1,password=dlhis123"); + var redis = ConnectionMultiplexer.Connect($"192.168.199.30:30115,defaultDatabase:1,password=dlhis123"); services.AddDataProtection() .SetApplicationName("basic") - .PersistKeysToStackExchangeRedis(redis, "DataProtection-Keys");*/ + .PersistKeysToStackExchangeRedis(redis, "DataProtection-Keys"); } } \ No newline at end of file diff --git a/Src/Dlhis.ScheduledTask/Program.cs b/Src/Dlhis.ScheduledTask/Program.cs index 1060cca9..aad2b382 100644 --- a/Src/Dlhis.ScheduledTask/Program.cs +++ b/Src/Dlhis.ScheduledTask/Program.cs @@ -26,11 +26,11 @@ public class Startup : DefaultStartup services.AddSingleton(sp => { - return ConnectionMultiplexer.Connect("10.27.21.15:30050,defaultDatabase:1,password=dlhis123"); + return ConnectionMultiplexer.Connect("192.168.199.30:30115,defaultDatabase:1,password=dlhis123"); }); //todo - var redis = ConnectionMultiplexer.Connect($"10.27.21.15:30050,defaultDatabase:1,password=dlhis123"); + var redis = ConnectionMultiplexer.Connect($"192.168.199.30:30115,defaultDatabase:1,password=dlhis123"); services.AddDataProtection() .SetApplicationName("basic") .PersistKeysToStackExchangeRedis(redis, "DataProtection-Keys"); From 78b92ab2231b26cc7f8c50f7f95f65c638f98c82 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 22 Feb 2024 17:10:09 +0800 Subject: [PATCH 018/146] =?UTF-8?q?fix=20=E9=85=8D=E7=BD=AEtenant=20api=20?= =?UTF-8?q?=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.ScheduledTask/appsettings.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Src/Dlhis.ScheduledTask/appsettings.json b/Src/Dlhis.ScheduledTask/appsettings.json index 3ba4c3a5..28bddadf 100644 --- a/Src/Dlhis.ScheduledTask/appsettings.json +++ b/Src/Dlhis.ScheduledTask/appsettings.json @@ -5,6 +5,9 @@ "Microsoft.AspNetCore": "Warning" } }, + "InternalRequest": { + "SysRequestUrl": "http://sys" + }, "SqlSugarOptions": { "DefaultConnectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=yikatong;charset=utf8mb4;", "SlaveConnectionString": [], From 4bd0c2403d78d3b5ba44d99b9683c5ca4b91079e Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 22 Feb 2024 17:43:33 +0800 Subject: [PATCH 019/146] =?UTF-8?q?fix=20=E8=AE=BE=E5=A4=87=E7=BB=84?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=B1=95=E7=A4=BA,=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E6=8E=A7=E5=88=B6editable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Response/DeviceGroupTreeResponse.cs | 26 ++++++++++++++++++- .../Services/Implements/DeviceGroupService.cs | 6 +++-- .../Device/Entities/DeviceGroupEntity.cs | 7 +++++ .../CommonJobs/CreateDefinitelyGroupJob.cs | 8 +++++- 4 files changed, 43 insertions(+), 4 deletions(-) diff --git a/Src/Dlhis.Basic/Device/Response/DeviceGroupTreeResponse.cs b/Src/Dlhis.Basic/Device/Response/DeviceGroupTreeResponse.cs index 6e9588ea..54d2c7fc 100644 --- a/Src/Dlhis.Basic/Device/Response/DeviceGroupTreeResponse.cs +++ b/Src/Dlhis.Basic/Device/Response/DeviceGroupTreeResponse.cs @@ -1,4 +1,7 @@ -namespace Dlhis.Basic.Device.Response; +using Dlhis.Entity.Device.Enums; +using Kurisu.AspNetCore.Utils.Extensions; + +namespace Dlhis.Basic.Device.Response; public class DeviceGroupTreeResponse { @@ -17,6 +20,27 @@ public class DeviceGroupTreeResponse /// public string Name { get; set; } + /// + /// 设备组类型 + /// + public DeviceTypeEnumType? Type { get; set; } + + /// + /// 分组类型描述 + /// + public string TypeDesc + { + get + { + if (!Type.HasValue) + { + return string.Empty; + } + + return Type.Value.GetDescription(); + } + } + /// /// 下级 /// diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs index 04722357..3047a115 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs @@ -56,8 +56,9 @@ public class DeviceGroupService : IDeviceGroupService if (!request.Id.HasValue) { var entity = request.Adapt(); - + entity.Editable = true; entity.Code = Guid.NewGuid(); + await _dbContext.InsertAsync(entity); } else @@ -65,6 +66,8 @@ public class DeviceGroupService : IDeviceGroupService var entity = await _dbContext.Queryable().Where(x => x.Id == request.Id).FirstAsync(); entity.ThrowIfNull("设备组不存在,无法更新"); + entity.Editable.ThrowIfFalse("不可编辑当前组"); + var nextDevices = await GetDevicesAsync(entity.Code); if (!entity.Type.HasValue) { @@ -75,7 +78,6 @@ public class DeviceGroupService : IDeviceGroupService (request.Type.HasValue && request.Type != entity.Type && nextDevices.Any()).ThrowIfTrue("分组设备类型不匹配,无法修改类型"); } - await _dbContext.UpdateAsync(entity); } } diff --git a/Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs b/Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs index 6d037b6a..b3f44bb9 100644 --- a/Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs +++ b/Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs @@ -37,6 +37,13 @@ public class DeviceGroupEntity : SugarBaseEntity, ITenantId, ISoftDeleted public string Name { get; set; } + /// + /// 是否可编辑 + /// + [SugarColumn(ColumnDescription = "是否可编辑")] + public bool Editable { get; set; } + + public string TenantId { get; set; } diff --git a/Src/Dlhis.ScheduledTask/CommonJobs/CreateDefinitelyGroupJob.cs b/Src/Dlhis.ScheduledTask/CommonJobs/CreateDefinitelyGroupJob.cs index 9390c884..7b8549a8 100644 --- a/Src/Dlhis.ScheduledTask/CommonJobs/CreateDefinitelyGroupJob.cs +++ b/Src/Dlhis.ScheduledTask/CommonJobs/CreateDefinitelyGroupJob.cs @@ -4,6 +4,7 @@ using Dlhis.Entity.Device.Enums; using Dlhis.Sys.Api; using Kurisu.Core.DataAccess.Entity; using Kurisu.SqlSugar.Services; +using Newtonsoft.Json; namespace Dlhis.ScheduledTask.CommonJobs; @@ -28,11 +29,12 @@ public class CreateDefinitelyGroupJob var tenantResult = await _tenantApi.GetTenantsInternalAsync(); var tenants = tenantResult.Data; + _logger.LogInformation("获取基地信息:{json}", JsonConvert.SerializeObject(tenants)); + foreach (var tenant in tenants) { if (!await _dbContext.Queryable().Where(x => x.TenantId == tenant.Code).AnyAsync(x => x.IsDefault)) { - var customGroup = new GainfoGroupEntity { PCode = null, @@ -82,6 +84,7 @@ public class CreateDefinitelyGroupJob Code = Guid.NewGuid(), Type = DeviceTypeEnumType.Attendance, Name = "*通用考勤设备组", + Editable = false, CreatedBy = 1, CreateTime = DateTime.Now, @@ -99,6 +102,7 @@ public class CreateDefinitelyGroupJob Code = Guid.NewGuid(), Type = DeviceTypeEnumType.Attendance, Name = "*专用考勤设备组", + Editable = false, CreatedBy = 1, CreateTime = DateTime.Now, @@ -121,6 +125,7 @@ public class CreateDefinitelyGroupJob Code = Guid.NewGuid(), Type = DeviceTypeEnumType.Door, Name = "*非公共区域", + Editable = false, CreatedBy = 1, CreateTime = DateTime.Now, @@ -141,6 +146,7 @@ public class CreateDefinitelyGroupJob Code = Guid.NewGuid(), Type = DeviceTypeEnumType.Door, Name = "*公共区域", + Editable = false, CreatedBy = 1, CreateTime = DateTime.Now, From 0143b2aba1e8d6aa787f8643757fa5b5d91465c3 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 22 Feb 2024 17:53:06 +0800 Subject: [PATCH 020/146] =?UTF-8?q?fix=20=E4=BC=98=E5=8C=96=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Basic/Device/Response/DeviceGroupPageResponse.cs | 5 +++++ .../CommonJobs/CreateDefinitelyGroupJob.cs | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Src/Dlhis.Basic/Device/Response/DeviceGroupPageResponse.cs b/Src/Dlhis.Basic/Device/Response/DeviceGroupPageResponse.cs index 8d81e4a4..941a4487 100644 --- a/Src/Dlhis.Basic/Device/Response/DeviceGroupPageResponse.cs +++ b/Src/Dlhis.Basic/Device/Response/DeviceGroupPageResponse.cs @@ -20,6 +20,11 @@ public class DeviceGroupPageResponse /// public DeviceTypeEnumType? Type { get; set; } + /// + /// 是否可编辑 + /// + public bool Editable { get; set; } + /// /// 分组类型描述 /// diff --git a/Src/Dlhis.ScheduledTask/CommonJobs/CreateDefinitelyGroupJob.cs b/Src/Dlhis.ScheduledTask/CommonJobs/CreateDefinitelyGroupJob.cs index 7b8549a8..0bdda3ff 100644 --- a/Src/Dlhis.ScheduledTask/CommonJobs/CreateDefinitelyGroupJob.cs +++ b/Src/Dlhis.ScheduledTask/CommonJobs/CreateDefinitelyGroupJob.cs @@ -14,11 +14,13 @@ public class CreateDefinitelyGroupJob private readonly ITenantApi _tenantApi; private readonly IDbContext _dbContext; - public CreateDefinitelyGroupJob(ILogger logger, ITenantApi tenantApi, IDbContext dbContext) + public CreateDefinitelyGroupJob(ILogger logger, ITenantApi tenantApi, IDbContext dbContext, ISqlSugarOptionsService sqlSugarOptionsService) { _logger = logger; _tenantApi = tenantApi; _dbContext = dbContext; + + sqlSugarOptionsService.IgnoreTenant = true; } public async Task RunAsync() From fd5dda33ab6c090eadc47d33b227541ff79b45cd Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Thu, 22 Feb 2024 17:56:36 +0800 Subject: [PATCH 021/146] =?UTF-8?q?fix=20=E4=BF=AE=E6=94=B9apk=E5=AE=9E?= =?UTF-8?q?=E4=BD=93=E7=9A=84name=E4=B8=BAstring?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Basic/Program.cs | 4 ++-- Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs | 2 ++ Src/Dlhis.Common/Request/ApkRequest.cs | 2 +- Src/Dlhis.Entity/Common/ApkFileEntity.cs | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Src/Dlhis.Basic/Program.cs b/Src/Dlhis.Basic/Program.cs index 0ebc0761..48192332 100644 --- a/Src/Dlhis.Basic/Program.cs +++ b/Src/Dlhis.Basic/Program.cs @@ -24,9 +24,9 @@ public class Startup : DefaultStartup base.ConfigureServices(services); //todo - /*var redis = ConnectionMultiplexer.Connect($"10.27.21.15:30050,defaultDatabase:1,password=dlhis123"); + var redis = ConnectionMultiplexer.Connect($"10.27.21.15:30050,defaultDatabase:1,password=dlhis123"); services.AddDataProtection() .SetApplicationName("basic") - .PersistKeysToStackExchangeRedis(redis, "DataProtection-Keys");*/ + .PersistKeysToStackExchangeRedis(redis, "DataProtection-Keys"); } } \ No newline at end of file diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs index f0cd8c8f..b3d1e7f0 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs @@ -59,6 +59,8 @@ public class OrderService : IOrderService .AnyAsync(); canteenUserExists.ThrowIfFalse($"就餐用户{request.UserUniqueNo}不存在,无法操作"); + + //消费 if (request.Type == BalanceRecordTypeEnumType.Out) { diff --git a/Src/Dlhis.Common/Request/ApkRequest.cs b/Src/Dlhis.Common/Request/ApkRequest.cs index 3665dafb..af368cce 100644 --- a/Src/Dlhis.Common/Request/ApkRequest.cs +++ b/Src/Dlhis.Common/Request/ApkRequest.cs @@ -15,7 +15,7 @@ /// /// 版本名称 /// - public int VersionName { get; set; } + public string VersionName { get; set; } /// /// 修改信息 diff --git a/Src/Dlhis.Entity/Common/ApkFileEntity.cs b/Src/Dlhis.Entity/Common/ApkFileEntity.cs index 7a6c7ce2..da72752e 100644 --- a/Src/Dlhis.Entity/Common/ApkFileEntity.cs +++ b/Src/Dlhis.Entity/Common/ApkFileEntity.cs @@ -36,7 +36,7 @@ public class ApkFileEntity : SugarBaseEntity /// 版本名称 /// [SugarColumn(ColumnDescription = "版本名称")] - public int VersionName { get; set; } + public string VersionName { get; set; } /// /// 修改信息 From 4ee5703b65b8a4423d6f4f7982514897598602da Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 22 Feb 2024 18:12:28 +0800 Subject: [PATCH 022/146] =?UTF-8?q?fix=20=E5=B0=B1=E9=A4=90=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=9D=83=E9=99=90=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dlis.Jinko.Yikatong.sln | 7 ++++++ Src/Dlhis.Basic.Api/Dlhis.Basic.Api.csproj | 13 ++++++++++ Src/Dlhis.Basic.Api/IDevicePermissionApi.cs | 11 ++++++++ .../DevicePermissionsController.cs | 13 ++++++++++ .../Response/DeviceGroupTreeResponse.cs | 3 +++ .../Services/IDevicePermissionService.cs | 8 ++++++ .../Implements/DevicePermissionService.cs | 15 +++++++++-- Src/Dlhis.Canteen/Dlhis.Canteen.csproj | 1 + .../Order/Controllers/OrdersController.cs | 1 - .../Order/Services/Implements/OrderService.cs | 18 +++++++++++-- .../appsettings.Development.json | 3 ++- Src/Dlhis.Canteen/appsettings.json | 3 ++- .../Basic/Entity/BusinessPlaceGroupEntity.cs | 25 +++++++++++++++++++ .../BusinessPlaceGroupRelationshipEntity.cs | 16 ++++++++++++ 14 files changed, 130 insertions(+), 7 deletions(-) create mode 100644 Src/Dlhis.Basic.Api/Dlhis.Basic.Api.csproj create mode 100644 Src/Dlhis.Basic.Api/IDevicePermissionApi.cs create mode 100644 Src/Dlhis.Entity/Basic/Entity/BusinessPlaceGroupEntity.cs create mode 100644 Src/Dlhis.Entity/Basic/Entity/BusinessPlaceGroupRelationshipEntity.cs diff --git a/Dlis.Jinko.Yikatong.sln b/Dlis.Jinko.Yikatong.sln index 254bd420..ff1fecaa 100644 --- a/Dlis.Jinko.Yikatong.sln +++ b/Dlis.Jinko.Yikatong.sln @@ -29,6 +29,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dlhis.Canteen", "Src\Dlhis. EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dlhis.Sys.Api", "Src\Dlhis.Sys.Api\Dlhis.Sys.Api.csproj", "{85A345C7-913E-4C1B-BE1C-600DE408A02F}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dlhis.Basic.Api", "Src\Dlhis.Basic.Api\Dlhis.Basic.Api.csproj", "{1F337648-8A22-4601-A842-0F634FBA2825}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -71,6 +73,10 @@ Global {85A345C7-913E-4C1B-BE1C-600DE408A02F}.Debug|Any CPU.Build.0 = Debug|Any CPU {85A345C7-913E-4C1B-BE1C-600DE408A02F}.Release|Any CPU.ActiveCfg = Release|Any CPU {85A345C7-913E-4C1B-BE1C-600DE408A02F}.Release|Any CPU.Build.0 = Release|Any CPU + {1F337648-8A22-4601-A842-0F634FBA2825}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1F337648-8A22-4601-A842-0F634FBA2825}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1F337648-8A22-4601-A842-0F634FBA2825}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1F337648-8A22-4601-A842-0F634FBA2825}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -84,6 +90,7 @@ Global {925048C9-5940-4B51-8480-4DC908C754A1} = {57074FD8-1A2F-40C7-8476-001778A3F65D} {8317C526-3523-4195-9B19-2F17CFD71927} = {3D8A98C1-83C9-4375-AEAB-4F72AFAF365B} {85A345C7-913E-4C1B-BE1C-600DE408A02F} = {57074FD8-1A2F-40C7-8476-001778A3F65D} + {1F337648-8A22-4601-A842-0F634FBA2825} = {4EBCE46B-CE3A-4A47-9432-82A1854CA58A} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {7439494A-E2FD-4FEA-8ABF-74AE57A4A5A0} diff --git a/Src/Dlhis.Basic.Api/Dlhis.Basic.Api.csproj b/Src/Dlhis.Basic.Api/Dlhis.Basic.Api.csproj new file mode 100644 index 00000000..e41324f5 --- /dev/null +++ b/Src/Dlhis.Basic.Api/Dlhis.Basic.Api.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/Src/Dlhis.Basic.Api/IDevicePermissionApi.cs b/Src/Dlhis.Basic.Api/IDevicePermissionApi.cs new file mode 100644 index 00000000..0792994e --- /dev/null +++ b/Src/Dlhis.Basic.Api/IDevicePermissionApi.cs @@ -0,0 +1,11 @@ +using Kurisu.Core.Result; +using Kurisu.RemoteCall.Attributes; + +namespace Dlhis.Basic.Api; + +[EnableRemoteClient(Name = "basic-service", BaseUrl = "${InternalRequest:BasicRequestUrl}")] +public interface IDevicePermissionApi +{ + [Get("/api/devicepermissions/canteen/uniqueNos")] + Task>> GetCanteenDeviceUniqueNosByUserNoAsync(string userNo); +} \ No newline at end of file diff --git a/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs b/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs index b0ecaf24..ad89e286 100644 --- a/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs +++ b/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs @@ -4,6 +4,7 @@ using Dlhis.Basic.Device.Services; using Kurisu.Core.DataAccess.Dto; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Org.BouncyCastle.Asn1.Ocsp; namespace Dlhis.Basic.Device.Controllers; @@ -51,4 +52,16 @@ public class DevicePermissionsController : ControllerBase { return await _devicePermissionService.GetAssigmentByCodeAsync(request); } + + + /// + /// 就餐设备唯一号权限 + /// + /// + /// + [HttpGet("canteen/uniqueNos")] + public async Task> GetCanteenDeviceUniqueNosByUserNoAsync(string userNo) + { + return await _devicePermissionService.GetCanteenDeviceUniqueNosByUserNoAsync(userNo); + } } diff --git a/Src/Dlhis.Basic/Device/Response/DeviceGroupTreeResponse.cs b/Src/Dlhis.Basic/Device/Response/DeviceGroupTreeResponse.cs index 54d2c7fc..9a1e26de 100644 --- a/Src/Dlhis.Basic/Device/Response/DeviceGroupTreeResponse.cs +++ b/Src/Dlhis.Basic/Device/Response/DeviceGroupTreeResponse.cs @@ -5,6 +5,9 @@ namespace Dlhis.Basic.Device.Response; public class DeviceGroupTreeResponse { + public long Id { get; set; } + + /// /// 上级分组code /// diff --git a/Src/Dlhis.Basic/Device/Services/IDevicePermissionService.cs b/Src/Dlhis.Basic/Device/Services/IDevicePermissionService.cs index 040d00ac..ef313da0 100644 --- a/Src/Dlhis.Basic/Device/Services/IDevicePermissionService.cs +++ b/Src/Dlhis.Basic/Device/Services/IDevicePermissionService.cs @@ -50,6 +50,14 @@ public interface IDevicePermissionService : IScopeDependency /// Task> GetAssignDeviceCodesAsync(string userNo); + + /// + /// 获取就餐权限唯一号 + /// + /// + /// + Task> GetCanteenDeviceUniqueNosByUserNoAsync(string userNo); + /// /// 获取用户权限设备 /// diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs index 1fbc6c88..e0c3d564 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs @@ -198,6 +198,17 @@ public class DevicePermissionService : IDevicePermissionService } + public async Task> GetCanteenDeviceUniqueNosByUserNoAsync(string userNo) + { + var all = await GetAssignDeviceCodesAsync(userNo); + + return await _dbContext.Queryable().Where(x => x.Type == DeviceTypeEnumType.Meal) + .Where(x => all.Contains(x.Code)) + .Select(x => x.UniqueNo) + .ToListAsync(); + } + + /// /// 获取用户所有设备权限 /// @@ -340,7 +351,7 @@ public class DevicePermissionService : IDevicePermissionService var devices = await _dbContext.Queryable().ToListAsync(); - if(ggs != null && ggs.Count > 0) + if (ggs != null && ggs.Count > 0) { foreach (var gid in ggs) { @@ -351,7 +362,7 @@ public class DevicePermissionService : IDevicePermissionService gds.AddRange(ds); } } - + var dds = gds.Distinct().ToList(); var lst = devices.Where(x => dds.Contains(x.Code)) .Select(x => new AssigmentByCodeResponse diff --git a/Src/Dlhis.Canteen/Dlhis.Canteen.csproj b/Src/Dlhis.Canteen/Dlhis.Canteen.csproj index 36fc7e42..36b6a9be 100644 --- a/Src/Dlhis.Canteen/Dlhis.Canteen.csproj +++ b/Src/Dlhis.Canteen/Dlhis.Canteen.csproj @@ -17,6 +17,7 @@ + diff --git a/Src/Dlhis.Canteen/Order/Controllers/OrdersController.cs b/Src/Dlhis.Canteen/Order/Controllers/OrdersController.cs index 3e8f30e5..86e9a5c6 100644 --- a/Src/Dlhis.Canteen/Order/Controllers/OrdersController.cs +++ b/Src/Dlhis.Canteen/Order/Controllers/OrdersController.cs @@ -43,5 +43,4 @@ public class OrdersController : ControllerBase { return await _orderService.AddAsync(request); } - } diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs index b3d1e7f0..dedd2a4e 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs @@ -1,10 +1,12 @@ -using Dlhis.Canteen.Order.Request; +using Dlhis.Basic.Api; +using Dlhis.Canteen.Order.Request; using Dlhis.Canteen.Order.Response; using Dlhis.Canteen.Setting.Services; using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Canteen.Entities; using Dlhis.Entity.Canteen.Enums; using Dlhis.Entity.Device.Entities; +using Dlhis.Entity.Sys.Entities; using Kurisu.AspNetCore.UnifyResultAndValidation; using Kurisu.AspNetCore.Utils; using Kurisu.AspNetCore.Utils.Extensions; @@ -22,14 +24,17 @@ public class OrderService : IOrderService { private readonly IDbContext _dbContext; private readonly ICanteenSettingService _canteenSettingService; + private readonly IDevicePermissionApi _devicePermissionApi; private readonly ILogger _logger; public OrderService(IDbContext dbContext, ICanteenSettingService canteenSettingService, + IDevicePermissionApi devicePermissionApi, ILogger logger) { _dbContext = dbContext; _canteenSettingService = canteenSettingService; + _devicePermissionApi = devicePermissionApi; _logger = logger; } @@ -42,6 +47,14 @@ public class OrderService : IOrderService return page; } + private async Task CheckPAsync(string userNo, string deviceUniqueNo) + { + var uniqueNosResult = await _devicePermissionApi.GetCanteenDeviceUniqueNosByUserNoAsync(userNo); + var uniqueNos = uniqueNosResult.Data; + + uniqueNos.Contains(deviceUniqueNo).ThrowIfFalse("无消费权限"); + } + [IgnoreTenant] public async Task AddAsync(OrderAddRequest request) { @@ -59,7 +72,8 @@ public class OrderService : IOrderService .AnyAsync(); canteenUserExists.ThrowIfFalse($"就餐用户{request.UserUniqueNo}不存在,无法操作"); - + //消费权限控制 + await CheckPAsync(gainfo.No, request.DeviceUniqueNo); //消费 if (request.Type == BalanceRecordTypeEnumType.Out) diff --git a/Src/Dlhis.Canteen/appsettings.Development.json b/Src/Dlhis.Canteen/appsettings.Development.json index 20ab3f6d..69b2958a 100644 --- a/Src/Dlhis.Canteen/appsettings.Development.json +++ b/Src/Dlhis.Canteen/appsettings.Development.json @@ -6,7 +6,8 @@ } }, "InternalRequest": { - "CommonRequestUrl": "http://localhost:5001" + "CommonRequestUrl": "http://localhost:5001", + "BasicRequestUrl": "http://localhost:5002" }, "SwaggerOptions": { "Enable": true, diff --git a/Src/Dlhis.Canteen/appsettings.json b/Src/Dlhis.Canteen/appsettings.json index d322419a..7ea06e04 100644 --- a/Src/Dlhis.Canteen/appsettings.json +++ b/Src/Dlhis.Canteen/appsettings.json @@ -7,7 +7,8 @@ }, "AllowedHosts": "*", "InternalRequest": { - "CommonRequestUrl": "http://common" + "CommonRequestUrl": "http://common", + "BasicRequestUrl": "http://basic" }, "SqlSugarOptions": { "DefaultConnectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=yikatong;charset=utf8mb4;", diff --git a/Src/Dlhis.Entity/Basic/Entity/BusinessPlaceGroupEntity.cs b/Src/Dlhis.Entity/Basic/Entity/BusinessPlaceGroupEntity.cs new file mode 100644 index 00000000..fdb19b6c --- /dev/null +++ b/Src/Dlhis.Entity/Basic/Entity/BusinessPlaceGroupEntity.cs @@ -0,0 +1,25 @@ +using Kurisu.Core.DataAccess.Entity; +using Kurisu.SqlSugar; +using SqlSugar; + +namespace Dlhis.Entity.Basic.Entity; + +/// +/// 营业点分组 +/// +[SugarTable(TableName = "BusinessPlaceGroup", TableDescription = "营业点分组")] +public class BusinessPlaceGroupEntity : SugarBaseEntity, ITenantId +{ + public Guid? PCode { get; set; } + + public Guid Code { get; set; } + + [SugarColumn(ColumnDescription = "名称")] + public string Name { get; set; } + + + [SugarColumn(ColumnDescription = "备注")] + public string Remark { get; set; } + + public string TenantId { get; set; } +} diff --git a/Src/Dlhis.Entity/Basic/Entity/BusinessPlaceGroupRelationshipEntity.cs b/Src/Dlhis.Entity/Basic/Entity/BusinessPlaceGroupRelationshipEntity.cs new file mode 100644 index 00000000..49a36419 --- /dev/null +++ b/Src/Dlhis.Entity/Basic/Entity/BusinessPlaceGroupRelationshipEntity.cs @@ -0,0 +1,16 @@ +using Kurisu.Core.DataAccess.Entity; +using Kurisu.SqlSugar; +using SqlSugar; + +namespace Dlhis.Entity.Basic.Entity; + + +[SugarTable(TableName = "BusinessPlaceGroupRelationship", TableDescription = "营业点分组")] +public class BusinessPlaceGroupRelationshipEntity : SugarBaseEntity, ITenantId +{ + public Guid BusinessPlaceGroupCode { get; set; } + + public Guid BusinessPlaceCode { get; set; } + + public string TenantId { get; set; } +} From 83704bb0171ef921a394362f81ad08ecd17ada09 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 22 Feb 2024 18:13:49 +0800 Subject: [PATCH 023/146] fix dockerfile --- Src/Dlhis.Canteen/Dlhis.Canteen.csproj | 1 + Src/Dlhis.Canteen/Dockerfile | 1 + 2 files changed, 2 insertions(+) diff --git a/Src/Dlhis.Canteen/Dlhis.Canteen.csproj b/Src/Dlhis.Canteen/Dlhis.Canteen.csproj index 36b6a9be..9e21386c 100644 --- a/Src/Dlhis.Canteen/Dlhis.Canteen.csproj +++ b/Src/Dlhis.Canteen/Dlhis.Canteen.csproj @@ -37,6 +37,7 @@ + diff --git a/Src/Dlhis.Canteen/Dockerfile b/Src/Dlhis.Canteen/Dockerfile index b148099c..5e510329 100644 --- a/Src/Dlhis.Canteen/Dockerfile +++ b/Src/Dlhis.Canteen/Dockerfile @@ -7,6 +7,7 @@ EXPOSE 80 FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build WORKDIR /src COPY ["Src/Dlhis.Canteen/Dlhis.Canteen.csproj", "Src/Dlhis.Canteen/"] +COPY ["Src/Dlhis.Basic.Api/Dlhis.Basic.Api.csproj", "Src/Dlhis.Basic.Api/"] COPY ["Src/Dlhis.Common.Api/Dlhis.Common.Api.csproj", "Src/Dlhis.Common.Api/"] COPY ["Src/Dlhis.Entity/Dlhis.Entity.csproj", "Src/Dlhis.Entity/"] RUN dotnet restore "Src/Dlhis.Canteen/Dlhis.Canteen.csproj" From cd5f7e115a097d19b783037f15f46c2010561ab0 Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Thu, 22 Feb 2024 18:16:44 +0800 Subject: [PATCH 024/146] =?UTF-8?q?fix=20=E4=BF=AE=E6=94=B9vername?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FileOperation/Services/Implements/ApkFIileService.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs b/Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs index 28726ace..8978cfb6 100644 --- a/Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs +++ b/Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs @@ -44,6 +44,7 @@ public class ApkFIileService : IApkFIileService Url = fileUrl, VersionCode = request.VersionCode, UpdateMessage = request.UpdateMessage, + VersionName = request.VersionName, }; await _dbContext.InsertAsync(info); } From f3b17dc6b82409dbe9b14ed0f156a41e2a02ed6e Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Thu, 22 Feb 2024 18:25:19 +0800 Subject: [PATCH 025/146] =?UTF-8?q?fix=20=E5=88=A0=E9=99=A4url=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/ApkFileController.cs | 31 ----- .../Services/IApkFIileService.cs | 14 --- .../Services/Implements/ApkFIileService.cs | 110 ------------------ Src/Dlhis.Entity/Common/ApkFileEntity.cs | 6 - 4 files changed, 161 deletions(-) diff --git a/Src/Dlhis.Common/FileOperation/Controllers/ApkFileController.cs b/Src/Dlhis.Common/FileOperation/Controllers/ApkFileController.cs index 7646dd3e..b2c442aa 100644 --- a/Src/Dlhis.Common/FileOperation/Controllers/ApkFileController.cs +++ b/Src/Dlhis.Common/FileOperation/Controllers/ApkFileController.cs @@ -46,40 +46,9 @@ public class ApkFileController : ControllerBase } - /// - /// 本地文件上传 - /// - /// - /// - [HttpPost("local")] - [RequestSizeLimit(100_000_0000)] - public async Task FormLocalFileUpload([FromForm] ApkRequest request) - { - return await _apkFIileService.FormLocalFileUpload(request); - } - /// - /// 查看最新版本 - /// - /// - /// - [HttpGet("lastfile")] - public async Task LatestFile(string fileName) - { - return await _apkFIileService.LatestFile(fileName); - } - /// - /// 本地文件下载 - /// - /// - /// - [HttpGet("local")] - public IActionResult FormLocalDownloadFile(string fileName) - { - return _apkFIileService.FormLocalDownloadFile(fileName); - } } diff --git a/Src/Dlhis.Common/FileOperation/Services/IApkFIileService.cs b/Src/Dlhis.Common/FileOperation/Services/IApkFIileService.cs index f9f29d73..ff5a079b 100644 --- a/Src/Dlhis.Common/FileOperation/Services/IApkFIileService.cs +++ b/Src/Dlhis.Common/FileOperation/Services/IApkFIileService.cs @@ -21,21 +21,7 @@ public interface IApkFIileService : IScopeDependency /// Task RequestDownloadFile(string fileName); - /// - /// 本地上传 - /// - /// - /// - Task FormLocalFileUpload(ApkRequest request); - Task LatestFile(string fileName); - - /// - /// 本地下载 - /// - /// - /// - IActionResult FormLocalDownloadFile(string fileName); } diff --git a/Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs b/Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs index 8978cfb6..ffe86e6b 100644 --- a/Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs +++ b/Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs @@ -41,7 +41,6 @@ public class ApkFIileService : IApkFIileService var info = new ApkFileEntity { Name = fileName, - Url = fileUrl, VersionCode = request.VersionCode, UpdateMessage = request.UpdateMessage, VersionName = request.VersionName, @@ -50,7 +49,6 @@ public class ApkFIileService : IApkFIileService } else { - entity.Url = fileUrl; entity.VersionCode = request.VersionCode; entity.UpdateMessage = request.UpdateMessage; await _dbContext.UpdateAsync(entity); @@ -69,116 +67,8 @@ public class ApkFIileService : IApkFIileService return await _minioService.MinloDownloadLinkAsync(fileName); } - /// - /// 本地文件上传 - /// - /// - /// - public async Task FormLocalFileUpload(ApkRequest request) - { - //上传 - var completeFilePath = FormSingleFileUpload(request.formFile); - if (completeFilePath == "No file uploaded" || completeFilePath.IsEmpty()) - { - return null; - } - //更新数据库 - var fileName = request.formFile.FileName; - var entity = await _dbContext.Queryable().Where(x => x.Name == fileName).FirstAsync(); - if (entity == null) - { - var info = new ApkFileEntity - { - Name = fileName, - Url = completeFilePath, - VersionCode = request.VersionCode, - VersionName = request.VersionName, - UpdateMessage = request.UpdateMessage, - }; - await _dbContext.InsertAsync(info); - } - else - { - entity.Url = completeFilePath; - entity.VersionCode = request.VersionCode; - entity.UpdateMessage = request.UpdateMessage; - entity.VersionName = request.VersionName; - await _dbContext.UpdateAsync(entity); - } - var newEntity = await _dbContext.Queryable().Where(x => x.Name == fileName).FirstAsync(); - var res = newEntity.Adapt(); - return res; - - } - public string FormSingleFileUpload(IFormFile formFile) - { - try - { - var filePath = "C:\\apk\\"; - - // 创建存储文件夹 - if (!Directory.Exists(filePath)) - { - Directory.CreateDirectory(filePath); - } - - if (formFile != null && formFile.Length > 0) - { - // 保存的文件名称 - var saveName = Path.GetFileName(formFile.FileName); - - // 文件保存 - using (var fs = File.Create(Path.Combine(filePath, saveName))) - { - formFile.CopyTo(fs); - fs.Flush(); - } - - // 完整的文件路径 - var completeFilePath = Path.Combine(filePath, saveName); - return completeFilePath; - } - else - { - return "No file uploaded"; - } - } - catch (Exception) - { - return null; - throw; - } - } - - /// - /// 返回最新版本信息 - /// - /// - /// - public async Task LatestFile(string fileName) - { - var info = await _dbContext.Queryable() - .Where(x => x.Name == fileName) - .OrderByDescending(x => x.VersionCode) - .FirstAsync(); - info.ThrowIfNull($"没有{fileName}信息"); - var res = info.Adapt(); - return res; - } - /// - /// 本地下载 - /// - /// - /// - public IActionResult FormLocalDownloadFile(string fileName) - { - - var Path = "C:\\apk\\"; - var filePath = Path + fileName; - return new FileStreamResult(new FileStream(filePath, FileMode.Open), "application/octet-stream") { FileDownloadName = fileName }; - } } diff --git a/Src/Dlhis.Entity/Common/ApkFileEntity.cs b/Src/Dlhis.Entity/Common/ApkFileEntity.cs index da72752e..cf1735ec 100644 --- a/Src/Dlhis.Entity/Common/ApkFileEntity.cs +++ b/Src/Dlhis.Entity/Common/ApkFileEntity.cs @@ -20,12 +20,6 @@ public class ApkFileEntity : SugarBaseEntity [SugarColumn(ColumnDescription = "文件名称")] public string Name { get; set; } - /// - /// 地址 - /// - [SugarColumn(ColumnDescription = "地址")] - public string Url { get; set; } - /// /// 版本号 /// From bbe5939887e29eb8d4f3a378b8b2c523492dd66d Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Thu, 22 Feb 2024 18:30:58 +0800 Subject: [PATCH 026/146] fix xiugai --- Src/Dlhis.Common/Services/Implements/ApkFIileService.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Src/Dlhis.Common/Services/Implements/ApkFIileService.cs b/Src/Dlhis.Common/Services/Implements/ApkFIileService.cs index bdd03d8f..03848263 100644 --- a/Src/Dlhis.Common/Services/Implements/ApkFIileService.cs +++ b/Src/Dlhis.Common/Services/Implements/ApkFIileService.cs @@ -39,7 +39,7 @@ public class ApkFIileService : IApkFIileService var info = new ApkFileEntity { Name = fileName, - Url = fileUrl, + //Url = fileUrl, VersionCode = request.VersionCode, UpdateMessage = request.UpdateMessage, }; @@ -47,7 +47,7 @@ public class ApkFIileService : IApkFIileService } else { - entity.Url = fileUrl; + //entity.Url = fileUrl; entity.VersionCode = request.VersionCode; entity.UpdateMessage = request.UpdateMessage; await _dbContext.UpdateAsync(entity); @@ -87,7 +87,7 @@ public class ApkFIileService : IApkFIileService var info = new ApkFileEntity { Name = fileName, - Url = completeFilePath, + //Url = completeFilePath, VersionCode = request.VersionCode, VersionName = request.VersionName, UpdateMessage = request.UpdateMessage, @@ -96,7 +96,7 @@ public class ApkFIileService : IApkFIileService } else { - entity.Url = completeFilePath; + //entity.Url = completeFilePath; entity.VersionCode = request.VersionCode; entity.VersionName = request.VersionName; entity.UpdateMessage = request.UpdateMessage; From 9f83188819f6c2ffe25f891a8b4ff2b766866b4e Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Thu, 22 Feb 2024 19:15:47 +0800 Subject: [PATCH 027/146] =?UTF-8?q?fix=20=E4=BF=AE=E6=94=B9apk=E5=A4=A7?= =?UTF-8?q?=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Order/Services/Implements/OrderService.cs | 32 +++++++++++++++---- .../Controllers/ApkFileController.cs | 2 ++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs index dedd2a4e..baa80576 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs @@ -58,13 +58,33 @@ public class OrderService : IOrderService [IgnoreTenant] public async Task AddAsync(OrderAddRequest request) { - //尝试匹配userId - _ = long.TryParse(request.UserUniqueNo, out var userId); - - //根据档案号 + var card = string.Empty; + long userId = 0; + if (request.Source == BalanceRecordSourceEnumType.Card) + { + card = request.UserUniqueNo; + } + else + { + _ = long.TryParse(request.UserUniqueNo, out userId); + } var gainfo = await _dbContext.Queryable() - .Where(x => x.No == request.UserUniqueNo || x.Code == request.UserUniqueNo || x.Id == userId) - .FirstAsync(); + .Where(x => x.No == request.UserUniqueNo || x.Code == request.UserUniqueNo || x.Id == userId|| x.CardNo == card) + .FirstAsync(); + + + // .... + { + ////尝试匹配userId + //_ = long.TryParse(request.UserUniqueNo, out var userId); + + ////根据档案号 + //var gainfo = await _dbContext.Queryable() + // .Where(x => x.No == request.UserUniqueNo || x.Code == request.UserUniqueNo || x.Id == userId) + // .FirstAsync(); + } + + gainfo.ThrowIfNull($"用户{request.UserUniqueNo}不存在,无法操作"); var canteenUserExists = await _dbContext.Queryable() diff --git a/Src/Dlhis.Common/FileOperation/Controllers/ApkFileController.cs b/Src/Dlhis.Common/FileOperation/Controllers/ApkFileController.cs index b2c442aa..06d16288 100644 --- a/Src/Dlhis.Common/FileOperation/Controllers/ApkFileController.cs +++ b/Src/Dlhis.Common/FileOperation/Controllers/ApkFileController.cs @@ -29,6 +29,8 @@ public class ApkFileController : ControllerBase /// /// [HttpPost("minlo")] + [DisableRequestSizeLimit] + [RequestSizeLimit(300000000)] public async Task FormSingleFileUpload([FromForm] ApkRequest request) { return await _apkFIileService.FormSingleFileUpload(request); From 89f2f7b9918cac3cfec927654b843c1091ffd1b2 Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Fri, 23 Feb 2024 09:29:10 +0800 Subject: [PATCH 028/146] =?UTF-8?q?fix=20=E4=BF=AE=E6=94=B9=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=8A=E4=BC=A0=E5=A4=A7=E5=B0=8F=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FileOperation/Controllers/ApkFileController.cs | 14 +++++++++++--- .../FileOperation/Response/ApkFileResponse.cs | 2 +- .../FileOperation/Services/IApkFIileService.cs | 3 +++ .../Services/Implements/ApkFIileService.cs | 10 ++++++++++ 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/Src/Dlhis.Common/FileOperation/Controllers/ApkFileController.cs b/Src/Dlhis.Common/FileOperation/Controllers/ApkFileController.cs index 06d16288..accb0bba 100644 --- a/Src/Dlhis.Common/FileOperation/Controllers/ApkFileController.cs +++ b/Src/Dlhis.Common/FileOperation/Controllers/ApkFileController.cs @@ -29,8 +29,7 @@ public class ApkFileController : ControllerBase /// /// [HttpPost("minlo")] - [DisableRequestSizeLimit] - [RequestSizeLimit(300000000)] + [RequestSizeLimit(300_000_000)] public async Task FormSingleFileUpload([FromForm] ApkRequest request) { return await _apkFIileService.FormSingleFileUpload(request); @@ -47,7 +46,16 @@ public class ApkFileController : ControllerBase return await _apkFIileService.RequestDownloadFile(fileName); } - + /// + /// 获取最新版本 + /// + /// + /// + [HttpGet("lastverison")] + public async Task GetLastVersionAsync(string fileName) + { + return await _apkFIileService.GetLastVersionAsync(fileName); + } diff --git a/Src/Dlhis.Common/FileOperation/Response/ApkFileResponse.cs b/Src/Dlhis.Common/FileOperation/Response/ApkFileResponse.cs index 886ca16a..7198cf6b 100644 --- a/Src/Dlhis.Common/FileOperation/Response/ApkFileResponse.cs +++ b/Src/Dlhis.Common/FileOperation/Response/ApkFileResponse.cs @@ -17,7 +17,7 @@ namespace Dlhis.Common.FileOperation.Response /// /// 版本名称 /// - public int VersionName { get; set; } + public string VersionName { get; set; } /// /// 修改信息 diff --git a/Src/Dlhis.Common/FileOperation/Services/IApkFIileService.cs b/Src/Dlhis.Common/FileOperation/Services/IApkFIileService.cs index ff5a079b..0f8afb8a 100644 --- a/Src/Dlhis.Common/FileOperation/Services/IApkFIileService.cs +++ b/Src/Dlhis.Common/FileOperation/Services/IApkFIileService.cs @@ -22,6 +22,9 @@ public interface IApkFIileService : IScopeDependency Task RequestDownloadFile(string fileName); + Task GetLastVersionAsync(string fileName); + + } diff --git a/Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs b/Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs index ffe86e6b..202dd65f 100644 --- a/Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs +++ b/Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs @@ -51,6 +51,7 @@ public class ApkFIileService : IApkFIileService { entity.VersionCode = request.VersionCode; entity.UpdateMessage = request.UpdateMessage; + entity.VersionName = request.VersionName; await _dbContext.UpdateAsync(entity); } var newEntity = await _dbContext.Queryable().Where(x => x.Name == fileName).FirstAsync(); @@ -58,6 +59,15 @@ public class ApkFIileService : IApkFIileService return res; } + public async Task GetLastVersionAsync(string fileName) + { + var info = await _dbContext.Queryable() + .Where(x => x.Name == fileName) + .Select() + .FirstAsync(); + return info; + } + /// /// 文件下载 /// From e7a4075b7811fb4ded3f2b8058331fa54c903624 Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Fri, 23 Feb 2024 10:09:22 +0800 Subject: [PATCH 029/146] =?UTF-8?q?fix=20=E6=B7=BB=E5=8A=A0=E8=B0=83?= =?UTF-8?q?=E7=94=A8api=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Basic.Api/IDevicePermissionApi.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Src/Dlhis.Basic.Api/IDevicePermissionApi.cs b/Src/Dlhis.Basic.Api/IDevicePermissionApi.cs index 0792994e..feeb452e 100644 --- a/Src/Dlhis.Basic.Api/IDevicePermissionApi.cs +++ b/Src/Dlhis.Basic.Api/IDevicePermissionApi.cs @@ -6,6 +6,7 @@ namespace Dlhis.Basic.Api; [EnableRemoteClient(Name = "basic-service", BaseUrl = "${InternalRequest:BasicRequestUrl}")] public interface IDevicePermissionApi { + [Auth] [Get("/api/devicepermissions/canteen/uniqueNos")] Task>> GetCanteenDeviceUniqueNosByUserNoAsync(string userNo); } \ No newline at end of file From cbb26575ac4a66dfcd9344b64a8695486ff699f6 Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Fri, 23 Feb 2024 11:06:54 +0800 Subject: [PATCH 030/146] =?UTF-8?q?fix=20=E5=90=88=E5=B9=B6=E9=A4=90?= =?UTF-8?q?=E9=A5=AE=E9=A6=96=E9=A1=B5=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Order/Controllers/BalancesController.cs | 20 ++----------------- .../Order/Response/ConsumeNumberResponse.cs | 10 ++++++++++ .../Order/Services/IBalanceService.cs | 3 +-- .../Services/Implements/BalanceService.cs | 18 +++++++++-------- 4 files changed, 23 insertions(+), 28 deletions(-) diff --git a/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs b/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs index 8c306db1..3015ff75 100644 --- a/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs +++ b/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs @@ -143,25 +143,9 @@ public class BalancesController : ControllerBase return await _balanceService.GetConsumeNumberAsync(); } - /// - /// 消费走势 - /// - /// - [HttpGet("consumptiontrends")] - public async Task> GetConsumptionTrendsAsync([FromQuery] ConsumptionTrendRequest request) - { - return await _balanceService.GetConsumptionTrendsAsync(request); - } - /// - /// 餐补走势 - /// - /// - [HttpGet("supplementtrend")] - public async Task> GetSupplementTrendsAsync([FromQuery] ConsumptionTrendRequest request) - { - return await _balanceService.GetSupplementTrendsAsync(request); - } + + /// /// 电子餐券申请记录查询 diff --git a/Src/Dlhis.Canteen/Order/Response/ConsumeNumberResponse.cs b/Src/Dlhis.Canteen/Order/Response/ConsumeNumberResponse.cs index 609b1a68..130bd99b 100644 --- a/Src/Dlhis.Canteen/Order/Response/ConsumeNumberResponse.cs +++ b/Src/Dlhis.Canteen/Order/Response/ConsumeNumberResponse.cs @@ -26,5 +26,15 @@ /// 人均日消费额 /// public int DailyNumber { get; set; } + + /// + /// 日消费额走势图 + /// + public List Days { get; set; } + + /// + /// 月消费额走势图 + /// + public List Months { get; set; } } } diff --git a/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs b/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs index 1c02cd6f..f90026d8 100644 --- a/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs @@ -27,9 +27,8 @@ public interface IBalanceService : IScopeDependency Task GetConsumeNumberAsync(); - Task> GetConsumptionTrendsAsync(ConsumptionTrendRequest request); - Task> GetSupplementTrendsAsync(ConsumptionTrendRequest request); + Task> GetOaEMealVoucherAsync([FromQuery] OaEMealVoucherRequest request); diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs index 9a3f88b0..063353ca 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs @@ -575,18 +575,25 @@ public class BalanceService : IBalanceService var monthlySpending = monthbs.Sum(x => x.Amount); //当日消费人数 var monthlyCount = monthbs.Select(x => x.UserCode).Distinct().Count(); + + //消费走势 + var months = await GetConsumptionTrendsAsync(ConsumptionTrendEnumType.Month); + var days = await GetConsumptionTrendsAsync(ConsumptionTrendEnumType.Day); + var res = new ConsumeNumberResponse { Total = devices.Count(), OffNumber = offCount, PlaceNumber = places.Count(), ConsumerableNumber = consumerable, - DailyNumber = monthlyCount != 0 ? (int)Math.Ceiling(monthlySpending / monthlyCount) : 0 + DailyNumber = monthlyCount != 0 ? Math.Abs((int)Math.Ceiling(monthlySpending / monthlyCount)) : 0, + Days = days, + Months = months }; return res; } - public async Task> GetConsumptionTrendsAsync(ConsumptionTrendRequest request) + private async Task> GetConsumptionTrendsAsync(ConsumptionTrendEnumType type) { var bs = await _dbContext.Queryable() .Where(x => x.Type == BalanceRecordTypeEnumType.Out) @@ -595,7 +602,7 @@ public class BalanceService : IBalanceService var totalAmount = Math.Round(Math.Abs(bs.Sum(x => x.Amount)), 2); var list = new List(); - if (request.Type == ConsumptionTrendEnumType.Month) + if (type == ConsumptionTrendEnumType.Month) { //月与总额对比 var months = GetMonthsOfYear(); @@ -636,11 +643,6 @@ public class BalanceService : IBalanceService return list; } - public async Task> GetSupplementTrendsAsync(ConsumptionTrendRequest request) - { - //todo - return new List(); - } public async Task> GetOaEMealVoucherAsync(OaEMealVoucherRequest request) { From b2723735849e91b8f3baa9bf0d7949d253587b1b Mon Sep 17 00:00:00 2001 From: liguoyang Date: Fri, 23 Feb 2024 12:12:30 +0800 Subject: [PATCH 031/146] =?UTF-8?q?fix=20=E8=90=A5=E4=B8=9A=E7=82=B9?= =?UTF-8?q?=E9=A4=90=E6=AC=A1=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/BusinessPlacesController.cs | 11 ++ .../Request/BusinessPlaceSaveShiftRequest.cs | 14 ++ .../Services/IBusinessPlaceService.cs | 19 ++- .../Implements/BusinessPlaceService.cs | 36 ++++- .../Controllers/BusinessShiftsController.cs | 10 ++ .../Request/BusinessPlaceShiftPageRequest.cs | 2 +- .../BusinessPlaceShiftSaveMealShiftRequest.cs | 38 +++++ .../Request/BusinessPlaceShiftSaveRequest.cs | 29 +--- .../Response/BusinessPlaceShiftResponse.cs | 25 --- .../BusinessPlaceShiftTinyResponse.cs | 5 - .../Services/IBusinessPlaceShiftService.cs | 4 + .../Implements/BusinessPlaceShiftService.cs | 146 ++++++++++++------ .../DevicePermissionsController.cs | 1 - .../Implements/DeviceConnectService.cs | 4 +- .../Services/Implements/DeviceGroupService.cs | 3 +- .../Implements/DevicePermissionService.cs | 1 - .../Controllers/GainfoGroupsController.cs | 2 +- .../Services/Implements/BalanceService.cs | 20 +-- .../Order/Services/Implements/OrderService.cs | 33 ++-- ...sPlaceEntity.cs => BusinessPlaceEntity.cs} | 4 +- .../BusinessPlaceShiftRelationshipEntity.cs | 18 +++ .../Basic/Entity/BusinessShiftEntity.cs | 32 ++++ ...=> BusinessShiftMealRelationshipEntity.cs} | 28 ++-- .../Canteen/Entities/BalanceRecordEntity.cs | 8 +- 24 files changed, 334 insertions(+), 159 deletions(-) create mode 100644 Src/Dlhis.Basic/BusinessPlace/Request/BusinessPlaceSaveShiftRequest.cs create mode 100644 Src/Dlhis.Basic/BusinessShift/Request/BusinessPlaceShiftSaveMealShiftRequest.cs rename Src/Dlhis.Entity/Basic/Entity/{CanteenBusinessPlaceEntity.cs => BusinessPlaceEntity.cs} (91%) create mode 100644 Src/Dlhis.Entity/Basic/Entity/BusinessPlaceShiftRelationshipEntity.cs create mode 100644 Src/Dlhis.Entity/Basic/Entity/BusinessShiftEntity.cs rename Src/Dlhis.Entity/Basic/Entity/{CanteenBusinessShiftEntity.cs => BusinessShiftMealRelationshipEntity.cs} (50%) diff --git a/Src/Dlhis.Basic/BusinessPlace/Controllers/BusinessPlacesController.cs b/Src/Dlhis.Basic/BusinessPlace/Controllers/BusinessPlacesController.cs index 9649c414..44ada252 100644 --- a/Src/Dlhis.Basic/BusinessPlace/Controllers/BusinessPlacesController.cs +++ b/Src/Dlhis.Basic/BusinessPlace/Controllers/BusinessPlacesController.cs @@ -58,6 +58,17 @@ public class BusinessPlacesController : ControllerBase await _businessPlaceService.SaveAsync(request); } + /// + /// 营业点保存餐次 + /// + /// + /// + [HttpPost("shift/save")] + public async Task SaveShiftAsync(BusinessPlaceSaveShiftRequest request) + { + await _businessPlaceService.SaveShiftAsync(request); + } + /// /// 根据手工号获取餐别 /// diff --git a/Src/Dlhis.Basic/BusinessPlace/Request/BusinessPlaceSaveShiftRequest.cs b/Src/Dlhis.Basic/BusinessPlace/Request/BusinessPlaceSaveShiftRequest.cs new file mode 100644 index 00000000..23fc1140 --- /dev/null +++ b/Src/Dlhis.Basic/BusinessPlace/Request/BusinessPlaceSaveShiftRequest.cs @@ -0,0 +1,14 @@ +namespace Dlhis.Basic.BusinessPlace.Request; + +public class BusinessPlaceSaveShiftRequest +{ + /// + /// 营业点id + /// + public long Id { get; set; } + + /// + /// 餐次code + /// + public Guid ShiftCode { get; set; } +} diff --git a/Src/Dlhis.Basic/BusinessPlace/Services/IBusinessPlaceService.cs b/Src/Dlhis.Basic/BusinessPlace/Services/IBusinessPlaceService.cs index e012ce37..2ada296c 100644 --- a/Src/Dlhis.Basic/BusinessPlace/Services/IBusinessPlaceService.cs +++ b/Src/Dlhis.Basic/BusinessPlace/Services/IBusinessPlaceService.cs @@ -1,12 +1,16 @@ using Dlhis.Basic.BusinessPlace.Request; using Dlhis.Basic.BusinessPlace.Response; using Kurisu.Core.DataAccess.Dto; -using Kurisu.SqlSugar.Attributes; namespace Dlhis.Basic.BusinessPlace.Services; public interface IBusinessPlaceService : IScopeDependency { + /// + /// 营业点分页 + /// + /// + /// Task> GetPageAsync(BusinessPlacePageRequest request); /// @@ -15,6 +19,17 @@ public interface IBusinessPlaceService : IScopeDependency /// Task> GetOpenedListAsync(); - + /// + /// 保存营业点 + /// + /// + /// Task SaveAsync(BusinessPlaceSaveRequest request); + + /// + /// 营业点保存餐次 + /// + /// + /// + Task SaveShiftAsync(BusinessPlaceSaveShiftRequest request); } diff --git a/Src/Dlhis.Basic/BusinessPlace/Services/Implements/BusinessPlaceService.cs b/Src/Dlhis.Basic/BusinessPlace/Services/Implements/BusinessPlaceService.cs index 6e60570a..66fe18e8 100644 --- a/Src/Dlhis.Basic/BusinessPlace/Services/Implements/BusinessPlaceService.cs +++ b/Src/Dlhis.Basic/BusinessPlace/Services/Implements/BusinessPlaceService.cs @@ -22,46 +22,68 @@ public class BusinessPlaceService : IBusinessPlaceService public async Task> GetPageAsync(BusinessPlacePageRequest request) { - var page = await _dbContext.Queryable() + var page = await _dbContext.Queryable() .WhereIF(request.Search.IsPresent(), x => x.CustomCode.Contains(request.Search)) .WhereIF(request.Catalog.HasValue, x => x.Catalog == request.Catalog) .WhereIF(request.Status.HasValue, x => x.Status == request.Status) .WhereIF(request.Source.HasValue, x => x.Source == request.Source) .Select() .ToPageListAsync(request); - + return page; } public async Task> GetOpenedListAsync() { - return await _dbContext.Queryable() + return await _dbContext.Queryable() .Where(x => x.Status == CanteenBusinessPlaceStatusEnumType.Opened) .Select() .ToListAsync(); } - + public async Task SaveAsync(BusinessPlaceSaveRequest request) { await CheckExistsCustomCodeAsync(request); if (!request.Id.HasValue) { - var entity = request.Adapt(); + var entity = request.Adapt(); entity.Code = Guid.NewGuid(); await _dbContext.InsertAsync(entity); } else { - var entity = await _dbContext.Queryable().FirstAsync(x => x.Id == request.Id); + var entity = await _dbContext.Queryable().FirstAsync(x => x.Id == request.Id); request.Adapt(entity); await _dbContext.UpdateAsync(entity); } } + + public async Task SaveShiftAsync(BusinessPlaceSaveShiftRequest request) + { + var place = await _dbContext.Queryable().Where(x => x.Id == request.Id).FirstAsync(); + place.ThrowIfNull("营业点不存在"); + + var relationship = await _dbContext.Queryable().Where(x => x.PlaceCode == place.Code).FirstAsync(); + if (relationship == null) + { + await _dbContext.InsertAsync(new BusinessPlaceShiftRelationshipEntity + { + PlaceCode = place.Code, + ShiftCode = request.ShiftCode, + }); + } + else + { + relationship.ShiftCode = request.ShiftCode; + await _dbContext.UpdateAsync(relationship); + } + } + //*********************************************** help methods ***************************************************// /// @@ -71,7 +93,7 @@ public class BusinessPlaceService : IBusinessPlaceService /// private async Task CheckExistsCustomCodeAsync(BusinessPlaceSaveRequest request) { - var existsSameCustomCode = await _dbContext.Queryable() + var existsSameCustomCode = await _dbContext.Queryable() .Where(x => x.CustomCode == request.CustomCode) .WhereIF(request.Id.HasValue, x => x.Id != request.Id) .AnyAsync(); diff --git a/Src/Dlhis.Basic/BusinessShift/Controllers/BusinessShiftsController.cs b/Src/Dlhis.Basic/BusinessShift/Controllers/BusinessShiftsController.cs index 154bb984..6ec9592c 100644 --- a/Src/Dlhis.Basic/BusinessShift/Controllers/BusinessShiftsController.cs +++ b/Src/Dlhis.Basic/BusinessShift/Controllers/BusinessShiftsController.cs @@ -33,6 +33,16 @@ public class BusinessShiftsController : ControllerBase return await _businessPlaceShiftService.GetPageAsync(request); } + /// + /// 餐次列表 + /// + /// + [HttpGet("list")] + public async Task> GetListAsync() + { + return await _businessPlaceShiftService.GetListAsync(); + } + /// /// 餐次保存 /// diff --git a/Src/Dlhis.Basic/BusinessShift/Request/BusinessPlaceShiftPageRequest.cs b/Src/Dlhis.Basic/BusinessShift/Request/BusinessPlaceShiftPageRequest.cs index ed518c13..5ed2e3c2 100644 --- a/Src/Dlhis.Basic/BusinessShift/Request/BusinessPlaceShiftPageRequest.cs +++ b/Src/Dlhis.Basic/BusinessShift/Request/BusinessPlaceShiftPageRequest.cs @@ -4,5 +4,5 @@ namespace Dlhis.Basic.BusinessShift.Request; public class BusinessPlaceShiftPageRequest : PageDto { - public Guid? BusinessPlaceCode { get; set; } + } diff --git a/Src/Dlhis.Basic/BusinessShift/Request/BusinessPlaceShiftSaveMealShiftRequest.cs b/Src/Dlhis.Basic/BusinessShift/Request/BusinessPlaceShiftSaveMealShiftRequest.cs new file mode 100644 index 00000000..98e63fae --- /dev/null +++ b/Src/Dlhis.Basic/BusinessShift/Request/BusinessPlaceShiftSaveMealShiftRequest.cs @@ -0,0 +1,38 @@ +using System.ComponentModel.DataAnnotations; +using Kurisu.Core.CustomClass; + +namespace Dlhis.Basic.BusinessShift.Request; + +public class BusinessPlaceShiftSaveMealShiftRequest : IValidatableObject +{ + public long? Id { get; set; } + + /// + /// 餐次Code + /// + public Guid ShiftCode { get; set; } + + /// + /// mealshift + /// + public string ShiftType { get; set; } + + /// + /// 序号 + /// + public int Sequence { get; set; } = 100; + + /// + /// 时间段 + /// + public TimePeriod TimePeriod { get; set; } + + + public IEnumerable Validate(ValidationContext validationContext) + { + if (TimePeriod.Start == TimePeriod.End) + { + yield return new ValidationResult("时间段设置区间有误,开始时段不能等于结束时段.", new[] { nameof(TimePeriod) }); + } + } +} diff --git a/Src/Dlhis.Basic/BusinessShift/Request/BusinessPlaceShiftSaveRequest.cs b/Src/Dlhis.Basic/BusinessShift/Request/BusinessPlaceShiftSaveRequest.cs index 8353c298..82f1c25c 100644 --- a/Src/Dlhis.Basic/BusinessShift/Request/BusinessPlaceShiftSaveRequest.cs +++ b/Src/Dlhis.Basic/BusinessShift/Request/BusinessPlaceShiftSaveRequest.cs @@ -1,39 +1,20 @@ using System.ComponentModel.DataAnnotations; -using Kurisu.Core.CustomClass; namespace Dlhis.Basic.BusinessShift.Request; -public class BusinessPlaceShiftSaveRequest : IValidatableObject +public class BusinessPlaceShiftSaveRequest { public long? Id { get; set; } - /// - /// 营业点代号 - /// - [Required(ErrorMessage = "营业点不能为空")] - public Guid BusinessPlaceCode { get; set; } - /// /// 自定义代号 mealshift /// - [Required(ErrorMessage = "餐次编号不能为空")] + [Required(ErrorMessage = "餐次手工号不能为空")] public string CustomCode { get; set; } /// - /// 序号 + /// 餐次名称 /// - public int Sequence { get; set; } = 100; - - /// - /// 时间段 - /// - public TimePeriod TimePeriod { get; set; } - - public IEnumerable Validate(ValidationContext validationContext) - { - if (TimePeriod.Start == TimePeriod.End) - { - yield return new ValidationResult("时间段设置区间有误,开始时段不能等于结束时段.", new[] { nameof(TimePeriod) }); - } - } + [Required(ErrorMessage = "餐次名称")] + public string Name { get; set; } } diff --git a/Src/Dlhis.Basic/BusinessShift/Response/BusinessPlaceShiftResponse.cs b/Src/Dlhis.Basic/BusinessShift/Response/BusinessPlaceShiftResponse.cs index 5c6848a6..f0a9d504 100644 --- a/Src/Dlhis.Basic/BusinessShift/Response/BusinessPlaceShiftResponse.cs +++ b/Src/Dlhis.Basic/BusinessShift/Response/BusinessPlaceShiftResponse.cs @@ -4,21 +4,6 @@ public class BusinessPlaceShiftResponse { public long Id { get; set; } - /// - /// 营业点代号 - /// - public Guid BusinessPlaceCode { get; set; } - - /// - /// 营业点手工号 - /// - public string BusinessPlaceCustomCode { get; set; } - - /// - /// 营业点 - /// - public string BusinessPlace { get; set; } - /// /// 代号 /// @@ -33,14 +18,4 @@ public class BusinessPlaceShiftResponse /// 餐次名称 /// public string Name { get; set; } - - /// - /// 经营开始时间 - /// - public TimeOnly Start { get; set; } - - /// - /// 经营结束时间 - /// - public TimeOnly End { get; set; } } diff --git a/Src/Dlhis.Basic/BusinessShift/Response/BusinessPlaceShiftTinyResponse.cs b/Src/Dlhis.Basic/BusinessShift/Response/BusinessPlaceShiftTinyResponse.cs index cf2576ab..1e01e9db 100644 --- a/Src/Dlhis.Basic/BusinessShift/Response/BusinessPlaceShiftTinyResponse.cs +++ b/Src/Dlhis.Basic/BusinessShift/Response/BusinessPlaceShiftTinyResponse.cs @@ -2,11 +2,6 @@ public class BusinessPlaceShiftTinyResponse { - /// - /// 自定义代号 - /// - public string CustomCode { get; set; } - /// /// 餐次名称 /// diff --git a/Src/Dlhis.Basic/BusinessShift/Services/IBusinessPlaceShiftService.cs b/Src/Dlhis.Basic/BusinessShift/Services/IBusinessPlaceShiftService.cs index 3993951a..694c7948 100644 --- a/Src/Dlhis.Basic/BusinessShift/Services/IBusinessPlaceShiftService.cs +++ b/Src/Dlhis.Basic/BusinessShift/Services/IBusinessPlaceShiftService.cs @@ -9,7 +9,11 @@ public interface IBusinessPlaceShiftService : IScopeDependency { Task> GetPageAsync(BusinessPlaceShiftPageRequest request); + Task> GetListAsync(); + Task SaveAsync(BusinessPlaceShiftSaveRequest request); + Task SaveMealShiftsAsync(List requests); + Task GetShiftsByPlaceCustomCodeAsync(string placeCustomCode); } diff --git a/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs b/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs index aa263e38..941378eb 100644 --- a/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs +++ b/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs @@ -11,6 +11,7 @@ using Kurisu.SqlSugar.Attributes; using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Services; using Mapster; +using Org.BouncyCastle.Asn1.Ocsp; namespace Dlhis.Basic.BusinessShift.Services.Implements; @@ -27,58 +28,81 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService public async Task> GetPageAsync(BusinessPlaceShiftPageRequest request) { - var page = await _dbContext.Queryable() - .LeftJoin((shift, place) => shift.BusinessPlaceCode == place.Code) - .LeftJoin((shift, place, type) => shift.Code.ToString() == type.Code) - .WhereIF(request.Search.IsPresent(), (shift, place) => shift.CustomCode.Contains(request.Search)) - .WhereIF(request.BusinessPlaceCode.HasValue, (shift, place) => shift.BusinessPlaceCode == request.BusinessPlaceCode) - .Select((shift, place, type) => new BusinessPlaceShiftResponse - { - Id = shift.Id, - BusinessPlaceCode = place.Code, - BusinessPlaceCustomCode = place.CustomCode, - BusinessPlace = place.Name, - Code = shift.Code, - CustomCode = shift.CustomCode, - Name = type.Display, - Start = shift.Start, - End = shift.End - }) + var page = await _dbContext.Queryable() + .WhereIF(request.Search.IsPresent(), (shift) => shift.CustomCode.Contains(request.Search) || shift.Name.Contains(request.Search)) + .Select() .ToPageListAsync(request); return page; } + public async Task> GetListAsync() + { + var result = await _dbContext.Queryable() + .Select().ToListAsync(); + + return result; + } + public async Task SaveAsync(BusinessPlaceShiftSaveRequest request) { - await CheckExistsCustomCodeAsync(request); - await DuplicateTimePeriodAsync(request); - await CheckPlaceExistsAsync(request.BusinessPlaceCode); - + await CheckExistsAsync(request); if (!request.Id.HasValue) { - var entity = request.Adapt(); + var entity = request.Adapt(); entity.Code = Guid.NewGuid(); - entity.Start = request.TimePeriod.Start.Value; - entity.End = request.TimePeriod.End.Value; - await _dbContext.InsertAsync(entity); } else { - var entity = await _dbContext.Queryable().FirstAsync(x => x.Id == request.Id); - entity.Adapt(request); + var entity = await _dbContext.Queryable().FirstAsync(x => x.Id == request.Id); + entity.ThrowIfNull("餐次不存在"); + request.Adapt(entity); await _dbContext.UpdateAsync(entity); } } + [Transactional] + public async Task SaveMealShiftsAsync(List requests) + { + var mealShifts = await GetMealShiftAsync(); + + foreach (var request in requests) + { + var shift = await CheckExistsShiftAsync(request.ShiftCode); + await CheckExistsMealShiftAsync(request); + await DuplicateTimePeriodAsync(request); + mealShifts.Contains(request.ShiftType).ThrowIfFalse($"{request.ShiftType}不存在"); + + if (!request.Id.HasValue) + { + var entity = request.Adapt(); + + entity.ShiftCode = shift.Code; + entity.ShiftCustomCode = shift.CustomCode; + entity.Start = request.TimePeriod.Start.Value; + entity.End = request.TimePeriod.End.Value; + + await _dbContext.InsertAsync(entity); + } + else + { + var entity = await _dbContext.Queryable().FirstAsync(x => x.Id == request.Id); + entity.ThrowIfNull("餐次不存在"); + + request.Adapt(entity); + await _dbContext.UpdateAsync(entity); + } + } + } + [IgnoreTenant] public async Task GetShiftsByPlaceCustomCodeAsync(string placeCustomCode) { - var place = await _dbContext.Queryable().Where(x => x.CustomCode == placeCustomCode).FirstAsync(); + var place = await _dbContext.Queryable().Where(x => x.CustomCode == placeCustomCode).FirstAsync(); if (place == null) { return new BusinessPlaceWithShiftResponse() @@ -87,8 +111,17 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService }; } - var shifts = await _dbContext.Queryable() - .Where(x => x.BusinessPlaceCode == place.Code) + var relationship = await _dbContext.Queryable().Where(x => x.PlaceCode == place.Code).FirstAsync(); + if (relationship == null) + { + return new BusinessPlaceWithShiftResponse() + { + Shifts = new List() + }; + } + + var shifts = await _dbContext.Queryable() + .Where(x => x.ShiftCode == relationship.ShiftCode) .OrderBy(x => x.Sequence) //排序 .ToListAsync(); @@ -97,15 +130,15 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService var tenantInfo = tenantResult.Data; var list = new List(); - foreach (CanteenBusinessShiftEntity shiftinfo in shifts) + foreach (BusinessShiftMealRelationshipEntity shiftinfo in shifts) { var name = _dbContext.Queryable() - .Where(x => x.Code == shiftinfo.CustomCode.ToString()) + .Where(x => x.Code == shiftinfo.ShiftType.ToString()) .Select(x => x.Display) .First(); + var shift = new BusinessPlaceShiftTinyResponse { - CustomCode = shiftinfo.CustomCode, Name = name, Start = shiftinfo.Start, End = shiftinfo.End @@ -122,24 +155,18 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService }; } + //*********************************************** help methods ***************************************************// - - private async Task CheckPlaceExistsAsync(Guid code) - { - var existsPlace = await _dbContext.Queryable().AnyAsync(x => x.Code == code); - existsPlace.ThrowIfFalse("营业点不存在,请检查."); - } - /// /// 时间段重合检查 /// /// /// - private async Task DuplicateTimePeriodAsync(BusinessPlaceShiftSaveRequest request) + private async Task DuplicateTimePeriodAsync(BusinessPlaceShiftSaveMealShiftRequest request) { - var periods = await _dbContext.Queryable() - .Where(x => x.BusinessPlaceCode == request.BusinessPlaceCode) + var periods = await _dbContext.Queryable() + .Where(x => x.ShiftCode == request.ShiftCode) .WhereIF(request.Id.HasValue, x => x.Id != request.Id) .Select(x => new TimePeriod { @@ -156,18 +183,41 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService /// - /// 检查重复手工号 + /// 检查重复 /// /// /// - private async Task CheckExistsCustomCodeAsync(BusinessPlaceShiftSaveRequest request) + private async Task CheckExistsAsync(BusinessPlaceShiftSaveRequest request) { - var existsSameCustomCode = await _dbContext.Queryable() - .Where(x => x.CustomCode == request.CustomCode) + var existsSameCustomCode = await _dbContext.Queryable() + .Where(x => x.CustomCode == request.CustomCode || x.Name == request.Name) .WhereIF(request.Id.HasValue, x => x.Id != request.Id) .AnyAsync(); - existsSameCustomCode.ThrowIfTrue($"自定义手工号[{request.CustomCode}]存在重复,请检查."); + existsSameCustomCode.ThrowIfTrue($"自定义手工号或者名称存在重复,请检查."); } + private async Task CheckExistsShiftAsync(Guid shiftCode) + { + var shift = await _dbContext.Queryable().Where(x => x.Code == shiftCode).FirstAsync(); + shift.ThrowIfNull("餐次不存在"); + + return shift; + } + + private async Task> GetMealShiftAsync() + { + return await _dbContext.Queryable().Where(x => x.Type == "mealshift").Select(x => x.Code).ToListAsync(); + } + + private async Task CheckExistsMealShiftAsync(BusinessPlaceShiftSaveMealShiftRequest request) + { + var exists = await _dbContext.Queryable() + .Where(x => x.ShiftCode == request.ShiftCode) + .Where(x => x.ShiftType == request.ShiftType) + .WhereIF(request.Id.HasValue, x => x.Id != request.Id) + .AnyAsync(); + + exists.ThrowIfTrue("重复设置!"); + } } diff --git a/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs b/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs index ad89e286..63a9d64c 100644 --- a/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs +++ b/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs @@ -4,7 +4,6 @@ using Dlhis.Basic.Device.Services; using Kurisu.Core.DataAccess.Dto; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Org.BouncyCastle.Asn1.Ocsp; namespace Dlhis.Basic.Device.Controllers; diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceConnectService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceConnectService.cs index e507e5e5..7dee0250 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceConnectService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceConnectService.cs @@ -23,7 +23,7 @@ public class DeviceConnectService : IDeviceConnectService [IgnoreTenant] public async Task ResigterAsync(DeviceResigterRequest request) { - var businessPlace = await _dbContext.Queryable().Where(x => x.CustomCode == request.BusinessCustomCode).FirstAsync(); + var businessPlace = await _dbContext.Queryable().Where(x => x.CustomCode == request.BusinessCustomCode).FirstAsync(); businessPlace.ThrowIfNull("营业点不存在"); var device = await GetEnableDeviceAsync(request.UniqueNo, false, request.DeployPlace, businessPlace.TenantId); @@ -71,7 +71,7 @@ public class DeviceConnectService : IDeviceConnectService var registry = await _dbContext.Queryable().Where(x => x.DeviceUniqueNo == request.UniqueNo).FirstAsync(); registry.ThrowIfNull($"{request.UniqueNo}的设备注册信息不存在,无法设置营业点"); - var businessPlace = await _dbContext.Queryable().Where(x => x.Code == request.BusinessPlaceCode).FirstAsync(); + var businessPlace = await _dbContext.Queryable().Where(x => x.Code == request.BusinessPlaceCode).FirstAsync(); businessPlace.ThrowIfNull("营业点不存在,无法设置到设备注册信息中"); //更新营业点信息 diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs index 3047a115..a8dfee90 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs @@ -65,7 +65,6 @@ public class DeviceGroupService : IDeviceGroupService { var entity = await _dbContext.Queryable().Where(x => x.Id == request.Id).FirstAsync(); entity.ThrowIfNull("设备组不存在,无法更新"); - entity.Editable.ThrowIfFalse("不可编辑当前组"); var nextDevices = await GetDevicesAsync(entity.Code); @@ -78,6 +77,7 @@ public class DeviceGroupService : IDeviceGroupService (request.Type.HasValue && request.Type != entity.Type && nextDevices.Any()).ThrowIfTrue("分组设备类型不匹配,无法修改类型"); } + request.Adapt(entity); await _dbContext.UpdateAsync(entity); } } @@ -106,7 +106,6 @@ public class DeviceGroupService : IDeviceGroupService var relationships = await _dbContext.Queryable().Where(x => x.GroupCode == request.GroupCode).ToListAsync(); await _dbContext.DeleteAsync(relationships); - var entities = request.DeviceCodes.Select(x => new DeviceGroupRelationshipEntity { GroupCode = request.GroupCode, diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs index e0c3d564..3aee41b7 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs @@ -9,7 +9,6 @@ using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.DataAccess.Dto; using Kurisu.SqlSugar.Attributes; using Kurisu.SqlSugar.Services; -using System.Collections.Generic; namespace Dlhis.Basic.Device.Services.Implements; diff --git a/Src/Dlhis.Basic/Organization/Controllers/GainfoGroupsController.cs b/Src/Dlhis.Basic/Organization/Controllers/GainfoGroupsController.cs index b578cf1a..42e765ba 100644 --- a/Src/Dlhis.Basic/Organization/Controllers/GainfoGroupsController.cs +++ b/Src/Dlhis.Basic/Organization/Controllers/GainfoGroupsController.cs @@ -50,7 +50,7 @@ public class GainfoGroupsController : ControllerBase /// /// /// - [HttpPost] + [HttpPost("save")] public async Task SaveAsync(GainfoGroupSaveRequest request) { await _gainfoGroupService.SaveAsync(request); diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs index 063353ca..59e76cd1 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs @@ -37,8 +37,8 @@ public class BalanceService : IBalanceService var page = await _dbContext.Queryable() .LeftJoin((record, ga) => record.UserNo == ga.No) .LeftJoin((record, ga, department) => ga.DepartmentNo == department.No) - .LeftJoin((record, ga, department, bplace) => record.BusinessPlaceCode == bplace.Code) - .LeftJoin((record, ga, department, bplace, bshift) => record.BusinessShiftCode == bshift.Code) + .LeftJoin((record, ga, department, bplace) => record.BusinessPlaceCode == bplace.Code) + .LeftJoin((record, ga, department, bplace, bshift) => record.BusinessShiftCode == bshift.Code) .LeftJoin((record, ga, department, bplace, bshift, type) => record.BusinessShiftCode.ToString() == type.Code) .WhereIF(request.SearchDateTimePeriod?.Start.HasValue == true, record => record.CostDate >= request.SearchDateTimePeriod.Start) .WhereIF(request.SearchDateTimePeriod?.End.HasValue == true, record => record.CostDate <= request.SearchDateTimePeriod.End) @@ -160,8 +160,8 @@ public class BalanceService : IBalanceService { var paeginfo = await _dbContext.Queryable() .LeftJoin((record, department) => record.DepartmentNo == department.No) - .LeftJoin((record, department, bplace) => record.BusinessPlaceCode == bplace.Code) - .LeftJoin((record, department, bplace, bshift) => record.BusinessShiftCode == bshift.Code) + .LeftJoin((record, department, bplace) => record.BusinessPlaceCode == bplace.Code) + .LeftJoin((record, department, bplace, bshift) => record.BusinessShiftCode == bshift.Code) .LeftJoin((record, department, bplace, bshift, type) => record.BusinessShiftCode.ToString() == type.Code) .WhereIF(!request.Name.IsEmpty(), record => record.Name == request.Name) .WhereIF(!request.DepartmentNo.IsEmpty(), record => record.DepartmentNo == request.DepartmentNo) @@ -436,8 +436,8 @@ public class BalanceService : IBalanceService var page = await _dbContext.Queryable() .LeftJoin((record, ga) => record.UserNo == ga.No) .LeftJoin((record, ga, department) => ga.DepartmentNo == department.No) - .LeftJoin((record, ga, department, bplace) => record.BusinessPlaceCode == bplace.Code) - .LeftJoin((record, ga, department, bplace, bshift) => record.BusinessShiftCode == bshift.Code) + .LeftJoin((record, ga, department, bplace) => record.BusinessPlaceCode == bplace.Code) + .LeftJoin((record, ga, department, bplace, bshift) => record.BusinessShiftCode == bshift.Code) .LeftJoin((record, ga, department, bplace, bshift, type) => record.BusinessShiftCode.ToString() == type.Code) .WhereIF(request.SearchDate.HasValue, record => record.CostDate >= start) .WhereIF(request.SearchDate.HasValue, record => record.CostDate <= end) @@ -492,8 +492,8 @@ public class BalanceService : IBalanceService var page = await _dbContext.Queryable() .LeftJoin((record, ga) => record.UserNo == ga.No) .LeftJoin((record, ga, department) => ga.DepartmentNo == department.No) - .LeftJoin((record, ga, department, bplace) => record.BusinessPlaceCode == bplace.Code) - .LeftJoin((record, ga, department, bplace, bshift) => record.BusinessShiftCode == bshift.Code) + .LeftJoin((record, ga, department, bplace) => record.BusinessPlaceCode == bplace.Code) + .LeftJoin((record, ga, department, bplace, bshift) => record.BusinessShiftCode == bshift.Code) .LeftJoin((record, ga, department, bplace, bshift, type) => record.BusinessShiftCode.ToString() == type.Code) .WhereIF(request.SearchDateTimePeriod?.Start.HasValue == true, record => record.CostDate >= request.SearchDateTimePeriod.Start) .WhereIF(request.SearchDateTimePeriod?.End.HasValue == true, record => record.CostDate <= request.SearchDateTimePeriod.End) @@ -557,7 +557,7 @@ public class BalanceService : IBalanceService var offCount = devices.Where(x => x.Enable == false).Count(); - var places = await _dbContext.Queryable() + var places = await _dbContext.Queryable() .ToListAsync(); var time = DateTime.Now.ToString("yyyy-MM-dd"); @@ -740,7 +740,7 @@ public class BalanceService : IBalanceService { var shiftCodeDict = new Dictionary(); - var shifts = await _dbContext.Queryable().ToListAsync(); + var shifts = await _dbContext.Queryable().ToListAsync(); //guid var breakfastCode = shifts.Where(x => x.CustomCode == "shift-breakfast").Select(x => x.Code).First().ToString(); diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs index baa80576..c16de272 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs @@ -6,7 +6,6 @@ using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Canteen.Entities; using Dlhis.Entity.Canteen.Enums; using Dlhis.Entity.Device.Entities; -using Dlhis.Entity.Sys.Entities; using Kurisu.AspNetCore.UnifyResultAndValidation; using Kurisu.AspNetCore.Utils; using Kurisu.AspNetCore.Utils.Extensions; @@ -66,10 +65,10 @@ public class OrderService : IOrderService } else { - _ = long.TryParse(request.UserUniqueNo, out userId); + _ = long.TryParse(request.UserUniqueNo, out userId); } var gainfo = await _dbContext.Queryable() - .Where(x => x.No == request.UserUniqueNo || x.Code == request.UserUniqueNo || x.Id == userId|| x.CardNo == card) + .Where(x => x.No == request.UserUniqueNo || x.Code == request.UserUniqueNo || x.Id == userId || x.CardNo == card) .FirstAsync(); @@ -134,11 +133,20 @@ public class OrderService : IOrderService device.ThrowIfNull("设备不存在或者尚未启用"); var registry = await _dbContext.Queryable().Where(x => x.DeviceUniqueNo == request.DeviceUniqueNo).FirstAsync(); registry.ThrowIfNull("设备尚未注册"); - var businessPlace = await _dbContext.Queryable().Where(x => x.Code == registry.BusinessPlaceCode).FirstAsync(); - businessPlace.ThrowIfNull("营业点尚未设置"); + var businessPlaceInfo = await _dbContext.Queryable() + .LeftJoin((x, sr) => x.Code == sr.PlaceCode) + .Where(x => x.Code == registry.BusinessPlaceCode) + .Select((x, sr) => new + { + x.Code, + sr.ShiftCode, + x.TenantId + }) + .FirstAsync(); + businessPlaceInfo.ThrowIfNull("营业点尚未设置"); //获取当前消费餐次 - var shifts = await _dbContext.Queryable().Where(x => x.BusinessPlaceCode == businessPlace.Code).ToListAsync(); + var shifts = await _dbContext.Queryable().Where(x => x.ShiftCode == businessPlaceInfo.ShiftCode).ToListAsync(); var shift = shifts.FirstOrDefault(x => new TimePeriod() { @@ -184,8 +192,9 @@ public class OrderService : IOrderService UserNo = gainfo.No, UserCode = gainfo.Code, Amount = request.Amount, - BusinessPlaceCode = businessPlace.Code, - BusinessShiftCode = shift?.Code, + BusinessPlaceCode = businessPlaceInfo.Code, + BusinessShiftCode = shift?.ShiftCode, + ShiftType = shift?.ShiftType, CostDate = costDate.Date, CostId = gainfo.CostId, DepartmentNo = gainfo.DepartmentNo, @@ -206,7 +215,7 @@ public class OrderService : IOrderService CostDateTime = request.CostDateTime, //标识当前消费的基地 - TenantId = businessPlace.TenantId, + TenantId = businessPlaceInfo.TenantId, }; var orderId = await _dbContext.InsertReturnIdentityAsync(order); @@ -364,7 +373,7 @@ public class OrderService : IOrderService /// /// /// - private async Task Verify(Dictionary settings, List shifts, DateTime costDateTime, CanteenOrderEntity order) + private async Task Verify(Dictionary settings, List shifts, DateTime costDateTime, CanteenOrderEntity order) { //在线 if (!order.IsOffline) @@ -388,7 +397,7 @@ public class OrderService : IOrderService var dayMarketCostMax = GetSetting(settings, CanteenSettingItemEnumType.DayMarketCostMax); if (dayMarketCostMax != default) { - var businessPlaceCodes = await _dbContext.Queryable() + var businessPlaceCodes = await _dbContext.Queryable() .Where(x => x.Catalog == CanteenBusinessPlaceCatalogEnumType.Supermarket) .Select(x => x.Code).ToListAsync(); @@ -473,7 +482,7 @@ public class OrderService : IOrderService /// /// /// - private async Task GenerateConsumeRecordAsync(long orderId, Dictionary settings, List shifts, DateTime costDateTime) + private async Task GenerateConsumeRecordAsync(long orderId, Dictionary settings, List shifts, DateTime costDateTime) { var order = await _dbContext.Queryable().Where(x => x.Id == orderId).FirstAsync(); //校验 diff --git a/Src/Dlhis.Entity/Basic/Entity/CanteenBusinessPlaceEntity.cs b/Src/Dlhis.Entity/Basic/Entity/BusinessPlaceEntity.cs similarity index 91% rename from Src/Dlhis.Entity/Basic/Entity/CanteenBusinessPlaceEntity.cs rename to Src/Dlhis.Entity/Basic/Entity/BusinessPlaceEntity.cs index 8af87c99..866f030a 100644 --- a/Src/Dlhis.Entity/Basic/Entity/CanteenBusinessPlaceEntity.cs +++ b/Src/Dlhis.Entity/Basic/Entity/BusinessPlaceEntity.cs @@ -9,8 +9,8 @@ namespace Dlhis.Entity.Basic.Entity; /// /// 营业点 /// -[SugarTable(TableName = "CanteenBusinessPlace", TableDescription = "营业点")] -public class CanteenBusinessPlaceEntity : SugarBaseEntity, ITenantId +[SugarTable(TableName = "BusinessPlace", TableDescription = "营业点")] +public class BusinessPlaceEntity : SugarBaseEntity, ITenantId { /// /// 代号 diff --git a/Src/Dlhis.Entity/Basic/Entity/BusinessPlaceShiftRelationshipEntity.cs b/Src/Dlhis.Entity/Basic/Entity/BusinessPlaceShiftRelationshipEntity.cs new file mode 100644 index 00000000..b4419ca8 --- /dev/null +++ b/Src/Dlhis.Entity/Basic/Entity/BusinessPlaceShiftRelationshipEntity.cs @@ -0,0 +1,18 @@ +using Kurisu.Core.DataAccess.Entity; +using Kurisu.SqlSugar; +using SqlSugar; + +namespace Dlhis.Entity.Basic.Entity; + +[SugarTable(TableName = "BusinessPlaceShiftRelationship", TableDescription = "营业点餐次关系")] +public class BusinessPlaceShiftRelationshipEntity : SugarBaseEntity, ITenantId +{ + [SugarColumn(ColumnDescription = "营业点code")] + public Guid PlaceCode { get; set; } + + + [SugarColumn(ColumnDescription = "餐次code")] + public Guid ShiftCode { get; set; } + + public string TenantId { get; set; } +} diff --git a/Src/Dlhis.Entity/Basic/Entity/BusinessShiftEntity.cs b/Src/Dlhis.Entity/Basic/Entity/BusinessShiftEntity.cs new file mode 100644 index 00000000..9893a6c6 --- /dev/null +++ b/Src/Dlhis.Entity/Basic/Entity/BusinessShiftEntity.cs @@ -0,0 +1,32 @@ +using Kurisu.Core.DataAccess.Entity; +using Kurisu.SqlSugar; +using SqlSugar; + +namespace Dlhis.Entity.Basic.Entity; + +/// +/// 营业点餐次 +/// +[SugarTable(TableName = "BusinessShift", TableDescription = "营业点餐次")] +public class BusinessShiftEntity : SugarBaseEntity, ITenantId +{ + /// + /// 代号 + /// + [SugarColumn(ColumnDescription = "code")] + public Guid Code { get; set; } + + /// + /// 自定义代号 + /// + [SugarColumn(ColumnDescription = "自定义手工号")] + public string CustomCode { get; set; } + + /// + /// 餐次名称 + /// + [SugarColumn(ColumnDescription = "餐次名称")] + public string Name { get; set; } + + public string TenantId { get; set; } +} \ No newline at end of file diff --git a/Src/Dlhis.Entity/Basic/Entity/CanteenBusinessShiftEntity.cs b/Src/Dlhis.Entity/Basic/Entity/BusinessShiftMealRelationshipEntity.cs similarity index 50% rename from Src/Dlhis.Entity/Basic/Entity/CanteenBusinessShiftEntity.cs rename to Src/Dlhis.Entity/Basic/Entity/BusinessShiftMealRelationshipEntity.cs index be1316ee..6172c059 100644 --- a/Src/Dlhis.Entity/Basic/Entity/CanteenBusinessShiftEntity.cs +++ b/Src/Dlhis.Entity/Basic/Entity/BusinessShiftMealRelationshipEntity.cs @@ -4,29 +4,26 @@ using SqlSugar; namespace Dlhis.Entity.Basic.Entity; -/// -/// 营业点餐次 -/// -[SugarTable(TableName = "CanteenBusinessShift", TableDescription = "营业点餐次")] -public class CanteenBusinessShiftEntity : SugarBaseEntity, ITenantId +[SugarTable(TableName = "BusinessShiftMealRelationship", TableDescription = "营业点餐次组合")] +public class BusinessShiftMealRelationshipEntity : SugarBaseEntity, ITenantId { /// - /// 营业点代号 + /// 餐次组合Code /// - [SugarColumn(ColumnDescription = "营业点code")] - public Guid BusinessPlaceCode { get; set; } + [SugarColumn(ColumnDescription = "餐次组合Code", UniqueGroupNameList = new[] { "idx_CanteenBusinessShiftRelationship_shiftcode_shifttype" })] + public Guid ShiftCode { get; set; } /// - /// 代号 + /// 餐次组合手工号 /// - [SugarColumn(ColumnDescription = "code")] - public Guid Code { get; set; } + [SugarColumn(ColumnDescription = "餐次组合手工号")] + public string ShiftCustomCode { get; set; } /// - /// 自定义代号 + /// 餐次 /// - [SugarColumn(ColumnDescription = "自定义手工号")] - public string CustomCode { get; set; } + [SugarColumn(ColumnDescription = "餐次", UniqueGroupNameList = new[] { "idx_CanteenBusinessShiftRelationship_shiftcode_shifttype" })] + public string ShiftType { get; set; } /// /// 经营开始时间 @@ -46,5 +43,6 @@ public class CanteenBusinessShiftEntity : SugarBaseEntity, ITenantId [SugarColumn(ColumnDescription = "序号")] public int Sequence { get; set; } + public string TenantId { get; set; } -} \ No newline at end of file +} diff --git a/Src/Dlhis.Entity/Canteen/Entities/BalanceRecordEntity.cs b/Src/Dlhis.Entity/Canteen/Entities/BalanceRecordEntity.cs index 3303970b..9b69d0ce 100644 --- a/Src/Dlhis.Entity/Canteen/Entities/BalanceRecordEntity.cs +++ b/Src/Dlhis.Entity/Canteen/Entities/BalanceRecordEntity.cs @@ -64,7 +64,7 @@ public class BalanceRecordEntity : SugarBaseEntity, ITenantId /// /// 营业点 /// - [SugarColumn(ColumnDescription = "营业点" , IsNullable = true)] + [SugarColumn(ColumnDescription = "营业点", IsNullable = true)] public Guid? BusinessPlaceCode { get; set; } /// @@ -73,6 +73,12 @@ public class BalanceRecordEntity : SugarBaseEntity, ITenantId [SugarColumn(ColumnDescription = "餐次", IsNullable = true)] public Guid? BusinessShiftCode { get; set; } + /// + /// 餐次段 + /// + [SugarColumn(ColumnDescription = "餐次段", IsNullable = true)] + public string ShiftType { get; set; } + /// /// 所属成本日期 /// From 7c0fa747673ea7f2d8ac1a760247b3ee976b76da Mon Sep 17 00:00:00 2001 From: liguoyang Date: Fri, 23 Feb 2024 12:22:03 +0800 Subject: [PATCH 032/146] =?UTF-8?q?fix=20=E6=95=B0=E6=8D=AE=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/BusinessPlaceShiftService.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs b/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs index 941378eb..aa3f2905 100644 --- a/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs +++ b/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs @@ -11,7 +11,6 @@ using Kurisu.SqlSugar.Attributes; using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Services; using Mapster; -using Org.BouncyCastle.Asn1.Ocsp; namespace Dlhis.Basic.BusinessShift.Services.Implements; @@ -111,11 +110,19 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService }; } + var tenantResult = await _tenantApi.GetTenantByCodeAsync(place.TenantId); + (tenantResult.Code == ApiStateCode.Success).ThrowIfFalse(tenantResult.Msg); + var tenantInfo = tenantResult.Data; + var relationship = await _dbContext.Queryable().Where(x => x.PlaceCode == place.Code).FirstAsync(); if (relationship == null) { return new BusinessPlaceWithShiftResponse() { + CustomCode = placeCustomCode, + Name = place.Name, + TenantCode = tenantInfo.Code, + TenantName = tenantInfo.Name, Shifts = new List() }; } @@ -125,10 +132,6 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService .OrderBy(x => x.Sequence) //排序 .ToListAsync(); - var tenantResult = await _tenantApi.GetTenantByCodeAsync(place.TenantId); - (tenantResult.Code == ApiStateCode.Success).ThrowIfFalse(tenantResult.Msg); - var tenantInfo = tenantResult.Data; - var list = new List(); foreach (BusinessShiftMealRelationshipEntity shiftinfo in shifts) { From 7c52b7fb1e01204e7f0cf78ee4aa2a165093e3bd Mon Sep 17 00:00:00 2001 From: liguoyang Date: Fri, 23 Feb 2024 14:13:04 +0800 Subject: [PATCH 033/146] =?UTF-8?q?fix=20=E8=B7=AF=E7=94=B1=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E9=87=8D=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs b/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs index e577baaa..94e62fe6 100644 --- a/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs +++ b/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs @@ -105,7 +105,7 @@ public class GainfosController : ControllerBase /// /// /// - [HttpPost("faces")] + [HttpPost("batchface")] public async Task UploadFaceAsync(List request) { await _gainfoService.UploadFacesAsync(request); @@ -156,6 +156,7 @@ public class GainfosController : ControllerBase { return await _gainfoService.GetGainfoListTaskAsync(request); } + /// /// 档案详情 /// From 36188926d468689f5c0a91f433f33ff8730ce508 Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Fri, 23 Feb 2024 15:19:16 +0800 Subject: [PATCH 034/146] =?UTF-8?q?fix=20=E4=BF=AE=E6=94=B9=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E9=93=BE=E6=8E=A5=E5=9F=9F=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/ApkFileController.cs | 6 ++-- .../FileOperation/Response/ApkFileResponse.cs | 10 +++++++ .../Services/IApkFIileService.cs | 2 +- .../Services/Implements/ApkFIileService.cs | 28 +++++++++++++++---- Src/Dlhis.Common/Request/ApkRequest.cs | 5 ++++ Src/Dlhis.Entity/Common/ApkFileEntity.cs | 8 +++++- 6 files changed, 49 insertions(+), 10 deletions(-) diff --git a/Src/Dlhis.Common/FileOperation/Controllers/ApkFileController.cs b/Src/Dlhis.Common/FileOperation/Controllers/ApkFileController.cs index accb0bba..5417f68f 100644 --- a/Src/Dlhis.Common/FileOperation/Controllers/ApkFileController.cs +++ b/Src/Dlhis.Common/FileOperation/Controllers/ApkFileController.cs @@ -49,12 +49,12 @@ public class ApkFileController : ControllerBase /// /// 获取最新版本 /// - /// + /// /// [HttpGet("lastverison")] - public async Task GetLastVersionAsync(string fileName) + public async Task GetLastVersionAsync(string productCode) { - return await _apkFIileService.GetLastVersionAsync(fileName); + return await _apkFIileService.GetLastVersionAsync(productCode); } diff --git a/Src/Dlhis.Common/FileOperation/Response/ApkFileResponse.cs b/Src/Dlhis.Common/FileOperation/Response/ApkFileResponse.cs index 7198cf6b..763f5cf9 100644 --- a/Src/Dlhis.Common/FileOperation/Response/ApkFileResponse.cs +++ b/Src/Dlhis.Common/FileOperation/Response/ApkFileResponse.cs @@ -23,5 +23,15 @@ namespace Dlhis.Common.FileOperation.Response /// 修改信息 /// public string UpdateMessage { get; set; } + + /// + /// 产品代码 + /// + public string ProductCode { get; set; } + + /// + /// url + /// + public string? Url { get; set; } } } diff --git a/Src/Dlhis.Common/FileOperation/Services/IApkFIileService.cs b/Src/Dlhis.Common/FileOperation/Services/IApkFIileService.cs index 0f8afb8a..5dfa8536 100644 --- a/Src/Dlhis.Common/FileOperation/Services/IApkFIileService.cs +++ b/Src/Dlhis.Common/FileOperation/Services/IApkFIileService.cs @@ -22,7 +22,7 @@ public interface IApkFIileService : IScopeDependency Task RequestDownloadFile(string fileName); - Task GetLastVersionAsync(string fileName); + Task GetLastVersionAsync(string productCode); } diff --git a/Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs b/Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs index 202dd65f..893859c7 100644 --- a/Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs +++ b/Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs @@ -15,11 +15,13 @@ public class ApkFIileService : IApkFIileService { private readonly IMinioService _minioService; private readonly IDbContext _dbContext; + private readonly IConfiguration Configuration; - public ApkFIileService(IMinioService minioService, IDbContext dbContext) + public ApkFIileService(IMinioService minioService, IDbContext dbContext, IConfiguration configuration) { _minioService = minioService; _dbContext = dbContext; + Configuration = configuration; } /// @@ -34,13 +36,21 @@ public class ApkFIileService : IApkFIileService string fileName = request.formFile.FileName; + var lenFive = request.formFile.FileName.Length >= 5; + + lenFive.ThrowIfFalse("文件名长度不能小于5"); + var houzhui = request.formFile.FileName.Substring(request.formFile.FileName.Length - 4, 4).ToLower(); + var isApk = request.formFile.FileName.Substring(request.formFile.FileName.Length - 4, 4) == ".apk"; + isApk.ThrowIfFalse("文件不是apk类型"); + //更新数据库 - var entity = await _dbContext.Queryable().Where(x => x.Name == fileName).FirstAsync(); + var entity = await _dbContext.Queryable().Where(x => x.ProductCode == request.ProductCode).FirstAsync(); if (entity == null) { var info = new ApkFileEntity { Name = fileName, + ProductCode = request.ProductCode, VersionCode = request.VersionCode, UpdateMessage = request.UpdateMessage, VersionName = request.VersionName, @@ -54,17 +64,25 @@ public class ApkFIileService : IApkFIileService entity.VersionName = request.VersionName; await _dbContext.UpdateAsync(entity); } - var newEntity = await _dbContext.Queryable().Where(x => x.Name == fileName).FirstAsync(); + var newEntity = await _dbContext.Queryable().Where(x => x.ProductCode == request.ProductCode).FirstAsync(); var res = newEntity.Adapt(); return res; } - public async Task GetLastVersionAsync(string fileName) + public async Task GetLastVersionAsync(string productCode) { var info = await _dbContext.Queryable() - .Where(x => x.Name == fileName) + .Where(x => x.ProductCode == productCode) .Select() .FirstAsync(); + var url =await RequestDownloadFile(info.Name); + + var host = Configuration["MinIO:Endpoint"]; + + var modified_url = url.Replace(host, "https://yikatong.isawesome.cn/m"); + + info.Url = modified_url; + return info; } diff --git a/Src/Dlhis.Common/Request/ApkRequest.cs b/Src/Dlhis.Common/Request/ApkRequest.cs index af368cce..86156c02 100644 --- a/Src/Dlhis.Common/Request/ApkRequest.cs +++ b/Src/Dlhis.Common/Request/ApkRequest.cs @@ -21,5 +21,10 @@ /// 修改信息 /// public string UpdateMessage { get; set; } + + /// + /// 产品代码 + /// + public string? ProductCode { get; set; } } } diff --git a/Src/Dlhis.Entity/Common/ApkFileEntity.cs b/Src/Dlhis.Entity/Common/ApkFileEntity.cs index cf1735ec..2c15bf57 100644 --- a/Src/Dlhis.Entity/Common/ApkFileEntity.cs +++ b/Src/Dlhis.Entity/Common/ApkFileEntity.cs @@ -37,6 +37,12 @@ public class ApkFileEntity : SugarBaseEntity /// [SugarColumn(ColumnDescription = "修改信息")] public string UpdateMessage { get; set; } - } + + /// + /// 产品代码 + /// + [SugarColumn(ColumnDescription = "产品代码")] + public string? ProductCode { get; set; } +} From 3e03b28a73863d6c300e9b56c9367669ed223ef7 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Fri, 23 Feb 2024 15:20:44 +0800 Subject: [PATCH 035/146] =?UTF-8?q?fix=20=E5=A2=9E=E5=8A=A0=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E9=A4=90=E6=AC=A1=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/BusinessShiftsController.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Src/Dlhis.Basic/BusinessShift/Controllers/BusinessShiftsController.cs b/Src/Dlhis.Basic/BusinessShift/Controllers/BusinessShiftsController.cs index 6ec9592c..b0438262 100644 --- a/Src/Dlhis.Basic/BusinessShift/Controllers/BusinessShiftsController.cs +++ b/Src/Dlhis.Basic/BusinessShift/Controllers/BusinessShiftsController.cs @@ -53,4 +53,15 @@ public class BusinessShiftsController : ControllerBase { await _businessPlaceShiftService.SaveAsync(request); } + + /// + /// 保存餐次段 + /// + /// + /// + [HttpPost("meal/save")] + public async Task SaveMealShiftsAsync(List requests) + { + await _businessPlaceShiftService.SaveMealShiftsAsync(requests); + } } From 7fa18402d146bed639d56fc4ae7e96c2a71dc2b9 Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Fri, 23 Feb 2024 15:23:16 +0800 Subject: [PATCH 036/146] =?UTF-8?q?fix=20=E8=8E=B7=E5=8F=96=E6=9C=80?= =?UTF-8?q?=E6=96=B0=E7=89=88=E6=9C=AC=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Common/FileOperation/Controllers/ApkFileController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/Dlhis.Common/FileOperation/Controllers/ApkFileController.cs b/Src/Dlhis.Common/FileOperation/Controllers/ApkFileController.cs index 5417f68f..7ab679b7 100644 --- a/Src/Dlhis.Common/FileOperation/Controllers/ApkFileController.cs +++ b/Src/Dlhis.Common/FileOperation/Controllers/ApkFileController.cs @@ -51,7 +51,7 @@ public class ApkFileController : ControllerBase /// /// /// - [HttpGet("lastverison")] + [HttpGet("lastversion")] public async Task GetLastVersionAsync(string productCode) { return await _apkFIileService.GetLastVersionAsync(productCode); From f255a87138b197e238a9ca76b5fb2b6948fb8715 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Fri, 23 Feb 2024 16:20:24 +0800 Subject: [PATCH 037/146] =?UTF-8?q?fix=20=E6=A1=86=E6=9E=B6=E8=B0=83?= =?UTF-8?q?=E6=95=B4,=E4=BC=98=E5=8C=96=E6=95=B0=E6=8D=AE=E8=BF=94?= =?UTF-8?q?=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/BusinessPlacesController.cs | 3 + .../Response/BusinessPlaceResponse.cs | 12 ++ .../Implements/BusinessPlaceService.cs | 20 +++- .../Controllers/BusinessShiftsController.cs | 6 +- .../Response/BusinessPlaceShiftResponse.cs | 5 + .../Response/MealShiftResponse.cs | 13 +++ .../Services/IBusinessPlaceShiftService.cs | 2 +- .../Implements/BusinessPlaceShiftService.cs | 33 +++++- .../Controllers/DeviceGroupsController.cs | 2 + .../DevicePermissionsController.cs | 2 + .../Device/Controllers/DevicesController.cs | 6 +- .../Implements/DeviceConnectService.cs | 4 +- .../Services/Implements/DeviceGroupService.cs | 1 - .../Implements/DevicePermissionService.cs | 1 - .../Services/Implements/DeviceService.cs | 3 +- Src/Dlhis.Basic/Dlhis.Basic.csproj | 2 +- .../Services/Implements/GainfoService.cs | 1 - Src/Dlhis.Basic/Packs/SqlSugarPack.cs | 98 +++++++++++++++++ Src/Dlhis.Canteen/Dlhis.Canteen.csproj | 2 +- .../Order/Controllers/BalancesController.cs | 2 + .../Services/Implements/BalanceService.cs | 2 +- .../Properties/launchSettings.json | 8 ++ Src/Dlhis.Canteen/SqlSugarPack.cs | 102 +++++++++++++++++ Src/Dlhis.Common/Dlhis.Common.csproj | 2 +- Src/Dlhis.Entity/Dlhis.Entity.csproj | 2 +- .../Controllers/DeviceUploadLogsController.cs | 6 +- .../Implements/DeviceUploadLogService.cs | 3 +- .../Dlhis.ScheduledTask.csproj | 2 +- Src/Dlhis.ScheduledTask/Packs/SqlSugarPack.cs | 104 ++++++++++++++++++ .../Controllers/AssignmentsController.cs | 7 +- .../Services/Implements/AssignmentService.cs | 2 - Src/Dlhis.Sys/Dlhis.Sys.csproj | 2 +- .../Menu/Controllers/MenusController.cs | 1 + .../Menu/Services/Implements/MenuService.cs | 2 +- Src/Dlhis.Sys/SqlSugarPack.cs | 103 +++++++++++++++++ Src/Dlhis.User/Dlhis.User.csproj | 2 +- 36 files changed, 534 insertions(+), 34 deletions(-) create mode 100644 Src/Dlhis.Basic/BusinessShift/Response/MealShiftResponse.cs diff --git a/Src/Dlhis.Basic/BusinessPlace/Controllers/BusinessPlacesController.cs b/Src/Dlhis.Basic/BusinessPlace/Controllers/BusinessPlacesController.cs index 44ada252..815f4e08 100644 --- a/Src/Dlhis.Basic/BusinessPlace/Controllers/BusinessPlacesController.cs +++ b/Src/Dlhis.Basic/BusinessPlace/Controllers/BusinessPlacesController.cs @@ -2,6 +2,7 @@ using Dlhis.Basic.BusinessPlace.Response; using Dlhis.Basic.BusinessPlace.Services; using Dlhis.Basic.BusinessShift.Services; +using Dlhis.Basic.Packs; using Kurisu.Core.DataAccess.Dto; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -75,6 +76,7 @@ public class BusinessPlacesController : ControllerBase /// /// [HttpPost("shifts")] + [IgnoreTenant] public async Task GetShiftsByPlaceCustomCodeHttpPostAsync(BusinessPlaceGetShiftsRequest request) { return await _businessPlaceShiftService.GetShiftsByPlaceCustomCodeAsync(request.CustomCode); @@ -86,6 +88,7 @@ public class BusinessPlacesController : ControllerBase /// /// [HttpGet("shifts")] + [IgnoreTenant] public async Task GetShiftsByPlaceCustomCodeHttpGetAsync([FromQuery] BusinessPlaceGetShiftsRequest request) { return await _businessPlaceShiftService.GetShiftsByPlaceCustomCodeAsync(request.CustomCode); diff --git a/Src/Dlhis.Basic/BusinessPlace/Response/BusinessPlaceResponse.cs b/Src/Dlhis.Basic/BusinessPlace/Response/BusinessPlaceResponse.cs index 9793da56..c954462a 100644 --- a/Src/Dlhis.Basic/BusinessPlace/Response/BusinessPlaceResponse.cs +++ b/Src/Dlhis.Basic/BusinessPlace/Response/BusinessPlaceResponse.cs @@ -35,9 +35,21 @@ public class BusinessPlaceResponse public CanteenBusinessPlaceSourceEnumType Source { get; set; } public string SourceDesc => Source.GetDescription(); + /// /// 分类,超市/餐厅/食堂 /// public CanteenBusinessPlaceCatalogEnumType Catalog { get; set; } public string CatalogDesc => Catalog.GetDescription(); + + + /// + /// 餐次code + /// + public Guid? ShiftCode { get; set; } + + /// + /// 餐次名称 + /// + public string ShiftName { get; set; } } diff --git a/Src/Dlhis.Basic/BusinessPlace/Services/Implements/BusinessPlaceService.cs b/Src/Dlhis.Basic/BusinessPlace/Services/Implements/BusinessPlaceService.cs index 66fe18e8..ace2b8e9 100644 --- a/Src/Dlhis.Basic/BusinessPlace/Services/Implements/BusinessPlaceService.cs +++ b/Src/Dlhis.Basic/BusinessPlace/Services/Implements/BusinessPlaceService.cs @@ -23,11 +23,25 @@ public class BusinessPlaceService : IBusinessPlaceService public async Task> GetPageAsync(BusinessPlacePageRequest request) { var page = await _dbContext.Queryable() + .LeftJoin((x, ps) => x.Code == ps.PlaceCode) + .LeftJoin((x, ps, s) => s.Code == ps.ShiftCode) .WhereIF(request.Search.IsPresent(), x => x.CustomCode.Contains(request.Search)) .WhereIF(request.Catalog.HasValue, x => x.Catalog == request.Catalog) .WhereIF(request.Status.HasValue, x => x.Status == request.Status) .WhereIF(request.Source.HasValue, x => x.Source == request.Source) - .Select() + .Select((x, ps, s) => new BusinessPlaceResponse + { + Id = x.Id, + Code = x.Code, + Status = x.Status, + Name = x.Name, + Catalog = x.Catalog, + CustomCode = x.CustomCode, + Source = x.Source, + + ShiftCode = s.Code, + ShiftName = s.Name + }) .ToPageListAsync(request); return page; @@ -38,8 +52,8 @@ public class BusinessPlaceService : IBusinessPlaceService { return await _dbContext.Queryable() .Where(x => x.Status == CanteenBusinessPlaceStatusEnumType.Opened) - .Select() - .ToListAsync(); + .Select() + .ToListAsync(); } diff --git a/Src/Dlhis.Basic/BusinessShift/Controllers/BusinessShiftsController.cs b/Src/Dlhis.Basic/BusinessShift/Controllers/BusinessShiftsController.cs index b0438262..323bb7bb 100644 --- a/Src/Dlhis.Basic/BusinessShift/Controllers/BusinessShiftsController.cs +++ b/Src/Dlhis.Basic/BusinessShift/Controllers/BusinessShiftsController.cs @@ -1,6 +1,7 @@ using Dlhis.Basic.BusinessShift.Request; using Dlhis.Basic.BusinessShift.Response; using Dlhis.Basic.BusinessShift.Services; +using Dlhis.Basic.Packs; using Kurisu.Core.DataAccess.Dto; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -49,9 +50,9 @@ public class BusinessShiftsController : ControllerBase /// /// [HttpPost("save")] - public async Task SaveAsync(BusinessPlaceShiftSaveRequest request) + public async Task SaveAsync(BusinessPlaceShiftSaveRequest request) { - await _businessPlaceShiftService.SaveAsync(request); + return await _businessPlaceShiftService.SaveAsync(request); } /// @@ -60,6 +61,7 @@ public class BusinessShiftsController : ControllerBase /// /// [HttpPost("meal/save")] + [Transactional] public async Task SaveMealShiftsAsync(List requests) { await _businessPlaceShiftService.SaveMealShiftsAsync(requests); diff --git a/Src/Dlhis.Basic/BusinessShift/Response/BusinessPlaceShiftResponse.cs b/Src/Dlhis.Basic/BusinessShift/Response/BusinessPlaceShiftResponse.cs index f0a9d504..82a3aab3 100644 --- a/Src/Dlhis.Basic/BusinessShift/Response/BusinessPlaceShiftResponse.cs +++ b/Src/Dlhis.Basic/BusinessShift/Response/BusinessPlaceShiftResponse.cs @@ -18,4 +18,9 @@ public class BusinessPlaceShiftResponse /// 餐次名称 /// public string Name { get; set; } + + /// + /// 就餐时间段 + /// + public List MealShifts { get; set; } } diff --git a/Src/Dlhis.Basic/BusinessShift/Response/MealShiftResponse.cs b/Src/Dlhis.Basic/BusinessShift/Response/MealShiftResponse.cs new file mode 100644 index 00000000..04290aff --- /dev/null +++ b/Src/Dlhis.Basic/BusinessShift/Response/MealShiftResponse.cs @@ -0,0 +1,13 @@ +namespace Dlhis.Basic.BusinessShift.Response +{ + public class MealShiftResponse + { + public Guid ShiftCode { get; set; } + + public string Name { get; set; } + + public TimeOnly Start { get; set; } + + public TimeOnly End { get; set; } + } +} diff --git a/Src/Dlhis.Basic/BusinessShift/Services/IBusinessPlaceShiftService.cs b/Src/Dlhis.Basic/BusinessShift/Services/IBusinessPlaceShiftService.cs index 694c7948..1dc289da 100644 --- a/Src/Dlhis.Basic/BusinessShift/Services/IBusinessPlaceShiftService.cs +++ b/Src/Dlhis.Basic/BusinessShift/Services/IBusinessPlaceShiftService.cs @@ -11,7 +11,7 @@ public interface IBusinessPlaceShiftService : IScopeDependency Task> GetListAsync(); - Task SaveAsync(BusinessPlaceShiftSaveRequest request); + Task SaveAsync(BusinessPlaceShiftSaveRequest request); Task SaveMealShiftsAsync(List requests); diff --git a/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs b/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs index aa3f2905..13169a48 100644 --- a/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs +++ b/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs @@ -7,7 +7,6 @@ using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.CustomClass; using Kurisu.Core.DataAccess.Dto; using Kurisu.Core.Result; -using Kurisu.SqlSugar.Attributes; using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Services; using Mapster; @@ -32,6 +31,26 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService .Select() .ToPageListAsync(request); + var shiftCodes = page.Data.Select(x => x.Code).ToList(); + + //下级就餐时间段 + var mealShifts = await _dbContext.Queryable() + .LeftJoin((x, bt) => x.ShiftType == bt.Code) + .Where(x => shiftCodes.Contains(x.ShiftCode)) + .Select((x, bt) => new MealShiftResponse + { + ShiftCode = x.ShiftCode, + Name = bt.Display, + Start = x.Start, + End = x.End, + }) + .ToListAsync(); + + page.Data.ForEach(x => + { + x.MealShifts = mealShifts.Where(item => item.ShiftCode == x.Code).ToList(); + }); + return page; } @@ -43,16 +62,19 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService return result; } - public async Task SaveAsync(BusinessPlaceShiftSaveRequest request) + public async Task SaveAsync(BusinessPlaceShiftSaveRequest request) { await CheckExistsAsync(request); + Guid code = Guid.Empty; if (!request.Id.HasValue) { var entity = request.Adapt(); entity.Code = Guid.NewGuid(); await _dbContext.InsertAsync(entity); + + code = entity.Code; } else { @@ -61,10 +83,13 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService request.Adapt(entity); await _dbContext.UpdateAsync(entity); + + code = entity.Code; } + + return code; } - [Transactional] public async Task SaveMealShiftsAsync(List requests) { var mealShifts = await GetMealShiftAsync(); @@ -98,7 +123,7 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService } } - [IgnoreTenant] + public async Task GetShiftsByPlaceCustomCodeAsync(string placeCustomCode) { var place = await _dbContext.Queryable().Where(x => x.CustomCode == placeCustomCode).FirstAsync(); diff --git a/Src/Dlhis.Basic/Device/Controllers/DeviceGroupsController.cs b/Src/Dlhis.Basic/Device/Controllers/DeviceGroupsController.cs index c05c41ba..29796a25 100644 --- a/Src/Dlhis.Basic/Device/Controllers/DeviceGroupsController.cs +++ b/Src/Dlhis.Basic/Device/Controllers/DeviceGroupsController.cs @@ -1,6 +1,7 @@ using Dlhis.Basic.Device.Request; using Dlhis.Basic.Device.Response; using Dlhis.Basic.Device.Services; +using Dlhis.Basic.Packs; using Dlhis.Entity.Device.Enums; using Kurisu.Core.DataAccess.Dto; using Microsoft.AspNetCore.Authorization; @@ -74,6 +75,7 @@ public class DeviceGroupsController : ControllerBase /// /// [HttpPost("assign")] + [Transactional] public async Task AssignDevicesAsync(DeviceAssignRequest request) { await _deviceGroupService.AssignDevicesAsync(request); diff --git a/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs b/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs index 63a9d64c..14ba9f29 100644 --- a/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs +++ b/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs @@ -1,6 +1,7 @@ using Dlhis.Basic.Device.Request; using Dlhis.Basic.Device.Response; using Dlhis.Basic.Device.Services; +using Dlhis.Basic.Packs; using Kurisu.Core.DataAccess.Dto; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -25,6 +26,7 @@ public class DevicePermissionsController : ControllerBase /// /// [HttpPost("assign")] + [Transactional] public async Task AssignAsync(DevicePermissionSaveReuqest request) { await _devicePermissionService.AssignAsync(request); diff --git a/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs b/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs index accdbbb3..f4bf018d 100644 --- a/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs +++ b/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs @@ -1,7 +1,7 @@ using Dlhis.Basic.Device.Request; using Dlhis.Basic.Device.Response; using Dlhis.Basic.Device.Services; -using Dlhis.Entity.Basic.Entity; +using Dlhis.Basic.Packs; using Kurisu.Core.DataAccess.Dto; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -71,6 +71,7 @@ public class DevicesController : ControllerBase /// /// [HttpPost("save")] + [Transactional] public async Task SaveAsync(DeviceSaveRequest request) { await _deviceService.SaveAsync(request); @@ -82,6 +83,7 @@ public class DevicesController : ControllerBase /// /// [HttpPost("resigter")] + [IgnoreTenant] public async Task ResigterAsync(DeviceResigterRequest request) { return await _deviceConnectService.ResigterAsync(request); @@ -129,6 +131,7 @@ public class DevicesController : ControllerBase /// /// [HttpPost("heartbeat")] + [IgnoreTenant] public async Task HeartbeatAsync(DeviceHeartbeatRequest request) { await _deviceConnectService.HeartbeatAsync(request); @@ -143,6 +146,7 @@ public class DevicesController : ControllerBase { return await _deviceService.CheckExistsAsync(deviceUniqueNo); } + /// /// 获取设备 /// diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceConnectService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceConnectService.cs index 7dee0250..70cb0034 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceConnectService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceConnectService.cs @@ -20,7 +20,7 @@ public class DeviceConnectService : IDeviceConnectService _dbContext = dbContext; } - [IgnoreTenant] + public async Task ResigterAsync(DeviceResigterRequest request) { var businessPlace = await _dbContext.Queryable().Where(x => x.CustomCode == request.BusinessCustomCode).FirstAsync(); @@ -82,7 +82,7 @@ public class DeviceConnectService : IDeviceConnectService //todo 通知设备重新获取 } - [IgnoreTenant] + public async Task HeartbeatAsync(DeviceHeartbeatRequest request) { var registry = await _dbContext.Queryable().Where(x => x.DeviceUniqueNo == request.UniqueNo).FirstAsync(); diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs index a8dfee90..7f1e5345 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs @@ -91,7 +91,6 @@ public class DeviceGroupService : IDeviceGroupService } - [Transactional] public async Task AssignDevicesAsync(DeviceAssignRequest request) { var group = await _dbContext.Queryable().Where(x => x.Code == request.GroupCode).FirstAsync(); diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs index 3aee41b7..4c494bcc 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs @@ -21,7 +21,6 @@ public class DevicePermissionService : IDevicePermissionService _dbContext = dbContext; } - [Transactional] public async Task AssignAsync(DevicePermissionSaveReuqest reuqest) { await GenerateDeviceTasksAsync(async () => diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs index 8a7e9bb3..3db17c09 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs @@ -86,7 +86,6 @@ public class DeviceService : IDeviceService } - [Transactional] public async Task SaveAsync(DeviceSaveRequest request) { await CheckUniqueNoExistsAsync(request); @@ -199,7 +198,7 @@ public class DeviceService : IDeviceService exists.ThrowIfTrue("唯一号已经存在"); } - [IgnoreTenant] + public async Task CheckExistsAsync(string deviceUniqueNo) { return await _dbContext.Queryable() diff --git a/Src/Dlhis.Basic/Dlhis.Basic.csproj b/Src/Dlhis.Basic/Dlhis.Basic.csproj index 1b0c0da7..4ada33a1 100644 --- a/Src/Dlhis.Basic/Dlhis.Basic.csproj +++ b/Src/Dlhis.Basic/Dlhis.Basic.csproj @@ -17,7 +17,7 @@ - + diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs index bfc6e493..d4cbc434 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs @@ -104,7 +104,6 @@ public class GainfoService : IGainfoService /// /// /// - [Transactional] public async Task DimissionAsync(GainfoDimissionRequest request) { var gainfo = await _gainfoStore.Queryable(GainfoStatusEnumType.Working) diff --git a/Src/Dlhis.Basic/Packs/SqlSugarPack.cs b/Src/Dlhis.Basic/Packs/SqlSugarPack.cs index 86dc45aa..a54c45cf 100644 --- a/Src/Dlhis.Basic/Packs/SqlSugarPack.cs +++ b/Src/Dlhis.Basic/Packs/SqlSugarPack.cs @@ -1,6 +1,9 @@ using Kurisu.AspNetCore; using Kurisu.AspNetCore.Startup; +using Kurisu.Core.DataAccess.Entity; using Kurisu.SqlSugar.Extensions; +using Kurisu.SqlSugar.Services; +using Microsoft.AspNetCore.Mvc.Filters; using SqlSugar; namespace Dlhis.Basic.Packs; @@ -33,3 +36,98 @@ public class SqlSugarPack : BaseAppPack //dbFace.CodeFirst.InitTables(); } } + + +/// +/// 日志 +/// +[AttributeUsage(AttributeTargets.Method)] +public class LogAttribute : Attribute, IAsyncActionFilter +{ + public LogAttribute(string title) + { + Title = title; + } + + /// + /// + /// + public string Title { get; set; } + + /// + /// 是否处理差异 + /// + public bool Diff { get; set; } + + + public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) + { + PreSetting(context.HttpContext); + await next(); + } + + private void PreSetting(HttpContext httpContext) + { + var options = httpContext.RequestServices.GetService(); + + options.Title = Title; + options.Diff = Diff; + options.BatchNo = Guid.NewGuid(); + options.RoutePath = httpContext.Request.Path.Value; + options.RaiseTime = DateTime.Now; + } +} + +/// +/// 事务 +/// +[AttributeUsage(AttributeTargets.Method)] +public class TransactionalAttribute : Attribute, IAsyncActionFilter +{ + public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) + { + var dbContext = context.HttpContext.RequestServices.GetRequiredService(); + await dbContext.Ado.BeginTranAsync(); + try + { + var result = await next(); + if (result.Exception != null) + { + throw result.Exception; + } + else + { + await dbContext.Ado.CommitTranAsync(); + } + } + catch (Exception) + { + await dbContext.Ado.RollbackTranAsync(); + throw; + } + } +} + +/// +/// 忽略租户 +/// +[AttributeUsage(AttributeTargets.Method)] +public class IgnoreTenantAttribute : Attribute, IAsyncActionFilter +{ + public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) + { + var dbContext = context.HttpContext.RequestServices.GetRequiredService(); + var options = context.HttpContext!.RequestServices.GetService(); + try + { + dbContext.QueryFilter.ClearAndBackup(); + options.IgnoreTenant = true; + await next(); + } + finally + { + options.IgnoreTenant = false; + dbContext.QueryFilter.Restore(); + } + } +} diff --git a/Src/Dlhis.Canteen/Dlhis.Canteen.csproj b/Src/Dlhis.Canteen/Dlhis.Canteen.csproj index 9e21386c..fe0b5fd0 100644 --- a/Src/Dlhis.Canteen/Dlhis.Canteen.csproj +++ b/Src/Dlhis.Canteen/Dlhis.Canteen.csproj @@ -36,7 +36,7 @@ - + diff --git a/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs b/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs index 3015ff75..e9757cc8 100644 --- a/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs +++ b/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs @@ -39,6 +39,7 @@ public class BalancesController : ControllerBase /// /// [HttpGet("device/page")] + [IgnoreTenant] public async Task> GetPageByDeviceUniqueNoGetAsync([FromQuery] BalanceRecordPageByDeviceUniqueNoRequest request) { return await _balanceService.GetPageByDeviceUniqueNoAsync(request); @@ -50,6 +51,7 @@ public class BalancesController : ControllerBase /// /// [HttpPost("device/page")] + [IgnoreTenant] public async Task> GetPageByDeviceUniqueNoPostAsync(BalanceRecordPageByDeviceUniqueNoRequest request) { return await _balanceService.GetPageByDeviceUniqueNoAsync(request); diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs index 59e76cd1..bde9dda2 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs @@ -407,7 +407,7 @@ public class BalanceService : IBalanceService } - [IgnoreTenant] + public async Task> GetPageByDeviceUniqueNoAsync(BalanceRecordPageByDeviceUniqueNoRequest request) { var now = DateTime.Now; diff --git a/Src/Dlhis.Canteen/Properties/launchSettings.json b/Src/Dlhis.Canteen/Properties/launchSettings.json index 706bb9bb..f13e2beb 100644 --- a/Src/Dlhis.Canteen/Properties/launchSettings.json +++ b/Src/Dlhis.Canteen/Properties/launchSettings.json @@ -7,6 +7,14 @@ }, "dotnetRunMessages": true, "applicationUrl": "http://localhost:5008" + }, + "Docker": { + "commandName": "Docker", + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}", + "environmentVariables": { + "ASPNETCORE_URLS": "http://+:80" + }, + "publishAllPorts": true } }, "$schema": "https://json.schemastore.org/launchsettings.json" diff --git a/Src/Dlhis.Canteen/SqlSugarPack.cs b/Src/Dlhis.Canteen/SqlSugarPack.cs index 3abac33b..f8d3a155 100644 --- a/Src/Dlhis.Canteen/SqlSugarPack.cs +++ b/Src/Dlhis.Canteen/SqlSugarPack.cs @@ -1,5 +1,9 @@ using Kurisu.AspNetCore.Startup; +using Kurisu.Core.DataAccess.Entity; using Kurisu.SqlSugar.Extensions; +using Kurisu.SqlSugar.Services; +using Microsoft.AspNetCore.Mvc.Filters; +using SqlSugar; namespace Dlhis.Canteen; @@ -12,3 +16,101 @@ public class SqlSugarPack : BaseAppPack services.AddSqlSugar(); } } + + + + + +/// +/// 日志 +/// +[AttributeUsage(AttributeTargets.Method)] +public class LogAttribute : Attribute, IAsyncActionFilter +{ + public LogAttribute(string title) + { + Title = title; + } + + /// + /// + /// + public string Title { get; set; } + + /// + /// 是否处理差异 + /// + public bool Diff { get; set; } + + + public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) + { + PreSetting(context.HttpContext); + await next(); + } + + private void PreSetting(HttpContext httpContext) + { + var options = httpContext.RequestServices.GetService(); + + options.Title = Title; + options.Diff = Diff; + options.BatchNo = Guid.NewGuid(); + options.RoutePath = httpContext.Request.Path.Value; + options.RaiseTime = DateTime.Now; + } +} + +/// +/// 事务 +/// +[AttributeUsage(AttributeTargets.Method)] +public class TransactionalAttribute : Attribute, IAsyncActionFilter +{ + public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) + { + var dbContext = context.HttpContext.RequestServices.GetRequiredService(); + await dbContext.Ado.BeginTranAsync(); + try + { + var result = await next(); + if (result.Exception != null) + { + throw result.Exception; + } + else + { + await dbContext.Ado.CommitTranAsync(); + } + } + catch (Exception) + { + await dbContext.Ado.RollbackTranAsync(); + throw; + } + } +} + +/// +/// 忽略租户 +/// +[AttributeUsage(AttributeTargets.Method)] +public class IgnoreTenantAttribute : Attribute, IAsyncActionFilter +{ + public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) + { + var dbContext = context.HttpContext.RequestServices.GetRequiredService(); + var options = context.HttpContext!.RequestServices.GetService(); + try + { + dbContext.QueryFilter.ClearAndBackup(); + options.IgnoreTenant = true; + await next(); + } + finally + { + options.IgnoreTenant = false; + dbContext.QueryFilter.Restore(); + } + } +} diff --git a/Src/Dlhis.Common/Dlhis.Common.csproj b/Src/Dlhis.Common/Dlhis.Common.csproj index 69affc46..3fe68313 100644 --- a/Src/Dlhis.Common/Dlhis.Common.csproj +++ b/Src/Dlhis.Common/Dlhis.Common.csproj @@ -21,7 +21,7 @@ - + diff --git a/Src/Dlhis.Entity/Dlhis.Entity.csproj b/Src/Dlhis.Entity/Dlhis.Entity.csproj index beec1bdc..8245cd0d 100644 --- a/Src/Dlhis.Entity/Dlhis.Entity.csproj +++ b/Src/Dlhis.Entity/Dlhis.Entity.csproj @@ -11,7 +11,7 @@ - + diff --git a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Controllers/DeviceUploadLogsController.cs b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Controllers/DeviceUploadLogsController.cs index 7a487c2d..ad8f44b7 100644 --- a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Controllers/DeviceUploadLogsController.cs +++ b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Controllers/DeviceUploadLogsController.cs @@ -1,7 +1,7 @@ -using Dlhis.Entity.Basic.Entity; -using Dlhis.ScheduledTask.DeviceUploadLog.Request; +using Dlhis.ScheduledTask.DeviceUploadLog.Request; using Dlhis.ScheduledTask.DeviceUploadLog.Response; using Dlhis.ScheduledTask.DeviceUploadLog.Services; +using Dlhis.ScheduledTask.Packs; using Kurisu.Core.DataAccess.Dto; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -40,6 +40,7 @@ public class DeviceUploadLogsController : ControllerBase /// /// [HttpPost("record")] + [IgnoreTenant] public async Task UploadLogAsync(DeviceUploadLogUploadRequest request) { await _deviceUploadLogService.UploadLogAsync(request); @@ -51,6 +52,7 @@ public class DeviceUploadLogsController : ControllerBase /// /// [HttpPost("records")] + [IgnoreTenant] public async Task UploadLogsAsync(List requests) { await _deviceUploadLogService.UploadLogsAsync(requests); diff --git a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs index 0577b046..de3f43fa 100644 --- a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs +++ b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs @@ -46,7 +46,6 @@ public class DeviceUploadLogService : IDeviceUploadLogService return page; } - [IgnoreTenant] public async Task UploadLogAsync(DeviceUploadLogUploadRequest request) { var device = await _dbContext.Queryable().Where(x => x.UniqueNo == request.DeviceUniqueNo).SingleAsync(); @@ -63,7 +62,7 @@ public class DeviceUploadLogService : IDeviceUploadLogService await _dbContext.InsertAsync(entity); } - [IgnoreTenant] + public async Task UploadLogsAsync(List requests) { //判断存在的记录 diff --git a/Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj b/Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj index c87349e5..74406a5b 100644 --- a/Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj +++ b/Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj @@ -20,7 +20,7 @@ - + diff --git a/Src/Dlhis.ScheduledTask/Packs/SqlSugarPack.cs b/Src/Dlhis.ScheduledTask/Packs/SqlSugarPack.cs index 24a3f080..2f562f2b 100644 --- a/Src/Dlhis.ScheduledTask/Packs/SqlSugarPack.cs +++ b/Src/Dlhis.ScheduledTask/Packs/SqlSugarPack.cs @@ -1,5 +1,9 @@ using Kurisu.AspNetCore.Startup; +using Kurisu.Core.DataAccess.Entity; using Kurisu.SqlSugar.Extensions; +using Kurisu.SqlSugar.Services; +using Microsoft.AspNetCore.Mvc.Filters; +using SqlSugar; namespace Dlhis.ScheduledTask.Packs; @@ -12,3 +16,103 @@ public class SqlSugarPack : BaseAppPack services.AddSqlSugar(); } } + + + + + + +/// +/// 日志 +/// +[AttributeUsage(AttributeTargets.Method)] +public class LogAttribute : Attribute, IAsyncActionFilter +{ + public LogAttribute(string title) + { + Title = title; + } + + /// + /// + /// + public string Title { get; set; } + + /// + /// 是否处理差异 + /// + public bool Diff { get; set; } + + + public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) + { + PreSetting(context.HttpContext); + await next(); + } + + private void PreSetting(HttpContext httpContext) + { + var options = httpContext.RequestServices.GetService(); + + options.Title = Title; + options.Diff = Diff; + options.BatchNo = Guid.NewGuid(); + options.RoutePath = httpContext.Request.Path.Value; + options.RaiseTime = DateTime.Now; + } +} + +/// +/// 事务 +/// +[AttributeUsage(AttributeTargets.Method)] +public class TransactionalAttribute : Attribute, IAsyncActionFilter +{ + public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) + { + var dbContext = context.HttpContext.RequestServices.GetRequiredService(); + await dbContext.Ado.BeginTranAsync(); + try + { + var result = await next(); + if (result.Exception != null) + { + throw result.Exception; + } + else + { + await dbContext.Ado.CommitTranAsync(); + } + } + catch (Exception) + { + await dbContext.Ado.RollbackTranAsync(); + throw; + } + } +} + +/// +/// 忽略租户 +/// +[AttributeUsage(AttributeTargets.Method)] +public class IgnoreTenantAttribute : Attribute, IAsyncActionFilter +{ + public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) + { + var dbContext = context.HttpContext.RequestServices.GetRequiredService(); + var options = context.HttpContext!.RequestServices.GetService(); + try + { + dbContext.QueryFilter.ClearAndBackup(); + options.IgnoreTenant = true; + await next(); + } + finally + { + options.IgnoreTenant = false; + dbContext.QueryFilter.Restore(); + } + } +} + diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Controllers/AssignmentsController.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Controllers/AssignmentsController.cs index 80dae44b..fb9b7e2a 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Controllers/AssignmentsController.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Controllers/AssignmentsController.cs @@ -1,4 +1,5 @@ -using Dlhis.ScheduledTask.TaskAssignment.Request; +using Dlhis.ScheduledTask.Packs; +using Dlhis.ScheduledTask.TaskAssignment.Request; using Dlhis.ScheduledTask.TaskAssignment.Response; using Dlhis.ScheduledTask.TaskAssignment.Services; using Microsoft.AspNetCore.Authorization; @@ -25,6 +26,7 @@ public class AssignmentsController : ControllerBase /// 获取设备任务(按设备) /// /// + [IgnoreTenant] [HttpGet("devicetasks")] public async Task> DeviceGetTasksGetAsync([FromQuery] DeviceTaskGetRequest request) { @@ -36,6 +38,7 @@ public class AssignmentsController : ControllerBase /// /// [HttpPost("devicetasks")] + [IgnoreTenant] public async Task> DeviceGetTasksPostAsync(DeviceTaskGetRequest request) { return await _assignmentService.DeviceGetTasksAsync(request); @@ -47,6 +50,7 @@ public class AssignmentsController : ControllerBase /// /// [HttpPost("taskstatus")] + [IgnoreTenant] public async Task UpdateDeviceTaskStatusAsync(List requests) { await _assignmentService.UpdateDeviceTaskStatusAsync(requests); @@ -58,6 +62,7 @@ public class AssignmentsController : ControllerBase /// /// [HttpGet("renewfaceurl")] + [IgnoreTenant] public async Task RenewFaceUrlAsync(long taskId) { return await _assignmentService.RenewFaceUrlAsync(taskId); diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs index 53c70e7d..70c3c029 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs @@ -12,13 +12,11 @@ using Microsoft.AspNetCore.DataProtection; using Microsoft.Extensions.Options; using SqlSugar; using Kurisu.SqlSugar.Extensions; -using Kurisu.SqlSugar.Attributes; using Newtonsoft.Json.Linq; using Kurisu.Core.CustomClass; namespace Dlhis.ScheduledTask.TaskAssignment.Services.Implements; -[IgnoreTenant] public class AssignmentService : IAssignmentService { private readonly IDbContext _dbContext; diff --git a/Src/Dlhis.Sys/Dlhis.Sys.csproj b/Src/Dlhis.Sys/Dlhis.Sys.csproj index fe92dc2c..2d7b45d8 100644 --- a/Src/Dlhis.Sys/Dlhis.Sys.csproj +++ b/Src/Dlhis.Sys/Dlhis.Sys.csproj @@ -17,7 +17,7 @@ - + diff --git a/Src/Dlhis.Sys/Menu/Controllers/MenusController.cs b/Src/Dlhis.Sys/Menu/Controllers/MenusController.cs index 006fb4f1..97808ff2 100644 --- a/Src/Dlhis.Sys/Menu/Controllers/MenusController.cs +++ b/Src/Dlhis.Sys/Menu/Controllers/MenusController.cs @@ -40,6 +40,7 @@ public class MenusController : ControllerBase /// /// [HttpPost] + [Transactional] public async Task Save(SaveMenuRequest request) { await _menuService.SaveMenuAsync(request); diff --git a/Src/Dlhis.Sys/Menu/Services/Implements/MenuService.cs b/Src/Dlhis.Sys/Menu/Services/Implements/MenuService.cs index b6c8601d..9fd30309 100644 --- a/Src/Dlhis.Sys/Menu/Services/Implements/MenuService.cs +++ b/Src/Dlhis.Sys/Menu/Services/Implements/MenuService.cs @@ -41,7 +41,7 @@ public class MenuService : IMenuService return top; } - [Transactional] + public async Task SaveMenuAsync(SaveMenuRequest request) { await CheckAsync(request); diff --git a/Src/Dlhis.Sys/SqlSugarPack.cs b/Src/Dlhis.Sys/SqlSugarPack.cs index 26d783d6..59e2db32 100644 --- a/Src/Dlhis.Sys/SqlSugarPack.cs +++ b/Src/Dlhis.Sys/SqlSugarPack.cs @@ -1,5 +1,9 @@ using Kurisu.AspNetCore.Startup; +using Kurisu.Core.DataAccess.Entity; using Kurisu.SqlSugar.Extensions; +using Kurisu.SqlSugar.Services; +using Microsoft.AspNetCore.Mvc.Filters; +using SqlSugar; namespace Dlhis.Sys; @@ -12,3 +16,102 @@ public class SqlSugarPack : BaseAppPack services.AddSqlSugar(); } } + + + + +/// +/// 日志 +/// +[AttributeUsage(AttributeTargets.Method)] +public class LogAttribute : Attribute, IAsyncActionFilter +{ + public LogAttribute(string title) + { + Title = title; + } + + /// + /// + /// + public string Title { get; set; } + + /// + /// 是否处理差异 + /// + public bool Diff { get; set; } + + + public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) + { + PreSetting(context.HttpContext); + await next(); + } + + private void PreSetting(HttpContext httpContext) + { + var options = httpContext.RequestServices.GetService(); + + options.Title = Title; + options.Diff = Diff; + options.BatchNo = Guid.NewGuid(); + options.RoutePath = httpContext.Request.Path.Value; + options.RaiseTime = DateTime.Now; + } +} + +/// +/// 事务 +/// +[AttributeUsage(AttributeTargets.Method)] +public class TransactionalAttribute : Attribute, IAsyncActionFilter +{ + public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) + { + var dbContext = context.HttpContext.RequestServices.GetRequiredService(); + await dbContext.Ado.BeginTranAsync(); + try + { + var result = await next(); + if (result.Exception != null) + { + throw result.Exception; + } + else + { + await dbContext.Ado.CommitTranAsync(); + } + } + catch (Exception) + { + await dbContext.Ado.RollbackTranAsync(); + throw; + } + } +} + +/// +/// 忽略租户 +/// +[AttributeUsage(AttributeTargets.Method)] +public class IgnoreTenantAttribute : Attribute, IAsyncActionFilter +{ + public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) + { + var dbContext = context.HttpContext.RequestServices.GetRequiredService(); + var options = context.HttpContext!.RequestServices.GetService(); + try + { + dbContext.QueryFilter.ClearAndBackup(); + options.IgnoreTenant = true; + await next(); + } + finally + { + options.IgnoreTenant = false; + dbContext.QueryFilter.Restore(); + } + } +} + + diff --git a/Src/Dlhis.User/Dlhis.User.csproj b/Src/Dlhis.User/Dlhis.User.csproj index 78c08d85..97629934 100644 --- a/Src/Dlhis.User/Dlhis.User.csproj +++ b/Src/Dlhis.User/Dlhis.User.csproj @@ -17,7 +17,7 @@ - + From e04954f4718a722d223344925b5f58c44ff27011 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Fri, 23 Feb 2024 16:59:53 +0800 Subject: [PATCH 038/146] =?UTF-8?q?feat=20=E7=A7=9F=E6=88=B7=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DeviceSetResigterBusinessPlaceRequest.cs | 2 +- .../Implements/DeviceConnectService.cs | 33 ++++++++++--------- .../Device/Enums/DeviceFuncEnumType.cs | 27 +-------------- .../Identity/Controllers/TenantsController.cs | 11 +++++++ .../Identity/Request/TenantSaveRequest.cs | 20 +++++++++++ .../Identity/Services/ITenantService.cs | 2 ++ .../Services/Implements/TenantService.cs | 23 +++++++++++++ 7 files changed, 76 insertions(+), 42 deletions(-) create mode 100644 Src/Dlhis.Sys/Identity/Request/TenantSaveRequest.cs diff --git a/Src/Dlhis.Basic/Device/Request/DeviceSetResigterBusinessPlaceRequest.cs b/Src/Dlhis.Basic/Device/Request/DeviceSetResigterBusinessPlaceRequest.cs index ef87f679..fb750ea1 100644 --- a/Src/Dlhis.Basic/Device/Request/DeviceSetResigterBusinessPlaceRequest.cs +++ b/Src/Dlhis.Basic/Device/Request/DeviceSetResigterBusinessPlaceRequest.cs @@ -10,6 +10,6 @@ /// /// 营业点 /// - public Guid BusinessPlaceCode { get; set; } + public Guid? BusinessPlaceCode { get; set; } } } diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceConnectService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceConnectService.cs index 70cb0034..810c377d 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceConnectService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceConnectService.cs @@ -3,9 +3,7 @@ using Dlhis.Basic.Device.Response; using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Device.Entities; using Dlhis.Entity.Device.Enums; -using Kurisu.AspNetCore.UnifyResultAndValidation; using Kurisu.AspNetCore.Utils.Extensions; -using Kurisu.SqlSugar.Attributes; using Kurisu.SqlSugar.Services; using Mapster; @@ -20,7 +18,7 @@ public class DeviceConnectService : IDeviceConnectService _dbContext = dbContext; } - + public async Task ResigterAsync(DeviceResigterRequest request) { var businessPlace = await _dbContext.Queryable().Where(x => x.CustomCode == request.BusinessCustomCode).FirstAsync(); @@ -55,7 +53,7 @@ public class DeviceConnectService : IDeviceConnectService public async Task> GetNotSetBusinessPlaceDevicesAsync() { var devices = await _dbContext.Queryable().Where(x => x.Enable).ToListAsync(); - devices = devices.Where(x => x.Funcs.Any(item => item == DeviceFuncEnumType.Meal)).ToList(); + devices = devices.Where(x => x.Type == DeviceTypeEnumType.Meal).ToList(); return devices.Adapt>(); } @@ -63,26 +61,31 @@ public class DeviceConnectService : IDeviceConnectService public async Task SetResigterBusinessPlaceAsync(DeviceSetResigterBusinessPlaceRequest request) { var device = await GetEnableDeviceAsync(request.UniqueNo); - if (device.Funcs?.Any(x => x == DeviceFuncEnumType.Meal) != true) - { - throw new UserFriendlyException("当前设备无用餐功能,无法设置"); - } + (device.Type != DeviceTypeEnumType.Meal).ThrowIfTrue("非就餐类型设备,无法设置"); var registry = await _dbContext.Queryable().Where(x => x.DeviceUniqueNo == request.UniqueNo).FirstAsync(); registry.ThrowIfNull($"{request.UniqueNo}的设备注册信息不存在,无法设置营业点"); - var businessPlace = await _dbContext.Queryable().Where(x => x.Code == request.BusinessPlaceCode).FirstAsync(); - businessPlace.ThrowIfNull("营业点不存在,无法设置到设备注册信息中"); + if (request.BusinessPlaceCode.HasValue) + { + var businessPlace = await _dbContext.Queryable().Where(x => x.Code == request.BusinessPlaceCode).FirstAsync(); + businessPlace.ThrowIfNull("营业点不存在,无法设置到设备注册信息中"); - //更新营业点信息 - registry.BusinessPlaceCode = businessPlace.Code; - registry.BusinessPlaceCustomCode = businessPlace.CustomCode; + //更新营业点信息 + registry.BusinessPlaceCode = businessPlace.Code; + registry.BusinessPlaceCustomCode = businessPlace.CustomCode; + } + else + { + //更新营业点信息 + registry.BusinessPlaceCode = null; + registry.BusinessPlaceCustomCode = null; + } await _dbContext.UpdateAsync(registry); - //todo 通知设备重新获取 } - + public async Task HeartbeatAsync(DeviceHeartbeatRequest request) { var registry = await _dbContext.Queryable().Where(x => x.DeviceUniqueNo == request.UniqueNo).FirstAsync(); diff --git a/Src/Dlhis.Entity/Device/Enums/DeviceFuncEnumType.cs b/Src/Dlhis.Entity/Device/Enums/DeviceFuncEnumType.cs index d8985ae7..b60112f4 100644 --- a/Src/Dlhis.Entity/Device/Enums/DeviceFuncEnumType.cs +++ b/Src/Dlhis.Entity/Device/Enums/DeviceFuncEnumType.cs @@ -8,23 +8,11 @@ namespace Dlhis.Entity.Device.Enums; [Description("设备功能")] public enum DeviceFuncEnumType { - /// - /// 门禁 - /// - [Description("门禁")] - Door = 1, - - /// - /// 就餐 - /// - [Description("就餐")] - Meal, - /// /// 人脸 /// [Description("人脸")] - Face, + Face = 1, /// /// 刷卡 @@ -38,22 +26,9 @@ public enum DeviceFuncEnumType [Description("二维码")] QrCode, - /// /// 布控 /// [Description("布控")] Control, - - /// - /// 考勤 - /// - [Description("考勤")] - Attendance, - - /// - /// 计划 - /// - [Description("计划")] - Schedule } diff --git a/Src/Dlhis.Sys/Identity/Controllers/TenantsController.cs b/Src/Dlhis.Sys/Identity/Controllers/TenantsController.cs index 1a0a605d..f34fb7ab 100644 --- a/Src/Dlhis.Sys/Identity/Controllers/TenantsController.cs +++ b/Src/Dlhis.Sys/Identity/Controllers/TenantsController.cs @@ -61,6 +61,17 @@ public class TenantsController : ControllerBase return await _tenantService.GetTenantByCode(code); } + /// + /// 保存租户 + /// + /// + /// + [HttpPost("save")] + public async Task SaveTenantAsync(TenantSaveRequest request) + { + await _tenantService.SaveTenantAsync(request); + } + /// /// 获取我的管理租户 /// diff --git a/Src/Dlhis.Sys/Identity/Request/TenantSaveRequest.cs b/Src/Dlhis.Sys/Identity/Request/TenantSaveRequest.cs new file mode 100644 index 00000000..a065d331 --- /dev/null +++ b/Src/Dlhis.Sys/Identity/Request/TenantSaveRequest.cs @@ -0,0 +1,20 @@ +using System.ComponentModel.DataAnnotations; + +namespace Dlhis.Sys.Identity.Request; + +public class TenantSaveRequest +{ + public int? Id { get; set; } + + /// + /// 代码 + /// + [Required(ErrorMessage = "基地/租户代码不能为空")] + public string Code { get; set; } + + /// + /// 名称 + /// + [Required(ErrorMessage = "基地/租户名称不能为空")] + public string Name { get; set; } +} diff --git a/Src/Dlhis.Sys/Identity/Services/ITenantService.cs b/Src/Dlhis.Sys/Identity/Services/ITenantService.cs index c8a144fb..4c58ad63 100644 --- a/Src/Dlhis.Sys/Identity/Services/ITenantService.cs +++ b/Src/Dlhis.Sys/Identity/Services/ITenantService.cs @@ -13,4 +13,6 @@ public interface ITenantService : IScopeDependency Task GetTenantByCode(string code); Task> GetMyTenantsAsync(); + + Task SaveTenantAsync(TenantSaveRequest request); } diff --git a/Src/Dlhis.Sys/Identity/Services/Implements/TenantService.cs b/Src/Dlhis.Sys/Identity/Services/Implements/TenantService.cs index 441bd744..7dfbbff8 100644 --- a/Src/Dlhis.Sys/Identity/Services/Implements/TenantService.cs +++ b/Src/Dlhis.Sys/Identity/Services/Implements/TenantService.cs @@ -45,6 +45,29 @@ public class TenantService : ITenantService .FirstAsync(); } + + public async Task SaveTenantAsync(TenantSaveRequest request) + { + if (!request.Id.HasValue) + { + await _dbContext.InsertAsync(new TenantEntity + { + Code = request.Code, + Name = request.Name, + }); + } + else + { + var entity = await _dbContext.Queryable().FirstAsync(x => x.Id == request.Id); + entity.ThrowIfNull("基地/租户信息不存在"); + + entity.Code = request.Code; + entity.Name = request.Name; + + await _dbContext.UpdateAsync(entity); + } + } + public async Task> GetMyTenantsAsync() { var userId = _currentUser.GetIntSubjectId(); From 9b8acdb47720b95bcf02b79dbc59030fde6d8f02 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Fri, 23 Feb 2024 17:04:33 +0800 Subject: [PATCH 039/146] =?UTF-8?q?fix=20=E6=9E=9A=E4=B8=BE=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Basic/Device/Response/DeviceResponse.cs | 3 +++ Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Src/Dlhis.Basic/Device/Response/DeviceResponse.cs b/Src/Dlhis.Basic/Device/Response/DeviceResponse.cs index d28b8650..642a250a 100644 --- a/Src/Dlhis.Basic/Device/Response/DeviceResponse.cs +++ b/Src/Dlhis.Basic/Device/Response/DeviceResponse.cs @@ -88,6 +88,9 @@ public class DeviceResponse } } + public DeviceTypeEnumType Type { get; set; } + public string TypeDesc => Type.GetDescription(); + /// /// 连接信息 /// diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs index 3db17c09..aeafde5a 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs @@ -236,7 +236,7 @@ public class DeviceService : IDeviceService }, true) .ToListAsync(); - return devices.Where(x => x.Funcs.Contains(DeviceFuncEnumType.Attendance)).ToList(); + return devices.Where(x => x.Type == DeviceTypeEnumType.Attendance).ToList(); } public async Task GetDeviceNumberAsync() From 0931d0bf531310802b189d01f740cfa0e9bd265b Mon Sep 17 00:00:00 2001 From: liguoyang Date: Fri, 23 Feb 2024 17:43:57 +0800 Subject: [PATCH 040/146] =?UTF-8?q?fix=20=E4=BC=98=E5=8C=96=E8=8E=B7?= =?UTF-8?q?=E5=8F=96face=E9=80=9F=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Response/MealShiftResponse.cs | 2 ++ .../Implements/BusinessPlaceShiftService.cs | 1 + .../Services/Implements/DeviceService.cs | 1 - .../Services/Implements/GainfoService.cs | 19 +++++++++-- Src/Dlhis.Basic/Packs/DataProtectionJob.cs | 19 +++++++++++ Src/Dlhis.Basic/Program.cs | 10 ++---- Src/Dlhis.Basic/appsettings.json | 3 ++ .../Order/Controllers/BalancesController.cs | 1 + .../Order/Controllers/OrdersController.cs | 1 + .../Services/Implements/BalanceService.cs | 3 -- .../Order/Services/Implements/OrderService.cs | 33 ++++--------------- .../Properties/launchSettings.json | 8 ----- .../Packs/DataProtectionJob.cs | 19 +++++++++++ Src/Dlhis.ScheduledTask/Program.cs | 12 ++----- Src/Dlhis.ScheduledTask/appsettings.json | 3 ++ 15 files changed, 76 insertions(+), 59 deletions(-) create mode 100644 Src/Dlhis.Basic/Packs/DataProtectionJob.cs create mode 100644 Src/Dlhis.ScheduledTask/Packs/DataProtectionJob.cs diff --git a/Src/Dlhis.Basic/BusinessShift/Response/MealShiftResponse.cs b/Src/Dlhis.Basic/BusinessShift/Response/MealShiftResponse.cs index 04290aff..be466ccc 100644 --- a/Src/Dlhis.Basic/BusinessShift/Response/MealShiftResponse.cs +++ b/Src/Dlhis.Basic/BusinessShift/Response/MealShiftResponse.cs @@ -4,6 +4,8 @@ { public Guid ShiftCode { get; set; } + public string ShiftType { get; set; } + public string Name { get; set; } public TimeOnly Start { get; set; } diff --git a/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs b/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs index 13169a48..69b4a0dd 100644 --- a/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs +++ b/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs @@ -40,6 +40,7 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService .Select((x, bt) => new MealShiftResponse { ShiftCode = x.ShiftCode, + ShiftType = bt.Code, Name = bt.Display, Start = x.Start, End = x.End, diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs index aeafde5a..474d1343 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs @@ -9,7 +9,6 @@ using Kurisu.AspNetCore.Scope; using Kurisu.AspNetCore.UnifyResultAndValidation; using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.DataAccess.Dto; -using Kurisu.SqlSugar.Attributes; using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Services; using Mapster; diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs index d4cbc434..61a8dc16 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs @@ -6,10 +6,10 @@ using Dlhis.Entity.Basic.Enums; using Dlhis.Entity.Device.Enums; using Kurisu.AspNetCore.Scope; using Kurisu.AspNetCore.UnifyResultAndValidation; +using Kurisu.AspNetCore.Utils; using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.DataAccess.Dto; using Kurisu.Core.User.Abstractions; -using Kurisu.SqlSugar.Attributes; using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Options; using Kurisu.SqlSugar.Services; @@ -26,18 +26,21 @@ public class GainfoService : IGainfoService private readonly IDbContext _dbContext; private readonly ICurrentUser _currentUser; private readonly IDevicePermissionService _devicePermissionService; + private readonly RedisCache _redisCache; private readonly ILogger _logger; public GainfoService(IGainfoStore gainfoStore, IDbContext dbContext, ICurrentUser currentUser, IDevicePermissionService devicePermissionService, + RedisCache redisCache, ILogger logger) { _gainfoStore = gainfoStore; _dbContext = dbContext; _currentUser = currentUser; _devicePermissionService = devicePermissionService; + _redisCache = redisCache; _logger = logger; } @@ -176,6 +179,12 @@ public class GainfoService : IGainfoService var password = timeLimitedDataProtector.Unprotect(token); var userCode = password.Split(':')[1]; + var faceCache = await _redisCache.HashGetAsync("faces", userCode); + if (faceCache.HasValue) + { + return new FileContentResult(Convert.FromBase64String(faceCache), "image/png"); + } + var configuration = sp.GetService(); var faceConnectionString = configuration.GetSection("SqlSugarOptions:FaceConnectionString").Value; if (faceConnectionString.IsEmpty()) @@ -195,6 +204,8 @@ public class GainfoService : IGainfoService return new NotFoundResult(); } + var limit = configuration.GetSection("FaceUrlOptions:Limit").Get(); + await _redisCache.HashSetAsync("faces", userCode, face.Face); return new FileContentResult(Convert.FromBase64String(face.Face), "image/png"); } catch (Exception ex) @@ -227,6 +238,8 @@ public class GainfoService : IGainfoService var face = await dbContext.Queryable().Where(x => x.UserCode == gainfo.Code).SingleAsync(); var taskType = face == null ? DeviceTaskEnumType.Add : DeviceTaskEnumType.Update; + + await _redisCache.HashSetAsync("faces", gainfo.Code, request.Face); if (face == null) { face = new GainfoFaceEntity @@ -274,6 +287,8 @@ public class GainfoService : IGainfoService var face = await dbContext.Queryable().Where(x => x.UserCode == gainfo.Code).SingleAsync(); var taskType = face == null ? DeviceTaskEnumType.Add : DeviceTaskEnumType.Update; + + await _redisCache.HashSetAsync("faces", gainfo.Code, request.Face); if (face == null) { face = new GainfoFaceEntity @@ -302,8 +317,6 @@ public class GainfoService : IGainfoService } } - - public async Task GetFaceByUserCodeAsync(string userCode) { var gainfo = await _dbContext.Queryable().Where(x => x.Code == userCode).SingleAsync(); diff --git a/Src/Dlhis.Basic/Packs/DataProtectionJob.cs b/Src/Dlhis.Basic/Packs/DataProtectionJob.cs new file mode 100644 index 00000000..0e78ff97 --- /dev/null +++ b/Src/Dlhis.Basic/Packs/DataProtectionJob.cs @@ -0,0 +1,19 @@ +using Kurisu.AspNetCore.Startup; +using Kurisu.AspNetCore.Utils; +using Microsoft.AspNetCore.DataProtection; +using StackExchange.Redis; + +namespace Dlhis.Basic.Packs; + +public class DataProtectionJobPack : BaseAppPack +{ + public override bool IsBeforeUseRouting { get; } + + public override void ConfigureServices(IServiceCollection services) + { + var redisConnection = ConnectionMultiplexer.Connect(Configuration.GetSection($"{nameof(RedisOptions)}:{nameof(RedisOptions.ConnectionString)}").Value); + services.AddDataProtection() + .SetApplicationName("basic") + .PersistKeysToStackExchangeRedis(redisConnection, "DataProtection-Keys"); + } +} diff --git a/Src/Dlhis.Basic/Program.cs b/Src/Dlhis.Basic/Program.cs index 966be9f0..953eea17 100644 --- a/Src/Dlhis.Basic/Program.cs +++ b/Src/Dlhis.Basic/Program.cs @@ -1,8 +1,7 @@ using Kurisu.AspNetCore.Startup; +using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Startup; -using Microsoft.AspNetCore.DataProtection; using Microsoft.IdentityModel.Logging; -using StackExchange.Redis; class Program { @@ -22,11 +21,6 @@ public class Startup : DefaultStartup public override void ConfigureServices(IServiceCollection services) { base.ConfigureServices(services); - - //todo - var redis = ConnectionMultiplexer.Connect($"192.168.199.30:30115,defaultDatabase:1,password=dlhis123"); - services.AddDataProtection() - .SetApplicationName("basic") - .PersistKeysToStackExchangeRedis(redis, "DataProtection-Keys"); + services.AddRedis(); } } \ No newline at end of file diff --git a/Src/Dlhis.Basic/appsettings.json b/Src/Dlhis.Basic/appsettings.json index f40f7fef..307752e9 100644 --- a/Src/Dlhis.Basic/appsettings.json +++ b/Src/Dlhis.Basic/appsettings.json @@ -34,6 +34,9 @@ "yikatong": "yikatong" } }, + "RedisOptions": { + "ConnectionString": "192.168.199.30:30115,defaultDatabase:1,password=dlhis123" + }, "IdentityServerOptions": { "Authority": "http://identity.oauth.svc.cluster.local", "RequireHttpsMetadata": false, diff --git a/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs b/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs index e9757cc8..f75a4927 100644 --- a/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs +++ b/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs @@ -74,6 +74,7 @@ public class BalancesController : ControllerBase /// /// [HttpPost("obsoluteOutRecord")] + [Transactional] public async Task ObsoluteAsync(BalanceRecordObsoluteRequest request) { await _balanceService.ObsoluteAsync(request); diff --git a/Src/Dlhis.Canteen/Order/Controllers/OrdersController.cs b/Src/Dlhis.Canteen/Order/Controllers/OrdersController.cs index 86e9a5c6..da3d8d38 100644 --- a/Src/Dlhis.Canteen/Order/Controllers/OrdersController.cs +++ b/Src/Dlhis.Canteen/Order/Controllers/OrdersController.cs @@ -39,6 +39,7 @@ public class OrdersController : ControllerBase /// /// [HttpPost] + [IgnoreTenant] public async Task AddAsync(OrderAddRequest request) { return await _orderService.AddAsync(request); diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs index bde9dda2..c6f5104a 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs @@ -516,7 +516,6 @@ public class BalanceService : IBalanceService return page; } - [Transactional] public async Task ObsoluteAsync(BalanceRecordObsoluteRequest request) { var balanceRecord = await _dbContext.Queryable().Where(x => x.Id == request.Id).SingleAsync(); @@ -731,10 +730,8 @@ public class BalanceService : IBalanceService throw new UserFriendlyException("操作失败,请重试"); } - [IgnoreTenant] public async Task> GetShiftCode() { - _dbContext.Client.QueryFilter.ClearAndBackup(); try { diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs index c16de272..0ecfee6e 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs @@ -11,7 +11,6 @@ using Kurisu.AspNetCore.Utils; using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.CustomClass; using Kurisu.Core.DataAccess.Dto; -using Kurisu.SqlSugar.Attributes; using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Services; using Mapster; @@ -54,35 +53,15 @@ public class OrderService : IOrderService uniqueNos.Contains(deviceUniqueNo).ThrowIfFalse("无消费权限"); } - [IgnoreTenant] public async Task AddAsync(OrderAddRequest request) { - var card = string.Empty; - long userId = 0; - if (request.Source == BalanceRecordSourceEnumType.Card) - { - card = request.UserUniqueNo; - } - else - { - _ = long.TryParse(request.UserUniqueNo, out userId); - } + //尝试匹配userId + _ = long.TryParse(request.UserUniqueNo, out var userId); + + //根据档案号 var gainfo = await _dbContext.Queryable() - .Where(x => x.No == request.UserUniqueNo || x.Code == request.UserUniqueNo || x.Id == userId || x.CardNo == card) - .FirstAsync(); - - - // .... - { - ////尝试匹配userId - //_ = long.TryParse(request.UserUniqueNo, out var userId); - - ////根据档案号 - //var gainfo = await _dbContext.Queryable() - // .Where(x => x.No == request.UserUniqueNo || x.Code == request.UserUniqueNo || x.Id == userId) - // .FirstAsync(); - } - + .Where(x => x.No == request.UserUniqueNo || x.Code == request.UserUniqueNo || x.Id == userId || x.CardNo == request.UserUniqueNo) + .FirstAsync(); gainfo.ThrowIfNull($"用户{request.UserUniqueNo}不存在,无法操作"); diff --git a/Src/Dlhis.Canteen/Properties/launchSettings.json b/Src/Dlhis.Canteen/Properties/launchSettings.json index f13e2beb..706bb9bb 100644 --- a/Src/Dlhis.Canteen/Properties/launchSettings.json +++ b/Src/Dlhis.Canteen/Properties/launchSettings.json @@ -7,14 +7,6 @@ }, "dotnetRunMessages": true, "applicationUrl": "http://localhost:5008" - }, - "Docker": { - "commandName": "Docker", - "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}", - "environmentVariables": { - "ASPNETCORE_URLS": "http://+:80" - }, - "publishAllPorts": true } }, "$schema": "https://json.schemastore.org/launchsettings.json" diff --git a/Src/Dlhis.ScheduledTask/Packs/DataProtectionJob.cs b/Src/Dlhis.ScheduledTask/Packs/DataProtectionJob.cs new file mode 100644 index 00000000..03d87356 --- /dev/null +++ b/Src/Dlhis.ScheduledTask/Packs/DataProtectionJob.cs @@ -0,0 +1,19 @@ +using Kurisu.AspNetCore.Startup; +using Kurisu.AspNetCore.Utils; +using Microsoft.AspNetCore.DataProtection; +using StackExchange.Redis; + +namespace Dlhis.ScheduledTask.Packs; + +public class DataProtectionJobPack : BaseAppPack +{ + public override bool IsBeforeUseRouting { get; } + + public override void ConfigureServices(IServiceCollection services) + { + var redisConnection = ConnectionMultiplexer.Connect(Configuration.GetSection($"{nameof(RedisOptions)}:{nameof(RedisOptions.ConnectionString)}").Value); + services.AddDataProtection() + .SetApplicationName("scheduled") + .PersistKeysToStackExchangeRedis(redisConnection, "DataProtection-Keys"); + } +} diff --git a/Src/Dlhis.ScheduledTask/Program.cs b/Src/Dlhis.ScheduledTask/Program.cs index aad2b382..4c81132c 100644 --- a/Src/Dlhis.ScheduledTask/Program.cs +++ b/Src/Dlhis.ScheduledTask/Program.cs @@ -1,10 +1,8 @@ -using System.Net.NetworkInformation; using Kurisu.AspNetCore.Startup; +using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Startup; using Microsoft.AspNetCore.DataProtection; -using Microsoft.Extensions.Options; using StackExchange.Redis; -using static StackExchange.Redis.Role; class Program { @@ -23,16 +21,12 @@ public class Startup : DefaultStartup public override void ConfigureServices(IServiceCollection services) { base.ConfigureServices(services); - - services.AddSingleton(sp => - { - return ConnectionMultiplexer.Connect("192.168.199.30:30115,defaultDatabase:1,password=dlhis123"); - }); + services.AddRedis(); //todo var redis = ConnectionMultiplexer.Connect($"192.168.199.30:30115,defaultDatabase:1,password=dlhis123"); services.AddDataProtection() - .SetApplicationName("basic") + .SetApplicationName("scheduled") .PersistKeysToStackExchangeRedis(redis, "DataProtection-Keys"); } } \ No newline at end of file diff --git a/Src/Dlhis.ScheduledTask/appsettings.json b/Src/Dlhis.ScheduledTask/appsettings.json index 28bddadf..8c70547a 100644 --- a/Src/Dlhis.ScheduledTask/appsettings.json +++ b/Src/Dlhis.ScheduledTask/appsettings.json @@ -54,6 +54,9 @@ "AttendanceUploadInterval": "30", "BeginSyncDate": "2020-5-1" }, + "RedisOptions": { + "ConnectionString": "192.168.199.30:30115,defaultDatabase:1,password=dlhis123" + }, "AllowedHosts": "*", "Serilog": { "MinimumLevel": { From bc812a30b9f3a7c3b5019838c9b7ab24b4b6a7e7 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Fri, 23 Feb 2024 18:07:03 +0800 Subject: [PATCH 041/146] =?UTF-8?q?fix=20=E4=B8=B4=E6=97=B6=E5=A4=84?= =?UTF-8?q?=E7=90=86bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessShift/Response/BusinessPlaceShiftTinyResponse.cs | 5 +++++ .../Services/Implements/BusinessPlaceShiftService.cs | 3 +++ .../Organization/Services/Implements/GainfoService.cs | 1 - Src/Dlhis.Basic/appsettings.Development.json | 4 ++++ Src/Dlhis.Basic/appsettings.json | 2 +- 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Src/Dlhis.Basic/BusinessShift/Response/BusinessPlaceShiftTinyResponse.cs b/Src/Dlhis.Basic/BusinessShift/Response/BusinessPlaceShiftTinyResponse.cs index 1e01e9db..908425b3 100644 --- a/Src/Dlhis.Basic/BusinessShift/Response/BusinessPlaceShiftTinyResponse.cs +++ b/Src/Dlhis.Basic/BusinessShift/Response/BusinessPlaceShiftTinyResponse.cs @@ -2,6 +2,11 @@ public class BusinessPlaceShiftTinyResponse { + /// + /// 无用字段,暂时不删除 //todo + /// + public string CustomCode { get; set; } + /// /// 餐次名称 /// diff --git a/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs b/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs index 69b4a0dd..b0df1e36 100644 --- a/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs +++ b/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs @@ -159,6 +159,7 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService .ToListAsync(); var list = new List(); + foreach (BusinessShiftMealRelationshipEntity shiftinfo in shifts) { var name = _dbContext.Queryable() @@ -168,10 +169,12 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService var shift = new BusinessPlaceShiftTinyResponse { + CustomCode = shiftinfo.Id.ToString(), Name = name, Start = shiftinfo.Start, End = shiftinfo.End }; + list.Add(shift); } return new BusinessPlaceWithShiftResponse diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs index 61a8dc16..42e5dd4a 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs @@ -204,7 +204,6 @@ public class GainfoService : IGainfoService return new NotFoundResult(); } - var limit = configuration.GetSection("FaceUrlOptions:Limit").Get(); await _redisCache.HashSetAsync("faces", userCode, face.Face); return new FileContentResult(Convert.FromBase64String(face.Face), "image/png"); } diff --git a/Src/Dlhis.Basic/appsettings.Development.json b/Src/Dlhis.Basic/appsettings.Development.json index ae653872..7b943fd9 100644 --- a/Src/Dlhis.Basic/appsettings.Development.json +++ b/Src/Dlhis.Basic/appsettings.Development.json @@ -9,6 +9,10 @@ "CommonRequestUrl": "http://localhost:5001", "SysRequestUrl": "http://localhost:5003" }, + "FaceUrlOptions": { + "Url": "http://localhost:5002/api/gainfos/face?token=", + "Limit": 7200 + }, "SwaggerOptions": { "Enable": true, "Authority": "https://yikatong.isawesome.cn/oauth2", diff --git a/Src/Dlhis.Basic/appsettings.json b/Src/Dlhis.Basic/appsettings.json index 307752e9..6e58507c 100644 --- a/Src/Dlhis.Basic/appsettings.json +++ b/Src/Dlhis.Basic/appsettings.json @@ -11,7 +11,7 @@ "SysRequestUrl": "http://sys" }, "FaceUrlOptions": { - "Url": "https://face.jinkosolar.com/api/basic/gainfos/face?token=", + "Url": "https://yikatong.isawesome.cn/api/basic/gainfos/face?token=", "Limit": 7200 }, "SqlSugarOptions": { From 0e156159b1ab23a3d90e41c15a1ab05fb510c99c Mon Sep 17 00:00:00 2001 From: liguoyang Date: Fri, 23 Feb 2024 18:14:15 +0800 Subject: [PATCH 042/146] =?UTF-8?q?fix=20=E5=90=8C=E6=AD=A5=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E7=94=9F=E6=88=90=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Job/CreateSyncServerDateTimeJob.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateSyncServerDateTimeJob.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateSyncServerDateTimeJob.cs index 44a2618c..3729ea1b 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateSyncServerDateTimeJob.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateSyncServerDateTimeJob.cs @@ -22,10 +22,18 @@ namespace Dlhis.ScheduledTask.TaskAssignment.Job _dbContext.Client.QueryFilter.ClearAndBackup(); try { - var devices = await _dbContext.Queryable().Where(x => x.Enable).ToListAsync(); + var deviceUniqueNos = await _dbContext.Queryable().Where(x => x.Status == DeviceTaskStatusEnumType.Wait) + .Where(x => x.Type == DeviceTaskEnumType.SyncDateTime) + .Select(x => x.DeviceUniqueNo) + .ToListAsync(); + + var devices = await _dbContext.Queryable() + .Where(x => deviceUniqueNos.Contains(x.UniqueNo)) + .Where(x => x.Enable) + .ToListAsync(); + var tasks = devices.Select(x => new DeviceTaskEntity { - DeviceUniqueNo = x.UniqueNo, Status = DeviceTaskStatusEnumType.Wait, From 517a0642953ae0f707d6a7dbdd43b913a3953d4f Mon Sep 17 00:00:00 2001 From: liguoyang Date: Fri, 23 Feb 2024 18:15:00 +0800 Subject: [PATCH 043/146] =?UTF-8?q?fix=20=E8=A1=A5=E5=85=85id=E5=AD=97?= =?UTF-8?q?=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Basic/BusinessShift/Response/MealShiftResponse.cs | 2 ++ .../Services/Implements/BusinessPlaceShiftService.cs | 1 + 2 files changed, 3 insertions(+) diff --git a/Src/Dlhis.Basic/BusinessShift/Response/MealShiftResponse.cs b/Src/Dlhis.Basic/BusinessShift/Response/MealShiftResponse.cs index be466ccc..bf99cb6a 100644 --- a/Src/Dlhis.Basic/BusinessShift/Response/MealShiftResponse.cs +++ b/Src/Dlhis.Basic/BusinessShift/Response/MealShiftResponse.cs @@ -2,6 +2,8 @@ { public class MealShiftResponse { + public long Id { get; set; } + public Guid ShiftCode { get; set; } public string ShiftType { get; set; } diff --git a/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs b/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs index b0df1e36..68227dc9 100644 --- a/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs +++ b/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs @@ -39,6 +39,7 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService .Where(x => shiftCodes.Contains(x.ShiftCode)) .Select((x, bt) => new MealShiftResponse { + Id = x.Id, ShiftCode = x.ShiftCode, ShiftType = bt.Code, Name = bt.Display, From d1dde626ef3b49d2dc115138c2ff5b5365d6e0f7 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Fri, 23 Feb 2024 18:20:43 +0800 Subject: [PATCH 044/146] =?UTF-8?q?fix=20=E6=97=A5=E6=9C=9F=E6=8E=92?= =?UTF-8?q?=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Basic/Summary/Services/Implements/SummaryService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/Dlhis.Basic/Summary/Services/Implements/SummaryService.cs b/Src/Dlhis.Basic/Summary/Services/Implements/SummaryService.cs index ad4f3e1e..38e03872 100644 --- a/Src/Dlhis.Basic/Summary/Services/Implements/SummaryService.cs +++ b/Src/Dlhis.Basic/Summary/Services/Implements/SummaryService.cs @@ -101,6 +101,6 @@ public class SummaryService : ISummaryService currentDate = currentDate.AddDays(1); } - return result; + return result.OrderBy(x => x.Date).ToList(); } } From ae8b48a78299606bf8fb56985f1422de7abb4ef1 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Fri, 23 Feb 2024 18:57:02 +0800 Subject: [PATCH 045/146] =?UTF-8?q?fix=20=E7=B4=A2=E5=BC=95,=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E9=87=8D=E5=A4=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/BusinessPlaceShiftService.cs | 6 +- .../BusinessShift/TimePeriodExtensions.cs | 73 +++++++++++++++++++ .../Basic/Entity/BasicTypeEntity.cs | 4 +- 3 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 Src/Dlhis.Basic/BusinessShift/TimePeriodExtensions.cs diff --git a/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs b/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs index 68227dc9..84931863 100644 --- a/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs +++ b/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs @@ -116,8 +116,8 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService } else { - var entity = await _dbContext.Queryable().FirstAsync(x => x.Id == request.Id); - entity.ThrowIfNull("餐次不存在"); + var entity = await _dbContext.Queryable().FirstAsync(x => x.Id == request.Id); + entity.ThrowIfNull("餐次段不存在"); request.Adapt(entity); await _dbContext.UpdateAsync(entity); @@ -210,7 +210,7 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService foreach (var period in periods) { - period.IsDuplicate(request.TimePeriod).ThrowIfTrue($"存在时间段重合[{period.Start}-{period.End}]"); + period.IsDuplicate1(request.TimePeriod).ThrowIfTrue($"存在时间段重合[{period.Start}-{period.End}]"); } } diff --git a/Src/Dlhis.Basic/BusinessShift/TimePeriodExtensions.cs b/Src/Dlhis.Basic/BusinessShift/TimePeriodExtensions.cs new file mode 100644 index 00000000..15d4c69d --- /dev/null +++ b/Src/Dlhis.Basic/BusinessShift/TimePeriodExtensions.cs @@ -0,0 +1,73 @@ +using Kurisu.Core.CustomClass; + +namespace Dlhis.Basic.BusinessShift; + + +/// +/// 临时的扩展类 todo: 嵌入框架 +/// +public static class TimePeriodExtensions +{ + public static bool IsDuplicate1(this TimePeriod current, TimePeriod period) + { + return !Check(); + + bool Check() + { + if (current.IsCrossDay()) + { + if (period.IsCrossDay()) + { + return true; + } + else + { + return period.Start > current.End && period.End < current.Start; + } + } + else + { + if (period.IsCrossDay()) + { + return period.Start > current.End && period.End < current.Start; + } + else + { + return period.Start > current.End || period.End < current.Start; + } + } + } + } + + + public static bool IsPresent1(this TimePeriod period, DateTime dateTime) + { + DateTime start; + DateTime end; + + if (period.IsCrossDay()) + { + var currentStart = DateTime.Today.Add(period.Start.Value.ToTimeSpan()); + var endOfDay = DateTime.Today.AddHours(23).AddMinutes(59).AddSeconds(59); + + if (dateTime >= currentStart && dateTime <= endOfDay) + { + start = DateTime.Today.Add(period.Start.Value.ToTimeSpan()); + end = DateTime.Today.AddDays(1).Add(period.End.Value.ToTimeSpan()); + } + else + { + //第二天 + start = DateTime.Today.AddDays(-1).Add(period.Start.Value.ToTimeSpan()); + end = DateTime.Today.Add(period.End.Value.ToTimeSpan()); + } + } + else + { + start = DateTime.Today.Add(period.Start.Value.ToTimeSpan()); + end = DateTime.Today.Add(period.End.Value.ToTimeSpan()); + } + + return dateTime >= start && dateTime <= end; + } +} diff --git a/Src/Dlhis.Entity/Basic/Entity/BasicTypeEntity.cs b/Src/Dlhis.Entity/Basic/Entity/BasicTypeEntity.cs index e6173c9f..14e5a309 100644 --- a/Src/Dlhis.Entity/Basic/Entity/BasicTypeEntity.cs +++ b/Src/Dlhis.Entity/Basic/Entity/BasicTypeEntity.cs @@ -12,13 +12,13 @@ public class BasicTypeEntity : SugarBaseEntity /// /// 类型 /// - [SugarColumn(ColumnDescription = "类型")] + [SugarColumn(ColumnDescription = "类型", UniqueGroupNameList = new[] { "idx_BasicType_type_code" })] public string Type { get; set; } /// /// 编码 /// - [SugarColumn(ColumnDescription = "编码")] + [SugarColumn(ColumnDescription = "编码", UniqueGroupNameList = new[] { "idx_BasicType_type_code" })] public string Code { get; set; } /// From a0e958322972beb3b902984a12b4585f2d5c69d2 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Fri, 23 Feb 2024 19:15:59 +0800 Subject: [PATCH 046/146] =?UTF-8?q?fix=20=E5=A2=9E=E5=8A=A0=E5=BF=83?= =?UTF-8?q?=E8=B7=B3=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CommonJobs/HeartbeatJob.cs | 42 +++++++++++++++++++ Src/Dlhis.ScheduledTask/IPPortDto.cs | 8 ++++ Src/Dlhis.ScheduledTask/Packs/JobPack.cs | 6 +++ .../SyncSapInfo/Comparers/SapOrgComparer.cs | 33 --------------- .../Comparers/SapPositionComparer.cs | 32 -------------- 5 files changed, 56 insertions(+), 65 deletions(-) create mode 100644 Src/Dlhis.ScheduledTask/CommonJobs/HeartbeatJob.cs create mode 100644 Src/Dlhis.ScheduledTask/IPPortDto.cs delete mode 100644 Src/Dlhis.ScheduledTask/SyncSapInfo/Comparers/SapOrgComparer.cs delete mode 100644 Src/Dlhis.ScheduledTask/SyncSapInfo/Comparers/SapPositionComparer.cs diff --git a/Src/Dlhis.ScheduledTask/CommonJobs/HeartbeatJob.cs b/Src/Dlhis.ScheduledTask/CommonJobs/HeartbeatJob.cs new file mode 100644 index 00000000..908ec2ad --- /dev/null +++ b/Src/Dlhis.ScheduledTask/CommonJobs/HeartbeatJob.cs @@ -0,0 +1,42 @@ +using System.Net; +using System.Net.Sockets; +using Dlhis.Entity.Basic.Entity; +using Dlhis.Entity.Device.Entities; +using Kurisu.SqlSugar.Services; +using Newtonsoft.Json; + +namespace Dlhis.ScheduledTask.CommonJobs; + +public class HeartbeatJob +{ + private readonly IDbContext _dbContext; + private readonly ILogger _logger; + + public HeartbeatJob(IDbContext dbContext, ILogger logger) + { + _dbContext = dbContext; + _logger = logger; + } + + public async Task RunAsync() + { + var devices = await _dbContext.Queryable().Where(x => x.Enable).ToListAsync(); + foreach (var device in devices) + { + try + { + var ipInfo = JsonConvert.DeserializeObject(device.ConnectionInfo); + + await new TcpClient().ConnectAsync(IPAddress.Parse(ipInfo.IP), ipInfo.Port); + await _dbContext.Updateable().SetColumns(x => x.LastHeartbeatTime == DateTime.Now) + .Where(x => x.DeviceUniqueNo == device.UniqueNo).ExecuteCommandAsync(); + + _logger.LogInformation("心跳设备:{no}成功", device.UniqueNo); + } + catch (Exception ex) + { + _logger.LogError(ex, "心跳设备失败:{message}", ex.Message); + } + } + } +} diff --git a/Src/Dlhis.ScheduledTask/IPPortDto.cs b/Src/Dlhis.ScheduledTask/IPPortDto.cs new file mode 100644 index 00000000..6a1bbd8a --- /dev/null +++ b/Src/Dlhis.ScheduledTask/IPPortDto.cs @@ -0,0 +1,8 @@ +namespace Dlhis.ScheduledTask +{ + public class IPPortDto + { + public string IP { get; set; } + public int Port { get; set; } + } +} diff --git a/Src/Dlhis.ScheduledTask/Packs/JobPack.cs b/Src/Dlhis.ScheduledTask/Packs/JobPack.cs index 5bccbd46..2a09eefb 100644 --- a/Src/Dlhis.ScheduledTask/Packs/JobPack.cs +++ b/Src/Dlhis.ScheduledTask/Packs/JobPack.cs @@ -41,5 +41,11 @@ public class JobPack : BaseAppPack { TimeZone = TimeZoneInfo.Local }); + + //心跳 + RecurringJob.AddOrUpdate("Heartbeat", s => s.RunAsync(), "10 * * * * ?", new RecurringJobOptions + { + TimeZone = TimeZoneInfo.Local + }); } } diff --git a/Src/Dlhis.ScheduledTask/SyncSapInfo/Comparers/SapOrgComparer.cs b/Src/Dlhis.ScheduledTask/SyncSapInfo/Comparers/SapOrgComparer.cs deleted file mode 100644 index da2ef800..00000000 --- a/Src/Dlhis.ScheduledTask/SyncSapInfo/Comparers/SapOrgComparer.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Dlhis.ScheduledTask.SyncSapInfo.Dto; - -namespace Dlhis.ScheduledTask.SyncSapInfo.Comparers; - -/// -/// 机构数据比较器 -/// -public class SapOrganizationComparer : IEqualityComparer -{ - public bool Equals(SapOrganizationItem x, SapOrganizationItem y) - { - if (ReferenceEquals(x, y)) return true; - if (ReferenceEquals(x, null) || ReferenceEquals(y, null)) return false; - if (x.GetType() != y.GetType()) return false; - - return x.BEGDA == y.BEGDA - && x.ENDDA == y.ENDDA - && x.LANGU == y.LANGU - && x.OBJID == y.OBJID - && x.STEXT == y.STEXT - && x.SOBID == y.SOBID - && x.ORGID01 == y.ORGID01 - && x.ORGID02 == y.ORGID02; - } - - public int GetHashCode(SapOrganizationItem obj) - { - return obj.BEGDA.SafeGetHashCode() ^ obj.ENDDA.SafeGetHashCode() - ^ obj.LANGU.SafeGetHashCode() ^ obj.OBJID.SafeGetHashCode() - ^ obj.STEXT.SafeGetHashCode() ^ obj.SOBID.SafeGetHashCode() - ^ obj.ORGID01.SafeGetHashCode() ^ obj.ORGID02.SafeGetHashCode(); - } -} diff --git a/Src/Dlhis.ScheduledTask/SyncSapInfo/Comparers/SapPositionComparer.cs b/Src/Dlhis.ScheduledTask/SyncSapInfo/Comparers/SapPositionComparer.cs deleted file mode 100644 index 2f6a04b2..00000000 --- a/Src/Dlhis.ScheduledTask/SyncSapInfo/Comparers/SapPositionComparer.cs +++ /dev/null @@ -1,32 +0,0 @@ -using Dlhis.ScheduledTask.SyncSapInfo.Dto; - -namespace Dlhis.ScheduledTask.SyncSapInfo.Comparers; - -/// -/// 岗位信息比较器 -/// -public class SapPositionComparer : IEqualityComparer -{ - public bool Equals(SapPositionItem x, SapPositionItem y) - { - if (ReferenceEquals(x, y)) return true; - if (ReferenceEquals(x, null) || ReferenceEquals(y, null)) return false; - if (x.GetType() != y.GetType()) return false; - - return x.BEGDA == y.BEGDA - && x.ENDDA == y.ENDDA - && x.LANGU == y.LANGU - && x.ZJOBID == y.ZJOBID - && x.ZJOBNAME == y.ZJOBNAME - && x.ZZWID == y.ZZWID - && x.ZDEPID == y.ZDEPID; - } - - public int GetHashCode(SapPositionItem obj) - { - return obj.BEGDA.SafeGetHashCode() ^ obj.ENDDA.SafeGetHashCode() - ^ obj.LANGU.SafeGetHashCode() ^ obj.ZJOBID.SafeGetHashCode() - ^ obj.ZJOBNAME.SafeGetHashCode() ^ obj.ZZWID.SafeGetHashCode() - ^ obj.ZDEPID.SafeGetHashCode(); - } -} From 80c84069e11f9578a0961165f56fec4974d57696 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Fri, 23 Feb 2024 19:21:49 +0800 Subject: [PATCH 047/146] =?UTF-8?q?fix=20=E5=BF=83=E8=B7=B3=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E8=8E=B7=E5=8F=96=E6=95=B0=E6=8D=AE=E4=B8=BA=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CommonJobs/HeartbeatJob.cs | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/Src/Dlhis.ScheduledTask/CommonJobs/HeartbeatJob.cs b/Src/Dlhis.ScheduledTask/CommonJobs/HeartbeatJob.cs index 908ec2ad..f9453196 100644 --- a/Src/Dlhis.ScheduledTask/CommonJobs/HeartbeatJob.cs +++ b/Src/Dlhis.ScheduledTask/CommonJobs/HeartbeatJob.cs @@ -2,6 +2,7 @@ using System.Net.Sockets; using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Device.Entities; +using Kurisu.Core.DataAccess.Entity; using Kurisu.SqlSugar.Services; using Newtonsoft.Json; @@ -20,23 +21,31 @@ public class HeartbeatJob public async Task RunAsync() { - var devices = await _dbContext.Queryable().Where(x => x.Enable).ToListAsync(); - foreach (var device in devices) + _dbContext.Client.QueryFilter.ClearAndBackup(); + try { - try + var devices = await _dbContext.Queryable().Where(x => x.Enable).ToListAsync(); + foreach (var device in devices) { - var ipInfo = JsonConvert.DeserializeObject(device.ConnectionInfo); + try + { + var ipInfo = JsonConvert.DeserializeObject(device.ConnectionInfo); - await new TcpClient().ConnectAsync(IPAddress.Parse(ipInfo.IP), ipInfo.Port); - await _dbContext.Updateable().SetColumns(x => x.LastHeartbeatTime == DateTime.Now) - .Where(x => x.DeviceUniqueNo == device.UniqueNo).ExecuteCommandAsync(); + await new TcpClient().ConnectAsync(IPAddress.Parse(ipInfo.IP), ipInfo.Port); + await _dbContext.Updateable().SetColumns(x => x.LastHeartbeatTime == DateTime.Now) + .Where(x => x.DeviceUniqueNo == device.UniqueNo).ExecuteCommandAsync(); - _logger.LogInformation("心跳设备:{no}成功", device.UniqueNo); - } - catch (Exception ex) - { - _logger.LogError(ex, "心跳设备失败:{message}", ex.Message); + _logger.LogInformation("心跳设备:{no}成功", device.UniqueNo); + } + catch (Exception ex) + { + _logger.LogError(ex, "心跳设备失败:{message}", ex.Message); + } } } + finally + { + _dbContext.Client.QueryFilter.Restore(); + } } } From 96cbaa1c3ab2d172165e619f771cc93743099c05 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Fri, 23 Feb 2024 19:22:08 +0800 Subject: [PATCH 048/146] =?UTF-8?q?fix=20=E9=87=91=E9=A2=9D=E5=B0=8F?= =?UTF-8?q?=E6=95=B0=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Canteen/Order/Response/OrderResultResponse.cs | 9 +++++++-- .../Order/Services/Implements/OrderService.cs | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Src/Dlhis.Canteen/Order/Response/OrderResultResponse.cs b/Src/Dlhis.Canteen/Order/Response/OrderResultResponse.cs index 69418e4d..98d4b96b 100644 --- a/Src/Dlhis.Canteen/Order/Response/OrderResultResponse.cs +++ b/Src/Dlhis.Canteen/Order/Response/OrderResultResponse.cs @@ -1,4 +1,6 @@ -namespace Dlhis.Canteen.Order.Response; +using Newtonsoft.Json; + +namespace Dlhis.Canteen.Order.Response; public class OrderResultResponse { @@ -22,8 +24,11 @@ public class OrderResultResponse /// public string DepartmentName { get; set; } + [JsonIgnore] + public decimal CurrentBalance { get; set; } + /// /// 余额 /// - public decimal Balance { get; set; } + public string Balance => CurrentBalance.ToString("f2"); } diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs index 0ecfee6e..6796f695 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs @@ -95,7 +95,7 @@ public class OrderService : IOrderService UserName = ga.Name, DepartmentNo = ga.DepartmentNo, DepartmentName = department.Name, - Balance = mealUser.Balance + CurrentBalance = mealUser.Balance }) .SingleAsync(); } From 07fdbd2f16b164a1cc107ce75d5ef9035686fd10 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Fri, 23 Feb 2024 19:30:59 +0800 Subject: [PATCH 049/146] =?UTF-8?q?fix=20=E5=BF=83=E8=B7=B3=E9=97=B4?= =?UTF-8?q?=E9=9A=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.ScheduledTask/CommonJobs/HeartbeatJob.cs | 7 +++++-- Src/Dlhis.ScheduledTask/Packs/JobPack.cs | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Src/Dlhis.ScheduledTask/CommonJobs/HeartbeatJob.cs b/Src/Dlhis.ScheduledTask/CommonJobs/HeartbeatJob.cs index f9453196..0d0c11b4 100644 --- a/Src/Dlhis.ScheduledTask/CommonJobs/HeartbeatJob.cs +++ b/Src/Dlhis.ScheduledTask/CommonJobs/HeartbeatJob.cs @@ -31,11 +31,14 @@ public class HeartbeatJob { var ipInfo = JsonConvert.DeserializeObject(device.ConnectionInfo); - await new TcpClient().ConnectAsync(IPAddress.Parse(ipInfo.IP), ipInfo.Port); + //超时时间 + var CancellationTokenSource = new CancellationTokenSource(300); + await new TcpClient().ConnectAsync(IPAddress.Parse(ipInfo.IP), ipInfo.Port, CancellationTokenSource.Token); + await _dbContext.Updateable().SetColumns(x => x.LastHeartbeatTime == DateTime.Now) .Where(x => x.DeviceUniqueNo == device.UniqueNo).ExecuteCommandAsync(); - _logger.LogInformation("心跳设备:{no}成功", device.UniqueNo); + _logger.LogInformation("心跳设备成功:{no}", device.UniqueNo); } catch (Exception ex) { diff --git a/Src/Dlhis.ScheduledTask/Packs/JobPack.cs b/Src/Dlhis.ScheduledTask/Packs/JobPack.cs index 2a09eefb..fc4c8870 100644 --- a/Src/Dlhis.ScheduledTask/Packs/JobPack.cs +++ b/Src/Dlhis.ScheduledTask/Packs/JobPack.cs @@ -43,7 +43,7 @@ public class JobPack : BaseAppPack }); //心跳 - RecurringJob.AddOrUpdate("Heartbeat", s => s.RunAsync(), "10 * * * * ?", new RecurringJobOptions + RecurringJob.AddOrUpdate("Heartbeat", s => s.RunAsync(), "0/10 * * * * ?", new RecurringJobOptions { TimeZone = TimeZoneInfo.Local }); From 4efc708177502031e9bb37613aa10d3dc79f08c7 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Fri, 23 Feb 2024 20:46:24 +0800 Subject: [PATCH 050/146] =?UTF-8?q?feat=20=E6=8D=A2=E5=8D=A1=E6=93=8D?= =?UTF-8?q?=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/GainfoCardsController.cs | 47 ++++++++++++++++ .../Organization/Request/ChangeCardRequest.cs | 17 ++++++ .../Response/ChangeCardResponse.cs | 15 ++++++ .../Services/IGainfoCardService.cs | 11 ++++ .../Organization/Services/IGainfoStore.cs | 2 +- .../Services/Implements/GainfoCardService.cs | 54 +++++++++++++++++++ .../Basic/Entity/GainfoCardRecordEntity.cs | 33 ++++++++++++ 7 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 Src/Dlhis.Basic/Organization/Controllers/GainfoCardsController.cs create mode 100644 Src/Dlhis.Basic/Organization/Request/ChangeCardRequest.cs create mode 100644 Src/Dlhis.Basic/Organization/Response/ChangeCardResponse.cs create mode 100644 Src/Dlhis.Basic/Organization/Services/IGainfoCardService.cs create mode 100644 Src/Dlhis.Basic/Organization/Services/Implements/GainfoCardService.cs create mode 100644 Src/Dlhis.Entity/Basic/Entity/GainfoCardRecordEntity.cs diff --git a/Src/Dlhis.Basic/Organization/Controllers/GainfoCardsController.cs b/Src/Dlhis.Basic/Organization/Controllers/GainfoCardsController.cs new file mode 100644 index 00000000..6ef9aed1 --- /dev/null +++ b/Src/Dlhis.Basic/Organization/Controllers/GainfoCardsController.cs @@ -0,0 +1,47 @@ +using Dlhis.Basic.Organization.Request; +using Dlhis.Basic.Organization.Response; +using Dlhis.Basic.Organization.Services; +using Dlhis.Basic.Packs; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; + +namespace Dlhis.Basic.Organization.Controllers; + +/// +/// 档案卡记录 +/// +[Authorize] +[Route("api/[controller]")] +[ApiController] +public class GainfoCardsController : ControllerBase +{ + private readonly IGainfoCardService _gainfoCardService; + + public GainfoCardsController(IGainfoCardService gainfoCardService) + { + _gainfoCardService = gainfoCardService; + } + + /// + /// 换卡 + /// + /// + /// + [HttpPost("change")] + [Transactional] + public async Task ChangeCardAsync(ChangeCardRequest request) + { + await _gainfoCardService.ChangeCardAsync(request); + } + + /// + /// 换卡记录 + /// + /// + /// + [HttpGet("records")] + public async Task> GetChangeRecordsAsync(string userNo) + { + return await _gainfoCardService.GetChangeRecordsAsync(userNo); + } +} diff --git a/Src/Dlhis.Basic/Organization/Request/ChangeCardRequest.cs b/Src/Dlhis.Basic/Organization/Request/ChangeCardRequest.cs new file mode 100644 index 00000000..d470812f --- /dev/null +++ b/Src/Dlhis.Basic/Organization/Request/ChangeCardRequest.cs @@ -0,0 +1,17 @@ +using System.ComponentModel.DataAnnotations; + +namespace Dlhis.Basic.Organization.Request; + +public class ChangeCardRequest +{ + [Required] + public string UserNo { get; set; } + + [Required] + public string CardNo { get; set; } + + [Required] + public string Reason { get; set; } + + public string Remark { get; set; } +} diff --git a/Src/Dlhis.Basic/Organization/Response/ChangeCardResponse.cs b/Src/Dlhis.Basic/Organization/Response/ChangeCardResponse.cs new file mode 100644 index 00000000..47943f0e --- /dev/null +++ b/Src/Dlhis.Basic/Organization/Response/ChangeCardResponse.cs @@ -0,0 +1,15 @@ +namespace Dlhis.Basic.Organization.Response; + +public class ChangeCardResponse +{ + public string UserNo { get; set; } + public string UserCode { get; set; } + public string UserName { get; set; } + public string CardNo { get; set; } + + public string Reason { get; set; } + + public string Remark { get; set; } + + public DateTime CreateTime { get; set; } +} diff --git a/Src/Dlhis.Basic/Organization/Services/IGainfoCardService.cs b/Src/Dlhis.Basic/Organization/Services/IGainfoCardService.cs new file mode 100644 index 00000000..8bbce4c7 --- /dev/null +++ b/Src/Dlhis.Basic/Organization/Services/IGainfoCardService.cs @@ -0,0 +1,11 @@ +using Dlhis.Basic.Organization.Request; +using Dlhis.Basic.Organization.Response; + +namespace Dlhis.Basic.Organization.Services; + +public interface IGainfoCardService +{ + Task ChangeCardAsync(ChangeCardRequest request); + + Task> GetChangeRecordsAsync(string userNo); +} diff --git a/Src/Dlhis.Basic/Organization/Services/IGainfoStore.cs b/Src/Dlhis.Basic/Organization/Services/IGainfoStore.cs index 3204fb74..8af56343 100644 --- a/Src/Dlhis.Basic/Organization/Services/IGainfoStore.cs +++ b/Src/Dlhis.Basic/Organization/Services/IGainfoStore.cs @@ -9,7 +9,7 @@ namespace Dlhis.Basic.Organization.Services; /// public interface IGainfoStore : IScopeDependency { - ISugarQueryable Queryable(GainfoStatusEnumType? gainfoStatus); + ISugarQueryable Queryable(GainfoStatusEnumType? gainfoStatus = null); diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoCardService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoCardService.cs new file mode 100644 index 00000000..c9d3213e --- /dev/null +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoCardService.cs @@ -0,0 +1,54 @@ +using Dlhis.Basic.Organization.Request; +using Dlhis.Basic.Organization.Response; +using Dlhis.Entity.Basic.Entity; +using Kurisu.AspNetCore.Utils.Extensions; +using Kurisu.SqlSugar.Services; + +namespace Dlhis.Basic.Organization.Services.Implements; + +public class GainfoCardService : IGainfoCardService +{ + private readonly IDbContext _dbContext; + private readonly IGainfoStore _gainfoStore; + + public GainfoCardService(IDbContext dbContext, IGainfoStore gainfoStore) + { + _dbContext = dbContext; + _gainfoStore = gainfoStore; + } + + public async Task ChangeCardAsync(ChangeCardRequest request) + { + var gainfo = await _gainfoStore.Queryable().Where(x => x.No == request.UserNo).FirstAsync(); + gainfo.ThrowIfNull("档案不存在"); + + gainfo.CardNo = request.CardNo; + + await _gainfoStore.UpdateAsync(gainfo); + await _dbContext.InsertAsync(new GainfoCardRecordEntity + { + UserNo = request.UserNo, + CardNo = request.CardNo, + Reason = request.Reason, + Remark = request.Remark, + }); + } + + public async Task> GetChangeRecordsAsync(string userNo) + { + return await _dbContext.Queryable() + .LeftJoin((x, ga) => x.UserNo == ga.No) + .Where(x => x.UserNo == userNo) + .Select((x, ga) => new ChangeCardResponse + { + UserNo = x.UserNo, + UserCode = ga.Code, + UserName = ga.Name, + CardNo = x.CardNo, + Reason = x.Reason, + Remark = x.Remark, + CreateTime = x.CreateTime, + }) + .ToListAsync(); + } +} diff --git a/Src/Dlhis.Entity/Basic/Entity/GainfoCardRecordEntity.cs b/Src/Dlhis.Entity/Basic/Entity/GainfoCardRecordEntity.cs new file mode 100644 index 00000000..59c4b49d --- /dev/null +++ b/Src/Dlhis.Entity/Basic/Entity/GainfoCardRecordEntity.cs @@ -0,0 +1,33 @@ +using Kurisu.Core.DataAccess.Entity; +using Kurisu.SqlSugar; +using SqlSugar; + +namespace Dlhis.Entity.Basic.Entity; + +[SugarTable(TableName = "GainfoCardRecord", TableDescription = "卡记录")] +public class GainfoCardRecordEntity : SugarBaseEntity, ITenantId +{ + /// + /// 档案No + /// + [SugarColumn(IsNullable = false, IndexGroupNameList = new[] { "idx_GainfoCardRecord_userno" })] + public string UserNo { get; set; } + + /// + /// 卡号 + /// + [SugarColumn(IsNullable = false)] + public string CardNo { get; set; } + + /// + /// 更换原因 + /// + public string Reason { get; set; } + + /// + /// 备注 + /// + public string Remark { get; set; } + + public string TenantId { get; set; } +} From 1ddebd466682d2146f735392f04caaa42a0a3e96 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Fri, 23 Feb 2024 20:46:38 +0800 Subject: [PATCH 051/146] =?UTF-8?q?fix=20=E8=AE=BE=E5=A4=87=E5=88=86?= =?UTF-8?q?=E7=BB=84=E4=BF=9D=E5=AD=98=E9=80=BB=E8=BE=91=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Implements/DeviceGroupService.cs | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs index 7f1e5345..7ffdc0d4 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs @@ -3,9 +3,9 @@ using Dlhis.Basic.Device.Response; using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Device.Entities; using Dlhis.Entity.Device.Enums; +using Kurisu.AspNetCore.UnifyResultAndValidation; using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.DataAccess.Dto; -using Kurisu.SqlSugar.Attributes; using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Services; using Mapster; @@ -55,6 +55,15 @@ public class DeviceGroupService : IDeviceGroupService if (!request.Id.HasValue) { + if (request.PCode.HasValue) + { + var pGrp = await _dbContext.Queryable().Where(x => x.Code == request.PCode).FirstAsync(); + if (pGrp != null && pGrp.Type != request.Type) + { + throw new UserFriendlyException("分组类型必须与上级类型保持一致"); + } + } + var entity = request.Adapt(); entity.Editable = true; entity.Code = Guid.NewGuid(); @@ -67,6 +76,23 @@ public class DeviceGroupService : IDeviceGroupService entity.ThrowIfNull("设备组不存在,无法更新"); entity.Editable.ThrowIfFalse("不可编辑当前组"); + if (entity.PCode.HasValue) + { + var pGrp = await _dbContext.Queryable().Where(x => x.Code == request.PCode).FirstAsync(); + if (pGrp != null && pGrp.Type != request.Type) + { + throw new UserFriendlyException("分组类型必须与上级类型保持一致"); + } + } + else + { + var nGrp = await _dbContext.Queryable().Where(x => x.PCode == entity.Code).FirstAsync(); + if (nGrp != null && nGrp.Type != request.Type) + { + throw new UserFriendlyException("存在下级分组类型不一致,无法修改"); + } + } + var nextDevices = await GetDevicesAsync(entity.Code); if (!entity.Type.HasValue) { From e259c3ab92656871f177d44b9e80e93717c8385f Mon Sep 17 00:00:00 2001 From: liguoyang Date: Fri, 23 Feb 2024 21:06:31 +0800 Subject: [PATCH 052/146] =?UTF-8?q?fix=20=E5=BF=83=E8=B7=B3=E9=97=B4?= =?UTF-8?q?=E9=9A=94=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Basic/Device/Request/DeviceSaveRequest.cs | 6 +++++- Src/Dlhis.ScheduledTask/CommonJobs/HeartbeatJob.cs | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Src/Dlhis.Basic/Device/Request/DeviceSaveRequest.cs b/Src/Dlhis.Basic/Device/Request/DeviceSaveRequest.cs index 96bd0278..f7e4a84c 100644 --- a/Src/Dlhis.Basic/Device/Request/DeviceSaveRequest.cs +++ b/Src/Dlhis.Basic/Device/Request/DeviceSaveRequest.cs @@ -43,7 +43,6 @@ public class DeviceSaveRequest : IValidatableObject /// /// 心跳间隔 /// - [Range(0, int.MaxValue)] public int HeartbeatInterval { get; set; } /// @@ -83,5 +82,10 @@ public class DeviceSaveRequest : IValidatableObject { yield return new ValidationResult($"{DeviceTypeEnumType.Door.GetDescription()}才可设置作为考勤设备", new[] { nameof(AsAttendance) }); } + + if (HeartbeatInterval != 0 && HeartbeatInterval < 30) + { + yield return new ValidationResult($"心跳间隔需要设置>=30秒", new[] { nameof(HeartbeatInterval) }); + } } } diff --git a/Src/Dlhis.ScheduledTask/CommonJobs/HeartbeatJob.cs b/Src/Dlhis.ScheduledTask/CommonJobs/HeartbeatJob.cs index 0d0c11b4..a8bd8579 100644 --- a/Src/Dlhis.ScheduledTask/CommonJobs/HeartbeatJob.cs +++ b/Src/Dlhis.ScheduledTask/CommonJobs/HeartbeatJob.cs @@ -24,7 +24,7 @@ public class HeartbeatJob _dbContext.Client.QueryFilter.ClearAndBackup(); try { - var devices = await _dbContext.Queryable().Where(x => x.Enable).ToListAsync(); + var devices = await _dbContext.Queryable().Where(x => x.Enable).Where(x => x.HeartbeatInterval > 0).ToListAsync(); foreach (var device in devices) { try From 412e5589e6711f6ffcf6c82562288cb917d7ab18 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Fri, 23 Feb 2024 21:06:47 +0800 Subject: [PATCH 053/146] =?UTF-8?q?fix=20=E5=8F=82=E6=95=B0=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=E9=9D=9E=E4=BD=99=E9=A2=9D=E5=88=B6=E6=B6=88=E8=B4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Order/Services/Implements/OrderService.cs | 46 +++++++++++++------ .../Implements/CanteenSettingService.cs | 1 + .../Enums/CanteenSettingItemEnumType.cs | 7 +++ 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs index 6796f695..c2cabe68 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs @@ -336,7 +336,20 @@ public class OrderService : IOrderService { if (settings.TryGetValue(item, out var v)) { - return v.Adapt(); + try + { + + if (int.TryParse(v, out var n)) + { + return n.Adapt(); + } + + return v.Adapt(); + } + catch (Exception) + { + return defaultValue; + } } return defaultValue; @@ -467,24 +480,29 @@ public class OrderService : IOrderService //校验 await Verify(settings, shifts, costDateTime, order); + var allowNoBalance = GetSetting(settings, CanteenSettingItemEnumType.AllowNoBalance); + await ContinueUpdateAsync(async () => { - var canteenUser = await _dbContext.Queryable().Where(x => x.UserNo == order.UserNo).FirstAsync(); - //金额+- - canteenUser.Balance += order.Amount; - if (canteenUser.Balance < 0) + if (!allowNoBalance) { - throw new UserFriendlyException("余额不足,无法消费"); + var canteenUser = await _dbContext.Queryable().Where(x => x.UserNo == order.UserNo).FirstAsync(); + //金额+- + canteenUser.Balance += order.Amount; + if (canteenUser.Balance < 0) + { + throw new UserFriendlyException("余额不足,无法消费"); + } + + var effect = await _dbContext.Updateable() + .SetColumns(x => x.Balance == canteenUser.Balance) + .SetColumns(x => x.Version == x.Version + 1) + .Where(x => x.UserNo == order.UserNo && x.Version == canteenUser.Version)//必须与查询时的version一致 + .ExecuteCommandAsync(); + + if (effect <= 0) throw new VersionExceptions("更新版本冲突"); } - var effect = await _dbContext.Updateable() - .SetColumns(x => x.Balance == canteenUser.Balance) - .SetColumns(x => x.Version == x.Version + 1) - .Where(x => x.UserNo == order.UserNo && x.Version == canteenUser.Version)//必须与查询时的version一致 - .ExecuteCommandAsync(); - - if (effect <= 0) throw new VersionExceptions("更新版本冲突"); - //写入记录 var balanceRecord = order.Adapt(); await _dbContext.InsertAsync(balanceRecord); diff --git a/Src/Dlhis.Canteen/Setting/Services/Implements/CanteenSettingService.cs b/Src/Dlhis.Canteen/Setting/Services/Implements/CanteenSettingService.cs index 0d24c61e..cb707ca8 100644 --- a/Src/Dlhis.Canteen/Setting/Services/Implements/CanteenSettingService.cs +++ b/Src/Dlhis.Canteen/Setting/Services/Implements/CanteenSettingService.cs @@ -90,6 +90,7 @@ public class CanteenSettingService : ICanteenSettingService CanteenSettingItemEnumType.InitBalance => IsValidFormat(value), //bool + CanteenSettingItemEnumType.AllowNoBalance => IsValidFormat(value, request.Item), CanteenSettingItemEnumType.AllowSendAtMeal => IsValidFormat(value, request.Item), CanteenSettingItemEnumType.AllowRepeatInOneShift => IsValidFormat(value, request.Item), CanteenSettingItemEnumType.AllowCrossTenant => IsValidFormat(value, request.Item), diff --git a/Src/Dlhis.Entity/Canteen/Enums/CanteenSettingItemEnumType.cs b/Src/Dlhis.Entity/Canteen/Enums/CanteenSettingItemEnumType.cs index 1b01b10f..a5ac6a98 100644 --- a/Src/Dlhis.Entity/Canteen/Enums/CanteenSettingItemEnumType.cs +++ b/Src/Dlhis.Entity/Canteen/Enums/CanteenSettingItemEnumType.cs @@ -71,6 +71,13 @@ public enum CanteenSettingItemEnumType AllowCrossTenant, + /// + /// 允许不使用余额消费 + /// + [Description("允许不使用余额消费(0/1)")] + AllowNoBalance, + + //--------------------------------------------------------------------[400,500)---------------------------------------------------------------------------------- /// From bd00d3d0b8cf4969a96e9df4d2d73b420af9f623 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Fri, 23 Feb 2024 21:43:09 +0800 Subject: [PATCH 054/146] =?UTF-8?q?fix=20=E6=9B=B4=E6=96=B0=E9=9B=AA?= =?UTF-8?q?=E8=8A=B1id=E6=95=B0=E6=8D=AE=E8=8A=82=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Canteen/Program.cs | 8 ++++++++ Src/Dlhis.Entity/Dlhis.Entity.csproj | 2 +- Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj | 2 +- Src/Dlhis.ScheduledTask/Program.cs | 6 ++++++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Src/Dlhis.Canteen/Program.cs b/Src/Dlhis.Canteen/Program.cs index d64882de..1a52e899 100644 --- a/Src/Dlhis.Canteen/Program.cs +++ b/Src/Dlhis.Canteen/Program.cs @@ -1,4 +1,5 @@ using Kurisu.AspNetCore.Startup; +using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Startup; using Microsoft.IdentityModel.Logging; @@ -18,4 +19,11 @@ public class Startup : DefaultStartup { IdentityModelEventSource.ShowPII = true; } + + public override void ConfigureServices(IServiceCollection services) + { + base.ConfigureServices(services); + + services.AddRedis(); + } } \ No newline at end of file diff --git a/Src/Dlhis.Entity/Dlhis.Entity.csproj b/Src/Dlhis.Entity/Dlhis.Entity.csproj index 8245cd0d..6aee2f83 100644 --- a/Src/Dlhis.Entity/Dlhis.Entity.csproj +++ b/Src/Dlhis.Entity/Dlhis.Entity.csproj @@ -11,7 +11,7 @@ - + diff --git a/Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj b/Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj index 74406a5b..03b573b7 100644 --- a/Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj +++ b/Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj @@ -20,7 +20,7 @@ - + diff --git a/Src/Dlhis.ScheduledTask/Program.cs b/Src/Dlhis.ScheduledTask/Program.cs index 4c81132c..fa11b1b8 100644 --- a/Src/Dlhis.ScheduledTask/Program.cs +++ b/Src/Dlhis.ScheduledTask/Program.cs @@ -29,4 +29,10 @@ public class Startup : DefaultStartup .SetApplicationName("scheduled") .PersistKeysToStackExchangeRedis(redis, "DataProtection-Keys"); } + + public override void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + base.Configure(app, env); + app.UseSnowFlakeInit(); + } } \ No newline at end of file From 58f4d69b4e89b779de71001f19c1d226800c9452 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Fri, 23 Feb 2024 21:44:24 +0800 Subject: [PATCH 055/146] =?UTF-8?q?fix=20=E9=9B=AA=E8=8A=B1id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Canteen/Dlhis.Canteen.csproj | 2 +- Src/Dlhis.Canteen/Program.cs | 6 ++++++ Src/Dlhis.ScheduledTask/Program.cs | 1 - 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Src/Dlhis.Canteen/Dlhis.Canteen.csproj b/Src/Dlhis.Canteen/Dlhis.Canteen.csproj index fe0b5fd0..cb61b6a5 100644 --- a/Src/Dlhis.Canteen/Dlhis.Canteen.csproj +++ b/Src/Dlhis.Canteen/Dlhis.Canteen.csproj @@ -36,7 +36,7 @@ - + diff --git a/Src/Dlhis.Canteen/Program.cs b/Src/Dlhis.Canteen/Program.cs index 1a52e899..ce855b85 100644 --- a/Src/Dlhis.Canteen/Program.cs +++ b/Src/Dlhis.Canteen/Program.cs @@ -26,4 +26,10 @@ public class Startup : DefaultStartup services.AddRedis(); } + + public override void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + base.Configure(app, env); + app.UseSnowFlakeInit(); + } } \ No newline at end of file diff --git a/Src/Dlhis.ScheduledTask/Program.cs b/Src/Dlhis.ScheduledTask/Program.cs index fa11b1b8..259155f7 100644 --- a/Src/Dlhis.ScheduledTask/Program.cs +++ b/Src/Dlhis.ScheduledTask/Program.cs @@ -33,6 +33,5 @@ public class Startup : DefaultStartup public override void Configure(IApplicationBuilder app, IWebHostEnvironment env) { base.Configure(app, env); - app.UseSnowFlakeInit(); } } \ No newline at end of file From 7ce3c65dc83a7b2df9b1bd8f97ff4fcc1720a8ac Mon Sep 17 00:00:00 2001 From: liguoyang Date: Fri, 23 Feb 2024 21:52:42 +0800 Subject: [PATCH 056/146] =?UTF-8?q?fix=20redis=E8=BF=9E=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Canteen/appsettings.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Src/Dlhis.Canteen/appsettings.json b/Src/Dlhis.Canteen/appsettings.json index 7ea06e04..0f4accb1 100644 --- a/Src/Dlhis.Canteen/appsettings.json +++ b/Src/Dlhis.Canteen/appsettings.json @@ -40,6 +40,9 @@ "ClientSecret": "123456" } }, + "RedisOptions": { + "ConnectionString": "192.168.199.30:30115,defaultDatabase:1,password=dlhis123" + }, "Serilog": { "MinimumLevel": { "Default": "Information", From 90641ebdc78edb19862718c06b4f543d64f8d153 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Fri, 23 Feb 2024 21:59:58 +0800 Subject: [PATCH 057/146] fix fw --- Src/Dlhis.Basic/Dlhis.Basic.csproj | 2 +- Src/Dlhis.Common/Dlhis.Common.csproj | 2 +- Src/Dlhis.Sys/Dlhis.Sys.csproj | 2 +- Src/Dlhis.User/Dlhis.User.csproj | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Src/Dlhis.Basic/Dlhis.Basic.csproj b/Src/Dlhis.Basic/Dlhis.Basic.csproj index 4ada33a1..a9a3c3da 100644 --- a/Src/Dlhis.Basic/Dlhis.Basic.csproj +++ b/Src/Dlhis.Basic/Dlhis.Basic.csproj @@ -17,7 +17,7 @@ - + diff --git a/Src/Dlhis.Common/Dlhis.Common.csproj b/Src/Dlhis.Common/Dlhis.Common.csproj index 3fe68313..3ca7f20f 100644 --- a/Src/Dlhis.Common/Dlhis.Common.csproj +++ b/Src/Dlhis.Common/Dlhis.Common.csproj @@ -21,7 +21,7 @@ - + diff --git a/Src/Dlhis.Sys/Dlhis.Sys.csproj b/Src/Dlhis.Sys/Dlhis.Sys.csproj index 2d7b45d8..bb2fec72 100644 --- a/Src/Dlhis.Sys/Dlhis.Sys.csproj +++ b/Src/Dlhis.Sys/Dlhis.Sys.csproj @@ -17,7 +17,7 @@ - + diff --git a/Src/Dlhis.User/Dlhis.User.csproj b/Src/Dlhis.User/Dlhis.User.csproj index 97629934..b1381bb6 100644 --- a/Src/Dlhis.User/Dlhis.User.csproj +++ b/Src/Dlhis.User/Dlhis.User.csproj @@ -17,7 +17,7 @@ - + From 5e29f013b8c248a1753bb92383328f0b890080aa Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Mon, 26 Feb 2024 10:14:36 +0800 Subject: [PATCH 058/146] =?UTF-8?q?fix=20=E4=BF=AE=E6=94=B9=E7=A6=BB?= =?UTF-8?q?=E7=BA=BF=E8=AE=BE=E5=A4=87=E5=88=A4=E6=96=AD=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Implements/DeviceService.cs | 65 ++++++++++++++++--- .../Services/Implements/BalanceService.cs | 24 ++++++- .../Services/Implements/ApkFIileService.cs | 1 + 3 files changed, 80 insertions(+), 10 deletions(-) diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs index 474d1343..4818fb29 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs @@ -241,24 +241,43 @@ public class DeviceService : IDeviceService public async Task GetDeviceNumberAsync() { var devices = await _dbContext.Queryable() - .Where(x => x.Type == DeviceTypeEnumType.Attendance) + .Where(x => x.Type == DeviceTypeEnumType.Attendance && x.Enable) .ToListAsync(); - var onlineNumber = devices.Where(x => x.Enable).Count(); - var offlineNumber = devices.Where(x => x.Enable == false).Count(); + + var offlineNumber = GetOfflineDevicesCount(devices).Count; + var res = new DeviceNumberResponse - { - OnlineNumber = onlineNumber, + { OfflineNumber = offlineNumber, - TotalNumber = devices.Count() + TotalNumber = devices.Count(), + OnlineNumber = devices.Count()- offlineNumber }; return res; } + /// + /// 获取离线设备 + /// + /// + /// + private List GetOfflineDevicesCount(List devices) + { + var list = new List(); + foreach (var device in devices) + { + TimeSpan timeDifference = DateTime.Now - device.ModifiedTime; + if (timeDifference.TotalSeconds > (device.HeartbeatInterval * 3)) + { + list.Add(device); + } + } + return list; + } public async Task> GetAttendanceTotalAsync(AttendanceTotalRequest request) { var page = await _dbContext.Queryable() .LeftJoin((d, dt) => d.TemplateCode == dt.Code) - .Where(d => d.Type == DeviceTypeEnumType.Attendance) + .Where(d => d.Type == DeviceTypeEnumType.Attendance && d.Enable) .Select((d, dt) => new DevicePageResponse { FuncsStr = d.Funcs.ToString(), @@ -273,9 +292,39 @@ public class DeviceService : IDeviceService public async Task> GetAttendanceOfflineAsync(DeviceOnlineAndofflineRequest request) { + var devices = await _dbContext.Queryable() + .Where(x => x.Type == DeviceTypeEnumType.Attendance && x.Enable) + .ToListAsync(); + + //离线 + var offDevices = GetOfflineDevicesCount(devices); + var offids = offDevices.Select(x => x.Id).ToList(); + + if (request.IsOnAndOff) + { + //离线 + var offpage = await _dbContext.Queryable() + .LeftJoin((d, dt) => d.TemplateCode == dt.Code) + .Where(d => d.Type == DeviceTypeEnumType.Attendance && d.Enable) + .Where(d => offids.Contains(d.Id)) + .Select((d, dt) => new DevicePageResponse + { + FuncsStr = d.Funcs.ToString(), + Brand = dt.Brand, + Type = d.Type, + + }, true) + .ToPageListAsync(request); + return offpage; + } + //在线 + var ids = devices.Select(x => x.Id).ToList(); + List onids = ids.Except(offids).ToList(); + var page = await _dbContext.Queryable() .LeftJoin((d, dt) => d.TemplateCode == dt.Code) - .Where(d => d.Type == DeviceTypeEnumType.Attendance && d.Enable == request.IsOnAndOff) + .Where(d => d.Type == DeviceTypeEnumType.Attendance && d.Enable) + .Where(d => onids.Contains(d.Id)) .Select((d, dt) => new DevicePageResponse { FuncsStr = d.Funcs.ToString(), diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs index c6f5104a..e4e1e6f6 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs @@ -551,10 +551,10 @@ public class BalanceService : IBalanceService public async Task GetConsumeNumberAsync() { var devices = await _dbContext.Queryable() - .Where(x => x.Type == DeviceTypeEnumType.Meal) + .Where(x => x.Type == DeviceTypeEnumType.Meal && x.Enable) .ToListAsync(); - var offCount = devices.Where(x => x.Enable == false).Count(); + var offCount = GetOfflineDevicesCount(devices).Count; var places = await _dbContext.Queryable() .ToListAsync(); @@ -592,6 +592,26 @@ public class BalanceService : IBalanceService return res; } + + /// + /// 获取离线设备 + /// + /// + /// + private List GetOfflineDevicesCount(List devices) + { + var list = new List(); + foreach (var device in devices) + { + TimeSpan timeDifference = DateTime.Now - device.ModifiedTime; + if (timeDifference.TotalSeconds > (device.HeartbeatInterval * 3)) + { + list.Add(device); + } + } + return list; + } + private async Task> GetConsumptionTrendsAsync(ConsumptionTrendEnumType type) { var bs = await _dbContext.Queryable() diff --git a/Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs b/Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs index 893859c7..4c7998ae 100644 --- a/Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs +++ b/Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs @@ -75,6 +75,7 @@ public class ApkFIileService : IApkFIileService .Where(x => x.ProductCode == productCode) .Select() .FirstAsync(); + info.ThrowIfNull($"产品{productCode}下没有apk存在"); var url =await RequestDownloadFile(info.Name); var host = Configuration["MinIO:Endpoint"]; From 94ba5beca9763be58402e92ec69437c154b17712 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Mon, 26 Feb 2024 13:50:39 +0800 Subject: [PATCH 059/146] =?UTF-8?q?fix=20=E4=BB=BB=E5=8A=A1=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0door=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TaskAssignment/Job/CreateGetAttendanceJob.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateGetAttendanceJob.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateGetAttendanceJob.cs index 34c614ae..b3b8a00b 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateGetAttendanceJob.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateGetAttendanceJob.cs @@ -25,7 +25,7 @@ public class CreateGetAttendanceJob { var devices = await _dbContext.Queryable() .Where(x => x.Enable) - .Where(x => x.Type == DeviceTypeEnumType.Attendance || (x.Type == DeviceTypeEnumType.Door && x.AsAttendance)) + .Where(x => x.Type == DeviceTypeEnumType.Attendance || (x.Type == DeviceTypeEnumType.Door && x.AsAttendance) || x.Type == DeviceTypeEnumType.Door) .ToListAsync(); var ds = devices.Select(x => x.UniqueNo).ToList(); From afa21b5294de2eeaab8159ce53e06f5ff53b3ed0 Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Mon, 26 Feb 2024 14:14:24 +0800 Subject: [PATCH 060/146] =?UTF-8?q?fix=20=E6=B7=BB=E5=8A=A0=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Implements/DeviceService.cs | 24 +++++++++++++------ .../Services/Implements/BalanceService.cs | 22 ++++++++++++----- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs index 4818fb29..e044f11c 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs @@ -244,13 +244,13 @@ public class DeviceService : IDeviceService .Where(x => x.Type == DeviceTypeEnumType.Attendance && x.Enable) .ToListAsync(); - var offlineNumber = GetOfflineDevicesCount(devices).Count; + var offlineNumber = await GetOfflineDevicesCount(devices); var res = new DeviceNumberResponse { - OfflineNumber = offlineNumber, - TotalNumber = devices.Count(), - OnlineNumber = devices.Count()- offlineNumber + OfflineNumber = offlineNumber.Count, + TotalNumber = devices.Count, + OnlineNumber = devices.Count- offlineNumber.Count }; return res; } @@ -259,12 +259,22 @@ public class DeviceService : IDeviceService /// /// /// - private List GetOfflineDevicesCount(List devices) + private async Task> GetOfflineDevicesCount(List devices) { + var nos = devices.Select(x => x.UniqueNo).ToList(); + var deviceRegistrys = await _dbContext.Queryable() + .Where(x => nos.Contains(x.DeviceUniqueNo)) + .ToListAsync(); + var list = new List(); foreach (var device in devices) { - TimeSpan timeDifference = DateTime.Now - device.ModifiedTime; + var regis = deviceRegistrys.FirstOrDefault(x => x.DeviceUniqueNo == device.UniqueNo); + if (regis == null) + { + continue; + } + TimeSpan timeDifference = DateTime.Now - regis.LastHeartbeatTime; if (timeDifference.TotalSeconds > (device.HeartbeatInterval * 3)) { list.Add(device); @@ -297,7 +307,7 @@ public class DeviceService : IDeviceService .ToListAsync(); //离线 - var offDevices = GetOfflineDevicesCount(devices); + var offDevices =await GetOfflineDevicesCount(devices); var offids = offDevices.Select(x => x.Id).ToList(); if (request.IsOnAndOff) diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs index e4e1e6f6..ac23c1cd 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs @@ -554,7 +554,7 @@ public class BalanceService : IBalanceService .Where(x => x.Type == DeviceTypeEnumType.Meal && x.Enable) .ToListAsync(); - var offCount = GetOfflineDevicesCount(devices).Count; + var offCount = await GetOfflineDevicesCount(devices); var places = await _dbContext.Queryable() .ToListAsync(); @@ -581,9 +581,9 @@ public class BalanceService : IBalanceService var res = new ConsumeNumberResponse { - Total = devices.Count(), - OffNumber = offCount, - PlaceNumber = places.Count(), + Total = devices.Count, + OffNumber = offCount.Count, + PlaceNumber = places.Count, ConsumerableNumber = consumerable, DailyNumber = monthlyCount != 0 ? Math.Abs((int)Math.Ceiling(monthlySpending / monthlyCount)) : 0, Days = days, @@ -598,12 +598,22 @@ public class BalanceService : IBalanceService /// /// /// - private List GetOfflineDevicesCount(List devices) + private async Task> GetOfflineDevicesCount(List devices) { + var nos = devices.Select(x => x.UniqueNo).ToList(); + var deviceRegistrys = await _dbContext.Queryable() + .Where(x => nos.Contains(x.DeviceUniqueNo)) + .ToListAsync(); + var list = new List(); foreach (var device in devices) { - TimeSpan timeDifference = DateTime.Now - device.ModifiedTime; + var regis = deviceRegistrys.FirstOrDefault(x => x.DeviceUniqueNo == device.UniqueNo); + if (regis == null) + { + continue; + } + TimeSpan timeDifference = DateTime.Now - regis.LastHeartbeatTime; if (timeDifference.TotalSeconds > (device.HeartbeatInterval * 3)) { list.Add(device); From d341f43009563aea25b1d45a9493e50c5ba8b80c Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Mon, 26 Feb 2024 14:50:29 +0800 Subject: [PATCH 061/146] =?UTF-8?q?fix=20=E6=96=87=E4=BB=B6=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E4=BF=AE=E6=94=B9=E8=AE=B0=E5=BD=95=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FileOperation/Services/Implements/ApkFIileService.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs b/Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs index 4c7998ae..4f5743aa 100644 --- a/Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs +++ b/Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs @@ -62,6 +62,7 @@ public class ApkFIileService : IApkFIileService entity.VersionCode = request.VersionCode; entity.UpdateMessage = request.UpdateMessage; entity.VersionName = request.VersionName; + entity.Name = fileName; await _dbContext.UpdateAsync(entity); } var newEntity = await _dbContext.Queryable().Where(x => x.ProductCode == request.ProductCode).FirstAsync(); From 3bf049a51ebf2f8a809d2ce710fb3b6dc157015e Mon Sep 17 00:00:00 2001 From: liguoyang Date: Mon, 26 Feb 2024 16:17:59 +0800 Subject: [PATCH 062/146] =?UTF-8?q?fix=20=E4=BC=98=E5=8C=96apilog=E5=92=8C?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E4=B8=8A=E4=BC=A0log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Device/Request/ApiLogRequest.cs | 19 ++-- .../Device/Response/ApiLogResponse.cs | 88 ++++++++++-------- .../Services/Implements/DeviceService.cs | 30 +++---- Src/Dlhis.Basic/Packs/SqlSugarPack.cs | 55 +++++++++--- .../EnumSetting/EnumsController.cs | 24 ++++- Src/Dlhis.Entity/Basic/Entity/ApiLogEntity.cs | 90 +++++++++---------- .../Basic/Entity/GainfoFaceEntity.cs | 2 +- .../Basic/Enums/ApiLogEnumType.cs | 24 ----- Src/Dlhis.Entity/Dlhis.Entity.csproj | 2 +- .../Controllers/DeviceUploadLogsController.cs | 13 --- .../Response/DeviceUploadLogResponse.cs | 7 +- .../Services/IDeviceUploadLogService.cs | 5 +- .../Implements/DeviceUploadLogService.cs | 48 ++++------ 13 files changed, 207 insertions(+), 200 deletions(-) delete mode 100644 Src/Dlhis.Entity/Basic/Enums/ApiLogEnumType.cs diff --git a/Src/Dlhis.Basic/Device/Request/ApiLogRequest.cs b/Src/Dlhis.Basic/Device/Request/ApiLogRequest.cs index 484b5983..03278171 100644 --- a/Src/Dlhis.Basic/Device/Request/ApiLogRequest.cs +++ b/Src/Dlhis.Basic/Device/Request/ApiLogRequest.cs @@ -1,14 +1,13 @@ -using Dlhis.Entity.Basic.Enums; -using Kurisu.Core.DataAccess.Dto; +using Kurisu.Core.DataAccess.Dto; using System.ComponentModel.DataAnnotations; -namespace Dlhis.Basic.Device.Request -{ - public class ApiLogRequest :PageDto - { - public string message { get; set; } +namespace Dlhis.Basic.Device.Request; - [EnumDataType(typeof(ApiLogEnumType)),] - public ApiLogEnumType? Type { get; set; } - } +public class ApiLogRequest : PageDto +{ + /// + /// 日志级别 LogLevel + /// + [EnumDataType(typeof(LogLevel))] + public LogLevel? Level { get; set; } } diff --git a/Src/Dlhis.Basic/Device/Response/ApiLogResponse.cs b/Src/Dlhis.Basic/Device/Response/ApiLogResponse.cs index 3d51efae..38fca5e6 100644 --- a/Src/Dlhis.Basic/Device/Response/ApiLogResponse.cs +++ b/Src/Dlhis.Basic/Device/Response/ApiLogResponse.cs @@ -1,42 +1,56 @@ -using SqlSugar; +using Newtonsoft.Json; -namespace Dlhis.Basic.Device.Response +namespace Dlhis.Basic.Device.Response; + +public class ApiLogResponse { - public class ApiLogResponse + /// + /// 时间UTC + /// + [JsonIgnore] + public string Timestamp { get; set; } + + /// + /// 产生时间 + /// + public DateTime RaiseTime { - /// - /// 时间 - /// - public string Timestamp { get; set; } - - /// - /// 级别 - /// - public string Level { get; set; } - - /// - /// 模板 - /// - public string Template { get; set; } - - /// - /// 消息内容 - /// - public string Message { get; set; } - - /// - /// 异常内容 - /// - public string Exception { get; set; } - - /// - /// 属性 - /// - public string Properties { get; set; } - - /// - /// 时间 - /// - public DateTime _ts { get; set; } + get + { + return DateTime.Parse(Timestamp).ToLocalTime(); + } } + + /// + /// 级别 + /// + public string Level { get; set; } + + /// + /// 模板 + /// + [JsonIgnore] + public string Template { get; set; } + + /// + /// 消息内容 + /// + public string Message { get; set; } + + /// + /// 异常内容 + /// + public string Exception { get; set; } + + /// + /// 属性 + /// + [JsonIgnore] + public string Properties { get; set; } + + /// + /// 时间 + /// + [JsonIgnore] + public DateTime _TS { get; set; } } diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs index e044f11c..f0afeb56 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs @@ -14,6 +14,7 @@ using Kurisu.SqlSugar.Services; using Mapster; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using SqlSugar; namespace Dlhis.Basic.Device.Services.Implements; @@ -247,10 +248,10 @@ public class DeviceService : IDeviceService var offlineNumber = await GetOfflineDevicesCount(devices); var res = new DeviceNumberResponse - { + { OfflineNumber = offlineNumber.Count, TotalNumber = devices.Count, - OnlineNumber = devices.Count- offlineNumber.Count + OnlineNumber = devices.Count - offlineNumber.Count }; return res; } @@ -270,14 +271,14 @@ public class DeviceService : IDeviceService foreach (var device in devices) { var regis = deviceRegistrys.FirstOrDefault(x => x.DeviceUniqueNo == device.UniqueNo); - if (regis == null) + if (regis == null) { continue; } TimeSpan timeDifference = DateTime.Now - regis.LastHeartbeatTime; if (timeDifference.TotalSeconds > (device.HeartbeatInterval * 3)) { - list.Add(device); + list.Add(device); } } return list; @@ -307,7 +308,7 @@ public class DeviceService : IDeviceService .ToListAsync(); //离线 - var offDevices =await GetOfflineDevicesCount(devices); + var offDevices = await GetOfflineDevicesCount(devices); var offids = offDevices.Select(x => x.Id).ToList(); if (request.IsOnAndOff) @@ -372,28 +373,19 @@ public class DeviceService : IDeviceService }; list.Add(res); }); + return list; } public async Task> GetLogsAsync(ApiLogRequest request) { - var level = request.Type.ToString(); - return await Scoped.Request.Value.CreateAsync(async (sp) => - { - var configuration = sp.GetService(); - var logConnectionString = configuration.GetSection("SqlSugarOptions:LogConnectionString").Value; - - //todo 切换连接字符串 - var dbContext = sp.GetService(); - dbContext.Client.CurrentConnectionConfig.ConnectionString = logConnectionString; - var logs = await dbContext.Queryable() - .WhereIF(!request.message.IsEmpty(), x => x.Message.Contains(request.message)) - .WhereIF(!level.IsEmpty(), x => x.Level == level) + var logs = await _dbContext.ChangeDb("log").Queryable() + .WhereIF(request.Search.IsPresent(), x => x.Message.Contains(request.Search)) + .WhereIF(request.Level.HasValue, x => x.Level == request.Level) .Select() .ToPageListAsync(request); - return logs; - }); + return logs; } } diff --git a/Src/Dlhis.Basic/Packs/SqlSugarPack.cs b/Src/Dlhis.Basic/Packs/SqlSugarPack.cs index a54c45cf..b46e77d5 100644 --- a/Src/Dlhis.Basic/Packs/SqlSugarPack.cs +++ b/Src/Dlhis.Basic/Packs/SqlSugarPack.cs @@ -1,4 +1,5 @@ -using Kurisu.AspNetCore; +using Dlhis.Entity.Basic.Entity; +using Kurisu.AspNetCore; using Kurisu.AspNetCore.Startup; using Kurisu.Core.DataAccess.Entity; using Kurisu.SqlSugar.Extensions; @@ -14,26 +15,58 @@ public class SqlSugarPack : BaseAppPack public override void ConfigureServices(IServiceCollection services) { - services.AddSqlSugar(); + services.AddSqlSugar(sp => + { + var configuration = sp.GetService(); + + return new List + { + new ConnectionConfig + { + ConfigId = "face", + + ConnectionString = configuration.GetSection("SqlSugarOptions:FaceConnectionString").Value, + DbType = DbType.MySql, + InitKeyType = InitKeyType.Attribute, + IsAutoCloseConnection = true, + + MoreSettings = new ConnMoreSettings + { + DisableNvarchar = true, + } + }, + new ConnectionConfig + { + ConfigId = "log", + + ConnectionString = configuration.GetSection("SqlSugarOptions:LogConnectionString").Value, + DbType = DbType.MySql, + InitKeyType = InitKeyType.Attribute, + IsAutoCloseConnection = true, + + MoreSettings = new ConnMoreSettings + { + DisableNvarchar = true, + } + }, + }; + }); } public override void Configure(IApplicationBuilder app, IWebHostEnvironment env) { using var scope = app.ApplicationServices.CreateScope(); - var db = scope.ServiceProvider.GetService(); + var db = scope.ServiceProvider.GetService(); var tables = App.ActiveTyps.Where(x => x.IsDefined(typeof(SugarTable), false)) .Where(x => !x.IsDefined(typeof(SkipScanAttribute), false)) .ToArray(); - db.DbMaintenance.CreateDatabase(); - db.CodeFirst.InitTables(tables); + db.Client.DbMaintenance.CreateDatabase(); + db.Client.CodeFirst.InitTables(tables); - //using var scopeFace = app.ApplicationServices.CreateScope(); - //var dbFace = scopeFace.ServiceProvider.GetService(); - //var faceConnectionString = Configuration.GetSection("SqlSugarOptions:FaceConnectionString").Value; - //dbFace.CurrentConnectionConfig.ConnectionString = faceConnectionString; - //dbFace.DbMaintenance.CreateDatabase(); - //dbFace.CodeFirst.InitTables(); + var faceDb = db.ChangeDb("face"); + faceDb.DbMaintenance.CreateDatabase(); + faceDb.CodeFirst.InitTables(); } } diff --git a/Src/Dlhis.Common/EnumSetting/EnumsController.cs b/Src/Dlhis.Common/EnumSetting/EnumsController.cs index f930928c..fde3ebb5 100644 --- a/Src/Dlhis.Common/EnumSetting/EnumsController.cs +++ b/Src/Dlhis.Common/EnumSetting/EnumsController.cs @@ -57,7 +57,6 @@ public class EnumsController : ControllerBase }) .ToList(); - //todo cache 速度 var dbTypes = _dbContext.Queryable().OrderBy(x => x.Sequence).ToList(); var dbResult = dbTypes.GroupBy(x => x.Type).Select(g => { @@ -77,6 +76,29 @@ public class EnumsController : ControllerBase result.AddRange(dbResult); + result.Add(GetCurrentEnums("LogLevel", "日志级别", typeof(LogLevel))); + return result; } + + + private static CommonEnumResponse GetCurrentEnums(string code, string name, Type enumType) + { + return new CommonEnumResponse + { + Code = code, + Name = name, + Data = enumType.GetFields(BindingFlags.Public | BindingFlags.Static).Select(item => + { + var e = (Enum)Enum.Parse(item.FieldType, item.GetValue(null).ToString()); + var fd = e.GetDescription(); + return new KeyValueDto + { + Key = fd, + Value = (int)item.GetValue(null) + }; + }) + .ToList() + }; + } } diff --git a/Src/Dlhis.Entity/Basic/Entity/ApiLogEntity.cs b/Src/Dlhis.Entity/Basic/Entity/ApiLogEntity.cs index 889cbd8c..96ddaa22 100644 --- a/Src/Dlhis.Entity/Basic/Entity/ApiLogEntity.cs +++ b/Src/Dlhis.Entity/Basic/Entity/ApiLogEntity.cs @@ -1,61 +1,55 @@ -using Kurisu.Core.DataAccess.Entity; -using Kurisu.SqlSugar; +using Microsoft.Extensions.Logging; using SqlSugar; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using SqlSugar.DbConvert; -namespace Dlhis.Entity.Basic.Entity +namespace Dlhis.Entity.Basic.Entity; + +/// +/// api日志表 +/// +[SugarTable(TableName = "Logs", TableDescription = "api日志表")] +public class ApiLogEntity { /// - /// api日志表 + /// 时间 /// - [SugarTable(TableName = "Logs", TableDescription = "api日志表")] - public class ApiLogEntity - { - /// - /// 时间 - /// - [SugarColumn(ColumnDescription = "时间")] - public string Timestamp { get; set; } + [SugarColumn(ColumnDescription = "时间")] + public string Timestamp { get; set; } - /// - /// 级别 - /// - [SugarColumn(ColumnDescription = "级别")] - public string Level { get; set; } + /// + /// 级别 + /// + [SugarColumn(ColumnDescription = "级别", SqlParameterDbType = typeof(EnumToStringConvert))] + public LogLevel Level { get; set; } - /// - /// 模板 - /// - [SugarColumn(ColumnDescription = "模板")] - public string Template { get; set; } + /// + /// 模板 + /// + [SugarColumn(ColumnDescription = "模板")] + public string Template { get; set; } - /// - /// 消息内容 - /// - [SugarColumn(ColumnDescription = "消息内容")] - public string Message { get; set; } + /// + /// 消息内容 + /// + [SugarColumn(ColumnDescription = "消息内容")] + public string Message { get; set; } - /// - /// 异常内容 - /// - [SugarColumn(ColumnDescription = "异常内容")] - public string Exception { get; set; } + /// + /// 异常内容 + /// + [SugarColumn(ColumnDescription = "异常内容")] + public string Exception { get; set; } - /// - /// 属性 - /// - [SugarColumn(ColumnDescription = "属性")] - public string Properties { get; set; } + /// + /// 属性 + /// + [SugarColumn(ColumnDescription = "属性")] + public string Properties { get; set; } - /// - /// 时间 - /// - [SugarColumn(ColumnDescription = "时间")] - public DateTime _ts { get; set; } + /// + /// 时间 + /// + [SugarColumn(ColumnDescription = "时间")] + public DateTime _ts { get; set; } - } } diff --git a/Src/Dlhis.Entity/Basic/Entity/GainfoFaceEntity.cs b/Src/Dlhis.Entity/Basic/Entity/GainfoFaceEntity.cs index 8cd7d09c..967ce16f 100644 --- a/Src/Dlhis.Entity/Basic/Entity/GainfoFaceEntity.cs +++ b/Src/Dlhis.Entity/Basic/Entity/GainfoFaceEntity.cs @@ -22,6 +22,6 @@ public class GainfoFaceEntity : SugarBaseEntity /// /// 人脸 /// - [SugarColumn(ColumnDataType = "text", IsNullable = false)] + [SugarColumn(ColumnDataType = "longtext", IsNullable = false)] public string Face { get; set; } } diff --git a/Src/Dlhis.Entity/Basic/Enums/ApiLogEnumType.cs b/Src/Dlhis.Entity/Basic/Enums/ApiLogEnumType.cs deleted file mode 100644 index a65befdd..00000000 --- a/Src/Dlhis.Entity/Basic/Enums/ApiLogEnumType.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Dlhis.Entity.Basic.Enums -{ - /// - /// api日志状态 - /// - [Description("api日志状态")] - public enum ApiLogEnumType - { - Information = 1, - - Warning = 2, - - Error = 3, - - Fatal = 4, - } -} diff --git a/Src/Dlhis.Entity/Dlhis.Entity.csproj b/Src/Dlhis.Entity/Dlhis.Entity.csproj index 6aee2f83..7a8afcc3 100644 --- a/Src/Dlhis.Entity/Dlhis.Entity.csproj +++ b/Src/Dlhis.Entity/Dlhis.Entity.csproj @@ -11,7 +11,7 @@ - + diff --git a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Controllers/DeviceUploadLogsController.cs b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Controllers/DeviceUploadLogsController.cs index ad8f44b7..edbbacb7 100644 --- a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Controllers/DeviceUploadLogsController.cs +++ b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Controllers/DeviceUploadLogsController.cs @@ -34,18 +34,6 @@ public class DeviceUploadLogsController : ControllerBase return await _deviceUploadLogService.GetPageAsync(request); } - /// - /// 上传记录 - /// - /// - /// - [HttpPost("record")] - [IgnoreTenant] - public async Task UploadLogAsync(DeviceUploadLogUploadRequest request) - { - await _deviceUploadLogService.UploadLogAsync(request); - } - /// /// 批量上传记录 /// @@ -57,5 +45,4 @@ public class DeviceUploadLogsController : ControllerBase { await _deviceUploadLogService.UploadLogsAsync(requests); } - } diff --git a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Response/DeviceUploadLogResponse.cs b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Response/DeviceUploadLogResponse.cs index c8de21fd..ca064b79 100644 --- a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Response/DeviceUploadLogResponse.cs +++ b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Response/DeviceUploadLogResponse.cs @@ -1,4 +1,6 @@ -namespace Dlhis.ScheduledTask.DeviceUploadLog.Response; +using Newtonsoft.Json; + +namespace Dlhis.ScheduledTask.DeviceUploadLog.Response; public class DeviceUploadLogResponse { @@ -29,4 +31,7 @@ public class DeviceUploadLogResponse /// 上传时间 /// public DateTime RaiseDateTime { get; set; } + + [JsonIgnore] + public string OriginUserUniqueNo { get; set; } } diff --git a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/IDeviceUploadLogService.cs b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/IDeviceUploadLogService.cs index fa2fed08..cc4a6b3e 100644 --- a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/IDeviceUploadLogService.cs +++ b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/IDeviceUploadLogService.cs @@ -1,5 +1,4 @@ -using Dlhis.Entity.Basic.Entity; -using Dlhis.ScheduledTask.DeviceUploadLog.Request; +using Dlhis.ScheduledTask.DeviceUploadLog.Request; using Dlhis.ScheduledTask.DeviceUploadLog.Response; using Kurisu.Core.DataAccess.Dto; @@ -9,8 +8,6 @@ public interface IDeviceUploadLogService : IScopeDependency { Task> GetPageAsync(DeviceUploadLogPageRequest request); - Task UploadLogAsync(DeviceUploadLogUploadRequest request); - Task UploadLogsAsync(List requests); } diff --git a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs index de3f43fa..c06a159e 100644 --- a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs +++ b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs @@ -1,18 +1,12 @@ -using System.Configuration; -using System.Linq.Expressions; +using System.Linq.Expressions; using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Device.Entities; using Dlhis.ScheduledTask.DeviceUploadLog.Request; using Dlhis.ScheduledTask.DeviceUploadLog.Response; -using Kurisu.AspNetCore.Scope; using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.DataAccess.Dto; -using Kurisu.SqlSugar.Attributes; using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Services; -using Microsoft.AspNetCore.DataProtection; -using Microsoft.AspNetCore.Mvc; -using NetTaste; using SqlSugar; namespace Dlhis.ScheduledTask.DeviceUploadLog.Services.Implements; @@ -29,40 +23,34 @@ public class DeviceUploadLogService : IDeviceUploadLogService public async Task> GetPageAsync(DeviceUploadLogPageRequest request) { var page = await _dbContext.Queryable() - .LeftJoin((deviceUp, ga) => deviceUp.UserUniqueNo == ga.No) .WhereIF(request.SearchDateTimePeriod?.Start.HasValue == true, deviceUp => deviceUp.RaiseDateTime >= request.SearchDateTimePeriod.Start) .WhereIF(request.SearchDateTimePeriod?.End.HasValue == true, deviceUp => deviceUp.RaiseDateTime <= request.SearchDateTimePeriod.End) - .Select((deviceUp, ga) => new DeviceUploadLogResponse + .Select((deviceUp) => new DeviceUploadLogResponse { + OriginUserUniqueNo = deviceUp.UserUniqueNo, DeviceUniqueNo = deviceUp.DeviceUniqueNo, Id = deviceUp.Id, RaiseDateTime = deviceUp.RaiseDateTime, - UserNo = ga.No, - UserCode = ga.Code, - UserName = ga.Name, + //UserNo = ga.No, + //UserCode = ga.Code, + //UserName = ga.Name, }) .ToPageListAsync(request); + var gainfos = await _dbContext.Queryable().ToListAsync(); + page.Data.ForEach(item => + { + _ = int.TryParse(item.OriginUserUniqueNo, out var userId); + + var gainfo = gainfos.FirstOrDefault(x => x.No == item.OriginUserUniqueNo || x.Id == userId || x.Code == item.OriginUserUniqueNo); + item.UserNo = gainfo?.No; + item.UserCode = gainfo?.Code; + item.UserName = gainfo?.Name; + }); + return page; } - public async Task UploadLogAsync(DeviceUploadLogUploadRequest request) - { - var device = await _dbContext.Queryable().Where(x => x.UniqueNo == request.DeviceUniqueNo).SingleAsync(); - device.ThrowIfNull("设备信息不存在"); - - var entity = new DeviceUploadLogEntity - { - DeviceUniqueNo = request.DeviceUniqueNo, - // UploadTime = request.UploadTime, - UserUniqueNo = request.UserUniqueNo, - TenantId = device.TenantId, - }; - - await _dbContext.InsertAsync(entity); - } - - public async Task UploadLogsAsync(List requests) { //判断存在的记录 @@ -105,5 +93,5 @@ public class DeviceUploadLogService : IDeviceUploadLogService await _dbContext.InsertAsync(records); } - + } From 55b6e957fe1613ae428694734a7dbebff1d5c45f Mon Sep 17 00:00:00 2001 From: liguoyang Date: Mon, 26 Feb 2024 16:31:57 +0800 Subject: [PATCH 063/146] =?UTF-8?q?fix=20=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Implements/GainfoService.cs | 209 +++++++----------- Src/Dlhis.ScheduledTask/Program.cs | 5 +- .../Services/Implements/UserService.cs | 1 - 3 files changed, 87 insertions(+), 128 deletions(-) diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs index 42e5dd4a..a0341149 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs @@ -27,6 +27,8 @@ public class GainfoService : IGainfoService private readonly ICurrentUser _currentUser; private readonly IDevicePermissionService _devicePermissionService; private readonly RedisCache _redisCache; + private readonly IServiceProvider _serviceProvider; + private readonly IConfiguration _configuration; private readonly ILogger _logger; public GainfoService(IGainfoStore gainfoStore, @@ -34,6 +36,8 @@ public class GainfoService : IGainfoService ICurrentUser currentUser, IDevicePermissionService devicePermissionService, RedisCache redisCache, + IServiceProvider serviceProvider, + IConfiguration configuration, ILogger logger) { _gainfoStore = gainfoStore; @@ -41,6 +45,8 @@ public class GainfoService : IGainfoService _currentUser = currentUser; _devicePermissionService = devicePermissionService; _redisCache = redisCache; + _serviceProvider = serviceProvider; + _configuration = configuration; _logger = logger; } @@ -168,51 +174,38 @@ public class GainfoService : IGainfoService public async Task GetFaceAsync(string token) { - return await Scoped.Request.Value.CreateAsync(async (sp) => + var timeLimitedDataProtector = _serviceProvider.GetService() + .CreateProtector("down:face") + .ToTimeLimitedDataProtector(); + + try { - var timeLimitedDataProtector = sp.GetService() - .CreateProtector("down:face") - .ToTimeLimitedDataProtector(); + var password = timeLimitedDataProtector.Unprotect(token); + var userCode = password.Split(':')[1]; - try + var faceCache = await _redisCache.HashGetAsync("faces", userCode); + if (faceCache.HasValue) { - var password = timeLimitedDataProtector.Unprotect(token); - var userCode = password.Split(':')[1]; - - var faceCache = await _redisCache.HashGetAsync("faces", userCode); - if (faceCache.HasValue) - { - return new FileContentResult(Convert.FromBase64String(faceCache), "image/png"); - } - - var configuration = sp.GetService(); - var faceConnectionString = configuration.GetSection("SqlSugarOptions:FaceConnectionString").Value; - if (faceConnectionString.IsEmpty()) - { - _logger.LogWarning("暂不支持获取人脸"); - return new NotFoundResult(); - } - - //todo 切换连接字符串 - var dbContext = sp.GetService(); - dbContext.Client.CurrentConnectionConfig.ConnectionString = faceConnectionString; - var face = await dbContext.Queryable().Where(x => x.UserCode == userCode).SingleAsync(); - - if (face == null) - { - _logger.LogWarning("学工号:{userCode}不存在人脸照片", userCode); - return new NotFoundResult(); - } - - await _redisCache.HashSetAsync("faces", userCode, face.Face); - return new FileContentResult(Convert.FromBase64String(face.Face), "image/png"); + return new FileContentResult(Convert.FromBase64String(faceCache), "image/png"); } - catch (Exception ex) + + var dbContext = _dbContext.ChangeDb("face"); + var face = await dbContext.Queryable().Where(x => x.UserCode == userCode).SingleAsync(); + + if (face == null) { - _logger.LogError(ex, "获取人脸失败:" + ex.Message); + _logger.LogWarning("学工号:{userCode}不存在人脸照片", userCode); return new NotFoundResult(); } - }); + + await _redisCache.HashSetAsync("faces", userCode, face.Face); + return new FileContentResult(Convert.FromBase64String(face.Face), "image/png"); + } + catch (Exception ex) + { + _logger.LogError(ex, "获取人脸失败:{message}", ex.Message); + return new NotFoundResult(); + } } public async Task UploadFaceAsync(GainfoUploadFaceRequest request) @@ -222,18 +215,48 @@ public class GainfoService : IGainfoService gainfo.ThrowIfNull("人员档案信息不存在"); - await Scoped.Request.Value.CreateAsync(async (sp) => + var dbContext = _dbContext.ChangeDb("face"); + var face = await dbContext.Queryable().Where(x => x.UserCode == gainfo.Code).SingleAsync(); + + var taskType = face == null ? DeviceTaskEnumType.Add : DeviceTaskEnumType.Update; + + await _redisCache.HashSetAsync("faces", gainfo.Code, request.Face); + if (face == null) { - var configuration = sp.GetService(); - var faceConnectionString = configuration.GetSection("SqlSugarOptions:FaceConnectionString").Value; - if (faceConnectionString.IsEmpty()) + face = new GainfoFaceEntity { - throw new UserFriendlyException("暂不支持人脸上传"); + UserCode = gainfo.Code, + Face = request.Face + }; + + await dbContext.Insertable(face).ExecuteCommandAsync(); + } + else + { + if (face.Face == request.Face) + { + _logger.LogWarning("相同的人脸照片更新忽略"); + return; } - var dbContext = sp.GetService(); - //todo 切换连接字符串 - dbContext.Client.CurrentConnectionConfig.ConnectionString = faceConnectionString; + face.Face = request.Face; + await dbContext.Updateable(face).ExecuteCommandAsync(); + } + + //生成任务 + await _devicePermissionService.GenerateDeviceTasksAsync(gainfo.No, taskType); + } + + public async Task UploadFacesAsync(List requests) + { + foreach (var request in requests) + { + var gainfo = await _gainfoStore.Queryable(GainfoStatusEnumType.Working).Where(x => x.No == request.UserNo).FirstAsync(); + gainfo ??= await _gainfoStore.Queryable(GainfoStatusEnumType.External).Where(x => x.No == request.UserNo).FirstAsync(); + + gainfo.ThrowIfNull("人员档案信息不存在"); + + var dbContext = _dbContext.ChangeDb("face"); var face = await dbContext.Queryable().Where(x => x.UserCode == gainfo.Code).SingleAsync(); var taskType = face == null ? DeviceTaskEnumType.Add : DeviceTaskEnumType.Update; @@ -247,7 +270,7 @@ public class GainfoService : IGainfoService Face = request.Face }; - await dbContext.InsertAsync(face); + await dbContext.Insertable(face).ExecuteCommandAsync(); } else { @@ -258,61 +281,11 @@ public class GainfoService : IGainfoService } face.Face = request.Face; - await dbContext.UpdateAsync(face); + await dbContext.Updateable(face).ExecuteCommandAsync(); } //生成任务 await _devicePermissionService.GenerateDeviceTasksAsync(gainfo.No, taskType); - }); - } - - public async Task UploadFacesAsync(List requests) - { - foreach (var request in requests) - { - var gainfo = await _gainfoStore.Queryable(GainfoStatusEnumType.Working).Where(x => x.No == request.UserNo).FirstAsync(); - gainfo ??= await _gainfoStore.Queryable(GainfoStatusEnumType.External).Where(x => x.No == request.UserNo).FirstAsync(); - - gainfo.ThrowIfNull("人员档案信息不存在"); - - await Scoped.Request.Value.CreateAsync(async (sp) => - { - var configuration = sp.GetService(); - var faceConnectionString = configuration.GetSection("SqlSugarOptions:FaceConnectionString").Value; - - var dbContext = sp.GetService(); - //todo 切换连接字符串 - dbContext.Client.CurrentConnectionConfig.ConnectionString = faceConnectionString; - var face = await dbContext.Queryable().Where(x => x.UserCode == gainfo.Code).SingleAsync(); - - var taskType = face == null ? DeviceTaskEnumType.Add : DeviceTaskEnumType.Update; - - await _redisCache.HashSetAsync("faces", gainfo.Code, request.Face); - if (face == null) - { - face = new GainfoFaceEntity - { - UserCode = gainfo.Code, - Face = request.Face - }; - - await dbContext.InsertAsync(face); - } - else - { - if (face.Face == request.Face) - { - _logger.LogWarning("相同的人脸照片更新忽略"); - return; - } - - face.Face = request.Face; - await dbContext.UpdateAsync(face); - } - - //生成任务 - await _devicePermissionService.GenerateDeviceTasksAsync(gainfo.No, taskType); - }); } } @@ -321,39 +294,25 @@ public class GainfoService : IGainfoService var gainfo = await _dbContext.Queryable().Where(x => x.Code == userCode).SingleAsync(); gainfo.ThrowIfNull($"{userCode}人员信息不存在"); - return await Scoped.Request.Value.CreateAsync(async (sp) => - { - var configuration = sp.GetService(); + var dbContext = _dbContext.ChangeDb("face"); - var faceConnectionString = configuration.GetSection($"{nameof(SqlSugarOptions)}:FaceConnectionString").Value; - if (faceConnectionString.IsEmpty()) - { - throw new UserFriendlyException("暂不支持获取人脸"); - } + var face = await dbContext.Queryable() + .Where(x => x.UserCode == userCode) + .SingleAsync(); - var dbContext = sp.GetService(); - //todo 切换连接字符串 - dbContext.Client.CurrentConnectionConfig.ConnectionString = faceConnectionString; + face.ThrowIfNull("人脸照片尚未录入"); - var face = await dbContext.Queryable() - .Where(x => x.UserCode == userCode) - .SingleAsync(); + var timeLimitedDataProtector = _serviceProvider.GetService() + .CreateProtector("down:face") + .ToTimeLimitedDataProtector(); - face.ThrowIfNull("人脸照片尚未录入"); + var faceUrl = _configuration.GetSection("FaceUrlOptions:Url").Value; + var limit = _configuration.GetSection("FaceUrlOptions:Limit").Get(); - var timeLimitedDataProtector = sp.GetService() - .CreateProtector("down:face") - .ToTimeLimitedDataProtector(); + var key = $"face:{userCode}"; + var token = timeLimitedDataProtector.Protect(key, TimeSpan.FromSeconds(limit)); - var faceUrl = configuration.GetSection("FaceUrlOptions:Url").Value; - var limit = configuration.GetSection("FaceUrlOptions:Limit").Get(); - var dataProtectionProvider = sp.GetService(); - - var key = $"face:{userCode}"; - var token = timeLimitedDataProtector.Protect(key, TimeSpan.FromSeconds(limit)); - - return faceUrl + token; - }); + return faceUrl + token; } public async Task> GetFaceByUserCodesAsync(GetFaceByUserCodesRequest request) diff --git a/Src/Dlhis.ScheduledTask/Program.cs b/Src/Dlhis.ScheduledTask/Program.cs index 259155f7..dd22aac6 100644 --- a/Src/Dlhis.ScheduledTask/Program.cs +++ b/Src/Dlhis.ScheduledTask/Program.cs @@ -1,4 +1,5 @@ using Kurisu.AspNetCore.Startup; +using Kurisu.AspNetCore.Utils; using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Startup; using Microsoft.AspNetCore.DataProtection; @@ -23,8 +24,8 @@ public class Startup : DefaultStartup base.ConfigureServices(services); services.AddRedis(); - //todo - var redis = ConnectionMultiplexer.Connect($"192.168.199.30:30115,defaultDatabase:1,password=dlhis123"); + var reidConnection = Configuration.GetSection($"{nameof(RedisOptions)}:{nameof(RedisOptions.ConnectionString)}").Value; + var redis = ConnectionMultiplexer.Connect(reidConnection); services.AddDataProtection() .SetApplicationName("scheduled") .PersistKeysToStackExchangeRedis(redis, "DataProtection-Keys"); diff --git a/Src/Dlhis.Sys/Identity/Services/Implements/UserService.cs b/Src/Dlhis.Sys/Identity/Services/Implements/UserService.cs index 63a9b19f..88394f60 100644 --- a/Src/Dlhis.Sys/Identity/Services/Implements/UserService.cs +++ b/Src/Dlhis.Sys/Identity/Services/Implements/UserService.cs @@ -48,7 +48,6 @@ public class UserService : IUserService public async Task> GetUsersAsync() { - //todo tenant var users = await _dbContext.Queryable().Select().ToListAsync(); return users; } From b7a6e5e8db76c82800dacb193816d521a3c2a8a3 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Mon, 26 Feb 2024 16:48:04 +0800 Subject: [PATCH 064/146] =?UTF-8?q?fix=20=E5=8D=87=E7=BA=A7changedb;=20?= =?UTF-8?q?=E5=A4=84=E7=90=86=E4=BA=BA=E8=84=B8token=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Implements/GainfoService.cs | 8 +++---- Src/Dlhis.Basic/Packs/DataProtectionJob.cs | 2 +- Src/Dlhis.Basic/Packs/SqlSugarPack.cs | 4 ++-- Src/Dlhis.Entity/Dlhis.Entity.csproj | 2 +- Src/Dlhis.ScheduledTask/Program.cs | 2 +- Src/Dlhis.Sys/SqlSugarPack.cs | 23 ++++++++++++++++++- 6 files changed, 31 insertions(+), 10 deletions(-) diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs index a0341149..85656105 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs @@ -229,7 +229,7 @@ public class GainfoService : IGainfoService Face = request.Face }; - await dbContext.Insertable(face).ExecuteCommandAsync(); + await dbContext.InsertAsync(face); } else { @@ -240,7 +240,7 @@ public class GainfoService : IGainfoService } face.Face = request.Face; - await dbContext.Updateable(face).ExecuteCommandAsync(); + await dbContext.UpdateAsync(face); } //生成任务 @@ -270,7 +270,7 @@ public class GainfoService : IGainfoService Face = request.Face }; - await dbContext.Insertable(face).ExecuteCommandAsync(); + await dbContext.InsertAsync(face); } else { @@ -281,7 +281,7 @@ public class GainfoService : IGainfoService } face.Face = request.Face; - await dbContext.Updateable(face).ExecuteCommandAsync(); + await dbContext.UpdateAsync(face); } //生成任务 diff --git a/Src/Dlhis.Basic/Packs/DataProtectionJob.cs b/Src/Dlhis.Basic/Packs/DataProtectionJob.cs index 0e78ff97..9bb6e44b 100644 --- a/Src/Dlhis.Basic/Packs/DataProtectionJob.cs +++ b/Src/Dlhis.Basic/Packs/DataProtectionJob.cs @@ -13,7 +13,7 @@ public class DataProtectionJobPack : BaseAppPack { var redisConnection = ConnectionMultiplexer.Connect(Configuration.GetSection($"{nameof(RedisOptions)}:{nameof(RedisOptions.ConnectionString)}").Value); services.AddDataProtection() - .SetApplicationName("basic") + .SetApplicationName("yiliantong") .PersistKeysToStackExchangeRedis(redisConnection, "DataProtection-Keys"); } } diff --git a/Src/Dlhis.Basic/Packs/SqlSugarPack.cs b/Src/Dlhis.Basic/Packs/SqlSugarPack.cs index b46e77d5..6979080e 100644 --- a/Src/Dlhis.Basic/Packs/SqlSugarPack.cs +++ b/Src/Dlhis.Basic/Packs/SqlSugarPack.cs @@ -65,8 +65,8 @@ public class SqlSugarPack : BaseAppPack db.Client.CodeFirst.InitTables(tables); var faceDb = db.ChangeDb("face"); - faceDb.DbMaintenance.CreateDatabase(); - faceDb.CodeFirst.InitTables(); + faceDb.Client.DbMaintenance.CreateDatabase(); + faceDb.Client.CodeFirst.InitTables(); } } diff --git a/Src/Dlhis.Entity/Dlhis.Entity.csproj b/Src/Dlhis.Entity/Dlhis.Entity.csproj index 7a8afcc3..09f988da 100644 --- a/Src/Dlhis.Entity/Dlhis.Entity.csproj +++ b/Src/Dlhis.Entity/Dlhis.Entity.csproj @@ -11,7 +11,7 @@ - + diff --git a/Src/Dlhis.ScheduledTask/Program.cs b/Src/Dlhis.ScheduledTask/Program.cs index dd22aac6..64b4094a 100644 --- a/Src/Dlhis.ScheduledTask/Program.cs +++ b/Src/Dlhis.ScheduledTask/Program.cs @@ -27,7 +27,7 @@ public class Startup : DefaultStartup var reidConnection = Configuration.GetSection($"{nameof(RedisOptions)}:{nameof(RedisOptions.ConnectionString)}").Value; var redis = ConnectionMultiplexer.Connect(reidConnection); services.AddDataProtection() - .SetApplicationName("scheduled") + .SetApplicationName("yiliantong") .PersistKeysToStackExchangeRedis(redis, "DataProtection-Keys"); } diff --git a/Src/Dlhis.Sys/SqlSugarPack.cs b/Src/Dlhis.Sys/SqlSugarPack.cs index 59e2db32..3c58cc41 100644 --- a/Src/Dlhis.Sys/SqlSugarPack.cs +++ b/Src/Dlhis.Sys/SqlSugarPack.cs @@ -13,7 +13,28 @@ public class SqlSugarPack : BaseAppPack public override void ConfigureServices(IServiceCollection services) { - services.AddSqlSugar(); + services.AddSqlSugar(sp => + { + var configuration = sp.GetService(); + + return new List + { + new ConnectionConfig + { + ConfigId = "identity", + + ConnectionString = configuration.GetSection("SqlSugarOptions:IdentityConnectionString").Value, + DbType = DbType.MySql, + InitKeyType = InitKeyType.Attribute, + IsAutoCloseConnection = true, + + MoreSettings = new ConnMoreSettings + { + DisableNvarchar = true, + } + } + }; + }); } } From 96f89fa8d5ec3a3a5c66a78c35cafa698ce90b31 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Mon, 26 Feb 2024 17:49:36 +0800 Subject: [PATCH 065/146] =?UTF-8?q?fix=20=E4=B8=8A=E4=BC=A0=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E5=A2=9E=E5=8A=A0serialno=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DeviceUploadLog/Response/DeviceUploadLogResponse.cs | 7 +++++++ .../Services/Implements/DeviceUploadLogService.cs | 1 + 2 files changed, 8 insertions(+) diff --git a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Response/DeviceUploadLogResponse.cs b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Response/DeviceUploadLogResponse.cs index ca064b79..47c6039d 100644 --- a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Response/DeviceUploadLogResponse.cs +++ b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Response/DeviceUploadLogResponse.cs @@ -32,6 +32,13 @@ public class DeviceUploadLogResponse /// public DateTime RaiseDateTime { get; set; } + + /// + /// 序列号 + /// + public string SerialNo { get; set; } + + [JsonIgnore] public string OriginUserUniqueNo { get; set; } } diff --git a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs index c06a159e..1397e0da 100644 --- a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs +++ b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs @@ -31,6 +31,7 @@ public class DeviceUploadLogService : IDeviceUploadLogService DeviceUniqueNo = deviceUp.DeviceUniqueNo, Id = deviceUp.Id, RaiseDateTime = deviceUp.RaiseDateTime, + SerialNo = deviceUp.SerialNo, //UserNo = ga.No, //UserCode = ga.Code, //UserName = ga.Name, From 33beb39408432828f15d6fe41936c175a47a0bea Mon Sep 17 00:00:00 2001 From: liguoyang Date: Mon, 26 Feb 2024 17:50:22 +0800 Subject: [PATCH 066/146] =?UTF-8?q?fix=20=E4=BB=BB=E5=8A=A1=E7=94=9F?= =?UTF-8?q?=E6=88=90=E9=80=BB=E8=BE=91=E5=8F=96=E5=8F=8D=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TaskAssignment/Job/CreateSyncServerDateTimeJob.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateSyncServerDateTimeJob.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateSyncServerDateTimeJob.cs index 3729ea1b..35a3ecce 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateSyncServerDateTimeJob.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateSyncServerDateTimeJob.cs @@ -1,6 +1,7 @@ using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Device.Entities; using Dlhis.Entity.Device.Enums; +using Kurisu.Core.DataAccess.Entity; using Kurisu.SqlSugar.Services; namespace Dlhis.ScheduledTask.TaskAssignment.Job @@ -19,16 +20,18 @@ namespace Dlhis.ScheduledTask.TaskAssignment.Job public async Task RunAsync() { - _dbContext.Client.QueryFilter.ClearAndBackup(); + _dbContext.Client.QueryFilter.ClearAndBackup(); try { - var deviceUniqueNos = await _dbContext.Queryable().Where(x => x.Status == DeviceTaskStatusEnumType.Wait) + var deviceUniqueNos = await _dbContext.Queryable() + .Where(x => x.Status == DeviceTaskStatusEnumType.Wait || x.Status == DeviceTaskStatusEnumType.Process) .Where(x => x.Type == DeviceTaskEnumType.SyncDateTime) .Select(x => x.DeviceUniqueNo) + .Distinct() .ToListAsync(); var devices = await _dbContext.Queryable() - .Where(x => deviceUniqueNos.Contains(x.UniqueNo)) + .Where(x => !deviceUniqueNos.Contains(x.UniqueNo)) .Where(x => x.Enable) .ToListAsync(); @@ -54,7 +57,7 @@ namespace Dlhis.ScheduledTask.TaskAssignment.Job } catch (Exception ex) { - _logger.LogError(ex, "生成同步时间任务失败:" + ex.Message); + _logger.LogError(ex, "生成同步时间任务失败:{message}", ex.Message); } finally { From 87d7d62c20da3608a391873367d6b98897eb8e61 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 27 Feb 2024 12:25:42 +0800 Subject: [PATCH 067/146] =?UTF-8?q?fix=20=E4=BB=BB=E5=8A=A1=E7=94=9F?= =?UTF-8?q?=E6=88=90=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Request/DevicePermissionSaveReuqest.cs | 7 +- .../Device/Services/IDeviceService.cs | 2 - .../Implements/DevicePermissionService.cs | 229 ++++++++---------- .../Response/AttendanceDeviceSummary.cs | 7 +- .../Services/Implements/SummaryService.cs | 2 +- .../Sys/Enums/AssignTypeEnumType.cs | 2 +- Src/Dlhis.ScheduledTask/Packs/HangfirePack.cs | 2 +- 7 files changed, 111 insertions(+), 140 deletions(-) diff --git a/Src/Dlhis.Basic/Device/Request/DevicePermissionSaveReuqest.cs b/Src/Dlhis.Basic/Device/Request/DevicePermissionSaveReuqest.cs index 5bca130a..f9efc594 100644 --- a/Src/Dlhis.Basic/Device/Request/DevicePermissionSaveReuqest.cs +++ b/Src/Dlhis.Basic/Device/Request/DevicePermissionSaveReuqest.cs @@ -12,9 +12,12 @@ public class DevicePermissionSaveReuqest public AssignTypeEnumType AssignType { get; set; } /// - /// 人员档案号 + /// 分配值 /// - [Required(ErrorMessage = "人员档案号不能为空")] + /// + /// 如果为用户,那么AssignValue=UserNo + /// + [Required(ErrorMessage = "分配值不能为空")] public string AssignValue { get; set; } /// diff --git a/Src/Dlhis.Basic/Device/Services/IDeviceService.cs b/Src/Dlhis.Basic/Device/Services/IDeviceService.cs index 8af87410..b6ab81bf 100644 --- a/Src/Dlhis.Basic/Device/Services/IDeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/IDeviceService.cs @@ -1,8 +1,6 @@ using Dlhis.Basic.Device.Request; using Dlhis.Basic.Device.Response; -using Dlhis.Entity.Basic.Entity; using Kurisu.Core.DataAccess.Dto; -using Microsoft.AspNetCore.Mvc; namespace Dlhis.Basic.Device.Services; diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs index 4c494bcc..7575648b 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs @@ -7,7 +7,6 @@ using Dlhis.Entity.Sys.Entities; using Dlhis.Entity.Sys.Enums; using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.DataAccess.Dto; -using Kurisu.SqlSugar.Attributes; using Kurisu.SqlSugar.Services; namespace Dlhis.Basic.Device.Services.Implements; @@ -25,7 +24,6 @@ public class DevicePermissionService : IDevicePermissionService { await GenerateDeviceTasksAsync(async () => { - var p = await _dbContext.Queryable() .Where(x => x.AssignType == reuqest.AssignType) .Where(x => x.AssignValue == reuqest.AssignValue) @@ -34,50 +32,27 @@ public class DevicePermissionService : IDevicePermissionService await _dbContext.DeleteReallyAsync(p); - var devicePermissions = reuqest.Codes.Select(x => new DevicePermissionEntity + var devicePermissions = reuqest.Codes.Select(grpOrDeviceCode => new DevicePermissionEntity { AssignType = reuqest.AssignType, AssignValue = reuqest.AssignValue, UniqueType = reuqest.UniqueType, - UniqueValue = x, + UniqueValue = grpOrDeviceCode, }).ToList(); - await _dbContext.InsertAsync(devicePermissions); + if (devicePermissions.Any()) + await _dbContext.InsertAsync(devicePermissions); }, null); } public async Task> GetAssignmentsAsync(DeviceAssignmentTypeEnumType uniqueType, AssignTypeEnumType assignType, string assignValue) { - var devicePermissions = await _dbContext.Queryable() - .Where(x => x.UniqueType == uniqueType) - .Where(x => x.AssignType == assignType) - .Where(x => x.AssignValue == assignValue) - .Select(x => x.UniqueValue) - .ToListAsync(); + var devicePermissions = await _dbContext.Queryable().ToListAsync(); + var deviceGroups = await _dbContext.Queryable().ToListAsync(); - if (uniqueType == DeviceAssignmentTypeEnumType.Group) - { - var deviceGroups = await _dbContext.Queryable().ToListAsync(); - var tops = deviceGroups.Where(x => !x.PCode.HasValue).ToList(); - tops.ForEach(x => - { - RecursionGetNext(x, deviceGroups, devicePermissions, devicePermissions.Contains(x.Code)); - }); - } - - return devicePermissions.Distinct().ToList(); - - void RecursionGetNext(DeviceGroupEntity current, List deviceGroups, List result, bool add) - { - var next = deviceGroups.Where(x => x.PCode == current.Code).ToList(); - foreach (var item in next) - { - if (add) result.Add(item.Code); - RecursionGetNext(item, deviceGroups, result, result.Contains(item.Code)); - } - } + return GetAssignmentsInternal(devicePermissions, deviceGroups, uniqueType, assignType, assignValue); } @@ -88,20 +63,18 @@ public class DevicePermissionService : IDevicePermissionService userNos = await GetPermissionUserNosAsync(); } - var beforeDic = await GetAssignDeviceCodesAsync(userNos); + var beforeDic = await GetAssignDeviceCodesInternalAsync(userNos); //获取处理 await func(); - //获取当前的权限code - var nextUserNos = await GetPermissionUserNosAsync(); if (nextUserNos.Any()) { userNos = nextUserNos; } - var currentDic = await GetAssignDeviceCodesAsync(userNos); + var currentDic = await GetAssignDeviceCodesInternalAsync(userNos); var deivces = await _dbContext.Queryable().ToListAsync(); foreach (var userNo in userNos) @@ -181,7 +154,6 @@ public class DevicePermissionService : IDevicePermissionService }) .SingleAsync(); - var tasks = deviceCodes.Select(x => new DeviceTaskEntity { DeviceUniqueNo = deivces.First(item => item.Code == x).UniqueNo, @@ -215,124 +187,58 @@ public class DevicePermissionService : IDevicePermissionService public async Task> GetAssignDeviceCodesAsync(string userNo) { var gainfo = await _dbContext.Queryable().Where(x => x.No == userNo).SingleAsync(); - var gainfoGroups = await _dbContext.Queryable().Where(x => x.UserNo == userNo).Select(x => x.GroupCode).ToListAsync(); + var gainfoGroups = await _dbContext.Queryable().ToListAsync(); + var devicePermissions = await _dbContext.Queryable().ToListAsync(); + var deviceGroups = await _dbContext.Queryable().ToListAsync(); + var deviceRelationships = await _dbContext.Queryable().ToListAsync(); + + return GetAssignDeviceCodesInternal(new List { gainfo }, gainfoGroups, devicePermissions, deviceGroups, deviceRelationships, userNo); + } + + public List GetAssignDeviceCodesInternal(List gainfos, + List gainfoGroupRelationships, + List devicePermissions, + List deviceGroups, + List deviceGroupRelationships, + string userNo) + { var deviceCodes = new List(); var deviceGroupCodes = new List(); - var du = await GetAssignmentsAsync(DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.User, userNo); - var gu = await GetAssignmentsAsync(DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.User, userNo); + var gainfo = gainfos.Where(x => x.No == userNo).FirstOrDefault(); + var gainfoGroups = gainfoGroupRelationships.Where(x => x.UserNo == userNo).Select(x => x.GroupCode).ToList(); + + var du = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.User, userNo); + var gu = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.User, userNo); deviceCodes.AddRange(du); deviceGroupCodes.AddRange(gu); foreach (var group in gainfoGroups) { - var dg = await GetAssignmentsAsync(DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Group, group.ToString()); - var gg = await GetAssignmentsAsync(DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Group, group.ToString()); + var dg = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Group, group.ToString()); + var gg = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Group, group.ToString()); deviceCodes.AddRange(dg); deviceGroupCodes.AddRange(gg); } - var dd = await GetAssignmentsAsync(DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Department, gainfo.DepartmentNo); - var gd = await GetAssignmentsAsync(DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Department, gainfo.DepartmentNo); + var dd = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Department, gainfo.DepartmentNo); + var gd = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Department, gainfo.DepartmentNo); deviceCodes.AddRange(dd); deviceGroupCodes.AddRange(gd); - var dt = await GetAssignmentsAsync(DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Tenant, gainfo.Werks); - var gt = await GetAssignmentsAsync(DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Tenant, gainfo.Werks); + var dt = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Tenant, gainfo.Werks); + var gt = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Tenant, gainfo.Werks); deviceCodes.AddRange(du); deviceGroupCodes.AddRange(gu); - var deveiceCodesByGroup = await _dbContext.Queryable().Where(x => deviceGroupCodes.Contains(x.GroupCode)).Select(x => x.DeviceCode).ToListAsync(); + var deveiceCodesByGroup = deviceGroupRelationships.Where(x => deviceGroupCodes.Contains(x.GroupCode)).Select(x => x.DeviceCode).ToList(); deviceCodes.AddRange(deveiceCodesByGroup); return deviceCodes.Distinct().ToList(); } - private async Task>> GetAssignDeviceCodesAsync(List userNos) - { - var gainfos = await _dbContext.Queryable().Where(x => userNos.Contains(x.No)).ToListAsync(); - if (!gainfos.Any()) - { - return new Dictionary>(); - } - var gainfoGroupRelationships = await _dbContext.Queryable().ToListAsync(); - var devicePermissions = await _dbContext.Queryable().ToListAsync(); - var deviceGroups = await _dbContext.Queryable().ToListAsync(); - var result = new Dictionary>(); - - foreach (var gainfo in gainfos) - { - var userNo = gainfo.No; - - var gainfoGroups = gainfoGroupRelationships.Where(x => x.UserNo == userNo).ToList(); - - var deviceCodes = new List(); - var deviceGroupCodes = new List(); - - var du = GetAssignmentsInternal(DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.User, userNo); - var gu = GetAssignmentsInternal(DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.User, userNo); - deviceCodes.AddRange(du); - deviceGroupCodes.AddRange(gu); - - foreach (var group in gainfoGroups) - { - var dg = GetAssignmentsInternal(DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Group, group.ToString()); - var gg = GetAssignmentsInternal(DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Group, group.ToString()); - deviceCodes.AddRange(dg); - deviceGroupCodes.AddRange(gg); - } - - var dd = GetAssignmentsInternal(DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Department, gainfo.DepartmentNo); - var gd = GetAssignmentsInternal(DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Department, gainfo.DepartmentNo); - deviceCodes.AddRange(dd); - deviceGroupCodes.AddRange(gd); - - var dt = GetAssignmentsInternal(DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Tenant, gainfo.Werks); - var gt = GetAssignmentsInternal(DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Tenant, gainfo.Werks); - deviceCodes.AddRange(du); - deviceGroupCodes.AddRange(gu); - - var deveiceCodesByGroup = await _dbContext.Queryable().Where(x => deviceGroupCodes.Contains(x.GroupCode)).Select(x => x.DeviceCode).ToListAsync(); - deviceCodes.AddRange(deveiceCodesByGroup); - - result.Add(userNo, deviceCodes.Distinct().ToList()); - } - - return result; - - - List GetAssignmentsInternal(DeviceAssignmentTypeEnumType uniqueTypeInternal, AssignTypeEnumType assignTypeInternal, string assignValueInternal) - { - var devicePermissionsInternal = devicePermissions.Where(x => x.UniqueType == uniqueTypeInternal) - .Where(x => x.AssignType == assignTypeInternal) - .Where(x => x.AssignValue == assignValueInternal) - .Select(x => x.UniqueValue) - .ToList(); - - if (uniqueTypeInternal == DeviceAssignmentTypeEnumType.Group) - { - var tops = deviceGroups.Where(x => !x.PCode.HasValue).ToList(); - tops.ForEach(x => - { - RecursionGetNext(x, deviceGroups, devicePermissionsInternal, devicePermissionsInternal.Contains(x.Code)); - }); - } - - return devicePermissionsInternal.Distinct().ToList(); - - void RecursionGetNext(DeviceGroupEntity current, List deviceGroups, List result, bool add) - { - var next = deviceGroups.Where(x => x.PCode == current.Code).ToList(); - foreach (var item in next) - { - if (add) result.Add(item.Code); - RecursionGetNext(item, deviceGroups, result, result.Contains(item.Code)); - } - } - } - } /// /// 获取用户权限设备 @@ -412,8 +318,67 @@ public class DevicePermissionService : IDevicePermissionService var tenants = permissions.Where(x => x.AssignType == AssignTypeEnumType.Tenant).Select(x => x.AssignValue).ToList(); var userNosByWerk = await _dbContext.Queryable().Where(x => tenants.Contains(x.Werks)).Select(x => x.No).ToListAsync(); - - return userNos.Concat(userNosByGroup).Concat(userNosByDepartment).Concat(userNosByWerk).ToList(); + return userNos.Concat(userNosByGroup).Concat(userNosByDepartment).Concat(userNosByWerk).Distinct().ToList(); } + + private static List GetAssignmentsInternal( + List devicePermissions, List deviceGroups, + DeviceAssignmentTypeEnumType uniqueType, AssignTypeEnumType assignType, string assignValue) + { + var devicePermissionCodes = devicePermissions + .Where(x => x.UniqueType == uniqueType) + .Where(x => x.AssignType == assignType) + .Where(x => x.AssignValue == assignValue) + .Select(x => x.UniqueValue).ToList(); + + //处理获取设备组的情况,递归到最下级获取设备code + if (uniqueType == DeviceAssignmentTypeEnumType.Group) + { + var tops = deviceGroups.Where(x => !x.PCode.HasValue).ToList(); + tops.ForEach(x => + { + RecursionGetNext(x, deviceGroups, devicePermissionCodes, devicePermissionCodes.Contains(x.Code)); + }); + } + + return devicePermissionCodes.Distinct().ToList(); + + void RecursionGetNext(DeviceGroupEntity current, List deviceGroups, List result, bool add) + { + var next = deviceGroups.Where(x => x.PCode == current.Code).ToList(); + foreach (var item in next) + { + if (add) result.Add(item.Code); + RecursionGetNext(item, deviceGroups, result, result.Contains(item.Code)); + } + } + } + + + private async Task>> GetAssignDeviceCodesInternalAsync(List userNos) + { + var gainfos = await _dbContext.Queryable().Where(x => userNos.Contains(x.No)).ToListAsync(); + if (!gainfos.Any()) + { + return new Dictionary>(); + } + + var gainfoGroupRelationships = await _dbContext.Queryable().ToListAsync(); + var devicePermissions = await _dbContext.Queryable().ToListAsync(); + var deviceGroups = await _dbContext.Queryable().ToListAsync(); + var deviceRelationships = await _dbContext.Queryable().ToListAsync(); + + var result = new Dictionary>(); + + foreach (var gainfo in gainfos) + { + var userNo = gainfo.No; + var codes = GetAssignDeviceCodesInternal(gainfos, gainfoGroupRelationships, devicePermissions, deviceGroups, deviceRelationships, userNo); + + result.Add(userNo, codes); + } + + return result; + } } diff --git a/Src/Dlhis.Basic/Summary/Response/AttendanceDeviceSummary.cs b/Src/Dlhis.Basic/Summary/Response/AttendanceDeviceSummary.cs index c0ebc007..77a92955 100644 --- a/Src/Dlhis.Basic/Summary/Response/AttendanceDeviceSummary.cs +++ b/Src/Dlhis.Basic/Summary/Response/AttendanceDeviceSummary.cs @@ -12,13 +12,18 @@ public class AttendanceDeviceSummary /// /// 在线数 /// - public int OnlineCount { get; set; } + public int OnlineCount { get; set; } /// /// 启用数 /// public int EnableCount { get; set; } + /// + /// 离线数 + /// + public int OfflineCount => Total - OnlineCount; + /// /// 新增设备趋势 30天内 /// diff --git a/Src/Dlhis.Basic/Summary/Services/Implements/SummaryService.cs b/Src/Dlhis.Basic/Summary/Services/Implements/SummaryService.cs index 38e03872..d1c15b1c 100644 --- a/Src/Dlhis.Basic/Summary/Services/Implements/SummaryService.cs +++ b/Src/Dlhis.Basic/Summary/Services/Implements/SummaryService.cs @@ -53,7 +53,7 @@ public class SummaryService : ISummaryService { if (x.HeartbeatInterval <= 0) { - return false; + return true; } return x.LastHeartbeatTime.AddSeconds(x.HeartbeatInterval * 3) >= now; diff --git a/Src/Dlhis.Entity/Sys/Enums/AssignTypeEnumType.cs b/Src/Dlhis.Entity/Sys/Enums/AssignTypeEnumType.cs index f41385d5..c4dcdf1b 100644 --- a/Src/Dlhis.Entity/Sys/Enums/AssignTypeEnumType.cs +++ b/Src/Dlhis.Entity/Sys/Enums/AssignTypeEnumType.cs @@ -21,7 +21,7 @@ public enum AssignTypeEnumType Role = 2, /// - /// 组别 + /// 用户组别 /// [Description("组别")] Group = 3, diff --git a/Src/Dlhis.ScheduledTask/Packs/HangfirePack.cs b/Src/Dlhis.ScheduledTask/Packs/HangfirePack.cs index 2fc2c372..9e90db6e 100644 --- a/Src/Dlhis.ScheduledTask/Packs/HangfirePack.cs +++ b/Src/Dlhis.ScheduledTask/Packs/HangfirePack.cs @@ -48,7 +48,7 @@ public class HangfirePack : BaseAppPack new BasicAuthAuthorizationUser { Login ="admin", - PasswordClear = "admin" + PasswordClear = "dlhis123" } } }) From da9e7db35959750f4162ac85899acdf648acd10d Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 27 Feb 2024 12:44:48 +0800 Subject: [PATCH 068/146] =?UTF-8?q?fix=20userNos=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Device/Services/Implements/DevicePermissionService.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs index 7575648b..8a5579f4 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs @@ -71,7 +71,7 @@ public class DevicePermissionService : IDevicePermissionService var nextUserNos = await GetPermissionUserNosAsync(); if (nextUserNos.Any()) { - userNos = nextUserNos; + userNos = userNos.Concat(nextUserNos).Distinct().ToList(); } var currentDic = await GetAssignDeviceCodesInternalAsync(userNos); @@ -79,6 +79,7 @@ public class DevicePermissionService : IDevicePermissionService var deivces = await _dbContext.Queryable().ToListAsync(); foreach (var userNo in userNos) { + beforeDic.TryGetValue(userNo, out var beforeCodes); beforeCodes ??= new List(); @@ -100,7 +101,6 @@ public class DevicePermissionService : IDevicePermissionService addItems = addItems.Where(x => deviceCodes.Contains(x)).ToList(); var userInfo = await _dbContext.Queryable() - .LeftJoin((ga, department) => department.No == ga.DepartmentNo) .Where(ga => ga.No == userNo) .Select(ga => new { From e4206131bbe09d2227efc80a079aa9230b010299 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 27 Feb 2024 15:01:34 +0800 Subject: [PATCH 069/146] =?UTF-8?q?fix=20=E5=AE=9E=E4=BD=93=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Entity/Basic/Entity/GainfoEntity.cs | 54 ++++++++++++++----- .../Device/Entities/DeviceTask.cs | 4 -- 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/Src/Dlhis.Entity/Basic/Entity/GainfoEntity.cs b/Src/Dlhis.Entity/Basic/Entity/GainfoEntity.cs index 66ff9e59..d1462881 100644 --- a/Src/Dlhis.Entity/Basic/Entity/GainfoEntity.cs +++ b/Src/Dlhis.Entity/Basic/Entity/GainfoEntity.cs @@ -14,7 +14,7 @@ public class GainfoEntity : SugarBaseEntity /// /// 档案号 /// - [SugarColumn(ColumnDescription = "档案号")] + [SugarColumn(ColumnDescription = "档案号", UniqueGroupNameList = new[] { "idx_Gainfo_No" })] public string No { get; set; } /// @@ -44,7 +44,7 @@ public class GainfoEntity : SugarBaseEntity /// /// 学工号 /// - [SugarColumn(ColumnDescription = "学工号")] + [SugarColumn(ColumnDescription = "学工号", UniqueGroupNameList = new[] { "idx_Gainfo_Code" })] public string Code { get; set; } /// @@ -128,7 +128,7 @@ public class GainfoEntity : SugarBaseEntity /// /// 卡号 /// - [SugarColumn(ColumnDescription = "卡号")] + [SugarColumn(ColumnDescription = "卡号", IndexGroupNameList = new[] { "idx_Gainfo_CardNo" })] public string CardNo { get; set; } /// @@ -149,19 +149,47 @@ public class GainfoEntity : SugarBaseEntity public string CostId { get; set; } /// - /// 身份认证用户Id + /// 身份认证用户Id /// - [SugarColumn(ColumnDescription = "身份认证用户Id")] + [SugarColumn(ColumnDescription = "身份认证用户Id", IndexGroupNameList = new[] { "idx_Gainfo_IdentityUserId" })] public int IdentityUserId { get; set; } } -//[SugarTable(TableName = "GainfoLeave", TableDescription = "离职人员档案表")] -//public class GainfoLeaveEntity : GainfoEntity -//{ +/// +/// 离职人员档案表 +/// +[SugarTable(TableName = "GainfoLeave", TableDescription = "离职人员档案表")] +public class GainfoLeaveEntity : GainfoEntity +{ +} -//} -//[SugarTable(TableName = "GainfoExternal", TableDescription = "外部人员档案表")] -//public class GainfoExternalEntity : GainfoEntity -//{ +/// +/// 外部人员档案表 +/// +[SugarTable(TableName = "GainfoExternal", TableDescription = "外部人员档案表")] +public class GainfoExternalEntity : GainfoEntity +{ + /// + /// 公司 + /// + [SugarColumn(ColumnDescription = "公司", IsNullable = false)] + public string Company { get; set; } -//} + /// + /// 到达时间 + /// + [SugarColumn(ColumnDescription = "到达时间")] + public DateTime From { get; set; } + + /// + /// 离开时间 + /// + [SugarColumn(ColumnDescription = "离开时间")] + public DateTime To { get; set; } + + /// + /// 对接人No + /// + [SugarColumn(ColumnDescription = "对接人", IsNullable = false)] + public string JinkoNo { get; set; } +} diff --git a/Src/Dlhis.Entity/Device/Entities/DeviceTask.cs b/Src/Dlhis.Entity/Device/Entities/DeviceTask.cs index 4d0b5a4b..84708348 100644 --- a/Src/Dlhis.Entity/Device/Entities/DeviceTask.cs +++ b/Src/Dlhis.Entity/Device/Entities/DeviceTask.cs @@ -23,10 +23,6 @@ public class DeviceTaskEntity : SugarBaseEntity, ITenantId, IVersion /// public string UserNo { get; set; } - /// - /// 用户学工号 - /// - public string UserCode { get; set; } /// /// 设备唯一号 From 6b08cb58a348392c13b2a5a53a45cd2caa61b783 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 27 Feb 2024 15:02:14 +0800 Subject: [PATCH 070/146] =?UTF-8?q?fix=20=E5=A2=9E=E5=8A=A0redis=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E4=BC=98=E5=8C=96=E9=80=9F=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DevicePermissionsController.cs | 3 +- .../Implements/DevicePermissionService.cs | 70 +++++++++++++------ .../Services/Implements/SummaryService.cs | 3 +- .../Job/CreateGetAttendanceJob.cs | 1 - .../Job/CreateSyncServerDateTimeJob.cs | 1 - .../Services/Implements/AssignmentService.cs | 25 +++---- .../Implements/DeviceTaskAssignmentService.cs | 7 +- 7 files changed, 63 insertions(+), 47 deletions(-) diff --git a/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs b/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs index 14ba9f29..9462d88e 100644 --- a/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs +++ b/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs @@ -1,4 +1,5 @@ -using Dlhis.Basic.Device.Request; +using System.Diagnostics; +using Dlhis.Basic.Device.Request; using Dlhis.Basic.Device.Response; using Dlhis.Basic.Device.Services; using Dlhis.Basic.Packs; diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs index 8a5579f4..901c21c4 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs @@ -1,23 +1,28 @@ -using Dlhis.Basic.Device.Request; +using System.Diagnostics; +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; using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.DataAccess.Dto; using Kurisu.SqlSugar.Services; +using Newtonsoft.Json; namespace Dlhis.Basic.Device.Services.Implements; public class DevicePermissionService : IDevicePermissionService { private readonly IDbContext _dbContext; + private readonly RedisCache _redisCache; - public DevicePermissionService(IDbContext dbContext) + public DevicePermissionService(IDbContext dbContext, RedisCache redisCache) { _dbContext = dbContext; + _redisCache = redisCache; } public async Task AssignAsync(DevicePermissionSaveReuqest reuqest) @@ -58,28 +63,46 @@ public class DevicePermissionService : IDevicePermissionService public async Task GenerateDeviceTasksAsync(Func func, List userNos) { + var sw = Stopwatch.StartNew(); + //获取当前所有人的权限 if (userNos.IsEmpty()) - { userNos = await GetPermissionUserNosAsync(); + + var beforeDic = new Dictionary>(); + if (await _redisCache.KeyExistsAsync("devicePermissions")) + { + var cache = await _redisCache.StringGetAsync>>("devicePermissions"); + if (cache?.Any() == true) + { + beforeDic = cache; + } + } + else + { + beforeDic = await GetAssignDeviceCodesInternalAsync(userNos); } - var beforeDic = await GetAssignDeviceCodesInternalAsync(userNos); + await Console.Out.WriteLineAsync($"获取当前所有人的权限耗时:{sw.ElapsedMilliseconds}"); - //获取处理 + sw.Restart(); + //业务处理 await func(); + await Console.Out.WriteLineAsync($"业务处理耗时:{sw.ElapsedMilliseconds}"); + sw.Restart(); + //获取业务处理后所有人的权限 var nextUserNos = await GetPermissionUserNosAsync(); if (nextUserNos.Any()) - { userNos = userNos.Concat(nextUserNos).Distinct().ToList(); - } var currentDic = await GetAssignDeviceCodesInternalAsync(userNos); + await Console.Out.WriteLineAsync($"获取业务处理后所有人的权限耗时:{sw.ElapsedMilliseconds}"); + sw.Restart(); var deivces = await _dbContext.Queryable().ToListAsync(); + var waitTasks = new List(); foreach (var userNo in userNos) { - beforeDic.TryGetValue(userNo, out var beforeCodes); beforeCodes ??= new List(); @@ -100,14 +123,6 @@ public class DevicePermissionService : IDevicePermissionService deletedItems = deletedItems.Where(x => deviceCodes.Contains(x)).ToList(); addItems = addItems.Where(x => deviceCodes.Contains(x)).ToList(); - var userInfo = await _dbContext.Queryable() - .Where(ga => ga.No == userNo) - .Select(ga => new - { - ga.Code - }) - .SingleAsync(); - //下发任务创建 var toDeleted = deletedItems.Select(x => new DeviceTaskEntity { @@ -116,7 +131,6 @@ public class DevicePermissionService : IDevicePermissionService Type = DeviceTaskEnumType.Delete, UserNo = userNo, Version = 0, - UserCode = userInfo.Code, }).ToList(); var toAdd = addItems.Select(x => new DeviceTaskEntity @@ -126,11 +140,20 @@ public class DevicePermissionService : IDevicePermissionService Type = DeviceTaskEnumType.Add, UserNo = userNo, Version = 0, - UserCode = userInfo.Code, }).ToList(); - var tasks = toDeleted.Concat(toAdd).ToList(); - await _dbContext.InsertAsync(tasks); + waitTasks.AddRange(toDeleted.Concat(toAdd).ToList()); + } + + await Console.Out.WriteLineAsync($"比对任务生成耗时:{sw.ElapsedMilliseconds}"); + + if (waitTasks.Any()) + { + sw.Restart(); + await _redisCache.StringSetAsync("devicePermissions", JsonConvert.SerializeObject(currentDic)); + await _dbContext.InsertAsync(waitTasks); + + await Console.Out.WriteLineAsync($"任务写入耗时:{sw.ElapsedMilliseconds}"); } } @@ -161,7 +184,6 @@ public class DevicePermissionService : IDevicePermissionService Type = taskType, UserNo = userNo, Version = 0, - UserCode = userInfo.Code, }).ToList(); await _dbContext.InsertAsync(tasks); @@ -358,10 +380,11 @@ public class DevicePermissionService : IDevicePermissionService private async Task>> GetAssignDeviceCodesInternalAsync(List userNos) { + var sw = Stopwatch.StartNew(); var gainfos = await _dbContext.Queryable().Where(x => userNos.Contains(x.No)).ToListAsync(); if (!gainfos.Any()) { - return new Dictionary>(); + return new Dictionary>(0); } var gainfoGroupRelationships = await _dbContext.Queryable().ToListAsync(); @@ -369,7 +392,7 @@ public class DevicePermissionService : IDevicePermissionService var deviceGroups = await _dbContext.Queryable().ToListAsync(); var deviceRelationships = await _dbContext.Queryable().ToListAsync(); - var result = new Dictionary>(); + var result = new Dictionary>(gainfos.Count); foreach (var gainfo in gainfos) { @@ -379,6 +402,7 @@ public class DevicePermissionService : IDevicePermissionService result.Add(userNo, codes); } + await Console.Out.WriteLineAsync($"获取所有人员权限耗时:{sw.ElapsedMilliseconds}"); return result; } } diff --git a/Src/Dlhis.Basic/Summary/Services/Implements/SummaryService.cs b/Src/Dlhis.Basic/Summary/Services/Implements/SummaryService.cs index d1c15b1c..a2306942 100644 --- a/Src/Dlhis.Basic/Summary/Services/Implements/SummaryService.cs +++ b/Src/Dlhis.Basic/Summary/Services/Implements/SummaryService.cs @@ -4,6 +4,7 @@ using Dlhis.Basic.Summary.Response; using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Basic.Enums; using Dlhis.Entity.Device.Entities; +using Dlhis.Entity.Device.Enums; using Kurisu.SqlSugar.Services; namespace Dlhis.Basic.Summary.Services.Implements; @@ -27,7 +28,7 @@ public class SummaryService : ISummaryService var before30Day = DateTime.Today.AddDays(-29); var before7Day = DateTime.Today.AddDays(-6); - var devices = await _dbContext.Queryable().ToListAsync(); + var devices = await _dbContext.Queryable().Where(x => x.Type == DeviceTypeEnumType.Attendance || (x.Type == DeviceTypeEnumType.Door && x.AsAttendance)).ToListAsync(); var deviceUniqueNos = devices.Select(x => x.UniqueNo).ToList(); var deviceRegistries = await _dbContext.Queryable() diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateGetAttendanceJob.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateGetAttendanceJob.cs index b3b8a00b..6c8b6cd7 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateGetAttendanceJob.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateGetAttendanceJob.cs @@ -49,7 +49,6 @@ public class CreateGetAttendanceJob TenantId = x.TenantId, Version = 0, UserNo = string.Empty, - UserCode = string.Empty, Type = DeviceTaskEnumType.UploadRecord, CreatedBy = 1, diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateSyncServerDateTimeJob.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateSyncServerDateTimeJob.cs index 35a3ecce..789d6722 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateSyncServerDateTimeJob.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateSyncServerDateTimeJob.cs @@ -43,7 +43,6 @@ namespace Dlhis.ScheduledTask.TaskAssignment.Job TenantId = x.TenantId, Version = 0, UserNo = string.Empty, - UserCode = string.Empty, Type = DeviceTaskEnumType.SyncDateTime, CreatedBy = 1, diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs index 70c3c029..dee7e916 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs @@ -14,6 +14,7 @@ using SqlSugar; using Kurisu.SqlSugar.Extensions; using Newtonsoft.Json.Linq; using Kurisu.Core.CustomClass; +using Kurisu.AspNetCore; namespace Dlhis.ScheduledTask.TaskAssignment.Services.Implements; @@ -52,7 +53,7 @@ public class AssignmentService : IAssignmentService deivceTamplate.Brand, FuncStr = deivce.Funcs.ToString(), deviceTask.UserNo, - deviceTask.UserCode, + UserCode = ga.Code, UserName = ga.Name, ga.DepartmentNo, DepartmentName = department.Name, @@ -282,25 +283,21 @@ public class AssignmentService : IAssignmentService { var task = await _dbContext.Queryable().Where(x => x.Id == taskId).FirstAsync(); task.ThrowIfNull("该任务不存在"); - (task.Status != DeviceTaskStatusEnumType.Process).ThrowIfTrue($"设备任务下发状态需为{DeviceTaskStatusEnumType.Process.GetDescription()}"); - return Scoped.Request.Value.Create((sp) => - { - var faceUrlOptions = sp.GetService>().Value; - var dataProtectionProvider = sp.GetService(); + var faceUrlOptions = App.GetServiceProvider(true).GetService>().Value; + var dataProtectionProvider = App.GetServiceProvider(true).GetService(); - var timeLimitedDataProtector = dataProtectionProvider - .CreateProtector("down:face") - .ToTimeLimitedDataProtector(); + var timeLimitedDataProtector = dataProtectionProvider + .CreateProtector("down:face") + .ToTimeLimitedDataProtector(); - var userCode = task.UserCode; + var userCode = await _dbContext.Queryable().Where(x => x.No == task.UserNo).Select(x => x.Code).SingleAsync(); - var key = $"face:{userCode}"; - var token = timeLimitedDataProtector.Protect(key, TimeSpan.FromSeconds(faceUrlOptions.Limit)); + var key = $"face:{userCode}"; + var token = timeLimitedDataProtector.Protect(key, TimeSpan.FromSeconds(faceUrlOptions.Limit)); - return faceUrlOptions.Url + token; - }); + return faceUrlOptions.Url + token; } diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs index 699bd273..f844e9df 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs @@ -1,14 +1,10 @@ using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Device.Entities; -using Dlhis.Entity.Device.Enums; using Dlhis.ScheduledTask.TaskAssignment.Request; using Dlhis.ScheduledTask.TaskAssignment.Response; -using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.DataAccess.Dto; using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Services; -using Newtonsoft.Json.Linq; -using System.Collections.Generic; namespace Dlhis.ScheduledTask.TaskAssignment.Services.Implements; @@ -33,14 +29,13 @@ public class DeviceTaskAssignmentService : IDeviceTaskAssignmentService Status = deviceTask.Status, UserNo = deviceTask.UserNo, UserName = ga.Name, - UserCode = deviceTask.UserCode, + UserCode = ga.Code, Type = deviceTask.Type, LastUpdateTime = deviceTask.ModifiedTime }) .ToPageListAsync(request); return page; } - } From 82faedcf417d62b1eeb879bc3ffb8dd94abe60ea Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 27 Feb 2024 15:25:57 +0800 Subject: [PATCH 071/146] =?UTF-8?q?fix=20=E5=85=88=E7=A7=BB=E9=99=A4redis?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/DevicePermissionService.cs | 52 +++++++------------ 1 file changed, 20 insertions(+), 32 deletions(-) diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs index 901c21c4..18519961 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs @@ -6,23 +6,22 @@ using Dlhis.Entity.Device.Entities; using Dlhis.Entity.Device.Enums; using Dlhis.Entity.Sys.Entities; using Dlhis.Entity.Sys.Enums; -using Kurisu.AspNetCore.Utils; using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.DataAccess.Dto; +using Kurisu.Core.User.Abstractions; using Kurisu.SqlSugar.Services; -using Newtonsoft.Json; namespace Dlhis.Basic.Device.Services.Implements; public class DevicePermissionService : IDevicePermissionService { private readonly IDbContext _dbContext; - private readonly RedisCache _redisCache; + private readonly ICurrentUser _currentUser; - public DevicePermissionService(IDbContext dbContext, RedisCache redisCache) + public DevicePermissionService(IDbContext dbContext, ICurrentUser currentUser) { _dbContext = dbContext; - _redisCache = redisCache; + _currentUser = currentUser; } public async Task AssignAsync(DevicePermissionSaveReuqest reuqest) @@ -63,42 +62,36 @@ public class DevicePermissionService : IDevicePermissionService public async Task GenerateDeviceTasksAsync(Func func, List userNos) { - var sw = Stopwatch.StartNew(); + //var redisKey = "devicePermissions:" + _currentUser.GetStringTenantId(); + //获取当前所有人的权限 if (userNos.IsEmpty()) userNos = await GetPermissionUserNosAsync(); - var beforeDic = new Dictionary>(); - if (await _redisCache.KeyExistsAsync("devicePermissions")) - { - var cache = await _redisCache.StringGetAsync>>("devicePermissions"); - if (cache?.Any() == true) - { - beforeDic = cache; - } - } - else - { - beforeDic = await GetAssignDeviceCodesInternalAsync(userNos); - } + var beforeDic = await GetAssignDeviceCodesInternalAsync(userNos); // new Dictionary>(); + //if (await _redisCache.KeyExistsAsync(redisKey)) + //{ + // var cache = await _redisCache.StringGetAsync>>(redisKey); + // if (cache?.Any() == true) + // { + // beforeDic = cache; + // } + //} + //else + //{ + // beforeDic = await GetAssignDeviceCodesInternalAsync(userNos); + //} - await Console.Out.WriteLineAsync($"获取当前所有人的权限耗时:{sw.ElapsedMilliseconds}"); - - sw.Restart(); //业务处理 await func(); - await Console.Out.WriteLineAsync($"业务处理耗时:{sw.ElapsedMilliseconds}"); - sw.Restart(); //获取业务处理后所有人的权限 var nextUserNos = await GetPermissionUserNosAsync(); if (nextUserNos.Any()) userNos = userNos.Concat(nextUserNos).Distinct().ToList(); var currentDic = await GetAssignDeviceCodesInternalAsync(userNos); - await Console.Out.WriteLineAsync($"获取业务处理后所有人的权限耗时:{sw.ElapsedMilliseconds}"); - sw.Restart(); var deivces = await _dbContext.Queryable().ToListAsync(); var waitTasks = new List(); foreach (var userNo in userNos) @@ -145,15 +138,10 @@ public class DevicePermissionService : IDevicePermissionService waitTasks.AddRange(toDeleted.Concat(toAdd).ToList()); } - await Console.Out.WriteLineAsync($"比对任务生成耗时:{sw.ElapsedMilliseconds}"); - if (waitTasks.Any()) { - sw.Restart(); - await _redisCache.StringSetAsync("devicePermissions", JsonConvert.SerializeObject(currentDic)); + //await _redisCache.StringSetAsync(redisKey, JsonConvert.SerializeObject(currentDic)); await _dbContext.InsertAsync(waitTasks); - - await Console.Out.WriteLineAsync($"任务写入耗时:{sw.ElapsedMilliseconds}"); } } From 364deaf21ef1ca7c666a8af78be75220bf2aebb2 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 27 Feb 2024 17:30:57 +0800 Subject: [PATCH 072/146] =?UTF-8?q?fix=20=E6=8E=A5=E5=8F=A3=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=B8=BApost?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs b/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs index 94e62fe6..435e51c5 100644 --- a/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs +++ b/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs @@ -41,8 +41,8 @@ public class GainfosController : ControllerBase /// /// /// - [HttpGet("page")] - public async Task> GetPageAsync([FromQuery] GainfoPageRequest request) + [HttpPost("page")] + public async Task> GetPageAsync(GainfoPageRequest request) { return await _gainfoService.GetPageAsync(request); } From e61833fa813051d10ff6ea68df6444c9bcb64a71 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 27 Feb 2024 18:15:46 +0800 Subject: [PATCH 073/146] =?UTF-8?q?feat=20=E6=A1=86=E6=9E=B6=E5=8D=87?= =?UTF-8?q?=E7=BA=A7,=E4=BB=A3=E7=A0=81=E6=95=B4=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/BusinessPlacesController.cs | 2 +- .../Controllers/BusinessShiftsController.cs | 2 +- .../Controllers/DeviceGroupsController.cs | 2 +- .../DevicePermissionsController.cs | 1 + .../Device/Controllers/DevicesController.cs | 2 +- Src/Dlhis.Basic/Dlhis.Basic.csproj | 4 +- .../Controllers/GainfoCardsController.cs | 2 +- Src/Dlhis.Basic/Packs/DataProtectionJob.cs | 19 ---- Src/Dlhis.Basic/Packs/SqlSugarPack.cs | 97 +--------------- Src/Dlhis.Basic/appsettings.json | 4 + Src/Dlhis.Canteen/Dlhis.Canteen.csproj | 3 +- Src/Dlhis.Common.Api/Dlhis.Common.Api.csproj | 2 +- Src/Dlhis.Common/Dlhis.Common.csproj | 2 +- Src/Dlhis.Entity/Dlhis.Entity.csproj | 2 +- .../Controllers/DeviceUploadLogsController.cs | 2 +- .../Dlhis.ScheduledTask.csproj | 3 +- .../Packs/DataProtectionJob.cs | 19 ---- Src/Dlhis.ScheduledTask/Packs/SqlSugarPack.cs | 104 ------------------ Src/Dlhis.ScheduledTask/Program.cs | 6 - .../Properties/launchSettings.json | 2 +- .../Controllers/AssignmentsController.cs | 4 +- Src/Dlhis.ScheduledTask/appsettings.json | 4 + Src/Dlhis.Sys.Api/Dlhis.Sys.Api.csproj | 2 +- Src/Dlhis.Sys/Dlhis.Sys.csproj | 3 +- Src/Dlhis.User/Dlhis.User.csproj | 3 +- 25 files changed, 28 insertions(+), 268 deletions(-) delete mode 100644 Src/Dlhis.Basic/Packs/DataProtectionJob.cs delete mode 100644 Src/Dlhis.ScheduledTask/Packs/DataProtectionJob.cs diff --git a/Src/Dlhis.Basic/BusinessPlace/Controllers/BusinessPlacesController.cs b/Src/Dlhis.Basic/BusinessPlace/Controllers/BusinessPlacesController.cs index 815f4e08..63dd5b4b 100644 --- a/Src/Dlhis.Basic/BusinessPlace/Controllers/BusinessPlacesController.cs +++ b/Src/Dlhis.Basic/BusinessPlace/Controllers/BusinessPlacesController.cs @@ -2,7 +2,7 @@ using Dlhis.Basic.BusinessPlace.Response; using Dlhis.Basic.BusinessPlace.Services; using Dlhis.Basic.BusinessShift.Services; -using Dlhis.Basic.Packs; +using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop; using Kurisu.Core.DataAccess.Dto; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; diff --git a/Src/Dlhis.Basic/BusinessShift/Controllers/BusinessShiftsController.cs b/Src/Dlhis.Basic/BusinessShift/Controllers/BusinessShiftsController.cs index 323bb7bb..981c650b 100644 --- a/Src/Dlhis.Basic/BusinessShift/Controllers/BusinessShiftsController.cs +++ b/Src/Dlhis.Basic/BusinessShift/Controllers/BusinessShiftsController.cs @@ -1,7 +1,7 @@ using Dlhis.Basic.BusinessShift.Request; using Dlhis.Basic.BusinessShift.Response; using Dlhis.Basic.BusinessShift.Services; -using Dlhis.Basic.Packs; +using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop; using Kurisu.Core.DataAccess.Dto; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; diff --git a/Src/Dlhis.Basic/Device/Controllers/DeviceGroupsController.cs b/Src/Dlhis.Basic/Device/Controllers/DeviceGroupsController.cs index 29796a25..5f6ac7f8 100644 --- a/Src/Dlhis.Basic/Device/Controllers/DeviceGroupsController.cs +++ b/Src/Dlhis.Basic/Device/Controllers/DeviceGroupsController.cs @@ -1,8 +1,8 @@ using Dlhis.Basic.Device.Request; using Dlhis.Basic.Device.Response; using Dlhis.Basic.Device.Services; -using Dlhis.Basic.Packs; using Dlhis.Entity.Device.Enums; +using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop; using Kurisu.Core.DataAccess.Dto; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; diff --git a/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs b/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs index 9462d88e..fffc51f0 100644 --- a/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs +++ b/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs @@ -3,6 +3,7 @@ using Dlhis.Basic.Device.Request; using Dlhis.Basic.Device.Response; using Dlhis.Basic.Device.Services; using Dlhis.Basic.Packs; +using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop; using Kurisu.Core.DataAccess.Dto; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; diff --git a/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs b/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs index f4bf018d..9829ea9a 100644 --- a/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs +++ b/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs @@ -1,7 +1,7 @@ using Dlhis.Basic.Device.Request; using Dlhis.Basic.Device.Response; using Dlhis.Basic.Device.Services; -using Dlhis.Basic.Packs; +using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop; using Kurisu.Core.DataAccess.Dto; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; diff --git a/Src/Dlhis.Basic/Dlhis.Basic.csproj b/Src/Dlhis.Basic/Dlhis.Basic.csproj index a9a3c3da..7094a50f 100644 --- a/Src/Dlhis.Basic/Dlhis.Basic.csproj +++ b/Src/Dlhis.Basic/Dlhis.Basic.csproj @@ -17,9 +17,7 @@ - - - + diff --git a/Src/Dlhis.Basic/Organization/Controllers/GainfoCardsController.cs b/Src/Dlhis.Basic/Organization/Controllers/GainfoCardsController.cs index 6ef9aed1..3e04aa6d 100644 --- a/Src/Dlhis.Basic/Organization/Controllers/GainfoCardsController.cs +++ b/Src/Dlhis.Basic/Organization/Controllers/GainfoCardsController.cs @@ -1,7 +1,7 @@ using Dlhis.Basic.Organization.Request; using Dlhis.Basic.Organization.Response; using Dlhis.Basic.Organization.Services; -using Dlhis.Basic.Packs; +using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; diff --git a/Src/Dlhis.Basic/Packs/DataProtectionJob.cs b/Src/Dlhis.Basic/Packs/DataProtectionJob.cs deleted file mode 100644 index 9bb6e44b..00000000 --- a/Src/Dlhis.Basic/Packs/DataProtectionJob.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Kurisu.AspNetCore.Startup; -using Kurisu.AspNetCore.Utils; -using Microsoft.AspNetCore.DataProtection; -using StackExchange.Redis; - -namespace Dlhis.Basic.Packs; - -public class DataProtectionJobPack : BaseAppPack -{ - public override bool IsBeforeUseRouting { get; } - - public override void ConfigureServices(IServiceCollection services) - { - var redisConnection = ConnectionMultiplexer.Connect(Configuration.GetSection($"{nameof(RedisOptions)}:{nameof(RedisOptions.ConnectionString)}").Value); - services.AddDataProtection() - .SetApplicationName("yiliantong") - .PersistKeysToStackExchangeRedis(redisConnection, "DataProtection-Keys"); - } -} diff --git a/Src/Dlhis.Basic/Packs/SqlSugarPack.cs b/Src/Dlhis.Basic/Packs/SqlSugarPack.cs index 6979080e..64d5b2aa 100644 --- a/Src/Dlhis.Basic/Packs/SqlSugarPack.cs +++ b/Src/Dlhis.Basic/Packs/SqlSugarPack.cs @@ -68,99 +68,4 @@ public class SqlSugarPack : BaseAppPack faceDb.Client.DbMaintenance.CreateDatabase(); faceDb.Client.CodeFirst.InitTables(); } -} - - -/// -/// 日志 -/// -[AttributeUsage(AttributeTargets.Method)] -public class LogAttribute : Attribute, IAsyncActionFilter -{ - public LogAttribute(string title) - { - Title = title; - } - - /// - /// - /// - public string Title { get; set; } - - /// - /// 是否处理差异 - /// - public bool Diff { get; set; } - - - public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) - { - PreSetting(context.HttpContext); - await next(); - } - - private void PreSetting(HttpContext httpContext) - { - var options = httpContext.RequestServices.GetService(); - - options.Title = Title; - options.Diff = Diff; - options.BatchNo = Guid.NewGuid(); - options.RoutePath = httpContext.Request.Path.Value; - options.RaiseTime = DateTime.Now; - } -} - -/// -/// 事务 -/// -[AttributeUsage(AttributeTargets.Method)] -public class TransactionalAttribute : Attribute, IAsyncActionFilter -{ - public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) - { - var dbContext = context.HttpContext.RequestServices.GetRequiredService(); - await dbContext.Ado.BeginTranAsync(); - try - { - var result = await next(); - if (result.Exception != null) - { - throw result.Exception; - } - else - { - await dbContext.Ado.CommitTranAsync(); - } - } - catch (Exception) - { - await dbContext.Ado.RollbackTranAsync(); - throw; - } - } -} - -/// -/// 忽略租户 -/// -[AttributeUsage(AttributeTargets.Method)] -public class IgnoreTenantAttribute : Attribute, IAsyncActionFilter -{ - public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) - { - var dbContext = context.HttpContext.RequestServices.GetRequiredService(); - var options = context.HttpContext!.RequestServices.GetService(); - try - { - dbContext.QueryFilter.ClearAndBackup(); - options.IgnoreTenant = true; - await next(); - } - finally - { - options.IgnoreTenant = false; - dbContext.QueryFilter.Restore(); - } - } -} +} \ No newline at end of file diff --git a/Src/Dlhis.Basic/appsettings.json b/Src/Dlhis.Basic/appsettings.json index 6e58507c..79da19b2 100644 --- a/Src/Dlhis.Basic/appsettings.json +++ b/Src/Dlhis.Basic/appsettings.json @@ -14,6 +14,10 @@ "Url": "https://yikatong.isawesome.cn/api/basic/gainfos/face?token=", "Limit": 7200 }, + "DataProtectionOptions": { + "Enable": true, + "AppName": "yiliantong" + }, "SqlSugarOptions": { "DefaultConnectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=yikatong;charset=utf8mb4;", "SlaveConnectionString": [], diff --git a/Src/Dlhis.Canteen/Dlhis.Canteen.csproj b/Src/Dlhis.Canteen/Dlhis.Canteen.csproj index cb61b6a5..f30be7d1 100644 --- a/Src/Dlhis.Canteen/Dlhis.Canteen.csproj +++ b/Src/Dlhis.Canteen/Dlhis.Canteen.csproj @@ -36,8 +36,7 @@ - - + diff --git a/Src/Dlhis.Common.Api/Dlhis.Common.Api.csproj b/Src/Dlhis.Common.Api/Dlhis.Common.Api.csproj index 26abb5b7..314a11ed 100644 --- a/Src/Dlhis.Common.Api/Dlhis.Common.Api.csproj +++ b/Src/Dlhis.Common.Api/Dlhis.Common.Api.csproj @@ -8,7 +8,7 @@ - + diff --git a/Src/Dlhis.Common/Dlhis.Common.csproj b/Src/Dlhis.Common/Dlhis.Common.csproj index 3ca7f20f..d3228328 100644 --- a/Src/Dlhis.Common/Dlhis.Common.csproj +++ b/Src/Dlhis.Common/Dlhis.Common.csproj @@ -21,7 +21,7 @@ - + diff --git a/Src/Dlhis.Entity/Dlhis.Entity.csproj b/Src/Dlhis.Entity/Dlhis.Entity.csproj index 09f988da..8000930a 100644 --- a/Src/Dlhis.Entity/Dlhis.Entity.csproj +++ b/Src/Dlhis.Entity/Dlhis.Entity.csproj @@ -11,7 +11,7 @@ - + diff --git a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Controllers/DeviceUploadLogsController.cs b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Controllers/DeviceUploadLogsController.cs index edbbacb7..a463aeac 100644 --- a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Controllers/DeviceUploadLogsController.cs +++ b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Controllers/DeviceUploadLogsController.cs @@ -1,7 +1,7 @@ using Dlhis.ScheduledTask.DeviceUploadLog.Request; using Dlhis.ScheduledTask.DeviceUploadLog.Response; using Dlhis.ScheduledTask.DeviceUploadLog.Services; -using Dlhis.ScheduledTask.Packs; +using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop; using Kurisu.Core.DataAccess.Dto; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; diff --git a/Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj b/Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj index 03b573b7..e412c478 100644 --- a/Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj +++ b/Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj @@ -20,8 +20,7 @@ - - + diff --git a/Src/Dlhis.ScheduledTask/Packs/DataProtectionJob.cs b/Src/Dlhis.ScheduledTask/Packs/DataProtectionJob.cs deleted file mode 100644 index 03d87356..00000000 --- a/Src/Dlhis.ScheduledTask/Packs/DataProtectionJob.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Kurisu.AspNetCore.Startup; -using Kurisu.AspNetCore.Utils; -using Microsoft.AspNetCore.DataProtection; -using StackExchange.Redis; - -namespace Dlhis.ScheduledTask.Packs; - -public class DataProtectionJobPack : BaseAppPack -{ - public override bool IsBeforeUseRouting { get; } - - public override void ConfigureServices(IServiceCollection services) - { - var redisConnection = ConnectionMultiplexer.Connect(Configuration.GetSection($"{nameof(RedisOptions)}:{nameof(RedisOptions.ConnectionString)}").Value); - services.AddDataProtection() - .SetApplicationName("scheduled") - .PersistKeysToStackExchangeRedis(redisConnection, "DataProtection-Keys"); - } -} diff --git a/Src/Dlhis.ScheduledTask/Packs/SqlSugarPack.cs b/Src/Dlhis.ScheduledTask/Packs/SqlSugarPack.cs index 2f562f2b..24a3f080 100644 --- a/Src/Dlhis.ScheduledTask/Packs/SqlSugarPack.cs +++ b/Src/Dlhis.ScheduledTask/Packs/SqlSugarPack.cs @@ -1,9 +1,5 @@ using Kurisu.AspNetCore.Startup; -using Kurisu.Core.DataAccess.Entity; using Kurisu.SqlSugar.Extensions; -using Kurisu.SqlSugar.Services; -using Microsoft.AspNetCore.Mvc.Filters; -using SqlSugar; namespace Dlhis.ScheduledTask.Packs; @@ -16,103 +12,3 @@ public class SqlSugarPack : BaseAppPack services.AddSqlSugar(); } } - - - - - - -/// -/// 日志 -/// -[AttributeUsage(AttributeTargets.Method)] -public class LogAttribute : Attribute, IAsyncActionFilter -{ - public LogAttribute(string title) - { - Title = title; - } - - /// - /// - /// - public string Title { get; set; } - - /// - /// 是否处理差异 - /// - public bool Diff { get; set; } - - - public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) - { - PreSetting(context.HttpContext); - await next(); - } - - private void PreSetting(HttpContext httpContext) - { - var options = httpContext.RequestServices.GetService(); - - options.Title = Title; - options.Diff = Diff; - options.BatchNo = Guid.NewGuid(); - options.RoutePath = httpContext.Request.Path.Value; - options.RaiseTime = DateTime.Now; - } -} - -/// -/// 事务 -/// -[AttributeUsage(AttributeTargets.Method)] -public class TransactionalAttribute : Attribute, IAsyncActionFilter -{ - public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) - { - var dbContext = context.HttpContext.RequestServices.GetRequiredService(); - await dbContext.Ado.BeginTranAsync(); - try - { - var result = await next(); - if (result.Exception != null) - { - throw result.Exception; - } - else - { - await dbContext.Ado.CommitTranAsync(); - } - } - catch (Exception) - { - await dbContext.Ado.RollbackTranAsync(); - throw; - } - } -} - -/// -/// 忽略租户 -/// -[AttributeUsage(AttributeTargets.Method)] -public class IgnoreTenantAttribute : Attribute, IAsyncActionFilter -{ - public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) - { - var dbContext = context.HttpContext.RequestServices.GetRequiredService(); - var options = context.HttpContext!.RequestServices.GetService(); - try - { - dbContext.QueryFilter.ClearAndBackup(); - options.IgnoreTenant = true; - await next(); - } - finally - { - options.IgnoreTenant = false; - dbContext.QueryFilter.Restore(); - } - } -} - diff --git a/Src/Dlhis.ScheduledTask/Program.cs b/Src/Dlhis.ScheduledTask/Program.cs index 64b4094a..9f35b5ee 100644 --- a/Src/Dlhis.ScheduledTask/Program.cs +++ b/Src/Dlhis.ScheduledTask/Program.cs @@ -23,12 +23,6 @@ public class Startup : DefaultStartup { base.ConfigureServices(services); services.AddRedis(); - - var reidConnection = Configuration.GetSection($"{nameof(RedisOptions)}:{nameof(RedisOptions.ConnectionString)}").Value; - var redis = ConnectionMultiplexer.Connect(reidConnection); - services.AddDataProtection() - .SetApplicationName("yiliantong") - .PersistKeysToStackExchangeRedis(redis, "DataProtection-Keys"); } public override void Configure(IApplicationBuilder app, IWebHostEnvironment env) diff --git a/Src/Dlhis.ScheduledTask/Properties/launchSettings.json b/Src/Dlhis.ScheduledTask/Properties/launchSettings.json index a6ea1802..fd368e29 100644 --- a/Src/Dlhis.ScheduledTask/Properties/launchSettings.json +++ b/Src/Dlhis.ScheduledTask/Properties/launchSettings.json @@ -5,7 +5,7 @@ "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, - "applicationUrl": "http://*:5010" + "applicationUrl": "http://localhost:5010" } } } \ No newline at end of file diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Controllers/AssignmentsController.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Controllers/AssignmentsController.cs index fb9b7e2a..f49e4ee8 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Controllers/AssignmentsController.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Controllers/AssignmentsController.cs @@ -1,7 +1,7 @@ -using Dlhis.ScheduledTask.Packs; -using Dlhis.ScheduledTask.TaskAssignment.Request; +using Dlhis.ScheduledTask.TaskAssignment.Request; using Dlhis.ScheduledTask.TaskAssignment.Response; using Dlhis.ScheduledTask.TaskAssignment.Services; +using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; diff --git a/Src/Dlhis.ScheduledTask/appsettings.json b/Src/Dlhis.ScheduledTask/appsettings.json index 8c70547a..2514f898 100644 --- a/Src/Dlhis.ScheduledTask/appsettings.json +++ b/Src/Dlhis.ScheduledTask/appsettings.json @@ -8,6 +8,10 @@ "InternalRequest": { "SysRequestUrl": "http://sys" }, + "DataProtectionOptions": { + "Enable": true, + "AppName": "yiliantong" + }, "SqlSugarOptions": { "DefaultConnectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=yikatong;charset=utf8mb4;", "SlaveConnectionString": [], diff --git a/Src/Dlhis.Sys.Api/Dlhis.Sys.Api.csproj b/Src/Dlhis.Sys.Api/Dlhis.Sys.Api.csproj index 71b4a337..50a74ddd 100644 --- a/Src/Dlhis.Sys.Api/Dlhis.Sys.Api.csproj +++ b/Src/Dlhis.Sys.Api/Dlhis.Sys.Api.csproj @@ -7,7 +7,7 @@ - + diff --git a/Src/Dlhis.Sys/Dlhis.Sys.csproj b/Src/Dlhis.Sys/Dlhis.Sys.csproj index bb2fec72..830d7da2 100644 --- a/Src/Dlhis.Sys/Dlhis.Sys.csproj +++ b/Src/Dlhis.Sys/Dlhis.Sys.csproj @@ -17,8 +17,7 @@ - - + diff --git a/Src/Dlhis.User/Dlhis.User.csproj b/Src/Dlhis.User/Dlhis.User.csproj index b1381bb6..a803e35b 100644 --- a/Src/Dlhis.User/Dlhis.User.csproj +++ b/Src/Dlhis.User/Dlhis.User.csproj @@ -17,7 +17,6 @@ - - + From dd44750a973d3e67c690d5489723c695ed1d09ca Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 27 Feb 2024 18:25:31 +0800 Subject: [PATCH 074/146] =?UTF-8?q?fix=20=E6=A1=A3=E6=A1=88=E6=98=8E?= =?UTF-8?q?=E7=BB=86=E8=BF=94=E5=9B=9E=E4=BA=BA=E8=84=B8base64?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/GainfosController.cs | 6 +- .../Request/GainfoDetailRequest.cs | 38 ++-- .../Response/GainfoDetailResponse.cs | 175 +++++++++--------- .../Organization/Services/IGainfoService.cs | 4 +- .../Services/Implements/GainfoService.cs | 14 +- 5 files changed, 124 insertions(+), 113 deletions(-) diff --git a/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs b/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs index 435e51c5..e51d85a5 100644 --- a/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs +++ b/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs @@ -154,7 +154,7 @@ public class GainfosController : ControllerBase [HttpGet("list")] public async Task> GetGainfoListTaskAsync([FromQuery] GainfoListRequest request) { - return await _gainfoService.GetGainfoListTaskAsync(request); + return await _gainfoService.GetGainfoListAsync(request); } /// @@ -163,9 +163,9 @@ public class GainfosController : ControllerBase /// /// [HttpGet("detail")] - public async Task GetGainfoDetailTaskAsync([FromQuery] GainfoDetailRequest request) + public async Task GetGainfoDetailAsync([FromQuery] GainfoDetailRequest request) { - return await _gainfoService.GetGainfoDetailTaskAsync(request); + return await _gainfoService.GetGainfoDetailAsync(request); } } diff --git a/Src/Dlhis.Basic/Organization/Request/GainfoDetailRequest.cs b/Src/Dlhis.Basic/Organization/Request/GainfoDetailRequest.cs index dde7384a..8de96bae 100644 --- a/Src/Dlhis.Basic/Organization/Request/GainfoDetailRequest.cs +++ b/Src/Dlhis.Basic/Organization/Request/GainfoDetailRequest.cs @@ -1,23 +1,25 @@ using Dlhis.Entity.Basic.Enums; -using Kurisu.Core.DataAccess.Dto; -using SqlSugar; using System.ComponentModel.DataAnnotations; -namespace Dlhis.Basic.Organization.Request -{ - public class GainfoDetailRequest : PageDto - { - /// - /// 档案类型 - /// - [Required] - [EnumDataType(typeof(GainfoStatusEnumType))] - public GainfoStatusEnumType Status { get; set; } +namespace Dlhis.Basic.Organization.Request; - /// - /// 档案号 - /// - [Required] - public string No { get; set; } - } +public class GainfoDetailRequest +{ + /// + /// 档案类型 + /// + [Required] + [EnumDataType(typeof(GainfoStatusEnumType))] + public GainfoStatusEnumType Status { get; set; } + + /// + /// 档案号 + /// + [Required] + public string No { get; set; } + + /// + /// 是否需要人脸信息 + /// + public bool WithFace { get; set; } } diff --git a/Src/Dlhis.Basic/Organization/Response/GainfoDetailResponse.cs b/Src/Dlhis.Basic/Organization/Response/GainfoDetailResponse.cs index 565d53dc..88f70f3f 100644 --- a/Src/Dlhis.Basic/Organization/Response/GainfoDetailResponse.cs +++ b/Src/Dlhis.Basic/Organization/Response/GainfoDetailResponse.cs @@ -1,109 +1,112 @@ using Dlhis.Entity.Basic.Enums; -using SqlSugar; -using SqlSugar.DbConvert; -namespace Dlhis.Basic.Organization.Response +namespace Dlhis.Basic.Organization.Response; + +public class GainfoDetailResponse { - public class GainfoDetailResponse - { - /// - /// 档案号 - /// - public string No { get; set; } + /// + /// 档案号 + /// + public string No { get; set; } - /// - /// SAP内部编号 - /// - public string SapNo { get; set; } + /// + /// SAP内部编号 + /// + public string SapNo { get; set; } - /// - /// 姓名 - /// - public string Name { get; set; } + /// + /// 姓名 + /// + public string Name { get; set; } - /// - /// 学工号 - /// - public string Code { get; set; } + /// + /// 学工号 + /// + public string Code { get; set; } - /// - /// 部门名称 - /// - public string DepartmentName { get; set; } + /// + /// 部门名称 + /// + public string DepartmentName { get; set; } - /// - /// 证件类型代码 - /// - public string IdClass { get; set; } + /// + /// 证件类型代码 + /// + public string IdClass { get; set; } - /// - /// 身份证号 - /// - public string IdNo { get; set; } + /// + /// 身份证号 + /// + public string IdNo { get; set; } - /// - /// 性别 - /// - public GenderEnumType Gender { get; set; } + /// + /// 性别 + /// + public GenderEnumType Gender { get; set; } - /// - /// 身份证籍贯 - /// - public string NativeName { get; set; } + /// + /// 身份证籍贯 + /// + public string NativeName { get; set; } - /// - /// 身份证地址 - /// - public string Address { get; set; } + /// + /// 身份证地址 + /// + public string Address { get; set; } - /// - /// 生日 - /// - public DateTime Birthday { get; set; } + /// + /// 生日 + /// + public DateTime Birthday { get; set; } - /// - /// 手机号码 - /// - public string Phone { get; set; } + /// + /// 手机号码 + /// + public string Phone { get; set; } - /// - /// 岗位 - /// - public string Position { get; set; } + /// + /// 岗位 + /// + public string Position { get; set; } - /// - /// 职等 - /// - public string Grade { get; set; } + /// + /// 职等 + /// + public string Grade { get; set; } - /// - /// 学历 - /// - public string Degree { get; set; } + /// + /// 学历 + /// + public string Degree { get; set; } - /// - /// 人事范围 - /// - public string Werks { get; set; } + /// + /// 人事范围 + /// + public string Werks { get; set; } - /// - /// 成本中心 - /// - public string CostId { get; set; } + /// + /// 成本中心 + /// + public string CostId { get; set; } - /// - /// 已婚/未婚 - /// - public string Marital { get; set; } + /// + /// 已婚/未婚 + /// + public string Marital { get; set; } - /// - /// 国家 - /// - public string CountryName { get; set; } + /// + /// 国家 + /// + public string CountryName { get; set; } - /// - /// 民族代码 - /// - public string NationName { get; set; } - } + /// + /// 民族代码 + /// + public string NationName { get; set; } + + + /// + /// 人脸base64 + /// + public string Face { get; set; } } diff --git a/Src/Dlhis.Basic/Organization/Services/IGainfoService.cs b/Src/Dlhis.Basic/Organization/Services/IGainfoService.cs index 768aa36b..b40f3678 100644 --- a/Src/Dlhis.Basic/Organization/Services/IGainfoService.cs +++ b/Src/Dlhis.Basic/Organization/Services/IGainfoService.cs @@ -29,7 +29,7 @@ public interface IGainfoService : IScopeDependency Task> GetFaceByUserCodesAsync(GetFaceByUserCodesRequest request); - Task> GetGainfoListTaskAsync(GainfoListRequest request); + Task> GetGainfoListAsync(GainfoListRequest request); - Task GetGainfoDetailTaskAsync(GainfoDetailRequest request); + Task GetGainfoDetailAsync(GainfoDetailRequest request); } diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs index 85656105..69b10816 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs @@ -332,7 +332,7 @@ public class GainfoService : IGainfoService /// /// /// - public async Task> GetGainfoListTaskAsync(GainfoListRequest request) + public async Task> GetGainfoListAsync(GainfoListRequest request) { var page = await _gainfoStore.Queryable(request.Status) .LeftJoin((ga, de) => ga.DepartmentNo == de.No) @@ -360,14 +360,14 @@ public class GainfoService : IGainfoService /// /// /// - public async Task GetGainfoDetailTaskAsync(GainfoDetailRequest request) + public async Task GetGainfoDetailAsync(GainfoDetailRequest request) { var info = await _gainfoStore.Queryable(request.Status) .LeftJoin((ga, de) => ga.DepartmentNo == de.No) .LeftJoin((ga, de, type) => ga.Native == type.Code && type.Type == "native") .LeftJoin((ga, de, type, posi) => ga.Position == posi.Name) .LeftJoin((ga, de, type, posi, type2) => ga.CountryNo == type2.Code && type2.Type == "country") - .LeftJoin((ga, de, type, posi, type2, type3) => ga.Nation == type3.Code && type3.Type == "nation") + .LeftJoin((ga, de, type, posi, type2, type3) => ga.Nation == type3.Code && type3.Type == "nation") .Where(ga => ga.No == request.No) .Select((ga, de, type, posi, type2, type3) => new GainfoDetailResponse { @@ -391,7 +391,13 @@ public class GainfoService : IGainfoService Marital = ga.Marital, CountryName = type2.Display, NationName = type3.Display, - }).FirstAsync(); + }) + .FirstAsync(); + + if (info != null) + { + info.Face = await _dbContext.ChangeDb("face").Queryable().Where(x => x.UserCode == info.Code).Select(x => x.Face).SingleAsync(); + } return info; } From 09165983cc5e839df9ca8ee3c991e837b1d65c69 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 27 Feb 2024 18:42:20 +0800 Subject: [PATCH 075/146] =?UTF-8?q?fix=20=E7=BB=A7=E6=89=BFbaseEntity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Device/Entities/DeviceUploadLogEntity.cs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/Src/Dlhis.Entity/Device/Entities/DeviceUploadLogEntity.cs b/Src/Dlhis.Entity/Device/Entities/DeviceUploadLogEntity.cs index 6381a33e..39904219 100644 --- a/Src/Dlhis.Entity/Device/Entities/DeviceUploadLogEntity.cs +++ b/Src/Dlhis.Entity/Device/Entities/DeviceUploadLogEntity.cs @@ -1,26 +1,21 @@ using Dlhis.Entity.Device.Enums; using Kurisu.Core.DataAccess.Entity; +using Kurisu.SqlSugar; using SqlSugar; using SqlSugar.DbConvert; namespace Dlhis.Entity.Device.Entities; [SugarTable(TableName = "DeviceUploadLog", TableDescription = "设备上传记录")] -public class DeviceUploadLogEntity : ITenantId +public class DeviceUploadLogEntity : SugarBaseEntity, ITenantId { - /// - /// id - /// - [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] - public long Id { get; set; } - - [SugarColumn(IsNullable = true)] public string SerialNo { get; set; } /// /// 设备号 /// + [SugarColumn(IsNullable = false)] public string DeviceUniqueNo { get; set; } /// @@ -32,9 +27,9 @@ public class DeviceUploadLogEntity : ITenantId /// /// 产生时间 /// + [SugarColumn(IsNullable = false)] public DateTime RaiseDateTime { get; set; } - /// /// 日志类型 /// From e3d6f72243f5372ca971dbb554fac898e8f2f1f6 Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Wed, 28 Feb 2024 12:13:25 +0800 Subject: [PATCH 076/146] =?UTF-8?q?fix=20=E5=A2=9E=E5=8A=A0=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=BD=93=E5=89=8D=E6=A1=A3=E6=A1=88=E7=9A=84=E4=B8=8B?= =?UTF-8?q?=E5=8F=91=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Organization/Response/GainfoDetailResponse.cs | 2 ++ .../Organization/Services/Implements/GainfoService.cs | 5 ++++- .../Services/Implements/DeviceTaskAssignmentService.cs | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Src/Dlhis.Basic/Organization/Response/GainfoDetailResponse.cs b/Src/Dlhis.Basic/Organization/Response/GainfoDetailResponse.cs index 88f70f3f..ac6e89ef 100644 --- a/Src/Dlhis.Basic/Organization/Response/GainfoDetailResponse.cs +++ b/Src/Dlhis.Basic/Organization/Response/GainfoDetailResponse.cs @@ -109,4 +109,6 @@ public class GainfoDetailResponse /// 人脸base64 /// public string Face { get; set; } + + } diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs index 69b10816..de768d1d 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs @@ -396,7 +396,10 @@ public class GainfoService : IGainfoService if (info != null) { - info.Face = await _dbContext.ChangeDb("face").Queryable().Where(x => x.UserCode == info.Code).Select(x => x.Face).SingleAsync(); + if (request.WithFace) + { + info.Face = await _dbContext.ChangeDb("face").Queryable().Where(x => x.UserCode == info.Code).Select(x => x.Face).SingleAsync(); + } } return info; diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs index f844e9df..403ca9fb 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs @@ -2,6 +2,7 @@ using Dlhis.Entity.Device.Entities; using Dlhis.ScheduledTask.TaskAssignment.Request; using Dlhis.ScheduledTask.TaskAssignment.Response; +using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.DataAccess.Dto; using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Services; @@ -21,6 +22,7 @@ public class DeviceTaskAssignmentService : IDeviceTaskAssignmentService { var page = await _dbContext.Queryable() .LeftJoin((deviceTask, ga) => deviceTask.UserNo == ga.No) + .WhereIF(!request.Search.IsEmpty(), deviceTask => deviceTask.UserNo == request.Search) .Select((deviceTask, ga) => new DeviceTaskAssignmentResponse { DeviceUniqueNo = deviceTask.DeviceUniqueNo, From a36681bc705c7c3e89c7441be6043a69bd35e3ba Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Wed, 28 Feb 2024 15:52:59 +0800 Subject: [PATCH 077/146] =?UTF-8?q?fix=20=E6=B7=BB=E5=8A=A0=E6=A1=A3?= =?UTF-8?q?=E6=A1=88=E8=AF=A6=E6=83=85idclassname?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Organization/Response/GainfoDetailResponse.cs | 5 +++++ .../Organization/Services/Implements/GainfoService.cs | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Src/Dlhis.Basic/Organization/Response/GainfoDetailResponse.cs b/Src/Dlhis.Basic/Organization/Response/GainfoDetailResponse.cs index ac6e89ef..7753e699 100644 --- a/Src/Dlhis.Basic/Organization/Response/GainfoDetailResponse.cs +++ b/Src/Dlhis.Basic/Organization/Response/GainfoDetailResponse.cs @@ -34,6 +34,11 @@ public class GainfoDetailResponse /// public string IdClass { get; set; } + /// + /// 证件类型名称 + /// + public string ClassName { get; set; } + /// /// 身份证号 /// diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs index de768d1d..05530061 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs @@ -368,8 +368,9 @@ public class GainfoService : IGainfoService .LeftJoin((ga, de, type, posi) => ga.Position == posi.Name) .LeftJoin((ga, de, type, posi, type2) => ga.CountryNo == type2.Code && type2.Type == "country") .LeftJoin((ga, de, type, posi, type2, type3) => ga.Nation == type3.Code && type3.Type == "nation") + .LeftJoin((ga, de, type, posi, type2, type3,type4) => ga.IdClass == type4.Code && type4.Type == "cls") .Where(ga => ga.No == request.No) - .Select((ga, de, type, posi, type2, type3) => new GainfoDetailResponse + .Select((ga, de, type, posi, type2, type3,type4) => new GainfoDetailResponse { No = ga.No, SapNo = ga.SapNo, @@ -391,6 +392,7 @@ public class GainfoService : IGainfoService Marital = ga.Marital, CountryName = type2.Display, NationName = type3.Display, + ClassName = type4.Display, }) .FirstAsync(); From 2fdc4d24f1274c82f0e9dc46f2aa89bfd87e0226 Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Wed, 28 Feb 2024 16:09:21 +0800 Subject: [PATCH 078/146] =?UTF-8?q?fix=20=E6=A1=A3=E6=A1=88=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E6=B7=BB=E5=8A=A0=E8=BF=94=E5=9B=9E=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Organization/Response/GainfoDetailResponse.cs | 6 ++++++ .../Organization/Services/Implements/GainfoService.cs | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Src/Dlhis.Basic/Organization/Response/GainfoDetailResponse.cs b/Src/Dlhis.Basic/Organization/Response/GainfoDetailResponse.cs index 7753e699..6ffc95a7 100644 --- a/Src/Dlhis.Basic/Organization/Response/GainfoDetailResponse.cs +++ b/Src/Dlhis.Basic/Organization/Response/GainfoDetailResponse.cs @@ -1,4 +1,5 @@ using Dlhis.Entity.Basic.Enums; +using Kurisu.AspNetCore.Utils.Extensions; namespace Dlhis.Basic.Organization.Response; @@ -49,6 +50,11 @@ public class GainfoDetailResponse /// public GenderEnumType Gender { get; set; } + /// + /// 性别描述 + /// + public string GenderCN => Gender.GetDescription(); + /// /// 身份证籍贯 /// diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs index 05530061..a9a6c726 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs @@ -389,7 +389,7 @@ public class GainfoService : IGainfoService Degree = ga.Degree, Werks = ga.Werks, CostId = ga.CostId, - Marital = ga.Marital, + Marital = ga.Marital== "Single" ? "未婚":"已婚", CountryName = type2.Display, NationName = type3.Display, ClassName = type4.Display, From d3521ec2dea4e0f6cf10ac7ce7153e1b7836b02c Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 29 Feb 2024 10:43:35 +0800 Subject: [PATCH 079/146] =?UTF-8?q?fix=20=E4=BC=98=E5=8C=96=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Order/Request/BalanceRecordPageRequest.cs | 11 +++++++ .../Order/Request/OrderPageRequest.cs | 1 + .../Services/Implements/BalanceService.cs | 19 ++++++------ .../DeviceTaskAssignmentsController.cs | 1 - .../Implements/DeviceTaskAssignmentService.cs | 29 ++++++++++--------- 5 files changed, 37 insertions(+), 24 deletions(-) diff --git a/Src/Dlhis.Canteen/Order/Request/BalanceRecordPageRequest.cs b/Src/Dlhis.Canteen/Order/Request/BalanceRecordPageRequest.cs index 34ead05f..b30c502c 100644 --- a/Src/Dlhis.Canteen/Order/Request/BalanceRecordPageRequest.cs +++ b/Src/Dlhis.Canteen/Order/Request/BalanceRecordPageRequest.cs @@ -7,6 +7,17 @@ namespace Dlhis.Canteen.Order.Request; public class BalanceRecordPageRequest : PageDto, IValidatableObject { + /// + /// 营业点codes + /// + public List BusinessplaceCodes { get; set; } + + /// + /// 餐次 + /// + public List ShiftTypes { get; set; } + + /// /// 查询日期范围类型 DateTimeSearchEnumType /// diff --git a/Src/Dlhis.Canteen/Order/Request/OrderPageRequest.cs b/Src/Dlhis.Canteen/Order/Request/OrderPageRequest.cs index cd82d190..95374cfa 100644 --- a/Src/Dlhis.Canteen/Order/Request/OrderPageRequest.cs +++ b/Src/Dlhis.Canteen/Order/Request/OrderPageRequest.cs @@ -4,4 +4,5 @@ namespace Dlhis.Canteen.Order.Request; public class OrderPageRequest : PageDto { + } diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs index ac23c1cd..69810e99 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs @@ -10,12 +10,9 @@ using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.DataAccess.Dto; using Kurisu.Core.DataAccess.Entity; using Kurisu.Core.User.Abstractions; -using Kurisu.SqlSugar.Attributes; using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Services; -using Microsoft.AspNetCore.Mvc; using SqlSugar; -using System.Globalization; namespace Dlhis.Canteen.Order.Services.Implements; @@ -42,6 +39,8 @@ public class BalanceService : IBalanceService .LeftJoin((record, ga, department, bplace, bshift, type) => record.BusinessShiftCode.ToString() == type.Code) .WhereIF(request.SearchDateTimePeriod?.Start.HasValue == true, record => record.CostDate >= request.SearchDateTimePeriod.Start) .WhereIF(request.SearchDateTimePeriod?.End.HasValue == true, record => record.CostDate <= request.SearchDateTimePeriod.End) + .WhereIF(request.BusinessplaceCodes.IsPresent(), record => request.BusinessplaceCodes.Contains(record.BusinessPlaceCode)) + .WhereIF(request.ShiftTypes.IsPresent(), record => request.ShiftTypes.Contains(record.ShiftType)) .OrderBy(record => record.CreateTime, OrderByType.Desc) .Select((record, ga, department, bplace, bshift, type) => new BalanceRecordResponse { @@ -407,7 +406,7 @@ public class BalanceService : IBalanceService } - + public async Task> GetPageByDeviceUniqueNoAsync(BalanceRecordPageByDeviceUniqueNoRequest request) { var now = DateTime.Now; @@ -675,11 +674,11 @@ public class BalanceService : IBalanceService public async Task> GetOaEMealVoucherAsync(OaEMealVoucherRequest request) { - var page = await _dbContext.Queryable() - .Where(x => x.UserCode == request.UserCode) - .Select() - .ToPageListAsync(request); - return page; + var page = await _dbContext.Queryable() + .Where(x => x.UserCode == request.UserCode) + .Select() + .ToPageListAsync(request); + return page; } public async Task> GetOaEMealVoucherDetailAsync(OaEMealVoucherDetailRequest request) @@ -793,6 +792,6 @@ public class BalanceService : IBalanceService { _dbContext.Client.QueryFilter.Restore(); } - + } } diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Controllers/DeviceTaskAssignmentsController.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Controllers/DeviceTaskAssignmentsController.cs index c11add0f..6b72836c 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Controllers/DeviceTaskAssignmentsController.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Controllers/DeviceTaskAssignmentsController.cs @@ -32,5 +32,4 @@ public class DeviceTaskAssignmentsController : ControllerBase { return await _deviceTaskAssignmentService.GetPageAsync(request); } - } diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs index 403ca9fb..ce217e35 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs @@ -6,6 +6,7 @@ using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.DataAccess.Dto; using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Services; +using SqlSugar; namespace Dlhis.ScheduledTask.TaskAssignment.Services.Implements; @@ -23,19 +24,21 @@ public class DeviceTaskAssignmentService : IDeviceTaskAssignmentService var page = await _dbContext.Queryable() .LeftJoin((deviceTask, ga) => deviceTask.UserNo == ga.No) .WhereIF(!request.Search.IsEmpty(), deviceTask => deviceTask.UserNo == request.Search) - .Select((deviceTask, ga) => new DeviceTaskAssignmentResponse - { - DeviceUniqueNo = deviceTask.DeviceUniqueNo, - ResultMessage = deviceTask.ResultMessage, - RetryCount = deviceTask.Version, - Status = deviceTask.Status, - UserNo = deviceTask.UserNo, - UserName = ga.Name, - UserCode = ga.Code, - Type = deviceTask.Type, - LastUpdateTime = deviceTask.ModifiedTime - }) - .ToPageListAsync(request); + .OrderBy(deviceTask => deviceTask.CreateTime, OrderByType.Desc) + .Select((deviceTask, ga) => new DeviceTaskAssignmentResponse + { + DeviceUniqueNo = deviceTask.DeviceUniqueNo, + ResultMessage = deviceTask.ResultMessage, + RetryCount = deviceTask.Version, + Status = deviceTask.Status, + UserNo = deviceTask.UserNo, + UserName = ga.Name, + UserCode = ga.Code, + Type = deviceTask.Type, + LastUpdateTime = deviceTask.ModifiedTime + }) + .ToPageListAsync(request); + return page; } } From 205778fd9f073c5f7157c47cf5a37d579f9ba539 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 29 Feb 2024 10:48:48 +0800 Subject: [PATCH 080/146] =?UTF-8?q?fix=20=E4=BB=BB=E5=8A=A1=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Entity/Device/Enums/DeviceTaskEnumType.cs | 2 +- Src/Dlhis.ScheduledTask/Packs/JobPack.cs | 2 +- ...etAttendanceJob.cs => CreateGetUploadRecordJob.cs} | 11 ++++++----- 3 files changed, 8 insertions(+), 7 deletions(-) rename Src/Dlhis.ScheduledTask/TaskAssignment/Job/{CreateGetAttendanceJob.cs => CreateGetUploadRecordJob.cs} (87%) diff --git a/Src/Dlhis.Entity/Device/Enums/DeviceTaskEnumType.cs b/Src/Dlhis.Entity/Device/Enums/DeviceTaskEnumType.cs index d642dcd5..788c41ec 100644 --- a/Src/Dlhis.Entity/Device/Enums/DeviceTaskEnumType.cs +++ b/Src/Dlhis.Entity/Device/Enums/DeviceTaskEnumType.cs @@ -59,7 +59,7 @@ public enum DeviceTaskEnumType /// - /// 同步时间 + /// 上传记录 /// [Description("上传记录")] UploadRecord = 500, diff --git a/Src/Dlhis.ScheduledTask/Packs/JobPack.cs b/Src/Dlhis.ScheduledTask/Packs/JobPack.cs index fc4c8870..77a184a7 100644 --- a/Src/Dlhis.ScheduledTask/Packs/JobPack.cs +++ b/Src/Dlhis.ScheduledTask/Packs/JobPack.cs @@ -31,7 +31,7 @@ public class JobPack : BaseAppPack }); //创建设备获取考勤的任务 - RecurringJob.AddOrUpdate("CreateGetAttendance", s => s.RunAsync(), "0 0/1 * * * ?", new RecurringJobOptions + RecurringJob.AddOrUpdate("CreateGetUploadRecord", s => s.RunAsync(), "0 0/1 * * * ?", new RecurringJobOptions { TimeZone = TimeZoneInfo.Local }); diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateGetAttendanceJob.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateGetUploadRecordJob.cs similarity index 87% rename from Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateGetAttendanceJob.cs rename to Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateGetUploadRecordJob.cs index 6c8b6cd7..d17e7215 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateGetAttendanceJob.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateGetUploadRecordJob.cs @@ -7,12 +7,12 @@ using Kurisu.SqlSugar.Services; namespace Dlhis.ScheduledTask.TaskAssignment.Job; -public class CreateGetAttendanceJob +public class CreateGetUploadRecordJob { private readonly IDbContext _dbContext; private readonly ILogger _logger; - public CreateGetAttendanceJob(IDbContext dbContext, ILogger logger) + public CreateGetUploadRecordJob(IDbContext dbContext, ILogger logger) { _logger = logger; _dbContext = dbContext; @@ -25,7 +25,8 @@ public class CreateGetAttendanceJob { var devices = await _dbContext.Queryable() .Where(x => x.Enable) - .Where(x => x.Type == DeviceTypeEnumType.Attendance || (x.Type == DeviceTypeEnumType.Door && x.AsAttendance) || x.Type == DeviceTypeEnumType.Door) + .Where(x => x.Type == DeviceTypeEnumType.Attendance || (x.Type == DeviceTypeEnumType.Door && x.AsAttendance) + || x.Type == DeviceTypeEnumType.Door) .ToListAsync(); var ds = devices.Select(x => x.UniqueNo).ToList(); @@ -48,7 +49,6 @@ public class CreateGetAttendanceJob TenantId = x.TenantId, Version = 0, - UserNo = string.Empty, Type = DeviceTaskEnumType.UploadRecord, CreatedBy = 1, @@ -56,7 +56,8 @@ public class CreateGetAttendanceJob ModifiedBy = 1, ModifiedTime = DateTime.Now, - }).ToList(); + }) + .ToList(); await _dbContext.InsertAsync(tasks); } From a0140627c020b6e52ec873b4ac0512d78fb4bed4 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 29 Feb 2024 10:53:51 +0800 Subject: [PATCH 081/146] =?UTF-8?q?fix=20=E4=B8=8B=E5=8F=91=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E7=8A=B6=E6=80=81,=E7=B1=BB=E5=9E=8B=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Request/DeviceTaskAssignmentRequest.cs | 15 ++++++++++++++- .../Response/DeviceTaskAssignmentResponse.cs | 2 ++ .../Implements/DeviceTaskAssignmentService.cs | 5 ++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Request/DeviceTaskAssignmentRequest.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Request/DeviceTaskAssignmentRequest.cs index a7c196f0..d41b722e 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Request/DeviceTaskAssignmentRequest.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Request/DeviceTaskAssignmentRequest.cs @@ -1,7 +1,20 @@ -using Kurisu.Core.DataAccess.Dto; +using System.ComponentModel.DataAnnotations; +using Dlhis.Entity.Device.Enums; +using Kurisu.Core.DataAccess.Dto; namespace Dlhis.ScheduledTask.TaskAssignment.Request; public class DeviceTaskAssignmentRequest : PageDto { + /// + /// 任务类型 + /// + [EnumDataType(typeof(DeviceTaskEnumType))] + public DeviceTaskEnumType? Type { get; set; } + + /// + /// 任务下发状态 + /// + [EnumDataType(typeof(DeviceTaskStatusEnumType))] + public DeviceTaskStatusEnumType? Status { get; set; } } diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Response/DeviceTaskAssignmentResponse.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Response/DeviceTaskAssignmentResponse.cs index e525d6d3..96ae9243 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Response/DeviceTaskAssignmentResponse.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Response/DeviceTaskAssignmentResponse.cs @@ -5,6 +5,8 @@ namespace Dlhis.ScheduledTask.TaskAssignment.Response; public class DeviceTaskAssignmentResponse { + public long Id { get; set; } + /// /// 任务类型 /// diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs index ce217e35..40f2386a 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs @@ -23,10 +23,13 @@ public class DeviceTaskAssignmentService : IDeviceTaskAssignmentService { var page = await _dbContext.Queryable() .LeftJoin((deviceTask, ga) => deviceTask.UserNo == ga.No) - .WhereIF(!request.Search.IsEmpty(), deviceTask => deviceTask.UserNo == request.Search) + .WhereIF(!request.Search.IsEmpty(), (deviceTask, ga) => deviceTask.UserNo == request.Search || ga.Name.Contains(request.Search)) + .WhereIF(request.Type.HasValue, deviceTask => deviceTask.Type == request.Type) + .WhereIF(request.Status.HasValue, deviceTask => deviceTask.Status == request.Status) .OrderBy(deviceTask => deviceTask.CreateTime, OrderByType.Desc) .Select((deviceTask, ga) => new DeviceTaskAssignmentResponse { + Id = deviceTask.Id, DeviceUniqueNo = deviceTask.DeviceUniqueNo, ResultMessage = deviceTask.ResultMessage, RetryCount = deviceTask.Version, From ea93b941e0ba6c5e3f0c4b9a11db0ce0918f5eee Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 29 Feb 2024 13:02:21 +0800 Subject: [PATCH 082/146] =?UTF-8?q?fix=20=E8=BF=87=E6=BB=A4=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Job/CreateGetUploadRecordJob.cs | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateGetUploadRecordJob.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateGetUploadRecordJob.cs index d17e7215..4b2b9062 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateGetUploadRecordJob.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateGetUploadRecordJob.cs @@ -25,24 +25,20 @@ public class CreateGetUploadRecordJob { var devices = await _dbContext.Queryable() .Where(x => x.Enable) - .Where(x => x.Type == DeviceTypeEnumType.Attendance || (x.Type == DeviceTypeEnumType.Door && x.AsAttendance) + .Where(x => x.Type == DeviceTypeEnumType.Attendance || (x.Type == DeviceTypeEnumType.Door && x.AsAttendance) || x.Type == DeviceTypeEnumType.Door) .ToListAsync(); - var ds = devices.Select(x => x.UniqueNo).ToList(); + var uniqueNos = devices.Select(x => x.UniqueNo).ToList(); + //过滤处理中的任务 + uniqueNos = await _dbContext.Queryable() + .Where(x => !uniqueNos.Contains(x.DeviceUniqueNo)) + .Where(x => x.Type == DeviceTaskEnumType.UploadRecord) + .Where(x => x.Status == DeviceTaskStatusEnumType.Process || x.Status == DeviceTaskStatusEnumType.Wait) + .Select(x => x.DeviceUniqueNo) + .ToListAsync(); - var b = await _dbContext.Queryable() - .Where(x => ds.Contains(x.DeviceUniqueNo)) - .Where(x => x.Type == DeviceTaskEnumType.UploadRecord) - .Where(x => x.Status == DeviceTaskStatusEnumType.Process || x.Status == DeviceTaskStatusEnumType.Wait) - .AnyAsync(); - - if (b) - { - return; - } - - var tasks = devices.Select(x => new DeviceTaskEntity + var tasks = devices.Where(x => uniqueNos.Contains(x.UniqueNo)).Select(x => new DeviceTaskEntity { DeviceUniqueNo = x.UniqueNo, Status = DeviceTaskStatusEnumType.Wait, From 942330fd1d1ce9a1864356697fab0e53f4816ada Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 29 Feb 2024 13:02:41 +0800 Subject: [PATCH 083/146] =?UTF-8?q?feat=20=E5=A2=9E=E5=8A=A0=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E7=B1=BB=E5=9E=8B=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TaskAssignment/Request/DeviceTaskGetRequest.cs | 6 ++++++ .../TaskAssignment/Services/Implements/AssignmentService.cs | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Request/DeviceTaskGetRequest.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Request/DeviceTaskGetRequest.cs index 178481ce..84cf335e 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Request/DeviceTaskGetRequest.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Request/DeviceTaskGetRequest.cs @@ -1,4 +1,5 @@ using System.ComponentModel.DataAnnotations; +using Dlhis.Entity.Device.Enums; using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.DataAccess.Dto; @@ -16,6 +17,11 @@ public class DeviceTaskGetRequest : PageDto, IValidatableObject /// public string DeviceUniqueNo { get; set; } + /// + /// 任务类型 + /// + public List Types { get; set; } + /// /// 获取处理中的任务 /// diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs index dee7e916..745c3e60 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs @@ -40,6 +40,7 @@ public class AssignmentService : IAssignmentService .LeftJoin((deviceTask, deivce, deivceTamplate, ga, department) => department.No == ga.DepartmentNo) .WhereIF(request.Brand.IsPresent(), (deviceTask, deivce, deivceTamplate) => deivceTamplate.Brand == request.Brand) .WhereIF(request.DeviceUniqueNo.IsPresent(), (deviceTask, deivce) => deviceTask.DeviceUniqueNo == request.DeviceUniqueNo) + .WhereIF(request.Types.IsPresent(), deviceTask => request.Types.Contains(deviceTask.Type)) .WhereIF(!request.IsProcess, deviceTask => deviceTask.Status == DeviceTaskStatusEnumType.Wait) .WhereIF(request.IsProcess, deviceTask => deviceTask.Status == DeviceTaskStatusEnumType.Process) .OrderBy(deviceTask => deviceTask.CreateTime) @@ -98,6 +99,7 @@ public class AssignmentService : IAssignmentService } return page.Data; + }, 5); if (!data.Any()) @@ -354,7 +356,7 @@ public class AssignmentService : IAssignmentService } catch (Exception ex) when (ex is VersionExceptions) { - _logger.LogWarning(ex, ex.Message); + _logger.LogWarning(ex, "并发更新失败:{message},", ex.Message); } catch (Exception) { From 10cc93cf7639fdf3ffbf181a17c05d236a4df52b Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 29 Feb 2024 13:43:53 +0800 Subject: [PATCH 084/146] =?UTF-8?q?fix=20=E8=BF=87=E6=BB=A4=E6=AD=A3?= =?UTF-8?q?=E5=9C=A8=E5=A4=84=E7=90=86=E7=9A=84=E4=B8=8A=E4=BC=A0=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E8=AE=BE=E5=A4=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TaskAssignment/Job/CreateGetUploadRecordJob.cs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateGetUploadRecordJob.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateGetUploadRecordJob.cs index 4b2b9062..3a53294b 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateGetUploadRecordJob.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateGetUploadRecordJob.cs @@ -29,16 +29,14 @@ public class CreateGetUploadRecordJob || x.Type == DeviceTypeEnumType.Door) .ToListAsync(); - var uniqueNos = devices.Select(x => x.UniqueNo).ToList(); //过滤处理中的任务 - uniqueNos = await _dbContext.Queryable() - .Where(x => !uniqueNos.Contains(x.DeviceUniqueNo)) - .Where(x => x.Type == DeviceTaskEnumType.UploadRecord) - .Where(x => x.Status == DeviceTaskStatusEnumType.Process || x.Status == DeviceTaskStatusEnumType.Wait) - .Select(x => x.DeviceUniqueNo) - .ToListAsync(); + var currentUniqueNos = await _dbContext.Queryable() + .Where(x => x.Type == DeviceTaskEnumType.UploadRecord) + .Where(x => x.Status == DeviceTaskStatusEnumType.Process || x.Status == DeviceTaskStatusEnumType.Wait) + .Select(x => x.DeviceUniqueNo) + .ToListAsync(); - var tasks = devices.Where(x => uniqueNos.Contains(x.UniqueNo)).Select(x => new DeviceTaskEntity + var tasks = devices.Where(x => !currentUniqueNos.Contains(x.UniqueNo)).Select(x => new DeviceTaskEntity { DeviceUniqueNo = x.UniqueNo, Status = DeviceTaskStatusEnumType.Wait, From dc1ba173d129619b9d336cde076aa1e03c2ae4b0 Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Fri, 1 Mar 2024 11:04:14 +0800 Subject: [PATCH 085/146] =?UTF-8?q?fix=20=E4=BF=AE=E6=94=B9GetShiftCode()?= =?UTF-8?q?=E7=A9=BA=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Implements/BalanceService.cs | 50 +++++++++++++++---- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs index 69810e99..fbbced47 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs @@ -768,18 +768,48 @@ public class BalanceService : IBalanceService var shifts = await _dbContext.Queryable().ToListAsync(); //guid - var breakfastCode = shifts.Where(x => x.CustomCode == "shift-breakfast").Select(x => x.Code).First().ToString(); + //早餐 + var breakfast = shifts.Where(x => x.CustomCode == "shift-breakfast").FirstOrDefault(); + var codeBreakfast = "Breakfast"; + if (breakfast != null) + { + codeBreakfast = breakfast.Code.ToString(); + } + //午餐 + var lunch = shifts.Where(x => x.CustomCode == "shift-lunch").FirstOrDefault(); + var codeLunch = "Lunch"; + if (lunch != null) + { + codeLunch = lunch.Code.ToString(); + } + //晚餐 + var dinner = shifts.Where(x => x.CustomCode == "shift-dinner").FirstOrDefault(); + var codeDinner = "Dinner"; + if (dinner != null) + { + codeDinner = dinner.Code.ToString(); + } + //宵夜 + var nightsnack = shifts.Where(x => x.CustomCode == "shift-nightsnack").FirstOrDefault(); + var codeNightsnack = "Nightsnack"; + if (nightsnack != null) + { + codeNightsnack = nightsnack.Code.ToString(); + } + //凌晨 + var midnightsnack = shifts.Where(x => x.CustomCode == "shift-midnightsnack").FirstOrDefault(); + var codeMidnightsnack = "Midnightsnack"; + if (midnightsnack != null) + { + codeMidnightsnack = midnightsnack.Code.ToString(); + } - var lunchCode = shifts.Where(x => x.CustomCode == "shift-lunch").Select(x => x.Code).First().ToString(); - var dinnerCode = shifts.Where(x => x.CustomCode == "shift-dinner").Select(x => x.Code).First().ToString(); - - var lateNightCode = shifts.Where(x => x.CustomCode == "shift-midnightsnack").Select(x => x.Code).First().ToString(); - - shiftCodeDict.Add("Breakfast", breakfastCode.ToString()); - shiftCodeDict.Add("Lunch", lunchCode.ToString()); - shiftCodeDict.Add("Dinner", dinnerCode.ToString()); - shiftCodeDict.Add("LateNight", lateNightCode.ToString()); + shiftCodeDict.Add("Breakfast", codeBreakfast); + shiftCodeDict.Add("Lunch", codeLunch); + shiftCodeDict.Add("Dinner", codeDinner); + shiftCodeDict.Add("LateNight", codeNightsnack); + shiftCodeDict.Add("Midnightsnack", codeMidnightsnack); return shiftCodeDict; } From 0dc2192dad9e35af571b162149067f7145e8b3c2 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Fri, 1 Mar 2024 12:03:28 +0800 Subject: [PATCH 086/146] =?UTF-8?q?fix=20=E5=8F=AF=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E8=AE=BE=E5=A4=87=E4=BF=9D=E5=AD=98=E6=97=B6?= =?UTF-8?q?=E5=80=99=E8=87=AA=E5=8A=A8=E4=BA=A7=E7=94=9F=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...Jinko.Yikatong.sln => Dlhis.Jinko.Face.sln | 0 .../DevicePermissionsController.cs | 4 +- .../Services/Implements/DeviceService.cs | 40 ++++++++++++++++--- Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs | 2 + .../Controllers/DeviceUploadLogsController.cs | 12 ++++++ .../SetUploadLogsBeginDateTimeRequest.cs | 17 ++++++++ .../Services/IDeviceUploadLogService.cs | 1 + .../Implements/DeviceUploadLogService.cs | 26 ++++++++++++ Src/Dlhis.ScheduledTask/Packs/JobPack.cs | 2 +- .../Job/CreateGetUploadRecordJob.cs | 3 +- .../Services/Implements/AssignmentService.cs | 5 --- 11 files changed, 95 insertions(+), 17 deletions(-) rename Dlis.Jinko.Yikatong.sln => Dlhis.Jinko.Face.sln (100%) create mode 100644 Src/Dlhis.ScheduledTask/DeviceUploadLog/Request/SetUploadLogsBeginDateTimeRequest.cs diff --git a/Dlis.Jinko.Yikatong.sln b/Dlhis.Jinko.Face.sln similarity index 100% rename from Dlis.Jinko.Yikatong.sln rename to Dlhis.Jinko.Face.sln diff --git a/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs b/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs index fffc51f0..c13ca4bc 100644 --- a/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs +++ b/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs @@ -1,8 +1,6 @@ -using System.Diagnostics; -using Dlhis.Basic.Device.Request; +using Dlhis.Basic.Device.Request; using Dlhis.Basic.Device.Response; using Dlhis.Basic.Device.Services; -using Dlhis.Basic.Packs; using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop; using Kurisu.Core.DataAccess.Dto; using Microsoft.AspNetCore.Authorization; diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs index f0afeb56..d9a06f35 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs @@ -5,7 +5,6 @@ using Dlhis.Entity.Canteen.Entities; using Dlhis.Entity.Canteen.Enums; using Dlhis.Entity.Device.Entities; using Dlhis.Entity.Device.Enums; -using Kurisu.AspNetCore.Scope; using Kurisu.AspNetCore.UnifyResultAndValidation; using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.DataAccess.Dto; @@ -92,9 +91,10 @@ public class DeviceService : IDeviceService var template = await CheckTemplateExistsAsync(request.TemplateCode); await CheckTemplateFieldAsync(request.TemplateCode, request.ConnectionInfo); + DeviceEntity entity = null; if (!request.Id.HasValue) { - var entity = request.Adapt(); + entity = request.Adapt(); entity.Code = Guid.NewGuid(); await _dbContext.InsertAsync(entity); //同时保存注册信息 @@ -115,7 +115,7 @@ public class DeviceService : IDeviceService } else { - var entity = await _dbContext.Queryable().Where(x => x.Id == request.Id).FirstAsync(); + entity = await _dbContext.Queryable().Where(x => x.Id == request.Id).FirstAsync(); entity.ThrowIfNull("设备不存在,无法更新"); //分类发生变化,检查是否存在分组 @@ -130,15 +130,42 @@ public class DeviceService : IDeviceService existsG.ThrowIfTrue("存在设备分组,不可修改设备分类"); } - var uniqueNo = entity.UniqueNo; - request.Adapt(entity).UniqueNo = uniqueNo; - + request.Adapt(entity); await _dbContext.UpdateAsync(entity); } + + await GenerateUploadRecordLogForBeginTimeAsync(entity); } //******************************************************** help methods ********************************************************** + private async Task GenerateUploadRecordLogForBeginTimeAsync(DeviceEntity entity) + { + if (entity.Type == DeviceTypeEnumType.Door || entity.Type == DeviceTypeEnumType.Attendance) + { + var exists = await _dbContext.Queryable() + .Where(x => x.DeviceUniqueNo == entity.UniqueNo) + .Where(x => x.Type == DeviceUploadLogTypeEnumType.Raise) + .AnyAsync(); + + if (!exists) + { + await _dbContext.InsertAsync(new DeviceUploadLogEntity + { + DeviceUniqueNo = entity.UniqueNo, + Type = DeviceUploadLogTypeEnumType.Raise, + UserUniqueNo = string.Empty, + RaiseDateTime = entity.CreateTime, + + CreatedBy = 1, + CreateTime = DateTime.Now, + ModifiedBy = 1, + ModifiedTime = DateTime.Now, + }); + } + } + } + /// /// 检查设备模板是否存在 /// @@ -230,6 +257,7 @@ public class DeviceService : IDeviceService { var devices = await _dbContext.Queryable() .Where(x => x.Enable) + .Where(x => x.Type == DeviceTypeEnumType.Attendance || (x.Type == DeviceTypeEnumType.Door && x.AsAttendance)) .Select(x => new DeviceResponse { FuncsStr = x.Funcs.ToString() diff --git a/Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs b/Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs index 6bde31c3..5804a32d 100644 --- a/Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs +++ b/Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs @@ -1,6 +1,7 @@ using Dlhis.Entity.Device.Enums; using Kurisu.Core.DataAccess.Entity; using Kurisu.SqlSugar; +using Mapster; using SqlSugar; using SqlSugar.DbConvert; @@ -21,6 +22,7 @@ public class DeviceEntity : SugarBaseEntity, ITenantId /// /// 设备唯一码,IP/MAC/SNO /// + [AdaptIgnore(MemberSide.Destination)] [SugarColumn(ColumnDescription = "设备唯一码", UniqueGroupNameList = new[] { "Idx_Device_UniqueNo" })] public string UniqueNo { get; set; } diff --git a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Controllers/DeviceUploadLogsController.cs b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Controllers/DeviceUploadLogsController.cs index a463aeac..9e2e6567 100644 --- a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Controllers/DeviceUploadLogsController.cs +++ b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Controllers/DeviceUploadLogsController.cs @@ -45,4 +45,16 @@ public class DeviceUploadLogsController : ControllerBase { await _deviceUploadLogService.UploadLogsAsync(requests); } + + /// + /// 设置设备获取记录开始时间 + /// + /// + /// + [HttpPost("reset-begintime")] + [Transactional] + public async Task SetUploadLogsBeginDateTime(List requests) + { + await _deviceUploadLogService.SetUploadLogsBeginDateTimeAsync(requests); + } } diff --git a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Request/SetUploadLogsBeginDateTimeRequest.cs b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Request/SetUploadLogsBeginDateTimeRequest.cs new file mode 100644 index 00000000..e5a65b58 --- /dev/null +++ b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Request/SetUploadLogsBeginDateTimeRequest.cs @@ -0,0 +1,17 @@ +using System.ComponentModel.DataAnnotations; + +namespace Dlhis.ScheduledTask.DeviceUploadLog.Request; + +public class SetUploadLogsBeginDateTimeRequest +{ + /// + /// 设备号不能为空 + /// + [Required(ErrorMessage = "设备号不能为空")] + public string DeviceUniqueNo { get; set; } + + /// + /// 开始时间 + /// + public DateTime Begin { get; set; } +} diff --git a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/IDeviceUploadLogService.cs b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/IDeviceUploadLogService.cs index cc4a6b3e..0d41b450 100644 --- a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/IDeviceUploadLogService.cs +++ b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/IDeviceUploadLogService.cs @@ -10,4 +10,5 @@ public interface IDeviceUploadLogService : IScopeDependency Task UploadLogsAsync(List requests); + Task SetUploadLogsBeginDateTimeAsync(List requests); } diff --git a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs index 1397e0da..335376f4 100644 --- a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs +++ b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs @@ -1,6 +1,7 @@ using System.Linq.Expressions; using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Device.Entities; +using Dlhis.Entity.Device.Enums; using Dlhis.ScheduledTask.DeviceUploadLog.Request; using Dlhis.ScheduledTask.DeviceUploadLog.Response; using Kurisu.AspNetCore.Utils.Extensions; @@ -95,4 +96,29 @@ public class DeviceUploadLogService : IDeviceUploadLogService await _dbContext.InsertAsync(records); } + public async Task SetUploadLogsBeginDateTimeAsync(List requests) + { + var uniqueNos = requests.DistinctBy(x => x.DeviceUniqueNo).Select(x => x.DeviceUniqueNo).ToList(); + var devices = await _dbContext.Queryable() + .Where(x => uniqueNos.Contains(x.UniqueNo)) + .Where(x => x.Type == DeviceTypeEnumType.Attendance || x.Type == DeviceTypeEnumType.Door) + .ToListAsync(); + + (uniqueNos.Count != devices.Count).ThrowIfTrue("存在非考勤和门禁的设备"); + + var tenantId = devices.FirstOrDefault().TenantId; + var logs = new List(requests.Count); + foreach (var request in requests) + { + logs.Add(new DeviceUploadLogEntity + { + DeviceUniqueNo = request.DeviceUniqueNo, + Type = DeviceUploadLogTypeEnumType.Raise, + RaiseDateTime = request.Begin, + TenantId = tenantId + }); + } + + await _dbContext.InsertAsync(logs); + } } diff --git a/Src/Dlhis.ScheduledTask/Packs/JobPack.cs b/Src/Dlhis.ScheduledTask/Packs/JobPack.cs index 77a184a7..77812d77 100644 --- a/Src/Dlhis.ScheduledTask/Packs/JobPack.cs +++ b/Src/Dlhis.ScheduledTask/Packs/JobPack.cs @@ -30,7 +30,7 @@ public class JobPack : BaseAppPack TimeZone = TimeZoneInfo.Local }); - //创建设备获取考勤的任务 + //创建设备获取的任务 RecurringJob.AddOrUpdate("CreateGetUploadRecord", s => s.RunAsync(), "0 0/1 * * * ?", new RecurringJobOptions { TimeZone = TimeZoneInfo.Local diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateGetUploadRecordJob.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateGetUploadRecordJob.cs index 3a53294b..c66584a7 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateGetUploadRecordJob.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Job/CreateGetUploadRecordJob.cs @@ -25,8 +25,7 @@ public class CreateGetUploadRecordJob { var devices = await _dbContext.Queryable() .Where(x => x.Enable) - .Where(x => x.Type == DeviceTypeEnumType.Attendance || (x.Type == DeviceTypeEnumType.Door && x.AsAttendance) - || x.Type == DeviceTypeEnumType.Door) + .Where(x => x.Type == DeviceTypeEnumType.Attendance || x.Type == DeviceTypeEnumType.Door) .ToListAsync(); //过滤处理中的任务 diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs index 745c3e60..2cd633bd 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs @@ -315,11 +315,6 @@ public class AssignmentService : IAssignmentService requests = requests.Where(x => taskIds.Contains(x.TaskId)).ToList(); - deviceTasks.ForEach(x => - { - - }); - var now = DateTime.Now; var tasks = new List(requests.Count); foreach (var request in requests) From 83d5e4f166b208ca6213ac37d2e575f7ccd62850 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Fri, 1 Mar 2024 12:20:37 +0800 Subject: [PATCH 087/146] =?UTF-8?q?fix=20=E5=88=86=E9=A1=B5=E5=80=92?= =?UTF-8?q?=E6=8E=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Implements/DeviceUploadLogService.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs index 335376f4..f8c0a199 100644 --- a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs +++ b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs @@ -26,6 +26,7 @@ public class DeviceUploadLogService : IDeviceUploadLogService var page = await _dbContext.Queryable() .WhereIF(request.SearchDateTimePeriod?.Start.HasValue == true, deviceUp => deviceUp.RaiseDateTime >= request.SearchDateTimePeriod.Start) .WhereIF(request.SearchDateTimePeriod?.End.HasValue == true, deviceUp => deviceUp.RaiseDateTime <= request.SearchDateTimePeriod.End) + .OrderBy(deviceUp => deviceUp.CreateTime, OrderByType.Desc) .Select((deviceUp) => new DeviceUploadLogResponse { OriginUserUniqueNo = deviceUp.UserUniqueNo, From 80088df845aeed7fe2f042ec4da73a1f08aea1d6 Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Fri, 1 Mar 2024 13:51:26 +0800 Subject: [PATCH 088/146] =?UTF-8?q?fix=20=E7=A7=BB=E5=8A=A8api=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Device/Controllers/DevicesController.cs | 9 --- .../Device/Request/ApiLogRequest.cs | 13 ----- .../Device/Response/ApiLogResponse.cs | 56 ------------------ .../Device/Services/IDeviceService.cs | 2 - .../Services/Implements/DeviceService.cs | 10 ---- .../Services/Implements/BalanceService.cs | 1 + .../ApiLog/ApiLogServiceController.cs | 36 ++++++++++++ Src/Dlhis.Common/Program.cs | 3 +- Src/Dlhis.Common/Request/ApiLogRequest.cs | 14 +++++ Src/Dlhis.Common/Response/ApiLogResponse.cs | 57 +++++++++++++++++++ Src/Dlhis.Common/Services/ApiLogService.cs | 32 +++++++++++ .../Services/Implements/IApiLogService.cs | 11 ++++ Src/Dlhis.Common/SqlSugarPack.cs | 48 ++++++++++++++++ Src/Dlhis.Common/appsettings.json | 2 + .../{Basic/Entity => Common}/ApiLogEntity.cs | 6 +- 15 files changed, 206 insertions(+), 94 deletions(-) delete mode 100644 Src/Dlhis.Basic/Device/Request/ApiLogRequest.cs delete mode 100644 Src/Dlhis.Basic/Device/Response/ApiLogResponse.cs create mode 100644 Src/Dlhis.Common/ApiLog/ApiLogServiceController.cs create mode 100644 Src/Dlhis.Common/Request/ApiLogRequest.cs create mode 100644 Src/Dlhis.Common/Response/ApiLogResponse.cs create mode 100644 Src/Dlhis.Common/Services/ApiLogService.cs create mode 100644 Src/Dlhis.Common/Services/Implements/IApiLogService.cs create mode 100644 Src/Dlhis.Common/SqlSugarPack.cs rename Src/Dlhis.Entity/{Basic/Entity => Common}/ApiLogEntity.cs (93%) diff --git a/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs b/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs index 9829ea9a..14c35704 100644 --- a/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs +++ b/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs @@ -208,13 +208,4 @@ public class DevicesController : ControllerBase return await _deviceService.GetRecentNumbersAsync(); } - /// - /// 获取api日志 - /// - /// - [HttpGet("logs")] - public async Task> GetLogsAsync([FromQuery]ApiLogRequest request) - { - return await _deviceService.GetLogsAsync(request); - } } diff --git a/Src/Dlhis.Basic/Device/Request/ApiLogRequest.cs b/Src/Dlhis.Basic/Device/Request/ApiLogRequest.cs deleted file mode 100644 index 03278171..00000000 --- a/Src/Dlhis.Basic/Device/Request/ApiLogRequest.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Kurisu.Core.DataAccess.Dto; -using System.ComponentModel.DataAnnotations; - -namespace Dlhis.Basic.Device.Request; - -public class ApiLogRequest : PageDto -{ - /// - /// 日志级别 LogLevel - /// - [EnumDataType(typeof(LogLevel))] - public LogLevel? Level { get; set; } -} diff --git a/Src/Dlhis.Basic/Device/Response/ApiLogResponse.cs b/Src/Dlhis.Basic/Device/Response/ApiLogResponse.cs deleted file mode 100644 index 38fca5e6..00000000 --- a/Src/Dlhis.Basic/Device/Response/ApiLogResponse.cs +++ /dev/null @@ -1,56 +0,0 @@ -using Newtonsoft.Json; - -namespace Dlhis.Basic.Device.Response; - -public class ApiLogResponse -{ - /// - /// 时间UTC - /// - [JsonIgnore] - public string Timestamp { get; set; } - - /// - /// 产生时间 - /// - public DateTime RaiseTime - { - get - { - return DateTime.Parse(Timestamp).ToLocalTime(); - } - } - - /// - /// 级别 - /// - public string Level { get; set; } - - /// - /// 模板 - /// - [JsonIgnore] - public string Template { get; set; } - - /// - /// 消息内容 - /// - public string Message { get; set; } - - /// - /// 异常内容 - /// - public string Exception { get; set; } - - /// - /// 属性 - /// - [JsonIgnore] - public string Properties { get; set; } - - /// - /// 时间 - /// - [JsonIgnore] - public DateTime _TS { get; set; } -} diff --git a/Src/Dlhis.Basic/Device/Services/IDeviceService.cs b/Src/Dlhis.Basic/Device/Services/IDeviceService.cs index b6ab81bf..fa3176e7 100644 --- a/Src/Dlhis.Basic/Device/Services/IDeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/IDeviceService.cs @@ -24,6 +24,4 @@ public interface IDeviceService : IScopeDependency Task> GetRecentNumbersAsync(); - Task> GetLogsAsync(ApiLogRequest request); - } diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs index d9a06f35..8173bcf9 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs @@ -405,15 +405,5 @@ public class DeviceService : IDeviceService return list; } - public async Task> GetLogsAsync(ApiLogRequest request) - { - var logs = await _dbContext.ChangeDb("log").Queryable() - .WhereIF(request.Search.IsPresent(), x => x.Message.Contains(request.Search)) - .WhereIF(request.Level.HasValue, x => x.Level == request.Level) - .Select() - .ToPageListAsync(request); - - return logs; - } } diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs index fbbced47..b4556880 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs @@ -388,6 +388,7 @@ public class BalanceService : IBalanceService obj.LunchNumberOfPeople = first.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Lunch"]).Select(x => x.UserNo).Distinct().Count(); obj.DinnerNumberOfPeople = first.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Dinner"]).Select(x => x.UserNo).Distinct().Count(); obj.LateNightNumberOfPeople = first.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["LateNight"]).Select(x => x.UserNo).Distinct().Count(); + obj.TotalNumberOfPeople = obj.BreakfastNumberOfPeople + obj.LunchNumberOfPeople + obj.DinnerNumberOfPeople + obj.LateNightNumberOfPeople; lst.Add(obj); } // 分页操作 diff --git a/Src/Dlhis.Common/ApiLog/ApiLogServiceController.cs b/Src/Dlhis.Common/ApiLog/ApiLogServiceController.cs new file mode 100644 index 00000000..03376a79 --- /dev/null +++ b/Src/Dlhis.Common/ApiLog/ApiLogServiceController.cs @@ -0,0 +1,36 @@ +using Dlhis.Common.Request; +using Dlhis.Common.Response; +using Dlhis.Common.Services.Implements; +using Kurisu.Core.DataAccess.Dto; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace Dlhis.Common.ApiLog +{ + /// + /// api日志控制器 + /// + [Authorize] + [Route("api/[controller]")] + [ApiController] + public class ApiLogServiceController : ControllerBase + { + private readonly IApiLogService _apiLogService; + + public ApiLogServiceController(IApiLogService apiLogService) + { + _apiLogService = apiLogService; + } + + /// + /// 获取api日志 + /// + /// + [HttpGet("logs")] + public async Task> GetLogsAsync([FromQuery] ApiLogRequest request) + { + return await _apiLogService.GetLogsAsync(request); + } + } +} diff --git a/Src/Dlhis.Common/Program.cs b/Src/Dlhis.Common/Program.cs index 1bcd1be2..6b0c15e8 100644 --- a/Src/Dlhis.Common/Program.cs +++ b/Src/Dlhis.Common/Program.cs @@ -1,4 +1,5 @@ using Kurisu.AspNetCore.Startup; +using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Startup; class Program @@ -13,6 +14,6 @@ public class Startup : DefaultStartup { public Startup(IConfiguration configuration) : base(configuration) { - + } } \ No newline at end of file diff --git a/Src/Dlhis.Common/Request/ApiLogRequest.cs b/Src/Dlhis.Common/Request/ApiLogRequest.cs new file mode 100644 index 00000000..ca4d00cc --- /dev/null +++ b/Src/Dlhis.Common/Request/ApiLogRequest.cs @@ -0,0 +1,14 @@ +using Kurisu.Core.DataAccess.Dto; +using System.ComponentModel.DataAnnotations; + +namespace Dlhis.Common.Request +{ + public class ApiLogRequest : PageDto + { + /// + /// 日志级别 LogLevel + /// + [EnumDataType(typeof(LogLevel))] + public LogLevel? Level { get; set; } + } +} diff --git a/Src/Dlhis.Common/Response/ApiLogResponse.cs b/Src/Dlhis.Common/Response/ApiLogResponse.cs new file mode 100644 index 00000000..ff51f853 --- /dev/null +++ b/Src/Dlhis.Common/Response/ApiLogResponse.cs @@ -0,0 +1,57 @@ +using Newtonsoft.Json; + +namespace Dlhis.Common.Response +{ + public class ApiLogResponse + { + /// + /// 时间UTC + /// + [JsonIgnore] + public string Timestamp { get; set; } + + /// + /// 产生时间 + /// + public DateTime RaiseTime + { + get + { + return DateTime.Parse(Timestamp).ToLocalTime(); + } + } + + /// + /// 级别 + /// + public string Level { get; set; } + + /// + /// 模板 + /// + [JsonIgnore] + public string Template { get; set; } + + /// + /// 消息内容 + /// + public string Message { get; set; } + + /// + /// 异常内容 + /// + public string Exception { get; set; } + + /// + /// 属性 + /// + [JsonIgnore] + public string Properties { get; set; } + + /// + /// 时间 + /// + [JsonIgnore] + public DateTime _TS { get; set; } + } +} diff --git a/Src/Dlhis.Common/Services/ApiLogService.cs b/Src/Dlhis.Common/Services/ApiLogService.cs new file mode 100644 index 00000000..b25c9ed3 --- /dev/null +++ b/Src/Dlhis.Common/Services/ApiLogService.cs @@ -0,0 +1,32 @@ +using Dlhis.Common.Request; +using Dlhis.Common.Response; +using Dlhis.Common.Services.Implements; +using Dlhis.Entity.Common; +using Kurisu.AspNetCore.Utils.Extensions; +using Kurisu.Core.DataAccess.Dto; +using Kurisu.SqlSugar.Extensions; +using Kurisu.SqlSugar.Services; + +namespace Dlhis.Common.Services +{ + public class ApiLogService : IApiLogService + { + private readonly IDbContext _dbContext; + + public ApiLogService(IDbContext dbContext) + { + _dbContext = dbContext; + } + + public async Task> GetLogsAsync(ApiLogRequest request) + { + var logs = await _dbContext.ChangeDb("log").Queryable() + .WhereIF(request.Search.IsPresent(), x => x.Message.Contains(request.Search)) + .WhereIF(request.Level.HasValue, x => x.Level == request.Level) + .Select() + .ToPageListAsync(request); + + return logs; + } + } +} diff --git a/Src/Dlhis.Common/Services/Implements/IApiLogService.cs b/Src/Dlhis.Common/Services/Implements/IApiLogService.cs new file mode 100644 index 00000000..4006c3b1 --- /dev/null +++ b/Src/Dlhis.Common/Services/Implements/IApiLogService.cs @@ -0,0 +1,11 @@ +using Dlhis.Common.Request; +using Dlhis.Common.Response; +using Kurisu.Core.DataAccess.Dto; + +namespace Dlhis.Common.Services.Implements +{ + public interface IApiLogService : IScopeDependency + { + Task> GetLogsAsync(ApiLogRequest request); + } +} diff --git a/Src/Dlhis.Common/SqlSugarPack.cs b/Src/Dlhis.Common/SqlSugarPack.cs new file mode 100644 index 00000000..185e346e --- /dev/null +++ b/Src/Dlhis.Common/SqlSugarPack.cs @@ -0,0 +1,48 @@ +using Kurisu.AspNetCore.Startup; +using Kurisu.SqlSugar.Extensions; +using SqlSugar; + +namespace Dlhis.Common; + +public class SqlSugarPack : BaseAppPack +{ + + public override bool IsBeforeUseRouting { get; } + + public override void ConfigureServices(IServiceCollection services) + { + services.AddSqlSugar(sp => + { + var configuration = sp.GetService(); + return new List + { + new ConnectionConfig + { + ConfigId = "face", + ConnectionString = configuration.GetSection("SqlSugarOptions:FaceConnectionString").Value, + DbType = DbType.MySql, + InitKeyType = InitKeyType.Attribute, + IsAutoCloseConnection = true, + MoreSettings = new ConnMoreSettings + { + DisableNvarchar = true, + } + }, + new ConnectionConfig + { + ConfigId = "log", + ConnectionString = configuration.GetSection("SqlSugarOptions:LogConnectionString").Value, + DbType = DbType.MySql, + InitKeyType = InitKeyType.Attribute, + IsAutoCloseConnection = true, + MoreSettings = new ConnMoreSettings + { + DisableNvarchar = true, + } + + } + }; + }); + } + +} \ No newline at end of file diff --git a/Src/Dlhis.Common/appsettings.json b/Src/Dlhis.Common/appsettings.json index 5dffea5e..b73cd02e 100644 --- a/Src/Dlhis.Common/appsettings.json +++ b/Src/Dlhis.Common/appsettings.json @@ -8,6 +8,8 @@ "SqlSugarOptions": { "DefaultConnectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=yikatong;charset=utf8mb4;", "SlaveConnectionString": [], + "FaceConnectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=face;charset=utf8mb4;", + "LogConnectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=log;charset=utf8mb4;", "Timeout": 30, "SlowSqlTime": 1, "EnableSqlLog": false diff --git a/Src/Dlhis.Entity/Basic/Entity/ApiLogEntity.cs b/Src/Dlhis.Entity/Common/ApiLogEntity.cs similarity index 93% rename from Src/Dlhis.Entity/Basic/Entity/ApiLogEntity.cs rename to Src/Dlhis.Entity/Common/ApiLogEntity.cs index 96ddaa22..70e0849e 100644 --- a/Src/Dlhis.Entity/Basic/Entity/ApiLogEntity.cs +++ b/Src/Dlhis.Entity/Common/ApiLogEntity.cs @@ -1,8 +1,8 @@ -using Microsoft.Extensions.Logging; -using SqlSugar; +using SqlSugar; using SqlSugar.DbConvert; +using Microsoft.Extensions.Logging; -namespace Dlhis.Entity.Basic.Entity; +namespace Dlhis.Entity.Common; /// /// api日志表 From bb236be406e832ddba3e90a45069e33df9d99629 Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Fri, 1 Mar 2024 15:16:09 +0800 Subject: [PATCH 089/146] =?UTF-8?q?fix=20=E4=BF=AE=E6=94=B9api=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=E5=99=A8=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{ApiLogServiceController.cs => ApiLogController.cs} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename Src/Dlhis.Common/ApiLog/{ApiLogServiceController.cs => ApiLogController.cs} (84%) diff --git a/Src/Dlhis.Common/ApiLog/ApiLogServiceController.cs b/Src/Dlhis.Common/ApiLog/ApiLogController.cs similarity index 84% rename from Src/Dlhis.Common/ApiLog/ApiLogServiceController.cs rename to Src/Dlhis.Common/ApiLog/ApiLogController.cs index 03376a79..2a912ac4 100644 --- a/Src/Dlhis.Common/ApiLog/ApiLogServiceController.cs +++ b/Src/Dlhis.Common/ApiLog/ApiLogController.cs @@ -9,16 +9,16 @@ using Microsoft.AspNetCore.Mvc; namespace Dlhis.Common.ApiLog { /// - /// api日志控制器 + /// API日志控制器 /// [Authorize] [Route("api/[controller]")] [ApiController] - public class ApiLogServiceController : ControllerBase + public class ApiLogController : ControllerBase { private readonly IApiLogService _apiLogService; - public ApiLogServiceController(IApiLogService apiLogService) + public ApiLogController(IApiLogService apiLogService) { _apiLogService = apiLogService; } From 640143eb6b655fa95fc734eefdb9ca849cbc9335 Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Mon, 4 Mar 2024 13:56:30 +0800 Subject: [PATCH 090/146] =?UTF-8?q?fix=20=E4=BF=AE=E6=AD=A3=E7=A6=BB?= =?UTF-8?q?=E7=BA=BF=E8=AE=BE=E5=A4=87=E5=88=A4=E6=96=AD=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Implements/DeviceService.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs index 8173bcf9..f06f81c4 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs @@ -298,16 +298,24 @@ public class DeviceService : IDeviceService var list = new List(); foreach (var device in devices) { - var regis = deviceRegistrys.FirstOrDefault(x => x.DeviceUniqueNo == device.UniqueNo); - if (regis == null) + if(device.HeartbeatInterval > 0) { - continue; + var regis = deviceRegistrys.FirstOrDefault(x => x.DeviceUniqueNo == device.UniqueNo); + if (regis == null) + { + continue; + } + TimeSpan timeDifference = DateTime.Now - regis.LastHeartbeatTime; + if (timeDifference.TotalSeconds > (device.HeartbeatInterval * 3)) + { + list.Add(device); + } } - TimeSpan timeDifference = DateTime.Now - regis.LastHeartbeatTime; - if (timeDifference.TotalSeconds > (device.HeartbeatInterval * 3)) + else { list.Add(device); } + } return list; } From fde0c2394ea9751259950a95975ab37f6a5779b6 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 5 Mar 2024 10:03:47 +0800 Subject: [PATCH 091/146] =?UTF-8?q?fix=20=E4=BC=98=E5=8C=96=E7=BB=86?= =?UTF-8?q?=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Request/DeviceOnlineAndofflineRequest.cs | 2 +- .../CommonJobs/HeartbeatJob.cs | 2 +- .../Implements/DeviceUploadLogService.cs | 28 ++++++++++--------- .../Services/Implements/UserService.cs | 3 +- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/Src/Dlhis.Basic/Device/Request/DeviceOnlineAndofflineRequest.cs b/Src/Dlhis.Basic/Device/Request/DeviceOnlineAndofflineRequest.cs index 14b9b1b5..0100289f 100644 --- a/Src/Dlhis.Basic/Device/Request/DeviceOnlineAndofflineRequest.cs +++ b/Src/Dlhis.Basic/Device/Request/DeviceOnlineAndofflineRequest.cs @@ -2,7 +2,7 @@ namespace Dlhis.Basic.Device.Request { - public class DeviceOnlineAndofflineRequest :PageDto + public class DeviceOnlineAndofflineRequest : PageDto { public bool IsOnAndOff { get; set; } } diff --git a/Src/Dlhis.ScheduledTask/CommonJobs/HeartbeatJob.cs b/Src/Dlhis.ScheduledTask/CommonJobs/HeartbeatJob.cs index a8bd8579..ed994038 100644 --- a/Src/Dlhis.ScheduledTask/CommonJobs/HeartbeatJob.cs +++ b/Src/Dlhis.ScheduledTask/CommonJobs/HeartbeatJob.cs @@ -42,7 +42,7 @@ public class HeartbeatJob } catch (Exception ex) { - _logger.LogError(ex, "心跳设备失败:{message}", ex.Message); + _logger.LogError(ex, "心跳设备失败:{no}. {message}", device.UniqueNo, ex.Message); } } } diff --git a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs index f8c0a199..775d130d 100644 --- a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs +++ b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs @@ -24,32 +24,34 @@ public class DeviceUploadLogService : IDeviceUploadLogService public async Task> GetPageAsync(DeviceUploadLogPageRequest request) { var page = await _dbContext.Queryable() + .LeftJoin((deviceUp, ga) => deviceUp.UserUniqueNo == ga.Code) .WhereIF(request.SearchDateTimePeriod?.Start.HasValue == true, deviceUp => deviceUp.RaiseDateTime >= request.SearchDateTimePeriod.Start) .WhereIF(request.SearchDateTimePeriod?.End.HasValue == true, deviceUp => deviceUp.RaiseDateTime <= request.SearchDateTimePeriod.End) + .WhereIF(request.Search.IsPresent(), (deviceUp, ga) => ga.Code.Contains(request.Search) || ga.Name.Contains(request.Search) || deviceUp.DeviceUniqueNo.Contains(request.Search)) .OrderBy(deviceUp => deviceUp.CreateTime, OrderByType.Desc) - .Select((deviceUp) => new DeviceUploadLogResponse + .Select((deviceUp, ga) => new DeviceUploadLogResponse { OriginUserUniqueNo = deviceUp.UserUniqueNo, DeviceUniqueNo = deviceUp.DeviceUniqueNo, Id = deviceUp.Id, RaiseDateTime = deviceUp.RaiseDateTime, SerialNo = deviceUp.SerialNo, - //UserNo = ga.No, - //UserCode = ga.Code, - //UserName = ga.Name, + UserNo = ga.No, + UserCode = ga.Code, + UserName = ga.Name, }) .ToPageListAsync(request); - var gainfos = await _dbContext.Queryable().ToListAsync(); - page.Data.ForEach(item => - { - _ = int.TryParse(item.OriginUserUniqueNo, out var userId); + //var gainfos = await _dbContext.Queryable().ToListAsync(); + //page.Data.ForEach(item => + //{ + // _ = int.TryParse(item.OriginUserUniqueNo, out var userId); - var gainfo = gainfos.FirstOrDefault(x => x.No == item.OriginUserUniqueNo || x.Id == userId || x.Code == item.OriginUserUniqueNo); - item.UserNo = gainfo?.No; - item.UserCode = gainfo?.Code; - item.UserName = gainfo?.Name; - }); + // var gainfo = gainfos.FirstOrDefault(x => x.No == item.OriginUserUniqueNo || x.Id == userId || x.Code == item.OriginUserUniqueNo); + // item.UserNo = gainfo?.No; + // item.UserCode = gainfo?.Code; + // item.UserName = gainfo?.Name; + //}); return page; } diff --git a/Src/Dlhis.Sys/Identity/Services/Implements/UserService.cs b/Src/Dlhis.Sys/Identity/Services/Implements/UserService.cs index 88394f60..55877e73 100644 --- a/Src/Dlhis.Sys/Identity/Services/Implements/UserService.cs +++ b/Src/Dlhis.Sys/Identity/Services/Implements/UserService.cs @@ -32,7 +32,8 @@ public class UserService : IUserService ) .Select((x, ur, r) => new UserResponse { - Id = x.Id + Id = x.Id, + Role = r.Name }, true) .ToPageListAsync(request); } From d280d035e2b41cb56253a28c5d90f303db555a34 Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Tue, 5 Mar 2024 10:16:15 +0800 Subject: [PATCH 092/146] =?UTF-8?q?fix=20=E7=A6=BB=E7=BA=BF=E5=88=A4?= =?UTF-8?q?=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Device/Services/Implements/DeviceService.cs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs index f06f81c4..fc88ef1a 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs @@ -298,10 +298,8 @@ public class DeviceService : IDeviceService var list = new List(); foreach (var device in devices) { - if(device.HeartbeatInterval > 0) - { var regis = deviceRegistrys.FirstOrDefault(x => x.DeviceUniqueNo == device.UniqueNo); - if (regis == null) + if (regis == null || device.HeartbeatInterval == 0) { continue; } @@ -310,12 +308,7 @@ public class DeviceService : IDeviceService { list.Add(device); } - } - else - { - list.Add(device); - } - + } return list; } From ec54d9ddbba3035d7ae8aeff3d8f6de69edd6106 Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Tue, 5 Mar 2024 12:13:47 +0800 Subject: [PATCH 093/146] =?UTF-8?q?fix=20=20=E9=80=BB=E8=BE=91=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Implements/DeviceService.cs | 61 +++++++++++-------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs index fc88ef1a..568bd507 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs @@ -11,6 +11,7 @@ using Kurisu.Core.DataAccess.Dto; using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Services; using Mapster; +using MySqlX.XDevAPI.Relational; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using SqlSugar; @@ -269,10 +270,8 @@ public class DeviceService : IDeviceService public async Task GetDeviceNumberAsync() { - var devices = await _dbContext.Queryable() - .Where(x => x.Type == DeviceTypeEnumType.Attendance && x.Enable) - .ToListAsync(); - + var devices = await _dbContext.Queryable().Where(x => x.Type == DeviceTypeEnumType.Attendance || (x.Type == DeviceTypeEnumType.Door && x.AsAttendance)).ToListAsync(); + var offlineNumber = await GetOfflineDevicesCount(devices); var res = new DeviceNumberResponse @@ -286,32 +285,48 @@ public class DeviceService : IDeviceService /// /// 获取离线设备 /// - /// /// private async Task> GetOfflineDevicesCount(List devices) { - var nos = devices.Select(x => x.UniqueNo).ToList(); - var deviceRegistrys = await _dbContext.Queryable() - .Where(x => nos.Contains(x.DeviceUniqueNo)) + var now = DateTime.Now; + + var deviceUniqueNos = devices.Select(x => x.UniqueNo).ToList(); + + var deviceRegistries = await _dbContext.Queryable() + .LeftJoin((x, d) => x.DeviceUniqueNo == d.UniqueNo) + .Where(x => deviceUniqueNos.Contains(x.DeviceUniqueNo)) + .Select((x, d) => new + { + UniqueNo = d.UniqueNo, + d.HeartbeatInterval, + x.LastHeartbeatTime + }) .ToListAsync(); - var list = new List(); - foreach (var device in devices) - { - var regis = deviceRegistrys.FirstOrDefault(x => x.DeviceUniqueNo == device.UniqueNo); - if (regis == null || device.HeartbeatInterval == 0) + var OnlineDevices = deviceRegistries + .Where(x => { - continue; - } - TimeSpan timeDifference = DateTime.Now - regis.LastHeartbeatTime; - if (timeDifference.TotalSeconds > (device.HeartbeatInterval * 3)) + if (x.HeartbeatInterval <= 0) + { + return true; + } + + return x.LastHeartbeatTime.AddSeconds(x.HeartbeatInterval * 3) >= now; + + }) + .Select(x => new { - list.Add(device); - } - - } + UniqueNo = x.UniqueNo, + }) + .ToList(); + var onlineUniqueNos = new List(); + OnlineDevices.ForEach(x => onlineUniqueNos.Add(x.UniqueNo)); + + var offUniqueNos = deviceUniqueNos.Except(onlineUniqueNos).ToList(); + var list = devices.Where(x => offUniqueNos.Contains(x.UniqueNo)).ToList(); return list; } + public async Task> GetAttendanceTotalAsync(AttendanceTotalRequest request) { @@ -332,9 +347,7 @@ public class DeviceService : IDeviceService public async Task> GetAttendanceOfflineAsync(DeviceOnlineAndofflineRequest request) { - var devices = await _dbContext.Queryable() - .Where(x => x.Type == DeviceTypeEnumType.Attendance && x.Enable) - .ToListAsync(); + var devices = await _dbContext.Queryable().Where(x => x.Type == DeviceTypeEnumType.Attendance || (x.Type == DeviceTypeEnumType.Door && x.AsAttendance)).ToListAsync(); //离线 var offDevices = await GetOfflineDevicesCount(devices); From 817eb9115ad3d307dd7300b778e8e989b8d83fe8 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 5 Mar 2024 15:29:25 +0800 Subject: [PATCH 094/146] =?UTF-8?q?fix=20=E7=B3=BB=E7=BB=9F=E5=88=86?= =?UTF-8?q?=E7=BB=84=E7=94=9F=E6=88=90=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Implements/GainfoService.cs | 20 +- .../Services/Implements/BalanceService.cs | 4 +- Src/Dlhis.Entity/Basic/Entity/GainfoEntity.cs | 16 +- Src/Dlhis.Entity/Sys/Entities/TenantEntity.cs | 5 + .../CommonJobs/CreateDefinitelyGroupJob.cs | 237 +++++++++--------- .../appsettings.Development.json | 3 + 6 files changed, 153 insertions(+), 132 deletions(-) diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs index a9a6c726..53f4be51 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs @@ -148,11 +148,19 @@ public class GainfoService : IGainfoService public async Task CurrentUserInfoAsync() { var identityId = _currentUser.GetIntSubjectId(); + var code = _currentUser.GetUserClaim("jinko-code"); + var gainfo = await _gainfoStore.Queryable().Where(x => x.Code == code).FirstAsync() + ?? await _gainfoStore.Queryable().Where(x => x.IdentityUserId == identityId).FirstAsync(); - var gainfo = await _gainfoStore.Queryable(GainfoStatusEnumType.Working) + if (gainfo == null) + { + return null; + } + + var info = await _gainfoStore.Queryable(GainfoStatusEnumType.Working) .LeftJoin((ga, department) => ga.DepartmentNo == department.No) .LeftJoin((ga, department, mealUser) => ga.No == mealUser.UserNo) - .Where((ga, department) => ga.IdentityUserId == identityId) + .Where((ga, department) => ga.Id == gainfo.Id) .Select((ga, department, mealUser) => new GainfoCurrentResponse { UserNo = ga.No, @@ -169,7 +177,7 @@ public class GainfoService : IGainfoService }) .FirstAsync(); - return gainfo; + return info; } public async Task GetFaceAsync(string token) @@ -368,9 +376,9 @@ public class GainfoService : IGainfoService .LeftJoin((ga, de, type, posi) => ga.Position == posi.Name) .LeftJoin((ga, de, type, posi, type2) => ga.CountryNo == type2.Code && type2.Type == "country") .LeftJoin((ga, de, type, posi, type2, type3) => ga.Nation == type3.Code && type3.Type == "nation") - .LeftJoin((ga, de, type, posi, type2, type3,type4) => ga.IdClass == type4.Code && type4.Type == "cls") + .LeftJoin((ga, de, type, posi, type2, type3, type4) => ga.IdClass == type4.Code && type4.Type == "cls") .Where(ga => ga.No == request.No) - .Select((ga, de, type, posi, type2, type3,type4) => new GainfoDetailResponse + .Select((ga, de, type, posi, type2, type3, type4) => new GainfoDetailResponse { No = ga.No, SapNo = ga.SapNo, @@ -389,7 +397,7 @@ public class GainfoService : IGainfoService Degree = ga.Degree, Werks = ga.Werks, CostId = ga.CostId, - Marital = ga.Marital== "Single" ? "未婚":"已婚", + Marital = ga.Marital == "Single" ? "未婚" : "已婚", CountryName = type2.Display, NationName = type3.Display, ClassName = type4.Display, diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs index b4556880..8de0e473 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs @@ -509,7 +509,7 @@ public class BalanceService : IBalanceService No = record.No, BusinessPlaceName = bplace.Name, BusinessShiftName = type.Display, - CostDateTime = record.CreateTime // todo + CostDateTime = record.CostDateTime }) .ToPageListAsync(request); @@ -774,7 +774,7 @@ public class BalanceService : IBalanceService var codeBreakfast = "Breakfast"; if (breakfast != null) { - codeBreakfast = breakfast.Code.ToString(); + codeBreakfast = breakfast.Code.ToString(); } //午餐 var lunch = shifts.Where(x => x.CustomCode == "shift-lunch").FirstOrDefault(); diff --git a/Src/Dlhis.Entity/Basic/Entity/GainfoEntity.cs b/Src/Dlhis.Entity/Basic/Entity/GainfoEntity.cs index d1462881..63631b17 100644 --- a/Src/Dlhis.Entity/Basic/Entity/GainfoEntity.cs +++ b/Src/Dlhis.Entity/Basic/Entity/GainfoEntity.cs @@ -143,15 +143,27 @@ public class GainfoEntity : SugarBaseEntity [SugarColumn(ColumnDescription = "人事范围")] public string Werks { get; set; } + /// + /// 工作地 + /// + [SugarColumn(ColumnDescription = "工作地")] + public string Workplace { get; set; } + + /// + /// 厂区 + /// + [SugarColumn(ColumnDescription = "厂区")] + public string Factory { get; set; } + /// /// 成本中心 /// public string CostId { get; set; } /// - /// 身份认证用户Id + /// 身份认证用户Id(如果为空匹配code) /// - [SugarColumn(ColumnDescription = "身份认证用户Id", IndexGroupNameList = new[] { "idx_Gainfo_IdentityUserId" })] + [SugarColumn(ColumnDescription = "身份认证用户Id", IsNullable = true)] public int IdentityUserId { get; set; } } diff --git a/Src/Dlhis.Entity/Sys/Entities/TenantEntity.cs b/Src/Dlhis.Entity/Sys/Entities/TenantEntity.cs index 5897f319..c67fa035 100644 --- a/Src/Dlhis.Entity/Sys/Entities/TenantEntity.cs +++ b/Src/Dlhis.Entity/Sys/Entities/TenantEntity.cs @@ -12,6 +12,11 @@ public class TenantEntity { public int Id { get; set; } + /// + /// 上级租户 + /// + public string PCode { get; set; } + /// /// 基地code /// diff --git a/Src/Dlhis.ScheduledTask/CommonJobs/CreateDefinitelyGroupJob.cs b/Src/Dlhis.ScheduledTask/CommonJobs/CreateDefinitelyGroupJob.cs index 0bdda3ff..830c8086 100644 --- a/Src/Dlhis.ScheduledTask/CommonJobs/CreateDefinitelyGroupJob.cs +++ b/Src/Dlhis.ScheduledTask/CommonJobs/CreateDefinitelyGroupJob.cs @@ -1,10 +1,14 @@ -using Dlhis.Entity.Basic.Entity; +using System.Collections.Generic; +using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Device.Entities; using Dlhis.Entity.Device.Enums; using Dlhis.Sys.Api; +using Dlhis.User.Api.Response; +using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.DataAccess.Entity; using Kurisu.SqlSugar.Services; using Newtonsoft.Json; +using SqlSugar; namespace Dlhis.ScheduledTask.CommonJobs; @@ -14,7 +18,10 @@ public class CreateDefinitelyGroupJob private readonly ITenantApi _tenantApi; private readonly IDbContext _dbContext; - public CreateDefinitelyGroupJob(ILogger logger, ITenantApi tenantApi, IDbContext dbContext, ISqlSugarOptionsService sqlSugarOptionsService) + public CreateDefinitelyGroupJob(ILogger logger, + ITenantApi tenantApi, + IDbContext dbContext, + ISqlSugarOptionsService sqlSugarOptionsService) { _logger = logger; _tenantApi = tenantApi; @@ -28,136 +35,23 @@ public class CreateDefinitelyGroupJob _dbContext.Client.QueryFilter.ClearAndBackup(); try { + //获取所有基地信息 var tenantResult = await _tenantApi.GetTenantsInternalAsync(); var tenants = tenantResult.Data; _logger.LogInformation("获取基地信息:{json}", JsonConvert.SerializeObject(tenants)); - foreach (var tenant in tenants) - { - if (!await _dbContext.Queryable().Where(x => x.TenantId == tenant.Code).AnyAsync(x => x.IsDefault)) - { - var customGroup = new GainfoGroupEntity - { - PCode = null, - Code = Guid.NewGuid(), - Name = "*自定义人员分组", - IsDefault = true, - Editable = false, + //****************************************************系统人员分组**********************************************************/ - CreatedBy = 1, - CreateTime = DateTime.Now, - ModifiedBy = 1, - ModifiedTime = DateTime.Now, - TenantId = tenant.Code - }; - await _dbContext.InsertAsync(customGroup); + await CreateGainfoGroupsAsync(tenants); + //*****************************************************考勤设备组*********************************************************/ - var groups = new[] { "*督查组", "*X3及以上领导组", "*外派人员组" }; - foreach (var group in groups) - { - var grp = new GainfoGroupEntity - { - PCode = null, - Code = Guid.NewGuid(), - Name = group, - IsDefault = false, - Editable = false, + await CreateDeviceGroupAsync(DeviceTypeEnumType.Attendance, new List { "*通用考勤设备组", "*专用考勤设备组" }, tenants); - CreatedBy = 1, - CreateTime = DateTime.Now, - ModifiedBy = 1, - ModifiedTime = DateTime.Now, - TenantId = tenant.Code - }; + //*****************************************************门禁设备组********************************************************/ - await _dbContext.InsertAsync(grp); - } - } - - //**************************************************************************************************************/ - - if (!await _dbContext.Queryable().Where(x => x.TenantId == tenant.Code).AnyAsync(x => x.Name == "*通用考勤设备组")) - { - await _dbContext.InsertAsync(new DeviceGroupEntity - { - PCode = null, - Code = Guid.NewGuid(), - Type = DeviceTypeEnumType.Attendance, - Name = "*通用考勤设备组", - Editable = false, - - CreatedBy = 1, - CreateTime = DateTime.Now, - ModifiedBy = 1, - ModifiedTime = DateTime.Now, - TenantId = tenant.Code, - }); - } - - if (!await _dbContext.Queryable().Where(x => x.TenantId == tenant.Code).AnyAsync(x => x.Name == "*专用考勤设备组")) - { - await _dbContext.InsertAsync(new DeviceGroupEntity - { - PCode = null, - Code = Guid.NewGuid(), - Type = DeviceTypeEnumType.Attendance, - Name = "*专用考勤设备组", - Editable = false, - - CreatedBy = 1, - CreateTime = DateTime.Now, - ModifiedBy = 1, - ModifiedTime = DateTime.Now, - TenantId = tenant.Code, - }); - } - - //**************************************************************************************************************/ - - if (!await _dbContext.Queryable().Where(x => x.TenantId == tenant.Code) - .Where(x => x.Type == DeviceTypeEnumType.Door) - .AnyAsync(x => x.Name == "*通用考勤设备组") - ) - { - await _dbContext.InsertAsync(new DeviceGroupEntity - { - PCode = null, - Code = Guid.NewGuid(), - Type = DeviceTypeEnumType.Door, - Name = "*非公共区域", - Editable = false, - - CreatedBy = 1, - CreateTime = DateTime.Now, - ModifiedBy = 1, - ModifiedTime = DateTime.Now, - TenantId = tenant.Code, - }); - } - - if (!await _dbContext.Queryable().Where(x => x.TenantId == tenant.Code) - .Where(x => x.Type == DeviceTypeEnumType.Door) - .AnyAsync(x => x.Name == "*专用考勤设备组") - ) - { - await _dbContext.InsertAsync(new DeviceGroupEntity - { - PCode = null, - Code = Guid.NewGuid(), - Type = DeviceTypeEnumType.Door, - Name = "*公共区域", - Editable = false, - - CreatedBy = 1, - CreateTime = DateTime.Now, - ModifiedBy = 1, - ModifiedTime = DateTime.Now, - TenantId = tenant.Code, - }); - } - } + await CreateDeviceGroupAsync(DeviceTypeEnumType.Door, new List { "*共用区域", "*非共用区域" }, tenants); } catch (Exception ex) { @@ -168,4 +62,103 @@ public class CreateDefinitelyGroupJob _dbContext.Client.QueryFilter.Restore(); } } + + private async Task CreateGainfoGroupsAsync(List tenants) + { + var grps = new List { "*自定义人员分组", "*督查组", "*X3及以上领导组" }; + var searchGrps = await _dbContext.Queryable().Where(x => grps.Contains(x.Name)).ToListAsync(); + foreach (var grp in grps) + { + if (!searchGrps.Any(x => x.Name == grp)) + { + await _dbContext.InsertAsync(new GainfoGroupEntity + { + PCode = null, + Code = Guid.NewGuid(), + Name = grp, + IsDefault = grp.Equals("*自定义人员分组"), + Editable = false, + + CreatedBy = 1, + CreateTime = DateTime.Now, + ModifiedBy = 1, + ModifiedTime = DateTime.Now, + TenantId = null + }); + } + } + } + + + private async Task CreateDeviceGroupAsync(DeviceTypeEnumType type, List topGroups, List tenants) + { + foreach (var grp in topGroups) + { + var topGrp = await _dbContext.Queryable().FirstAsync(x => x.Name == grp); + if (topGrp == null) + { + topGrp = new DeviceGroupEntity + { + PCode = null, + Code = Guid.NewGuid(), + Type = type, + Name = grp, + Editable = false, + + CreatedBy = 1, + CreateTime = DateTime.Now, + ModifiedBy = 1, + ModifiedTime = DateTime.Now, + TenantId = null, + }; + await _dbContext.InsertAsync(topGrp); + } + + foreach (var workplace in tenants.Where(x => x.PCode.IsEmpty())) + { + var workplaceName = $"*{type.GetDescription()}工作地系统组({workplace.Name})"; + var workplaceGrp = await _dbContext.Queryable().FirstAsync(x => x.Name == workplaceName); + if (workplaceGrp == null) + { + workplaceGrp = new DeviceGroupEntity + { + PCode = topGrp.Code, + Code = Guid.NewGuid(), + Type = type, + Name = workplaceName, + Editable = false, + + CreatedBy = 1, + CreateTime = DateTime.Now, + ModifiedBy = 1, + ModifiedTime = DateTime.Now, + TenantId = null, + }; + await _dbContext.InsertAsync(workplaceGrp); + } + + foreach (var factory in tenants.Where(x => x.PCode == workplace.Code)) + { + var factoryName = $"*{type.GetDescription()}厂区系统组({factory.Name})"; + if (!await _dbContext.Queryable().AnyAsync(x => x.Name == factoryName)) + { + await _dbContext.InsertAsync(new DeviceGroupEntity + { + PCode = workplaceGrp.Code, + Code = Guid.NewGuid(), + Type = type, + Name = factoryName, + Editable = false, + + CreatedBy = 1, + CreateTime = DateTime.Now, + ModifiedBy = 1, + ModifiedTime = DateTime.Now, + TenantId = factory.Code, + }); + } + } + } + } + } } diff --git a/Src/Dlhis.ScheduledTask/appsettings.Development.json b/Src/Dlhis.ScheduledTask/appsettings.Development.json index fbfb5dd0..8674e444 100644 --- a/Src/Dlhis.ScheduledTask/appsettings.Development.json +++ b/Src/Dlhis.ScheduledTask/appsettings.Development.json @@ -5,6 +5,9 @@ "Microsoft.AspNetCore": "Warning" } }, + "InternalRequest": { + "SysRequestUrl": "http://localhost:5003" + }, "FaceUrlOptions": { "Url": "http://localhost:5002/api/gainfos/face?token=", "Limit": 7200 From f6a155ae73a8fb189e1a3f934c9bc12a807ae794 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 5 Mar 2024 15:30:44 +0800 Subject: [PATCH 095/146] =?UTF-8?q?fix=20=E4=BC=98=E5=8C=96=E7=BB=86?= =?UTF-8?q?=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Organization/Services/Implements/GainfoService.cs | 3 --- Src/Dlhis.Basic/appsettings.json | 2 +- Src/Dlhis.Sys.Api/Response/TenantResponse.cs | 2 ++ Src/Dlhis.Sys/Identity/Response/TenantResponse.cs | 2 ++ 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs index 53f4be51..f500ad8c 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs @@ -59,14 +59,11 @@ public class GainfoService : IGainfoService { request.DepartmentNos = await GetRecursionDepartmentNosAsync(request.DepartmentNos); - var tenant = _currentUser.GetStringTenantId(); - var page = await _gainfoStore.Queryable(request.Status) .WhereIF(request.DepartmentNos.IsPresent(), gainfo => request.DepartmentNos.Contains(gainfo.DepartmentNo)) .WhereIF(request.Search.IsPresent(), gainfo => gainfo.Name.Contains(request.Search) || gainfo.Code.Contains(request.Search)) - .Where(gainfo => gainfo.Werks == tenant) .Select() .ToPageListAsync(request); diff --git a/Src/Dlhis.Basic/appsettings.json b/Src/Dlhis.Basic/appsettings.json index 79da19b2..428e90e9 100644 --- a/Src/Dlhis.Basic/appsettings.json +++ b/Src/Dlhis.Basic/appsettings.json @@ -25,7 +25,7 @@ "LogConnectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=log;charset=utf8mb4;", "Timeout": 30, "SlowSqlTime": 1, - "EnableSqlLog": false + "EnableSqlLog": true }, "SwaggerOptions": { "Enable": true, diff --git a/Src/Dlhis.Sys.Api/Response/TenantResponse.cs b/Src/Dlhis.Sys.Api/Response/TenantResponse.cs index 1201754e..e20f2110 100644 --- a/Src/Dlhis.Sys.Api/Response/TenantResponse.cs +++ b/Src/Dlhis.Sys.Api/Response/TenantResponse.cs @@ -4,6 +4,8 @@ public class TenantResponse { public int Id { get; set; } + public string PCode { get; set; } + public string Code { get; set; } public string Name { get; set; } diff --git a/Src/Dlhis.Sys/Identity/Response/TenantResponse.cs b/Src/Dlhis.Sys/Identity/Response/TenantResponse.cs index 1949b745..b265def5 100644 --- a/Src/Dlhis.Sys/Identity/Response/TenantResponse.cs +++ b/Src/Dlhis.Sys/Identity/Response/TenantResponse.cs @@ -4,6 +4,8 @@ public class TenantResponse { public int Id { get; set; } + public string PCode { get; set; } + public string Code { get; set; } public string Name { get; set; } From 3de3fde888f0dcf5a1c1df6080e9c7425f45d971 Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Tue, 5 Mar 2024 15:45:21 +0800 Subject: [PATCH 096/146] =?UTF-8?q?fix=20=E4=BF=AE=E6=94=B9=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E5=AF=B9=E5=BA=94=E8=90=A5=E4=B8=9A=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/BusinessPlacesController.cs | 10 ++++++ .../Request/BusinessPlaceGetByCodeRequest.cs | 13 +++++++ .../Response/DeviceCodeNameDetail.cs | 6 ++++ .../Services/IBusinessPlaceShiftService.cs | 5 ++- .../Implements/BusinessPlaceShiftService.cs | 7 +++- .../Device/Response/DevicePageResponse.cs | 5 +++ .../Device/Response/PlaceCodeNameDetil.cs | 9 +++++ .../Services/Implements/DeviceService.cs | 34 +++++++++++++++++-- 8 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 Src/Dlhis.Basic/BusinessPlace/Request/BusinessPlaceGetByCodeRequest.cs create mode 100644 Src/Dlhis.Basic/BusinessPlace/Response/DeviceCodeNameDetail.cs create mode 100644 Src/Dlhis.Basic/Device/Response/PlaceCodeNameDetil.cs diff --git a/Src/Dlhis.Basic/BusinessPlace/Controllers/BusinessPlacesController.cs b/Src/Dlhis.Basic/BusinessPlace/Controllers/BusinessPlacesController.cs index 63dd5b4b..557100dc 100644 --- a/Src/Dlhis.Basic/BusinessPlace/Controllers/BusinessPlacesController.cs +++ b/Src/Dlhis.Basic/BusinessPlace/Controllers/BusinessPlacesController.cs @@ -93,4 +93,14 @@ public class BusinessPlacesController : ControllerBase { return await _businessPlaceShiftService.GetShiftsByPlaceCustomCodeAsync(request.CustomCode); } + + /// + /// 根据营业点获取下面的设备 + /// + /// + /// + public async Task GetDevicesByCode(BusinessPlaceGetByCodeRequest request) + { + return await _businessPlaceShiftService.GetDevicesByCode(request); + } } diff --git a/Src/Dlhis.Basic/BusinessPlace/Request/BusinessPlaceGetByCodeRequest.cs b/Src/Dlhis.Basic/BusinessPlace/Request/BusinessPlaceGetByCodeRequest.cs new file mode 100644 index 00000000..7aaa6060 --- /dev/null +++ b/Src/Dlhis.Basic/BusinessPlace/Request/BusinessPlaceGetByCodeRequest.cs @@ -0,0 +1,13 @@ +using System.ComponentModel.DataAnnotations; + +namespace Dlhis.Basic.BusinessPlace.Request +{ + public class BusinessPlaceGetByCodeRequest + { + /// + /// 营业点号 + /// + [Required(ErrorMessage = "营业点号不能为空")] + public string Code { get; set; } + } +} diff --git a/Src/Dlhis.Basic/BusinessPlace/Response/DeviceCodeNameDetail.cs b/Src/Dlhis.Basic/BusinessPlace/Response/DeviceCodeNameDetail.cs new file mode 100644 index 00000000..fb7d0426 --- /dev/null +++ b/Src/Dlhis.Basic/BusinessPlace/Response/DeviceCodeNameDetail.cs @@ -0,0 +1,6 @@ +namespace Dlhis.Basic.BusinessPlace.Response +{ + public class DeviceCodeNameDetail + { + } +} diff --git a/Src/Dlhis.Basic/BusinessShift/Services/IBusinessPlaceShiftService.cs b/Src/Dlhis.Basic/BusinessShift/Services/IBusinessPlaceShiftService.cs index 1dc289da..70b32573 100644 --- a/Src/Dlhis.Basic/BusinessShift/Services/IBusinessPlaceShiftService.cs +++ b/Src/Dlhis.Basic/BusinessShift/Services/IBusinessPlaceShiftService.cs @@ -1,4 +1,5 @@ -using Dlhis.Basic.BusinessPlace.Response; +using Dlhis.Basic.BusinessPlace.Request; +using Dlhis.Basic.BusinessPlace.Response; using Dlhis.Basic.BusinessShift.Request; using Dlhis.Basic.BusinessShift.Response; using Kurisu.Core.DataAccess.Dto; @@ -16,4 +17,6 @@ public interface IBusinessPlaceShiftService : IScopeDependency Task SaveMealShiftsAsync(List requests); Task GetShiftsByPlaceCustomCodeAsync(string placeCustomCode); + + Task GetDevicesByCode(BusinessPlaceGetByCodeRequest request); } diff --git a/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs b/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs index 84931863..ec61ffb4 100644 --- a/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs +++ b/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs @@ -1,4 +1,5 @@ -using Dlhis.Basic.BusinessPlace.Response; +using Dlhis.Basic.BusinessPlace.Request; +using Dlhis.Basic.BusinessPlace.Response; using Dlhis.Basic.BusinessShift.Request; using Dlhis.Basic.BusinessShift.Response; using Dlhis.Entity.Basic.Entity; @@ -188,6 +189,10 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService }; } + public async Task> GetDevicesByCode(BusinessPlaceGetByCodeRequest request) + { + + } //*********************************************** help methods ***************************************************// diff --git a/Src/Dlhis.Basic/Device/Response/DevicePageResponse.cs b/Src/Dlhis.Basic/Device/Response/DevicePageResponse.cs index d9d47179..9fe547c6 100644 --- a/Src/Dlhis.Basic/Device/Response/DevicePageResponse.cs +++ b/Src/Dlhis.Basic/Device/Response/DevicePageResponse.cs @@ -99,4 +99,9 @@ public class DevicePageResponse /// 消费人次 /// public int UserCount { get; set; } + + /// + /// 设备营业点 + /// + public List detils { get; set; } } diff --git a/Src/Dlhis.Basic/Device/Response/PlaceCodeNameDetil.cs b/Src/Dlhis.Basic/Device/Response/PlaceCodeNameDetil.cs new file mode 100644 index 00000000..9f449033 --- /dev/null +++ b/Src/Dlhis.Basic/Device/Response/PlaceCodeNameDetil.cs @@ -0,0 +1,9 @@ +namespace Dlhis.Basic.Device.Response +{ + public class PlaceCodeNameDetil + { + public string BusinessPlaceCode { get; set; } + public string BusinessPlaceName { get; set; } + + } +} diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs index 568bd507..f17f71c2 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs @@ -37,7 +37,6 @@ public class DeviceService : IDeviceService FuncsStr = d.Funcs.ToString(), Brand = dt.Brand, Type = d.Type, - }, true) .ToPageListAsync(request); @@ -59,6 +58,37 @@ public class DeviceService : IDeviceService }) .ToListAsync(); + var Registries = await _dbContext.Queryable() + .ToListAsync(); + var BusinessPlaces = await _dbContext.Queryable() + .ToListAsync(); + + foreach (var res in page.Data) + { + var list = new List(); + var regis = Registries.Where(x => x.DeviceUniqueNo == res.UniqueNo).ToList(); + if (regis!=null && regis.Count>0) + { + foreach (var re in regis) + { + var place = BusinessPlaces.Where(x => x.Code == re.BusinessPlaceCode) + .FirstOrDefault(); + + if (place != null) + { + var detil = new PlaceCodeNameDetil + { + BusinessPlaceCode = re.BusinessPlaceCode.ToString(), + BusinessPlaceName = place.Name + }; + list.Add(detil); + } + + } + } + res.detils = list; + + } page.Data.ForEach(device => { device.Amount = balanceRecords.Sum(x => x.Amount); @@ -332,7 +362,7 @@ public class DeviceService : IDeviceService { var page = await _dbContext.Queryable() .LeftJoin((d, dt) => d.TemplateCode == dt.Code) - .Where(d => d.Type == DeviceTypeEnumType.Attendance && d.Enable) + .Where(x => x.Type == DeviceTypeEnumType.Attendance || (x.Type == DeviceTypeEnumType.Door && x.AsAttendance)) .Select((d, dt) => new DevicePageResponse { FuncsStr = d.Funcs.ToString(), From c696f654813e565884ec3379dc7c6532318efe8d Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 5 Mar 2024 15:53:40 +0800 Subject: [PATCH 097/146] =?UTF-8?q?fix=20=E5=A2=9E=E5=8A=A0PCode=E6=9D=A1?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CommonJobs/CreateDefinitelyGroupJob.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Src/Dlhis.ScheduledTask/CommonJobs/CreateDefinitelyGroupJob.cs b/Src/Dlhis.ScheduledTask/CommonJobs/CreateDefinitelyGroupJob.cs index 830c8086..af824291 100644 --- a/Src/Dlhis.ScheduledTask/CommonJobs/CreateDefinitelyGroupJob.cs +++ b/Src/Dlhis.ScheduledTask/CommonJobs/CreateDefinitelyGroupJob.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using Dlhis.Entity.Basic.Entity; +using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Device.Entities; using Dlhis.Entity.Device.Enums; using Dlhis.Sys.Api; @@ -117,7 +116,7 @@ public class CreateDefinitelyGroupJob foreach (var workplace in tenants.Where(x => x.PCode.IsEmpty())) { var workplaceName = $"*{type.GetDescription()}工作地系统组({workplace.Name})"; - var workplaceGrp = await _dbContext.Queryable().FirstAsync(x => x.Name == workplaceName); + var workplaceGrp = await _dbContext.Queryable().Where(x => x.PCode == topGrp.Code).FirstAsync(x => x.Name == workplaceName); if (workplaceGrp == null) { workplaceGrp = new DeviceGroupEntity @@ -140,7 +139,7 @@ public class CreateDefinitelyGroupJob foreach (var factory in tenants.Where(x => x.PCode == workplace.Code)) { var factoryName = $"*{type.GetDescription()}厂区系统组({factory.Name})"; - if (!await _dbContext.Queryable().AnyAsync(x => x.Name == factoryName)) + if (!await _dbContext.Queryable().Where(x => x.PCode == workplaceGrp.Code).AnyAsync(x => x.Name == factoryName)) { await _dbContext.InsertAsync(new DeviceGroupEntity { From 6f1514932162e3d55f89a79000870a33528ab235 Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Tue, 5 Mar 2024 16:03:57 +0800 Subject: [PATCH 098/146] =?UTF-8?q?feat=20=E8=90=A5=E4=B8=9A=E7=82=B9?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E4=B8=8B=E9=9D=A2=E8=AE=BE=E5=A4=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/BusinessPlacesController.cs | 3 ++- .../Request/BusinessPlaceGetByCodeRequest.cs | 5 ++-- .../Response/DeviceCodeNameDetail.cs | 2 ++ .../Services/IBusinessPlaceShiftService.cs | 2 +- .../Implements/BusinessPlaceShiftService.cs | 27 ++++++++++++++++++- 5 files changed, 34 insertions(+), 5 deletions(-) diff --git a/Src/Dlhis.Basic/BusinessPlace/Controllers/BusinessPlacesController.cs b/Src/Dlhis.Basic/BusinessPlace/Controllers/BusinessPlacesController.cs index 557100dc..cc72eb4f 100644 --- a/Src/Dlhis.Basic/BusinessPlace/Controllers/BusinessPlacesController.cs +++ b/Src/Dlhis.Basic/BusinessPlace/Controllers/BusinessPlacesController.cs @@ -99,7 +99,8 @@ public class BusinessPlacesController : ControllerBase /// /// /// - public async Task GetDevicesByCode(BusinessPlaceGetByCodeRequest request) + [HttpGet("devicenos")] + public async Task> GetDevicesByCode([FromQuery]BusinessPlaceGetByCodeRequest request) { return await _businessPlaceShiftService.GetDevicesByCode(request); } diff --git a/Src/Dlhis.Basic/BusinessPlace/Request/BusinessPlaceGetByCodeRequest.cs b/Src/Dlhis.Basic/BusinessPlace/Request/BusinessPlaceGetByCodeRequest.cs index 7aaa6060..5177dd0c 100644 --- a/Src/Dlhis.Basic/BusinessPlace/Request/BusinessPlaceGetByCodeRequest.cs +++ b/Src/Dlhis.Basic/BusinessPlace/Request/BusinessPlaceGetByCodeRequest.cs @@ -1,8 +1,9 @@ -using System.ComponentModel.DataAnnotations; +using Kurisu.Core.DataAccess.Dto; +using System.ComponentModel.DataAnnotations; namespace Dlhis.Basic.BusinessPlace.Request { - public class BusinessPlaceGetByCodeRequest + public class BusinessPlaceGetByCodeRequest : PageDto { /// /// 营业点号 diff --git a/Src/Dlhis.Basic/BusinessPlace/Response/DeviceCodeNameDetail.cs b/Src/Dlhis.Basic/BusinessPlace/Response/DeviceCodeNameDetail.cs index fb7d0426..0841c315 100644 --- a/Src/Dlhis.Basic/BusinessPlace/Response/DeviceCodeNameDetail.cs +++ b/Src/Dlhis.Basic/BusinessPlace/Response/DeviceCodeNameDetail.cs @@ -2,5 +2,7 @@ { public class DeviceCodeNameDetail { + public string UniqueNo { get; set; } + public string UniqueName { get; set; } } } diff --git a/Src/Dlhis.Basic/BusinessShift/Services/IBusinessPlaceShiftService.cs b/Src/Dlhis.Basic/BusinessShift/Services/IBusinessPlaceShiftService.cs index 70b32573..3a88f5db 100644 --- a/Src/Dlhis.Basic/BusinessShift/Services/IBusinessPlaceShiftService.cs +++ b/Src/Dlhis.Basic/BusinessShift/Services/IBusinessPlaceShiftService.cs @@ -18,5 +18,5 @@ public interface IBusinessPlaceShiftService : IScopeDependency Task GetShiftsByPlaceCustomCodeAsync(string placeCustomCode); - Task GetDevicesByCode(BusinessPlaceGetByCodeRequest request); + Task> GetDevicesByCode(BusinessPlaceGetByCodeRequest request); } diff --git a/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs b/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs index ec61ffb4..a0636ae0 100644 --- a/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs +++ b/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs @@ -3,6 +3,7 @@ using Dlhis.Basic.BusinessPlace.Response; using Dlhis.Basic.BusinessShift.Request; using Dlhis.Basic.BusinessShift.Response; using Dlhis.Entity.Basic.Entity; +using Dlhis.Entity.Device.Entities; using Dlhis.Sys.Api; using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.CustomClass; @@ -189,9 +190,33 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService }; } - public async Task> GetDevicesByCode(BusinessPlaceGetByCodeRequest request) + public async Task> GetDevicesByCode(BusinessPlaceGetByCodeRequest request) { + var regiss = await _dbContext.Queryable() + .Where(x => x.BusinessPlaceCode.ToString() == request.Code) + .ToListAsync(); + var devices = await _dbContext.Queryable().ToListAsync(); + + var list = new List(); + if (regiss.Count > 0) + { + foreach (var regis in regiss) + { + var device = devices.Where(x => x.UniqueNo == regis.DeviceUniqueNo) + .FirstOrDefault(); + if (device != null) + { + var detail = new DeviceCodeNameDetail + { + UniqueNo = regis.DeviceUniqueNo, + UniqueName = device.Supplier + }; + list.Add(detail); + } + } + } + return list; } //*********************************************** help methods ***************************************************// From 888460ea99460f9311bef8d768a43a3faedd1b49 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 5 Mar 2024 16:45:15 +0800 Subject: [PATCH 099/146] =?UTF-8?q?fix=20=E6=A1=86=E6=9E=B6tenant=E9=97=AE?= =?UTF-8?q?=E9=A2=98;=E6=A1=A3=E6=A1=88=E7=BB=84=E5=92=8C=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E7=BB=84=E7=89=B9=E6=AE=8A=E5=A4=84=E7=90=86=E8=BF=94?= =?UTF-8?q?=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/DeviceGroupsController.cs | 12 +-- .../Device/Request/DeviceGroupPageRequest.cs | 12 --- .../Response/DeviceGroupTreeResponse.cs | 4 + .../Device/Services/IDeviceGroupService.cs | 3 - .../Services/Implements/DeviceGroupService.cs | 40 ++++++---- .../Controllers/GainfoGroupsController.cs | 22 ++---- .../Request/GainfoGroupPageRequest.cs | 7 -- .../Request/GainfoGroupSaveRequest.cs | 5 ++ .../Response/GainfoGroupResponse.cs | 21 ------ .../Response/GainfoGroupTreeResponse.cs | 34 +++++++++ .../Services/IGainfoGroupService.cs | 5 +- .../Services/Implements/GainfoGroupService.cs | 75 +++++++++++++++---- .../Basic/Entity/GainfoGroupEntity.cs | 4 +- 13 files changed, 139 insertions(+), 105 deletions(-) delete mode 100644 Src/Dlhis.Basic/Device/Request/DeviceGroupPageRequest.cs delete mode 100644 Src/Dlhis.Basic/Organization/Request/GainfoGroupPageRequest.cs delete mode 100644 Src/Dlhis.Basic/Organization/Response/GainfoGroupResponse.cs create mode 100644 Src/Dlhis.Basic/Organization/Response/GainfoGroupTreeResponse.cs diff --git a/Src/Dlhis.Basic/Device/Controllers/DeviceGroupsController.cs b/Src/Dlhis.Basic/Device/Controllers/DeviceGroupsController.cs index 5f6ac7f8..66a5089f 100644 --- a/Src/Dlhis.Basic/Device/Controllers/DeviceGroupsController.cs +++ b/Src/Dlhis.Basic/Device/Controllers/DeviceGroupsController.cs @@ -24,17 +24,6 @@ public class DeviceGroupsController : ControllerBase _deviceGroupService = deviceGroupService; } - /// - /// 设备组分页 - /// - /// - /// - [HttpPost("page")] - public async Task> GetPageAsync([FromQuery] DeviceGroupPageRequest request) - { - return await _deviceGroupService.GetPageAsync(request); - } - /// /// 获取设备组树 /// @@ -42,6 +31,7 @@ public class DeviceGroupsController : ControllerBase /// 分组类型 /// [HttpGet("tree")] + [IgnoreTenant] public async Task> GetTreeAsync(bool showDevices, DeviceTypeEnumType? type) { return await _deviceGroupService.GetTreeAsync(showDevices, type); diff --git a/Src/Dlhis.Basic/Device/Request/DeviceGroupPageRequest.cs b/Src/Dlhis.Basic/Device/Request/DeviceGroupPageRequest.cs deleted file mode 100644 index aee1a3d9..00000000 --- a/Src/Dlhis.Basic/Device/Request/DeviceGroupPageRequest.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Dlhis.Entity.Device.Enums; -using Kurisu.Core.DataAccess.Dto; - -namespace Dlhis.Basic.Device.Request; - -public class DeviceGroupPageRequest : PageDto -{ - /// - /// 分组类型 - /// - public DeviceTypeEnumType? Type { get; set; } -} diff --git a/Src/Dlhis.Basic/Device/Response/DeviceGroupTreeResponse.cs b/Src/Dlhis.Basic/Device/Response/DeviceGroupTreeResponse.cs index 9a1e26de..31b5f3f3 100644 --- a/Src/Dlhis.Basic/Device/Response/DeviceGroupTreeResponse.cs +++ b/Src/Dlhis.Basic/Device/Response/DeviceGroupTreeResponse.cs @@ -1,5 +1,6 @@ using Dlhis.Entity.Device.Enums; using Kurisu.AspNetCore.Utils.Extensions; +using Newtonsoft.Json; namespace Dlhis.Basic.Device.Response; @@ -44,6 +45,9 @@ public class DeviceGroupTreeResponse } } + [JsonIgnore] + public string TenantId { get; set; } + /// /// 下级 /// diff --git a/Src/Dlhis.Basic/Device/Services/IDeviceGroupService.cs b/Src/Dlhis.Basic/Device/Services/IDeviceGroupService.cs index 13368b4f..4335fce8 100644 --- a/Src/Dlhis.Basic/Device/Services/IDeviceGroupService.cs +++ b/Src/Dlhis.Basic/Device/Services/IDeviceGroupService.cs @@ -1,14 +1,11 @@ using Dlhis.Basic.Device.Request; using Dlhis.Basic.Device.Response; using Dlhis.Entity.Device.Enums; -using Kurisu.Core.DataAccess.Dto; namespace Dlhis.Basic.Device.Services; public interface IDeviceGroupService : IScopeDependency { - Task> GetPageAsync(DeviceGroupPageRequest request); - Task> GetTreeAsync(bool showDevices, DeviceTypeEnumType? type); Task SaveAsync(DeviceGroupSaveRequest request); diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs index 7ffdc0d4..361d6289 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs @@ -5,8 +5,7 @@ using Dlhis.Entity.Device.Entities; using Dlhis.Entity.Device.Enums; using Kurisu.AspNetCore.UnifyResultAndValidation; using Kurisu.AspNetCore.Utils.Extensions; -using Kurisu.Core.DataAccess.Dto; -using Kurisu.SqlSugar.Extensions; +using Kurisu.Core.User.Abstractions; using Kurisu.SqlSugar.Services; using Mapster; @@ -16,21 +15,15 @@ public class DeviceGroupService : IDeviceGroupService { private readonly IDbContext _dbContext; private readonly IDevicePermissionService _devicePermissionService; + private readonly ICurrentUser _currentUser; - public DeviceGroupService(IDbContext dbContext, IDevicePermissionService devicePermissionService) + public DeviceGroupService(IDbContext dbContext, IDevicePermissionService devicePermissionService, ICurrentUser currentUser) { _dbContext = dbContext; _devicePermissionService = devicePermissionService; + _currentUser = currentUser; } - public async Task> GetPageAsync(DeviceGroupPageRequest request) - { - return await _dbContext.Queryable() - .WhereIF(request.Search.IsPresent(), x => x.Name.Contains(request.Search)) - .WhereIF(request.Type.HasValue, x => x.Type == request.Type) - .Select() - .ToPageListAsync(request); - } public async Task> GetTreeAsync(bool showDevices, DeviceTypeEnumType? type) { @@ -206,15 +199,32 @@ public class DeviceGroupService : IDeviceGroupService /// 递归获取树 /// /// - /// + /// /// - private void RecursionGetNext(DeviceGroupTreeResponse current, List departments, bool showDevices) + private void RecursionGetNext(DeviceGroupTreeResponse current, List deviceGroups, bool showDevices) { - var next = departments.Where(x => x.PCode == current.Code).ToList(); + var currentTenantId = _currentUser.GetStringTenantId(); + var next = deviceGroups.Where(x => + { + if (x.PCode == current.Code) + { + if (x.TenantId.IsEmpty()) + { + return true; + } + else + { + return x.TenantId == currentTenantId; + } + } + + return false; + + }).ToList(); current.Next = next; foreach (var item in next) { - RecursionGetNext(item, departments, showDevices); + RecursionGetNext(item, deviceGroups, showDevices); } //最后层级附加设备信息 diff --git a/Src/Dlhis.Basic/Organization/Controllers/GainfoGroupsController.cs b/Src/Dlhis.Basic/Organization/Controllers/GainfoGroupsController.cs index 42e765ba..ca2225a9 100644 --- a/Src/Dlhis.Basic/Organization/Controllers/GainfoGroupsController.cs +++ b/Src/Dlhis.Basic/Organization/Controllers/GainfoGroupsController.cs @@ -1,8 +1,8 @@ using Dlhis.Basic.Organization.Request; using Dlhis.Basic.Organization.Response; using Dlhis.Basic.Organization.Services; +using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop; using Kurisu.AspNetCore.MVC; -using Kurisu.Core.DataAccess.Dto; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -25,24 +25,14 @@ public class GainfoGroupsController : ControllerBase } /// - /// 获取档案组分页 - /// - /// - /// - [HttpGet("page")] - public async Task> GetPageAsync([FromQuery] GainfoGroupPageRequest request) - { - return await _gainfoGroupService.GetPageAsync(request); - } - - /// - /// 获取所有档案组 + /// 获取档案分组树 /// /// - [HttpGet("list")] - public async Task> GetListAsync() + [HttpGet("tree")] + [IgnoreTenant] + public async Task> GetTreeAsync() { - return await _gainfoGroupService.GetListAsync(); + return await _gainfoGroupService.GetTreeAsync(); } /// diff --git a/Src/Dlhis.Basic/Organization/Request/GainfoGroupPageRequest.cs b/Src/Dlhis.Basic/Organization/Request/GainfoGroupPageRequest.cs deleted file mode 100644 index b38a161d..00000000 --- a/Src/Dlhis.Basic/Organization/Request/GainfoGroupPageRequest.cs +++ /dev/null @@ -1,7 +0,0 @@ -using Kurisu.Core.DataAccess.Dto; - -namespace Dlhis.Basic.Organization.Request; - -public class GainfoGroupPageRequest: PageDto -{ -} diff --git a/Src/Dlhis.Basic/Organization/Request/GainfoGroupSaveRequest.cs b/Src/Dlhis.Basic/Organization/Request/GainfoGroupSaveRequest.cs index bb5173e4..eb4bfe9a 100644 --- a/Src/Dlhis.Basic/Organization/Request/GainfoGroupSaveRequest.cs +++ b/Src/Dlhis.Basic/Organization/Request/GainfoGroupSaveRequest.cs @@ -4,6 +4,11 @@ public class GainfoGroupSaveRequest { public long? Id { get; set; } + /// + /// 上级 + /// + public Guid? PCode { get; set; } + /// /// 名称 /// diff --git a/Src/Dlhis.Basic/Organization/Response/GainfoGroupResponse.cs b/Src/Dlhis.Basic/Organization/Response/GainfoGroupResponse.cs deleted file mode 100644 index f7f397b4..00000000 --- a/Src/Dlhis.Basic/Organization/Response/GainfoGroupResponse.cs +++ /dev/null @@ -1,21 +0,0 @@ -namespace Dlhis.Basic.Organization.Response; - -public class GainfoGroupResponse -{ - public long Id { get; set; } - - /// - /// 分组code - /// - public Guid Code { get; set; } - - /// - /// 名称 - /// - public string Name { get; set; } - - /// - /// 备注 - /// - public string Remark { get; set; } -} diff --git a/Src/Dlhis.Basic/Organization/Response/GainfoGroupTreeResponse.cs b/Src/Dlhis.Basic/Organization/Response/GainfoGroupTreeResponse.cs new file mode 100644 index 00000000..3fb4ca63 --- /dev/null +++ b/Src/Dlhis.Basic/Organization/Response/GainfoGroupTreeResponse.cs @@ -0,0 +1,34 @@ +using Newtonsoft.Json; + +namespace Dlhis.Basic.Organization.Response; + +public class GainfoGroupTreeResponse +{ + public long Id { get; set; } + + public Guid? PCode { get; set; } + + /// + /// 分组code + /// + public Guid Code { get; set; } + + /// + /// 名称 + /// + public string Name { get; set; } + + /// + /// 备注 + /// + public string Remark { get; set; } + + + [JsonIgnore] + public string TenantId { get; set; } + + /// + /// 下级数据 + /// + public List Next { get; set; } +} diff --git a/Src/Dlhis.Basic/Organization/Services/IGainfoGroupService.cs b/Src/Dlhis.Basic/Organization/Services/IGainfoGroupService.cs index 344f4dd1..d9b2801e 100644 --- a/Src/Dlhis.Basic/Organization/Services/IGainfoGroupService.cs +++ b/Src/Dlhis.Basic/Organization/Services/IGainfoGroupService.cs @@ -1,14 +1,11 @@ using Dlhis.Basic.Organization.Request; using Dlhis.Basic.Organization.Response; -using Kurisu.Core.DataAccess.Dto; namespace Dlhis.Basic.Organization.Services; public interface IGainfoGroupService : IScopeDependency { - Task> GetPageAsync(GainfoGroupPageRequest request); - - Task> GetListAsync(); + Task> GetTreeAsync(); Task SaveAsync(GainfoGroupSaveRequest request); diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs index ae598cf1..2a4390ef 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs @@ -2,8 +2,8 @@ using Dlhis.Basic.Organization.Response; using Dlhis.Entity.Basic.Entity; using Kurisu.AspNetCore.Utils.Extensions; -using Kurisu.Core.DataAccess.Dto; -using Kurisu.SqlSugar.Extensions; +using Kurisu.Core.DataAccess.Entity; +using Kurisu.Core.User.Abstractions; using Kurisu.SqlSugar.Services; using Mapster; @@ -12,42 +12,61 @@ namespace Dlhis.Basic.Organization.Services.Implements; public class GainfoGroupService : IGainfoGroupService { private readonly IDbContext _dbContext; + private readonly ICurrentUser _currentUser; - public GainfoGroupService(IDbContext dbContext) + public GainfoGroupService(IDbContext dbContext, ICurrentUser currentUser) { _dbContext = dbContext; + _currentUser = currentUser; } - public async Task> GetPageAsync(GainfoGroupPageRequest request) + public async Task> GetTreeAsync() { - return await _dbContext.Queryable() - .Select() - .ToPageListAsync(request); - } + var deviceGroups = await _dbContext.Queryable() + .Select() + .ToListAsync(); + var tops = deviceGroups.Where(x => !x.PCode.HasValue).ToList(); + tops.ForEach(x => + { + RecursionGetNext(x, deviceGroups); + }); - public async Task> GetListAsync() - { - return await _dbContext.Queryable() - .Select() - .ToListAsync(); + return tops; } public async Task SaveAsync(GainfoGroupSaveRequest request) { await CheckDuplicateNameAsync(request); + try + { + //todo + _dbContext.Client.QueryFilter.ClearAndBackup(); + var defaultGroup = await _dbContext.Queryable().Where(x => x.IsDefault).FirstAsync(); + + if (!request.PCode.HasValue) + { + request.PCode = defaultGroup.Code; + } + } + finally + { + _dbContext.Client.QueryFilter.Restore(); + } + if (!request.Id.HasValue) { var entity = request.Adapt(); entity.Code = Guid.NewGuid(); + entity.Editable = true; await _dbContext.InsertAsync(entity); } else { var entity = await _dbContext.Queryable().Where(x => x.Id == request.Id).SingleAsync(); request.Adapt(entity); - + entity.Editable = true; await _dbContext.UpdateAsync(entity); } } @@ -99,4 +118,32 @@ public class GainfoGroupService : IGainfoGroupService exists.ThrowIfTrue($"重复组名{request.Name}"); } + + + private void RecursionGetNext(GainfoGroupTreeResponse current, List gainfoGroups) + { + var currentTenantId = _currentUser.GetStringTenantId(); + var next = gainfoGroups.Where(x => + { + if (x.PCode == current.Code) + { + if (x.TenantId.IsEmpty()) + { + return true; + } + else + { + return x.TenantId == currentTenantId; + } + } + + return false; + + }).ToList(); + current.Next = next; + foreach (var item in next) + { + RecursionGetNext(item, gainfoGroups); + } + } } diff --git a/Src/Dlhis.Entity/Basic/Entity/GainfoGroupEntity.cs b/Src/Dlhis.Entity/Basic/Entity/GainfoGroupEntity.cs index b7e533c0..84c1bbf1 100644 --- a/Src/Dlhis.Entity/Basic/Entity/GainfoGroupEntity.cs +++ b/Src/Dlhis.Entity/Basic/Entity/GainfoGroupEntity.cs @@ -36,13 +36,13 @@ public class GainfoGroupEntity : SugarBaseEntity, ITenantId /// /// 是否默认分组 /// - [SugarColumn(ColumnDescription = "是否默认分组")] + [SugarColumn(ColumnDescription = "是否默认分组", ColumnDataType = "bit")] public bool IsDefault { get; set; } /// /// 是否可编辑 /// - [SugarColumn(ColumnDescription = "是否可编辑")] + [SugarColumn(ColumnDescription = "是否可编辑", ColumnDataType = "bit")] public bool Editable { get; set; } From 49dcf96bfcf31b515297909a3bc3c8511cbcd042 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 5 Mar 2024 16:45:30 +0800 Subject: [PATCH 100/146] =?UTF-8?q?add=20=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Basic/Dlhis.Basic.csproj | 2 +- Src/Dlhis.Canteen/Dlhis.Canteen.csproj | 2 +- Src/Dlhis.Common/Dlhis.Common.csproj | 2 +- Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj | 2 +- Src/Dlhis.Sys/Dlhis.Sys.csproj | 2 +- Src/Dlhis.User/Dlhis.User.csproj | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Src/Dlhis.Basic/Dlhis.Basic.csproj b/Src/Dlhis.Basic/Dlhis.Basic.csproj index 7094a50f..43b23333 100644 --- a/Src/Dlhis.Basic/Dlhis.Basic.csproj +++ b/Src/Dlhis.Basic/Dlhis.Basic.csproj @@ -17,7 +17,7 @@ - + diff --git a/Src/Dlhis.Canteen/Dlhis.Canteen.csproj b/Src/Dlhis.Canteen/Dlhis.Canteen.csproj index f30be7d1..30b34732 100644 --- a/Src/Dlhis.Canteen/Dlhis.Canteen.csproj +++ b/Src/Dlhis.Canteen/Dlhis.Canteen.csproj @@ -36,7 +36,7 @@ - + diff --git a/Src/Dlhis.Common/Dlhis.Common.csproj b/Src/Dlhis.Common/Dlhis.Common.csproj index d3228328..02b72955 100644 --- a/Src/Dlhis.Common/Dlhis.Common.csproj +++ b/Src/Dlhis.Common/Dlhis.Common.csproj @@ -21,7 +21,7 @@ - + diff --git a/Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj b/Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj index e412c478..96b47437 100644 --- a/Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj +++ b/Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj @@ -20,7 +20,7 @@ - + diff --git a/Src/Dlhis.Sys/Dlhis.Sys.csproj b/Src/Dlhis.Sys/Dlhis.Sys.csproj index 830d7da2..b14b421d 100644 --- a/Src/Dlhis.Sys/Dlhis.Sys.csproj +++ b/Src/Dlhis.Sys/Dlhis.Sys.csproj @@ -17,7 +17,7 @@ - + diff --git a/Src/Dlhis.User/Dlhis.User.csproj b/Src/Dlhis.User/Dlhis.User.csproj index a803e35b..7934a4d0 100644 --- a/Src/Dlhis.User/Dlhis.User.csproj +++ b/Src/Dlhis.User/Dlhis.User.csproj @@ -17,6 +17,6 @@ - + From ae29ddee87b2d868ed1fe67472dd76f4cc20f538 Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Tue, 5 Mar 2024 16:58:46 +0800 Subject: [PATCH 101/146] =?UTF-8?q?fix=20=E4=BF=AE=E6=94=B9=E8=90=A5?= =?UTF-8?q?=E4=B8=9A=E7=82=B9=E5=88=86=E9=A1=B5=E6=A8=A1=E7=B3=8A=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/BusinessPlacesController.cs | 2 +- .../Implements/BusinessPlaceService.cs | 3 +- .../Services/IBusinessPlaceShiftService.cs | 2 +- .../Implements/BusinessPlaceShiftService.cs | 17 ++++++- .../Device/Response/DevicePageResponse.cs | 9 +++- .../Device/Response/PlaceCodeNameDetil.cs | 9 ---- .../Services/Implements/DeviceService.cs | 27 +++------- .../Services/Implements/BalanceService.cs | 51 ++++++++++++------- 8 files changed, 68 insertions(+), 52 deletions(-) delete mode 100644 Src/Dlhis.Basic/Device/Response/PlaceCodeNameDetil.cs diff --git a/Src/Dlhis.Basic/BusinessPlace/Controllers/BusinessPlacesController.cs b/Src/Dlhis.Basic/BusinessPlace/Controllers/BusinessPlacesController.cs index cc72eb4f..887dfe09 100644 --- a/Src/Dlhis.Basic/BusinessPlace/Controllers/BusinessPlacesController.cs +++ b/Src/Dlhis.Basic/BusinessPlace/Controllers/BusinessPlacesController.cs @@ -100,7 +100,7 @@ public class BusinessPlacesController : ControllerBase /// /// [HttpGet("devicenos")] - public async Task> GetDevicesByCode([FromQuery]BusinessPlaceGetByCodeRequest request) + public async Task> GetDevicesByCode([FromQuery]BusinessPlaceGetByCodeRequest request) { return await _businessPlaceShiftService.GetDevicesByCode(request); } diff --git a/Src/Dlhis.Basic/BusinessPlace/Services/Implements/BusinessPlaceService.cs b/Src/Dlhis.Basic/BusinessPlace/Services/Implements/BusinessPlaceService.cs index ace2b8e9..a49ecf44 100644 --- a/Src/Dlhis.Basic/BusinessPlace/Services/Implements/BusinessPlaceService.cs +++ b/Src/Dlhis.Basic/BusinessPlace/Services/Implements/BusinessPlaceService.cs @@ -25,7 +25,8 @@ public class BusinessPlaceService : IBusinessPlaceService var page = await _dbContext.Queryable() .LeftJoin((x, ps) => x.Code == ps.PlaceCode) .LeftJoin((x, ps, s) => s.Code == ps.ShiftCode) - .WhereIF(request.Search.IsPresent(), x => x.CustomCode.Contains(request.Search)) + .WhereIF(request.Search.IsPresent(), x => x.CustomCode.Contains(request.Search) + || x.Code.ToString().Contains(request.Search) || x.Name.Contains(request.Search)) .WhereIF(request.Catalog.HasValue, x => x.Catalog == request.Catalog) .WhereIF(request.Status.HasValue, x => x.Status == request.Status) .WhereIF(request.Source.HasValue, x => x.Source == request.Source) diff --git a/Src/Dlhis.Basic/BusinessShift/Services/IBusinessPlaceShiftService.cs b/Src/Dlhis.Basic/BusinessShift/Services/IBusinessPlaceShiftService.cs index 3a88f5db..ba4e1114 100644 --- a/Src/Dlhis.Basic/BusinessShift/Services/IBusinessPlaceShiftService.cs +++ b/Src/Dlhis.Basic/BusinessShift/Services/IBusinessPlaceShiftService.cs @@ -18,5 +18,5 @@ public interface IBusinessPlaceShiftService : IScopeDependency Task GetShiftsByPlaceCustomCodeAsync(string placeCustomCode); - Task> GetDevicesByCode(BusinessPlaceGetByCodeRequest request); + Task> GetDevicesByCode(BusinessPlaceGetByCodeRequest request); } diff --git a/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs b/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs index a0636ae0..6df8324d 100644 --- a/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs +++ b/Src/Dlhis.Basic/BusinessShift/Services/Implements/BusinessPlaceShiftService.cs @@ -12,6 +12,7 @@ using Kurisu.Core.Result; using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Services; using Mapster; +using System.Collections.Generic; namespace Dlhis.Basic.BusinessShift.Services.Implements; @@ -190,7 +191,7 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService }; } - public async Task> GetDevicesByCode(BusinessPlaceGetByCodeRequest request) + public async Task> GetDevicesByCode(BusinessPlaceGetByCodeRequest request) { var regiss = await _dbContext.Queryable() .Where(x => x.BusinessPlaceCode.ToString() == request.Code) @@ -216,7 +217,19 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService } } } - return list; + //分页 + var startIndex = (request.PageIndex - 1) * request.PageSize; + var pagedData = list.Skip(startIndex).Take(request.PageSize).ToList(); + + var pagination = new Pagination + { + PageIndex = request.PageIndex, + PageSize = request.PageSize, + Total = list.Count, // 使用原始列表的总数进行分页 + Data = pagedData + }; + + return pagination; } //*********************************************** help methods ***************************************************// diff --git a/Src/Dlhis.Basic/Device/Response/DevicePageResponse.cs b/Src/Dlhis.Basic/Device/Response/DevicePageResponse.cs index 9fe547c6..ab586f63 100644 --- a/Src/Dlhis.Basic/Device/Response/DevicePageResponse.cs +++ b/Src/Dlhis.Basic/Device/Response/DevicePageResponse.cs @@ -101,7 +101,12 @@ public class DevicePageResponse public int UserCount { get; set; } /// - /// 设备营业点 + /// 营业点code /// - public List detils { get; set; } + public string BusinessPlaceCode { get; set; } + + /// + /// 营业点名称 + /// + public string BusinessPlaceName { get; set; } } diff --git a/Src/Dlhis.Basic/Device/Response/PlaceCodeNameDetil.cs b/Src/Dlhis.Basic/Device/Response/PlaceCodeNameDetil.cs deleted file mode 100644 index 9f449033..00000000 --- a/Src/Dlhis.Basic/Device/Response/PlaceCodeNameDetil.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Dlhis.Basic.Device.Response -{ - public class PlaceCodeNameDetil - { - public string BusinessPlaceCode { get; set; } - public string BusinessPlaceName { get; set; } - - } -} diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs index f17f71c2..dc9409e9 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs @@ -15,6 +15,7 @@ using MySqlX.XDevAPI.Relational; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using SqlSugar; +using System.Collections.Generic; namespace Dlhis.Basic.Device.Services.Implements; @@ -65,28 +66,16 @@ public class DeviceService : IDeviceService foreach (var res in page.Data) { - var list = new List(); - var regis = Registries.Where(x => x.DeviceUniqueNo == res.UniqueNo).ToList(); - if (regis!=null && regis.Count>0) + var regis = Registries.Where(x => x.DeviceUniqueNo == res.UniqueNo).FirstOrDefault(); + if (regis != null) { - foreach (var re in regis) + var place = BusinessPlaces.Where(x => x.Code == regis.BusinessPlaceCode).FirstOrDefault(); + if (place != null) { - var place = BusinessPlaces.Where(x => x.Code == re.BusinessPlaceCode) - .FirstOrDefault(); - - if (place != null) - { - var detil = new PlaceCodeNameDetil - { - BusinessPlaceCode = re.BusinessPlaceCode.ToString(), - BusinessPlaceName = place.Name - }; - list.Add(detil); - } - - } + res.BusinessPlaceCode = regis.BusinessPlaceCode.ToString(); + res.BusinessPlaceName = place.Name; + } } - res.detils = list; } page.Data.ForEach(device => diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs index 8de0e473..3dc1a432 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs @@ -600,25 +600,42 @@ public class BalanceService : IBalanceService /// private async Task> GetOfflineDevicesCount(List devices) { - var nos = devices.Select(x => x.UniqueNo).ToList(); - var deviceRegistrys = await _dbContext.Queryable() - .Where(x => nos.Contains(x.DeviceUniqueNo)) + var now = DateTime.Now; + + var deviceUniqueNos = devices.Select(x => x.UniqueNo).ToList(); + + var deviceRegistries = await _dbContext.Queryable() + .LeftJoin((x, d) => x.DeviceUniqueNo == d.UniqueNo) + .Where(x => deviceUniqueNos.Contains(x.DeviceUniqueNo)) + .Select((x, d) => new + { + UniqueNo = d.UniqueNo, + d.HeartbeatInterval, + x.LastHeartbeatTime + }) .ToListAsync(); - var list = new List(); - foreach (var device in devices) - { - var regis = deviceRegistrys.FirstOrDefault(x => x.DeviceUniqueNo == device.UniqueNo); - if (regis == null) - { - continue; - } - TimeSpan timeDifference = DateTime.Now - regis.LastHeartbeatTime; - if (timeDifference.TotalSeconds > (device.HeartbeatInterval * 3)) - { - list.Add(device); - } - } + var OnlineDevices = deviceRegistries + .Where(x => + { + if (x.HeartbeatInterval <= 0) + { + return true; + } + + return x.LastHeartbeatTime.AddSeconds(x.HeartbeatInterval * 3) >= now; + + }) + .Select(x => new + { + UniqueNo = x.UniqueNo, + }) + .ToList(); + var onlineUniqueNos = new List(); + OnlineDevices.ForEach(x => onlineUniqueNos.Add(x.UniqueNo)); + + var offUniqueNos = deviceUniqueNos.Except(onlineUniqueNos).ToList(); + var list = devices.Where(x => offUniqueNos.Contains(x.UniqueNo)).ToList(); return list; } From 509662429b2384ba8ffcc9846ca65dc1afb67d3b Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 5 Mar 2024 17:06:12 +0800 Subject: [PATCH 102/146] =?UTF-8?q?fix=20=E7=A7=BB=E9=99=A4=E6=97=A0?= =?UTF-8?q?=E7=94=A8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/DepartmentsController.cs | 14 +------------- .../Organization/Request/DepartmentPageRequest.cs | 8 -------- 2 files changed, 1 insertion(+), 21 deletions(-) delete mode 100644 Src/Dlhis.Basic/Organization/Request/DepartmentPageRequest.cs diff --git a/Src/Dlhis.Basic/Organization/Controllers/DepartmentsController.cs b/Src/Dlhis.Basic/Organization/Controllers/DepartmentsController.cs index 678e2e0a..55fa4c2b 100644 --- a/Src/Dlhis.Basic/Organization/Controllers/DepartmentsController.cs +++ b/Src/Dlhis.Basic/Organization/Controllers/DepartmentsController.cs @@ -1,8 +1,6 @@ -using Dlhis.Basic.Organization.Request; -using Dlhis.Basic.Organization.Response; +using Dlhis.Basic.Organization.Response; using Dlhis.Basic.Organization.Services; using Kurisu.AspNetCore.MVC; -using Kurisu.Core.DataAccess.Dto; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -33,14 +31,4 @@ public class DepartmentsController : ControllerBase { return await _departmentService.GetTreeAsync(); } - - /// - /// 获取部门树分页 - /// - /// - [HttpGet("treepage")] - public async Task> GetTreePageAsync([FromQuery]DepartmentPageRequest request) - { - return await _departmentService.GetTreePageAsync(request); - } } diff --git a/Src/Dlhis.Basic/Organization/Request/DepartmentPageRequest.cs b/Src/Dlhis.Basic/Organization/Request/DepartmentPageRequest.cs deleted file mode 100644 index cdba378c..00000000 --- a/Src/Dlhis.Basic/Organization/Request/DepartmentPageRequest.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Kurisu.Core.DataAccess.Dto; - -namespace Dlhis.Basic.Organization.Request -{ - public class DepartmentPageRequest : PageDto - { - } -} From 6fbf517aa2a23669a458190b102a8f72f8908dda Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 5 Mar 2024 17:07:57 +0800 Subject: [PATCH 103/146] =?UTF-8?q?fix=20=E7=BC=96=E8=AF=91=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/IDepartmentService.cs | 6 +--- .../Services/Implements/DepartmentService.cs | 29 ------------------- 2 files changed, 1 insertion(+), 34 deletions(-) diff --git a/Src/Dlhis.Basic/Organization/Services/IDepartmentService.cs b/Src/Dlhis.Basic/Organization/Services/IDepartmentService.cs index cfd0b9d2..5e3784c1 100644 --- a/Src/Dlhis.Basic/Organization/Services/IDepartmentService.cs +++ b/Src/Dlhis.Basic/Organization/Services/IDepartmentService.cs @@ -1,12 +1,8 @@ -using Dlhis.Basic.Organization.Request; -using Dlhis.Basic.Organization.Response; -using Kurisu.Core.DataAccess.Dto; +using Dlhis.Basic.Organization.Response; namespace Dlhis.Basic.Organization.Services; public interface IDepartmentService : IScopeDependency { Task> GetTreeAsync(); - - Task> GetTreePageAsync(DepartmentPageRequest request); } diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/DepartmentService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/DepartmentService.cs index 77f42f9a..bf42c549 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/DepartmentService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/DepartmentService.cs @@ -32,35 +32,6 @@ public class DepartmentService : IDepartmentService return tops; } - public async Task> GetTreePageAsync(DepartmentPageRequest request) - { - var departments = await _dbContext - .Queryable() - .WhereIF(!request.Search.IsEmpty(), x => x.Name.Contains(request.Search) || x.No.Contains(request.Search)).ToListAsync(); - - var tops = departments.Where(x => x.PNo.IsEmpty()).Adapt>(); - - tops.ForEach(x => - { - RecursionGetNext(x, departments); - }); - - // 分页操作 - var startIndex = (request.PageIndex - 1) * request.PageSize; - var pagedData = tops.Skip(startIndex).Take(request.PageSize).ToList(); - - var pagination = new Pagination - { - PageIndex = request.PageIndex, - PageSize = request.PageSize, - Total = tops.Count, // 使用原始列表的总数进行分页 - Data = pagedData - }; - - return pagination; - - } - private void RecursionGetNext(DepartmentTreeResponse current, List departments) { var next = departments.Where(x => x.PNo == current.No).ToList(); From 5008f1dc6a71613892be310702b4aefe8314f364 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 5 Mar 2024 17:35:59 +0800 Subject: [PATCH 104/146] =?UTF-8?q?fix=20=E5=A4=84=E7=90=86=E6=A1=86?= =?UTF-8?q?=E6=9E=B6string=20null=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Basic/Dlhis.Basic.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/Dlhis.Basic/Dlhis.Basic.csproj b/Src/Dlhis.Basic/Dlhis.Basic.csproj index 43b23333..ffe86e4d 100644 --- a/Src/Dlhis.Basic/Dlhis.Basic.csproj +++ b/Src/Dlhis.Basic/Dlhis.Basic.csproj @@ -17,7 +17,7 @@ - + From 001f28c4c37d1380096da34e44dc8bbf60c0930f Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 5 Mar 2024 18:32:48 +0800 Subject: [PATCH 105/146] =?UTF-8?q?fix=20=E8=BF=94=E5=9B=9EEditable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Organization/Response/GainfoGroupTreeResponse.cs | 5 +++++ .../Organization/Services/Implements/GainfoGroupService.cs | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Src/Dlhis.Basic/Organization/Response/GainfoGroupTreeResponse.cs b/Src/Dlhis.Basic/Organization/Response/GainfoGroupTreeResponse.cs index 3fb4ca63..b9219035 100644 --- a/Src/Dlhis.Basic/Organization/Response/GainfoGroupTreeResponse.cs +++ b/Src/Dlhis.Basic/Organization/Response/GainfoGroupTreeResponse.cs @@ -23,6 +23,11 @@ public class GainfoGroupTreeResponse /// public string Remark { get; set; } + /// + /// 是否编辑 + /// + public bool Editable { get; set; } + [JsonIgnore] public string TenantId { get; set; } diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs index 2a4390ef..82c91486 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs @@ -22,14 +22,14 @@ public class GainfoGroupService : IGainfoGroupService public async Task> GetTreeAsync() { - var deviceGroups = await _dbContext.Queryable() + var gainfoGroups = await _dbContext.Queryable() .Select() .ToListAsync(); - var tops = deviceGroups.Where(x => !x.PCode.HasValue).ToList(); + var tops = gainfoGroups.Where(x => !x.PCode.HasValue).ToList(); tops.ForEach(x => { - RecursionGetNext(x, deviceGroups); + RecursionGetNext(x, gainfoGroups); }); return tops; From 778d100e72aed749d7d37e5d8269ec9326992357 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 5 Mar 2024 19:35:03 +0800 Subject: [PATCH 106/146] =?UTF-8?q?feat=20=E5=9F=BA=E5=9C=B0/=E7=A7=9F?= =?UTF-8?q?=E6=88=B7tree?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Sys.Api/ITenantApi.cs | 7 +- Src/Dlhis.Sys.Api/Response/TenantResponse.cs | 2 +- .../Response/TenantTreeResponse.cs | 12 ++ .../Identity/Controllers/TenantsController.cs | 10 ++ .../Identity/Request/TenantSaveRequest.cs | 5 + .../Identity/Response/TenantTreeResponse.cs | 12 ++ .../Identity/Services/ITenantService.cs | 2 + .../Services/Implements/TenantService.cs | 35 +++++- .../Menu/Controllers/MenusController.cs | 1 + Src/Dlhis.Sys/SqlSugarPack.cs | 104 +----------------- 10 files changed, 80 insertions(+), 110 deletions(-) create mode 100644 Src/Dlhis.Sys.Api/Response/TenantTreeResponse.cs create mode 100644 Src/Dlhis.Sys/Identity/Response/TenantTreeResponse.cs diff --git a/Src/Dlhis.Sys.Api/ITenantApi.cs b/Src/Dlhis.Sys.Api/ITenantApi.cs index efa3634f..72feba3b 100644 --- a/Src/Dlhis.Sys.Api/ITenantApi.cs +++ b/Src/Dlhis.Sys.Api/ITenantApi.cs @@ -1,4 +1,4 @@ -using Dlhis.User.Api.Response; +using Dlhis.Sys.Api.Response; using Kurisu.Core.Result; using Kurisu.RemoteCall.Attributes; @@ -18,6 +18,11 @@ public interface ITenantApi [Get("/api/tenants/list")] Task>> GetTenantsAsync(); + + [Auth] + [Get("/api/tenants/tree")] + Task>> GetTenantTreeAsync(); + /// /// 获取所有租户(内部使用) /// diff --git a/Src/Dlhis.Sys.Api/Response/TenantResponse.cs b/Src/Dlhis.Sys.Api/Response/TenantResponse.cs index e20f2110..329c0b98 100644 --- a/Src/Dlhis.Sys.Api/Response/TenantResponse.cs +++ b/Src/Dlhis.Sys.Api/Response/TenantResponse.cs @@ -1,4 +1,4 @@ -namespace Dlhis.User.Api.Response; +namespace Dlhis.Sys.Api.Response; public class TenantResponse { diff --git a/Src/Dlhis.Sys.Api/Response/TenantTreeResponse.cs b/Src/Dlhis.Sys.Api/Response/TenantTreeResponse.cs new file mode 100644 index 00000000..a81ba190 --- /dev/null +++ b/Src/Dlhis.Sys.Api/Response/TenantTreeResponse.cs @@ -0,0 +1,12 @@ +using Newtonsoft.Json; + +namespace Dlhis.Sys.Api.Response; + +public class TenantTreeResponse : TenantResponse +{ + /// + /// 下级 + /// + [JsonProperty(Order = 99)] + public List Next { get; set; } +} diff --git a/Src/Dlhis.Sys/Identity/Controllers/TenantsController.cs b/Src/Dlhis.Sys/Identity/Controllers/TenantsController.cs index f34fb7ab..4018d12d 100644 --- a/Src/Dlhis.Sys/Identity/Controllers/TenantsController.cs +++ b/Src/Dlhis.Sys/Identity/Controllers/TenantsController.cs @@ -51,6 +51,16 @@ public class TenantsController : ControllerBase return await _tenantService.GetListAsync(); } + /// + /// 租户树 + /// + /// + [HttpGet("tree")] + public async Task> GetTreeAsync() + { + return await _tenantService.GetTreeAsync(); + } + /// /// 获取租户 /// diff --git a/Src/Dlhis.Sys/Identity/Request/TenantSaveRequest.cs b/Src/Dlhis.Sys/Identity/Request/TenantSaveRequest.cs index a065d331..700c3ba0 100644 --- a/Src/Dlhis.Sys/Identity/Request/TenantSaveRequest.cs +++ b/Src/Dlhis.Sys/Identity/Request/TenantSaveRequest.cs @@ -6,6 +6,11 @@ public class TenantSaveRequest { public int? Id { get; set; } + /// + /// 上级 + /// + public string PCode { get; set; } + /// /// 代码 /// diff --git a/Src/Dlhis.Sys/Identity/Response/TenantTreeResponse.cs b/Src/Dlhis.Sys/Identity/Response/TenantTreeResponse.cs new file mode 100644 index 00000000..dc940ba0 --- /dev/null +++ b/Src/Dlhis.Sys/Identity/Response/TenantTreeResponse.cs @@ -0,0 +1,12 @@ +using Newtonsoft.Json; + +namespace Dlhis.Sys.Identity.Response; + +public class TenantTreeResponse : TenantResponse +{ + /// + /// 下级 + /// + [JsonProperty(Order = 99)] + public List Next { get; set; } +} diff --git a/Src/Dlhis.Sys/Identity/Services/ITenantService.cs b/Src/Dlhis.Sys/Identity/Services/ITenantService.cs index 4c58ad63..c7fb53d8 100644 --- a/Src/Dlhis.Sys/Identity/Services/ITenantService.cs +++ b/Src/Dlhis.Sys/Identity/Services/ITenantService.cs @@ -10,6 +10,8 @@ public interface ITenantService : IScopeDependency Task> GetListAsync(); + Task> GetTreeAsync(); + Task GetTenantByCode(string code); Task> GetMyTenantsAsync(); diff --git a/Src/Dlhis.Sys/Identity/Services/Implements/TenantService.cs b/Src/Dlhis.Sys/Identity/Services/Implements/TenantService.cs index 7dfbbff8..9302cc6e 100644 --- a/Src/Dlhis.Sys/Identity/Services/Implements/TenantService.cs +++ b/Src/Dlhis.Sys/Identity/Services/Implements/TenantService.cs @@ -1,4 +1,5 @@ -using Dlhis.Entity.Sys.Entities; +using Dlhis.Entity.Basic.Entity; +using Dlhis.Entity.Sys.Entities; using Dlhis.Sys.Identity.Request; using Dlhis.Sys.Identity.Response; using Kurisu.AspNetCore.Utils.Extensions; @@ -14,11 +15,9 @@ public class TenantService : ITenantService private readonly IDbContext _dbContext; private readonly ICurrentUser _currentUser; - public TenantService(IDbContext dbContext, IConfiguration configuration, ICurrentUser currentUser) + public TenantService(IDbContext dbContext, ICurrentUser currentUser) { - var identityConnection = configuration.GetSection("SqlSugarOptions:IdentityConnectionString").Value; - dbContext.Client.CurrentConnectionConfig.ConnectionString = identityConnection; - _dbContext = dbContext; + _dbContext = dbContext.ChangeDb("identity"); _currentUser = currentUser; } @@ -52,6 +51,7 @@ public class TenantService : ITenantService { await _dbContext.InsertAsync(new TenantEntity { + PCode = request.PCode, Code = request.Code, Name = request.Name, }); @@ -89,4 +89,29 @@ public class TenantService : ITenantService return myTenants; } + + public async Task> GetTreeAsync() + { + var tenants = await _dbContext.Queryable() + .Select() + .ToListAsync(); + + var tops = tenants.Where(x => x.PCode.IsEmpty()).ToList(); + foreach (var item in tops) + { + RecursionGetNext(item, tenants); + } + return tops; + } + + + private void RecursionGetNext(TenantTreeResponse current, List data) + { + var next = data.Where(x => x.PCode == current.Code).ToList(); + current.Next = next; + foreach (var item in next) + { + RecursionGetNext(item, data); + } + } } diff --git a/Src/Dlhis.Sys/Menu/Controllers/MenusController.cs b/Src/Dlhis.Sys/Menu/Controllers/MenusController.cs index 97808ff2..cf0247f4 100644 --- a/Src/Dlhis.Sys/Menu/Controllers/MenusController.cs +++ b/Src/Dlhis.Sys/Menu/Controllers/MenusController.cs @@ -5,6 +5,7 @@ using Dlhis.Sys.Menu.Services; using Dlhis.Sys.Menu.Response; using Dlhis.Sys.Menu.Request; using Dlhis.Entity.Sys.Enums; +using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop; namespace Dlhis.Sys.Menu.Controllers; diff --git a/Src/Dlhis.Sys/SqlSugarPack.cs b/Src/Dlhis.Sys/SqlSugarPack.cs index 3c58cc41..9458f466 100644 --- a/Src/Dlhis.Sys/SqlSugarPack.cs +++ b/Src/Dlhis.Sys/SqlSugarPack.cs @@ -1,8 +1,5 @@ using Kurisu.AspNetCore.Startup; -using Kurisu.Core.DataAccess.Entity; using Kurisu.SqlSugar.Extensions; -using Kurisu.SqlSugar.Services; -using Microsoft.AspNetCore.Mvc.Filters; using SqlSugar; namespace Dlhis.Sys; @@ -36,103 +33,4 @@ public class SqlSugarPack : BaseAppPack }; }); } -} - - - - -/// -/// 日志 -/// -[AttributeUsage(AttributeTargets.Method)] -public class LogAttribute : Attribute, IAsyncActionFilter -{ - public LogAttribute(string title) - { - Title = title; - } - - /// - /// - /// - public string Title { get; set; } - - /// - /// 是否处理差异 - /// - public bool Diff { get; set; } - - - public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) - { - PreSetting(context.HttpContext); - await next(); - } - - private void PreSetting(HttpContext httpContext) - { - var options = httpContext.RequestServices.GetService(); - - options.Title = Title; - options.Diff = Diff; - options.BatchNo = Guid.NewGuid(); - options.RoutePath = httpContext.Request.Path.Value; - options.RaiseTime = DateTime.Now; - } -} - -/// -/// 事务 -/// -[AttributeUsage(AttributeTargets.Method)] -public class TransactionalAttribute : Attribute, IAsyncActionFilter -{ - public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) - { - var dbContext = context.HttpContext.RequestServices.GetRequiredService(); - await dbContext.Ado.BeginTranAsync(); - try - { - var result = await next(); - if (result.Exception != null) - { - throw result.Exception; - } - else - { - await dbContext.Ado.CommitTranAsync(); - } - } - catch (Exception) - { - await dbContext.Ado.RollbackTranAsync(); - throw; - } - } -} - -/// -/// 忽略租户 -/// -[AttributeUsage(AttributeTargets.Method)] -public class IgnoreTenantAttribute : Attribute, IAsyncActionFilter -{ - public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) - { - var dbContext = context.HttpContext.RequestServices.GetRequiredService(); - var options = context.HttpContext!.RequestServices.GetService(); - try - { - dbContext.QueryFilter.ClearAndBackup(); - options.IgnoreTenant = true; - await next(); - } - finally - { - options.IgnoreTenant = false; - dbContext.QueryFilter.Restore(); - } - } -} - - +} \ No newline at end of file From 22a1d9359d910f852a3392596601fda04977b43d Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 5 Mar 2024 19:35:35 +0800 Subject: [PATCH 107/146] =?UTF-8?q?fix=20=E5=A2=9E=E5=8A=A0=E7=B4=A2?= =?UTF-8?q?=E5=BC=95,=E5=A2=9E=E5=8A=A0=E5=A4=87=E6=B3=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs | 6 ++++++ Src/Dlhis.Entity/Device/Entities/DeviceRegistryEntity.cs | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs b/Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs index b3f44bb9..9b551fbe 100644 --- a/Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs +++ b/Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs @@ -43,6 +43,12 @@ public class DeviceGroupEntity : SugarBaseEntity, ITenantId, ISoftDeleted [SugarColumn(ColumnDescription = "是否可编辑")] public bool Editable { get; set; } + /// + /// 备注 + /// + [SugarColumn(IsNullable = true)] + public string Remark { get; set; } + public string TenantId { get; set; } diff --git a/Src/Dlhis.Entity/Device/Entities/DeviceRegistryEntity.cs b/Src/Dlhis.Entity/Device/Entities/DeviceRegistryEntity.cs index aa88393e..4d45f3ef 100644 --- a/Src/Dlhis.Entity/Device/Entities/DeviceRegistryEntity.cs +++ b/Src/Dlhis.Entity/Device/Entities/DeviceRegistryEntity.cs @@ -13,7 +13,7 @@ public class DeviceRegistryEntity : SugarBaseEntity, ITenantId /// /// 设备唯一号 /// - [SugarColumn(ColumnDescription = "设备唯一号")] + [SugarColumn(ColumnDescription = "设备唯一号", UniqueGroupNameList = new[] { "idx_DeviceRegistry_DeviceUniqueNo" })] public string DeviceUniqueNo { get; set; } /// From 4c959ccd40e0c294c731fac6f6d2cca1a9dbbf03 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 5 Mar 2024 19:36:13 +0800 Subject: [PATCH 108/146] =?UTF-8?q?fix=20=E4=BB=A3=E7=A0=81=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Device/Request/DeviceGroupSaveRequest.cs | 5 ++ .../Response/DeviceGroupTreeResponse.cs | 5 ++ .../Device/Response/DevicePageResponse.cs | 26 ++++++- .../Services/Implements/DeviceService.cs | 68 ++++--------------- .../Controllers/WerksController.cs | 5 +- .../Response/DepartmentTreeResponse.cs | 5 ++ .../Organization/Services/IWerkService.cs | 2 +- .../Services/Implements/DepartmentService.cs | 26 +++---- .../Services/Implements/WerkService.cs | 2 +- .../CommonJobs/CreateDefinitelyGroupJob.cs | 8 ++- .../Response/DeviceTaskAssignmentResponse.cs | 5 ++ .../Implements/DeviceTaskAssignmentService.cs | 1 + 12 files changed, 83 insertions(+), 75 deletions(-) diff --git a/Src/Dlhis.Basic/Device/Request/DeviceGroupSaveRequest.cs b/Src/Dlhis.Basic/Device/Request/DeviceGroupSaveRequest.cs index 9cbf1ee9..f16286ff 100644 --- a/Src/Dlhis.Basic/Device/Request/DeviceGroupSaveRequest.cs +++ b/Src/Dlhis.Basic/Device/Request/DeviceGroupSaveRequest.cs @@ -23,4 +23,9 @@ public class DeviceGroupSaveRequest /// [EnumDataType(typeof(DeviceTypeEnumType))] public DeviceTypeEnumType? Type { get; set; } + + /// + /// 备注 + /// + public string Remark { get; set; } } diff --git a/Src/Dlhis.Basic/Device/Response/DeviceGroupTreeResponse.cs b/Src/Dlhis.Basic/Device/Response/DeviceGroupTreeResponse.cs index 31b5f3f3..24e19c85 100644 --- a/Src/Dlhis.Basic/Device/Response/DeviceGroupTreeResponse.cs +++ b/Src/Dlhis.Basic/Device/Response/DeviceGroupTreeResponse.cs @@ -29,6 +29,11 @@ public class DeviceGroupTreeResponse /// public DeviceTypeEnumType? Type { get; set; } + /// + /// 备注 + /// + public string Remark { get; set; } + /// /// 分组类型描述 /// diff --git a/Src/Dlhis.Basic/Device/Response/DevicePageResponse.cs b/Src/Dlhis.Basic/Device/Response/DevicePageResponse.cs index ab586f63..5543715e 100644 --- a/Src/Dlhis.Basic/Device/Response/DevicePageResponse.cs +++ b/Src/Dlhis.Basic/Device/Response/DevicePageResponse.cs @@ -85,10 +85,32 @@ public class DevicePageResponse /// public bool Enable { get; set; } + + //*********************************************************附加信息**************************************************************/ + + /// + /// 最后心跳时间 + /// + public DateTime? LastHeartbeatTime { get; set; } + /// /// 是否在线 /// - public bool IsOnline { get; set; } + public bool IsOnline + { + get + { + if (!LastHeartbeatTime.HasValue) + return false; + else + { + if (HeartbeatInterval <= 0) + return true; + else + return LastHeartbeatTime.Value.AddSeconds(HeartbeatInterval * 3) >= DateTime.Now; + } + } + } /// /// 消费总额 @@ -103,7 +125,7 @@ public class DevicePageResponse /// /// 营业点code /// - public string BusinessPlaceCode { get; set; } + public Guid? BusinessPlaceCode { get; set; } /// /// 营业点名称 diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs index dc9409e9..7632b1b6 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs @@ -11,11 +11,9 @@ using Kurisu.Core.DataAccess.Dto; using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Services; using Mapster; -using MySqlX.XDevAPI.Relational; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using SqlSugar; -using System.Collections.Generic; namespace Dlhis.Basic.Device.Services.Implements; @@ -32,73 +30,35 @@ public class DeviceService : IDeviceService { var page = await _dbContext.Queryable() .LeftJoin((d, dt) => d.TemplateCode == dt.Code) + .LeftJoin((d, dt, dr) => d.UniqueNo == dr.DeviceUniqueNo) + .LeftJoin((d, dt, dr, bp) => dr.BusinessPlaceCode == bp.Code) .WhereIF(request.Type.HasValue, (d, dt) => d.Type == request.Type) - .Select((d, dt) => new DevicePageResponse + .Select((d, dt, dr, bp) => new DevicePageResponse { FuncsStr = d.Funcs.ToString(), Brand = dt.Brand, Type = d.Type, + BusinessPlaceCode = bp.Code, + BusinessPlaceName = bp.Name, + LastHeartbeatTime = dr.LastHeartbeatTime }, true) .ToPageListAsync(request); - var now = DateTime.Now; var deviceUniqueNos = page.Data.Select(x => x.UniqueNo).ToList(); var balanceRecords = await _dbContext.Queryable().Where(x => x.Type == BalanceRecordTypeEnumType.Out) .Where(x => deviceUniqueNos.Contains(x.DeviceInfo)) + .Select(x => new + { + x.Amount, + x.UserCode + }) .ToListAsync(); - var deviceRegistries = await _dbContext.Queryable() - .LeftJoin((x, d) => x.DeviceUniqueNo == d.UniqueNo) - .Where(x => deviceUniqueNos.Contains(x.DeviceUniqueNo)) - .Select((x, d) => new - { - d.HeartbeatInterval, - x.LastHeartbeatTime, - x.DeviceUniqueNo, - }) - .ToListAsync(); - - var Registries = await _dbContext.Queryable() - .ToListAsync(); - var BusinessPlaces = await _dbContext.Queryable() - .ToListAsync(); - - foreach (var res in page.Data) - { - var regis = Registries.Where(x => x.DeviceUniqueNo == res.UniqueNo).FirstOrDefault(); - if (regis != null) - { - var place = BusinessPlaces.Where(x => x.Code == regis.BusinessPlaceCode).FirstOrDefault(); - if (place != null) - { - res.BusinessPlaceCode = regis.BusinessPlaceCode.ToString(); - res.BusinessPlaceName = place.Name; - } - } - - } page.Data.ForEach(device => { device.Amount = balanceRecords.Sum(x => x.Amount); device.UserCount = balanceRecords.DistinctBy(x => x.UserCode).Count(); - - var r = deviceRegistries.FirstOrDefault(x => x.DeviceUniqueNo == device.UniqueNo); - if (r == null) - { - device.IsOnline = false; - } - else - { - if (r.HeartbeatInterval <= 0) - { - device.IsOnline = true; - } - else - { - device.IsOnline = r.LastHeartbeatTime.AddSeconds(r.HeartbeatInterval * 3) >= now; - } - } }); return page; @@ -290,7 +250,7 @@ public class DeviceService : IDeviceService public async Task GetDeviceNumberAsync() { var devices = await _dbContext.Queryable().Where(x => x.Type == DeviceTypeEnumType.Attendance || (x.Type == DeviceTypeEnumType.Door && x.AsAttendance)).ToListAsync(); - + var offlineNumber = await GetOfflineDevicesCount(devices); var res = new DeviceNumberResponse @@ -333,7 +293,7 @@ public class DeviceService : IDeviceService return x.LastHeartbeatTime.AddSeconds(x.HeartbeatInterval * 3) >= now; }) - .Select(x => new + .Select(x => new { UniqueNo = x.UniqueNo, }) @@ -345,7 +305,7 @@ public class DeviceService : IDeviceService var list = devices.Where(x => offUniqueNos.Contains(x.UniqueNo)).ToList(); return list; } - + public async Task> GetAttendanceTotalAsync(AttendanceTotalRequest request) { diff --git a/Src/Dlhis.Basic/Organization/Controllers/WerksController.cs b/Src/Dlhis.Basic/Organization/Controllers/WerksController.cs index 5f7522dd..bbbb7904 100644 --- a/Src/Dlhis.Basic/Organization/Controllers/WerksController.cs +++ b/Src/Dlhis.Basic/Organization/Controllers/WerksController.cs @@ -1,6 +1,5 @@ -using Dlhis.Basic.Organization.Response; -using Dlhis.Basic.Organization.Services; -using Dlhis.User.Api.Response; +using Dlhis.Basic.Organization.Services; +using Dlhis.Sys.Api.Response; using Kurisu.AspNetCore.MVC; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; diff --git a/Src/Dlhis.Basic/Organization/Response/DepartmentTreeResponse.cs b/Src/Dlhis.Basic/Organization/Response/DepartmentTreeResponse.cs index c30d68b1..309e6d58 100644 --- a/Src/Dlhis.Basic/Organization/Response/DepartmentTreeResponse.cs +++ b/Src/Dlhis.Basic/Organization/Response/DepartmentTreeResponse.cs @@ -2,6 +2,11 @@ public class DepartmentTreeResponse { + /// + /// 上级 + /// + public string PNo { get; set; } + /// /// 部门号 /// diff --git a/Src/Dlhis.Basic/Organization/Services/IWerkService.cs b/Src/Dlhis.Basic/Organization/Services/IWerkService.cs index 8f8ecc4b..42b1a90e 100644 --- a/Src/Dlhis.Basic/Organization/Services/IWerkService.cs +++ b/Src/Dlhis.Basic/Organization/Services/IWerkService.cs @@ -1,4 +1,4 @@ -using Dlhis.User.Api.Response; +using Dlhis.Sys.Api.Response; namespace Dlhis.Basic.Organization.Services; diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/DepartmentService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/DepartmentService.cs index bf42c549..9800dc40 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/DepartmentService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/DepartmentService.cs @@ -1,28 +1,28 @@ -using Dlhis.Basic.Organization.Request; -using Dlhis.Basic.Organization.Response; +using Dlhis.Basic.Organization.Response; using Dlhis.Entity.Basic.Entity; -using Kurisu.AspNetCore.Utils.Extensions; -using Kurisu.Core.DataAccess.Dto; +using Kurisu.Core.User.Abstractions; using Kurisu.SqlSugar.Services; -using Mapster; -using System.Collections.Generic; namespace Dlhis.Basic.Organization.Services.Implements; public class DepartmentService : IDepartmentService { private readonly IDbContext _dbContext; + private readonly ICurrentUser _currentUser; - public DepartmentService(IDbContext dbContext) + public DepartmentService(IDbContext dbContext, ICurrentUser currentUser) { _dbContext = dbContext; + _currentUser = currentUser; } public async Task> GetTreeAsync() { - var departments = await _dbContext.Queryable().ToListAsync(); + var myTenants = _currentUser.GetUserClaim("tenants").Split(',').ToList(); + + var departments = await _dbContext.Queryable().Select().ToListAsync(); //00001000 一定是这个开头的 - var tops = departments.Where(x => x.PNo == "00001000").Adapt>(); + var tops = departments.Where(x => x.PNo == "00001000").ToList(); tops.ForEach(x => { @@ -32,13 +32,13 @@ public class DepartmentService : IDepartmentService return tops; } - private void RecursionGetNext(DepartmentTreeResponse current, List departments) + private void RecursionGetNext(DepartmentTreeResponse current, List data) { - var next = departments.Where(x => x.PNo == current.No).ToList(); - current.Next = next.Adapt>(); + var next = data.Where(x => x.PNo == current.No).ToList(); + current.Next = next; foreach (var item in next) { - RecursionGetNext(item.Adapt(), departments); + RecursionGetNext(item, data); } } } diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/WerkService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/WerkService.cs index 718bd6c1..99517d8a 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/WerkService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/WerkService.cs @@ -1,5 +1,5 @@ using Dlhis.Sys.Api; -using Dlhis.User.Api.Response; +using Dlhis.Sys.Api.Response; using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.Result; using Kurisu.Core.User.Abstractions; diff --git a/Src/Dlhis.ScheduledTask/CommonJobs/CreateDefinitelyGroupJob.cs b/Src/Dlhis.ScheduledTask/CommonJobs/CreateDefinitelyGroupJob.cs index af824291..553f4138 100644 --- a/Src/Dlhis.ScheduledTask/CommonJobs/CreateDefinitelyGroupJob.cs +++ b/Src/Dlhis.ScheduledTask/CommonJobs/CreateDefinitelyGroupJob.cs @@ -2,7 +2,7 @@ using Dlhis.Entity.Device.Entities; using Dlhis.Entity.Device.Enums; using Dlhis.Sys.Api; -using Dlhis.User.Api.Response; +using Dlhis.Sys.Api.Response; using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.DataAccess.Entity; using Kurisu.SqlSugar.Services; @@ -29,6 +29,8 @@ public class CreateDefinitelyGroupJob sqlSugarOptionsService.IgnoreTenant = true; } + private static readonly string _remark = "系统自动生成"; + public async Task RunAsync() { _dbContext.Client.QueryFilter.ClearAndBackup(); @@ -77,6 +79,7 @@ public class CreateDefinitelyGroupJob Name = grp, IsDefault = grp.Equals("*自定义人员分组"), Editable = false, + Remark = _remark, CreatedBy = 1, CreateTime = DateTime.Now, @@ -103,6 +106,7 @@ public class CreateDefinitelyGroupJob Type = type, Name = grp, Editable = false, + Remark = _remark, CreatedBy = 1, CreateTime = DateTime.Now, @@ -126,6 +130,7 @@ public class CreateDefinitelyGroupJob Type = type, Name = workplaceName, Editable = false, + Remark = _remark, CreatedBy = 1, CreateTime = DateTime.Now, @@ -148,6 +153,7 @@ public class CreateDefinitelyGroupJob Type = type, Name = factoryName, Editable = false, + Remark = _remark, CreatedBy = 1, CreateTime = DateTime.Now, diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Response/DeviceTaskAssignmentResponse.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Response/DeviceTaskAssignmentResponse.cs index 96ae9243..7eb69334 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Response/DeviceTaskAssignmentResponse.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Response/DeviceTaskAssignmentResponse.cs @@ -57,6 +57,11 @@ public class DeviceTaskAssignmentResponse /// public string ResultMessage { get; set; } + /// + /// 任务创建时间 + /// + public DateTime CreateTime { get; set; } + /// /// 数据状态最新修改时间 /// diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs index 40f2386a..ea755590 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs @@ -38,6 +38,7 @@ public class DeviceTaskAssignmentService : IDeviceTaskAssignmentService UserName = ga.Name, UserCode = ga.Code, Type = deviceTask.Type, + CreateTime = deviceTask.CreateTime, LastUpdateTime = deviceTask.ModifiedTime }) .ToPageListAsync(request); From 9e2440fe779b17f327f40f2ecb80ed4e1d296090 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 5 Mar 2024 19:46:27 +0800 Subject: [PATCH 109/146] =?UTF-8?q?fix=20=E5=88=86=E9=A1=B5=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Organization/Services/Implements/GainfoService.cs | 5 ++++- .../Order/Services/Implements/BalanceService.cs | 8 ++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs index f500ad8c..7997ceb8 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs @@ -63,7 +63,10 @@ public class GainfoService : IGainfoService .WhereIF(request.DepartmentNos.IsPresent(), gainfo => request.DepartmentNos.Contains(gainfo.DepartmentNo)) .WhereIF(request.Search.IsPresent(), gainfo => gainfo.Name.Contains(request.Search) - || gainfo.Code.Contains(request.Search)) + || gainfo.Code.Contains(request.Search) + || gainfo.IdNo.Contains(request.Search) + || gainfo.Werks.Contains(request.Search) + ) .Select() .ToPageListAsync(request); diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs index 3dc1a432..df747aa0 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs @@ -36,11 +36,15 @@ public class BalanceService : IBalanceService .LeftJoin((record, ga, department) => ga.DepartmentNo == department.No) .LeftJoin((record, ga, department, bplace) => record.BusinessPlaceCode == bplace.Code) .LeftJoin((record, ga, department, bplace, bshift) => record.BusinessShiftCode == bshift.Code) - .LeftJoin((record, ga, department, bplace, bshift, type) => record.BusinessShiftCode.ToString() == type.Code) + .LeftJoin((record, ga, department, bplace, bshift, type) => record.ShiftType == type.Code && type.Type == "mealshift") .WhereIF(request.SearchDateTimePeriod?.Start.HasValue == true, record => record.CostDate >= request.SearchDateTimePeriod.Start) .WhereIF(request.SearchDateTimePeriod?.End.HasValue == true, record => record.CostDate <= request.SearchDateTimePeriod.End) .WhereIF(request.BusinessplaceCodes.IsPresent(), record => request.BusinessplaceCodes.Contains(record.BusinessPlaceCode)) .WhereIF(request.ShiftTypes.IsPresent(), record => request.ShiftTypes.Contains(record.ShiftType)) + .WhereIF(request.Search.IsPresent(), (record, ga) => + ga.Name.Contains(request.Search) + || ga.Code.Contains(request.Search) + ) .OrderBy(record => record.CreateTime, OrderByType.Desc) .Select((record, ga, department, bplace, bshift, type) => new BalanceRecordResponse { @@ -66,7 +70,7 @@ public class BalanceService : IBalanceService DepartmentName = department.Name, BusinessPlaceName = bplace.Name, BusinessShiftName = type.Display, - CostDateTime = record.CreateTime // todo + CostDateTime = record.CostDateTime }) .ToPageListAsync(request); From eada9b6af973fc9a7dbc67d21e6779f959196211 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 5 Mar 2024 20:09:55 +0800 Subject: [PATCH 110/146] =?UTF-8?q?feat=20=E4=BB=BB=E5=8A=A1=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E9=87=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DeviceTaskAssignmentsController.cs | 10 ++++++++ .../Request/DeviceTaskResetRequest.cs | 17 ++++++++++++++ .../Services/IDeviceTaskAssignmentService.cs | 2 ++ .../Implements/DeviceTaskAssignmentService.cs | 23 +++++++++++++++++++ 4 files changed, 52 insertions(+) create mode 100644 Src/Dlhis.ScheduledTask/TaskAssignment/Request/DeviceTaskResetRequest.cs diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Controllers/DeviceTaskAssignmentsController.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Controllers/DeviceTaskAssignmentsController.cs index 6b72836c..52822708 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Controllers/DeviceTaskAssignmentsController.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Controllers/DeviceTaskAssignmentsController.cs @@ -32,4 +32,14 @@ public class DeviceTaskAssignmentsController : ControllerBase { return await _deviceTaskAssignmentService.GetPageAsync(request); } + + /// + /// 重置任务 + /// + /// + [HttpPost("reset")] + public async Task ResetAsync(DeviceTaskResetRequest request) + { + await _deviceTaskAssignmentService.ResetAsync(request); + } } diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Request/DeviceTaskResetRequest.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Request/DeviceTaskResetRequest.cs new file mode 100644 index 00000000..516be624 --- /dev/null +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Request/DeviceTaskResetRequest.cs @@ -0,0 +1,17 @@ +using System.ComponentModel.DataAnnotations; + +namespace Dlhis.ScheduledTask.TaskAssignment.Request; + +public class DeviceTaskResetRequest +{ + /// + /// 任务ids + /// + [MinLength(1, ErrorMessage = "请选择任务进行重置")] + public List Ids { get; set; } + + /// + /// 是否强制重置 + /// + public bool Force { get; set; } +} diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/IDeviceTaskAssignmentService.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/IDeviceTaskAssignmentService.cs index e5bc005c..67c172dd 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/IDeviceTaskAssignmentService.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/IDeviceTaskAssignmentService.cs @@ -8,4 +8,6 @@ public interface IDeviceTaskAssignmentService : IScopeDependency { Task> GetPageAsync(DeviceTaskAssignmentRequest request); + Task ResetAsync(DeviceTaskResetRequest request); + } diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs index ea755590..f2cff78a 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs @@ -1,5 +1,6 @@ using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Device.Entities; +using Dlhis.Entity.Device.Enums; using Dlhis.ScheduledTask.TaskAssignment.Request; using Dlhis.ScheduledTask.TaskAssignment.Response; using Kurisu.AspNetCore.Utils.Extensions; @@ -45,6 +46,28 @@ public class DeviceTaskAssignmentService : IDeviceTaskAssignmentService return page; } + + public async Task ResetAsync(DeviceTaskResetRequest request) + { + var tasks = await _dbContext.Queryable() + .Where(x => request.Ids.Contains(x.Id)) + .Where(x => x.Status == DeviceTaskStatusEnumType.Process || x.Status == DeviceTaskStatusEnumType.Error) + .ToListAsync(); + + //判断process任务时间 + if (!request.Force) + { + var now = DateTime.Now; + tasks.Any(x => x.ModifiedTime.AddMinutes(10) < now && x.Status == DeviceTaskStatusEnumType.Process).ThrowIfTrue("请等待任务处理完成"); + } + + //更新任务状态 + await _dbContext.Updateable() + .SetColumns(x => x.Status == DeviceTaskStatusEnumType.Wait) + .Where(x => request.Ids.Contains(x.Id)) + .Where(x => x.Status == DeviceTaskStatusEnumType.Process || x.Status == DeviceTaskStatusEnumType.Error) + .ExecuteCommandAsync(); + } } From 8157f0a01bf3117db52530d1c112e5ceed16da2a Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 5 Mar 2024 20:38:00 +0800 Subject: [PATCH 111/146] =?UTF-8?q?fix=20=E4=BC=98=E5=8C=96=E5=88=86?= =?UTF-8?q?=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dlhis.Jinko.Face.sln | 2 +- .../Device/Request/DeviceGroupSaveRequest.cs | 2 +- .../Response/DeviceGroupTreeResponse.cs | 10 ++++ .../Services/Implements/DeviceGroupService.cs | 53 ++++++------------- .../Response/GainfoGroupTreeResponse.cs | 12 ++++- .../Services/Implements/GainfoGroupService.cs | 2 - .../Device/Entities/DeviceGroupEntity.cs | 12 +++-- .../CommonJobs/CreateDefinitelyGroupJob.cs | 3 ++ 8 files changed, 50 insertions(+), 46 deletions(-) diff --git a/Dlhis.Jinko.Face.sln b/Dlhis.Jinko.Face.sln index ff1fecaa..0f893f5a 100644 --- a/Dlhis.Jinko.Face.sln +++ b/Dlhis.Jinko.Face.sln @@ -29,7 +29,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dlhis.Canteen", "Src\Dlhis. EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dlhis.Sys.Api", "Src\Dlhis.Sys.Api\Dlhis.Sys.Api.csproj", "{85A345C7-913E-4C1B-BE1C-600DE408A02F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dlhis.Basic.Api", "Src\Dlhis.Basic.Api\Dlhis.Basic.Api.csproj", "{1F337648-8A22-4601-A842-0F634FBA2825}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dlhis.Basic.Api", "Src\Dlhis.Basic.Api\Dlhis.Basic.Api.csproj", "{1F337648-8A22-4601-A842-0F634FBA2825}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/Src/Dlhis.Basic/Device/Request/DeviceGroupSaveRequest.cs b/Src/Dlhis.Basic/Device/Request/DeviceGroupSaveRequest.cs index f16286ff..73bf5281 100644 --- a/Src/Dlhis.Basic/Device/Request/DeviceGroupSaveRequest.cs +++ b/Src/Dlhis.Basic/Device/Request/DeviceGroupSaveRequest.cs @@ -10,7 +10,7 @@ public class DeviceGroupSaveRequest /// /// 上级分组 /// - public Guid? PCode { get; set; } + public Guid PCode { get; set; } /// /// 设备组名称 diff --git a/Src/Dlhis.Basic/Device/Response/DeviceGroupTreeResponse.cs b/Src/Dlhis.Basic/Device/Response/DeviceGroupTreeResponse.cs index 24e19c85..a1e7456a 100644 --- a/Src/Dlhis.Basic/Device/Response/DeviceGroupTreeResponse.cs +++ b/Src/Dlhis.Basic/Device/Response/DeviceGroupTreeResponse.cs @@ -1,5 +1,6 @@ using Dlhis.Entity.Device.Enums; using Kurisu.AspNetCore.Utils.Extensions; +using Microsoft.AspNetCore.Server.IISIntegration; using Newtonsoft.Json; namespace Dlhis.Basic.Device.Response; @@ -50,6 +51,15 @@ public class DeviceGroupTreeResponse } } + public bool Editable { get; set; } + + public bool IsDefault { get; set; } + + /// + /// 是否允许设置下级 + /// + public bool AbleSetNext => IsDefault; + [JsonIgnore] public string TenantId { get; set; } diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs index 361d6289..23cc9137 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs @@ -3,7 +3,6 @@ using Dlhis.Basic.Device.Response; using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Device.Entities; using Dlhis.Entity.Device.Enums; -using Kurisu.AspNetCore.UnifyResultAndValidation; using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.User.Abstractions; using Kurisu.SqlSugar.Services; @@ -46,19 +45,13 @@ public class DeviceGroupService : IDeviceGroupService //检查父级节点 await CheckPCodeExistsDeviceAsync(request.PCode); + var pGrp = await _dbContext.Queryable().Where(x => x.Code == request.PCode).FirstAsync(); + pGrp.AbleSetNext.ThrowIfFalse($"分组{pGrp.Name}不可添加下级"); + (pGrp != null && pGrp.Type != request.Type).ThrowIfTrue("分组类型必须与上级类型保持一致"); + if (!request.Id.HasValue) { - if (request.PCode.HasValue) - { - var pGrp = await _dbContext.Queryable().Where(x => x.Code == request.PCode).FirstAsync(); - if (pGrp != null && pGrp.Type != request.Type) - { - throw new UserFriendlyException("分组类型必须与上级类型保持一致"); - } - } - var entity = request.Adapt(); - entity.Editable = true; entity.Code = Guid.NewGuid(); await _dbContext.InsertAsync(entity); @@ -69,31 +62,18 @@ public class DeviceGroupService : IDeviceGroupService entity.ThrowIfNull("设备组不存在,无法更新"); entity.Editable.ThrowIfFalse("不可编辑当前组"); - if (entity.PCode.HasValue) + if (request.Type != entity.Type) { - var pGrp = await _dbContext.Queryable().Where(x => x.Code == request.PCode).FirstAsync(); - if (pGrp != null && pGrp.Type != request.Type) - { - throw new UserFriendlyException("分组类型必须与上级类型保持一致"); - } - } - else - { - var nGrp = await _dbContext.Queryable().Where(x => x.PCode == entity.Code).FirstAsync(); - if (nGrp != null && nGrp.Type != request.Type) - { - throw new UserFriendlyException("存在下级分组类型不一致,无法修改"); - } - } + //检查下级分组type不一致 + var existsDiffNextGroups = await _dbContext.Queryable() + .Where(x => x.PCode == entity.Code) + .Where(x => x.Type != request.Type) + .AnyAsync(); - var nextDevices = await GetDevicesAsync(entity.Code); - if (!entity.Type.HasValue) - { - (request.Type.HasValue && nextDevices.Any(x => x.Type != request.Type)).ThrowIfTrue($"分组设备存在非{request.Type.Value.GetDescription()}类型的设备设备"); - } - else - { - (request.Type.HasValue && request.Type != entity.Type && nextDevices.Any()).ThrowIfTrue("分组设备类型不匹配,无法修改类型"); + existsDiffNextGroups.ThrowIfTrue("存在下级分组类型不一致,无法修改"); + + var nextDevices = await GetDevicesAsync(entity.Code); + nextDevices.Any(x => x.Type != request.Type).ThrowIfTrue("分组设备类型不匹配,无法修改类型"); } request.Adapt(entity); @@ -185,10 +165,7 @@ public class DeviceGroupService : IDeviceGroupService { var devices = await _dbContext.Queryable().Where(x => request.DeviceCodes.Contains(x.Code)).ToListAsync(); //检查分组的分类控制 - if (group.Type.HasValue) - { - devices.Any(x => x.Type != group.Type).ThrowIfTrue("存在设备类型有误,无法分配到当前分组"); - } + devices.Any(x => x.Type != group.Type).ThrowIfTrue("存在设备类型有误,无法分配到当前分组"); //重新赋值到请求参数中 request.DeviceCodes = devices.Select(x => x.Code).ToList(); diff --git a/Src/Dlhis.Basic/Organization/Response/GainfoGroupTreeResponse.cs b/Src/Dlhis.Basic/Organization/Response/GainfoGroupTreeResponse.cs index b9219035..5b5000fd 100644 --- a/Src/Dlhis.Basic/Organization/Response/GainfoGroupTreeResponse.cs +++ b/Src/Dlhis.Basic/Organization/Response/GainfoGroupTreeResponse.cs @@ -24,10 +24,20 @@ public class GainfoGroupTreeResponse public string Remark { get; set; } /// - /// 是否编辑 + /// 是否可编辑 /// public bool Editable { get; set; } + /// + /// 是否为业务默认分组 + /// + public bool IsDefault { get; set; } + + /// + /// 是否允许设置下级 + /// + public bool AbleSetNext => IsDefault; + [JsonIgnore] public string TenantId { get; set; } diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs index 82c91486..ea35ff11 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs @@ -59,14 +59,12 @@ public class GainfoGroupService : IGainfoGroupService { var entity = request.Adapt(); entity.Code = Guid.NewGuid(); - entity.Editable = true; await _dbContext.InsertAsync(entity); } else { var entity = await _dbContext.Queryable().Where(x => x.Id == request.Id).SingleAsync(); request.Adapt(entity); - entity.Editable = true; await _dbContext.UpdateAsync(entity); } } diff --git a/Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs b/Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs index 9b551fbe..a56c8c97 100644 --- a/Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs +++ b/Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs @@ -15,8 +15,8 @@ public class DeviceGroupEntity : SugarBaseEntity, ITenantId, ISoftDeleted /// /// 设备组功能类型 /// - [SugarColumn(IsNullable = true, ColumnDescription = "设备组功能类型", ColumnDataType = "varchar(50)", SqlParameterDbType = typeof(EnumToStringConvert))] - public DeviceTypeEnumType? Type { get; set; } + [SugarColumn(IsNullable = false, ColumnDescription = "设备组功能类型", ColumnDataType = "varchar(50)", SqlParameterDbType = typeof(EnumToStringConvert))] + public DeviceTypeEnumType Type { get; set; } /// /// 上级设备组code @@ -40,9 +40,15 @@ public class DeviceGroupEntity : SugarBaseEntity, ITenantId, ISoftDeleted /// /// 是否可编辑 /// - [SugarColumn(ColumnDescription = "是否可编辑")] + [SugarColumn(ColumnDataType = "bit", DefaultValue = "1", ColumnDescription = "是否可编辑")] public bool Editable { get; set; } + /// + /// 可设置下级 + /// + [SugarColumn(ColumnDataType = "bit", DefaultValue = "1")] + public bool AbleSetNext { get; set; } + /// /// 备注 /// diff --git a/Src/Dlhis.ScheduledTask/CommonJobs/CreateDefinitelyGroupJob.cs b/Src/Dlhis.ScheduledTask/CommonJobs/CreateDefinitelyGroupJob.cs index 553f4138..9daadce1 100644 --- a/Src/Dlhis.ScheduledTask/CommonJobs/CreateDefinitelyGroupJob.cs +++ b/Src/Dlhis.ScheduledTask/CommonJobs/CreateDefinitelyGroupJob.cs @@ -106,6 +106,7 @@ public class CreateDefinitelyGroupJob Type = type, Name = grp, Editable = false, + AbleSetNext = false, Remark = _remark, CreatedBy = 1, @@ -130,6 +131,7 @@ public class CreateDefinitelyGroupJob Type = type, Name = workplaceName, Editable = false, + AbleSetNext = false, Remark = _remark, CreatedBy = 1, @@ -153,6 +155,7 @@ public class CreateDefinitelyGroupJob Type = type, Name = factoryName, Editable = false, + AbleSetNext = true, Remark = _remark, CreatedBy = 1, From 18a92b96d8ed83f98a90c0438b88cf5dcad80a36 Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Wed, 6 Mar 2024 09:25:34 +0800 Subject: [PATCH 112/146] =?UTF-8?q?feat=20=E6=B6=88=E8=B4=B9=E6=9C=BA?= =?UTF-8?q?=E5=8F=8A=E7=A6=BB=E7=BA=BF=E8=AE=BE=E5=A4=87=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Order/Controllers/BalancesController.cs | 11 +- .../Order/Request/GetConsumeDeviceRequest.cs | 9 ++ .../Response/DevicePageResponseResponse.cs | 104 ++++++++++++++++++ .../Order/Services/IBalanceService.cs | 2 +- .../Services/Implements/BalanceService.cs | 43 +++++++- 5 files changed, 166 insertions(+), 3 deletions(-) create mode 100644 Src/Dlhis.Canteen/Order/Request/GetConsumeDeviceRequest.cs create mode 100644 Src/Dlhis.Canteen/Order/Response/DevicePageResponseResponse.cs diff --git a/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs b/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs index f75a4927..ab61d200 100644 --- a/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs +++ b/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs @@ -146,7 +146,16 @@ public class BalancesController : ControllerBase return await _balanceService.GetConsumeNumberAsync(); } - + /// + /// 获取消费机详情 + /// + /// + /// + [HttpGet("consumeDevices")] + public async Task> GetConsumeDeviceAsync([FromQuery] GetConsumeDeviceRequest request) + { + return await _balanceService.GetConsumeDeviceAsync(request); + } diff --git a/Src/Dlhis.Canteen/Order/Request/GetConsumeDeviceRequest.cs b/Src/Dlhis.Canteen/Order/Request/GetConsumeDeviceRequest.cs new file mode 100644 index 00000000..ee74d2fb --- /dev/null +++ b/Src/Dlhis.Canteen/Order/Request/GetConsumeDeviceRequest.cs @@ -0,0 +1,9 @@ +using Kurisu.Core.DataAccess.Dto; + +namespace Dlhis.Canteen.Order.Request +{ + public class GetConsumeDeviceRequest : PageDto + { + public bool IsOff { get; set; } + } +} diff --git a/Src/Dlhis.Canteen/Order/Response/DevicePageResponseResponse.cs b/Src/Dlhis.Canteen/Order/Response/DevicePageResponseResponse.cs new file mode 100644 index 00000000..1b3724d1 --- /dev/null +++ b/Src/Dlhis.Canteen/Order/Response/DevicePageResponseResponse.cs @@ -0,0 +1,104 @@ +using Dlhis.Entity.Device.Enums; +using Kurisu.AspNetCore.Utils.Extensions; + +namespace Dlhis.Canteen.Order.Response +{ + public class DevicePageResponse + { + public long Id { get; set; } + + /// + /// 设备code + /// + public Guid Code { get; set; } + + /// + /// 设备唯一码,IP/MAC/SNO + /// + public string UniqueNo { get; set; } + + /// + /// 心跳间隔 + /// + public int HeartbeatInterval { get; set; } + + /// + /// 品牌 + /// + public string Brand { get; set; } + + /// + /// 供应商 + /// + public string Supplier { get; set; } + + /// + /// 设备功能 DeviceFuncEnumType + /// + public List Funcs + { + get + { + if (FuncsStr.IsEmpty()) FuncsStr = "[]"; + + return FuncsStr.ToObject>(); + } + } + + public string FuncsStr { get; set; } + + /// + /// 设备机功能类型 + /// + public DeviceTypeEnumType Type { get; set; } + + public string TypeDescription => Type.GetDescription(); + + /// + /// 部署点 + /// + public string DeployPlace { get; set; } + + /// + /// 部署坐标 + /// + public string DeployPosition { get; set; } + + /// + /// 部署方向 + /// + public string DeployDirection { get; set; } + + /// + /// 模板code + /// + public Guid TemplateCode { get; set; } + + /// + /// 连接信息 + /// + public string ConnectionInfo { get; set; } + + + /// + /// 是否启用 + /// + public bool Enable { get; set; } + + /// + /// 是否在线 + /// + public bool IsOnline { get; set; } + + /// + /// 消费总额 + /// + public decimal Amount { get; set; } + + /// + /// 消费人次 + /// + public int UserCount { get; set; } + + } +} diff --git a/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs b/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs index f90026d8..342553b4 100644 --- a/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs @@ -27,7 +27,7 @@ public interface IBalanceService : IScopeDependency Task GetConsumeNumberAsync(); - + Task> GetConsumeDeviceAsync(GetConsumeDeviceRequest request); Task> GetOaEMealVoucherAsync([FromQuery] OaEMealVoucherRequest request); diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs index 3dc1a432..1a7c47f4 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs @@ -551,7 +551,7 @@ public class BalanceService : IBalanceService public async Task GetConsumeNumberAsync() { var devices = await _dbContext.Queryable() - .Where(x => x.Type == DeviceTypeEnumType.Meal && x.Enable) + .Where(x => x.Type == DeviceTypeEnumType.Meal) .ToListAsync(); var offCount = await GetOfflineDevicesCount(devices); @@ -593,6 +593,47 @@ public class BalanceService : IBalanceService } + public async Task> GetConsumeDeviceAsync(GetConsumeDeviceRequest request) + { + if (request.IsOff) + { + //消费机离线设备 + var devices = await _dbContext.Queryable() + .Where(x => x.Type == DeviceTypeEnumType.Meal) + .ToListAsync(); + + var offs = await GetOfflineDevicesCount(devices); + var offUniqueNos = offs.Select(x => x.UniqueNo).ToList(); + + var offpage = await _dbContext.Queryable() + .LeftJoin((d, dt) => d.TemplateCode == dt.Code) + .Where(d => offUniqueNos.Contains(d.UniqueNo)) + .Select((d, dt) => new DevicePageResponse + { + FuncsStr = d.Funcs.ToString(), + Brand = dt.Brand, + Type = d.Type, + + }, true) + .ToPageListAsync(request); + return offpage; + } + //消费机总数 + var page = await _dbContext.Queryable() + .LeftJoin((d, dt) => d.TemplateCode == dt.Code) + .Where(d => d.Type == DeviceTypeEnumType.Meal) + .Select((d, dt) => new DevicePageResponse + { + FuncsStr = d.Funcs.ToString(), + Brand = dt.Brand, + Type = d.Type, + + }, true) + .ToPageListAsync(request); + return page; + } + + /// /// 获取离线设备 /// From 05369a691fc41aec0920fd5c1d8dc39305e4958d Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Wed, 6 Mar 2024 10:23:55 +0800 Subject: [PATCH 113/146] =?UTF-8?q?feat=20=E8=90=A5=E4=B8=9A=E7=82=B9?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE=E8=AE=BE=E5=A4=87=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Order/Controllers/BalancesController.cs | 12 ++++++++ .../Order/Request/DispositionDeviceRequest.cs | 9 ++++++ .../Order/Services/IBalanceService.cs | 2 ++ .../Services/Implements/BalanceService.cs | 28 +++++++++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 Src/Dlhis.Canteen/Order/Request/DispositionDeviceRequest.cs diff --git a/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs b/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs index ab61d200..967f1c81 100644 --- a/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs +++ b/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs @@ -4,6 +4,7 @@ using Dlhis.Canteen.Order.Services; using Kurisu.Core.DataAccess.Dto; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Org.BouncyCastle.Asn1.Ocsp; namespace Dlhis.Canteen.Order.Controllers; @@ -158,6 +159,17 @@ public class BalancesController : ControllerBase } + /// + /// 营业点增加配置设备接口 + /// + /// + /// + [HttpGet("disposition")] + public async Task DispositionDeviceAsync([FromQuery]DispositionDeviceRequest request) + { + await _balanceService.DispositionDeviceAsync(request); + } + /// /// 电子餐券申请记录查询 diff --git a/Src/Dlhis.Canteen/Order/Request/DispositionDeviceRequest.cs b/Src/Dlhis.Canteen/Order/Request/DispositionDeviceRequest.cs new file mode 100644 index 00000000..aa76e8c5 --- /dev/null +++ b/Src/Dlhis.Canteen/Order/Request/DispositionDeviceRequest.cs @@ -0,0 +1,9 @@ +namespace Dlhis.Canteen.Order.Request +{ + public class DispositionDeviceRequest + { + public string PlaceCode { get; set; } + + public List UniqueNos { get; set; } + } +} diff --git a/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs b/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs index 342553b4..90847d70 100644 --- a/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs @@ -29,6 +29,8 @@ public interface IBalanceService : IScopeDependency Task> GetConsumeDeviceAsync(GetConsumeDeviceRequest request); + Task DispositionDeviceAsync(DispositionDeviceRequest request); + Task> GetOaEMealVoucherAsync([FromQuery] OaEMealVoucherRequest request); diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs index f8e57a1f..3122faca 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs @@ -12,6 +12,7 @@ using Kurisu.Core.DataAccess.Entity; using Kurisu.Core.User.Abstractions; using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Services; +using Microsoft.AspNetCore.Mvc; using SqlSugar; namespace Dlhis.Canteen.Order.Services.Implements; @@ -735,6 +736,33 @@ public class BalanceService : IBalanceService } + public async Task DispositionDeviceAsync(DispositionDeviceRequest request) + { + var places = await _dbContext.Queryable().ToListAsync(); + var place = places.Where(x => x.Code.ToString() == request.PlaceCode).First(); + place.ThrowIfNull($"{request.PlaceCode}:该营业点不存在"); + + var devices = await _dbContext.Queryable().ToListAsync(); + foreach (var no in request.UniqueNos) + { + var device = devices.Where(x => x.UniqueNo == no).First(); + device.ThrowIfNull("设备不存在"); + } + var regiss = await _dbContext.Queryable() + .Where(x => request.UniqueNos.Contains(x.DeviceUniqueNo)) + .ToListAsync(); + + var list = new List(); + + foreach (var regis in regiss) + { + regis.BusinessPlaceCode = place.Code; + regis.BusinessPlaceCustomCode = place.CustomCode; + list.Add(regis); + } + await _dbContext.UpdateAsync(list); + } + public async Task> GetOaEMealVoucherAsync(OaEMealVoucherRequest request) { var page = await _dbContext.Queryable() From ca239ce87396e68bec89508b19982516c58c8d84 Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Wed, 6 Mar 2024 10:40:59 +0800 Subject: [PATCH 114/146] =?UTF-8?q?fix=20=E4=BF=AE=E6=94=B9=E7=82=B9?= =?UTF-8?q?=E5=87=BB=E5=85=B3=E6=8E=89=E5=9C=A8=E8=81=8C/=E7=A6=BB?= =?UTF-8?q?=E8=81=8C=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Basic/Organization/Request/GainfoPageRequest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/Dlhis.Basic/Organization/Request/GainfoPageRequest.cs b/Src/Dlhis.Basic/Organization/Request/GainfoPageRequest.cs index 0bfb339b..37cc810f 100644 --- a/Src/Dlhis.Basic/Organization/Request/GainfoPageRequest.cs +++ b/Src/Dlhis.Basic/Organization/Request/GainfoPageRequest.cs @@ -10,7 +10,7 @@ public class GainfoPageRequest : PageDto /// 档案类型 /// [EnumDataType(typeof(GainfoStatusEnumType))] - public GainfoStatusEnumType Status { get; set; } = GainfoStatusEnumType.Working; + public GainfoStatusEnumType? Status { get; set; } = GainfoStatusEnumType.Working; /// /// 部门号(部门树传入) From 41d4807ccad9ba0b32bed648b581747a868e8ff0 Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Wed, 6 Mar 2024 10:49:34 +0800 Subject: [PATCH 115/146] =?UTF-8?q?fix=20=E4=BF=AE=E6=94=B9=E8=90=A5?= =?UTF-8?q?=E4=B8=9A=E7=82=B9=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E6=8E=A5=E5=8F=A3=E4=B8=BApost?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs b/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs index 967f1c81..9f206652 100644 --- a/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs +++ b/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs @@ -164,7 +164,7 @@ public class BalancesController : ControllerBase /// /// /// - [HttpGet("disposition")] + [HttpPost("disposition")] public async Task DispositionDeviceAsync([FromQuery]DispositionDeviceRequest request) { await _balanceService.DispositionDeviceAsync(request); From 11690623a4d0b257421277ac8befd0a0146c7290 Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Wed, 6 Mar 2024 14:05:36 +0800 Subject: [PATCH 116/146] =?UTF-8?q?fix=20=E4=BF=AE=E6=AD=A3=E8=AF=AD?= =?UTF-8?q?=E6=B3=95=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Basic/Device/Services/IDeviceService.cs | 1 + Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs | 4 ++-- Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Src/Dlhis.Basic/Device/Services/IDeviceService.cs b/Src/Dlhis.Basic/Device/Services/IDeviceService.cs index fa3176e7..7f47e38f 100644 --- a/Src/Dlhis.Basic/Device/Services/IDeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/IDeviceService.cs @@ -1,6 +1,7 @@ using Dlhis.Basic.Device.Request; using Dlhis.Basic.Device.Response; using Kurisu.Core.DataAccess.Dto; +using Microsoft.AspNetCore.Mvc; namespace Dlhis.Basic.Device.Services; diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs index 7632b1b6..e28e3c0d 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs @@ -11,6 +11,7 @@ using Kurisu.Core.DataAccess.Dto; using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Services; using Mapster; +using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using SqlSugar; @@ -311,7 +312,7 @@ public class DeviceService : IDeviceService { var page = await _dbContext.Queryable() .LeftJoin((d, dt) => d.TemplateCode == dt.Code) - .Where(x => x.Type == DeviceTypeEnumType.Attendance || (x.Type == DeviceTypeEnumType.Door && x.AsAttendance)) + .Where(d => d.Type == DeviceTypeEnumType.Attendance || (d.Type == DeviceTypeEnumType.Door && d.AsAttendance)) .Select((d, dt) => new DevicePageResponse { FuncsStr = d.Funcs.ToString(), @@ -397,6 +398,5 @@ public class DeviceService : IDeviceService return list; } - } diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs index 3122faca..2aea8546 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs @@ -746,7 +746,7 @@ public class BalanceService : IBalanceService foreach (var no in request.UniqueNos) { var device = devices.Where(x => x.UniqueNo == no).First(); - device.ThrowIfNull("设备不存在"); + device.ThrowIfNull($"{no}:设备不存在"); } var regiss = await _dbContext.Queryable() .Where(x => request.UniqueNos.Contains(x.DeviceUniqueNo)) From 1f17e7a92b6368e732b64d3ebf01f553b4d25fcc Mon Sep 17 00:00:00 2001 From: liguoyang Date: Wed, 6 Mar 2024 16:05:11 +0800 Subject: [PATCH 117/146] =?UTF-8?q?fix=20=E7=A7=BB=E9=99=A4=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E5=88=A0=E9=99=A4=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Entity/Sys/Entities/DevicePermissionEntity.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Src/Dlhis.Entity/Sys/Entities/DevicePermissionEntity.cs b/Src/Dlhis.Entity/Sys/Entities/DevicePermissionEntity.cs index cb4e2e0f..8f2a3c09 100644 --- a/Src/Dlhis.Entity/Sys/Entities/DevicePermissionEntity.cs +++ b/Src/Dlhis.Entity/Sys/Entities/DevicePermissionEntity.cs @@ -10,7 +10,7 @@ namespace Dlhis.Entity.Sys.Entities; /// 设备权限 /// [SugarTable(TableName = "DevicePermission", TableDescription = "设备权限")] -public class DevicePermissionEntity : SugarBaseEntity, ITenantId, ISoftDeleted +public class DevicePermissionEntity : SugarBaseEntity, ITenantId { /// /// 分配权限类型 @@ -24,7 +24,6 @@ public class DevicePermissionEntity : SugarBaseEntity, ITenantId, ISoftDeleted [SugarColumn(ColumnDescription = "分配值")] public string AssignValue { get; set; } - /// /// 设备权限类型 /// @@ -37,7 +36,6 @@ public class DevicePermissionEntity : SugarBaseEntity, ITenantId, ISoftDeleted [SugarColumn(ColumnDescription = "类型值")] public Guid UniqueValue { get; set; } - public string TenantId { get; set; } - public bool IsDeleted { get; set; } + public string TenantId { get; set; } } \ No newline at end of file From 973142db2fbabf61d46c096921b8ab00bf934160 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Wed, 6 Mar 2024 16:11:12 +0800 Subject: [PATCH 118/146] =?UTF-8?q?fix=20=E6=9B=B4=E6=96=B0=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E8=AF=B7=E6=B1=82=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Canteen/Dlhis.Canteen.csproj | 2 +- Src/Dlhis.Canteen/appsettings.json | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Src/Dlhis.Canteen/Dlhis.Canteen.csproj b/Src/Dlhis.Canteen/Dlhis.Canteen.csproj index 30b34732..8ad57920 100644 --- a/Src/Dlhis.Canteen/Dlhis.Canteen.csproj +++ b/Src/Dlhis.Canteen/Dlhis.Canteen.csproj @@ -36,7 +36,7 @@ - + diff --git a/Src/Dlhis.Canteen/appsettings.json b/Src/Dlhis.Canteen/appsettings.json index 0f4accb1..e8f2179e 100644 --- a/Src/Dlhis.Canteen/appsettings.json +++ b/Src/Dlhis.Canteen/appsettings.json @@ -10,6 +10,9 @@ "CommonRequestUrl": "http://common", "BasicRequestUrl": "http://basic" }, + "FilterOptions": { + "EnableApiRequestLog": true + }, "SqlSugarOptions": { "DefaultConnectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=yikatong;charset=utf8mb4;", "SlaveConnectionString": [], From 2364b82540cb4adfbbd3fb230dab4f0b29df4618 Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Wed, 6 Mar 2024 16:12:39 +0800 Subject: [PATCH 119/146] =?UTF-8?q?fix=20=E6=97=A5=E5=BF=97=E5=80=92?= =?UTF-8?q?=E5=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Order/Controllers/BalancesController.cs | 1 + .../Order/Response/SpendingDetailResponse.cs | 24 +++++++++++++++++++ .../Order/Services/IBalanceService.cs | 2 ++ .../Services/Implements/BalanceService.cs | 14 ++++++++--- Src/Dlhis.Common/Services/ApiLogService.cs | 2 ++ 5 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 Src/Dlhis.Canteen/Order/Response/SpendingDetailResponse.cs diff --git a/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs b/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs index 9f206652..a94dc314 100644 --- a/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs +++ b/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs @@ -147,6 +147,7 @@ public class BalancesController : ControllerBase return await _balanceService.GetConsumeNumberAsync(); } + /// /// 获取消费机详情 /// diff --git a/Src/Dlhis.Canteen/Order/Response/SpendingDetailResponse.cs b/Src/Dlhis.Canteen/Order/Response/SpendingDetailResponse.cs new file mode 100644 index 00000000..ad309eb9 --- /dev/null +++ b/Src/Dlhis.Canteen/Order/Response/SpendingDetailResponse.cs @@ -0,0 +1,24 @@ +using SqlSugar; + +namespace Dlhis.Canteen.Order.Response +{ + public class SpendingDetailResponse + { + /// + /// 档案号 + /// + public string No { get; set; } + + /// + /// 姓名 + /// + public string Name { get; set; } + + /// + /// 学工号 + /// + public string Code { get; set; } + + + } +} diff --git a/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs b/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs index 90847d70..73c3497a 100644 --- a/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs @@ -27,6 +27,8 @@ public interface IBalanceService : IScopeDependency Task GetConsumeNumberAsync(); + + Task> GetConsumeDeviceAsync(GetConsumeDeviceRequest request); Task DispositionDeviceAsync(DispositionDeviceRequest request); diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs index 2aea8546..94370d33 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs @@ -562,6 +562,7 @@ public class BalanceService : IBalanceService var offCount = await GetOfflineDevicesCount(devices); var places = await _dbContext.Queryable() + .Where(x =>x.Status == CanteenBusinessPlaceStatusEnumType.Opened) .ToListAsync(); var time = DateTime.Now.ToString("yyyy-MM-dd"); @@ -598,6 +599,8 @@ public class BalanceService : IBalanceService } + + public async Task> GetConsumeDeviceAsync(GetConsumeDeviceRequest request) { if (request.IsOff) @@ -743,11 +746,16 @@ public class BalanceService : IBalanceService place.ThrowIfNull($"{request.PlaceCode}:该营业点不存在"); var devices = await _dbContext.Queryable().ToListAsync(); - foreach (var no in request.UniqueNos) + + if (request.UniqueNos!=null && request.UniqueNos.Count > 0) { - var device = devices.Where(x => x.UniqueNo == no).First(); - device.ThrowIfNull($"{no}:设备不存在"); + foreach (var no in request.UniqueNos) + { + var device = devices.Where(x => x.UniqueNo == no).First(); + device.ThrowIfNull($"{no}:设备不存在"); + } } + var regiss = await _dbContext.Queryable() .Where(x => request.UniqueNos.Contains(x.DeviceUniqueNo)) .ToListAsync(); diff --git a/Src/Dlhis.Common/Services/ApiLogService.cs b/Src/Dlhis.Common/Services/ApiLogService.cs index b25c9ed3..2a6b9550 100644 --- a/Src/Dlhis.Common/Services/ApiLogService.cs +++ b/Src/Dlhis.Common/Services/ApiLogService.cs @@ -6,6 +6,7 @@ using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.DataAccess.Dto; using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Services; +using SqlSugar; namespace Dlhis.Common.Services { @@ -23,6 +24,7 @@ namespace Dlhis.Common.Services var logs = await _dbContext.ChangeDb("log").Queryable() .WhereIF(request.Search.IsPresent(), x => x.Message.Contains(request.Search)) .WhereIF(request.Level.HasValue, x => x.Level == request.Level) + .OrderBy(x => x.Timestamp,OrderByType.Desc) .Select() .ToPageListAsync(request); From 4bab1fd2fd358aedf1f459e4ac144e95457cb375 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Wed, 6 Mar 2024 16:37:54 +0800 Subject: [PATCH 120/146] =?UTF-8?q?fix=20ignoreTenant=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Device/Controllers/DevicePermissionsController.cs | 1 + Src/Dlhis.Basic/appsettings.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs b/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs index c13ca4bc..0c61d995 100644 --- a/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs +++ b/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs @@ -61,6 +61,7 @@ public class DevicePermissionsController : ControllerBase /// /// [HttpGet("canteen/uniqueNos")] + [IgnoreTenant] public async Task> GetCanteenDeviceUniqueNosByUserNoAsync(string userNo) { return await _devicePermissionService.GetCanteenDeviceUniqueNosByUserNoAsync(userNo); diff --git a/Src/Dlhis.Basic/appsettings.json b/Src/Dlhis.Basic/appsettings.json index 428e90e9..79da19b2 100644 --- a/Src/Dlhis.Basic/appsettings.json +++ b/Src/Dlhis.Basic/appsettings.json @@ -25,7 +25,7 @@ "LogConnectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=log;charset=utf8mb4;", "Timeout": 30, "SlowSqlTime": 1, - "EnableSqlLog": true + "EnableSqlLog": false }, "SwaggerOptions": { "Enable": true, From 6352ffd9afaec09f264d7cce1ec7ee67153f388d Mon Sep 17 00:00:00 2001 From: liguoyang Date: Wed, 6 Mar 2024 17:34:14 +0800 Subject: [PATCH 121/146] =?UTF-8?q?fix=20=E6=A1=A3=E6=A1=88=E7=BB=84?= =?UTF-8?q?=E5=88=86=E9=85=8D=E4=BA=BA=E5=91=98=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Organization/Services/Implements/GainfoGroupService.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs index ea35ff11..55df243d 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs @@ -53,7 +53,7 @@ public class GainfoGroupService : IGainfoGroupService { _dbContext.Client.QueryFilter.Restore(); } - + if (!request.Id.HasValue) { @@ -86,6 +86,9 @@ public class GainfoGroupService : IGainfoGroupService public async Task AssignGainfosAsync(GainfoAssignRequest request) { + var existsNextGroup = await _dbContext.Queryable().Where(x => x.PCode == request.GroupCode).AnyAsync(); + existsNextGroup.ThrowIfTrue("存在下级分组,无法分配人员"); + var relations = await _dbContext.Queryable().Where(x => x.GroupCode == request.GroupCode).ToListAsync(); await _dbContext.DeleteReallyAsync(relations); From 9f771bc865212a5692ae00a87827ac1e5c5adb64 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Wed, 6 Mar 2024 19:22:14 +0800 Subject: [PATCH 122/146] =?UTF-8?q?fix=20=E4=BC=98=E5=8C=96=E7=BB=86?= =?UTF-8?q?=E8=8A=82=E5=92=8Ctenant=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/DeviceGroupsController.cs | 1 + .../Request/DevicePermissionSaveReuqest.cs | 4 +-- .../Services/Implements/DeviceGroupService.cs | 35 ++++++++++--------- .../Services/Implements/DeviceService.cs | 16 ++++++--- .../Sys/Entities/DevicePermissionEntity.cs | 4 +-- .../CommonJobs/HeartbeatJob.cs | 6 ++-- 6 files changed, 38 insertions(+), 28 deletions(-) diff --git a/Src/Dlhis.Basic/Device/Controllers/DeviceGroupsController.cs b/Src/Dlhis.Basic/Device/Controllers/DeviceGroupsController.cs index 66a5089f..723635c4 100644 --- a/Src/Dlhis.Basic/Device/Controllers/DeviceGroupsController.cs +++ b/Src/Dlhis.Basic/Device/Controllers/DeviceGroupsController.cs @@ -43,6 +43,7 @@ public class DeviceGroupsController : ControllerBase /// /// [HttpPost("save")] + [IgnoreTenant] public async Task SaveAsync(DeviceGroupSaveRequest request) { await _deviceGroupService.SaveAsync(request); diff --git a/Src/Dlhis.Basic/Device/Request/DevicePermissionSaveReuqest.cs b/Src/Dlhis.Basic/Device/Request/DevicePermissionSaveReuqest.cs index f9efc594..ae282891 100644 --- a/Src/Dlhis.Basic/Device/Request/DevicePermissionSaveReuqest.cs +++ b/Src/Dlhis.Basic/Device/Request/DevicePermissionSaveReuqest.cs @@ -27,7 +27,7 @@ public class DevicePermissionSaveReuqest public DeviceAssignmentTypeEnumType UniqueType { get; set; } /// - /// 分配权限值不能为空 + /// 分配权限值 /// - public List Codes { get; set; } = new List(); + public List Codes { get; set; } } diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs index 23cc9137..3bef9e57 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs @@ -43,11 +43,7 @@ public class DeviceGroupService : IDeviceGroupService public async Task SaveAsync(DeviceGroupSaveRequest request) { //检查父级节点 - await CheckPCodeExistsDeviceAsync(request.PCode); - - var pGrp = await _dbContext.Queryable().Where(x => x.Code == request.PCode).FirstAsync(); - pGrp.AbleSetNext.ThrowIfFalse($"分组{pGrp.Name}不可添加下级"); - (pGrp != null && pGrp.Type != request.Type).ThrowIfTrue("分组类型必须与上级类型保持一致"); + var pGrp = await CheckPCodeAsync(request); if (!request.Id.HasValue) { @@ -59,8 +55,8 @@ public class DeviceGroupService : IDeviceGroupService else { var entity = await _dbContext.Queryable().Where(x => x.Id == request.Id).FirstAsync(); - entity.ThrowIfNull("设备组不存在,无法更新"); - entity.Editable.ThrowIfFalse("不可编辑当前组"); + entity.ThrowIfNull("设备分组不存在,无法更新"); + entity.Editable.ThrowIfFalse("不可编辑当前分组"); if (request.Type != entity.Type) { @@ -84,7 +80,7 @@ public class DeviceGroupService : IDeviceGroupService public async Task DeleteAsync(long id) { var deviceGroup = await _dbContext.Queryable().Where(x => x.Id == id).FirstAsync(); - deviceGroup.ThrowIfNull("设备组不存在,无需删除"); + deviceGroup.ThrowIfNull("设备分组不存在,无需删除"); await _dbContext.DeleteAsync(deviceGroup); } @@ -131,28 +127,35 @@ public class DeviceGroupService : IDeviceGroupService /****************************************************** help methods *********************************************************/ /// - /// 检查父级分组存在设备 + /// 检查父级分组 /// - /// + /// /// - private async Task CheckPCodeExistsDeviceAsync(Guid? pCode) + private async Task CheckPCodeAsync(DeviceGroupSaveRequest request) { - if (pCode.HasValue) + + var pGrp = await _dbContext.Queryable().Where(x => x.Code == request.PCode).FirstAsync(); + if (pGrp != null) { - var exists = await _dbContext.Queryable().Where(x => x.GroupCode == pCode).AnyAsync(); + (!pGrp.AbleSetNext && !request.Id.HasValue).ThrowIfTrue($"{pGrp.Name}不可添加下级"); + var exists = await _dbContext.Queryable().Where(x => x.GroupCode == request.PCode).AnyAsync(); exists.ThrowIfTrue("父级分组存在设备"); } + + (pGrp != null && pGrp.Type != request.Type).ThrowIfTrue("分组类型必须与上级类型保持一致"); + + return pGrp; } /// - /// + /// 检查分组是否存在下级 /// /// /// private async Task CheckNoNextGroupAsync(Guid currentCode) { var exists = await _dbContext.Queryable().Where(x => x.PCode == currentCode).AnyAsync(); - exists.ThrowIfTrue("存在下级设备分组"); + exists.ThrowIfTrue("存在下级设备分组,无法分配设备"); } /// @@ -165,7 +168,7 @@ public class DeviceGroupService : IDeviceGroupService { var devices = await _dbContext.Queryable().Where(x => request.DeviceCodes.Contains(x.Code)).ToListAsync(); //检查分组的分类控制 - devices.Any(x => x.Type != group.Type).ThrowIfTrue("存在设备类型有误,无法分配到当前分组"); + devices.Any(x => x.Type != group.Type).ThrowIfTrue($"存在设备类型不一致,无法分配到当前{group.Type.GetDescription()}分组"); //重新赋值到请求参数中 request.DeviceCodes = devices.Select(x => x.Code).ToList(); diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs index e28e3c0d..42fac162 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs @@ -47,19 +47,25 @@ public class DeviceService : IDeviceService var deviceUniqueNos = page.Data.Select(x => x.UniqueNo).ToList(); - var balanceRecords = await _dbContext.Queryable().Where(x => x.Type == BalanceRecordTypeEnumType.Out) + var balanceInfos = await _dbContext.Queryable().Where(x => x.Type == BalanceRecordTypeEnumType.Out) .Where(x => deviceUniqueNos.Contains(x.DeviceInfo)) .Select(x => new { - x.Amount, - x.UserCode + x.DeviceInfo, + Amount = SqlFunc.AggregateSum(x.Amount), + UserCount = SqlFunc.AggregateDistinctCount(x.UserCode) }) + .GroupBy(x => x.DeviceInfo) .ToListAsync(); page.Data.ForEach(device => { - device.Amount = balanceRecords.Sum(x => x.Amount); - device.UserCount = balanceRecords.DistinctBy(x => x.UserCode).Count(); + var info = balanceInfos.FirstOrDefault(x => x.DeviceInfo == device.UniqueNo); + if (info != null) + { + device.Amount = info.Amount; + device.UserCount = info.UserCount; + } }); return page; diff --git a/Src/Dlhis.Entity/Sys/Entities/DevicePermissionEntity.cs b/Src/Dlhis.Entity/Sys/Entities/DevicePermissionEntity.cs index 8f2a3c09..39135b68 100644 --- a/Src/Dlhis.Entity/Sys/Entities/DevicePermissionEntity.cs +++ b/Src/Dlhis.Entity/Sys/Entities/DevicePermissionEntity.cs @@ -13,7 +13,7 @@ namespace Dlhis.Entity.Sys.Entities; public class DevicePermissionEntity : SugarBaseEntity, ITenantId { /// - /// 分配权限类型 + /// 分配权限类型(User,Role,Group...) /// [SugarColumn(ColumnDataType = "varchar(50)", ColumnDescription = "分配权限类型", SqlParameterDbType = typeof(EnumToStringConvert))] public AssignTypeEnumType AssignType { get; set; } @@ -25,7 +25,7 @@ public class DevicePermissionEntity : SugarBaseEntity, ITenantId public string AssignValue { get; set; } /// - /// 设备权限类型 + /// 设备权限类型(Device/DeviceGroup) /// [SugarColumn(ColumnDataType = "varchar(50)", ColumnDescription = "设备权限类型", SqlParameterDbType = typeof(EnumToStringConvert))] public DeviceAssignmentTypeEnumType UniqueType { get; set; } diff --git a/Src/Dlhis.ScheduledTask/CommonJobs/HeartbeatJob.cs b/Src/Dlhis.ScheduledTask/CommonJobs/HeartbeatJob.cs index ed994038..bd7cdb19 100644 --- a/Src/Dlhis.ScheduledTask/CommonJobs/HeartbeatJob.cs +++ b/Src/Dlhis.ScheduledTask/CommonJobs/HeartbeatJob.cs @@ -38,11 +38,11 @@ public class HeartbeatJob await _dbContext.Updateable().SetColumns(x => x.LastHeartbeatTime == DateTime.Now) .Where(x => x.DeviceUniqueNo == device.UniqueNo).ExecuteCommandAsync(); - _logger.LogInformation("心跳设备成功:{no}", device.UniqueNo); + // _logger.LogInformation("心跳设备成功:{no}", device.UniqueNo); } - catch (Exception ex) + catch (Exception) { - _logger.LogError(ex, "心跳设备失败:{no}. {message}", device.UniqueNo, ex.Message); + //_logger.LogError(ex, "心跳设备失败:{no}. {message}", device.UniqueNo, ex.Message); } } } From 64fbe4737d007b33ec701791bfd813ce3025375a Mon Sep 17 00:00:00 2001 From: liguoyang Date: Wed, 6 Mar 2024 19:30:47 +0800 Subject: [PATCH 123/146] =?UTF-8?q?fix=20AbleSetNext=E5=80=BC=E6=98=A0?= =?UTF-8?q?=E5=B0=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Basic/Device/Response/DeviceGroupTreeResponse.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Src/Dlhis.Basic/Device/Response/DeviceGroupTreeResponse.cs b/Src/Dlhis.Basic/Device/Response/DeviceGroupTreeResponse.cs index a1e7456a..b1b919d9 100644 --- a/Src/Dlhis.Basic/Device/Response/DeviceGroupTreeResponse.cs +++ b/Src/Dlhis.Basic/Device/Response/DeviceGroupTreeResponse.cs @@ -1,6 +1,5 @@ using Dlhis.Entity.Device.Enums; using Kurisu.AspNetCore.Utils.Extensions; -using Microsoft.AspNetCore.Server.IISIntegration; using Newtonsoft.Json; namespace Dlhis.Basic.Device.Response; @@ -53,12 +52,10 @@ public class DeviceGroupTreeResponse public bool Editable { get; set; } - public bool IsDefault { get; set; } - /// /// 是否允许设置下级 /// - public bool AbleSetNext => IsDefault; + public bool AbleSetNext { get; set; } [JsonIgnore] public string TenantId { get; set; } From 21b7ec64b21ea26f8ff08cf3087d24cc731762c3 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Wed, 6 Mar 2024 19:39:14 +0800 Subject: [PATCH 124/146] =?UTF-8?q?fix=20=E9=BB=98=E8=AE=A4=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Entity/Basic/Entity/GainfoGroupEntity.cs | 8 ++++---- Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Src/Dlhis.Entity/Basic/Entity/GainfoGroupEntity.cs b/Src/Dlhis.Entity/Basic/Entity/GainfoGroupEntity.cs index 84c1bbf1..809c8727 100644 --- a/Src/Dlhis.Entity/Basic/Entity/GainfoGroupEntity.cs +++ b/Src/Dlhis.Entity/Basic/Entity/GainfoGroupEntity.cs @@ -36,14 +36,14 @@ public class GainfoGroupEntity : SugarBaseEntity, ITenantId /// /// 是否默认分组 /// - [SugarColumn(ColumnDescription = "是否默认分组", ColumnDataType = "bit")] - public bool IsDefault { get; set; } + [SugarColumn(ColumnDescription = "是否默认分组", ColumnDataType = "bit", DefaultValue = "1")] + public bool IsDefault { get; set; } = true; /// /// 是否可编辑 /// - [SugarColumn(ColumnDescription = "是否可编辑", ColumnDataType = "bit")] - public bool Editable { get; set; } + [SugarColumn(ColumnDescription = "是否可编辑", ColumnDataType = "bit", DefaultValue = "1")] + public bool Editable { get; set; } = true; public string TenantId { get; set; } diff --git a/Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs b/Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs index a56c8c97..c37a5228 100644 --- a/Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs +++ b/Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs @@ -41,13 +41,13 @@ public class DeviceGroupEntity : SugarBaseEntity, ITenantId, ISoftDeleted /// 是否可编辑 /// [SugarColumn(ColumnDataType = "bit", DefaultValue = "1", ColumnDescription = "是否可编辑")] - public bool Editable { get; set; } + public bool Editable { get; set; } = = true; /// /// 可设置下级 /// [SugarColumn(ColumnDataType = "bit", DefaultValue = "1")] - public bool AbleSetNext { get; set; } + public bool AbleSetNext { get; set; } = true; /// /// 备注 From 2e6602737a246a4eba3eb443041499ef91f83d79 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Wed, 6 Mar 2024 19:42:35 +0800 Subject: [PATCH 125/146] fix tenantId --- .../Device/Services/Implements/DeviceGroupService.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs index 3bef9e57..dfd02f8a 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs @@ -49,6 +49,7 @@ public class DeviceGroupService : IDeviceGroupService { var entity = request.Adapt(); entity.Code = Guid.NewGuid(); + entity.TenantId = _currentUser.GetStringTenantId(); await _dbContext.InsertAsync(entity); } @@ -89,7 +90,7 @@ public class DeviceGroupService : IDeviceGroupService public async Task AssignDevicesAsync(DeviceAssignRequest request) { var group = await _dbContext.Queryable().Where(x => x.Code == request.GroupCode).FirstAsync(); - group.ThrowIfNull("设备组不存在"); + group.ThrowIfNull("设备组不存在,无法进行分配"); await CheckNoNextGroupAsync(group.Code); await CheckGroupTypeMatchAsync(request, group); @@ -133,17 +134,15 @@ public class DeviceGroupService : IDeviceGroupService /// private async Task CheckPCodeAsync(DeviceGroupSaveRequest request) { - var pGrp = await _dbContext.Queryable().Where(x => x.Code == request.PCode).FirstAsync(); if (pGrp != null) { (!pGrp.AbleSetNext && !request.Id.HasValue).ThrowIfTrue($"{pGrp.Name}不可添加下级"); var exists = await _dbContext.Queryable().Where(x => x.GroupCode == request.PCode).AnyAsync(); - exists.ThrowIfTrue("父级分组存在设备"); + exists.ThrowIfTrue("上级分组存在设备"); } - (pGrp != null && pGrp.Type != request.Type).ThrowIfTrue("分组类型必须与上级类型保持一致"); - + (pGrp != null && pGrp.Type != request.Type).ThrowIfTrue("分组类型必须与上级类型保持一致"); return pGrp; } From 107b5b970f390efcf47f049abac2dcf301b1d90b Mon Sep 17 00:00:00 2001 From: liguoyang Date: Wed, 6 Mar 2024 19:43:43 +0800 Subject: [PATCH 126/146] =?UTF-8?q?fix=20=E7=BC=96=E8=AF=91=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs b/Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs index c37a5228..0d22dc00 100644 --- a/Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs +++ b/Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs @@ -41,7 +41,7 @@ public class DeviceGroupEntity : SugarBaseEntity, ITenantId, ISoftDeleted /// 是否可编辑 /// [SugarColumn(ColumnDataType = "bit", DefaultValue = "1", ColumnDescription = "是否可编辑")] - public bool Editable { get; set; } = = true; + public bool Editable { get; set; } = true; /// /// 可设置下级 From 83a2bcd02a308b4da5a48bc61805f5406cb77546 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Wed, 6 Mar 2024 20:37:55 +0800 Subject: [PATCH 127/146] =?UTF-8?q?fix=20=E8=AE=BE=E5=A4=87=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E4=B8=8B=E5=8F=91=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Device/Dtos/UserTenantDeviceCodeDto.cs | 14 + .../Implements/DevicePermissionService.cs | 308 +++++++++++++----- 2 files changed, 237 insertions(+), 85 deletions(-) create mode 100644 Src/Dlhis.Basic/Device/Dtos/UserTenantDeviceCodeDto.cs diff --git a/Src/Dlhis.Basic/Device/Dtos/UserTenantDeviceCodeDto.cs b/Src/Dlhis.Basic/Device/Dtos/UserTenantDeviceCodeDto.cs new file mode 100644 index 00000000..1d1b3b82 --- /dev/null +++ b/Src/Dlhis.Basic/Device/Dtos/UserTenantDeviceCodeDto.cs @@ -0,0 +1,14 @@ +namespace Dlhis.Basic.Device.Dtos; + +public class UserTenantDeviceCodeDto +{ + /// + /// 租户 + /// + public string Tenant { get; set; } + + /// + /// 设备权限 + /// + public List Codes { get; set; } +} diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs index 18519961..c0285bb3 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs @@ -1,4 +1,4 @@ -using System.Diagnostics; +using Dlhis.Basic.Device.Dtos; using Dlhis.Basic.Device.Request; using Dlhis.Basic.Device.Response; using Dlhis.Entity.Basic.Entity; @@ -8,7 +8,7 @@ using Dlhis.Entity.Sys.Entities; using Dlhis.Entity.Sys.Enums; using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.DataAccess.Dto; -using Kurisu.Core.User.Abstractions; +using Kurisu.Core.DataAccess.Entity; using Kurisu.SqlSugar.Services; namespace Dlhis.Basic.Device.Services.Implements; @@ -16,18 +16,17 @@ namespace Dlhis.Basic.Device.Services.Implements; public class DevicePermissionService : IDevicePermissionService { private readonly IDbContext _dbContext; - private readonly ICurrentUser _currentUser; - public DevicePermissionService(IDbContext dbContext, ICurrentUser currentUser) + public DevicePermissionService(IDbContext dbContext) { _dbContext = dbContext; - _currentUser = currentUser; } public async Task AssignAsync(DevicePermissionSaveReuqest reuqest) { await GenerateDeviceTasksAsync(async () => { + //删除当前匹配的基地权限 var p = await _dbContext.Queryable() .Where(x => x.AssignType == reuqest.AssignType) .Where(x => x.AssignValue == reuqest.AssignValue) @@ -36,17 +35,20 @@ public class DevicePermissionService : IDevicePermissionService await _dbContext.DeleteReallyAsync(p); - var devicePermissions = reuqest.Codes.Select(grpOrDeviceCode => new DevicePermissionEntity + //保存配置的权限 + if (reuqest.Codes.IsPresent()) { - AssignType = reuqest.AssignType, - AssignValue = reuqest.AssignValue, - UniqueType = reuqest.UniqueType, - UniqueValue = grpOrDeviceCode, + var devicePermissions = reuqest.Codes.Select(code => new DevicePermissionEntity + { + AssignType = reuqest.AssignType, + AssignValue = reuqest.AssignValue, + UniqueType = reuqest.UniqueType, + UniqueValue = code, - }).ToList(); + }).ToList(); - if (devicePermissions.Any()) await _dbContext.InsertAsync(devicePermissions); + } }, null); } @@ -62,86 +64,93 @@ public class DevicePermissionService : IDevicePermissionService public async Task GenerateDeviceTasksAsync(Func func, List userNos) { - //var redisKey = "devicePermissions:" + _currentUser.GetStringTenantId(); - - //获取当前所有人的权限 - if (userNos.IsEmpty()) - userNos = await GetPermissionUserNosAsync(); - - var beforeDic = await GetAssignDeviceCodesInternalAsync(userNos); // new Dictionary>(); - //if (await _redisCache.KeyExistsAsync(redisKey)) - //{ - // var cache = await _redisCache.StringGetAsync>>(redisKey); - // if (cache?.Any() == true) - // { - // beforeDic = cache; - // } - //} - //else - //{ - // beforeDic = await GetAssignDeviceCodesInternalAsync(userNos); - //} - - //业务处理 - await func(); - - //获取业务处理后所有人的权限 - var nextUserNos = await GetPermissionUserNosAsync(); - if (nextUserNos.Any()) - userNos = userNos.Concat(nextUserNos).Distinct().ToList(); - - var currentDic = await GetAssignDeviceCodesInternalAsync(userNos); - - var deivces = await _dbContext.Queryable().ToListAsync(); - var waitTasks = new List(); - foreach (var userNo in userNos) + _dbContext.Client.QueryFilter.ClearAndBackup(); + try { - beforeDic.TryGetValue(userNo, out var beforeCodes); - beforeCodes ??= new List(); + //获取所有人的权限 + if (userNos.IsEmpty()) + userNos = await GetPermissionUserNosAsync(); - currentDic.TryGetValue(userNo, out var currentCodes); - currentCodes ??= new List(); + //var before = await GetAssignDeviceCodesInternalAsync(userNos); + var before = await GetAssignDeviceCodesInternal1Async(userNos); - //被删除 - var deletedItems = beforeCodes.Where(x => !currentCodes.Contains(x)).ToList(); - //新增 - var addItems = currentCodes.Where(x => !beforeCodes.Contains(x)).ToList(); + _dbContext.Client.QueryFilter.Restore(); + //业务处理 + await func(); + _dbContext.Client.QueryFilter.ClearAndBackup(); - if (!deletedItems.Any() && !addItems.Any()) + //获取业务处理后所有人的权限 + var nextUserNos = await GetPermissionUserNosAsync(); + if (nextUserNos.Any()) + userNos = userNos.Concat(nextUserNos).Distinct().ToList(); + + //var current = await GetAssignDeviceCodesInternalAsync(userNos); + var current = await GetAssignDeviceCodesInternal1Async(userNos); + + var deivces = await _dbContext.Queryable().ToListAsync(); + var waitTasks = new List(); + + foreach (var userNo in userNos) { - continue; + before.TryGetValue(userNo, out var beforeTenantDeviceCodes); + beforeTenantDeviceCodes ??= new(); + + current.TryGetValue(userNo, out var currentTenantDeviceCodes); + currentTenantDeviceCodes ??= new(); + + foreach (var item in currentTenantDeviceCodes) + { + var currentCodes = item.Codes; + var beforeCodes = beforeTenantDeviceCodes.FirstOrDefault(x => x.Tenant == item.Tenant)?.Codes ?? new(); + + //被删除 + var deletedItems = beforeCodes.Where(x => !currentCodes.Contains(x)).ToList(); + //新增 + var addItems = currentCodes.Where(x => !beforeCodes.Contains(x)).ToList(); + + if (!deletedItems.Any() && !addItems.Any()) + { + continue; + } + + var deviceCodes = deivces.Where(x => deletedItems.Contains(x.Code) || addItems.Contains(x.Code)).Select(x => x.Code).ToList(); + deletedItems = deletedItems.Where(x => deviceCodes.Contains(x)).ToList(); + addItems = addItems.Where(x => deviceCodes.Contains(x)).ToList(); + + //下发任务创建 + var toDeleted = deletedItems.Select(x => new DeviceTaskEntity + { + DeviceUniqueNo = deivces.First(item => item.Code == x).UniqueNo, + Status = DeviceTaskStatusEnumType.Wait, + Type = DeviceTaskEnumType.Delete, + UserNo = userNo, + Version = 0, + TenantId = item.Tenant, + }).ToList(); + + var toAdd = addItems.Select(x => new DeviceTaskEntity + { + DeviceUniqueNo = deivces.First(item => item.Code == x).UniqueNo, + Status = DeviceTaskStatusEnumType.Wait, + Type = DeviceTaskEnumType.Add, + UserNo = userNo, + Version = 0, + TenantId = item.Tenant, + }).ToList(); + + waitTasks.AddRange(toDeleted.Concat(toAdd).ToList()); + } } - var deviceCodes = deivces.Where(x => deletedItems.Contains(x.Code) || addItems.Contains(x.Code)).Select(x => x.Code).ToList(); - deletedItems = deletedItems.Where(x => deviceCodes.Contains(x)).ToList(); - addItems = addItems.Where(x => deviceCodes.Contains(x)).ToList(); - //下发任务创建 - var toDeleted = deletedItems.Select(x => new DeviceTaskEntity + if (waitTasks.Any()) { - DeviceUniqueNo = deivces.First(item => item.Code == x).UniqueNo, - Status = DeviceTaskStatusEnumType.Wait, - Type = DeviceTaskEnumType.Delete, - UserNo = userNo, - Version = 0, - }).ToList(); - - var toAdd = addItems.Select(x => new DeviceTaskEntity - { - DeviceUniqueNo = deivces.First(item => item.Code == x).UniqueNo, - Status = DeviceTaskStatusEnumType.Wait, - Type = DeviceTaskEnumType.Add, - UserNo = userNo, - Version = 0, - }).ToList(); - - waitTasks.AddRange(toDeleted.Concat(toAdd).ToList()); + await _dbContext.InsertAsync(waitTasks); + } } - - if (waitTasks.Any()) + finally { - //await _redisCache.StringSetAsync(redisKey, JsonConvert.SerializeObject(currentDic)); - await _dbContext.InsertAsync(waitTasks); + _dbContext.Client.QueryFilter.Restore(); } } @@ -248,6 +257,62 @@ public class DevicePermissionService : IDevicePermissionService return deviceCodes.Distinct().ToList(); } + public List GetAssignDeviceCodesInternal1(GainfoEntity gainfo, + List gainfoGroupRelationships, + List devicePermissions, + List deviceGroups, + List deviceGroupRelationships) + { + var userNo = gainfo.No; + var deviceCodes = new List(); + var deviceGroupCodes = new List(); + + //获取人员的分组,跨基地 + var gainfoGroups = gainfoGroupRelationships.Where(x => x.UserNo == userNo).Select(x => x.GroupCode).ToList(); + + //按User获取权限 + var du = GetAssignCodesInternal1(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.User, userNo); + var gu = GetAssignCodesInternal1(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.User, userNo); + deviceCodes.AddRange(du); + deviceGroupCodes.AddRange(gu); + + foreach (var groupCode in gainfoGroups) + { + var dg = GetAssignCodesInternal1(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Group, groupCode.ToString()); + var gg = GetAssignCodesInternal1(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Group, groupCode.ToString()); + deviceCodes.AddRange(dg); + deviceGroupCodes.AddRange(gg); + } + + var dd = GetAssignCodesInternal1(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Department, gainfo.DepartmentNo); + var gd = GetAssignCodesInternal1(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Department, gainfo.DepartmentNo); + deviceCodes.AddRange(dd); + deviceGroupCodes.AddRange(gd); + + var dt = GetAssignCodesInternal1(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Tenant, gainfo.Factory); + var gt = GetAssignCodesInternal1(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Tenant, gainfo.Factory); + deviceCodes.AddRange(du); + deviceGroupCodes.AddRange(gu); + + var groupCodes = deviceGroupCodes.SelectMany(x => x.Codes).Distinct().ToList(); + var deveiceCodesByGroup = deviceGroupRelationships.Where(x => groupCodes.Contains(x.GroupCode)).GroupBy(x => x.TenantId) + .Select(x => new UserTenantDeviceCodeDto + { + Tenant = x.Key, + Codes = x.Select(item => item.DeviceCode).Distinct().ToList() + }); + + deviceCodes.AddRange(deveiceCodesByGroup); + + return deviceCodes.GroupBy(x => x.Tenant).Select(x => new UserTenantDeviceCodeDto + { + Tenant = x.Key, + Codes = x.SelectMany(item => item.Codes).Distinct().ToList() + + }).ToList(); + } + + /// @@ -365,17 +430,65 @@ public class DevicePermissionService : IDevicePermissionService } } + private static List GetAssignCodesInternal1( + List devicePermissions, List deviceGroups, + DeviceAssignmentTypeEnumType uniqueType, AssignTypeEnumType assignType, string assignValue) + { + var tenantDevicePermissions = devicePermissions + .Where(x => x.UniqueType == uniqueType) + .Where(x => x.AssignType == assignType) + .Where(x => x.AssignValue == assignValue) + .GroupBy(x => x.TenantId) + .Select(x => new UserTenantDeviceCodeDto { Tenant = x.Key, Codes = x.Select(x => x.UniqueValue).ToList() }) + .ToList(); + + //处理获取设备分组的情况 + if (uniqueType == DeviceAssignmentTypeEnumType.Group) + { + //开始递归处理 + var tops = deviceGroups.Where(x => !x.PCode.HasValue).ToList(); + tops.ForEach(x => + { + RecursionGetNext(x, deviceGroups, tenantDevicePermissions, tenantDevicePermissions.SelectMany(x => x.Codes).Contains(x.Code)); + }); + } + + return tenantDevicePermissions.GroupBy(x => x.Tenant).Select(x => + { + var tenant = x.Key; + + return new UserTenantDeviceCodeDto + { + Tenant = tenant, + Codes = x.SelectMany(item => item.Codes).ToList() + }; + }) + .Where(x => x.Tenant.IsPresent()).ToList(); + + void RecursionGetNext(DeviceGroupEntity current, List deviceGroups, List result, bool add) + { + var next = deviceGroups.Where(x => x.PCode == current.Code).ToList(); + foreach (var item in next) + { + if (add && item.TenantId.IsPresent()) + { + result.Add(new UserTenantDeviceCodeDto { Tenant = item.TenantId, Codes = new List { item.Code } }); + } + RecursionGetNext(item, deviceGroups, result, result.SelectMany(x => x.Codes).Contains(item.Code)); + } + } + } + private async Task>> GetAssignDeviceCodesInternalAsync(List userNos) { - var sw = Stopwatch.StartNew(); var gainfos = await _dbContext.Queryable().Where(x => userNos.Contains(x.No)).ToListAsync(); if (!gainfos.Any()) { - return new Dictionary>(0); + return new Dictionary>(); } - var gainfoGroupRelationships = await _dbContext.Queryable().ToListAsync(); + var gainfoGroupRelationships = await _dbContext.Queryable().Where(x => userNos.Contains(x.UserNo)).ToListAsync(); var devicePermissions = await _dbContext.Queryable().ToListAsync(); var deviceGroups = await _dbContext.Queryable().ToListAsync(); var deviceRelationships = await _dbContext.Queryable().ToListAsync(); @@ -390,7 +503,32 @@ public class DevicePermissionService : IDevicePermissionService result.Add(userNo, codes); } - await Console.Out.WriteLineAsync($"获取所有人员权限耗时:{sw.ElapsedMilliseconds}"); return result; } + + private async Task>> GetAssignDeviceCodesInternal1Async(List userNos) + { + var gainfos = await _dbContext.Queryable().Where(x => userNos.Contains(x.No)).ToListAsync(); + if (!gainfos.Any()) + { + return new Dictionary>(); + } + + var gainfoGroupRelationships = await _dbContext.Queryable().Where(x => userNos.Contains(x.UserNo)).ToListAsync(); + var devicePermissions = await _dbContext.Queryable().ToListAsync(); + var deviceGroups = await _dbContext.Queryable().ToListAsync(); + var deviceRelationships = await _dbContext.Queryable().ToListAsync(); + + var result = new Dictionary>(gainfos.Count); + + foreach (var gainfo in gainfos) + { + var codes = GetAssignDeviceCodesInternal1(gainfo, gainfoGroupRelationships, devicePermissions, deviceGroups, deviceRelationships); + result.Add(gainfo.No, codes); + } + + return result; + } + + } From b6f02b433bd40c64d1637e013ef797cdfdb799ef Mon Sep 17 00:00:00 2001 From: liguoyang Date: Wed, 6 Mar 2024 20:55:20 +0800 Subject: [PATCH 128/146] =?UTF-8?q?fix=20=E6=A1=A3=E6=A1=88=E7=BB=84?= =?UTF-8?q?=E5=88=86=E9=85=8D=E4=BA=BA=E5=91=98=E8=A7=A6=E5=8F=91=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E4=B8=8B=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Implements/GainfoGroupService.cs | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs index 55df243d..fceb4425 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs @@ -1,4 +1,5 @@ -using Dlhis.Basic.Organization.Request; +using Dlhis.Basic.Device.Services; +using Dlhis.Basic.Organization.Request; using Dlhis.Basic.Organization.Response; using Dlhis.Entity.Basic.Entity; using Kurisu.AspNetCore.Utils.Extensions; @@ -13,11 +14,13 @@ public class GainfoGroupService : IGainfoGroupService { private readonly IDbContext _dbContext; private readonly ICurrentUser _currentUser; + private readonly IDevicePermissionService _devicePermissionService; - public GainfoGroupService(IDbContext dbContext, ICurrentUser currentUser) + public GainfoGroupService(IDbContext dbContext, ICurrentUser currentUser, IDevicePermissionService devicePermissionService) { _dbContext = dbContext; _currentUser = currentUser; + _devicePermissionService = devicePermissionService; } public async Task> GetTreeAsync() @@ -86,21 +89,25 @@ public class GainfoGroupService : IGainfoGroupService public async Task AssignGainfosAsync(GainfoAssignRequest request) { - var existsNextGroup = await _dbContext.Queryable().Where(x => x.PCode == request.GroupCode).AnyAsync(); - existsNextGroup.ThrowIfTrue("存在下级分组,无法分配人员"); + await _devicePermissionService.GenerateDeviceTasksAsync(async ()=> + { + var existsNextGroup = await _dbContext.Queryable().Where(x => x.PCode == request.GroupCode).AnyAsync(); + existsNextGroup.ThrowIfTrue("存在下级分组,无法分配人员"); - var relations = await _dbContext.Queryable().Where(x => x.GroupCode == request.GroupCode).ToListAsync(); - await _dbContext.DeleteReallyAsync(relations); + var relations = await _dbContext.Queryable().Where(x => x.GroupCode == request.GroupCode).ToListAsync(); + await _dbContext.DeleteReallyAsync(relations); - request.UserNos = await _dbContext.Queryable().Where(x => request.UserNos.Contains(x.No)).Select(x => x.No).ToListAsync(); - var entities = request.UserNos.Select(x => new GainfoGroupRelationshipEntity - { - GroupCode = request.GroupCode, - UserNo = x + request.UserNos = await _dbContext.Queryable().Where(x => request.UserNos.Contains(x.No)).Select(x => x.No).ToListAsync(); + var entities = request.UserNos.Select(x => new GainfoGroupRelationshipEntity + { + GroupCode = request.GroupCode, + UserNo = x - }).ToList(); + }).ToList(); - await _dbContext.InsertAsync(entities); + await _dbContext.InsertAsync(entities); + + }, null); } //******************************************************* help methods *********************************************************** From d3e0581963b54d7cf8e7b87119e309b05258bb96 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Wed, 6 Mar 2024 21:30:31 +0800 Subject: [PATCH 129/146] =?UTF-8?q?fix=20=E5=A2=9E=E5=8A=A0=E6=A1=A3?= =?UTF-8?q?=E6=A1=88=E7=BB=84=E5=88=86=E9=85=8D=E6=A3=80=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Organization/Services/Implements/GainfoGroupService.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs index fceb4425..4bf17d67 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs @@ -89,8 +89,11 @@ public class GainfoGroupService : IGainfoGroupService public async Task AssignGainfosAsync(GainfoAssignRequest request) { - await _devicePermissionService.GenerateDeviceTasksAsync(async ()=> + await _devicePermissionService.GenerateDeviceTasksAsync(async () => { + var pGrp = await _dbContext.Queryable().Where(x => x.Code == request.GroupCode).FirstAsync(); + pGrp?.Editable.ThrowIfFalse("不可分配人员到当前分组"); + var existsNextGroup = await _dbContext.Queryable().Where(x => x.PCode == request.GroupCode).AnyAsync(); existsNextGroup.ThrowIfTrue("存在下级分组,无法分配人员"); From 14c63ead736861b2e5df16ece47b4f510280b9e4 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Wed, 6 Mar 2024 21:40:34 +0800 Subject: [PATCH 130/146] =?UTF-8?q?fix=20=E4=BC=98=E5=8C=96=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Device/Controllers/DeviceGroupsController.cs | 1 + .../Services/Implements/DeviceGroupService.cs | 4 ++-- .../Controllers/GainfoGroupsController.cs | 2 ++ .../Services/Implements/GainfoGroupService.cs | 14 +++++++------- .../Entities/DeviceGroupRelationshipEntity.cs | 5 +---- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Src/Dlhis.Basic/Device/Controllers/DeviceGroupsController.cs b/Src/Dlhis.Basic/Device/Controllers/DeviceGroupsController.cs index 723635c4..b3b849cd 100644 --- a/Src/Dlhis.Basic/Device/Controllers/DeviceGroupsController.cs +++ b/Src/Dlhis.Basic/Device/Controllers/DeviceGroupsController.cs @@ -66,6 +66,7 @@ public class DeviceGroupsController : ControllerBase /// /// [HttpPost("assign")] + [IgnoreTenant] [Transactional] public async Task AssignDevicesAsync(DeviceAssignRequest request) { diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs index dfd02f8a..a6ed9c39 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs @@ -90,7 +90,7 @@ public class DeviceGroupService : IDeviceGroupService public async Task AssignDevicesAsync(DeviceAssignRequest request) { var group = await _dbContext.Queryable().Where(x => x.Code == request.GroupCode).FirstAsync(); - group.ThrowIfNull("设备组不存在,无法进行分配"); + group.ThrowIfNull("设备分组不存在,无法进行分配"); await CheckNoNextGroupAsync(group.Code); await CheckGroupTypeMatchAsync(request, group); @@ -99,7 +99,7 @@ public class DeviceGroupService : IDeviceGroupService await _devicePermissionService.GenerateDeviceTasksAsync(async () => { var relationships = await _dbContext.Queryable().Where(x => x.GroupCode == request.GroupCode).ToListAsync(); - await _dbContext.DeleteAsync(relationships); + await _dbContext.DeleteReallyAsync(relationships); var entities = request.DeviceCodes.Select(x => new DeviceGroupRelationshipEntity { diff --git a/Src/Dlhis.Basic/Organization/Controllers/GainfoGroupsController.cs b/Src/Dlhis.Basic/Organization/Controllers/GainfoGroupsController.cs index ca2225a9..8fc33da5 100644 --- a/Src/Dlhis.Basic/Organization/Controllers/GainfoGroupsController.cs +++ b/Src/Dlhis.Basic/Organization/Controllers/GainfoGroupsController.cs @@ -63,6 +63,8 @@ public class GainfoGroupsController : ControllerBase /// /// [HttpPost("assign")] + [IgnoreTenant] + [Transactional] public async Task AssignGainfosAsync(GainfoAssignRequest request) { await _gainfoGroupService.AssignGainfosAsync(request); diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs index 4bf17d67..5f0c3267 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs @@ -89,14 +89,14 @@ public class GainfoGroupService : IGainfoGroupService public async Task AssignGainfosAsync(GainfoAssignRequest request) { + var pGrp = await _dbContext.Queryable().Where(x => x.Code == request.GroupCode).FirstAsync(); + pGrp?.Editable.ThrowIfFalse("不可分配人员到当前分组"); + + var existsNextGroup = await _dbContext.Queryable().Where(x => x.PCode == request.GroupCode).AnyAsync(); + existsNextGroup.ThrowIfTrue("存在下级分组,无法分配人员"); + await _devicePermissionService.GenerateDeviceTasksAsync(async () => - { - var pGrp = await _dbContext.Queryable().Where(x => x.Code == request.GroupCode).FirstAsync(); - pGrp?.Editable.ThrowIfFalse("不可分配人员到当前分组"); - - var existsNextGroup = await _dbContext.Queryable().Where(x => x.PCode == request.GroupCode).AnyAsync(); - existsNextGroup.ThrowIfTrue("存在下级分组,无法分配人员"); - + { var relations = await _dbContext.Queryable().Where(x => x.GroupCode == request.GroupCode).ToListAsync(); await _dbContext.DeleteReallyAsync(relations); diff --git a/Src/Dlhis.Entity/Device/Entities/DeviceGroupRelationshipEntity.cs b/Src/Dlhis.Entity/Device/Entities/DeviceGroupRelationshipEntity.cs index 352c55c4..d3d79fe0 100644 --- a/Src/Dlhis.Entity/Device/Entities/DeviceGroupRelationshipEntity.cs +++ b/Src/Dlhis.Entity/Device/Entities/DeviceGroupRelationshipEntity.cs @@ -8,7 +8,7 @@ namespace Dlhis.Entity.Device.Entities; /// 设备组/设备关系 /// [SugarTable(TableName = "DeviceGroupRelationship", TableDescription = "设备组/设备关系")] -public class DeviceGroupRelationshipEntity : SugarBaseEntity, ITenantId, ISoftDeleted +public class DeviceGroupRelationshipEntity : SugarBaseEntity, ITenantId { /// /// 设备组code @@ -22,8 +22,5 @@ public class DeviceGroupRelationshipEntity : SugarBaseEntity, ITenantId, ISoftDe [SugarColumn(ColumnDescription = "设备code")] public Guid DeviceCode { get; set; } - public string TenantId { get; set; } - - public bool IsDeleted { get; set; } } \ No newline at end of file From c0f1b15b105b3a373d548647301264e2b98e3ae4 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Wed, 6 Mar 2024 21:57:16 +0800 Subject: [PATCH 131/146] =?UTF-8?q?fix=20=E8=AE=BE=E5=A4=87=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E7=A7=BB=E9=99=A4tenantId?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Entity/Basic/Entity/DeviceTemplateEntity.cs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/Src/Dlhis.Entity/Basic/Entity/DeviceTemplateEntity.cs b/Src/Dlhis.Entity/Basic/Entity/DeviceTemplateEntity.cs index 8ea2e16b..84cf035b 100644 --- a/Src/Dlhis.Entity/Basic/Entity/DeviceTemplateEntity.cs +++ b/Src/Dlhis.Entity/Basic/Entity/DeviceTemplateEntity.cs @@ -1,6 +1,4 @@ -using System; -using Kurisu.Core.DataAccess.Entity; -using Kurisu.SqlSugar; +using Kurisu.SqlSugar; using SqlSugar; namespace Dlhis.Entity.Basic.Entity; @@ -9,7 +7,7 @@ namespace Dlhis.Entity.Basic.Entity; /// 设备配置模板 /// [SugarTable(TableName = "DeviceTemplate", TableDescription = "设备配置模板")] -public class DeviceTemplateEntity : SugarBaseEntity, ITenantId +public class DeviceTemplateEntity : SugarBaseEntity { /// /// 模板code @@ -34,7 +32,4 @@ public class DeviceTemplateEntity : SugarBaseEntity, ITenantId /// [SugarColumn(ColumnDescription = "模板json")] public string Template { get; set; } - - - public string TenantId { get; set; } } \ No newline at end of file From 28390abaa591a4d2782bdcbe740e9c1a8e12b7c0 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Wed, 6 Mar 2024 22:19:05 +0800 Subject: [PATCH 132/146] =?UTF-8?q?fix=20tenantId=E6=89=8B=E5=8A=A8?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Device/Services/Implements/DeviceGroupService.cs | 4 +++- .../Organization/Services/Implements/GainfoGroupService.cs | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs index a6ed9c39..3c8797d6 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs @@ -104,7 +104,9 @@ public class DeviceGroupService : IDeviceGroupService var entities = request.DeviceCodes.Select(x => new DeviceGroupRelationshipEntity { GroupCode = request.GroupCode, - DeviceCode = x + DeviceCode = x, + + TenantId = _currentUser.GetStringTenantId(), }).ToList(); diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs index 5f0c3267..14092a2c 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs @@ -104,7 +104,8 @@ public class GainfoGroupService : IGainfoGroupService var entities = request.UserNos.Select(x => new GainfoGroupRelationshipEntity { GroupCode = request.GroupCode, - UserNo = x + UserNo = x, + }).ToList(); From 04f20e7cf2a3a4160586e08846a3ecb880fa1c21 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Wed, 6 Mar 2024 22:36:02 +0800 Subject: [PATCH 133/146] =?UTF-8?q?fix=20=E5=94=AF=E4=B8=80=E5=8F=B7?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Basic/Device/Request/DeviceSaveRequest.cs | 5 +++++ Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs | 1 - Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs | 1 - 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Src/Dlhis.Basic/Device/Request/DeviceSaveRequest.cs b/Src/Dlhis.Basic/Device/Request/DeviceSaveRequest.cs index f7e4a84c..1308a9a2 100644 --- a/Src/Dlhis.Basic/Device/Request/DeviceSaveRequest.cs +++ b/Src/Dlhis.Basic/Device/Request/DeviceSaveRequest.cs @@ -78,6 +78,11 @@ public class DeviceSaveRequest : IValidatableObject public IEnumerable Validate(ValidationContext validationContext) { + if (Id.HasValue) + { + UniqueNo = null; + } + if (Type != DeviceTypeEnumType.Door && AsAttendance) { yield return new ValidationResult($"{DeviceTypeEnumType.Door.GetDescription()}才可设置作为考勤设备", new[] { nameof(AsAttendance) }); diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs index 42fac162..f43f3c7a 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs @@ -111,7 +111,6 @@ public class DeviceService : IDeviceService var existsG = await _dbContext.Queryable() .LeftJoin((dgr, dg) => dgr.GroupCode == dg.Code) .Where((dgr, dg) => dgr.DeviceCode == entity.Code) - .Where((dgr, dg) => dg.Type != null) .AnyAsync(); existsG.ThrowIfTrue("存在设备分组,不可修改设备分类"); diff --git a/Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs b/Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs index 5804a32d..6b8f2348 100644 --- a/Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs +++ b/Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs @@ -22,7 +22,6 @@ public class DeviceEntity : SugarBaseEntity, ITenantId /// /// 设备唯一码,IP/MAC/SNO /// - [AdaptIgnore(MemberSide.Destination)] [SugarColumn(ColumnDescription = "设备唯一码", UniqueGroupNameList = new[] { "Idx_Device_UniqueNo" })] public string UniqueNo { get; set; } From 83aa9cb954230b13199c860fc60f8638faec3eb7 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Wed, 6 Mar 2024 22:51:39 +0800 Subject: [PATCH 134/146] =?UTF-8?q?fix=20=E4=BC=98=E5=8C=96=E7=BB=86?= =?UTF-8?q?=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Implements/GainfoGroupService.cs | 31 ++++++++++--------- Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs | 3 +- .../Device/Entities/DeviceTask.cs | 2 +- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs index 14092a2c..077e7887 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs @@ -89,29 +89,32 @@ public class GainfoGroupService : IGainfoGroupService public async Task AssignGainfosAsync(GainfoAssignRequest request) { - var pGrp = await _dbContext.Queryable().Where(x => x.Code == request.GroupCode).FirstAsync(); - pGrp?.Editable.ThrowIfFalse("不可分配人员到当前分组"); - + if (request.UserNos.IsPresent()) + { + var pGrp = await _dbContext.Queryable().Where(x => x.Code == request.GroupCode).FirstAsync(); + pGrp?.Editable.ThrowIfFalse("不可分配人员到当前分组"); + } + var existsNextGroup = await _dbContext.Queryable().Where(x => x.PCode == request.GroupCode).AnyAsync(); existsNextGroup.ThrowIfTrue("存在下级分组,无法分配人员"); await _devicePermissionService.GenerateDeviceTasksAsync(async () => { - var relations = await _dbContext.Queryable().Where(x => x.GroupCode == request.GroupCode).ToListAsync(); - await _dbContext.DeleteReallyAsync(relations); + var relations = await _dbContext.Queryable().Where(x => x.GroupCode == request.GroupCode).ToListAsync(); + await _dbContext.DeleteReallyAsync(relations); - request.UserNos = await _dbContext.Queryable().Where(x => request.UserNos.Contains(x.No)).Select(x => x.No).ToListAsync(); - var entities = request.UserNos.Select(x => new GainfoGroupRelationshipEntity - { - GroupCode = request.GroupCode, - UserNo = x, - + request.UserNos = await _dbContext.Queryable().Where(x => request.UserNos.Contains(x.No)).Select(x => x.No).ToListAsync(); + var entities = request.UserNos.Select(x => new GainfoGroupRelationshipEntity + { + GroupCode = request.GroupCode, + UserNo = x, - }).ToList(); - await _dbContext.InsertAsync(entities); + }).ToList(); - }, null); + await _dbContext.InsertAsync(entities); + + }, null); } //******************************************************* help methods *********************************************************** diff --git a/Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs b/Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs index 6b8f2348..ddedd0ec 100644 --- a/Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs +++ b/Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs @@ -1,7 +1,6 @@ using Dlhis.Entity.Device.Enums; using Kurisu.Core.DataAccess.Entity; using Kurisu.SqlSugar; -using Mapster; using SqlSugar; using SqlSugar.DbConvert; @@ -22,7 +21,7 @@ public class DeviceEntity : SugarBaseEntity, ITenantId /// /// 设备唯一码,IP/MAC/SNO /// - [SugarColumn(ColumnDescription = "设备唯一码", UniqueGroupNameList = new[] { "Idx_Device_UniqueNo" })] + [SugarColumn(ColumnDescription = "设备唯一码", IsNullable = false, UniqueGroupNameList = new[] { "Idx_Device_UniqueNo" })] public string UniqueNo { get; set; } /// diff --git a/Src/Dlhis.Entity/Device/Entities/DeviceTask.cs b/Src/Dlhis.Entity/Device/Entities/DeviceTask.cs index 84708348..f1348681 100644 --- a/Src/Dlhis.Entity/Device/Entities/DeviceTask.cs +++ b/Src/Dlhis.Entity/Device/Entities/DeviceTask.cs @@ -23,10 +23,10 @@ public class DeviceTaskEntity : SugarBaseEntity, ITenantId, IVersion /// public string UserNo { get; set; } - /// /// 设备唯一号 /// + [SugarColumn(IsNullable = false, IndexGroupNameList = new[] { "idx_DeviceTask_DeviceUniqueNo" })] public string DeviceUniqueNo { get; set; } /// From 3416b16e02dec1fcfa96dc282713c5f4f87f4352 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Wed, 6 Mar 2024 23:13:51 +0800 Subject: [PATCH 135/146] =?UTF-8?q?fix=20=E6=A1=A3=E6=A1=88=E7=BB=84?= =?UTF-8?q?=E5=88=86=E9=85=8D=E4=BA=BA=E5=91=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Organization/Services/Implements/GainfoGroupService.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs index 077e7887..3c00eeca 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs @@ -92,9 +92,9 @@ public class GainfoGroupService : IGainfoGroupService if (request.UserNos.IsPresent()) { var pGrp = await _dbContext.Queryable().Where(x => x.Code == request.GroupCode).FirstAsync(); - pGrp?.Editable.ThrowIfFalse("不可分配人员到当前分组"); + (pGrp?.Editable == false && pGrp?.IsDefault == true).ThrowIfTrue("不可分配人员到当前分组"); } - + var existsNextGroup = await _dbContext.Queryable().Where(x => x.PCode == request.GroupCode).AnyAsync(); existsNextGroup.ThrowIfTrue("存在下级分组,无法分配人员"); From 20aa1b08156d9a7255b9930671fe0efe92969f4c Mon Sep 17 00:00:00 2001 From: liguoyang Date: Wed, 6 Mar 2024 23:48:52 +0800 Subject: [PATCH 136/146] =?UTF-8?q?fix=20=E4=BC=98=E5=8C=96=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/DevicePermissionService.cs | 220 ++++++------------ 1 file changed, 77 insertions(+), 143 deletions(-) diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs index c0285bb3..7b0a9f2e 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs @@ -9,6 +9,7 @@ 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; namespace Dlhis.Basic.Device.Services.Implements; @@ -16,10 +17,12 @@ namespace Dlhis.Basic.Device.Services.Implements; public class DevicePermissionService : IDevicePermissionService { private readonly IDbContext _dbContext; + private readonly ICurrentUser _currentUser; - public DevicePermissionService(IDbContext dbContext) + public DevicePermissionService(IDbContext dbContext, ICurrentUser currentUser) { _dbContext = dbContext; + _currentUser = currentUser; } public async Task AssignAsync(DevicePermissionSaveReuqest reuqest) @@ -58,7 +61,8 @@ public class DevicePermissionService : IDevicePermissionService var devicePermissions = await _dbContext.Queryable().ToListAsync(); var deviceGroups = await _dbContext.Queryable().ToListAsync(); - return GetAssignmentsInternal(devicePermissions, deviceGroups, uniqueType, assignType, assignValue); + var result = GetAssignCodesInternal(devicePermissions, deviceGroups, uniqueType, assignType, assignValue); + return result.FirstOrDefault(x => x.Tenant == _currentUser.GetStringTenantId())?.Codes; } @@ -72,7 +76,7 @@ public class DevicePermissionService : IDevicePermissionService userNos = await GetPermissionUserNosAsync(); //var before = await GetAssignDeviceCodesInternalAsync(userNos); - var before = await GetAssignDeviceCodesInternal1Async(userNos); + var before = await GetAssignDeviceCodesInternalAsync(userNos); _dbContext.Client.QueryFilter.Restore(); //业务处理 @@ -85,7 +89,7 @@ public class DevicePermissionService : IDevicePermissionService userNos = userNos.Concat(nextUserNos).Distinct().ToList(); //var current = await GetAssignDeviceCodesInternalAsync(userNos); - var current = await GetAssignDeviceCodesInternal1Async(userNos); + var current = await GetAssignDeviceCodesInternalAsync(userNos); var deivces = await _dbContext.Queryable().ToListAsync(); var waitTasks = new List(); @@ -98,10 +102,12 @@ public class DevicePermissionService : IDevicePermissionService current.TryGetValue(userNo, out var currentTenantDeviceCodes); currentTenantDeviceCodes ??= new(); - foreach (var item in currentTenantDeviceCodes) + var tenants = beforeTenantDeviceCodes.Select(x => x.Tenant).Concat(currentTenantDeviceCodes.Select(x => x.Tenant)).Distinct().ToList(); + + foreach (var tenant in tenants) { - var currentCodes = item.Codes; - var beforeCodes = beforeTenantDeviceCodes.FirstOrDefault(x => x.Tenant == item.Tenant)?.Codes ?? new(); + var currentCodes = currentTenantDeviceCodes.FirstOrDefault(x => x.Tenant == tenant)?.Codes ?? new(); + var beforeCodes = beforeTenantDeviceCodes.FirstOrDefault(x => x.Tenant == tenant)?.Codes ?? new(); //被删除 var deletedItems = beforeCodes.Where(x => !currentCodes.Contains(x)).ToList(); @@ -125,7 +131,7 @@ public class DevicePermissionService : IDevicePermissionService Type = DeviceTaskEnumType.Delete, UserNo = userNo, Version = 0, - TenantId = item.Tenant, + TenantId = tenant, }).ToList(); var toAdd = addItems.Select(x => new DeviceTaskEntity @@ -135,14 +141,13 @@ public class DevicePermissionService : IDevicePermissionService Type = DeviceTaskEnumType.Add, UserNo = userNo, Version = 0, - TenantId = item.Tenant, + TenantId = tenant, }).ToList(); waitTasks.AddRange(toDeleted.Concat(toAdd).ToList()); } } - if (waitTasks.Any()) { await _dbContext.InsertAsync(waitTasks); @@ -212,108 +217,10 @@ public class DevicePermissionService : IDevicePermissionService var deviceGroups = await _dbContext.Queryable().ToListAsync(); var deviceRelationships = await _dbContext.Queryable().ToListAsync(); - return GetAssignDeviceCodesInternal(new List { gainfo }, gainfoGroups, devicePermissions, deviceGroups, deviceRelationships, userNo); + var result = GetAssignDeviceCodesInternal(gainfo, gainfoGroups, devicePermissions, deviceGroups, deviceRelationships); + return result.SelectMany(x => x.Codes).ToList(); } - public List GetAssignDeviceCodesInternal(List gainfos, - List gainfoGroupRelationships, - List devicePermissions, - List deviceGroups, - List deviceGroupRelationships, - string userNo) - { - var deviceCodes = new List(); - var deviceGroupCodes = new List(); - - var gainfo = gainfos.Where(x => x.No == userNo).FirstOrDefault(); - var gainfoGroups = gainfoGroupRelationships.Where(x => x.UserNo == userNo).Select(x => x.GroupCode).ToList(); - - var du = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.User, userNo); - var gu = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.User, userNo); - deviceCodes.AddRange(du); - deviceGroupCodes.AddRange(gu); - - foreach (var group in gainfoGroups) - { - var dg = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Group, group.ToString()); - var gg = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Group, group.ToString()); - deviceCodes.AddRange(dg); - deviceGroupCodes.AddRange(gg); - } - - var dd = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Department, gainfo.DepartmentNo); - var gd = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Department, gainfo.DepartmentNo); - deviceCodes.AddRange(dd); - deviceGroupCodes.AddRange(gd); - - var dt = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Tenant, gainfo.Werks); - var gt = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Tenant, gainfo.Werks); - deviceCodes.AddRange(du); - deviceGroupCodes.AddRange(gu); - - var deveiceCodesByGroup = deviceGroupRelationships.Where(x => deviceGroupCodes.Contains(x.GroupCode)).Select(x => x.DeviceCode).ToList(); - deviceCodes.AddRange(deveiceCodesByGroup); - - return deviceCodes.Distinct().ToList(); - } - - public List GetAssignDeviceCodesInternal1(GainfoEntity gainfo, - List gainfoGroupRelationships, - List devicePermissions, - List deviceGroups, - List deviceGroupRelationships) - { - var userNo = gainfo.No; - var deviceCodes = new List(); - var deviceGroupCodes = new List(); - - //获取人员的分组,跨基地 - var gainfoGroups = gainfoGroupRelationships.Where(x => x.UserNo == userNo).Select(x => x.GroupCode).ToList(); - - //按User获取权限 - var du = GetAssignCodesInternal1(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.User, userNo); - var gu = GetAssignCodesInternal1(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.User, userNo); - deviceCodes.AddRange(du); - deviceGroupCodes.AddRange(gu); - - foreach (var groupCode in gainfoGroups) - { - var dg = GetAssignCodesInternal1(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Group, groupCode.ToString()); - var gg = GetAssignCodesInternal1(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Group, groupCode.ToString()); - deviceCodes.AddRange(dg); - deviceGroupCodes.AddRange(gg); - } - - var dd = GetAssignCodesInternal1(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Department, gainfo.DepartmentNo); - var gd = GetAssignCodesInternal1(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Department, gainfo.DepartmentNo); - deviceCodes.AddRange(dd); - deviceGroupCodes.AddRange(gd); - - var dt = GetAssignCodesInternal1(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Tenant, gainfo.Factory); - var gt = GetAssignCodesInternal1(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Tenant, gainfo.Factory); - deviceCodes.AddRange(du); - deviceGroupCodes.AddRange(gu); - - var groupCodes = deviceGroupCodes.SelectMany(x => x.Codes).Distinct().ToList(); - var deveiceCodesByGroup = deviceGroupRelationships.Where(x => groupCodes.Contains(x.GroupCode)).GroupBy(x => x.TenantId) - .Select(x => new UserTenantDeviceCodeDto - { - Tenant = x.Key, - Codes = x.Select(item => item.DeviceCode).Distinct().ToList() - }); - - deviceCodes.AddRange(deveiceCodesByGroup); - - return deviceCodes.GroupBy(x => x.Tenant).Select(x => new UserTenantDeviceCodeDto - { - Tenant = x.Key, - Codes = x.SelectMany(item => item.Codes).Distinct().ToList() - - }).ToList(); - } - - - /// /// 获取用户权限设备 @@ -430,7 +337,7 @@ public class DevicePermissionService : IDevicePermissionService } } - private static List GetAssignCodesInternal1( + private static List GetAssignCodesInternal( List devicePermissions, List deviceGroups, DeviceAssignmentTypeEnumType uniqueType, AssignTypeEnumType assignType, string assignValue) { @@ -462,15 +369,14 @@ public class DevicePermissionService : IDevicePermissionService Tenant = tenant, Codes = x.SelectMany(item => item.Codes).ToList() }; - }) - .Where(x => x.Tenant.IsPresent()).ToList(); + }).ToList(); void RecursionGetNext(DeviceGroupEntity current, List deviceGroups, List result, bool add) { var next = deviceGroups.Where(x => x.PCode == current.Code).ToList(); foreach (var item in next) { - if (add && item.TenantId.IsPresent()) + if (add) { result.Add(new UserTenantDeviceCodeDto { Tenant = item.TenantId, Codes = new List { item.Code } }); } @@ -479,34 +385,7 @@ public class DevicePermissionService : IDevicePermissionService } } - - private async Task>> GetAssignDeviceCodesInternalAsync(List userNos) - { - var gainfos = await _dbContext.Queryable().Where(x => userNos.Contains(x.No)).ToListAsync(); - if (!gainfos.Any()) - { - return new Dictionary>(); - } - - var gainfoGroupRelationships = await _dbContext.Queryable().Where(x => userNos.Contains(x.UserNo)).ToListAsync(); - var devicePermissions = await _dbContext.Queryable().ToListAsync(); - var deviceGroups = await _dbContext.Queryable().ToListAsync(); - var deviceRelationships = await _dbContext.Queryable().ToListAsync(); - - var result = new Dictionary>(gainfos.Count); - - foreach (var gainfo in gainfos) - { - var userNo = gainfo.No; - var codes = GetAssignDeviceCodesInternal(gainfos, gainfoGroupRelationships, devicePermissions, deviceGroups, deviceRelationships, userNo); - - result.Add(userNo, codes); - } - - return result; - } - - private async Task>> GetAssignDeviceCodesInternal1Async(List userNos) + private async Task>> GetAssignDeviceCodesInternalAsync(List userNos) { var gainfos = await _dbContext.Queryable().Where(x => userNos.Contains(x.No)).ToListAsync(); if (!gainfos.Any()) @@ -523,7 +402,7 @@ public class DevicePermissionService : IDevicePermissionService foreach (var gainfo in gainfos) { - var codes = GetAssignDeviceCodesInternal1(gainfo, gainfoGroupRelationships, devicePermissions, deviceGroups, deviceRelationships); + var codes = GetAssignDeviceCodesInternal(gainfo, gainfoGroupRelationships, devicePermissions, deviceGroups, deviceRelationships); result.Add(gainfo.No, codes); } @@ -531,4 +410,59 @@ public class DevicePermissionService : IDevicePermissionService } + + private static List GetAssignDeviceCodesInternal(GainfoEntity gainfo, + List gainfoGroupRelationships, + List devicePermissions, + List deviceGroups, + List deviceGroupRelationships) + { + var userNo = gainfo.No; + var deviceCodes = new List(); + var deviceGroupCodes = new List(); + + //获取人员的分组,跨基地 + var gainfoGroups = gainfoGroupRelationships.Where(x => x.UserNo == userNo).Select(x => x.GroupCode).ToList(); + + //按User获取权限 + var du = GetAssignCodesInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.User, userNo); + var gu = GetAssignCodesInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.User, userNo); + deviceCodes.AddRange(du); + deviceGroupCodes.AddRange(gu); + + foreach (var groupCode in gainfoGroups) + { + var dg = GetAssignCodesInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Group, groupCode.ToString()); + var gg = GetAssignCodesInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Group, groupCode.ToString()); + deviceCodes.AddRange(dg); + deviceGroupCodes.AddRange(gg); + } + + var dd = GetAssignCodesInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Department, gainfo.DepartmentNo); + var gd = GetAssignCodesInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Department, gainfo.DepartmentNo); + deviceCodes.AddRange(dd); + deviceGroupCodes.AddRange(gd); + + var dt = GetAssignCodesInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Tenant, gainfo.Factory); + var gt = GetAssignCodesInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Tenant, gainfo.Factory); + deviceCodes.AddRange(du); + deviceGroupCodes.AddRange(gu); + + var groupCodes = deviceGroupCodes.SelectMany(x => x.Codes).Distinct().ToList(); + var deveiceCodesByGroup = deviceGroupRelationships.Where(x => groupCodes.Contains(x.GroupCode)).GroupBy(x => x.TenantId) + .Select(x => new UserTenantDeviceCodeDto + { + Tenant = x.Key, + Codes = x.Select(item => item.DeviceCode).Distinct().ToList() + }); + + deviceCodes.AddRange(deveiceCodesByGroup); + + return deviceCodes.GroupBy(x => x.Tenant).Select(x => new UserTenantDeviceCodeDto + { + Tenant = x.Key, + Codes = x.SelectMany(item => item.Codes).Distinct().ToList() + + }).ToList(); + } } From a0505a1a93d9357a6a88dade3ec4cd6bbdaab5f7 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 7 Mar 2024 00:31:27 +0800 Subject: [PATCH 137/146] =?UTF-8?q?fix=20=E6=A0=B9=E6=8D=AE=E6=9D=83?= =?UTF-8?q?=E9=99=90=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Canteen/Dlhis.Canteen.csproj | 3 +- Src/Dlhis.Canteen/Dockerfile | 2 +- .../Order/Controllers/BalancesController.cs | 8 ++++-- .../Order/Response/BalanceRecordResponse.cs | 10 +++++++ .../Services/Implements/BalanceService.cs | 28 +++++++++++++++---- .../Dlhis.ScheduledTask.csproj | 2 +- .../DeviceTaskAssignmentsController.cs | 2 ++ .../Response/DeviceTaskAssignmentResponse.cs | 11 ++++++++ .../Implements/DeviceTaskAssignmentService.cs | 25 +++++++++++++++-- 9 files changed, 78 insertions(+), 13 deletions(-) diff --git a/Src/Dlhis.Canteen/Dlhis.Canteen.csproj b/Src/Dlhis.Canteen/Dlhis.Canteen.csproj index 8ad57920..a17298ed 100644 --- a/Src/Dlhis.Canteen/Dlhis.Canteen.csproj +++ b/Src/Dlhis.Canteen/Dlhis.Canteen.csproj @@ -18,8 +18,8 @@ - + @@ -37,6 +37,7 @@ + diff --git a/Src/Dlhis.Canteen/Dockerfile b/Src/Dlhis.Canteen/Dockerfile index 5e510329..f9585740 100644 --- a/Src/Dlhis.Canteen/Dockerfile +++ b/Src/Dlhis.Canteen/Dockerfile @@ -8,8 +8,8 @@ FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build WORKDIR /src COPY ["Src/Dlhis.Canteen/Dlhis.Canteen.csproj", "Src/Dlhis.Canteen/"] COPY ["Src/Dlhis.Basic.Api/Dlhis.Basic.Api.csproj", "Src/Dlhis.Basic.Api/"] -COPY ["Src/Dlhis.Common.Api/Dlhis.Common.Api.csproj", "Src/Dlhis.Common.Api/"] COPY ["Src/Dlhis.Entity/Dlhis.Entity.csproj", "Src/Dlhis.Entity/"] +COPY ["Src/Dlhis.Sys.Api/Dlhis.Sys.Api.csproj", "Src/Dlhis.Sys.Api/"] RUN dotnet restore "Src/Dlhis.Canteen/Dlhis.Canteen.csproj" COPY . . WORKDIR "/src/Src/Dlhis.Canteen" diff --git a/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs b/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs index a94dc314..974c31ae 100644 --- a/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs +++ b/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs @@ -1,6 +1,7 @@ using Dlhis.Canteen.Order.Request; using Dlhis.Canteen.Order.Response; using Dlhis.Canteen.Order.Services; +using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop; using Kurisu.Core.DataAccess.Dto; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -28,6 +29,7 @@ public class BalancesController : ControllerBase /// /// /// + [DataPermission] [HttpGet] public async Task> GetPageAsync([FromQuery] BalanceRecordPageRequest request) { @@ -89,7 +91,7 @@ public class BalancesController : ControllerBase [HttpGet("recordByCostId")] public async Task> RecordByCostIdAsync([FromQuery] BalanceRecordPageByCostIdRequest request) { - return await _balanceService.RecordByCostIdAsync(request); + return await _balanceService.RecordByCostIdAsync(request); } /// @@ -166,9 +168,9 @@ public class BalancesController : ControllerBase /// /// [HttpPost("disposition")] - public async Task DispositionDeviceAsync([FromQuery]DispositionDeviceRequest request) + public async Task DispositionDeviceAsync([FromQuery] DispositionDeviceRequest request) { - await _balanceService.DispositionDeviceAsync(request); + await _balanceService.DispositionDeviceAsync(request); } diff --git a/Src/Dlhis.Canteen/Order/Response/BalanceRecordResponse.cs b/Src/Dlhis.Canteen/Order/Response/BalanceRecordResponse.cs index d8ffb6ad..dcb63bab 100644 --- a/Src/Dlhis.Canteen/Order/Response/BalanceRecordResponse.cs +++ b/Src/Dlhis.Canteen/Order/Response/BalanceRecordResponse.cs @@ -119,4 +119,14 @@ public class BalanceRecordResponse /// 汇总金额 /// public decimal Sum { get; set; } + + /// + /// 厂区id + /// + public string TenantId { get; set; } + + /// + /// 厂区名称 + /// + public string TenantName { get; set; } } diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs index 94370d33..18342e69 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs @@ -5,6 +5,7 @@ using Dlhis.Entity.Canteen.Entities; using Dlhis.Entity.Canteen.Enums; using Dlhis.Entity.Device.Entities; using Dlhis.Entity.Device.Enums; +using Dlhis.Sys.Api; using Kurisu.AspNetCore.UnifyResultAndValidation; using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.DataAccess.Dto; @@ -12,7 +13,6 @@ using Kurisu.Core.DataAccess.Entity; using Kurisu.Core.User.Abstractions; using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Services; -using Microsoft.AspNetCore.Mvc; using SqlSugar; namespace Dlhis.Canteen.Order.Services.Implements; @@ -22,12 +22,14 @@ public class BalanceService : IBalanceService private readonly IDbContext _dbContext; private readonly ICurrentUser _currentUser; private readonly ILogger _logger; + private readonly ITenantApi _tenantApi; - public BalanceService(IDbContext dbContext, ICurrentUser currentUser, ILogger logger) + public BalanceService(IDbContext dbContext, ICurrentUser currentUser, ILogger logger ,ITenantApi tenantApi) { _dbContext = dbContext; _currentUser = currentUser; _logger = logger; + _tenantApi = tenantApi; } public async Task> GetPageAsync(BalanceRecordPageRequest request) @@ -71,10 +73,26 @@ public class BalanceService : IBalanceService DepartmentName = department.Name, BusinessPlaceName = bplace.Name, BusinessShiftName = type.Display, - CostDateTime = record.CostDateTime + CostDateTime = record.CostDateTime, + TenantId = record.TenantId, }) .ToPageListAsync(request); + try + { + var tenantResult = await _tenantApi.GetTenantsInternalAsync(); + var tenants = tenantResult.Data; + + page.Data.ForEach(item => + { + item.TenantName = tenants.FirstOrDefault(x => x.Code == item.TenantId)?.Name; + }); + + } + catch (Exception) + { + } + return page; } /// @@ -562,7 +580,7 @@ public class BalanceService : IBalanceService var offCount = await GetOfflineDevicesCount(devices); var places = await _dbContext.Queryable() - .Where(x =>x.Status == CanteenBusinessPlaceStatusEnumType.Opened) + .Where(x => x.Status == CanteenBusinessPlaceStatusEnumType.Opened) .ToListAsync(); var time = DateTime.Now.ToString("yyyy-MM-dd"); @@ -747,7 +765,7 @@ public class BalanceService : IBalanceService var devices = await _dbContext.Queryable().ToListAsync(); - if (request.UniqueNos!=null && request.UniqueNos.Count > 0) + if (request.UniqueNos != null && request.UniqueNos.Count > 0) { foreach (var no in request.UniqueNos) { diff --git a/Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj b/Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj index 96b47437..9efffeb1 100644 --- a/Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj +++ b/Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj @@ -20,7 +20,7 @@ - + diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Controllers/DeviceTaskAssignmentsController.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Controllers/DeviceTaskAssignmentsController.cs index 52822708..5d488ed9 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Controllers/DeviceTaskAssignmentsController.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Controllers/DeviceTaskAssignmentsController.cs @@ -1,6 +1,7 @@ using Dlhis.ScheduledTask.TaskAssignment.Request; using Dlhis.ScheduledTask.TaskAssignment.Response; using Dlhis.ScheduledTask.TaskAssignment.Services; +using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop; using Kurisu.Core.DataAccess.Dto; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -28,6 +29,7 @@ public class DeviceTaskAssignmentsController : ControllerBase /// /// [HttpGet("page")] + [DataPermission] public async Task> GetPageAsync([FromQuery] DeviceTaskAssignmentRequest request) { return await _deviceTaskAssignmentService.GetPageAsync(request); diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Response/DeviceTaskAssignmentResponse.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Response/DeviceTaskAssignmentResponse.cs index 7eb69334..73ad0d63 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Response/DeviceTaskAssignmentResponse.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Response/DeviceTaskAssignmentResponse.cs @@ -66,4 +66,15 @@ public class DeviceTaskAssignmentResponse /// 数据状态最新修改时间 /// public DateTime LastUpdateTime { get; set; } + + + /// + /// 厂区id + /// + public string TenantId { get; set; } + + /// + /// 厂区名称 + /// + public string TenantName { get; set; } } diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs index f2cff78a..8e7b2cb9 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs @@ -3,6 +3,7 @@ using Dlhis.Entity.Device.Entities; using Dlhis.Entity.Device.Enums; using Dlhis.ScheduledTask.TaskAssignment.Request; using Dlhis.ScheduledTask.TaskAssignment.Response; +using Dlhis.Sys.Api; using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.DataAccess.Dto; using Kurisu.SqlSugar.Extensions; @@ -14,10 +15,12 @@ namespace Dlhis.ScheduledTask.TaskAssignment.Services.Implements; public class DeviceTaskAssignmentService : IDeviceTaskAssignmentService { private readonly IDbContext _dbContext; + private readonly ITenantApi _tenantApi; - public DeviceTaskAssignmentService(IDbContext dbContext) + public DeviceTaskAssignmentService(IDbContext dbContext, ITenantApi tenantApi) { _dbContext = dbContext; + _tenantApi = tenantApi; } public async Task> GetPageAsync(DeviceTaskAssignmentRequest request) @@ -27,6 +30,7 @@ public class DeviceTaskAssignmentService : IDeviceTaskAssignmentService .WhereIF(!request.Search.IsEmpty(), (deviceTask, ga) => deviceTask.UserNo == request.Search || ga.Name.Contains(request.Search)) .WhereIF(request.Type.HasValue, deviceTask => deviceTask.Type == request.Type) .WhereIF(request.Status.HasValue, deviceTask => deviceTask.Status == request.Status) + .Where(deviceTask => 1 == 1) .OrderBy(deviceTask => deviceTask.CreateTime, OrderByType.Desc) .Select((deviceTask, ga) => new DeviceTaskAssignmentResponse { @@ -40,10 +44,27 @@ public class DeviceTaskAssignmentService : IDeviceTaskAssignmentService UserCode = ga.Code, Type = deviceTask.Type, CreateTime = deviceTask.CreateTime, - LastUpdateTime = deviceTask.ModifiedTime + LastUpdateTime = deviceTask.ModifiedTime, + TenantId = deviceTask.TenantId, }) .ToPageListAsync(request); + + try + { + var tenantResult = await _tenantApi.GetTenantsInternalAsync(); + var tenants = tenantResult.Data; + + page.Data.ForEach(item => + { + item.TenantName = tenants.FirstOrDefault(x => x.Code == item.TenantId)?.Name; + }); + + } + catch (Exception) + { + } + return page; } From 224ddf1be582c49ff59ac78832be228a665a5ce2 Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Thu, 7 Mar 2024 09:33:13 +0800 Subject: [PATCH 138/146] =?UTF-8?q?feat=20=E9=A4=90=E9=A5=AE=E4=B8=BB?= =?UTF-8?q?=E9=A1=B5=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Order/Controllers/BalancesController.cs | 20 ++++ .../Order/Request/AverageDailyRequest.cs | 8 ++ .../Order/Request/SpendingDetailRequest.cs | 8 ++ .../Order/Response/AverageDailyResponse.cs | 25 +++++ .../Order/Response/SpendingDetailResponse.cs | 20 +++- .../Order/Services/IBalanceService.cs | 2 + .../Services/Implements/BalanceService.cs | 97 +++++++++++++++++-- 7 files changed, 168 insertions(+), 12 deletions(-) create mode 100644 Src/Dlhis.Canteen/Order/Request/AverageDailyRequest.cs create mode 100644 Src/Dlhis.Canteen/Order/Request/SpendingDetailRequest.cs create mode 100644 Src/Dlhis.Canteen/Order/Response/AverageDailyResponse.cs diff --git a/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs b/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs index a94dc314..b8ab1e83 100644 --- a/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs +++ b/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs @@ -147,6 +147,26 @@ public class BalancesController : ControllerBase return await _balanceService.GetConsumeNumberAsync(); } + /// + /// 消费人数详情 + /// + /// + [HttpGet("spendingDetails")] + public async Task> GetSpendingDetailsAsync([FromQuery]SpendingDetailRequest request) + { + return await _balanceService.GetSpendingDetailsAsync(request); + } + + /// + /// 日消费均额 + /// + /// + /// + [HttpGet("averageDaily")] + public async Task> AverageDailyAsync([FromQuery] AverageDailyRequest request) + { + return await _balanceService.AverageDailyAsync(request); + } /// /// 获取消费机详情 diff --git a/Src/Dlhis.Canteen/Order/Request/AverageDailyRequest.cs b/Src/Dlhis.Canteen/Order/Request/AverageDailyRequest.cs new file mode 100644 index 00000000..01a91d70 --- /dev/null +++ b/Src/Dlhis.Canteen/Order/Request/AverageDailyRequest.cs @@ -0,0 +1,8 @@ +using Kurisu.Core.DataAccess.Dto; + +namespace Dlhis.Canteen.Order.Request +{ + public class AverageDailyRequest : PageDto + { + } +} diff --git a/Src/Dlhis.Canteen/Order/Request/SpendingDetailRequest.cs b/Src/Dlhis.Canteen/Order/Request/SpendingDetailRequest.cs new file mode 100644 index 00000000..fcdcff5f --- /dev/null +++ b/Src/Dlhis.Canteen/Order/Request/SpendingDetailRequest.cs @@ -0,0 +1,8 @@ +using Kurisu.Core.DataAccess.Dto; + +namespace Dlhis.Canteen.Order.Request +{ + public class SpendingDetailRequest:PageDto + { + } +} diff --git a/Src/Dlhis.Canteen/Order/Response/AverageDailyResponse.cs b/Src/Dlhis.Canteen/Order/Response/AverageDailyResponse.cs new file mode 100644 index 00000000..92541825 --- /dev/null +++ b/Src/Dlhis.Canteen/Order/Response/AverageDailyResponse.cs @@ -0,0 +1,25 @@ +namespace Dlhis.Canteen.Order.Response +{ + public class AverageDailyResponse + { + /// + /// 档案号/QRCode + /// + public string UserNo { get; set; } + + /// + /// 姓名 + /// + public string Name { get; set; } + + /// + /// 学工号 + /// + public string UserCode { get; set; } + + /// + /// 日消费均额 + /// + public int AverageAmount { get; set; } + } +} diff --git a/Src/Dlhis.Canteen/Order/Response/SpendingDetailResponse.cs b/Src/Dlhis.Canteen/Order/Response/SpendingDetailResponse.cs index ad309eb9..8ad95ac5 100644 --- a/Src/Dlhis.Canteen/Order/Response/SpendingDetailResponse.cs +++ b/Src/Dlhis.Canteen/Order/Response/SpendingDetailResponse.cs @@ -5,9 +5,9 @@ namespace Dlhis.Canteen.Order.Response public class SpendingDetailResponse { /// - /// 档案号 + /// 档案号/QRCode /// - public string No { get; set; } + public string UserNo { get; set; } /// /// 姓名 @@ -17,8 +17,22 @@ namespace Dlhis.Canteen.Order.Response /// /// 学工号 /// - public string Code { get; set; } + public string UserCode { get; set; } + /// + /// 部门号 + /// + public string DepartmentNo { get; set; } + + /// + /// 成本中心 + /// + public string CostId { get; set; } + + /// + /// 消费者所在基地 + /// + public string OriginTenantId { get; set; } } } diff --git a/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs b/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs index 73c3497a..8302795d 100644 --- a/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/IBalanceService.cs @@ -27,7 +27,9 @@ public interface IBalanceService : IScopeDependency Task GetConsumeNumberAsync(); + Task> GetSpendingDetailsAsync(SpendingDetailRequest request); + Task> AverageDailyAsync(AverageDailyRequest request); Task> GetConsumeDeviceAsync(GetConsumeDeviceRequest request); diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs index 94370d33..dcfc0ab5 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs @@ -12,6 +12,7 @@ using Kurisu.Core.DataAccess.Entity; using Kurisu.Core.User.Abstractions; using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Services; +using Mapster; using Microsoft.AspNetCore.Mvc; using SqlSugar; @@ -565,7 +566,7 @@ public class BalanceService : IBalanceService .Where(x =>x.Status == CanteenBusinessPlaceStatusEnumType.Opened) .ToListAsync(); - var time = DateTime.Now.ToString("yyyy-MM-dd"); + //所有消费数据 var bs = await _dbContext.Queryable() .Where(x => x.Type == BalanceRecordTypeEnumType.Out) @@ -573,13 +574,8 @@ public class BalanceService : IBalanceService //可消费人数 var consumerable = bs.Select(x => x.UserCode).Distinct().Count(); - //当日消费数据 - var monthbs = bs - .Where(x => x.CostDateTime.ToString("yyyy-MM-dd") == time); - //当日消费额 - var monthlySpending = monthbs.Sum(x => x.Amount); - //当日消费人数 - var monthlyCount = monthbs.Select(x => x.UserCode).Distinct().Count(); + var dailyNumber = SameDay(bs,""); + //消费走势 var months = await GetConsumptionTrendsAsync(ConsumptionTrendEnumType.Month); @@ -591,15 +587,98 @@ public class BalanceService : IBalanceService OffNumber = offCount.Count, PlaceNumber = places.Count, ConsumerableNumber = consumerable, - DailyNumber = monthlyCount != 0 ? Math.Abs((int)Math.Ceiling(monthlySpending / monthlyCount)) : 0, + DailyNumber = dailyNumber, Days = days, Months = months }; return res; } + /// + /// 获取单日消费数据 + /// + /// + /// + /// + private int SameDay(List bs,string userCode) + { + var time = DateTime.Now.ToString("yyyy-MM-dd"); + var b = userCode.IsEmpty(); + //当日消费数据 + var monthbs = bs + .Where(x => x.CostDateTime.ToString("yyyy-MM-dd") == time) + .WhereIF(!userCode.IsEmpty(),x => x.UserCode == userCode); + //当日消费额 + var monthlySpending = monthbs.Sum(x => x.Amount); + //当日消费人数 + var monthlyCount = monthbs.Select(x => x.UserCode).Distinct().Count(); + var dailyNumber = monthlyCount != 0 ? Math.Abs((int)Math.Ceiling(monthlySpending / monthlyCount)) : 0; + return dailyNumber; + } + public async Task> GetSpendingDetailsAsync(SpendingDetailRequest request) + { + var brs = await _dbContext + .Queryable() + .Where(x => x.Type == BalanceRecordTypeEnumType.Out) + .ToListAsync(); + var codes = brs.Select(x => x.UserCode).ToList().Distinct().ToList(); + var lst = new List(); + foreach (var code in codes) + { + var br = brs.Where(x => x.UserCode == code).FirstOrDefault(); + var res = br.Adapt(); + lst.Add(res); + } + + // 分页操作 + var startIndex = (request.PageIndex - 1) * request.PageSize; + var pagedData = lst.Skip(startIndex).Take(request.PageSize).ToList(); + + var pagination = new Pagination + { + PageIndex = request.PageIndex, + PageSize = request.PageSize, + Total = lst.Count, // 使用原始列表的总数进行分页 + Data = pagedData + }; + + return pagination; + } + + public async Task> AverageDailyAsync(AverageDailyRequest request) + { + //所有消费数据 + var brs = await _dbContext.Queryable() + .Where(x => x.Type == BalanceRecordTypeEnumType.Out) + .ToListAsync(); + var codes = brs.Select(x => x.UserCode).ToList().Distinct().ToList(); + + var lst = new List(); + foreach (var code in codes) + { + var br = brs.Where(x => x.UserCode == code).FirstOrDefault(); + var res = br.Adapt(); + var dailyNumber = SameDay(brs,code); + res.AverageAmount = dailyNumber; + lst.Add(res); + } + + // 分页操作 + var startIndex = (request.PageIndex - 1) * request.PageSize; + var pagedData = lst.Skip(startIndex).Take(request.PageSize).ToList(); + + var pagination = new Pagination + { + PageIndex = request.PageIndex, + PageSize = request.PageSize, + Total = lst.Count, // 使用原始列表的总数进行分页 + Data = pagedData + }; + + return pagination; + } public async Task> GetConsumeDeviceAsync(GetConsumeDeviceRequest request) { From a1aa61b251cb7e324244fb789fc2ff0fc1698fd8 Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Thu, 7 Mar 2024 10:51:28 +0800 Subject: [PATCH 139/146] =?UTF-8?q?fix=20=E8=AE=BE=E5=A4=87=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E5=88=86=E9=A1=B5=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Response/DeviceTaskAssignmentResponse.cs | 11 +++++++++++ .../Implements/DeviceTaskAssignmentService.cs | 7 +++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Response/DeviceTaskAssignmentResponse.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Response/DeviceTaskAssignmentResponse.cs index 73ad0d63..beeb82ed 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Response/DeviceTaskAssignmentResponse.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Response/DeviceTaskAssignmentResponse.cs @@ -1,5 +1,6 @@ using Dlhis.Entity.Device.Enums; using Kurisu.AspNetCore.Utils.Extensions; +using SqlSugar; namespace Dlhis.ScheduledTask.TaskAssignment.Response; @@ -77,4 +78,14 @@ public class DeviceTaskAssignmentResponse /// 厂区名称 /// public string TenantName { get; set; } + + /// + /// 部署点 + /// + public string DeployPlace { get; set; } + + /// + /// 连接信息 + /// + public string ConnectionInfo { get; set; } } diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs index 8e7b2cb9..979f2b17 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs @@ -27,12 +27,13 @@ public class DeviceTaskAssignmentService : IDeviceTaskAssignmentService { var page = await _dbContext.Queryable() .LeftJoin((deviceTask, ga) => deviceTask.UserNo == ga.No) - .WhereIF(!request.Search.IsEmpty(), (deviceTask, ga) => deviceTask.UserNo == request.Search || ga.Name.Contains(request.Search)) + .LeftJoin((deviceTask, ga,device) => deviceTask.DeviceUniqueNo == device.UniqueNo) + .WhereIF(!request.Search.IsEmpty(), (deviceTask, ga,device) => deviceTask.UserNo == request.Search || ga.Name.Contains(request.Search) || ga.Code == request.Search || deviceTask.DeviceUniqueNo == request.Search || deviceTask.ModifiedTime.ToString("yyyy-MM-dd").Contains(request.Search)) .WhereIF(request.Type.HasValue, deviceTask => deviceTask.Type == request.Type) .WhereIF(request.Status.HasValue, deviceTask => deviceTask.Status == request.Status) .Where(deviceTask => 1 == 1) .OrderBy(deviceTask => deviceTask.CreateTime, OrderByType.Desc) - .Select((deviceTask, ga) => new DeviceTaskAssignmentResponse + .Select((deviceTask, ga,device) => new DeviceTaskAssignmentResponse { Id = deviceTask.Id, DeviceUniqueNo = deviceTask.DeviceUniqueNo, @@ -46,6 +47,8 @@ public class DeviceTaskAssignmentService : IDeviceTaskAssignmentService CreateTime = deviceTask.CreateTime, LastUpdateTime = deviceTask.ModifiedTime, TenantId = deviceTask.TenantId, + DeployPlace = device.DeployPlace, + ConnectionInfo = device.ConnectionInfo }) .ToPageListAsync(request); From 12215fdfd7f59f249ab424db57119c1b92242475 Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Thu, 7 Mar 2024 11:10:46 +0800 Subject: [PATCH 140/146] =?UTF-8?q?fix=20=E8=AE=BE=E5=A4=87=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E4=BF=9D=E5=AD=98=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Device/Services/Implements/DeviceTemplateService.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceTemplateService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceTemplateService.cs index 4f60c45d..c9c7accb 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceTemplateService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceTemplateService.cs @@ -46,6 +46,7 @@ public class DeviceTemplateService : IDeviceTemplateService { var entity = await _dbContext.Queryable().Where(x => x.Id == request.Id).FirstAsync(); await ExistsDeviceUsingTemplateAsync(entity.Code); + request.Adapt(entity); await _dbContext.UpdateAsync(entity); } } From 1de6bc6c0f94a01c756ee93b7771f1d890c5e5c9 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 7 Mar 2024 15:17:40 +0800 Subject: [PATCH 141/146] =?UTF-8?q?fix=20=E7=BB=84=E7=BB=87=E6=9E=B6?= =?UTF-8?q?=E6=9E=84=E6=A0=91=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DevicePermissionsController.cs | 1 + .../Request/DevicePermissionSaveReuqest.cs | 19 ++++++++++- .../Implements/DevicePermissionService.cs | 28 ++++++++-------- .../Response/DepartmentTreeResponse.cs | 22 +++++++++++-- .../Services/Implements/DepartmentService.cs | 32 ++++++++++++++----- 5 files changed, 78 insertions(+), 24 deletions(-) diff --git a/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs b/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs index 0c61d995..736902c0 100644 --- a/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs +++ b/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs @@ -27,6 +27,7 @@ public class DevicePermissionsController : ControllerBase /// [HttpPost("assign")] [Transactional] + [IgnoreTenant] public async Task AssignAsync(DevicePermissionSaveReuqest request) { await _devicePermissionService.AssignAsync(request); diff --git a/Src/Dlhis.Basic/Device/Request/DevicePermissionSaveReuqest.cs b/Src/Dlhis.Basic/Device/Request/DevicePermissionSaveReuqest.cs index ae282891..85c3a613 100644 --- a/Src/Dlhis.Basic/Device/Request/DevicePermissionSaveReuqest.cs +++ b/Src/Dlhis.Basic/Device/Request/DevicePermissionSaveReuqest.cs @@ -1,9 +1,10 @@ using System.ComponentModel.DataAnnotations; using Dlhis.Entity.Sys.Enums; +using Kurisu.AspNetCore.Utils.Extensions; namespace Dlhis.Basic.Device.Request; -public class DevicePermissionSaveReuqest +public class DevicePermissionSaveReuqest : IValidatableObject { /// /// 分配类型 AssignTypeEnumType @@ -30,4 +31,20 @@ public class DevicePermissionSaveReuqest /// 分配权限值 /// public List Codes { get; set; } + + /// + /// AssignType == AssignTypeEnumType.Department 需要传入 + /// + public string TenantId { get; set; } + + public IEnumerable Validate(ValidationContext validationContext) + { + if (AssignType == AssignTypeEnumType.Department) + { + if (TenantId.IsEmpty()) + { + yield return new ValidationResult("请明确具体的厂区", new[] { nameof(TenantId) }); + } + } + } } diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs index 7b0a9f2e..91019ab8 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs @@ -34,6 +34,7 @@ public class DevicePermissionService : IDevicePermissionService .Where(x => x.AssignType == reuqest.AssignType) .Where(x => x.AssignValue == reuqest.AssignValue) .Where(x => x.UniqueType == reuqest.UniqueType) + .WhereIF(reuqest.AssignType == AssignTypeEnumType.Department, x => x.TenantId == reuqest.TenantId) .ToListAsync(); await _dbContext.DeleteReallyAsync(p); @@ -41,14 +42,17 @@ public class DevicePermissionService : IDevicePermissionService //保存配置的权限 if (reuqest.Codes.IsPresent()) { + var tenantId = reuqest.AssignType == AssignTypeEnumType.Department ? reuqest.TenantId : _currentUser.GetStringSubjectId(); + var devicePermissions = reuqest.Codes.Select(code => new DevicePermissionEntity { AssignType = reuqest.AssignType, AssignValue = reuqest.AssignValue, UniqueType = reuqest.UniqueType, UniqueValue = code, - - }).ToList(); + TenantId = tenantId + }) + .ToList(); await _dbContext.InsertAsync(devicePermissions); } @@ -75,7 +79,6 @@ public class DevicePermissionService : IDevicePermissionService if (userNos.IsEmpty()) userNos = await GetPermissionUserNosAsync(); - //var before = await GetAssignDeviceCodesInternalAsync(userNos); var before = await GetAssignDeviceCodesInternalAsync(userNos); _dbContext.Client.QueryFilter.Restore(); @@ -88,7 +91,6 @@ public class DevicePermissionService : IDevicePermissionService if (nextUserNos.Any()) userNos = userNos.Concat(nextUserNos).Distinct().ToList(); - //var current = await GetAssignDeviceCodesInternalAsync(userNos); var current = await GetAssignDeviceCodesInternalAsync(userNos); var deivces = await _dbContext.Queryable().ToListAsync(); @@ -409,13 +411,12 @@ public class DevicePermissionService : IDevicePermissionService return result; } - - - private static List GetAssignDeviceCodesInternal(GainfoEntity gainfo, - List gainfoGroupRelationships, - List devicePermissions, - List deviceGroups, - List deviceGroupRelationships) + private static List GetAssignDeviceCodesInternal( + GainfoEntity gainfo, + List gainfoGroupRelationships, + List devicePermissions, + List deviceGroups, + List deviceGroupRelationships) { var userNo = gainfo.No; var deviceCodes = new List(); @@ -438,8 +439,9 @@ public class DevicePermissionService : IDevicePermissionService deviceGroupCodes.AddRange(gg); } - var dd = GetAssignCodesInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Department, gainfo.DepartmentNo); - var gd = GetAssignCodesInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Department, gainfo.DepartmentNo); + var gainfoFactoryDevicePermissions = devicePermissions.Where(x => x.TenantId == gainfo.Factory).ToList(); + var dd = GetAssignCodesInternal(gainfoFactoryDevicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Department, gainfo.DepartmentNo); + var gd = GetAssignCodesInternal(gainfoFactoryDevicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Department, gainfo.DepartmentNo); deviceCodes.AddRange(dd); deviceGroupCodes.AddRange(gd); diff --git a/Src/Dlhis.Basic/Organization/Response/DepartmentTreeResponse.cs b/Src/Dlhis.Basic/Organization/Response/DepartmentTreeResponse.cs index 309e6d58..88aba019 100644 --- a/Src/Dlhis.Basic/Organization/Response/DepartmentTreeResponse.cs +++ b/Src/Dlhis.Basic/Organization/Response/DepartmentTreeResponse.cs @@ -1,4 +1,6 @@ -namespace Dlhis.Basic.Organization.Response; +using Newtonsoft.Json; + +namespace Dlhis.Basic.Organization.Response; public class DepartmentTreeResponse { @@ -17,8 +19,24 @@ public class DepartmentTreeResponse /// public string Name { get; set; } + + public string Tenant { get; set; } + /// /// 下级部门 /// - public List Next { get; set; } = new List(); + [JsonIgnore] + public List _Next { get; set; } = new List(); + + /// + /// 下级部门 + /// + public List Next + { + get + { + _Next.ForEach(x => x.Tenant = Tenant); + return _Next; + } + } } diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/DepartmentService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/DepartmentService.cs index 9800dc40..fd4f8e74 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/DepartmentService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/DepartmentService.cs @@ -1,25 +1,24 @@ using Dlhis.Basic.Organization.Response; using Dlhis.Entity.Basic.Entity; -using Kurisu.Core.User.Abstractions; +using Dlhis.Sys.Api; using Kurisu.SqlSugar.Services; +using Mapster; namespace Dlhis.Basic.Organization.Services.Implements; public class DepartmentService : IDepartmentService { private readonly IDbContext _dbContext; - private readonly ICurrentUser _currentUser; + private readonly ITenantApi _tenantApi; - public DepartmentService(IDbContext dbContext, ICurrentUser currentUser) + public DepartmentService(IDbContext dbContext, ITenantApi tenantApi) { _dbContext = dbContext; - _currentUser = currentUser; + _tenantApi = tenantApi; } public async Task> GetTreeAsync() { - var myTenants = _currentUser.GetUserClaim("tenants").Split(',').ToList(); - var departments = await _dbContext.Queryable().Select().ToListAsync(); //00001000 一定是这个开头的 var tops = departments.Where(x => x.PNo == "00001000").ToList(); @@ -29,13 +28,30 @@ public class DepartmentService : IDepartmentService RecursionGetNext(x, departments); }); - return tops; + var myTenantResult = await _tenantApi.GetMyTenantsAsync(); + var tenants = myTenantResult.Data; + + return tenants.Select(x => new DepartmentTreeResponse + { + Name = x.Name, + No = x.Code, + PNo = x.PCode, + Tenant = x.Code, + _Next = tops.Select(item => + { + var i = item.Adapt(); + i.PNo = x.Code; + return i; + + }).ToList() + }) + .ToList(); } private void RecursionGetNext(DepartmentTreeResponse current, List data) { var next = data.Where(x => x.PNo == current.No).ToList(); - current.Next = next; + current._Next = next; foreach (var item in next) { RecursionGetNext(item, data); From 5b38f09a36a573dcdc3077a31a8ca6215d12a31f Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 7 Mar 2024 15:31:20 +0800 Subject: [PATCH 142/146] =?UTF-8?q?fix=20unique=E4=B8=BAnull=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.Basic/Device/Request/DeviceSaveRequest.cs | 5 ----- Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs | 3 ++- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/Src/Dlhis.Basic/Device/Request/DeviceSaveRequest.cs b/Src/Dlhis.Basic/Device/Request/DeviceSaveRequest.cs index 1308a9a2..f7e4a84c 100644 --- a/Src/Dlhis.Basic/Device/Request/DeviceSaveRequest.cs +++ b/Src/Dlhis.Basic/Device/Request/DeviceSaveRequest.cs @@ -78,11 +78,6 @@ public class DeviceSaveRequest : IValidatableObject public IEnumerable Validate(ValidationContext validationContext) { - if (Id.HasValue) - { - UniqueNo = null; - } - if (Type != DeviceTypeEnumType.Door && AsAttendance) { yield return new ValidationResult($"{DeviceTypeEnumType.Door.GetDescription()}才可设置作为考勤设备", new[] { nameof(AsAttendance) }); diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs index f43f3c7a..41d82124 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs @@ -204,7 +204,8 @@ public class DeviceService : IDeviceService /// private async Task CheckUniqueNoExistsAsync(DeviceSaveRequest request) { - var exists = await _dbContext.Queryable().Where(x => x.UniqueNo == request.UniqueNo) + var exists = await _dbContext.Queryable() + .Where(x => x.UniqueNo == request.UniqueNo) .WhereIF(request.Id.HasValue, x => x.Id != request.Id) .AnyAsync(); From ff15ae9176e2b96ac5385caccb50846e37aaa552 Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Thu, 7 Mar 2024 16:45:31 +0800 Subject: [PATCH 143/146] =?UTF-8?q?feat=20=E8=AE=BE=E5=A4=87=E6=89=B9?= =?UTF-8?q?=E9=87=8F=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Device/Controllers/DevicesController.cs | 23 ++- .../Device/Request/BulkUploadsRequest.cs | 10 ++ .../Device/Request/ImportDeviceSaveRequest.cs | 76 ++++++++ .../Device/Response/GetDoorOfflineRequest.cs | 9 + .../Device/Services/IDeviceService.cs | 5 + .../Services/Implements/DeviceService.cs | 165 +++++++++++++++++- Src/Dlhis.Basic/Dlhis.Basic.csproj | 1 + .../Controllers/SummariesController.cs | 13 +- .../Summary/Response/DoorHomeDataResponse.cs | 11 ++ .../Summary/Services/ISummaryService.cs | 5 +- .../Services/Implements/SummaryService.cs | 84 ++++++++- 11 files changed, 395 insertions(+), 7 deletions(-) create mode 100644 Src/Dlhis.Basic/Device/Request/BulkUploadsRequest.cs create mode 100644 Src/Dlhis.Basic/Device/Request/ImportDeviceSaveRequest.cs create mode 100644 Src/Dlhis.Basic/Device/Response/GetDoorOfflineRequest.cs create mode 100644 Src/Dlhis.Basic/Summary/Response/DoorHomeDataResponse.cs diff --git a/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs b/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs index 14c35704..400cff09 100644 --- a/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs +++ b/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs @@ -199,7 +199,17 @@ public class DevicesController : ControllerBase } /// - /// 获取近期30天新增设备数 + /// 获取门禁在线/离线设备详情列表 + /// + /// + [HttpGet("dooroffline")] + public async Task> GetDoorOfflineAsync([FromQuery] GetDoorOfflineRequest request) + { + return await _deviceService.GetDoorOfflineAsync(request); + } + + /// + /// 获取近期30天考勤新增设备数 /// /// [HttpGet("recentnumbers")] @@ -208,4 +218,15 @@ public class DevicesController : ControllerBase return await _deviceService.GetRecentNumbersAsync(); } + /// + /// 批量导入设备信息 + /// + /// + /// + [HttpPost("bulkUploads")] + public async Task BulkUploadsAsync([FromForm] BulkUploadsRequest request) + { + await _deviceService.BulkUploadsAsync(request); + } + } diff --git a/Src/Dlhis.Basic/Device/Request/BulkUploadsRequest.cs b/Src/Dlhis.Basic/Device/Request/BulkUploadsRequest.cs new file mode 100644 index 00000000..a0ff5fb0 --- /dev/null +++ b/Src/Dlhis.Basic/Device/Request/BulkUploadsRequest.cs @@ -0,0 +1,10 @@ +namespace Dlhis.Basic.Device.Request +{ + public class BulkUploadsRequest + { + /// + /// 设备信息文件 + /// + public IFormFile FormFile { get; set; } + } +} diff --git a/Src/Dlhis.Basic/Device/Request/ImportDeviceSaveRequest.cs b/Src/Dlhis.Basic/Device/Request/ImportDeviceSaveRequest.cs new file mode 100644 index 00000000..eddbcaed --- /dev/null +++ b/Src/Dlhis.Basic/Device/Request/ImportDeviceSaveRequest.cs @@ -0,0 +1,76 @@ +using Dlhis.Entity.Device.Enums; +using System.ComponentModel.DataAnnotations; + +namespace Dlhis.Basic.Device.Request +{ + public class ImportDeviceSaveRequest + { + + public long? Id { get; set; } + + /// + /// 设备唯一号 + /// + public string UniqueNo { get; set; } + + /// + /// 模板code + /// + public Guid TemplateCode { get; set; } + + /// + /// 供应商信息 + /// + public string Supplier { get; set; } + + /// + /// 设备功能 + /// + public List Funcs { get; set; } + + /// + /// 设备类型 DeviceTypeEnumType + /// + public DeviceTypeEnumType Type { get; set; } + + /// + /// 心跳间隔 + /// + public int HeartbeatInterval { get; set; } + + /// + /// 部署点 + /// + public string DeployPlace { get; set; } + + /// + /// 部署坐标 + /// + public string DeployPosition { get; set; } + + /// + /// 部署方向 + /// + public string DeployDirection { get; set; } + + /// + /// 连接信息 + /// + public string ConnectionInfo { get; set; } + + /// + /// 是否启用 + /// + public bool Enable { get; set; } + + /// + /// 是否作为考勤设备 + /// + public bool AsAttendance { get; set; } + + /// + /// 营业点code + /// + public Guid? PlaceeCode { get; set; } + } +} diff --git a/Src/Dlhis.Basic/Device/Response/GetDoorOfflineRequest.cs b/Src/Dlhis.Basic/Device/Response/GetDoorOfflineRequest.cs new file mode 100644 index 00000000..89d4eff4 --- /dev/null +++ b/Src/Dlhis.Basic/Device/Response/GetDoorOfflineRequest.cs @@ -0,0 +1,9 @@ +using Kurisu.Core.DataAccess.Dto; + +namespace Dlhis.Basic.Device.Response +{ + public class GetDoorOfflineRequest : PageDto + { + public bool IsOnAndOff { get; set; } + } +} diff --git a/Src/Dlhis.Basic/Device/Services/IDeviceService.cs b/Src/Dlhis.Basic/Device/Services/IDeviceService.cs index 7f47e38f..a5549121 100644 --- a/Src/Dlhis.Basic/Device/Services/IDeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/IDeviceService.cs @@ -23,6 +23,11 @@ public interface IDeviceService : IScopeDependency Task> GetAttendanceOfflineAsync(DeviceOnlineAndofflineRequest request); + Task> GetDoorOfflineAsync(GetDoorOfflineRequest request); + Task> GetRecentNumbersAsync(); + Task BulkUploadsAsync(BulkUploadsRequest request); + + } diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs index f43f3c7a..9563702a 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs @@ -12,8 +12,12 @@ using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Services; using Mapster; using Microsoft.AspNetCore.Mvc; +using MySqlX.XDevAPI.Relational; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using NPOI.OpenXmlFormats; +using NPOI.SS.UserModel; +using NPOI.XSSF.UserModel; using SqlSugar; namespace Dlhis.Basic.Device.Services.Implements; @@ -123,6 +127,53 @@ public class DeviceService : IDeviceService await GenerateUploadRecordLogForBeginTimeAsync(entity); } + /// + /// 批量导入 + /// + /// + /// + public async Task BulkUploadsAsync(BulkUploadsRequest request) + { + var lst = ImportFromExcel(request.FormFile); + var places = await _dbContext.Queryable().ToListAsync(); + + foreach (var form in lst) + { + if (form.PlaceeCode != null) + { + var place = places.Where(x => x.Code == form.PlaceeCode).FirstOrDefault(); + place.ThrowIfNull($"该设备{form.UniqueNo}配置的营业点营业点不存在!"); + } + //插入 + var exists = await _dbContext.Queryable().Where(x => x.UniqueNo == form.UniqueNo) + .AnyAsync(); + exists.ThrowIfTrue("唯一号已经存在"); + var template = await CheckTemplateExistsAsync(form.TemplateCode); + await CheckTemplateFieldAsync(form.TemplateCode, form.ConnectionInfo); + + var saveEntity = form.Adapt(); + saveEntity.Code = Guid.NewGuid(); + await _dbContext.InsertAsync(saveEntity); + //保存注册信息 + var regis = await _dbContext.Queryable() + .Where(x => x.DeviceUniqueNo == form.UniqueNo) + .FirstAsync(); + if(regis == null) + { + var custCode = places.Where(x => x.Code == form.PlaceeCode).Select(x => x.CustomCode).FirstOrDefault(); + regis = new DeviceRegistryEntity + { + DeviceUniqueNo = form.UniqueNo, + LastHeartbeatTime = DateTime.Now, + RegisterTime = DateTime.Now, + BusinessPlaceCode = form.PlaceeCode, + BusinessPlaceCustomCode = custCode + }; + await _dbContext.InsertAsync(regis); + } + } + } + //******************************************************** help methods ********************************************************** private async Task GenerateUploadRecordLogForBeginTimeAsync(DeviceEntity entity) @@ -343,7 +394,7 @@ public class DeviceService : IDeviceService //离线 var offpage = await _dbContext.Queryable() .LeftJoin((d, dt) => d.TemplateCode == dt.Code) - .Where(d => d.Type == DeviceTypeEnumType.Attendance && d.Enable) + .Where(d => d.Type == DeviceTypeEnumType.Attendance) .Where(d => offids.Contains(d.Id)) .Select((d, dt) => new DevicePageResponse { @@ -361,7 +412,7 @@ public class DeviceService : IDeviceService var page = await _dbContext.Queryable() .LeftJoin((d, dt) => d.TemplateCode == dt.Code) - .Where(d => d.Type == DeviceTypeEnumType.Attendance && d.Enable) + .Where(d => d.Type == DeviceTypeEnumType.Attendance) .Where(d => onids.Contains(d.Id)) .Select((d, dt) => new DevicePageResponse { @@ -375,6 +426,51 @@ public class DeviceService : IDeviceService return page; } + public async Task> GetDoorOfflineAsync(GetDoorOfflineRequest request) + { + var devices = await _dbContext.Queryable().Where(x => x.Type == DeviceTypeEnumType.Door).ToListAsync(); + + var offDevices = await GetOfflineDevicesCount(devices); + var offids = offDevices.Select(x => x.Id).ToList(); + + if (request.IsOnAndOff) + { + //离线 + var offpage = await _dbContext.Queryable() + .LeftJoin((d, dt) => d.TemplateCode == dt.Code) + .Where(d => d.Type == DeviceTypeEnumType.Door) + .Where(d => offids.Contains(d.Id)) + .Select((d, dt) => new DevicePageResponse + { + FuncsStr = d.Funcs.ToString(), + Brand = dt.Brand, + Type = d.Type, + + }, true) + .ToPageListAsync(request); + return offpage; + } + //在线 + var ids = devices.Select(x => x.Id).ToList(); + List onids = ids.Except(offids).ToList(); + + var page = await _dbContext.Queryable() + .LeftJoin((d, dt) => d.TemplateCode == dt.Code) + .Where(d => d.Type == DeviceTypeEnumType.Door) + .Where(d => onids.Contains(d.Id)) + .Select((d, dt) => new DevicePageResponse + { + FuncsStr = d.Funcs.ToString(), + Brand = dt.Brand, + Type = d.Type, + + }, true) + .ToPageListAsync(request); + + return page; + + } + public async Task> GetRecentNumbersAsync() { //获取近30天并转化为"yyyy-MM-dd"集合 @@ -387,7 +483,7 @@ public class DeviceService : IDeviceService times.Add(dateString); } - var devices = await _dbContext.Queryable().ToListAsync(); + var devices = await _dbContext.Queryable().Where(x => x.Type == DeviceTypeEnumType.Attendance || (x.Type == DeviceTypeEnumType.Door && x.AsAttendance)).ToListAsync(); var list = new List(); times.ForEach(time => @@ -403,5 +499,68 @@ public class DeviceService : IDeviceService return list; } + private List ImportFromExcel(IFormFile formFile) + { + var requests = new List(); + + using (var stream = formFile.OpenReadStream()) + { + XSSFWorkbook workbook = new XSSFWorkbook(stream); + ISheet sheet = workbook.GetSheetAt(0); + + for (int rowIdx = 1; rowIdx <= sheet.LastRowNum; rowIdx++) + { + IRow row = sheet.GetRow(rowIdx); + if (row == null) continue; + + var request = new ImportDeviceSaveRequest(); + + request.UniqueNo = row.GetCell(0).ToString(); + request.TemplateCode = Guid.Parse(row.GetCell(1).ToString()); + request.Supplier = row.GetCell(2).ToString(); + + var funs = new List(); + var fs = row.GetCell(3).ToString().Split(','); + foreach (string str in fs) + { + switch (str) + { + case "1": + funs.Add(DeviceFuncEnumType.Face); + break; + case "2": + funs.Add(DeviceFuncEnumType.Card); + break; + case "3": + funs.Add(DeviceFuncEnumType.QrCode); + break; + case "4": + funs.Add(DeviceFuncEnumType.Control); + break; + default: + break; + } + } + request.Funcs = funs; + request.Type = (DeviceTypeEnumType)Enum.Parse(typeof(DeviceTypeEnumType), row.GetCell(4).ToString()); + request.HeartbeatInterval = int.Parse(row.GetCell(5).ToString()); + request.DeployPlace = row.GetCell(6).ToString(); + request.DeployPosition = row.GetCell(7).ToString(); + request.DeployDirection = row.GetCell(8).ToString(); + request.ConnectionInfo = row.GetCell(9).ToString(); + request.Enable = Convert.ToBoolean(Convert.ToInt32(row.GetCell(10).ToString())); + request.AsAttendance = Convert.ToBoolean(Convert.ToInt32(row.GetCell(11).ToString())); + if (row.GetCell(12) != null) + { + request.PlaceeCode = Guid.Parse(row.GetCell(12)?.ToString()); + } + requests.Add(request); + } + } + + return requests; + } } + + diff --git a/Src/Dlhis.Basic/Dlhis.Basic.csproj b/Src/Dlhis.Basic/Dlhis.Basic.csproj index ffe86e4d..d0e8b356 100644 --- a/Src/Dlhis.Basic/Dlhis.Basic.csproj +++ b/Src/Dlhis.Basic/Dlhis.Basic.csproj @@ -18,6 +18,7 @@ + diff --git a/Src/Dlhis.Basic/Summary/Controllers/SummariesController.cs b/Src/Dlhis.Basic/Summary/Controllers/SummariesController.cs index 0f7f9fb0..2acddc4e 100644 --- a/Src/Dlhis.Basic/Summary/Controllers/SummariesController.cs +++ b/Src/Dlhis.Basic/Summary/Controllers/SummariesController.cs @@ -1,4 +1,5 @@ -using Dlhis.Basic.Summary.Response; +using Dlhis.Basic.Device.Response; +using Dlhis.Basic.Summary.Response; using Dlhis.Basic.Summary.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -26,4 +27,14 @@ public class SummariesController : ControllerBase { return await _summaryService.GetAttendanceSummaryAsync(); } + + /// + /// 门禁首页数据 + /// + /// + [HttpGet("door-summary")] + public async Task GetDoorHomeDataAsync() + { + return await _summaryService.GetDoorHomeDataAsync(); + } } diff --git a/Src/Dlhis.Basic/Summary/Response/DoorHomeDataResponse.cs b/Src/Dlhis.Basic/Summary/Response/DoorHomeDataResponse.cs new file mode 100644 index 00000000..163a35fe --- /dev/null +++ b/Src/Dlhis.Basic/Summary/Response/DoorHomeDataResponse.cs @@ -0,0 +1,11 @@ +using Dlhis.Basic.Summary.Dto; + +namespace Dlhis.Basic.Summary.Response +{ + public class DoorHomeDataResponse + { + public int OffNum { get; set; } + public int TotalNum { get; set; } + public List Trend { get; set; } + } +} diff --git a/Src/Dlhis.Basic/Summary/Services/ISummaryService.cs b/Src/Dlhis.Basic/Summary/Services/ISummaryService.cs index 775379d2..9c92e218 100644 --- a/Src/Dlhis.Basic/Summary/Services/ISummaryService.cs +++ b/Src/Dlhis.Basic/Summary/Services/ISummaryService.cs @@ -1,8 +1,11 @@ -using Dlhis.Basic.Summary.Response; +using Dlhis.Basic.Device.Response; +using Dlhis.Basic.Summary.Response; namespace Dlhis.Basic.Summary.Services; public interface ISummaryService : IScopeDependency { Task GetAttendanceSummaryAsync(); + + Task GetDoorHomeDataAsync(); } diff --git a/Src/Dlhis.Basic/Summary/Services/Implements/SummaryService.cs b/Src/Dlhis.Basic/Summary/Services/Implements/SummaryService.cs index a2306942..4feeb179 100644 --- a/Src/Dlhis.Basic/Summary/Services/Implements/SummaryService.cs +++ b/Src/Dlhis.Basic/Summary/Services/Implements/SummaryService.cs @@ -1,4 +1,5 @@ -using Dlhis.Basic.Organization.Services; +using Dlhis.Basic.Device.Response; +using Dlhis.Basic.Organization.Services; using Dlhis.Basic.Summary.Dto; using Dlhis.Basic.Summary.Response; using Dlhis.Entity.Basic.Entity; @@ -81,6 +82,42 @@ public class SummaryService : ISummaryService }; } + public async Task GetDoorHomeDataAsync() + { + var devices = await _dbContext.Queryable().Where(x => x.Type == DeviceTypeEnumType.Door).ToListAsync(); + + var offDevices = await GetOfflineDevicesCount(devices); + + //获取近30天并转化为"yyyy-MM-dd"集合 + DateTime currentDate = DateTime.Now; + List times = new List(); + for (int i = 0; i < 30; i++) + { + DateTime date = currentDate.AddDays(-i); + string dateString = date.ToString("yyyy-MM-dd"); + times.Add(dateString); + } + + var list = new List(); + times.ForEach(time => + { + var count = devices.Where(x => x.CreateTime.ToString("yyyy-MM-dd") == time).Count(); + var trend = new TrendDto + { + Date = DateTime.ParseExact(time, "yyyy-MM-dd", null), + Count = count, + }; + list.Add(trend); + }); + var res = new DoorHomeDataResponse + { + OffNum = offDevices.Count, + TotalNum = devices.Count, + Trend = list + }; + return res; + } + private static List FixTrend(IEnumerable dtos, DateTime start, DateTime end) { var result = dtos.ToList(); @@ -104,4 +141,49 @@ public class SummaryService : ISummaryService return result.OrderBy(x => x.Date).ToList(); } + + /// + /// 获取离线设备 + /// + /// + private async Task> GetOfflineDevicesCount(List devices) + { + var now = DateTime.Now; + + var deviceUniqueNos = devices.Select(x => x.UniqueNo).ToList(); + + var deviceRegistries = await _dbContext.Queryable() + .LeftJoin((x, d) => x.DeviceUniqueNo == d.UniqueNo) + .Where(x => deviceUniqueNos.Contains(x.DeviceUniqueNo)) + .Select((x, d) => new + { + UniqueNo = d.UniqueNo, + d.HeartbeatInterval, + x.LastHeartbeatTime + }) + .ToListAsync(); + + var OnlineDevices = deviceRegistries + .Where(x => + { + if (x.HeartbeatInterval <= 0) + { + return true; + } + + return x.LastHeartbeatTime.AddSeconds(x.HeartbeatInterval * 3) >= now; + + }) + .Select(x => new + { + UniqueNo = x.UniqueNo, + }) + .ToList(); + var onlineUniqueNos = new List(); + OnlineDevices.ForEach(x => onlineUniqueNos.Add(x.UniqueNo)); + + var offUniqueNos = deviceUniqueNos.Except(onlineUniqueNos).ToList(); + var list = devices.Where(x => offUniqueNos.Contains(x.UniqueNo)).ToList(); + return list; + } } From 990fc247bc45d8982a22d6987d34a85347e8e1d2 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 7 Mar 2024 17:26:46 +0800 Subject: [PATCH 144/146] =?UTF-8?q?fix=20type=E4=BF=AE=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Request/DeviceTaskAssignmentRequest.cs | 9 ++++++++- .../Services/Implements/DeviceTaskAssignmentService.cs | 9 +++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Request/DeviceTaskAssignmentRequest.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Request/DeviceTaskAssignmentRequest.cs index d41b722e..fee03043 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Request/DeviceTaskAssignmentRequest.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Request/DeviceTaskAssignmentRequest.cs @@ -6,11 +6,18 @@ namespace Dlhis.ScheduledTask.TaskAssignment.Request; public class DeviceTaskAssignmentRequest : PageDto { + /// + /// 设备类型 + /// + [EnumDataType(typeof(DeviceTypeEnumType))] + public DeviceTypeEnumType? Type { get; set; } + + /// /// 任务类型 /// [EnumDataType(typeof(DeviceTaskEnumType))] - public DeviceTaskEnumType? Type { get; set; } + public DeviceTaskEnumType? TaskType { get; set; } /// /// 任务下发状态 diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs index 979f2b17..f194ca21 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs @@ -27,13 +27,14 @@ public class DeviceTaskAssignmentService : IDeviceTaskAssignmentService { var page = await _dbContext.Queryable() .LeftJoin((deviceTask, ga) => deviceTask.UserNo == ga.No) - .LeftJoin((deviceTask, ga,device) => deviceTask.DeviceUniqueNo == device.UniqueNo) - .WhereIF(!request.Search.IsEmpty(), (deviceTask, ga,device) => deviceTask.UserNo == request.Search || ga.Name.Contains(request.Search) || ga.Code == request.Search || deviceTask.DeviceUniqueNo == request.Search || deviceTask.ModifiedTime.ToString("yyyy-MM-dd").Contains(request.Search)) - .WhereIF(request.Type.HasValue, deviceTask => deviceTask.Type == request.Type) + .LeftJoin((deviceTask, ga, device) => deviceTask.DeviceUniqueNo == device.UniqueNo) + .WhereIF(!request.Search.IsEmpty(), (deviceTask, ga, device) => deviceTask.UserNo == request.Search || ga.Name.Contains(request.Search) || ga.Code == request.Search || deviceTask.DeviceUniqueNo == request.Search || deviceTask.ModifiedTime.ToString("yyyy-MM-dd").Contains(request.Search)) + .WhereIF(request.TaskType.HasValue, deviceTask => deviceTask.Type == request.TaskType) + .WhereIF(request.Type.HasValue, (deviceTask, ga, device) => device.Type == request.Type) .WhereIF(request.Status.HasValue, deviceTask => deviceTask.Status == request.Status) .Where(deviceTask => 1 == 1) .OrderBy(deviceTask => deviceTask.CreateTime, OrderByType.Desc) - .Select((deviceTask, ga,device) => new DeviceTaskAssignmentResponse + .Select((deviceTask, ga, device) => new DeviceTaskAssignmentResponse { Id = deviceTask.Id, DeviceUniqueNo = deviceTask.DeviceUniqueNo, From 538fe7c4b456c15595959a77f1e60f38139cbd08 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 7 Mar 2024 21:34:04 +0800 Subject: [PATCH 145/146] =?UTF-8?q?fix=20=E4=BC=98=E5=8C=96=E6=A1=A3?= =?UTF-8?q?=E6=A1=88=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Organization/Request/GainfoPageRequest.cs | 4 +-- .../Request/TenantDepartmentRequest.cs | 14 +++++++++++ .../Services/Implements/GainfoService.cs | 25 ++++++++++++------- .../Request/DeviceUploadLogPageRequest.cs | 24 +++++++++--------- .../Implements/DeviceTaskAssignmentService.cs | 7 +++++- .../Services/Implements/TenantService.cs | 16 ++++++------ 6 files changed, 59 insertions(+), 31 deletions(-) create mode 100644 Src/Dlhis.Basic/Organization/Request/TenantDepartmentRequest.cs diff --git a/Src/Dlhis.Basic/Organization/Request/GainfoPageRequest.cs b/Src/Dlhis.Basic/Organization/Request/GainfoPageRequest.cs index 37cc810f..c9a13210 100644 --- a/Src/Dlhis.Basic/Organization/Request/GainfoPageRequest.cs +++ b/Src/Dlhis.Basic/Organization/Request/GainfoPageRequest.cs @@ -13,7 +13,7 @@ public class GainfoPageRequest : PageDto public GainfoStatusEnumType? Status { get; set; } = GainfoStatusEnumType.Working; /// - /// 部门号(部门树传入) + /// 部门选择 /// - public List DepartmentNos { get; set; } + public List DepartmentSelections { get; set; } = new List(); } diff --git a/Src/Dlhis.Basic/Organization/Request/TenantDepartmentRequest.cs b/Src/Dlhis.Basic/Organization/Request/TenantDepartmentRequest.cs new file mode 100644 index 00000000..b2bff024 --- /dev/null +++ b/Src/Dlhis.Basic/Organization/Request/TenantDepartmentRequest.cs @@ -0,0 +1,14 @@ +using System.ComponentModel.DataAnnotations; + +namespace Dlhis.Basic.Organization.Request; + +public class TenantDepartmentRequest +{ + [Required] + public string Tenant { get; set; } + + /// + /// 部门号(部门树传入) + /// + public List DepartmentNos { get; set; } +} diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs index 7997ceb8..c7ceda84 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs @@ -4,19 +4,17 @@ using Dlhis.Basic.Organization.Response; using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Basic.Enums; using Dlhis.Entity.Device.Enums; -using Kurisu.AspNetCore.Scope; -using Kurisu.AspNetCore.UnifyResultAndValidation; using Kurisu.AspNetCore.Utils; using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.DataAccess.Dto; using Kurisu.Core.User.Abstractions; using Kurisu.SqlSugar.Extensions; -using Kurisu.SqlSugar.Options; using Kurisu.SqlSugar.Services; using Mapster; using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Mvc; using System.IdentityModel.Tokens.Jwt; +using System.Linq.Expressions; namespace Dlhis.Basic.Organization.Services.Implements; @@ -57,10 +55,22 @@ public class GainfoService : IGainfoService /// public async Task> GetPageAsync(GainfoPageRequest request) { - request.DepartmentNos = await GetRecursionDepartmentNosAsync(request.DepartmentNos); + var currentTenantId = _currentUser.GetStringTenantId(); + + //根据组织架构搜索档案 + Expression> where = LinqExpressionExtension.False(); + foreach (var item in request.DepartmentSelections) + { + var depts = await GetRecursionDepartmentNosAsync(item.DepartmentNos); + if (depts.Any()) + where = where.Or(gainfo => gainfo.Factory == item.Tenant && depts.Contains(gainfo.DepartmentNo)); + else + where = where.Or(gainfo => gainfo.Factory == item.Tenant); + } var page = await _gainfoStore.Queryable(request.Status) - .WhereIF(request.DepartmentNos.IsPresent(), gainfo => request.DepartmentNos.Contains(gainfo.DepartmentNo)) + .WhereIF(request.DepartmentSelections.IsPresent(), where) + .WhereIF(request.DepartmentSelections.IsEmpty(), gainfo => gainfo.Factory == currentTenantId) .WhereIF(request.Search.IsPresent(), gainfo => gainfo.Name.Contains(request.Search) || gainfo.Code.Contains(request.Search) @@ -574,13 +584,10 @@ public class GainfoService : IGainfoService void RecursionGetNext(string currentCode, List departments, List result) { var next = departments.Where(x => x.PNo == currentCode).ToList(); - foreach (var item in next) - { - result.Add(item.No); - } foreach (var item in next) { + result.Add(item.No); RecursionGetNext(item.No, departments, result); } } diff --git a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Request/DeviceUploadLogPageRequest.cs b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Request/DeviceUploadLogPageRequest.cs index 37aef592..670a5411 100644 --- a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Request/DeviceUploadLogPageRequest.cs +++ b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Request/DeviceUploadLogPageRequest.cs @@ -20,7 +20,7 @@ public class DeviceUploadLogPageRequest : PageDto, IValidatableObject public IEnumerable Validate(ValidationContext validationContext) { - var now = DateTime.Now; + var today = DateTime.Today; if (SearchDateTimeDimension.HasValue) { //重新赋值 @@ -28,37 +28,37 @@ public class DeviceUploadLogPageRequest : PageDto, IValidatableObject if (SearchDateTimeDimension == DateTimeSearchEnumType.Day) { - SearchDateTimePeriod.Start = new DateTime(now.Year, now.Month, now.Day, 0, 0, 1); - SearchDateTimePeriod.End = new DateTime(now.Year, now.Month, now.Day, 23, 59, 59); + SearchDateTimePeriod.Start = today; + SearchDateTimePeriod.End = today.AddDays(1).AddSeconds(-1); } else if (SearchDateTimeDimension == DateTimeSearchEnumType.Week) { - SearchDateTimePeriod.Start = now.AddDays(1 - (int)now.DayOfWeek); + SearchDateTimePeriod.Start = today.AddDays(1 - (int)today.DayOfWeek); SearchDateTimePeriod.End = SearchDateTimePeriod.Start.Value.AddDays(6); } else if (SearchDateTimeDimension == DateTimeSearchEnumType.Month) { - SearchDateTimePeriod.Start = new DateTime(now.Year, now.Month, 1); + SearchDateTimePeriod.Start = new DateTime(today.Year, today.Month, 1); SearchDateTimePeriod.End = SearchDateTimePeriod.Start.Value.AddMonths(1).AddDays(-1); } else if (SearchDateTimeDimension == DateTimeSearchEnumType.Season) { - SearchDateTimePeriod.Start = now.AddMonths(0 - ((now.Month - 1) % 3)); - SearchDateTimePeriod.End = now.AddMonths(3 - ((now.Month - 1) % 3)).AddMonths(1).AddDays(-1); + SearchDateTimePeriod.Start = new DateTime(today.Year, today.Month, 1).AddMonths(2 - ((today.Month - 1) % 3)); + SearchDateTimePeriod.End = SearchDateTimePeriod.Start.Value.AddMonths(2); } else if (SearchDateTimeDimension == DateTimeSearchEnumType.HalfOfYear) { - SearchDateTimePeriod.Start = now.AddDays(-180); - SearchDateTimePeriod.End = now; + SearchDateTimePeriod.Start = today.AddDays(-180); + SearchDateTimePeriod.End = today; } else if (SearchDateTimeDimension == DateTimeSearchEnumType.Year) { - SearchDateTimePeriod.Start = new DateTime(now.Year, 1, 1); + SearchDateTimePeriod.Start = new DateTime(today.Year, 1, 1); SearchDateTimePeriod.End = SearchDateTimePeriod.Start.Value.AddYears(1).AddDays(-1); } - SearchDateTimePeriod.Start = SearchDateTimePeriod.Start.Value.Date; - SearchDateTimePeriod.End = SearchDateTimePeriod.End.Value.Date; + SearchDateTimePeriod.Start = SearchDateTimePeriod.Start.Value; + SearchDateTimePeriod.End = SearchDateTimePeriod.End.Value; } yield break; diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs index f194ca21..2b8d28f8 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs @@ -28,7 +28,12 @@ public class DeviceTaskAssignmentService : IDeviceTaskAssignmentService var page = await _dbContext.Queryable() .LeftJoin((deviceTask, ga) => deviceTask.UserNo == ga.No) .LeftJoin((deviceTask, ga, device) => deviceTask.DeviceUniqueNo == device.UniqueNo) - .WhereIF(!request.Search.IsEmpty(), (deviceTask, ga, device) => deviceTask.UserNo == request.Search || ga.Name.Contains(request.Search) || ga.Code == request.Search || deviceTask.DeviceUniqueNo == request.Search || deviceTask.ModifiedTime.ToString("yyyy-MM-dd").Contains(request.Search)) + .WhereIF(!request.Search.IsEmpty(), (deviceTask, ga, device) => + deviceTask.UserNo == request.Search + || ga.Name.Contains(request.Search) + || ga.Code == request.Search + || deviceTask.DeviceUniqueNo == request.Search + ) .WhereIF(request.TaskType.HasValue, deviceTask => deviceTask.Type == request.TaskType) .WhereIF(request.Type.HasValue, (deviceTask, ga, device) => device.Type == request.Type) .WhereIF(request.Status.HasValue, deviceTask => deviceTask.Status == request.Status) diff --git a/Src/Dlhis.Sys/Identity/Services/Implements/TenantService.cs b/Src/Dlhis.Sys/Identity/Services/Implements/TenantService.cs index 9302cc6e..ecb8795b 100644 --- a/Src/Dlhis.Sys/Identity/Services/Implements/TenantService.cs +++ b/Src/Dlhis.Sys/Identity/Services/Implements/TenantService.cs @@ -1,5 +1,4 @@ -using Dlhis.Entity.Basic.Entity; -using Dlhis.Entity.Sys.Entities; +using Dlhis.Entity.Sys.Entities; using Dlhis.Sys.Identity.Request; using Dlhis.Sys.Identity.Response; using Kurisu.AspNetCore.Utils.Extensions; @@ -71,23 +70,26 @@ public class TenantService : ITenantService public async Task> GetMyTenantsAsync() { var userId = _currentUser.GetIntSubjectId(); + 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(); - if (myTenants.IsEmpty()) - { - myTenants = await GetListAsync(); - } + var currentTenant = myTenants.First(x => x.Code == tenantId); + var otherTenants = myTenants.Where(x => x.Code != tenantId); - return myTenants; + var result = new List { currentTenant }; + result.AddRange(otherTenants); + return result; } public async Task> GetTreeAsync() From 4fa49efeac4de2281c15b696c0e3c0530f84d6fe Mon Sep 17 00:00:00 2001 From: liguoyang Date: Fri, 8 Mar 2024 10:30:29 +0800 Subject: [PATCH 146/146] =?UTF-8?q?fix=20=E6=9D=83=E9=99=90=E5=88=86?= =?UTF-8?q?=E9=85=8DtenantId=E9=94=99=E8=AF=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/DevicePermissionService.cs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs index 91019ab8..d46ac987 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs @@ -27,23 +27,23 @@ public class DevicePermissionService : IDevicePermissionService public async Task AssignAsync(DevicePermissionSaveReuqest reuqest) { + 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(); + + await _dbContext.DeleteReallyAsync(p); + await GenerateDeviceTasksAsync(async () => { - //删除当前匹配的基地权限 - var p = await _dbContext.Queryable() - .Where(x => x.AssignType == reuqest.AssignType) - .Where(x => x.AssignValue == reuqest.AssignValue) - .Where(x => x.UniqueType == reuqest.UniqueType) - .WhereIF(reuqest.AssignType == AssignTypeEnumType.Department, x => x.TenantId == reuqest.TenantId) - .ToListAsync(); - - await _dbContext.DeleteReallyAsync(p); - //保存配置的权限 if (reuqest.Codes.IsPresent()) { - var tenantId = reuqest.AssignType == AssignTypeEnumType.Department ? reuqest.TenantId : _currentUser.GetStringSubjectId(); - var devicePermissions = reuqest.Codes.Select(code => new DevicePermissionEntity { AssignType = reuqest.AssignType,