You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
2.1 KiB
C#
73 lines
2.1 KiB
C#
using DS.Module.Core;
|
|
using DS.Module.UserModule;
|
|
using DS.WMS.Core.App.Dtos;
|
|
using DS.WMS.Core.App.Interface;
|
|
using DS.WMS.Core.System.Dtos;
|
|
using DS.WMS.Core.System.Entity;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using SqlSugar;
|
|
|
|
namespace DS.WMS.Core.App.Method;
|
|
|
|
public class AppCommonService : IAppCommonService
|
|
{
|
|
private readonly IServiceProvider _serviceProvider;
|
|
private readonly ISqlSugarClient db;
|
|
private readonly IUser user;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="serviceProvider"></param>
|
|
public AppCommonService(IServiceProvider serviceProvider)
|
|
{
|
|
_serviceProvider = serviceProvider;
|
|
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
|
|
user = _serviceProvider.GetRequiredService<IUser>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// App用户登录
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public DataResult<CurrentUserViewModel> AppUserLogin(AppLoginModel model)
|
|
{
|
|
var user = db.Queryable<SysUser>().First(x => x.UserCode == model.UserCode);
|
|
if (user == null)
|
|
{
|
|
return DataResult<CurrentUserViewModel>.Failed("账号不存在,请检查!");
|
|
}
|
|
|
|
if (user.Password != model.Password)
|
|
{
|
|
return DataResult<CurrentUserViewModel>.Failed("密码错误!");
|
|
}
|
|
|
|
|
|
var data = db.Queryable<SysUser>()
|
|
.Where(a =>
|
|
a.Id == user.Id)
|
|
.Select(a => new CurrentUserViewModel
|
|
{
|
|
UserId = a.Id.ToString(),
|
|
UserCode = a.UserCode,
|
|
UserName = a.UserName,
|
|
CompanyId = a.CompanyId.ToString(),
|
|
// CompanyName = a.c
|
|
}).First();
|
|
|
|
var tokenModel = new JwtHelper.JwtTokenModel
|
|
{
|
|
Uid = data.UserId.ToString(),
|
|
CompanyId = data.CompanyId,
|
|
GID = user.GID,
|
|
TenantId = user.TenantId,
|
|
};
|
|
data.Token = JwtHelper.Encrypt(tokenModel);
|
|
|
|
// data.Token = JwtHelper.GetJWT(data.ObjToString());
|
|
|
|
return DataResult<CurrentUserViewModel>.Success("登录成功!", data);
|
|
}
|
|
} |