Пример #1
0
        public Response Execute(User currentUser, string request)
        {
            var res = GameLoopTempletHelper.GetTempletList(currentUser.Id, "", 2);

            res.SetRowCount();
            return(res);
        }
Пример #2
0
        public Response Execute(User currentUser, string request)
        {
            var      req = JsonConvert.DeserializeObject <Request <GameTeamLoopTempletFilter> >(request);
            Response res = GameLoopTempletHelper.GetTempletDetail(req.Filter);

            return(res);
        }
Пример #3
0
        public Response Execute(User currentUser, string request)
        {
            var req = JsonConvert.DeserializeObject <Request <GameTeamLoopTemplet> >(request);
            GameTeamLoopTemplet templet = req.FirstEntity();
            var res = GameLoopTempletHelper.SetTempletState(templet, currentUser);

            return(res);
        }
Пример #4
0
        public Response Execute(string request)
        {
            var req = JsonConvert.DeserializeObject <Request <GameTeamLoopTempletFilter> >(request);

            Response res = ResultHelper.Success();

            res.Tag  = GameLoopTempletHelper.IsExistTemplet(req.Filter.Name, req.Filter.ModifyFlag); //bool类型 ,TRUE为名称重复
            res.Tag1 = GameLoopTempletHelper.GetRuleCodes(req.Filter.PersonCount, true, true);       //队伍1(主队)对阵编码字符数组
            if (req.Filter.IsGuest)
            {
                res.Tag2 = GameLoopTempletHelper.GetRuleCodes(req.Filter.PersonCount, false, true);//队伍2(客队)对阵编码字符数组
            }
            else
            {
                res.Tag2 = GameLoopTempletHelper.GetRuleCodes(req.Filter.PersonCount, true, true);//队伍2(客队)对阵编码字符数组
            }
            return(res);
        }
Пример #5
0
        public Response Execute(string request)
        {
            string updateSql = @"UPDATE GameTeamLoopTemplet SET IsEnable=@isEnable WHERE Id=@templetId";
            var    req       = JsonConvert.DeserializeObject <Request <GameTeamLoopTemplet> >(request);
            var    templet   = req.Entities[0] as GameTeamLoopTemplet;
            var    cmd       = CommandHelper.CreateText(FetchType.Execute, updateSql);

            cmd.Params.Add("@templetId", templet.Id);
            cmd.Params.Add("@isEnable", templet.IsEnable);
            var res = DbContext.GetInstance().Execute(cmd);

            if (res.IsSuccess && !templet.IsEnable)
            {
                res.Tag = GameLoopTempletHelper.IsUseTemplet(templet.Id);//停用模板,假如被赛事使用过,则返回true
                ///res.Message = "可删除此模板,需要删除吗?";
            }
            else
            {
                res.Tag = false;
            }

            return(res);
        }
Пример #6
0
        public Response Execute(User currentUser, string request)
        {
            var req = JsonConvert.DeserializeObject <Request <GetCoachRelatedFilter> >(request);
            UserMyPagePermission permission = new UserMyPagePermission();
            var currentUserId = req.Filter.CurrentUserId;

            //一般用户(简单说就是所有用户)权限设置
            SetGeneralUserPermission(permission);

            //教练权限设置
            if (CoachHelper.Instance.IsCoach(currentUserId))
            {
                SetCoachPermission(permission);
            }

            //教练管理员权限设置
            if (PermissionCheck.Instance.IsCoachManager(currentUserId))
            {
                SetCoachManagerPermission(permission);
            }

            //系统管理员权限设置
            if (PermissionCheck.Instance.IsSystemManager(currentUserId))
            {
                SetSystemManagerPermission(permission);
            }

            //封闭机构管理员权限设置
            if (PermissionCheck.Instance.IsSealedOrganizationManager(currentUserId))
            {
                SetOrganizationManagerPermission(permission);
            }

            //封闭机构教练权限设置
            if (CoachHelper.Instance.IsSealedCoach(currentUserId))
            {
                SetSealedCoachPermission(permission, currentUserId);
            }

            //特殊权限处理
            SetSpecialPermission(permission, currentUserId);
            //默认所有用户都有的权限
            permission.IsShowMyPermission = true;
            permission.IsShowSetting      = true;
            //处理有冲突的权限
            SetConflictPermission(permission);
            //最后返回
            Response rsp = new Response();

            rsp.IsSuccess = true;
            rsp.Entities  = new List <EntityBase>();
            ///////////////获取我的团体模板能使用的总数
            var res = GameLoopTempletHelper.GetTempletList(currentUser.Id, "", 2);

            res.SetRowCount();
            permission.TempletCount = res.RowCount;
            res = null;
            ///////////////

            rsp.Entities.Add(permission);


            return(rsp);
        }
