first commit
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
using Infrastructure.Attribute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.Model.Dto.System;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Repository.System
|
||||
{
|
||||
/// <summary>
|
||||
/// 文章管理
|
||||
/// </summary>
|
||||
[AppService(ServiceLifetime = LifeTime.Transient)]
|
||||
public class ArticleRepository
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using Infrastructure.Attribute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using ZR.Repository.DbProvider;
|
||||
|
||||
namespace ZR.Repository.System
|
||||
{
|
||||
public class BaseRepository : SugarDbContext
|
||||
{
|
||||
protected void PrintLog()
|
||||
{
|
||||
//调式代码 用来打印SQL
|
||||
Db.Aop.OnLogExecuting = (sql, pars) =>
|
||||
{
|
||||
Console.WriteLine("【SQL语句】" + sql.ToLower() + "\r\n" + Db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)));
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using Infrastructure.Attribute;
|
||||
using System.Collections.Generic;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Repository.System
|
||||
{
|
||||
/// <summary>
|
||||
/// 部门管理
|
||||
/// </summary>
|
||||
[AppService(ServiceLifetime= LifeTime.Transient)]
|
||||
public class SysDeptRepository : BaseRepository
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="deptId"></param>
|
||||
/// <returns></returns>
|
||||
public List<SysDept> SelectChildrenDeptById(long deptId)
|
||||
{
|
||||
string sql = "select * from sys_dept where find_in_set(@deptId, ancestors)";
|
||||
|
||||
return Db.SqlQueryable<SysDept>(sql).AddParameters(new { @deptId = deptId }).ToList();
|
||||
}
|
||||
|
||||
public int UdateDeptChildren(SysDept dept)
|
||||
{
|
||||
return Db.Updateable(dept).UpdateColumns(it => new { it.Ancestors }).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
using Infrastructure.Attribute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Repository.System
|
||||
{
|
||||
/// <summary>
|
||||
/// 字典数据
|
||||
/// </summary>
|
||||
[AppService(ServiceLifetime = LifeTime.Transient)]
|
||||
public class SysDictDataRepository : BaseRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// 字典类型数据搜索
|
||||
/// </summary>
|
||||
/// <param name="dictData"></param>
|
||||
/// <returns></returns>
|
||||
public List<SysDictData> SelectDictDataList(SysDictData dictData)
|
||||
{
|
||||
return Db.Queryable<SysDictData>()
|
||||
.WhereIF(!string.IsNullOrEmpty(dictData.DictLabel), it => it.DictLabel.Contains(dictData.DictLabel))
|
||||
.WhereIF(!string.IsNullOrEmpty(dictData.Status), it => it.Status == dictData.Status)
|
||||
.WhereIF(!string.IsNullOrEmpty(dictData.DictType), it => it.DictType == dictData.DictType)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据字典类型查询
|
||||
/// </summary>
|
||||
/// <param name="dictData"></param>
|
||||
/// <returns></returns>
|
||||
public List<SysDictData> SelectDictDataByType(string dictType)
|
||||
{
|
||||
return Db.Queryable<SysDictData>().Where(f => f.Status == "0" && f.DictType == dictType)
|
||||
.OrderBy(it => it.DictSort)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据DictCode查询
|
||||
/// </summary>
|
||||
/// <param name="dictCode"></param>
|
||||
/// <returns></returns>
|
||||
public SysDictData SelectDictDataById(long dictCode)
|
||||
{
|
||||
return Db.Queryable<SysDictData>().Where(f => f.DictCode == dictCode).First();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增保存字典数据信息
|
||||
/// </summary>
|
||||
/// <param name="dict"></param>
|
||||
/// <returns></returns>
|
||||
public long InsertDictData(SysDictData dict)
|
||||
{
|
||||
var result = Db.Insertable(dict).IgnoreColumns(it => new { dict.Update_by })
|
||||
.ExecuteReturnIdentity();
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改数据
|
||||
/// </summary>
|
||||
/// <param name="dict"></param>
|
||||
/// <returns></returns>
|
||||
public long UpdateDictData(SysDictData dict)
|
||||
{
|
||||
return Db.Updateable<SysDictData>()
|
||||
.SetColumns(t => new SysDictData()
|
||||
{
|
||||
Remark = dict.Remark,
|
||||
Update_time = DateTime.Now,
|
||||
DictSort = dict.DictSort,
|
||||
DictLabel = dict.DictLabel,
|
||||
DictValue = dict.DictValue,
|
||||
Status = dict.Status
|
||||
})
|
||||
.Where(f => f.DictCode == dict.DictCode).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量删除字典数据信息
|
||||
/// </summary>
|
||||
/// <param name="dictCodes"></param>
|
||||
/// <returns></returns>
|
||||
public int DeleteDictDataByIds(long[] dictCodes)
|
||||
{
|
||||
return Db.Deleteable<SysDictData>().In(dictCodes).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询字典数据
|
||||
/// </summary>
|
||||
/// <param name="dictType"></param>
|
||||
/// <returns></returns>
|
||||
public int CountDictDataByType(string dictType)
|
||||
{
|
||||
return Db.Queryable<SysDictData>().Count(f => f.DictType == dictType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步修改字典类型
|
||||
/// </summary>
|
||||
/// <param name="old_dictType">旧字典类型</param>
|
||||
/// <param name="new_dictType">新字典类型</param>
|
||||
/// <returns></returns>
|
||||
public int UpdateDictDataType(string old_dictType, string new_dictType)
|
||||
{
|
||||
//只更新DictType字段根据where条件
|
||||
return Db.Updateable<SysDictData>()
|
||||
.SetColumns(t => new SysDictData() { DictType = new_dictType })
|
||||
.Where(f => f.DictType == old_dictType)
|
||||
.ExecuteCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
using Infrastructure.Attribute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Repository.System
|
||||
{
|
||||
/// <summary>
|
||||
/// 字典
|
||||
/// </summary>
|
||||
[AppService(ServiceLifetime = LifeTime.Transient)]
|
||||
public class SysDictRepository : BaseRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// 查询字段类型列表
|
||||
/// </summary>
|
||||
/// <param name="dictType">实体模型</param>
|
||||
/// <returns></returns>
|
||||
public List<SysDictType> SelectDictTypeList(SysDictType dictType)
|
||||
{
|
||||
return Db
|
||||
.Queryable<SysDictType>()
|
||||
.WhereIF(!string.IsNullOrEmpty(dictType.DictName), it => it.DictName.Contains(dictType.DictName))
|
||||
.WhereIF(!string.IsNullOrEmpty(dictType.Status), it => it.Status == dictType.Status)
|
||||
.WhereIF(!string.IsNullOrEmpty(dictType.DictType), it => it.DictType == dictType.DictType).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据Id查询
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public SysDictType SelectDictTypeById(long id)
|
||||
{
|
||||
return Db.Queryable<SysDictType>().First(it => it.DictId == id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查字典类型唯一值
|
||||
/// </summary>
|
||||
/// <param name="dictType"></param>
|
||||
/// <returns></returns>
|
||||
public SysDictType CheckDictTypeUnique(string dictType)
|
||||
{
|
||||
return Db.Queryable<SysDictType>().First(it => it.DictType == dictType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除一个
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public int DeleteDictTypeById(long id)
|
||||
{
|
||||
return Db.Deleteable<SysDictType>().In(id).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量删除
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public int DeleteDictTypeByIds(long[] id)
|
||||
{
|
||||
return Db.Deleteable<SysDictType>().In(id).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 插入
|
||||
/// </summary>
|
||||
/// <param name="sysDictType"></param>
|
||||
/// <returns></returns>
|
||||
public long InsertDictType(SysDictType sysDictType)
|
||||
{
|
||||
var result = Db.Insertable(sysDictType).IgnoreColumns(it => new { sysDictType.Update_by })
|
||||
.ExecuteReturnIdentity();
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改
|
||||
/// </summary>
|
||||
/// <param name="sysDictType"></param>
|
||||
/// <returns></returns>
|
||||
public int UpdateDictType(SysDictType dictType)
|
||||
{
|
||||
return Db.Updateable(dictType).IgnoreColumns(it => new { dictType.Create_by }).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Extensions;
|
||||
using System.Collections.Generic;
|
||||
using ZR.Model;
|
||||
using ZR.Model.Dto.System;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Repository.System
|
||||
{
|
||||
[AppService(ServiceLifetime = LifeTime.Transient)]
|
||||
public class SysLogininfoRepository : BaseRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// 查询登录日志
|
||||
/// </summary>
|
||||
/// <param name="logininfoDto"></param>
|
||||
/// <param name="pager"></param>
|
||||
/// <returns></returns>
|
||||
public List<SysLogininfor> GetLoginLog(SysLogininfor logininfoDto, PagerInfo pager)
|
||||
{
|
||||
int totalCount = 0;
|
||||
var list = Db.Queryable<SysLogininfor>()
|
||||
.Where(it => it.loginTime >= logininfoDto.BeginTime && it.loginTime <= logininfoDto.EndTime)
|
||||
.WhereIF(logininfoDto.ipaddr.IfNotEmpty(), f => f.ipaddr == logininfoDto.ipaddr)
|
||||
.WhereIF(logininfoDto.userName.IfNotEmpty(), f => f.userName.Contains(logininfoDto.userName))
|
||||
.WhereIF(logininfoDto.status.IfNotEmpty(), f => f.status == logininfoDto.status)
|
||||
.OrderBy(it => it.infoId, SqlSugar.OrderByType.Desc)
|
||||
.IgnoreColumns(it => new { it.Create_by, it.Create_time, it.Update_by, it.Update_time, it.Remark })
|
||||
.ToPageList(pager.PageNum, pager.PageSize, ref totalCount);
|
||||
pager.TotalNum = totalCount;
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 登录日志记录
|
||||
/// </summary>
|
||||
/// <param name="sysLogininfor"></param>
|
||||
/// <returns></returns>
|
||||
public void AddLoginInfo(SysLogininfor sysLogininfor)
|
||||
{
|
||||
int result = Db.Insertable(sysLogininfor)
|
||||
.IgnoreColumns(it => new { it.Create_by, it.Create_time, it.Remark })
|
||||
.ExecuteReturnIdentity();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空登录日志
|
||||
/// </summary>
|
||||
public void TruncateLogininfo()
|
||||
{
|
||||
string sql = "truncate table sys_logininfor";
|
||||
|
||||
Db.Ado.ExecuteCommand(sql);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除登录日志
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
public int DeleteLogininforByIds(long[] ids)
|
||||
{
|
||||
return Db.Deleteable<SysLogininfor>().In(ids).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 登录
|
||||
/// </summary>
|
||||
/// <param name="user">登录实体</param>
|
||||
/// <returns></returns>
|
||||
public SysUser Login(LoginBodyDto user)
|
||||
{
|
||||
return Db.Queryable<SysUser>().First(it => it.UserName == user.Username && it.Password == user.Password);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改登录信息
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public void UpdateLoginInfo(LoginBodyDto user, long userId)
|
||||
{
|
||||
Db.Updateable(new SysUser() { LoginIP = user.LoginIP, LoginDate = Db.GetDate(), UserId = userId })
|
||||
.UpdateColumns(it => new { it.LoginIP, it.LoginDate })
|
||||
.ExecuteCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
using Infrastructure.Attribute;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ZR.Model.Dto.System;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Repository.System
|
||||
{
|
||||
/// <summary>
|
||||
/// 系统菜单
|
||||
/// </summary>
|
||||
[AppService(ServiceLifetime = LifeTime.Transient)]
|
||||
public class SysMenuRepository : BaseRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取所有菜单(菜单管理)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<SysMenu> SelectMenuList(SysMenu menu)
|
||||
{
|
||||
return Db.Queryable<SysMenu>()
|
||||
.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)
|
||||
.OrderBy(it => new { it.parentId, it.orderNum })
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据用户查询系统菜单列表
|
||||
/// </summary>
|
||||
/// <param name="sysMenu"></param>
|
||||
/// <param name="userId">用户id</param>
|
||||
/// <returns></returns>
|
||||
public List<SysMenu> SelectMenuListByUserId(SysMenu sysMenu, long userId)
|
||||
{
|
||||
return Db.Queryable<SysMenu, SysRoleMenu, SysUserRole, SysRole>((menu, roleMenu, userRole, role) => new JoinQueryInfos(
|
||||
JoinType.Left, menu.menuId == roleMenu.Menu_id,
|
||||
JoinType.Left, roleMenu.Role_id == userRole.RoleId,
|
||||
JoinType.Left, userRole.RoleId == role.RoleId
|
||||
))
|
||||
.Where((menu, roleMenu, userRole, role) => userRole.UserId == userId)
|
||||
.WhereIF(!string.IsNullOrEmpty(sysMenu.menuName), (menu, roleMenu, userRole, role) => menu.menuName.Contains(sysMenu.menuName))
|
||||
.WhereIF(!string.IsNullOrEmpty(sysMenu.visible), (menu, roleMenu, userRole, role) => menu.visible == sysMenu.visible)
|
||||
.WhereIF(!string.IsNullOrEmpty(sysMenu.status), (menu, roleMenu, userRole, role) => menu.status == sysMenu.status)
|
||||
.OrderBy((menu, roleMenu, userRole, role) => new { menu.parentId, menu.orderNum })
|
||||
//.Distinct()
|
||||
.Select((menu, roleMenu, userRole, role) => menu).ToList();
|
||||
}
|
||||
|
||||
#region 左侧菜单树
|
||||
|
||||
/// <summary>
|
||||
/// 管理员获取左侧菜单树
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<SysMenu> SelectMenuTreeAll()
|
||||
{
|
||||
var menuTypes = new string[] { "M", "C" };
|
||||
|
||||
return Db.Queryable<SysMenu>()
|
||||
.Where(f => f.status == "0" && menuTypes.Contains(f.menuType))
|
||||
.OrderBy(it => new { it.parentId, it.orderNum }).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据用户角色获取左侧菜单树
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public List<SysMenu> SelectMenuTreeByRoleIds(List<long> roleIds)
|
||||
{
|
||||
var menuTypes = new string[] { "M", "C"};
|
||||
return Db.Queryable<SysMenu, SysRoleMenu>((menu, roleMenu) => new JoinQueryInfos(
|
||||
JoinType.Left, menu.menuId == roleMenu.Menu_id
|
||||
))
|
||||
.Where((menu, roleMenu) => roleIds.Contains(roleMenu.Role_id) && menuTypes.Contains(menu.menuType) && menu.status == "0")
|
||||
.OrderBy((menu, roleMenu) => new { menu.parentId, menu.orderNum })
|
||||
.Select((menu, roleMenu) => menu).ToList();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 获取菜单详情
|
||||
/// </summary>
|
||||
/// <param name="menuId"></param>
|
||||
/// <returns></returns>
|
||||
public SysMenu SelectMenuById(int menuId)
|
||||
{
|
||||
return Db.Queryable<SysMenu>().Where(it => it.menuId == menuId).Single();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加菜单
|
||||
/// </summary>
|
||||
/// <param name="menu"></param>
|
||||
/// <returns></returns>
|
||||
public int AddMenu(SysMenu menu)
|
||||
{
|
||||
menu.Create_time = Db.GetDate();
|
||||
menu.menuId = Db.Insertable(menu).ExecuteReturnIdentity();
|
||||
return 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 编辑菜单
|
||||
/// </summary>
|
||||
/// <param name="menu"></param>
|
||||
/// <returns></returns>
|
||||
public int EditMenu(SysMenu menu)
|
||||
{
|
||||
return Db.Updateable(menu).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除菜单
|
||||
/// </summary>
|
||||
/// <param name="menuId"></param>
|
||||
/// <returns></returns>
|
||||
public int DeleteMenuById(int menuId)
|
||||
{
|
||||
return Db.Deleteable<SysMenu>().Where(it => it.menuId == menuId).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 菜单排序
|
||||
/// </summary>
|
||||
/// <param name="menuDto">菜单Dto</param>
|
||||
/// <returns></returns>
|
||||
public int ChangeSortMenu(MenuDto menuDto)
|
||||
{
|
||||
var result = Db.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 Db.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 Db.Queryable<SysMenu>()
|
||||
.Where(it => it.menuName == menu.menuName && it.parentId == menu.parentId).Single();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否存在菜单子节点
|
||||
/// </summary>
|
||||
/// <param name="menuId"></param>
|
||||
/// <returns></returns>
|
||||
public int HasChildByMenuId(long menuId)
|
||||
{
|
||||
return Db.Queryable<SysMenu>().Where(it => it.parentId == menuId).Count();
|
||||
}
|
||||
|
||||
#region RoleMenu
|
||||
|
||||
/// <summary>
|
||||
/// 查询菜单使用数量
|
||||
/// </summary>
|
||||
/// <param name="menuId"></param>
|
||||
/// <returns></returns>
|
||||
public int CheckMenuExistRole(long menuId)
|
||||
{
|
||||
return Db.Queryable<SysRoleMenu>().Where(it => it.Menu_id == menuId).Count();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Extensions;
|
||||
using System.Collections.Generic;
|
||||
using ZR.Model;
|
||||
using ZR.Model.Dto.System;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Repository.System
|
||||
{
|
||||
[AppService(ServiceLifetime = LifeTime.Transient)]
|
||||
public class SysOperLogRepository : BaseRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// 查询操作日志
|
||||
/// </summary>
|
||||
/// <param name="sysOper"></param>
|
||||
/// <param name="pagerInfo">分页数据</param>
|
||||
/// <returns></returns>
|
||||
public List<SysOperLog> GetSysOperLog(SysOperLogDto sysOper, PagerInfo pagerInfo)
|
||||
{
|
||||
int totalCount = 0;
|
||||
var list = Db.Queryable<SysOperLog>()
|
||||
.Where(it => it.operTime >= sysOper.BeginTime && it.operTime <= sysOper.EndTime)
|
||||
.WhereIF(sysOper.Title.IfNotEmpty(), it => it.title.Contains(sysOper.Title))
|
||||
.WhereIF(sysOper.operName.IfNotEmpty(), it => it.operName.Contains(sysOper.operName))
|
||||
.WhereIF(sysOper.BusinessType != -1, it =>it.businessType == sysOper.BusinessType)
|
||||
.WhereIF(sysOper.Status != -1, it => it.status == sysOper.Status)
|
||||
.OrderBy(it => it.OperId, SqlSugar.OrderByType.Desc)
|
||||
.ToPageList(pagerInfo.PageNum, pagerInfo.PageSize, ref totalCount);
|
||||
pagerInfo.TotalNum = totalCount;
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加操作日志
|
||||
/// </summary>
|
||||
/// <param name="sysOperLog"></param>
|
||||
/// <returns></returns>
|
||||
public void AddSysOperLog(SysOperLog sysOperLog)
|
||||
{
|
||||
Db.Insertable(sysOperLog).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空日志
|
||||
/// </summary>
|
||||
public void ClearOperLog()
|
||||
{
|
||||
string sql = "truncate table sys_oper_log";
|
||||
Db.Ado.ExecuteCommand(sql);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除操作日志
|
||||
/// </summary>
|
||||
/// <param name="operIds"></param>
|
||||
/// <returns></returns>
|
||||
public int DeleteOperLogByIds(long[] operIds)
|
||||
{
|
||||
return Db.Deleteable<SysOperLog>().In(operIds).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询操作日志
|
||||
/// </summary>
|
||||
/// <param name="operId"></param>
|
||||
/// <returns></returns>
|
||||
public SysOperLog SelectOperLogById(long operId)
|
||||
{
|
||||
return Db.Queryable<SysOperLog>().InSingle(operId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
using Infrastructure.Attribute;
|
||||
using SqlSugar;
|
||||
using System.Collections.Generic;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Repository.System
|
||||
{
|
||||
/// <summary>
|
||||
/// 角色操作类
|
||||
/// </summary>
|
||||
[AppService(ServiceLifetime = LifeTime.Transient)]
|
||||
public class SysRoleRepository : BaseRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// 根据条件分页查询角色数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<SysRole> SelectRoleList(SysRole sysRole)
|
||||
{
|
||||
return Db.Queryable<SysRole>()
|
||||
.Where(role => role.DelFlag == "0")
|
||||
.WhereIF(!string.IsNullOrEmpty(sysRole.RoleName), role => role.RoleName.Contains(sysRole.RoleName))
|
||||
.WhereIF(!string.IsNullOrEmpty(sysRole.Status), role => role.Status == sysRole.Status)
|
||||
.WhereIF(!string.IsNullOrEmpty(sysRole.RoleKey), role => role.RoleKey == sysRole.RoleKey)
|
||||
.OrderBy(role => role.RoleSort)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据用户查询
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public List<SysRole> SelectRolePermissionByUserId(long userId)
|
||||
{
|
||||
return Db.Queryable<SysRole>()
|
||||
.Where(role => role.DelFlag == "0")
|
||||
.Where(it => SqlFunc.Subqueryable<SysUserRole>().Where(s => s.UserId == userId).Any())
|
||||
.OrderBy(role => role.RoleSort)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询所有角色
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<SysRole> SelectRoleAll()
|
||||
{
|
||||
return Db.Queryable<SysRole>().OrderBy(it => it.RoleSort).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过角色ID查询角色
|
||||
/// </summary>
|
||||
/// <param name="roleId">角色编号</param>
|
||||
/// <returns></returns>
|
||||
public SysRole SelectRoleById(long roleId)
|
||||
{
|
||||
return Db.Queryable<SysRole>().InSingle(roleId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过角色ID删除角色
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <returns></returns>
|
||||
public int DeleteRoleByRoleIds(long[] roleId)
|
||||
{
|
||||
return Db.Deleteable<SysRole>().In(roleId).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户所有角色信息
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public List<SysRole> SelectUserRoleListByUserId(long userId)
|
||||
{
|
||||
return Db.Queryable<SysUserRole, SysRole>((ur, r) => new SqlSugar.JoinQueryInfos(
|
||||
SqlSugar.JoinType.Left, ur.RoleId == r.RoleId
|
||||
)).Where((ur, r) => ur.UserId == userId)
|
||||
.Select((ur, r) => r).ToList();
|
||||
}
|
||||
|
||||
#region 用户角色对应菜单 用户N-1角色
|
||||
|
||||
/// <summary>
|
||||
/// 根据角色获取菜单id
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <returns></returns>
|
||||
public List<SysRoleMenu> SelectRoleMenuByRoleId(long roleId)
|
||||
{
|
||||
return Db.Queryable<SysRoleMenu>().Where(it => it.Role_id == roleId).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量插入用户菜单
|
||||
/// </summary>
|
||||
/// <param name="sysRoleMenus"></param>
|
||||
/// <returns></returns>
|
||||
public int AddRoleMenu(List<SysRoleMenu> sysRoleMenus)
|
||||
{
|
||||
return Db.Insertable(sysRoleMenus).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除角色与菜单关联
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <returns></returns>
|
||||
public int DeleteRoleMenuByRoleId(long roleId)
|
||||
{
|
||||
return Db.Deleteable<SysRoleMenu>().Where(it => it.Role_id == roleId).ExecuteCommand();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 添加角色
|
||||
/// </summary>
|
||||
/// <param name="sysRole"></param>
|
||||
/// <returns></returns>
|
||||
public long InsertRole(SysRole sysRole)
|
||||
{
|
||||
sysRole.Create_time = Db.GetDate();
|
||||
return Db.Insertable(sysRole).ExecuteReturnBigIdentity();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改用户角色
|
||||
/// </summary>
|
||||
/// <param name="sysRole"></param>
|
||||
/// <returns></returns>
|
||||
public int UpdateSysRole(SysRole sysRole)
|
||||
{
|
||||
var db = Db;
|
||||
sysRole.Update_time = db.GetDate();
|
||||
|
||||
return db.Updateable<SysRole>()
|
||||
.SetColumns(it => it.Update_time == sysRole.Update_time)
|
||||
.SetColumns(it => it.Remark == sysRole.Remark)
|
||||
.SetColumns(it => it.Update_by == sysRole.Update_by)
|
||||
.SetColumnsIF(!string.IsNullOrEmpty(sysRole.RoleName), it => it.RoleName == sysRole.RoleName)
|
||||
.SetColumnsIF(!string.IsNullOrEmpty(sysRole.RoleKey), it => it.RoleKey == sysRole.RoleKey)
|
||||
.SetColumnsIF(sysRole.RoleSort >= 0, it => it.RoleSort == sysRole.RoleSort)
|
||||
.Where(it => it.RoleId == sysRole.RoleId)
|
||||
.ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更改角色权限状态
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <param name="status"></param>
|
||||
/// <returns></returns>
|
||||
public int UpdateRoleStatus(SysRole role)
|
||||
{
|
||||
return Db.Updateable(role).UpdateColumns(t => new { t.Status }).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查角色权限是否存在
|
||||
/// </summary>
|
||||
/// <param name="roleKey">角色权限</param>
|
||||
/// <returns></returns>
|
||||
public SysRole CheckRoleKeyUnique(string roleKey)
|
||||
{
|
||||
return Db.Queryable<SysRole>().Where(it => it.RoleKey == roleKey).Single();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 校验角色名称是否唯一
|
||||
/// </summary>
|
||||
/// <param name="roleName">角色名称</param>
|
||||
/// <returns></returns>
|
||||
public SysRole CheckRoleNameUnique(string roleName)
|
||||
{
|
||||
return Db.Queryable<SysRole>().Where(it => it.RoleName == roleName).Single();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using Infrastructure.Attribute;
|
||||
using SqlSugar;
|
||||
using System.Collections.Generic;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Repository.System
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户岗位
|
||||
/// </summary>
|
||||
[AppService(ServiceLifetime = LifeTime.Transient)]
|
||||
public class SysUserPostRepository : BaseRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取用户岗位
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public List<SysPost> SelectPostsByUserId(long userId)
|
||||
{
|
||||
return Db.Queryable<SysPost, SysUserPost>((p, up) => new JoinQueryInfos(
|
||||
JoinType.Left, up.PostId == p.PostId
|
||||
)).Where((p, up) => up.UserId == userId)
|
||||
.Select<SysPost>().ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
using Infrastructure.Attribute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ZR.Model;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Repository.System
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户管理
|
||||
/// </summary>
|
||||
[AppService(ServiceLifetime = LifeTime.Transient)]
|
||||
public class SysUserRepository : BaseRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// 根据条件分页查询用户列表
|
||||
/// <paramref name="user"/>
|
||||
/// <paramref name="user"/>
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<SysUser> SelectUserList(SysUser user, PagerInfo pager)
|
||||
{
|
||||
string sql = @"SELECT u.*,d.deptName, d.leader
|
||||
FROM sys_user u
|
||||
left join sys_dept d on u.deptId = d.deptId
|
||||
WHERE u.delFlag = '0' ";
|
||||
int totalCount = 0;
|
||||
var list = Db.SqlQueryable<SysUser>(sql)
|
||||
.WhereIF(!string.IsNullOrEmpty(user.UserName), it => it.UserName.Contains(user.UserName))
|
||||
.WhereIF(!string.IsNullOrEmpty(user.Status), it => it.Status == user.Status)
|
||||
.WhereIF(user.BeginTime != DateTime.MinValue && user.BeginTime != null, it => it.Create_time >= user.BeginTime)
|
||||
.WhereIF(user.EndTime != DateTime.MinValue && user.BeginTime != null, it => it.EndTime <= user.EndTime)
|
||||
.WhereIF(user.DeptId != 0, it => it.DeptId == user.DeptId)
|
||||
.OrderBy(it => it.UserId)
|
||||
.ToPageList(pager.PageNum, pager.PageSize, ref totalCount);
|
||||
pager.TotalNum = totalCount;
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过用户ID查询用户
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public SysUser SelectUserById(long userId)
|
||||
{
|
||||
return Db.Queryable<SysUser>().Where(f => f.UserId == userId).First();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 校验用户名是否存在
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
public int CheckUserNameUnique(string userName)
|
||||
{
|
||||
return Db.Queryable<SysUser>().Where(it => it.UserName == userName).Count();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加用户
|
||||
/// </summary>
|
||||
/// <param name="sysUser"></param>
|
||||
/// <returns></returns>
|
||||
public int AddUser(SysUser sysUser)
|
||||
{
|
||||
sysUser.Create_time = DateTime.Now;
|
||||
return Db.Insertable(sysUser).ExecuteReturnIdentity();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重置密码
|
||||
/// </summary>
|
||||
/// <param name="userid"></param>
|
||||
/// <param name="password"></param>
|
||||
/// <returns></returns>
|
||||
public int ResetPwd(long userid, string password)
|
||||
{
|
||||
return Db.Updateable(new SysUser() { UserId = userid, Password = password })
|
||||
.UpdateColumns(it => new { it.Password }).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 改变用户状态
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
public int ChangeUserStatus(SysUser user)
|
||||
{
|
||||
return Db.Updateable(user).UpdateColumns(t => new { t.Status })
|
||||
.ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除用户
|
||||
/// </summary>
|
||||
/// <param name="userid">用户id</param>
|
||||
/// <returns></returns>
|
||||
public int DeleteUser(long userid)
|
||||
{
|
||||
return Db.Updateable(new SysUser() { UserId = userid, DelFlag = "2" })
|
||||
.UpdateColumns(t => t.DelFlag)
|
||||
.ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改用户信息
|
||||
/// </summary>
|
||||
/// <param name="sysUser"></param>
|
||||
/// <returns></returns>
|
||||
public int UpdateUser(SysUser user)
|
||||
{
|
||||
return Db.Updateable(user)
|
||||
//.SetColumns(t => new SysUser()
|
||||
//{
|
||||
// UserName = user.UserName,
|
||||
// Status = user.Status,
|
||||
// NickName = user.NickName,
|
||||
// Remark = user.Remark,
|
||||
// Email = user.Email,
|
||||
// Update_by = user.Update_by,
|
||||
// Phonenumber = user.Phonenumber,
|
||||
// Update_time = DateTime.Now,
|
||||
// Sex = user.Sex,
|
||||
// DeptId = user.DeptId
|
||||
//})
|
||||
.IgnoreColumns(ignoreAllNullColumns: true)//忽略所有为null
|
||||
.IgnoreColumns(it => new { it.Password, it.Avatar })
|
||||
.Where(f => f.UserId == user.UserId).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改用户头像
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
public int UpdatePhoto(SysUser user)
|
||||
{
|
||||
return Db.Updateable<SysUser>()
|
||||
.SetColumns(t => new SysUser()
|
||||
{
|
||||
Avatar = user.Avatar
|
||||
})
|
||||
.Where(f => f.UserId == user.UserId).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
using Infrastructure.Attribute;
|
||||
using SqlSugar;
|
||||
using System.Collections.Generic;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Repository.System
|
||||
{
|
||||
[AppService(ServiceLifetime = LifeTime.Transient)]
|
||||
public class SysUserRoleRepository : BaseRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// 删除用户角色
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public int DeleteUserRoleByUserId(int userId)
|
||||
{
|
||||
return Db.Deleteable<SysUserRole>().Where(it => it.UserId == userId).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量删除角色对应用户
|
||||
/// </summary>
|
||||
/// <param name="roleId">角色id</param>
|
||||
/// <param name="userIds">用户id集合</param>
|
||||
/// <returns></returns>
|
||||
public int DeleteRoleUserByUserIds(long roleId, List<long> userIds)
|
||||
{
|
||||
return Db.Deleteable<SysUserRole>().Where(it => it.RoleId == roleId && userIds.Contains(it.UserId))
|
||||
.ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加用户角色
|
||||
/// </summary>
|
||||
/// <param name="sysUsers"></param>
|
||||
/// <returns></returns>
|
||||
public int AddUserRole(List<SysUserRole> sysUsers)
|
||||
{
|
||||
return Db.Insertable(sysUsers).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除角色关联的用户
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <returns></returns>
|
||||
public int DeleteUserRoleByRoleId(int roleId)
|
||||
{
|
||||
return Db.Deleteable<SysUserRole>().In(roleId).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取角色分配个数
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <returns></returns>
|
||||
public int CountUserRoleByRoleId(long roleId)
|
||||
{
|
||||
return Db.Queryable<SysUserRole>().Where(it => it.RoleId == roleId).Count();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户数据根据角色id
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <returns></returns>
|
||||
public List<SysUser> GetSysUsersByRoleId(long roleId)
|
||||
{
|
||||
return Db.Queryable<SysUserRole, SysUser>((t1, user) => new JoinQueryInfos(
|
||||
JoinType.Left, t1.UserId == user.UserId))
|
||||
.Where((t1, user) => t1.RoleId == roleId && user.DelFlag == "0")
|
||||
.Select((t1, user) => user)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user