sunpengfei
2025-08-11 29767916b8e523a425970b3e21397f39803ac2b7
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
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
{
    /// <summary>
    /// 任务雇佣命令处理器
    /// </summary>
    public class TaskUserCommandHandler(
            IRepository<UserTaskCollect> repUserTaskCollect
        ) :
        IRequestHandler<CollectTaskCommand, bool>
    {
        private readonly IRepository<UserTaskCollect> repUserTaskCollect = repUserTaskCollect;
 
        /// <summary>
        /// 收藏任务
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<bool> Handle(CollectTaskCommand request, CancellationToken cancellationToken)
        {
            var logier = JwtUtils.GetCurrentLogier();
            var entity = await repUserTaskCollect.AsQueryable().AsNoTracking()
                .Where(it => it.TaskInfoId == request.Id && it.UserId == logier.Id)
                .FirstOrDefaultAsync(cancellationToken);
            if (entity == null)
            {
                entity = new UserTaskCollect
                {
                    TaskInfoId = request.Id,
                    UserId = logier.Id
                };
                await repUserTaskCollect.InsertAsync(entity);
            }
            return true;
        }
    }
}