|
|
using Dapper;
|
|
|
using Estsh.Core.Dapper;
|
|
|
using Estsh.Core.Models;
|
|
|
using Estsh.Core.Repository.IRepositories;
|
|
|
using Estsh.Core.Services.IServices;
|
|
|
using Estsh.Core.Util;
|
|
|
using System.Collections;
|
|
|
|
|
|
/***************************************************************************************************
|
|
|
*
|
|
|
* 更新人:sitong.dong
|
|
|
* 描述:角色模块业务处理类
|
|
|
* 修改时间:2022.06.22
|
|
|
* 修改日志:系统迭代升级
|
|
|
*
|
|
|
**************************************************************************************************/
|
|
|
namespace Estsh.Core.Services
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 角色模块管理业务处理类
|
|
|
/// </summary>
|
|
|
public class RoleService : BaseService<SysRole>, IRoleService
|
|
|
{
|
|
|
private readonly IRoleRepository repository;
|
|
|
|
|
|
public RoleService(IRoleRepository _repository) : base(_repository)
|
|
|
{
|
|
|
repository = _repository;
|
|
|
}
|
|
|
|
|
|
#region 角色管理
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据分页条件获取角色列表
|
|
|
/// </summary>
|
|
|
/// <param name="account"></param>
|
|
|
/// <param name="pager"></param>
|
|
|
/// <param name="direction"></param>
|
|
|
/// <param name="sort"></param>
|
|
|
/// <returns></returns>
|
|
|
public Hashtable getRoleListByPage(String role_name, Pager pager, String direction, String sort, String enabled)
|
|
|
{
|
|
|
Hashtable result = new Hashtable();
|
|
|
String strWhere = " 1=1 ";
|
|
|
if (role_name != null && !role_name.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += " and role_name like '%" + role_name.Trim() + "%'";
|
|
|
}
|
|
|
if (enabled != null && !enabled.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += " and a.enabled = '" + enabled + "'";
|
|
|
}
|
|
|
|
|
|
String orderBy = "";
|
|
|
if (sort != null && !"".Equals(sort.Trim()))
|
|
|
{
|
|
|
orderBy += typeof(SysRole).GetEntityColumnName(sort.Trim()) + " " + direction;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
orderBy += typeof(SysRole).GetEntityColumnName("RoleId") + " " + direction;
|
|
|
}
|
|
|
result = repository.getRoleListByPage(pager.pageSize, pager.pageNo, strWhere, orderBy);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据角色ID获取角色的功能树信息
|
|
|
/// </summary>
|
|
|
/// <param name="role_id"></param>
|
|
|
/// <returns></returns>
|
|
|
public ArrayList getRoleMenuTree(String role_id)
|
|
|
{
|
|
|
role_id= String.IsNullOrEmpty(role_id) ? "" : role_id;
|
|
|
List<SysWebMenu> dt = repository.getRoleMenuTree(role_id);
|
|
|
ArrayList treeNodes = new ArrayList();
|
|
|
Hashtable node ;
|
|
|
for (int i = 0; i < dt.Count; i++)
|
|
|
{
|
|
|
node = new Hashtable();
|
|
|
node.Add("id", dt[i].MenuId);
|
|
|
node.Add("name", dt[i].Name);
|
|
|
node.Add("parentId", dt[i].ParentId);
|
|
|
//if (dt.Rows[i]["parent_id"] == null || "0".Equals(dt.Rows[i]["parent_id"].ToString().Trim()))
|
|
|
//{
|
|
|
node.Add("open", true);
|
|
|
//}
|
|
|
if (dt[i].RoleId != null && role_id.Equals(dt[i].RoleId.ToString().Trim()) && !role_id.Equals(""))
|
|
|
{
|
|
|
node.Add("checked" , true);
|
|
|
}
|
|
|
treeNodes.Add(node);
|
|
|
}
|
|
|
List<SysProgramFunOp> dtOp = repository.getRoleMenuOpTree(role_id);
|
|
|
|
|
|
foreach (SysProgramFunOp dr in dtOp)
|
|
|
{
|
|
|
node = new Hashtable();
|
|
|
node.Add("id", dr.OpId.ToString());
|
|
|
node.Add("name", dr.OpName.ToString());
|
|
|
node.Add("parentId", dr.ParentId.ToString());
|
|
|
if (dr.RoleId != null && role_id.Equals(dr.RoleId.ToString().Trim()) && !role_id.Equals(""))
|
|
|
{
|
|
|
node.Add("checked", true);
|
|
|
}
|
|
|
|
|
|
treeNodes.Add(node);
|
|
|
}
|
|
|
|
|
|
return treeNodes;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据角色ID获取角色信息
|
|
|
/// </summary>
|
|
|
/// <param name="role_id"></param>
|
|
|
/// <returns></returns>
|
|
|
public List<SysRole> getRoleDetail(String role_id)
|
|
|
{
|
|
|
List<SysRole> result = repository.getRoleInfoById(role_id);
|
|
|
return result; ;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 保存角色数据
|
|
|
/// </summary>
|
|
|
/// <param name="htParams"></param>
|
|
|
/// <returns></returns>
|
|
|
public int saveRoleInfo(SysRole htParams, string menuTreeInfo, string opMenuTreeInfo)
|
|
|
{
|
|
|
return repository.saveRoleInfo(htParams, menuTreeInfo, opMenuTreeInfo);
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新角色数据
|
|
|
/// </summary>
|
|
|
/// <param name="htParams"></param>
|
|
|
/// <returns></returns>
|
|
|
public int updateRoleInfo(SysRole htParams, string menuTreeInfo, string opMenuTreeInfo)
|
|
|
{
|
|
|
return repository.updateRoleInfo(htParams, menuTreeInfo, opMenuTreeInfo);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 删除角色
|
|
|
/// </summary>
|
|
|
/// <param name="ids"></param>
|
|
|
/// <returns></returns>
|
|
|
public int deleteRole(String ids)
|
|
|
{
|
|
|
String[] idArray = ids.Split(',');
|
|
|
int count = 0;
|
|
|
foreach (String id in idArray)
|
|
|
{
|
|
|
if (!"".Equals(id))
|
|
|
{
|
|
|
count += this.repository.deleteRole(id);
|
|
|
}
|
|
|
}
|
|
|
return count;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 启用
|
|
|
/// </summary>
|
|
|
/// <param name="ids"></param>
|
|
|
/// <returns></returns>
|
|
|
public int EnableData(String ids)
|
|
|
{
|
|
|
ids = ids.Substring(0, ids.Length - 1);
|
|
|
return this.repository.EnableData(ids);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 禁用
|
|
|
/// </summary>
|
|
|
/// <param name="ids"></param>
|
|
|
/// <returns></returns>
|
|
|
public int DisableData(String ids)
|
|
|
{
|
|
|
ids = ids.Substring(0, ids.Length - 1);
|
|
|
return this.repository.DisableData(ids);
|
|
|
}
|
|
|
#endregion
|
|
|
}
|
|
|
} |