149 lines
5.8 KiB
C#
149 lines
5.8 KiB
C#
using LearningOfficer.OA.Common.Attributes;
|
|
using LearningOfficer.OA.Common.Configs;
|
|
using LearningOfficer.OA.Common.Dtos.LoginMobile;
|
|
using LearningOfficer.OA.Common.Enums;
|
|
using LearningOfficer.OA.Common.Exceptions;
|
|
using LearningOfficer.OA.Core.Entities.OA.SystemInfo;
|
|
using LearningOfficer.OA.Core.Entities.UserCenter;
|
|
using LearningOfficer.OA.Core.ServicesInterfaces.LoginMobile;
|
|
using LearningOfficer.OA.Infrastructure.DBContext;
|
|
using Masuit.Tools.Models;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.IdentityModel.Tokens;
|
|
using SqlSugar;
|
|
using StackExchange.Redis;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IdentityModel.Tokens.Jwt;
|
|
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
using System.Security.Claims;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace LearningOfficer.OA.Services.LoginMobile
|
|
{
|
|
[Inject]
|
|
public class LoginMobilAppService : BaseService<User>, ILoginMobilAppService
|
|
{
|
|
private readonly SugarRepository<User> _userRepository;
|
|
private readonly IConfiguration _configuration;
|
|
private readonly ISqlSugarClient _db;
|
|
|
|
public LoginMobilAppService(ISqlSugarClient dbContext, SugarRepository<User> userRepository, IConfiguration configuration) : base(userRepository)
|
|
{
|
|
_db = dbContext;
|
|
_configuration = configuration;
|
|
_userRepository = userRepository;
|
|
}
|
|
private async Task<UserResult> GetUserResultByWhere(
|
|
Expression<Func<User, OaUserPermissions, Cloudschool, SysRole, bool>> where)
|
|
{
|
|
var data = await _db.Queryable<User>().AS("usercenter_v1.user")
|
|
.InnerJoin<OaUserPermissions>((u, up) => u.Id == up.UserId, "usercenter_v1.oa_user_permissions")
|
|
.LeftJoin<Cloudschool>((u, up, c) => u.CloudSchoolId == c.Id, "usercenter_v1.cloudschool")
|
|
.LeftJoin<SysRole>((u, up, c, role) => up.RoleEnum == role.RoleEnum, "`learningofficer.oa`.sys_role")
|
|
.Where(where)
|
|
.Select((u, up, c, role) =>
|
|
new
|
|
{
|
|
u,up ,c,role
|
|
}
|
|
).ToListAsync();
|
|
if (data.Count == 0)
|
|
{
|
|
return null;
|
|
}
|
|
else if (data.Count == 1)
|
|
{
|
|
//判断是不是总部长
|
|
var userinfo = data.FirstOrDefault();
|
|
if (userinfo.role.RoleEnum == SysRoleEnum.GeneralMinisterAdmin)
|
|
{
|
|
return new UserResult
|
|
{
|
|
Id = userinfo.u.Id,
|
|
RealName = userinfo.u.RealName,
|
|
Account = userinfo.u.Account,
|
|
Phone = userinfo.u.Phone,
|
|
RoleEnum = userinfo.role.RoleEnum,
|
|
Role_Name = userinfo.role.RoleName,
|
|
Cloud_id = userinfo.c.Id,
|
|
CloudName = userinfo.c.Name,
|
|
HeadImage = userinfo.u.HeadImage
|
|
};
|
|
}
|
|
else
|
|
{
|
|
//判断云校状态是否正常
|
|
if (userinfo.c.Enable != true || userinfo.c.DeleteState != false)
|
|
{
|
|
return null;
|
|
|
|
}
|
|
return new UserResult
|
|
{
|
|
Id = userinfo.u.Id,
|
|
RealName = userinfo.u.RealName,
|
|
Account = userinfo.u.Account,
|
|
Phone = userinfo.u.Phone,
|
|
RoleEnum = userinfo.role.RoleEnum,
|
|
Role_Name = userinfo.role.RoleName,
|
|
Cloud_id = userinfo.c.Id,
|
|
CloudName = userinfo.c.Name,
|
|
HeadImage = userinfo.u.HeadImage
|
|
};
|
|
}
|
|
}
|
|
else if (data.Count > 1)
|
|
{
|
|
//过滤
|
|
var userinfo = data.Where(s => s.c.Enable == true && s.c.DeleteState == false).First();
|
|
|
|
return new UserResult
|
|
{
|
|
Id = userinfo.u.Id,
|
|
RealName = userinfo.u.RealName,
|
|
Account = userinfo.u.Account,
|
|
Phone = userinfo.u.Phone,
|
|
RoleEnum = userinfo.role.RoleEnum,
|
|
Role_Name = userinfo.role.RoleName,
|
|
Cloud_id = userinfo.c.Id,
|
|
CloudName = userinfo.c.Name,
|
|
HeadImage = userinfo.u.HeadImage
|
|
};
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public async Task<UserResult> userLogin(LoginRequest request)
|
|
{
|
|
UserResult model = new UserResult();
|
|
var userResult = await GetUserResultByWhere((u, up, c, role) => u.Account == request.username && u.Password == request.Pwd && u.DeleteState == false && u.State == 1);
|
|
|
|
if (userResult == null)
|
|
{
|
|
throw new BusinessException("账号或密码错误");
|
|
}
|
|
var per = await _db.Queryable<OaUserPermissions>().AS("usercenter_v1.oa_user_permissions")
|
|
.Where(s => s.UserId == userResult.Id)
|
|
.FirstAsync();
|
|
if (per == null)
|
|
{
|
|
throw new BusinessException("用户权限配置错误,请联系管理员");
|
|
}
|
|
if (per.RoleEnum != SysRoleEnum.TeamLeader && per.RoleEnum != SysRoleEnum.LearningOfficer)
|
|
{
|
|
throw new BusinessException("只有组长/学习官可以登录");
|
|
}
|
|
userResult.UserType = 1;
|
|
return userResult;
|
|
}
|
|
|
|
|
|
}
|
|
}
|