zhoufan 4 gadi atpakaļ
vecāks
revīzija
668e7c1158

+ 12 - 2
RMYY_CallCenter_Api.Bll/T_Sys_Menu.cs

@@ -1,6 +1,8 @@
1 1
 using System;
2 2
 using System.Data;
3 3
 using System.Collections.Generic;
4
+using RMYY_CallCenter_Api.Utility;
5
+
4 6
 namespace RMYY_CallCenter_Api.Bll
5 7
 {
6 8
     /// <summary>
@@ -25,6 +27,7 @@ namespace RMYY_CallCenter_Api.Bll
25 27
         /// </summary>
26 28
         public int Add(Model.T_Sys_Menu model)
27 29
         {
30
+            CacheHelper.Remove("AuthActions");
28 31
             return dal.Add(model);
29 32
         }
30 33
 
@@ -33,6 +36,9 @@ namespace RMYY_CallCenter_Api.Bll
33 36
         /// </summary>
34 37
         public bool Update(Model.T_Sys_Menu model)
35 38
         {
39
+            CacheHelper.RemoveContain("RoleMenus_");
40
+            CacheHelper.RemoveContain("RoleActions_");
41
+            CacheHelper.Remove("AuthActions");
36 42
             return dal.Update(model);
37 43
         }
38 44
 
@@ -41,7 +47,9 @@ namespace RMYY_CallCenter_Api.Bll
41 47
         /// </summary>
42 48
         public bool Delete(int F_MenuId)
43 49
         {
44
-
50
+            CacheHelper.RemoveContain("RoleMenus_");
51
+            CacheHelper.RemoveContain("RoleActions_");
52
+            CacheHelper.Remove("AuthActions");
45 53
             return dal.Delete(F_MenuId);
46 54
         }
47 55
         /// <summary>
@@ -49,6 +57,9 @@ namespace RMYY_CallCenter_Api.Bll
49 57
         /// </summary>
50 58
         public bool DeleteList(string F_MenuIdlist)
51 59
         {
60
+            CacheHelper.RemoveContain("RoleMenus_");
61
+            CacheHelper.RemoveContain("RoleActions_");
62
+            CacheHelper.Remove("AuthActions");
52 63
             return dal.DeleteList(F_MenuIdlist);
53 64
         }
54 65
 
@@ -57,7 +68,6 @@ namespace RMYY_CallCenter_Api.Bll
57 68
         /// </summary>
58 69
         public Model.T_Sys_Menu GetModel(int F_MenuId)
59 70
         {
60
-
61 71
             return dal.GetModel(F_MenuId);
62 72
         }
63 73
 

+ 5 - 6
RMYY_CallCenter_Api.Bll/T_Sys_UserAccount.cs

@@ -28,7 +28,6 @@ namespace RMYY_CallCenter_Api.Bll
28 28
         /// </summary>
29 29
         public int Add(Model.T_Sys_UserAccount model)
30 30
         {
31
-            CacheHelper.Remove(model.F_UserCode);
32 31
             return dal.Add(model);
33 32
         }
34 33
 
@@ -37,7 +36,7 @@ namespace RMYY_CallCenter_Api.Bll
37 36
         /// </summary>
38 37
         public bool Update(Model.T_Sys_UserAccount model)
39 38
         {
40
-            CacheHelper.Remove(model.F_UserCode);
39
+            CacheHelper.Remove("User_" + model.F_UserCode);
41 40
             return dal.Update(model);
42 41
         }
43 42
 
@@ -46,7 +45,7 @@ namespace RMYY_CallCenter_Api.Bll
46 45
         /// </summary>
47 46
         public bool Delete(int F_UserId)
48 47
         {
49
-            CacheHelper.RemoveAll();
48
+            CacheHelper.RemoveContain("User_");
50 49
             return dal.Delete(F_UserId);
51 50
         }
52 51
         /// <summary>
@@ -54,7 +53,7 @@ namespace RMYY_CallCenter_Api.Bll
54 53
         /// </summary>
55 54
         public bool DeleteList(string F_UserIdlist)
56 55
         {
57
-            CacheHelper.RemoveAll();
56
+            CacheHelper.RemoveContain("User_");
58 57
             return dal.DeleteList(F_UserIdlist);
59 58
         }
60 59
 
@@ -71,10 +70,10 @@ namespace RMYY_CallCenter_Api.Bll
71 70
         /// </summary>
72 71
         public Model.T_Sys_UserAccount GetModel(string F_UserCode)
73 72
         {
74
-            var user=CacheHelper.Get(F_UserCode);
73
+            var user=CacheHelper.Get<Model.T_Sys_UserAccount>("User_"+F_UserCode);
75 74
             if (user != null)
76 75
             {
77
-                return user as Model.T_Sys_UserAccount;
76
+                return user;
78 77
             }
79 78
             else
80 79
             {

+ 12 - 0
RMYY_CallCenter_Api.Dal/T_Sys_Menu.cs

@@ -314,6 +314,18 @@ namespace RMYY_CallCenter_Api.Dal
314 314
         }
315 315
 
316 316
         /// <summary>
317
+        /// 获得数据列表
318
+        /// </summary>
319
+        public DataSet GetListByRoleId(int roleId)
320
+        {
321
+            StringBuilder strSql = new StringBuilder();
322
+            strSql.Append("select m.F_MenuId,m.F_ParentId,m.F_MenuCode,m.F_MenuName,m.F_Type,m.F_Url,m.F_Icon,m.F_Action,m.F_Sort,m.F_Remark,m.F_State,m.F_CreateUser,m.F_CreateTime ");
323
+            strSql.Append(" FROM T_Sys_RoleMenu rm with(nolock) left join T_Sys_Menu m with(nolock) on rm.F_MenuId=m.F_MenuId ");
324
+            strSql.Append(" where rm.RoleId=" + roleId + " and m.F_State=1");
325
+            return DbHelperSQL.Query(strSql.ToString());
326
+        }
327
+
328
+        /// <summary>
317 329
         /// 获得前几行数据
318 330
         /// </summary>
319 331
         public DataSet GetList(int Top, string strWhere, string filedOrder)

+ 1 - 0
RMYY_CallCenter_Api.Model/T_Sys_UserAccount.cs

@@ -178,6 +178,7 @@ namespace RMYY_CallCenter_Api.Model
178 178
             set { _f_deletetime = value; }
179 179
             get { return _f_deletetime; }
180 180
         }
181
+
181 182
         #endregion Model
182 183
 
183 184
     }

