using Dm;
|
using Model.ModelDto.SysDto;
|
using Model.ModelVm.SysVm;
|
using SqlSugar;
|
using System;
|
using System.Collections.Generic;
|
using System.Data;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WMS.Entity.Context;
|
using WMS.Entity.SysEntity;
|
using WMS.IDAL.ISysInterface;
|
|
namespace WMS.DAL.SysInfrastructure
|
{
|
/// <summary>
|
/// 角色仓储实践
|
/// </summary>
|
public class RolesRepository : BaseRepository<SysRoles>, IRolesRepository
|
{
|
private static readonly SqlSugarScope Db = DataContext.Db;
|
public RolesRepository() : base(Db)
|
{
|
}
|
|
/// <summary>
|
/// 查询角色数据信息列表
|
/// </summary>
|
/// <param name="RoleNo">角色号</param>
|
/// <param name="RoleName">角色名称</param>
|
/// <returns></returns>
|
public List<RoleDto> GetRoleList(string RoleNo, string RoleName,string UserId)
|
{
|
string whereSql = " role.IsDel = '0' ";
|
if (!string.IsNullOrEmpty(UserId))
|
{
|
SysUserInfor userEntry = Db.Ado.SqlQuerySingle<SysUserInfor>($"select * from SysUserInfor where Id={UserId}");
|
if (userEntry != null && userEntry.UserName.ToUpper() !="ADMIN")
|
{
|
//除系统超级管理员admin外其他账号角色权限列表只能看到自己创建的角色
|
whereSql += $" and role.CreateUser = {UserId}";
|
}
|
}
|
if (!string.IsNullOrEmpty(RoleNo))
|
{
|
whereSql += $" and role.RoleNo like '%{RoleNo}%' ";
|
}
|
if (!string.IsNullOrEmpty(RoleName))
|
{
|
whereSql += $" and role.RoleName like '%{RoleName}%' ";
|
}
|
string str = $@"select
|
role.*,
|
user1.RealName CreateUserName,
|
user2.RealName UpdateUserName
|
from SysRoles role
|
left join SysUserInfor user1 on role.CreateUser = user1.Id
|
left join SysUserInfor user2 on role.UpdateUser = user2.Id
|
where {whereSql} order by role.Id";
|
|
List<RoleDto> roles = Db.Ado.SqlQuery<RoleDto>(str);
|
return roles;
|
}
|
|
/// <summary>
|
/// 根据编号获取用户信息列表
|
/// </summary>
|
/// <param name="RoleNo">角色号</param>
|
/// <returns></returns>
|
public List<SysRoles> GetRoleByNo(string RoleNo)
|
{
|
string str = "select * from SysRoles where RoleNo = @roleno";
|
List<SysRoles> userlist = Db.Ado.SqlQuery<SysRoles>(str, new
|
{
|
roleno = RoleNo //角色号
|
});
|
return userlist;
|
}
|
|
/// <summary>
|
/// 新增角色数据信息
|
/// </summary>
|
/// <param name="roles">角色实体模型</param>
|
/// <returns></returns>
|
public async Task<int> InsertRoleInfo(SysRoles roles)
|
{
|
string str = "insert into SysRoles values(@roleno, @rolename, @demo, @isdel, @createtime, @createuser, null, null)";
|
int i = await Db.Ado.ExecuteCommandAsync(str, new
|
{
|
roleno = roles.RoleNo, //角色号
|
rolename = roles.RoleName, //角色名称
|
demo = roles.Demo, //备注
|
isdel = "0", //是否删除
|
createtime = Db.GetDate(), //创建时间
|
createuser = roles.CreateUser, //创建人
|
});
|
return i;
|
}
|
|
/// <summary>
|
/// 删除\批量删除角色信息
|
/// </summary>
|
/// <param name="roles">角色实体模型</param>
|
/// <returns></returns>
|
public async Task<int> DeleteRoleInfo(SysRoles roles)
|
{
|
string str = "update SysRoles set IsDel = @isdel, UpdateTime = @updatetime, UpdateUser = @updateuser where Id in (@id)";
|
//删除\批量删除
|
int i = await Db.Ado.ExecuteCommandAsync(str, new
|
{
|
isdel = "1", //是否删除
|
updatetime = Db.GetDate(), //更改时间
|
updateuser = roles.UpdateUser, //更改人
|
id = roles.Id //角色id
|
});
|
return i;
|
}
|
|
|
/// <summary>
|
/// 编辑角色信息
|
/// </summary>
|
/// <param name="role">角色实体模型</param>
|
/// <returns></returns>
|
public async Task<int> UpdateRoleInfo(SysRoles role)
|
{
|
string str = "update SysRoles set RoleName = @rolename, Demo = @demo, UpdateTime = @updatetime, UpdateUser = @updateuser where Id = @id";
|
//修改
|
int i = await Db.Ado.ExecuteCommandAsync(str, new
|
{
|
roleno = role.RoleNo, //角色号
|
rolename = role.RoleName, //角色名称
|
demo = role.Demo, //备注
|
updatetime = Db.GetDate(), //更改时间
|
updateuser = role.UpdateUser, //更改人
|
id = role.Id //角色id
|
});
|
return i;
|
|
}
|
|
/// <summary>
|
/// 根据id获取角色信息
|
/// </summary>
|
/// <param name="roleid">角色id</param>
|
/// <returns></returns>
|
public SysRoles GetRoleInfoById(int roleid)
|
{
|
string str = "select * from SysRoles where Id = @id and IsDel = @isdel";
|
SysRoles role= Db.Ado.SqlQuerySingle<SysRoles>(str, new
|
{
|
id = roleid, //角色id
|
isdel = "0" //是否删除
|
});
|
return role;
|
|
}
|
|
}
|
}
|