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

@@ -29,6 +29,7 @@ public class GainfoCardsController : ControllerBase
/// <param name="request"></param>
/// <returns></returns>
[HttpPost("change")]
[IgnoreTenant]
[Transactional]
public async Task ChangeCardAsync(GainfoChangeCardRequest request)
{

View File

@@ -35,6 +35,19 @@ public class GainfoFingerprintsController : ControllerBase
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>

View File

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

View File

@@ -1,10 +1,12 @@
using Dlhis.Basic.Organization.Response;
using Dlhis.Basic.Organization.Request;
using Dlhis.Basic.Organization.Response;
namespace Dlhis.Basic.Organization.Services;
public interface IGainfoFingerprintService : IScopeDependency
{
Task CollectFingerprintAsync(string userCode, int fingerNum, string fingerprint);
Task CollectFingerprintAsync(FingerprintBatchCollectRequest request);
Task<GainfoFingerprintResponse> GetFingerprintAsync(string userCode, int? fingerNum);
}

View File

@@ -29,13 +29,23 @@ public class GainfoCardService : IGainfoCardService
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();
gainfo.ThrowIfNull("档案不存在");
gainfo.CardNo = request.CardNo;
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)

View File

@@ -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.Device.Entities;
using Dlhis.Entity.Device.Enums;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
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;
public GainfoFingerprintService(IDbContext dbContext)
_dbContext = dbContext;
_devicePermissionService = devicePermissionService;
}
public async Task CollectFingerprintAsync(string userCode, int fingerNum, string fingerprint)
{
await CollectFingerprintAsync(new FingerprintBatchCollectRequest
{
_dbContext = dbContext;
}
public async Task CollectFingerprintAsync(string userCode, int fingerNum, string fingerprint)
{
if (!await _dbContext.Queryable<GainfoEntity>().Where(x => x.Code == userCode).AnyAsync())
UserCode = userCode,
Fingerprints = new List<FingerprintItem>
{
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)
{
gainfoFingerprint = new GainfoFingerprintEntity
{
UserCode = userCode,
FingerNum = fingerNum,
Fingerprint = fingerprint
UserCode = request.UserCode,
FingerNum = item.FingerNum,
Fingerprint = item.Fingerprint
};
await _dbContext.InsertAsync(gainfoFingerprint);
}
else
{
gainfoFingerprint.Fingerprint = fingerprint;
gainfoFingerprint.Fingerprint = item.Fingerprint;
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>()
.LeftJoin<DepartmentEntity>((x, dept) => x.DepartmentNo == dept.No)
.Where(x => x.Code == userCode)
.Select((x, dept) => new
{
x.Code,
x.Name,
x.DepartmentNo,
DepartmentName = dept.Name
})
.FirstAsync();
gainfo.ThrowIfNull("人员不存在");
DeviceUniqueNo = x.UniqueNo,
Status = DeviceTaskStatusEnumType.Wait,
Type = DeviceTaskEnumType.Add,
DeviceType = x.Type,
UserNo = gainfo.No,
UserId = gainfo.Id,
Priority = 0,
Version = 0,
TenantId = x.TenantId,
Source = "指纹采集下发"
}).ToList());
}
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,
UserName = gainfo.Name,
DepartmentNo = gainfo.DepartmentNo,
DepartmentName = gainfo.DepartmentName,
Fingerprints = fingerprins.Select(x => new FingerprintResponse
{
FingerNum = x.FingerNum,
Fingerprint = x.Fingerprint
}).ToList()
};
}
x.Code,
x.Name,
x.DepartmentNo,
DepartmentName = dept.Name
})
.FirstAsync();
gainfo.ThrowIfNull("人员不存在");
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()
};
}
}

View File

