Example #1
0
        private static Response Excute(List <GameGroup> gplist)
        {
            if (gplist.IsNullOrEmpty())
            {
                return(ResultHelper.Fail("无数据。"));
            }
            //检查比赛状态,比赛准备才允许小组抽签
            var firstGroup = gplist.First();

            var game = GameHelper.GetGame(firstGroup.GameId);

            if (game.State != GameState.PREPARE.Id)
            {
                return(ResultHelper.Fail("比赛准备才能进行小组抽签。"));
            }

            bool isRoundThenKnock = game.KnockoutOption == KnockoutOption.ROUND_KNOCKOUT.Id;

            //先循环后淘汰,验证组成员
            if (isRoundThenKnock)
            {
                var firstOrder = GameHelper.GetGameOrder(firstGroup.OrderId);
                //根据OrderNo排序
                foreach (var group in gplist)
                {
                    //验证小组人数不足出线人数
                    if (group.MemberList.Count < firstOrder.KnockoutCountAB)
                    {
                        return(ResultHelper.Fail(string.Format("{0}人数不足要求出线人数{1}个,无法保存。", group.Name, firstOrder.KnockoutCount)));
                    }
                    group.MemberList = group.MemberList.OrderBy(p => p.OrderNo).ToList();
                }
            }

            var memberEntities = new List <EntityBase>();
            var loopEntities   = new List <EntityBase>();

            foreach (var group in gplist)
            {
                if (group.MemberList.IsNotNullOrEmpty())
                {
                    //先循环后淘汰,创建组成员
                    if (isRoundThenKnock)
                    {
                        CreateOneGroupMembers(memberEntities, group);
                    }
                    //创建组循环赛
                    CreateOneGroupLoops(loopEntities, group);
                }
            }

            //合并数据
            var entities = new List <EntityBase>();

            //先循环后淘汰,保存组成员
            if (isRoundThenKnock && memberEntities.IsNotNullOrEmpty())
            {
                entities.AddRange(memberEntities);
            }
            if (loopEntities.IsNotNullOrEmpty())
            {
                entities.AddRange(loopEntities);
            }

            var cmdSave = CommandHelper.CreateSave(entities);

            //删除原来生成的小组赛轮次表,后面重新生成
            var cmdDelete = CommandHelper.CreateProcedure(FetchType.Execute, "sp_DeleteGameGroup");

            cmdDelete.Params.Add("@GameId", gplist.First().GameId);
            cmdDelete.Params.Add("@GroupIdString", GetGroupIdString(gplist));
            cmdSave.PreCommands.Add(cmdDelete);

            return(DbContext.GetInstance().Execute(cmdSave));
        }
