fix 修复已知问题

This commit is contained in:
2025-06-11 17:03:07 +08:00
parent 9b93eef87d
commit 74667f7d39
11 changed files with 62 additions and 135 deletions

View File

@@ -185,6 +185,7 @@ public class AppointmentService : IAppointmentService
var detail = await _dbContext.Queryable<VisitorAppointmentDetailEntity>().Where(x => x.Id == id).SingleAsync();
detail.ThrowIfNull("数据不存在");
//Wait->obsolete; Arrived->FocusLeave
if (detail.IsEnterDoorArea && detail.DoorStatus == VisitorAppointmentDetailStatusEnumType.Arrived)
detail.DoorStatus = VisitorAppointmentDetailStatusEnumType.FocusLeave;
@@ -198,9 +199,10 @@ public class AppointmentService : IAppointmentService
detail.WorkplaceStatus = VisitorAppointmentDetailStatusEnumType.Obsolete;
detail.FocusLeaveDateTime = DateTime.Now;
detail.Remark += "强制离场原因:" + reason;
detail.Remark += "强制离场:" + reason;
await GenerateDeviceTasksAsync(detail, true, DeviceTaskEnumType.Delete, "访客手动强制离场");
await GenerateDeviceTasksAsync(detail, true, DeviceTaskEnumType.Delete, $"强制离场:{reason}");
await _dbContext.UpdateAsync(detail);
}
public async Task<Pagination<AppointmentDetailResponse>> GetRecordPageByIdNoAsync(AppointmentIdNoPageRequest request)
@@ -345,7 +347,8 @@ public class AppointmentService : IAppointmentService
/// <inheritdoc />
public async Task AutoResignAsync()
{
var outsources = await _dbContext.Queryable<GainfoEntity>()
//获取外部人员
var externals = await _dbContext.Queryable<GainfoEntity>()
.Where(x => x.Type == GainfoUserTypeEnumType.External)
.Select(x => new { x.Id, x.Code, x.Factory, x.CreateTime })
.ToListAsync();
@@ -357,23 +360,25 @@ public class AppointmentService : IAppointmentService
//todo 临时处理循环依赖
var gainfoService = _serviceProvider.GetService<IGainfoService>();
foreach (var grp in outsources.GroupBy(x => x.Factory))
//人员分组,key为factory
foreach (var grp in externals.GroupBy(x => x.Factory))
{
//factory的设置
var setting = settings.First(x => x.Factory == grp.Key);
if (setting.NoRecordAutoResignExternalDays == 0)
{
continue;
}
foreach (var outsource in grp)
foreach (var ext in grp)
{
var raiseDateTime = await _dbContext.Queryable<DeviceUploadLogEntity>()
.Where(x => x.UserUniqueNo == outsource.Code)
.Where(x => x.UserUniqueNo == ext.Code)
.GroupBy(x => x.UserUniqueNo)
.Select(x => SqlFunc.IsNull(SqlFunc.AggregateMax(x.RaiseDateTime), outsource.CreateTime))
.Select(x => SqlFunc.IsNull(SqlFunc.AggregateMax(x.RaiseDateTime), ext.CreateTime))
.SingleAsync();
raiseDateTime = raiseDateTime == nullDateTime ? outsource.CreateTime : raiseDateTime;
raiseDateTime = raiseDateTime == nullDateTime ? ext.CreateTime : raiseDateTime;
if (raiseDateTime.AddDays(setting.NoRecordAutoResignExternalDays) < DateTime.Now)
{
@@ -381,10 +386,9 @@ public class AppointmentService : IAppointmentService
{
await gainfoService.ResignAsync(new GainfoResignRequest
{
Id = outsource.Id,
Id = ext.Id,
Reason = $"{setting.NoRecordAutoResignExternalDays}天无通行记录",
Date = DateTime.Now,
IsOutsource = true
Date = DateTime.Now
});
}
catch (Exception e)
@@ -432,6 +436,12 @@ public class AppointmentService : IAppointmentService
}).ToList());
}
/// <summary>
/// 获取有效的区域编码
/// </summary>
/// <param name="detail"></param>
/// <param name="withWorkplace"></param>
/// <returns></returns>
private static IEnumerable<string> GetValidAreaCodes(VisitorAppointmentDetailEntity detail, bool withWorkplace)
{
if (detail.IsEnterDoorArea)

View File

@@ -1,13 +1,8 @@
using Dlhis.Basic.Device.Request;
using Dlhis.Basic.Device.Response;
using Dlhis.Basic.Device.Services;
using Dlhis.Entity.Basic.Entity;
using Dlhis.Entity.Basic.Enums;
using Dlhis.Entity.Device.Entities;
using Dlhis.Entity.Device.Enums;
using Kurisu.AspNetCore.DataAccess.Dto;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
using Kurisu.AspNetCore.UnifyResultAndValidation.Aop;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
@@ -24,18 +19,15 @@ public class DevicesController : ControllerBase
{
private readonly IDeviceService _deviceService;
private readonly IDeviceTemplateService _deviceTemplateService;
private readonly IDbContext _dbContext;
private readonly IDeviceConnectService _deviceConnectService;
private readonly IConfiguration _configuration;
public DevicesController(IDeviceService deviceService,
IDeviceTemplateService deviceTemplateService,
IDbContext dbContext,
IDeviceConnectService deviceConnectService, IConfiguration configuration)
{
_deviceService = deviceService;
_deviceTemplateService = deviceTemplateService;
_dbContext = dbContext;
_deviceConnectService = deviceConnectService;
_configuration = configuration;
}
@@ -170,70 +162,4 @@ public class DevicesController : ControllerBase
{
await _deviceService.ImportAsync(request);
}
[HttpPost("test")]
[IgnoreTenant]
[AllowAnonymous]
public async Task<int> Test()
{
var tasks = new List<DeviceTaskEntity>();
var devices = await _dbContext.Queryable<DeviceEntity>().Where(x => x.TenantId == "2401").Where(x => x.Type == DeviceTypeEnumType.Meal).ToListAsync();
var gainfos = await _dbContext.Queryable<GainfoEntity>()
.Where(x => x.Type == GainfoUserTypeEnumType.External || x.Type == GainfoUserTypeEnumType.Outsource)
.Where(x => x.Factory == "2401")
.ToListAsync();
var gainfoLeaves = await _dbContext.Queryable<GainfoLeaveEntity>()
.Where(x => x.Type == GainfoUserTypeEnumType.External || x.Type == GainfoUserTypeEnumType.Outsource)
.Where(x => x.Factory == "2401")
.ToListAsync();
foreach (var device in devices)
{
foreach (var gainfo in gainfos)
{
tasks.Add(new DeviceTaskEntity
{
Type = DeviceTaskEnumType.Delete,
DeviceType = DeviceTypeEnumType.Meal,
UserId = gainfo.Id,
UserNo = gainfo.No,
DeviceUniqueNo = device.UniqueNo,
Status = DeviceTaskStatusEnumType.Wait,
Version = 0,
ResultMessage = null,
Source = "主动删除2401异常餐饮人员",
Priority = 0,
TenantId = device.TenantId
});
}
foreach (var gainfo in gainfoLeaves)
{
tasks.Add(new DeviceTaskEntity
{
Type = DeviceTaskEnumType.Delete,
DeviceType = DeviceTypeEnumType.Meal,
UserId = gainfo.IdentityUserId,
UserNo = gainfo.No,
DeviceUniqueNo = device.UniqueNo,
Status = DeviceTaskStatusEnumType.Wait,
Version = 0,
ResultMessage = null,
Source = "主动删除2401异常餐饮人员",
Priority = 0,
TenantId = device.TenantId
});
}
}
foreach (var items in tasks.Chunk(1000))
{
await _dbContext.InsertAsync(items);
}
return tasks.Count;
}
}

View File

@@ -43,7 +43,7 @@ public interface IDevicePermissionAnalyzeService : IScopeDependency
/// 获取人员权限(人员--(厂区--分配方式--设备codes))
/// </summary>
/// <param name="userNos"></param>
/// <param name="ignoreUniqueType"></param>
/// <param name="ignoreUniqueType">忽略设备/设备组;</param>
/// <param name="ignoreAssignValue"></param>
/// <param name="ignoreAssignType"></param>
/// <returns></returns>

View File

@@ -168,8 +168,12 @@ public class DevicePermissionAnalyzeService : IDevicePermissionAnalyzeService
var deviceDtos = new List<TenantAssignTypeDeviceCode>();
var uniqueTypes = new[] { DeviceAssignmentTypeEnumType.Device, DeviceAssignmentTypeEnumType.Group };
//根据权限分配类型
foreach (var assignType in new[] { AssignTypeEnumType.User, AssignTypeEnumType.Group, AssignTypeEnumType.Department, AssignTypeEnumType.Tenant })
{
//二选一移除当前类型的权限,差异分析使用
//eg: 按人分配,移除A设备,只需要查看其他3个类型是否存在A设备而进行删除任务生成
// 按部门分配,移除A设备,需要查看部门上顶级部门是否存在A设备,则通过IgnoreAssignValue移除当前部门其他权限(分组同理)
if (analyzePack.IgnoreAssignTypes.Contains(assignType) && analyzePack.IgnoreAssignValue.IsEmpty())
{
continue;
@@ -197,6 +201,7 @@ public class DevicePermissionAnalyzeService : IDevicePermissionAnalyzeService
};
var data = assignValues.SelectMany(x => uniqueTypes.Select(p => new { assignValue = x, uniqueType = p })).ToList();
//移除IgnoreAssignValue的数据,对应以上说明
var needRemove = data.Where(x => x.assignValue == analyzePack.IgnoreAssignValue && x.uniqueType == analyzePack.IgnoreUniqueType);
data = data.ExceptBy(needRemove, x => new { x.assignValue, x.uniqueType }).ToList();

View File

@@ -1,10 +1,7 @@
using System.Text;
using Dlhis.Basic.Organization.Request;
using Dlhis.Basic.Organization.Request;
using Dlhis.Basic.Organization.Response;
using Dlhis.Basic.Organization.Services;
using HttpUtil;
using Kurisu.AspNetCore.DataAccess.Dto;
using Kurisu.AspNetCore.Utils.Extensions;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
@@ -19,12 +16,10 @@ namespace Dlhis.Basic.Organization.Controllers;
public class GainfoFacesController : ControllerBase
{
private readonly IGainfoFaceService _gainfoFaceService;
private readonly IHttpClientFactory _httpClientFactory;
public GainfoFacesController(IGainfoFaceService gainfoFaceService, IHttpClientFactory httpClientFactory)
public GainfoFacesController(IGainfoFaceService gainfoFaceService)
{
_gainfoFaceService = gainfoFaceService;
_httpClientFactory = httpClientFactory;
}
/// <summary>
@@ -48,31 +43,4 @@ public class GainfoFacesController : ControllerBase
{
return await _gainfoFaceService.GetUploadPageRecordsAsync(request);
}
[AllowAnonymous]
[HttpPost("test")]
public async Task<HikResponse<SimilarityData>> TestAsync(GainfoFaceValidateRequest request)
{
var client = _httpClientFactory.CreateClient("hik-openapi");
var body = request.ToJson(JsonExtensions.DefaultSetting);
var url = "/artemis/api/frs/v1/application/oneToOne";
var key = "27390082";
var secret = "MLl7Dv7p5Pgc9XYI3r4O";
HttpUtillib.SetPlatformInfo(key, secret, "10.32.0.10");
var r = HttpUtillib.HttpPost(url, body, 15);
return Encoding.UTF8.GetString(r).ToObject<HikResponse<SimilarityData>>();
// var headers = InitRequest(url, body, key, secret);
// client.DefaultRequestHeaders.Accept.Clear();
// client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(headers["Accept"]));
// var content = new StringContent(body, Encoding.UTF8, "application/json");
// foreach (var item in headers.Where(x => x.Key != "Accept").Where(x => x.Key != "Content-Type"))
// {
// content.Headers.Add(item.Key, item.Value);
// }
//
// var r = await client.PostAsync(url, content);
// return await r.Content.ReadAsStringAsync();
}
}

View File

@@ -4,6 +4,9 @@ namespace Dlhis.Basic.Organization.Request
{
public class FaceValidationRequest : PageDto
{
/// <summary>
/// 显示成功与否.null全部
/// </summary>
public bool? IsSuccess { get; set; }
}
}

View File

@@ -15,12 +15,6 @@ public class GainfoResignRequest : IValidatableObject
public DateTime Date { get; set; } = DateTime.Now;
/// <summary>
/// 是否外包
/// </summary>
public bool IsOutsource { get; set; } = true;
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if (Date < DateTime.Now.Date)

View File

@@ -150,8 +150,7 @@ public class GainfoOutsourceService : IGainfoOutsourceService
{
Id = outsource.Id,
Reason = $"{setting.NoRecordAutoResignOutsourceDays}天无通行记录",
Date = DateTime.Now,
IsOutsource = true
Date = DateTime.Now
});
}
catch (Exception e)

