using IRaCIS.Core.Domain.Share;
using Microsoft.AspNetCore.Mvc;
using IRaCIS.Core.Application.Service.Reading.Dto;
using MassTransit;
using IRaCIS.Core.Infra.EFCore.Common;
using Panda.DynamicWebApi.Attributes;
using AutoMapper;
using IRaCIS.Core.Application.Contracts;
using IRaCIS.Core.Infrastructure;
using Newtonsoft.Json;
using IRaCIS.Core.Application.Service;
using IRaCIS.Core.Application.ViewModel;

namespace IRaCIS.Application.Services
{
  
    /// <summary>
    /// 裁判
    /// </summary>
    public partial class ReadingImageTaskService : BaseService, IReadingImageTaskService
    {
        #region 配置裁判问题相关

        /// <summary>
        /// 获取项目标准的裁判问题
        /// </summary>
        /// <param name="inDto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<(List<GetTrialCriterionJudgeQuestionListOutDto>, object)> GetTrialCriterionJudgeQuestionList(GetTrialCriterionJudgeQuestionListInDto inDto)
        {
            var trialCriterion = await _readingQuestionCriterionTrialRepository.Where(x => x.Id == inDto.TrialReadingCriterionId).FirstNotNullAsync();

            var result = await _readingQuestionTrialRepository.Where(x => x.ReadingQuestionCriterionTrialId == inDto.TrialReadingCriterionId && x.IsJudgeQuestion)
                  .WhereIf(trialCriterion.FormType == FormType.SinglePage, x => x.ReadingCriterionPageId == null)
                 .WhereIf(trialCriterion.FormType == FormType.MultiplePage, x => x.ReadingCriterionPageId != null)
                .Select(x => new GetTrialCriterionJudgeQuestionListOutDto()
                {
                    AnswerGroup = JsonConvert.DeserializeObject<List<string>>(x.AnswerGroup.IsNullOrEmpty() ? "[]" : x.AnswerGroup),
                    AnswerCombination = JsonConvert.DeserializeObject<List<AnswerCombinationDto>>(x.AnswerCombination.IsNullOrEmpty() ? "[]" : x.AnswerCombination),
                    QuestionName = x.QuestionName,
                    PageName = x.ReadingCriterionPage.PageName,
                    TypeValue = x.TypeValue,
                    QuestionGenre=x.QuestionGenre,
                    DictionaryCode=x.DictionaryCode,
                    JudgeType = x.JudgeType,
                    ReadingQuestionTrialId = x.Id
                }).ToListAsync();


            return (result, new
            {
                IsSign = trialCriterion.ReadingInfoSignTime != null,
            });

        }

        /// <summary>
        /// 设置裁判问题的答案分组
        /// </summary>
        /// <param name="inDto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IResponseOutput> SetTrialCriterionJudgeQuestionAnswerGroup(SetTrialCriterionJudgeQuestionAnswerGroupInDto inDto)
        {
            await _readingQuestionTrialRepository.UpdatePartialFromQueryAsync(inDto.ReadingQuestionTrialId, x => new ReadingQuestionTrial()
            {
                AnswerGroup = JsonConvert.SerializeObject(inDto.AnswerGroup),
                AnswerCombination = JsonConvert.SerializeObject(inDto.AnswerCombination),
                JudgeType = inDto.JudgeType,
            });

            var result = await _readingQuestionTrialRepository.SaveChangesAsync();

            return ResponseOutput.Ok(result);
        }
        #endregion


