feat 设备分组
This commit is contained in:
46
Src/Dlhis.Basic/Device/Controllers/DeviceGroupsController.cs
Normal file
46
Src/Dlhis.Basic/Device/Controllers/DeviceGroupsController.cs
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
using Dlhis.Basic.Device.Request;
|
||||||
|
using Dlhis.Basic.Device.Response;
|
||||||
|
using Dlhis.Basic.Device.Services;
|
||||||
|
using Kurisu.Core.DataAccess.Dto;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace Dlhis.Basic.Device.Controllers;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设备分组
|
||||||
|
/// </summary>
|
||||||
|
[Authorize]
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
[ApiController]
|
||||||
|
public class DeviceGroupsController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly IDeviceGroupService _deviceGroupService;
|
||||||
|
|
||||||
|
public DeviceGroupsController(IDeviceGroupService deviceGroupService)
|
||||||
|
{
|
||||||
|
_deviceGroupService = deviceGroupService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设备分组分页
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost("page")]
|
||||||
|
public async Task<Pagination<DeviceGroupPageResponse>> GetPageAsync([FromQuery] DeviceGroupPageRequest request)
|
||||||
|
{
|
||||||
|
return await _deviceGroupService.GetPageAsync(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设备分组保存
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost("save")]
|
||||||
|
public async Task SaveAsync(DeviceGroupSaveRequest request)
|
||||||
|
{
|
||||||
|
await _deviceGroupService.SaveAsync(request);
|
||||||
|
}
|
||||||
|
}
|
||||||
12
Src/Dlhis.Basic/Device/Request/AssignDeviceRequest.cs
Normal file
12
Src/Dlhis.Basic/Device/Request/AssignDeviceRequest.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace Dlhis.Basic.Device.Request;
|
||||||
|
|
||||||
|
public class AssignDevicesRequest
|
||||||
|
{
|
||||||
|
[Required(ErrorMessage = "设备组不能为空")]
|
||||||
|
public Guid GroupCode { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
public List<Guid> DeviceCodes { get; set; } = new List<Guid>();
|
||||||
|
}
|
||||||
7
Src/Dlhis.Basic/Device/Request/DeviceGroupPageRequest.cs
Normal file
7
Src/Dlhis.Basic/Device/Request/DeviceGroupPageRequest.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
using Kurisu.Core.DataAccess.Dto;
|
||||||
|
|
||||||
|
namespace Dlhis.Basic.Device.Request;
|
||||||
|
|
||||||
|
public class DeviceGroupPageRequest : PageDto
|
||||||
|
{
|
||||||
|
}
|
||||||
14
Src/Dlhis.Basic/Device/Request/DeviceGroupSaveRequest.cs
Normal file
14
Src/Dlhis.Basic/Device/Request/DeviceGroupSaveRequest.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace Dlhis.Basic.Device.Request;
|
||||||
|
|
||||||
|
public class DeviceGroupSaveRequest
|
||||||
|
{
|
||||||
|
public long? Id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设备组名称
|
||||||
|
/// </summary>
|
||||||
|
[Required(ErrorMessage = "设备组名称不能为空")]
|
||||||
|
public string Name { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
namespace Dlhis.Basic.Device.Response;
|
||||||
|
|
||||||
|
public class DeviceGroupPageResponse
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -2,5 +2,23 @@
|
|||||||
|
|
||||||
public class DeviceTemplateResponse
|
public class DeviceTemplateResponse
|
||||||
{
|
{
|
||||||
|
public long Id { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
public Guid Code { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 品牌
|
||||||
|
/// </summary>
|
||||||
|
public string Brand { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 模板名称
|
||||||
|
/// </summary>
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 模板json
|
||||||
|
/// </summary>
|
||||||
|
public string Template { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
19
Src/Dlhis.Basic/Device/Response/DeviceUnderGroupResponse.cs
Normal file
19
Src/Dlhis.Basic/Device/Response/DeviceUnderGroupResponse.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
namespace Dlhis.Basic.Device.Response;
|
||||||
|
|
||||||
|
public class DeviceUnderGroupResponse
|
||||||
|
{
|
||||||
|
public Guid Code { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设备唯一码,IP/MAC/SNO
|
||||||
|
/// </summary>
|
||||||
|
public string UniqueNo { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 品牌
|
||||||
|
/// </summary>
|
||||||
|
public string Brand { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
public bool Enable { get; set; }
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@ using Dlhis.Basic.Device.Response;
|
|||||||
|
|
||||||
namespace Dlhis.Basic.Device.Services;
|
namespace Dlhis.Basic.Device.Services;
|
||||||
|
|
||||||
public interface IDeviceConnectService
|
public interface IDeviceConnectService : IScopeDependency
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设备注册
|
/// 设备注册
|
||||||
|
|||||||
16
Src/Dlhis.Basic/Device/Services/IDeviceGroupService.cs
Normal file
16
Src/Dlhis.Basic/Device/Services/IDeviceGroupService.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using Dlhis.Basic.Device.Request;
|
||||||
|
using Dlhis.Basic.Device.Response;
|
||||||
|
using Kurisu.Core.DataAccess.Dto;
|
||||||
|
|
||||||
|
namespace Dlhis.Basic.Device.Services;
|
||||||
|
|
||||||
|
public interface IDeviceGroupService : IScopeDependency
|
||||||
|
{
|
||||||
|
Task<Pagination<DeviceGroupPageResponse>> GetPageAsync(DeviceGroupPageRequest request);
|
||||||
|
|
||||||
|
Task SaveAsync(DeviceGroupSaveRequest request);
|
||||||
|
|
||||||
|
Task<List<DeviceUnderGroupResponse>> GetDevicesAsync(Guid code);
|
||||||
|
|
||||||
|
Task AssignDevicesAsync(AssignDevicesRequest requests);
|
||||||
|
}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
using Dlhis.Basic.Device.Request;
|
||||||
|
using Dlhis.Basic.Device.Response;
|
||||||
|
using Dlhis.Entity.Basic.Entity;
|
||||||
|
using Dlhis.Entity.Device.Entities;
|
||||||
|
using Kurisu.AspNetCore.Utils.Extensions;
|
||||||
|
using Kurisu.Core.DataAccess.Dto;
|
||||||
|
using Kurisu.SqlSugar.Extensions;
|
||||||
|
using Kurisu.SqlSugar.Services;
|
||||||
|
using Mapster;
|
||||||
|
|
||||||
|
namespace Dlhis.Basic.Device.Services.Implements;
|
||||||
|
|
||||||
|
public class DeviceGroupService : IDeviceGroupService
|
||||||
|
{
|
||||||
|
private readonly IDbContext _dbContext;
|
||||||
|
|
||||||
|
public DeviceGroupService(IDbContext dbContext)
|
||||||
|
{
|
||||||
|
_dbContext = dbContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Pagination<DeviceGroupPageResponse>> GetPageAsync(DeviceGroupPageRequest request)
|
||||||
|
{
|
||||||
|
return await _dbContext.Queryable<DeviceGroupEntity>()
|
||||||
|
.WhereIF(request.Search.IsPresent(), x => x.Name.Contains(request.Search))
|
||||||
|
.Select<DeviceGroupPageResponse>()
|
||||||
|
.ToPageListAsync(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task SaveAsync(DeviceGroupSaveRequest request)
|
||||||
|
{
|
||||||
|
if (!request.Id.HasValue)
|
||||||
|
{
|
||||||
|
var entity = request.Adapt<DeviceGroupEntity>();
|
||||||
|
|
||||||
|
entity.Code = Guid.NewGuid();
|
||||||
|
await _dbContext.InsertAsync(entity);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var entity = await _dbContext.Queryable<DeviceGroupEntity>().Where(x => x.Id == request.Id).FirstAsync();
|
||||||
|
entity.ThrowIfNull("设备组不存在,无法更新");
|
||||||
|
await _dbContext.UpdateAsync(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task DeleteAsync(long id)
|
||||||
|
{
|
||||||
|
var deviceGroup = await _dbContext.Queryable<DeviceGroupEntity>().Where(x => x.Id == id).FirstAsync();
|
||||||
|
deviceGroup.ThrowIfNull("设备组不存在,无需删除");
|
||||||
|
|
||||||
|
await _dbContext.DeleteAsync(deviceGroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task AssignDevicesAsync(AssignDevicesRequest request)
|
||||||
|
{
|
||||||
|
var group = await _dbContext.Queryable<DeviceGroupEntity>().Where(x => x.Code == request.GroupCode).FirstAsync();
|
||||||
|
group.ThrowIfNull("设备组不存在");
|
||||||
|
|
||||||
|
if (!request.DeviceCodes.Any())
|
||||||
|
{
|
||||||
|
//todo 删除时候判断权限是否分配
|
||||||
|
|
||||||
|
var relationships = await _dbContext.Queryable<DeviceGroupRelationshipEntity>().Where(x => x.GroupCode == request.GroupCode).ToListAsync();
|
||||||
|
await _dbContext.DeleteAsync(relationships);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var entities = request.DeviceCodes.Select(x => new DeviceGroupRelationshipEntity
|
||||||
|
{
|
||||||
|
GroupCode = request.GroupCode,
|
||||||
|
DeviceCode = x
|
||||||
|
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
|
await _dbContext.InsertAsync(entities);
|
||||||
|
}
|
||||||
|
|
||||||
|
//todo 生成下发任务
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<List<DeviceUnderGroupResponse>> GetDevicesAsync(Guid code)
|
||||||
|
{
|
||||||
|
var relationships = await _dbContext.Queryable<DeviceGroupRelationshipEntity>().Where(x => x.GroupCode == code).ToListAsync();
|
||||||
|
var deviceCodes = relationships.Select(x => x.DeviceCode);
|
||||||
|
|
||||||
|
return await _dbContext.Queryable<DeviceEntity>()
|
||||||
|
.Where(x => deviceCodes.Contains(x.Code))
|
||||||
|
.Select<DeviceUnderGroupResponse>()
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
using Dlhis.Basic.Device.Request;
|
using Dlhis.Basic.Device.Request;
|
||||||
using Dlhis.Basic.Device.Response;
|
using Dlhis.Basic.Device.Response;
|
||||||
using Dlhis.Entity.Basic.Entity;
|
using Dlhis.Entity.Basic.Entity;
|
||||||
using Dlhis.Entity.Device.Entities;
|
|
||||||
using Dlhis.Entity.Device.Enums;
|
|
||||||
using Kurisu.AspNetCore.UnifyResultAndValidation;
|
using Kurisu.AspNetCore.UnifyResultAndValidation;
|
||||||
using Kurisu.AspNetCore.Utils.Extensions;
|
using Kurisu.AspNetCore.Utils.Extensions;
|
||||||
using Kurisu.Core.DataAccess.Dto;
|
using Kurisu.Core.DataAccess.Dto;
|
||||||
@@ -117,6 +115,5 @@ public class DeviceService : IDeviceService
|
|||||||
|
|
||||||
exists.ThrowIfTrue("唯一号已经存在");
|
exists.ThrowIfTrue("唯一号已经存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,8 +25,4 @@
|
|||||||
<ProjectReference Include="..\Dlhis.Entity\Dlhis.Entity.csproj" />
|
<ProjectReference Include="..\Dlhis.Entity\Dlhis.Entity.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="Organization\Request\" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -17,11 +17,11 @@ public class SqlSugarPack : BaseAppPack
|
|||||||
public override void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
public override void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||||
{
|
{
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
using var scope = app.ApplicationServices.CreateScope();
|
//using var scope = app.ApplicationServices.CreateScope();
|
||||||
var db = scope.ServiceProvider.GetService<ISqlSugarClient>();
|
//var db = scope.ServiceProvider.GetService<ISqlSugarClient>();
|
||||||
var tables = App.ActiveTyps.Where(x => x.IsDefined(typeof(SugarTable), false)).ToArray();
|
//var tables = App.ActiveTyps.Where(x => x.IsDefined(typeof(SugarTable), false)).ToArray();
|
||||||
db.DbMaintenance.CreateDatabase();
|
//db.DbMaintenance.CreateDatabase();
|
||||||
db.CodeFirst.InitTables(tables);
|
//db.CodeFirst.InitTables(tables);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,13 +7,13 @@ namespace Dlhis.Entity.Device.Entities;
|
|||||||
/// 设备组
|
/// 设备组
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarTable(TableName = "DeviceGroup", TableDescription = "设备组")]
|
[SugarTable(TableName = "DeviceGroup", TableDescription = "设备组")]
|
||||||
public class DeviceGroupEntity : SugarBaseEntity, ITenantId
|
public class DeviceGroupEntity : SugarBaseEntity, ITenantId, ISoftDeleted
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设备组code
|
/// 设备组code
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(ColumnDescription = "设备组code")]
|
[SugarColumn(ColumnDescription = "设备组code")]
|
||||||
public string Code { get; set; }
|
public Guid Code { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设备组名称
|
/// 设备组名称
|
||||||
@@ -21,6 +21,8 @@ public class DeviceGroupEntity : SugarBaseEntity, ITenantId
|
|||||||
[SugarColumn(ColumnDescription = "设备组名称")]
|
[SugarColumn(ColumnDescription = "设备组名称")]
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public string TenantId { get; set; }
|
public string TenantId { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
public bool IsDeleted { get; set; }
|
||||||
}
|
}
|
||||||
@@ -7,20 +7,22 @@ namespace Dlhis.Entity.Device.Entities;
|
|||||||
/// 设备组/设备关系
|
/// 设备组/设备关系
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarTable(TableName = "DeviceGroupRelationship", TableDescription = "设备组/设备关系")]
|
[SugarTable(TableName = "DeviceGroupRelationship", TableDescription = "设备组/设备关系")]
|
||||||
public class DeviceGroupRelationshipEntity : SugarBaseEntity, ITenantId
|
public class DeviceGroupRelationshipEntity : SugarBaseEntity, ITenantId, ISoftDeleted
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设备组code
|
/// 设备组code
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(ColumnDescription = "设备组code")]
|
[SugarColumn(ColumnDescription = "设备组code")]
|
||||||
public string GroupCode { get; set; }
|
public Guid GroupCode { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设备code
|
/// 设备code
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(ColumnDescription = "设备code")]
|
[SugarColumn(ColumnDescription = "设备code")]
|
||||||
public string DeviceCode { get; set; }
|
public Guid DeviceCode { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public string TenantId { get; set; }
|
public string TenantId { get; set; }
|
||||||
|
|
||||||
|
public bool IsDeleted { get; set; }
|
||||||
}
|
}
|
||||||
@@ -39,4 +39,11 @@ public enum DeviceFuncEnumType
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[Description("二维码")]
|
[Description("二维码")]
|
||||||
QrCode,
|
QrCode,
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 布控
|
||||||
|
/// </summary>
|
||||||
|
[Description("布控")]
|
||||||
|
Control,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
namespace Dlhis.Entity.Sys.Entities;
|
namespace Dlhis.Entity.Sys.Entities;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// identity-roles
|
||||||
|
/// </summary>
|
||||||
[SugarTable(TableName = "Roles")]
|
[SugarTable(TableName = "Roles")]
|
||||||
public class RoleEntity
|
public class RoleEntity
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
namespace Dlhis.Entity.Sys.Entities;
|
namespace Dlhis.Entity.Sys.Entities;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// identity-user
|
||||||
|
/// </summary>
|
||||||
[SugarTable("Users")]
|
[SugarTable("Users")]
|
||||||
public class UserEntity
|
public class UserEntity
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user