View File

@@ -267,15 +267,13 @@ public class GainfoService : IGainfoService
if (gainfo.Type == GainfoUserTypeEnumType.External)
{
//获取人员所有的访客申请
var visitorAppointmentDetails = await _dbContext.Queryable<VisitorAppointmentDetailEntity>()
.Where(x => x.UserNo == gainfo.No)
.Where(x => x.DoorStatus == VisitorAppointmentDetailStatusEnumType.Wait
|| x.WorkplaceStatus == VisitorAppointmentDetailStatusEnumType.Wait
|| x.DoorStatus == VisitorAppointmentDetailStatusEnumType.Arrived
|| x.WorkplaceStatus == VisitorAppointmentDetailStatusEnumType.Arrived)
.Where(x => (x.IsEnterDoorArea && x.DoorStatus != VisitorAppointmentDetailStatusEnumType.Leave)
|| (x.IsEnterWorkplace && x.WorkplaceStatus != VisitorAppointmentDetailStatusEnumType.Leave))
.ToListAsync();
foreach (var visitorAppointment in visitorAppointmentDetails)
{
await _appointmentService.FocusLeaveAsync(visitorAppointment.Id, request.Reason);

View File

@@ -1,9 +1,10 @@
using System.ComponentModel.DataAnnotations;
using Dlhis.Entity.Basic.Enums;
using Kurisu.AspNetCore.Utils.Extensions;
namespace Dlhis.Basic.WorkGrids.Request;
public class WorkGridTimePeriodSaveRequest
public class WorkGridTimePeriodSaveRequest : IValidatableObject
{
public long? Id { get; set; }
@@ -33,4 +34,22 @@ public class WorkGridTimePeriodSaveRequest
/// 结束时间
/// </summary>
public TimeOnly End { get; set; }
/// <inheritdoc />
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if (Type != WorkGridTimePeriodEnumType.Day)
{
yield break;
}
var today = DateTime.Today;
var start = today.Add(Start.AddMinutes(-Before).ToTimeSpan());
var end = today.Add(End.AddMinutes(After).ToTimeSpan());
if (start.Date != end.Date)
{
yield return new ValidationResult(WorkGridTimePeriodEnumType.Day.GetDescription() + "禁止跨天", new[] { nameof(Type) });
}
}
}

View File

@@ -57,7 +57,7 @@ public class AutoRemoveAppointmentJob : BaseJob
Type = DeviceTaskEnumType.Delete,
Priority = 100,
TenantId = x.TenantId,
Source = "定时任务判断触发移除",
Source = "访客时间到期自动移除",
Version = 0
}).ToList());
@@ -76,6 +76,11 @@ public class AutoRemoveAppointmentJob : BaseJob
}
/// <summary>
/// 获取有效的区域编码,需要根据申请时间和当前时间判断
/// </summary>
/// <param name="detail"></param>
/// <returns></returns>
private static IEnumerable<string> GetValidAreaCodes(VisitorAppointmentDetailEntity detail)
{
var now = DateTime.Now;