        #region 获取裁判阅片任务信息
        /// <summary>
        /// 获取裁判阅片任务信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<GetJudgeReadingInfoOutDto> GetJudgeReadingInfo(GetJudgeReadingInfo inDto)
        {
            var visitTask = await _visitTaskRepository.Where(x => x.Id == inDto.VisitTaskId).FirstOrDefaultAsync();
            GetJudgeReadingInfoOutDto judgeInfo = new GetJudgeReadingInfoOutDto()
            {
                ReadingTaskState = visitTask.ReadingTaskState,
                JudgeResultTaskId = visitTask.JudgeResultTaskId,
                JudgeResultRemark = visitTask.JudgeResultRemark,
                JudgeResultImagePathList = visitTask.JudgeResultImagePathList,
                VisitInfoList = new List<JudgeReadingInfoDto>()
            };

            var judgeDataInfo = await _readingJudgeInfoRepository.Where(x => x.JudgeTaskId == inDto.VisitTaskId).FirstNotNullAsync();

            var taskids = new List<Guid>();

            taskids.Add(judgeDataInfo.TaskIdOne);
            taskids.Add(judgeDataInfo.TaskIdTwo);
            var taskList = await _visitTaskRepository.Where(x => taskids.Contains(x.Id)).OrderBy(x => x.ArmEnum).ToListAsync();
            judgeInfo.VisitTaskArmList = taskList.Select(x => new VisitTaskArm()
            {
                ArmEnum = x.ArmEnum,
                VisitTaskId = x.Id

            }).ToList();
            var visitIds = await _visitTaskRepository.Where(x => x.JudgeVisitTaskId == inDto.VisitTaskId).Select(x => new
            {
                x.Id,
                x.ArmEnum,
            }).ToListAsync();

            switch (taskList[0].ReadingCategory)
            {
                case ReadingCategory.Visit:
                    JudgeReadingInfoDto judgeReadingInfoDto = new JudgeReadingInfoDto()
                    {
                        VisitId = taskList[0].SourceSubjectVisitId.Value,
                        VisitName = taskList[0].TaskBlindName,
                        VisitTaskInfoList = new List<JudgeReadingQuestion>(),
                    };

                    foreach (var item in taskList)
                    {
                        judgeReadingInfoDto.VisitTaskInfoList.Add(new JudgeReadingQuestion()
                        {
                            ArmEnum = item.ArmEnum,
                            VisitTaskId = item.Id,
                            JudgeQuestionList = await _readingTaskQuestionAnswerRepository.Where(x => x.VisitTaskId == item.Id && x.ReadingQuestionTrial.IsJudgeQuestion).OrderBy(x => x.ReadingQuestionTrial.ShowOrder)
                        .Select(x => new JudgeQuestion()
                        {
                            Answer = x.Answer,
                            QuestionId = x.ReadingQuestionTrial.Id,
                            QuestionName = x.ReadingQuestionTrial.QuestionName,
                            QuestionGenre=x.ReadingQuestionTrial.QuestionGenre,
                            DictionaryCode=x.ReadingQuestionTrial.DictionaryCode,

                        }).ToListAsync(),
                        });
                    }
                    judgeInfo.VisitInfoList.Add(judgeReadingInfoDto);
                    break;

                case ReadingCategory.Global:
                    var taskOneInfo = await this.GetGlobalReadingInfo(new GetGlobalReadingInfoInDto()
                    {
                        UsingOriginalData = true,
                        VisitTaskId = taskList[0].Id
                    });

                    var taskTwoInfo = await this.GetGlobalReadingInfo(new GetGlobalReadingInfoInDto()
                    {
                        UsingOriginalData = true,
                        VisitTaskId = taskList[1].Id
                    });


                    foreach (var item in taskOneInfo.TaskList)
                    {
                        GlobalVisitInfo twoItem = taskTwoInfo.TaskList.Where(x => x.VisitId == item.VisitId).FirstOrDefault();

                        JudgeReadingInfoDto judgeReadingInfo = new JudgeReadingInfoDto()
                        {
                            VisitId = item.VisitId,
                            VisitName = item.VisitName,
                            VisitTaskInfoList = new List<JudgeReadingQuestion>(),
                        };

                        var judgeReadingQuestion = new JudgeReadingQuestion()
                        {
                            ArmEnum = item.ArmEnum,
                            VisitTaskId = item.VisitTaskId,
                            GlobalVisitTaskId = taskList[0].Id,
                            JudgeQuestionList = item.AfterQuestionList.Where(x => x.GlobalAnswerType== GlobalAnswerType.Question).Select(x => new JudgeQuestion()
                            {

                                Answer = x.Answer,
                                QuestionId = x.QuestionId.Value,
                                QuestionName = x.QuestionName,
                                QuestionGenre=x.QuestionGenre,
                                DictionaryCode=x.DictionaryCode,
                            }).ToList()
                        };



                        // 加全局是否更新 和访视点注释
                        judgeReadingQuestion.JudgeQuestionList.Add(new JudgeQuestion()
                        {
                            Answer = item.AfterQuestionList.Any(x => x.IsHaveChange),
                            QuestionType = JudgeReadingQuestionType.GlobalChange,

                        });

                        judgeReadingQuestion.JudgeQuestionList.Add(new JudgeQuestion()
                        {
                            Answer = item.AfterQuestionList.Where(x => x.GlobalAnswerType == GlobalAnswerType.Reason).Select(x => x.Answer).FirstOrDefault(),
                            QuestionType = JudgeReadingQuestionType.VisitRemark,
                            QuestionName = "全局阅片备注",
                        });

                        judgeReadingInfo.VisitTaskInfoList.Add(judgeReadingQuestion);
                        if (twoItem != null)
                        {
                            var rTwoJudge = new JudgeReadingQuestion()
                            {
                                ArmEnum = twoItem.ArmEnum,
                                VisitTaskId = twoItem.VisitTaskId,
                                GlobalVisitTaskId = taskList[1].Id,
                                JudgeQuestionList = twoItem.AfterQuestionList.Where(x => x.GlobalAnswerType == GlobalAnswerType.Question).Select(x => new JudgeQuestion()
                                {

                                    Answer = x.Answer,
                                    QuestionId = x.QuestionId.Value,
                                    QuestionName = x.QuestionName,
                                    QuestionGenre = x.QuestionGenre,
                                    DictionaryCode = x.DictionaryCode,
                                }).ToList()
                            };

                            // 加全局是否更新 和访视点注释
                            rTwoJudge.JudgeQuestionList.Add(new JudgeQuestion()
                            {
                                Answer = twoItem.AfterQuestionList.Any(x => x.IsHaveChange),
                                QuestionType = JudgeReadingQuestionType.GlobalChange,

                            });

                            rTwoJudge.JudgeQuestionList.Add(new JudgeQuestion()
                            {
                                Answer = twoItem.AfterQuestionList.Where(x => x.GlobalAnswerType == GlobalAnswerType.Reason).Select(x => x.Answer).FirstOrDefault(),
                                QuestionType = JudgeReadingQuestionType.VisitRemark,
                                QuestionName = "全局阅片备注",
                            });

                            judgeReadingInfo.VisitTaskInfoList.Add(rTwoJudge);
                        }

                        judgeInfo.VisitInfoList.Add(judgeReadingInfo);


                    }

                    break;
            }

            return judgeInfo;

        }
        #endregion

