You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
189 lines
6.9 KiB
189 lines
6.9 KiB
2 years ago
|
using Dapper;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Data;
|
||
|
using System.Threading.Tasks;
|
||
|
using Znyc.Cloudcar.Admin.Commons.IDbContext;
|
||
|
using Znyc.Cloudcar.Admin.Commons.Repositories;
|
||
|
using Znyc.Cloudcar.Admin.Security.Dtos;
|
||
|
using Znyc.Cloudcar.Admin.Security.Entitys;
|
||
|
using Znyc.Cloudcar.Admin.Security.IRepositories;
|
||
|
|
||
|
namespace Znyc.Cloudcar.Admin.Security.Repositories
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// Ӧ�òִ�ʵ��
|
||
|
/// </summary>
|
||
|
public class AdminUserRepository : BaseRepository<AdminUserEntity, long>, IAdminUserRepository
|
||
|
{
|
||
|
public AdminUserRepository()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
public AdminUserRepository(IDbContextCore context) : base(context)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// �����û��˺Ų�ѯ�û���Ϣ
|
||
|
/// </summary>
|
||
|
/// <param name="userName"></param>
|
||
|
/// <returns></returns>
|
||
|
public async Task<AdminUserEntity> GetByUserName(string userName)
|
||
|
{
|
||
|
string sql = @"SELECT * FROM sys_adminuser t WHERE t.Account = @UserName";
|
||
|
return await DapperConn.QueryFirstOrDefaultAsync<AdminUserEntity>(sql, new { UserName = userName });
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// �����û��ֻ�������ѯ�û���Ϣ
|
||
|
/// </summary>
|
||
|
/// <param name="mobilephone">�ֻ�����</param>
|
||
|
/// <returns></returns>
|
||
|
public async Task<AdminUserEntity> GetUserByMobilePhone(string mobilephone)
|
||
|
{
|
||
|
string sql = @"SELECT * FROM sys_adminuser t WHERE t.MobilePhone = @MobilePhone";
|
||
|
return await DapperConn.QueryFirstOrDefaultAsync<AdminUserEntity>(sql, new { MobilePhone = mobilephone });
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// ����Email��Account���ֻ��Ų�ѯ�û���Ϣ
|
||
|
/// </summary>
|
||
|
/// <param name="account">��¼�˺�</param>
|
||
|
/// <returns></returns>
|
||
|
public async Task<AdminUserEntity> GetUserByLogin(string account)
|
||
|
{
|
||
|
string sql =
|
||
|
@"SELECT * FROM sys_adminuser t WHERE (t.Account = @Account or t.MobilePhone = @Account)";
|
||
|
return await DapperConn.QueryFirstOrDefaultAsync<AdminUserEntity>(sql, new { Account = account });
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// ������UnionId��ѯ�û���Ϣ
|
||
|
/// </summary>
|
||
|
/// <param name="unionId">UnionIdֵ</param>
|
||
|
/// <returns></returns>
|
||
|
public AdminUserEntity GetUserByUnionId(string unionId)
|
||
|
{
|
||
|
string sql = string.Format("select * from sys_adminuser where UnionId = '{0}'", unionId);
|
||
|
return DapperConn.QueryFirstOrDefault<AdminUserEntity>(sql);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// ���ݵ�����OpenId��ѯ�û���Ϣ
|
||
|
/// </summary>
|
||
|
/// <param name="openIdType">����������</param>
|
||
|
/// <param name="openId">OpenIdֵ</param>
|
||
|
/// <returns></returns>
|
||
|
public AdminUserEntity GetUserByOpenId(string openIdType, string openId)
|
||
|
{
|
||
|
string sql = string.Format(
|
||
|
"select * from sys_adminuser as u join sys_adminuserOpenIds as o on u.Id = o.UserId and o.OpenIdType = '{0}' and o.OpenId = '{1}'",
|
||
|
openIdType, openId);
|
||
|
return DapperConn.QueryFirstOrDefault<AdminUserEntity>(sql);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// ����userId��ѯ�û���Ϣ
|
||
|
/// </summary>
|
||
|
/// <param name="openIdType">����������</param>
|
||
|
/// <param name="userId">userId</param>
|
||
|
/// <returns></returns>
|
||
|
public UserOpenIdsEntity GetUserOpenIdByuserId(string openIdType, long userId)
|
||
|
{
|
||
|
string sql = string.Format("select * from sys_adminuserOpenIds where OpenIdType = '{0}' and UserId = '{1}'",
|
||
|
openIdType, userId);
|
||
|
return DapperConn.QueryFirstOrDefault<UserOpenIdsEntity>(sql);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// �����û���Ϣ,������ƽ̨
|
||
|
/// </summary>
|
||
|
/// <param name="entity"></param>
|
||
|
/// <param name="userLogOnEntity"></param>
|
||
|
/// <param name="trans"></param>
|
||
|
public bool UpdateUserByOpenId(AdminUserEntity entity, AdminUserLogOnEntity userLogOnEntity,
|
||
|
UserOpenIdsEntity userOpenIds,
|
||
|
IDbTransaction trans = null)
|
||
|
{
|
||
|
DbContext.GetDbSet<AdminUserEntity>().Add(entity);
|
||
|
DbContext.GetDbSet<UserOpenIdsEntity>().Add(userOpenIds);
|
||
|
return DbContext.SaveChanges() > 0;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// ��ҳ�õ������û����ڹ�ע
|
||
|
/// </summary>
|
||
|
/// <param name="currentpage"></param>
|
||
|
/// <param name="pagesize"></param>
|
||
|
/// <param name="userid"></param>
|
||
|
/// <returns></returns>
|
||
|
public IEnumerable<UserAllListFocusOutPutDto> GetUserAllListFocusByPage(string currentpage,
|
||
|
string pagesize, long userId)
|
||
|
{
|
||
|
string sqlRecord = "";
|
||
|
string sql = "";
|
||
|
|
||
|
long countNotIn = (long.Parse(currentpage) - 1) * long.Parse(pagesize);
|
||
|
|
||
|
sqlRecord = @"select * from sys_adminuser where UserName <> '�ο�' and ismember=1 ";
|
||
|
|
||
|
sql = @"SELECT TOP " + pagesize +
|
||
|
@"
|
||
|
case when t2.Id is null then 'n'
|
||
|
else 'y' end as IfFocus ,
|
||
|
IsNull(t3.totalFocus,0) as TotalFocus,
|
||
|
t1.*
|
||
|
from
|
||
|
(select ISNULL(tin2.VipGrade,0) as VipGrade,
|
||
|
ISNULL(tin2.IsAuthentication,0) as IsAuthentication,
|
||
|
ISNULL(tin2.AuthenticationType,0) as AuthenticationType,
|
||
|
tin1.* from sys_adminuser tin1
|
||
|
left join sys_adminuserExtend tin2 on tin1.Id=tin2.UserId
|
||
|
where UserName <> '�ο�' and ismember=1) t1
|
||
|
left join
|
||
|
(select * from sys_adminuserFocus where CreatedUserId='" + userId + @"') t2
|
||
|
on t1.id=t2.focususerid
|
||
|
left join
|
||
|
(select top 100 percent focusUserID,count(*) as totalFocus from sys_adminuserFocus group by focusUserID order by totalfocus desc) t3
|
||
|
on t1.Id=t3.focusUserID
|
||
|
|
||
|
where t1.Id not in
|
||
|
(
|
||
|
select top " + countNotIn + @"
|
||
|
tt1.Id
|
||
|
from
|
||
|
(select ISNULL(tin2.VipGrade,0) as VipGrade,
|
||
|
ISNULL(tin2.IsAuthentication,0) as IsAuthentication,
|
||
|
ISNULL(tin2.AuthenticationType,0) as AuthenticationType,
|
||
|
tin1.* from sys_adminuser tin1
|
||
|
left join sys_adminuserExtend tin2 on tin1.Id=tin2.UserId
|
||
|
where UserName <> '�ο�' and ismember=1) tt1
|
||
|
left join
|
||
|
(select * from sys_adminuserFocus where CreatedUserId='" + userId + @"') tt2
|
||
|
on tt1.id=tt2.focususerid
|
||
|
left join
|
||
|
(select top 100 percent focusUserID,count(*) as totalFocus from sys_adminuserFocus group by focusUserID order by totalfocus desc) tt3
|
||
|
on tt1.Id=tt3.focusUserID
|
||
|
|
||
|
order by tt3.totalFocus desc
|
||
|
)
|
||
|
|
||
|
order by t3.totalFocus desc";
|
||
|
|
||
|
List<UserAllListFocusOutPutDto> list = new List<UserAllListFocusOutPutDto>();
|
||
|
|
||
|
IEnumerable<UserAllListFocusOutPutDto> infoOutputDto = DapperConn.Query<UserAllListFocusOutPutDto>(sql);
|
||
|
|
||
|
//�õ��ܼ�¼��
|
||
|
List<UserAllListFocusOutPutDto> recordCountList = DapperConn.Query<UserAllListFocusOutPutDto>(sqlRecord).AsList();
|
||
|
|
||
|
list = infoOutputDto.AsList();
|
||
|
for (int i = 0; i < list.Count; i++)
|
||
|
{
|
||
|
list[i].RecordCount = recordCountList.Count;
|
||
|
}
|
||
|
|
||
|
return list;
|
||
|
}
|
||
|
}
|
||
|
}
|