+ 23 - 1
RMYY_CallCenter_Api.Utility/Helper/CacheHelper.cs

@@ -109,6 +109,28 @@ namespace RMYY_CallCenter_Api.Utility
109 109
             objCache.Remove(Key);
110 110
         }
111 111
         /// <summary>
112
+        /// 移出Cache对象
113
+        /// </summary>
114
+        /// <param name="CacheKey"></param>
115
+        public static void RemoveContain(string Key)
116
+        {
117
+            System.Web.Caching.Cache cache = HttpRuntime.Cache;
118
+            IDictionaryEnumerator cacheEnum = cache.GetEnumerator();
119
+            ArrayList al = new ArrayList();
120
+            while (cacheEnum.MoveNext())
121
+            {
122
+                if (cacheEnum.Key.ToString().IndexOf(Key) != -1)
123
+                {
124
+                    al.Add(cacheEnum.Key.ToString());
125
+                }
126
+            }
127
+
128
+            foreach (string key in al)
129
+            {
130
+                cache.Remove(key);
131
+            }
132
+        }
133
+        /// <summary>
112 134
         /// 移除所有Cache对象
113 135
         /// </summary>
114 136
         public static void RemoveAll()
@@ -118,7 +140,7 @@ namespace RMYY_CallCenter_Api.Utility
118 140
             ArrayList al = new ArrayList();
119 141
             while (cacheEnum.MoveNext())
120 142
             {
121
-                al.Add(cacheEnum.Key);
143
+                al.Add(cacheEnum.Key.ToString());
122 144
             }
123 145
 
124 146
             foreach (string key in al)

+ 52 - 0
RMYY_CallCenter_Api/Common/Common.cs