Пример #7
0
        /// <summary>
        /// 获取某个团体对阵模板及规则详情
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        public static Response GetTempletDetail(GameTeamLoopTempletFilter filter)
        {
            string  sqlStr = @"SELECT a.*,CASE WHEN ISNULL(b.PetName, '')='' THEN b.CardName ELSE b.PetName END AS SharePerson,
                             CAST(CASE WHEN a.UseCount >=5 THEN 1 ELSE 0 END AS BIT) AS IsEnableShare 
                             FROM GameTeamLoopTemplet AS a LEFT JOIN UserAccount AS b ON a.SharePersonId=b.Id
                             WHERE a.Id=@templetId";
            Command cmd    = CommandHelper.CreateText <GameTeamLoopTemplet>(FetchType.Fetch, sqlStr);

            cmd.Params.Add("@templetId", filter.TempletId);
            Response res = DbContext.GetInstance().Execute(cmd);

            if (res.Entities.Count > 0)
            {
                var temp = res.Entities[0] as GameTeamLoopTemplet;
                if (temp.UseCount > 0)
                {
                    temp.UseDes = "已被" + temp.UseCount + "场比赛使用";
                }
                else
                {
                    temp.UseDes = "还未正式被比赛使用过";
                }
                temp.IsUse = GameLoopTempletHelper.IsUseTemplet(filter.TempletId);                //模板是否使用
                sqlStr     = @"SELECT * FROM GameTeamLoopTempletDetail WHERE TempletId=@templetId ORDER BY OrderNo ";
                if (!string.IsNullOrEmpty(filter.GameId) && !string.IsNullOrEmpty(filter.LoopId)) //进入团体对阵页面时,获取规则对员对阵详情
                {
                    sqlStr = @"SELECT a.*,b.User1Name,b.User1Id,b.User2Name,b.User2Id FROM GameTeamLoopTempletDetail AS a LEFT JOIN GameLoopMap AS b ON a.OrderNo=b.OrderNo AND b.LoopId=@loopId
                               WHERE a.TempletId=@templetId ORDER BY a.OrderNo";
                }
                cmd = CommandHelper.CreateText <GameTeamLoopTempletDetail>(FetchType.Fetch, sqlStr);
                cmd.Params.Add("@templetId", filter.TempletId);
                if (!string.IsNullOrEmpty(filter.GameId) && !string.IsNullOrEmpty(filter.LoopId))
                {
                    cmd.Params.Add("@loopId", filter.LoopId);
                }
                Response res1 = DbContext.GetInstance().Execute(cmd);
                temp.Detail = res1.Entities.ToList <EntityBase, GameTeamLoopTempletDetail>();
                if (!string.IsNullOrEmpty(filter.GameId) && !string.IsNullOrEmpty(filter.LoopId))//进入团体对阵页面时,获取规则编码与队员映射关系
                {
                    sqlStr = @"SELECT a.Id,a.TempletId,a.GameId,a.LoopId,a.TeamId,a.Code,a.CodeUserId,a.CodeUserName,a.CreateDate,b.TeamName  
                              FROM GameTeamLoopTempletMap as a LEFT JOIN GameTeam as b ON a.TeamId=b.Id 
                              WHERE a.TempletId=@templetId AND a.GameId=@gameId AND a.LoopId=@loopId ORDER BY TeamId,a.Code";
                    cmd    = CommandHelper.CreateText <GameTeamLoopTempletMap>(FetchType.Fetch, sqlStr);
                    cmd.Params.Add("@templetId", filter.TempletId);
                    cmd.Params.Add("@gameId", filter.GameId);
                    cmd.Params.Add("@loopId", filter.LoopId);
                    res1            = DbContext.GetInstance().Execute(cmd);
                    temp.Map        = res1.Entities.ToList <EntityBase, GameTeamLoopTempletMap>();//规则编码与队员映射关系
                    temp.Team1Codes = GameLoopTempletHelper.GetRuleCodes(temp.PersonCount, true, false);
                    if (temp.IsGuest)
                    {
                        temp.Team2Codes = GameLoopTempletHelper.GetRuleCodes(temp.PersonCount, false, false);
                    }
                    else
                    {
                        temp.Team2Codes = GameLoopTempletHelper.GetRuleCodes(temp.PersonCount, true, false);
                    }
                }
            }
            return(res);
        }
Пример #8
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);
        }
