Files
jinko.yikatong/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs
liguoyang 3ea432943f Squashed commit of the following:
commit afdd9e6f14
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 21:48:05 2024 +0800

    fix 价格默认获取菜单中的设置

commit a3cfc472c8
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 21:40:04 2024 +0800

    fix 时间范围逻辑

commit 83f8906f12
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 21:32:55 2024 +0800

    fix 时间范围逻辑

commit 35660b1d0c
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 21:29:36 2024 +0800

    fix 数据范围罗逻辑修改

commit 7407955bc5
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 21:14:06 2024 +0800

    fix 分类树增加营业点参数

commit ed5196d1a1
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 21:02:52 2024 +0800

    feat 用户创建

commit d25909a235
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 20:51:20 2024 +0800

    fix 菜单明细调整

commit 8915f9ff0f
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 20:42:08 2024 +0800

    fix 判断提前

commit 45aa52aa2a
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 20:34:22 2024 +0800

    fix 逻辑取反

commit 89904fead1
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 20:23:20 2024 +0800

    fix 菜单时效范围

commit 573911f907
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 19:13:33 2024 +0800

    fix 订单聚合返回状态

commit 93c38be18a
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 18:40:12 2024 +0800

    fix 订单查询

commit e256d18d36
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 18:14:33 2024 +0800

    fix 订单取消接口,分页权限控制

commit 1218aec811
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 17:32:45 2024 +0800

    fix 营业点权限控制优化

commit 226c61ee41
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 17:09:42 2024 +0800

    fix tenantId赋值

commit 28d2c1d8d4
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 17:05:37 2024 +0800

    fix ignoretenant

commit 5ae6dd97b4
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 16:53:40 2024 +0800

    fix ignoretenant

commit 4c866eaf3f
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 16:40:24 2024 +0800

    feat 获取所有地址

commit 2ca8f2db49
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 16:22:47 2024 +0800

    fix 优化查询

commit 212a1fa073
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 16:01:49 2024 +0800

    fix 临时数据模拟

commit 0eb76e878c
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 15:48:59 2024 +0800

    fix 处理删除缺少判断

commit c582fb40c0
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 15:40:22 2024 +0800

    fix 查询优化

commit 6d3a19b283
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 11:48:45 2024 +0800

    fix 错误值修改

commit c39f77008d
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 11:31:50 2024 +0800

    fix 营业点控制(admin),unit返回

commit a5dcab1d07
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 11:16:23 2024 +0800

    fix 营业点分页控制

commit 02084be82b
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 11:01:14 2024 +0800

    fix 分类控制菜品获取

commit 96c5c5feba
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 10:39:58 2024 +0800

    fix DI

commit 367ede2eeb
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Thu Mar 21 10:35:24 2024 +0800

    fix 订餐返回当前信息,增加数量入参和响应

commit 0e1f6cb4a0
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Wed Mar 20 16:40:10 2024 +0800

    fix 餐补查询代码调整

commit 21fc2f78d3
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Wed Mar 20 15:52:46 2024 +0800

    fix 支付批量操作

commit 878b44a146
Merge: a90d4e6 bf5c937
Author: cheche <717840555@qq.com>
Date:   Wed Mar 20 15:27:39 2024 +0800

    Merge branch 'development' of https://git.dlhis.com/liguoyang/jinko.yikatong into development

commit a90d4e66a7
Author: cheche <717840555@qq.com>
Date:   Wed Mar 20 15:27:37 2024 +0800

    fix 餐补查询及日志删除

commit bf5c937037
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Wed Mar 20 15:12:30 2024 +0800

    fix 补充营业点分配权限接口

commit 07672f1d32
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Wed Mar 20 13:56:33 2024 +0800

    fix 优化changeDb

commit 7090ee4a33
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Wed Mar 20 13:41:25 2024 +0800

    fix 敏感信息混淆

