225 lines
8.0 KiB
C#
225 lines
8.0 KiB
C#
using MyCode.Project.Domain.Config;
|
|
using MyCode.Project.Domain.Message.Act.User;
|
|
using MyCode.Project.Domain.Message.Common;
|
|
using MyCode.Project.Domain.Message.Request.User;
|
|
using MyCode.Project.Domain.Message.Response.User;
|
|
using MyCode.Project.Domain.Model;
|
|
using MyCode.Project.Domain.Repositories;
|
|
using MyCode.Project.Infrastructure.Common;
|
|
using MyCode.Project.Infrastructure.Constant;
|
|
using MyCode.Project.Infrastructure.Enumeration;
|
|
using MyCode.Project.Infrastructure.Exceptions;
|
|
using MyCode.Project.Infrastructure.Extensions;
|
|
using MyCode.Project.Repositories.Common;
|
|
using Senparc.NeuChar.NeuralSystems;
|
|
using System;
|
|
using System.Runtime.CompilerServices;
|
|
using Wolf.Infrastructure.Domain.Entities;
|
|
|
|
namespace MyCode.Project.Services.Implementation
|
|
{
|
|
/// <summary>
|
|
/// 采购订单 相关服务
|
|
/// </summary>
|
|
public class SysLoginService : ServiceBase , ISysLoginService
|
|
{
|
|
private ISysLoginRepository _sysLoginRepository;
|
|
|
|
|
|
public SysLoginService(ISysLoginRepository sysLoginRepository)
|
|
{
|
|
|
|
_sysLoginRepository = sysLoginRepository;
|
|
}
|
|
|
|
#region Login(账号密码获取token)
|
|
/// <summary>
|
|
/// 账号密码获取token
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="LoginError"></exception>
|
|
public string Login(GetTokenRequest request)
|
|
{
|
|
SysLogin login = new SysLogin();
|
|
//string pwd = EncryptHelper.SHA1Hash(request.PassWord);
|
|
string pwd = request.PassWord;
|
|
LoginInfo loginInfo = new LoginInfo();
|
|
login = _sysLoginRepository.SelectFirst(t => (t.Login == request.UserName) && t.Password == pwd );
|
|
if (login == null)
|
|
{
|
|
pwd = EncryptHelper.SHA1Hash(request.PassWord);
|
|
login = _sysLoginRepository.SelectFirst(t => (t.Login == request.UserName) && t.Password == pwd);
|
|
if (login == null)
|
|
throw new BaseException("账号密码不对");
|
|
}
|
|
|
|
if (login.Status != (int)Status.Enable)
|
|
{
|
|
throw new BaseException("账号已被禁用,请联系管理员");
|
|
}
|
|
loginInfo.Name = login.Name;
|
|
loginInfo.UserId = login.ID;
|
|
loginInfo.RoleType = login.SystemType;
|
|
loginInfo.SupplierId = login.SupplierId;
|
|
loginInfo.SupplierName = login.SupplierName;
|
|
loginInfo.IfForeign = login.IfForeign;
|
|
loginInfo.FPurchaseOrgId = login.FPurchaseOrgId;
|
|
loginInfo.FPurchaseOrgName = loginInfo.FPurchaseOrgName;
|
|
string token = TokenHelper.CreateToken(SystemConfig.JwtKey, Const.LoginInfoKey, loginInfo);
|
|
return token;
|
|
}
|
|
#endregion
|
|
|
|
#region GetPageList(获取分页列表)
|
|
/// <summary>
|
|
/// 获取分页列表
|
|
/// </summary>
|
|
/// <param name="search"></param>
|
|
/// <param name="SupplierId"></param>
|
|
/// <returns></returns>
|
|
public PageResult<AccountPageList> GetPageList(PagedSearch<SysLoginPageSearch> search, LoginInfo loginInfo)
|
|
{
|
|
string SupplierId = "";
|
|
if (loginInfo.RoleType == 0)
|
|
SupplierId = loginInfo.SupplierId;
|
|
|
|
return _sysLoginRepository.GetPageList(search, SupplierId);
|
|
}
|
|
#endregion
|
|
|
|
#region Save(保存账号)
|
|
/// <summary>
|
|
/// 保存账号
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
[TransactionCallHandler]
|
|
public void Save(SysloginAct request, LoginInfo loginInfo)
|
|
{
|
|
Guid loginId = Guid.Empty;
|
|
bool add = false;
|
|
string pwd = "";
|
|
if (!string.IsNullOrWhiteSpace(request.Password))
|
|
{
|
|
pwd = EncryptHelper.SHA1Hash(request.Password);
|
|
}
|
|
SysLogin entity = new SysLogin();
|
|
if (request.Id.IsEmpty())
|
|
{
|
|
add = true;
|
|
|
|
if (pwd == "")
|
|
{
|
|
throw new BaseException("新增账号密码不能为空");
|
|
}
|
|
var hasExist = _sysLoginRepository.IsExist(e => (e.Login == request.Login));
|
|
if (hasExist)
|
|
{
|
|
throw new BaseException("系统账号已存在.");
|
|
}
|
|
entity.ID = Guid.NewGuid();
|
|
entity.IsDeleted = false;
|
|
entity.Login = request.Login;
|
|
entity.Creater = loginInfo.Name;
|
|
entity.CreateTime = DateTime.Now;
|
|
entity.Status = (int)Status.Enable;
|
|
entity.Password = pwd;
|
|
|
|
}
|
|
else
|
|
{
|
|
entity = _sysLoginRepository.SelectFirst(e => e.ID == request.Id);
|
|
var hasExist = _sysLoginRepository.IsExist(e => (e.Login == request.Login ) && e.ID != request.Id );
|
|
if (hasExist)
|
|
{
|
|
throw new BaseException("系统账号已存在.");
|
|
}
|
|
|
|
if (pwd!="")
|
|
{
|
|
entity.Password = pwd;
|
|
}
|
|
//_sysLoginRepository.Update(entity);
|
|
|
|
}
|
|
entity.EditTime = DateTime.Now;
|
|
entity.Editor= loginInfo.Name;
|
|
entity.Mobile = request.Mobile;
|
|
entity.Name = request.Name;
|
|
entity.SupplierName = request.SupplierName;
|
|
entity.SupplierId = request.SupplierId;
|
|
entity.SystemType = request.SystemType;
|
|
entity.IfForeign = request.IfForeign;
|
|
entity.Login = request.Login;
|
|
entity.FPurchaseOrgId = request.FPurchaseOrgId;
|
|
entity.FPurchaseOrgName = request.FPurchaseOrgName;
|
|
|
|
if (entity.SystemType == 1)
|
|
{
|
|
entity.SupplierId = "";
|
|
entity.SupplierName = "";
|
|
entity.FPurchaseOrgId = "-1";
|
|
entity.FPurchaseOrgName = "全部";
|
|
}
|
|
|
|
if (add == true)
|
|
_sysLoginRepository.Add(entity);
|
|
else
|
|
_sysLoginRepository.Update(entity);
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region UpPassword(供应商修改自己的密码)
|
|
/// <summary>
|
|
/// 供应商修改自己的密码
|
|
/// </summary>
|
|
/// <param name="pwd"></param>
|
|
/// <param name="loginInfo"></param>
|
|
/// <exception cref="BaseException"></exception>
|
|
public void UpPassword(string pwd, LoginInfo loginInfo)
|
|
{
|
|
|
|
if (!string.IsNullOrWhiteSpace(pwd))
|
|
{
|
|
pwd = EncryptHelper.SHA1Hash(pwd);
|
|
}
|
|
else
|
|
throw new BaseException("密码不能为空");
|
|
var entity = _sysLoginRepository.SelectFirst(e => e.ID == loginInfo.UserId);
|
|
entity.Password = pwd;
|
|
entity.EditTime = DateTime.Now;
|
|
entity.Editor = loginInfo.Name;
|
|
_sysLoginRepository.Update(entity);
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region BatchUpdateStatus(批量更新账号状态)
|
|
/// <summary>
|
|
/// 批量更新账号状态
|
|
/// </summary>
|
|
/// <param name="act">系统编号 操作</param>
|
|
/// <param name="status">状态</param>
|
|
[TransactionCallHandler]
|
|
public void BatchUpdateStatus(IdActs act, Status status)
|
|
{
|
|
var list = this._sysLoginRepository.Queryable().Where(t=>act.Ids.Contains(t.ID)).ToList();
|
|
if (list.Count == 0)
|
|
{
|
|
throw new BaseException("数据不存在");
|
|
}
|
|
list.ForEach(t =>
|
|
{
|
|
|
|
t.Status = (int)status;
|
|
_sysLoginRepository.Update(t);
|
|
});
|
|
|
|
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
}
|