Пример #9
0
        /// <summary>
        ///  保存对阵映射关系
        /// </summary>
        /// <param name="currentUser">忽略</param>
        /// <param name="request">Request.GameLoopMap</param>
        /// <returns>Response.EmptyEntity</returns>
        public Response Execute(string request)
        {
            var reqAll = JsonConvert.DeserializeObject <Request <GameLoopMapNew> >(request);
            var mapNew = reqAll.Entities[0] as GameLoopMapNew;

            //检查规则编码对应的人员是否重复
            if (GameLoopTempletHelper.IsSame(mapNew.TempletMapList))
            {
                return(ResultHelper.Fail("对阵人员不能重复"));
            }

            //var req = JsonConvert.DeserializeObject<Request<GameLoopMap>>(request);
            var loopMapList = mapNew.LoopMapList;;
            //var firstMap = req.FirstEntity();
            var firstMap           = loopMapList[0];
            List <EntityBase> list = new List <EntityBase>();

            foreach (var obj in loopMapList)
            {
                obj.Team1Id = obj.Team1Id.GetId();
                obj.Team2Id = obj.Team2Id.GetId();
                //if (obj.RowState == RowState.Added)
                //{
                //    obj.SetNewId();
                //    obj.SetCreateDate();
                //}
                obj.SetNewEntity();
                list.Add(obj);
            }

            var cmd = CommandHelper.CreateSave(list);

            //删除映射及比赛详情  先删除规则队员映射关系
            var cmdDelete = CommandHelper.CreateText(FetchType.Execute);

            //cmdDelete.Text = "DELETE FROM dbo.GameLoopMap WHERE LoopId=@loopId  DELETE FROM dbo.GameLoopDetail WHERE LoopId=@loopId ";
            cmdDelete.Text = "DELETE FROM dbo.GameLoopMap WHERE LoopId=@loopId  DELETE FROM dbo.GameLoopDetail WHERE LoopId=@loopId  DELETE FROM GameTeamLoopTempletMap WHERE LoopId=@loopId";
            cmdDelete.Params.Add("@loopId", firstMap.LoopId);
            cmd.PreCommands = new List <Command> {
                cmdDelete
            };
            var res = DbContext.GetInstance().Execute(cmd);

            //////////////////保存模板规则队员映射关系/////////////////
            if (res.IsSuccess)
            {
                list.Clear();
                cmdDelete = null;
                cmd       = null;
                foreach (var item in mapNew.TempletMapList)
                {
                    item.SetNewEntity();
                    list.Add(item);
                }
                cmd = CommandHelper.CreateSave(list);
                res = DbContext.GetInstance().Execute(cmd);
            }

            //

            /*
             * var firstMap = req.FirstEntity();
             * if (firstMap.SaveMapOption == "1")
             * {
             *  cmd.OnlyFields = new List<TableFieldPair> { new TableFieldPair { Table = "GameLoopMap", Fields = "Team1Id,User1Id,User1Name" } };
             * }
             * else if (firstMap.SaveMapOption == "2")
             * {
             *  cmd.OnlyFields = new List<TableFieldPair> { new TableFieldPair { Table = "GameLoopMap", Fields = "Team2Id,User2Id,User2Name" } };
             * }*/
            return(res);
        }
Пример #10
0
        public Response Execute(User currentUser, string request)
        {
            var req = JsonConvert.DeserializeObject <Request <GameTeamLoopTemplet> >(request);
            GameTeamLoopTemplet templet = req.FirstEntity();
            Response            res     = null;
            Command             cmd     = null;

            if (templet.RowState == RowState.Added || templet.RowState == RowState.Modified)
            {
                if (templet.PersonCount <= 0 || templet.PersonCount > 9)
                {
                    return(ResultHelper.Fail("上场人数不超过9人"));
                }
                if (templet.LoopCount <= 0 || templet.LoopCount > 9)
                {
                    return(ResultHelper.Fail("总对阵场数不超过9场"));
                }
            }

            if (templet.RowState == RowState.Added)//新增,
            {
                //假如上传基于模板ID,判断是否基于已有模板创建,不检查同名
                if (string.IsNullOrEmpty(templet.Id))
                {
                    if (GameLoopTempletHelper.IsExistTemplet(templet.Name, false))
                    {
                        return(ResultHelper.Fail("对阵模板重名"));
                    }
                }
                else
                {
                    templet.Name = GameLoopTempletHelper.GetNewTempletName(templet.Name);//模板名称基于上个模板递增序号
                }

                if (templet.Detail.Count <= 0)
                {
                    return(ResultHelper.Fail("缺少模板规则"));
                }
                templet.SetNewEntity();
                res     = AddTemplet(templet, currentUser, true);
                res.Tag = false;
                res.Entities.Add(templet);
                return(res);
            }
            else
            {
                GameTeamLoopTemplet temp = GameLoopTempletHelper.GetTemplet(templet.Id);//获取对阵模板对象
                if (temp.CreatorId != currentUser.Id)
                {
                    return(ResultHelper.Fail("不能修改或删除非自己创建的模板"));
                }

                if (templet.RowState == RowState.Modified)              //修改
                {
                    if (GameLoopTempletHelper.IsUseTemplet(templet.Id)) //模板在使用中,直接按内容新建模板
                    {
                        templet.SetNewEntity();
                        templet.RowState = RowState.Added;
                        templet.Name     = GameLoopTempletHelper.GetNewTempletName(templet.Name);
                        res = AddTemplet(templet, currentUser, true);
                        if (res.IsSuccess)
                        {
                            res.Message = "模板在使用中,已保存为新的模板【" + templet.Name + "】";
                            res.Tag     = true;//修改正在使用的模板保存,些值为true
                        }


                        return(res);
                    }
                    ///先删除对应模板ID所有的规则详情
                    string delSql = @"DELETE FROM GameTeamLoopTempletDetail WHERE TempletId=@templetId";
                    cmd = CommandHelper.CreateText(FetchType.Execute, delSql);
                    cmd.Params.Add("@templetId", templet.Id);
                    DbContext.GetInstance().Execute(cmd);

                    ////////////////////////////////////////////////////////////
                    var entities = GameLoopTempletHelper.GetTemplets(templet.Name);//通过新名称检查模板
                    if (entities.Count > 0)
                    {
                        var temp1 = entities[0] as GameTeamLoopTemplet;
                        if (temp1.Id != templet.Id)//假如有同名但是模板id与修改的模板ID不同
                        {
                            return(ResultHelper.Fail("已存在相同名称对阵模板"));
                        }
                    }
                    templet.SetCreateDate();
                    res     = AddTemplet(templet, currentUser, false);
                    res.Tag = false;
                }
                else if (templet.RowState == RowState.Deleted)//删除
                {
                    if (GameLoopTempletHelper.IsUseTemplet(templet.Id))
                    {
                        res     = ResultHelper.Fail("模板已被使用,不能删除");
                        res.Tag = false;
                        return(res);
                    }
                    string delSql = @"DELETE FROM GameTeamLoopTemplet WHERE Id=@templetId  DELETE FROM GameTeamLoopTempletDetail WHERE TempletId=@templetId";
                    cmd = CommandHelper.CreateText(FetchType.Execute, delSql);
                    cmd.Params.Add("@templetId", templet.Id);
                    res     = DbContext.GetInstance().Execute(cmd);
                    res.Tag = false;
                }
            }

            return(res);
        }