@@ -19,11 +19,15 @@ namespace Dlhis.Basic.Organization.Services.Implements;
public class GainfoPermissionService : IGainfoPermissionService
{
private readonly IDevicePermissionAnalyzeService _devicePermissionAnalyzeService;
private readonly IDevicePermissionService _devicePermissionService;
private readonly IDbContext _dbContext;
public GainfoPermissionService(IDevicePermissionAnalyzeService devicePermissionAnalyzeService, IDbContext dbContext)
public GainfoPermissionService(IDevicePermissionAnalyzeService devicePermissionAnalyzeService,
IDevicePermissionService devicePermissionService,
IDbContext dbContext)
{
_devicePermissionAnalyzeService = devicePermissionAnalyzeService;
_devicePermissionService = devicePermissionService;
_dbContext = dbContext;
}
@@ -102,81 +106,81 @@ public class GainfoPermissionService : IGainfoPermissionService
}).ToList());
}
public async Task<Pagination<GainfoDevicePermissionResponse>> GetAssignDeviceCodes2Async(DeviceAssRequest request)
{
var result = await _devicePermissionAnalyzeService.GetUserAssignDeviceCodesWithTypeInTenantAsync(new List<string> { request.UserNo });
if (!result.TryGetValue(request.UserNo, out var permissions))
{
return new Pagination<GainfoDevicePermissionResponse>();
}
//public async Task<Pagination<GainfoDevicePermissionResponse>> GetAssignDeviceCodes2Async(DeviceAssRequest request)
//{
// var result = await _devicePermissionAnalyzeService.GetUserAssignDeviceCodesWithTypeInTenantAsync(new List<string> { request.UserNo });
// if (!result.TryGetValue(request.UserNo, out var permissions))
// {
// 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>()
.LeftJoin<DeviceRegistryEntity>((d, dr) => d.UniqueNo == dr.DeviceUniqueNo)
.WhereIF(request.Search.IsPresent(), d => d.UniqueNo == request.Search)
.Where(d => deviceCodes.Contains(d.Code))
.Select((d, dr) => new GainfoDevicePermissionResponse { Factory = d.TenantId }, true)
.ToListAsync();
// var list = await _dbContext.Queryable<DeviceEntity>()
// .LeftJoin<DeviceRegistryEntity>((d, dr) => d.UniqueNo == dr.DeviceUniqueNo)
// .WhereIF(request.Search.IsPresent(), d => d.UniqueNo == request.Search)
// .Where(d => deviceCodes.Contains(d.Code))
// .Select((d, dr) => new GainfoDevicePermissionResponse { Factory = d.TenantId }, true)
// .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))
? await _dbContext.Queryable<DepartmentEntity>().Select(x => new { x.No, x.Name }).ToListAsync()
: new[] { new { No = string.Empty, Name = string.Empty } }.ToList();
// 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();
// 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();
list.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;
// list.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;
// 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
};
// 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
};
// 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 r;
// })
// };
// }
// });
var page = list.Where(x => x.Type == request.DeviceType).ToPage(request);
page.Total = list.Where(x => x.Type == request.DeviceType).Count();
// var page = list.Where(x => x.Type == request.DeviceType).ToPage(request);
// 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)
{
@@ -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)
{
var gainfo = await _dbContext.Queryable<GainfoEntity>()
.Where(x => x.No == userNo)
.SingleAsync();
if (gainfo == null)
{
gainfo = await _dbContext.Queryable<GainfoEntity>().AS("GainfoLeave")
.Where(x => x.No == userNo)
.SingleAsync();
if (gainfo != null)
.Where(x => x.No == userNo || x.Code == userNo)
.Select(x => new
{
UserId = x.Id,
UserNo = x.No,
UserCode = x.Code
})
.SingleAsync()
?? await _dbContext.Queryable<GainfoLeaveEntity>()
.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("档案数据不存在");
//获取人员的设备权限
if (deviceCodes.IsEmpty())
{
deviceCodes = await _devicePermissionAnalyzeService.GetUserPermissionDeviceCodesAsync(gainfo!.No);
deviceCodes = await _devicePermissionService.GetUserDeviceCodesByNoOrCodeAsync(gainfo.UserCode);
}
var devices = await _dbContext.Queryable<DeviceEntity>()
@@ -372,11 +311,11 @@ public class GainfoPermissionService : IGainfoPermissionService
var tasks = devices.Select(x => new DeviceTaskEntity
{
UserId = gainfo!.Id,
UserId = gainfo!.UserId,
UserNo = userNo,
DeviceUniqueNo = x.UniqueNo,
Status = DeviceTaskStatusEnumType.Wait,
Version = 0,
UserNo = userNo,
Type = type,
DeviceType = x.Type,
TenantId = x.TenantId,

View File

@@ -313,7 +313,7 @@ public class GainfoService : IGainfoService
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)
.Where((x, xt) => xt.Name == "大华人脸机")

View File

@@ -365,7 +365,7 @@ public class GainfoUpdateService : IGainfoUpdateService
}
}
}
else
else
{
await _gainfoPermissionService.ResetPermissionsAsync(gainfo.No, DeviceTaskEnumType.Delete, null, null, "人员离职生成");