        #region 保存裁判问题
        /// <summary>
        /// 保存裁判问题
        /// </summary>
        /// <param name="inDto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IResponseOutput> SaveJudgeVisitTaskResult(SaveJudgeVisitTaskResult inDto)
        {
            await VerifyTaskIsSign(inDto.VisitTaskId);
            await _visitTaskRepository.UpdatePartialFromQueryAsync(inDto.VisitTaskId, x => new VisitTask()
            {
                JudgeResultTaskId = inDto.JudgeResultTaskId,
                JudgeResultRemark = inDto.JudgeResultRemark,
                JudgeResultImagePath = string.Join(',',inDto.JudgeResultImagePathList),

            });
            var result = await _visitTaskRepository.SaveChangesAsync();
            return ResponseOutput.Ok(result);
        }
        #endregion


        /// <summary>
        /// 提交裁判问题
        /// </summary>
        /// <param name="inDto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IResponseOutput> SubmitJudgeVisitTaskResult(SaveJudgeVisitTaskResult inDto)
        {
            await VerifyTaskIsSign(inDto.VisitTaskId);
            await _visitTaskRepository.UpdatePartialFromQueryAsync(inDto.VisitTaskId, x => new VisitTask()
            {
                JudgeResultTaskId = inDto.JudgeResultTaskId,
                ReadingTaskState = ReadingTaskState.HaveSigned,
                JudgeResultRemark = inDto.JudgeResultRemark,
                SignTime = DateTime.Now,
                JudgeResultImagePath = string.Join(',', inDto.JudgeResultImagePathList),
            });
            await _visitTaskRepository.SaveChangesAsync();
            // 需要判断是否添加肿瘤学任务
            var taskInfo = await _visitTaskRepository.Where(x => x.JudgeVisitTaskId == inDto.VisitTaskId).FirstNotNullAsync();
            if (taskInfo.ReadingCategory == ReadingCategory.Global)
            {
                if (taskInfo.SouceReadModuleId == null)
                {
                    throw new BusinessValidationFailedException($"当前裁判的全局任务的SouceId为null");
                }

                var visitId = await _readModuleRepository.Where(x => x.Id == taskInfo.SouceReadModuleId).Select(x => x.SubjectVisitId).FirstOrDefaultAsync();

                var oncologModuleId = await _readModuleRepository.Where(x => x.SubjectVisitId == visitId && x.ModuleType == ModuleTypeEnum.Oncology
                &&x.TrialReadingCriterionId== taskInfo.TrialReadingCriterionId
                ).Select(x => x.Id).FirstOrDefaultAsync();

                await AddOncologyTask(oncologModuleId);

            }


            var result = await _visitTaskRepository.SaveChangesAsync();
            return ResponseOutput.Ok(result);
        }

