104 lines
3.8 KiB
C#
104 lines
3.8 KiB
C#
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)
|
|
.WhereIF(requestDto.Search.IsPresent(), (x, d, g) => g.Code == requestDto.Search || g.Name.Contains(requestDto.Search))
|
|
.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);
|
|
}
|
|
} |