fix 组织架构树调整
This commit is contained in:
@@ -27,6 +27,7 @@ public class DevicePermissionsController : ControllerBase
|
||||
/// <returns></returns>
|
||||
[HttpPost("assign")]
|
||||
[Transactional]
|
||||
[IgnoreTenant]
|
||||
public async Task AssignAsync(DevicePermissionSaveReuqest request)
|
||||
{
|
||||
await _devicePermissionService.AssignAsync(request);
|
||||
|
||||
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// 分配类型 AssignTypeEnumType
|
||||
@@ -30,4 +31,20 @@ public class DevicePermissionSaveReuqest
|
||||
/// 分配权限值
|
||||
/// </summary>
|
||||
public List<Guid> Codes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// AssignType == AssignTypeEnumType.Department 需要传入
|
||||
/// </summary>
|
||||
public string TenantId { get; set; }
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if (AssignType == AssignTypeEnumType.Department)
|
||||
{
|
||||
if (TenantId.IsEmpty())
|
||||
{
|
||||
yield return new ValidationResult("请明确具体的厂区", new[] { nameof(TenantId) });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<DeviceEntity>().ToListAsync();
|
||||
@@ -409,13 +411,12 @@ public class DevicePermissionService : IDevicePermissionService
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static List<UserTenantDeviceCodeDto> GetAssignDeviceCodesInternal(GainfoEntity gainfo,
|
||||
List<GainfoGroupRelationshipEntity> gainfoGroupRelationships,
|
||||
List<DevicePermissionEntity> devicePermissions,
|
||||
List<DeviceGroupEntity> deviceGroups,
|
||||
List<DeviceGroupRelationshipEntity> deviceGroupRelationships)
|
||||
private static List<UserTenantDeviceCodeDto> GetAssignDeviceCodesInternal(
|
||||
GainfoEntity gainfo,
|
||||
List<GainfoGroupRelationshipEntity> gainfoGroupRelationships,
|
||||
List<DevicePermissionEntity> devicePermissions,
|
||||
List<DeviceGroupEntity> deviceGroups,
|
||||
List<DeviceGroupRelationshipEntity> deviceGroupRelationships)
|
||||
{
|
||||
var userNo = gainfo.No;
|
||||
var deviceCodes = new List<UserTenantDeviceCodeDto>();
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
|
||||
public string Tenant { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 下级部门
|
||||
/// </summary>
|
||||
public List<DepartmentTreeResponse> Next { get; set; } = new List<DepartmentTreeResponse>();
|
||||
[JsonIgnore]
|
||||
public List<DepartmentTreeResponse> _Next { get; set; } = new List<DepartmentTreeResponse>();
|
||||
|
||||
/// <summary>
|
||||
/// 下级部门
|
||||
/// </summary>
|
||||
public List<DepartmentTreeResponse> Next
|
||||
{
|
||||
get
|
||||
{
|
||||
_Next.ForEach(x => x.Tenant = Tenant);
|
||||
return _Next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<List<DepartmentTreeResponse>> GetTreeAsync()
|
||||
{
|
||||
var myTenants = _currentUser.GetUserClaim("tenants").Split(',').ToList();
|
||||
|
||||
var departments = await _dbContext.Queryable<DepartmentEntity>().Select<DepartmentTreeResponse>().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<DepartmentTreeResponse>();
|
||||
i.PNo = x.Code;
|
||||
return i;
|
||||
|
||||
}).ToList()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
private void RecursionGetNext(DepartmentTreeResponse current, List<DepartmentTreeResponse> 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);
|
||||
|
||||
Reference in New Issue
Block a user