fix 组织架构树调整
This commit is contained in:
@@ -27,6 +27,7 @@ public class DevicePermissionsController : ControllerBase
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost("assign")]
|
[HttpPost("assign")]
|
||||||
[Transactional]
|
[Transactional]
|
||||||
|
[IgnoreTenant]
|
||||||
public async Task AssignAsync(DevicePermissionSaveReuqest request)
|
public async Task AssignAsync(DevicePermissionSaveReuqest request)
|
||||||
{
|
{
|
||||||
await _devicePermissionService.AssignAsync(request);
|
await _devicePermissionService.AssignAsync(request);
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using Dlhis.Entity.Sys.Enums;
|
using Dlhis.Entity.Sys.Enums;
|
||||||
|
using Kurisu.AspNetCore.Utils.Extensions;
|
||||||
|
|
||||||
namespace Dlhis.Basic.Device.Request;
|
namespace Dlhis.Basic.Device.Request;
|
||||||
|
|
||||||
public class DevicePermissionSaveReuqest
|
public class DevicePermissionSaveReuqest : IValidatableObject
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 分配类型 AssignTypeEnumType
|
/// 分配类型 AssignTypeEnumType
|
||||||
@@ -30,4 +31,20 @@ public class DevicePermissionSaveReuqest
|
|||||||
/// 分配权限值
|
/// 分配权限值
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<Guid> Codes { get; set; }
|
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.AssignType == reuqest.AssignType)
|
||||||
.Where(x => x.AssignValue == reuqest.AssignValue)
|
.Where(x => x.AssignValue == reuqest.AssignValue)
|
||||||
.Where(x => x.UniqueType == reuqest.UniqueType)
|
.Where(x => x.UniqueType == reuqest.UniqueType)
|
||||||
|
.WhereIF(reuqest.AssignType == AssignTypeEnumType.Department, x => x.TenantId == reuqest.TenantId)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
await _dbContext.DeleteReallyAsync(p);
|
await _dbContext.DeleteReallyAsync(p);
|
||||||
@@ -41,14 +42,17 @@ public class DevicePermissionService : IDevicePermissionService
|
|||||||
//保存配置的权限
|
//保存配置的权限
|
||||||
if (reuqest.Codes.IsPresent())
|
if (reuqest.Codes.IsPresent())
|
||||||
{
|
{
|
||||||
|
var tenantId = reuqest.AssignType == AssignTypeEnumType.Department ? reuqest.TenantId : _currentUser.GetStringSubjectId();
|
||||||
|
|
||||||
var devicePermissions = reuqest.Codes.Select(code => new DevicePermissionEntity
|
var devicePermissions = reuqest.Codes.Select(code => new DevicePermissionEntity
|
||||||
{
|
{
|
||||||
AssignType = reuqest.AssignType,
|
AssignType = reuqest.AssignType,
|
||||||
AssignValue = reuqest.AssignValue,
|
AssignValue = reuqest.AssignValue,
|
||||||
UniqueType = reuqest.UniqueType,
|
UniqueType = reuqest.UniqueType,
|
||||||
UniqueValue = code,
|
UniqueValue = code,
|
||||||
|
TenantId = tenantId
|
||||||
}).ToList();
|
})
|
||||||
|
.ToList();
|
||||||
|
|
||||||
await _dbContext.InsertAsync(devicePermissions);
|
await _dbContext.InsertAsync(devicePermissions);
|
||||||
}
|
}
|
||||||
@@ -75,7 +79,6 @@ public class DevicePermissionService : IDevicePermissionService
|
|||||||
if (userNos.IsEmpty())
|
if (userNos.IsEmpty())
|
||||||
userNos = await GetPermissionUserNosAsync();
|
userNos = await GetPermissionUserNosAsync();
|
||||||
|
|
||||||
//var before = await GetAssignDeviceCodesInternalAsync(userNos);
|
|
||||||
var before = await GetAssignDeviceCodesInternalAsync(userNos);
|
var before = await GetAssignDeviceCodesInternalAsync(userNos);
|
||||||
|
|
||||||
_dbContext.Client.QueryFilter.Restore();
|
_dbContext.Client.QueryFilter.Restore();
|
||||||
@@ -88,7 +91,6 @@ public class DevicePermissionService : IDevicePermissionService
|
|||||||
if (nextUserNos.Any())
|
if (nextUserNos.Any())
|
||||||
userNos = userNos.Concat(nextUserNos).Distinct().ToList();
|
userNos = userNos.Concat(nextUserNos).Distinct().ToList();
|
||||||
|
|
||||||
//var current = await GetAssignDeviceCodesInternalAsync(userNos);
|
|
||||||
var current = await GetAssignDeviceCodesInternalAsync(userNos);
|
var current = await GetAssignDeviceCodesInternalAsync(userNos);
|
||||||
|
|
||||||
var deivces = await _dbContext.Queryable<DeviceEntity>().ToListAsync();
|
var deivces = await _dbContext.Queryable<DeviceEntity>().ToListAsync();
|
||||||
@@ -409,13 +411,12 @@ public class DevicePermissionService : IDevicePermissionService
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static List<UserTenantDeviceCodeDto> GetAssignDeviceCodesInternal(
|
||||||
|
GainfoEntity gainfo,
|
||||||
private static List<UserTenantDeviceCodeDto> GetAssignDeviceCodesInternal(GainfoEntity gainfo,
|
List<GainfoGroupRelationshipEntity> gainfoGroupRelationships,
|
||||||
List<GainfoGroupRelationshipEntity> gainfoGroupRelationships,
|
List<DevicePermissionEntity> devicePermissions,
|
||||||
List<DevicePermissionEntity> devicePermissions,
|
List<DeviceGroupEntity> deviceGroups,
|
||||||
List<DeviceGroupEntity> deviceGroups,
|
List<DeviceGroupRelationshipEntity> deviceGroupRelationships)
|
||||||
List<DeviceGroupRelationshipEntity> deviceGroupRelationships)
|
|
||||||
{
|
{
|
||||||
var userNo = gainfo.No;
|
var userNo = gainfo.No;
|
||||||
var deviceCodes = new List<UserTenantDeviceCodeDto>();
|
var deviceCodes = new List<UserTenantDeviceCodeDto>();
|
||||||
@@ -438,8 +439,9 @@ public class DevicePermissionService : IDevicePermissionService
|
|||||||
deviceGroupCodes.AddRange(gg);
|
deviceGroupCodes.AddRange(gg);
|
||||||
}
|
}
|
||||||
|
|
||||||
var dd = GetAssignCodesInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Department, gainfo.DepartmentNo);
|
var gainfoFactoryDevicePermissions = devicePermissions.Where(x => x.TenantId == gainfo.Factory).ToList();
|
||||||
var gd = GetAssignCodesInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Department, gainfo.DepartmentNo);
|
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);
|
deviceCodes.AddRange(dd);
|
||||||
deviceGroupCodes.AddRange(gd);
|
deviceGroupCodes.AddRange(gd);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
namespace Dlhis.Basic.Organization.Response;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Dlhis.Basic.Organization.Response;
|
||||||
|
|
||||||
public class DepartmentTreeResponse
|
public class DepartmentTreeResponse
|
||||||
{
|
{
|
||||||
@@ -17,8 +19,24 @@ public class DepartmentTreeResponse
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
public string Tenant { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 下级部门
|
/// 下级部门
|
||||||
/// </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.Basic.Organization.Response;
|
||||||
using Dlhis.Entity.Basic.Entity;
|
using Dlhis.Entity.Basic.Entity;
|
||||||
using Kurisu.Core.User.Abstractions;
|
using Dlhis.Sys.Api;
|
||||||
using Kurisu.SqlSugar.Services;
|
using Kurisu.SqlSugar.Services;
|
||||||
|
using Mapster;
|
||||||
|
|
||||||
namespace Dlhis.Basic.Organization.Services.Implements;
|
namespace Dlhis.Basic.Organization.Services.Implements;
|
||||||
|
|
||||||
public class DepartmentService : IDepartmentService
|
public class DepartmentService : IDepartmentService
|
||||||
{
|
{
|
||||||
private readonly IDbContext _dbContext;
|
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;
|
_dbContext = dbContext;
|
||||||
_currentUser = currentUser;
|
_tenantApi = tenantApi;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<List<DepartmentTreeResponse>> GetTreeAsync()
|
public async Task<List<DepartmentTreeResponse>> GetTreeAsync()
|
||||||
{
|
{
|
||||||
var myTenants = _currentUser.GetUserClaim("tenants").Split(',').ToList();
|
|
||||||
|
|
||||||
var departments = await _dbContext.Queryable<DepartmentEntity>().Select<DepartmentTreeResponse>().ToListAsync();
|
var departments = await _dbContext.Queryable<DepartmentEntity>().Select<DepartmentTreeResponse>().ToListAsync();
|
||||||
//00001000 一定是这个开头的
|
//00001000 一定是这个开头的
|
||||||
var tops = departments.Where(x => x.PNo == "00001000").ToList();
|
var tops = departments.Where(x => x.PNo == "00001000").ToList();
|
||||||
@@ -29,13 +28,30 @@ public class DepartmentService : IDepartmentService
|
|||||||
RecursionGetNext(x, departments);
|
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)
|
private void RecursionGetNext(DepartmentTreeResponse current, List<DepartmentTreeResponse> data)
|
||||||
{
|
{
|
||||||
var next = data.Where(x => x.PNo == current.No).ToList();
|
var next = data.Where(x => x.PNo == current.No).ToList();
|
||||||
current.Next = next;
|
current._Next = next;
|
||||||
foreach (var item in next)
|
foreach (var item in next)
|
||||||
{
|
{
|
||||||
RecursionGetNext(item, data);
|
RecursionGetNext(item, data);
|
||||||
|
|||||||
Reference in New Issue
Block a user