feat 梯控相关

This commit is contained in:
2026-03-13 15:42:36 +08:00
parent 9d0600ebb8
commit f1cb0813db
34 changed files with 1112 additions and 320 deletions

View File

@@ -4,9 +4,9 @@ using Dlhis.ScheduledTask.Attributes;
namespace Dlhis.ScheduledTask.Jobs;
/// <summary>
/// 自动处理外包离职
/// 自动处理访客离场
/// </summary>
[RecurringJob(nameof(ExternalAutoResignJob), "0 0 1 1/1 * ? ", Name = "自动处理外部人员离职")]
[RecurringJob(nameof(ExternalAutoResignJob), "0 0 1 1/1 * ? ", Name = "自动处理访客离场")]
public class ExternalAutoResignJob : BaseJob
{
private readonly ISyncApi _syncApi;

View File

@@ -51,6 +51,32 @@ public class AssignmentsController : ControllerBase
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>
@@ -71,6 +97,7 @@ public class AssignmentsController : ControllerBase
[DisableApiLog]
[HttpPost("taskStatus")]
[IgnoreTenant]
[Transactional]
public async Task UpdateDeviceTaskStatusAsync(List<UpdateDeviceTaskStatusRequest> requests)
{
await _assignmentService.UpdateDeviceTaskStatusAsync(requests);
@@ -262,9 +289,9 @@ public class AssignmentsController : ControllerBase
{
x.OpeningBalance = Math.Abs(x.OpeningBalance);
x.CostAmount = Math.Abs(x.CostAmount);
x.ClosingAmount = Math.Abs(x.ClosingAmount);
x.ClosingAmount = Math.Abs(x.ClosingAmount);
});
return page;
}
@@ -293,12 +320,12 @@ public class AssignmentsController : ControllerBase
catch (Exception)
{
}
page.Data.ForEach(x =>
{
x.OpeningBalance = Math.Abs(x.OpeningBalance);
x.CostAmount = Math.Abs(x.CostAmount);
x.ClosingAmount = Math.Abs(x.ClosingAmount);
x.ClosingAmount = Math.Abs(x.ClosingAmount);
});
return page;

View File

@@ -0,0 +1,7 @@
namespace Dlhis.ScheduledTask.TaskAssignment.Dto
{
public class ElevatorTaskDto : TaskDto
{
public int FloorAcsValue { get; set; }
}
}

View File

@@ -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; }
}

View File

@@ -12,6 +12,10 @@ public interface IAssignmentService : IScopeDependency
/// <returns></returns>
Task<List<DeviceTaskToDeviceByDeviceResponse>> DeviceGetTasksAsync(DeviceTaskGetRequest request);
Task<List<string>> ElevatorAcsDeviceGetTasksGetAsync(string userCode);
Task<ElevatorAcsDeviceTaskToDeviceByDeviceResponse> GetElevatorAcsTaskAsync(string deviceUniqueNo, string userCode);
/// <summary>
/// 更新设备任务状态
/// </summary>

View File

@@ -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.Enums;
using Dlhis.Entity.Device.Models;
using Dlhis.ScheduledTask.TaskAssignment.Dto;
using Dlhis.ScheduledTask.TaskAssignment.Request;
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.DataAccess.SqlSugar.Services;
using Kurisu.AspNetCore.Utils;
using Kurisu.AspNetCore.Utils.Extensions;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Options;
using Newtonsoft.Json.Linq;
using SqlSugar;
namespace Dlhis.ScheduledTask.TaskAssignment.Services.Implements;
@@ -22,6 +23,7 @@ public class AssignmentService : IAssignmentService
private readonly IDbContext _dbContext;
private readonly IDataProtectionProvider _dataProtectionProvider;
private readonly IMemoryCache _memoryCache;
private readonly IGainfoPermissionApi _gainfoPermissionApi;
private readonly ILogger<AssignmentService> _logger;
private readonly FaceUrlOptions _faceUrlOptions;
@@ -29,11 +31,13 @@ public class AssignmentService : IAssignmentService
IDataProtectionProvider dataProtectionProvider,
IOptions<FaceUrlOptions> options,
IMemoryCache memoryCache,
IGainfoPermissionApi gainfoPermissionApi,
ILogger<AssignmentService> logger)
{
_dbContext = dbContext;
_dataProtectionProvider = dataProtectionProvider;
_memoryCache = memoryCache;
_gainfoPermissionApi = gainfoPermissionApi;
_logger = logger;
_faceUrlOptions = options.Value;
}
@@ -85,60 +89,60 @@ public class AssignmentService : IAssignmentService
case DeviceTaskEnumType.Add:
case DeviceTaskEnumType.Delete:
case DeviceTaskEnumType.Update:
{
dto.Info = new UserToDeviceResponse
{
UserId = item.UserId ?? 0,
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
dto.Info = new UserToDeviceResponse
{
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
};
}
UserId = item.UserId ?? 0,
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)),
End = DateOnly.FromDateTime(DateTime.Now.AddYears(20)),
},
TimePeriods = new List<int> { item.CardType },
Doors = new List<int> { 1 },
Schedule = 1
};
}
break;
case DeviceTaskEnumType.TimePeriodAdd:
case DeviceTaskEnumType.TimePeriodDelete:
{
dto.Info = item.TimePeriods.Select(t => new TimePeriodToDeviceResponse
{
Id = t.CardType,
Name = t.CardName,
Enable = item.EnableTimePeriod,
Sections = t.Sections.Select(s => new TimePeriodWeekDaySection
dto.Info = item.TimePeriods.Select(t => new TimePeriodToDeviceResponse
{
DayOfWeek = s.DayOfWeek,
TimePeriods = s.TimePeriods.Select(p => new DeviceTimePeriod
Id = t.CardType,
Name = t.CardName,
Enable = item.EnableTimePeriod,
Sections = t.Sections.Select(s => new TimePeriodWeekDaySection
{
Enable = p.Enable,
Start = p.Enable ? p.Start : new TimeOnly(00, 00, 00),
End = p.Enable ? p.End : new TimeOnly(00, 00, 00)
DayOfWeek = s.DayOfWeek,
TimePeriods = s.TimePeriods.Select(p => new DeviceTimePeriod
{
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()
});
}
});
}
break;
case DeviceTaskEnumType.ScheduleAdd:
case DeviceTaskEnumType.ScheduleDelete:
{
dto.Info = new ScheduleToDeviceResponse
{
Id = 1,
Enable = true,
Name = "计划的一部分",
Schedules = new List<ScheduleDto>
dto.Info = new ScheduleToDeviceResponse
{
Id = 1,
Enable = true,
Name = "计划的一部分",
Schedules = new List<ScheduleDto>
{
new()
{
@@ -150,22 +154,22 @@ public class AssignmentService : IAssignmentService
}
}
}
};
}
};
}
break;
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,
End = timeInfo.Item2
}
};
}
DateTimePeriod = new DateTimePeriod
{
Start = timeInfo.Item1,
End = timeInfo.Item2
}
};
}
break;
}
@@ -175,6 +179,109 @@ public class AssignmentService : IAssignmentService
}).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)
{