diff --git a/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs b/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs index 5f3d9cea..41dbf10f 100644 --- a/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs +++ b/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs @@ -1,8 +1,13 @@ using Dlhis.Basic.Device.Request; using Dlhis.Basic.Device.Response; using Dlhis.Basic.Device.Services; +using Dlhis.Entity.Basic.Entity; +using Dlhis.Entity.Basic.Enums; +using Dlhis.Entity.Device.Entities; +using Dlhis.Entity.Device.Enums; using Kurisu.AspNetCore.DataAccess.Dto; using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop; +using Kurisu.AspNetCore.DataAccess.SqlSugar.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -18,15 +23,18 @@ public class DevicesController : ControllerBase { private readonly IDeviceService _deviceService; private readonly IDeviceTemplateService _deviceTemplateService; + private readonly IDbContext _dbContext; private readonly IDeviceConnectService _deviceConnectService; private readonly IConfiguration _configuration; public DevicesController(IDeviceService deviceService, IDeviceTemplateService deviceTemplateService, + IDbContext dbContext, IDeviceConnectService deviceConnectService, IConfiguration configuration) { _deviceService = deviceService; _deviceTemplateService = deviceTemplateService; + _dbContext = dbContext; _deviceConnectService = deviceConnectService; _configuration = configuration; } @@ -79,7 +87,7 @@ public class DevicesController : ControllerBase { return await _deviceConnectService.RegisterAsync(request); } - + /// /// 获取激活码 /// @@ -160,4 +168,70 @@ public class DevicesController : ControllerBase { await _deviceService.ImportAsync(request); } + + [HttpPost("test")] + [IgnoreTenant] + [AllowAnonymous] + public async Task Test() + { + var tasks = new List(); + + var devices = await _dbContext.Queryable().Where(x => x.TenantId == "2401").Where(x => x.Type == DeviceTypeEnumType.Meal).ToListAsync(); + + var gainfos = await _dbContext.Queryable() + .Where(x => x.Type == GainfoUserTypeEnumType.External || x.Type == GainfoUserTypeEnumType.Outsource) + .Where(x => x.Factory == "2401") + .ToListAsync(); + + var gainfoLeaves = await _dbContext.Queryable() + .Where(x => x.Type == GainfoUserTypeEnumType.External || x.Type == GainfoUserTypeEnumType.Outsource) + .Where(x => x.Factory == "2401") + .ToListAsync(); + + foreach (var device in devices) + { + foreach (var gainfo in gainfos) + { + tasks.Add(new DeviceTaskEntity + { + Type = DeviceTaskEnumType.Delete, + DeviceType = DeviceTypeEnumType.Meal, + UserId = gainfo.Id, + UserNo = gainfo.No, + DeviceUniqueNo = device.UniqueNo, + Status = DeviceTaskStatusEnumType.Wait, + Version = 0, + ResultMessage = null, + Source = "主动删除2401异常餐饮人员", + Priority = 0, + TenantId = device.TenantId + }); + } + + foreach (var gainfo in gainfoLeaves) + { + tasks.Add(new DeviceTaskEntity + { + Type = DeviceTaskEnumType.Delete, + DeviceType = DeviceTypeEnumType.Meal, + UserId = gainfo.IdentityUserId, + UserNo = gainfo.No, + DeviceUniqueNo = device.UniqueNo, + Status = DeviceTaskStatusEnumType.Wait, + Version = 0, + ResultMessage = null, + Source = "主动删除2401异常餐饮人员", + Priority = 0, + TenantId = device.TenantId + }); + } + } + + foreach (var items in tasks.Chunk(1000)) + { + await _dbContext.InsertAsync(items); + } + + return tasks.Count; + } } \ No newline at end of file