@@ -0,0 +1,52 @@
1
+using RMYY_CallCenter_Api.Utility;
2
+using System;
3
+using System.Collections.Generic;
4
+using System.Data;
5
+using System.Linq;
6
+using System.Web;
7
+
8
+namespace RMYY_CallCenter_Api
9
+{
10
+    public static class Common
11
+    {
12
+        /// <summary>
13
+        /// 获取授权action
14
+        /// </summary>
15
+        /// <returns></returns>
16
+        public static List<string> GetAuthActions()
17
+        {
18
+            var actions = CacheHelper.Get<List<string>>("AuthActions");
19
+            if (actions != null)
20
+            {
21
+                return actions;
22
+            }
23
+            else
24
+            {
25
+                var dt = DB.DbHelperSQL.Query("select F_Action FROM T_Sys_Menu with(nolock) where F_State=1 and isnull(F_Action,'')!='' ").Tables[0];
26
+                var actions1 = (from DataRow dr in dt.Rows select dr["F_Action"].ToString().ToLower()).ToList();
27
+                CacheHelper.Insert("AuthActions", actions1, 10);
28
+                return actions1;
29
+            }
30
+        }
31
+
32
+        /// <summary>
33
+        /// 获取角色授权action
34
+        /// </summary>
35
+        /// <returns></returns>
36
+        public static List<string> GetRoleActions(int roleId)
37
+        {
38
+            var actions = CacheHelper.Get<List<string>>("RoleActions_" + roleId);
39
+            if (actions != null)
40
+            {
41
+                return actions;
42
+            }
43
+            else
44
+            {
45
+                var dt = DB.DbHelperSQL.Query("select m.F_Action FROM T_Sys_RoleMenu rm with(nolock) left join T_Sys_Menu m with(nolock) on rm.F_MenuId=m.F_MenuId where m.F_State=1 and rm.RoleId=" + roleId + " and isnull(m.F_Action,'')!='' ").Tables[0];
46
+                var actions1 = (from DataRow dr in dt.Rows select dr["F_Action"].ToString().ToLower()).ToList();
47
+                CacheHelper.Insert("RoleActions_" + roleId, actions1, 10);
48
+                return actions1;
49
+            }
50
+        }
51
+    }
52
+}

+ 54 - 0
RMYY_CallCenter_Api/Controllers/IndexController.cs

@@ -0,0 +1,54 @@
1
+using RMYY_CallCenter_Api.Utility;
2
+using System;
3
+using System.Collections.Generic;
4
+using System.Data;
5
+using System.Linq;
6
+using System.Web;
7
+using System.Web.Mvc;
8
+
9
+namespace RMYY_CallCenter_Api.Controllers
10
+{
11
+    public class IndexController : BaseController
12
+    {
13
+        // GET: Index
14
+        /// <summary>
15
+        /// 获取当前用户
16
+        /// </summary>
17
+        /// <returns></returns>
18
+        public ActionResult GetCurrentUser()
19
+        {
20
+            var Role = new Bll.T_Sys_Role().GetModel(User.F_RoleId);
21
+            var Dept = new Bll.T_Sys_Department().GetModel(User.F_DeptId);
22
+            return Success("成功", new { User, Role, Dept });
23
+        }
24
+        /// <summary>
25
+        /// 获取当前用户菜单
26
+        /// </summary>
27
+        /// <returns></returns>
28
+        public ActionResult GetMenu()
29
+        {
30
+            var Menus = CacheHelper.Get<DataTable>("RoleMenus_" + User.F_RoleId);
31
+            if (Menus != null)
32
+            {
33
+                return Success("成功", Menus);
34
+            }
35
+            else
36
+            {
37
+                var dt = new DataTable();
38
+                if (User.F_UserCode == "8000")
39
+                {
40
+                    dt = DB.DbHelperSQL.Query("select * FROM T_Sys_Menu m with(nolock) where F_State=1 ").Tables[0];
41
+                }
42
+                else
43
+                {
44
+                    dt = DB.DbHelperSQL.Query("select m.* FROM T_Sys_RoleMenu rm with(nolock) left join T_Sys_Menu m with(nolock) on rm.F_MenuId=m.F_MenuId where m.F_State=1 and rm.RoleId=" + User.F_RoleId + " and isnull(m.F_Action,'')!='' ").Tables[0];
45
+                }
46
+
47
+                CacheHelper.Insert("RoleMenus_" + User.F_RoleId, dt, 10);
48
+
49
+
50
+                return Success("成功", dt);
51
+            }
52
+        }
53
+    }
54
+}

+ 4 - 3
RMYY_CallCenter_Api/Controllers/System/RoleController.cs

@@ -181,7 +181,7 @@ namespace RMYY_CallCenter_Api.Controllers.System
181 181
         [HttpPost]
182 182
         public ActionResult Delete(string[] ids)
