示例#1
0
 public ResponseUserMenusGet GetMenu([FromBody] RequestUserMenusGet request)
 {
     try
     {
         UserBLL bll = new UserBLL();
         return(bll.GetMenu(request));
     }
     catch (Exception ex)
     {
         throw new HttpResponseException(
                   Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
     }
 }
示例#2
0
        public ResponseUserMenusGet GetMenu(RequestUserMenusGet request)
        {
            ResponseUserMenusGet response = new ResponseUserMenusGet();

            using (cnn = GetConnection())
            {
                var ts = cnn.BeginTransaction();
                try
                {
                    string rootId = ConfigurationManager.AppSettings["funcId"];
                    //string lst_rootId = "('"+ rootId + "','27bdaf9d01bc4960b2be86c8923b4b56','6ca8509327ae49c49008f35595c997c7','9de61fd017954080888318fca45b023e')";
                    string lst_rootId = "('27bdaf9d01bc4960b2be86c8923b4b56','6ca8509327ae49c49008f35595c997c7','9de61fd017954080888318fca45b023e')";
                    var    userInfo   = this.UserInfoGetButAccount(request.Token, ts);

                    //role
                    var roles = cnn.Query <string>("select roleid from TKS_FAS_User2Role where userid=@UserId",
                                                   new { UserId = userInfo.User.Id }, ts).ToList();
                    string inId = string.Empty;
                    if (roles.Count() > 0)
                    {
                        inId = "and entityId in ('" + string.Join("','", roles.ToArray()) + "')";
                    }
                    else
                    {
                        inId = " and 1=2";
                    }



                    //func by role
                    string sql = @"select functionId from TKS_FAS_Entity2Function where type=@Type  {0} group by functionId";
                    sql = string.Format(sql, inId);


                    var checkedFuncs = cnn.Query <string>(sql, new
                    {
                        Type = "R"
                    }, ts).ToList();
                    string inFuncs = string.Empty;
                    if (checkedFuncs.Count() > 0)
                    {
                        inFuncs = " and  id in ('" + string.Join("','", checkedFuncs.ToArray()) + "')";
                    }
                    else
                    {
                        inFuncs = " and 1=2";
                    }


                    sql = @"WITH CTE  AS
                         (SELECT *
                            FROM tks_fas_function
                           WHERE id in{0}
  
                          UNION ALL
                          SELECT B.*
                            FROM tks_fas_function B
                           INNER JOIN CTE
                              ON  B.PARENTID = CTE.id)
      
                     SELECT * FROM CTE  where 1=1 {1} union
	SELECT *
		FROM tks_fas_function
		WHERE id = @Id order by seq"        ;
                    sql = string.Format(sql, lst_rootId, inFuncs);

                    var funcs = cnn.Query <TKS_FAS_Function>(sql, new { Id = rootId }, ts).ToList();


                    TKS_FAS_MenuItem root = new TKS_FAS_MenuItem();
                    var first             = funcs.Where(p => p.Id == rootId).FirstOrDefault();
                    if (first == null)
                    {
                        response.Data      = null;
                        response.Message   = "没有权限";
                        response.IsSuccess = false;
                    }
                    else
                    {
                        root = Trans2MenuItem(first);
                        CreateTree(funcs, ref root);
                        response.Data      = root.children;
                        response.Message   = "加载完毕";
                        response.IsSuccess = true;
                    }

                    ts.Commit();

                    return(response);
                }
                catch (Exception ex)
                {
                    ts.Rollback();
                    return(this.DealException(response, ex) as ResponseUserMenusGet);
                }
            }
        }
示例#3
0
        public ResponseUserMenusGet UserMenuGet(RequestUserMenusGet request)
        {
            ResponseUserMenusGet response = new ResponseUserMenusGet();

            using (cnn = GetConnection())
            {
                var ts = cnn.BeginTransaction();
                try
                {
                    string rootId = request.FuncId;
                    //rootId = ConfigurationManager.AppSettings[key];
                    var userInfo = this.UserInfoGetButAccount(request.Token, ts);
                    #region 权限控制 用户进入平台管理或者会计操作页面 add by Hero.Zhang
                    var Permission = this.GetPermission(request.Token, ts);
                    if (userInfo.User.UserName == "admin")
                    {
                        rootId = ConfigurationManager.AppSettings["funcId_admin"];
                    }
                    else
                    {
                        if (Permission == null)
                        {
                            response.Data      = null;
                            response.Message   = "没有角色权限";
                            response.IsSuccess = false;
                            return(response);
                        }
                        if (Permission.PLevel == 1)
                        {
                            rootId = ConfigurationManager.AppSettings["funcId_admin"];
                        }
                        else if (Permission.PLevel > 1)
                        {
                            rootId = ConfigurationManager.AppSettings["funcId"];
                        }
                    }
                    #endregion
                    //role
                    var roles = cnn.Query <string>("select roleid from TKS_FAS_User2Role where userid=@UserId",
                                                   new { UserId = userInfo.User.Id }, ts).ToList();
                    string inId = string.Empty;
                    if (roles.Count() > 0)
                    {
                        inId = "and entityId in ('" + string.Join("','", roles.ToArray()) + "')";
                    }
                    else
                    {
                        inId = " and 1=2";
                    }



                    //func by role
                    string sql = @"select functionId from TKS_FAS_Entity2Function where type=@Type  {0} group by functionId";
                    sql = string.Format(sql, inId);


                    var checkedFuncs = cnn.Query <string>(sql, new
                    {
                        Type = "R"
                    }, ts).ToList();
                    string inFuncs = string.Empty;
                    if (checkedFuncs.Count() > 0)
                    {
                        inFuncs = " and  id in ('" + string.Join("','", checkedFuncs.ToArray()) + "')";
                    }
                    else
                    {
                        inFuncs = " and 1=2";
                    }


                    sql = @"WITH CTE  AS
                         (SELECT *
                            FROM tks_fas_function
                           WHERE id = @Id
  
                          UNION ALL
                          SELECT B.*
                            FROM tks_fas_function B
                           INNER JOIN CTE
                              ON  B.PARENTID = CTE.id)
      
                     SELECT * FROM CTE  where 1=1 {0} order by seq";
                    sql = string.Format(sql, inFuncs);

                    var funcs = cnn.Query <TKS_FAS_Function>(sql, new { Id = rootId }, ts).ToList();


                    TKS_FAS_MenuItem root = new TKS_FAS_MenuItem();
                    var first             = funcs.Where(p => p.Id == rootId).FirstOrDefault();
                    if (first == null)
                    {
                        response.Data      = null;
                        response.Message   = "没有权限";
                        response.IsSuccess = false;
                    }
                    else
                    {
                        root = Trans2MenuItem(first);
                        CreateTree(funcs, ref root);
                        response.Data      = root.children;
                        response.Message   = "加载完毕";
                        response.IsSuccess = true;
                        response.FuncId    = rootId;
                    }

                    ts.Commit();

                    return(response);
                }
                catch (Exception ex)
                {
                    ts.Rollback();
                    return(this.DealException(response, ex) as ResponseUserMenusGet);
                }
            }
        }