200 lines
8.4 KiB
C#
200 lines
8.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Air.Model.AirAdminViewModel;
|
|
using Air.Model;
|
|
using Mini.Model;
|
|
using Mini.Model.Entity;
|
|
|
|
namespace Mini.Services.Bas
|
|
{
|
|
public class BasRightGroupService : IBasRightGroupService
|
|
{
|
|
private readonly IAdminRepository<Bas_RightGroup> _basRightGroupRepository;
|
|
private readonly IAdminRepository<Bas_Right> _basRightRepository;
|
|
private readonly IAdminRepository<Bas_Right_ToolButton> _basRightToolButtonRepository;
|
|
public BasRightGroupService(IAdminRepository<Bas_RightGroup> basRightGroupRepository, IAdminRepository<Bas_Right> basRightRepository, IAdminRepository<Bas_Right_ToolButton> basRightToolButtonRepository)
|
|
{
|
|
this._basRightGroupRepository = basRightGroupRepository;
|
|
this._basRightRepository = basRightRepository;
|
|
this._basRightToolButtonRepository = basRightToolButtonRepository;
|
|
}
|
|
|
|
public void Create(Bas_RightGroupModel model)
|
|
{
|
|
var info = new Bas_RightGroup() {
|
|
Name = model.Name,
|
|
ParentId = model.ParentId,
|
|
CTime = model.CTime,
|
|
CreateUser = model.CreateUser
|
|
};
|
|
_basRightGroupRepository.Add(info);
|
|
}
|
|
|
|
public void Delete(Bas_RightGroupModel model)
|
|
{
|
|
var info = _basRightGroupRepository.Get(p => p.PkId == model.PkId);
|
|
if (info != null)
|
|
{
|
|
_basRightGroupRepository.Delete(info);
|
|
}
|
|
}
|
|
|
|
public Bas_RightGroupModel Get(int Id)
|
|
{
|
|
var model = _basRightGroupRepository.Get(p => p.PkId == Id);
|
|
var info = new Bas_RightGroupModel() { PkId = model.PkId, Name = model.Name, ParentId = model.ParentId, CTime = model.CTime, CreateUser = model.CreateUser };
|
|
return info;
|
|
}
|
|
|
|
public object GetAllTreeList()
|
|
{
|
|
var rightGroup = _basRightGroupRepository.GetList().ToList();
|
|
List<object> obj = new List<object>();
|
|
obj.Add(new { id = 0, text = "权限树结构", iconCls = "icon-group", children = GetTreeChildList(rightGroup, 0) });
|
|
return obj;
|
|
}
|
|
|
|
private object GetTreeChildList(List<Bas_RightGroup> rightGroup, decimal parentId)
|
|
{
|
|
List<object> obj = null;
|
|
object childObj = null;
|
|
foreach (var model in rightGroup.FindAll(m => m.ParentId == parentId))
|
|
{
|
|
if (obj == null)
|
|
obj = new List<object>();
|
|
childObj = new { id = model.PkId, text = model.Name, children = GetTreeChildList(rightGroup, model.PkId) };
|
|
obj.Add(childObj);
|
|
}
|
|
return obj;
|
|
}
|
|
|
|
public IList<Bas_RightGroupModel> GetList()
|
|
{
|
|
return _basRightGroupRepository.GetList()
|
|
.Select(p => new Bas_RightGroupModel() { PkId = p.PkId, Name = p.Name, ParentId = p.ParentId, CTime = p.CTime, CreateUser = p.CreateUser })
|
|
.ToList();
|
|
}
|
|
|
|
public object GetNodeTreeList(int id)
|
|
{
|
|
var rightGroup = _basRightGroupRepository.GetList().ToList();
|
|
var rightList = _basRightRepository.GetList().ToList();//获取所有权限列表
|
|
List<object> obj = GetRightTreeChildList(rightGroup, rightList, id);
|
|
if (obj == null)
|
|
obj = new List<object>();
|
|
foreach (var right in rightList.Where(m => m.GroupId == id))
|
|
{
|
|
obj.Add(new
|
|
{
|
|
id = right.RightId,
|
|
text = right.RName,
|
|
iconCls = "icon-redmini",
|
|
attributes = "right"
|
|
});
|
|
}
|
|
return obj;
|
|
}
|
|
|
|
public object GetRightTreeList(bool isSelect = false)
|
|
{
|
|
var rightGroup = _basRightGroupRepository.GetList().ToList();
|
|
var rightList = _basRightRepository.GetList().ToList();//获取所有权限列表
|
|
List<object> obj = new List<object>();
|
|
List<object> childobj = new List<object>();
|
|
childobj = GetRightTreeChildList(rightGroup, rightList, 0, isSelect);
|
|
var right_buttons = _basRightToolButtonRepository.GetList().ToList();
|
|
var noGroupRight = rightList.Where(o => !o.GroupId.HasValue).ToList();
|
|
foreach (var right in noGroupRight)
|
|
{
|
|
var toolButton = right_buttons.Where(p => p.RightId.Equals(right.RightId)).OrderBy(m=>m.ButtonId).ToList();
|
|
string buttons = "";
|
|
if (toolButton != null && toolButton.Count > 0)
|
|
{
|
|
buttons = " 按钮:";
|
|
if (isSelect)
|
|
{
|
|
foreach (var button in toolButton)
|
|
{
|
|
buttons += string.Format("<input class='tool_button' type='checkbox' name='{0}' value='{1}' />{2}", right.RightId, button.ButtonId, button.ButtonName);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
buttons += string.Join(" , ", toolButton.Select(p => p.ButtonName).ToArray());
|
|
}
|
|
}
|
|
childobj.Add(new { id = right.RightId, text = right.RName + buttons, iconCls = "icon-redmini", attributes = "right" });
|
|
}
|
|
obj.Add(new { id = 0, text = "权限树结构", iconCls = "icon-group", children = childobj });
|
|
return obj;
|
|
}
|
|
|
|
private List<object> GetRightTreeChildList(List<Bas_RightGroup> rightGroup, List<Bas_Right> rightList, decimal parentId, bool isSelect = false)
|
|
{
|
|
List<object> obj = new List<object>(); ;
|
|
object childObj = null;
|
|
List<object> nchildObj = null;
|
|
var right_buttons = _basRightToolButtonRepository.GetList().ToList();
|
|
foreach (var model in rightGroup.FindAll(m => m.ParentId == parentId))
|
|
{
|
|
nchildObj = GetRightTreeChildList(rightGroup, rightList, model.PkId, isSelect);
|
|
if (nchildObj == null)
|
|
nchildObj = new List<object>();
|
|
foreach (var right in rightList.Where(m => m.GroupId == model.PkId))
|
|
{
|
|
var toolButton = right_buttons.Where(p => p.RightId.Equals(right.RightId)).OrderBy(m => m.ButtonId).ToList();
|
|
string buttons = "";
|
|
if (toolButton != null && toolButton.Count > 0)
|
|
{
|
|
buttons = " 按钮:";
|
|
if (isSelect)
|
|
{
|
|
foreach (var button in toolButton)
|
|
{
|
|
buttons += string.Format("<input class='tool_button' type='checkbox' name='{0}' value='{1}' />{2}", right.RightId, button.ButtonId, button.ButtonName);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
buttons += string.Join(" , ", toolButton.Select(p => p.ButtonName).ToArray());
|
|
}
|
|
}
|
|
nchildObj.Add(new
|
|
{
|
|
id = right.RightId,
|
|
text = right.RName + buttons,
|
|
iconCls = "icon-redmini",
|
|
attributes = "right"
|
|
});
|
|
}
|
|
if (nchildObj.Count == 0)
|
|
childObj = new { id = model.PkId, text = model.Name };
|
|
else
|
|
childObj = new { id = model.PkId, text = model.Name, children = nchildObj };
|
|
obj.Add(childObj);
|
|
}
|
|
|
|
return obj;
|
|
}
|
|
|
|
public object GetTopTreeList()
|
|
{
|
|
return new List<object>() { new { id = 0, text = "权限树结构", attributes = "group", iconCls = "icon-group", children = GetNodeTreeList(0) } };
|
|
}
|
|
|
|
public void Update(Bas_RightGroupModel model)
|
|
{
|
|
var info = _basRightGroupRepository.Get(p => p.PkId == model.PkId);
|
|
if (info != null)
|
|
{
|
|
info.Name = model.Name;
|
|
info.ParentId = model.ParentId;
|
|
_basRightGroupRepository.Update(info);
|
|
}
|
|
}
|
|
}
|
|
}
|