sunpengfei
2025-08-14 1b07d3f0191424cbf06dad186f5eb622ac9144e0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
using FlexJobApi.Core;
using Furion.DatabaseAccessor;
using Furion.FriendlyException;
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
{
    /// <summary>
    /// 任务人员查询处理器
    /// </summary>
    public class TaskUserQueryHandler(
        IRepository<TaskInfoUser> rep) :
        IRequestHandler<GetTaskUsersQuery, GetTaskUsersQueryResult>,
        IRequestHandler<GetArrangeTaskUsersQuery, GetArrangeTaskUsersQueryResult>,
        IRequestHandler<GetTaskUserHireStatusQuery, GetTaskUserHireStatusQueryResult>
    {
        private readonly IRepository<TaskInfoUser> rep = rep;
 
        /// <summary>
        /// B端查询应聘报名分页列表信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<GetTaskUsersQueryResult> 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);
            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));
            }
            if (request.HireStatus.HasValue)
            {
                q = q.Where(it => it.EnterpriseEmployee.HireStatus == request.HireStatus);
            }
            var s = q
                .Select(it => new GetTaskUsersQueryResultItem
                {
                    Id = it.Id,
                    EnterpriseEmployeeId = it.EnterpriseEmployeeId,
                    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<GetTaskUsersQueryResult, GetTaskUsersQueryResultItem>(s, cancellationToken);
        }
 
        /// <summary>
        /// B端查询人员安排分页列表信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<GetArrangeTaskUsersQueryResult> 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<GetArrangeTaskUsersQueryResult, GetArrangeTaskUsersQueryResultItem>(s, cancellationToken);
        }
 
        /// <summary>
        /// 查询应聘报名人员录用状态
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<GetTaskUserHireStatusQueryResult> Handle(GetTaskUserHireStatusQuery request, CancellationToken cancellationToken)
        {
            var logier = JwtUtils.GetCurrentLogier();
            var q = rep.AsQueryable().AsNoTracking()
                .Where(it => it.TaskInfoId == request.TaskInfoId);
            if (logier.Type == EnumUserType.Personal)
            {
                q = q.Where(it => it.EnterpriseEmployee.UserId == request.UserId);
            }
            else if (request.UserId == null)
            {
                throw Oops.Oh(EnumErrorCodeType.s400, "请选择用户");
            }
            var model = await q
                .Select(it => new GetTaskUserHireStatusQueryResult
                {
                    HireStatus = it.EnterpriseEmployee.HireStatus
                })
                .FirstOrDefaultAsync(cancellationToken);
            if (model == null) throw Oops.Oh(EnumErrorCodeType.s404, "该报名信息");
            return model;
        }
    }
}