using FlexJobApi.Core;
using Furion.DatabaseAccessor;
using MediatR;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FlexJobApi.FlexJobServer.Application
{
///
/// 任务人员查询处理器
///
public class TaskUserQueryHandler(
IRepository rep) :
IRequestHandler,
IRequestHandler
{
private readonly IRepository rep = rep;
///
/// B端查询应聘报名分页列表信息
///
///
///
///
public async Task Handle(GetTaskUsersQuery request, CancellationToken cancellationToken)
{
var logier = JwtUtils.GetCurrentLogier();
var q = rep.AsQueryable().AsNoTracking()
.OrderBy(it => it.CreatedTime)
.Where(it => it.TaskInfo.EnterpriseId == logier.EnterpriseId && it.TaskInfoId == request.Id);
var s = q
.Select(it => new GetTaskUsersQueryResultItem
{
Id = it.Id,
Avatar = it.EnterpriseEmployee.User.Avatar,
Name = it.EnterpriseEmployee.User.Name,
Identity = it.EnterpriseEmployee.User.Identity,
ContactPhoneNumber = it.EnterpriseEmployee.User.ContactPhoneNumber,
Gender = it.EnterpriseEmployee.User.Gender,
Age = it.EnterpriseEmployee.User.Age,
IsReal = it.EnterpriseEmployee.User.IsReal,
RealMethod = it.EnterpriseEmployee.User.RealMethod,
PersonalIdentityCode = it.EnterpriseEmployee.User.PersonalIdentityCode,
PersonalIdentityContent = it.EnterpriseEmployee.User.PersonalIdentity.Content,
EducationalBackgroundCode = it.EnterpriseEmployee.User.EducationalBackgroundCode,
EducationalBackgroundContent = it.EnterpriseEmployee.User.EducationalBackground.Content,
TaskCount = it.EnterpriseEmployee.TaskInfoUsers.Count(tu => tu.EnterpriseEmployee.HireStatus == EnumTaskUserHireStatus.Pass),
WorkSeniority = it.EnterpriseEmployee.User.WorkSeniority,
WorkExperience = it.EnterpriseEmployee.User.WorkExperience,
HireStatus = it.EnterpriseEmployee.HireStatus
});
return await request.PageModel.GetPagedListAsync(s, cancellationToken);
}
///
/// B端查询人员安排分页列表信息
///
///
///
///
public async Task Handle(GetArrangeTaskUsersQuery request, CancellationToken cancellationToken)
{
var logier = JwtUtils.GetCurrentLogier();
var q = rep.AsQueryable().AsNoTracking()
.OrderBy(it => it.CreatedTime)
.Where(it =>
it.TaskInfo.EnterpriseId == logier.EnterpriseId
&& it.TaskInfoId == request.Id
&& it.EnterpriseEmployee.HireStatus == EnumTaskUserHireStatus.Pass
&& it.EnterpriseEmployee.UserSignContractStatus == EnumTaskUserSignContractStatus.Pass
&& it.EnterpriseEmployee.EnterpriseSignContractStatus == EnumTaskUserSignContractStatus.Pass);
if (request.ArrangeStatus.HasValue)
{
q = q.Where(it=>it.ArrangeStatus == request.ArrangeStatus);
}
if (request.Keywords.IsNotNull())
{
q = q.Where(it =>
it.EnterpriseEmployee.User.Name.Contains(request.Keywords)
|| it.EnterpriseEmployee.User.Identity.Contains(request.Keywords)
|| it.EnterpriseEmployee.User.PhoneNumber.Contains(request.Keywords));
}
var s = q
.Select(it => new GetArrangeTaskUsersQueryResultItem
{
Id = it.Id,
Avatar = it.EnterpriseEmployee.User.Avatar,
Name = it.EnterpriseEmployee.User.Name,
Identity = it.EnterpriseEmployee.User.Identity,
ContactPhoneNumber = it.EnterpriseEmployee.User.ContactPhoneNumber,
Gender = it.EnterpriseEmployee.User.Gender,
Age = it.EnterpriseEmployee.User.Age,
IsReal = it.EnterpriseEmployee.User.IsReal,
RealMethod = it.EnterpriseEmployee.User.RealMethod,
PersonalIdentityCode = it.EnterpriseEmployee.User.PersonalIdentityCode,
PersonalIdentityContent = it.EnterpriseEmployee.User.PersonalIdentity.Content,
EducationalBackgroundCode = it.EnterpriseEmployee.User.EducationalBackgroundCode,
EducationalBackgroundContent = it.EnterpriseEmployee.User.EducationalBackground.Content,
TaskCount = it.EnterpriseEmployee.TaskInfoUsers.Count(tu => tu.EnterpriseEmployee.HireStatus == EnumTaskUserHireStatus.Pass),
WorkSeniority = it.EnterpriseEmployee.User.WorkSeniority,
WorkExperience = it.EnterpriseEmployee.User.WorkExperience,
ArrangeStatus = it.ArrangeStatus
});
return await request.PageModel.GetPagedListAsync(s, cancellationToken);
}
}
}