feat 梯控相关
This commit is contained in:
@@ -130,7 +130,7 @@ public class DevicePermissionsController : ControllerBase
|
|||||||
[IgnoreTenant]
|
[IgnoreTenant]
|
||||||
public async Task<List<Guid>> GetAssignDeviceCodesAsync(string userCode)
|
public async Task<List<Guid>> GetAssignDeviceCodesAsync(string userCode)
|
||||||
{
|
{
|
||||||
return await _devicePermissionService.GetUserDeviceCodesByNoAsync(userCode);
|
return await _devicePermissionService.GetUserDeviceCodesByNoOrCodeAsync(userCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
48
Src/Dlhis.Basic/Device/Controllers/ElevatorAcsController.cs
Normal file
48
Src/Dlhis.Basic/Device/Controllers/ElevatorAcsController.cs
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
using Dlhis.Basic.Device.Request;
|
||||||
|
using Dlhis.Basic.Device.Response;
|
||||||
|
using Dlhis.Basic.Device.Services;
|
||||||
|
using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace Dlhis.Basic.Device.Controllers;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 梯控设备
|
||||||
|
/// </summary>
|
||||||
|
[Authorize]
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
[ApiController]
|
||||||
|
public class ElevatorAcsController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly IElevatorAcsService _elevatorAcsService;
|
||||||
|
|
||||||
|
public ElevatorAcsController(IElevatorAcsService elevatorAcsService)
|
||||||
|
{
|
||||||
|
_elevatorAcsService = elevatorAcsService;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设备保存
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost("save")]
|
||||||
|
[Transactional]
|
||||||
|
public async Task SaveAsync(ElevatorAcsSaveRequest request)
|
||||||
|
{
|
||||||
|
await _elevatorAcsService.SaveAsync(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取设备详情
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="deviceUniqueNo"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("detail")]
|
||||||
|
public async Task<ElevatorAcsDetailResponse> GetDetailsAsync(string deviceUniqueNo)
|
||||||
|
{
|
||||||
|
return await _elevatorAcsService.GetDetailsAsync(deviceUniqueNo);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,4 +23,9 @@ public class DevicePageRequest : PageDto
|
|||||||
/// 启用状态
|
/// 启用状态
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool? Enable { get; set; }
|
public bool? Enable { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否为梯控
|
||||||
|
/// </summary>
|
||||||
|
public bool IsElevatorAcs { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Linq.Expressions;
|
|
||||||
using Dlhis.Entity.Device.Enums;
|
using Dlhis.Entity.Device.Enums;
|
||||||
using Dlhis.Entity.Sys.Entities;
|
|
||||||
using Dlhis.Entity.Sys.Enums;
|
using Dlhis.Entity.Sys.Enums;
|
||||||
using Kurisu.AspNetCore.Utils.Extensions;
|
using Kurisu.AspNetCore.Utils.Extensions;
|
||||||
|
|
||||||
|
|||||||
78
Src/Dlhis.Basic/Device/Request/ElevatorAcsSaveRequest.cs
Normal file
78
Src/Dlhis.Basic/Device/Request/ElevatorAcsSaveRequest.cs
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Dlhis.Entity.Device.Enums;
|
||||||
|
|
||||||
|
namespace Dlhis.Basic.Device.Request;
|
||||||
|
|
||||||
|
public class ElevatorAcsSaveRequest
|
||||||
|
{
|
||||||
|
public bool IsEdit { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设备唯一号
|
||||||
|
/// </summary>
|
||||||
|
[Required(ErrorMessage = "设备唯一号不能为空")]
|
||||||
|
public string UniqueNo { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 模板code
|
||||||
|
/// </summary>
|
||||||
|
[Required(ErrorMessage = "模板不能为空")]
|
||||||
|
public Guid TemplateCode { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 供应商信息
|
||||||
|
/// </summary>
|
||||||
|
[Required(ErrorMessage = "供应商信息不能为空")]
|
||||||
|
public string Supplier { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设备功能 DeviceFuncEnumType
|
||||||
|
/// </summary>
|
||||||
|
[MinLength(1, ErrorMessage = "设备功能不能为空")]
|
||||||
|
[Required(ErrorMessage = "设备功能不能为空")]
|
||||||
|
public List<DeviceFuncEnumType> Funcs { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 心跳间隔
|
||||||
|
/// </summary>
|
||||||
|
public int HeartbeatInterval { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 部署点
|
||||||
|
/// </summary>
|
||||||
|
public string DeployPlace { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 部署坐标
|
||||||
|
/// </summary>
|
||||||
|
public string DeployPosition { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 部署方向 DeviceDeployDirectionEnumType
|
||||||
|
/// </summary>
|
||||||
|
public DeviceDeployDirectionEnumType? DeployDirection { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 连接信息
|
||||||
|
/// </summary>
|
||||||
|
[Required(ErrorMessage = "连接信息不能为空")]
|
||||||
|
public string ConnectionInfo { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否启用
|
||||||
|
/// </summary>
|
||||||
|
public bool Enable { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 楼层列表
|
||||||
|
/// </summary>
|
||||||
|
public List<FloorInfo> Floors { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class FloorInfo
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 楼层名称
|
||||||
|
/// </summary>
|
||||||
|
public string FloorName { get; set; }
|
||||||
|
}
|
||||||
@@ -102,6 +102,33 @@ public class DevicePageResponse
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool EnableTimePeriod { get; set; }
|
public bool EnableTimePeriod { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否作为梯控
|
||||||
|
/// </summary>
|
||||||
|
public bool IsElevatorAcs { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 同源标记
|
||||||
|
/// </summary>
|
||||||
|
public int SourceFlag
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(RealDeviceUniqueNo))
|
||||||
|
{
|
||||||
|
return UniqueNo.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
return RealDeviceUniqueNo.GetHashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
[JsonIgnore]
|
||||||
|
public string RealDeviceUniqueNo { get; set; }
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 同步标志
|
/// 同步标志
|
||||||
|
|||||||
112
Src/Dlhis.Basic/Device/Response/ElevatorAcsDetailResponse.cs
Normal file
112
Src/Dlhis.Basic/Device/Response/ElevatorAcsDetailResponse.cs
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
using Dlhis.DataPermission.Model;
|
||||||
|
using Dlhis.Entity.Device.Enums;
|
||||||
|
using Mapster;
|
||||||
|
using SqlSugar;
|
||||||
|
using SqlSugar.DbConvert;
|
||||||
|
|
||||||
|
namespace Dlhis.Basic.Device.Response;
|
||||||
|
|
||||||
|
public class ElevatorAcsDetailResponse
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 设备code
|
||||||
|
/// </summary>
|
||||||
|
[DeviceCode]
|
||||||
|
[SugarColumn(IsNullable = false, ColumnDescription = "设备code")]
|
||||||
|
public Guid Code { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设备唯一码,IP/MAC/SNO
|
||||||
|
/// </summary>
|
||||||
|
[AdaptIgnore(MemberSide.Destination)]
|
||||||
|
[SugarColumn(IsNullable = false, ColumnDescription = "设备唯一码", UniqueGroupNameList = new[] { "Idx_Device_UniqueNo" })]
|
||||||
|
public string UniqueNo { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 心跳间隔
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(IsNullable = false, ColumnDescription = "心跳检查间隔")]
|
||||||
|
public int HeartbeatInterval { get; set; } = 30;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 供应商
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(IsNullable = true, ColumnDescription = "供应商")]
|
||||||
|
public string Supplier { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设备功能
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(IsNullable = false, ColumnDataType = "varchar(150)", IsJson = true, ColumnDescription = "设备功能", DefaultValue = "[]")]
|
||||||
|
public List<DeviceFuncEnumType> Funcs { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设备类型
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(IsNullable = false, ColumnDescription = "设备类型", ColumnDataType = "varchar(50)", SqlParameterDbType = typeof(EnumToStringConvert))]
|
||||||
|
public DeviceTypeEnumType Type { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 部署点
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(IsNullable = true, ColumnDescription = "部署点")]
|
||||||
|
public string DeployPlace { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 部署坐标
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(IsNullable = true, ColumnDescription = "部署坐标")]
|
||||||
|
public string DeployPosition { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 部署方向
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(IsNullable = true, ColumnDescription = "部署方向", ColumnDataType = "varchar(50)", SqlParameterDbType = typeof(EnumToStringConvert))]
|
||||||
|
public DeviceDeployDirectionEnumType? DeployDirection { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 模板code
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(IsNullable = false, ColumnDescription = "模板code")]
|
||||||
|
public Guid TemplateCode { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 连接信息
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(IsNullable = false, ColumnDescription = "连接信息")]
|
||||||
|
public string ConnectionInfo { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否启用
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(IsNullable = false, ColumnDataType = "bit", ColumnDescription = "是否启用")]
|
||||||
|
public bool Enable { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否作为考勤设备
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(IsNullable = false, ColumnDataType = "bit", ColumnDescription = "是否作为考勤设备")]
|
||||||
|
public bool AsAttendance { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否启用时段码
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(IsNullable = false, ColumnDataType = "bit", ColumnDescription = "是否启用时段码", DefaultValue = "0")]
|
||||||
|
public bool EnableTimePeriod { get; set; } = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否为电梯门禁设备
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(IsNullable = false, ColumnDataType = "bit", ColumnDescription = "是否为电梯门禁设备", DefaultValue = "0")]
|
||||||
|
public bool IsElevatorAcs { get; set; }
|
||||||
|
|
||||||
|
public List<ElevatorAcsFloorResponse> Floors { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ElevatorAcsFloorResponse
|
||||||
|
{
|
||||||
|
public string FloorName { get; set; }
|
||||||
|
public string AcsValue { get; set; }
|
||||||
|
}
|
||||||
@@ -27,18 +27,18 @@ public interface IDevicePermissionService : IScopeDependency
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 生成下发任务(主动生成)
|
/// 生成下发任务(主动生成)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userNo"></param>
|
/// <param name="userNoOrCode"></param>
|
||||||
/// <param name="taskType"></param>
|
/// <param name="taskType"></param>
|
||||||
/// <param name="source"></param>
|
/// <param name="source"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task GenerateDeviceTasksAsync(string userNo, DeviceTaskEnumType taskType, string source);
|
Task GenerateDeviceTasksAsync(string userNoOrCode, DeviceTaskEnumType taskType, string source);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取用户所有设备权限
|
/// 获取用户所有设备权限
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userNo"></param>
|
/// <param name="userNoOrCode"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<List<Guid>> GetUserDeviceCodesByNoAsync(string userNo);
|
Task<List<Guid>> GetUserDeviceCodesByNoOrCodeAsync(string userNoOrCode);
|
||||||
|
|
||||||
Task<Pagination<DeviceGainfoResponse>> GetGainfoPageByDeviceAsync(DeviceWithGainfoRequest request);
|
Task<Pagination<DeviceGainfoResponse>> GetGainfoPageByDeviceAsync(DeviceWithGainfoRequest request);
|
||||||
|
|
||||||
@@ -64,5 +64,6 @@ public interface IDevicePermissionService : IScopeDependency
|
|||||||
|
|
||||||
Task<int> GenerateDeleteDeviceTasksAsync(string deviceUniqueNo);
|
Task<int> GenerateDeleteDeviceTasksAsync(string deviceUniqueNo);
|
||||||
|
|
||||||
|
[Obsolete("不建议使用,建议使用GetUserDeviceCodesByNoOrCodeAsync方法")]
|
||||||
Task<List<TempC>> GetUserDeviceCodesByNoAsync(List<string> userCodes);
|
Task<List<TempC>> GetUserDeviceCodesByNoAsync(List<string> userCodes);
|
||||||
}
|
}
|
||||||
10
Src/Dlhis.Basic/Device/Services/IElevatorAcsService.cs
Normal file
10
Src/Dlhis.Basic/Device/Services/IElevatorAcsService.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
using Dlhis.Basic.Device.Request;
|
||||||
|
using Dlhis.Basic.Device.Response;
|
||||||
|
|
||||||
|
namespace Dlhis.Basic.Device.Services;
|
||||||
|
|
||||||
|
public interface IElevatorAcsService : IScopeDependency
|
||||||
|
{
|
||||||
|
Task SaveAsync(ElevatorAcsSaveRequest request);
|
||||||
|
Task<ElevatorAcsDetailResponse> GetDetailsAsync(string deviceUniqueNo);
|
||||||
|
}
|
||||||
@@ -139,15 +139,35 @@ public class DeviceConnectService : IDeviceConnectService
|
|||||||
{
|
{
|
||||||
var factories = factory.Split(",").ToList();
|
var factories = factory.Split(",").ToList();
|
||||||
|
|
||||||
return await _dbContext.Queryable<DeviceEntity>()
|
var results = await _dbContext.Queryable<DeviceEntity>()
|
||||||
.LeftJoin<DeviceTemplateEntity>((d, dt) => d.TemplateCode == dt.Code)
|
.LeftJoin<DeviceTemplateEntity>((d, dt) => d.TemplateCode == dt.Code)
|
||||||
.Where((d, dt) => dt.Brand == brand && factories.Contains(d.TenantId))
|
.Where((d, dt) => dt.Brand == brand && factories.Contains(d.TenantId))
|
||||||
.Select(d => new DeviceUniqueWithConnectionInfoDto
|
.Where(d => d.IsElevatorAcs == false)//先排除梯控
|
||||||
{
|
.Where(d => d.Enable == true)
|
||||||
DeviceUnique = d.UniqueNo,
|
.Select(d => new DeviceUniqueWithConnectionInfoDto
|
||||||
ConnectionInfo = d.ConnectionInfo
|
{
|
||||||
})
|
DeviceUnique = d.UniqueNo,
|
||||||
.ToListAsync();
|
ConnectionInfo = d.ConnectionInfo
|
||||||
|
})
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
|
||||||
|
var elevatorAcses = await _dbContext.Queryable<DeviceEntity>()
|
||||||
|
.LeftJoin<DeviceTemplateEntity>((d, dt) => d.TemplateCode == dt.Code)
|
||||||
|
.LeftJoin<ElevatorAcsFloorEntity>((d, dt, f) => d.UniqueNo == f.VirtualDeviceUniqueNo)
|
||||||
|
.Where((d, dt) => dt.Brand == brand && factories.Contains(d.TenantId))
|
||||||
|
.Where(d => d.IsElevatorAcs == true)
|
||||||
|
.Where(d => d.Enable == true)
|
||||||
|
.Select((d, dt, f) => new DeviceUniqueWithConnectionInfoDto
|
||||||
|
{
|
||||||
|
DeviceUnique = f.RealDeviceUniqueNo,
|
||||||
|
ConnectionInfo = d.ConnectionInfo
|
||||||
|
})
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
results.AddRange(elevatorAcses.DistinctBy(x => x.DeviceUnique).ToList());
|
||||||
|
|
||||||
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -298,9 +298,9 @@ public class DevicePermissionService : IDevicePermissionService
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task GenerateDeviceTasksAsync(string userNo, DeviceTaskEnumType taskType, string source)
|
public async Task GenerateDeviceTasksAsync(string userNoOrCode, DeviceTaskEnumType taskType, string source)
|
||||||
{
|
{
|
||||||
var deviceCodes = await GetUserDeviceCodesByNoAsync(userNo);
|
var deviceCodes = await GetUserDeviceCodesByNoOrCodeAsync(userNoOrCode);
|
||||||
if (deviceCodes.IsEmpty()) return;
|
if (deviceCodes.IsEmpty()) return;
|
||||||
|
|
||||||
var devices = await _dbContext.Queryable<DeviceEntity>()
|
var devices = await _dbContext.Queryable<DeviceEntity>()
|
||||||
@@ -308,13 +308,33 @@ public class DevicePermissionService : IDevicePermissionService
|
|||||||
.Where(x => deviceCodes.Contains(x.Code))
|
.Where(x => deviceCodes.Contains(x.Code))
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
|
var gainfo = await _dbContext.Queryable<GainfoEntity>()
|
||||||
|
.Where(x => x.No == userNoOrCode || x.Code == userNoOrCode)
|
||||||
|
.Select(x => new
|
||||||
|
{
|
||||||
|
UserId = x.Id,
|
||||||
|
UserNo = x.No,
|
||||||
|
UserCode = x.Code
|
||||||
|
})
|
||||||
|
.SingleAsync()
|
||||||
|
?? await _dbContext.Queryable<GainfoLeaveEntity>()
|
||||||
|
.Where(x => x.No == userNoOrCode || x.Code == userNoOrCode)
|
||||||
|
.Select(x => new
|
||||||
|
{
|
||||||
|
UserId = (long)x.IdentityUserId,
|
||||||
|
UserNo = x.No,
|
||||||
|
UserCode = x.Code
|
||||||
|
})
|
||||||
|
.SingleAsync();
|
||||||
|
|
||||||
await _dbContext.InsertAsync(devices.Select(x => new DeviceTaskEntity
|
await _dbContext.InsertAsync(devices.Select(x => new DeviceTaskEntity
|
||||||
{
|
{
|
||||||
DeviceUniqueNo = x.UniqueNo,
|
DeviceUniqueNo = x.UniqueNo,
|
||||||
Status = DeviceTaskStatusEnumType.Wait,
|
Status = DeviceTaskStatusEnumType.Wait,
|
||||||
Type = taskType,
|
Type = taskType,
|
||||||
DeviceType = x.Type,
|
DeviceType = x.Type,
|
||||||
UserNo = userNo,
|
UserNo = gainfo.UserNo,
|
||||||
|
UserId = gainfo.UserId,
|
||||||
Priority = 0,
|
Priority = 0,
|
||||||
Version = 0,
|
Version = 0,
|
||||||
TenantId = x.TenantId,
|
TenantId = x.TenantId,
|
||||||
@@ -326,11 +346,14 @@ public class DevicePermissionService : IDevicePermissionService
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取用户所有设备权限
|
/// 获取用户所有设备权限
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userNo"></param>
|
/// <param name="userNoOrCode"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<List<Guid>> GetUserDeviceCodesByNoAsync(string userNo)
|
public async Task<List<Guid>> GetUserDeviceCodesByNoOrCodeAsync(string userNoOrCode)
|
||||||
{
|
{
|
||||||
var no = await _dbContext.Queryable<GainfoEntity>().Where(x => x.No == userNo || x.Code == userNo).Select(x => x.No).SingleAsync();
|
var no = await _dbContext.Queryable<GainfoEntity>().Where(x => x.No == userNoOrCode || x.Code == userNoOrCode).Select(x => x.No).SingleAsync()
|
||||||
|
??
|
||||||
|
await _dbContext.Queryable<GainfoLeaveEntity>().Where(x => x.No == userNoOrCode || x.Code == userNoOrCode).Select(x => x.No).FirstAsync();
|
||||||
|
|
||||||
var result = await _devicePermissionAnalyzeService.GetUserAssignDeviceCodesWithTypeInTenantAsync(new List<string> { no });
|
var result = await _devicePermissionAnalyzeService.GetUserAssignDeviceCodesWithTypeInTenantAsync(new List<string> { no });
|
||||||
var deviceCodes = result.First().Value.SelectMany(x => x.AssignTypes.SelectMany(p => p.Codes)).Distinct().ToList();
|
var deviceCodes = result.First().Value.SelectMany(x => x.AssignTypes.SelectMany(p => p.Codes)).Distinct().ToList();
|
||||||
|
|
||||||
|
|||||||
@@ -38,24 +38,29 @@ public class DeviceService : IDeviceService
|
|||||||
public async Task<Pagination<DevicePageResponse>> GetPageAsync(DevicePageRequest request)
|
public async Task<Pagination<DevicePageResponse>> GetPageAsync(DevicePageRequest request)
|
||||||
{
|
{
|
||||||
var page = await _dbContext.Queryable<DeviceEntity>()
|
var page = await _dbContext.Queryable<DeviceEntity>()
|
||||||
.LeftJoin<DeviceTemplateEntity>((d, dt) => d.TemplateCode == dt.Code)
|
.LeftJoin<DeviceTemplateEntity>((d, dt) => d.TemplateCode == dt.Code)
|
||||||
.LeftJoin<DeviceRegistryEntity>((d, dt, dr) => d.UniqueNo == dr.DeviceUniqueNo)
|
.LeftJoin<DeviceRegistryEntity>((d, dt, dr) => d.UniqueNo == dr.DeviceUniqueNo)
|
||||||
.LeftJoin<BusinessPlaceEntity>((d, dt, dr, bp) => dr.BusinessPlaceCode == bp.Code)
|
.LeftJoin<BusinessPlaceEntity>((d, dt, dr, bp) => dr.BusinessPlaceCode == bp.Code)
|
||||||
.Where((d, dt) => d.Type == request.Type)
|
.LeftJoin<ElevatorAcsFloorEntity>((d, dt, dr, bp, ef) => d.UniqueNo == ef.VirtualDeviceUniqueNo)
|
||||||
.WhereIF(request.Enable.HasValue, (d, dt) => d.Enable == request.Enable)
|
.Where((d, dt) => d.Type == request.Type)
|
||||||
.WhereIF(request.Search.IsPresent(), d => d.UniqueNo == request.Search || d.DeployPlace.Contains(request.Search))
|
.Where(d => d.IsElevatorAcs == request.IsElevatorAcs)
|
||||||
.WhereIF(request.Supplier.IsPresent(), d => d.Supplier.Contains(request.Supplier))
|
.WhereIF(request.Enable.HasValue, (d, dt) => d.Enable == request.Enable)
|
||||||
.Select((d, dt, dr, bp) => new DevicePageResponse
|
.WhereIF(request.Search.IsPresent(), d => d.UniqueNo == request.Search || d.DeployPlace.Contains(request.Search))
|
||||||
{
|
.WhereIF(request.Supplier.IsPresent(), d => d.Supplier.Contains(request.Supplier))
|
||||||
FuncsStr = d.Funcs.ToString(),
|
.Select((d, dt, dr, bp, ef) => new DevicePageResponse
|
||||||
Brand = dt.Brand,
|
{
|
||||||
Type = d.Type,
|
IsElevatorAcs = d.IsElevatorAcs,
|
||||||
BusinessPlaceCode = bp.Code,
|
FuncsStr = d.Funcs.ToString(),
|
||||||
BusinessPlaceName = bp.Name,
|
Brand = dt.Brand,
|
||||||
LastHeartbeatTime = dr.LastHeartbeatTime,
|
Type = d.Type,
|
||||||
Factory = d.TenantId
|
BusinessPlaceCode = bp.Code,
|
||||||
}, true)
|
BusinessPlaceName = bp.Name,
|
||||||
.ToPageListAsync(request);
|
LastHeartbeatTime = dr.LastHeartbeatTime,
|
||||||
|
RealDeviceUniqueNo = ef.RealDeviceUniqueNo,
|
||||||
|
Factory = d.TenantId,
|
||||||
|
}, true)
|
||||||
|
.ToPageListAsync(request);
|
||||||
|
|
||||||
|
|
||||||
//获取当前用户角色
|
//获取当前用户角色
|
||||||
var role = _currentUser.GetRole();
|
var role = _currentUser.GetRole();
|
||||||
@@ -77,7 +82,6 @@ public class DeviceService : IDeviceService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var deviceUniqueNos = page.Data.Select(x => x.UniqueNo).ToList();
|
var deviceUniqueNos = page.Data.Select(x => x.UniqueNo).ToList();
|
||||||
var deviceUsers = await _dbContext.Queryable<DeviceUserEntity>()
|
var deviceUsers = await _dbContext.Queryable<DeviceUserEntity>()
|
||||||
.Where(x => deviceUniqueNos.Contains(x.DeviceUniqueNo))
|
.Where(x => deviceUniqueNos.Contains(x.DeviceUniqueNo))
|
||||||
|
|||||||
216
Src/Dlhis.Basic/Device/Services/Implements/ElevatorAcsService.cs
Normal file
216
Src/Dlhis.Basic/Device/Services/Implements/ElevatorAcsService.cs
Normal file
@@ -0,0 +1,216 @@
|
|||||||
|
using Dlhis.Basic.Device.Request;
|
||||||
|
using Dlhis.Basic.Device.Response;
|
||||||
|
using Dlhis.Entity.Basic.Entity;
|
||||||
|
using Dlhis.Entity.Device.Enums;
|
||||||
|
using Dlhis.Sys.Api;
|
||||||
|
using Kurisu.AspNetCore.Authentication.Abstractions;
|
||||||
|
using Kurisu.AspNetCore.CustomClass;
|
||||||
|
using Kurisu.AspNetCore.DataAccess.Entity;
|
||||||
|
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||||
|
using Kurisu.AspNetCore.Utils.Extensions;
|
||||||
|
using Mapster;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
|
namespace Dlhis.Basic.Device.Services.Implements;
|
||||||
|
|
||||||
|
public class ElevatorAcsService : IElevatorAcsService
|
||||||
|
{
|
||||||
|
private readonly IDbContext _dbContext;
|
||||||
|
private readonly ICurrentUser _currentUser;
|
||||||
|
private readonly ITenantApi _tenantApi;
|
||||||
|
|
||||||
|
private const string DefaultPassword = "********";
|
||||||
|
private const string DefaultPasswordKey = "password";
|
||||||
|
|
||||||
|
public ElevatorAcsService(IDbContext dbContext, ICurrentUser currentUser, ITenantApi tenantApi)
|
||||||
|
{
|
||||||
|
_dbContext = dbContext;
|
||||||
|
_currentUser = currentUser;
|
||||||
|
_tenantApi = tenantApi;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task SaveAsync(ElevatorAcsSaveRequest request)
|
||||||
|
{
|
||||||
|
await CheckUniqueNoExistsAsync(request);
|
||||||
|
await CheckTemplateExistsAsync(request.TemplateCode);
|
||||||
|
await CheckTemplateFieldAsync(request.TemplateCode, request.ConnectionInfo);
|
||||||
|
|
||||||
|
if (!request.IsEdit)
|
||||||
|
{
|
||||||
|
var password = GetJsonValue(request.ConnectionInfo, DefaultPasswordKey);
|
||||||
|
if (password.IsPresent())
|
||||||
|
{
|
||||||
|
(password == DefaultPassword).ThrowIfTrue("不支持错误的密码类型");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < request.Floors.Count; i++)
|
||||||
|
{
|
||||||
|
var floor = request.Floors[i];
|
||||||
|
|
||||||
|
DeviceEntity entity = request.Adapt<DeviceEntity>();
|
||||||
|
entity.Code = Guid.NewGuid();
|
||||||
|
entity.Type = DeviceTypeEnumType.Door;
|
||||||
|
entity.IsElevatorAcs = true;
|
||||||
|
entity.Enable = true;
|
||||||
|
|
||||||
|
var virtualDeviceUniqueNo = $"{request.UniqueNo}-EACS-{floor.FloorName}";
|
||||||
|
entity.UniqueNo = virtualDeviceUniqueNo;
|
||||||
|
|
||||||
|
var elevatorAcsFloor = new ElevatorAcsFloorEntity
|
||||||
|
{
|
||||||
|
RealDeviceUniqueNo = request.UniqueNo,
|
||||||
|
FloorName = floor.FloorName,
|
||||||
|
AcsValue = i,
|
||||||
|
VirtualDeviceUniqueNo = virtualDeviceUniqueNo,
|
||||||
|
};
|
||||||
|
|
||||||
|
await _dbContext.InsertAsync(entity);
|
||||||
|
await _dbContext.InsertAsync(elevatorAcsFloor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var prefix = request.UniqueNo + "-EACS-";
|
||||||
|
List<DeviceEntity> entities = await _dbContext.Queryable<DeviceEntity>().Where(x => x.UniqueNo.StartsWith(prefix)).ToListAsync();
|
||||||
|
|
||||||
|
foreach (var entity in entities)
|
||||||
|
{
|
||||||
|
//检查更新的密码字段是否为默认密码,如果是,则将原有密码从数据库实体中取出并替换到请求的连接信息中,防止默认密码被保存。
|
||||||
|
// 这样可以避免用户在未修改密码时,前端传递默认密码导致密码被覆盖为不可用的默认值。
|
||||||
|
var updatePassword = GetJsonValue(request.ConnectionInfo, DefaultPasswordKey);
|
||||||
|
if (updatePassword.IsPresent())
|
||||||
|
{
|
||||||
|
if (updatePassword == DefaultPassword)
|
||||||
|
{
|
||||||
|
var jObj = JObject.Parse(request.ConnectionInfo);
|
||||||
|
var password = GetJsonValue(entity.ConnectionInfo, DefaultPasswordKey);
|
||||||
|
|
||||||
|
jObj[DefaultPasswordKey] = password;
|
||||||
|
request.ConnectionInfo = jObj.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
request.Adapt(entity);
|
||||||
|
await _dbContext.UpdateAsync(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<ElevatorAcsDetailResponse> GetDetailsAsync(string deviceUniqueNo)
|
||||||
|
{
|
||||||
|
var floor = await _dbContext.Queryable<ElevatorAcsFloorEntity>().Where(x => x.VirtualDeviceUniqueNo == deviceUniqueNo).SingleAsync();
|
||||||
|
var floors = await _dbContext.Queryable<ElevatorAcsFloorEntity>().Where(x => x.RealDeviceUniqueNo == floor.RealDeviceUniqueNo).ToListAsync();
|
||||||
|
var deviceUniqueNos = floors.Select(x => x.VirtualDeviceUniqueNo).ToList();
|
||||||
|
|
||||||
|
var device = await _dbContext.Queryable<DeviceEntity>().Where(x => x.UniqueNo == deviceUniqueNo).SingleAsync();
|
||||||
|
|
||||||
|
|
||||||
|
var result = device.Adapt<ElevatorAcsDetailResponse>();
|
||||||
|
result.UniqueNo = floor.RealDeviceUniqueNo;
|
||||||
|
result.Floors = floors.Adapt<List<ElevatorAcsFloorResponse>>();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取json的字段值
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="json"></param>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="UserFriendlyException"></exception>
|
||||||
|
private static string GetJsonValue(string json, string key)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var jObj = JObject.Parse(json);
|
||||||
|
return jObj.TryGetValue(key, out var value)
|
||||||
|
? value.Value<string>()
|
||||||
|
: string.Empty;
|
||||||
|
}
|
||||||
|
catch (JsonReaderException)
|
||||||
|
{
|
||||||
|
throw new UserFriendlyException("连接信息参数格式不正确");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 检查设备模板是否存在
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="templateCode"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private async Task CheckTemplateExistsAsync(Guid templateCode)
|
||||||
|
{
|
||||||
|
var entity = await _dbContext.Queryable<DeviceTemplateEntity>().Where(x => x.Code == templateCode).FirstAsync();
|
||||||
|
entity.ThrowIfNull("设备模板不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 检查设备连接参数是否与模板设定一致
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="templateCode"></param>
|
||||||
|
/// <param name="jsonContent"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private async Task CheckTemplateFieldAsync(Guid templateCode, string jsonContent)
|
||||||
|
{
|
||||||
|
var template = await _dbContext.Queryable<DeviceTemplateEntity>().Where(x => x.Code == templateCode).SingleAsync();
|
||||||
|
template.ThrowIfNull("设备模板不存在");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var templateJObj = JObject.Parse(template.Template);
|
||||||
|
var jObj = JObject.Parse(jsonContent);
|
||||||
|
(templateJObj.Count == jObj.Count).ThrowIfFalse("连接参数字段数不一致");
|
||||||
|
|
||||||
|
foreach (var item in templateJObj)
|
||||||
|
{
|
||||||
|
jObj.ContainsKey(item.Key).ThrowIfFalse($"设备连接参数需要和模板一致.缺失{item.Key}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex) when (ex is JsonReaderException)
|
||||||
|
{
|
||||||
|
throw new UserFriendlyException("连接信息参数格式不正确");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 检查唯一号是否存在
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private async Task CheckUniqueNoExistsAsync(ElevatorAcsSaveRequest request)
|
||||||
|
{
|
||||||
|
await _dbContext.IgnoreAsync<ITenantId>(async () =>
|
||||||
|
{
|
||||||
|
var currentTenantId = _currentUser.GetStringTenantId();
|
||||||
|
|
||||||
|
var prefix = request.UniqueNo + "-EACS-";
|
||||||
|
|
||||||
|
//查询设备是否存在
|
||||||
|
var device = await _dbContext.Queryable<DeviceEntity>()
|
||||||
|
.Where(x => x.UniqueNo == request.UniqueNo)
|
||||||
|
.WhereIF(!request.IsEdit, x => x.UniqueNo.StartsWith(prefix))
|
||||||
|
.SingleAsync();
|
||||||
|
|
||||||
|
if (device != null)
|
||||||
|
{
|
||||||
|
(device.TenantId == currentTenantId).ThrowIfTrue("设备已经存在,请检查");
|
||||||
|
|
||||||
|
var factory = device.TenantId;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var tenant = await _tenantApi.GetTenantByCodeAsync(device.TenantId);
|
||||||
|
factory = tenant?.Name ?? string.Empty;
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
//ignore
|
||||||
|
}
|
||||||
|
|
||||||
|
true.ThrowIfTrue($"设备已添加{factory}厂区");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,6 +29,7 @@ public class GainfoCardsController : ControllerBase
|
|||||||
/// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost("change")]
|
[HttpPost("change")]
|
||||||
|
[IgnoreTenant]
|
||||||
[Transactional]
|
[Transactional]
|
||||||
public async Task ChangeCardAsync(GainfoChangeCardRequest request)
|
public async Task ChangeCardAsync(GainfoChangeCardRequest request)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -35,6 +35,19 @@ public class GainfoFingerprintsController : ControllerBase
|
|||||||
await _gainfoFingerprintService.CollectFingerprintAsync(request.UserCode, request.FingerNum, request.Fingerprint);
|
await _gainfoFingerprintService.CollectFingerprintAsync(request.UserCode, request.FingerNum, request.Fingerprint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 批量采集
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost("batchCollect")]
|
||||||
|
[IgnoreTenant]
|
||||||
|
[Transactional]
|
||||||
|
public async Task CollectFingerprintAsync(FingerprintBatchCollectRequest request)
|
||||||
|
{
|
||||||
|
await _gainfoFingerprintService.CollectFingerprintAsync(request);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取人员指纹数据
|
/// 获取人员指纹数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace Dlhis.Basic.Organization.Request
|
||||||
|
{
|
||||||
|
public class FingerprintBatchCollectRequest
|
||||||
|
{
|
||||||
|
[Required(ErrorMessage = "工号不能为空")]
|
||||||
|
public string UserCode { get; set; }
|
||||||
|
|
||||||
|
[MinLength(1, ErrorMessage = "指纹列表不能为空")]
|
||||||
|
public List<FingerprintItem> Fingerprints { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public class FingerprintItem
|
||||||
|
{
|
||||||
|
public int FingerNum { get; set; }
|
||||||
|
public string Fingerprint { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
using Dlhis.Basic.Organization.Response;
|
using Dlhis.Basic.Organization.Request;
|
||||||
|
using Dlhis.Basic.Organization.Response;
|
||||||
|
|
||||||
namespace Dlhis.Basic.Organization.Services;
|
namespace Dlhis.Basic.Organization.Services;
|
||||||
|
|
||||||
public interface IGainfoFingerprintService : IScopeDependency
|
public interface IGainfoFingerprintService : IScopeDependency
|
||||||
{
|
{
|
||||||
Task CollectFingerprintAsync(string userCode, int fingerNum, string fingerprint);
|
Task CollectFingerprintAsync(string userCode, int fingerNum, string fingerprint);
|
||||||
|
Task CollectFingerprintAsync(FingerprintBatchCollectRequest request);
|
||||||
|
|
||||||
Task<GainfoFingerprintResponse> GetFingerprintAsync(string userCode, int? fingerNum);
|
Task<GainfoFingerprintResponse> GetFingerprintAsync(string userCode, int? fingerNum);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,13 +29,23 @@ public class GainfoCardService : IGainfoCardService
|
|||||||
|
|
||||||
public async Task ChangeCardAsync(GainfoChangeCardRequest request)
|
public async Task ChangeCardAsync(GainfoChangeCardRequest request)
|
||||||
{
|
{
|
||||||
|
if (await _gainfoStore.Queryable().Where(x => x.CardNo == request.CardNo).AnyAsync())
|
||||||
|
{
|
||||||
|
true.ThrowIfTrue("卡号已分配");
|
||||||
|
}
|
||||||
|
|
||||||
var gainfo = await _gainfoStore.Queryable().Where(x => x.No == request.UserNo).FirstAsync();
|
var gainfo = await _gainfoStore.Queryable().Where(x => x.No == request.UserNo).FirstAsync();
|
||||||
gainfo.ThrowIfNull("档案不存在");
|
gainfo.ThrowIfNull("档案不存在");
|
||||||
|
|
||||||
gainfo.CardNo = request.CardNo;
|
gainfo.CardNo = request.CardNo;
|
||||||
|
|
||||||
await _gainfoStore.UpdateAsync(gainfo);
|
await _gainfoStore.UpdateAsync(gainfo);
|
||||||
await _dbContext.InsertAsync(request.Adapt<GainfoCardRecordEntity>());
|
|
||||||
|
var cardRecord = request.Adapt<GainfoCardRecordEntity>();
|
||||||
|
cardRecord.TenantId = gainfo.Factory;
|
||||||
|
await _dbContext.InsertAsync(cardRecord);
|
||||||
|
|
||||||
|
await _gainfoPermissionService.ResetPermissionsAsync(gainfo.No, DeviceTaskEnumType.Update, null, null, "更新卡号下发");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<List<ChangeCardResponse>> GetChangeRecordsAsync(string userNo)
|
public async Task<List<ChangeCardResponse>> GetChangeRecordsAsync(string userNo)
|
||||||
|
|||||||
@@ -1,72 +1,117 @@
|
|||||||
using Dlhis.Basic.Organization.Response;
|
using Dlhis.Basic.Device.Services;
|
||||||
|
using Dlhis.Basic.Organization.Request;
|
||||||
|
using Dlhis.Basic.Organization.Response;
|
||||||
using Dlhis.Entity.Basic.Entity;
|
using Dlhis.Entity.Basic.Entity;
|
||||||
|
using Dlhis.Entity.Device.Entities;
|
||||||
|
using Dlhis.Entity.Device.Enums;
|
||||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||||
using Kurisu.AspNetCore.Utils.Extensions;
|
using Kurisu.AspNetCore.Utils.Extensions;
|
||||||
|
|
||||||
namespace Dlhis.Basic.Organization.Services.Implements
|
namespace Dlhis.Basic.Organization.Services.Implements;
|
||||||
|
|
||||||
|
public class GainfoFingerprintService : IGainfoFingerprintService
|
||||||
{
|
{
|
||||||
public class GainfoFingerprintService : IGainfoFingerprintService
|
private readonly IDbContext _dbContext;
|
||||||
|
private readonly IDevicePermissionService _devicePermissionService;
|
||||||
|
|
||||||
|
public GainfoFingerprintService(IDbContext dbContext, IDevicePermissionService devicePermissionService)
|
||||||
{
|
{
|
||||||
private readonly IDbContext _dbContext;
|
_dbContext = dbContext;
|
||||||
|
_devicePermissionService = devicePermissionService;
|
||||||
public GainfoFingerprintService(IDbContext dbContext)
|
}
|
||||||
|
public async Task CollectFingerprintAsync(string userCode, int fingerNum, string fingerprint)
|
||||||
|
{
|
||||||
|
await CollectFingerprintAsync(new FingerprintBatchCollectRequest
|
||||||
{
|
{
|
||||||
_dbContext = dbContext;
|
UserCode = userCode,
|
||||||
}
|
Fingerprints = new List<FingerprintItem>
|
||||||
public async Task CollectFingerprintAsync(string userCode, int fingerNum, string fingerprint)
|
|
||||||
{
|
|
||||||
if (!await _dbContext.Queryable<GainfoEntity>().Where(x => x.Code == userCode).AnyAsync())
|
|
||||||
{
|
{
|
||||||
true.ThrowIfTrue("人员不存在");
|
new FingerprintItem
|
||||||
|
{
|
||||||
|
FingerNum = fingerNum,
|
||||||
|
Fingerprint = fingerprint
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
var gainfoFingerprint = await _dbContext.Queryable<GainfoFingerprintEntity>().Where(x => x.UserCode == userCode && x.FingerNum == fingerNum).FirstAsync();
|
public async Task CollectFingerprintAsync(FingerprintBatchCollectRequest request)
|
||||||
|
{
|
||||||
|
var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.Code == request.UserCode).SingleAsync();
|
||||||
|
gainfo.ThrowIfNull("人员不存在");
|
||||||
|
gainfo.CardNo.IsEmpty().ThrowIfTrue("人员未绑定卡号,无法采集指纹");
|
||||||
|
|
||||||
|
|
||||||
|
foreach (var item in request.Fingerprints)
|
||||||
|
{
|
||||||
|
var gainfoFingerprint = await _dbContext.Queryable<GainfoFingerprintEntity>().Where(x => x.UserCode == request.UserCode && x.FingerNum == item.FingerNum).FirstAsync();
|
||||||
if (gainfoFingerprint == null)
|
if (gainfoFingerprint == null)
|
||||||
{
|
{
|
||||||
gainfoFingerprint = new GainfoFingerprintEntity
|
gainfoFingerprint = new GainfoFingerprintEntity
|
||||||
{
|
{
|
||||||
UserCode = userCode,
|
UserCode = request.UserCode,
|
||||||
FingerNum = fingerNum,
|
FingerNum = item.FingerNum,
|
||||||
Fingerprint = fingerprint
|
Fingerprint = item.Fingerprint
|
||||||
};
|
};
|
||||||
await _dbContext.InsertAsync(gainfoFingerprint);
|
await _dbContext.InsertAsync(gainfoFingerprint);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gainfoFingerprint.Fingerprint = fingerprint;
|
gainfoFingerprint.Fingerprint = item.Fingerprint;
|
||||||
await _dbContext.UpdateAsync(gainfoFingerprint);
|
await _dbContext.UpdateAsync(gainfoFingerprint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<GainfoFingerprintResponse> GetFingerprintAsync(string userCode, int? fingerNum)
|
var deviceCodes = await _devicePermissionService.GetUserDeviceCodesByNoOrCodeAsync(request.UserCode);
|
||||||
|
var devices = await _dbContext.Queryable<DeviceEntity>()
|
||||||
|
.Where(x => x.IsElevatorAcs)
|
||||||
|
.Where(x => deviceCodes.Contains(x.Code))
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
await _dbContext.InsertAsync(devices.Select(x => new DeviceTaskEntity
|
||||||
{
|
{
|
||||||
var gainfo = await _dbContext.Queryable<GainfoEntity>()
|
DeviceUniqueNo = x.UniqueNo,
|
||||||
.LeftJoin<DepartmentEntity>((x, dept) => x.DepartmentNo == dept.No)
|
Status = DeviceTaskStatusEnumType.Wait,
|
||||||
.Where(x => x.Code == userCode)
|
Type = DeviceTaskEnumType.Add,
|
||||||
.Select((x, dept) => new
|
DeviceType = x.Type,
|
||||||
{
|
UserNo = gainfo.No,
|
||||||
x.Code,
|
UserId = gainfo.Id,
|
||||||
x.Name,
|
Priority = 0,
|
||||||
x.DepartmentNo,
|
Version = 0,
|
||||||
DepartmentName = dept.Name
|
TenantId = x.TenantId,
|
||||||
})
|
Source = "指纹采集下发"
|
||||||
.FirstAsync();
|
}).ToList());
|
||||||
gainfo.ThrowIfNull("人员不存在");
|
}
|
||||||
|
|
||||||
var fingerprins = await _dbContext.Queryable<GainfoFingerprintEntity>().Where(x => x.UserCode == userCode).OrderBy(x => x.FingerNum).ToListAsync();
|
|
||||||
|
|
||||||
return new GainfoFingerprintResponse
|
public async Task<GainfoFingerprintResponse> GetFingerprintAsync(string userCode, int? fingerNum)
|
||||||
|
{
|
||||||
|
var gainfo = await _dbContext.Queryable<GainfoEntity>()
|
||||||
|
.LeftJoin<DepartmentEntity>((x, dept) => x.DepartmentNo == dept.No)
|
||||||
|
.Where(x => x.Code == userCode)
|
||||||
|
.Select((x, dept) => new
|
||||||
{
|
{
|
||||||
UserCode = gainfo.Code,
|
x.Code,
|
||||||
UserName = gainfo.Name,
|
x.Name,
|
||||||
DepartmentNo = gainfo.DepartmentNo,
|
x.DepartmentNo,
|
||||||
DepartmentName = gainfo.DepartmentName,
|
DepartmentName = dept.Name
|
||||||
Fingerprints = fingerprins.Select(x => new FingerprintResponse
|
})
|
||||||
{
|
.FirstAsync();
|
||||||
FingerNum = x.FingerNum,
|
gainfo.ThrowIfNull("人员不存在");
|
||||||
Fingerprint = x.Fingerprint
|
|
||||||
}).ToList()
|
var fingerprins = await _dbContext.Queryable<GainfoFingerprintEntity>().Where(x => x.UserCode == userCode).OrderBy(x => x.FingerNum).ToListAsync();
|
||||||
};
|
|
||||||
}
|
return new GainfoFingerprintResponse
|
||||||
|
{
|
||||||
|
UserCode = gainfo.Code,
|
||||||
|
UserName = gainfo.Name,
|
||||||
|
DepartmentNo = gainfo.DepartmentNo,
|
||||||
|
DepartmentName = gainfo.DepartmentName,
|
||||||
|
Fingerprints = fingerprins.Select(x => new FingerprintResponse
|
||||||
|
{
|
||||||
|
FingerNum = x.FingerNum,
|
||||||
|
Fingerprint = x.Fingerprint
|
||||||
|
}).ToList()
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,11 +19,15 @@ namespace Dlhis.Basic.Organization.Services.Implements;
|
|||||||
public class GainfoPermissionService : IGainfoPermissionService
|
public class GainfoPermissionService : IGainfoPermissionService
|
||||||
{
|
{
|
||||||
private readonly IDevicePermissionAnalyzeService _devicePermissionAnalyzeService;
|
private readonly IDevicePermissionAnalyzeService _devicePermissionAnalyzeService;
|
||||||
|
private readonly IDevicePermissionService _devicePermissionService;
|
||||||
private readonly IDbContext _dbContext;
|
private readonly IDbContext _dbContext;
|
||||||
|
|
||||||
public GainfoPermissionService(IDevicePermissionAnalyzeService devicePermissionAnalyzeService, IDbContext dbContext)
|
public GainfoPermissionService(IDevicePermissionAnalyzeService devicePermissionAnalyzeService,
|
||||||
|
IDevicePermissionService devicePermissionService,
|
||||||
|
IDbContext dbContext)
|
||||||
{
|
{
|
||||||
_devicePermissionAnalyzeService = devicePermissionAnalyzeService;
|
_devicePermissionAnalyzeService = devicePermissionAnalyzeService;
|
||||||
|
_devicePermissionService = devicePermissionService;
|
||||||
_dbContext = dbContext;
|
_dbContext = dbContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,81 +106,81 @@ public class GainfoPermissionService : IGainfoPermissionService
|
|||||||
}).ToList());
|
}).ToList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Pagination<GainfoDevicePermissionResponse>> GetAssignDeviceCodes2Async(DeviceAssRequest request)
|
//public async Task<Pagination<GainfoDevicePermissionResponse>> GetAssignDeviceCodes2Async(DeviceAssRequest request)
|
||||||
{
|
//{
|
||||||
var result = await _devicePermissionAnalyzeService.GetUserAssignDeviceCodesWithTypeInTenantAsync(new List<string> { request.UserNo });
|
// var result = await _devicePermissionAnalyzeService.GetUserAssignDeviceCodesWithTypeInTenantAsync(new List<string> { request.UserNo });
|
||||||
if (!result.TryGetValue(request.UserNo, out var permissions))
|
// if (!result.TryGetValue(request.UserNo, out var permissions))
|
||||||
{
|
// {
|
||||||
return new Pagination<GainfoDevicePermissionResponse>();
|
// return new Pagination<GainfoDevicePermissionResponse>();
|
||||||
}
|
// }
|
||||||
|
|
||||||
var expandResult = await ExpandUserAssignDeviceCodesWithTypeInTenantAsync(result);
|
// var expandResult = await ExpandUserAssignDeviceCodesWithTypeInTenantAsync(result);
|
||||||
|
|
||||||
var deviceCodes = permissions.SelectMany(x => x.AssignTypes.SelectMany(p => p.Codes)).Distinct().ToList();
|
// var deviceCodes = permissions.SelectMany(x => x.AssignTypes.SelectMany(p => p.Codes)).Distinct().ToList();
|
||||||
|
|
||||||
var list = await _dbContext.Queryable<DeviceEntity>()
|
// var list = await _dbContext.Queryable<DeviceEntity>()
|
||||||
.LeftJoin<DeviceRegistryEntity>((d, dr) => d.UniqueNo == dr.DeviceUniqueNo)
|
// .LeftJoin<DeviceRegistryEntity>((d, dr) => d.UniqueNo == dr.DeviceUniqueNo)
|
||||||
.WhereIF(request.Search.IsPresent(), d => d.UniqueNo == request.Search)
|
// .WhereIF(request.Search.IsPresent(), d => d.UniqueNo == request.Search)
|
||||||
.Where(d => deviceCodes.Contains(d.Code))
|
// .Where(d => deviceCodes.Contains(d.Code))
|
||||||
.Select((d, dr) => new GainfoDevicePermissionResponse { Factory = d.TenantId }, true)
|
// .Select((d, dr) => new GainfoDevicePermissionResponse { Factory = d.TenantId }, true)
|
||||||
.ToListAsync();
|
// .ToListAsync();
|
||||||
|
|
||||||
var deviceGroups = await _dbContext.Queryable<DeviceGroupEntity>().Select(x => new { x.Code, x.Name }).ToListAsync();
|
// var deviceGroups = await _dbContext.Queryable<DeviceGroupEntity>().Select(x => new { x.Code, x.Name }).ToListAsync();
|
||||||
var departments = permissions.Any(x => x.AssignTypes.Any(p => p.AssignType == AssignTypeEnumType.Department))
|
// var departments = permissions.Any(x => x.AssignTypes.Any(p => p.AssignType == AssignTypeEnumType.Department))
|
||||||
? await _dbContext.Queryable<DepartmentEntity>().Select(x => new { x.No, x.Name }).ToListAsync()
|
// ? await _dbContext.Queryable<DepartmentEntity>().Select(x => new { x.No, x.Name }).ToListAsync()
|
||||||
: new[] { new { No = string.Empty, Name = string.Empty } }.ToList();
|
// : new[] { new { No = string.Empty, Name = string.Empty } }.ToList();
|
||||||
|
|
||||||
var userGroups = permissions.Any(x => x.AssignTypes.Any(p => p.AssignType == AssignTypeEnumType.Group))
|
// var userGroups = permissions.Any(x => x.AssignTypes.Any(p => p.AssignType == AssignTypeEnumType.Group))
|
||||||
? await _dbContext.Queryable<GainfoGroupEntity>().Select(x => new { x.Code, x.Name }).ToListAsync()
|
// ? await _dbContext.Queryable<GainfoGroupEntity>().Select(x => new { x.Code, x.Name }).ToListAsync()
|
||||||
: new[] { new { Code = Guid.Empty, Name = string.Empty } }.ToList();
|
// : new[] { new { Code = Guid.Empty, Name = string.Empty } }.ToList();
|
||||||
|
|
||||||
|
|
||||||
list.ForEach(item =>
|
// list.ForEach(item =>
|
||||||
{
|
// {
|
||||||
var permission = permissions.FirstOrDefault(x => x.Tenant == item.Factory);
|
// var permission = permissions.FirstOrDefault(x => x.Tenant == item.Factory);
|
||||||
if (permission != null)
|
// if (permission != null)
|
||||||
{
|
// {
|
||||||
item.Source = new DevicePermissionSourceDto
|
// item.Source = new DevicePermissionSourceDto
|
||||||
{
|
// {
|
||||||
Factory = item.Factory,
|
// Factory = item.Factory,
|
||||||
Types = permission.AssignTypes.Where(x => x.Codes.Any(p => p == item.Code)).Select(x =>
|
// Types = permission.AssignTypes.Where(x => x.Codes.Any(p => p == item.Code)).Select(x =>
|
||||||
{
|
// {
|
||||||
var codeDesc = x.UniqueType == DeviceAssignmentTypeEnumType.Device
|
// var codeDesc = x.UniqueType == DeviceAssignmentTypeEnumType.Device
|
||||||
? item.DeployPlace
|
// ? item.DeployPlace
|
||||||
: deviceGroups.FirstOrDefault(p => p.Code == x.OriginalCodes.First())?.Name;
|
// : deviceGroups.FirstOrDefault(p => p.Code == x.OriginalCodes.First())?.Name;
|
||||||
|
|
||||||
var currentAssignValue = x.AssignValue;
|
// var currentAssignValue = x.AssignValue;
|
||||||
|
|
||||||
currentAssignValue = x.AssignType switch
|
// currentAssignValue = x.AssignType switch
|
||||||
{
|
// {
|
||||||
AssignTypeEnumType.Department => departments.FirstOrDefault(p => p.No == x.AssignValue.Split(":")[1])?.Name,
|
// AssignTypeEnumType.Department => departments.FirstOrDefault(p => p.No == x.AssignValue.Split(":")[1])?.Name,
|
||||||
AssignTypeEnumType.Group => userGroups.FirstOrDefault(p => p.Code == Guid.Parse(currentAssignValue))?.Name,
|
// AssignTypeEnumType.Group => userGroups.FirstOrDefault(p => p.Code == Guid.Parse(currentAssignValue))?.Name,
|
||||||
AssignTypeEnumType.User => "自己",
|
// AssignTypeEnumType.User => "自己",
|
||||||
_ => currentAssignValue
|
// _ => currentAssignValue
|
||||||
};
|
// };
|
||||||
|
|
||||||
var r = new DevicePermissionSourceTypeDto
|
// var r = new DevicePermissionSourceTypeDto
|
||||||
{
|
// {
|
||||||
AssignType = x.AssignType,
|
// AssignType = x.AssignType,
|
||||||
AssignValue = currentAssignValue,
|
// AssignValue = currentAssignValue,
|
||||||
UniqueType = x.UniqueType,
|
// UniqueType = x.UniqueType,
|
||||||
Codes = x.UniqueType == DeviceAssignmentTypeEnumType.Device
|
// Codes = x.UniqueType == DeviceAssignmentTypeEnumType.Device
|
||||||
? x.Codes.Where(p => p == item.Code)
|
// ? x.Codes.Where(p => p == item.Code)
|
||||||
: x.Codes.Take(1),
|
// : x.Codes.Take(1),
|
||||||
CodeDesc = codeDesc
|
// CodeDesc = codeDesc
|
||||||
};
|
// };
|
||||||
|
|
||||||
return r;
|
// return r;
|
||||||
})
|
// })
|
||||||
};
|
// };
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
|
||||||
var page = list.Where(x => x.Type == request.DeviceType).ToPage(request);
|
// var page = list.Where(x => x.Type == request.DeviceType).ToPage(request);
|
||||||
page.Total = list.Where(x => x.Type == request.DeviceType).Count();
|
// page.Total = list.Where(x => x.Type == request.DeviceType).Count();
|
||||||
|
|
||||||
return page;
|
// return page;
|
||||||
}
|
//}
|
||||||
|
|
||||||
private void HandleNext(Guid current, List<Guid> links, List<DeviceGroupEntity> deviceGroups, List<DeviceGroupRelationshipEntity> deviceGroupRelationships, List<TenantAssignTypeDeviceCodeExpanded> result)
|
private void HandleNext(Guid current, List<Guid> links, List<DeviceGroupEntity> deviceGroups, List<DeviceGroupRelationshipEntity> deviceGroupRelationships, List<TenantAssignTypeDeviceCodeExpanded> result)
|
||||||
{
|
{
|
||||||
@@ -270,99 +274,34 @@ public class GainfoPermissionService : IGainfoPermissionService
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// public async Task<Pagination<GainfoDevicePermissionResponse>> GetAllUserAssignDeviceCodesAsync()
|
|
||||||
// {
|
|
||||||
// var result = await _devicePermissionAnalyzeService.GetUserAssignDeviceCodesWithTypeInTenantAsync(null);
|
|
||||||
//
|
|
||||||
// var codes = permissions.SelectMany(x => x.AssignTypes.SelectMany(p => p.Codes)).Distinct().ToList();
|
|
||||||
//
|
|
||||||
// var page = await _dbContext.Queryable<DeviceEntity>()
|
|
||||||
// .LeftJoin<DeviceRegistryEntity>((d, dr) => d.UniqueNo == dr.DeviceUniqueNo)
|
|
||||||
// .WhereIF(request.DeviceType.HasValue, d => d.Type == request.DeviceType)
|
|
||||||
// .WhereIF(request.Search.IsPresent(), d => d.UniqueNo == request.Search)
|
|
||||||
// .Where(d => codes.Contains(d.Code))
|
|
||||||
// .Select((d, dr) => new GainfoDevicePermissionResponse { Factory = d.TenantId }, true)
|
|
||||||
// .ToPageListAsync(request);
|
|
||||||
//
|
|
||||||
// var deviceGroups = await _dbContext.Queryable<DeviceGroupEntity>().Select(x => new { x.Code, x.Name }).ToListAsync();
|
|
||||||
// var departments = permissions.Any(x => x.AssignTypes.Any(p => p.AssignType == AssignTypeEnumType.Department))
|
|
||||||
// ? await _dbContext.Queryable<DepartmentEntity>().Select(x => new { x.No, x.Name }).ToListAsync()
|
|
||||||
// : new[] { new { No = string.Empty, Name = string.Empty } }.ToList();
|
|
||||||
//
|
|
||||||
// var userGroups = permissions.Any(x => x.AssignTypes.Any(p => p.AssignType == AssignTypeEnumType.Group))
|
|
||||||
// ? await _dbContext.Queryable<GainfoGroupEntity>().Select(x => new { x.Code, x.Name }).ToListAsync()
|
|
||||||
// : new[] { new { Code = Guid.Empty, Name = string.Empty } }.ToList();
|
|
||||||
//
|
|
||||||
// page.Data.ForEach(item =>
|
|
||||||
// {
|
|
||||||
// var permission = permissions.FirstOrDefault(x => x.Tenant == item.Factory);
|
|
||||||
// if (permission != null)
|
|
||||||
// {
|
|
||||||
// item.Source = new DevicePermissionSourceDto
|
|
||||||
// {
|
|
||||||
// Factory = item.Factory,
|
|
||||||
// Types = permission.AssignTypes.Where(x => x.Codes.Any(p => p == item.Code)).Select(x =>
|
|
||||||
// {
|
|
||||||
// var codeDesc = x.UniqueType == DeviceAssignmentTypeEnumType.Device
|
|
||||||
// ? item.DeployPlace
|
|
||||||
// : deviceGroups.FirstOrDefault(p => p.Code == x.OriginalCodes.First())?.Name;
|
|
||||||
//
|
|
||||||
// var currentAssignValue = x.AssignValue;
|
|
||||||
//
|
|
||||||
// currentAssignValue = x.AssignType switch
|
|
||||||
// {
|
|
||||||
// AssignTypeEnumType.Department => departments.FirstOrDefault(p => p.No == x.AssignValue.Split(":")[1])?.Name,
|
|
||||||
// AssignTypeEnumType.Group => userGroups.FirstOrDefault(p => p.Code == Guid.Parse(currentAssignValue))?.Name,
|
|
||||||
// AssignTypeEnumType.User => "自己",
|
|
||||||
// _ => currentAssignValue
|
|
||||||
// };
|
|
||||||
//
|
|
||||||
// var r = new DevicePermissionSourceTypeDto
|
|
||||||
// {
|
|
||||||
// AssignType = x.AssignType,
|
|
||||||
// AssignValue = currentAssignValue,
|
|
||||||
// UniqueType = x.UniqueType,
|
|
||||||
// Codes = x.UniqueType == DeviceAssignmentTypeEnumType.Device
|
|
||||||
// ? x.Codes.Where(p => p == item.Code)
|
|
||||||
// : x.Codes.Take(1),
|
|
||||||
// CodeDesc = codeDesc
|
|
||||||
// };
|
|
||||||
//
|
|
||||||
// return r;
|
|
||||||
// })
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// return page;
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
public async Task<DevicePermissionAssignResponse> ResetPermissionsAsync(string userNo, DeviceTaskEnumType type, DeviceTypeEnumType? deviceType, List<Guid> deviceCodes, string source)
|
public async Task<DevicePermissionAssignResponse> ResetPermissionsAsync(string userNo, DeviceTaskEnumType type, DeviceTypeEnumType? deviceType, List<Guid> deviceCodes, string source)
|
||||||
{
|
{
|
||||||
var gainfo = await _dbContext.Queryable<GainfoEntity>()
|
var gainfo = await _dbContext.Queryable<GainfoEntity>()
|
||||||
.Where(x => x.No == userNo)
|
.Where(x => x.No == userNo || x.Code == userNo)
|
||||||
.SingleAsync();
|
.Select(x => new
|
||||||
|
{
|
||||||
if (gainfo == null)
|
UserId = x.Id,
|
||||||
{
|
UserNo = x.No,
|
||||||
gainfo = await _dbContext.Queryable<GainfoEntity>().AS("GainfoLeave")
|
UserCode = x.Code
|
||||||
.Where(x => x.No == userNo)
|
})
|
||||||
.SingleAsync();
|
.SingleAsync()
|
||||||
|
?? await _dbContext.Queryable<GainfoLeaveEntity>()
|
||||||
if (gainfo != null)
|
.Where(x => x.No == userNo || x.Code == userNo)
|
||||||
|
.Select(x => new
|
||||||
{
|
{
|
||||||
gainfo.Id = gainfo.IdentityUserId;
|
UserId = (long)x.IdentityUserId,
|
||||||
}
|
UserNo = x.No,
|
||||||
}
|
UserCode = x.Code
|
||||||
|
})
|
||||||
|
.SingleAsync();
|
||||||
|
|
||||||
gainfo.ThrowIfNull("档案数据不存在");
|
gainfo.ThrowIfNull("档案数据不存在");
|
||||||
|
|
||||||
//获取人员的设备权限
|
//获取人员的设备权限
|
||||||
if (deviceCodes.IsEmpty())
|
if (deviceCodes.IsEmpty())
|
||||||
{
|
{
|
||||||
deviceCodes = await _devicePermissionAnalyzeService.GetUserPermissionDeviceCodesAsync(gainfo!.No);
|
deviceCodes = await _devicePermissionService.GetUserDeviceCodesByNoOrCodeAsync(gainfo.UserCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
var devices = await _dbContext.Queryable<DeviceEntity>()
|
var devices = await _dbContext.Queryable<DeviceEntity>()
|
||||||
@@ -372,11 +311,11 @@ public class GainfoPermissionService : IGainfoPermissionService
|
|||||||
|
|
||||||
var tasks = devices.Select(x => new DeviceTaskEntity
|
var tasks = devices.Select(x => new DeviceTaskEntity
|
||||||
{
|
{
|
||||||
UserId = gainfo!.Id,
|
UserId = gainfo!.UserId,
|
||||||
|
UserNo = userNo,
|
||||||
DeviceUniqueNo = x.UniqueNo,
|
DeviceUniqueNo = x.UniqueNo,
|
||||||
Status = DeviceTaskStatusEnumType.Wait,
|
Status = DeviceTaskStatusEnumType.Wait,
|
||||||
Version = 0,
|
Version = 0,
|
||||||
UserNo = userNo,
|
|
||||||
Type = type,
|
Type = type,
|
||||||
DeviceType = x.Type,
|
DeviceType = x.Type,
|
||||||
TenantId = x.TenantId,
|
TenantId = x.TenantId,
|
||||||
|
|||||||
@@ -313,7 +313,7 @@ public class GainfoService : IGainfoService
|
|||||||
|
|
||||||
await _dbContext.UpdateAsync(gainfo);
|
await _dbContext.UpdateAsync(gainfo);
|
||||||
|
|
||||||
var deviceCodes = await _devicePermissionService.GetUserDeviceCodesByNoAsync(gainfo.No);
|
var deviceCodes = await _devicePermissionService.GetUserDeviceCodesByNoOrCodeAsync(gainfo.No);
|
||||||
|
|
||||||
var dhDevices = await _dbContext.Queryable<DeviceEntity>().LeftJoin<DeviceTemplateEntity>((x, xt) => x.TemplateCode == xt.Code)
|
var dhDevices = await _dbContext.Queryable<DeviceEntity>().LeftJoin<DeviceTemplateEntity>((x, xt) => x.TemplateCode == xt.Code)
|
||||||
.Where((x, xt) => xt.Name == "大华人脸机")
|
.Where((x, xt) => xt.Name == "大华人脸机")
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- https://go.microsoft.com/fwlink/?LinkID=208121. -->
|
||||||
|
<Project>
|
||||||
|
<PropertyGroup>
|
||||||
|
<DeleteExistingFiles>false</DeleteExistingFiles>
|
||||||
|
<ExcludeApp_Data>false</ExcludeApp_Data>
|
||||||
|
<LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
|
||||||
|
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
|
||||||
|
<LastUsedPlatform>Any CPU</LastUsedPlatform>
|
||||||
|
<PublishProvider>FileSystem</PublishProvider>
|
||||||
|
<PublishUrl>bin\Release\net6.0\publish\</PublishUrl>
|
||||||
|
<WebPublishMethod>FileSystem</WebPublishMethod>
|
||||||
|
<_TargetId>Folder</_TargetId>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
||||||
@@ -15,82 +15,82 @@ namespace Dlhis.Entity.Basic.Entity;
|
|||||||
public class DeviceEntity : SugarBaseEntity, ITenantId
|
public class DeviceEntity : SugarBaseEntity, ITenantId
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设备code
|
/// 设备code
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DeviceCode]
|
[DeviceCode]
|
||||||
[SugarColumn(IsNullable = false, ColumnDescription = "设备code")]
|
[SugarColumn(IsNullable = false, ColumnDescription = "设备code")]
|
||||||
public Guid Code { get; set; }
|
public Guid Code { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设备唯一码,IP/MAC/SNO
|
/// 设备唯一码,IP/MAC/SNO
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[AdaptIgnore(MemberSide.Destination)]
|
[AdaptIgnore(MemberSide.Destination)]
|
||||||
[SugarColumn(IsNullable = false, ColumnDescription = "设备唯一码", UniqueGroupNameList = new[] { "Idx_Device_UniqueNo" })]
|
[SugarColumn(IsNullable = false, ColumnDescription = "设备唯一码", UniqueGroupNameList = new[] { "Idx_Device_UniqueNo" })]
|
||||||
public string UniqueNo { get; set; }
|
public string UniqueNo { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 心跳间隔
|
/// 心跳间隔
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(IsNullable = false, ColumnDescription = "心跳检查间隔")]
|
[SugarColumn(IsNullable = false, ColumnDescription = "心跳检查间隔")]
|
||||||
public int HeartbeatInterval { get; set; } = 30;
|
public int HeartbeatInterval { get; set; } = 30;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 供应商
|
/// 供应商
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(IsNullable = true, ColumnDescription = "供应商")]
|
[SugarColumn(IsNullable = true, ColumnDescription = "供应商")]
|
||||||
public string Supplier { get; set; }
|
public string Supplier { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设备功能
|
/// 设备功能
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(IsNullable = false, ColumnDataType = "varchar(150)", IsJson = true, ColumnDescription = "设备功能", DefaultValue = "[]")]
|
[SugarColumn(IsNullable = false, ColumnDataType = "varchar(150)", IsJson = true, ColumnDescription = "设备功能", DefaultValue = "[]")]
|
||||||
public List<DeviceFuncEnumType> Funcs { get; set; }
|
public List<DeviceFuncEnumType> Funcs { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设备类型
|
/// 设备类型
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(IsNullable = false, ColumnDescription = "设备类型", ColumnDataType = "varchar(50)", SqlParameterDbType = typeof(EnumToStringConvert))]
|
[SugarColumn(IsNullable = false, ColumnDescription = "设备类型", ColumnDataType = "varchar(50)", SqlParameterDbType = typeof(EnumToStringConvert))]
|
||||||
public DeviceTypeEnumType Type { get; set; }
|
public DeviceTypeEnumType Type { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 部署点
|
/// 部署点
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(IsNullable = true, ColumnDescription = "部署点")]
|
[SugarColumn(IsNullable = true, ColumnDescription = "部署点")]
|
||||||
public string DeployPlace { get; set; }
|
public string DeployPlace { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 部署坐标
|
/// 部署坐标
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(IsNullable = true, ColumnDescription = "部署坐标")]
|
[SugarColumn(IsNullable = true, ColumnDescription = "部署坐标")]
|
||||||
public string DeployPosition { get; set; }
|
public string DeployPosition { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 部署方向
|
/// 部署方向
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(IsNullable = true, ColumnDescription = "部署方向", ColumnDataType = "varchar(50)", SqlParameterDbType = typeof(EnumToStringConvert))]
|
[SugarColumn(IsNullable = true, ColumnDescription = "部署方向", ColumnDataType = "varchar(50)", SqlParameterDbType = typeof(EnumToStringConvert))]
|
||||||
public DeviceDeployDirectionEnumType? DeployDirection { get; set; }
|
public DeviceDeployDirectionEnumType? DeployDirection { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 模板code
|
/// 模板code
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(IsNullable = false, ColumnDescription = "模板code")]
|
[SugarColumn(IsNullable = false, ColumnDescription = "模板code")]
|
||||||
public Guid TemplateCode { get; set; }
|
public Guid TemplateCode { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 连接信息
|
/// 连接信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(IsNullable = false, ColumnDescription = "连接信息")]
|
[SugarColumn(IsNullable = false, ColumnDescription = "连接信息")]
|
||||||
public string ConnectionInfo { get; set; }
|
public string ConnectionInfo { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否启用
|
/// 是否启用
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(IsNullable = false, ColumnDataType = "bit", ColumnDescription = "是否启用")]
|
[SugarColumn(IsNullable = false, ColumnDataType = "bit", ColumnDescription = "是否启用")]
|
||||||
public bool Enable { get; set; }
|
public bool Enable { get; set; }
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否作为考勤设备
|
/// 是否作为考勤设备
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(IsNullable = false, ColumnDataType = "bit", ColumnDescription = "是否作为考勤设备")]
|
[SugarColumn(IsNullable = false, ColumnDataType = "bit", ColumnDescription = "是否作为考勤设备")]
|
||||||
public bool AsAttendance { get; set; }
|
public bool AsAttendance { get; set; }
|
||||||
@@ -102,5 +102,11 @@ public class DeviceEntity : SugarBaseEntity, ITenantId
|
|||||||
[SugarColumn(IsNullable = false, ColumnDataType = "bit", ColumnDescription = "是否启用时段码", DefaultValue = "0")]
|
[SugarColumn(IsNullable = false, ColumnDataType = "bit", ColumnDescription = "是否启用时段码", DefaultValue = "0")]
|
||||||
public bool EnableTimePeriod { get; set; } = false;
|
public bool EnableTimePeriod { get; set; } = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否为电梯门禁设备
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(IsNullable = false, ColumnDataType = "bit", ColumnDescription = "是否为电梯门禁设备", DefaultValue = "0")]
|
||||||
|
public bool IsElevatorAcs { get; set; }
|
||||||
|
|
||||||
public string TenantId { get; set; }
|
public string TenantId { get; set; }
|
||||||
}
|
}
|
||||||
37
Src/Dlhis.Entity/Basic/Entity/ElevatorAcsFloorEntity.cs
Normal file
37
Src/Dlhis.Entity/Basic/Entity/ElevatorAcsFloorEntity.cs
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
using Kurisu.AspNetCore.DataAccess.Entity;
|
||||||
|
using Kurisu.AspNetCore.DataAccess.SqlSugar;
|
||||||
|
using SqlSugar;
|
||||||
|
|
||||||
|
namespace Dlhis.Entity.Basic.Entity;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 梯控楼层对照表
|
||||||
|
/// </summary>
|
||||||
|
[SugarTable(TableName = "ElevatorAcsFloors", TableDescription = "梯控楼层对照表")]
|
||||||
|
public class ElevatorAcsFloorEntity : SugarBaseEntity, ITenantId
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 实际设备唯一编号
|
||||||
|
/// </summary>
|
||||||
|
public string RealDeviceUniqueNo { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 虚拟设备唯一编号,用于区分同一设备的不同楼层 <see cref="DeviceEntity.UniqueNo"/>
|
||||||
|
/// </summary>
|
||||||
|
public string VirtualDeviceUniqueNo { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 关联的控制器对应的值(access control system value)
|
||||||
|
/// </summary>
|
||||||
|
public int AcsValue { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 楼层名称
|
||||||
|
/// </summary>
|
||||||
|
public string FloorName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 租户ID
|
||||||
|
/// </summary>
|
||||||
|
public string TenantId { get; set; }
|
||||||
|
}
|
||||||
@@ -8,24 +8,24 @@ namespace Dlhis.Entity.Basic.Entity
|
|||||||
public class GainfoCardRecordEntity : SugarBaseEntity, ITenantId
|
public class GainfoCardRecordEntity : SugarBaseEntity, ITenantId
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 档案No
|
/// 档案No
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(IsNullable = false, IndexGroupNameList = new[] { "idx_GainfoCardRecord_userno" })]
|
[SugarColumn(IsNullable = false, IndexGroupNameList = new[] { "idx_GainfoCardRecord_userno" })]
|
||||||
public string UserNo { get; set; }
|
public string UserNo { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 卡号
|
/// 卡号
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(IsNullable = false)]
|
[SugarColumn(IsNullable = false)]
|
||||||
public string CardNo { get; set; }
|
public string CardNo { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 更换原因
|
/// 更换原因
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Reason { get; set; }
|
public string Reason { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 备注
|
/// 备注
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Remark { get; set; }
|
public string Remark { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -25,5 +25,6 @@ public class GainfoFingerprintEntity : SugarBaseEntity
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 指纹数据
|
/// 指纹数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[SugarColumn(ColumnDataType = "text")]
|
||||||
public string Fingerprint { get; set; }
|
public string Fingerprint { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ using Dlhis.ScheduledTask.Attributes;
|
|||||||
namespace Dlhis.ScheduledTask.Jobs;
|
namespace Dlhis.ScheduledTask.Jobs;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 自动处理外包离职
|
/// 自动处理访客离场
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[RecurringJob(nameof(ExternalAutoResignJob), "0 0 1 1/1 * ? ", Name = "自动处理外部人员离职")]
|
[RecurringJob(nameof(ExternalAutoResignJob), "0 0 1 1/1 * ? ", Name = "自动处理访客离场")]
|
||||||
public class ExternalAutoResignJob : BaseJob
|
public class ExternalAutoResignJob : BaseJob
|
||||||
{
|
{
|
||||||
private readonly ISyncApi _syncApi;
|
private readonly ISyncApi _syncApi;
|
||||||
|
|||||||
@@ -51,6 +51,32 @@ public class AssignmentsController : ControllerBase
|
|||||||
return await _assignmentService.DeviceGetTasksAsync(request);
|
return await _assignmentService.DeviceGetTasksAsync(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取设备任务关联人员
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[DisableApiLog]
|
||||||
|
[IgnoreTenant]
|
||||||
|
[AllowAnonymous]
|
||||||
|
[HttpGet("elevatorAcs/users")]
|
||||||
|
public async Task<List<string>> ElevatorAcsDeviceGetTasksGetAsync(string deviceUniqueNo)
|
||||||
|
{
|
||||||
|
return await _assignmentService.ElevatorAcsDeviceGetTasksGetAsync(deviceUniqueNo);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取设备任务
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[DisableApiLog]
|
||||||
|
[IgnoreTenant]
|
||||||
|
[HttpGet("elevatorAcs/users/deviceTasks")]
|
||||||
|
public async Task<ElevatorAcsDeviceTaskToDeviceByDeviceResponse> ElevatorAcsDeviceGetTasksGetAsync(string deviceUniqueNo, string userCode)
|
||||||
|
{
|
||||||
|
return await _assignmentService.GetElevatorAcsTaskAsync(deviceUniqueNo, userCode);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取设备任务(按设备)
|
/// 获取设备任务(按设备)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -71,6 +97,7 @@ public class AssignmentsController : ControllerBase
|
|||||||
[DisableApiLog]
|
[DisableApiLog]
|
||||||
[HttpPost("taskStatus")]
|
[HttpPost("taskStatus")]
|
||||||
[IgnoreTenant]
|
[IgnoreTenant]
|
||||||
|
[Transactional]
|
||||||
public async Task UpdateDeviceTaskStatusAsync(List<UpdateDeviceTaskStatusRequest> requests)
|
public async Task UpdateDeviceTaskStatusAsync(List<UpdateDeviceTaskStatusRequest> requests)
|
||||||
{
|
{
|
||||||
await _assignmentService.UpdateDeviceTaskStatusAsync(requests);
|
await _assignmentService.UpdateDeviceTaskStatusAsync(requests);
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace Dlhis.ScheduledTask.TaskAssignment.Dto
|
||||||
|
{
|
||||||
|
public class ElevatorTaskDto : TaskDto
|
||||||
|
{
|
||||||
|
public int FloorAcsValue { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
namespace Dlhis.ScheduledTask.TaskAssignment.Response;
|
||||||
|
|
||||||
|
public class ElevatorAcsDeviceTaskToDeviceByDeviceResponse
|
||||||
|
{
|
||||||
|
public string DeviceUniqueNo { get; set; }
|
||||||
|
|
||||||
|
public long? UserId { get; set; }
|
||||||
|
public string UserCode { get; set; }
|
||||||
|
public string UserName { get; set; }
|
||||||
|
|
||||||
|
public string CardNo { get; set; }
|
||||||
|
|
||||||
|
public List<long> TaskIds { get; set; }
|
||||||
|
|
||||||
|
public List<int> FloorAcsValues { get; set; }
|
||||||
|
}
|
||||||
@@ -12,6 +12,10 @@ public interface IAssignmentService : IScopeDependency
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<List<DeviceTaskToDeviceByDeviceResponse>> DeviceGetTasksAsync(DeviceTaskGetRequest request);
|
Task<List<DeviceTaskToDeviceByDeviceResponse>> DeviceGetTasksAsync(DeviceTaskGetRequest request);
|
||||||
|
|
||||||
|
|
||||||
|
Task<List<string>> ElevatorAcsDeviceGetTasksGetAsync(string userCode);
|
||||||
|
Task<ElevatorAcsDeviceTaskToDeviceByDeviceResponse> GetElevatorAcsTaskAsync(string deviceUniqueNo, string userCode);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 更新设备任务状态
|
/// 更新设备任务状态
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,19 +1,20 @@
|
|||||||
using Dlhis.Entity.Basic.Entity;
|
using Dlhis.Basic.Api;
|
||||||
|
using Dlhis.Entity.Basic.Entity;
|
||||||
using Dlhis.Entity.Device.Entities;
|
using Dlhis.Entity.Device.Entities;
|
||||||
using Dlhis.Entity.Device.Enums;
|
using Dlhis.Entity.Device.Enums;
|
||||||
using Dlhis.Entity.Device.Models;
|
using Dlhis.Entity.Device.Models;
|
||||||
|
using Dlhis.ScheduledTask.TaskAssignment.Dto;
|
||||||
using Dlhis.ScheduledTask.TaskAssignment.Request;
|
using Dlhis.ScheduledTask.TaskAssignment.Request;
|
||||||
using Dlhis.ScheduledTask.TaskAssignment.Response;
|
using Dlhis.ScheduledTask.TaskAssignment.Response;
|
||||||
using Kurisu.AspNetCore.Utils.Extensions;
|
|
||||||
using Microsoft.AspNetCore.DataProtection;
|
|
||||||
using Microsoft.Extensions.Options;
|
|
||||||
using SqlSugar;
|
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
using Kurisu.AspNetCore.Utils;
|
|
||||||
using Dlhis.ScheduledTask.TaskAssignment.Dto;
|
|
||||||
using Kurisu.AspNetCore.CustomClass;
|
using Kurisu.AspNetCore.CustomClass;
|
||||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||||
|
using Kurisu.AspNetCore.Utils;
|
||||||
|
using Kurisu.AspNetCore.Utils.Extensions;
|
||||||
|
using Microsoft.AspNetCore.DataProtection;
|
||||||
using Microsoft.Extensions.Caching.Memory;
|
using Microsoft.Extensions.Caching.Memory;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using SqlSugar;
|
||||||
|
|
||||||
namespace Dlhis.ScheduledTask.TaskAssignment.Services.Implements;
|
namespace Dlhis.ScheduledTask.TaskAssignment.Services.Implements;
|
||||||
|
|
||||||
@@ -22,6 +23,7 @@ public class AssignmentService : IAssignmentService
|
|||||||
private readonly IDbContext _dbContext;
|
private readonly IDbContext _dbContext;
|
||||||
private readonly IDataProtectionProvider _dataProtectionProvider;
|
private readonly IDataProtectionProvider _dataProtectionProvider;
|
||||||
private readonly IMemoryCache _memoryCache;
|
private readonly IMemoryCache _memoryCache;
|
||||||
|
private readonly IGainfoPermissionApi _gainfoPermissionApi;
|
||||||
private readonly ILogger<AssignmentService> _logger;
|
private readonly ILogger<AssignmentService> _logger;
|
||||||
private readonly FaceUrlOptions _faceUrlOptions;
|
private readonly FaceUrlOptions _faceUrlOptions;
|
||||||
|
|
||||||
@@ -29,11 +31,13 @@ public class AssignmentService : IAssignmentService
|
|||||||
IDataProtectionProvider dataProtectionProvider,
|
IDataProtectionProvider dataProtectionProvider,
|
||||||
IOptions<FaceUrlOptions> options,
|
IOptions<FaceUrlOptions> options,
|
||||||
IMemoryCache memoryCache,
|
IMemoryCache memoryCache,
|
||||||
|
IGainfoPermissionApi gainfoPermissionApi,
|
||||||
ILogger<AssignmentService> logger)
|
ILogger<AssignmentService> logger)
|
||||||
{
|
{
|
||||||
_dbContext = dbContext;
|
_dbContext = dbContext;
|
||||||
_dataProtectionProvider = dataProtectionProvider;
|
_dataProtectionProvider = dataProtectionProvider;
|
||||||
_memoryCache = memoryCache;
|
_memoryCache = memoryCache;
|
||||||
|
_gainfoPermissionApi = gainfoPermissionApi;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_faceUrlOptions = options.Value;
|
_faceUrlOptions = options.Value;
|
||||||
}
|
}
|
||||||
@@ -85,60 +89,60 @@ public class AssignmentService : IAssignmentService
|
|||||||
case DeviceTaskEnumType.Add:
|
case DeviceTaskEnumType.Add:
|
||||||
case DeviceTaskEnumType.Delete:
|
case DeviceTaskEnumType.Delete:
|
||||||
case DeviceTaskEnumType.Update:
|
case DeviceTaskEnumType.Update:
|
||||||
{
|
|
||||||
dto.Info = new UserToDeviceResponse
|
|
||||||
{
|
{
|
||||||
UserId = item.UserId ?? 0,
|
dto.Info = new UserToDeviceResponse
|
||||||
UserNo = item.UserNo,
|
|
||||||
OldUserNo = item.OldUserNo,
|
|
||||||
UserCode = item.UserCode,
|
|
||||||
UserType = item.UserType,
|
|
||||||
UserName = item.UserName,
|
|
||||||
DepartmentNo = item.DepartmentNo,
|
|
||||||
DepartmentName = item.DepartmentName,
|
|
||||||
CardNo = item.CardNo,
|
|
||||||
Face = item.Type == DeviceTaskEnumType.Delete ? string.Empty : _faceUrlOptions.Url + token, //下发才附带照片信息
|
|
||||||
ValidDatePeriod = new DatePeriod
|
|
||||||
{
|
{
|
||||||
Start = DateOnly.FromDateTime(DateTime.Now.AddDays(-1)),
|
UserId = item.UserId ?? 0,
|
||||||
End = DateOnly.FromDateTime(DateTime.Now.AddYears(20)),
|
UserNo = item.UserNo,
|
||||||
},
|
OldUserNo = item.OldUserNo,
|
||||||
TimePeriods = new List<int> { item.CardType },
|
UserCode = item.UserCode,
|
||||||
Doors = new List<int> { 1 },
|
UserType = item.UserType,
|
||||||
Schedule = 1
|
UserName = item.UserName,
|
||||||
};
|
DepartmentNo = item.DepartmentNo,
|
||||||
}
|
DepartmentName = item.DepartmentName,
|
||||||
|
CardNo = item.CardNo,
|
||||||
|
Face = item.Type == DeviceTaskEnumType.Delete ? string.Empty : _faceUrlOptions.Url + token, //下发才附带照片信息
|
||||||
|
ValidDatePeriod = new DatePeriod
|
||||||
|
{
|
||||||
|
Start = DateOnly.FromDateTime(DateTime.Now.AddDays(-1)),
|
||||||
|
End = DateOnly.FromDateTime(DateTime.Now.AddYears(20)),
|
||||||
|
},
|
||||||
|
TimePeriods = new List<int> { item.CardType },
|
||||||
|
Doors = new List<int> { 1 },
|
||||||
|
Schedule = 1
|
||||||
|
};
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case DeviceTaskEnumType.TimePeriodAdd:
|
case DeviceTaskEnumType.TimePeriodAdd:
|
||||||
case DeviceTaskEnumType.TimePeriodDelete:
|
case DeviceTaskEnumType.TimePeriodDelete:
|
||||||
{
|
|
||||||
dto.Info = item.TimePeriods.Select(t => new TimePeriodToDeviceResponse
|
|
||||||
{
|
{
|
||||||
Id = t.CardType,
|
dto.Info = item.TimePeriods.Select(t => new TimePeriodToDeviceResponse
|
||||||
Name = t.CardName,
|
|
||||||
Enable = item.EnableTimePeriod,
|
|
||||||
Sections = t.Sections.Select(s => new TimePeriodWeekDaySection
|
|
||||||
{
|
{
|
||||||
DayOfWeek = s.DayOfWeek,
|
Id = t.CardType,
|
||||||
TimePeriods = s.TimePeriods.Select(p => new DeviceTimePeriod
|
Name = t.CardName,
|
||||||
|
Enable = item.EnableTimePeriod,
|
||||||
|
Sections = t.Sections.Select(s => new TimePeriodWeekDaySection
|
||||||
{
|
{
|
||||||
Enable = p.Enable,
|
DayOfWeek = s.DayOfWeek,
|
||||||
Start = p.Enable ? p.Start : new TimeOnly(00, 00, 00),
|
TimePeriods = s.TimePeriods.Select(p => new DeviceTimePeriod
|
||||||
End = p.Enable ? p.End : new TimeOnly(00, 00, 00)
|
{
|
||||||
|
Enable = p.Enable,
|
||||||
|
Start = p.Enable ? p.Start : new TimeOnly(00, 00, 00),
|
||||||
|
End = p.Enable ? p.End : new TimeOnly(00, 00, 00)
|
||||||
|
}).ToList()
|
||||||
}).ToList()
|
}).ToList()
|
||||||
}).ToList()
|
});
|
||||||
});
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case DeviceTaskEnumType.ScheduleAdd:
|
case DeviceTaskEnumType.ScheduleAdd:
|
||||||
case DeviceTaskEnumType.ScheduleDelete:
|
case DeviceTaskEnumType.ScheduleDelete:
|
||||||
{
|
|
||||||
dto.Info = new ScheduleToDeviceResponse
|
|
||||||
{
|
{
|
||||||
Id = 1,
|
dto.Info = new ScheduleToDeviceResponse
|
||||||
Enable = true,
|
{
|
||||||
Name = "计划的一部分",
|
Id = 1,
|
||||||
Schedules = new List<ScheduleDto>
|
Enable = true,
|
||||||
|
Name = "计划的一部分",
|
||||||
|
Schedules = new List<ScheduleDto>
|
||||||
{
|
{
|
||||||
new()
|
new()
|
||||||
{
|
{
|
||||||
@@ -150,22 +154,22 @@ public class AssignmentService : IAssignmentService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DeviceTaskEnumType.UploadRecord:
|
case DeviceTaskEnumType.UploadRecord:
|
||||||
{
|
|
||||||
var timeInfo = deviceUploadInfos[d];
|
|
||||||
dto.Info = new UploadRecordToDeviceResponse
|
|
||||||
{
|
{
|
||||||
DateTimePeriod = new DateTimePeriod
|
var timeInfo = deviceUploadInfos[d];
|
||||||
|
dto.Info = new UploadRecordToDeviceResponse
|
||||||
{
|
{
|
||||||
Start = timeInfo.Item1,
|
DateTimePeriod = new DateTimePeriod
|
||||||
End = timeInfo.Item2
|
{
|
||||||
}
|
Start = timeInfo.Item1,
|
||||||
};
|
End = timeInfo.Item2
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,6 +179,109 @@ public class AssignmentService : IAssignmentService
|
|||||||
}).ToList();
|
}).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<List<string>> ElevatorAcsDeviceGetTasksGetAsync(string deviceUniqueNo)
|
||||||
|
{
|
||||||
|
//梯控
|
||||||
|
var elevatorAcsFloors = await _dbContext.Queryable<ElevatorAcsFloorEntity>().Where(x => x.RealDeviceUniqueNo == deviceUniqueNo).ToListAsync();
|
||||||
|
if (elevatorAcsFloors.IsPresent())
|
||||||
|
{
|
||||||
|
var virtualDeviceUniqueNos = elevatorAcsFloors.Select(x => x.VirtualDeviceUniqueNo).ToList();
|
||||||
|
|
||||||
|
var allUserNos = new List<string>();
|
||||||
|
foreach (var virtualDeviceUniqueNo in virtualDeviceUniqueNos)
|
||||||
|
{
|
||||||
|
var userNos = await _dbContext.Queryable<DeviceTaskEntity>().Where(x => x.DeviceUniqueNo == virtualDeviceUniqueNo)
|
||||||
|
.Where(x => (x.Status == DeviceTaskStatusEnumType.Wait || x.Status == DeviceTaskStatusEnumType.Process) && !string.IsNullOrEmpty(x.UserNo))
|
||||||
|
.OrderBy(x => new { x.Id, Priority = SqlFunc.Desc(x.Priority) })
|
||||||
|
.Select(x => x.UserNo)
|
||||||
|
.ToListAsync();
|
||||||
|
allUserNos.AddRange(userNos);
|
||||||
|
}
|
||||||
|
allUserNos = allUserNos.Distinct().ToList();
|
||||||
|
if (allUserNos.IsEmpty())
|
||||||
|
{
|
||||||
|
return new List<string>();
|
||||||
|
}
|
||||||
|
var userCodes = await _dbContext.Queryable<GainfoEntity>().Where(x => allUserNos.Contains(x.No)).Select(x => x.Code).ToListAsync();
|
||||||
|
var leaveUserCodes = await _dbContext.Queryable<GainfoLeaveEntity>().Where(x => allUserNos.Contains(x.No)).Select(x => x.Code).ToListAsync();
|
||||||
|
return userCodes.Concat(leaveUserCodes).Distinct().ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new List<string>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<ElevatorAcsDeviceTaskToDeviceByDeviceResponse> GetElevatorAcsTaskAsync(string deviceUniqueNo, string userCode)
|
||||||
|
{
|
||||||
|
var elevatorAcsFloors = await _dbContext.Queryable<ElevatorAcsFloorEntity>().Where(x => x.RealDeviceUniqueNo == deviceUniqueNo).ToListAsync();
|
||||||
|
var virtualDeviceUniqueNos = elevatorAcsFloors.Select(x => x.VirtualDeviceUniqueNo).ToList();
|
||||||
|
|
||||||
|
var deviceCodes = await _gainfoPermissionApi.GetPermissionsDeviceCodesAsync(userCode);
|
||||||
|
var floorAcsValues = await _dbContext.Queryable<DeviceEntity>()
|
||||||
|
.LeftJoin<ElevatorAcsFloorEntity>((x, f) => x.UniqueNo == f.VirtualDeviceUniqueNo)
|
||||||
|
.Where(x => virtualDeviceUniqueNos.Contains(x.UniqueNo) && deviceCodes.Contains(x.Code))
|
||||||
|
.Select((x, f) => f.AcsValue)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
|
||||||
|
var all = await CommonHelper.RetryAsync(async () =>
|
||||||
|
{
|
||||||
|
var internalAll = new List<long>();
|
||||||
|
|
||||||
|
foreach (var virtualDeviceUniqueNo in virtualDeviceUniqueNos)
|
||||||
|
{
|
||||||
|
var taskIds = await _dbContext.Queryable<DeviceTaskEntity>()
|
||||||
|
.LeftJoin<DeviceEntity>((deviceTask, device) => deviceTask.DeviceUniqueNo == device.UniqueNo)
|
||||||
|
.Where((deviceTask, device) => deviceTask.DeviceUniqueNo == virtualDeviceUniqueNo)
|
||||||
|
.Where((deviceTask, device) => device.Enable)
|
||||||
|
.Where(deviceTask => (deviceTask.Status == DeviceTaskStatusEnumType.Wait || deviceTask.Status == DeviceTaskStatusEnumType.Process) && !string.IsNullOrEmpty(deviceTask.UserNo))
|
||||||
|
.OrderBy(deviceTask => new { deviceTask.Id, Priority = SqlFunc.Desc(deviceTask.Priority) })
|
||||||
|
.Select((deviceTask, device) => deviceTask.Id)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
internalAll.AddRange(taskIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
var effect = await _dbContext.Updateable<DeviceTaskEntity>()
|
||||||
|
.SetColumns(x => x.Status == DeviceTaskStatusEnumType.Process)
|
||||||
|
.SetColumns(x => x.ModifiedTime == DateTime.Now)
|
||||||
|
.Where(x => internalAll.Contains(x.Id) && (x.Status == DeviceTaskStatusEnumType.Wait || x.Status == DeviceTaskStatusEnumType.Process))
|
||||||
|
.ExecuteCommandAsync();
|
||||||
|
|
||||||
|
if (effect != internalAll.Count)
|
||||||
|
{
|
||||||
|
throw new VersionExceptions("version exceptions");
|
||||||
|
}
|
||||||
|
|
||||||
|
return internalAll;
|
||||||
|
|
||||||
|
}, 5);
|
||||||
|
|
||||||
|
if (!all.Any())
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var userInfo = await _dbContext.Queryable<GainfoEntity>()
|
||||||
|
.Where(x => x.Code == userCode)
|
||||||
|
.Select(x => new { UserId = x.Id, UserCode = x.Code, UserName = x.Name, x.CardNo })
|
||||||
|
.FirstAsync()
|
||||||
|
??
|
||||||
|
await _dbContext.Queryable<GainfoLeaveEntity>()
|
||||||
|
.Where(x => x.Code == userCode)
|
||||||
|
.Select(x => new { UserId = x.Id, UserCode = x.Code, UserName = x.Name, x.CardNo })
|
||||||
|
.FirstAsync();
|
||||||
|
|
||||||
|
return new ElevatorAcsDeviceTaskToDeviceByDeviceResponse
|
||||||
|
{
|
||||||
|
DeviceUniqueNo = deviceUniqueNo,
|
||||||
|
UserId = userInfo.UserId,
|
||||||
|
UserCode = userInfo.UserCode,
|
||||||
|
CardNo = userInfo.CardNo,
|
||||||
|
UserName = userInfo.UserName,
|
||||||
|
FloorAcsValues = floorAcsValues,
|
||||||
|
TaskIds = all
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public async Task UpdateDeviceTaskStatusAsync(List<UpdateDeviceTaskStatusRequest> requests)
|
public async Task UpdateDeviceTaskStatusAsync(List<UpdateDeviceTaskStatusRequest> requests)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user