feat 权限重置
This commit is contained in:
@@ -3,6 +3,7 @@ using Dlhis.Basic.Organization.Request;
|
|||||||
using Dlhis.Basic.Organization.Response;
|
using Dlhis.Basic.Organization.Response;
|
||||||
using Dlhis.Basic.Organization.Services;
|
using Dlhis.Basic.Organization.Services;
|
||||||
using Dlhis.Basic.Places.Response;
|
using Dlhis.Basic.Places.Response;
|
||||||
|
using Dlhis.Entity.Device.Enums;
|
||||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
@@ -65,4 +66,16 @@ public class GainfoPermissionsController : ControllerBase
|
|||||||
{
|
{
|
||||||
return await _gainfoPermissions.GetAssignGroupAsync(userNo);
|
return await _gainfoPermissions.GetAssignGroupAsync(userNo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 权限重置
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[Authorize(Roles = "admin")]
|
||||||
|
[HttpPost("reset")]
|
||||||
|
public async Task<DevicePermissionAssignResponse> ResetPermissionsAsync(GainfoPermissionResetRequest request)
|
||||||
|
{
|
||||||
|
return await _gainfoPermissions.ResetPermissionsAsync(request.UserNo, request.Status ? DeviceTaskEnumType.Add : DeviceTaskEnumType.Delete, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace Dlhis.Basic.Organization.Request;
|
||||||
|
|
||||||
|
public class GainfoPermissionResetRequest
|
||||||
|
{
|
||||||
|
[Required]
|
||||||
|
public string UserNo { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// true下发所有,false删除所有
|
||||||
|
/// </summary>
|
||||||
|
public bool Status { get; set; }
|
||||||
|
}
|
||||||
@@ -17,5 +17,5 @@ public interface IGainfoPermissionService : IScopeDependency
|
|||||||
|
|
||||||
Task<List<DeviceGroupTreeResponse>> GetAssignGroupAsync(string userNo);
|
Task<List<DeviceGroupTreeResponse>> GetAssignGroupAsync(string userNo);
|
||||||
|
|
||||||
Task ResetPermissionsAsync(string userNo, DeviceTaskEnumType type, List<Guid> deviceCodes);
|
Task<DevicePermissionAssignResponse> ResetPermissionsAsync(string userNo, DeviceTaskEnumType type, List<Guid> deviceCodes);
|
||||||
}
|
}
|
||||||
@@ -33,7 +33,7 @@ public class GainfoPermissionService : IGainfoPermissionService
|
|||||||
{
|
{
|
||||||
var gainfo = await _gainfoStore.Queryable()
|
var gainfo = await _gainfoStore.Queryable()
|
||||||
.Where(x => x.No == request.UserNo)
|
.Where(x => x.No == request.UserNo)
|
||||||
.FirstAsync();
|
.SingleAsync();
|
||||||
|
|
||||||
if (gainfo == null)
|
if (gainfo == null)
|
||||||
{
|
{
|
||||||
@@ -77,7 +77,7 @@ public class GainfoPermissionService : IGainfoPermissionService
|
|||||||
return new List<GetDevicesUnderGroupByUserNoResponse>();
|
return new List<GetDevicesUnderGroupByUserNoResponse>();
|
||||||
}
|
}
|
||||||
|
|
||||||
var groups = RecursionGetNext(currentGroup, deviceGroups).ToList();
|
var groups = RecursionHelper.HandlerDeviceGroupNextCodes(currentGroup.Code, deviceGroups);
|
||||||
|
|
||||||
return groups.Select(groupCode =>
|
return groups.Select(groupCode =>
|
||||||
{
|
{
|
||||||
@@ -191,7 +191,7 @@ public class GainfoPermissionService : IGainfoPermissionService
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task ResetPermissionsAsync(string userNo, DeviceTaskEnumType type, List<Guid> deviceCodes)
|
public async Task<DevicePermissionAssignResponse> ResetPermissionsAsync(string userNo, DeviceTaskEnumType type, List<Guid> deviceCodes)
|
||||||
{
|
{
|
||||||
var gainfo = await _dbContext.Queryable<GainfoEntity>()
|
var gainfo = await _dbContext.Queryable<GainfoEntity>()
|
||||||
.Where(x => x.No == userNo)
|
.Where(x => x.No == userNo)
|
||||||
@@ -230,10 +230,14 @@ public class GainfoPermissionService : IGainfoPermissionService
|
|||||||
DeviceType = x.Type,
|
DeviceType = x.Type,
|
||||||
TenantId = x.TenantId,
|
TenantId = x.TenantId,
|
||||||
Priority = 10,
|
Priority = 10,
|
||||||
Source = DeviceTaskSourceEnumType.Manually
|
Source = DeviceTaskSourceEnumType.Manually,
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
await _dbContext.InsertAsync(tasks);
|
await _dbContext.InsertAsync(tasks);
|
||||||
|
|
||||||
|
var addCount = type == DeviceTaskEnumType.Add ? tasks.Count : 0;
|
||||||
|
var deleteCount = type == DeviceTaskEnumType.Delete ? tasks.Count : 0;
|
||||||
|
return new DevicePermissionAssignResponse(addCount, deleteCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -252,17 +256,4 @@ public class GainfoPermissionService : IGainfoPermissionService
|
|||||||
.Select<DeviceGroupTreeResponse>()
|
.Select<DeviceGroupTreeResponse>()
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
//**********************************************************************************************************************************************
|
|
||||||
|
|
||||||
private static IEnumerable<Guid> RecursionGetNext(DeviceGroupEntity current, List<DeviceGroupEntity> deviceGroups)
|
|
||||||
{
|
|
||||||
var next = deviceGroups.Where(x => x.PCode == current.Code).ToList();
|
|
||||||
foreach (var item in next)
|
|
||||||
{
|
|
||||||
RecursionGetNext(item, deviceGroups);
|
|
||||||
}
|
|
||||||
|
|
||||||
yield return current.Code;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user