| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- using CallCenterApi.DB;
- using CallCenterApi.Interface.Controllers.Base;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- namespace CallCenterApi.Interface.Controllers
- {
- [Authority]
- public class RoleFunctionController : BaseController
- {
- private BLL.T_Sys_RoleFunction roleFunctionBll = new BLL.T_Sys_RoleFunction();
- private BLL.T_Sys_RoleInfo roleInfoBll = new BLL.T_Sys_RoleInfo();
- private BLL.T_Sys_Function functionsBLL = new BLL.T_Sys_Function();
- /// <summary>
- /// 获取菜单
- /// </summary>
- /// <returns></returns>
- public ActionResult GetMenu()
- {
- Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(User.UserData["F_UserCode"]);
- var fids = new BLL.T_Sys_RoleFunction().GetModelList(" F_RoleId='" + userModel.F_RoleId + "'").Select(p => p.F_FunctionId).ToList();
- if (fids.Count > 0)
- {
- var ids = string.Join(",", fids);
- 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];
- dt.Columns.Add("item", typeof(object));
- foreach (DataRow dr in dt.Rows)
- {
- 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];
- }
- return Success("成功", dt);
- }
- else
- {
- return Error("失败");
- }
- }
- /// <summary>
- /// 保存角色权限
- /// </summary>
- /// <param name="functionIds"></param>
- /// <param name="roleId"></param>
- /// <returns></returns>
- public ActionResult SaveRoleFunction(string[] functionIds, int roleId = 0)
- {
- DataTable dt = new DataTable();
- if (functionIds == null)
- return Error("参数错误");
- Model.T_Sys_RoleFunction RoleModel = new Model.T_Sys_RoleFunction();
- //查询选中页面中的权限
- var idStr = string.Join(",", functionIds);
- if (roleId != 0)
- {
- var role = roleInfoBll.GetModel(roleId);
- if (role != null)
- {
- List<string> sqls = new List<string>();
- string sql = " delete T_Sys_RoleFunction where F_RoleId=" + roleId + ";";
- sqls.Add(sql);
- foreach (string fid in functionIds)
- {
- var fun = functionsBLL.GetModel(Int32.Parse(fid));
- if (fun != null)
- {
- string sql1 = " insert into T_Sys_RoleFunction(F_RoleId,F_FunctionId) values(" + roleId + "," + fid + ");";
- sqls.Add(sql1);
- }
- }
- int n = DbHelperSQL.ExecuteSqlTransaction(sqls);
- return Success("权限设置成功");
- }
- else
- {
- return Error("参数错误");
- }
- }
- else
- {
- return Error("参数错误");
- }
- }
- /// <summary>
- /// 获取用户权限树形结构
- /// </summary>
- /// <param name="roleId"></param>
- /// <returns></returns>
- public ActionResult GetRoleFunction(int roleId = 0)
- {
- var moduleFList = functionsBLL.GetModelList(" F_State=1 ");
- var list = roleFunctionBll.GetModelList(" F_RoleId=" + roleId).Select(x => x.F_FunctionId).ToList();
- return Success("加载成功", moduleFList.Select(x => new
- {
- id = x.F_FunctionId,
- pid = x.F_ParentId,
- name = x.F_FunctionName,
- sort = x.F_Sort,
- ischecked = list.Where(y => y == x.F_FunctionId).Count() > 0 ? true : false
- }).OrderBy(p => p.sort));
- }
- }
- }
|