Example #2
0
        /// <summary>
        /// 第二轮淘汰赛,保存按人抽签
        /// </summary>
        /// <param name="request">Request.GameOrder.Entities</param>
        /// <returns>Response.EmptyEntity</returns>
        public Response Execute(string request)
        {
            var req  = JsonConvert.DeserializeObject <Request <GameOrder> >(request);
            var temp = req.FirstEntity();

            //验证数据
            var valResult = Validate(temp);

            if (!valResult.IsSuccess)
            {
                return(valResult);
            }

            var firstOrder = GameHelper.GetGameOrder(req.Entities.First().Id);

            //设置新的位置列表
            firstOrder.PositionList = temp.PositionList;

            //缓存KnockOutAB,保存之前再恢复
            string tempKnockOutAB = firstOrder.KnockOutAB;

            firstOrder.KnockOutAB = temp.KnockOutAB.IsNotNullOrEmpty() ? temp.KnockOutAB : KnockOutAB.A;

            //设置AB选项
            var game = GameHelper.GetGame(firstOrder.GameId);

            firstOrder.SetKnockOutAB(game.IsKnockOutAB);

            var entities = new List <EntityBase>();
            //获取第二轮淘汰比赛所有场次(非附加赛)
            List <GameLoop> loopList = null;

            //获取第二轮编号(用于小组循环后淘汰)
            var actualNextOrderId = temp.KnockOutAB == KnockOutAB.B ? firstOrder.NextOrderBId : firstOrder.NextOrderId;

            if (firstOrder.KnockoutOption == KnockoutOption.ROUND.Id)
            {
                //小组循环后淘汰,设置本轮次结束,并获取下轮次比赛
                firstOrder.State = GameOrderState.FINISH.Id;
                firstOrder.SetRowModified();
                entities.Add(firstOrder);

                //获取第二轮比赛
                loopList = GameHelper.GetOrderLoopListNoExtra(actualNextOrderId);
            }
            else
            {
                //单淘汰,获取第一轮比赛
                var cmd = CommandHelper.CreateText <GameLoop>();
                cmd.Text = "SELECT * FROM GameLoop WHERE GameId=@gameId AND OrderId=@orderId AND IsExtra=0 AND ISNULL(KnockLoopId,'')='' ORDER BY OrderNo";
                cmd.Params.Add("@gameId", firstOrder.GameId);
                cmd.Params.Add("@orderId", firstOrder.Id);
                loopList = DbContext.GetInstance().Execute(cmd).Entities.ToList <EntityBase, GameLoop>();
            }
            //将相邻位置球员进入对应场次比赛
            SetEnterKnockPos(firstOrder, entities, loopList);

            var cmdSave = CommandHelper.CreateSave(entities);
            //保存之前删除原来抢位赛(单淘汰为第一轮,小组循环后为第二轮)
            var cmdDelete = CommandHelper.CreateText(FetchType.Execute, "DELETE FROM GameLoop WHERE GameId=@gameId AND OrderId=@orderId AND ISNULL(KnockLoopId,'')!=''");

            cmdDelete.Params.Add("@gameId", firstOrder.GameId);
            cmdDelete.Params.Add("@orderId", firstOrder.KnockoutOption == KnockoutOption.ROUND.Id ? actualNextOrderId : firstOrder.Id);

            cmdSave.PreCommands = new List <Command> {
                cmdDelete
            };

            //保存前恢复firstOrder.KnockOutAB原数据(小组赛第一轮为空)
            firstOrder.KnockOutAB = tempKnockOutAB;

            return(DbContext.GetInstance().Execute(cmdSave));
        }
Example #3
0
        /// <summary>
        /// 定义首轮,并自动创建剩下轮次,可以形成拓扑图(小组赛不创建,创建淘汰赛轮次的所有比赛,附加赛)
        /// </summary>
        /// <param name="request">Request.GameOrder.Entities</param>
        /// <returns>Response.EmptyEntity</returns>
        public Response Execute(User currentUser, string request)
        {
            var req = JsonConvert.DeserializeObject <Request <GameOrder> >(request);

            var firstOrder = req.FirstEntity();

            if (firstOrder.RowState == RowState.Added)
            {
                firstOrder.SetNewId();
                firstOrder.SetCreateDate();
                firstOrder.State = GameOrderState.NOTSTART.Id;
            }
            var entities = new List <EntityBase> {
                firstOrder
            };

            var game = GameHelper.GetGame(firstOrder.GameId);

            //设置第一轮KnockoutOption
            firstOrder.IsTeam         = game.IsTeam;
            firstOrder.KnockoutOption = game.KnockoutOption == KnockoutOption.ROUND_KNOCKOUT.Id ? KnockoutOption.ROUND.Id : game.KnockoutOption;

            if (game.KnockoutOption == KnockoutOption.ROUND.Id)
            {
                //单循环赛
                var filter = new GetGameTeamListFilter {
                    GameId = game.Id, PageIndex = 1, PageSize = 10000
                };
                var teamList = GameHelper.GetGameTeamList(filter).Entities.ToList <EntityBase, GameTeam>();
                if (teamList.Count < 2)
                {
                    return(ResultHelper.Fail("至少2支参赛队才能建立单循环赛!"));
                }
                CreateSingleRound(firstOrder, entities, game, teamList);
            }
            else
            {
                //单淘汰赛,先循环后淘汰赛

                //设置AB模式选项
                firstOrder.SetKnockOutAB(game.IsKnockOutAB);

                //验证数据
                var valResult = Validate(game, firstOrder);
                if (!valResult.IsSuccess)
                {
                    return(ResultHelper.Fail(valResult.Message));
                }

                //设置第一轮数据
                int orderNo = 1;//大轮次序号,从1开始
                firstOrder.OrderNo = orderNo;
                firstOrder.Name    = string.Format(firstOrder.KnockoutOption == KnockoutOption.ROUND.Id ? "小组赛" : "1/{1}决赛", firstOrder.OrderNo, firstOrder.GroupCount);

                //创建轮次,正常比赛,附加赛,合并数据
                var loopEntities  = new List <EntityBase>();
                var groupEntities = new List <EntityBase>();
                var extraEntities = new List <EntityBase>();
                CreateMoreOrderAndLoop(req, entities, firstOrder, game, orderNo, loopEntities, groupEntities);

                //初始化轮次计分模式
                entities.ForEach(p => (p as GameOrder).TeamScoreMode = TeamScoreMode.STANDARD.Id);

                if (firstOrder.TopNumber > 0)
                {
                    //决出名次验证
                    if (entities.Count < Math.Log(firstOrder.TopNumber, 2))
                    {
                        return(ResultHelper.Fail("决出名次大于轮次可决出名次。"));
                    }
                    CreateExtraGame(game, entities, firstOrder.TopNumber, extraEntities);
                }
                MergeData(entities, loopEntities, groupEntities, extraEntities);
            }
            //创建保存命令,并加入删除之前数据命令
            var cmdDelete = CommandHelper.CreateProcedure(FetchType.Execute, "sp_DeleteGameAllDetail");

            cmdDelete.Params.Add("@gameId", firstOrder.GameId);

            var cmdSave = CommandHelper.CreateSave(entities);

            cmdSave.PreCommands.Add(cmdDelete);

            return(DbContext.GetInstance().Execute(cmdSave));
        }
