提交rbac
提交设置右键错位的bug
This commit is contained in:
167
DH.RBAC/Logic/Sys/SysItemLogic.cs
Normal file
167
DH.RBAC/Logic/Sys/SysItemLogic.cs
Normal file
@ -0,0 +1,167 @@
|
||||
using DH.RBAC.Model.Sys;
|
||||
using DH.RBAC.Logic.Base;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SqlSugar;
|
||||
using DH.RBAC.Utility.Other;
|
||||
|
||||
|
||||
namespace DH.RBAC.Logic.Sys
|
||||
{
|
||||
public class SysItemLogic : BaseLogic
|
||||
{
|
||||
|
||||
public List<SysItem> GetList()
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
return db.Queryable<SysItem>().Where(it => it.DeleteFlag == "N")
|
||||
.Includes(it => it.CreateUser)
|
||||
.Includes(it => it.ModifyUser)
|
||||
.OrderBy(it => it.SortCode)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public List<SysItem> GetAppList(int pageIndex, int pageSize, ref int totalCount)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
return db.Queryable<SysItem>().Where(it => it.ParentId != "0" && it.DeleteFlag == "N")
|
||||
.Includes(it => it.CreateUser)
|
||||
.Includes(it => it.ModifyUser)
|
||||
.OrderBy(it => it.SortCode)
|
||||
.ToPageList(pageIndex, pageSize, ref totalCount);
|
||||
}
|
||||
}
|
||||
public List<SysItem> GetList(int pageIndex, int pageSize, string keyWord, ref int totalCount)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
ISugarQueryable<SysItem> queryable = db.Queryable<SysItem>().Where(it => it.DeleteFlag == "N");
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(keyWord))
|
||||
{
|
||||
queryable = queryable.Where(it => (it.Name.Contains(keyWord) || it.EnCode.Contains(keyWord)));
|
||||
}
|
||||
return queryable
|
||||
.Includes(it => it.CreateUser)
|
||||
.Includes(it => it.ModifyUser)
|
||||
.OrderBy(it => it.SortCode)
|
||||
.ToPageList(pageIndex, pageSize, ref totalCount);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int GetChildCount(string parentId)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
return db.Queryable<SysItem>()
|
||||
.Where(it => it.ParentId == parentId && it.DeleteFlag == "N")
|
||||
.ToList().Count();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public SysItem Get(string primaryKey)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
return db.Queryable<SysItem>().Where(it => it.DeleteFlag == "N")
|
||||
.Where(it => it.Id == primaryKey)
|
||||
.Includes(it => it.CreateUser)
|
||||
.Includes(it => it.ModifyUser)
|
||||
.First();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int AppInsert(SysItem model, string operateUser)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
SysItem s = db.Queryable<SysItem>().Where(it => it.ParentId == "0").First();
|
||||
model.Id = UUID.StrSnowId;
|
||||
model.Layer = s.Layer + 1;
|
||||
model.ParentId = s.Id;
|
||||
model.DeleteFlag = "N";
|
||||
model.CreateUserId = operateUser;
|
||||
model.CreateTime = DateTime.Now;
|
||||
model.ModifyUserId = model.CreateUser.Id;
|
||||
model.ModifyTime = model.CreateTime;
|
||||
return db.Insertable<SysItem>(model).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
|
||||
public int Insert(SysItem model, string account)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
model.Id = UUID.StrSnowId;
|
||||
model.Layer = Get(model.ParentId).Layer += 1;
|
||||
model.DeleteFlag = "N";
|
||||
model.CreateUserId = account;
|
||||
model.CreateTime = DateTime.Now;
|
||||
model.ModifyUserId = model.CreateUserId;
|
||||
model.ModifyTime = model.CreateTime;
|
||||
return db.Insertable<SysItem>(model).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
|
||||
public int Delete(string primaryKey)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
SysItem item = db.Queryable<SysItem>().Where(it => it.Id == primaryKey).First();
|
||||
if (item == null)
|
||||
return 0;
|
||||
item.DeleteFlag = "Y";
|
||||
return db.Updateable<SysItem>(item).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
public int Update(SysItem model, string account)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
model.Layer = Get(model.ParentId).Layer += 1;
|
||||
model.ModifyUserId = account;
|
||||
model.ModifyTime = DateTime.Now;
|
||||
return db.Updateable<SysItem>(model).UpdateColumns(it => new
|
||||
{
|
||||
it.ParentId,
|
||||
it.Layer,
|
||||
it.EnCode,
|
||||
it.Name,
|
||||
it.SortCode,
|
||||
it.EnableFlag,
|
||||
it.Remark,
|
||||
it.ModifyUserId,
|
||||
it.ModifyTime
|
||||
}).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int AppUpdate(SysItem model, string operateUser)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
model.ModifyUserId = operateUser;
|
||||
model.ModifyTime = DateTime.Now;
|
||||
return db.Updateable<SysItem>(model).UpdateColumns(it => new
|
||||
{
|
||||
it.EnCode,
|
||||
it.Name,
|
||||
it.SortCode,
|
||||
it.Remark,
|
||||
it.ModifyUserId,
|
||||
it.ModifyTime
|
||||
}).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
182
DH.RBAC/Logic/Sys/SysItemsDetailLogic.cs
Normal file
182
DH.RBAC/Logic/Sys/SysItemsDetailLogic.cs
Normal file
@ -0,0 +1,182 @@
|
||||
using DH.RBAC.Model.Sys;
|
||||
using DH.RBAC.Logic.Base;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using DH.RBAC.Utility.Other;
|
||||
|
||||
|
||||
namespace DH.RBAC.Logic.Sys
|
||||
{
|
||||
public class SysItemsDetailLogic : BaseLogic
|
||||
{
|
||||
public List<SysItemDetail> GetItemDetailList(string strItemCode)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
|
||||
SysItem item = db.Queryable<SysItem>().Where(it => it.EnCode == strItemCode && it.DeleteFlag == "N").First();
|
||||
if (null == item)
|
||||
return null;
|
||||
return db.Queryable<SysItemDetail>().Where(it => it.ItemId == item.Id && it.DeleteFlag == "N")
|
||||
.Includes(it => it.CreateUser)
|
||||
.Includes(it => it.ModifyUser)
|
||||
.OrderBy(it => it.SortCode)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public List<SysItemDetail> GetList(int pageIndex, int pageSize, string itemId, string keyWord, ref int totalCount)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
ISugarQueryable<SysItemDetail> queryable = db.Queryable<SysItemDetail>().Where(it => it.DeleteFlag == "N" && it.ItemId == itemId);
|
||||
if (!keyWord.IsNullOrEmpty())
|
||||
{
|
||||
queryable = queryable.Where(it => (it.Name.Contains(keyWord) || it.EnCode.Contains(keyWord)));
|
||||
}
|
||||
return queryable
|
||||
.Includes(it => it.CreateUser)
|
||||
.Includes(it => it.ModifyUser)
|
||||
.OrderBy(it => it.SortCode)
|
||||
.ToPageList(pageIndex, pageSize, ref totalCount);
|
||||
}
|
||||
}
|
||||
|
||||
public List<SysItemDetail> GetListByItemId(string itemId)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
return db.Queryable<SysItemDetail>()
|
||||
.Where(it => it.ItemId == itemId && it.DeleteFlag == "N")
|
||||
.Includes(it => it.CreateUser)
|
||||
.Includes(it => it.ModifyUser)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public void InsertItemDetail(string itemId, List<SysItemDetail> list)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
try
|
||||
{
|
||||
db.BeginTran();
|
||||
List<SysItemDetail> list2 = db.Queryable<SysItemDetail>().Where(it => it.ItemId == itemId && it.DeleteFlag == "N").ToList();
|
||||
list2.ForEach(it => { it.DeleteFlag = "Y"; });
|
||||
db.Updateable<SysItemDetail>(list2).ExecuteCommand();
|
||||
db.Insertable<SysItemDetail>(list).ExecuteCommand();
|
||||
db.CommitTran();
|
||||
}
|
||||
catch
|
||||
{
|
||||
db.RollbackTran();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public SysItemDetail Get(string primaryKey)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
return db.Queryable<SysItemDetail>()
|
||||
.Where(it => it.DeleteFlag == "N" && it.Id == primaryKey)
|
||||
.Includes(it => it.CreateUser)
|
||||
.Includes(it => it.ModifyUser)
|
||||
.First();
|
||||
}
|
||||
}
|
||||
|
||||
public int Insert(SysItemDetail model, string account)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
model.Id = UUID.StrSnowId;
|
||||
model.IsDefault = model.IsDefault == null ? "0" : "1";
|
||||
model.DeleteFlag = "N";
|
||||
model.CreateUserId = account;
|
||||
model.CreateTime = DateTime.Now;
|
||||
model.ModifyUserId = model.CreateUserId;
|
||||
model.ModifyTime = model.CreateTime;
|
||||
return db.Insertable<SysItemDetail>(model).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
|
||||
public int AppInsert(SysItemDetail model, string operateUser)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
model.Id = UUID.StrSnowId;
|
||||
model.IsDefault = "0";
|
||||
model.DeleteFlag = "N";
|
||||
model.CreateUserId = operateUser;
|
||||
model.CreateTime = DateTime.Now;
|
||||
model.ModifyUserId = model.CreateUserId;
|
||||
model.ModifyTime = model.CreateTime;
|
||||
return db.Insertable<SysItemDetail>(model).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int AppUpdate(SysItemDetail model, string operateUser)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
model.ModifyUserId = operateUser;
|
||||
model.ModifyTime = DateTime.Now;
|
||||
return db.Updateable<SysItemDetail>(model).UpdateColumns(it => new
|
||||
{
|
||||
it.EnCode,
|
||||
it.Name,
|
||||
it.SortCode,
|
||||
it.ModifyUserId,
|
||||
it.ModifyTime
|
||||
}).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
|
||||
public int Delete(string itemId)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
SysItemDetail itemDetail = db.Queryable<SysItemDetail>().Where(it => it.Id == itemId).First();
|
||||
if (itemDetail == null)
|
||||
return 0;
|
||||
itemDetail.DeleteFlag = "Y";
|
||||
return db.Updateable<SysItemDetail>(itemDetail).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
|
||||
public int Update(SysItemDetail model, string account)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
model.IsDefault = model.IsDefault == null ? "0" : "1";
|
||||
model.ModifyUserId = account;
|
||||
model.ModifyTime = DateTime.Now;
|
||||
return db.Updateable<SysItemDetail>(model).UpdateColumns(it => new
|
||||
{
|
||||
it.ItemId,
|
||||
it.EnCode,
|
||||
it.Name,
|
||||
it.IsDefault,
|
||||
it.SortCode,
|
||||
it.EnableFlag,
|
||||
it.ModifyUserId,
|
||||
it.ModifyTime
|
||||
}).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
|
||||
public SysItemDetail GetSoftwareName()
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
return db.Queryable<SysItemDetail>().Where(it => it.EnCode == "SoftwareName").First();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
123
DH.RBAC/Logic/Sys/SysLogLogic.cs
Normal file
123
DH.RBAC/Logic/Sys/SysLogLogic.cs
Normal file
@ -0,0 +1,123 @@
|
||||
using DH.RBAC.Model.Sys;
|
||||
using DH.RBAC.Logic.Base;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using DH.RBAC.Utility.Other;
|
||||
|
||||
|
||||
namespace DH.RBAC.Logic.Sys
|
||||
{
|
||||
/// <summary>
|
||||
/// 系统日志表数据访问
|
||||
/// </summary>
|
||||
public class SysLogLogic : BaseLogic
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 根据日志类型获得日志
|
||||
/// </summary>
|
||||
/// <param name="pageIndex"></param>
|
||||
/// <param name="pageSize"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="index"></param>
|
||||
/// <param name="keyWord"></param>
|
||||
/// <param name="totalCount"></param>
|
||||
/// <returns></returns>
|
||||
public List<SysLog> GetList(int pageIndex, int pageSize, string type, string index, string keyWord, ref int totalCount)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
ISugarQueryable<SysLog> query = db.Queryable<SysLog>().Where(it => it.Type == type);
|
||||
if (!keyWord.IsNullOrEmpty())
|
||||
{
|
||||
query = query.Where(it => it.Message.Contains(keyWord));
|
||||
}
|
||||
//查询当日
|
||||
if (index == "1")
|
||||
{
|
||||
DateTime today = DateTime.Today;
|
||||
DateTime startTime = today;
|
||||
DateTime endTime = today.AddDays(1);
|
||||
query = query.Where(it => it.CreateTime >= startTime && it.CreateTime < endTime);
|
||||
}
|
||||
//近7天
|
||||
else if (index == "2")
|
||||
{
|
||||
DateTime today = DateTime.Today;
|
||||
DateTime startTime = today.AddDays(-6);
|
||||
DateTime endTime = today.AddDays(1);
|
||||
query = query.Where(it => it.CreateTime >= startTime && it.CreateTime < endTime);
|
||||
}
|
||||
//近1月
|
||||
else if (index == "3")
|
||||
{
|
||||
DateTime today = DateTime.Today;
|
||||
DateTime startTime = today.AddDays(-29);
|
||||
DateTime endTime = today.AddDays(1);
|
||||
query = query.Where(it => it.CreateTime >= startTime && it.CreateTime < endTime);
|
||||
}
|
||||
//近3月
|
||||
else if (index == "4")
|
||||
{
|
||||
DateTime today = DateTime.Today;
|
||||
DateTime startTime = today.AddDays(-91);
|
||||
DateTime endTime = today.AddDays(1);
|
||||
query = query.Where(it => it.CreateTime >= startTime && it.CreateTime < endTime);
|
||||
}
|
||||
return query.OrderBy(it => it.Id, OrderByType.Desc).ToPageList(pageIndex, pageSize, ref totalCount);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 删除日志
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="index"></param>
|
||||
/// <returns></returns>
|
||||
public int Delete(string type, string index)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
IDeleteable<SysLog> query = db.Deleteable<SysLog>().Where(it => it.Type == type);
|
||||
//保留一个月
|
||||
if (index == "1")
|
||||
{
|
||||
DateTime today = DateTime.Today;
|
||||
DateTime startTime = today;
|
||||
DateTime endTime = today.AddDays(-29);
|
||||
query = query.Where(it => it.CreateTime < endTime);
|
||||
return query.ExecuteCommand();
|
||||
}
|
||||
//保留7天
|
||||
else if (index == "2")
|
||||
{
|
||||
DateTime today = DateTime.Today;
|
||||
DateTime startTime = today.AddDays(-6);
|
||||
query = query.Where(it => it.CreateTime < startTime);
|
||||
return query.ExecuteCommand();
|
||||
}
|
||||
//保留近3个月
|
||||
else if (index == "3")
|
||||
{
|
||||
DateTime today = DateTime.Today;
|
||||
DateTime startTime = today.AddDays(-92);
|
||||
query = query.Where(it => it.CreateTime < startTime);
|
||||
return query.ExecuteCommand();
|
||||
}
|
||||
//全部
|
||||
else if (index == "4")
|
||||
{
|
||||
return query.ExecuteCommand();
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
157
DH.RBAC/Logic/Sys/SysOrganizeLogic.cs
Normal file
157
DH.RBAC/Logic/Sys/SysOrganizeLogic.cs
Normal file
@ -0,0 +1,157 @@
|
||||
using DH.RBAC.Model.Sys;
|
||||
using DH.RBAC.Logic.Base;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using DH.RBAC.Utility.Other;
|
||||
|
||||
|
||||
namespace DH.RBAC.Logic.Sys
|
||||
{
|
||||
public class SysOrganizeLogic : BaseLogic
|
||||
{
|
||||
public List<SysOrganize> GetList()
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
return db.Queryable<SysOrganize>().Where(it => it.DeleteFlag == "N").ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public List<SysOrganize> GetList(int pageIndex, int pageSize, string keyWord, ref int totalCount)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
ISugarQueryable<SysOrganize> queryable = db.Queryable<SysOrganize>().Where(it => it.ParentId != "0" && it.DeleteFlag == "N");
|
||||
|
||||
if (!keyWord.IsNullOrEmpty())
|
||||
{
|
||||
queryable = queryable.Where(it => (it.FullName.Contains(keyWord) || it.EnCode.Contains(keyWord)));
|
||||
}
|
||||
return queryable
|
||||
.OrderBy(it => it.SortCode)
|
||||
.ToPageList(pageIndex, pageSize, ref totalCount);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int GetChildCount(string parentId)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
return db.Queryable<SysOrganize>().Where(it => it.ParentId == parentId && it.DeleteFlag == "N").Count();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int AppUpdate(SysOrganize model, string opreaterUser)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
model.ModifyUserId = opreaterUser;
|
||||
model.ModifyTime = DateTime.Now;
|
||||
return db.Updateable<SysOrganize>(model).UpdateColumns(it => new
|
||||
{
|
||||
it.EnCode,
|
||||
it.FullName,
|
||||
it.Type,
|
||||
it.ManagerId,
|
||||
it.TelePhone,
|
||||
it.WeChat,
|
||||
it.Fax,
|
||||
it.Email,
|
||||
it.Address,
|
||||
it.SortCode,
|
||||
it.Remark,
|
||||
it.ModifyUserId,
|
||||
it.ModifyTime
|
||||
}).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
|
||||
public int AppInsert(SysOrganize model, string opreaterUser)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
SysOrganize s = db.Queryable<SysOrganize>().Where(it => it.ParentId == "0").First();
|
||||
model.Id = UUID.StrSnowId;
|
||||
model.Layer = s.Layer + 1;
|
||||
model.ParentId = s.Id;
|
||||
|
||||
model.EnableFlag = "Y";
|
||||
model.DeleteFlag = "N";
|
||||
model.CreateUserId = opreaterUser;
|
||||
model.CreateTime = DateTime.Now;
|
||||
model.ModifyUserId = model.CreateUserId;
|
||||
model.ModifyTime = model.CreateTime;
|
||||
return db.Insertable<SysOrganize>(model).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
public int Insert(SysOrganize model, string account)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
model.Id = UUID.StrSnowId;
|
||||
model.Layer = Get(model.ParentId).Layer += 1;
|
||||
model.EnableFlag = "Y";
|
||||
model.DeleteFlag = "N";
|
||||
model.CreateUserId = account;
|
||||
model.CreateTime = DateTime.Now;
|
||||
model.ModifyUserId = model.CreateUserId;
|
||||
model.ModifyTime = model.CreateTime;
|
||||
return db.Insertable<SysOrganize>(model).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
|
||||
public int Delete(string primaryKey)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
SysOrganize organize = db.Queryable<SysOrganize>().Where(it => it.Id == primaryKey).First();
|
||||
if (organize == null)
|
||||
return 0;
|
||||
organize.DeleteFlag = "Y";
|
||||
return db.Updateable<SysOrganize>(organize).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
public SysOrganize Get(string primaryKey)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
return db.Queryable<SysOrganize>().Where(it => it.Id == primaryKey).Includes(it => it.CreateUser).Includes(it => it.ModifyUser).First();
|
||||
}
|
||||
}
|
||||
public int Update(SysOrganize model, string account)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
model.ModifyUserId = account;
|
||||
model.ModifyTime = DateTime.Now;
|
||||
return db.Updateable<SysOrganize>(model).UpdateColumns(it => new
|
||||
{
|
||||
it.ParentId,
|
||||
it.Layer,
|
||||
it.EnCode,
|
||||
it.FullName,
|
||||
it.Type,
|
||||
it.ManagerId,
|
||||
it.TelePhone,
|
||||
it.WeChat,
|
||||
it.Fax,
|
||||
it.Email,
|
||||
it.Address,
|
||||
it.SortCode,
|
||||
it.EnableFlag,
|
||||
it.Remark,
|
||||
it.ModifyUserId,
|
||||
it.ModifyTime
|
||||
}).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
238
DH.RBAC/Logic/Sys/SysPermissionLogic.cs
Normal file
238
DH.RBAC/Logic/Sys/SysPermissionLogic.cs
Normal file
@ -0,0 +1,238 @@
|
||||
using DH.RBAC.Model.Sys;
|
||||
using DH.RBAC.Logic.Base;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using DH.RBAC.Utility.Other;
|
||||
|
||||
|
||||
namespace DH.RBAC.Logic.Sys
|
||||
{
|
||||
public class SysPermissionLogic : BaseLogic
|
||||
{
|
||||
public bool ActionValidate(string userId, string action)
|
||||
{
|
||||
List<SysPermission> authorizeModules;
|
||||
if (new SysUserLogic().ContainsUser("admin", userId))
|
||||
{
|
||||
authorizeModules = GetList();
|
||||
}
|
||||
else
|
||||
{
|
||||
authorizeModules = GetList(userId);
|
||||
}
|
||||
foreach (var item in authorizeModules)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(item.Url))
|
||||
{
|
||||
string[] url = item.Url.Split('?');
|
||||
if (url[0].ToLower() == action.ToLower())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public List<SysPermission> GetList(string userId)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
List<string> permissionIdList = db.Queryable<SysUserRoleRelation, SysRoleAuthorize, SysPermission>((A, B, C) => new object[] {
|
||||
JoinType.Left,A.RoleId == B.RoleId,
|
||||
JoinType.Left,C.Id == B.ModuleId,
|
||||
})
|
||||
.Where((A, B, C) => A.UserId == userId && C.EnableFlag == "Y" && B.DeleteFlag == "N")
|
||||
.Select((A, B, C) => C.Id).ToList();
|
||||
return db.Queryable<SysPermission>().Where(it => permissionIdList.Contains(it.Id)).OrderBy(it => it.SortCode).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<SysPermission> GetList(int pageIndex, int pageSize, string keyWord, ref int totalCount)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
if (keyWord.IsNullOrEmpty())
|
||||
{
|
||||
return db.Queryable<SysPermission>().Where(it => it.DeleteFlag == "N").OrderBy(it => it.SortCode).ToPageList(pageIndex, pageSize, ref totalCount);
|
||||
}
|
||||
return db.Queryable<SysPermission>().Where(it => it.DeleteFlag == "N" && (it.Name.Contains(keyWord) || it.EnCode.Contains(keyWord))).OrderBy(it => it.SortCode).ToPageList(pageIndex, pageSize, ref totalCount);
|
||||
}
|
||||
}
|
||||
|
||||
public int Delete(params string[] primaryKeys)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
try
|
||||
{
|
||||
db.BeginTran();
|
||||
//删除权限与角色的对应关系。
|
||||
List<SysPermission> list = db.Queryable<SysPermission>().Where(it => primaryKeys.Contains(it.Id) && it.DeleteFlag == "N").ToList();
|
||||
List<string> ids = list.Select(it => it.Id).ToList();
|
||||
list.ForEach(it => { it.DeleteFlag = "Y"; });
|
||||
db.Updateable<SysPermission>(list).ExecuteCommand();
|
||||
List<SysRoleAuthorize> list2 = db.Queryable<SysRoleAuthorize>().Where(it => ids.Contains(it.ModuleId) && it.DeleteFlag == "N").ToList();
|
||||
list2.ForEach(it => { it.DeleteFlag = "Y"; });
|
||||
db.Updateable<SysRoleAuthorize>(list2).ExecuteCommand();
|
||||
db.CommitTran();
|
||||
return 1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
db.RollbackTran();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public int GetMaxChildMenuOrderCode(string parentId)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
//得到当前节点
|
||||
SysPermission permission = db.Queryable<SysPermission>().Where(it => it.Id == parentId && it.DeleteFlag == "N").First();
|
||||
if (permission == null)
|
||||
return 0;
|
||||
//得到子的
|
||||
SysPermission child = db.Queryable<SysPermission>().Where(it => it.ParentId == parentId && it.DeleteFlag == "N").OrderBy(it => it.SortCode, OrderByType.Desc).First();
|
||||
if (child == null)
|
||||
return permission.SortCode.Value + 100;
|
||||
else
|
||||
return child.SortCode.Value + 100;
|
||||
}
|
||||
}
|
||||
public int GetChildCount(string parentId)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
return db.Queryable<SysPermission>().Where(it => it.ParentId == parentId && it.DeleteFlag == "N").ToList().Count();
|
||||
}
|
||||
}
|
||||
|
||||
public List<SysPermission> GetList()
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
return db.Queryable<SysPermission>().Where(it => it.DeleteFlag == "N").OrderBy(it => it.SortCode).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public SysPermission Get(string primaryKey)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
return db.Queryable<SysPermission>().Where(it => it.Id == primaryKey).Includes(it => it.CreateUser).Includes(it => it.ModifyUser).First();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int Insert(SysPermission model, string account)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
model.Id = UUID.StrSnowId;
|
||||
model.Layer = model.Type == 2 ? 0 : model.Type == 0 ? 1 : 2;
|
||||
model.IsEdit = model.IsEdit == null ? "0" : "1";
|
||||
model.IsPublic = model.IsPublic == null ? "0" : "1";
|
||||
|
||||
model.DeleteFlag = "N";
|
||||
model.EnableFlag = "Y";
|
||||
model.CreateUserId = account;
|
||||
model.CreateTime = DateTime.Now;
|
||||
model.ModifyUserId = model.CreateUserId;
|
||||
model.ModifyTime = model.CreateTime;
|
||||
return db.Insertable<SysPermission>(model).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
public int AppInsert(SysPermission model, string operateUser)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
model.Id = UUID.StrSnowId;
|
||||
model.Layer = model.Type == 2 ? 0 : model.Type == 0 ? 1 : 2;
|
||||
model.IsEdit = "1";
|
||||
model.IsPublic = "0";
|
||||
|
||||
model.DeleteFlag = "N";
|
||||
model.EnableFlag = "Y";
|
||||
model.CreateUserId = operateUser;
|
||||
model.CreateTime = DateTime.Now;
|
||||
model.ModifyUserId = model.CreateUserId;
|
||||
model.ModifyTime = model.CreateTime;
|
||||
return db.Insertable<SysPermission>(model).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
|
||||
public int AppUpdate(SysPermission model, string operateUser)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
model.Layer = model.Type == 2 ? 0 : model.Type == 0 ? 1 : 2;
|
||||
model.ModifyUserId = operateUser;
|
||||
model.ModifyTime = DateTime.Now;
|
||||
return db.Updateable<SysPermission>(model).UpdateColumns(it => new
|
||||
{
|
||||
it.ParentId,
|
||||
it.Layer,
|
||||
it.EnCode,
|
||||
it.Name,
|
||||
it.JsEvent,
|
||||
it.Icon,
|
||||
it.SymbolIndex,
|
||||
it.Url,
|
||||
it.Remark,
|
||||
it.Type,
|
||||
it.SortCode,
|
||||
it.ModifyUserId,
|
||||
it.ModifyTime,
|
||||
}).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int Update(SysPermission model, string account)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
model.Layer = model.Type == 2 ? 0 : model.Type == 0 ? 1 : 2;
|
||||
model.IsEdit = model.IsEdit == null ? "0" : "1";
|
||||
model.IsPublic = model.IsPublic == null ? "0" : "1";
|
||||
model.ModifyUserId = account;
|
||||
model.ModifyTime = DateTime.Now;
|
||||
return db.Updateable<SysPermission>(model).UpdateColumns(it => new
|
||||
{
|
||||
it.ParentId,
|
||||
it.Layer,
|
||||
it.EnCode,
|
||||
it.Name,
|
||||
it.JsEvent,
|
||||
it.Icon,
|
||||
it.SymbolIndex,
|
||||
it.Url,
|
||||
it.Remark,
|
||||
it.Type,
|
||||
it.SortCode,
|
||||
it.IsPublic,
|
||||
it.EnableFlag,
|
||||
it.IsEdit,
|
||||
it.ModifyUserId,
|
||||
it.ModifyTime,
|
||||
}).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
public int InsertList(List<SysPermission> permissionList)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
return db.Insertable<SysPermission>(permissionList).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
170
DH.RBAC/Logic/Sys/SysRoleAuthorizeLogic.cs
Normal file
170
DH.RBAC/Logic/Sys/SysRoleAuthorizeLogic.cs
Normal file
@ -0,0 +1,170 @@
|
||||
using DH.RBAC.Model.Sys;
|
||||
using DH.RBAC.Logic.Base;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using DH.RBAC.Utility.Other;
|
||||
|
||||
|
||||
namespace DH.RBAC.Logic.Sys
|
||||
{
|
||||
public class SysRoleAuthorizeLogic : BaseLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// 获得角色权限关系
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<SysRoleAuthorize> GetList()
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
return db.Queryable<SysRoleAuthorize>().ToList();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据角色ID获得角色权限关系
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <returns></returns>
|
||||
public List<SysRoleAuthorize> GetList(string roleId)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
return db.Queryable<SysRoleAuthorize>().Where(it => it.RoleId == roleId && it.DeleteFlag == "N").ToList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 给某个角色授权
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <param name="perIds"></param>
|
||||
public void AppAuthorize(string operate, string roleId, params string[] perIds)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
try
|
||||
{
|
||||
db.BeginTran();
|
||||
//获得所有权限
|
||||
List<SysPermission> permissionList = db.Queryable<SysPermission>().Where(it => it.DeleteFlag == "N").ToList();
|
||||
List<string> perList = new List<string>();
|
||||
foreach (string perId in perIds)
|
||||
{
|
||||
string id = perId;
|
||||
while (!id.IsNullOrEmpty() && id != "0")
|
||||
{
|
||||
if (!perList.Contains(id))
|
||||
{
|
||||
perList.Add(id);
|
||||
}
|
||||
id = permissionList.Where(it => it.Id == id).Select(it => it.ParentId).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
//删除旧的
|
||||
List<SysRoleAuthorize> list2 = db.Queryable<SysRoleAuthorize>().Where(it => it.RoleId == roleId && it.DeleteFlag == "N").ToList();
|
||||
list2.ForEach(it => { it.DeleteFlag = "Y"; });
|
||||
db.Updateable<SysRoleAuthorize>(list2).ExecuteCommand();
|
||||
|
||||
|
||||
List<SysRoleAuthorize> newRoleAuthorizeList = perList.Select(it => new SysRoleAuthorize
|
||||
{
|
||||
Id = UUID.StrSnowId,
|
||||
RoleId = roleId,
|
||||
ModuleId = it,
|
||||
DeleteFlag = "N",
|
||||
EnableFlag = "Y",
|
||||
CreateUserId = operate,
|
||||
CreateTime = DateTime.Now,
|
||||
ModifyUserId = operate,
|
||||
ModifyTime = DateTime.Now
|
||||
|
||||
}).ToList();
|
||||
db.Insertable<SysRoleAuthorize>(newRoleAuthorizeList).ExecuteCommand();
|
||||
db.CommitTran();
|
||||
}
|
||||
catch
|
||||
{
|
||||
db.RollbackTran();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 给某个角色授权
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <param name="perIds"></param>
|
||||
public void Authorize(string roleId, string account, params string[] perIds)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
try
|
||||
{
|
||||
db.BeginTran();
|
||||
//获得所有权限
|
||||
List<SysPermission> permissionList = db.Queryable<SysPermission>().ToList();
|
||||
List<string> perList = new List<string>();
|
||||
foreach (string perId in perIds)
|
||||
{
|
||||
string id = perId;
|
||||
while (!id.IsNullOrEmpty() && id != "0")
|
||||
{
|
||||
if (!perList.Contains(id))
|
||||
{
|
||||
perList.Add(id);
|
||||
}
|
||||
id = permissionList.Where(it => it.Id == id).Select(it => it.ParentId).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
//删除旧的
|
||||
List<SysRoleAuthorize> list2 = db.Queryable<SysRoleAuthorize>().Where(it => it.RoleId == roleId && it.DeleteFlag == "N").ToList();
|
||||
list2.ForEach(it => { it.DeleteFlag = "Y"; });
|
||||
db.Updateable<SysRoleAuthorize>(list2).ExecuteCommand();
|
||||
|
||||
|
||||
List<SysRoleAuthorize> newRoleAuthorizeList = perList.Select(it => new SysRoleAuthorize
|
||||
{
|
||||
Id = UUID.StrSnowId,
|
||||
RoleId = roleId,
|
||||
ModuleId = it,
|
||||
DeleteFlag = "N",
|
||||
EnableFlag = "Y",
|
||||
CreateUserId = account,
|
||||
CreateTime = DateTime.Now,
|
||||
ModifyUserId = account,
|
||||
ModifyTime = DateTime.Now
|
||||
}).ToList();
|
||||
db.Insertable<SysRoleAuthorize>(newRoleAuthorizeList).ExecuteCommand();
|
||||
db.CommitTran();
|
||||
}
|
||||
catch
|
||||
{
|
||||
db.RollbackTran();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从角色权限关系中删除某个模块
|
||||
/// </summary>
|
||||
/// <param name="moduleIds"></param>
|
||||
/// <returns></returns>
|
||||
public int Delete(params string[] moduleIds)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
List<SysRoleAuthorize> list = db.Queryable<SysRoleAuthorize>().Where(it => moduleIds.Contains(it.ModuleId)).ToList();
|
||||
list.ForEach(it => { it.DeleteFlag = "Y"; });
|
||||
return db.Updateable<SysRoleAuthorize>(list).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
176
DH.RBAC/Logic/Sys/SysRoleLogic.cs
Normal file
176
DH.RBAC/Logic/Sys/SysRoleLogic.cs
Normal file
@ -0,0 +1,176 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using DH.RBAC.Model.Sys;
|
||||
using DH.RBAC.Logic.Base;
|
||||
using SqlSugar;
|
||||
using DH.RBAC.Utility.Other;
|
||||
|
||||
|
||||
namespace DH.RBAC.Logic.Sys
|
||||
{
|
||||
public class SysRoleLogic : BaseLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// 得到角色列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<SysRole> GetList()
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
return db.Queryable<SysRole>().Where(it => it.DeleteFlag == "N")
|
||||
.Includes(it => it.Organize)
|
||||
.Includes(it => it.CreateUser)
|
||||
.Includes(it => it.ModifyUser)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得角色列表分页
|
||||
/// </summary>
|
||||
/// <param name="pageIndex"></param>
|
||||
/// <param name="pageSize"></param>
|
||||
/// <param name="keyWord"></param>
|
||||
/// <param name="totalCount"></param>
|
||||
/// <returns></returns>
|
||||
public List<SysRole> GetList(int pageIndex, int pageSize, string keyWord, ref int totalCount)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
|
||||
ISugarQueryable<SysRole> queryable = db.Queryable<SysRole>().Where(it => it.DeleteFlag == "N");
|
||||
|
||||
if (!keyWord.IsNullOrEmpty())
|
||||
{
|
||||
queryable = queryable.Where(it => (it.Name.Contains(keyWord) || it.EnCode.Contains(keyWord)));
|
||||
}
|
||||
|
||||
return queryable.Includes(it => it.Organize)
|
||||
.Includes(it => it.CreateUser)
|
||||
.Includes(it => it.ModifyUser)
|
||||
.OrderBy(it => it.SortCode)
|
||||
.ToPageList(pageIndex, pageSize, ref totalCount);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增角色
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public int Insert(SysRole model, string account)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
model.Id = UUID.StrSnowId;
|
||||
model.AllowEdit = model.AllowEdit == null ? "0" : "1";
|
||||
model.DeleteFlag = "N";
|
||||
model.CreateUserId = account;
|
||||
model.CreateTime = DateTime.Now;
|
||||
model.ModifyUserId = model.CreateUserId;
|
||||
model.ModifyTime = model.CreateTime;
|
||||
return db.Insertable<SysRole>(model).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
|
||||
public int AppInsert(SysRole model, string operateUser)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
model.Id = UUID.StrSnowId;
|
||||
model.AllowEdit = "1";
|
||||
model.DeleteFlag = "N";
|
||||
model.CreateUserId = operateUser;
|
||||
model.CreateTime = DateTime.Now;
|
||||
model.ModifyUserId = model.CreateUserId;
|
||||
model.ModifyTime = model.CreateTime;
|
||||
return db.Insertable<SysRole>(model).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
|
||||
public int AppUpdate(SysRole model, string operateUser)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
model.AllowEdit = model.AllowEdit == null ? "0" : "1";
|
||||
model.ModifyUserId = operateUser;
|
||||
model.ModifyTime = DateTime.Now;
|
||||
return db.Updateable<SysRole>(model).UpdateColumns(it => new
|
||||
{
|
||||
it.OrganizeId,
|
||||
it.EnCode,
|
||||
it.Type,
|
||||
it.Name,
|
||||
it.Remark,
|
||||
it.SortCode,
|
||||
it.ModifyUserId,
|
||||
it.ModifyTime
|
||||
}).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 更新角色信息
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public int Update(SysRole model, string account)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
model.AllowEdit = model.AllowEdit == null ? "0" : "1";
|
||||
model.ModifyUserId = account;
|
||||
model.ModifyTime = DateTime.Now;
|
||||
return db.Updateable<SysRole>(model).UpdateColumns(it => new
|
||||
{
|
||||
it.OrganizeId,
|
||||
it.EnCode,
|
||||
it.Type,
|
||||
it.Name,
|
||||
it.AllowEdit,
|
||||
it.EnableFlag,
|
||||
it.Remark,
|
||||
it.SortCode,
|
||||
it.ModifyUserId,
|
||||
it.ModifyTime
|
||||
}).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据主键得到角色信息
|
||||
/// </summary>
|
||||
/// <param name="primaryKey"></param>
|
||||
/// <returns></returns>
|
||||
public SysRole Get(string primaryKey)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
return db.Queryable<SysRole>().Where(it => it.Id == primaryKey)
|
||||
.Includes(it => it.Organize)
|
||||
.Includes(it => it.CreateUser)
|
||||
.Includes(it => it.ModifyUser)
|
||||
.First();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 删除角色信息
|
||||
/// </summary>
|
||||
/// <param name="primaryKeys"></param>
|
||||
/// <returns></returns>
|
||||
public int Delete(List<string> primaryKeys)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
List<SysRole> list = db.Queryable<SysRole>().Where(it => primaryKeys.Contains(it.Id)).ToList();
|
||||
list.ForEach(it => { it.DeleteFlag = "Y"; });
|
||||
return db.Updateable<SysRole>(list).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
175
DH.RBAC/Logic/Sys/SysUserLogOnLogic.cs
Normal file
175
DH.RBAC/Logic/Sys/SysUserLogOnLogic.cs
Normal file
@ -0,0 +1,175 @@
|
||||
using DH.RBAC.Model.Sys;
|
||||
using DH.RBAC.Logic.Base;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using DH.RBAC.Utility.Other;
|
||||
|
||||
|
||||
namespace DH.RBAC.Logic.Sys
|
||||
{
|
||||
public class SysUserLogOnLogic : BaseLogic
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 根据用户Id得到登录账号信息
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public SysUserLogOn GetByAccount(string userId)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
return db.Queryable<SysUserLogOn>().Where(it => it.UserId == userId).First();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新用户登录账号信息
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public int UpdateLogin(SysUserLogOn model)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
model.IsOnLine = "1";
|
||||
model.LastVisitTime = DateTime.Now;
|
||||
model.PrevVisitTime = model.LastVisitTime;
|
||||
model.LoginCount += 1;
|
||||
model.ModifyTime = DateTime.Now;
|
||||
model.ModifyUserId = model.UserId;
|
||||
return db.Updateable<SysUserLogOn>(model).UpdateColumns(it => new
|
||||
{
|
||||
it.IsOnLine,
|
||||
it.PrevVisitTime,
|
||||
it.LastVisitTime,
|
||||
it.LoginCount,
|
||||
it.ModifyTime,
|
||||
it.ModifyUserId
|
||||
}).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改密码
|
||||
/// </summary>
|
||||
/// <param name="userLoginEntity"></param>
|
||||
/// <returns></returns>
|
||||
public int ModifyPwd(SysUserLogOn userLoginEntity)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
userLoginEntity.ChangePwdTime = DateTime.Now;
|
||||
userLoginEntity.ModifyUserId = userLoginEntity.UserId;
|
||||
userLoginEntity.ModifyTime = DateTime.Now;
|
||||
|
||||
return db.Updateable<SysUserLogOn>(userLoginEntity).UpdateColumns(it => new
|
||||
{
|
||||
it.Password,
|
||||
it.ChangePwdTime,
|
||||
it.ModifyUserId,
|
||||
it.ModifyTime
|
||||
}).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除用户登录信息
|
||||
/// </summary>
|
||||
/// <param name="userIds"></param>
|
||||
/// <returns></returns>
|
||||
public int Delete(List<string> userIds)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
List<SysUserLogOn> list = db.Queryable<SysUserLogOn>().Where(it => userIds.Contains(it.UserId)).ToList();
|
||||
list.ForEach(it => { it.DeleteFlag = "Y"; });
|
||||
return db.Updateable<SysUserLogOn>(list).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增用户登录账号
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public int Insert(SysUserLogOn model)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
model.Id = UUID.StrSnowId;
|
||||
model.SecretKey = model.Id.DESEncrypt().Substring(0, 8);
|
||||
model.Password = model.Password.MD5Encrypt().DESEncrypt(model.SecretKey).MD5Encrypt();
|
||||
model.LoginCount = 0;
|
||||
model.IsOnLine = "0";
|
||||
model.EnableFlag = "Y";
|
||||
model.DeleteFlag = "N";
|
||||
model.CreateTime = DateTime.Now;
|
||||
model.ModifyTime = DateTime.Now;
|
||||
model.ModifyUserId = model.UserId;
|
||||
model.CreateUserId = model.UserId;
|
||||
return db.Insertable<SysUserLogOn>(model).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新用户登录账号信息
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public int UpdateInfo(SysUserLogOn model)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
model.ModifyTime = DateTime.Now;
|
||||
model.ModifyUserId = model.UserId;
|
||||
|
||||
return db.Updateable<SysUserLogOn>(model).UpdateColumns(it => new
|
||||
{
|
||||
it.AllowMultiUserOnline,
|
||||
it.Question,
|
||||
it.AnswerQuestion,
|
||||
it.CheckIPAddress,
|
||||
it.Language,
|
||||
it.Theme,
|
||||
it.ModifyUserId,
|
||||
it.ModifyTime
|
||||
}).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
|
||||
public int UpdateTheme(SysUserLogOn model)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
model.ModifyTime = DateTime.Now;
|
||||
model.ModifyUserId = model.UserId;
|
||||
return db.Updateable<SysUserLogOn>(model).UpdateColumns(it => new
|
||||
{
|
||||
it.Theme,
|
||||
it.ModifyUserId,
|
||||
it.ModifyTime
|
||||
}).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
|
||||
public int UpdatePassword(SysUserLogOn model)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
model.ModifyTime = DateTime.Now;
|
||||
model.ModifyUserId = model.UserId;
|
||||
return db.Updateable<SysUserLogOn>(model).UpdateColumns(it => new
|
||||
{
|
||||
it.Password,
|
||||
it.ModifyUserId,
|
||||
it.ModifyTime
|
||||
}).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
509
DH.RBAC/Logic/Sys/SysUserLogic.cs
Normal file
509
DH.RBAC/Logic/Sys/SysUserLogic.cs
Normal file
@ -0,0 +1,509 @@
|
||||
|
||||
using DH.RBAC.Logic.Base;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Security.Principal;
|
||||
using DH.RBAC.Model.Sys;
|
||||
|
||||
using DH.RBAC.Utility.Other;
|
||||
using SqlSugar;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace DH.RBAC.Logic.Sys
|
||||
{
|
||||
public class SysUserLogic : BaseLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// 根据账号得到用户信息
|
||||
/// </summary>
|
||||
/// <param name="account"></param>
|
||||
/// <returns></returns>
|
||||
public SysUser GetByUserName(string account)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
return db.Queryable<SysUser>().Where(it => it.Account == account && it.DeleteFlag == "N")
|
||||
.Includes(it => it.Organize)
|
||||
.Includes(it => it.CreateUser)
|
||||
.Includes(it => it.ModifyUser)
|
||||
.First();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改用户基础信息
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public int UpdateBasicInfo(SysUser model, string account)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
model.ModifyUserId = account;
|
||||
model.ModifyTime = DateTime.Now;
|
||||
return db.Updateable<SysUser>(model).UpdateColumns(it => new
|
||||
{
|
||||
it.RealName,
|
||||
it.NickName,
|
||||
it.Gender,
|
||||
it.Birthday,
|
||||
it.MobilePhone,
|
||||
it.Avatar,
|
||||
it.Email,
|
||||
it.Signature,
|
||||
it.Address,
|
||||
it.ModifyUserId,
|
||||
it.ModifyTime
|
||||
}).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
|
||||
public int AppUpdateBasicInfo(SysUser model)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
model.ModifyUserId = model.Id;
|
||||
model.ModifyTime = DateTime.Now;
|
||||
return db.Updateable<SysUser>(model).UpdateColumns(it => new
|
||||
{
|
||||
it.RealName,
|
||||
it.NickName,
|
||||
it.Gender,
|
||||
it.Birthday,
|
||||
it.MobilePhone,
|
||||
it.Avatar,
|
||||
it.Email,
|
||||
it.Signature,
|
||||
it.Address,
|
||||
it.ModifyUserId,
|
||||
it.ModifyTime
|
||||
}).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
|
||||
public int Insert(SysUser model, string password, string account, string[] roleIds)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
try
|
||||
{
|
||||
db.BeginTran();
|
||||
////新增用户基本信息。
|
||||
model.Id = UUID.StrSnowId;
|
||||
model.EnableFlag = "Y";
|
||||
model.DeleteFlag = "N";
|
||||
model.CreateUserId = account;
|
||||
model.CreateTime = DateTime.Now;
|
||||
model.ModifyUserId = model.CreateUserId;
|
||||
model.ModifyTime = model.CreateTime;
|
||||
model.Avatar = "/Content/framework/images/avatar.png";
|
||||
int row = db.Insertable<SysUser>(model).ExecuteCommand();
|
||||
if (row == 0)
|
||||
{
|
||||
db.RollbackTran();
|
||||
return row;
|
||||
}
|
||||
|
||||
//新增新的角色
|
||||
List<SysUserRoleRelation> list = new List<SysUserRoleRelation>();
|
||||
foreach (string roleId in roleIds)
|
||||
{
|
||||
SysUserRoleRelation roleRelation = new SysUserRoleRelation
|
||||
{
|
||||
Id = UUID.StrSnowId,
|
||||
UserId = model.Id,
|
||||
RoleId = roleId,
|
||||
EnableFlag = "Y",
|
||||
DeleteFlag = "N",
|
||||
CreateUserId = account,
|
||||
CreateTime = DateTime.Now,
|
||||
ModifyUserId = account,
|
||||
ModifyTime = DateTime.Now
|
||||
};
|
||||
list.Add(roleRelation);
|
||||
}
|
||||
row = db.Insertable<SysUserRoleRelation>(list).ExecuteCommand();
|
||||
if (row == 0)
|
||||
{
|
||||
db.RollbackTran();
|
||||
return row;
|
||||
}
|
||||
//新增用户登陆信息。
|
||||
SysUserLogOn userLogOnEntity = new SysUserLogOn();
|
||||
userLogOnEntity.Id = UUID.StrSnowId;
|
||||
userLogOnEntity.UserId = model.Id;
|
||||
userLogOnEntity.SecretKey = userLogOnEntity.Id.DESEncrypt().Substring(0, 8);
|
||||
userLogOnEntity.Password = password.MD5Encrypt().DESEncrypt(userLogOnEntity.SecretKey).MD5Encrypt();
|
||||
userLogOnEntity.LoginCount = 0;
|
||||
userLogOnEntity.IsOnLine = "0";
|
||||
userLogOnEntity.EnableFlag = "Y";
|
||||
userLogOnEntity.DeleteFlag = "N";
|
||||
userLogOnEntity.CreateUserId = account;
|
||||
userLogOnEntity.CreateTime = DateTime.Now;
|
||||
userLogOnEntity.ModifyUserId = account;
|
||||
userLogOnEntity.ModifyTime = DateTime.Now;
|
||||
row = db.Insertable<SysUserLogOn>(userLogOnEntity).ExecuteCommand();
|
||||
if (row == 0)
|
||||
{
|
||||
db.RollbackTran();
|
||||
return row;
|
||||
}
|
||||
db.CommitTran();
|
||||
return row;
|
||||
}
|
||||
catch
|
||||
{
|
||||
db.RollbackTran();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool ContainsUser(string userAccount, params string[] userIdList)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
List<string> accountList = db.Queryable<SysUser>().Where(it => userIdList.Contains(it.Id)).Select(it => it.Account).ToList();
|
||||
if (accountList.IsNullOrEmpty())
|
||||
return false;
|
||||
if (accountList.Contains(userAccount))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public int AppInsert(SysUser model, string password, string[] roleIds, string opearateUser)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
try
|
||||
{
|
||||
db.BeginTran();
|
||||
////新增用户基本信息。
|
||||
model.Id = UUID.StrSnowId;
|
||||
model.EnableFlag = "Y";
|
||||
model.DeleteFlag = "N";
|
||||
model.CreateUserId = opearateUser;
|
||||
model.CreateTime = DateTime.Now;
|
||||
model.ModifyUserId = model.CreateUserId;
|
||||
model.ModifyTime = model.CreateTime;
|
||||
model.Avatar = "/Content/framework/images/avatar.png";
|
||||
int row = db.Insertable<SysUser>(model).ExecuteCommand();
|
||||
if (row == 0)
|
||||
{
|
||||
db.RollbackTran();
|
||||
return row;
|
||||
}
|
||||
|
||||
//新增新的角色
|
||||
List<SysUserRoleRelation> list = new List<SysUserRoleRelation>();
|
||||
foreach (string roleId in roleIds)
|
||||
{
|
||||
SysUserRoleRelation roleRelation = new SysUserRoleRelation
|
||||
{
|
||||
Id = UUID.StrSnowId,
|
||||
UserId = model.Id,
|
||||
RoleId = roleId,
|
||||
EnableFlag = "Y",
|
||||
DeleteFlag = "N",
|
||||
CreateUserId = opearateUser,
|
||||
CreateTime = DateTime.Now,
|
||||
ModifyUserId = opearateUser,
|
||||
ModifyTime = DateTime.Now
|
||||
};
|
||||
list.Add(roleRelation);
|
||||
}
|
||||
row = db.Insertable<SysUserRoleRelation>(list).ExecuteCommand();
|
||||
if (row == 0)
|
||||
{
|
||||
db.RollbackTran();
|
||||
return row;
|
||||
}
|
||||
//新增用户登陆信息。
|
||||
SysUserLogOn userLogOnEntity = new SysUserLogOn();
|
||||
userLogOnEntity.Id = UUID.StrSnowId;
|
||||
userLogOnEntity.UserId = model.Id;
|
||||
userLogOnEntity.SecretKey = userLogOnEntity.Id.DESEncrypt().Substring(0, 8);
|
||||
userLogOnEntity.Password = password.DESEncrypt(userLogOnEntity.SecretKey).MD5Encrypt();
|
||||
userLogOnEntity.LoginCount = 0;
|
||||
userLogOnEntity.IsOnLine = "0";
|
||||
userLogOnEntity.EnableFlag = "Y";
|
||||
userLogOnEntity.DeleteFlag = "N";
|
||||
userLogOnEntity.CreateUserId = opearateUser;
|
||||
userLogOnEntity.CreateTime = DateTime.Now;
|
||||
userLogOnEntity.ModifyUserId = userLogOnEntity.CreateUserId;
|
||||
userLogOnEntity.ModifyTime = userLogOnEntity.CreateTime;
|
||||
row = db.Insertable<SysUserLogOn>(userLogOnEntity).ExecuteCommand();
|
||||
if (row == 0)
|
||||
{
|
||||
db.RollbackTran();
|
||||
return row;
|
||||
}
|
||||
db.CommitTran();
|
||||
return row;
|
||||
}
|
||||
catch
|
||||
{
|
||||
db.RollbackTran();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 根据主键得到用户信息
|
||||
/// </summary>
|
||||
/// <param name="primaryKey"></param>
|
||||
/// <returns></returns>
|
||||
public SysUser Get(string primaryKey)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
return db.Queryable<SysUser>().Where(it => it.Id == primaryKey)
|
||||
.Includes(it => it.Organize)
|
||||
.Includes(it => it.CreateUser)
|
||||
.Includes(it => it.ModifyUser).First();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得用户列表分页
|
||||
/// </summary>
|
||||
/// <param name="pageIndex"></param>
|
||||
/// <param name="pageSize"></param>
|
||||
/// <param name="keyWord"></param>
|
||||
/// <param name="totalCount"></param>
|
||||
/// <returns></returns>
|
||||
public List<SysUser> GetList(int pageIndex, int pageSize, string keyWord, ref int totalCount)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
ISugarQueryable<SysUser> queryable = db.Queryable<SysUser>().Where(it => it.DeleteFlag == "N");
|
||||
if (!keyWord.IsNullOrEmpty())
|
||||
{
|
||||
queryable = queryable.Where(it => it.Account.Contains(keyWord) || it.RealName.Contains(keyWord));
|
||||
}
|
||||
return queryable.OrderBy(it => it.SortCode)
|
||||
.Includes(it => it.Organize)
|
||||
.Includes(it => it.CreateUser)
|
||||
.Includes(it => it.ModifyUser).ToPageList(pageIndex, pageSize, ref totalCount);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 删除用户信息
|
||||
/// </summary>
|
||||
/// <param name="primaryKeys"></param>
|
||||
/// <returns></returns>
|
||||
public int Delete(List<string> primaryKeys)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
List<SysUser> list = db.Queryable<SysUser>().Where(it => primaryKeys.Contains(it.Id)).ToList();
|
||||
list.ForEach(it => { it.DeleteFlag = "Y"; });
|
||||
return db.Updateable<SysUser>(list).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增用户基础信息
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public int Insert(SysUser model, string account)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
model.Id = UUID.StrSnowId;
|
||||
model.DeleteFlag = "N";
|
||||
model.EnableFlag = "Y";
|
||||
|
||||
|
||||
model.CreateUserId = account;
|
||||
model.CreateTime = DateTime.Now;
|
||||
model.ModifyUserId = model.CreateUserId;
|
||||
model.ModifyTime = model.CreateTime;
|
||||
model.Avatar = "/Content/framework/images/avatar.png";
|
||||
return db.Insertable<SysUser>(model).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 更新用户基础信息
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public int Update(SysUser model, string account)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
model.ModifyUserId = account;
|
||||
model.ModifyTime = DateTime.Now;
|
||||
|
||||
return db.Updateable<SysUser>(model).UpdateColumns(it => new
|
||||
{
|
||||
it.NickName,
|
||||
it.RealName,
|
||||
it.Birthday,
|
||||
it.Gender,
|
||||
it.Email,
|
||||
it.DepartmentId,
|
||||
it.RoleId,
|
||||
it.MobilePhone,
|
||||
it.Address,
|
||||
it.Signature,
|
||||
it.SortCode,
|
||||
it.IsEnabled,
|
||||
it.ModifyUserId,
|
||||
it.ModifyTime
|
||||
}).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int AppUpdateAndSetRole(SysUser model, string[] roleIds, string opereateUser)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
try
|
||||
{
|
||||
db.BeginTran();
|
||||
model.ModifyUserId = opereateUser;
|
||||
model.ModifyTime = DateTime.Now;
|
||||
int row = db.Updateable<SysUser>(model).UpdateColumns(it => new
|
||||
{
|
||||
it.NickName,
|
||||
it.RealName,
|
||||
it.Birthday,
|
||||
it.Gender,
|
||||
it.Email,
|
||||
it.DepartmentId,
|
||||
it.RoleId,
|
||||
it.MobilePhone,
|
||||
it.Address,
|
||||
it.Signature,
|
||||
it.SortCode,
|
||||
it.ModifyUserId,
|
||||
it.ModifyTime
|
||||
}).ExecuteCommand();
|
||||
if (row == 0)
|
||||
{
|
||||
db.RollbackTran();
|
||||
return row;
|
||||
}
|
||||
//删除原来的角色
|
||||
List<SysUserRoleRelation> list2 = db.Queryable<SysUserRoleRelation>().Where(it => it.UserId == model.Id && it.DeleteFlag == "N").ToList();
|
||||
list2.ForEach(it => { it.DeleteFlag = "Y"; });
|
||||
db.Updateable<SysUserRoleRelation>(list2).ExecuteCommand();
|
||||
//新增新的角色
|
||||
List<SysUserRoleRelation> list = new List<SysUserRoleRelation>();
|
||||
foreach (string roleId in roleIds)
|
||||
{
|
||||
SysUserRoleRelation roleRelation = new SysUserRoleRelation
|
||||
{
|
||||
Id = UUID.StrSnowId,
|
||||
UserId = model.Id,
|
||||
RoleId = roleId,
|
||||
DeleteFlag = "N",
|
||||
EnableFlag = "Y",
|
||||
CreateUserId = opereateUser,
|
||||
CreateTime = DateTime.Now,
|
||||
ModifyUserId = opereateUser,
|
||||
ModifyTime = DateTime.Now
|
||||
};
|
||||
list.Add(roleRelation);
|
||||
}
|
||||
row = db.Insertable<SysUserRoleRelation>(list).ExecuteCommand();
|
||||
if (row == 0)
|
||||
{
|
||||
db.RollbackTran();
|
||||
return row;
|
||||
}
|
||||
db.CommitTran();
|
||||
return row;
|
||||
}
|
||||
catch
|
||||
{
|
||||
db.RollbackTran();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int UpdateAndSetRole(SysUser model, string account, string[] roleIds)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
try
|
||||
{
|
||||
db.BeginTran();
|
||||
model.ModifyUserId = account;
|
||||
model.ModifyTime = DateTime.Now;
|
||||
int row = db.Updateable<SysUser>(model).UpdateColumns(it => new
|
||||
{
|
||||
it.NickName,
|
||||
it.RealName,
|
||||
it.Birthday,
|
||||
it.Gender,
|
||||
it.Email,
|
||||
it.DepartmentId,
|
||||
it.RoleId,
|
||||
it.MobilePhone,
|
||||
it.Address,
|
||||
it.Signature,
|
||||
it.SortCode,
|
||||
it.EnableFlag,
|
||||
it.ModifyUserId,
|
||||
it.ModifyTime
|
||||
}).ExecuteCommand();
|
||||
if (row == 0)
|
||||
{
|
||||
db.RollbackTran();
|
||||
return row;
|
||||
}
|
||||
//删除原来的角色
|
||||
List<SysUserRoleRelation> list2 = db.Queryable<SysUserRoleRelation>().Where(it => it.UserId == model.Id && it.DeleteFlag == "N").ToList();
|
||||
list2.ForEach(it => { it.DeleteFlag = "Y"; });
|
||||
db.Updateable<SysUserRoleRelation>(list2).ExecuteCommand();
|
||||
//新增新的角色
|
||||
List<SysUserRoleRelation> list = new List<SysUserRoleRelation>();
|
||||
foreach (string roleId in roleIds)
|
||||
{
|
||||
SysUserRoleRelation roleRelation = new SysUserRoleRelation
|
||||
{
|
||||
Id = UUID.StrSnowId,
|
||||
UserId = model.Id,
|
||||
RoleId = roleId,
|
||||
EnableFlag = "Y",
|
||||
DeleteFlag = "N",
|
||||
CreateUserId = account,
|
||||
CreateTime = DateTime.Now,
|
||||
ModifyTime = DateTime.Now,
|
||||
ModifyUserId = account
|
||||
};
|
||||
list.Add(roleRelation);
|
||||
}
|
||||
row = db.Insertable<SysUserRoleRelation>(list).ExecuteCommand();
|
||||
if (row == 0)
|
||||
{
|
||||
db.RollbackTran();
|
||||
return row;
|
||||
}
|
||||
db.CommitTran();
|
||||
return row;
|
||||
}
|
||||
catch
|
||||
{
|
||||
db.RollbackTran();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
57
DH.RBAC/Logic/Sys/SysUserRoleRelationLogic.cs
Normal file
57
DH.RBAC/Logic/Sys/SysUserRoleRelationLogic.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using DH.RBAC.Model.Sys;
|
||||
using DH.RBAC.Logic.Base;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace DH.RBAC.Logic.Sys
|
||||
{
|
||||
public class SysUserRoleRelationLogic : BaseLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// 删除用户角色关系
|
||||
/// </summary>
|
||||
/// <param name="userIds"></param>
|
||||
/// <returns></returns>
|
||||
public int Delete(List<string> userIds)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
List<SysUserRoleRelation> list = db.Queryable<SysUserRoleRelation>().Where(it => userIds.Contains(it.UserId)).ToList();
|
||||
list.ForEach(it => { it.DeleteFlag = "Y"; });
|
||||
return db.Updateable<SysUserRoleRelation>(list).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据ID得到用户角色关系
|
||||
/// </summary>
|
||||
/// <param name="userIds"></param>
|
||||
/// <returns></returns>
|
||||
public List<SysUserRoleRelation> GetList(string userId)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
return db.Queryable<SysUserRoleRelation>().Where(it => it.UserId == userId && it.DeleteFlag=="N").ToList();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从用户角色关系表中得到所有角色绑定信息
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
public List<SysUserRoleRelation> GetByRoles(List<string> ids)
|
||||
{
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
return db.Queryable<SysUserRoleRelation>().Where(it => ids.Contains(it.RoleId) && it.DeleteFlag == "N").ToList();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user