fix 设备组重组
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Dlhis.Basic.Device.Request;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Dlhis.Basic.Device.Request;
|
||||
using Dlhis.Basic.Device.Response;
|
||||
using Dlhis.Basic.Device.Services;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
@@ -26,14 +27,16 @@ public class DeviceGroupsController : ControllerBase
|
||||
/// <summary>
|
||||
/// 获取设备组树
|
||||
/// </summary>
|
||||
/// <param name="showDevices">是否显示设备</param>
|
||||
/// <param name="type">分组类型</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("tree")]
|
||||
[IgnoreTenant]
|
||||
public async Task<List<DeviceGroupTreeResponse>> GetTreeAsync(bool showDevices, DeviceTypeEnumType? type)
|
||||
public async Task<List<DeviceGroupTreeResponse>> GetTreeAsync(
|
||||
[EnumDataType(typeof(DeviceTypeEnumType), ErrorMessage = "请选择正确的类型")]
|
||||
DeviceTypeEnumType type
|
||||
)
|
||||
{
|
||||
return await _deviceGroupService.GetTreeAsync(showDevices, type);
|
||||
return await _deviceGroupService.GetTreeAsync(type);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -54,9 +57,9 @@ public class DeviceGroupsController : ControllerBase
|
||||
/// <param name="code"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("devices")]
|
||||
public async Task<List<DeviceUnderGroupResponse>> GetDevicesAsync(Guid code)
|
||||
public async Task<List<DeviceUnderGroupResponse>> GetDevicesByGroupCodeAsync(Guid code)
|
||||
{
|
||||
return await _deviceGroupService.GetDevicesAsync(code);
|
||||
return await _deviceGroupService.GetDevicesByGroupCodeAsync(code);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -4,6 +4,9 @@ namespace Dlhis.Basic.Device.Response;
|
||||
|
||||
public class DeviceUnderGroupResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// 设备code
|
||||
/// </summary>
|
||||
public Guid Code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -21,7 +24,6 @@ public class DeviceUnderGroupResponse
|
||||
/// </summary>
|
||||
public DeviceTypeEnumType Type { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 是否启用
|
||||
/// </summary>
|
||||
|
||||
@@ -6,11 +6,11 @@ namespace Dlhis.Basic.Device.Services;
|
||||
|
||||
public interface IDeviceGroupService : IScopeDependency
|
||||
{
|
||||
Task<List<DeviceGroupTreeResponse>> GetTreeAsync(bool showDevices, DeviceTypeEnumType? type);
|
||||
Task<List<DeviceGroupTreeResponse>> GetTreeAsync(DeviceTypeEnumType type);
|
||||
|
||||
Task SaveAsync(DeviceGroupSaveRequest request);
|
||||
|
||||
Task<List<DeviceUnderGroupResponse>> GetDevicesAsync(Guid code);
|
||||
Task<List<DeviceUnderGroupResponse>> GetDevicesByGroupCodeAsync(Guid code);
|
||||
|
||||
Task AssignDevicesAsync(DeviceAssignRequest requests);
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ using Dlhis.Basic.Device.Response;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Dlhis.Sys.Api;
|
||||
using Kurisu.AspNetCore.Authentication.Abstractions;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
@@ -15,27 +16,42 @@ public class DeviceGroupService : IDeviceGroupService
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly IDevicePermissionService _devicePermissionService;
|
||||
private readonly ICurrentUser _currentUser;
|
||||
private readonly ITenantApi _tenantApi;
|
||||
|
||||
public DeviceGroupService(IDbContext dbContext, IDevicePermissionService devicePermissionService, ICurrentUser currentUser)
|
||||
public DeviceGroupService(IDbContext dbContext,
|
||||
IDevicePermissionService devicePermissionService,
|
||||
ICurrentUser currentUser,
|
||||
ITenantApi tenantApi
|
||||
)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_devicePermissionService = devicePermissionService;
|
||||
_currentUser = currentUser;
|
||||
_tenantApi = tenantApi;
|
||||
}
|
||||
|
||||
|
||||
public async Task<List<DeviceGroupTreeResponse>> GetTreeAsync(bool showDevices, DeviceTypeEnumType? type)
|
||||
public async Task<List<DeviceGroupTreeResponse>> GetTreeAsync(DeviceTypeEnumType type)
|
||||
{
|
||||
var tenantResult = await _tenantApi.GetMyTenantsAsync();
|
||||
var tenantIds = tenantResult.Data.Select(x => x.Code).ToList();
|
||||
tenantIds.AddRange(tenantResult.Data.Select(x => x.PCode));
|
||||
|
||||
var deviceGroups = await _dbContext.Queryable<DeviceGroupEntity>()
|
||||
.WhereIF(type.HasValue, x => x.Type == type)
|
||||
.Where(x => tenantIds.Contains(x.TenantId))
|
||||
.Where(x => x.Type == type)
|
||||
.Select<DeviceGroupTreeResponse>()
|
||||
.ToListAsync();
|
||||
|
||||
var others = await _dbContext.Queryable<DeviceGroupEntity>()
|
||||
.Where(x => x.Type == type)
|
||||
.Where(x => x.Name == "*共用区域" || x.Name == "*非共用区域" || x.Name == "*通用考勤设备组" || x.Name == "*专用考勤设备组")
|
||||
.Select<DeviceGroupTreeResponse>()
|
||||
.ToListAsync();
|
||||
deviceGroups.AddRange(others);
|
||||
|
||||
var tops = deviceGroups.Where(x => !x.PCode.HasValue).ToList();
|
||||
tops.ForEach(x =>
|
||||
{
|
||||
RecursionGetNext(x, deviceGroups, showDevices);
|
||||
});
|
||||
tops.ForEach(x => { RecursionGetNext(x, deviceGroups); });
|
||||
|
||||
return tops;
|
||||
}
|
||||
@@ -69,7 +85,7 @@ public class DeviceGroupService : IDeviceGroupService
|
||||
|
||||
existsDiffNextGroups.ThrowIfTrue("存在下级分组类型不一致,无法修改");
|
||||
|
||||
var nextDevices = await GetDevicesAsync(entity.Code);
|
||||
var nextDevices = await GetDevicesByGroupCodeAsync(entity.Code);
|
||||
nextDevices.Any(x => x.Type != request.Type).ThrowIfTrue("分组设备类型不匹配,无法修改类型");
|
||||
}
|
||||
|
||||
@@ -99,15 +115,13 @@ public class DeviceGroupService : IDeviceGroupService
|
||||
DeviceCode = x,
|
||||
|
||||
TenantId = _currentUser.GetStringTenantId(),
|
||||
|
||||
}).ToList();
|
||||
|
||||
await _dbContext.InsertAsync(entities);
|
||||
|
||||
}, null);
|
||||
}
|
||||
|
||||
public async Task<List<DeviceUnderGroupResponse>> GetDevicesAsync(Guid code)
|
||||
public async Task<List<DeviceUnderGroupResponse>> GetDevicesByGroupCodeAsync(Guid code)
|
||||
{
|
||||
var relationships = await _dbContext.Queryable<DeviceGroupRelationshipEntity>()
|
||||
.Where(x => x.GroupCode == code)
|
||||
@@ -198,47 +212,14 @@ public class DeviceGroupService : IDeviceGroupService
|
||||
/// </summary>
|
||||
/// <param name="current"></param>
|
||||
/// <param name="deviceGroups"></param>
|
||||
/// <param name="showDevices"></param>
|
||||
private void RecursionGetNext(DeviceGroupTreeResponse current, List<DeviceGroupTreeResponse> deviceGroups, bool showDevices)
|
||||
private static void RecursionGetNext(DeviceGroupTreeResponse current, List<DeviceGroupTreeResponse> deviceGroups)
|
||||
{
|
||||
var currentTenantId = _currentUser.GetStringTenantId();
|
||||
var next = deviceGroups.Where(x =>
|
||||
{
|
||||
if (x.PCode == current.Code)
|
||||
{
|
||||
if (x.TenantId.IsEmpty())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return x.TenantId == currentTenantId;
|
||||
}
|
||||
}
|
||||
var next = deviceGroups.Where(x => x.PCode == current.Code).ToList();
|
||||
|
||||
return false;
|
||||
|
||||
}).ToList();
|
||||
current.Next = next;
|
||||
foreach (var item in next)
|
||||
{
|
||||
RecursionGetNext(item, deviceGroups, showDevices);
|
||||
}
|
||||
|
||||
//最后层级附加设备信息
|
||||
if (!current.Next.Any() && showDevices)
|
||||
{
|
||||
current.Next = _dbContext.Queryable<DeviceGroupRelationshipEntity>()
|
||||
.LeftJoin<DeviceEntity>((relation, device) => relation.DeviceCode == device.Code)
|
||||
.Where((relation, device) => relation.GroupCode == current.Code)
|
||||
.Select((relation, device) => new DeviceGroupTreeResponse
|
||||
{
|
||||
Code = device.Code,
|
||||
Name = device.UniqueNo,
|
||||
PCode = relation.GroupCode
|
||||
})
|
||||
.Distinct()
|
||||
.ToList();
|
||||
RecursionGetNext(item, deviceGroups);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ public class CreateDefinitelyGroupJob : BaseJob
|
||||
_tenantApi = tenantApi;
|
||||
}
|
||||
|
||||
private static readonly string _remark = "系统自动生成";
|
||||
private const string _remark = "系统自动生成";
|
||||
|
||||
protected override async Task RunAsync(IServiceProvider serviceProvider)
|
||||
{
|
||||
@@ -45,16 +45,15 @@ public class CreateDefinitelyGroupJob : BaseJob
|
||||
//*****************************************************门禁设备组********************************************************/
|
||||
|
||||
await CreateDeviceGroupAsync(DeviceTypeEnumType.Door, new List<string> { "*共用区域", "*非共用区域" }, tenants);
|
||||
|
||||
}
|
||||
|
||||
private async Task CreateGainfoGroupsAsync(List<TenantResponse> tenants)
|
||||
{
|
||||
var grps = new List<string> { "*自定义人员分组", "*督查组", "*X3及以上领导组" };
|
||||
var searchGrps = await DbContext.Queryable<GainfoGroupEntity>().Where(x => grps.Contains(x.Name)).ToListAsync();
|
||||
foreach (var grp in grps)
|
||||
var groups = new List<string> { "*自定义人员分组", "*督查组", "*X3及以上领导组" };
|
||||
var searchGroups = await DbContext.Queryable<GainfoGroupEntity>().Where(x => groups.Contains(x.Name)).ToListAsync();
|
||||
foreach (var grp in groups)
|
||||
{
|
||||
if (!searchGrps.Any(x => x.Name == grp))
|
||||
if (searchGroups.All(x => x.Name != grp))
|
||||
{
|
||||
await DbContext.InsertAsync(new GainfoGroupEntity
|
||||
{
|
||||
@@ -122,7 +121,7 @@ public class CreateDefinitelyGroupJob : BaseJob
|
||||
CreateTime = DateTime.Now,
|
||||
ModifiedBy = 1,
|
||||
ModifiedTime = DateTime.Now,
|
||||
TenantId = null,
|
||||
TenantId = workplace.Code,
|
||||
};
|
||||
await DbContext.InsertAsync(workplaceGrp);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,11 @@ public class DeviceTaskAssignmentRequest : PageDto, IValidatableObject
|
||||
|
||||
public string UserNo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 厂区
|
||||
/// </summary>
|
||||
public string Factory { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 搜索范围
|
||||
/// </summary>
|
||||
@@ -32,7 +37,7 @@ public class DeviceTaskAssignmentRequest : PageDto, IValidatableObject
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if (SearchDateTimePeriod != null && SearchDateTimePeriod.End.HasValue)
|
||||
if (SearchDateTimePeriod is { End: not null })
|
||||
{
|
||||
SearchDateTimePeriod.End = SearchDateTimePeriod.End.Value.AddDays(1).AddSeconds(-1);
|
||||
}
|
||||
|
||||
@@ -164,8 +164,6 @@ public class AssignmentService : IAssignmentService
|
||||
};
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return dto;
|
||||
@@ -232,32 +230,32 @@ public class AssignmentService : IAssignmentService
|
||||
var data = await CommonHelper.RetryAsync(async () =>
|
||||
{
|
||||
var page = await _dbContext.Queryable<DeviceTaskEntity>()
|
||||
.LeftJoin<DeviceEntity>((deviceTask, deivce) => deviceTask.DeviceUniqueNo == deivce.UniqueNo)
|
||||
.LeftJoin<DeviceTemplateEntity>((deviceTask, deivce, deivceTamplate) => deivceTamplate.Code == deivce.TemplateCode)
|
||||
.LeftJoin<GainfoEntity>((deviceTask, deivce, deivceTamplate, ga) => deviceTask.UserNo == ga.No)
|
||||
.LeftJoin<GainfoLeaveEntity>((deviceTask, deivce, deivceTamplate, ga, galeave) => deviceTask.UserNo == galeave.No)
|
||||
.LeftJoin<DepartmentEntity>((deviceTask, deivce, deivceTamplate, ga, galeave, department) => department.No == ga.DepartmentNo)
|
||||
.LeftJoin<GainfoExternalEntity>((deviceTask, deivce, deivceTamplate, ga, galeave, department, gainfoEx) => deviceTask.UserNo == gainfoEx.No)
|
||||
.LeftJoin<DeviceEntity>((deviceTask, device) => deviceTask.DeviceUniqueNo == device.UniqueNo)
|
||||
.LeftJoin<DeviceTemplateEntity>((deviceTask, device, deviceTemplate) => deviceTemplate.Code == device.TemplateCode)
|
||||
.LeftJoin<GainfoEntity>((deviceTask, device, deviceTemplate, ga) => deviceTask.UserNo == ga.No)
|
||||
.LeftJoin<GainfoLeaveEntity>((deviceTask, device, deviceTemplate, ga, gaLeave) => deviceTask.UserNo == gaLeave.No)
|
||||
.LeftJoin<DepartmentEntity>((deviceTask, device, deviceTemplate, ga, gaLeave, department) => department.No == ga.DepartmentNo)
|
||||
.LeftJoin<GainfoExternalEntity>((deviceTask, device, deviceTemplate, ga, gaLeave, department, gainfoEx) => deviceTask.UserNo == gainfoEx.No)
|
||||
.WhereIF(!request.IsProcess, deviceTask => deviceTask.Status == DeviceTaskStatusEnumType.Wait)
|
||||
.WhereIF(request.IsProcess, deviceTask => deviceTask.Status == DeviceTaskStatusEnumType.Process
|
||||
&& SqlFunc.DateDiff(DateType.Minute, deviceTask.ModifiedTime, DateTime.Now) > 30)
|
||||
.WhereIF(request.DeviceUniqueNo.IsPresent(), (deviceTask, deivce) => deviceTask.DeviceUniqueNo == request.DeviceUniqueNo)
|
||||
.WhereIF(request.Factory.IsPresent(), (deviceTask, deivce) => deviceTask.TenantId == request.Factory)
|
||||
.WhereIF(request.DeviceUniqueNo.IsPresent(), (deviceTask, device) => deviceTask.DeviceUniqueNo == request.DeviceUniqueNo)
|
||||
.WhereIF(request.Factory.IsPresent(), (deviceTask, device) => deviceTask.TenantId == request.Factory)
|
||||
.WhereIF(request.Types.IsPresent(), deviceTask => request.Types.Contains(deviceTask.Type))
|
||||
.WhereIF(request.Brand.IsPresent(), (deviceTask, deivce, deivceTamplate) => deivceTamplate.Brand == request.Brand)
|
||||
.WhereIF(request.Brand.IsPresent(), (deviceTask, device, deviceTemplate) => deviceTemplate.Brand == request.Brand)
|
||||
.OrderBy(deviceTask => new { Priority = SqlFunc.Desc(deviceTask.Priority), deviceTask.CreateTime })
|
||||
.Select((deviceTask, deivce, deivceTamplate, ga, galeave, department, gainfoEx) => new TaskDto
|
||||
.Select((deviceTask, device, deviceTemplate, ga, gaLeave, department, gainfoEx) => new TaskDto
|
||||
{
|
||||
UserId = SqlFunc.IsNull(SqlFunc.IsNull(deviceTask.UserId, ga.Id), galeave.IdentityUserId),
|
||||
UserId = SqlFunc.IsNull(SqlFunc.IsNull(deviceTask.UserId, ga.Id), gaLeave.IdentityUserId),
|
||||
TaskId = deviceTask.Id,
|
||||
Type = deviceTask.Type,
|
||||
DeviceUniqueNo = deviceTask.DeviceUniqueNo,
|
||||
DeviceConnectionInfo = deivce.ConnectionInfo,
|
||||
Brand = deivceTamplate.Brand,
|
||||
FuncStr = deivce.Funcs.ToString(),
|
||||
DeviceConnectionInfo = device.ConnectionInfo,
|
||||
Brand = deviceTemplate.Brand,
|
||||
FuncStr = device.Funcs.ToString(),
|
||||
UserNo = deviceTask.UserNo,
|
||||
UserCode = SqlFunc.IsNull(SqlFunc.IsNull(ga.Code, galeave.Code), gainfoEx.Code),
|
||||
UserName = SqlFunc.IsNull(SqlFunc.IsNull(ga.Name, galeave.Name), gainfoEx.Name),
|
||||
UserCode = SqlFunc.IsNull(SqlFunc.IsNull(ga.Code, gaLeave.Code), gainfoEx.Code),
|
||||
UserName = SqlFunc.IsNull(SqlFunc.IsNull(ga.Name, gaLeave.Name), gainfoEx.Name),
|
||||
DepartmentNo = ga.DepartmentNo,
|
||||
DepartmentName = department.Name,
|
||||
CardNo = ga.CardNo,
|
||||
@@ -294,8 +292,8 @@ public class AssignmentService : IAssignmentService
|
||||
{
|
||||
if (data.Any(x => x.Type == DeviceTaskEnumType.UploadRecord))
|
||||
{
|
||||
var deviceNos = data.Select(x => x.DeviceUniqueNo).Distinct();
|
||||
var result = new Dictionary<string, DateTime?>(deviceNos.Count());
|
||||
var deviceNos = data.Select(x => x.DeviceUniqueNo).Distinct().ToList();
|
||||
var result = new Dictionary<string, DateTime?>(deviceNos.Count);
|
||||
|
||||
//日志数据最后一条
|
||||
var logInfos = await _dbContext.Queryable<DeviceUploadLogEntity>().Select(it => new
|
||||
|
||||
@@ -28,6 +28,7 @@ public class DeviceTaskAssignmentService : IDeviceTaskAssignmentService
|
||||
var page = await _dbContext.Queryable<DeviceTaskEntity>()
|
||||
.LeftJoin<GainfoEntity>((deviceTask, ga) => deviceTask.UserNo == ga.No)
|
||||
.LeftJoin<DeviceEntity>((deviceTask, ga, device) => deviceTask.DeviceUniqueNo == device.UniqueNo)
|
||||
.Where(deviceTask => deviceTask.TenantId == request.Factory)
|
||||
.WhereIF(request.Type.HasValue, (deviceTask, ga, device) => deviceTask.DeviceType == request.Type)
|
||||
.WhereIF(request.SearchDateTimePeriod?.Start.HasValue == true && request.SearchDateTimePeriod?.End.HasValue == true,
|
||||
deviceTask => deviceTask.ModifiedTime >= request.SearchDateTimePeriod.Start && deviceTask.ModifiedTime <= request.SearchDateTimePeriod.End
|
||||
|
||||
Reference in New Issue
Block a user