diff --git a/Src/Dlhis.Basic/Device/Controllers/DeviceGroupsController.cs b/Src/Dlhis.Basic/Device/Controllers/DeviceGroupsController.cs
index 66a5089f..b3b849cd 100644
--- a/Src/Dlhis.Basic/Device/Controllers/DeviceGroupsController.cs
+++ b/Src/Dlhis.Basic/Device/Controllers/DeviceGroupsController.cs
@@ -43,6 +43,7 @@ public class DeviceGroupsController : ControllerBase
///
///
[HttpPost("save")]
+ [IgnoreTenant]
public async Task SaveAsync(DeviceGroupSaveRequest request)
{
await _deviceGroupService.SaveAsync(request);
@@ -65,6 +66,7 @@ public class DeviceGroupsController : ControllerBase
///
///
[HttpPost("assign")]
+ [IgnoreTenant]
[Transactional]
public async Task AssignDevicesAsync(DeviceAssignRequest request)
{
diff --git a/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs b/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs
index c13ca4bc..0c61d995 100644
--- a/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs
+++ b/Src/Dlhis.Basic/Device/Controllers/DevicePermissionsController.cs
@@ -61,6 +61,7 @@ public class DevicePermissionsController : ControllerBase
///
///
[HttpGet("canteen/uniqueNos")]
+ [IgnoreTenant]
public async Task> GetCanteenDeviceUniqueNosByUserNoAsync(string userNo)
{
return await _devicePermissionService.GetCanteenDeviceUniqueNosByUserNoAsync(userNo);
diff --git a/Src/Dlhis.Basic/Device/Dtos/UserTenantDeviceCodeDto.cs b/Src/Dlhis.Basic/Device/Dtos/UserTenantDeviceCodeDto.cs
new file mode 100644
index 00000000..1d1b3b82
--- /dev/null
+++ b/Src/Dlhis.Basic/Device/Dtos/UserTenantDeviceCodeDto.cs
@@ -0,0 +1,14 @@
+namespace Dlhis.Basic.Device.Dtos;
+
+public class UserTenantDeviceCodeDto
+{
+ ///
+ /// 租户
+ ///
+ public string Tenant { get; set; }
+
+ ///
+ /// 设备权限
+ ///
+ public List Codes { get; set; }
+}
diff --git a/Src/Dlhis.Basic/Device/Request/DevicePermissionSaveReuqest.cs b/Src/Dlhis.Basic/Device/Request/DevicePermissionSaveReuqest.cs
index f9efc594..ae282891 100644
--- a/Src/Dlhis.Basic/Device/Request/DevicePermissionSaveReuqest.cs
+++ b/Src/Dlhis.Basic/Device/Request/DevicePermissionSaveReuqest.cs
@@ -27,7 +27,7 @@ public class DevicePermissionSaveReuqest
public DeviceAssignmentTypeEnumType UniqueType { get; set; }
///
- /// 分配权限值不能为空
+ /// 分配权限值
///
- public List Codes { get; set; } = new List();
+ public List Codes { get; set; }
}
diff --git a/Src/Dlhis.Basic/Device/Request/DeviceSaveRequest.cs b/Src/Dlhis.Basic/Device/Request/DeviceSaveRequest.cs
index f7e4a84c..1308a9a2 100644
--- a/Src/Dlhis.Basic/Device/Request/DeviceSaveRequest.cs
+++ b/Src/Dlhis.Basic/Device/Request/DeviceSaveRequest.cs
@@ -78,6 +78,11 @@ public class DeviceSaveRequest : IValidatableObject
public IEnumerable Validate(ValidationContext validationContext)
{
+ if (Id.HasValue)
+ {
+ UniqueNo = null;
+ }
+
if (Type != DeviceTypeEnumType.Door && AsAttendance)
{
yield return new ValidationResult($"{DeviceTypeEnumType.Door.GetDescription()}才可设置作为考勤设备", new[] { nameof(AsAttendance) });
diff --git a/Src/Dlhis.Basic/Device/Response/DeviceGroupTreeResponse.cs b/Src/Dlhis.Basic/Device/Response/DeviceGroupTreeResponse.cs
index a1e7456a..b1b919d9 100644
--- a/Src/Dlhis.Basic/Device/Response/DeviceGroupTreeResponse.cs
+++ b/Src/Dlhis.Basic/Device/Response/DeviceGroupTreeResponse.cs
@@ -1,6 +1,5 @@
using Dlhis.Entity.Device.Enums;
using Kurisu.AspNetCore.Utils.Extensions;
-using Microsoft.AspNetCore.Server.IISIntegration;
using Newtonsoft.Json;
namespace Dlhis.Basic.Device.Response;
@@ -53,12 +52,10 @@ public class DeviceGroupTreeResponse
public bool Editable { get; set; }
- public bool IsDefault { get; set; }
-
///
/// 是否允许设置下级
///
- public bool AbleSetNext => IsDefault;
+ public bool AbleSetNext { get; set; }
[JsonIgnore]
public string TenantId { get; set; }
diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs
index 23cc9137..3c8797d6 100644
--- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs
+++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs
@@ -43,24 +43,21 @@ public class DeviceGroupService : IDeviceGroupService
public async Task SaveAsync(DeviceGroupSaveRequest request)
{
//检查父级节点
- await CheckPCodeExistsDeviceAsync(request.PCode);
-
- var pGrp = await _dbContext.Queryable().Where(x => x.Code == request.PCode).FirstAsync();
- pGrp.AbleSetNext.ThrowIfFalse($"分组{pGrp.Name}不可添加下级");
- (pGrp != null && pGrp.Type != request.Type).ThrowIfTrue("分组类型必须与上级类型保持一致");
+ var pGrp = await CheckPCodeAsync(request);
if (!request.Id.HasValue)
{
var entity = request.Adapt();
entity.Code = Guid.NewGuid();
+ entity.TenantId = _currentUser.GetStringTenantId();
await _dbContext.InsertAsync(entity);
}
else
{
var entity = await _dbContext.Queryable().Where(x => x.Id == request.Id).FirstAsync();
- entity.ThrowIfNull("设备组不存在,无法更新");
- entity.Editable.ThrowIfFalse("不可编辑当前组");
+ entity.ThrowIfNull("设备分组不存在,无法更新");
+ entity.Editable.ThrowIfFalse("不可编辑当前分组");
if (request.Type != entity.Type)
{
@@ -84,7 +81,7 @@ public class DeviceGroupService : IDeviceGroupService
public async Task DeleteAsync(long id)
{
var deviceGroup = await _dbContext.Queryable().Where(x => x.Id == id).FirstAsync();
- deviceGroup.ThrowIfNull("设备组不存在,无需删除");
+ deviceGroup.ThrowIfNull("设备分组不存在,无需删除");
await _dbContext.DeleteAsync(deviceGroup);
}
@@ -93,7 +90,7 @@ public class DeviceGroupService : IDeviceGroupService
public async Task AssignDevicesAsync(DeviceAssignRequest request)
{
var group = await _dbContext.Queryable().Where(x => x.Code == request.GroupCode).FirstAsync();
- group.ThrowIfNull("设备组不存在");
+ group.ThrowIfNull("设备分组不存在,无法进行分配");
await CheckNoNextGroupAsync(group.Code);
await CheckGroupTypeMatchAsync(request, group);
@@ -102,12 +99,14 @@ public class DeviceGroupService : IDeviceGroupService
await _devicePermissionService.GenerateDeviceTasksAsync(async () =>
{
var relationships = await _dbContext.Queryable().Where(x => x.GroupCode == request.GroupCode).ToListAsync();
- await _dbContext.DeleteAsync(relationships);
+ await _dbContext.DeleteReallyAsync(relationships);
var entities = request.DeviceCodes.Select(x => new DeviceGroupRelationshipEntity
{
GroupCode = request.GroupCode,
- DeviceCode = x
+ DeviceCode = x,
+
+ TenantId = _currentUser.GetStringTenantId(),
}).ToList();
@@ -131,28 +130,33 @@ public class DeviceGroupService : IDeviceGroupService
/****************************************************** help methods *********************************************************/
///
- /// 检查父级分组存在设备
+ /// 检查父级分组
///
- ///
+ ///
///
- private async Task CheckPCodeExistsDeviceAsync(Guid? pCode)
+ private async Task CheckPCodeAsync(DeviceGroupSaveRequest request)
{
- if (pCode.HasValue)
+ var pGrp = await _dbContext.Queryable().Where(x => x.Code == request.PCode).FirstAsync();
+ if (pGrp != null)
{
- var exists = await _dbContext.Queryable().Where(x => x.GroupCode == pCode).AnyAsync();
- exists.ThrowIfTrue("父级分组存在设备");
+ (!pGrp.AbleSetNext && !request.Id.HasValue).ThrowIfTrue($"{pGrp.Name}不可添加下级");
+ var exists = await _dbContext.Queryable().Where(x => x.GroupCode == request.PCode).AnyAsync();
+ exists.ThrowIfTrue("上级分组存在设备");
}
+
+ (pGrp != null && pGrp.Type != request.Type).ThrowIfTrue("分组类型必须与上级类型保持一致");
+ return pGrp;
}
///
- ///
+ /// 检查分组是否存在下级
///
///
///
private async Task CheckNoNextGroupAsync(Guid currentCode)
{
var exists = await _dbContext.Queryable().Where(x => x.PCode == currentCode).AnyAsync();
- exists.ThrowIfTrue("存在下级设备分组");
+ exists.ThrowIfTrue("存在下级设备分组,无法分配设备");
}
///
@@ -165,7 +169,7 @@ public class DeviceGroupService : IDeviceGroupService
{
var devices = await _dbContext.Queryable().Where(x => request.DeviceCodes.Contains(x.Code)).ToListAsync();
//检查分组的分类控制
- devices.Any(x => x.Type != group.Type).ThrowIfTrue("存在设备类型有误,无法分配到当前分组");
+ devices.Any(x => x.Type != group.Type).ThrowIfTrue($"存在设备类型不一致,无法分配到当前{group.Type.GetDescription()}分组");
//重新赋值到请求参数中
request.DeviceCodes = devices.Select(x => x.Code).ToList();
diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs
index 18519961..7b0a9f2e 100644
--- a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs
+++ b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs
@@ -1,4 +1,4 @@
-using System.Diagnostics;
+using Dlhis.Basic.Device.Dtos;
using Dlhis.Basic.Device.Request;
using Dlhis.Basic.Device.Response;
using Dlhis.Entity.Basic.Entity;
@@ -8,6 +8,7 @@ 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;
@@ -28,6 +29,7 @@ public class DevicePermissionService : IDevicePermissionService
{
await GenerateDeviceTasksAsync(async () =>
{
+ //删除当前匹配的基地权限
var p = await _dbContext.Queryable()
.Where(x => x.AssignType == reuqest.AssignType)
.Where(x => x.AssignValue == reuqest.AssignValue)
@@ -36,17 +38,20 @@ public class DevicePermissionService : IDevicePermissionService
await _dbContext.DeleteReallyAsync(p);
- var devicePermissions = reuqest.Codes.Select(grpOrDeviceCode => new DevicePermissionEntity
+ //保存配置的权限
+ if (reuqest.Codes.IsPresent())
{
- AssignType = reuqest.AssignType,
- AssignValue = reuqest.AssignValue,
- UniqueType = reuqest.UniqueType,
- UniqueValue = grpOrDeviceCode,
+ var devicePermissions = reuqest.Codes.Select(code => new DevicePermissionEntity
+ {
+ AssignType = reuqest.AssignType,
+ AssignValue = reuqest.AssignValue,
+ UniqueType = reuqest.UniqueType,
+ UniqueValue = code,
- }).ToList();
+ }).ToList();
- if (devicePermissions.Any())
await _dbContext.InsertAsync(devicePermissions);
+ }
}, null);
}
@@ -56,92 +61,101 @@ public class DevicePermissionService : IDevicePermissionService
var devicePermissions = await _dbContext.Queryable().ToListAsync();
var deviceGroups = await _dbContext.Queryable().ToListAsync();
- return GetAssignmentsInternal(devicePermissions, deviceGroups, uniqueType, assignType, assignValue);
+ var result = GetAssignCodesInternal(devicePermissions, deviceGroups, uniqueType, assignType, assignValue);
+ return result.FirstOrDefault(x => x.Tenant == _currentUser.GetStringTenantId())?.Codes;
}
public async Task GenerateDeviceTasksAsync(Func func, List userNos)
{
- //var redisKey = "devicePermissions:" + _currentUser.GetStringTenantId();
-
- //获取当前所有人的权限
- if (userNos.IsEmpty())
- userNos = await GetPermissionUserNosAsync();
-
- var beforeDic = await GetAssignDeviceCodesInternalAsync(userNos); // new Dictionary>();
- //if (await _redisCache.KeyExistsAsync(redisKey))
- //{
- // var cache = await _redisCache.StringGetAsync>>(redisKey);
- // if (cache?.Any() == true)
- // {
- // beforeDic = cache;
- // }
- //}
- //else
- //{
- // beforeDic = await GetAssignDeviceCodesInternalAsync(userNos);
- //}
-
- //业务处理
- await func();
-
- //获取业务处理后所有人的权限
- var nextUserNos = await GetPermissionUserNosAsync();
- if (nextUserNos.Any())
- userNos = userNos.Concat(nextUserNos).Distinct().ToList();
-
- var currentDic = await GetAssignDeviceCodesInternalAsync(userNos);
-
- var deivces = await _dbContext.Queryable().ToListAsync();
- var waitTasks = new List();
- foreach (var userNo in userNos)
+ _dbContext.Client.QueryFilter.ClearAndBackup();
+ try
{
- beforeDic.TryGetValue(userNo, out var beforeCodes);
- beforeCodes ??= new List();
+ //获取所有人的权限
+ if (userNos.IsEmpty())
+ userNos = await GetPermissionUserNosAsync();
- currentDic.TryGetValue(userNo, out var currentCodes);
- currentCodes ??= new List();
+ //var before = await GetAssignDeviceCodesInternalAsync(userNos);
+ var before = await GetAssignDeviceCodesInternalAsync(userNos);
- //被删除
- var deletedItems = beforeCodes.Where(x => !currentCodes.Contains(x)).ToList();
- //新增
- var addItems = currentCodes.Where(x => !beforeCodes.Contains(x)).ToList();
+ _dbContext.Client.QueryFilter.Restore();
+ //业务处理
+ await func();
+ _dbContext.Client.QueryFilter.ClearAndBackup();
- if (!deletedItems.Any() && !addItems.Any())
+ //获取业务处理后所有人的权限
+ var nextUserNos = await GetPermissionUserNosAsync();
+ if (nextUserNos.Any())
+ userNos = userNos.Concat(nextUserNos).Distinct().ToList();
+
+ //var current = await GetAssignDeviceCodesInternalAsync(userNos);
+ var current = await GetAssignDeviceCodesInternalAsync(userNos);
+
+ var deivces = await _dbContext.Queryable().ToListAsync();
+ var waitTasks = new List();
+
+ foreach (var userNo in userNos)
{
- continue;
+ before.TryGetValue(userNo, out var beforeTenantDeviceCodes);
+ beforeTenantDeviceCodes ??= new();
+
+ current.TryGetValue(userNo, out var currentTenantDeviceCodes);
+ currentTenantDeviceCodes ??= new();
+
+ var tenants = beforeTenantDeviceCodes.Select(x => x.Tenant).Concat(currentTenantDeviceCodes.Select(x => x.Tenant)).Distinct().ToList();
+
+ foreach (var tenant in tenants)
+ {
+ var currentCodes = currentTenantDeviceCodes.FirstOrDefault(x => x.Tenant == tenant)?.Codes ?? new();
+ var beforeCodes = beforeTenantDeviceCodes.FirstOrDefault(x => x.Tenant == tenant)?.Codes ?? new();
+
+ //被删除
+ var deletedItems = beforeCodes.Where(x => !currentCodes.Contains(x)).ToList();
+ //新增
+ var addItems = currentCodes.Where(x => !beforeCodes.Contains(x)).ToList();
+
+ if (!deletedItems.Any() && !addItems.Any())
+ {
+ continue;
+ }
+
+ var deviceCodes = deivces.Where(x => deletedItems.Contains(x.Code) || addItems.Contains(x.Code)).Select(x => x.Code).ToList();
+ deletedItems = deletedItems.Where(x => deviceCodes.Contains(x)).ToList();
+ addItems = addItems.Where(x => deviceCodes.Contains(x)).ToList();
+
+ //下发任务创建
+ var toDeleted = deletedItems.Select(x => new DeviceTaskEntity
+ {
+ DeviceUniqueNo = deivces.First(item => item.Code == x).UniqueNo,
+ Status = DeviceTaskStatusEnumType.Wait,
+ Type = DeviceTaskEnumType.Delete,
+ UserNo = userNo,
+ Version = 0,
+ TenantId = tenant,
+ }).ToList();
+
+ var toAdd = addItems.Select(x => new DeviceTaskEntity
+ {
+ DeviceUniqueNo = deivces.First(item => item.Code == x).UniqueNo,
+ Status = DeviceTaskStatusEnumType.Wait,
+ Type = DeviceTaskEnumType.Add,
+ UserNo = userNo,
+ Version = 0,
+ TenantId = tenant,
+ }).ToList();
+
+ waitTasks.AddRange(toDeleted.Concat(toAdd).ToList());
+ }
}
- var deviceCodes = deivces.Where(x => deletedItems.Contains(x.Code) || addItems.Contains(x.Code)).Select(x => x.Code).ToList();
- deletedItems = deletedItems.Where(x => deviceCodes.Contains(x)).ToList();
- addItems = addItems.Where(x => deviceCodes.Contains(x)).ToList();
-
- //下发任务创建
- var toDeleted = deletedItems.Select(x => new DeviceTaskEntity
+ if (waitTasks.Any())
{
- DeviceUniqueNo = deivces.First(item => item.Code == x).UniqueNo,
- Status = DeviceTaskStatusEnumType.Wait,
- Type = DeviceTaskEnumType.Delete,
- UserNo = userNo,
- Version = 0,
- }).ToList();
-
- var toAdd = addItems.Select(x => new DeviceTaskEntity
- {
- DeviceUniqueNo = deivces.First(item => item.Code == x).UniqueNo,
- Status = DeviceTaskStatusEnumType.Wait,
- Type = DeviceTaskEnumType.Add,
- UserNo = userNo,
- Version = 0,
- }).ToList();
-
- waitTasks.AddRange(toDeleted.Concat(toAdd).ToList());
+ await _dbContext.InsertAsync(waitTasks);
+ }
}
-
- if (waitTasks.Any())
+ finally
{
- //await _redisCache.StringSetAsync(redisKey, JsonConvert.SerializeObject(currentDic));
- await _dbContext.InsertAsync(waitTasks);
+ _dbContext.Client.QueryFilter.Restore();
}
}
@@ -203,52 +217,10 @@ public class DevicePermissionService : IDevicePermissionService
var deviceGroups = await _dbContext.Queryable().ToListAsync();
var deviceRelationships = await _dbContext.Queryable().ToListAsync();
- return GetAssignDeviceCodesInternal(new List { gainfo }, gainfoGroups, devicePermissions, deviceGroups, deviceRelationships, userNo);
+ var result = GetAssignDeviceCodesInternal(gainfo, gainfoGroups, devicePermissions, deviceGroups, deviceRelationships);
+ return result.SelectMany(x => x.Codes).ToList();
}
- public List GetAssignDeviceCodesInternal(List gainfos,
- List gainfoGroupRelationships,
- List devicePermissions,
- List deviceGroups,
- List deviceGroupRelationships,
- string userNo)
- {
- var deviceCodes = new List();
- var deviceGroupCodes = new List();
-
- var gainfo = gainfos.Where(x => x.No == userNo).FirstOrDefault();
- var gainfoGroups = gainfoGroupRelationships.Where(x => x.UserNo == userNo).Select(x => x.GroupCode).ToList();
-
- var du = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.User, userNo);
- var gu = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.User, userNo);
- deviceCodes.AddRange(du);
- deviceGroupCodes.AddRange(gu);
-
- foreach (var group in gainfoGroups)
- {
- var dg = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Group, group.ToString());
- var gg = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Group, group.ToString());
- deviceCodes.AddRange(dg);
- deviceGroupCodes.AddRange(gg);
- }
-
- var dd = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Department, gainfo.DepartmentNo);
- var gd = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Department, gainfo.DepartmentNo);
- deviceCodes.AddRange(dd);
- deviceGroupCodes.AddRange(gd);
-
- var dt = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Tenant, gainfo.Werks);
- var gt = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Tenant, gainfo.Werks);
- deviceCodes.AddRange(du);
- deviceGroupCodes.AddRange(gu);
-
- var deveiceCodesByGroup = deviceGroupRelationships.Where(x => deviceGroupCodes.Contains(x.GroupCode)).Select(x => x.DeviceCode).ToList();
- deviceCodes.AddRange(deveiceCodesByGroup);
-
- return deviceCodes.Distinct().ToList();
- }
-
-
///
/// 获取用户权限设备
@@ -365,32 +337,132 @@ public class DevicePermissionService : IDevicePermissionService
}
}
-
- private async Task>> GetAssignDeviceCodesInternalAsync(List userNos)
+ private static List GetAssignCodesInternal(
+ List devicePermissions, List deviceGroups,
+ DeviceAssignmentTypeEnumType uniqueType, AssignTypeEnumType assignType, string assignValue)
+ {
+ var tenantDevicePermissions = devicePermissions
+ .Where(x => x.UniqueType == uniqueType)
+ .Where(x => x.AssignType == assignType)
+ .Where(x => x.AssignValue == assignValue)
+ .GroupBy(x => x.TenantId)
+ .Select(x => new UserTenantDeviceCodeDto { Tenant = x.Key, Codes = x.Select(x => x.UniqueValue).ToList() })
+ .ToList();
+
+ //处理获取设备分组的情况
+ if (uniqueType == DeviceAssignmentTypeEnumType.Group)
+ {
+ //开始递归处理
+ var tops = deviceGroups.Where(x => !x.PCode.HasValue).ToList();
+ tops.ForEach(x =>
+ {
+ RecursionGetNext(x, deviceGroups, tenantDevicePermissions, tenantDevicePermissions.SelectMany(x => x.Codes).Contains(x.Code));
+ });
+ }
+
+ return tenantDevicePermissions.GroupBy(x => x.Tenant).Select(x =>
+ {
+ var tenant = x.Key;
+
+ return new UserTenantDeviceCodeDto
+ {
+ Tenant = tenant,
+ Codes = x.SelectMany(item => item.Codes).ToList()
+ };
+ }).ToList();
+
+ void RecursionGetNext(DeviceGroupEntity current, List deviceGroups, List result, bool add)
+ {
+ var next = deviceGroups.Where(x => x.PCode == current.Code).ToList();
+ foreach (var item in next)
+ {
+ if (add)
+ {
+ result.Add(new UserTenantDeviceCodeDto { Tenant = item.TenantId, Codes = new List { item.Code } });
+ }
+ RecursionGetNext(item, deviceGroups, result, result.SelectMany(x => x.Codes).Contains(item.Code));
+ }
+ }
+ }
+
+ private async Task>> GetAssignDeviceCodesInternalAsync(List userNos)
{
- var sw = Stopwatch.StartNew();
var gainfos = await _dbContext.Queryable().Where(x => userNos.Contains(x.No)).ToListAsync();
if (!gainfos.Any())
{
- return new Dictionary>(0);
+ return new Dictionary>();
}
- var gainfoGroupRelationships = await _dbContext.Queryable().ToListAsync();
+ var gainfoGroupRelationships = await _dbContext.Queryable().Where(x => userNos.Contains(x.UserNo)).ToListAsync();
var devicePermissions = await _dbContext.Queryable().ToListAsync();
var deviceGroups = await _dbContext.Queryable().ToListAsync();
var deviceRelationships = await _dbContext.Queryable().ToListAsync();
- var result = new Dictionary>(gainfos.Count);
+ var result = new Dictionary>(gainfos.Count);
foreach (var gainfo in gainfos)
{
- var userNo = gainfo.No;
- var codes = GetAssignDeviceCodesInternal(gainfos, gainfoGroupRelationships, devicePermissions, deviceGroups, deviceRelationships, userNo);
-
- result.Add(userNo, codes);
+ var codes = GetAssignDeviceCodesInternal(gainfo, gainfoGroupRelationships, devicePermissions, deviceGroups, deviceRelationships);
+ result.Add(gainfo.No, codes);
}
- await Console.Out.WriteLineAsync($"获取所有人员权限耗时:{sw.ElapsedMilliseconds}");
return result;
}
+
+
+
+ private static List GetAssignDeviceCodesInternal(GainfoEntity gainfo,
+ List gainfoGroupRelationships,
+ List devicePermissions,
+ List deviceGroups,
+ List deviceGroupRelationships)
+ {
+ var userNo = gainfo.No;
+ var deviceCodes = new List();
+ var deviceGroupCodes = new List();
+
+ //获取人员的分组,跨基地
+ var gainfoGroups = gainfoGroupRelationships.Where(x => x.UserNo == userNo).Select(x => x.GroupCode).ToList();
+
+ //按User获取权限
+ var du = GetAssignCodesInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.User, userNo);
+ var gu = GetAssignCodesInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.User, userNo);
+ deviceCodes.AddRange(du);
+ deviceGroupCodes.AddRange(gu);
+
+ foreach (var groupCode in gainfoGroups)
+ {
+ var dg = GetAssignCodesInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Group, groupCode.ToString());
+ var gg = GetAssignCodesInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Group, groupCode.ToString());
+ deviceCodes.AddRange(dg);
+ deviceGroupCodes.AddRange(gg);
+ }
+
+ var dd = GetAssignCodesInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Department, gainfo.DepartmentNo);
+ var gd = GetAssignCodesInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Department, gainfo.DepartmentNo);
+ deviceCodes.AddRange(dd);
+ deviceGroupCodes.AddRange(gd);
+
+ var dt = GetAssignCodesInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Tenant, gainfo.Factory);
+ var gt = GetAssignCodesInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Tenant, gainfo.Factory);
+ deviceCodes.AddRange(du);
+ deviceGroupCodes.AddRange(gu);
+
+ var groupCodes = deviceGroupCodes.SelectMany(x => x.Codes).Distinct().ToList();
+ var deveiceCodesByGroup = deviceGroupRelationships.Where(x => groupCodes.Contains(x.GroupCode)).GroupBy(x => x.TenantId)
+ .Select(x => new UserTenantDeviceCodeDto
+ {
+ Tenant = x.Key,
+ Codes = x.Select(item => item.DeviceCode).Distinct().ToList()
+ });
+
+ deviceCodes.AddRange(deveiceCodesByGroup);
+
+ return deviceCodes.GroupBy(x => x.Tenant).Select(x => new UserTenantDeviceCodeDto
+ {
+ Tenant = x.Key,
+ Codes = x.SelectMany(item => item.Codes).Distinct().ToList()
+
+ }).ToList();
+ }
}
diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs
index e28e3c0d..f43f3c7a 100644
--- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs
+++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs
@@ -47,19 +47,25 @@ public class DeviceService : IDeviceService
var deviceUniqueNos = page.Data.Select(x => x.UniqueNo).ToList();
- var balanceRecords = await _dbContext.Queryable().Where(x => x.Type == BalanceRecordTypeEnumType.Out)
+ var balanceInfos = await _dbContext.Queryable().Where(x => x.Type == BalanceRecordTypeEnumType.Out)
.Where(x => deviceUniqueNos.Contains(x.DeviceInfo))
.Select(x => new
{
- x.Amount,
- x.UserCode
+ x.DeviceInfo,
+ Amount = SqlFunc.AggregateSum(x.Amount),
+ UserCount = SqlFunc.AggregateDistinctCount(x.UserCode)
})
+ .GroupBy(x => x.DeviceInfo)
.ToListAsync();
page.Data.ForEach(device =>
{
- device.Amount = balanceRecords.Sum(x => x.Amount);
- device.UserCount = balanceRecords.DistinctBy(x => x.UserCode).Count();
+ var info = balanceInfos.FirstOrDefault(x => x.DeviceInfo == device.UniqueNo);
+ if (info != null)
+ {
+ device.Amount = info.Amount;
+ device.UserCount = info.UserCount;
+ }
});
return page;
@@ -105,7 +111,6 @@ public class DeviceService : IDeviceService
var existsG = await _dbContext.Queryable()
.LeftJoin((dgr, dg) => dgr.GroupCode == dg.Code)
.Where((dgr, dg) => dgr.DeviceCode == entity.Code)
- .Where((dgr, dg) => dg.Type != null)
.AnyAsync();
existsG.ThrowIfTrue("存在设备分组,不可修改设备分类");
diff --git a/Src/Dlhis.Basic/Organization/Controllers/GainfoGroupsController.cs b/Src/Dlhis.Basic/Organization/Controllers/GainfoGroupsController.cs
index ca2225a9..8fc33da5 100644
--- a/Src/Dlhis.Basic/Organization/Controllers/GainfoGroupsController.cs
+++ b/Src/Dlhis.Basic/Organization/Controllers/GainfoGroupsController.cs
@@ -63,6 +63,8 @@ public class GainfoGroupsController : ControllerBase
///
///
[HttpPost("assign")]
+ [IgnoreTenant]
+ [Transactional]
public async Task AssignGainfosAsync(GainfoAssignRequest request)
{
await _gainfoGroupService.AssignGainfosAsync(request);
diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs
index ea35ff11..3c00eeca 100644
--- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs
+++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs
@@ -1,4 +1,5 @@
-using Dlhis.Basic.Organization.Request;
+using Dlhis.Basic.Device.Services;
+using Dlhis.Basic.Organization.Request;
using Dlhis.Basic.Organization.Response;
using Dlhis.Entity.Basic.Entity;
using Kurisu.AspNetCore.Utils.Extensions;
@@ -13,11 +14,13 @@ public class GainfoGroupService : IGainfoGroupService
{
private readonly IDbContext _dbContext;
private readonly ICurrentUser _currentUser;
+ private readonly IDevicePermissionService _devicePermissionService;
- public GainfoGroupService(IDbContext dbContext, ICurrentUser currentUser)
+ public GainfoGroupService(IDbContext dbContext, ICurrentUser currentUser, IDevicePermissionService devicePermissionService)
{
_dbContext = dbContext;
_currentUser = currentUser;
+ _devicePermissionService = devicePermissionService;
}
public async Task> GetTreeAsync()
@@ -53,7 +56,7 @@ public class GainfoGroupService : IGainfoGroupService
{
_dbContext.Client.QueryFilter.Restore();
}
-
+
if (!request.Id.HasValue)
{
@@ -86,18 +89,32 @@ public class GainfoGroupService : IGainfoGroupService
public async Task AssignGainfosAsync(GainfoAssignRequest request)
{
- var relations = await _dbContext.Queryable().Where(x => x.GroupCode == request.GroupCode).ToListAsync();
- await _dbContext.DeleteReallyAsync(relations);
-
- request.UserNos = await _dbContext.Queryable().Where(x => request.UserNos.Contains(x.No)).Select(x => x.No).ToListAsync();
- var entities = request.UserNos.Select(x => new GainfoGroupRelationshipEntity
+ if (request.UserNos.IsPresent())
{
- GroupCode = request.GroupCode,
- UserNo = x
+ var pGrp = await _dbContext.Queryable().Where(x => x.Code == request.GroupCode).FirstAsync();
+ (pGrp?.Editable == false && pGrp?.IsDefault == true).ThrowIfTrue("不可分配人员到当前分组");
+ }
- }).ToList();
+ var existsNextGroup = await _dbContext.Queryable().Where(x => x.PCode == request.GroupCode).AnyAsync();
+ existsNextGroup.ThrowIfTrue("存在下级分组,无法分配人员");
- await _dbContext.InsertAsync(entities);
+ await _devicePermissionService.GenerateDeviceTasksAsync(async () =>
+ {
+ var relations = await _dbContext.Queryable().Where(x => x.GroupCode == request.GroupCode).ToListAsync();
+ await _dbContext.DeleteReallyAsync(relations);
+
+ request.UserNos = await _dbContext.Queryable().Where(x => request.UserNos.Contains(x.No)).Select(x => x.No).ToListAsync();
+ var entities = request.UserNos.Select(x => new GainfoGroupRelationshipEntity
+ {
+ GroupCode = request.GroupCode,
+ UserNo = x,
+
+
+ }).ToList();
+
+ await _dbContext.InsertAsync(entities);
+
+ }, null);
}
//******************************************************* help methods ***********************************************************
diff --git a/Src/Dlhis.Basic/appsettings.json b/Src/Dlhis.Basic/appsettings.json
index 428e90e9..79da19b2 100644
--- a/Src/Dlhis.Basic/appsettings.json
+++ b/Src/Dlhis.Basic/appsettings.json
@@ -25,7 +25,7 @@
"LogConnectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=log;charset=utf8mb4;",
"Timeout": 30,
"SlowSqlTime": 1,
- "EnableSqlLog": true
+ "EnableSqlLog": false
},
"SwaggerOptions": {
"Enable": true,
diff --git a/Src/Dlhis.Canteen/Dlhis.Canteen.csproj b/Src/Dlhis.Canteen/Dlhis.Canteen.csproj
index 8ad57920..a17298ed 100644
--- a/Src/Dlhis.Canteen/Dlhis.Canteen.csproj
+++ b/Src/Dlhis.Canteen/Dlhis.Canteen.csproj
@@ -18,8 +18,8 @@
-
+
@@ -37,6 +37,7 @@
+
diff --git a/Src/Dlhis.Canteen/Dockerfile b/Src/Dlhis.Canteen/Dockerfile
index 5e510329..f9585740 100644
--- a/Src/Dlhis.Canteen/Dockerfile
+++ b/Src/Dlhis.Canteen/Dockerfile
@@ -8,8 +8,8 @@ FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["Src/Dlhis.Canteen/Dlhis.Canteen.csproj", "Src/Dlhis.Canteen/"]
COPY ["Src/Dlhis.Basic.Api/Dlhis.Basic.Api.csproj", "Src/Dlhis.Basic.Api/"]
-COPY ["Src/Dlhis.Common.Api/Dlhis.Common.Api.csproj", "Src/Dlhis.Common.Api/"]
COPY ["Src/Dlhis.Entity/Dlhis.Entity.csproj", "Src/Dlhis.Entity/"]
+COPY ["Src/Dlhis.Sys.Api/Dlhis.Sys.Api.csproj", "Src/Dlhis.Sys.Api/"]
RUN dotnet restore "Src/Dlhis.Canteen/Dlhis.Canteen.csproj"
COPY . .
WORKDIR "/src/Src/Dlhis.Canteen"
diff --git a/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs b/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs
index b8ab1e83..e114ea36 100644
--- a/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs
+++ b/Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs
@@ -1,6 +1,7 @@
using Dlhis.Canteen.Order.Request;
using Dlhis.Canteen.Order.Response;
using Dlhis.Canteen.Order.Services;
+using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop;
using Kurisu.Core.DataAccess.Dto;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
@@ -28,6 +29,7 @@ public class BalancesController : ControllerBase
///
///
///
+ [DataPermission]
[HttpGet]
public async Task> GetPageAsync([FromQuery] BalanceRecordPageRequest request)
{
@@ -89,7 +91,7 @@ public class BalancesController : ControllerBase
[HttpGet("recordByCostId")]
public async Task> RecordByCostIdAsync([FromQuery] BalanceRecordPageByCostIdRequest request)
{
- return await _balanceService.RecordByCostIdAsync(request);
+ return await _balanceService.RecordByCostIdAsync(request);
}
///
@@ -186,9 +188,9 @@ public class BalancesController : ControllerBase
///
///
[HttpPost("disposition")]
- public async Task DispositionDeviceAsync([FromQuery]DispositionDeviceRequest request)
+ public async Task DispositionDeviceAsync([FromQuery] DispositionDeviceRequest request)
{
- await _balanceService.DispositionDeviceAsync(request);
+ await _balanceService.DispositionDeviceAsync(request);
}
diff --git a/Src/Dlhis.Canteen/Order/Response/BalanceRecordResponse.cs b/Src/Dlhis.Canteen/Order/Response/BalanceRecordResponse.cs
index d8ffb6ad..dcb63bab 100644
--- a/Src/Dlhis.Canteen/Order/Response/BalanceRecordResponse.cs
+++ b/Src/Dlhis.Canteen/Order/Response/BalanceRecordResponse.cs
@@ -119,4 +119,14 @@ public class BalanceRecordResponse
/// 汇总金额
///
public decimal Sum { get; set; }
+
+ ///
+ /// 厂区id
+ ///
+ public string TenantId { get; set; }
+
+ ///
+ /// 厂区名称
+ ///
+ public string TenantName { get; set; }
}
diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs
index dcfc0ab5..9cddd2da 100644
--- a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs
+++ b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs
@@ -5,6 +5,7 @@ using Dlhis.Entity.Canteen.Entities;
using Dlhis.Entity.Canteen.Enums;
using Dlhis.Entity.Device.Entities;
using Dlhis.Entity.Device.Enums;
+using Dlhis.Sys.Api;
using Kurisu.AspNetCore.UnifyResultAndValidation;
using Kurisu.AspNetCore.Utils.Extensions;
using Kurisu.Core.DataAccess.Dto;
@@ -23,12 +24,14 @@ public class BalanceService : IBalanceService
private readonly IDbContext _dbContext;
private readonly ICurrentUser _currentUser;
private readonly ILogger _logger;
+ private readonly ITenantApi _tenantApi;
- public BalanceService(IDbContext dbContext, ICurrentUser currentUser, ILogger logger)
+ public BalanceService(IDbContext dbContext, ICurrentUser currentUser, ILogger logger ,ITenantApi tenantApi)
{
_dbContext = dbContext;
_currentUser = currentUser;
_logger = logger;
+ _tenantApi = tenantApi;
}
public async Task> GetPageAsync(BalanceRecordPageRequest request)
@@ -72,10 +75,26 @@ public class BalanceService : IBalanceService
DepartmentName = department.Name,
BusinessPlaceName = bplace.Name,
BusinessShiftName = type.Display,
- CostDateTime = record.CostDateTime
+ CostDateTime = record.CostDateTime,
+ TenantId = record.TenantId,
})
.ToPageListAsync(request);
+ try
+ {
+ var tenantResult = await _tenantApi.GetTenantsInternalAsync();
+ var tenants = tenantResult.Data;
+
+ page.Data.ForEach(item =>
+ {
+ item.TenantName = tenants.FirstOrDefault(x => x.Code == item.TenantId)?.Name;
+ });
+
+ }
+ catch (Exception)
+ {
+ }
+
return page;
}
///
@@ -563,7 +582,7 @@ public class BalanceService : IBalanceService
var offCount = await GetOfflineDevicesCount(devices);
var places = await _dbContext.Queryable()
- .Where(x =>x.Status == CanteenBusinessPlaceStatusEnumType.Opened)
+ .Where(x => x.Status == CanteenBusinessPlaceStatusEnumType.Opened)
.ToListAsync();
@@ -826,7 +845,7 @@ public class BalanceService : IBalanceService
var devices = await _dbContext.Queryable().ToListAsync();
- if (request.UniqueNos!=null && request.UniqueNos.Count > 0)
+ if (request.UniqueNos != null && request.UniqueNos.Count > 0)
{
foreach (var no in request.UniqueNos)
{
diff --git a/Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs b/Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs
index 5804a32d..ddedd0ec 100644
--- a/Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs
+++ b/Src/Dlhis.Entity/Basic/Entity/DeviceEntity.cs
@@ -1,7 +1,6 @@
using Dlhis.Entity.Device.Enums;
using Kurisu.Core.DataAccess.Entity;
using Kurisu.SqlSugar;
-using Mapster;
using SqlSugar;
using SqlSugar.DbConvert;
@@ -22,8 +21,7 @@ public class DeviceEntity : SugarBaseEntity, ITenantId
///
/// 设备唯一码,IP/MAC/SNO
///
- [AdaptIgnore(MemberSide.Destination)]
- [SugarColumn(ColumnDescription = "设备唯一码", UniqueGroupNameList = new[] { "Idx_Device_UniqueNo" })]
+ [SugarColumn(ColumnDescription = "设备唯一码", IsNullable = false, UniqueGroupNameList = new[] { "Idx_Device_UniqueNo" })]
public string UniqueNo { get; set; }
///
diff --git a/Src/Dlhis.Entity/Basic/Entity/DeviceTemplateEntity.cs b/Src/Dlhis.Entity/Basic/Entity/DeviceTemplateEntity.cs
index 8ea2e16b..84cf035b 100644
--- a/Src/Dlhis.Entity/Basic/Entity/DeviceTemplateEntity.cs
+++ b/Src/Dlhis.Entity/Basic/Entity/DeviceTemplateEntity.cs
@@ -1,6 +1,4 @@
-using System;
-using Kurisu.Core.DataAccess.Entity;
-using Kurisu.SqlSugar;
+using Kurisu.SqlSugar;
using SqlSugar;
namespace Dlhis.Entity.Basic.Entity;
@@ -9,7 +7,7 @@ namespace Dlhis.Entity.Basic.Entity;
/// 设备配置模板
///
[SugarTable(TableName = "DeviceTemplate", TableDescription = "设备配置模板")]
-public class DeviceTemplateEntity : SugarBaseEntity, ITenantId
+public class DeviceTemplateEntity : SugarBaseEntity
{
///
/// 模板code
@@ -34,7 +32,4 @@ public class DeviceTemplateEntity : SugarBaseEntity, ITenantId
///
[SugarColumn(ColumnDescription = "模板json")]
public string Template { get; set; }
-
-
- public string TenantId { get; set; }
}
\ No newline at end of file
diff --git a/Src/Dlhis.Entity/Basic/Entity/GainfoGroupEntity.cs b/Src/Dlhis.Entity/Basic/Entity/GainfoGroupEntity.cs
index 84c1bbf1..809c8727 100644
--- a/Src/Dlhis.Entity/Basic/Entity/GainfoGroupEntity.cs
+++ b/Src/Dlhis.Entity/Basic/Entity/GainfoGroupEntity.cs
@@ -36,14 +36,14 @@ public class GainfoGroupEntity : SugarBaseEntity, ITenantId
///
/// 是否默认分组
///
- [SugarColumn(ColumnDescription = "是否默认分组", ColumnDataType = "bit")]
- public bool IsDefault { get; set; }
+ [SugarColumn(ColumnDescription = "是否默认分组", ColumnDataType = "bit", DefaultValue = "1")]
+ public bool IsDefault { get; set; } = true;
///
/// 是否可编辑
///
- [SugarColumn(ColumnDescription = "是否可编辑", ColumnDataType = "bit")]
- public bool Editable { get; set; }
+ [SugarColumn(ColumnDescription = "是否可编辑", ColumnDataType = "bit", DefaultValue = "1")]
+ public bool Editable { get; set; } = true;
public string TenantId { get; set; }
diff --git a/Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs b/Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs
index a56c8c97..0d22dc00 100644
--- a/Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs
+++ b/Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs
@@ -41,13 +41,13 @@ public class DeviceGroupEntity : SugarBaseEntity, ITenantId, ISoftDeleted
/// 是否可编辑
///
[SugarColumn(ColumnDataType = "bit", DefaultValue = "1", ColumnDescription = "是否可编辑")]
- public bool Editable { get; set; }
+ public bool Editable { get; set; } = true;
///
/// 可设置下级
///
[SugarColumn(ColumnDataType = "bit", DefaultValue = "1")]
- public bool AbleSetNext { get; set; }
+ public bool AbleSetNext { get; set; } = true;
///
/// 备注
diff --git a/Src/Dlhis.Entity/Device/Entities/DeviceGroupRelationshipEntity.cs b/Src/Dlhis.Entity/Device/Entities/DeviceGroupRelationshipEntity.cs
index 352c55c4..d3d79fe0 100644
--- a/Src/Dlhis.Entity/Device/Entities/DeviceGroupRelationshipEntity.cs
+++ b/Src/Dlhis.Entity/Device/Entities/DeviceGroupRelationshipEntity.cs
@@ -8,7 +8,7 @@ namespace Dlhis.Entity.Device.Entities;
/// 设备组/设备关系
///
[SugarTable(TableName = "DeviceGroupRelationship", TableDescription = "设备组/设备关系")]
-public class DeviceGroupRelationshipEntity : SugarBaseEntity, ITenantId, ISoftDeleted
+public class DeviceGroupRelationshipEntity : SugarBaseEntity, ITenantId
{
///
/// 设备组code
@@ -22,8 +22,5 @@ public class DeviceGroupRelationshipEntity : SugarBaseEntity, ITenantId, ISoftDe
[SugarColumn(ColumnDescription = "设备code")]
public Guid DeviceCode { get; set; }
-
public string TenantId { get; set; }
-
- public bool IsDeleted { get; set; }
}
\ No newline at end of file
diff --git a/Src/Dlhis.Entity/Device/Entities/DeviceTask.cs b/Src/Dlhis.Entity/Device/Entities/DeviceTask.cs
index 84708348..f1348681 100644
--- a/Src/Dlhis.Entity/Device/Entities/DeviceTask.cs
+++ b/Src/Dlhis.Entity/Device/Entities/DeviceTask.cs
@@ -23,10 +23,10 @@ public class DeviceTaskEntity : SugarBaseEntity, ITenantId, IVersion
///
public string UserNo { get; set; }
-
///
/// 设备唯一号
///
+ [SugarColumn(IsNullable = false, IndexGroupNameList = new[] { "idx_DeviceTask_DeviceUniqueNo" })]
public string DeviceUniqueNo { get; set; }
///
diff --git a/Src/Dlhis.Entity/Sys/Entities/DevicePermissionEntity.cs b/Src/Dlhis.Entity/Sys/Entities/DevicePermissionEntity.cs
index 8f2a3c09..39135b68 100644
--- a/Src/Dlhis.Entity/Sys/Entities/DevicePermissionEntity.cs
+++ b/Src/Dlhis.Entity/Sys/Entities/DevicePermissionEntity.cs
@@ -13,7 +13,7 @@ namespace Dlhis.Entity.Sys.Entities;
public class DevicePermissionEntity : SugarBaseEntity, ITenantId
{
///
- /// 分配权限类型
+ /// 分配权限类型(User,Role,Group...)
///
[SugarColumn(ColumnDataType = "varchar(50)", ColumnDescription = "分配权限类型", SqlParameterDbType = typeof(EnumToStringConvert))]
public AssignTypeEnumType AssignType { get; set; }
@@ -25,7 +25,7 @@ public class DevicePermissionEntity : SugarBaseEntity, ITenantId
public string AssignValue { get; set; }
///
- /// 设备权限类型
+ /// 设备权限类型(Device/DeviceGroup)
///
[SugarColumn(ColumnDataType = "varchar(50)", ColumnDescription = "设备权限类型", SqlParameterDbType = typeof(EnumToStringConvert))]
public DeviceAssignmentTypeEnumType UniqueType { get; set; }
diff --git a/Src/Dlhis.ScheduledTask/CommonJobs/HeartbeatJob.cs b/Src/Dlhis.ScheduledTask/CommonJobs/HeartbeatJob.cs
index ed994038..bd7cdb19 100644
--- a/Src/Dlhis.ScheduledTask/CommonJobs/HeartbeatJob.cs
+++ b/Src/Dlhis.ScheduledTask/CommonJobs/HeartbeatJob.cs
@@ -38,11 +38,11 @@ public class HeartbeatJob
await _dbContext.Updateable().SetColumns(x => x.LastHeartbeatTime == DateTime.Now)
.Where(x => x.DeviceUniqueNo == device.UniqueNo).ExecuteCommandAsync();
- _logger.LogInformation("心跳设备成功:{no}", device.UniqueNo);
+ // _logger.LogInformation("心跳设备成功:{no}", device.UniqueNo);
}
- catch (Exception ex)
+ catch (Exception)
{
- _logger.LogError(ex, "心跳设备失败:{no}. {message}", device.UniqueNo, ex.Message);
+ //_logger.LogError(ex, "心跳设备失败:{no}. {message}", device.UniqueNo, ex.Message);
}
}
}
diff --git a/Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj b/Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj
index 96b47437..9efffeb1 100644
--- a/Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj
+++ b/Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj
@@ -20,7 +20,7 @@
-
+
diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Controllers/DeviceTaskAssignmentsController.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Controllers/DeviceTaskAssignmentsController.cs
index 52822708..5d488ed9 100644
--- a/Src/Dlhis.ScheduledTask/TaskAssignment/Controllers/DeviceTaskAssignmentsController.cs
+++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Controllers/DeviceTaskAssignmentsController.cs
@@ -1,6 +1,7 @@
using Dlhis.ScheduledTask.TaskAssignment.Request;
using Dlhis.ScheduledTask.TaskAssignment.Response;
using Dlhis.ScheduledTask.TaskAssignment.Services;
+using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop;
using Kurisu.Core.DataAccess.Dto;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
@@ -28,6 +29,7 @@ public class DeviceTaskAssignmentsController : ControllerBase
///
///
[HttpGet("page")]
+ [DataPermission]
public async Task> GetPageAsync([FromQuery] DeviceTaskAssignmentRequest request)
{
return await _deviceTaskAssignmentService.GetPageAsync(request);
diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Response/DeviceTaskAssignmentResponse.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Response/DeviceTaskAssignmentResponse.cs
index 7eb69334..73ad0d63 100644
--- a/Src/Dlhis.ScheduledTask/TaskAssignment/Response/DeviceTaskAssignmentResponse.cs
+++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Response/DeviceTaskAssignmentResponse.cs
@@ -66,4 +66,15 @@ public class DeviceTaskAssignmentResponse
/// 数据状态最新修改时间
///
public DateTime LastUpdateTime { get; set; }
+
+
+ ///
+ /// 厂区id
+ ///
+ public string TenantId { get; set; }
+
+ ///
+ /// 厂区名称
+ ///
+ public string TenantName { get; set; }
}
diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs
index f2cff78a..8e7b2cb9 100644
--- a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs
+++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs
@@ -3,6 +3,7 @@ using Dlhis.Entity.Device.Entities;
using Dlhis.Entity.Device.Enums;
using Dlhis.ScheduledTask.TaskAssignment.Request;
using Dlhis.ScheduledTask.TaskAssignment.Response;
+using Dlhis.Sys.Api;
using Kurisu.AspNetCore.Utils.Extensions;
using Kurisu.Core.DataAccess.Dto;
using Kurisu.SqlSugar.Extensions;
@@ -14,10 +15,12 @@ namespace Dlhis.ScheduledTask.TaskAssignment.Services.Implements;
public class DeviceTaskAssignmentService : IDeviceTaskAssignmentService
{
private readonly IDbContext _dbContext;
+ private readonly ITenantApi _tenantApi;
- public DeviceTaskAssignmentService(IDbContext dbContext)
+ public DeviceTaskAssignmentService(IDbContext dbContext, ITenantApi tenantApi)
{
_dbContext = dbContext;
+ _tenantApi = tenantApi;
}
public async Task> GetPageAsync(DeviceTaskAssignmentRequest request)
@@ -27,6 +30,7 @@ public class DeviceTaskAssignmentService : IDeviceTaskAssignmentService
.WhereIF(!request.Search.IsEmpty(), (deviceTask, ga) => deviceTask.UserNo == request.Search || ga.Name.Contains(request.Search))
.WhereIF(request.Type.HasValue, deviceTask => deviceTask.Type == request.Type)
.WhereIF(request.Status.HasValue, deviceTask => deviceTask.Status == request.Status)
+ .Where(deviceTask => 1 == 1)
.OrderBy(deviceTask => deviceTask.CreateTime, OrderByType.Desc)
.Select((deviceTask, ga) => new DeviceTaskAssignmentResponse
{
@@ -40,10 +44,27 @@ public class DeviceTaskAssignmentService : IDeviceTaskAssignmentService
UserCode = ga.Code,
Type = deviceTask.Type,
CreateTime = deviceTask.CreateTime,
- LastUpdateTime = deviceTask.ModifiedTime
+ LastUpdateTime = deviceTask.ModifiedTime,
+ TenantId = deviceTask.TenantId,
})
.ToPageListAsync(request);
+
+ try
+ {
+ var tenantResult = await _tenantApi.GetTenantsInternalAsync();
+ var tenants = tenantResult.Data;
+
+ page.Data.ForEach(item =>
+ {
+ item.TenantName = tenants.FirstOrDefault(x => x.Code == item.TenantId)?.Name;
+ });
+
+ }
+ catch (Exception)
+ {
+ }
+
return page;
}