        /// <summary>
        /// 触发裁判任务(新)
        /// </summary>
        /// <param name="visitTaskId"></param>
        /// <returns></returns>
        public async Task TriggerJudgeQuestion(Guid visitTaskId)
        {
            List<Guid> visitTaskids = new List<Guid>();

            var visitTask = await _visitTaskRepository.Where(x => x.Id == visitTaskId).AsNoTracking().FirstNotNullAsync();

            // 判断是否是一致性核查产生
            if (visitTask.IsAnalysisCreate)
            {
                visitTaskids = await _visitTaskRepository.Where(x => x.ArmEnum == visitTask.ArmEnum && x.TaskState == TaskState.Effect && x.SourceSubjectVisitId == visitTask.SourceSubjectVisitId
                  &&x.TrialReadingCriterionId== visitTask.TrialReadingCriterionId
                  && x.SouceReadModuleId == visitTask.SouceReadModuleId && x.ReadingCategory != ReadingCategory.Judge && x.ReadingTaskState == ReadingTaskState.HaveSigned).Select(x => x.Id).ToListAsync();

            }
            else
            {
                // 这里是非一致性分析产生的
                visitTaskids = await _visitTaskRepository.Where(x => x.ReadingTaskState == ReadingTaskState.HaveSigned && x.ReadingCategory != ReadingCategory.Judge
                && x.TaskState == TaskState.Effect
                && x.TrialReadingCriterionId == visitTask.TrialReadingCriterionId
                && x.IsAnalysisCreate == false
                && x.SourceSubjectVisitId == visitTask.SourceSubjectVisitId && x.SouceReadModuleId == visitTask.SouceReadModuleId).Select(x => x.Id).ToListAsync();
            }


            var criterionInfo = await _readingQuestionCriterionTrialRepository.Where(x => x.Id == visitTask.TrialReadingCriterionId).Select(x => new
            {
                x.IsArbitrationReading,
                x.ArbitrationRule
            }).FirstNotNullAsync();

            var noteEqual = false;

            // 判断项目是否设置了裁判
            if (criterionInfo.IsArbitrationReading)
            {
                // 判断数量是否为2 是否仲裁
                if (visitTaskids.Count == 2)
                {
                    switch (visitTask.ReadingCategory)
                    {
                        // 访视
                        case ReadingCategory.Visit:
                            // 查找两个 访视的阅片答案
                            var query = from questionAnswet in _readingTaskQuestionAnswerRepository.Where(x => visitTaskids.Contains(x.VisitTaskId))
                                        join question in _readingQuestionTrialRepository.Where(x => x.IsJudgeQuestion) on new { ReadingQuestionTrialId = questionAnswet.ReadingQuestionTrialId } equals new { ReadingQuestionTrialId = question.Id }
                                        select new TaskAnswerDto()
                                        {
                                            Answer = questionAnswet.Answer,
                                            AnswerGroup = question.AnswerGroup,
                                            AnswerCombination = question.AnswerCombination,
                                            JudgeType = question.JudgeType,
                                            QuestionId = question.Id,
                                            VisitTaskId = questionAnswet.VisitTaskId,
                                        };
                            var questionAnswerlist = await query.ToListAsync();

                            // 将答案进行分组
                            List<GroupTaskAnswerDto> groupTasks = questionAnswerlist.GroupBy(x => new { x.QuestionId, x.AnswerGroup, x.JudgeType, x.AnswerCombination }).Select(x => new GroupTaskAnswerDto
                            {
                                QuestionId = x.Key.QuestionId,
                                AnswerGroup = x.Key.AnswerGroup,
                                AnswerCombination = x.Key.AnswerCombination,
                                JudgeType = x.Key.JudgeType,
                                TaskAnswerList = x.Select(y => y.Answer).ToList(),
                            }).ToList();
                            noteEqual = ComputeJudgeResult(groupTasks);
                            break;
                        case ReadingCategory.Global:
                            var taskOneInfo = await this.GetGlobalReadingInfo(new GetGlobalReadingInfoInDto()
                            {
                                UsingOriginalData = true,
                                VisitTaskId = visitTaskids[0]
                            });

                            var taskTwoInfo = await this.GetGlobalReadingInfo(new GetGlobalReadingInfoInDto()
                            {
                                UsingOriginalData = true,
                                VisitTaskId = visitTaskids[1]
                            });

                            // 判断两个任务是否
                            if (taskOneInfo.TaskList.Count() != taskTwoInfo.TaskList.Count())
                            {
                                noteEqual = true;
                            }
                            else
                            {
                                foreach (var item in taskOneInfo.TaskList)
                                {
                                    GlobalVisitInfo twoItem = taskTwoInfo.TaskList.Where(x => x.VisitId == item.VisitId).FirstOrDefault();

                                    if (twoItem == null)
                                    {
                                        noteEqual = true;
                                        break;
                                    }
                                    else
                                    {
                                        var newlist = item.AfterQuestionList.Where(x => x.QuestionId != null&&x.IsJudgeQuestion).ToList().Union(
                                            twoItem.AfterQuestionList.Where(x => x.QuestionId != null&&x.IsJudgeQuestion).ToList()
                                            ).ToList();

                                        List<GroupTaskAnswerDto> globalGroupTasks = newlist.GroupBy(x => new { x.QuestionId, x.AnswerGroup, x.JudgeType, x.AnswerCombination }).Select(x => new GroupTaskAnswerDto
                                        {
                                            QuestionId = x.Key.QuestionId.Value,
                                            AnswerGroup = x.Key.AnswerGroup,
                                            AnswerCombination = x.Key.AnswerCombination,
                                            JudgeType = x.Key.JudgeType,
                                            TaskAnswerList = x.Select(y => y.Answer).ToList(),
                                        }).ToList();
                                        noteEqual = noteEqual || ComputeJudgeResult(globalGroupTasks);
                                    }

                                }
                            }
                            break;
                    }

                }
                else
                {
                    // 这里判断一致性分析产生的全局阅片
                    if (visitTask.ReadingCategory == ReadingCategory.Global && visitTask.IsAnalysisCreate && (visitTask.IsSelfAnalysis ?? false))
                    {
                        var taskOneInfo = await this.GetGlobalReadingInfo(new GetGlobalReadingInfoInDto()
                        {
                            UsingOriginalData = true,
                            VisitTaskId = visitTask.Id
                        });

                        // 找到最后一个任务ID
                        var lastTask = taskOneInfo.TaskList.Last();

                        if (lastTask == null)
                        {
                            noteEqual = true;
                        }
                        else
                        {
                            var query = from questionAnswet in _readingTaskQuestionAnswerRepository.Where(x =>
                            x.VisitTask.IsAnalysisCreate == false &&
                            x.VisitTask.DoctorUserId == visitTask.DoctorUserId &&
                            x.VisitTask.TaskState == TaskState.Effect &&
                            (x.VisitTask.SourceSubjectVisitId ?? default(Guid)) == lastTask.VisitId)
                                        join question in _readingQuestionTrialRepository.Where(x => x.IsJudgeQuestion) on new { ReadingQuestionTrialId = questionAnswet.ReadingQuestionTrialId } equals new { ReadingQuestionTrialId = question.Id }
                                        select new GlobalQuestionInfo()
                                        {
                                            Answer = questionAnswet.Answer,
                                            AnswerGroup = question.AnswerGroup,
                                            AnswerCombination = question.AnswerCombination,
                                            JudgeType = question.JudgeType,
                                            QuestionId = question.Id,

                                        };

                            var visitTaskQuestions = await query.ToListAsync();

                            var newlist = visitTaskQuestions.Where(x => x.QuestionId != null).ToList().Union(
                                            lastTask.AfterQuestionList.Where(x => x.QuestionId != null).ToList()
                                            ).ToList();

                            List<GroupTaskAnswerDto> globalGroupTasks = newlist.GroupBy(x => new { x.QuestionId, x.AnswerGroup, x.JudgeType, x.AnswerCombination }).Select(x => new GroupTaskAnswerDto
                            {
                                QuestionId = x.Key.QuestionId.Value,
                                AnswerGroup = x.Key.AnswerGroup,
                                AnswerCombination = x.Key.AnswerCombination,
                                JudgeType = x.Key.JudgeType,
                                TaskAnswerList = x.Select(y => y.Answer).ToList(),
                            }).ToList();
                            noteEqual = noteEqual || ComputeJudgeResult(globalGroupTasks);
                        }


                    }
                }


            }




            if (noteEqual)
            {
                if (visitTask.IsAnalysisCreate)
                {
                    await _visitTaskRepository.BatchUpdateNoTrackingAsync(x => x.Id == visitTaskId, x => new VisitTask()
                    {
                        IsAnalysisDiffToOriginalData = true
                    });
                    await _visitTaskRepository.SaveChangesAsync();

                }
                else
                {

                    if ((visitTask.SourceSubjectVisitId != null && criterionInfo.ArbitrationRule == ArbitrationRule.Visit) || (visitTask.SouceReadModuleId != null && criterionInfo.ArbitrationRule == ArbitrationRule.Reading))
                    {
                        await this.SaveJudgeTask(new SaveJudgeTaskDto()
                        {
                            VisitTaskIds = visitTaskids,
                        });
                    }

                }

            }
            else
            {

                if (visitTask.IsAnalysisCreate)
                {
                    await _visitTaskRepository.BatchUpdateNoTrackingAsync(x => x.Id == visitTaskId, x => new VisitTask()
                    {
                        IsAnalysisDiffToOriginalData = false
                    });
                    await _visitTaskRepository.SaveChangesAsync();
                }
            }
        }