commit 4366b68831
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Wed Mar 20 12:42:48 2024 +0800

    fix 代码优化

commit 03b73515b5
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Wed Mar 20 10:59:08 2024 +0800

    fix tree返回营业点

commit 1ce60bedc2
Merge: aba4fa7 2d83930
Author: cheche <717840555@qq.com>
Date:   Wed Mar 20 09:55:17 2024 +0800

    Merge branch 'development' of https://git.dlhis.com/liguoyang/jinko.yikatong into development

commit aba4fa7ee9
Author: cheche <717840555@qq.com>
Date:   Wed Mar 20 09:55:13 2024 +0800

    fix 删除日志优化

commit 2d8393068f
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Tue Mar 19 20:53:16 2024 +0800

    feat 订单聚合接口

commit 0cde1d3d92
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Tue Mar 19 20:03:06 2024 +0800

    fix 表名称调整

commit f003e30169
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Tue Mar 19 19:51:56 2024 +0800

    fix 订餐null异常处理

commit f427338715
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Tue Mar 19 18:43:19 2024 +0800

    feat 获取菜品

commit 3a65d95701
Merge: 9a7091b 7432fae
Author: cheche <717840555@qq.com>
Date:   Tue Mar 19 18:36:16 2024 +0800

    Merge branch 'development' of https://git.dlhis.com/liguoyang/jinko.yikatong into development

commit 9a7091b4e0
Author: cheche <717840555@qq.com>
Date:   Tue Mar 19 18:36:14 2024 +0800

    fix 删除日志try

commit 7432fae103
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Tue Mar 19 18:02:31 2024 +0800

    fix 配送点增加

commit ecd162c7af
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Tue Mar 19 17:51:15 2024 +0800

    fix 预定就餐送货地点

commit 1c7a054ed4
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Tue Mar 19 15:53:22 2024 +0800

    feat 获取所有营业点接口

commit 84398a566e
Merge: 217d9f7 84b4025
Author: cheche <717840555@qq.com>
Date:   Tue Mar 19 15:26:42 2024 +0800

    Merge branch 'development' of https://git.dlhis.com/liguoyang/jinko.yikatong into development

commit 217d9f7770
Author: cheche <717840555@qq.com>
Date:   Tue Mar 19 15:26:40 2024 +0800

    feat  配送点管理

commit 84b402538e
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Tue Mar 19 14:59:21 2024 +0800

    fix 菜单分页响应调整,增加详情接口

commit 098d7c7e9d
Author: liguoyang <Ligy.97@foxmail.com>
Date:   Tue Mar 19 14:26:24 2024 +0800

    fix 代码优化
2024-03-21 22:04:52 +08:00

513 lines
18 KiB
C#

