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.
286 lines
11 KiB
286 lines
11 KiB
2 years ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Data;
|
||
|
using System.Threading.Tasks;
|
||
|
using Znyc.Recruitment.Admin.Commons.Const;
|
||
|
using Znyc.Recruitment.Admin.Commons.Encrypt;
|
||
|
using Znyc.Recruitment.Admin.Commons.Enums;
|
||
|
using Znyc.Recruitment.Admin.Commons.Mapping;
|
||
|
using Znyc.Recruitment.Admin.Commons.Pages;
|
||
|
using Znyc.Recruitment.Admin.Commons.Services;
|
||
|
using Znyc.Recruitment.Admin.Security.Dtos;
|
||
|
using Znyc.Recruitment.Admin.Security.Entitys;
|
||
|
using Znyc.Recruitment.Admin.Security.IRepositories;
|
||
|
using Znyc.Recruitment.Admin.Security.IServices;
|
||
|
|
||
|
namespace Znyc.Recruitment.Admin.Security.Services
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// </summary>
|
||
|
public class AdminUserService : BaseService<AdminUserEntity, AdminUserOutputDto, long>, IAdminUserService
|
||
|
{
|
||
|
private readonly IAdminUserLogOnRepository _adminUserLogOnRepository;
|
||
|
private readonly IAdminUserRepository _adminUserRepository;
|
||
|
private readonly IOrganizeService _organizeService;
|
||
|
private readonly IRoleService _roleService;
|
||
|
|
||
|
/// <summary>
|
||
|
/// </summary>
|
||
|
/// <param name="repository"></param>
|
||
|
/// <param name="userLogOnRepository"></param>
|
||
|
/// <param name="logService"></param>
|
||
|
/// <param name="roleService"></param>
|
||
|
/// <param name="organizeService"></param>
|
||
|
public AdminUserService(IAdminUserRepository repository, IAdminUserLogOnRepository adminUserLogOnRepository,
|
||
|
IRoleService roleService, IOrganizeService organizeService) : base(repository)
|
||
|
{
|
||
|
_adminUserRepository = repository;
|
||
|
_roleService = roleService;
|
||
|
_organizeService = organizeService;
|
||
|
_adminUserLogOnRepository = adminUserLogOnRepository;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// �û���½��֤��
|
||
|
/// </summary>
|
||
|
/// <param name="userName">�û���</param>
|
||
|
/// <param name="password">���루��һ��md5���ܺ���</param>
|
||
|
/// <returns>��֤�ɹ������û�ʵ�壬��֤ʧ�ܷ���null|��ʾ��Ϣ</returns>
|
||
|
public async Task<Tuple<AdminUserEntity, string>> Validate(string userName, string password)
|
||
|
{
|
||
|
AdminUserEntity userEntity = await _adminUserRepository.GetUserByLogin(userName);
|
||
|
|
||
|
if (userEntity == null)
|
||
|
{
|
||
|
return new Tuple<AdminUserEntity, string>(null, ReturnConst.User_Not_Exist);
|
||
|
}
|
||
|
|
||
|
if (userEntity.Status == -1)
|
||
|
{
|
||
|
return new Tuple<AdminUserEntity, string>(null, ReturnConst.User_Disable);
|
||
|
}
|
||
|
|
||
|
AdminUserLogOnEntity userSinginEntity = _adminUserLogOnRepository.GetByUserId(userEntity.Id);
|
||
|
string inputPassword = MD5Util
|
||
|
.GetMD5_32(DEncrypt.Encrypt(MD5Util.GetMD5_32(password).ToLower(), userSinginEntity.UserSecretkey)
|
||
|
.ToLower()).ToLower();
|
||
|
|
||
|
if (inputPassword != userSinginEntity.UserPassword)
|
||
|
{
|
||
|
return new Tuple<AdminUserEntity, string>(null, ReturnConst.Password_Error);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
AdminUserLogOnEntity userLogOn = _adminUserLogOnRepository.GetWhere("UserId=" + userEntity.Id);
|
||
|
userLogOn.LogOnCount++;
|
||
|
userLogOn.LastVisitTime = DateTime.Now;
|
||
|
userLogOn.UserOnLine = true;
|
||
|
await _adminUserLogOnRepository.UpdateAsync(userLogOn, userLogOn.Id);
|
||
|
return new Tuple<AdminUserEntity, string>(userEntity, "");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// �û���½��֤��
|
||
|
/// </summary>
|
||
|
/// <param name="userName">�û���</param>
|
||
|
/// <param name="password">���루��һ��md5���ܺ���</param>
|
||
|
/// <param name="userType">�û�����</param>
|
||
|
/// <returns>��֤�ɹ������û�ʵ�壬��֤ʧ�ܷ���null|��ʾ��Ϣ</returns>
|
||
|
public async Task<Tuple<AdminUserEntity, string>> Validate(string userName, string password, UserType userType)
|
||
|
{
|
||
|
AdminUserEntity userEntity = await _adminUserRepository.GetUserByLogin(userName);
|
||
|
|
||
|
if (userEntity == null)
|
||
|
{
|
||
|
return new Tuple<AdminUserEntity, string>(null, ReturnConst.User_Not_Exist);
|
||
|
}
|
||
|
|
||
|
if (userEntity.Status == -1)
|
||
|
{
|
||
|
return new Tuple<AdminUserEntity, string>(null, ReturnConst.User_Disable);
|
||
|
}
|
||
|
|
||
|
AdminUserLogOnEntity userSinginEntity = _adminUserLogOnRepository.GetByUserId(userEntity.Id);
|
||
|
|
||
|
string inputPassword = MD5Util
|
||
|
.GetMD5_32(DEncrypt.Encrypt(MD5Util.GetMD5_32(password).ToLower(), userSinginEntity.UserSecretkey)
|
||
|
.ToLower()).ToLower();
|
||
|
|
||
|
if (inputPassword != userSinginEntity.UserPassword)
|
||
|
{
|
||
|
return new Tuple<AdminUserEntity, string>(null, ReturnConst.Password_Error);
|
||
|
}
|
||
|
|
||
|
AdminUserLogOnEntity userLogOn = _adminUserLogOnRepository.GetWhere("UserId='" + userEntity.Id + "'");
|
||
|
userLogOn.LogOnCount++;
|
||
|
userLogOn.LastVisitTime = DateTime.Now;
|
||
|
userLogOn.UserOnLine = true;
|
||
|
await _adminUserLogOnRepository.UpdateAsync(userLogOn, userLogOn.Id);
|
||
|
return new Tuple<AdminUserEntity, string>(userEntity, "");
|
||
|
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// �����û��˺Ų�ѯ�û���Ϣ
|
||
|
/// </summary>
|
||
|
/// <param name="userName"></param>
|
||
|
/// <returns></returns>
|
||
|
public async Task<AdminUserEntity> GetByUserName(string userName)
|
||
|
{
|
||
|
return await _adminUserRepository.GetByUserName(userName);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// �����û��ֻ�������ѯ�û���Ϣ
|
||
|
/// </summary>
|
||
|
/// <param name="mobilephone">�ֻ�����</param>
|
||
|
/// <returns></returns>
|
||
|
public async Task<AdminUserEntity> GetUserByMobilePhone(string mobilephone)
|
||
|
{
|
||
|
return await _adminUserRepository.GetUserByMobilePhone(mobilephone);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// ����Account���ֻ��Ų�ѯ�û���Ϣ
|
||
|
/// </summary>
|
||
|
/// <param name="account">��¼�˺�</param>
|
||
|
/// <returns></returns>
|
||
|
public async Task<AdminUserEntity> GetUserByLogin(string account)
|
||
|
{
|
||
|
return await _adminUserRepository.GetUserByLogin(account);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// ���ݵ�����OpenId��ѯ�û���Ϣ
|
||
|
/// </summary>
|
||
|
/// <param name="openIdType">����������</param>
|
||
|
/// <param name="openId">OpenIdֵ</param>
|
||
|
/// <returns></returns>
|
||
|
public AdminUserEntity GetUserByOpenId(string openIdType, string openId)
|
||
|
{
|
||
|
return _adminUserRepository.GetUserByOpenId(openIdType, openId);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// ����userId��ѯ�û���Ϣ
|
||
|
/// </summary>
|
||
|
/// <param name="openIdType">����������</param>
|
||
|
/// <param name="userId">userId</param>
|
||
|
/// <returns></returns>
|
||
|
public UserOpenIdsEntity GetUserOpenIdByuserId(string openIdType, long userId)
|
||
|
{
|
||
|
return _adminUserRepository.GetUserOpenIdByuserId(openIdType, userId);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// �����û���Ϣ,������ƽ̨
|
||
|
/// </summary>
|
||
|
/// <param name="entity"></param>
|
||
|
/// <param name="userLogOnEntity"></param>
|
||
|
/// <param name="userOpenIds"></param>
|
||
|
/// <param name="trans"></param>
|
||
|
public bool UpdateUserByOpenId(AdminUserEntity entity, AdminUserLogOnEntity userLogOnEntity,
|
||
|
UserOpenIdsEntity userOpenIds,
|
||
|
IDbTransaction trans = null)
|
||
|
{
|
||
|
return _adminUserRepository.UpdateUserByOpenId(entity, userLogOnEntity, userOpenIds, trans);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// ������UnionId��ѯ�û���Ϣ
|
||
|
/// </summary>
|
||
|
/// <param name="unionId">UnionIdֵ</param>
|
||
|
/// <returns></returns>
|
||
|
public AdminUserEntity GetUserByUnionId(string unionId)
|
||
|
{
|
||
|
return _adminUserRepository.GetUserByUnionId(unionId);
|
||
|
}
|
||
|
|
||
|
|
||
|
/// <summary>
|
||
|
/// ����������ѯ���ݿ�,�����ض���(���ڷ�ҳ������ʾ)
|
||
|
/// </summary>
|
||
|
/// <param name="search">��ѯ������</param>
|
||
|
/// <returns>ָ�������ļ���</returns>
|
||
|
public async Task<PageResult<AdminUserOutputDto>> FindWithPagerSearchAsync(SearchUserModel search)
|
||
|
{
|
||
|
bool order = search.Order == "asc" ? false : true;
|
||
|
string where = GetDataPrivilege(false);
|
||
|
|
||
|
if (!string.IsNullOrEmpty(search.Keywords))
|
||
|
{
|
||
|
where += string.Format(
|
||
|
" and (UserName like '%{0}%' or Account like '%{0}%' or MobilePhone like '%{0}%')",
|
||
|
search.Keywords);
|
||
|
}
|
||
|
|
||
|
if (!string.IsNullOrEmpty(search.RoleId))
|
||
|
{
|
||
|
@where += string.Format(" and RoleId = {0}", search.RoleId);
|
||
|
}
|
||
|
|
||
|
if (!string.IsNullOrEmpty(search.StartTime))
|
||
|
{
|
||
|
where += " and CreatedTime >='" + search.StartTime + " 00:00:00'";
|
||
|
}
|
||
|
|
||
|
if (!string.IsNullOrEmpty(search.EndTime))
|
||
|
{
|
||
|
where += " and CreatedTime <='" + search.EndTime + " 23:59:59'";
|
||
|
}
|
||
|
|
||
|
PagerInfo pagerInfo = new PagerInfo
|
||
|
{
|
||
|
CurrenetPageIndex = search.CurrenetPageIndex,
|
||
|
PageSize = search.PageSize
|
||
|
};
|
||
|
List<AdminUserEntity> list = await repository.FindWithPagerAsync(where, pagerInfo, search.Sort, order);
|
||
|
List<AdminUserOutputDto> resultList = list.MapTo<AdminUserOutputDto>();
|
||
|
List<AdminUserOutputDto> listResult = new List<AdminUserOutputDto>();
|
||
|
foreach (AdminUserOutputDto item in resultList)
|
||
|
{
|
||
|
if (!string.IsNullOrEmpty(item.OrganizeId.ToString()))
|
||
|
{
|
||
|
item.OrganizeName = _organizeService.Get(item.OrganizeId)?.FullName;
|
||
|
}
|
||
|
|
||
|
if (!string.IsNullOrEmpty(item.RoleId))
|
||
|
{
|
||
|
item.RoleName = _roleService.GetRoleNameStr(item.RoleId);
|
||
|
}
|
||
|
|
||
|
if (!string.IsNullOrEmpty(item.DepartmentId.ToString()))
|
||
|
{
|
||
|
item.DepartmentName = _organizeService.Get(item.DepartmentId).FullName;
|
||
|
}
|
||
|
//if (!string.IsNullOrEmpty(item.DutyId))
|
||
|
//{
|
||
|
// item.DutyName = _roleService.Get(item.DutyId).FullName;
|
||
|
//}
|
||
|
listResult.Add(item);
|
||
|
}
|
||
|
|
||
|
PageResult<AdminUserOutputDto> pageResult = new PageResult<AdminUserOutputDto>
|
||
|
{
|
||
|
CurrentPage = pagerInfo.CurrenetPageIndex,
|
||
|
Items = listResult,
|
||
|
ItemsPerPage = pagerInfo.PageSize,
|
||
|
TotalItems = pagerInfo.RecordCount
|
||
|
};
|
||
|
return pageResult;
|
||
|
}
|
||
|
|
||
|
public bool CreateUserByWxOpenId(UserInputDto userInPut)
|
||
|
{
|
||
|
throw new NotImplementedException();
|
||
|
}
|
||
|
|
||
|
public bool UpdateUserByOpenId(UserInputDto userInPut)
|
||
|
{
|
||
|
throw new NotImplementedException();
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|