183 183
         {
184
-            if (ids.Count() > 0)
184
+            if (ids != null && ids.Count() > 0)
185 185
             {
186 186
                 bool bl = true;
187 187
                 var idStr = string.Join(",", ids);
@@ -208,7 +208,6 @@ namespace RMYY_CallCenter_Api.Controllers.System
208 208
             {
209 209
                 return Error("删除失败");
210 210
             }
211
-
212 211
         }
213 212
 
214 213
         /// <summary>
@@ -219,7 +218,7 @@ namespace RMYY_CallCenter_Api.Controllers.System
219 218
         public ActionResult GetRoleFunction(int roleid)
220 219
         {
221 220
             var moduleFList = new Bll.T_Sys_Menu().GetModelList(" F_State=1 ");
222
-            var list = DB.DbHelperSQL.Query("select F_MenuId from T_Sys_RoleMenu where F_RoleId=" + roleid).Tables[0];
221
+            var list = DB.DbHelperSQL.Query("select F_MenuId from T_Sys_RoleMenu with(nolock) where F_RoleId=" + roleid).Tables[0];
223 222
 
224 223
             return Success("加载成功", moduleFList.Select(x => new
225 224
             {
@@ -260,6 +259,8 @@ namespace RMYY_CallCenter_Api.Controllers.System
260 259
                 int n = DB.DbHelperSQL.ExecuteSqlTransaction(sqls);
261 260
                 if (n > 0)
262 261
                 {
262
+                    CacheHelper.Remove("RoleMenus_" + roleid);
263
+                    CacheHelper.Remove("RoleActions_" + roleid);
263 264
                     return Success("保存成功");
264 265
                 }
265 266
                 else

+ 15 - 4
RMYY_CallCenter_Api/Filter/AuthorizeFilter.cs

@@ -17,8 +17,9 @@ namespace RMYY_CallCenter_Api.Filter
17 17
         /// <param name="filterContext"></param>
18 18
         public override void OnAuthorization(AuthorizationContext filterContext)
19 19
         {
20
-            if (filterContext.ActionDescriptor.IsDefined(typeof(AllowAnonymousAttribute), true)
21
-                || filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(AllowAnonymousAttribute), true))
20
+            var ad = filterContext.ActionDescriptor;
21
+            if (ad.IsDefined(typeof(AllowAnonymousAttribute), true)
22
+                || ad.ControllerDescriptor.IsDefined(typeof(AllowAnonymousAttribute), true))
22 23
             {
23 24
                 return;
24 25
             }
@@ -40,8 +41,18 @@ namespace RMYY_CallCenter_Api.Filter
40 41
                             var user = new Bll.T_Sys_UserAccount().GetModel(userData["F_UserCode"]);
41 42
                             if (user != null && user.F_RoleId.ToString() == userData["F_RoleId"])
42 43
                             {
43
-                                isAuth = true;
44
-                                context.User = new FormsPrincipal<Model.T_Sys_UserAccount>(ticket, user);//重新给context.User赋值。
44
+                                string action = ad.ControllerDescriptor.ControllerName + "/" + ad.ActionName;
45
+                                if ((Common.GetAuthActions().Contains(action.ToLower()) && Common.GetRoleActions(user.F_RoleId).Contains(action.ToLower()))|| user.F_UserCode == "8000")
46
+                                {
47
+                                    isAuth = true;
48
+                                    context.User = new FormsPrincipal<Model.T_Sys_UserAccount>(ticket, user);//重新给context.User赋值。
49
+                                }
50
+                                else
51
+                                {
52
+                                    context.Response.StatusCode = 200;
53
+                                    filterContext.Result = new ContentResult { Content = new AjaxResult { state = ResultTypes.error.ToString(), message = "无权限" }.ToJson() };
54
+                                    return;
55
+                                }
45 56
                             }
46 57
                         }
47 58
                     }

+ 3 - 0
RMYY_CallCenter_Api/RMYY_CallCenter_Api.csproj

@@ -119,8 +119,10 @@
119 119
   <ItemGroup>
120 120
     <Compile Include="App_Start\FilterConfig.cs" />
121 121
     <Compile Include="App_Start\RouteConfig.cs" />
122
+    <Compile Include="Common\Common.cs" />
122 123
     <Compile Include="Controllers\BaseController.cs" />
123 124
     <Compile Include="Controllers\HomeController.cs" />
125
+    <Compile Include="Controllers\IndexController.cs" />
124 126
     <Compile Include="Controllers\System\DepartmentController.cs" />
125 127
     <Compile Include="Controllers\System\MenuController.cs" />
126 128
     <Compile Include="Controllers\System\RoleController.cs" />
@@ -145,6 +147,7 @@
145 147
   </ItemGroup>
146 148
   <ItemGroup>
147 149
     <Folder Include="App_Data\" />
150
+    <Folder Include="Views\Index\" />
148 151
   </ItemGroup>
149 152
   <ItemGroup>
150 153
     <Content Include="Configs\log4net.config" />