重构代码
重构代码
This commit is contained in:
@@ -1,136 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Enum;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.ModelFactory;
|
||||
|
||||
namespace Yi.Framework.Service
|
||||
{
|
||||
public class BaseService<T> : IBaseService<T> where T : class, new()
|
||||
{
|
||||
public DbContext _Db;
|
||||
public DbContext _DbRead;
|
||||
public IDbContextFactory _DbFactory;
|
||||
public BaseService(IDbContextFactory DbFactory)
|
||||
{
|
||||
_DbFactory = DbFactory;
|
||||
_Db = DbFactory.ConnWriteOrRead(WriteAndReadEnum.Write);
|
||||
_DbRead = DbFactory.ConnWriteOrRead(WriteAndReadEnum.Read);
|
||||
}
|
||||
|
||||
public async Task<T> GetEntityById(int id)
|
||||
{
|
||||
return await _Db.Set<T>().FindAsync(id);
|
||||
}
|
||||
|
||||
|
||||
public async Task<IEnumerable<T>> GetAllEntitiesAsync()
|
||||
{
|
||||
return await _Db.Set<T>().ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<T>> GetEntitiesAsync(Expression<Func<T, bool>> whereLambda)
|
||||
{
|
||||
return await _Db.Set<T>().Where(whereLambda).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<int> GetCountAsync(Expression<Func<T, bool>> whereLambda) //统计数量
|
||||
{
|
||||
return await _Db.Set<T>().CountAsync(whereLambda);
|
||||
}
|
||||
|
||||
public IQueryable<IGrouping<S, T>> GetGroup<S>(Expression<Func<T, bool>> whereLambda, Expression<Func<T, S>> groupByLambda) //分组
|
||||
{
|
||||
return _Db.Set<T>().Where(whereLambda).GroupBy(groupByLambda).AsQueryable();
|
||||
}
|
||||
|
||||
public async Task<Tuple<IEnumerable<T>, int>> GetPageEntities<S>(int pageSize, int pageIndex, Expression<Func<T, bool>> whereLambda, Expression<Func<T, S>> orderByLambda, bool isAsc)
|
||||
{
|
||||
int total = await GetCountAsync(whereLambda);
|
||||
|
||||
IEnumerable<T> pageData;
|
||||
if (isAsc)
|
||||
{
|
||||
pageData = await _Db.Set<T>().Where(whereLambda)
|
||||
.OrderBy<T, S>(orderByLambda)
|
||||
.Skip(pageSize * (pageIndex - 1))
|
||||
.Take(pageSize).ToListAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
pageData = await _Db.Set<T>().Where(whereLambda)
|
||||
.OrderByDescending<T, S>(orderByLambda)
|
||||
.Skip(pageSize * (pageIndex - 1))
|
||||
.Take(pageSize).ToListAsync();
|
||||
}
|
||||
|
||||
return Tuple.Create<IEnumerable<T>, int>(pageData, total);
|
||||
}
|
||||
|
||||
public async Task<bool> AddAsync(T entity)
|
||||
{
|
||||
_Db.Set<T>().Add(entity);
|
||||
return await _Db.SaveChangesAsync() > 0;
|
||||
}
|
||||
|
||||
public async Task<bool> AddAsync(IEnumerable<T> entities)
|
||||
{
|
||||
_Db.Set<T>().AddRange(entities);
|
||||
return await _Db.SaveChangesAsync() > 0;
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateAsync(T entity)
|
||||
{
|
||||
_Db.Set<T>().Update(entity);
|
||||
return await _Db.SaveChangesAsync() > 0;
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateListAsync(IEnumerable<T> entities)
|
||||
{
|
||||
_Db.Set<T>().UpdateRange(entities);
|
||||
return await _Db.SaveChangesAsync() > 0;
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteAsync(T entity)
|
||||
{
|
||||
_Db.Set<T>().Remove(entity);
|
||||
return await _Db.SaveChangesAsync() > 0;
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteAsync(int id)
|
||||
{
|
||||
_Db.Set<T>().Remove(await GetEntityById(id));
|
||||
return await _Db.SaveChangesAsync() > 0;
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteAsync(IEnumerable<int> ids)
|
||||
{
|
||||
foreach (var id in ids)
|
||||
{
|
||||
_Db.Set<T>().RemoveRange(await GetEntityById(id));
|
||||
}
|
||||
return await _Db.SaveChangesAsync() > 0;
|
||||
}
|
||||
public async Task<bool> DeleteAsync(Expression<Func<T, bool>> where)
|
||||
{
|
||||
IEnumerable<T> entities = await GetEntitiesAsync(where);
|
||||
if (entities != null)
|
||||
{
|
||||
_Db.Set<T>().RemoveRange(entities);
|
||||
|
||||
return await _Db.SaveChangesAsync() > 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public async Task<T> GetEntity(Expression<Func<T, bool>> whereLambda)
|
||||
{
|
||||
return await _Db.Set<T>().Where(whereLambda).FirstOrDefaultAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Enum;
|
||||
using Yi.Framework.Common.Helper;
|
||||
using Yi.Framework.Core;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
|
||||
namespace Yi.Framework.Service
|
||||
{
|
||||
public partial class MenuService:BaseService<menu>, IMenuService
|
||||
{
|
||||
short Normal = (short)DelFlagEnum.Normal;
|
||||
public async Task<menu> AddChildrenMenu(int menu_id, menu _children)
|
||||
{
|
||||
_children.parentId = menu_id;
|
||||
_children.is_top = (short)TopFlagEnum.Children;
|
||||
_children.is_delete = (short)DelFlagEnum.Normal;
|
||||
await AddAsync(_children);
|
||||
return _children;
|
||||
}
|
||||
|
||||
public async Task<bool> AddTopMenu(menu _menu)
|
||||
{
|
||||
_menu.is_top = (short)TopFlagEnum.Children;
|
||||
|
||||
return await AddAsync(_menu);
|
||||
}
|
||||
|
||||
public async Task<menu> GetMenuInMould()
|
||||
{
|
||||
var menu_data = await _DbRead.Set<menu>().Include(u => u.mould).Where(u=>u.is_delete==(short)DelFlagEnum.Normal).ToListAsync();
|
||||
return TreeHelper.SetTree(menu_data, null)[0]; ;
|
||||
}
|
||||
|
||||
|
||||
public async Task<List<menu>> GetTopMenusByTopMenuIds(List<int> menuIds)
|
||||
{
|
||||
return await _DbRead.Set<menu>().AsNoTracking().Where(u => menuIds.Contains(u.id)).OrderBy(u=>u.sort).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<menu> SetMouldByMenu(int id1,int id2)
|
||||
{
|
||||
var menu_data = await _DbRead.Set<menu>().Include(u => u.mould).Where(u => u.id == id1).FirstOrDefaultAsync();
|
||||
var mould_data = await _DbRead.Set<mould>().Where(u => u.id == id1).FirstOrDefaultAsync();
|
||||
menu_data.mould = mould_data;
|
||||
_Db.Update(menu_data);
|
||||
return menu_data;
|
||||
}
|
||||
|
||||
|
||||
public async Task<List<menu>> GetTopMenuByUserId(int userId)
|
||||
{
|
||||
var user_data = await _DbRead.Set<user>().Include(u => u.roles).ThenInclude(u => u.menus).Where(u=>u.id==userId).FirstOrDefaultAsync();
|
||||
List<menu> menuList = new();
|
||||
user_data.roles.ForEach(u =>
|
||||
{
|
||||
var m = u.menus.Where(u => u.is_delete == Normal).ToList();
|
||||
menuList = menuList.Union(m).ToList();
|
||||
});
|
||||
|
||||
var menuIds=menuList.Select(u => u.id).ToList();
|
||||
|
||||
return await _DbRead.Set<menu>().Include(u => u.mould).Where(u => menuIds.Contains(u.id)).ToListAsync();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
|
||||
namespace Yi.Framework.Service
|
||||
{
|
||||
public partial class MouldService:BaseService<mould>, IMouldService
|
||||
{
|
||||
/// <summary>
|
||||
/// 这个获取的是菜单,用的是菜单表,应该放到菜单service里面,像这种只用到id的,就传一个id就可以了
|
||||
/// </summary>
|
||||
/// <param name="_mould"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<menu> GetMenuByMould(mould _mould)
|
||||
{
|
||||
var menu_data = await _Db.Set<menu>().Include(u => u.mould).Where(u => u.mould == _mould && u.is_delete == (short)Common.Enum.DelFlagEnum.Normal).FirstOrDefaultAsync();
|
||||
return menu_data;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
|
||||
namespace Yi.Framework.Service
|
||||
{
|
||||
public partial class RoleService : BaseService<role>, IRoleService
|
||||
{
|
||||
short Normal = (short)Common.Enum.DelFlagEnum.Normal;
|
||||
|
||||
public async Task<List<role>> GetRolesByUserId(int userId)
|
||||
{
|
||||
var user_data = await _Db.Set<user>().Include(u => u.roles).Where(u => u.id == userId).FirstOrDefaultAsync();
|
||||
var roleList = user_data.roles.Where(u => u.is_delete == Normal).ToList();
|
||||
roleList.ForEach(u => u.users = null);
|
||||
return roleList;
|
||||
}
|
||||
|
||||
|
||||
public async Task<bool> SetMenusByRolesId(List<int> menuIds, List<int> roleIds)
|
||||
{
|
||||
var role_data = await _Db.Set<role>().Include(u => u.menus).Where(u => roleIds.Contains(u.id) && u.is_delete == Normal).ToListAsync();
|
||||
var menuList = await _Db.Set<menu>().Where(u => menuIds.Contains(u.id) && u.is_delete == Normal).ToListAsync();
|
||||
foreach (var role in role_data)
|
||||
{
|
||||
role.menus = menuList;
|
||||
}
|
||||
return await UpdateListAsync(role_data);
|
||||
}
|
||||
|
||||
public async Task<List<menu>> GetMenusByRoleId(List<int> roleIds)
|
||||
{
|
||||
var role_data = await _Db.Set<role>().Include(u => u.menus).Where(u => roleIds.Contains(u.id) && u.is_delete == Normal).ToListAsync();
|
||||
List<menu> menuList = new();
|
||||
role_data.ForEach(u =>
|
||||
{
|
||||
var m = u.menus.Where(u => u.is_delete == Normal).ToList();
|
||||
menuList = menuList.Union(m).ToList();
|
||||
});
|
||||
return menuList;
|
||||
}
|
||||
public async Task<List<menu>> GetTopMenusByRoleId(int roleId)
|
||||
{
|
||||
var role_data = await _Db.Set<role>().Include(u => u.menus).Where(u => u.id == roleId).FirstOrDefaultAsync();
|
||||
var menuList = role_data.menus.Where(u => u.is_delete == Normal).ToList();
|
||||
|
||||
menuList.ForEach(u => u.roles = null);
|
||||
|
||||
return menuList;
|
||||
}
|
||||
|
||||
public async Task<List<menu>> GetMenusByRole(int roleId)
|
||||
{
|
||||
var role_data = await _Db.Set<role>().Include(u => u.menus).Where(u => u.id == roleId).FirstOrDefaultAsync();
|
||||
var menuList = role_data.menus.Where(u => u.is_delete == Normal).ToList();
|
||||
return menuList;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Interface;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Yi.Framework.Model.ModelFactory;
|
||||
|
||||
namespace Yi.Framework.Service
|
||||
{
|
||||
|
||||
public partial class MenuService:BaseService<menu>,IMenuService
|
||||
{
|
||||
public MenuService(IDbContextFactory DbFactory):base(DbFactory){ }
|
||||
|
||||
public async Task<bool> DelListByUpdateAsync(List<int> _ids)
|
||||
{
|
||||
var menuList = await GetEntitiesAsync(u=>_ids.Contains(u.id));
|
||||
menuList.ToList().ForEach(u => u.is_delete = (short)Common.Enum.DelFlagEnum.Deleted);
|
||||
return await UpdateListAsync(menuList);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<menu>> GetAllEntitiesTrueAsync()
|
||||
{
|
||||
return await GetEntitiesAsync(u=> u.is_delete == (short)Common.Enum.DelFlagEnum.Normal);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public partial class MouldService:BaseService<mould>,IMouldService
|
||||
{
|
||||
public MouldService(IDbContextFactory DbFactory):base(DbFactory){ }
|
||||
|
||||
public async Task<bool> DelListByUpdateAsync(List<int> _ids)
|
||||
{
|
||||
var mouldList = await GetEntitiesAsync(u=>_ids.Contains(u.id));
|
||||
mouldList.ToList().ForEach(u => u.is_delete = (short)Common.Enum.DelFlagEnum.Deleted);
|
||||
return await UpdateListAsync(mouldList);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<mould>> GetAllEntitiesTrueAsync()
|
||||
{
|
||||
return await GetEntitiesAsync(u=> u.is_delete == (short)Common.Enum.DelFlagEnum.Normal);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public partial class RoleService:BaseService<role>,IRoleService
|
||||
{
|
||||
public RoleService(IDbContextFactory DbFactory):base(DbFactory){ }
|
||||
|
||||
public async Task<bool> DelListByUpdateAsync(List<int> _ids)
|
||||
{
|
||||
var roleList = await GetEntitiesAsync(u=>_ids.Contains(u.id));
|
||||
roleList.ToList().ForEach(u => u.is_delete = (short)Common.Enum.DelFlagEnum.Deleted);
|
||||
return await UpdateListAsync(roleList);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<role>> GetAllEntitiesTrueAsync()
|
||||
{
|
||||
return await GetEntitiesAsync(u=> u.is_delete == (short)Common.Enum.DelFlagEnum.Normal);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public partial class UserService:BaseService<user>,IUserService
|
||||
{
|
||||
public UserService(IDbContextFactory DbFactory):base(DbFactory){ }
|
||||
|
||||
public async Task<bool> DelListByUpdateAsync(List<int> _ids)
|
||||
{
|
||||
var userList = await GetEntitiesAsync(u=>_ids.Contains(u.id));
|
||||
userList.ToList().ForEach(u => u.is_delete = (short)Common.Enum.DelFlagEnum.Deleted);
|
||||
return await UpdateListAsync(userList);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<user>> GetAllEntitiesTrueAsync()
|
||||
{
|
||||
return await GetEntitiesAsync(u=> u.is_delete == (short)Common.Enum.DelFlagEnum.Normal);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public partial class VisitService:BaseService<visit>,IVisitService
|
||||
{
|
||||
public VisitService(IDbContextFactory DbFactory):base(DbFactory){ }
|
||||
|
||||
public async Task<bool> DelListByUpdateAsync(List<int> _ids)
|
||||
{
|
||||
var visitList = await GetEntitiesAsync(u=>_ids.Contains(u.id));
|
||||
visitList.ToList().ForEach(u => u.is_delete = (short)Common.Enum.DelFlagEnum.Deleted);
|
||||
return await UpdateListAsync(visitList);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<visit>> GetAllEntitiesTrueAsync()
|
||||
{
|
||||
return await GetEntitiesAsync(u=> u.is_delete == (short)Common.Enum.DelFlagEnum.Normal);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
<#@ template debug="false" hostspecific="true" language="C#" #>
|
||||
<#@ assembly name="System.Core" #>
|
||||
<#@ import namespace="System.Linq" #>
|
||||
<#@ import namespace="System.Text" #>
|
||||
<#@ import namespace="System.IO" #>
|
||||
<#@ import namespace="System.Collections.Generic" #>
|
||||
<#@ output extension=".cs" #>
|
||||
<#
|
||||
string solutionsPath = Host.ResolveAssemblyReference("$(SolutionDir)");//获取解决方案路径
|
||||
string dirPath= Path.Combine(solutionsPath,@"Yi.Framework.Model\Models\");
|
||||
DirectoryInfo dir = new DirectoryInfo(dirPath);
|
||||
FileInfo[] finfo = dir.GetFiles();
|
||||
string filenames = string.Empty;
|
||||
List<string> filenameList = new List<string>();
|
||||
for (int i = 0; i < finfo.Length; i++)
|
||||
{
|
||||
filenames = finfo[i].Name ;
|
||||
string[] fname=filenames.Split('.');
|
||||
filenameList.Add(fname[0]);
|
||||
}
|
||||
|
||||
|
||||
#>
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Interface;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Yi.Framework.Model.ModelFactory;
|
||||
|
||||
namespace Yi.Framework.Service
|
||||
{
|
||||
<# foreach(string k in filenameList){
|
||||
string fn= k.Substring(0,1).ToUpper()+k.Substring(1);
|
||||
#>
|
||||
|
||||
public partial class <#= fn #>Service:BaseService<<#= k #>>,I<#= fn #>Service
|
||||
{
|
||||
public <#= fn #>Service(IDbContextFactory DbFactory):base(DbFactory){ }
|
||||
|
||||
public async Task<bool> DelListByUpdateAsync(List<int> _ids)
|
||||
{
|
||||
var <#= k #>List = await GetEntitiesAsync(u=>_ids.Contains(u.id));
|
||||
<#= k #>List.ToList().ForEach(u => u.is_delete = (short)Common.Enum.DelFlagEnum.Deleted);
|
||||
return await UpdateListAsync(<#= k #>List);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<<#= k #>>> GetAllEntitiesTrueAsync()
|
||||
{
|
||||
return await GetEntitiesAsync(u=> u.is_delete == (short)Common.Enum.DelFlagEnum.Normal);
|
||||
}
|
||||
|
||||
}
|
||||
<# } #>
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
@@ -8,106 +7,15 @@ using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Const;
|
||||
using Yi.Framework.Common.Helper;
|
||||
using Yi.Framework.Core;
|
||||
using Yi.Framework.DTOModel;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model;
|
||||
using Yi.Framework.Model.ModelFactory;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
|
||||
namespace Yi.Framework.Service
|
||||
{
|
||||
public partial class UserService : BaseService<user>, IUserService
|
||||
public partial class UserService : Repository<User>, IUserService
|
||||
{
|
||||
CacheClientDB _cacheClientDB;
|
||||
public UserService(CacheClientDB cacheClientDB, IDbContextFactory DbFactory) : base(DbFactory)
|
||||
{
|
||||
_cacheClientDB = cacheClientDB;
|
||||
}
|
||||
short Normal = (short)Common.Enum.DelFlagEnum.Normal;
|
||||
public async Task<bool> PhoneIsExsit(string smsAddress)
|
||||
{
|
||||
var userList = await GetEntity(u => u.phone == smsAddress);
|
||||
if (userList == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<bool> EmailIsExsit(string emailAddress)
|
||||
{
|
||||
var userList = await GetEntity(u => u.email == emailAddress);
|
||||
if (userList == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<user> GetUserById(int userId)
|
||||
{
|
||||
var user_data = await _DbRead.Set<user>().Include(u => u.roles).ThenInclude(u => u.menus).ThenInclude(u => u.mould).Where(u => u.id == userId).FirstOrDefaultAsync();
|
||||
return user_data;
|
||||
|
||||
}
|
||||
public async Task<List<menu>> GetAxiosByRouter(string router, List<int> menuIds)
|
||||
{
|
||||
var menu_data= await _DbRead.Set<menu>().Where(u => u.router.Trim().ToUpper() == router.Trim().ToUpper() && u.is_delete == (short)Common.Enum.DelFlagEnum.Normal).FirstOrDefaultAsync();
|
||||
return await _DbRead.Set<menu>().Include(u=>u.mould).Where(u => u.parentId == menu_data.id && u.is_delete == (short)Common.Enum.DelFlagEnum.Normal).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<menu> GetMenuByHttpUser(List<int> allMenuIds)
|
||||
{
|
||||
var topMenu = await _DbRead.Set<menu>().Where(u => allMenuIds.Contains(u.id)&& u.is_show == (short)Common.Enum.ShowFlagEnum.Show && u.is_delete == (short)Common.Enum.DelFlagEnum.Normal).ToListAsync();
|
||||
//现在要开始关联菜单了
|
||||
return TreeHelper.SetTree(topMenu)[0];
|
||||
}
|
||||
public async Task<user> GetUserInRolesByHttpUser(int userId)
|
||||
{
|
||||
var data = await GetUserById(userId);
|
||||
data.roles?.ForEach(u =>
|
||||
{
|
||||
u.users = null;
|
||||
u.menus = null;
|
||||
});
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<user> Login(user _user)
|
||||
{
|
||||
var user_data = await _DbRead.Set<user>().Include(u => u.roles).Where(u => u.username == _user.username && u.password == _user.password && u.is_delete == Normal).FirstOrDefaultAsync();
|
||||
return user_data;
|
||||
}
|
||||
|
||||
public async Task<bool> Register(user _user)
|
||||
{
|
||||
var user_data = await GetEntity(u => u.username == _user.username);
|
||||
if (user_data != null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return await UpdateAsync(_user);
|
||||
}
|
||||
|
||||
public async Task<bool> SetRoleByUser(List<int> roleIds, List<int> userIds)
|
||||
{
|
||||
var user_data = await _DbRead.Set<user>().Include(u => u.roles).Where(u => userIds.Contains(u.id)).ToListAsync();
|
||||
var roleList = await _DbRead.Set<role>().Where(u => roleIds.Contains(u.id)).ToListAsync();
|
||||
user_data.ForEach(u => u.roles = roleList);
|
||||
return await UpdateListAsync(user_data);
|
||||
}
|
||||
|
||||
public bool SaveUserApi(int userId, List<menuDto> menus)
|
||||
{
|
||||
return _cacheClientDB.Set(RedisConst.userMenusApi + ":" + userId.ToString(), menus, new TimeSpan(0, 30, 0));
|
||||
}
|
||||
public List<int> GetCurrentMenuInfo(int userId)
|
||||
{
|
||||
return _cacheClientDB.Get<List<menuDto>>(RedisConst.userMenusApi + ":" + userId).Select(u => u.id).ToList();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,25 +13,11 @@
|
||||
<ProjectReference Include="..\Yi.Framework.DTOModel\Yi.Framework.DTOModel.csproj" />
|
||||
<ProjectReference Include="..\Yi.Framework.Interface\Yi.Framework.Interface.csproj" />
|
||||
<ProjectReference Include="..\Yi.Framework.Model\Yi.Framework.Model.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="T4Service.tt">
|
||||
<LastGenOutput>T4Service.cs</LastGenOutput>
|
||||
<Generator>TextTemplatingFileGenerator</Generator>
|
||||
</None>
|
||||
<ProjectReference Include="..\Yi.Framework.Repository\Yi.Framework.Repository.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="T4Service.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>T4Service.tt</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user