fix 优化批量处理逻辑

This commit is contained in:
2025-01-06 10:57:04 +08:00
parent a915492d27
commit a9d284b43c
6 changed files with 28 additions and 56 deletions

View File

@@ -45,17 +45,7 @@ public class GainfoCardsController : ControllerBase
{
return await _gainfoCardService.GetChangeRecordsAsync(userNo);
}
/// <summary>
/// 获取卡类型
/// </summary>
/// <returns></returns>
[HttpGet("cardTypes")]
public async Task<List<KeyValueDto<string, string>>> GetCardTypesAsync()
{
return await _gainfoCardService.GetCardTypesAsync();
}
/// <summary>
/// 编辑卡类型
/// </summary>
@@ -63,7 +53,6 @@ public class GainfoCardsController : ControllerBase
[HttpPost("cardType")]
public async Task EditCardTypeAsync(GainfoCardEditRequest request)
{
//string code, int typeId
await _gainfoCardService.EditCardTypeAsync(request.UserCode, request.CardType);
await _gainfoCardService.EditCardTypeAsync(request.UserCodes, request.CardType);
}
}

View File

@@ -7,8 +7,8 @@ public class GainfoCardEditRequest
/// <summary>
/// 工号
/// </summary>
[Required(ErrorMessage = "工号不能为空")]
public string UserCode { get; set; }
[MinLength(1, ErrorMessage = "工号不能为空")]
public List<string> UserCodes { get; set; }
/// <summary>
/// 卡类型

View File

@@ -1,6 +1,5 @@
using Dlhis.Basic.Organization.Request;
using Dlhis.Basic.Organization.Response;
using Kurisu.AspNetCore.CustomClass;
namespace Dlhis.Basic.Organization.Services;
@@ -20,17 +19,11 @@ public interface IGainfoCardService : IScopeDependency
/// <returns></returns>
Task<List<ChangeCardResponse>> GetChangeRecordsAsync(string userNo);
/// <summary>
/// 获取卡类型
/// </summary>
/// <returns></returns>
Task<List<KeyValueDto<string, string>>> GetCardTypesAsync();
/// <summary>
/// 编辑卡类型
/// </summary>
/// <param name="code"></param>
/// <param name="userCodes"></param>
/// <param name="typeId"></param>
/// <returns></returns>
Task EditCardTypeAsync(string code, int typeId);
Task EditCardTypeAsync(List<string> userCodes, int typeId);
}

View File

@@ -3,7 +3,6 @@ using Dlhis.Basic.Organization.Request;
using Dlhis.Basic.Organization.Response;
using Dlhis.Entity.Basic.Entity;
using Dlhis.Entity.Device.Enums;
using Kurisu.AspNetCore.CustomClass;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
using Kurisu.AspNetCore.Utils.Extensions;
using Mapster;
@@ -14,17 +13,17 @@ public class GainfoCardService : IGainfoCardService
{
private readonly IDbContext _dbContext;
private readonly IGainfoStore _gainfoStore;
private readonly IDevicePermissionService _devicePermissionService;
private readonly IDevicePermissionAnalyzeService _devicePermissionAnalyzeService;
private readonly IGainfoPermissionService _gainfoPermissionService;
public GainfoCardService(IDbContext dbContext,
IGainfoStore gainfoStore,
IDevicePermissionService devicePermissionService,
IDevicePermissionAnalyzeService devicePermissionAnalyzeService,
IGainfoPermissionService gainfoPermissionService)
{
_dbContext = dbContext;
_gainfoStore = gainfoStore;
_devicePermissionService = devicePermissionService;
_devicePermissionAnalyzeService = devicePermissionAnalyzeService;
_gainfoPermissionService = gainfoPermissionService;
}
@@ -57,36 +56,28 @@ public class GainfoCardService : IGainfoCardService
.ToListAsync();
}
public async Task<List<KeyValueDto<string, string>>> GetCardTypesAsync()
public async Task EditCardTypeAsync(List<string> userCodes, int typeId)
{
var r = new List<KeyValueDto<string, string>>
var gainfos = await _dbContext.Queryable<GainfoEntity>().Where(x => userCodes.Contains(x.Code)).ToListAsync();
(gainfos.Count == userCodes.Count).ThrowIfFalse("人员不存在");
var result = await _devicePermissionAnalyzeService.GetUserAssignDeviceCodesWithTypeInTenantAsync(gainfos.Select(x => x.No).ToList());
foreach (var gainfo in gainfos)
{
new()
{
Key = "行政卡", Value = "2"
},
new()
{
Key = "车间卡", Value = "3"
}
};
var userNo = gainfo.No;
var myDeviceCodes = result[userNo].SelectMany(x => x.AssignTypes.SelectMany(p => p.Codes)).Distinct().ToList();
return await Task.FromResult(r);
}
var deviceCodes = await _dbContext.Queryable<DeviceEntity>()
.Where(x => myDeviceCodes.Contains(x.Code))
.Where(x => x.EnableTimePeriod)
.Select(x => x.Code)
.ToListAsync();
public async Task EditCardTypeAsync(string code, int typeId)
{
var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.Code == code).SingleAsync();
gainfo.ThrowIfNull("人员不存在");
gainfo.CardType = typeId;
await _gainfoPermissionService.ResetPermissionsAsync(userNo, DeviceTaskEnumType.Update, deviceCodes, "卡类型编辑下发");
gainfo.CardType = typeId;
}
var myDeviceCodes = await _devicePermissionService.GetUserDeviceCodesByNoAsync(gainfo.No);
var deviceCodes = await _dbContext.Queryable<DeviceEntity>()
.Where(x => myDeviceCodes.Contains(x.Code))
.Where(x => x.EnableTimePeriod)
.Select(x => x.Code)
.ToListAsync();
await _gainfoPermissionService.ResetPermissionsAsync(gainfo.No, DeviceTaskEnumType.Update, deviceCodes, "卡类型编辑下发");
await _dbContext.UpdateAsync(gainfos);
}
}

View File

@@ -33,6 +33,7 @@ public class DeviceTaskEntity : SugarBaseEntity, ITenantId, IVersion
/// <summary>
/// 用户档案号
/// </summary>
[SugarColumn(IsNullable = true)]
public string UserNo { get; set; }
/// <summary>

View File

@@ -262,8 +262,6 @@ public class AssignmentService : IAssignmentService
.WhereIF(request.Brand.IsPresent(), (deviceTask, device, deviceTemplate) => deviceTemplate.Brand == request.Brand)
.Where((deviceTask, device, deviceTemplate, ga, gaLeave, department, deviceRegistry) =>
device.HeartbeatInterval == 0 || SqlFunc.DateAdd(deviceRegistry.LastHeartbeatTime, device.HeartbeatInterval, DateType.Second) > DateTime.Now)
#if !DEBUG
#endif
.OrderBy(deviceTask => new { deviceTask.CreateTime, Priority = SqlFunc.Desc(deviceTask.Priority) })
.Select((deviceTask, device, deviceTemplate, ga, gaLeave, department) => new TaskDto
{