Пример #11
0
        /// <summary>
        /// 保存实体模板
        /// </summary>
        /// <param name="templet"></param>
        /// <param name="currentUser"></param>
        /// <param name="flag">新增为true;纯修改为false</param>
        /// <returns></returns>
        private Response AddTemplet(GameTeamLoopTemplet templet, User currentUser, bool flag)
        {
            /////每个用户最多创建多少条模板,适当减少垃圾数据
            if (flag)
            {
                int maxCount = 10;//默认,配置文件读取错误
                try
                {
                    maxCount = int.Parse(ConfigurationManager.AppSettings["TempletMaxCount"]);
                }
                catch { }
                int templetCount = GameLoopTempletHelper.GetCountByUser(currentUser.Id);
                if (templetCount > maxCount)
                {
                    return(ResultHelper.Fail("模板数量已满"));
                }
            }
            //////////////////////////////////////////////////
            templet.IsEnable  = true;                    //新建时,默认为启用
            templet.CreatorId = currentUser.Id;
            StringBuilder ruleStr = new StringBuilder(); //根据规则生成规则字符串

            List <EntityBase> detailList = new List <EntityBase>();

            foreach (GameTeamLoopTempletDetail item in templet.Detail)//规则详情
            {
                item.RowState = RowState.Added;
                item.SetNewEntity();
                item.TempletId = templet.Id;
                detailList.Add(item);
                ////////////生成规则字符串
                string ruleNo = string.Empty;
                switch (item.OrderNo)
                {
                case 1:
                    ruleNo = "①";
                    break;

                case 2:
                    ruleNo = "②";
                    break;

                case 3:
                    ruleNo = "③";
                    break;

                case 4:
                    ruleNo = "④";
                    break;

                case 5:
                    ruleNo = "⑤";
                    break;

                case 6:
                    ruleNo = "⑥";
                    break;

                case 7:
                    ruleNo = "⑦";
                    break;

                case 8:
                    ruleNo = "⑧";
                    break;

                case 9:
                    ruleNo = "⑨";
                    break;
                }
                ruleStr.Append(ruleNo + item.Code1 + "-" + item.Code2);
            }
            templet.RuleCode = ruleStr.ToString();
            var detailCmd = CommandHelper.CreateSave(detailList);
            var cmd       = CommandHelper.CreateSave(templet);
            var res       = DbContext.GetInstance().Execute(cmd);//保存主模板

            if (res.IsSuccess)
            {
                res = DbContext.GetInstance().Execute(detailCmd);//不能同时使用多个CreateSave生成的命令列表,保存要出错,直接用SQL字符串生成的命令列表,则可以
            }
            res.Entities.Add(templet);
            return(res);
        }
Пример #12
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);
        }