/// <summary> /// 审核任务 /// </summary> /// <param name="user"></param> /// <param name="request"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <ResponseMessage> ExaminetaskAsync(UserInfo user, ExamineTaskRequest request, CancellationToken cancellationToken = default(CancellationToken)) { var response = new ResponseMessage(); if (!user.IsAdmin) { response.Code = ResponseCodeDefines.NotAllow; response.Message = "不是管理员,没有权限"; return(response); } var taskInfo = await _iTaskStore.GetTaskInfos().Where(a => !a.IsDelete && a.Id == request.TaskId).FirstOrDefaultAsync(cancellationToken); var periodInfo = await _iTaskStore.GetScorePeriods().Where(w => !w.IsDelete && w.Id == taskInfo.PeriodId).FirstOrDefaultAsync(); if (periodInfo == null || periodInfo.State != 1) { response.Code = ResponseCodeDefines.ModelStateInvalid; response.Message = "只有进行中的赛季才能操作"; return(response); } //修改审核状态 时间 审核人 备注 taskInfo.ExamineState = request.IsOk == true ? 2 : 3; taskInfo.ExamineMemo = request.ExamineMemo; taskInfo.ExamineTime = DateTime.Now; taskInfo.ExamineUser = user.Id; var taskPushUserInfo = await _iUserStore.GetUserInfos().Where(w => !w.IsDelete && w.Id == taskInfo.CreateUser).FirstOrDefaultAsync(); if (taskInfo.LootTime > DateTime.Now) { #region << 调度中心添加计划任务:刷新任务状态从未开抢(0)到未认领(1) >> var task = await _iTaskStore.GetTaskInfos().Where(a => a.IsDelete == false && a.Id == request.TaskId).FirstOrDefaultAsync(cancellationToken); var args = new Dictionary <string, string>(); args.Add(nameof(task.Id), task.Id); var schedulerRequest = new ApiCore.Dto.ScheduleSubmitRequest { JobGroup = "KcoinTaskGrab", JobName = task.Id, CronStr = "", StarRunTime = task.LootTime, EndRunTime = null, Callback = $"{_config["PointGameUrl"]}/api/task/state/refresh/callback", Args = args, }; string schedulerUrl = $"{_config["ScheduleServerUrl"]}/api/scheduler/start"; var re = await _restClient.Post <ResponseMessage>(schedulerUrl, schedulerRequest); if (re.Code != ResponseCodeDefines.SuccessCode) { response.Code = re.Code; response.Message = "调度中心添加计划任务失败:" + re.Message; return(response); } #endregion } else { taskInfo.TaskState = 1; } var dynamicContent = string.Empty; //事务保存 using (var trans = await _transaction.BeginTransaction()) { try { await _iTaskStore.UpdateTaskInfoAsync(taskInfo); // 添加动态 dynamicContent = await _dynamicHelper.AddDynamicContent( DynamicType.TaskPublish, taskInfo.PeriodId, taskInfo.Id, "", "", taskPushUserInfo?.UserName, taskPushUserInfo?.GroupName, taskInfo.CreateUser, taskInfo.TaskName, taskInfo.Score, taskInfo.UserNumber, taskInfo.LootTime); trans.Commit(); } catch (Exception e) { trans.Rollback(); throw new Exception("保存事务失败", e); } } #region 发送新任务提醒 if (request.IsOk) { //通过发所有人 var usersIds = await _iUserStore.GetUserInfos().Where(w => !w.IsDelete && !string.IsNullOrWhiteSpace(w.UserId)).Select(s => s.UserId).ToListAsync(); if (usersIds.Any()) { _hellperEmail.SendEmpPush($"《{periodInfo.Caption}》中有新任务发布啦![{taskInfo.TaskState == 0}]", $"尊敬的勇士您好:{dynamicContent}{taskInfo.LootTime.ToString("yyyy-MM-dd HH:mm:ss")}开抢,赶紧去看看吧。", usersIds); } } else { //驳回发给发起人 var usersIds = await _iUserStore.GetUserInfos().Where(w => !w.IsDelete && taskInfo.CreateUser == w.Id && !string.IsNullOrWhiteSpace(w.UserId)).Select(s => s.UserId).ToListAsync(); if (usersIds.Any()) { _hellperEmail.SendEmpPush($"您发布的任务《{(taskInfo.TaskName.Length>10? taskInfo.TaskName.Substring(0, 10)+"...":taskInfo.TaskName.Substring(0,10))}》被驳回", $"尊敬的勇士您好:您发布的任务《{taskInfo.TaskName}》被驳回,因为:{taskInfo.ExamineMemo},赶紧去看看吧。", usersIds); } } #endregion return(response); }