diff --git a/Src/Dlhis.Basic/Organization/Controllers/GainfoPermissionsController.cs b/Src/Dlhis.Basic/Organization/Controllers/GainfoPermissionsController.cs
index 60a71318..28d3882f 100644
--- a/Src/Dlhis.Basic/Organization/Controllers/GainfoPermissionsController.cs
+++ b/Src/Dlhis.Basic/Organization/Controllers/GainfoPermissionsController.cs
@@ -1,5 +1,7 @@
-using Dlhis.Basic.Organization.Response;
+using System.ComponentModel.DataAnnotations;
+using Dlhis.Basic.Organization.Response;
using Dlhis.Basic.Organization.Services;
+using Dlhis.Basic.Organization.Services.Implements;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
@@ -24,7 +26,7 @@ public class GainfoPermissionsController : ControllerBase
///
///
[HttpGet("placesByGainfo")]
- public async Task> GetPlaceByGainfoAsync(string userNo)
+ public async Task> GetPlaceByGainfoAsync([Required] string userNo)
{
return await _gainfoPermissions.GetPlaceByGainfoAsync(userNo);
}
@@ -35,8 +37,9 @@ public class GainfoPermissionsController : ControllerBase
///
///
///
- public async Task GetDevicesUnderGroupByUserNoAsync(string userNo, string deviceGroupCode)
+ [HttpGet("devicesUnderGroupByUserNo")]
+ public async Task>> GetDevicesUnderGroupByUserNoAsync([Required] string userNo, [Required] string deviceGroupCode)
{
- return await _gainfoPermissions.GetDevicesUnderGroupByUserNoAsync(userNo,deviceGroupCode);
+ return await _gainfoPermissions.GetDevicesUnderGroupByUserNoAsync(userNo, deviceGroupCode);
}
}
diff --git a/Src/Dlhis.Basic/Organization/Services/IGainfoPermissions.cs b/Src/Dlhis.Basic/Organization/Services/IGainfoPermissions.cs
index a1a7a5b9..329bbbb6 100644
--- a/Src/Dlhis.Basic/Organization/Services/IGainfoPermissions.cs
+++ b/Src/Dlhis.Basic/Organization/Services/IGainfoPermissions.cs
@@ -1,4 +1,5 @@
using Dlhis.Basic.Organization.Response;
+using Dlhis.Basic.Organization.Services.Implements;
namespace Dlhis.Basic.Organization.Services;
@@ -6,5 +7,5 @@ public interface IGainfoPermissions : IScopeDependency
{
Task> GetPlaceByGainfoAsync(string userNo);
- Task GetDevicesUnderGroupByUserNoAsync(string userNo, string deviceGroupCode);
+ Task>> GetDevicesUnderGroupByUserNoAsync(string userNo, string deviceGroupCode);
}
diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoPermissions.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoPermissions.cs
index 31cb2b1c..bfa9c66e 100644
--- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoPermissions.cs
+++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoPermissions.cs
@@ -3,9 +3,6 @@ using Dlhis.Basic.Organization.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 Dm.filter.rw;
using Kurisu.SqlSugar.Services;
namespace Dlhis.Basic.Organization.Services.Implements;
@@ -52,48 +49,46 @@ public class GainfoPermissions : IGainfoPermissions
.ToListAsync();
}
- public async Task GetDevicesUnderGroupByUserNoAsync(string userNo, string deviceGroupCode)
- {;
+ public async Task>> GetDevicesUnderGroupByUserNoAsync(string userNo, string deviceGroupCode)
+ {
var deviceGroups = await _dbContext.Queryable().ToListAsync();
-
var currentGroup = deviceGroups.Where(x => x.Code.ToString() == deviceGroupCode).First();
- var groups = new List();
- if(!currentGroup.PCode.HasValue)
- {
- RecursionGetNext(currentGroup, deviceGroups, groups);
- }
- else
- {
- groups.Add((Guid)currentGroup.PCode);
- }
+ var groups = RecursionGetNext(currentGroup, deviceGroups).ToList();
- var gs = await _dbContext.Queryable()
- .Where(x => groups.Contains(x.UniqueValue))
- .Where(x => x.UniqueType == DeviceAssignmentTypeEnumType.Group)
- .Where(x => x.AssignType == AssignTypeEnumType.User)
- .Where(x => x.AssignValue == userNo)
- .Select(x => x.UniqueValue)
- .ToListAsync();
+ //用户所有deviceCode权限
+ var deviceCodes = await _devicePermissionService.GetAssignDeviceCodesAsync(userNo);
- var lst = new List();
- foreach (var gcode in gs)
+ var result = await _dbContext.Queryable()
+ .LeftJoin((x, d) => x.DeviceCode == d.Code)
+ .Where(x => groups.Contains(x.GroupCode))
+ .Where(x => deviceCodes.Contains(x.DeviceCode))
+ .Select((x, d) => new { x.DeviceCode, d.DeployPlace })
+ .Distinct()
+ .ToListAsync();
+
+ return result.Select(x => new KeyValue
{
- var devices = await _dbContext.Queryable()
- .Where(x => x.GroupCode == gcode)
- .Select(x => x.DeviceCode)
- .ToListAsync();
-
- }
+ Key = x.DeviceCode.ToString(),
+ Value = x.DeployPlace
+ })
+ .ToList();
}
- private void RecursionGetNext(DeviceGroupEntity current, List deviceGroups,List res)
+ private IEnumerable RecursionGetNext(DeviceGroupEntity current, List deviceGroups)
{
var next = deviceGroups.Where(x => x.PCode == current.Code).ToList();
foreach (var item in next)
{
- RecursionGetNext(item, deviceGroups,res);
+ RecursionGetNext(item, deviceGroups);
}
- res.Add(current.Code);
+
+ yield return current.Code;
}
}
+
+public class KeyValue
+{
+ public string Key { get; set; }
+ public T Value { get; set; }
+}