fix 优化分配出差组和例外批量删除

This commit is contained in:
2025-04-24 11:57:10 +08:00
parent 289c6eccc2
commit d96cd44ffd
4 changed files with 56 additions and 27 deletions

View File

@@ -53,4 +53,14 @@ public class DevicePermissionManuallyController : ControllerBase
{
await _devicePermissionService.DeleteAsync(id);
}
/// <summary>
/// 删除权限
/// </summary>
/// <param name="ids"></param>
[HttpPost("batchDelete")]
public async Task DeleteAsync(List<long> ids)
{
await _devicePermissionService.DeleteAsync(ids);
}
}

View File

@@ -29,4 +29,11 @@ public interface IDevicePermissionManuallyService : IScopeDependency
/// <param name="id"></param>
/// <returns></returns>
Task DeleteAsync(long id);
/// <summary>
/// 批量删除
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
Task DeleteAsync(List<long> ids);
}

View File

@@ -152,7 +152,6 @@ public class DeviceGroupService : IDeviceGroupService
else
{
//当前组没有tenant级别
var currentAssignedToOthers = await _dbContext.Queryable<DevicePermissionEntity>()
.Where(x => x.AssignType != AssignTypeEnumType.Tenant)
.Where(x => x.UniqueType == DeviceAssignmentTypeEnumType.Group)
@@ -170,7 +169,7 @@ public class DeviceGroupService : IDeviceGroupService
.Where(x => x.AssignType == AssignTypeEnumType.Tenant)
.Where(x => x.UniqueType == DeviceAssignmentTypeEnumType.Group)
.Where(x => groupCodes.Contains(x.UniqueValue))
.AnyAsync() && currentAssignedToOthers)
.AnyAsync() && currentAssignedToOthers && group.IsBusinessTrip == false)
{
true.ThrowIfTrue("存在设备所在的分组已分配到厂区级别,但当前分组存在其他级别的分配");
}

View File

@@ -1,6 +1,7 @@
using Dlhis.Basic.Device.Request;
using Dlhis.Basic.Device.Response;
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;
@@ -46,7 +47,8 @@ public class DevicePermissionManuallyService : IDevicePermissionManuallyService
var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.No == request.UserNo).SingleAsync();
gainfo.ThrowIfNull("人员不存在");
//var types = new List<GainfoUserTypeEnumType> { GainfoUserTypeEnumType.Normal, GainfoUserTypeEnumType.SecurityWhite };
//types.Contains(gainfo.Type).ThrowIfFalse($"人员类型为:{gainfo.Type.GetDescription()},无法分配");
await _dbContext.InsertAsync(new DevicePermissionManuallyEntity
{
@@ -73,32 +75,43 @@ public class DevicePermissionManuallyService : IDevicePermissionManuallyService
/// <inheritdoc />
public async Task DeleteAsync(long id)
{
var data = await _dbContext.Queryable<DevicePermissionManuallyEntity>().Where(x => x.Id == id).SingleAsync();
data.ThrowIfNull("数据不存在");
await DeleteAsync(new List<long> { id });
}
var device = await _dbContext.Queryable<DeviceEntity>().Where(x => x.Code == data.DeviceCode).SingleAsync();
if (device != null)
public async Task DeleteAsync(List<long> ids)
{
var data = await _dbContext.Queryable<DevicePermissionManuallyEntity>().Where(x => ids.Contains(x.Id)).ToListAsync();
var deviceCodes = data.Select(x => x.DeviceCode).Distinct().ToList();
var devices = await _dbContext.Queryable<DeviceEntity>().Where(x => deviceCodes.Contains(x.Code)).ToListAsync();
foreach (var item in data)
{
var userNo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.No == data.UserNo).Select(x => x.No).SingleAsync();
if (userNo.IsPresent())
{
await _dbContext.InsertAsync(new DeviceTaskEntity
{
Type = DeviceTaskEnumType.Delete,
DeviceType = device.Type,
UserId = null,
UserNo = userNo,
DeviceUniqueNo = device.UniqueNo,
Status = DeviceTaskStatusEnumType.Wait,
Version = 0,
ResultMessage = null,
Source = "手动分配额外权限",
Priority = 0,
TenantId = device.TenantId
});
}
}
var userInfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.No == item.UserNo).Select(x => new { x.Id, x.No }).SingleAsync()
?? await _dbContext.Queryable<GainfoLeaveEntity>().Where(x => x.No == item.UserNo).Select(x => new { Id = (long)x.IdentityUserId, x.No }).SingleAsync();
await _dbContext.DeleteAsync(data);
if (userInfo != null)
{
var device = devices.FirstOrDefault(x => x.Code == item.DeviceCode);
if (device != null)
{
await _dbContext.InsertAsync(new DeviceTaskEntity
{
Type = DeviceTaskEnumType.Delete,
DeviceType = device.Type,
UserId = userInfo.Id,
UserNo = userInfo.No,
DeviceUniqueNo = device.UniqueNo,
Status = DeviceTaskStatusEnumType.Wait,
Version = 0,
ResultMessage = null,
Source = "手动分配额外权限",
Priority = 0,
TenantId = device.TenantId
});
}
}
await _dbContext.DeleteAsync(item);
}
}
}