增加根据群组指定用户功能
This commit is contained in:
parent
9d1f5c1385
commit
15dc1a6b1b
|
@ -235,7 +235,7 @@
|
|||
}
|
||||
if (result) { swal("成功", "授权角色", "success"); }
|
||||
else { swal("失败", "授权角色", "error"); }
|
||||
data.callback(result);
|
||||
if ($.isFunction(data.callback)) data.callback(result);
|
||||
},
|
||||
error: function (XMLHttpRequest, textStatus, errorThrown) {
|
||||
if ($.isFunction(data.callback)) data.callback(false);
|
||||
|
@ -284,7 +284,7 @@
|
|||
}
|
||||
if (result) { swal("成功", "授权用户", "success"); }
|
||||
else { swal("失败", "授权用户", "error"); }
|
||||
data.callback(result);
|
||||
if ($.isFunction(data.callback)) data.callback(result);
|
||||
},
|
||||
error: function (XMLHttpRequest, textStatus, errorThrown) {
|
||||
if ($.isFunction(data.callback)) data.callback(false);
|
||||
|
@ -299,6 +299,12 @@
|
|||
User.saveUsersByRoleId = function (roleId, userIds, callback) {
|
||||
processUsersData({ Id: roleId, callback: callback, method: "PUT", data: { type: "role", userIds: userIds } });
|
||||
}
|
||||
User.getUsersByGroupeId = function (groupId, callback) {
|
||||
processUsersData({ Id: groupId, callback: callback, data: { type: "group" } });
|
||||
};
|
||||
User.saveUsersByGroupId = function (groupId, userIds, callback) {
|
||||
processUsersData({ Id: groupId, callback: callback, method: "PUT", data: { type: "group", userIds: userIds } });
|
||||
}
|
||||
|
||||
var processGroupsData = function (options) {
|
||||
var data = $.extend({ data: { type: "" }, method: "POST", Id: "" }, options);
|
||||
|
|
|
@ -38,6 +38,9 @@ namespace Bootstrap.Admin.Controllers
|
|||
case "role":
|
||||
ret = UserHelper.RetrieveUsersByRoleId(id).ToList();
|
||||
break;
|
||||
case "group":
|
||||
ret = UserHelper.RetrieveUsersByGroupId(id).ToList();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -75,6 +78,9 @@ namespace Bootstrap.Admin.Controllers
|
|||
case "role":
|
||||
ret = UserHelper.SaveUsersByRoleId(id, userIds);
|
||||
break;
|
||||
case "group":
|
||||
ret = UserHelper.SaveUsersByGroupId(id, userIds);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -19,26 +19,32 @@
|
|||
});
|
||||
}
|
||||
}, {
|
||||
id: 'btn_assignGroup',
|
||||
id: 'btn_assignUser',
|
||||
click: function (row) {
|
||||
var userId = row.ID;
|
||||
User.getUsersByGroupeId(row.ID, function (data) {
|
||||
$("#dialogUser .modal-title").text($.format('{0}-指定用户窗口', row.GroupName));
|
||||
$('#dialogUser form').html(data);
|
||||
$('#dialogUser').modal('show');
|
||||
});
|
||||
}
|
||||
}, {
|
||||
id: 'btnSubmitUserRole',
|
||||
click: function (row) {
|
||||
var userId = row.ID;
|
||||
|
||||
var groupId = row.ID;
|
||||
var roleIds = $('#dialogRole :checked').map(function (index, element) {
|
||||
return $(element).val();
|
||||
}).toArray().join(',');
|
||||
Role.saveRolesByGroupId(userId, roleIds, function (result) {
|
||||
if (result) {
|
||||
$('#dialogRole').modal("hide");
|
||||
swal("成功", "修改角色", "success");
|
||||
} else {
|
||||
swal("失败", "修改角色", "error");
|
||||
}
|
||||
|
||||
});
|
||||
Role.saveRolesByGroupId(groupId, roleIds, { modal: 'dialogRole' });
|
||||
}
|
||||
},{
|
||||
id: 'btnSubmitRoleUser',
|
||||
click: function (row) {
|
||||
var groupId = row.ID;
|
||||
var userIds = $('#dialogUser :checked').map(function (index, element) {
|
||||
return $(element).val();
|
||||
}).toArray().join(',');
|
||||
User.saveUsersByGroupId(groupId, userIds, { modal: 'dialogUser' });
|
||||
}
|
||||
}]
|
||||
},
|
||||
|
|
|
@ -56,4 +56,5 @@
|
|||
}
|
||||
@section customModal {
|
||||
@Html.Partial("RoleConfig")
|
||||
@Html.Partial("UserConfig")
|
||||
}
|
|
@ -35,6 +35,7 @@
|
|||
<add key="MenuData-CodeMenuHelper" interval="600" desc="菜单信息缓存" />
|
||||
<add key="LogData-CodeMenuHelper" interval="600" desc="日志信息缓存" />
|
||||
<add key="DictData-CodeDictHelper" interval="600" desc="字典信息缓存" />
|
||||
<add key="UserData-CodeUserHelper-Group-" interval="600" desc="用户信息缓存" />
|
||||
</cacheManager>
|
||||
|
||||
<cacheManagerList>
|
||||
|
|
|
@ -21,6 +21,7 @@ namespace Bootstrap.DataAccess
|
|||
private const string UserDataKey = "UserData-CodeUserHelper";
|
||||
private const string UserDisplayNameDataKey = "UserData-CodeUserHelper-";
|
||||
private const string UserRoleIDDataKey = "UserData-CodeUserHelper-Role-";
|
||||
private const string UserGroupIDDataKey = "UserData-CodeUserHelper-Group-";
|
||||
/// <summary>
|
||||
/// 查询所有用户
|
||||
/// </summary>
|
||||
|
@ -254,5 +255,92 @@ namespace Bootstrap.DataAccess
|
|||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过groupId获取所有用户
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<User> RetrieveUsersByGroupId(int groupId)
|
||||
{
|
||||
|
||||
string key = string.Format("{0}{1}", UserGroupIDDataKey, groupId);
|
||||
return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(UserGroupIDDataKey), k =>
|
||||
{
|
||||
List<User> Users = new List<User>();
|
||||
string sql = "select u.ID,u.UserName,u.DisplayName,case ur.UserID when u.ID then 'checked' else '' end [status] from Users u left join UserGroup ur on u.ID=ur.UserID and GroupID =@groupId";
|
||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@GroupID", groupId, ParameterDirection.Input));
|
||||
try
|
||||
{
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
Users.Add(new User()
|
||||
{
|
||||
ID = (int)reader[0],
|
||||
UserName = (string)reader[1],
|
||||
DisplayName = (string)reader[2],
|
||||
Checked = (string)reader[3]
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { ExceptionManager.Publish(ex); }
|
||||
return Users;
|
||||
}, CacheSection.RetrieveDescByKey(UserRoleIDDataKey));
|
||||
}
|
||||
/// <summary>
|
||||
/// 通过部门ID保存当前授权用户(插入)
|
||||
/// </summary>
|
||||
/// <param name="id">GroupID</param>
|
||||
/// <param name="value">用户ID数组</param>
|
||||
/// <returns></returns>
|
||||
public static bool SaveUsersByGroupId(int id, string userIds)
|
||||
{
|
||||
bool ret = false;
|
||||
DataTable dt = new DataTable();
|
||||
dt.Columns.Add("UserID", typeof(int));
|
||||
dt.Columns.Add("GroupID", typeof(int));
|
||||
if (!string.IsNullOrEmpty(userIds))
|
||||
{
|
||||
userIds.Split(',').ToList().ForEach(userId =>
|
||||
{
|
||||
DataRow dr = dt.NewRow();
|
||||
dt.Rows.Add(userId, id);
|
||||
});
|
||||
}
|
||||
using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
|
||||
{
|
||||
try
|
||||
{
|
||||
//删除用户角色表该角色所有的用户
|
||||
string sql = "delete from UserGroup where GroupID=@groupID";
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
{
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@groupID", id, ParameterDirection.Input));
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd, transaction);
|
||||
//批插入用户角色表
|
||||
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
||||
{
|
||||
bulk.DestinationTableName = "UserGroup";
|
||||
bulk.ColumnMappings.Add("UserID", "UserID");
|
||||
bulk.ColumnMappings.Add("GroupID", "GroupID");
|
||||
bulk.WriteToServer(dt);
|
||||
transaction.CommitTransaction();
|
||||
}
|
||||
}
|
||||
ret = true;
|
||||
ClearCache();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
transaction.RollbackTransaction();
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue