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 { /// /// 采购订单 相关服务 /// public class SysLoginService : ServiceBase , ISysLoginService { private ISysLoginRepository _sysLoginRepository; public SysLoginService(ISysLoginRepository sysLoginRepository) { _sysLoginRepository = sysLoginRepository; } #region Login(账号密码获取token) /// /// 账号密码获取token /// /// /// /// 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(获取分页列表) /// /// 获取分页列表 /// /// /// /// public PageResult GetPageList(PagedSearch search, LoginInfo loginInfo) { string SupplierId = ""; if (loginInfo.RoleType == 0) SupplierId = loginInfo.SupplierId; return _sysLoginRepository.GetPageList(search, SupplierId); } #endregion #region Save(保存账号) /// /// 保存账号 /// /// [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); } if (string.IsNullOrWhiteSpace(request.SupplierId) && request.SystemType == 0) { throw new BaseException("供应商类型的账号必须选一个供应商"); } 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(供应商修改自己的密码) /// /// 供应商修改自己的密码 /// /// /// /// 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(批量更新账号状态) /// /// 批量更新账号状态 /// /// 系统编号 操作 /// 状态 [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 } }