Example #4
0
        /// <summary>
        /// 更新比赛状态
        /// </summary>
        /// <param name="currentUser">忽略</param>
        /// <param name="request">Request.Game</param>
        /// <returns>Response.EmptyEntity</returns>
        public Response Execute(string request)
        {
            var req  = JsonConvert.DeserializeObject <Request <Game> >(request);
            var game = req.Entities.FirstOrDefault();
            //进行中的比赛不能取消
            var dbGame = GameHelper.GetGame(game.Id);

            if (game.State.GetId() == GameState.CANCEL.Id && dbGame.State.GetId() == GameState.PROCESSING.Id)
            {
                return(ResultHelper.Fail("进行中的比赛不能取消"));
            }
            //状态更新
            var cmd = CommandHelper.CreateProcedure(FetchType.Execute, "sp_SetGameState");

            cmd.Params.Add("@gameId", game.Id);
            cmd.Params.Add("@state", game.State.GetId());
            cmd.CreateParamMsg();
            var result = DbContext.GetInstance().Execute(cmd);

            ///////////////////////////////////////////////////////////////////////
            if (result.IsSuccess)//假如是赛事正常结束状态,则更新选中团体模板的使用数量
            {
                bool flag = false;
                if (result.OutParams.Count <= 0)
                {
                    flag = true;
                }
                else
                {
                    string outValue = result.OutParams[0].value.ToString();
                    if (string.IsNullOrEmpty(outValue))
                    {
                        flag = true;
                    }
                }
                if (game.State == GameState.FINISH.Id) //比赛结束时 015005 ,更改模板使用次数
                {
                    if (flag)                          //假如输出参数有值,则表示不能结束比赛,不更新模板次数
                    {
                        var cmd2 = CommandHelper.CreateText <Game>(FetchType.Fetch, "SELECT TeamMode FROM Game WHERE Id=@gameId");
                        cmd2.Params.Add("@gameId", game.Id);
                        var    res2      = DbContext.GetInstance().Execute(cmd2);
                        string templetId = (res2.Entities[0] as Game).TeamMode;//模板ID
                        if (!string.IsNullOrEmpty(templetId))
                        {
                            GameLoopTempletHelper.UpdateTempletUseCount(templetId, "");
                        }
                    }
                }
                ///////////////////////////////////////////////////////////////////////////////////////
                try
                {
                    if (flag)//根据返回输出参数判断,是否能更改状态,不空为不能更改
                    {
                        var state = GameState.Find(game.State.GetId());
                        var msg   = string.Format("您参加的[{0}] 比赛[{1}]。", game.Name, state.Name);
                        JPushHelper.SendNotify(MasterType.GAME.Id, game.Id, msg, GameHelper.GetAllUserIdList(game.Id));
                    }
                }
                catch (Exception)
                {
                }
            }

            return(result);
        }
        /// <summary>
        /// 获取某大轮次下面所有比赛场次,正赛/附加赛
        /// </summary>
        /// <param name="request">Request.GetGameOrderLoopListFilter.Filter</param>
        /// <returns>Response.GameLoop</returns>
        public Response Execute(string request)
        {
            var req = JsonConvert.DeserializeObject <Request <GetGameOrderLoopListFilter> >(request);

            if (string.IsNullOrEmpty(req.Filter.GameId))
            {
                return(ResultHelper.Fail("赛事ID未上传"));
            }
            Command cmd = null;

            if (req.Filter.PageIndex <= 0)
            {
                cmd = CommandHelper.CreateProcedure <GameLoop>(text: "sp_GetGameOrderLoopList");
            }
            else
            {
                cmd = CommandHelper.CreateProcedure <GameLoop>(text: "sp_GetGameOrderLoopListPage");
                cmd.CreateParamPager(req.Filter);
            }

            cmd.Params.Add(CommandHelper.CreateParam("@gameId", req.Filter.GameId));
            cmd.Params.Add(CommandHelper.CreateParam("@knockOutAB", req.Filter.KnockOutAB));
            cmd.Params.Add(CommandHelper.CreateParam("@orderId", req.Filter.OrderId));
            cmd.Params.Add(CommandHelper.CreateParam("@groupId", req.Filter.GroupId));
            cmd.Params.Add(CommandHelper.CreateParam("@isExtra", req.Filter.IsExtra));
            cmd.Params.Add(CommandHelper.CreateParam("@groupOrderNo", req.Filter.GroupOrderNo));
            cmd.Params.Add(CommandHelper.CreateParam("@orderNo", req.Filter.OrderNo));

            cmd.Params.Add(CommandHelper.CreateParam("@startTime", req.Filter.StartTime));
            string endTime = req.Filter.EndTime;

            if (!string.IsNullOrEmpty(endTime))
            {
                endTime = DateTime.Parse(endTime).AddDays(1).ToString("yyyy-MM-dd");
            }

            cmd.Params.Add(CommandHelper.CreateParam("@endTime", endTime));
            cmd.Params.Add(CommandHelper.CreateParam("@team1Id", req.Filter.Team1Id));
            if (req.Filter.Team1Id == req.Filter.Team2Id)
            {
                cmd.Params.Add(CommandHelper.CreateParam("@team2Id", ""));
            }
            else
            {
                cmd.Params.Add(CommandHelper.CreateParam("@team2Id", req.Filter.Team2Id));
            }

            cmd.Params.Add(CommandHelper.CreateParam("@tableNo", req.Filter.TableNo));


            var result = DbContext.GetInstance().Execute(cmd);

            result.SetRowCount();
            GetGameLoopDetailListFilter detailFilter = new GetGameLoopDetailListFilter();//查询每次对阵的小局详情模型

            foreach (var item in result.Entities)
            {
                GameLoop gl = item as GameLoop;
                if (gl.IsTeam)
                {
                    gl.DetailList = GameHelper.GetLoopMapByLoop(gl.Id);//取LOOPMAP里的大分数据
                }
                else
                {
                    detailFilter.LoopId = gl.Id;
                    try
                    {
                        var tempResut = GameHelper.GetGameLoopDetailList(detailFilter).Entities;
                        gl.DetailList = tempResut.ToList <EntityBase, GameLoopDetail>();
                    }
                    catch { }
                }
            }

            return(result);
        }
