using Dapper;
using System.Collections.Generic;
using System.Threading.Tasks;
using Znyc.Recruitment.Admin.Commons.Enums;
using Znyc.Recruitment.Admin.Commons.IDbContext;
using Znyc.Recruitment.Admin.Commons.Pages;
using Znyc.Recruitment.Admin.Commons.Repositories;
using Znyc.Recruitment.Admin.Security.Dtos;
using Znyc.Recruitment.Admin.Security.Entitys;
using Znyc.Recruitment.Admin.Security.IRepositories;
namespace Znyc.Recruitment.Admin.Security.Repositories
{
///
///
public class UserRepository : BaseRepository, IUserRepository
{
///
///
public UserRepository()
{
}
public UserRepository(IDbContextCore dbContext) : base(dbContext)
{
}
///
/// 根据用户UnionId查询用户信息
///
///
///
public async Task GetUserByUnionId(string unionId)
{
string sql = @"SELECT * FROM rm_user t WHERE t.UnionId = @UnionId";
return await DapperConn.QueryFirstOrDefaultAsync(sql, new { UnionId = unionId });
}
public async Task> FindUserWithPagerAsync(SearchUserModel search, PagerInfo info)
{
bool order = search.Order == "asc" ? false : true;
string strwhere = "";
if (search.CertificationStatus >= 0 && search.CertificationStatus != (int)UserCertificationEnum.None)
{
strwhere = $" AND znyc.sys_certification.`Status`={search.CertificationStatus}";
}
if (search.CertificationStatus == (int)UserCertificationEnum.None)
{
strwhere = $" AND znyc_recruitment.rm_user.`IsRealAuthentication`=0";
}
if (!string.IsNullOrEmpty(search.Keywords))
{
strwhere += string.Format(" and (znyc_recruitment.rm_user.UserName like '%{0}%'or znyc_recruitment.rm_user.Phone like '%{0}%')", search.Keywords);
}
if (search.Status > 0)
{
strwhere += string.Format(" and znyc_recruitment.rm_user.Status={0}", search.Status);
}
if (!string.IsNullOrEmpty(search.StartTime))
{
strwhere += " and znyc_recruitment.rm_user.CreatedTime >='" + search.StartTime + " 00:00:00'";
}
if (!string.IsNullOrEmpty(search.EndTime))
{
strwhere += " and znyc_recruitment.rm_user.CreatedTime <='" + search.EndTime + " 23:59:59'";
}
string countSQL = $"select count(znyc_recruitment.rm_user.Id) as Total from znyc_recruitment.rm_user " +
$"LEFT JOIN znyc.sys_certification ON znyc_recruitment.rm_user.UnionId = znyc.sys_certification.UnionId " +
$"Where znyc_recruitment.rm_user.IsDeleted = 0 {strwhere};";
int minRow = search.PageSize * (search.CurrenetPageIndex - 1);
string sql = $"select * from znyc_recruitment.rm_user where Id IN(select t.Id from (select znyc_recruitment.rm_user.Id from znyc_recruitment.rm_user " +
$"LEFT JOIN znyc.sys_certification ON znyc_recruitment.rm_user.UnionId = znyc.sys_certification.UnionId " +
$"Where znyc_recruitment.rm_user.IsDeleted = 0 {strwhere} )as t) " +
$"order by znyc_recruitment.rm_user.{search.Sort} {search.Order} limit {minRow},{search.PageSize}; ";
SqlMapper.GridReader reader = await DapperConnRead.QueryMultipleAsync(countSQL + sql);
info.RecordCount = reader.ReadFirst();
List list = reader.Read().AsList();
return list;
}
}
}