优化仓储
This commit is contained in:
parent
7f5e74122d
commit
5cd7e5dba3
@ -1,20 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Infrastructure.Attribute;
|
|
||||||
using ZR.Repository.System;
|
|
||||||
using ZR.Model.Models;
|
|
||||||
|
|
||||||
namespace ZR.Repository
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 演示仓储
|
|
||||||
///
|
|
||||||
/// @author zz
|
|
||||||
/// @date 2022-03-31
|
|
||||||
/// </summary>
|
|
||||||
[AppService(ServiceLifetime = LifeTime.Transient)]
|
|
||||||
public class GenDemoRepository : BaseRepository<GenDemo>
|
|
||||||
{
|
|
||||||
#region 业务逻辑代码
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,204 +0,0 @@
|
|||||||
using Infrastructure.Attribute;
|
|
||||||
using SqlSugar;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using ZR.Model.System.Dto;
|
|
||||||
using ZR.Model.System;
|
|
||||||
|
|
||||||
namespace ZR.Repository.System
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 系统菜单
|
|
||||||
/// </summary>
|
|
||||||
[AppService(ServiceLifetime = LifeTime.Transient)]
|
|
||||||
public class SysMenuRepository : BaseRepository<SysMenu>
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 获取所有菜单(菜单管理)
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public List<SysMenu> SelectTreeMenuList(MenuQueryDto menu)
|
|
||||||
{
|
|
||||||
int parentId = 0;
|
|
||||||
if (menu.ParentId != null)
|
|
||||||
{
|
|
||||||
parentId = (int)menu.ParentId;
|
|
||||||
}
|
|
||||||
var list = Queryable()
|
|
||||||
.WhereIF(!string.IsNullOrEmpty(menu.MenuName), it => it.MenuName.Contains(menu.MenuName))
|
|
||||||
.WhereIF(!string.IsNullOrEmpty(menu.Visible), it => it.Visible == menu.Visible)
|
|
||||||
.WhereIF(!string.IsNullOrEmpty(menu.Status), it => it.Status == menu.Status)
|
|
||||||
.WhereIF(!string.IsNullOrEmpty(menu.MenuTypeIds), it => menu.MenuTypeIdArr.Contains(it.MenuType))
|
|
||||||
.WhereIF(menu.ParentId != null, it => it.ParentId == menu.ParentId)
|
|
||||||
.OrderBy(it => new { it.ParentId, it.OrderNum })
|
|
||||||
.ToTree(it => it.Children, it => it.ParentId, menu.ParentId);
|
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 根据用户查询系统菜单列表
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="menu"></param>
|
|
||||||
/// <param name="roles">用户角色集合</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public List<SysMenu> SelectTreeMenuListByRoles(MenuQueryDto menu, List<long> roles)
|
|
||||||
{
|
|
||||||
var roleMenus = Context.Queryable<SysRoleMenu>()
|
|
||||||
.Where(r => roles.Contains(r.Role_id))
|
|
||||||
.Select(f => f.Menu_id).Distinct().ToList();
|
|
||||||
|
|
||||||
return Queryable()
|
|
||||||
.Where(c => roleMenus.Contains(c.MenuId))
|
|
||||||
.WhereIF(!string.IsNullOrEmpty(menu.MenuName), (c) => c.MenuName.Contains(menu.MenuName))
|
|
||||||
.WhereIF(!string.IsNullOrEmpty(menu.Visible), (c) => c.Visible == menu.Visible)
|
|
||||||
.WhereIF(!string.IsNullOrEmpty(menu.Status), (c) => c.Status == menu.Status)
|
|
||||||
.WhereIF(!string.IsNullOrEmpty(menu.MenuTypeIds), c => menu.MenuTypeIdArr.Contains(c.MenuType))
|
|
||||||
.OrderBy((c) => new { c.ParentId, c.OrderNum })
|
|
||||||
.Select(c => c)
|
|
||||||
.ToTree(it => it.Children, it => it.ParentId, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取所有菜单
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public List<SysMenu> SelectMenuList(MenuQueryDto menu)
|
|
||||||
{
|
|
||||||
return Queryable()
|
|
||||||
.WhereIF(!string.IsNullOrEmpty(menu.MenuName), it => it.MenuName.Contains(menu.MenuName))
|
|
||||||
.WhereIF(!string.IsNullOrEmpty(menu.Visible), it => it.Visible == menu.Visible)
|
|
||||||
.WhereIF(!string.IsNullOrEmpty(menu.Status), it => it.Status == menu.Status)
|
|
||||||
.WhereIF(menu.ParentId != null, it => it.ParentId == menu.ParentId)
|
|
||||||
.OrderBy(it => new { it.ParentId, it.OrderNum })
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 根据用户查询系统菜单列表
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sysMenu"></param>
|
|
||||||
/// <param name="roles">用户角色集合</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public List<SysMenu> SelectMenuListByRoles(MenuQueryDto sysMenu, List<long> roles)
|
|
||||||
{
|
|
||||||
var roleMenus = Context.Queryable<SysRoleMenu>()
|
|
||||||
.Where(r => roles.Contains(r.Role_id));
|
|
||||||
|
|
||||||
return Queryable()
|
|
||||||
.InnerJoin(roleMenus, (c, j) => c.MenuId == j.Menu_id)
|
|
||||||
.Where((c, j) => c.Status == "0")
|
|
||||||
.WhereIF(!string.IsNullOrEmpty(sysMenu.MenuName), (c, j) => c.MenuName.Contains(sysMenu.MenuName))
|
|
||||||
.WhereIF(!string.IsNullOrEmpty(sysMenu.Visible), (c, j) => c.Visible == sysMenu.Visible)
|
|
||||||
.OrderBy((c, j) => new { c.ParentId, c.OrderNum })
|
|
||||||
.Select(c => c)
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取菜单详情
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="menuId"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public SysMenu SelectMenuById(int menuId)
|
|
||||||
{
|
|
||||||
return GetFirst(it => it.MenuId == menuId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 添加菜单
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="menu"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public int AddMenu(SysMenu menu)
|
|
||||||
{
|
|
||||||
menu.Create_time = DateTime.Now;
|
|
||||||
menu.MenuId = InsertReturnIdentity(menu);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 编辑菜单
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="menu"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public int EditMenu(SysMenu menu)
|
|
||||||
{
|
|
||||||
return Update(menu, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 删除菜单
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="menuId"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public int DeleteMenuById(int menuId)
|
|
||||||
{
|
|
||||||
return Delete(menuId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 菜单排序
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="menuDto">菜单Dto</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public int ChangeSortMenu(MenuDto menuDto)
|
|
||||||
{
|
|
||||||
var result = Context.Updateable(new SysMenu() { MenuId = menuDto.MenuId, OrderNum = menuDto.OrderNum })
|
|
||||||
.UpdateColumns(it => new { it.OrderNum }).ExecuteCommand();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 查询菜单权限
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="userId"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public List<SysMenu> SelectMenuPermsByUserId(long userId)
|
|
||||||
{
|
|
||||||
return Context.Queryable<SysMenu, SysRoleMenu, SysUserRole, SysRole>((m, rm, ur, r) => new JoinQueryInfos(
|
|
||||||
JoinType.Left, m.MenuId == rm.Menu_id,
|
|
||||||
JoinType.Left, rm.Role_id == ur.RoleId,
|
|
||||||
JoinType.Left, ur.RoleId == r.RoleId
|
|
||||||
))
|
|
||||||
//.Distinct()
|
|
||||||
.Where((m, rm, ur, r) => m.Status == "0" && r.Status == "0" && ur.UserId == userId)
|
|
||||||
.Select((m, rm, ur, r) => m).ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 校验菜单名称是否唯一
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="menu"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public SysMenu CheckMenuNameUnique(SysMenu menu)
|
|
||||||
{
|
|
||||||
return GetFirst(it => it.MenuName == menu.MenuName && it.ParentId == menu.ParentId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 是否存在菜单子节点
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="menuId"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public int HasChildByMenuId(long menuId)
|
|
||||||
{
|
|
||||||
return Count(it => it.ParentId == menuId);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region RoleMenu
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 查询菜单使用数量
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="menuId"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public int CheckMenuExistRole(long menuId)
|
|
||||||
{
|
|
||||||
return Context.Queryable<SysRoleMenu>().Where(it => it.Menu_id == menuId).Count();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,21 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Infrastructure.Attribute;
|
|
||||||
using ZR.Repository.System;
|
|
||||||
using ZR.Model.Models;
|
|
||||||
using ZR.Model.System;
|
|
||||||
|
|
||||||
namespace ZR.Repository.System
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 通知公告表仓储
|
|
||||||
///
|
|
||||||
/// @author zr
|
|
||||||
/// @date 2021-12-15
|
|
||||||
/// </summary>
|
|
||||||
[AppService(ServiceLifetime = LifeTime.Transient)]
|
|
||||||
public class SysNoticeRepository : BaseRepository<SysNotice>
|
|
||||||
{
|
|
||||||
#region 业务逻辑代码
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -19,5 +19,6 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Business\" />
|
<Folder Include="Business\" />
|
||||||
|
<Folder Include="System\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@ -20,12 +20,6 @@ namespace ZR.Service.Business
|
|||||||
[AppService(ServiceType = typeof(IGenDemoService), ServiceLifetime = LifeTime.Transient)]
|
[AppService(ServiceType = typeof(IGenDemoService), ServiceLifetime = LifeTime.Transient)]
|
||||||
public class GenDemoService : BaseService<GenDemo>, IGenDemoService
|
public class GenDemoService : BaseService<GenDemo>, IGenDemoService
|
||||||
{
|
{
|
||||||
private readonly GenDemoRepository _GenDemorepository;
|
|
||||||
public GenDemoService(GenDemoRepository repository)
|
|
||||||
{
|
|
||||||
_GenDemorepository = repository;
|
|
||||||
}
|
|
||||||
|
|
||||||
#region 业务逻辑代码
|
#region 业务逻辑代码
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -44,8 +38,7 @@ namespace ZR.Service.Business
|
|||||||
predicate = predicate.AndIF(parm.ShowStatus != null, it => it.ShowStatus == parm.ShowStatus);
|
predicate = predicate.AndIF(parm.ShowStatus != null, it => it.ShowStatus == parm.ShowStatus);
|
||||||
predicate = predicate.AndIF(parm.BeginAddTime == null, it => it.AddTime >= DateTime.Now.AddDays(-1));
|
predicate = predicate.AndIF(parm.BeginAddTime == null, it => it.AddTime >= DateTime.Now.AddDays(-1));
|
||||||
predicate = predicate.AndIF(parm.BeginAddTime != null, it => it.AddTime >= parm.BeginAddTime && it.AddTime <= parm.EndAddTime);
|
predicate = predicate.AndIF(parm.BeginAddTime != null, it => it.AddTime >= parm.BeginAddTime && it.AddTime <= parm.EndAddTime);
|
||||||
var response = _GenDemorepository
|
var response = Queryable()
|
||||||
.Queryable()
|
|
||||||
.Where(predicate.ToExpression())
|
.Where(predicate.ToExpression())
|
||||||
.ToPage(parm);
|
.ToPage(parm);
|
||||||
return response;
|
return response;
|
||||||
|
|||||||
@ -9,7 +9,6 @@ using System.Text;
|
|||||||
using ZR.Common;
|
using ZR.Common;
|
||||||
using ZR.Model.System;
|
using ZR.Model.System;
|
||||||
using ZR.Model.System.Vo;
|
using ZR.Model.System.Vo;
|
||||||
using ZR.Repository.System;
|
|
||||||
using ZR.Service.System.IService;
|
using ZR.Service.System.IService;
|
||||||
|
|
||||||
namespace ZR.Service.System
|
namespace ZR.Service.System
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user