229 lines
7.5 KiB
C#
229 lines
7.5 KiB
C#
using System.Configuration;
|
|
using Dlhis.Basic.Organization.Request;
|
|
using Dlhis.Basic.Organization.Response;
|
|
using Dlhis.Entity.Basic.Entity;
|
|
using Dlhis.Entity.Basic.Enums;
|
|
using Kurisu.AspNetCore.Scope;
|
|
using Kurisu.AspNetCore.UnifyResultAndValidation;
|
|
using Kurisu.AspNetCore.Utils.Extensions;
|
|
using Kurisu.Core.DataAccess.Dto;
|
|
using Kurisu.Core.User.Abstractions;
|
|
using Kurisu.SqlSugar.Attributes;
|
|
using Kurisu.SqlSugar.Extensions;
|
|
using Kurisu.SqlSugar.Services;
|
|
using Mapster;
|
|
|
|
namespace Dlhis.Basic.Organization.Services.Implements;
|
|
|
|
public class GainfoService : IGainfoService
|
|
{
|
|
private readonly IGainfoStore _gainfoStore;
|
|
private readonly IDbContext _dbContext;
|
|
private readonly ICurrentUser _currentUser;
|
|
|
|
public GainfoService(IGainfoStore gainfoStore, IDbContext dbContext, ICurrentUser currentUser)
|
|
{
|
|
_gainfoStore = gainfoStore;
|
|
_dbContext = dbContext;
|
|
_currentUser = currentUser;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 档案分页
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
public async Task<Pagination<GainfoPageResponse>> GetPageAsync(GainfoPageRequest request)
|
|
{
|
|
request.DepartmentNos = await GetRecursionDepartmentNosAsync(request.DepartmentNos);
|
|
|
|
var page = await _gainfoStore.Queryable(request.Status)
|
|
.WhereIF(request.DepartmentNos?.Any() == true, gainfo => request.DepartmentNos.Contains(gainfo.DepartmentNo))
|
|
.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>
|
|
[Transactional]
|
|
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 gainfo = await _gainfoStore.Queryable(GainfoStatusEnumType.Working)
|
|
.LeftJoin<DepartmentEntity>((ga, department) => ga.DepartmentNo == department.No)
|
|
.LeftJoin<CanteenUserEntity>((ga, department, mealUser) => ga.No == mealUser.UserNo)
|
|
.Where((ga, department) => ga.IdentityUserId == identityId)
|
|
.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 gainfo;
|
|
}
|
|
|
|
|
|
//-------------------------------------------help methods ------------------------------------------------
|
|
|
|
/// <summary>
|
|
/// 递归获取部门No
|
|
/// </summary>
|
|
/// <param name="departmentNos"></param>
|
|
/// <returns></returns>
|
|
private async Task<List<string>> GetRecursionDepartmentNosAsync(List<string> departmentNos)
|
|
{
|
|
if (departmentNos == null || departmentNos.Count == 0)
|
|
{
|
|
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);
|
|
}
|
|
|
|
foreach (var item in next)
|
|
{
|
|
RecursionGetNext(item.No, departments, result);
|
|
}
|
|
}
|
|
}
|
|
|
|
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("人员档案信息不存在");
|
|
|
|
|
|
|
|
await Scoped.Request.Value.CreateAsync(async (sp) =>
|
|
{
|
|
var configuration = sp.GetService<IConfiguration>();
|
|
var faceConnectionString = configuration.GetSection("SqlSugarOptions:FaceConnectionString").Value;
|
|
if (faceConnectionString.IsEmpty())
|
|
{
|
|
throw new UserFriendlyException("暂不支持人脸上传");
|
|
}
|
|
|
|
var dbContext = sp.GetService<IDbContext>();
|
|
//todo 切换连接字符串
|
|
dbContext.Client.CurrentConnectionConfig.ConnectionString = faceConnectionString;
|
|
var face = await dbContext.Queryable<GainfoFaceEntity>().Where(x => x.UserCode == gainfo.Code).SingleAsync();
|
|
|
|
if (face == null)
|
|
{
|
|
face = new GainfoFaceEntity
|
|
{
|
|
UserCode = gainfo.Code,
|
|
Face = request.Face
|
|
};
|
|
|
|
await dbContext.InsertAsync(face);
|
|
}
|
|
else
|
|
{
|
|
face.Face = request.Face;
|
|
await dbContext.UpdateAsync(face);
|
|
}
|
|
});
|
|
}
|
|
}
|