        /// <summary>
        /// 计算返回的结果  为True表示不相等
        /// </summary>
        /// <param name="groupTasks"></param>
        /// <returns></returns>
        private bool ComputeJudgeResult(List<GroupTaskAnswerDto> groupTasks)
        {
            var noteEqual = false;
            foreach (var item in groupTasks)
            {
                if (item.TaskAnswerList.Count() != 2)
                {
                    noteEqual = true;
                    break;
                }
                else
                {
                    var taskAnswer1 = item.TaskAnswerList[0];
                    var taskAnswer2 = item.TaskAnswerList[1];
                    if (taskAnswer1 != taskAnswer2)
                    {

                        switch (item.JudgeType)
                        {
                            case JudgeTypeEnum.AnswerDisaffinity:
                                noteEqual = true;
                                break;
                            case JudgeTypeEnum.AnswerGroup:
                                var answerGroupList = JsonConvert.DeserializeObject<List<string>>(item.AnswerGroup).Select(x => new AnswerGroup()
                                {
                                    GroupId = NewId.NextGuid(),
                                    GroupValue = x
                                }).ToList();
                                var itemAnswerGroupsitem1 = answerGroupList.Where(x => x.GroupValue.Contains($"|{taskAnswer1}|"));
                                var itemAnswerGroupsitem2 = answerGroupList.Where(x => x.GroupValue.Contains($"|{taskAnswer2}|"));
                                var unionList = itemAnswerGroupsitem1.Intersect(itemAnswerGroupsitem2).ToList();
                                if (unionList.Count < 1)
                                {
                                    noteEqual = true;
                                }
                                break;
                            case JudgeTypeEnum.AnswerCombination:
                                var answerCombinationList = JsonConvert.DeserializeObject<List<AnswerCombinationDto>>(item.AnswerCombination == string.Empty ? "[]" : item.AnswerCombination).ToList();
                                answerCombinationList.ForEach(x =>
                                {
                                    if (x.AnswerGroupA.Contains(taskAnswer1) && x.AnswerGroupB.Contains(taskAnswer2))
                                    {
                                        noteEqual = true;
                                    }
                                    if (x.AnswerGroupB.Contains(taskAnswer1) && x.AnswerGroupA.Contains(taskAnswer2))
                                    {
                                        noteEqual = true;
                                    }
                                });
                                break;
                            case JudgeTypeEnum.NotCalculate:
                                noteEqual = false;
                                break;
                        }
                    }
                }
            }

            return noteEqual;
        }

        /// <summary>
        /// 添加裁判任务
        /// </summary>
        /// <returns></returns>
        private async Task SaveJudgeTask(SaveJudgeTaskDto inDto)
        {
            var trialId = await _visitTaskRepository.Where(x => inDto.VisitTaskIds.Contains(x.Id)).Select(x => x.TrialId).FirstOrDefaultAsync();

            await _visitTaskHelpeService.AddTaskAsync(new GenerateTaskCommand()
            {
                JudgeVisitTaskIdList = inDto.VisitTaskIds,
                ReadingCategory = GenerateTaskCategory.Judge,
                TrialId = trialId
            });
        }
    }
}
