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.
285 lines
11 KiB
285 lines
11 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Threading.Tasks;
|
|
using Znyc.Cloudcar.Admin.Commons;
|
|
using Znyc.Cloudcar.Admin.Commons.Encrypt;
|
|
using Znyc.Cloudcar.Admin.Commons.Enums;
|
|
using Znyc.Cloudcar.Admin.Commons.Mapping;
|
|
using Znyc.Cloudcar.Admin.Commons.Pages;
|
|
using Znyc.Cloudcar.Admin.Commons.Services;
|
|
using Znyc.Cloudcar.Admin.Security.Dtos;
|
|
using Znyc.Cloudcar.Admin.Security.Entitys;
|
|
using Znyc.Cloudcar.Admin.Security.IRepositories;
|
|
using Znyc.Cloudcar.Admin.Security.IServices;
|
|
|
|
namespace Znyc.Cloudcar.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.State == -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.State == -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();
|
|
}
|
|
|
|
}
|
|
}
|
|
|