Example #6
0
        /// <summary>
        /// 单打比赛保存比赛结果详情,每次保存一次对阵结果,单打比赛要设置比赛结束
        /// </summary>
        /// <param name="currentUser">忽略</param>
        /// <param name="request">Request.GameLoop.Entities</param>
        /// <returns>Response.EmptyEntity</returns>
        public Response Execute(string request)
        {
            var req  = JsonConvert.DeserializeObject <Request <GameLoop> >(request);
            var temp = req.FirstEntity();

            //非轮空,非双方弃权,需要胜方签名
            if (!temp.IsBye && temp.WaiverOption != WaiverOption.AB && Ext.IsNullOrEmpty(temp.WinSign))
            {
                return(ResultHelper.Fail("非轮空,非双方弃权,需要胜方签名。"));
            }

            var loop = GameHelper.GetLoop(temp.Id);

            //从数据库取出,重新赋值
            loop.IsBye        = req.Entities.First().IsBye;
            loop.State        = GameLoopState.FINISH.Id;
            loop.DetailList   = temp.DetailList;
            loop.WaiverOption = temp.WaiverOption.GetId();
            loop.WinSign      = temp.WinSign;
            loop.JudgeSign    = temp.JudgeSign;
            //更新结束时间
            loop.EndTime = DateTime.Now;
            if (loop.StartTime == null)
            {
                loop.StartTime = loop.EndTime;
            }
            loop.SetRowModified();

            loop.Team1Id = loop.Team1Id.GetId();
            loop.Team2Id = loop.Team2Id.GetId();

            var     entities = new List <EntityBase>();
            IWaiver waiver   = new OneWaiver();

            if (loop.WaiverOption.IsNotNullOrEmpty())
            {
                waiver.SetWaiver(loop);
            }
            else
            {
                waiver.SetScore(loop);
                var order = GameHelper.GetGameOrder(loop.OrderId.GetId());

                int max = loop.Game1 > loop.Game2 ? loop.Game1 : loop.Game2;
                if (max != order.WinGame)
                {
                    //个人比赛胜局检查
                    return(ResultHelper.Fail(string.Format("胜方需要赢{0}局。", order.WinGame)));
                }

                foreach (var item in loop.DetailList)
                {
                    //item.SetNewEntity();
                    item.LoopId = loop.Id.GetId();
                    int maxFen = item.Fen1 > item.Fen2 ? item.Fen1 : item.Fen2;
                    if (maxFen >= 11)                      //大致判小局分数是否有效
                    {
                        item.RowState = RowState.Modified; //获取小局对阵列表时,已经生成空对阵,故此处只需要保存相应小局的得分,状态更改为修改状态
                        entities.Add(item);
                    }
                    entities.Add(item);
                }
            }

            entities.Add(loop);
            SetNextLoopUser(loop, entities);

            var cmdSave = CommandHelper.CreateSave(entities);
            //cmdSave.PreCommands = new List<Command> { GameHelper.GetDeleteLoopDetailCmd(loop.Id, null) };//此处不需要再删除原有的对阵
            //更新个人积分
            var cmdUpdateScore = CommandHelper.CreateProcedure(FetchType.Execute, "sp_UpdateGameSportScoreForOne");

            cmdUpdateScore.Params.Add("@GameId", loop.GameId);
            cmdUpdateScore.Params.Add("@LoopId", loop.Id.GetId());
            cmdSave.AfterCommands = new List <Command> {
                cmdUpdateScore
            };


            return(DbContext.GetInstance().Execute(cmdSave));
        }
        /// <summary>
        /// 团体比赛设置一次对阵比赛结果
        /// </summary>
        /// <param name="request">Request.GameLoopMap.Entities</param>
        /// <returns>Response.EmptyEntity</returns>
        public Response Execute(string request)
        {
            var req = JsonConvert.DeserializeObject <Request <GameLoopMap> >(request);
            var map = req.FirstEntity();

            if (map == null)
            {
                return(ResultHelper.Fail("没有传递数据对象。"));
            }

            map.Team1Id   = map.Team1Id.GetId();
            map.Team2Id   = map.Team2Id.GetId();
            map.WinSign   = map.WinSign;
            map.JudgeSign = map.JudgeSign;

            map.SetRowModified();
            var entities = new List <EntityBase> {
                map
            };

            IWaiver waiver = new MapWaiver();

            if (map.WaiverOption.IsNotNullOrEmpty())
            {
                waiver.SetWaiver(map);
            }
            else
            {
                waiver.SetScore(map);
                var order = GameHelper.GetGameOrderByLoop(map.LoopId.GetId());

                int max = map.Game1 > map.Game2 ? map.Game1 : map.Game2;

                //取胜局(乒超团队模式每场胜局不一样)
                var winGame = map.WinGame > 0 ? map.WinGame : order.WinGame;
                //南充比赛临时要求更改
                //if (!map.User1Id.Contains(",") && !map.User2Id.Contains(",")) //南充比赛临时要求更改,双打不检查胜局
                //{
                if (max != winGame)
                {
                    //个人比赛胜局检查
                    return(ResultHelper.Fail(string.Format("胜方需要赢{0}局。", winGame)));
                }
                //}


                foreach (var item in map.DetailList)
                {
                    //item.SetNewEntity();
                    item.LoopId = map.LoopId.GetId();
                    item.MapId  = map.Id.GetId();

                    int maxFen = item.Fen1 > item.Fen2 ? item.Fen1 : item.Fen2;
                    if (maxFen >= 11)                      //大致判小局分数是否有效
                    {
                        item.RowState = RowState.Modified; //获取小局对阵列表时,已经生成空对阵,故此处只需要保存相应小局的得分,状态更改为修改状态
                        entities.Add(item);
                    }
                }
            }

            var cmdSave = CommandHelper.CreateSave(entities);

            //cmdSave.PreCommands = new List<Command> { GameHelper.GetDeleteLoopDetailCmd(map.LoopId, map.Id) };//此处不需要再删除原有的对阵

            return(DbContext.GetInstance().Execute(cmdSave));
        }
