县级监管平台

RoleFunctionController.cs 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using CallCenterApi.DB;
  2. using CallCenterApi.Interface.Controllers.Base;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Web;
  8. using System.Web.Mvc;
  9. namespace CallCenterApi.Interface.Controllers
  10. {
  11. [Authority]
  12. public class RoleFunctionController : BaseController
  13. {
  14. private BLL.T_Sys_RoleFunction roleFunctionBll = new BLL.T_Sys_RoleFunction();
  15. private BLL.T_Sys_RoleInfo roleInfoBll = new BLL.T_Sys_RoleInfo();
  16. private BLL.T_Sys_Function functionsBLL = new BLL.T_Sys_Function();
  17. /// <summary>
  18. /// 获取菜单
  19. /// </summary>
  20. /// <returns></returns>
  21. public ActionResult GetMenu()
  22. {
  23. Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(User.UserData["F_UserCode"]);
  24. var fids = new BLL.T_Sys_RoleFunction().GetModelList(" F_RoleId='" + userModel.F_RoleId + "'").Select(p => p.F_FunctionId).ToList();
  25. if (fids.Count > 0)
  26. {
  27. var ids = string.Join(",", fids);
  28. var dt = new BLL.T_Sys_Function().GetList(0, " F_FunctionId in (" + ids + ") and F_State=1 and F_ParentId=-1 ", " F_Sort asc").Tables[0];
  29. dt.Columns.Add("item", typeof(object));
  30. foreach (DataRow dr in dt.Rows)
  31. {
  32. dr["item"] = new BLL.T_Sys_Function().GetList(0, " F_FunctionId in (" + ids + ") and F_State=1 and F_ParentId=" + dr["F_FunctionId"].ToString(), " F_Sort asc").Tables[0];
  33. }
  34. return Success("成功", dt);
  35. }
  36. else
  37. {
  38. return Error("失败");
  39. }
  40. }
  41. /// <summary>
  42. /// 保存角色权限
  43. /// </summary>
  44. /// <param name="functionIds"></param>
  45. /// <param name="roleId"></param>
  46. /// <returns></returns>
  47. public ActionResult SaveRoleFunction(string[] functionIds, int roleId = 0)
  48. {
  49. DataTable dt = new DataTable();
  50. if (functionIds == null)
  51. return Error("参数错误");
  52. Model.T_Sys_RoleFunction RoleModel = new Model.T_Sys_RoleFunction();
  53. //查询选中页面中的权限
  54. var idStr = string.Join(",", functionIds);
  55. if (roleId != 0)
  56. {
  57. var role = roleInfoBll.GetModel(roleId);
  58. if (role != null)
  59. {
  60. List<string> sqls = new List<string>();
  61. string sql = " delete T_Sys_RoleFunction where F_RoleId=" + roleId + ";";
  62. sqls.Add(sql);
  63. foreach (string fid in functionIds)
  64. {
  65. var fun = functionsBLL.GetModel(Int32.Parse(fid));
  66. if (fun != null)
  67. {
  68. string sql1 = " insert into T_Sys_RoleFunction(F_RoleId,F_FunctionId) values(" + roleId + "," + fid + ");";
  69. sqls.Add(sql1);
  70. }
  71. }
  72. int n = DbHelperSQL.ExecuteSqlTransaction(sqls);
  73. return Success("权限设置成功");
  74. }
  75. else
  76. {
  77. return Error("参数错误");
  78. }
  79. }
  80. else
  81. {
  82. return Error("参数错误");
  83. }
  84. }
  85. /// <summary>
  86. /// 获取用户权限树形结构
  87. /// </summary>
  88. /// <param name="roleId"></param>
  89. /// <returns></returns>
  90. public ActionResult GetRoleFunction(int roleId = 0)
  91. {
  92. var moduleFList = functionsBLL.GetModelList(" F_State=1 ");
  93. var list = roleFunctionBll.GetModelList(" F_RoleId=" + roleId).Select(x => x.F_FunctionId).ToList();
  94. return Success("加载成功", moduleFList.Select(x => new
  95. {
  96. id = x.F_FunctionId,
  97. pid = x.F_ParentId,
  98. name = x.F_FunctionName,
  99. sort = x.F_Sort,
  100. ischecked = list.Where(y => y == x.F_FunctionId).Count() > 0 ? true : false
  101. }).OrderBy(p => p.sort));
  102. }
  103. }
  104. }