using Model.ModelVm.SysVm; using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; using SqlSugar; using WMS.Entity.Context; using WMS.Entity.SysEntity; using WMS.IDAL.ISysInterface; using SQLitePCL; using Model.ModelDto.SysDto; using Dm; using System.Security.Cryptography; using System.Security.Policy; using System.Linq; namespace WMS.DAL.SysInfrastructure { /// /// 菜单仓储实践 /// public class MenuRepository : BaseRepository, IMenuRepository { private static readonly SqlSugarScope Db = DataContext.Db; public MenuRepository() : base(Db) { } /// /// 获取菜单信息列表 /// /// sql语句 /// public List GetMenuList(string str = "") { List menulist = Db.Ado.SqlQuery(str); return menulist; } /// /// 获取模块菜单列表 /// /// public List GetParentMenuList() { string str = "select MenuNo,ParentNo,MenuName from SysFunctionMenu where IsDel = @isdel and IsEnable = @isenable"; List menulist = Db.Ado.SqlQuery(str, new { isdel = "0", //是否删除 isenable = "0" //是否可用 }); return menulist; } /// /// 获取菜单信息列表 /// /// sql语句 /// public List GetMenuDtoList(string MenuNo, string UserId) { var userEntry = Db.Ado.SqlQuery($"select * from SysUserInfor where Id ={UserId}").FirstOrDefault(); //获取全部菜单信息 string strmenu = "select * from SysFunctionMenu where IsDel = '0'"; //判断菜单号 if (!string.IsNullOrEmpty(MenuNo)) { strmenu += $" and ParentNo in ({MenuNo})"; } //分配权限只能分配当前登录用户有的权限 if (userEntry !=null && userEntry.UserName.ToUpper() != "ADMIN") { strmenu += $" and MenuNo in (select MenuNo from SysRoleRight where RoleNo='{userEntry.RoleNo}')"; } strmenu += " order by Ord asc"; List menulist = Db.Ado.SqlQuery(strmenu); return menulist; } /// /// 根据id获取菜单信息列表 /// /// 菜单id /// public SysFunctionMenu GetMenuListById(int menuid) { string str = "select * from SysFunctionMenu where IsDel = @isdel and Id = @id and IsEnable = @isenable "; SysFunctionMenu menulist = Db.Ado.SqlQuerySingle(str, new { isdel = "0", //是否删除 isenable = "0", //是否公开 id = menuid //id }); return menulist; } /// /// 根据编号获取菜单信息列表 /// /// sql /// public List GetMenuListByNo(string str) { List menulist = Db.Ado.SqlQuery(str); return menulist; } /// /// 新增菜单信息 /// /// 菜单实体模型 /// public async Task InsertMenu(SysFunctionMenu menu) { string str = "insert SysFunctionMenu values(@menuno, @menuname, @parentno, @ord, @url, @level, @isenable, @demo, @isdel, @createtime, @createuser, null, null)"; int i = await Db.Ado.ExecuteCommandAsync(str, new { menuno = menu.MenuNo, //菜单号 menuname = menu.MenuName, //菜单名称 parentno = menu.ParentNo, //父级菜单号 ord = menu.Ord, //显示顺序 url = menu.Url, //路径 level = menu.Level, //层级 isenable = "0", //是否可用 demo = menu.Demo, //备注 isdel = "0", //是否删除 createtime = Db.GetDate(), //创建时间 createuser = menu.CreateUser //创建人 }); return i; } /// /// 删除菜单信息 /// /// 菜单实体模型 /// public async Task DeleteMenu(SysFunctionMenu menu) { try { Db.BeginTran(); string str = "update SysFunctionMenu set IsDel = @isdel, UpdateTime = @updatetime, UpdateUser = @updateuser where MenuNo in (select MenuNo from SysFunctionMenu where MenuNo = @menuno or ParentNo = @menuno or ParentNo in (select MenuNo from SysFunctionMenu where ParentNo = @menuno));"; int i = await Db.Ado.ExecuteCommandAsync(str, new { isdel = "1", //是否删除 updatetime = Db.GetDate(), //更改时间 updateuser = menu.UpdateUser, //更改人 menuno = menu.MenuNo//id }); str = "delete from SysRoleRight where MenuNo in (select MenuNo from SysFunctionMenu where MenuNo = @menuno or ParentNo = @menuno or ParentNo in (select MenuNo from SysFunctionMenu where ParentNo = @menuno));"; //删除菜单对应的权限 i = await Db.Ado.ExecuteCommandAsync(str, new { isdel = "1", //是否删除 updatetime = Db.GetDate(), //更改时间 updateuser = menu.UpdateUser, //更改人 menuno = menu.MenuNo }); Db.CommitTran(); return i; } catch (Exception ex) { Db.RollbackTran(); throw ex; } } /// /// 编辑菜单信息 /// /// 菜单实体模型 /// public async Task UpdateMenu(SysFunctionMenu menu) { string str = "Update SysFunctionMenu set MenuName = @menuname, ParentNo = @parentno, Ord = @ord, Url = @url, Level = @level, IsEnable = @isenable, Demo = @demo, UpdateTime = @updatetime, UpdateUser = @updateuser where Id = @id"; int i = await Db.Ado.ExecuteCommandAsync(str, new { menuname = menu.MenuName, //菜单名称 parentno = menu.ParentNo, //父级菜单号 ord = menu.Ord, //显示顺序 url = menu.Url, //路径 level = menu.Level, //层级 isenable = "0", //是否可用 demo = menu.Demo, //备注 updatetime = Db.GetDate(), //创建时间 updateuser = menu.UpdateUser, //创建人 id = menu.Id //id }); return i; } /// /// 根据父级菜单号获取菜单信息 /// /// 菜单号 /// public List GetMenuByParentNo(string MenuNo) { string str = "select * from SysFunctionMenu where IsDel = @isdel and IsEnable = @isenable "; List menulist; //判断菜单号是否为空 if (!string.IsNullOrEmpty(MenuNo)) { str += " and ParentNo = @menuno"; menulist = Db.Ado.SqlQuery(str, new { isdel = "0", //是否删除 isenable = "0", //是否公开 menuno = MenuNo //菜单号 }); } else { str = "select * from SysFunctionMenu where IsDel = '3' and IsEnable = '0'"; menulist = Db.Ado.SqlQuery(str); } return menulist; } } }