/// <summary>
        /// 增量同步所有赛事配置至赛事实例
        /// </summary>
        /// <param name="matchInstance"></param>
        /// <returns></returns>
        public async Task ReSyncMatchInstanceResource(MatchInstance matchInstance)
        {
            //专业分类;
            var majorMapDic = matchInstance.GetData <Dictionary <int, int> >("MajorMapDic");//专业分类新老id配对
            var majors      = await _majorRepository.GetAll().Where(o => o.MatchId == matchInstance.MatchId).ToListAsync();

            foreach (var major in majors.Where(o => o.ParentId == null))
            {
                Major newMajor = null;
                //是否已存在已同步的专业
                if (majorMapDic.ContainsKey(major.Id))
                {
                    //更新原有赛事实例专业
                    newMajor = await _majorRepository.GetAsync(majorMapDic[major.Id]);

                    newMajor.LoadFrom(major);
                    newMajor.MatchId         = null;
                    newMajor.MatchInstanceId = matchInstance.Id;
                    await _majorRepository.UpdateAsync(newMajor);
                }
                else
                {
                    //新增赛事实例专业
                    newMajor                 = new Major(major);
                    newMajor.MatchId         = null;
                    newMajor.MatchInstanceId = matchInstance.Id;
                    await _majorRepository.InsertAsync(newMajor);
                }
                await CurrentUnitOfWork.SaveChangesAsync();

                majorMapDic[major.Id] = newMajor.Id;
                //子级
                foreach (var subMajor in majors.Where(o => o.ParentId == major.Id))
                {
                    Major newSubMajor = null;
                    //是否已存在已同步的专业
                    if (majorMapDic.ContainsKey(subMajor.Id))
                    {
                        //更新原有赛事实例专业
                        newSubMajor = await _majorRepository.GetAsync(majorMapDic[subMajor.Id]);

                        newSubMajor.LoadFrom(subMajor);
                        newSubMajor.MatchId         = null;
                        newSubMajor.MatchInstanceId = matchInstance.Id;
                        newSubMajor.ParentId        = newMajor.Id;
                        await _majorRepository.UpdateAsync(newSubMajor);
                    }
                    else
                    {
                        //新增赛事实例专业
                        newSubMajor                 = new Major(subMajor);
                        newSubMajor.MatchId         = null;
                        newSubMajor.MatchInstanceId = matchInstance.Id;
                        newSubMajor.ParentId        = newMajor.Id;
                        await _majorRepository.InsertAsync(newSubMajor);
                    }
                    await CurrentUnitOfWork.SaveChangesAsync();

                    majorMapDic[subMajor.Id] = newSubMajor.Id;
                    //三级
                    foreach (var thirdMajor in majors.Where(o => o.ParentId == subMajor.Id))
                    {
                        Major newThirdMajor = null;
                        //是否已存在已同步的专业
                        if (majorMapDic.ContainsKey(thirdMajor.Id))
                        {
                            //更新原有赛事实例专业
                            newThirdMajor = await _majorRepository.GetAsync(majorMapDic[thirdMajor.Id]);

                            newThirdMajor.LoadFrom(thirdMajor);
                            newThirdMajor.MatchId         = null;
                            newThirdMajor.MatchInstanceId = matchInstance.Id;
                            newThirdMajor.ParentId        = newSubMajor.Id;
                            await _majorRepository.UpdateAsync(newThirdMajor);
                        }
                        else
                        {
                            //新增赛事实例专业
                            newThirdMajor                 = new Major(thirdMajor);
                            newThirdMajor.MatchId         = null;
                            newThirdMajor.MatchInstanceId = matchInstance.Id;
                            newThirdMajor.ParentId        = newSubMajor.Id;
                            await _majorRepository.InsertAsync(newThirdMajor);
                        }
                        await CurrentUnitOfWork.SaveChangesAsync();

                        majorMapDic[thirdMajor.Id] = newThirdMajor.Id;
                    }
                }
            }
            //奖项
            var prizeMapDic = matchInstance.GetData <Dictionary <int, int> >("PrizeMapDic");//奖项新老id配对
            var prizes      = await _prizeRepository.GetAll().Include(o => o.PrizeSubMajors).Where(o => o.MatchId == matchInstance.MatchId).ToListAsync();

            foreach (var prize in prizes)
            {
                Prize newPrize = null;
                //是否已存在已同步的奖项
                if (prizeMapDic.ContainsKey(prize.Id))
                {
                    newPrize = await _prizeRepository.GetAsync(prizeMapDic[prize.Id]);

                    newPrize.PrizeName       = prize.PrizeName;
                    newPrize.PrizeType       = prize.PrizeType;
                    newPrize.ExtensionData   = prize.ExtensionData;
                    newPrize.Remarks         = prize.Remarks;
                    newPrize.IsActive        = prize.IsActive;
                    newPrize.MatchInstanceId = matchInstance.Id;
                    newPrize.MajorId         = majorMapDic[prize.MajorId];
                }
                else
                {
                    newPrize = new Prize()
                    {
                        PrizeName       = prize.PrizeName,
                        PrizeType       = prize.PrizeType,
                        ExtensionData   = prize.ExtensionData,
                        Remarks         = prize.Remarks,
                        IsActive        = prize.IsActive,
                        MatchInstanceId = matchInstance.Id,
                        MajorId         = majorMapDic[prize.MajorId]
                    };
                    await _prizeRepository.InsertAsync(newPrize);
                }
                await CurrentUnitOfWork.SaveChangesAsync();

                prizeMapDic[prize.Id] = newPrize.Id;
                foreach (var prizeSubMajor in prize.PrizeSubMajors)
                {
                    var newPrizeSubMajor = await _prizeSubMajorRepository.GetAll()
                                           .Where(o => o.PrizeId == newPrize.Id && o.MajorId == majorMapDic[prizeSubMajor.MajorId]).FirstOrDefaultAsync();

                    if (newPrizeSubMajor == null)
                    {
                        newPrizeSubMajor = new PrizeSubMajor()
                        {
                            PrizeId = newPrize.Id,
                            MajorId = majorMapDic[prizeSubMajor.MajorId],
                            Percent = prizeSubMajor.Percent,
                            Checked = prizeSubMajor.Checked,
                            Ratio   = prizeSubMajor.Ratio
                        };
                        await _prizeSubMajorRepository.InsertAsync(newPrizeSubMajor);
                    }
                    else
                    {
                        newPrizeSubMajor.Percent = prizeSubMajor.Percent;
                        newPrizeSubMajor.Checked = prizeSubMajor.Checked;
                        newPrizeSubMajor.Ratio   = prizeSubMajor.Ratio;
                        await _prizeSubMajorRepository.UpdateAsync(newPrizeSubMajor);
                    }
                }
            }
            //上传清单
            //下载清单
            //评分表
            //表单设计
            //先清空所有赛事资源
            await _matchResourceRepository.DeleteAsync(o => o.MatchId == null && o.MatchInstanceId == matchInstance.Id);

            var matchResources = await _matchResourceRepository.GetAll().Where(o => o.MatchId == matchInstance.MatchId).ToListAsync();

            foreach (var matchResource in matchResources)
            {
                var newMatchResource = new MatchResource()
                {
                    MatchInstanceId     = matchInstance.Id,
                    MajorId             = majorMapDic[matchResource.MajorId],
                    MatchResourceStatus = matchResource.MatchResourceStatus,
                    MatchResourceType   = matchResource.MatchResourceType,
                    ExtensionData       = matchResource.ExtensionData,
                };
                if (matchResource.SubMajorId != null)
                {
                    newMatchResource.SubMajorId = majorMapDic[matchResource.SubMajorId.Value];
                }
                await _matchResourceRepository.InsertAsync(newMatchResource);
            }
            //保存映射关系
            matchInstance.SetData("MajorMapDic", majorMapDic);
            matchInstance.SetData("PrizeMapDic", prizeMapDic);

            return;
        }
        /// <summary>
        /// 同步所有赛事配置至赛事实例
        /// </summary>
        /// <param name="matchInstance"></param>
        /// <returns></returns>
        private async Task SyncMatchInstanceResource(MatchInstance matchInstance)
        {
            //专业分类;
            var majorMapDic = new Dictionary <int, int>();//专业分类新老id配对
            var majors      = await _majorRepository.GetAll().Where(o => o.MatchId == matchInstance.MatchId).ToListAsync();

            foreach (var major in majors.Where(o => o.ParentId == null))
            {
                var newMajor = new Major(major);
                newMajor.MatchId         = null;
                newMajor.MatchInstanceId = matchInstance.Id;
                await _majorRepository.InsertAsync(newMajor);

                await CurrentUnitOfWork.SaveChangesAsync();

                majorMapDic[major.Id] = newMajor.Id;
                //子级
                foreach (var subMajor in majors.Where(o => o.ParentId == major.Id))
                {
                    var newSubMajor = new Major(subMajor);
                    newSubMajor.MatchId         = null;
                    newSubMajor.MatchInstanceId = matchInstance.Id;
                    newSubMajor.ParentId        = newMajor.Id;
                    await _majorRepository.InsertAsync(newSubMajor);

                    await CurrentUnitOfWork.SaveChangesAsync();

                    majorMapDic[subMajor.Id] = newSubMajor.Id;
                    //三级
                    foreach (var thirdMajor in majors.Where(o => o.ParentId == subMajor.Id))
                    {
                        var newThirdMajor = new Major(thirdMajor);
                        newThirdMajor.MatchId         = null;
                        newThirdMajor.MatchInstanceId = matchInstance.Id;
                        newThirdMajor.ParentId        = newSubMajor.Id;
                        await _majorRepository.InsertAsync(newThirdMajor);

                        await CurrentUnitOfWork.SaveChangesAsync();

                        majorMapDic[thirdMajor.Id] = newThirdMajor.Id;
                    }
                }
            }
            //奖项
            var prizeMapDic = new Dictionary <int, int>();
            var prizes      = await _prizeRepository.GetAll().Include(o => o.PrizeSubMajors).Where(o => o.MatchId == matchInstance.MatchId).ToListAsync();

            foreach (var prize in prizes)
            {
                var newPrize = new Prize()
                {
                    PrizeName       = prize.PrizeName,
                    PrizeType       = prize.PrizeType,
                    ExtensionData   = prize.ExtensionData,
                    Remarks         = prize.Remarks,
                    IsActive        = prize.IsActive,
                    MatchInstanceId = matchInstance.Id,
                    MajorId         = majorMapDic[prize.MajorId]
                };
                await _prizeRepository.InsertAsync(newPrize);

                await CurrentUnitOfWork.SaveChangesAsync();

                prizeMapDic[prize.Id] = newPrize.Id;

                foreach (var prizeSubMajor in prize.PrizeSubMajors)
                {
                    var newPrizeSubMajor = new PrizeSubMajor()
                    {
                        PrizeId = newPrize.Id,
                        MajorId = majorMapDic[prizeSubMajor.MajorId],
                        Percent = prizeSubMajor.Percent,
                        Checked = prizeSubMajor.Checked,
                        Ratio   = prizeSubMajor.Ratio
                    };
                    await _prizeSubMajorRepository.InsertAsync(newPrizeSubMajor);
                }
            }
            //上传清单
            //下载清单
            //评分表
            //表单设计
            var matchResources = await _matchResourceRepository.GetAll().Where(o => o.MatchId == matchInstance.MatchId).ToListAsync();

            foreach (var matchResource in matchResources)
            {
                var newMatchResource = new MatchResource()
                {
                    MatchInstanceId     = matchInstance.Id,
                    MajorId             = majorMapDic[matchResource.MajorId],
                    MatchResourceStatus = matchResource.MatchResourceStatus,
                    MatchResourceType   = matchResource.MatchResourceType,
                    ExtensionData       = matchResource.ExtensionData,
                };
                if (matchResource.SubMajorId != null)
                {
                    newMatchResource.SubMajorId = majorMapDic[matchResource.SubMajorId.Value];
                }
                await _matchResourceRepository.InsertAsync(newMatchResource);
            }

            //保存映射关系
            matchInstance.SetData("MajorMapDic", majorMapDic);
            matchInstance.SetData("PrizeMapDic", prizeMapDic);
            return;
        }