first commit
This commit is contained in:
@@ -0,0 +1,313 @@
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Model;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using ZR.Model;
|
||||
using ZR.Repository.DbProvider;
|
||||
|
||||
namespace ZR.Service
|
||||
{
|
||||
/// <summary>
|
||||
/// 基础服务定义
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public class BaseService<T> : SugarDbContext, IBaseService<T> where T : class, new()
|
||||
{
|
||||
#region 事务
|
||||
|
||||
/// <summary>
|
||||
/// 启用事务
|
||||
/// </summary>
|
||||
public void BeginTran()
|
||||
{
|
||||
Db.Ado.BeginTran();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 提交事务
|
||||
/// </summary>
|
||||
public void CommitTran()
|
||||
{
|
||||
Db.Ado.CommitTran();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 回滚事务
|
||||
/// </summary>
|
||||
public void RollbackTran()
|
||||
{
|
||||
Db.Ado.RollbackTran();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 添加操作
|
||||
/// <summary>
|
||||
/// 添加一条数据
|
||||
/// </summary>
|
||||
/// <param name="parm">T</param>
|
||||
/// <returns></returns>
|
||||
public int Add(T parm)
|
||||
{
|
||||
return Db.Insertable(parm).RemoveDataCache().ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量添加数据
|
||||
/// </summary>
|
||||
/// <param name="parm">List<T></param>
|
||||
/// <returns></returns>
|
||||
public int Add(List<T> parm)
|
||||
{
|
||||
return Db.Insertable(parm).RemoveDataCache().ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加或更新数据
|
||||
/// </summary>
|
||||
/// <param name="parm">List<T></param>
|
||||
/// <returns></returns>
|
||||
public T Saveable(T parm, Expression<Func<T, object>> uClumns = null, Expression<Func<T, object>> iColumns = null)
|
||||
{
|
||||
var command = Db.Saveable(parm);
|
||||
|
||||
if (uClumns != null)
|
||||
{
|
||||
command = command.UpdateIgnoreColumns(uClumns);
|
||||
}
|
||||
|
||||
if (iColumns != null)
|
||||
{
|
||||
command = command.InsertIgnoreColumns(iColumns);
|
||||
}
|
||||
|
||||
return command.ExecuteReturnEntity();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量添加或更新数据
|
||||
/// </summary>
|
||||
/// <param name="parm">List<T></param>
|
||||
/// <returns></returns>
|
||||
public List<T> Saveable(List<T> parm, Expression<Func<T, object>> uClumns = null, Expression<Func<T, object>> iColumns = null)
|
||||
{
|
||||
var command = Db.Saveable(parm);
|
||||
|
||||
if (uClumns != null)
|
||||
{
|
||||
command = command.UpdateIgnoreColumns(uClumns);
|
||||
}
|
||||
|
||||
if (iColumns != null)
|
||||
{
|
||||
command = command.InsertIgnoreColumns(iColumns);
|
||||
}
|
||||
|
||||
return command.ExecuteReturnList();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 查询操作
|
||||
|
||||
/// <summary>
|
||||
/// 根据条件查询数据是否存在
|
||||
/// </summary>
|
||||
/// <param name="where">条件表达式树</param>
|
||||
/// <returns></returns>
|
||||
public bool Any(Expression<Func<T, bool>> where)
|
||||
{
|
||||
return Db.Queryable<T>().Any(where);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据条件合计字段
|
||||
/// </summary>
|
||||
/// <param name="where">条件表达式树</param>
|
||||
/// <returns></returns>
|
||||
public TResult Sum<TResult>(Expression<Func<T, bool>> where, Expression<Func<T, TResult>> field)
|
||||
{
|
||||
return Db.Queryable<T>().Where(where).Sum(field);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据主值查询单条数据
|
||||
/// </summary>
|
||||
/// <param name="pkValue">主键值</param>
|
||||
/// <returns>泛型实体</returns>
|
||||
public T GetId(object pkValue)
|
||||
{
|
||||
return Db.Queryable<T>().InSingle(pkValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据主键查询多条数据
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
public List<T> GetIn(object[] ids)
|
||||
{
|
||||
return Db.Queryable<T>().In(ids).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据条件取条数
|
||||
/// </summary>
|
||||
/// <param name="where">条件表达式树</param>
|
||||
/// <returns></returns>
|
||||
public int GetCount(Expression<Func<T, bool>> where)
|
||||
{
|
||||
return Db.Queryable<T>().Count(where);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询所有数据(无分页,请慎用)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<T> GetAll(bool useCache = false, int cacheSecond = 3600)
|
||||
{
|
||||
return Db.Queryable<T>().WithCacheIF(useCache, cacheSecond).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得一条数据
|
||||
/// </summary>
|
||||
/// <param name="where">Expression<Func<T, bool>></param>
|
||||
/// <returns></returns>
|
||||
public T GetFirst(Expression<Func<T, bool>> where)
|
||||
{
|
||||
return Db.Queryable<T>().Where(where).First();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得一条数据
|
||||
/// </summary>
|
||||
/// <param name="parm">string</param>
|
||||
/// <returns></returns>
|
||||
public T GetFirst(string parm)
|
||||
{
|
||||
return Db.Queryable<T>().Where(parm).First();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 根据条件查询分页数据
|
||||
/// </summary>
|
||||
/// <param name="where"></param>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
public PagedInfo<T> GetPages(Expression<Func<T, bool>> where, PagerInfo parm)
|
||||
{
|
||||
var source = Db.Queryable<T>().Where(where);
|
||||
|
||||
return source.ToPage(parm);
|
||||
}
|
||||
|
||||
public PagedInfo<T> GetPages(Expression<Func<T, bool>> where, PagerInfo parm, Expression<Func<T, object>> order, string orderEnum = "Asc")
|
||||
{
|
||||
var source = Db.Queryable<T>().Where(where).OrderByIF(orderEnum == "Asc", order, OrderByType.Asc).OrderByIF(orderEnum == "Desc", order, OrderByType.Desc);
|
||||
|
||||
return source.ToPage(parm);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据条件查询数据
|
||||
/// </summary>
|
||||
/// <param name="where">条件表达式树</param>
|
||||
/// <returns></returns>
|
||||
public List<T> GetWhere(Expression<Func<T, bool>> where, bool useCache = false, int cacheSecond = 3600)
|
||||
{
|
||||
var query = Db.Queryable<T>().Where(where).WithCacheIF(useCache, cacheSecond);
|
||||
return query.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据条件查询数据
|
||||
/// </summary>
|
||||
/// <param name="where">条件表达式树</param>
|
||||
/// <returns></returns>
|
||||
public List<T> GetWhere(Expression<Func<T, bool>> where, Expression<Func<T, object>> order, string orderEnum = "Asc", bool useCache = false, int cacheSecond = 3600)
|
||||
{
|
||||
var query = Db.Queryable<T>().Where(where).OrderByIF(orderEnum == "Asc", order, OrderByType.Asc).OrderByIF(orderEnum == "Desc", order, OrderByType.Desc).WithCacheIF(useCache, cacheSecond);
|
||||
return query.ToList();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 修改操作
|
||||
|
||||
/// <summary>
|
||||
/// 修改一条数据
|
||||
/// </summary>
|
||||
/// <param name="parm">T</param>
|
||||
/// <returns></returns>
|
||||
public int Update(T parm)
|
||||
{
|
||||
return Db.Updateable(parm).RemoveDataCache().ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量修改
|
||||
/// </summary>
|
||||
/// <param name="parm">T</param>
|
||||
/// <returns></returns>
|
||||
public int Update(List<T> parm)
|
||||
{
|
||||
return Db.Updateable(parm).RemoveDataCache().ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 按查询条件更新
|
||||
/// </summary>
|
||||
/// <param name="where"></param>
|
||||
/// <param name="columns"></param>
|
||||
/// <returns></returns>
|
||||
public int Update(Expression<Func<T, bool>> where, Expression<Func<T, T>> columns)
|
||||
{
|
||||
return Db.Updateable<T>().SetColumns(columns).Where(where).RemoveDataCache().ExecuteCommand();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 删除操作
|
||||
|
||||
/// <summary>
|
||||
/// 删除一条或多条数据
|
||||
/// </summary>
|
||||
/// <param name="parm">string</param>
|
||||
/// <returns></returns>
|
||||
public int Delete(object id)
|
||||
{
|
||||
return Db.Deleteable<T>(id).RemoveDataCache().ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除一条或多条数据
|
||||
/// </summary>
|
||||
/// <param name="parm">string</param>
|
||||
/// <returns></returns>
|
||||
public int Delete(object[] ids)
|
||||
{
|
||||
return Db.Deleteable<T>().In(ids).RemoveDataCache().ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据条件删除一条或多条数据
|
||||
/// </summary>
|
||||
/// <param name="where">过滤条件</param>
|
||||
/// <returns></returns>
|
||||
public int Delete(Expression<Func<T, bool>> where)
|
||||
{
|
||||
return Db.Deleteable<T>().Where(where).RemoveDataCache().ExecuteCommand();
|
||||
}
|
||||
|
||||
public int DeleteTable()
|
||||
{
|
||||
return Db.Deleteable<T>().RemoveDataCache().ExecuteCommand();
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
|
||||
using Infrastructure.Model;
|
||||
using SqlSugar;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.Model;
|
||||
using ZR.Model.Vo;
|
||||
|
||||
namespace ZR.Service
|
||||
{
|
||||
public static class QueryableExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// 读取列表
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="pageIndex"></param>
|
||||
/// <param name="pageSize"></param>
|
||||
/// <returns></returns>
|
||||
//public static async Task<PagedInfo<T>> ToPageAsync<T>(this ISugarQueryable<T> source, PageParm parm)
|
||||
//{
|
||||
// var page = new PagedInfo<T>();
|
||||
// var total = await source.CountAsync();
|
||||
// page.TotalCount = total;
|
||||
// page.TotalPages = total / parm.PageSize;
|
||||
|
||||
// if (total % parm.PageSize > 0)
|
||||
// page.TotalPages++;
|
||||
|
||||
// page.PageSize = parm.PageSize;
|
||||
// page.PageIndex = parm.PageIndex;
|
||||
|
||||
// page.DataSource = await source.OrderByIF(!string.IsNullOrEmpty(parm.Sort), $"{parm.OrderBy} {(parm.Sort == "descending" ? "desc" : "asc")}").ToPageListAsync(parm.PageIndex, parm.PageSize);
|
||||
// return page;
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 读取列表
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="pageIndex"></param>
|
||||
/// <param name="pageSize"></param>
|
||||
/// <returns></returns>
|
||||
public static PagedInfo<T> ToPage<T>(this ISugarQueryable<T> source, PagerInfo parm)
|
||||
{
|
||||
var page = new PagedInfo<T>();
|
||||
var total = source.Count();
|
||||
page.TotalCount = total;
|
||||
//page.TotalPage = total / parm.PageSize;
|
||||
|
||||
//if (total % parm.PageSize > 0)
|
||||
// page.TotalPages++;
|
||||
|
||||
page.PageSize = parm.PageSize;
|
||||
page.PageIndex = parm.PageNum;
|
||||
|
||||
//page.DataSource = source.OrderByIF(!string.IsNullOrEmpty(parm.Sort), $"{parm.OrderBy} {(parm.Sort == "descending" ? "desc" : "asc")}").ToPageList(parm.PageNum, parm.PageSize);
|
||||
page.Result = source.ToPageList(parm.PageNum, parm.PageSize);
|
||||
return page;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
using Infrastructure.Model;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.Model;
|
||||
|
||||
namespace ZR.Service
|
||||
{
|
||||
/// <summary>
|
||||
/// 基础服务定义
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public interface IBaseService<T> where T : class
|
||||
{
|
||||
|
||||
#region 事务
|
||||
|
||||
/// <summary>
|
||||
/// 启用事务
|
||||
/// </summary>
|
||||
void BeginTran();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 提交事务
|
||||
/// </summary>
|
||||
void CommitTran();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 回滚事务
|
||||
/// </summary>
|
||||
void RollbackTran();
|
||||
|
||||
#endregion
|
||||
|
||||
#region 添加操作
|
||||
/// <summary>
|
||||
/// 添加一条数据
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
int Add(T parm);
|
||||
|
||||
/// <summary>
|
||||
/// 批量添加数据
|
||||
/// </summary>
|
||||
/// <param name="parm">List<T></param>
|
||||
/// <returns></returns>
|
||||
int Add(List<T> parm);
|
||||
|
||||
/// <summary>
|
||||
/// 添加或更新数据
|
||||
/// </summary>
|
||||
/// <param name="parm"><T></param>
|
||||
/// <returns></returns>
|
||||
T Saveable(T parm, Expression<Func<T, object>> uClumns = null, Expression<Func<T, object>> iColumns = null);
|
||||
|
||||
/// <summary>
|
||||
/// 批量添加或更新数据
|
||||
/// </summary>
|
||||
/// <param name="parm">List<T></param>
|
||||
/// <returns></returns>
|
||||
List<T> Saveable(List<T> parm, Expression<Func<T, object>> uClumns = null, Expression<Func<T, object>> iColumns = null);
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region 查询操作
|
||||
|
||||
/// <summary>
|
||||
/// 根据条件查询数据是否存在
|
||||
/// </summary>
|
||||
/// <param name="where">条件表达式树</param>
|
||||
/// <returns></returns>
|
||||
bool Any(Expression<Func<T, bool>> where);
|
||||
|
||||
/// <summary>
|
||||
/// 根据条件合计字段
|
||||
/// </summary>
|
||||
/// <param name="where">条件表达式树</param>
|
||||
/// <returns></returns>
|
||||
TResult Sum<TResult>(Expression<Func<T, bool>> where, Expression<Func<T, TResult>> field);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 根据主值查询单条数据
|
||||
/// </summary>
|
||||
/// <param name="pkValue">主键值</param>
|
||||
/// <returns>泛型实体</returns>
|
||||
T GetId(object pkValue);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 根据主键查询多条数据
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
List<T> GetIn(object[] ids);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 根据条件取条数
|
||||
/// </summary>
|
||||
/// <param name="where">条件表达式树</param>
|
||||
/// <returns></returns>
|
||||
int GetCount(Expression<Func<T, bool>> where);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 查询所有数据(无分页,请慎用)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
List<T> GetAll(bool useCache = false, int cacheSecond = 3600);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获得一条数据
|
||||
/// </summary>
|
||||
/// <param name="where">Expression<Func<T, bool>></param>
|
||||
/// <returns></returns>
|
||||
T GetFirst(Expression<Func<T, bool>> where);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获得一条数据
|
||||
/// </summary>
|
||||
/// <param name="parm">string</param>
|
||||
/// <returns></returns>
|
||||
T GetFirst(string parm);
|
||||
|
||||
/// <summary>
|
||||
/// 根据条件查询分页数据
|
||||
/// </summary>
|
||||
/// <param name="where"></param>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
PagedInfo<T> GetPages(Expression<Func<T, bool>> where, PagerInfo parm);
|
||||
|
||||
/// <summary>
|
||||
/// 根据条件查询分页
|
||||
/// </summary>
|
||||
/// <param name="where"></param>
|
||||
/// <param name="parm"></param>
|
||||
/// <param name="order"></param>
|
||||
/// <param name="orderEnum"></param>
|
||||
/// <returns></returns>
|
||||
PagedInfo<T> GetPages(Expression<Func<T, bool>> where, PagerInfo parm, Expression<Func<T, object>> order, string orderEnum = "Asc");
|
||||
|
||||
/// <summary>
|
||||
/// 根据条件查询数据
|
||||
/// </summary>
|
||||
/// <param name="where">条件表达式树</param>
|
||||
/// <returns></returns>
|
||||
List<T> GetWhere(Expression<Func<T, bool>> where, bool useCache = false, int cacheSecond = 3600);
|
||||
|
||||
/// <summary>
|
||||
/// 根据条件查询数据
|
||||
/// </summary>
|
||||
/// <param name="where">条件表达式树</param>
|
||||
/// <returns></returns>
|
||||
List<T> GetWhere(Expression<Func<T, bool>> where, Expression<Func<T, object>> order, string orderEnum = "Asc", bool useCache = false, int cacheSecond = 3600);
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region 修改操作
|
||||
|
||||
/// <summary>
|
||||
/// 修改一条数据
|
||||
/// </summary>
|
||||
/// <param name="parm">T</param>
|
||||
/// <returns></returns>
|
||||
int Update(T parm);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 批量修改
|
||||
/// </summary>
|
||||
/// <param name="parm">T</param>
|
||||
/// <returns></returns>
|
||||
int Update(List<T> parm);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 按查询条件更新
|
||||
/// </summary>
|
||||
/// <param name="where"></param>
|
||||
/// <param name="columns"></param>
|
||||
/// <returns></returns>
|
||||
int Update(Expression<Func<T, bool>> where, Expression<Func<T, T>> columns);
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region 删除操作
|
||||
|
||||
/// <summary>
|
||||
/// 删除一条或多条数据
|
||||
/// </summary>
|
||||
/// <param name="parm">string</param>
|
||||
/// <returns></returns>
|
||||
int Delete(object id);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 删除一条或多条数据
|
||||
/// </summary>
|
||||
/// <param name="parm">string</param>
|
||||
/// <returns></returns>
|
||||
int Delete(object[] ids);
|
||||
|
||||
/// <summary>
|
||||
/// 根据条件删除一条或多条数据
|
||||
/// </summary>
|
||||
/// <param name="where">过滤条件</param>
|
||||
/// <returns></returns>
|
||||
int Delete(Expression<Func<T, bool>> where);
|
||||
|
||||
/// <summary>
|
||||
/// 清空表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
int DeleteTable();
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Service.IService
|
||||
{
|
||||
public interface IArticleCategoryService : IBaseService<ArticleCategory>
|
||||
{
|
||||
List<ArticleCategory> BuildCategoryTree(List<ArticleCategory> categories);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
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.Service.IService
|
||||
{
|
||||
public interface IArticleService : IBaseService<Article>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using ZR.Model.System;
|
||||
using ZR.Model.Vo.System;
|
||||
|
||||
namespace ZR.Service.IService
|
||||
{
|
||||
public interface ISysDeptService : IBaseService<SysDept>
|
||||
{
|
||||
public List<SysDept> GetSysDepts(SysDept dept);
|
||||
public string CheckDeptNameUnique(SysDept dept);
|
||||
public int InsertDept(SysDept dept);
|
||||
public int UpdateDept(SysDept dept);
|
||||
public void UpdateDeptChildren(long deptId, string newAncestors, string oldAncestors);
|
||||
public List<SysDept> GetChildrenDepts(List<SysDept> depts, long deptId);
|
||||
public List<SysDept> BuildDeptTree(List<SysDept> depts);
|
||||
public List<TreeSelectVo> BuildDeptTreeSelect(List<SysDept> depts);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Service.IService
|
||||
{
|
||||
public interface ISysDictDataService : IBaseService<SysDictData>
|
||||
{
|
||||
public List<SysDictData> SelectDictDataList(SysDictData dictData);
|
||||
public List<SysDictData> SelectDictDataByType(string dictType);
|
||||
public SysDictData SelectDictDataById(long dictCode);
|
||||
public long InsertDictData(SysDictData dict);
|
||||
public long UpdateDictData(SysDictData dict);
|
||||
public int DeleteDictDataByIds(long[] dictCodes);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Service.IService
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public interface ISysDictService: IBaseService<SysDictType>
|
||||
{
|
||||
public List<SysDictType> SelectDictTypeList(SysDictType dictType);
|
||||
|
||||
/// <summary>
|
||||
/// 根据Id查询
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public SysDictType SelectDictTypeById(long id);
|
||||
|
||||
/// <summary>
|
||||
/// 校验字典类型称是否唯一
|
||||
/// </summary>
|
||||
/// <param name="dictType">字典类型</param>
|
||||
/// <returns></returns>
|
||||
public string CheckDictTypeUnique(SysDictType dictType);
|
||||
|
||||
/// <summary>
|
||||
/// 删除一个
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public int DeleteDictTypeById(long id);
|
||||
|
||||
/// <summary>
|
||||
/// 批量删除字典数据信息
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public int DeleteDictTypeByIds(long[] dictIds);
|
||||
|
||||
/// <summary>
|
||||
/// 插入字典类型
|
||||
/// </summary>
|
||||
/// <param name="sysDictType"></param>
|
||||
/// <returns></returns>
|
||||
public long InsertDictType(SysDictType sysDictType);
|
||||
|
||||
/// <summary>
|
||||
/// 修改字典类型
|
||||
/// </summary>
|
||||
/// <param name="sysDictType"></param>
|
||||
/// <returns></returns>
|
||||
public int UpdateDictType(SysDictType sysDictType);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using Infrastructure.Attribute;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Service.IService
|
||||
{
|
||||
public interface ISysFileService : IBaseService<SysFile>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using ZR.Model;
|
||||
using ZR.Model.Dto.System;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Service.IService
|
||||
{
|
||||
public interface ISysLoginService
|
||||
{
|
||||
public SysUser Login(LoginBodyDto loginBody, SysLogininfor logininfor);
|
||||
|
||||
/// <summary>
|
||||
/// 查询操作日志
|
||||
/// </summary>
|
||||
/// <param name="logininfoDto"></param>
|
||||
/// <param name="pager">分页</param>
|
||||
/// <returns></returns>
|
||||
public List<SysLogininfor> GetLoginLog(SysLogininfor logininfoDto, PagerInfo pager);
|
||||
|
||||
/// <summary>
|
||||
/// 记录登录日志
|
||||
/// </summary>
|
||||
/// <param name="sysLogininfor"></param>
|
||||
/// <returns></returns>
|
||||
public void AddLoginInfo(SysLogininfor sysLogininfor);
|
||||
|
||||
/// <summary>
|
||||
/// 清空登录日志
|
||||
/// </summary>
|
||||
public void TruncateLogininfo();
|
||||
|
||||
/// <summary>
|
||||
/// 删除登录日志
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
public int DeleteLogininforByIds(long[] ids);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using System.Collections.Generic;
|
||||
using ZR.Model.Dto.System;
|
||||
using ZR.Model.System;
|
||||
using ZR.Model.System.Vo;
|
||||
using ZR.Model.Vo.System;
|
||||
|
||||
namespace ZR.Service.IService
|
||||
{
|
||||
public interface ISysMenuService: IBaseService<SysMenu>
|
||||
{
|
||||
public List<SysMenu> SelectMenuList(long userId);
|
||||
|
||||
public List<SysMenu> SelectMenuList(SysMenu menu, long userId);
|
||||
|
||||
public SysMenu GetMenuByMenuId(int menuId);
|
||||
|
||||
public int AddMenu(SysMenu menu);
|
||||
|
||||
public int EditMenu(SysMenu menu);
|
||||
|
||||
public int DeleteMenuById(int menuId);
|
||||
|
||||
public string CheckMenuNameUnique(SysMenu menu);
|
||||
|
||||
public int ChangeSortMenu(MenuDto menuDto);
|
||||
|
||||
public bool HasChildByMenuId(long menuId);
|
||||
|
||||
public List<SysMenu> SelectMenuTreeByUserId(long userId);
|
||||
|
||||
public List<SysMenu> SelectMenuPermsListByUserId(long userId);
|
||||
|
||||
public List<string> SelectMenuPermsByUserId(long userId);
|
||||
|
||||
public bool CheckMenuExistRole(long menuId);
|
||||
|
||||
public List<RouterVo> BuildMenus(List<SysMenu> menus);
|
||||
|
||||
public List<TreeSelectVo> BuildMenuTreeSelect(List<SysMenu> menus);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using System.Collections.Generic;
|
||||
using ZR.Model;
|
||||
using ZR.Model.Dto.System;
|
||||
using ZR.Model.System;
|
||||
using ZR.Service.System;
|
||||
|
||||
namespace ZR.Service.IService
|
||||
{
|
||||
public interface ISysOperLogService : IBaseService<SysOperLog>
|
||||
{
|
||||
public void InsertOperlog(SysOperLog operLog);
|
||||
|
||||
/// <summary>
|
||||
/// 查询系统操作日志集合
|
||||
/// </summary>
|
||||
/// <param name="operLog">操作日志对象</param>
|
||||
/// <param name="pager"></param>
|
||||
/// <returns>操作日志集合</returns>
|
||||
public List<SysOperLog> SelectOperLogList(SysOperLogDto operLog, PagerInfo pager);
|
||||
|
||||
/// <summary>
|
||||
/// 清空操作日志
|
||||
/// </summary>
|
||||
public void CleanOperLog();
|
||||
|
||||
/// <summary>
|
||||
/// 批量删除系统操作日志
|
||||
/// </summary>
|
||||
/// <param name="operIds">需要删除的操作日志ID</param>
|
||||
/// <returns>结果</returns>
|
||||
public int DeleteOperLogByIds(long[] operIds);
|
||||
|
||||
/// <summary>
|
||||
/// 查询操作日志详细
|
||||
/// </summary>
|
||||
/// <param name="operId">操作ID</param>
|
||||
/// <returns>操作日志对象</returns>
|
||||
public SysOperLog SelectOperLogById(long operId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Service.IService
|
||||
{
|
||||
public interface ISysPermissionService
|
||||
{
|
||||
public List<string> GetRolePermission(SysUser user);
|
||||
public List<string> GetMenuPermission(SysUser user);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Service.IService
|
||||
{
|
||||
public interface ISysPostService: IBaseService<SysPost>
|
||||
{
|
||||
string CheckPostNameUnique(SysPost sysPost);
|
||||
string CheckPostCodeUnique(SysPost sysPost);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Service.IService
|
||||
{
|
||||
public interface ISysRoleService: IBaseService<SysRole>
|
||||
{
|
||||
/// <summary>
|
||||
/// 根据条件分页查询角色数据
|
||||
/// </summary>
|
||||
/// <param name="role">角色信息</param>
|
||||
/// <returns>角色数据集合信息</returns>
|
||||
public List<SysRole> SelectRoleList(SysRole role);
|
||||
|
||||
/// <summary>
|
||||
/// 查询所有角色
|
||||
/// </summary>
|
||||
/// <param name="role"></param>
|
||||
/// <returns></returns>
|
||||
public List<SysRole> SelectRoleAll();
|
||||
|
||||
/// <summary>
|
||||
/// 根据用户查询
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public List<SysRole> SelectRolePermissionByUserId(long userId);
|
||||
|
||||
/// <summary>
|
||||
/// 通过角色ID查询角色
|
||||
/// </summary>
|
||||
/// <param name="roleId">角色ID</param>
|
||||
/// <returns>角色对象信息</returns>
|
||||
public SysRole SelectRoleById(long roleId);
|
||||
|
||||
/// <summary>
|
||||
/// 批量删除角色信息
|
||||
/// </summary>
|
||||
/// <param name="roleIds">需要删除的角色ID</param>
|
||||
/// <returns></returns>
|
||||
public int DeleteRoleByRoleId(long[] roleIds);
|
||||
|
||||
/// <summary>
|
||||
/// 更改角色权限状态
|
||||
/// </summary>
|
||||
/// <param name="SysRoleDto"></param>
|
||||
/// <returns></returns>
|
||||
public int UpdateRoleStatus(SysRole roleDto);
|
||||
|
||||
/// <summary>
|
||||
/// 校验角色权限是否唯一
|
||||
/// </summary>
|
||||
/// <param name="sysRole">角色信息</param>
|
||||
/// <returns></returns>
|
||||
public string CheckRoleKeyUnique(SysRole sysRole);
|
||||
|
||||
/// <summary>
|
||||
/// 校验角色是否允许操作
|
||||
/// </summary>
|
||||
/// <param name="role"></param>
|
||||
public void CheckRoleAllowed(SysRole role);
|
||||
|
||||
/// <summary>
|
||||
/// 新增保存角色信息
|
||||
/// </summary>
|
||||
/// <param name="sysRole">角色信息</param>
|
||||
/// <returns></returns>
|
||||
public long InsertRole(SysRole sysRole);
|
||||
|
||||
/// <summary>
|
||||
/// 通过角色ID删除角色和菜单关联
|
||||
/// </summary>
|
||||
/// <param name="roleId">角色ID</param>
|
||||
/// <returns></returns>
|
||||
public int DeleteRoleMenuByRoleId(long roleId);
|
||||
|
||||
#region Service
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 新增角色菜单信息
|
||||
/// </summary>
|
||||
/// <param name="sysRoleDto"></param>
|
||||
/// <returns></returns>
|
||||
public int InsertRoleMenu(SysRole sysRoleDto);
|
||||
|
||||
/// <summary>
|
||||
/// 判断是否是管理员
|
||||
/// </summary>
|
||||
/// <param name="userid"></param>
|
||||
/// <returns></returns>
|
||||
public bool IsAdmin(long userid);
|
||||
|
||||
/// <summary>
|
||||
/// 获取角色菜单id集合
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public List<long> SelectUserRoleMenus(long roleId);
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户角色列表
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public List<SysRole> SelectUserRoleListByUserId(long userId);
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户权限集合
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public List<long> SelectUserRoles(long userId);
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户权限字符串集合
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public List<string> SelectUserRoleKeys(long userId);
|
||||
|
||||
public List<string> SelectUserRoleNames(long userId);
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 修改保存角色信息
|
||||
/// </summary>
|
||||
/// <param name="sysRole">角色信息</param>
|
||||
/// <returns></returns>
|
||||
public int UpdateRole(SysRole sysRole);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Service.IService
|
||||
{
|
||||
public interface ISysTasksLogService : IBaseService<SysTasksLog>
|
||||
{
|
||||
/// <summary>
|
||||
/// 记录任务执行日志
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
//public int AddTaskLog(string jobId);
|
||||
public SysTasksLog AddTaskLog(string jobId, SysTasksLog tasksLog);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Service.IService
|
||||
{
|
||||
public interface ISysTasksQzService: IBaseService<SysTasksQz>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Service.IService
|
||||
{
|
||||
public interface ISysUserPostService: IBaseService<SysUserPost>
|
||||
{
|
||||
public void InsertUserPost(SysUser user);
|
||||
|
||||
public List<long> GetUserPostsByUserId(long userId);
|
||||
|
||||
public string GetPostsStrByUserId(long userId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
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.Service.IService
|
||||
{
|
||||
public interface ISysUserRoleService
|
||||
{
|
||||
public int CountUserRoleByRoleId(long roleId);
|
||||
|
||||
/// <summary>
|
||||
/// 删除用户角色
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public int DeleteUserRoleByUserId(int userId);
|
||||
|
||||
/// <summary>
|
||||
/// 批量删除角色对应用户
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <param name="userIds"></param>
|
||||
/// <returns></returns>
|
||||
public int DeleteRoleUserByUserIds(long roleId, List<long> userIds);
|
||||
|
||||
/// <summary>
|
||||
/// 添加用户角色
|
||||
/// </summary>
|
||||
/// <param name="sysRoleMenus"></param>
|
||||
/// <returns></returns>
|
||||
public int AddUserRole(List<SysUserRole> sysUsers);
|
||||
|
||||
public List<SysUser> GetSysUsersByRoleId(long roleId);
|
||||
|
||||
/// <summary>
|
||||
/// 新增用户角色信息
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
public int InsertUserRole(SysUser user);
|
||||
|
||||
/// <summary>
|
||||
/// 新增加角色用户
|
||||
/// </summary>
|
||||
/// <param name="roleId">角色id</param>
|
||||
/// <param name="userids">用户ids</param>
|
||||
/// <returns></returns>
|
||||
public int InsertRoleUser(RoleUsersCreateDto roleUsersCreateDto);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.Model;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Service.IService
|
||||
{
|
||||
public interface ISysUserService : IBaseService<SysUser>
|
||||
{
|
||||
public List<SysUser> SelectUserList(SysUser user, PagerInfo pager);
|
||||
|
||||
/// <summary>
|
||||
/// 通过用户ID查询用户
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public SysUser SelectUserById(long userId);
|
||||
|
||||
/// <summary>
|
||||
/// 校验用户名称是否唯一
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
public string CheckUserNameUnique(string userName);
|
||||
|
||||
/// <summary>
|
||||
/// 新增保存用户信息
|
||||
/// </summary>
|
||||
/// <param name="sysUser"></param>
|
||||
/// <returns></returns>
|
||||
public long InsertUser(SysUser sysUser);
|
||||
|
||||
/// <summary>
|
||||
/// 修改用户信息
|
||||
/// </summary>
|
||||
/// <param name="sysUser"></param>
|
||||
/// <returns></returns>
|
||||
public int UpdateUser(SysUser user);
|
||||
|
||||
public int ChangeUser(SysUser user);
|
||||
|
||||
/// <summary>
|
||||
/// 重置密码
|
||||
/// </summary>
|
||||
/// <param name="userid"></param>
|
||||
/// <param name="password"></param>
|
||||
/// <returns></returns>
|
||||
public int ResetPwd(long userid, string password);
|
||||
|
||||
public int ChangeUserStatus(SysUser user);
|
||||
|
||||
/// <summary>
|
||||
/// 删除用户
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
public int DeleteUser(long userid);
|
||||
|
||||
/// <summary>
|
||||
/// 修改用户头像
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
public int UpdatePhoto(SysUser user);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
using Infrastructure.Attribute;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ZR.Model.System;
|
||||
using ZR.Service.IService;
|
||||
|
||||
namespace ZR.Service.System
|
||||
{
|
||||
/// <summary>
|
||||
/// 文章目录
|
||||
/// </summary>
|
||||
[AppService(ServiceType = typeof(IArticleCategoryService), ServiceLifetime = LifeTime.Transient)]
|
||||
public class ArticleCategoryService : BaseService<ArticleCategory>, IArticleCategoryService
|
||||
{
|
||||
/// <summary>
|
||||
/// 构建前端所需要树结构
|
||||
/// </summary>
|
||||
/// <param name="categories">目录列表</param>
|
||||
/// <returns></returns>
|
||||
public List<ArticleCategory> BuildCategoryTree(List<ArticleCategory> categories)
|
||||
{
|
||||
List<ArticleCategory> returnList = new List<ArticleCategory>();
|
||||
List<int> tempList = categories.Select(f => f.Category_Id).ToList();
|
||||
foreach (var dept in categories)
|
||||
{
|
||||
// 如果是顶级节点, 遍历该父节点的所有子节点
|
||||
if (!tempList.Contains(dept.ParentId))
|
||||
{
|
||||
RecursionFn(categories, dept);
|
||||
returnList.Add(dept);
|
||||
}
|
||||
}
|
||||
|
||||
if (!returnList.Any())
|
||||
{
|
||||
returnList = categories;
|
||||
}
|
||||
return returnList;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 递归列表
|
||||
/// </summary>
|
||||
/// <param name="list"></param>
|
||||
/// <param name="t"></param>
|
||||
private void RecursionFn(List<ArticleCategory> list, ArticleCategory t)
|
||||
{
|
||||
//得到子节点列表
|
||||
List<ArticleCategory> childList = GetChildList(list, t);
|
||||
t.Children = childList;
|
||||
foreach (var item in childList)
|
||||
{
|
||||
if (GetChildList(list, item).Count() > 0)
|
||||
{
|
||||
RecursionFn(list, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 递归获取子菜单
|
||||
/// </summary>
|
||||
/// <param name="list">所有菜单</param>
|
||||
/// <param name="dept"></param>
|
||||
/// <returns></returns>
|
||||
private List<ArticleCategory> GetChildList(List<ArticleCategory> list, ArticleCategory t)
|
||||
{
|
||||
return list.Where(p => p.ParentId == t.Category_Id).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using Infrastructure.Attribute;
|
||||
using ZR.Model.System;
|
||||
using ZR.Service.IService;
|
||||
|
||||
namespace ZR.Service.System
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[AppService(ServiceType = typeof(IArticleService), ServiceLifetime = LifeTime.Transient)]
|
||||
public class ArticleService : BaseService<Article>, IArticleService
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
using Infrastructure;
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Extensions;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using ZR.Common;
|
||||
using ZR.Model.System;
|
||||
using ZR.Model.Vo.System;
|
||||
using ZR.Repository.System;
|
||||
using ZR.Service.IService;
|
||||
|
||||
namespace ZR.Service.System
|
||||
{
|
||||
/// <summary>
|
||||
/// 部门管理
|
||||
/// </summary>
|
||||
[AppService(ServiceType = typeof(ISysDeptService), ServiceLifetime = LifeTime.Transient)]
|
||||
public class SysDeptService : BaseService<SysDept>, ISysDeptService
|
||||
{
|
||||
public SysDeptRepository DeptRepository;
|
||||
|
||||
public SysDeptService(SysDeptRepository deptRepository)
|
||||
{
|
||||
DeptRepository = deptRepository;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询部门管理数据
|
||||
/// </summary>
|
||||
/// <param name="dept"></param>
|
||||
/// <returns></returns>
|
||||
public List<SysDept> GetSysDepts(SysDept dept)
|
||||
{
|
||||
//开始拼装查询条件
|
||||
var predicate = Expressionable.Create<SysDept>();
|
||||
predicate = predicate.And(it => it.DelFlag == "0");
|
||||
predicate = predicate.AndIF(dept.DeptName.IfNotEmpty(), it => it.DeptName.Contains(dept.DeptName));
|
||||
predicate = predicate.AndIF(dept.Status.IfNotEmpty(), it => it.Status == dept.Status);
|
||||
|
||||
var response = GetWhere(predicate.ToExpression());
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 校验部门名称是否唯一
|
||||
/// </summary>
|
||||
/// <param name="dept"></param>
|
||||
/// <returns></returns>
|
||||
public string CheckDeptNameUnique(SysDept dept)
|
||||
{
|
||||
long deptId = dept.DeptId == 0 ? -1L : dept.DeptId;
|
||||
SysDept info = GetFirst(it => it.DeptName == dept.DeptName && it.ParentId == dept.ParentId);
|
||||
if (info != null && info.DeptId != deptId)
|
||||
{
|
||||
return UserConstants.NOT_UNIQUE;
|
||||
}
|
||||
return UserConstants.UNIQUE;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增保存部门信息
|
||||
/// </summary>
|
||||
/// <param name="dept"></param>
|
||||
/// <returns></returns>
|
||||
public int InsertDept(SysDept dept)
|
||||
{
|
||||
SysDept info = GetFirst(it => it.DeptId == dept.ParentId);
|
||||
//如果父节点不为正常状态,则不允许新增子节点
|
||||
if (!UserConstants.DEPT_NORMAL.Equals(info.Status))
|
||||
{
|
||||
throw new CustomException("部门停用,不允许新增");
|
||||
}
|
||||
|
||||
dept.Ancestors = info.Ancestors + "," + dept.ParentId;
|
||||
return Add(dept);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改保存部门信息
|
||||
/// </summary>
|
||||
/// <param name="dept"></param>
|
||||
/// <returns></returns>
|
||||
public int UpdateDept(SysDept dept)
|
||||
{
|
||||
SysDept newParentDept = GetFirst(it => it.ParentId == dept.ParentId);
|
||||
SysDept oldDept = GetFirst(m => m.DeptId == dept.DeptId);
|
||||
if (newParentDept != null && oldDept != null)
|
||||
{
|
||||
string newAncestors = newParentDept.Ancestors + "," + newParentDept.DeptId;
|
||||
string oldAncestors = oldDept.Ancestors;
|
||||
dept.Ancestors = newAncestors;
|
||||
UpdateDeptChildren(dept.DeptId, newAncestors, oldAncestors);
|
||||
}
|
||||
int result = Update(dept);
|
||||
if (UserConstants.DEPT_NORMAL.Equals(dept.Status))
|
||||
{
|
||||
// 如果该部门是启用状态,则启用该部门的所有上级部门
|
||||
//UpdateParentDeptStatus(dept);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改该部门的父级部门状态
|
||||
/// </summary>
|
||||
/// <param name="dept">当前部门</param>
|
||||
private void UpdateParentDeptStatus(SysDept dept)
|
||||
{
|
||||
string updateBy = dept.Update_by;
|
||||
dept = GetFirst(it => it.DeptId == dept.DeptId);
|
||||
dept.Update_by = updateBy;
|
||||
//DeptRepository.UpdateParentDeptStatus(dept);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改子元素关系
|
||||
/// </summary>
|
||||
/// <param name="deptId">被修改的部门ID</param>
|
||||
/// <param name="newAncestors">新的父ID集合</param>
|
||||
/// <param name="oldAncestors">旧的父ID集合</param>
|
||||
public void UpdateDeptChildren(long deptId, string newAncestors, string oldAncestors)
|
||||
{
|
||||
List<SysDept> children = GetChildrenDepts(GetSysDepts(new SysDept()), deptId);
|
||||
|
||||
foreach (var child in children)
|
||||
{
|
||||
child.Ancestors = child.Ancestors.Replace(oldAncestors, newAncestors);
|
||||
|
||||
if (child.DeptId.Equals(deptId))
|
||||
{
|
||||
DeptRepository.UdateDeptChildren(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<SysDept> GetChildrenDepts(List<SysDept> depts, long deptId)
|
||||
{
|
||||
return depts.FindAll(delegate (SysDept item)
|
||||
{
|
||||
long[] pid = Tools.SpitLongArrary(item.Ancestors);
|
||||
return pid.Contains(deptId);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 构建前端所需要树结构
|
||||
/// </summary>
|
||||
/// <param name="depts">部门列表</param>
|
||||
/// <returns></returns>
|
||||
public List<SysDept> BuildDeptTree(List<SysDept> depts)
|
||||
{
|
||||
List<SysDept> returnList = new List<SysDept>();
|
||||
List<long> tempList = depts.Select(f => f.DeptId).ToList();
|
||||
foreach (var dept in depts)
|
||||
{
|
||||
// 如果是顶级节点, 遍历该父节点的所有子节点
|
||||
if (!tempList.Contains(dept.ParentId))
|
||||
{
|
||||
RecursionFn(depts, dept);
|
||||
returnList.Add(dept);
|
||||
}
|
||||
}
|
||||
|
||||
if (!returnList.Any())
|
||||
{
|
||||
returnList = depts;
|
||||
}
|
||||
return returnList;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 构建前端所需下拉树结构
|
||||
/// </summary>
|
||||
/// <param name="depts"></param>
|
||||
/// <returns></returns>
|
||||
public List<TreeSelectVo> BuildDeptTreeSelect(List<SysDept> depts)
|
||||
{
|
||||
List<SysDept> menuTrees = BuildDeptTree(depts);
|
||||
List<TreeSelectVo> treeMenuVos = new List<TreeSelectVo>();
|
||||
foreach (var item in menuTrees)
|
||||
{
|
||||
treeMenuVos.Add(new TreeSelectVo(item));
|
||||
}
|
||||
return treeMenuVos;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 递归列表
|
||||
/// </summary>
|
||||
/// <param name="list"></param>
|
||||
/// <param name="t"></param>
|
||||
private void RecursionFn(List<SysDept> list, SysDept t)
|
||||
{
|
||||
//得到子节点列表
|
||||
List<SysDept> childList = GetChildList(list, t);
|
||||
t.children = childList;
|
||||
foreach (var item in childList)
|
||||
{
|
||||
if (GetChildList(list, item).Count() > 0)
|
||||
{
|
||||
RecursionFn(list, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 递归获取子菜单
|
||||
/// </summary>
|
||||
/// <param name="list">所有菜单</param>
|
||||
/// <param name="dept"></param>
|
||||
/// <returns></returns>
|
||||
private List<SysDept> GetChildList(List<SysDept> list, SysDept dept)
|
||||
{
|
||||
return list.Where(p => p.ParentId == dept.DeptId).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
using Infrastructure.Attribute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using ZR.Common;
|
||||
using ZR.Model.System;
|
||||
using ZR.Repository.System;
|
||||
using ZR.Service.IService;
|
||||
|
||||
namespace ZR.Service.System
|
||||
{
|
||||
[AppService(ServiceType = typeof(ISysDictDataService), ServiceLifetime = LifeTime.Transient)]
|
||||
public class SysDictDataService: BaseService<SysDictData>, ISysDictDataService
|
||||
{
|
||||
|
||||
private readonly SysDictDataRepository SysDictDataRepository;
|
||||
public SysDictDataService(SysDictDataRepository sysDictDataRepository)
|
||||
{
|
||||
SysDictDataRepository = sysDictDataRepository;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询字典数据
|
||||
/// </summary>
|
||||
/// <param name="dictData"></param>
|
||||
/// <returns></returns>
|
||||
public List<SysDictData> SelectDictDataList(SysDictData dictData)
|
||||
{
|
||||
return SysDictDataRepository.SelectDictDataList(dictData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据字典类型查询
|
||||
/// </summary>
|
||||
/// <param name="dictData"></param>
|
||||
/// <returns></returns>
|
||||
public List<SysDictData> SelectDictDataByType(string dictType)
|
||||
{
|
||||
string CK = $"SelectDictDataByType_{dictType}";
|
||||
if (!(CacheHelper.GetCache(CK) is List<SysDictData> list))
|
||||
{
|
||||
list = SysDictDataRepository.SelectDictDataByType(dictType);
|
||||
CacheHelper.SetCache(CK, list, 30);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据字典数据ID查询信息
|
||||
/// </summary>
|
||||
/// <param name="dictCode"></param>
|
||||
/// <returns></returns>
|
||||
public SysDictData SelectDictDataById(long dictCode)
|
||||
{
|
||||
string CK = $"SelectDictDataByCode_{dictCode}";
|
||||
if (!(CacheHelper.GetCache(CK) is SysDictData list))
|
||||
{
|
||||
list = SysDictDataRepository.SelectDictDataById(dictCode);
|
||||
CacheHelper.SetCache(CK, list, 5);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 插入数据
|
||||
/// </summary>
|
||||
/// <param name="dict"></param>
|
||||
/// <returns></returns>
|
||||
public long InsertDictData(SysDictData dict)
|
||||
{
|
||||
return SysDictDataRepository.InsertDictData(dict);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改数据
|
||||
/// </summary>
|
||||
/// <param name="dict"></param>
|
||||
/// <returns></returns>
|
||||
public long UpdateDictData(SysDictData dict)
|
||||
{
|
||||
return SysDictDataRepository.UpdateDictData(dict);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量删除字典数据信息
|
||||
/// </summary>
|
||||
/// <param name="dictCodes"></param>
|
||||
/// <returns></returns>
|
||||
public int DeleteDictDataByIds(long[] dictCodes)
|
||||
{
|
||||
return SysDictDataRepository.DeleteDictDataByIds(dictCodes);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
using Infrastructure;
|
||||
using Infrastructure.Attribute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using ZR.Model.System;
|
||||
using ZR.Repository.System;
|
||||
using ZR.Service.IService;
|
||||
|
||||
namespace ZR.Service.System
|
||||
{
|
||||
/// <summary>
|
||||
/// 字典类型
|
||||
/// </summary>
|
||||
[AppService(ServiceType = typeof(ISysDictService), ServiceLifetime = LifeTime.Transient)]
|
||||
public class SysDictService : BaseService<SysDictType>, ISysDictService
|
||||
{
|
||||
private SysDictRepository sysDictRepository;
|
||||
private SysDictDataRepository DictDataRepository;
|
||||
|
||||
public SysDictService(SysDictRepository sysDictRepository, SysDictDataRepository dictDataRepository)
|
||||
{
|
||||
this.sysDictRepository = sysDictRepository;
|
||||
this.DictDataRepository = dictDataRepository;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询字段类型列表
|
||||
/// </summary>
|
||||
/// <param name="dictType">实体模型</param>
|
||||
/// <returns></returns>
|
||||
public List<SysDictType> SelectDictTypeList(SysDictType dictType)
|
||||
{
|
||||
return sysDictRepository.SelectDictTypeList(dictType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据Id查询
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public SysDictType SelectDictTypeById(long id)
|
||||
{
|
||||
return sysDictRepository.SelectDictTypeById(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 校验字典类型称是否唯一
|
||||
/// </summary>
|
||||
/// <param name="dictType">字典类型</param>
|
||||
/// <returns></returns>
|
||||
public string CheckDictTypeUnique(SysDictType dictType)
|
||||
{
|
||||
SysDictType sysDictType = sysDictRepository.CheckDictTypeUnique(dictType.DictType);
|
||||
if (sysDictType != null && sysDictType.DictId != dictType.DictId)
|
||||
{
|
||||
return UserConstants.NOT_UNIQUE;
|
||||
}
|
||||
return UserConstants.UNIQUE;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除一个
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public int DeleteDictTypeById(long id)
|
||||
{
|
||||
return sysDictRepository.DeleteDictTypeById(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量删除字典数据信息
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public int DeleteDictTypeByIds(long[] dictIds)
|
||||
{
|
||||
foreach (var dictId in dictIds)
|
||||
{
|
||||
SysDictType dictType = SelectDictTypeById(dictId);
|
||||
if (DictDataRepository.CountDictDataByType(dictType.DictType) > 0)
|
||||
{
|
||||
throw new CustomException($"{dictType.DictName}已分配,不能删除");
|
||||
}
|
||||
}
|
||||
int count = sysDictRepository.DeleteDictTypeByIds(dictIds);
|
||||
//if (count > 0)
|
||||
//{
|
||||
// DictUtils.clearDictCache();
|
||||
//}
|
||||
return count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 插入字典类型
|
||||
/// </summary>
|
||||
/// <param name="sysDictType"></param>
|
||||
/// <returns></returns>
|
||||
public long InsertDictType(SysDictType sysDictType)
|
||||
{
|
||||
return sysDictRepository.InsertDictType(sysDictType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改字典类型
|
||||
/// </summary>
|
||||
/// <param name="sysDictType"></param>
|
||||
/// <returns></returns>
|
||||
public int UpdateDictType(SysDictType sysDictType)
|
||||
{
|
||||
SysDictType oldDict = sysDictRepository.SelectDictTypeById(sysDictType.DictId);
|
||||
if (sysDictType.DictType != oldDict.DictType)
|
||||
{
|
||||
//同步修改 dict_data表里面的DictType值
|
||||
DictDataRepository.UpdateDictDataType(oldDict.DictType, sysDictType.DictType);
|
||||
}
|
||||
return sysDictRepository.UpdateDictType(sysDictType);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using Infrastructure.Attribute;
|
||||
using ZR.Model.System;
|
||||
using ZR.Service.IService;
|
||||
|
||||
namespace ZR.Service.System
|
||||
{
|
||||
/// <summary>
|
||||
/// 文件管理
|
||||
/// </summary>
|
||||
[AppService(ServiceType = typeof(ISysFileService), ServiceLifetime = LifeTime.Transient)]
|
||||
public class SysFileService: BaseService<SysFile>, ISysFileService
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
using Infrastructure;
|
||||
using Infrastructure.Attribute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ZR.Common;
|
||||
using ZR.Model;
|
||||
using ZR.Model.Dto.System;
|
||||
using ZR.Model.System;
|
||||
using ZR.Repository.System;
|
||||
using ZR.Service.IService;
|
||||
|
||||
namespace ZR.Service.System
|
||||
{
|
||||
/// <summary>
|
||||
/// 登录
|
||||
/// </summary>
|
||||
[AppService(ServiceType = typeof(ISysLoginService), ServiceLifetime = LifeTime.Transient)]
|
||||
public class SysLoginService: ISysLoginService
|
||||
{
|
||||
private SysLogininfoRepository SysLogininfoRepository;
|
||||
|
||||
public SysLoginService(SysLogininfoRepository sysLogininfo)
|
||||
{
|
||||
SysLogininfoRepository = sysLogininfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 登录验证
|
||||
/// </summary>
|
||||
/// <param name="loginBody"></param>
|
||||
/// <returns></returns>
|
||||
public SysUser Login(LoginBodyDto loginBody, SysLogininfor logininfor)
|
||||
{
|
||||
//密码md5
|
||||
loginBody.Password = NETCore.Encrypt.EncryptProvider.Md5(loginBody.Password);
|
||||
|
||||
SysUser user = SysLogininfoRepository.Login(loginBody);
|
||||
logininfor.userName = loginBody.Username;
|
||||
logininfor.status = "1";
|
||||
logininfor.loginTime = DateTime.Now;
|
||||
|
||||
if (user == null || user.UserId <= 0)
|
||||
{
|
||||
logininfor.msg = "用户名或密码错误";
|
||||
AddLoginInfo(logininfor);
|
||||
throw new CustomException(ResultCode.LOGIN_ERROR ,logininfor.msg);
|
||||
}
|
||||
if (user.Status == "1")
|
||||
{
|
||||
logininfor.msg = "该用户已禁用";
|
||||
AddLoginInfo(logininfor);
|
||||
throw new CustomException(ResultCode.LOGIN_ERROR, logininfor.msg);
|
||||
}
|
||||
|
||||
logininfor.status = "0";
|
||||
logininfor.msg = "登录成功";
|
||||
AddLoginInfo(logininfor);
|
||||
SysLogininfoRepository.UpdateLoginInfo(loginBody, user.UserId);
|
||||
return user;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 查询操作日志
|
||||
/// </summary>
|
||||
/// <param name="logininfoDto"></param>
|
||||
/// <param name="pager">分页</param>
|
||||
/// <returns></returns>
|
||||
public List<SysLogininfor> GetLoginLog(SysLogininfor logininfoDto, PagerInfo pager)
|
||||
{
|
||||
logininfoDto.BeginTime = DateTimeHelper.GetBeginTime(logininfoDto.BeginTime, -1);
|
||||
logininfoDto.EndTime = DateTimeHelper.GetBeginTime(logininfoDto.EndTime, 1);
|
||||
|
||||
var list = SysLogininfoRepository.GetLoginLog(logininfoDto, pager);
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 记录登录日志
|
||||
/// </summary>
|
||||
/// <param name="sysLogininfor"></param>
|
||||
/// <returns></returns>
|
||||
public void AddLoginInfo(SysLogininfor sysLogininfor)
|
||||
{
|
||||
SysLogininfoRepository.AddLoginInfo(sysLogininfor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空登录日志
|
||||
/// </summary>
|
||||
public void TruncateLogininfo()
|
||||
{
|
||||
SysLogininfoRepository.TruncateLogininfo();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除登录日志
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
public int DeleteLogininforByIds(long[] ids)
|
||||
{
|
||||
return SysLogininfoRepository.DeleteLogininforByIds(ids);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,418 @@
|
||||
using Infrastructure.Attribute;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ZR.Model.Dto.System;
|
||||
using ZR.Model.System;
|
||||
using ZR.Model.System.Vo;
|
||||
using ZR.Model.Vo;
|
||||
using ZR.Model.Vo.System;
|
||||
using ZR.Repository.System;
|
||||
using ZR.Service.IService;
|
||||
|
||||
namespace ZR.Service
|
||||
{
|
||||
/// <summary>
|
||||
/// 菜单
|
||||
/// </summary>
|
||||
[AppService(ServiceType = typeof(ISysMenuService), ServiceLifetime = LifeTime.Transient)]
|
||||
public class SysMenuService: BaseService<SysMenu>, ISysMenuService
|
||||
{
|
||||
public SysMenuRepository MenuRepository;
|
||||
public ISysRoleService SysRoleService;
|
||||
|
||||
public SysMenuService(
|
||||
SysMenuRepository menuRepository,
|
||||
ISysRoleService sysRoleService)
|
||||
{
|
||||
MenuRepository = menuRepository;
|
||||
SysRoleService = sysRoleService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据用户查询系统菜单列表
|
||||
/// </summary>
|
||||
/// <param name="menu"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public List<SysMenu> SelectMenuList(long userId)
|
||||
{
|
||||
return SelectMenuList(new SysMenu(), userId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有菜单(菜单管理)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<SysMenu> SelectMenuList(SysMenu menu, long userId)
|
||||
{
|
||||
List<SysMenu> menuList;
|
||||
if (SysUser.IsAdmin(userId))
|
||||
{
|
||||
menuList = MenuRepository.SelectMenuList(menu);
|
||||
}
|
||||
else
|
||||
{
|
||||
menuList = MenuRepository.SelectMenuListByUserId(menu, userId);
|
||||
}
|
||||
return menuList;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取菜单详情
|
||||
/// </summary>
|
||||
/// <param name="menuId"></param>
|
||||
/// <returns></returns>
|
||||
public SysMenu GetMenuByMenuId(int menuId)
|
||||
{
|
||||
return MenuRepository.SelectMenuById(menuId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加菜单
|
||||
/// </summary>
|
||||
/// <param name="menu"></param>
|
||||
/// <returns></returns>
|
||||
public int AddMenu(SysMenu menu)
|
||||
{
|
||||
return MenuRepository.AddMenu(menu);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 编辑菜单
|
||||
/// </summary>
|
||||
/// <param name="menu"></param>
|
||||
/// <returns></returns>
|
||||
public int EditMenu(SysMenu menu)
|
||||
{
|
||||
menu.icon = string.IsNullOrEmpty(menu.icon) ? "" : menu.icon;
|
||||
return MenuRepository.EditMenu(menu);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除菜单管理信息
|
||||
/// </summary>
|
||||
/// <param name="menuId"></param>
|
||||
/// <returns></returns>
|
||||
public int DeleteMenuById(int menuId)
|
||||
{
|
||||
return MenuRepository.DeleteMenuById(menuId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 校验菜单名称是否唯一
|
||||
/// </summary>
|
||||
/// <param name="menu"></param>
|
||||
/// <returns></returns>
|
||||
public string CheckMenuNameUnique(SysMenu menu)
|
||||
{
|
||||
long menuId = menu.menuId == 0 ? -1 : menu.menuId;
|
||||
SysMenu info = MenuRepository.CheckMenuNameUnique(menu);
|
||||
|
||||
//if (info != null && menuId != info.menuId && menu.menuName.Equals(info.menuName))
|
||||
//{
|
||||
// return UserConstants.NOT_UNIQUE;
|
||||
//}
|
||||
if (info != null && info.menuId != menu.menuId)
|
||||
{
|
||||
return UserConstants.NOT_UNIQUE;
|
||||
}
|
||||
return UserConstants.UNIQUE;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 菜单排序
|
||||
/// </summary>
|
||||
/// <param name="menuId"></param>
|
||||
/// <returns></returns>
|
||||
public int ChangeSortMenu(MenuDto menuDto)
|
||||
{
|
||||
return MenuRepository.ChangeSortMenu(menuDto);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否存在菜单子节点
|
||||
/// </summary>
|
||||
/// <param name="menuId"></param>
|
||||
/// <returns></returns>
|
||||
public bool HasChildByMenuId(long menuId)
|
||||
{
|
||||
return MenuRepository.HasChildByMenuId(menuId) > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取左边导航栏菜单树
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public List<SysMenu> SelectMenuTreeByUserId(long userId)
|
||||
{
|
||||
List<SysMenu> menus;
|
||||
if (SysRoleService.IsAdmin(userId))
|
||||
{
|
||||
menus = MenuRepository.SelectMenuTreeAll();
|
||||
}
|
||||
else
|
||||
{
|
||||
List<long> roleIds = SysRoleService.SelectUserRoles(userId);
|
||||
menus = MenuRepository.SelectMenuTreeByRoleIds(roleIds);
|
||||
}
|
||||
return GetChildPerms(menus, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询菜单权限
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public List<SysMenu> SelectMenuPermsListByUserId(long userId)
|
||||
{
|
||||
return MenuRepository.SelectMenuPermsByUserId(userId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询精确到按钮的操作权限
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public List<string> SelectMenuPermsByUserId(long userId)
|
||||
{
|
||||
var menuList = SelectMenuPermsListByUserId(userId).Where(f => !string.IsNullOrEmpty(f.perms));
|
||||
|
||||
return menuList.Select(x => x.perms).Distinct().ToList();
|
||||
}
|
||||
|
||||
#region RoleMenu
|
||||
|
||||
/// <summary>
|
||||
/// 查询菜单使用数量
|
||||
/// </summary>
|
||||
/// <param name="menuId"></param>
|
||||
/// <returns></returns>
|
||||
public bool CheckMenuExistRole(long menuId)
|
||||
{
|
||||
return MenuRepository.CheckMenuExistRole(menuId) > 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 方法
|
||||
|
||||
/// <summary>
|
||||
/// 根据父节点的ID获取所有子节点
|
||||
/// </summary>
|
||||
/// <param name="list">分类表</param>
|
||||
/// <param name="parentId">传入的父节点ID</param>
|
||||
/// <returns></returns>
|
||||
public List<SysMenu> GetChildPerms(List<SysMenu> list, int parentId)
|
||||
{
|
||||
List<SysMenu> returnList = new List<SysMenu>();
|
||||
var data = list.FindAll(f => f.parentId == parentId);
|
||||
|
||||
foreach (var item in data)
|
||||
{
|
||||
RecursionFn(list, item);
|
||||
|
||||
returnList.Add(item);
|
||||
}
|
||||
return returnList;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 递归列表
|
||||
/// </summary>
|
||||
/// <param name="list"></param>
|
||||
/// <param name="t"></param>
|
||||
private void RecursionFn(List<SysMenu> list, SysMenu t)
|
||||
{
|
||||
//得到子节点列表
|
||||
List<SysMenu> childList = GetChildList(list, t);
|
||||
t.children = childList;
|
||||
foreach (var item in childList)
|
||||
{
|
||||
if (GetChildList(list, item).Count() > 0)
|
||||
{
|
||||
RecursionFn(list, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 递归获取子菜单
|
||||
/// </summary>
|
||||
/// <param name="list">所有菜单</param>
|
||||
/// <param name="sysMenu"></param>
|
||||
/// <returns></returns>
|
||||
private List<SysMenu> GetChildList(List<SysMenu> list, SysMenu sysMenu)
|
||||
{
|
||||
return list.Where(p => p.parentId == sysMenu.menuId).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取路由侧边栏,动态生成
|
||||
/// </summary>
|
||||
/// <param name="menus"></param>
|
||||
/// <returns></returns>
|
||||
public List<RouterVo> BuildMenus(List<SysMenu> menus)
|
||||
{
|
||||
List<RouterVo> routers = new List<RouterVo>();
|
||||
|
||||
foreach (var menu in menus)
|
||||
{
|
||||
RouterVo router = new RouterVo
|
||||
{
|
||||
Hidden = "1".Equals(menu.visible),
|
||||
Name = GetRouteName(menu),
|
||||
Path = GetRoutePath(menu),
|
||||
Component = GetComponent(menu),
|
||||
Meta = new Meta(menu.menuName, menu.icon, "1".Equals(menu.isCache))
|
||||
};
|
||||
|
||||
List<SysMenu> cMenus = menu.children;
|
||||
//是目录并且有子菜单
|
||||
if (cMenus != null && cMenus.Count > 0 && (UserConstants.TYPE_DIR.Equals(menu.menuType)))
|
||||
{
|
||||
router.AlwaysShow = true;
|
||||
router.Redirect = "noRedirect";
|
||||
router.Children = BuildMenus(cMenus);
|
||||
}
|
||||
else if (IsMeunFrame(menu))
|
||||
{
|
||||
List<RouterVo> childrenList = new List<RouterVo>();
|
||||
RouterVo children = new RouterVo
|
||||
{
|
||||
Path = menu.path,
|
||||
Component = menu.component,
|
||||
Name = string.IsNullOrEmpty(menu.path) ? "" : menu.path.ToLower(),
|
||||
Meta = new Meta(menu.menuName, menu.icon, "1".Equals(menu.isCache))
|
||||
};
|
||||
childrenList.Add(children);
|
||||
router.Children = childrenList;
|
||||
}
|
||||
routers.Add(router);
|
||||
}
|
||||
|
||||
return routers;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 构建前端所需要下拉树结构
|
||||
/// </summary>
|
||||
/// <param name="menus">菜单列表</param>
|
||||
/// <returns>下拉树结构列表</returns>
|
||||
public List<SysMenu> BuildMenuTree(List<SysMenu> menus)
|
||||
{
|
||||
List<SysMenu> returnList = new List<SysMenu>();
|
||||
List<long> tempList = menus.Select(f => f.menuId).ToList();
|
||||
|
||||
foreach (var menu in menus)
|
||||
{
|
||||
// 如果是顶级节点, 遍历该父节点的所有子节点
|
||||
if (!tempList.Contains(menu.parentId))
|
||||
{
|
||||
RecursionFn(menus, menu);
|
||||
returnList.Add(menu);
|
||||
}
|
||||
}
|
||||
if (!returnList.Any())
|
||||
{
|
||||
returnList = menus;
|
||||
}
|
||||
return returnList;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 构建前端所需要下拉树结构
|
||||
/// </summary>
|
||||
/// <param name="menus"></param>
|
||||
/// <returns></returns>
|
||||
public List<TreeSelectVo> BuildMenuTreeSelect(List<SysMenu> menus)
|
||||
{
|
||||
List<SysMenu> menuTrees = BuildMenuTree(menus);
|
||||
List<TreeSelectVo> treeMenuVos = new List<TreeSelectVo>();
|
||||
foreach (var item in menuTrees)
|
||||
{
|
||||
treeMenuVos.Add(new TreeSelectVo(item));
|
||||
}
|
||||
return treeMenuVos;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取路由名称
|
||||
/// </summary>
|
||||
/// <param name="menu">菜单信息</param>
|
||||
/// <returns>路由名称</returns>
|
||||
public string GetRouteName(SysMenu menu)
|
||||
{
|
||||
string routerName = menu.path.ToLower();
|
||||
// 非外链并且是一级目录(类型为目录)
|
||||
if (IsMeunFrame(menu))
|
||||
{
|
||||
routerName = string.Empty;
|
||||
}
|
||||
return routerName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取路由路径
|
||||
/// </summary>
|
||||
/// <param name="menu">菜单信息</param>
|
||||
/// <returns>路由地址</returns>
|
||||
public string GetRoutePath(SysMenu menu)
|
||||
{
|
||||
string routePath = menu.path;
|
||||
// 非外链并且是一级目录(类型为目录)
|
||||
if (0 == menu.parentId && UserConstants.TYPE_DIR.Equals(menu.menuType) && UserConstants.NO_FRAME.Equals(menu.isFrame))
|
||||
{
|
||||
routePath = "/" + menu.path;
|
||||
}
|
||||
else if (IsMeunFrame(menu))// 非外链并且是一级目录(类型为菜单)
|
||||
{
|
||||
routePath = "/";
|
||||
}
|
||||
return routePath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取组件名称
|
||||
/// </summary>
|
||||
/// <param name="menu"></param>
|
||||
/// <returns></returns>
|
||||
public string GetComponent(SysMenu menu)
|
||||
{
|
||||
string component = UserConstants.LAYOUT;
|
||||
if (!string.IsNullOrEmpty(menu.component) && !IsMeunFrame(menu))
|
||||
{
|
||||
component = menu.component;
|
||||
}
|
||||
else if (string.IsNullOrEmpty(menu.component) && IsParentView(menu))
|
||||
{
|
||||
component = UserConstants.PARENT_VIEW;
|
||||
}
|
||||
return component;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否为菜单内部跳转
|
||||
/// </summary>
|
||||
/// <param name="menu">菜单信息</param>
|
||||
/// <returns></returns>
|
||||
public bool IsMeunFrame(SysMenu menu)
|
||||
{
|
||||
return menu.parentId == 0 && UserConstants.TYPE_MENU.Equals(menu.menuType) && menu.isFrame.Equals(UserConstants.NO_FRAME);
|
||||
}
|
||||
|
||||
///
|
||||
/// <summary>
|
||||
/// 是否为parent_view组件
|
||||
/// </summary>
|
||||
/// <param name="menu">菜单信息</param>
|
||||
/// <returns></returns>
|
||||
public bool IsParentView(SysMenu menu)
|
||||
{
|
||||
return menu.parentId != 0 && UserConstants.TYPE_DIR.Equals(menu.menuType);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
using Infrastructure.Attribute;
|
||||
using System.Collections.Generic;
|
||||
using ZR.Common;
|
||||
using ZR.Model;
|
||||
using ZR.Model.Dto.System;
|
||||
using ZR.Model.System;
|
||||
using ZR.Repository.System;
|
||||
using ZR.Service.IService;
|
||||
|
||||
namespace ZR.Service.System
|
||||
{
|
||||
/// <summary>
|
||||
/// 操作日志
|
||||
/// </summary>
|
||||
[AppService(ServiceType = typeof(ISysOperLogService), ServiceLifetime = LifeTime.Transient)]
|
||||
public class SysOperLogService: BaseService<SysOperLog>, ISysOperLogService
|
||||
{
|
||||
public SysOperLogRepository sysOperLogRepository;
|
||||
|
||||
public SysOperLogService(SysOperLogRepository sysOperLog)
|
||||
{
|
||||
sysOperLogRepository = sysOperLog;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增操作日志操作
|
||||
/// </summary>
|
||||
/// <param name="operLog">日志对象</param>
|
||||
public void InsertOperlog(SysOperLog operLog)
|
||||
{
|
||||
sysOperLogRepository.AddSysOperLog(operLog);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询系统操作日志集合
|
||||
/// </summary>
|
||||
/// <param name="operLog">操作日志对象</param>
|
||||
/// <param name="pager"></param>
|
||||
/// <returns>操作日志集合</returns>
|
||||
public List<SysOperLog> SelectOperLogList(SysOperLogDto operLog, PagerInfo pager)
|
||||
{
|
||||
operLog.BeginTime = DateTimeHelper.GetBeginTime(operLog.BeginTime, -1);
|
||||
operLog.EndTime = DateTimeHelper.GetBeginTime(operLog.EndTime, 1);
|
||||
|
||||
var list = sysOperLogRepository.GetSysOperLog(operLog, pager);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空操作日志
|
||||
/// </summary>
|
||||
public void CleanOperLog()
|
||||
{
|
||||
sysOperLogRepository.ClearOperLog();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量删除系统操作日志
|
||||
/// </summary>
|
||||
/// <param name="operIds">需要删除的操作日志ID</param>
|
||||
/// <returns>结果</returns>
|
||||
public int DeleteOperLogByIds(long[] operIds)
|
||||
{
|
||||
return sysOperLogRepository.DeleteOperLogByIds(operIds);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询操作日志详细
|
||||
/// </summary>
|
||||
/// <param name="operId">操作ID</param>
|
||||
/// <returns>操作日志对象</returns>
|
||||
public SysOperLog SelectOperLogById(long operId)
|
||||
{
|
||||
return sysOperLogRepository.SelectOperLogById(operId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using Infrastructure;
|
||||
using Infrastructure.Attribute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using ZR.Model.System;
|
||||
using ZR.Service.IService;
|
||||
|
||||
namespace ZR.Service.System
|
||||
{
|
||||
[AppService(ServiceType = typeof(ISysPermissionService), ServiceLifetime = LifeTime.Transient)]
|
||||
public class SysPermissionService : ISysPermissionService
|
||||
{
|
||||
private readonly ISysRoleService SysRoleService;
|
||||
private readonly ISysMenuService SysMenuService;
|
||||
|
||||
public SysPermissionService(
|
||||
ISysRoleService sysRoleService,
|
||||
ISysMenuService sysMenuService)
|
||||
{
|
||||
SysRoleService = sysRoleService;
|
||||
SysMenuService = sysMenuService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取角色数据权限
|
||||
/// </summary>
|
||||
/// <param name="user">用户信息</param>
|
||||
/// <returns>角色权限信息</returns>
|
||||
public List<string> GetRolePermission(SysUser user)
|
||||
{
|
||||
List<string> roles = new List<string>();
|
||||
// 管理员拥有所有权限
|
||||
if (user.IsAdmin())
|
||||
{
|
||||
roles.Add("admin");
|
||||
}
|
||||
else
|
||||
{
|
||||
roles.AddRange(SysRoleService.SelectUserRoleKeys(user.UserId));
|
||||
}
|
||||
return roles;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取菜单数据权限
|
||||
/// </summary>
|
||||
/// <param name="user">用户信息</param>
|
||||
/// <returns>菜单权限信息</returns>
|
||||
public List<string> GetMenuPermission(SysUser user)
|
||||
{
|
||||
List<string> perms = new List<string>();
|
||||
// 管理员拥有所有权限
|
||||
if (user.IsAdmin())
|
||||
{
|
||||
perms.Add(GlobalConstant.AdminPerm);
|
||||
}
|
||||
else
|
||||
{
|
||||
perms.AddRange(SysMenuService.SelectMenuPermsByUserId(user.UserId));
|
||||
}
|
||||
return perms;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
using Infrastructure.Attribute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using ZR.Model.System;
|
||||
using ZR.Service.IService;
|
||||
|
||||
namespace ZR.Service.System
|
||||
{
|
||||
/// <summary>
|
||||
/// 岗位管理
|
||||
/// </summary>
|
||||
[AppService(ServiceType = typeof(ISysPostService), ServiceLifetime = LifeTime.Transient)]
|
||||
public class SysPostService : BaseService<SysPost>, ISysPostService
|
||||
{
|
||||
/// <summary>
|
||||
/// 校验岗位编码是否唯一
|
||||
/// </summary>
|
||||
/// <param name="sysPost"></param>
|
||||
/// <returns></returns>
|
||||
public string CheckPostCodeUnique(SysPost post)
|
||||
{
|
||||
SysPost info = GetFirst(it => it.PostCode.Equals(post.PostCode));
|
||||
if (info != null && info.PostId != post.PostId)
|
||||
{
|
||||
return UserConstants.NOT_UNIQUE;
|
||||
}
|
||||
return UserConstants.UNIQUE;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 校验岗位名称是否唯一
|
||||
/// </summary>
|
||||
/// <param name="sysPost"></param>
|
||||
/// <returns></returns>
|
||||
public string CheckPostNameUnique(SysPost post)
|
||||
{
|
||||
SysPost info = GetFirst(it => it.PostName.Equals(post.PostName));
|
||||
if (info != null && info.PostId != post.PostId)
|
||||
{
|
||||
return UserConstants.NOT_UNIQUE;
|
||||
}
|
||||
return UserConstants.UNIQUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,255 @@
|
||||
using Infrastructure;
|
||||
using Infrastructure.Attribute;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using ZR.Model.System;
|
||||
using ZR.Repository.System;
|
||||
using ZR.Service.IService;
|
||||
using ZR.Service.System;
|
||||
|
||||
namespace ZR.Service
|
||||
{
|
||||
/// <summary>
|
||||
/// 角色
|
||||
/// </summary>
|
||||
[AppService(ServiceType = typeof(ISysRoleService), ServiceLifetime = LifeTime.Transient)]
|
||||
public class SysRoleService: BaseService<SysRole>, ISysRoleService
|
||||
{
|
||||
private SysRoleRepository SysRoleRepository;
|
||||
private ISysUserRoleService SysUserRoleService;
|
||||
|
||||
public SysRoleService(
|
||||
SysRoleRepository sysRoleRepository,
|
||||
ISysUserRoleService sysUserRoleService)
|
||||
{
|
||||
SysRoleRepository = sysRoleRepository;
|
||||
SysUserRoleService = sysUserRoleService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据条件分页查询角色数据
|
||||
/// </summary>
|
||||
/// <param name="role">角色信息</param>
|
||||
/// <returns>角色数据集合信息</returns>
|
||||
public List<SysRole> SelectRoleList(SysRole role)
|
||||
{
|
||||
return SysRoleRepository.SelectRoleList(role);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询所有角色
|
||||
/// </summary>
|
||||
/// <param name="role"></param>
|
||||
/// <returns></returns>
|
||||
public List<SysRole> SelectRoleAll()
|
||||
{
|
||||
return SysRoleRepository.SelectRoleList(new SysRole());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据用户查询
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public List<SysRole> SelectRolePermissionByUserId(long userId)
|
||||
{
|
||||
return SysRoleRepository.SelectRolePermissionByUserId(userId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过角色ID查询角色
|
||||
/// </summary>
|
||||
/// <param name="roleId">角色ID</param>
|
||||
/// <returns>角色对象信息</returns>
|
||||
public SysRole SelectRoleById(long roleId)
|
||||
{
|
||||
return SysRoleRepository.SelectRoleById(roleId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量删除角色信息
|
||||
/// </summary>
|
||||
/// <param name="roleIds">需要删除的角色ID</param>
|
||||
/// <returns></returns>
|
||||
public int DeleteRoleByRoleId(long[] roleIds)
|
||||
{
|
||||
foreach (var item in roleIds)
|
||||
{
|
||||
CheckRoleAllowed(new SysRole(item));
|
||||
SysRole role = SelectRoleById(item);
|
||||
if (SysUserRoleService.CountUserRoleByRoleId(item) > 0)
|
||||
{
|
||||
throw new CustomException($"{role.RoleName}已分配,不能删除");
|
||||
}
|
||||
}
|
||||
return SysRoleRepository.DeleteRoleByRoleIds(roleIds);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更改角色权限状态
|
||||
/// </summary>
|
||||
/// <param name="SysRoleDto"></param>
|
||||
/// <returns></returns>
|
||||
public int UpdateRoleStatus(SysRole roleDto)
|
||||
{
|
||||
return SysRoleRepository.UpdateRoleStatus(roleDto);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 校验角色权限是否唯一
|
||||
/// </summary>
|
||||
/// <param name="sysRole">角色信息</param>
|
||||
/// <returns></returns>
|
||||
public string CheckRoleKeyUnique(SysRole sysRole)
|
||||
{
|
||||
long roleId = 0 == sysRole.RoleId ? -1L : sysRole.RoleId;
|
||||
SysRole info = SysRoleRepository.CheckRoleKeyUnique(sysRole.RoleKey);
|
||||
if (info != null && info.RoleId != roleId)
|
||||
{
|
||||
return UserConstants.NOT_UNIQUE;
|
||||
}
|
||||
return UserConstants.UNIQUE;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 校验角色是否允许操作
|
||||
/// </summary>
|
||||
/// <param name="role"></param>
|
||||
public void CheckRoleAllowed(SysRole role)
|
||||
{
|
||||
if (IsAdmin(role.RoleId))
|
||||
{
|
||||
throw new CustomException("不允许操作超级管理员角色");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增保存角色信息
|
||||
/// </summary>
|
||||
/// <param name="sysRole">角色信息</param>
|
||||
/// <returns></returns>
|
||||
public long InsertRole(SysRole sysRole)
|
||||
{
|
||||
return SysRoleRepository.InsertRole(sysRole);
|
||||
//return InsertRoleMenu(sysRole);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过角色ID删除角色和菜单关联
|
||||
/// </summary>
|
||||
/// <param name="roleId">角色ID</param>
|
||||
/// <returns></returns>
|
||||
public int DeleteRoleMenuByRoleId(long roleId)
|
||||
{
|
||||
return SysRoleRepository.DeleteRoleMenuByRoleId(roleId);
|
||||
}
|
||||
|
||||
#region Service
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 新增角色菜单信息
|
||||
/// </summary>
|
||||
/// <param name="sysRoleDto"></param>
|
||||
/// <returns></returns>
|
||||
public int InsertRoleMenu(SysRole sysRoleDto)
|
||||
{
|
||||
int rows = 1;
|
||||
// 新增用户与角色管理
|
||||
List<SysRoleMenu> sysRoleMenus = new List<SysRoleMenu>();
|
||||
foreach (var item in sysRoleDto.MenuIds)
|
||||
{
|
||||
SysRoleMenu rm = new SysRoleMenu();
|
||||
rm.Menu_id = item;
|
||||
rm.Role_id = sysRoleDto.RoleId;
|
||||
rm.Create_by = sysRoleDto.Create_by;
|
||||
rm.Create_time = DateTime.Now;
|
||||
sysRoleMenus.Add(rm);
|
||||
}
|
||||
//添加角色菜单
|
||||
if (sysRoleMenus.Count > 0)
|
||||
{
|
||||
rows = SysRoleRepository.AddRoleMenu(sysRoleMenus);
|
||||
}
|
||||
|
||||
return rows;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断是否是管理员
|
||||
/// </summary>
|
||||
/// <param name="userid"></param>
|
||||
/// <returns></returns>
|
||||
public bool IsAdmin(long userid)
|
||||
{
|
||||
List<string> roles = SelectUserRoleKeys(userid);
|
||||
|
||||
return ((IList)roles).Contains("admin");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取角色菜单id集合
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public List<long> SelectUserRoleMenus(long roleId)
|
||||
{
|
||||
var list = SysRoleRepository.SelectRoleMenuByRoleId(roleId);
|
||||
|
||||
return list.Select(x => x.Menu_id).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户角色列表
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public List<SysRole> SelectUserRoleListByUserId(long userId)
|
||||
{
|
||||
return SysRoleRepository.SelectUserRoleListByUserId(userId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户权限集合
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public List<long> SelectUserRoles(long userId)
|
||||
{
|
||||
var list = SelectUserRoleListByUserId(userId).Where(f => f.Status == "0");
|
||||
|
||||
return list.Select(x => x.RoleId).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户权限字符串集合
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public List<string> SelectUserRoleKeys(long userId)
|
||||
{
|
||||
var list = SelectUserRoleListByUserId(userId);
|
||||
return list.Select(x => x.RoleKey).ToList();
|
||||
}
|
||||
|
||||
public List<string> SelectUserRoleNames(long userId)
|
||||
{
|
||||
var list = SelectUserRoleListByUserId(userId);
|
||||
return list.Select(x => x.RoleName).ToList();
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 修改保存角色信息
|
||||
/// </summary>
|
||||
/// <param name="sysRole">角色信息</param>
|
||||
/// <returns></returns>
|
||||
public int UpdateRole(SysRole sysRole)
|
||||
{
|
||||
return SysRoleRepository.UpdateSysRole(sysRole);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using Infrastructure.Attribute;
|
||||
using System;
|
||||
using ZR.Model.System;
|
||||
using ZR.Service.IService;
|
||||
|
||||
namespace ZR.Service.System
|
||||
{
|
||||
[AppService(ServiceLifetime = LifeTime.Transient, ServiceType = typeof(ISysTasksLogService))]
|
||||
public class SysTasksLogService : BaseService<SysTasksLog>, ISysTasksLogService
|
||||
{
|
||||
private ISysTasksQzService _tasksQzService;
|
||||
public SysTasksLogService(ISysTasksQzService tasksQzService)
|
||||
{
|
||||
_tasksQzService = tasksQzService;
|
||||
}
|
||||
|
||||
public SysTasksLog AddTaskLog(string jobId, SysTasksLog logModel)
|
||||
{
|
||||
//获取任务信息
|
||||
var model = _tasksQzService.GetId(jobId);
|
||||
|
||||
if (model != null)
|
||||
{
|
||||
logModel.JobId = jobId;
|
||||
logModel.JobName = model.Name;
|
||||
logModel.JobGroup = model.JobGroup;
|
||||
logModel.CreateTime = DateTime.Now;
|
||||
}
|
||||
|
||||
Add(logModel);
|
||||
return logModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using Infrastructure.Attribute;
|
||||
using ZR.Model.System;
|
||||
using ZR.Service.IService;
|
||||
|
||||
namespace ZR.Service.System
|
||||
{
|
||||
[AppService(ServiceType = typeof(ISysTasksQzService), ServiceLifetime = LifeTime.Transient)]
|
||||
public class SysTasksQzService : BaseService<SysTasksQz>, ISysTasksQzService
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
using Infrastructure.Attribute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using ZR.Model.System;
|
||||
using ZR.Repository.System;
|
||||
using ZR.Service.IService;
|
||||
|
||||
namespace ZR.Service.System
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户岗位
|
||||
/// </summary>
|
||||
[AppService(ServiceType = typeof(ISysUserPostService), ServiceLifetime = LifeTime.Transient)]
|
||||
public class SysUserPostService : BaseService<SysUserPost>, ISysUserPostService
|
||||
{
|
||||
public SysUserPostRepository UserPostRepository;
|
||||
|
||||
public SysUserPostService(SysUserPostRepository userPostRepository)
|
||||
{
|
||||
UserPostRepository = userPostRepository;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增用户岗位信息
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
public void InsertUserPost(SysUser user)
|
||||
{
|
||||
// 新增用户与岗位管理
|
||||
List<SysUserPost> list = new List<SysUserPost>();
|
||||
foreach (var item in user.PostIds)
|
||||
{
|
||||
list.Add(new SysUserPost() { PostId = item, UserId = user.UserId });
|
||||
}
|
||||
Add(list);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 查询用户岗位集合
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public List<long> GetUserPostsByUserId(long userId)
|
||||
{
|
||||
var list = GetWhere(f => f.UserId == userId);
|
||||
return list.Select(x => x.PostId).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户岗位
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public string GetPostsStrByUserId(long userId)
|
||||
{
|
||||
var list = UserPostRepository.SelectPostsByUserId(userId);
|
||||
return string.Join(',', list.Select(x => x.PostName));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
using Infrastructure.Attribute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using ZR.Model.Dto.System;
|
||||
using ZR.Model.System;
|
||||
using ZR.Repository.System;
|
||||
using ZR.Service.IService;
|
||||
|
||||
namespace ZR.Service.System
|
||||
{
|
||||
[AppService(ServiceType = typeof(ISysUserRoleService),ServiceLifetime = LifeTime.Transient)]
|
||||
public class SysUserRoleService: ISysUserRoleService
|
||||
{
|
||||
public SysUserRoleRepository SysUserRoleRepository;
|
||||
|
||||
public SysUserRoleService(SysUserRoleRepository sysUserRoleRepository)
|
||||
{
|
||||
SysUserRoleRepository = sysUserRoleRepository;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 通过角色ID查询角色使用数量
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <returns></returns>
|
||||
public int CountUserRoleByRoleId(long roleId)
|
||||
{
|
||||
return SysUserRoleRepository.CountUserRoleByRoleId(roleId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除用户角色
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public int DeleteUserRoleByUserId(int userId)
|
||||
{
|
||||
return SysUserRoleRepository.DeleteUserRoleByUserId(userId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量删除角色对应用户
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <param name="userIds"></param>
|
||||
/// <returns></returns>
|
||||
public int DeleteRoleUserByUserIds(long roleId, List<long> userIds)
|
||||
{
|
||||
return SysUserRoleRepository.DeleteRoleUserByUserIds(roleId, userIds);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加用户角色
|
||||
/// </summary>
|
||||
/// <param name="sysRoleMenus"></param>
|
||||
/// <returns></returns>
|
||||
public int AddUserRole(List<SysUserRole> sysUsers)
|
||||
{
|
||||
return SysUserRoleRepository.AddUserRole(sysUsers);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户数据根据角色id
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <returns></returns>
|
||||
public List<SysUser> GetSysUsersByRoleId(long roleId)
|
||||
{
|
||||
return SysUserRoleRepository.GetSysUsersByRoleId(roleId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增用户角色信息
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
public int InsertUserRole(SysUser user)
|
||||
{
|
||||
List<SysUserRole> userRoles = new List<SysUserRole>();
|
||||
foreach (var item in user.RoleIds)
|
||||
{
|
||||
userRoles.Add(new SysUserRole() { RoleId = item, UserId = user.UserId });
|
||||
}
|
||||
|
||||
return userRoles.Count > 0 ? AddUserRole(userRoles) : 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增加角色用户
|
||||
/// </summary>
|
||||
/// <param name="roleId">角色id</param>
|
||||
/// <param name="userids">用户ids</param>
|
||||
/// <returns></returns>
|
||||
public int InsertRoleUser(RoleUsersCreateDto roleUsersCreateDto)
|
||||
{
|
||||
List<SysUserRole> userRoles = new List<SysUserRole>();
|
||||
foreach (var item in roleUsersCreateDto.UserIds)
|
||||
{
|
||||
userRoles.Add(new SysUserRole() { RoleId = roleUsersCreateDto.RoleId, UserId = item });
|
||||
}
|
||||
|
||||
return userRoles.Count > 0 ? AddUserRole(userRoles) : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
using Infrastructure.Attribute;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using ZR.Model;
|
||||
using ZR.Model.System;
|
||||
using ZR.Repository.System;
|
||||
using ZR.Service.IService;
|
||||
|
||||
namespace ZR.Service
|
||||
{
|
||||
[AppService(ServiceType = typeof(ISysUserService), ServiceLifetime = LifeTime.Transient)]
|
||||
public class SysUserService : BaseService<SysUser>, ISysUserService
|
||||
{
|
||||
private readonly SysUserRepository UserRepository;
|
||||
private readonly ISysRoleService RoleService;
|
||||
private readonly ISysUserRoleService UserRoleService;
|
||||
private readonly ISysUserPostService UserPostService;
|
||||
|
||||
public SysUserService(
|
||||
SysUserRepository userRepository,
|
||||
ISysRoleService sysRoleService,
|
||||
ISysUserRoleService userRoleService,
|
||||
ISysUserPostService userPostService)
|
||||
{
|
||||
UserRepository = userRepository;
|
||||
RoleService = sysRoleService;
|
||||
UserRoleService = userRoleService;
|
||||
UserPostService = userPostService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据条件分页查询用户列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<SysUser> SelectUserList(SysUser user, PagerInfo pager)
|
||||
{
|
||||
var list = UserRepository.SelectUserList(user, pager);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过用户ID查询用户
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public SysUser SelectUserById(long userId)
|
||||
{
|
||||
return UserRepository.SelectUserById(userId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 校验用户名称是否唯一
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
public string CheckUserNameUnique(string userName)
|
||||
{
|
||||
int count = UserRepository.CheckUserNameUnique(userName);
|
||||
if (count > 0)
|
||||
{
|
||||
return UserConstants.NOT_UNIQUE;
|
||||
}
|
||||
return UserConstants.UNIQUE;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增保存用户信息
|
||||
/// </summary>
|
||||
/// <param name="sysUser"></param>
|
||||
/// <returns></returns>
|
||||
public long InsertUser(SysUser sysUser)
|
||||
{
|
||||
long userId = UserRepository.AddUser(sysUser);
|
||||
sysUser.UserId = userId;
|
||||
//新增用户角色信息
|
||||
UserRoleService.InsertUserRole(sysUser);
|
||||
//新增用户岗位信息
|
||||
UserPostService.InsertUserPost(sysUser);
|
||||
return userId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改用户信息
|
||||
/// </summary>
|
||||
/// <param name="sysUser"></param>
|
||||
/// <returns></returns>
|
||||
public int UpdateUser(SysUser user)
|
||||
{
|
||||
var roleIds = RoleService.SelectUserRoles(user.UserId);
|
||||
var diffArr = roleIds.Where(c => !((IList)user.RoleIds).Contains(c)).ToArray();
|
||||
var diffArr2 = user.RoleIds.Where(c => !((IList)roleIds).Contains(c)).ToArray();
|
||||
|
||||
if (diffArr.Length > 0 || diffArr2.Length > 0)
|
||||
{
|
||||
//删除用户与角色关联
|
||||
UserRoleService.DeleteUserRoleByUserId((int)user.UserId);
|
||||
//新增用户与角色关联
|
||||
UserRoleService.InsertUserRole(user);
|
||||
}
|
||||
// 删除用户与岗位关联
|
||||
UserPostService.Delete(it => it.UserId == user.UserId);
|
||||
// 新增用户与岗位管理
|
||||
UserPostService.InsertUserPost(user);
|
||||
return UserRepository.UpdateUser(user);
|
||||
}
|
||||
|
||||
public int ChangeUser(SysUser user)
|
||||
{
|
||||
return UserRepository.UpdateUser(user);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重置密码
|
||||
/// </summary>
|
||||
/// <param name="userid"></param>
|
||||
/// <param name="password"></param>
|
||||
/// <returns></returns>
|
||||
public int ResetPwd(long userid, string password)
|
||||
{
|
||||
return UserRepository.ResetPwd(userid, password);
|
||||
}
|
||||
|
||||
public int ChangeUserStatus(SysUser user)
|
||||
{
|
||||
return UserRepository.ChangeUserStatus(user);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除用户
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
public int DeleteUser(long userid)
|
||||
{
|
||||
return UserRepository.DeleteUser(userid);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改用户头像
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
public int UpdatePhoto(SysUser user)
|
||||
{
|
||||
return UserRepository.UpdatePhoto(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ZR.Common\ZR.Common.csproj" />
|
||||
<ProjectReference Include="..\ZR.Repository\ZR.Repository.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user