Example #8
0
        /// <summary>
        /// 参赛队伍报名
        /// </summary>
        /// <param name="currentUser">忽略</param>
        /// <param name="request">Request.GameTeam</param>
        /// <returns>Response.EmptyEntity</returns>
        public Response Execute(User currentUser, string request)
        {
            var req  = JsonConvert.DeserializeObject <Request <GameTeam> >(request);
            var team = req.Entities.FirstOrDefault();

            //////////////////团体对阵时增加对阵模板上场人数与队员人数比较/////////////////////
            if (team.IsTeam)
            {
                bool flag = GameLoopTempletHelper.IsJoinGame(team.GameId, team.TeamUserId);
                if (!flag)
                {
                    return(ResultHelper.Fail("参赛队伍人数少于团体对阵模板最少人数"));
                }
            }

            ////////////////////////////////////////////////////////////////////
            team.AuditorId = team.AuditorId.GetId();
            team.CreatorId = team.CreatorId.GetId();
            team.GameId    = team.GameId.GetId();
            team.State     = team.State.GetId();
            team.CompanyId = team.CompanyId.GetId();
            if (team.TeamName.IsNullOrEmpty())
            {
                team.TeamName = team.TeamUserName;
            }
            if (string.IsNullOrEmpty(team.NationalId))
            {
                team.NationalId = "flag_china@2x";//默认是中国
            }
            var entities = new List <EntityBase> {
                team
            };

            if (team.RowState == RowState.Added)
            {
                team.SetNewId();
                team.SetCreateDate();
                if (team.CreatorId.IsNullOrEmpty())
                {
                    team.CreatorId = currentUser.Id;
                }
                //如果没有设置头像,则使用当前创建者的头像
                SetHeadUrl(team.CreatorId, team);
            }

            var resultCheck = Validate(team, team.CreatorId.GetId());//待加入存在未支付消费的验证

            if (!resultCheck.IsSuccess)
            {
                return(ResultHelper.Fail(resultCheck.Message));
            }

            team.ModifyHeadIcon();
            var result = DbContext.GetInstance().Execute(CommandHelper.CreateSave(entities));

            try
            {
                var game = GameHelper.GetGame(team.GameId);
                var msg  = string.Format("有参赛人员[{0}]报名,请及时审核资格。", team.TeamName);
                JPushHelper.SendNotify(MasterType.GAME.Id, game.Id, msg, new List <string> {
                    game.CreatorId
                });
            }
            catch (Exception)
            {
            }
            return(result);
        }