@@ -1,13 +1,11 @@
using Dlhis.Basic.Device.Dtos ;
using Dlhis.Basic.Device.Request ;
using Dlhis.Basic.Device.Response ;
using Dlhis.Entity.Basic.Entity ;
using Dlhis.Entity.Device.Entities ;
using Dlhis.Entity.Device.Enums ;
using Dlhis.Entity.Sys.Entities ;
using Dlhis.Entity.Sys.Enums ;
using Kurisu.AspNetCore.Utils.Extensions ;
using Kurisu.Core.DataAccess.Dto ;
using Kurisu.Core.DataAccess.Entity ;
using Kurisu.Core.User.Abstractions ;
using Kurisu.SqlSugar.Services ;
@@ -26,38 +24,36 @@ public class DevicePermissionService : IDevicePermissionService
_currentUser = currentUser ;
}
public async Task AssignAsync ( DevicePermissionSaveReuqest reu qest )
public async Task AssignAsync ( DevicePermissionSaveReuqest requ est )
{
var tenantId = request . AssignType = = AssignTypeEnumType . Department ? request . TenantId : _currentUser . GetStringTenantId ( ) ;
await GenerateDeviceTasksAsync ( async ( ) = >
{
var tenantId = reuqest . AssignType = = AssignTypeEnumType . Department ? reuqest . TenantId : _currentUser . GetStringTenantId ( ) ;
//删除当前匹配的基地权限
var p = await _dbContext . Queryable < DevicePermissionEntity > ( )
. Where ( x = > x . AssignType = = reu qest . AssignType )
. Where ( x = > x . AssignValue = = reu qest . AssignValue )
. Where ( x = > x . UniqueType = = reu qest . UniqueType )
. Where ( x = > x . TenantId = = tenantId )
. ToListAsync ( ) ;
. Where ( x = > x . AssignType = = requ est . AssignType )
. Where ( x = > x . AssignValue = = requ est . AssignValue )
. Where ( x = > x . UniqueType = = requ est . UniqueType )
. Where ( x = > x . TenantId = = tenantId )
. ToListAsync ( ) ;
await _dbContext . DeleteReallyAsync ( p ) ;
//保存配置的权限
if ( reu qest . Codes . IsPresent ( ) )
if ( requ est . Codes . IsPresent ( ) )
{
var devicePermissions = reu qest . Codes . Select ( code = > new DevicePermissionEntity
var devicePermissions = requ est . Codes . Select ( code = > new DevicePermissionEntity
{
AssignType = reu qest . AssignType ,
AssignValue = reu qest . AssignValue ,
UniqueType = reu qest . UniqueType ,
AssignType = requ est . AssignType ,
AssignValue = requ est . AssignValue ,
UniqueType = requ est . UniqueType ,
UniqueValue = code ,
TenantId = tenantId
} )
. ToList ( ) ;
} ) . ToList ( ) ;
await _dbContext . InsertAsync ( devicePermissions ) ;
}
} , null ) ;
}
@@ -277,8 +273,7 @@ public class DevicePermissionService : IDevicePermissionService
CancellationId = 0 ,
Version = 0 ,
TenantId = x . TenantId
} )
. ToList ( ) ;
} ) . ToList ( ) ;
await _dbContext . InsertAsync ( tasks ) ;
}
@@ -288,11 +283,11 @@ public class DevicePermissionService : IDevicePermissionService
var all = await GetAssignDeviceCodesAsync ( userNo ) ;
return await _dbContext . Queryable < DeviceEntity > ( )
. Where ( x = > x . Enable )
. Where ( x = > x . Type = = DeviceTypeEnumType . Meal )
. Where ( x = > all . Contains ( x . Code ) )
. Select ( x = > x . UniqueNo )
. ToListAsync ( ) ;
. Where ( x = > x . Enable )
. Where ( x = > x . Type = = DeviceTypeEnumType . Meal )
. Where ( x = > all . Contains ( x . Code ) )
. Select ( x = > x . UniqueNo )
. ToListAsync ( ) ;
}
@@ -307,7 +302,7 @@ public class DevicePermissionService : IDevicePermissionService
var deviceRegistries = await _dbContext . Queryable < DeviceRegistryEntity > ( ) . Where ( x = > ! SqlFunc . IsNullOrEmpty ( x . BusinessPlaceCode ) ) . ToListAsync ( ) ;
var gainfo = await _dbContext . Queryable < GainfoEntity > ( ) . Where ( x = > x . No = = userNo ) . SingleAsync ( )
? ? await _dbContext . Queryable < GainfoEntity > ( ) . AS ( "GainfoLeave" ) . Where ( x = > x . No = = userNo ) . SingleAsync ( ) ;
? ? await _dbContext . Queryable < GainfoEntity > ( ) . AS ( "GainfoLeave" ) . Where ( x = > x . No = = userNo ) . SingleAsync ( ) ;
var gainfoGroups = await _dbContext . Queryable < GainfoGroupRelationshipEntity > ( ) . ToListAsync ( ) ;
var devicePermissions = await _dbContext . Queryable < DevicePermissionEntity > ( ) . ToListAsync ( ) ;
@@ -349,8 +344,8 @@ public class DevicePermissionService : IDevicePermissionService
}
private static List < UserTenantDeviceCodeDto > GetAssignCodesInternal (
List < DevicePermissionEntity > devicePermissions , List < DeviceGroupEntity > deviceGroups ,
DeviceAssignmentTypeEnumType uniqueType , AssignTypeEnumType assignType , string assignValue )
List < DevicePermissionEntity > devicePermissions , List < DeviceGroupEntity > deviceGroups ,
DeviceAssignmentTypeEnumType uniqueType , AssignTypeEnumType assignType , string assignValue )
{
var tenantDevicePermissions = devicePermissions
. Where ( x = > x . UniqueType = = uniqueType )
@@ -365,10 +360,7 @@ public class DevicePermissionService : IDevicePermissionService
{
//开始递归处理
var tops = deviceGroups . Where ( x = > ! x . PCode . HasValue ) . ToList ( ) ;
tops . ForEach ( x = >
{
RecursionGetNext ( x , deviceGroups , tenantDevicePermissions , tenantDevicePermissions . SelectMany ( item = > item . Codes ) . Contains ( x . Code ) ) ;
} ) ;
tops . ForEach ( x = > { RecursionGetNext ( x , deviceGroups , tenantDevicePermissions , tenantDevicePermissions . SelectMany ( item = > item . Codes ) . Contains ( x . Code ) ) ; } ) ;
}
return tenantDevicePermissions . GroupBy ( x = > x . Tenant ) . Select ( x = >
@@ -391,6 +383,7 @@ public class DevicePermissionService : IDevicePermissionService
{
result . Add ( new UserTenantDeviceCodeDto { Tenant = item . TenantId , Codes = new List < Guid > { item . Code } } ) ;
}
RecursionGetNext ( item , deviceGroups , result , result . SelectMany ( x = > x . Codes ) . Contains ( item . Code ) ) ;
}
}
@@ -435,7 +428,7 @@ public class DevicePermissionService : IDevicePermissionService
List < DeviceGroupRelationshipEntity > deviceGroupRelationships ,
List < DeviceRegistryEntity > deviceRegistries ,
List < DeviceEntity > devices
)
)
{
var userNo = gainfo . No ;
var deviceDtos = new List < UserTenantDeviceCodeDto > ( ) ;
@@ -492,18 +485,18 @@ public class DevicePermissionService : IDevicePermissionService
Codes = x . Select ( item = > item . DeviceCode ) . Distinct ( ) . ToList ( )
} ) ;
var placeGroup = deviceRegistries . Where ( x = > businessPlaceCodes . Contains ( x . BusinessPlaceCode ! . Value ) ) . GroupBy ( x = > x . TenantId )
. Select ( x = >
{
var currentDeviceUniqueNos = x . Select ( item = > item . DeviceUniqueNo ) . ToList ( ) ;
var placeGroup = deviceRegistries . Where ( x = > businessPlaceCodes . Contains ( x . BusinessPlaceCode ! . Value ) )
. GroupBy ( x = > x . TenantId )
. Select ( x = >
{
var currentDeviceUniqueNos = x . Select ( item = > item . DeviceUniqueNo ) . ToList ( ) ;
return new UserTenantDeviceCodeDto
{
Tenant = x . Key ,
Codes = devices . Where ( d = > currentDeviceUniqueNos . Contains ( d . UniqueNo ) ) . Select ( d = > d . Code ) . Distinct ( ) . ToList ( )
} ;
} )
. ToList ( ) ;
return new UserTenantDeviceCodeDto
{
Tenant = x . Key ,
Codes = devices . Where ( d = > currentDeviceUniqueNos . Contains ( d . UniqueNo ) ) . Select ( d = > d . Code ) . Distinct ( ) . ToList ( )
} ;
} ) . ToList ( ) ;
deviceDtos . AddRange ( deviceCodesByGroup ) ;
deviceDtos . AddRange ( placeGroup ) ;
@@ -512,7 +505,6 @@ public class DevicePermissionService : IDevicePermissionService
{
Tenant = x . Key ,
Codes = x . SelectMany ( item = > item . Codes ) . Distinct ( ) . ToList ( )
} ) . ToList ( ) ;
}
}
}