using Model.ModelDto.SysDto; using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using WMS.Entity.Context; using WMS.Entity.SysEntity; using WMS.IBLL.ISysServer; namespace WMS.BLL.SysServer { public class RoleWareHouseServer: IRoleWareHouseServer { private static readonly SqlSugarScope Db = DataContext.Db; public List GetRoleWareHouseOneListById(int id) { try { var role = Db.Queryable().First(m => m.IsDel == "0" && m.Id == id); if (role == null) { throw new Exception("没有找到角色信息"); } var roleWare = Db.Queryable().Where(m => m.RoleNo == role.RoleNo && m.IsDel == "0").ToList(); return roleWare; } catch (Exception e) { throw new Exception(e.Message); } } /// /// 获取仓库信息列表 /// /// sql语句 /// public List GetHouseList(string UserId) { var userEntry = Db.Ado.SqlQuery($"select * from SysUserInfor where Id ={UserId}").FirstOrDefault(); //获取全部菜单信息 string strmenu = "select * from SysWareHouse where IsDel = '0'"; //分配权限只能分配当前登录用户有的权限 if (userEntry != null && userEntry.UserName.ToUpper() != "ADMIN") { strmenu += $" and WareHouseNo in (select WareHouseNo from SysRoleWareHouse where RoleNo='{userEntry.RoleNo}')"; } strmenu += " order by WareHouseNo asc"; List houselist = Db.Ado.SqlQuery(strmenu); return houselist; } /// /// 新增角色权限信息 /// /// 仓库号 /// 角色号 /// /// 捕获异常 public async Task InsertRoleWareHouse(string WareHouseNo, string RoleNo, string userId) { //捕获异常 try { //将菜单号进行分割 存储数组中 var arr = WareHouseNo.Split(','); int i = 0; //查询该角色是否拥有权限 List rolelist = await Db.Queryable().Where(m=>m.IsDel == "0" && m.RoleNo == RoleNo).ToListAsync(); //有 if (rolelist.Count > 0) { //删除该角色所有菜单信息 i = await Db.Deleteable(rolelist).ExecuteCommandAsync(); } //无 else if (rolelist.Count == 0) { i = 1; } //开始新增权限 if (i > 0) { //循环将菜单数组分别加入到数据模型中 for (int j = 0; j < arr.Count(); j++) { if (string.IsNullOrWhiteSpace(arr[j]) || arr[j] == ",") { continue; } SysRoleWareHouse roleright = new SysRoleWareHouse(); roleright.RoleNo = RoleNo;//角色号 roleright.WareHouseNo = arr[j];//仓库号 roleright.CreateUser = Convert.ToInt32(userId);//创建人 //成功 将菜单号和角色号新增为新的数据 i += await Db.Insertable(roleright).ExecuteCommandAsync(); } //返回 return i; } else { return i; } } catch (Exception ex) { //抛出异常 throw new Exception("新增角色权限信息异常", ex); } } } }