diff --git a/Src/Dlhis.Basic/Device/Response/DevicePageResponse.cs b/Src/Dlhis.Basic/Device/Response/DevicePageResponse.cs
index 448e34e9..d9d47179 100644
--- a/Src/Dlhis.Basic/Device/Response/DevicePageResponse.cs
+++ b/Src/Dlhis.Basic/Device/Response/DevicePageResponse.cs
@@ -84,4 +84,19 @@ public class DevicePageResponse
/// 是否启用
///
public bool Enable { get; set; }
+
+ ///
+ /// 是否在线
+ ///
+ public bool IsOnline { get; set; }
+
+ ///
+ /// 消费总额
+ ///
+ public decimal Amount { get; set; }
+
+ ///
+ /// 消费人次
+ ///
+ public int UserCount { get; set; }
}
diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs
index fe0257a7..8a7e9bb3 100644
--- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs
+++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs
@@ -1,6 +1,8 @@
using Dlhis.Basic.Device.Request;
using Dlhis.Basic.Device.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.AspNetCore.Scope;
@@ -11,7 +13,6 @@ using Kurisu.SqlSugar.Attributes;
using Kurisu.SqlSugar.Extensions;
using Kurisu.SqlSugar.Services;
using Mapster;
-using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
@@ -40,9 +41,51 @@ public class DeviceService : IDeviceService
}, true)
.ToPageListAsync(request);
+ var now = DateTime.Now;
+ var deviceUniqueNos = page.Data.Select(x => x.UniqueNo).ToList();
+
+ var balanceRecords = await _dbContext.Queryable().Where(x => x.Type == BalanceRecordTypeEnumType.Out)
+ .Where(x => deviceUniqueNos.Contains(x.DeviceInfo))
+ .ToListAsync();
+
+ var deviceRegistries = await _dbContext.Queryable()
+ .LeftJoin((x, d) => x.DeviceUniqueNo == d.UniqueNo)
+ .Where(x => deviceUniqueNos.Contains(x.DeviceUniqueNo))
+ .Select((x, d) => new
+ {
+ d.HeartbeatInterval,
+ x.LastHeartbeatTime,
+ x.DeviceUniqueNo,
+ })
+ .ToListAsync();
+
+ page.Data.ForEach(device =>
+ {
+ device.Amount = balanceRecords.Sum(x => x.Amount);
+ device.UserCount = balanceRecords.DistinctBy(x => x.UserCode).Count();
+
+ var r = deviceRegistries.FirstOrDefault(x => x.DeviceUniqueNo == device.UniqueNo);
+ if (r == null)
+ {
+ device.IsOnline = false;
+ }
+ else
+ {
+ if (r.HeartbeatInterval <= 0)
+ {
+ device.IsOnline = true;
+ }
+ else
+ {
+ device.IsOnline = r.LastHeartbeatTime.AddSeconds(r.HeartbeatInterval * 3) >= now;
+ }
+ }
+ });
+
return page;
}
+
[Transactional]
public async Task SaveAsync(DeviceSaveRequest request)
{
@@ -288,7 +331,7 @@ public class DeviceService : IDeviceService
dbContext.Client.CurrentConnectionConfig.ConnectionString = logConnectionString;
var logs = await dbContext.Queryable()
.WhereIF(!request.message.IsEmpty(), x => x.Message.Contains(request.message))
- .WhereIF(!level.IsEmpty(),x => x.Level == level)
+ .WhereIF(!level.IsEmpty(), x => x.Level == level)
.Select()
.ToPageListAsync(request);
return logs;
diff --git a/Src/Dlhis.Sys/Identity/Controllers/RolesController.cs b/Src/Dlhis.Sys/Identity/Controllers/RolesController.cs
index 0924f7c3..cd65a44d 100644
--- a/Src/Dlhis.Sys/Identity/Controllers/RolesController.cs
+++ b/Src/Dlhis.Sys/Identity/Controllers/RolesController.cs
@@ -85,8 +85,8 @@ public class RolesController : ControllerBase
///
///
[HttpGet("my")]
- public async Task GetMyRoleAsync()
+ public async Task GetMyRoleAsync(int? userId)
{
- return await _roleService.GetMyRoleAsync();
+ return await _roleService.GetMyRoleAsync(userId);
}
}
diff --git a/Src/Dlhis.Sys/Identity/Response/UserResponse.cs b/Src/Dlhis.Sys/Identity/Response/UserResponse.cs
index 45ff5c74..15c1fe33 100644
--- a/Src/Dlhis.Sys/Identity/Response/UserResponse.cs
+++ b/Src/Dlhis.Sys/Identity/Response/UserResponse.cs
@@ -58,4 +58,10 @@ public class UserResponse
/// 登陆失败次数
///
public int AccessFailedCount { get; set; }
+
+
+ ///
+ /// 角色
+ ///
+ public string Role { get; set; }
}
diff --git a/Src/Dlhis.Sys/Identity/Services/IRoleService.cs b/Src/Dlhis.Sys/Identity/Services/IRoleService.cs
index 3b789429..8b02ba23 100644
--- a/Src/Dlhis.Sys/Identity/Services/IRoleService.cs
+++ b/Src/Dlhis.Sys/Identity/Services/IRoleService.cs
@@ -12,7 +12,7 @@ public interface IRoleService : IScopeDependency
Task SaveRoleAsync(RoleSaveRequest request);
- Task GetMyRoleAsync();
+ Task GetMyRoleAsync(int? userId);
Task RemoveRoleAsync(RoleRemoveRequest request);
diff --git a/Src/Dlhis.Sys/Identity/Services/Implements/RoleService.cs b/Src/Dlhis.Sys/Identity/Services/Implements/RoleService.cs
index 38cd025a..2702f1a2 100644
--- a/Src/Dlhis.Sys/Identity/Services/Implements/RoleService.cs
+++ b/Src/Dlhis.Sys/Identity/Services/Implements/RoleService.cs
@@ -9,7 +9,6 @@ using Kurisu.Core.DataAccess.Dto;
using Kurisu.Core.User.Abstractions;
using Kurisu.SqlSugar.Extensions;
using Kurisu.SqlSugar.Services;
-using Org.BouncyCastle.Asn1.Ocsp;
namespace Dlhis.Sys.Identity.Services.Implements;
@@ -40,9 +39,9 @@ public class RoleService : IRoleService
});
}
- public async Task GetMyRoleAsync()
+ public async Task GetMyRoleAsync(int? userId)
{
- var userId = _currentUser.GetIntSubjectId();
+ userId ??= _currentUser.GetIntSubjectId();
return await Scoped.Request.Value.CreateAsync(async sp =>
{
@@ -50,7 +49,6 @@ public class RoleService : IRoleService
var identityConnection = _configuration.GetSection("SqlSugarOptions:IdentityConnectionString").Value;
dbContext.Client.CurrentConnectionConfig.ConnectionString = identityConnection;
-
return await dbContext.Queryable()
.LeftJoin((x, r) => x.RoleId == r.Id)
.Where(x => x.UserId == userId)
diff --git a/Src/Dlhis.Sys/Identity/Services/Implements/UserService.cs b/Src/Dlhis.Sys/Identity/Services/Implements/UserService.cs
index f27e0528..63a9b19f 100644
--- a/Src/Dlhis.Sys/Identity/Services/Implements/UserService.cs
+++ b/Src/Dlhis.Sys/Identity/Services/Implements/UserService.cs
@@ -1,5 +1,4 @@
-using System.Configuration;
-using Dlhis.Entity.Sys.Entities;
+using Dlhis.Entity.Sys.Entities;
using Dlhis.Sys.Identity.Request;
using Dlhis.Sys.Identity.Response;
using Kurisu.AspNetCore.Utils.Extensions;
@@ -23,13 +22,18 @@ public class UserService : IUserService
public async Task> GetPageAsync(UserPageRequest request)
{
return await _dbContext.Queryable()
+ .LeftJoin((x, ur) => x.Id == ur.UserId)
+ .LeftJoin((x, ur, r) => ur.RoleId == r.Id)
.WhereIF(request.Search.IsPresent(), x => x.UserName.Contains(request.Search)
|| x.NormalizedUserName.Contains(request.Search)
|| x.Email.Contains(request.Search)
|| x.NormalizedEmail.Contains(request.Search)
|| x.PhoneNumber.Contains(request.Search)
)
- .Select()
+ .Select((x, ur, r) => new UserResponse
+ {
+ Id = x.Id
+ }, true)
.ToPageListAsync(request);
}