角色指派部门功能
This commit is contained in:
parent
8c79d0955d
commit
2b912b73e5
|
@ -333,7 +333,11 @@
|
|||
Group.saveGroupsByUserId = function (userId, groupIds, callback) {
|
||||
processGroupsData({ Id: userId, callback: callback, method: "PUT", data: { type: "user", groupIds: groupIds } });
|
||||
};
|
||||
Group.getGroupsByRoleId = function (roleId) {
|
||||
|
||||
Group.getGroupsByRoleId = function (roleId,callback) {
|
||||
processGroupsData({ Id: roleId, callback: callback, data: { type: "role" } });
|
||||
};
|
||||
Group.saveGroupsByRoleId = function (roleId,groupIds,callback) {
|
||||
processGroupsData({ Id: roleId, callback: callback, method: "PUT", data: { type: "role", groupIds: groupIds } });
|
||||
};
|
||||
};
|
||||
})(jQuery);
|
|
@ -62,6 +62,9 @@ namespace Bootstrap.Admin.Controllers
|
|||
{
|
||||
case "user":
|
||||
ret = GroupHelper.RetrieveGroupsByUserId(id).ToList();
|
||||
break;
|
||||
case "role":
|
||||
ret = GroupHelper.RetrieveGroupsByRoleId(id).ToList();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -84,6 +87,9 @@ namespace Bootstrap.Admin.Controllers
|
|||
{
|
||||
case "user":
|
||||
ret = GroupHelper.SaveGroupsByUserId(id, groupIds);
|
||||
break;
|
||||
case "role":
|
||||
ret = GroupHelper.SaveGroupsByRoleId(id, groupIds);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -21,7 +21,11 @@
|
|||
}, {
|
||||
id: 'btn_assignGroup',
|
||||
click: function (row) {
|
||||
var roleId = row.ID;
|
||||
Group.getGroupsByRoleId(row.ID, function (data) {
|
||||
$("#dialogGroup.modal-title").text($.format('{0}-部门授权窗口', row.RoleName));
|
||||
$('#dialogGroup form').html(data);
|
||||
$('#dialogGroup').modal('show');
|
||||
})
|
||||
}
|
||||
}, {
|
||||
id: 'btnSubmitRoleUser',
|
||||
|
@ -32,6 +36,24 @@
|
|||
}).toArray().join(',');
|
||||
User.saveUsersByRoleId(roleId, userIds, { modal: 'dialogUser' });
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'btnSubmitRoleGroup',
|
||||
click: function (row) {
|
||||
var roleId = row.ID;
|
||||
var groupIds = $('#dialogGroup :checked').map(function (index, element) {
|
||||
return $(element).val();
|
||||
}).toArray().join(',');
|
||||
Group.saveGroupsByRoleId(roleId, groupIds, function (result) {
|
||||
if (result) {
|
||||
$('#dialogGroup').modal('hide');
|
||||
swal("成功", "修改部门", "success");
|
||||
}
|
||||
else {
|
||||
swal("失败", "修改部门", "error");
|
||||
}
|
||||
});
|
||||
}
|
||||
}]
|
||||
}
|
||||
});
|
||||
|
|
|
@ -56,4 +56,5 @@
|
|||
}
|
||||
@section customModal{
|
||||
@Html.Partial("UserConfig")
|
||||
}
|
||||
@Html.Partial("GroupConfig")
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
<add key="TerminalData-CodeTerminalHelper" interval="600" desc="输入口信息缓存" />
|
||||
<add key="GroupData-CodeGroupHelper" interval="600" desc="群组信息缓存" />
|
||||
<add key="UserData-CodeUserHelper-Role-" interval="600" desc="角色用户信息缓存" />
|
||||
<add key="GroupData-CodeGroupHelper-Role-" interval="600" desc="角色部门信息缓存" />
|
||||
<add key="UserData-CodeUserHelper" interval="600" desc="用户信息缓存" />
|
||||
<add key="UserData-CodeUserHelper-" interval="600" desc="用户信息缓存" />
|
||||
<add key="RoleData-CodeRoleHelper" interval="600" desc="角色信息缓存" />
|
||||
|
|
|
@ -20,6 +20,7 @@ namespace Bootstrap.DataAccess
|
|||
{
|
||||
private const string GroupDataKey = "GroupData-CodeGroupHelper";
|
||||
private const string GroupUserIDDataKey = "GroupData-CodeGroupHelper-";
|
||||
private const string GroupRoleIDDataKey = "GroupData-CodeGroupHelper-Role-";
|
||||
/// <summary>
|
||||
/// 查询所有群组信息
|
||||
/// </summary>
|
||||
|
@ -203,6 +204,91 @@ namespace Bootstrap.DataAccess
|
|||
{
|
||||
CacheManager.Clear(key => key == GroupDataKey);
|
||||
CacheManager.Clear(key => key == GroupUserIDDataKey);
|
||||
CacheManager.Clear(key => key.Contains(GroupRoleIDDataKey));
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据角色ID指派部门
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<Group> RetrieveGroupsByRoleId(int roleId)
|
||||
{
|
||||
string k = string.Format("{0}{1}", GroupRoleIDDataKey, roleId);
|
||||
return CacheManager.GetOrAdd(k, CacheSection.RetrieveIntervalByKey(GroupRoleIDDataKey), key =>
|
||||
{
|
||||
List<Group> Groups = new List<Group>();
|
||||
string sql = "select g.ID,g.GroupName,g.[Description],case rg.GroupID when g.ID then 'checked' else '' end [status] from Groups g left join RoleGroup rg on g.ID=rg.GroupID and RoleID=@RoleID";
|
||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@RoleID", roleId, ParameterDirection.Input));
|
||||
try
|
||||
{
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
Groups.Add(new Group()
|
||||
{
|
||||
ID=(int)reader[0],
|
||||
GroupName=(string)reader[1],
|
||||
Description=(string)reader[2],
|
||||
Checked = (string)reader[3]
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { ExceptionManager.Publish(ex); }
|
||||
return Groups;
|
||||
},CacheSection.RetrieveDescByKey(GroupRoleIDDataKey));
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据角色ID以及选定的部门ID,保到角色部门表
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static bool SaveGroupsByRoleId(int id, string groupIds)
|
||||
{
|
||||
bool ret = false;
|
||||
DataTable dt = new DataTable();
|
||||
dt.Columns.Add("GroupID", typeof(int));
|
||||
dt.Columns.Add("RoleID", typeof(int));
|
||||
if (!string.IsNullOrEmpty(groupIds))
|
||||
{
|
||||
groupIds.Split(',').ToList().ForEach(groupId =>
|
||||
{
|
||||
DataRow dr = dt.NewRow();
|
||||
dt.Rows.Add(groupId, id);
|
||||
});
|
||||
}
|
||||
using(TransactionPackage transaction=DBAccessManager.SqlDBAccess.BeginTransaction()){
|
||||
try
|
||||
{
|
||||
//删除角色部门表该角色所有的部门
|
||||
string sql = "delete from RoleGroup where RoleID=@RoleID";
|
||||
using (DbCommand cmd=DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text,sql))
|
||||
{
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@RoleID", id, ParameterDirection.Input));
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd, transaction);
|
||||
//批插入角色部门表
|
||||
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
||||
{
|
||||
bulk.BatchSize=1000;
|
||||
bulk.ColumnMappings.Add("GroupID","GroupID");
|
||||
bulk.ColumnMappings.Add("RoleID","RoleID");
|
||||
bulk.DestinationTableName = "RoleGroup";
|
||||
bulk.WriteToServer(dt);
|
||||
transaction.CommitTransaction();
|
||||
}
|
||||
}
|
||||
ret = true;
|
||||
ClearCache();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ExceptionManager.Publish(ex);
|
||||
transaction.RollbackTransaction();
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,16 +107,7 @@ namespace Bootstrap.DataAccess
|
|||
}
|
||||
return ret;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static bool SaveRolesByGroupId(int id, string value)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询某个用户所拥有的角色
|
||||
/// </summary>
|
||||
|
@ -150,15 +141,7 @@ namespace Bootstrap.DataAccess
|
|||
return Roles;
|
||||
}, CacheSection.RetrieveDescByKey(RoleUserIDDataKey));
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="groupId"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<Role> RetrieveRolesByGroupId(int groupId)
|
||||
{
|
||||
return new List<Role>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除角色表
|
||||
/// </summary>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Longbow.Caching;
|
||||
using Longbow.Caching.Configuration;
|
||||
using Longbow.Data;
|
||||
using Longbow.ExceptionManagement;
|
||||
using Longbow.Security;
|
||||
using System;
|
||||
|
@ -208,48 +209,50 @@ namespace Bootstrap.DataAccess
|
|||
/// <param name="id">角色ID</param>
|
||||
/// <param name="value">用户ID数组</param>
|
||||
/// <returns></returns>
|
||||
public static bool SaveUsersByRoleId(int id, string value)
|
||||
public static bool SaveUsersByRoleId(int id, string userIds)
|
||||
{
|
||||
bool ret = false;
|
||||
DataTable dt = new DataTable();
|
||||
dt.Columns.Add("RoleID", typeof(int));
|
||||
dt.Columns.Add("UserID", typeof(int));
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
if (!string.IsNullOrEmpty(userIds))
|
||||
{
|
||||
string[] userIds = value.Split(',');
|
||||
foreach (string userId in userIds)
|
||||
userIds.Split(',').ToList().ForEach(userId =>
|
||||
{
|
||||
DataRow dr = dt.NewRow();
|
||||
dr["RoleID"] = id;
|
||||
dr["UserID"] = userId;
|
||||
dt.Rows.Add(dr);
|
||||
}
|
||||
dt.Rows.Add(id, userId);
|
||||
});
|
||||
}
|
||||
var trans = DBAccessManager.SqlDBAccess.BeginTransaction();
|
||||
try
|
||||
using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
|
||||
{
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, string.Empty))
|
||||
try
|
||||
{
|
||||
cmd.CommandText = "delete from UserRole where RoleId=@RoleId";
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@RoleId", id, ParameterDirection.Input));
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd, trans);
|
||||
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)trans.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)trans.Transaction))
|
||||
//删除用户角色表该角色所有的用户
|
||||
string sql = "delete from UserRole where RoleId=@RoleId";
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
{
|
||||
bulk.BatchSize = 1000;
|
||||
bulk.DestinationTableName = "UserRole";
|
||||
bulk.ColumnMappings.Add("RoleID", "RoleID");
|
||||
bulk.ColumnMappings.Add("UserID", "UserID");
|
||||
bulk.WriteToServer(dt);
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@RoleID", id, ParameterDirection.Input));
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd, transaction);
|
||||
//批插入用户角色表
|
||||
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
||||
{
|
||||
bulk.DestinationTableName = "UserRole";
|
||||
bulk.ColumnMappings.Add("RoleID", "RoleID");
|
||||
bulk.ColumnMappings.Add("UserID", "UserID");
|
||||
bulk.WriteToServer(dt);
|
||||
transaction.CommitTransaction();
|
||||
}
|
||||
}
|
||||
trans.CommitTransaction();
|
||||
ret= true;
|
||||
ClearCache();
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
transaction.RollbackTransaction();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
trans.RollbackTransaction();
|
||||
return false;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue