| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- using EFCore.Sharding;
- using Microsoft.EntityFrameworkCore;
- using Microsoft.Extensions.Caching.Distributed;
- using Net6Demo_Api.Entity;
- using Net6Demo_Api.IBusiness;
- using Net6Demo_Api.Util;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Linq.Dynamic.Core;
- using System.Text;
- using System.Threading.Tasks;
- using AutoMapper;
- namespace Net6Demo_Api.Business
- {
- public class UserAccountBusiness : BaseBusiness<T_Sys_UserAccount>, IUserAccountBusiness, ITransientDependency
- {
- private readonly IMapper _mapper;
- public UserAccountBusiness(IDbAccessor db, IDistributedCache cache, IMapper mapper) : base(db, cache, true)
- {
- _mapper = mapper;
- }
- /// <summary>
- /// 多表关联查询分页
- /// </summary>
- /// <param name="page">分页信息</param>
- /// <param name="condition">条件</param>
- /// <param name="orderBy">排序</param>
- /// <returns></returns>
- public async Task<ValueTuple<List<UserAccountView>, int>> GetMultipleListPageAsync(PageInput page, Expression<Func<T_Sys_UserAccount, bool>> condition, Func<IQueryable<T_Sys_UserAccount>, IOrderedQueryable<T_Sys_UserAccount>> orderBy)
- {
- var iq = _db.GetIQueryable<T_Sys_UserAccount>().AsNoTracking().Where(condition);
- var miq = from a in orderBy(iq)
- join b in _db.GetIQueryable<T_Sys_Role>().AsNoTracking() on a.F_RoleId equals b.F_RoleId into ab
- from b in ab.DefaultIfEmpty()
- join c in _db.GetIQueryable<T_Sys_Department>().AsNoTracking() on a.F_DeptId equals c.F_DeptId into ac
- from c in ac.DefaultIfEmpty()
- select new { a, b, c };
- var oldlist = await miq.Skip((page.PageIndex - 1) * page.PageRows).Take(page.PageRows).ToListAsync();
- var list = oldlist.Select(p =>
- {
- var a = _mapper.Map<UserAccountView>(p.a);
- a.RoleCode = p.b?.F_RoleCode;
- a.RoleName = p.b?.F_RoleName;
- a.DeptCode = p.c?.F_DeptCode;
- a.DeptName = p.c?.F_DeptName;
- return a;
- }).ToList();
- int total = await iq.CountAsync();
- return (list, total);
- }
- }
- }
|