fix 设备,设备分组调整
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using Dlhis.Basic.Device.Request;
|
||||
using Dlhis.Basic.Device.Response;
|
||||
using Dlhis.Basic.Device.Services;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@@ -37,11 +38,12 @@ public class DeviceGroupsController : ControllerBase
|
||||
/// 获取设备组树
|
||||
/// </summary>
|
||||
/// <param name="showDevices">是否显示设备</param>
|
||||
/// <param name="type">分组类型</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("tree")]
|
||||
public async Task<List<DeviceGroupTreeResponse>> GetTreeAsync(bool showDevices)
|
||||
public async Task<List<DeviceGroupTreeResponse>> GetTreeAsync(bool showDevices, DeviceTypeEnumType? type)
|
||||
{
|
||||
return await _deviceGroupService.GetTreeAsync(showDevices);
|
||||
return await _deviceGroupService.GetTreeAsync(showDevices, type);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
|
||||
namespace Dlhis.Basic.Device.Request;
|
||||
|
||||
public class DeviceGroupPageRequest : PageDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 分组类型
|
||||
/// </summary>
|
||||
public DeviceTypeEnumType? Type { get; set; }
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ public class DeviceGroupSaveRequest
|
||||
/// <summary>
|
||||
/// 分类类型 DeviceTypeEnumType
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "分类不能为空")]
|
||||
[EnumDataType(typeof(DeviceTypeEnumType))]
|
||||
public DeviceTypeEnumType Type { get; set; }
|
||||
public DeviceTypeEnumType? Type { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
namespace Dlhis.Basic.Device.Response;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
|
||||
namespace Dlhis.Basic.Device.Response;
|
||||
|
||||
public class DeviceGroupPageResponse
|
||||
{
|
||||
@@ -11,4 +14,25 @@ public class DeviceGroupPageResponse
|
||||
/// 设备组名称
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 分组类型
|
||||
/// </summary>
|
||||
public DeviceTypeEnumType? Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 分组类型描述
|
||||
/// </summary>
|
||||
public string TypeDesc
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Type.HasValue)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
return Type.Value.GetDescription();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace Dlhis.Basic.Device.Response;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
|
||||
namespace Dlhis.Basic.Device.Response;
|
||||
|
||||
public class DeviceUnderGroupResponse
|
||||
{
|
||||
@@ -14,6 +16,12 @@ public class DeviceUnderGroupResponse
|
||||
/// </summary>
|
||||
public string Brand { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设备类型
|
||||
/// </summary>
|
||||
public DeviceTypeEnumType Type { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 是否启用
|
||||
/// </summary>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Dlhis.Basic.Device.Request;
|
||||
using Dlhis.Basic.Device.Response;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
|
||||
namespace Dlhis.Basic.Device.Services;
|
||||
@@ -8,7 +9,7 @@ public interface IDeviceGroupService : IScopeDependency
|
||||
{
|
||||
Task<Pagination<DeviceGroupPageResponse>> GetPageAsync(DeviceGroupPageRequest request);
|
||||
|
||||
Task<List<DeviceGroupTreeResponse>> GetTreeAsync(bool showDevices);
|
||||
Task<List<DeviceGroupTreeResponse>> GetTreeAsync(bool showDevices, DeviceTypeEnumType? type);
|
||||
|
||||
Task SaveAsync(DeviceGroupSaveRequest request);
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Dlhis.Basic.Device.Response;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
using Kurisu.SqlSugar.Attributes;
|
||||
@@ -26,13 +27,15 @@ public class DeviceGroupService : IDeviceGroupService
|
||||
{
|
||||
return await _dbContext.Queryable<DeviceGroupEntity>()
|
||||
.WhereIF(request.Search.IsPresent(), x => x.Name.Contains(request.Search))
|
||||
.WhereIF(request.Type.HasValue, x => x.Type == request.Type)
|
||||
.Select<DeviceGroupPageResponse>()
|
||||
.ToPageListAsync(request);
|
||||
}
|
||||
|
||||
public async Task<List<DeviceGroupTreeResponse>> GetTreeAsync(bool showDevices)
|
||||
public async Task<List<DeviceGroupTreeResponse>> GetTreeAsync(bool showDevices, DeviceTypeEnumType? type)
|
||||
{
|
||||
var deviceGroups = await _dbContext.Queryable<DeviceGroupEntity>()
|
||||
.WhereIF(type.HasValue, x => x.Type == type)
|
||||
.Select<DeviceGroupTreeResponse>()
|
||||
.ToListAsync();
|
||||
|
||||
@@ -61,6 +64,18 @@ public class DeviceGroupService : IDeviceGroupService
|
||||
{
|
||||
var entity = await _dbContext.Queryable<DeviceGroupEntity>().Where(x => x.Id == request.Id).FirstAsync();
|
||||
entity.ThrowIfNull("设备组不存在,无法更新");
|
||||
|
||||
var nextDevices = await GetDevicesAsync(entity.Code);
|
||||
if (!entity.Type.HasValue)
|
||||
{
|
||||
(request.Type.HasValue && nextDevices.Any(x => x.Type != request.Type)).ThrowIfTrue($"分组设备存在非{request.Type.Value.GetDescription()}类型的设备设备");
|
||||
}
|
||||
else
|
||||
{
|
||||
(request.Type.HasValue && request.Type != entity.Type && nextDevices.Any()).ThrowIfTrue("分组设备类型不匹配,无法修改类型");
|
||||
}
|
||||
|
||||
|
||||
await _dbContext.UpdateAsync(entity);
|
||||
}
|
||||
}
|
||||
@@ -73,6 +88,7 @@ public class DeviceGroupService : IDeviceGroupService
|
||||
await _dbContext.DeleteAsync(deviceGroup);
|
||||
}
|
||||
|
||||
|
||||
[Transactional]
|
||||
public async Task AssignDevicesAsync(DeviceAssignRequest request)
|
||||
{
|
||||
|
||||
@@ -84,5 +84,12 @@ public class DeviceEntity : SugarBaseEntity, ITenantId
|
||||
[SugarColumn(ColumnDataType = "bit", ColumnDescription = "是否启用")]
|
||||
public bool Enable { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 是否作为考勤设备
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDataType = "bit", ColumnDescription = "是否作为考勤设备")]
|
||||
public bool AsAttendance { get; set; }
|
||||
|
||||
public string TenantId { get; set; }
|
||||
}
|
||||
@@ -25,10 +25,4 @@ public enum DeviceTypeEnumType
|
||||
/// </summary>
|
||||
[Description("考勤")]
|
||||
Attendance = 3,
|
||||
|
||||
/// <summary>
|
||||
/// 门禁并作为考勤
|
||||
/// </summary>
|
||||
[Description("门禁并作为考勤")]
|
||||
DoorAndAttendance = 4,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user