feat 梯控相关
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user