feat 手动生成权限任务
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
using Dlhis.Basic.Device.Request;
|
||||
using Dlhis.Basic.Device.Response;
|
||||
using Dlhis.Basic.Device.Services;
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Dlhis.Basic.Device.Controllers;
|
||||
|
||||
[Authorize]
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class DevicePermissionManuallyController : ControllerBase
|
||||
{
|
||||
private readonly IDevicePermissionManuallyService _devicePermissionService;
|
||||
|
||||
public DevicePermissionManuallyController(IDevicePermissionManuallyService devicePermissionService)
|
||||
{
|
||||
_devicePermissionService = devicePermissionService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 数据分页
|
||||
/// </summary>
|
||||
/// <param name="requestDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("page")]
|
||||
[DataPermission]
|
||||
public async Task<Pagination<DevicePermissionManuallyResponse>> GetPageAsync([FromQuery] PageDto requestDto)
|
||||
{
|
||||
return await _devicePermissionService.GetPageAsync(requestDto);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加权限
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
[HttpPost("add")]
|
||||
[Transactional]
|
||||
public async Task AddAsync(DevicePermissionManuallyAddRequest request)
|
||||
{
|
||||
await _devicePermissionService.AddAsync(request);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除权限
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
[HttpGet("{id:long}")]
|
||||
[Transactional]
|
||||
public async Task DeleteAsync(long id)
|
||||
{
|
||||
await _devicePermissionService.DeleteAsync(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Dlhis.Basic.Device.Request;
|
||||
|
||||
public class DevicePermissionManuallyAddRequest
|
||||
{
|
||||
public Guid DeviceCode { get; set; }
|
||||
|
||||
[Required]
|
||||
public string UserNo { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace Dlhis.Basic.Device.Response;
|
||||
|
||||
public class DevicePermissionManuallyResponse
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public Guid DeviceCode { get; set; }
|
||||
public string DeviceUniqueNo { get; set; }
|
||||
public string DeployPlace { get; set; }
|
||||
public string UserNo { get; set; }
|
||||
public string UserName { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Dlhis.Basic.Device.Request;
|
||||
using Dlhis.Basic.Device.Response;
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
|
||||
namespace Dlhis.Basic.Device.Services;
|
||||
|
||||
public interface IDevicePermissionManuallyService : IScopeDependency
|
||||
{
|
||||
Task<Pagination<DevicePermissionManuallyResponse>> GetPageAsync(PageDto requestDto);
|
||||
|
||||
Task AddAsync(DevicePermissionManuallyAddRequest request);
|
||||
|
||||
Task DeleteAsync(long id);
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
using Dlhis.Basic.Device.Request;
|
||||
using Dlhis.Basic.Device.Response;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
|
||||
namespace Dlhis.Basic.Device.Services.Implements;
|
||||
|
||||
public class DevicePermissionManuallyService : IDevicePermissionManuallyService
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
|
||||
public DevicePermissionManuallyService(IDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<Pagination<DevicePermissionManuallyResponse>> GetPageAsync(PageDto requestDto)
|
||||
{
|
||||
return await _dbContext.Queryable<DevicePermissionManuallyEntity>()
|
||||
.LeftJoin<DeviceEntity>((x, d) => x.DeviceCode == d.Code)
|
||||
.LeftJoin<GainfoEntity>((x, d, g) => x.UserNo == g.No)
|
||||
.Select((x, d, g) => new DevicePermissionManuallyResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
DeviceCode = x.DeviceCode,
|
||||
DeviceUniqueNo = d.UniqueNo,
|
||||
DeployPlace = d.DeployPlace,
|
||||
UserNo = x.UserNo,
|
||||
UserName = g.Name
|
||||
})
|
||||
.ToPageListAsync(requestDto);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task AddAsync(DevicePermissionManuallyAddRequest request)
|
||||
{
|
||||
var device = await _dbContext.Queryable<DeviceEntity>().Where(x => x.Code == request.DeviceCode).SingleAsync();
|
||||
device.ThrowIfNull("设备不存在");
|
||||
|
||||
var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.No == request.UserNo).SingleAsync();
|
||||
gainfo.ThrowIfNull("人员不存在");
|
||||
|
||||
|
||||
await _dbContext.InsertAsync(new DevicePermissionManuallyEntity
|
||||
{
|
||||
DeviceCode = request.DeviceCode,
|
||||
UserNo = request.UserNo
|
||||
});
|
||||
|
||||
await _dbContext.InsertAsync(new DeviceTaskEntity
|
||||
{
|
||||
Type = DeviceTaskEnumType.Add,
|
||||
DeviceType = device.Type,
|
||||
UserId = null,
|
||||
UserNo = request.UserNo,
|
||||
DeviceUniqueNo = device.UniqueNo,
|
||||
Status = DeviceTaskStatusEnumType.Wait,
|
||||
Version = 0,
|
||||
ResultMessage = null,
|
||||
Source = "手动分配额外权限",
|
||||
Priority = 0,
|
||||
TenantId = device.TenantId
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task DeleteAsync(long id)
|
||||
{
|
||||
var data = await _dbContext.Queryable<DevicePermissionManuallyEntity>().Where(x => x.Id == id).SingleAsync();
|
||||
data.ThrowIfNull("数据不存在");
|
||||
|
||||
var device = await _dbContext.Queryable<DeviceEntity>().Where(x => x.Code == data.DeviceCode).SingleAsync();
|
||||
if (device != null)
|
||||
{
|
||||
var userNo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.No == data.UserNo).Select(x => x.No).SingleAsync();
|
||||
if (userNo.IsPresent())
|
||||
{
|
||||
await _dbContext.InsertAsync(new DeviceTaskEntity
|
||||
{
|
||||
Type = DeviceTaskEnumType.Delete,
|
||||
DeviceType = device.Type,
|
||||
UserId = null,
|
||||
UserNo = userNo,
|
||||
DeviceUniqueNo = device.UniqueNo,
|
||||
Status = DeviceTaskStatusEnumType.Wait,
|
||||
Version = 0,
|
||||
ResultMessage = null,
|
||||
Source = "手动分配额外权限",
|
||||
Priority = 0,
|
||||
TenantId = device.TenantId
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
await _dbContext.DeleteAsync(data);
|
||||
}
|
||||
}
|
||||
@@ -312,6 +312,7 @@ public class GainfoUpdateService : IGainfoUpdateService
|
||||
await _dbContext.Deleteable<GainfoGroupRelationshipEntity>().Where(x => x.UserNo == gainfo.No).ExecuteCommandAsync();
|
||||
await _dbContext.Deleteable<DevicePermissionEntity>().Where(x => x.AssignType == AssignTypeEnumType.User && x.AssignValue == gainfo.No).ExecuteCommandAsync();
|
||||
|
||||
|
||||
gainfo.Id = gainfo.IdentityUserId;
|
||||
await _dbContext.DeleteReallyAsync(gainfo);
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
using Dlhis.DataPermission.Model;
|
||||
using Kurisu.AspNetCore.DataAccess.Entity;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Dlhis.Entity.Device.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// 设备权限(手动)
|
||||
/// </summary>
|
||||
[SugarTable(TableName = "DevicePermissionManually")]
|
||||
public class DevicePermissionManuallyEntity : SugarBaseEntity, ISoftDeleted
|
||||
{
|
||||
[DeviceCode]
|
||||
[SugarColumn(IsNullable = false)]
|
||||
public Guid DeviceCode { get; set; }
|
||||
|
||||
[SugarColumn(IsNullable = false)]
|
||||
public string UserNo { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsDeleted { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user