using System; using System.Collections.Generic; using System.Linq; using CommonHelper; using CommonHelper.Weixin; using GasolineBlend.DAL; using GasolineBlend.Entity; namespace GasolineBlend.BLL { public class AccountBLL { private AccountDAL _acc = new AccountDAL(); /// /// 获取用户信息全集 /// /// public List GetAccountList() { return _acc.GetAccountList(); } /// /// 根据角色获取账户列表 /// /// /// public List GetAccountList(int RoleId) { return _acc.GetAccountList(RoleId); } /// /// 根据角色+企业Id获取账户列表 /// /// /// /// public List GetAccountList(int RoleId, int CompanyId) { return _acc.GetAccountList(RoleId, CompanyId); } /// /// 根据角色+企业Id获取账户列表 针对资金监控 /// /// /// /// public List GetAccountListByCompany(int RoleId, int CompanyId,int MoneyMonitorId) { var list = _acc.GetAccountList(RoleId, CompanyId); if (MoneyMonitorId==0) { list = list.Where(p => p.MoneyMonitorId > 0).ToList(); } if (MoneyMonitorId==2) { var UserId = OperatorProvider.Instance.Current.UserId; list = list.Where(p => p.MoneyMonitorId == 2).ToList(); list = list.OrderByDescending(p => p.Id == UserId).ToList(); } foreach (var item in list) { item.Password = ""; } return list; } /// /// 根据Id 获取列表 /// /// /// public List GetAccountByIdList(string Id) { return _acc.GetAccountByIdList(Id); } /// /// 根据角色+企业Id获取账户列表 /// /// /// /// public List GetAccountByCompanyId(int CompanyId) { var list = _acc.GetAccountList((int)UserRoleType.User, CompanyId); list.ForEach(p => p.Password = ""); list = list.Where(p => p.Id != OperatorProvider.Instance.Current.UserId).ToList(); return list; } /// /// 提取不包含某个用户的用户组清单 /// /// /// /// /// //public List GetAccountList(int RoleId, int CompanyId, int UserIdExclude) //{ // return _acc.GetAccountList(RoleId, CompanyId, UserIdExclude); //} /// /// 根据id获取用户信息 /// /// 用户id /// public Account GetAccount(int id) { return _acc.GetAccount(id); } /// /// 根据id获取用户信息 /// /// 用户id /// public int GetMobileAccountid(string Mobile) { return _acc.GetMobileAccountid(Mobile); } /// /// 根据登录名获取用户信息 /// /// /// public Account GetAccount(string loginName,string companyRemark) { return _acc.GetAccount(loginName, companyRemark); } /// /// 根据WX标识获取用户信息 /// /// /// public Account GetAccount(string WXopenid) { return _acc.GetAccount(WXopenid); } /// /// 获取预警配置基本信息--邮件/微信 /// /// /// public AccountAlarm GetAlarmInfo(int id) { return _acc.GetAlarmInfo(id); } /// /// 判断用户是否存在 /// /// /// /// public bool ExistAccount(Account account, bool ModifyFlag) { return _acc.ExistAccount(account, ModifyFlag); } /// /// 判断用户是否存在Reg /// /// /// public bool ExistAccount(Account account) { return _acc.ExistAccount(account); } /// /// 判断用户名称是否重名 /// /// /// /// public bool ExistAccountRealName(Account account, bool ModifyFlag) { return _acc.ExistAccountRealName(account, ModifyFlag); } /// /// 判断机构名称是否重名 /// /// /// /// public bool ExistAccountCompanyName(Account account, bool ModifyFlag) { return _acc.ExistAccountCompanyName(account, ModifyFlag); } /// /// 添加用户账户信息 /// /// /// public int AddAccount(Account account) { if (account.RoleId==(int)UserRoleType.CommonAdmin) { account.CurrentTypeId = -3; account.CurrentTypeName = "accountManagement"; account.CurrentRedirect = "accountManagement"; } else if (account.RoleId == (int)UserRoleType.User) { account.CurrentTypeId = 3; account.CurrentTypeName = "newdiligenceTools"; account.CurrentRedirect = "newsFlashEx_tool"; } return _acc.AddAccount(account); } /// /// 修改用户账户信息 /// /// /// public bool UpdateAccount(Account account) { return _acc.UpdateAccount(account); } /// /// 修改当前版本状态 /// /// /// /// public bool UpdCurrentTypeId(int CurrentTypeId,string CurrentTypeName,string Redirect, int Id) { return _acc.UpdCurrentTypeId(CurrentTypeId, CurrentTypeName,Redirect, Id); } /// /// 更新用户基本信息 /// /// /// public bool UpdateAccountBasic(Account account) { return _acc.UpdateAccountBasic(account); } /// /// 更新用户基本信息 /// /// /// public bool UpdateAccountAddress(Account account) { return _acc.UpdateAccountAddress(account); } /// /// 绑定微信账户-登录 /// /// /// /// /// /// public bool BindWXAccount(string userName, string password, string companyRemark, string WXopenid,string WXunionid) { return _acc.BindWXAccount(userName, password, companyRemark, WXopenid,WXunionid); } /// /// 绑定微信账户-预警 /// /// /// /// /// /// public bool BindWXAlarmAccount(string userName, string password, string companyRemark, string AlarmWXId) { return _acc.BindWXAlarmAccount(userName, password, companyRemark, AlarmWXId); } /// /// 处理登录具体任务 /// /// /// public string HandelLoginAction(Account user) { //更新登录时间 user.LastLoginTime = DateTime.Now; user.LastLoginIp = Net.Ip; _acc.UpdateLastLogin(user); var token = Guid.NewGuid().ToString(); var model = new Operator() { UserId = user.Id, Password = user.Password, LoginName = user.LoginName, RealName = user.RealName, LoginTime = user.LastLoginTime, UserType = user.RoleId, Token = token, Avator = "https://file.iviewui.com/dist/a0e88e83800f138b94d2414621bd9704.png" }; OperatorProvider.Instance.Current = model; //寻找之前是否有同名账号登录,如果登录就剔除旧的缓存 string TokenOld = (string)CacheHelper.GetCache(user.Id.ToString()); if (TokenOld != null) { CacheHelper.RemoveKeyCache(user.Id.ToString()); } TimeSpan SessTimeOut = new TimeSpan(0, 0, System.Web.HttpContext.Current.Session.Timeout, 0, 0); CacheHelper.SetCache(user.Id.ToString(), token, DateTime.MaxValue, SessTimeOut); //如果记录为9 则回退至项目管理 if (user.CurrentTypeId == 9) { _acc.UpdCurrentTypeId(2, "_homeEx", "homeEx", user.Id); } return token; } /// /// 更新标准版默认的ProjId和Mode /// /// /// public bool UpdateDefaultProjIdMode(Account model) { return _acc.UpdateDefaultProjIdMode(model); } /// /// 更新是否启用主标尺的标识 /// /// /// /// public bool UpdateRateGradeFlag(int id, bool RateGradeFlag) { return _acc.UpdateRateGradeFlag(id, RateGradeFlag); } /// /// 企业监控邮件告警配置 /// /// /// /// /// /// public bool UpdateAlarmEmail(int id, bool AlarmEmailFlag, string AlarmEmail, string AlarmEmailGrade) { return _acc.UpdateAlarmEmail(id, AlarmEmailFlag, AlarmEmail, AlarmEmailGrade); } /// /// 企业监控邮件告警配置 /// /// /// /// /// /// public bool UpdateAlarmWX(int id, bool AlarmWXFlag, string AlarmWXId, string AlarmWXGrade) { return _acc.UpdateAlarmWX(id, AlarmWXFlag, AlarmWXId, AlarmWXGrade); } /// /// 融资监控邮件告警配置 /// /// /// /// /// /// public bool UpdateAlarmRZEmail(int id, bool AlarmEmailRZFlag, string AlarmEmailRZ) { return _acc.UpdateAlarmRZEmail(id, AlarmEmailRZFlag, AlarmEmailRZ); } /// /// 融资监控邮件告警配置 /// /// /// /// /// /// public bool UpdateAlarmRZWX(int id, bool AlarmWXRZFlag, string AlarmWXRZId) { return _acc.UpdateAlarmRZWX(id, AlarmWXRZFlag, AlarmWXRZId); } /// /// 更新最后登录时间和ip /// /// /// public bool UpdateLastLogin(Account model) { try { return _acc.UpdateLastLogin(model); } catch (System.Exception e) { LogHelper.Write(Level.Error, "更新最后登录时间和ip UpdateLastLogin", e, OperatorProvider.Instance.Current==null?"GuestEx":OperatorProvider.Instance.Current.LoginName); return false; } } /// /// 添加企业管理员后更新CompanyId /// /// /// /// public bool UpdateCompanyIdbyId(int id, int CompanyId) { return _acc.UpdateCompanyIdbyId(id, CompanyId); } /// /// 修改密码 /// /// 用户id /// 密码(已加密) /// public bool ChangePassword(int userid, string pwd) { return _acc.ChangePassword(userid, pwd); } /// /// 删除当前单独账号 /// /// /// /// public bool DeleteAccountbyId(int id,string UserName) { //删除当前账号下的所有项目 ProjectBLL projectBll = new ProjectBLL(); projectBll.DeleteProjectbyAccountId(id, UserName); return _acc.DeleteAccountbyId(id); } /// /// 删除当前账号的所有子账号 /// /// /// /// public bool DeleteAccountbyCompanyId(int RoleId, int CompanyId) { //删除所有账号下的所有项目 var listAccount = _acc.GetAccountList(RoleId, CompanyId); if (listAccount != null && listAccount.Count > 0) { ProjectBLL projectBll = new ProjectBLL(); for (int i = 0; i < listAccount.Count; i++) { projectBll.DeleteProjectbyAccountId(listAccount[i].Id,listAccount[i].LoginName); } } return _acc.DeleteAccountbyCompanyId(CompanyId); } /// /// 获取账号数量 /// /// /// public int GetAccountNum(int CompanyId) { return _acc.GetAccountNum(CompanyId); } /// /// 获取用户初始化标签 /// /// /// public bool[] GetUserFlag(int ProjId, int UserId, ref Project project) { bool[] bFlag = { true, false }; ProjectBLL projectBll = new ProjectBLL(); project = projectBll.GetProjOverview(ProjId); if (project != null) { //比较基础年利率与项目年利率是否一致 //true代表一致无需更新,false代表不一致需要更新 RateBaseBLL rateBaseBll = new RateBaseBLL(); List listRateBases = rateBaseBll.GetRateBaseList(0); //基础年利率 RateCompanyBLL rateCompanyBll = new RateCompanyBLL(); List listRateCompanies = rateCompanyBll.GetRateCompanyListSrc(ProjId, true, 0); if (listRateBases != null && listRateCompanies != null && listRateBases.Count == listRateCompanies.Count) { for (int i = 0; i < listRateBases.Count; i++) { if (listRateBases[i].Days != listRateCompanies[i].Days || listRateBases[i].RatesBase != listRateCompanies[i].RatesBase) { bFlag[0] = false; break; } } } else { bFlag[0] = false; } //是否需要显示处理项目流程按钮 //true代表需要显示,false代表不要显示 if (UserId == project.CurrentUserId && project.ProjStateShow) { bFlag[1] = true; } } return bFlag; } #region 极速版 /// /// 获取用户初始化标签 极速版 /// /// /// public bool[] GetUserFlagEx(int ProjId,int UserId,ref ProjectEx project) { bool []bFlag = {true,false}; ProjectExBLL projectBll = new ProjectExBLL(); project = projectBll.GetProjOverview(ProjId); if (project!=null) { //比较基础年利率与项目年利率是否一致 //true代表一致无需更新,false代表不一致需要更新 RateBaseBLL rateBaseBll =new RateBaseBLL(); List listRateBases = rateBaseBll.GetRateBaseList(0); //基础年利率 RateCompanyBLL rateCompanyBll = new RateCompanyBLL(); List listRateCompanies = rateCompanyBll.GetRateCompanyListSrc(ProjId, true, 0); if (listRateBases != null && listRateCompanies != null && listRateBases.Count == listRateCompanies.Count) { for (int i = 0; i < listRateBases.Count; i++) { if (listRateBases[i].Days != listRateCompanies[i].Days || listRateBases[i].RatesBase != listRateCompanies[i].RatesBase) { bFlag[0] = false; break; } } } else { bFlag[0] = false; } //是否需要显示处理项目流程按钮 //true代表需要显示,false代表不要显示 if (UserId == project.CurrentUserId && project.ProjStateShow) { bFlag[1] = true; } } return bFlag; } /// /// 更新默认的ProjIdEx /// /// /// public bool UpdateDefaultProjIdModeEx(Account model) { return _acc.UpdateDefaultProjIdModeEx(model); } #endregion } }