123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- using OASystem.Domain;
- using OASystem.Domain.Entities.System;
- using OASystem.Domain.ViewModels.System;
- using Org.BouncyCastle.Utilities;
- using System.Collections;
- namespace OASystem.Infrastructure.Repositories.System
- {
- public class SystemMenuPermissionRepository : BaseRepository<Sys_SystemMenuPermission, SystemMenuPermissionView>
- {
- public SystemMenuPermissionRepository(SqlSugarClient sqlSugar) : base(sqlSugar)
- {
- }
- /// <summary>
- /// 分页查询页面表
- /// </summary>
- /// <param name="_SystemMenuPermissionRepository"></param>
- /// <param name="mid">模块id</param>
- /// <param name="pageSize">行数</param>
- /// <param name="currentPage">页码</param>
- /// <returns></returns>
- public Result GetSystemMenuViweData(SystemMenuPermissionRepository _SystemMenuPermissionRepository,int mid,int pageSize,int currentPage)
- {
- Result result = new Result();
- if (currentPage == 0 || pageSize == 0)
- {
- return result;
- }
- string sql = $@"select top {pageSize} * from (select row_number()
- over(order by id asc) as rownumber,*
- from Sys_SystemMenuPermission where mid = {mid} and isdel = 0 and IsEnable = 1 ) temp_row
- where rownumber> {(currentPage - 1) * pageSize};";
- var DBdata = _SystemMenuPermissionRepository.GetListBySqlWithNolock(sql);
- if (DBdata == null || DBdata.Count == 0)
- {
- result.Code = -1;
- result.Msg = "暂无数据!";
- result.Data = new
- {
- DBdata,
- total = 0
- };
- return result;
- }
- var total = _SystemMenuPermissionRepository.Query<Sys_SystemMenuPermission>(x => x.Mid == mid).Count();
- result.Code = 0;
- result.Msg = "成功!";
- result.Data = new
- {
- DBdata = DBdata.Select(x => new SystemMenuPermissionView
- {
- Id = x.Id,
- Name = x.Name,
- Mid = mid,
- SystemMenuCode = x.SystemMenuCode
- }),
- total = total
- };
- return result;
- }
- public Result QueryMenuLoad(int uid,int PortType)
- {
- Result result = new Result();
- result.Data = new string [0];
- if (uid != 0)
- {
- List<MenuLoadView> DBData = new List<MenuLoadView>();
- string sql = $@"
- select a.UId,a.SmId,b.Id as Funid,b.FunctionName,b.FunctionCode,c.Id as modulid,
- c.Name as modulName,c.STid,d.Id as pageid ,d.Name as PageName,d.SystemMenuCode,d.webUrl,d.AndroidUrl,d.icon,
- d.IosUrl
- from Sys_UserAuthority a inner join Sys_PageFunctionPermission b on a.FId = b.Id
- inner join Sys_SystemMenuPermission d on a.SmId = d.Id inner join Sys_SetData c on c.Id = d.Mid
- where uid = {uid} and a.IsDel= 0 and b.IsDel = 0
- and b.IsEnable = 1 and c.IsDel = 0 and d.IsDel = 0 ";
- if (PortType == 1)
- {
- //只返回查看权限
- //sql += $@" and b.Id = 1 and d.IsEnable = 1 group by
- // a.UId,a.SmId,b.Id,b.FunctionName,b.FunctionCode,c.Id,
- // c.Name,c.STid,d.Id,d.Name,d.SystemMenuCode,d.webUrl,d.AndroidUrl,d.icon,
- // d.IosUrl";
- //返回所有权限
- sql += $@" and d.IsEnable = 1 group by
- a.UId,a.SmId,b.Id,b.FunctionName,b.FunctionCode,c.Id,
- c.Name,c.STid,d.Id,d.Name,d.SystemMenuCode,d.webUrl,d.AndroidUrl,d.icon,
- d.IosUrl";
- DBData = _sqlSugar.SqlQueryable<MenuLoadView>(sql).ToList();
- }
- else if (PortType == 2)
- {
- sql += $@" and d.phoneIsEnable = 1 group by
- a.UId,a.SmId,b.Id,b.FunctionName,b.FunctionCode,c.Id,
- c.Name,c.STid,d.Id,d.Name,d.SystemMenuCode,d.webUrl,d.AndroidUrl,d.icon,
- d.IosUrl ";
- DBData = _sqlSugar.SqlQueryable<MenuLoadView>(sql).ToList();
- }
- result.Code = -1;
- result.Msg = "暂无数据!";
- if (DBData.Count > 0)
- {
- result.Code = 0;
- result.Msg = "成功!";
- var arr = new ArrayList();
- var setDataArr = _sqlSugar.SqlQueryable<Sys_SetData>("select * from Sys_SetData ssd WHERE IsDel = 0 AND STid = 5").ToList();
- if (PortType == 1)
- {
- var menuGroup = DBData.GroupBy(x => x.modulid);
- foreach (var item in menuGroup)
- {
- var pageData = item.Select(it => new
- {
- it.Uid,
- it.SmId,
- //it.Funid,
- //it.FunctionName,
- //it.FunctionCode,
- //it.modulid,
- //it.modulName,
- //it.STid,
- it.pageid,
- it.PageName,
- PageAuth = item.Where(x => x.pageid == it.pageid).Select(x => new { x.Funid, x.FunctionCode, x.FunctionName }),
- it.SystemMenuCode,
- it.webUrl,
- //it.AndroidUrl,
- //it.IosUrl,
- //it.icon,
- });
- pageData = pageData.GroupBy(x => x.SmId).Select(y => y.First());
- string Remark = setDataArr.Find(x => x.Id == item.FirstOrDefault()?.modulid)?.Remark ?? "";
-
- arr.Add(new
- {
- modulName = item.FirstOrDefault()?.modulName,
- modulid = item.FirstOrDefault()?.modulid,
- pageList = pageData,
- Remark
- });
-
- }
- }
- else if (PortType == 2)
- {
- var AndMenu = DBData.GroupBy(x => x.SmId).ToList();
- foreach (var item in AndMenu)
- {
- arr.Add(new
- {
- pageId = item.Key,
- opList = item.Select(x => x.Funid).ToList(),
- });
- }
- }
- result.Data = arr;
- }
-
- }
- return result;
- }
- public Result MobileMenuLoad(int uid, int PortType)
- {
- Result result = new Result();
- result.Data = new string[0];
- if (uid != 0)
- {
- List<MenuLoadView> DBData = new List<MenuLoadView>();
- string sql = $@"
- select a.UId,a.SmId,b.Id as Funid,b.FunctionName,b.FunctionCode,c.Id as modulid,
- c.Name as modulName,c.STid,d.Id as pageid ,d.Name as PageName,d.SystemMenuCode,d.webUrl,d.AndroidUrl,d.icon,
- d.IosUrl
- from Sys_UserAuthority a inner join Sys_PageFunctionPermission b on a.FId = b.Id
- inner join Sys_SystemMenuPermission d on a.SmId = d.Id inner join Sys_SetData c on c.Id = d.Mid
- where uid = {uid} and a.IsDel= 0 and b.IsDel = 0
- and b.IsEnable = 1 and c.IsDel = 0 and d.IsDel = 0 ";
- if (PortType == 1)
- {
- //只返回查看权限
- //sql += $@" and b.Id = 1 and d.IsEnable = 1 group by
- // a.UId,a.SmId,b.Id,b.FunctionName,b.FunctionCode,c.Id,
- // c.Name,c.STid,d.Id,d.Name,d.SystemMenuCode,d.webUrl,d.AndroidUrl,d.icon,
- // d.IosUrl";
- //返回所有权限
- sql += $@" and d.IsEnable = 1 group by
- a.UId,a.SmId,b.Id,b.FunctionName,b.FunctionCode,c.Id,
- c.Name,c.STid,d.Id,d.Name,d.SystemMenuCode,d.webUrl,d.AndroidUrl,d.icon,
- d.IosUrl";
- DBData = _sqlSugar.SqlQueryable<MenuLoadView>(sql).ToList();
- }
- else if (PortType == 2)
- {
- sql += $@" and d.phoneIsEnable = 1 group by
- a.UId,a.SmId,b.Id,b.FunctionName,b.FunctionCode,c.Id,
- c.Name,c.STid,d.Id,d.Name,d.SystemMenuCode,d.webUrl,d.AndroidUrl,d.icon,
- d.IosUrl ";
- DBData = _sqlSugar.SqlQueryable<MenuLoadView>(sql).ToList();
- }
- result.Code = -1;
- result.Msg = "暂无数据!";
- if (DBData.Count > 0)
- {
- result.Code = 0;
- result.Msg = "成功!";
- var arr = new ArrayList();
- var modelGroup = DBData.GroupBy(x => x.modulid);
- foreach (var item in modelGroup)
- {
- var modelData = new
- {
- modelId = item.Key,
- modelName = item.First().modulName,
- PageList = new ArrayList(),
- };
- var pageGroup = item.GroupBy(x => x.pageid);
- foreach (var page in pageGroup)
- {
- modelData.PageList.Add(new
- {
- pageId = page.Key,
- pageName = page.First().PageName,
- opList = page.Select(x => x.Funid)
- }) ;
- }
- arr.Add(modelData);
- }
- result.Data = arr;
- }
- }
- return result;
- }
- }
- }
|