using Dlhis.Basic.Device.Services;
using Dlhis.Basic.Organization.Request;
using Dlhis.Basic.Organization.Response;
using Dlhis.Entity.Basic.Entity;
using Dlhis.Entity.Basic.Enums;
using Dlhis.Entity.Device.Enums;
using Kurisu.AspNetCore.Utils;
using Kurisu.AspNetCore.Utils.Extensions;
using Kurisu.Core.DataAccess.Dto;
using Kurisu.Core.User.Abstractions;
using Kurisu.SqlSugar.Extensions;
using Kurisu.SqlSugar.Services;
using Mapster;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Mvc;
using System.Linq.Expressions;
namespace Dlhis.Basic.Organization.Services.Implements;
public class GainfoService : IGainfoService
{
private readonly IGainfoStore _gainfoStore;
private readonly IDbContext _dbContext;
private readonly ICurrentUser _currentUser;
private readonly IDevicePermissionService _devicePermissionService;
private readonly RedisCache _redisCache;
private readonly IServiceProvider _serviceProvider;
private readonly IConfiguration _configuration;
private readonly ILogger<GainfoService> _logger;
public GainfoService(IGainfoStore gainfoStore,
IDbContext dbContext,
ICurrentUser currentUser,
IDevicePermissionService devicePermissionService,
RedisCache redisCache,
IServiceProvider serviceProvider,
IConfiguration configuration,
ILogger<GainfoService> logger,
IDepartmentService departmentService)
{
_gainfoStore = gainfoStore;
_dbContext = dbContext;
_currentUser = currentUser;
_devicePermissionService = devicePermissionService;
_redisCache = redisCache;
_serviceProvider = serviceProvider;
_configuration = configuration;
_logger = logger;
}
/// <summary>
/// 档案分页
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public async Task<Pagination<GainfoPageResponse>> GetPageAsync(GainfoPageRequest request)
{
var currentTenantId = _currentUser.GetStringTenantId();
//根据组织架构搜索档案
Expression<Func<GainfoEntity, bool>> where = LinqExpressionExtension.False<GainfoEntity>();
foreach (var item in request.DepartmentSelections)
{
var depts = await GetRecursionDepartmentNosAsync(item.DepartmentNos);
if (depts.Any())
where = where.Or(gainfo => gainfo.Factory == item.Tenant && depts.Contains(gainfo.DepartmentNo));
else
where = where.Or(gainfo => gainfo.Factory == item.Tenant);
}
var page = await _gainfoStore.Queryable(request.Status)
.WhereIF(request.DepartmentSelections.IsPresent(), where)
.WhereIF(request.DepartmentSelections.IsEmpty(), gainfo => gainfo.Factory == currentTenantId)
.WhereIF(request.Search.IsPresent(), gainfo =>
gainfo.Name.Contains(request.Search)
|| gainfo.Code.Contains(request.Search)
|| gainfo.IdNo.Contains(request.Search)
|| gainfo.Werks.Contains(request.Search)
)
.Select<GainfoPageResponse>()
.ToPageListAsync(request);
return page;
}
/// <summary>
///保存档案号
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public async Task SaveAsync(List<GainfoSaveRequest> request)
{
//todo check
var entities = request.Adapt<List<GainfoEntity>>();
entities.ForEach(x =>
{
if (x.No.IsEmpty())
{
x.No = "F" + Guid.NewGuid().ToString();
}
});
await _gainfoStore.InsertAsync(entities);
}
/// <summary>
///修改档案号
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public async Task UpdateAsync(GainfoSaveRequest request)
{
var gainfo = await _gainfoStore.Queryable(request.GainfoStatus).Where(x => x.Id == request.Id).FirstAsync();
gainfo.ThrowIfNull("档案数据不存在,无法更新");
request.Adapt(gainfo);
await _gainfoStore.UpdateAsync(gainfo);
}
/// <summary>
/// 正式转离职
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public async Task DimissionAsync(GainfoDimissionRequest request)
{
var gainfo = await _gainfoStore.Queryable(GainfoStatusEnumType.Working)
.Where(x => x.No == request.UserNo)
.FirstAsync();
gainfo.ThrowIfNull("该档案不存在");
//添加到离职表
await _gainfoStore.InsertAsync(gainfo, GainfoStatusEnumType.Leave);
//删除原数据
await _gainfoStore.DeleteAsync(gainfo, GainfoStatusEnumType.Working);
}
/// <summary>
/// 临时转正式
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public async Task OnboardingAsync(GainfoDimissionRequest request)
{
var gainfo = await _gainfoStore.Queryable(GainfoStatusEnumType.External)
.Where(x => x.No == request.UserNo)
.FirstAsync();
gainfo.ThrowIfNull($"该档案不存在");
//添加到正式表,不删除原数据,留档处理
await _gainfoStore.InsertAsync(gainfo);
}
public async Task<GainfoCurrentResponse> CurrentUserInfoAsync()
{
var identityId = _currentUser.GetIntSubjectId();
var code = _currentUser.GetUserClaim("jinko-code");
var gainfo = await _gainfoStore.Queryable().Where(x => x.Code == code).FirstAsync()
?? await _gainfoStore.Queryable().Where(x => x.IdentityUserId == identityId).FirstAsync();
if (gainfo == null)
{
return null;
}
var info = await _gainfoStore.Queryable(GainfoStatusEnumType.Working)
.LeftJoin<DepartmentEntity>((ga, department) => ga.DepartmentNo == department.No)
.LeftJoin<GainfoMealEntity>((ga, department, mealUser) => ga.No == mealUser.UserNo)
.Where((ga, department) => ga.Id == gainfo.Id)
.Select((ga, department, mealUser) => new GainfoCurrentResponse
{
UserNo = ga.No,
Birthday = ga.Birthday,
DepartmentNo = department.No,
DepartmentName = department.Name,
Gender = ga.Gender,
UserCode = ga.Code,
UserName = ga.Name,
MealInfo = new GainfoCurrentMealInfoResponse
{
Balance = mealUser.Balance
}
})
.FirstAsync();
return info;
}
public async Task<IActionResult> GetFaceAsync(string token)
{
var timeLimitedDataProtector = _serviceProvider.GetService<IDataProtectionProvider>()
.CreateProtector("down:face")
.ToTimeLimitedDataProtector();
try
{
var password = timeLimitedDataProtector.Unprotect(token);
var userCode = password.Split(':')[1];
var faceCache = await _redisCache.HashGetAsync("faces", userCode);
if (faceCache.HasValue)
{
return new FileContentResult(Convert.FromBase64String(faceCache), "image/png");
}
var dbContext = _dbContext.ChangeDb("face");
var face = await dbContext.Queryable<GainfoFaceEntity>().Where(x => x.UserCode == userCode).SingleAsync();
if (face == null)
{
_logger.LogWarning("学工号:{userCode}不存在人脸照片", userCode);
return new NotFoundResult();
}
await _redisCache.HashSetAsync("faces", userCode, face.Face);
return new FileContentResult(Convert.FromBase64String(face.Face), "image/png");
}
catch (Exception ex)
{
_logger.LogError(ex, "获取人脸失败:{message}", ex.Message);
return new NotFoundResult();
}
}
public async Task UploadFaceAsync(GainfoUploadFaceRequest request)
{
var gainfo = await _gainfoStore.Queryable(GainfoStatusEnumType.Working).Where(x => x.No == request.UserNo).FirstAsync();
gainfo ??= await _gainfoStore.Queryable(GainfoStatusEnumType.External).Where(x => x.No == request.UserNo).FirstAsync();
gainfo.ThrowIfNull("人员档案信息不存在");
var userId = _currentUser.GetIntSubjectId();
var faceContext = _dbContext.ChangeDb("face");
var face = await faceContext.Queryable<GainfoFaceEntity>().Where(x => x.UserCode == gainfo.Code).SingleAsync();
var taskType = face == null ? DeviceTaskEnumType.Add : DeviceTaskEnumType.Update;
await _redisCache.HashSetAsync("faces", gainfo.Code, request.Face);
if (face == null)
{
face = new GainfoFaceEntity
{
UserCode = gainfo.Code,
Face = request.Face,
CreateTime = DateTime.Now,
ModifiedTime = DateTime.Now,
CreatedBy = userId,
ModifiedBy = userId
};
await faceContext.InsertAsync(face);
}
else
{
if (face.Face == request.Face)
{
_logger.LogWarning("相同的人脸照片更新忽略");
return;
}
face.Face = request.Face;
face.ModifiedBy = userId;
face.ModifiedTime = DateTime.Now;
await faceContext.UpdateAsync(face);
}
//生成任务
await _devicePermissionService.GenerateDeviceTasksAsync(gainfo.No, taskType);
}
public async Task UploadFacesAsync(List<GainfoUploadFaceRequest> requests)
{
foreach (var request in requests)
{
var gainfo = await _gainfoStore.Queryable(GainfoStatusEnumType.Working).Where(x => x.No == request.UserNo).FirstAsync();
gainfo ??= await _gainfoStore.Queryable(GainfoStatusEnumType.External).Where(x => x.No == request.UserNo).FirstAsync();
gainfo.ThrowIfNull("人员档案信息不存在");
var dbContext = _dbContext.ChangeDb("face");
var face = await dbContext.Queryable<GainfoFaceEntity>().Where(x => x.UserCode == gainfo.Code).SingleAsync();
var taskType = face == null ? DeviceTaskEnumType.Add : DeviceTaskEnumType.Update;
await _redisCache.HashSetAsync("faces", gainfo.Code, request.Face);
if (face == null)
{
face = new GainfoFaceEntity
{
UserCode = gainfo.Code,
Face = request.Face
};
await dbContext.InsertAsync(face);
}
else
{
if (face.Face == request.Face)
{
_logger.LogWarning("相同的人脸照片更新忽略");
return;
}
face.Face = request.Face;
await dbContext.UpdateAsync(face);
}
//生成任务
await _devicePermissionService.GenerateDeviceTasksAsync(gainfo.No, taskType);
}
}
public async Task<string> GetFaceByUserCodeAsync(string userCode)
{
var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.Code == userCode).SingleAsync();
gainfo.ThrowIfNull($"{userCode}人员信息不存在");
var dbContext = _dbContext.ChangeDb("face");
var face = await dbContext.Queryable<GainfoFaceEntity>()
.Where(x => x.UserCode == userCode)
.SingleAsync();
face.ThrowIfNull("人脸照片尚未录入");
var timeLimitedDataProtector = _serviceProvider.GetService<IDataProtectionProvider>()
.CreateProtector("down:face")
.ToTimeLimitedDataProtector();
var faceUrl = _configuration.GetSection("FaceUrlOptions:Url").Value;
var limit = _configuration.GetSection("FaceUrlOptions:Limit").Get<int>();
var key = $"face:{userCode}";
var token = timeLimitedDataProtector.Protect(key, TimeSpan.FromSeconds(limit));
return faceUrl + token;
}
public async Task<Dictionary<string, string>> GetFaceByUserCodesAsync(GetFaceByUserCodesRequest request)
{
var faceDictionary = new Dictionary<string, string>();
foreach (var userCode in request.UserCodes)
{
var faceUrl = await GetFaceByUserCodeAsync(userCode);
faceDictionary.Add(userCode, faceUrl);
}
return faceDictionary;
}
/// <summary>
/// 档案列表
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public async Task<Pagination<GainfoListResponse>> GetGainfoListAsync(GainfoListRequest request)
{
var page = await _gainfoStore.Queryable(request.Status)
.LeftJoin<DepartmentEntity>((ga, de) => ga.DepartmentNo == de.No)
.WhereIF(!request.Name.IsEmpty(), ga => ga.Name == request.Name)
.WhereIF(!request.IdNo.IsEmpty(), ga => ga.IdNo == request.IdNo)
.WhereIF(!request.DepartmentNo.IsEmpty(), ga => ga.DepartmentNo == request.DepartmentNo)
.WhereIF(!request.Code.IsEmpty(), ga => ga.Code == request.Code)
.Select((ga, de) => new GainfoListResponse
{
No = ga.No,
Name = ga.Name,
Code = ga.Code,
IdNo = ga.IdNo,
Gender = ga.Gender,
Phone = ga.Phone,
DepartmentNo = de.No,
DepartmentName = de.Name,
Address = ga.Address,
}).ToPageListAsync(request);
return page;
}
/// <summary>
/// 档案详情
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public async Task<GainfoDetailResponse> GetGainfoDetailAsync(GainfoDetailRequest request)
{
var info = await _gainfoStore.Queryable(request.Status)
.LeftJoin<DepartmentEntity>((ga, de) => ga.DepartmentNo == de.No)
.LeftJoin<BasicTypeEntity>((ga, de, type) => ga.Native == type.Code && type.Type == "native")
.LeftJoin<PositionEntity>((ga, de, type, posi) => ga.Position == posi.Name)
.LeftJoin<BasicTypeEntity>((ga, de, type, posi, type2) => ga.CountryNo == type2.Code && type2.Type == "country")
.LeftJoin<BasicTypeEntity>((ga, de, type, posi, type2, type3) => ga.Nation == type3.Code && type3.Type == "nation")
.LeftJoin<BasicTypeEntity>((ga, de, type, posi, type2, type3, type4) => ga.IdClass == type4.Code && type4.Type == "cls")
.Where(ga => ga.No == request.No)
.Select((ga, de, type, posi, type2, type3, type4) => new GainfoDetailResponse
{
No = ga.No,
SapNo = ga.SapNo,
Name = ga.Name,
Code = ga.Code,
DepartmentName = de.Name,
IdClass = ga.IdClass,
IdNo = ga.IdNo,
Gender = ga.Gender,
NativeName = type.Display,
Address = ga.Address,
Birthday = ga.Birthday,
Phone = ga.Phone,
Position = ga.Position,
Grade = posi.Grade,
Degree = ga.Degree,
Werks = ga.Werks,
CostId = ga.CostId,
Marital = ga.Marital == "Single" ? "未婚" : "已婚",
CountryName = type2.Display,
NationName = type3.Display,
ClassName = type4.Display,
Factory = ga.Factory,
OnboardingDate = ga.CreateTime,
})
.FirstAsync();
if (info != null)
{
if (request.WithFace)
{
info.Face = await _dbContext.ChangeDb("face").Queryable<GainfoFaceEntity>().Where(x => x.UserCode == info.Code).Select(x => x.Face).SingleAsync();
}
}
return info;
}
public async Task MigrationAsync(MigrationRequest request)
{
//档案数据
var gainfo = await _gainfoStore.Queryable().Where(x => x.Code == request.Code).FirstAsync();
if (gainfo == null)
{
return;
}
//卡号为空则更新
if (gainfo.CardNo.IsEmpty())
{
gainfo.CardNo = request.CardNo;
await _gainfoStore.UpdateAsync(gainfo);
}
//外部传入人脸
if (request.Face.IsPresent())
{
var faceDbContext = _dbContext.ChangeDb("face");
var exists = await faceDbContext.Queryable<GainfoFaceEntity>().AnyAsync(x => x.UserCode == gainfo.Code);
//人脸不存在则写入
if (!exists)
{
await faceDbContext.InsertAsync(new GainfoFaceEntity
{
CreatedBy = 1,
CreateTime = DateTime.Now,
ModifiedBy = 1,
ModifiedTime = DateTime.Now,
UserCode = gainfo.Code,
Face = request.Face,
});
}
}
}
//-------------------------------------------help methods ------------------------------------------------
/// <summary>
/// 递归获取部门No
/// </summary>
/// <param name="departmentNos"></param>
/// <returns></returns>
private async Task<List<string>> GetRecursionDepartmentNosAsync(List<string> departmentNos)
{
if (departmentNos.IsEmpty())
{
return new List<string>();
}
var departments = await _dbContext.Queryable<DepartmentEntity>().ToListAsync();
var currentNos = departments.Where(x => departmentNos.Contains(x.No)).ToList();
foreach (var item in currentNos)
{
RecursionGetNext(item.No, departments, departmentNos);
}
return departmentNos.Distinct().ToList();
void RecursionGetNext(string currentCode, List<DepartmentEntity> departments, List<string> result)
{
var next = departments.Where(x => x.PNo == currentCode).ToList();
foreach (var item in next)
{
result.Add(item.No);
RecursionGetNext(item.No, departments, result);
}
}
}
}