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;
///
///
///
///
public AppCommonService(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
db = _serviceProvider.GetRequiredService();
user = _serviceProvider.GetRequiredService();
}
///
/// App用户登录
///
///
///
public DataResult AppUserLogin(AppLoginModel model)
{
var user = db.Queryable().First(x => x.UserCode == model.UserCode);
if (user == null)
{
return DataResult.Failed("账号不存在,请检查!");
}
if (user.Password != model.Password)
{
return DataResult.Failed("密码错误!");
}
var data = db.Queryable()
.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.Success("登录成功!", data);
}
}