You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
415 lines
16 KiB
415 lines
16 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Data;
|
|
|
|
namespace FangYar.WebUI.ashx
|
|
{
|
|
/// <summary>
|
|
/// SysUsersRulesHandler 的摘要说明
|
|
/// </summary>
|
|
public class SysUsersRulesHandler : IHttpHandler
|
|
{
|
|
private FangYar.BLL.TBL.SysUSerRulesBLL bll = new BLL.TBL.SysUSerRulesBLL();
|
|
public void ProcessRequest(HttpContext context)
|
|
{
|
|
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Other, "用户角色操作请求", "");
|
|
|
|
context.Response.ContentType = "text/json";
|
|
string action = context.Request.Params["Action"];
|
|
string returnstr = "";
|
|
switch (action)
|
|
{
|
|
case "List":
|
|
returnstr = GetModelList(context);
|
|
break;
|
|
case "Add":
|
|
returnstr = AddModel(context);
|
|
break;
|
|
case "Edit":
|
|
returnstr = EditModel(context);
|
|
break;
|
|
case "Del":
|
|
returnstr = DelModel(context);
|
|
break;
|
|
case "getUserRules":
|
|
returnstr = getUserRules(context);
|
|
break;
|
|
case "UserPermAddEdit":
|
|
returnstr = UserPermAddEdit(context);
|
|
break;
|
|
case "ChooseUSer":
|
|
returnstr = ChooseUSer(context);
|
|
break;
|
|
case "RoleChooseUser":
|
|
returnstr = RoleChooseUser(context);
|
|
break;
|
|
}
|
|
context.Response.Write(returnstr);
|
|
|
|
}
|
|
//查询
|
|
private string GetModelList(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
try
|
|
{
|
|
string keywords = context.Request.Params["keywords"];
|
|
string limit = context.Request.Params["limit"];
|
|
string page = context.Request.Params["page"];
|
|
int pageIndex = 1;
|
|
int pageSize = 10;
|
|
if (!string.IsNullOrEmpty(limit)) { pageIndex = int.Parse(page); }
|
|
if (!string.IsNullOrEmpty(limit)) { pageSize = int.Parse(limit); }
|
|
string where = null;
|
|
if (!string.IsNullOrEmpty(keywords))
|
|
{
|
|
where = "USERS_UID like '" + keywords + "' or APP_ID like '" + keywords + "' ";
|
|
}
|
|
returnstr = "{\"code\":0,\"msg\":\"\",";
|
|
int count = bll.Count(where);
|
|
returnstr += "\"count\":" + count + ",\"data\":";
|
|
if (count == 0)
|
|
{
|
|
returnstr += "[]";
|
|
}
|
|
else
|
|
{
|
|
List<FangYar.Model.TBL.TBL_SYS_USERSRULES_Model> list = bll.QueryList(pageIndex, pageSize, where, null);
|
|
returnstr += FangYar.Common.JsonHelper.ToJson(list);
|
|
}
|
|
returnstr += "}";
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}";
|
|
}
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "用户角色操作请求", "查询");
|
|
return returnstr;
|
|
|
|
}
|
|
// 添加
|
|
private string AddModel(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
int code = -1;
|
|
string msg = "";
|
|
try
|
|
{
|
|
string UsersUid = context.Request.Params["UsersUid"];
|
|
string AppId = context.Request.Params["AppId"];
|
|
string ruleType = context.Request.Params["ruleType"];
|
|
string RulesId = context.Request.Params["RulesId"];
|
|
|
|
if (string.IsNullOrEmpty(UsersUid))
|
|
{
|
|
msg = "登录账户不能为空!";
|
|
}
|
|
else if (string.IsNullOrEmpty(AppId))
|
|
{
|
|
msg = "所属应用不能为空!";
|
|
}
|
|
|
|
else
|
|
{
|
|
|
|
FangYar.Model.TBL.TBL_SYS_USERSRULES_Model model = new Model.TBL.TBL_SYS_USERSRULES_Model();
|
|
model.ID = Guid.NewGuid().ToString("N");
|
|
model.USERS_UID = UsersUid;
|
|
model.APP_ID = AppId;
|
|
model.RULES_TYPE = ruleType;
|
|
model.RULES_ID = RulesId;
|
|
if (bll.Add(model))
|
|
{
|
|
msg = "添加成功!";
|
|
code = 1;
|
|
}
|
|
else
|
|
{
|
|
msg = "添加失败!";
|
|
}
|
|
}
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
msg = "添加失败!";
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "用户角色操作请求", "添加异常:" + e);
|
|
}
|
|
returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}";
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Add, "用户角色操作请求", "添加");
|
|
return returnstr;
|
|
|
|
}
|
|
//修改
|
|
private string EditModel(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
int code = -1;
|
|
string msg = "";
|
|
try
|
|
{
|
|
string ID = context.Request.Params["ID"];
|
|
string UsersUid = context.Request.Params["UsersUid"];
|
|
string AppId = context.Request.Params["AppId"];
|
|
string ruleType = context.Request.Params["ruleType"];
|
|
string RulesId = context.Request.Params["RulesId"];
|
|
|
|
if (string.IsNullOrEmpty(UsersUid))
|
|
{
|
|
msg = "登录账户不能为空!";
|
|
}
|
|
else if (string.IsNullOrEmpty(AppId))
|
|
{
|
|
msg = "所属应用不能为空!";
|
|
}
|
|
FangYar.Model.TBL.TBL_SYS_USERSRULES_Model model = bll.GetModelByID(ID);
|
|
if (model == null)
|
|
{
|
|
msg = "应用记录不存在!";
|
|
}
|
|
else
|
|
{
|
|
model.USERS_UID = UsersUid;
|
|
model.APP_ID = AppId;
|
|
model.RULES_TYPE = ruleType;
|
|
model.RULES_ID = RulesId;
|
|
if (bll.Edit(model))
|
|
{
|
|
msg = "修改成功!";
|
|
code = 1;
|
|
}
|
|
else
|
|
{
|
|
msg = "修改失败!";
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
msg = "修改失败!";
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "用户角色操作请求", "修改异常:" + e);
|
|
}
|
|
returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}";
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Update, "用户角色操作请求", "修改");
|
|
return returnstr;
|
|
|
|
}
|
|
//删除
|
|
private string DelModel(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
int code = -1;
|
|
string msg = "";
|
|
try
|
|
{
|
|
string UIDList = context.Request.Params["UIDList"];
|
|
UIDList = UIDList.Replace(",", "','");
|
|
if (bll.Delete(UIDList))
|
|
{
|
|
msg = "删除成功!";
|
|
code = 1;
|
|
}
|
|
else
|
|
{
|
|
msg = "删除失败!";
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
msg = "删除失败!";
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "用户角色操作请求", "删除异常:" + e);
|
|
}
|
|
returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}";
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Delete, "用户角色操作请求", "删除");
|
|
return returnstr;
|
|
|
|
}
|
|
//获取当前权限列表
|
|
private string getUserRules(HttpContext context)
|
|
{
|
|
|
|
string UsersUid = context.Request.Params["UsersUid"];
|
|
string AppId = context.Request.Params["AppId"];
|
|
string rulesTypes = context.Request.Params["rulesTypes"];
|
|
string OrgId = context.Request.Params["OrgId"];
|
|
|
|
string returnstr = "";
|
|
try
|
|
{
|
|
returnstr = "{\"code\":0,\"data\":";
|
|
|
|
DataTable dt = bll.getUserRules(UsersUid, AppId, rulesTypes, OrgId);
|
|
if (dt == null || dt.Rows.Count == 0)
|
|
{
|
|
returnstr += "[]";
|
|
}
|
|
else
|
|
{
|
|
returnstr += FangYar.Common.JsonHelper.ToJson(dt);
|
|
}
|
|
returnstr += "}";
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
returnstr = "{\"code\":-1,\"data\":[]}";
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "用户角色操作请求", "获取当前权限列表异常:" + e);
|
|
}
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "用户角色操作请求", "获取当前权限列表");
|
|
return returnstr;
|
|
|
|
}
|
|
//用户设置权限或者角色
|
|
private string UserPermAddEdit(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
int code = -1;
|
|
string msg = "";
|
|
int deleteCount = 0;
|
|
try
|
|
{
|
|
string UsersUid = context.Request.Params["UsersUid"];
|
|
string AppId = context.Request.Params["AppId"];
|
|
string ruleType = context.Request.Params["ruleType"];
|
|
string RulesId = context.Request.Params["RulesId"];
|
|
RulesId = RulesId.Trim(',');
|
|
string[] RulesIdArry = RulesId.Split(',');
|
|
//清空原来的权限或角色
|
|
bool isDelete = bll.Delete(UsersUid, ruleType);
|
|
if (isDelete)
|
|
{
|
|
for (int i = 0; i < RulesIdArry.Length; i++)
|
|
{
|
|
FangYar.Model.TBL.TBL_SYS_USERSRULES_Model model = new Model.TBL.TBL_SYS_USERSRULES_Model();
|
|
model.APP_ID = AppId;
|
|
model.USERS_UID = UsersUid;
|
|
model.RULES_TYPE = ruleType;
|
|
model.RULES_ID = RulesIdArry[i];
|
|
bll.Add(model);
|
|
}
|
|
msg = "设置成功!";
|
|
code = 1;
|
|
}
|
|
else
|
|
{
|
|
msg = "设置失败!";
|
|
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
msg = "设置失败!";
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "用户角色操作请求", "用户设置权限或者角色异常:" + e);
|
|
|
|
}
|
|
returnstr = "{\"code\":" + code + ",\"deleteCount\":" + deleteCount + ",\"msg\":\"" + msg + "\"}";
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Update, "用户角色操作请求", "用户设置权限或者角色");
|
|
return returnstr;
|
|
}
|
|
// 角色选择用户展示用户列表
|
|
private string ChooseUSer(HttpContext context)
|
|
{
|
|
string appId = context.Request.Params["appId"];
|
|
string roleId = context.Request.Params["roleId"];
|
|
string returnstr = "";
|
|
try
|
|
{
|
|
returnstr = "{\"code\":0,\"data\":";
|
|
|
|
DataTable dt = bll.ChooseUSer(appId, roleId);
|
|
if (dt.Rows.Count == 0)
|
|
{
|
|
returnstr += "[]";
|
|
}
|
|
else
|
|
{
|
|
returnstr += FangYar.Common.JsonHelper.ToJson(dt);
|
|
}
|
|
returnstr += "}";
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
returnstr = "{\"code\":-1,\"data\":[]}";
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "用户角色操作请求", "角色选择用户展示用户列表异常:" + e);
|
|
|
|
}
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "用户角色操作请求", "角色选择用户展示用户列表");
|
|
return returnstr;
|
|
|
|
|
|
}
|
|
//保存角色选择的用户
|
|
private string RoleChooseUser(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
int code = -1;
|
|
string msg = "";
|
|
int deleteCount = 0;
|
|
try
|
|
{
|
|
string appId = context.Request.Params["appId"];
|
|
string roleId = context.Request.Params["roleId"];//角色
|
|
string ruleType = context.Request.Params["ruleType"];
|
|
string userIdList = context.Request.Params["userIdList"];
|
|
userIdList = userIdList.Trim(',');
|
|
string[] userIdArry = userIdList.Split(',');
|
|
//清空所有角色下的用户
|
|
bool isDelete = bll.DeleteByRulesId(roleId, ruleType);
|
|
if (isDelete)
|
|
{
|
|
for (int i = 0; i < userIdArry.Length; i++)
|
|
{
|
|
FangYar.Model.TBL.TBL_SYS_USERSRULES_Model model = new Model.TBL.TBL_SYS_USERSRULES_Model();
|
|
model.APP_ID = appId;
|
|
model.USERS_UID = userIdArry[i];
|
|
model.RULES_TYPE = ruleType;
|
|
model.RULES_ID = roleId;
|
|
bll.Add(model);
|
|
}
|
|
msg = "设置成功!";
|
|
code = 1;
|
|
}
|
|
else
|
|
{
|
|
msg = "设置失败";
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
msg = "设置失败!";
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "用户角色操作请求", "保存角色选择的用户异常:" + e);
|
|
}
|
|
returnstr = "{\"code\":" + code + ",\"deleteCount\":" + deleteCount + ",\"msg\":\"" + msg + "\"}";
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Add, "用户角色操作请求", "保存角色选择的用户");
|
|
return returnstr;
|
|
|
|
}
|
|
public bool IsReusable
|
|
{
|
|
get
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|