diff --git a/Src/Dlhis.Basic/Organization/Controllers/GainfoPermissionsController.cs b/Src/Dlhis.Basic/Organization/Controllers/GainfoPermissionsController.cs index 5015cdba..84ab0fb5 100644 --- a/Src/Dlhis.Basic/Organization/Controllers/GainfoPermissionsController.cs +++ b/Src/Dlhis.Basic/Organization/Controllers/GainfoPermissionsController.cs @@ -1,7 +1,11 @@ using System.ComponentModel.DataAnnotations; +using Dlhis.Basic.BusinessPlace.Response; +using Dlhis.Basic.Device.Response; +using Dlhis.Basic.Organization.Request; using Dlhis.Basic.Organization.Response; using Dlhis.Basic.Organization.Services; using Dlhis.Basic.Organization.Services.Implements; +using Kurisu.Core.DataAccess.Dto; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -23,12 +27,12 @@ public class GainfoPermissionsController : ControllerBase /// /// 根据用户查看餐饮点 /// - /// + /// /// [HttpGet("placesByGainfo")] - public async Task> GetPlaceByGainfoAsync([Required] string userNo) + public async Task> GetPlaceByGainfoAsync([FromQuery]DeviceAssRequest request) { - return await _gainfoPermissions.GetPlaceByGainfoAsync(userNo); + return await _gainfoPermissions.GetPlaceByGainfoAsync(request); } /// @@ -38,7 +42,7 @@ public class GainfoPermissionsController : ControllerBase /// /// [HttpGet("devicesUnderGroupByUserNo")] - public async Task>> GetDevicesUnderGroupByUserNoAsync([Required] string userNo, [Required] string deviceGroupCode) + public async Task> GetDevicesUnderGroupByUserNoAsync(string userNo, string deviceGroupCode) { return await _gainfoPermissions.GetDevicesUnderGroupByUserNoAsync(userNo, deviceGroupCode); } @@ -46,11 +50,11 @@ public class GainfoPermissionsController : ControllerBase /// /// 获取用户所有设备权限 /// - /// + /// /// [HttpGet("assignDeviceCodes")] - public async Task> GetAssignDeviceCodesAsync(string userNo) + public async Task> GetAssignDeviceCodesAsync([FromQuery]DeviceAssRequest request) { - return await _gainfoPermissions.GetAssignDeviceCodesAsync(userNo); + return await _gainfoPermissions.GetAssignDeviceCodesAsync(request); } } diff --git a/Src/Dlhis.Basic/Organization/Request/DeviceAssRequest.cs b/Src/Dlhis.Basic/Organization/Request/DeviceAssRequest.cs new file mode 100644 index 00000000..095b49f7 --- /dev/null +++ b/Src/Dlhis.Basic/Organization/Request/DeviceAssRequest.cs @@ -0,0 +1,11 @@ +using Kurisu.Core.DataAccess.Dto; +using System.ComponentModel.DataAnnotations; + +namespace Dlhis.Basic.Organization.Request +{ + public class DeviceAssRequest : PageDto + { + [Required] + public string UserNo { get; set; } + } +} diff --git a/Src/Dlhis.Basic/Organization/Response/GetDevicesUnderGroupByUserNoResponse.cs b/Src/Dlhis.Basic/Organization/Response/GetDevicesUnderGroupByUserNoResponse.cs new file mode 100644 index 00000000..09ab5aa8 --- /dev/null +++ b/Src/Dlhis.Basic/Organization/Response/GetDevicesUnderGroupByUserNoResponse.cs @@ -0,0 +1,10 @@ +using Dlhis.Basic.Device.Response; + +namespace Dlhis.Basic.Organization.Response +{ + public class GetDevicesUnderGroupByUserNoResponse + { + public Guid GroupCode { get; set; } + public List Devices { get; set; } + } +} diff --git a/Src/Dlhis.Basic/Organization/Services/IGainfoPermissions.cs b/Src/Dlhis.Basic/Organization/Services/IGainfoPermissions.cs index af209196..7b1f6183 100644 --- a/Src/Dlhis.Basic/Organization/Services/IGainfoPermissions.cs +++ b/Src/Dlhis.Basic/Organization/Services/IGainfoPermissions.cs @@ -1,13 +1,17 @@ -using Dlhis.Basic.Organization.Response; +using Dlhis.Basic.BusinessPlace.Response; +using Dlhis.Basic.Device.Response; +using Dlhis.Basic.Organization.Request; +using Dlhis.Basic.Organization.Response; using Dlhis.Basic.Organization.Services.Implements; +using Kurisu.Core.DataAccess.Dto; namespace Dlhis.Basic.Organization.Services; public interface IGainfoPermissions : IScopeDependency { - Task> GetPlaceByGainfoAsync(string userNo); + Task> GetPlaceByGainfoAsync(DeviceAssRequest request); - Task>> GetDevicesUnderGroupByUserNoAsync(string userNo, string deviceGroupCode); + Task> GetDevicesUnderGroupByUserNoAsync(string userNo, string deviceGroupCode); - Task> GetAssignDeviceCodesAsync(string userNo); + Task> GetAssignDeviceCodesAsync(DeviceAssRequest request); } diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoPermissions.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoPermissions.cs index 48c2e26d..14707aa6 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoPermissions.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoPermissions.cs @@ -1,9 +1,19 @@ -using Dlhis.Basic.Device.Services; +using Dlhis.Basic.BusinessPlace.Response; +using Dlhis.Basic.Device.Response; +using Dlhis.Basic.Device.Services; +using Dlhis.Basic.Organization.Request; using Dlhis.Basic.Organization.Response; using Dlhis.Entity.Basic.Entity; +using Dlhis.Entity.Canteen.Entities; +using Dlhis.Entity.Canteen.Enums; using Dlhis.Entity.Device.Entities; using Dlhis.Entity.Device.Enums; +using Kurisu.Core.DataAccess.Dto; +using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Services; +using Org.BouncyCastle.Asn1.Ocsp; +using Org.BouncyCastle.Crypto; +using SqlSugar; namespace Dlhis.Basic.Organization.Services.Implements; @@ -20,15 +30,15 @@ public class GainfoPermissions : IGainfoPermissions _dbContext = dbContext; } - public async Task> GetPlaceByGainfoAsync(string userNo) + public async Task> GetPlaceByGainfoAsync(DeviceAssRequest request) { var gainfo = await _gainfoStore.Queryable() - .Where(x => x.No == userNo) + .Where(x => x.No == request.UserNo) .FirstAsync(); if (gainfo == null) { - return new List(); + return new Pagination(); } //用户所有deviceCode权限 @@ -37,19 +47,29 @@ public class GainfoPermissions : IGainfoPermissions return await _dbContext.Queryable() .LeftJoin((x, dr) => x.UniqueNo == dr.DeviceUniqueNo) .LeftJoin((x, dr, place) => dr.BusinessPlaceCode == place.Code) + .LeftJoin((x,dr,place, ps) => x.Code == ps.PlaceCode) + .LeftJoin((x, dr, place, ps,s) => s.Code == ps.ShiftCode) .Where(x => x.Type == DeviceTypeEnumType.Meal) .Where(x => deviceCodes.Contains(x.Code)) .Where((x, dr) => !string.IsNullOrEmpty(dr.BusinessPlaceCustomCode)) - .Select((x, dr, place) => new GetPlaceByGainfoResponse - { - PlaceCode = place.Code, - PlaceName = place.Name - }) - .Distinct() - .ToListAsync(); + .Select((x, dr, place, ps, s) => new BusinessPlaceResponse + { + Id = place.Id, + Code = place.Code, + Status = place.Status, + Name = place.Name, + Catalog = place.Catalog, + CustomCode = place.CustomCode, + Source = place.Source, + + ShiftCode = s.Code, + ShiftName = s.Name + }) + .Distinct() + .ToPageListAsync(request); } - 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(); @@ -59,25 +79,108 @@ public class GainfoPermissions : IGainfoPermissions //用户所有deviceCode权限 var deviceCodes = await _devicePermissionService.GetAssignDeviceCodesAsync(userNo); - 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 lst = new List(); + foreach (var groupcode in groups) { - Key = x.DeviceCode.ToString(), - Value = x.DeployPlace - }) - .ToList(); + var nos = await _dbContext.Queryable() + .LeftJoin((x, d) => x.DeviceCode == d.Code) + .Where(x => groupcode == x.GroupCode) + .Select((x, d) => d.UniqueNo) + .ToListAsync(); + + var page = await _dbContext.Queryable() + .LeftJoin((d, dt) => d.TemplateCode == dt.Code) + .LeftJoin((d, dt, dr) => d.UniqueNo == dr.DeviceUniqueNo) + .LeftJoin((d, dt, dr, bp) => dr.BusinessPlaceCode == bp.Code) + .Where(d => nos.Contains(d.UniqueNo)) + .Select((d, dt, dr, bp) => new DevicePageResponse + { + FuncsStr = d.Funcs.ToString(), + Brand = dt.Brand, + Type = d.Type, + BusinessPlaceCode = bp.Code, + BusinessPlaceName = bp.Name, + LastHeartbeatTime = dr.LastHeartbeatTime + }) + .ToListAsync(); + var deviceUniqueNos = page.Select(x => x.UniqueNo).ToList(); + + var balanceInfos = await _dbContext.Queryable().Where(x => x.Type == BalanceRecordTypeEnumType.Out) + .Where(x => deviceUniqueNos.Contains(x.DeviceInfo)) + .Select(x => new + { + x.DeviceInfo, + Amount = SqlFunc.AggregateSum(x.Amount), + UserCount = SqlFunc.AggregateDistinctCount(x.UserCode) + }) + .GroupBy(x => x.DeviceInfo) + .ToListAsync(); + + page.ForEach(device => + { + var info = balanceInfos.FirstOrDefault(x => x.DeviceInfo == device.UniqueNo); + if (info != null) + { + device.Amount = info.Amount; + device.UserCount = info.UserCount; + } + }); + + var res = new GetDevicesUnderGroupByUserNoResponse + { + GroupCode = groupcode, + Devices = page + }; + lst.Add(res); + } + return lst; } - public Task> GetAssignDeviceCodesAsync(string userNo) + public async Task> GetAssignDeviceCodesAsync(DeviceAssRequest request) { - return _devicePermissionService.GetAssignDeviceCodesAsync(userNo); + var ids = await _devicePermissionService.GetAssignDeviceCodesAsync(request.UserNo); + + var page = await _dbContext.Queryable() + .LeftJoin((d, dt) => d.TemplateCode == dt.Code) + .LeftJoin((d, dt, dr) => d.UniqueNo == dr.DeviceUniqueNo) + .LeftJoin((d, dt, dr, bp) => dr.BusinessPlaceCode == bp.Code) + .Where(d => ids.Contains(d.Code)) + .Select((d, dt, dr, bp) => new DevicePageResponse + { + FuncsStr = d.Funcs.ToString(), + Brand = dt.Brand, + Type = d.Type, + BusinessPlaceCode = bp.Code, + BusinessPlaceName = bp.Name, + LastHeartbeatTime = dr.LastHeartbeatTime + }, true) + .ToPageListAsync(request); + + var deviceUniqueNos = page.Data.Select(x => x.UniqueNo).ToList(); + + var balanceInfos = await _dbContext.Queryable().Where(x => x.Type == BalanceRecordTypeEnumType.Out) + .Where(x => deviceUniqueNos.Contains(x.DeviceInfo)) + .Select(x => new + { + x.DeviceInfo, + Amount = SqlFunc.AggregateSum(x.Amount), + UserCount = SqlFunc.AggregateDistinctCount(x.UserCode) + }) + .GroupBy(x => x.DeviceInfo) + .ToListAsync(); + + page.Data.ForEach(device => + { + var info = balanceInfos.FirstOrDefault(x => x.DeviceInfo == device.UniqueNo); + if (info != null) + { + device.Amount = info.Amount; + device.UserCount = info.UserCount; + } + }); + + return page; + } private IEnumerable RecursionGetNext(DeviceGroupEntity current, List deviceGroups)