|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137 |
- using Learun.Cache.Base;
- using Learun.Cache.Factory;
- using Learun.Util;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Drawing;
- using Learun.Application.WeChat;
- using System.Configuration;
- using System.Linq;
-
- namespace Learun.Application.Organization
- {
- /// <summary>
- /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
- /// Copyright (c) 2013-2018 北京泉江科技有限公司
- /// 创建人:陈彬彬
- /// 日 期:2017.03.06
- /// 描 述:用户模块业务类
- /// </summary>
- public class UserBLL : UserIBLL
- {
- #region 属性
- private UserService userService = new UserService();
- private DepartmentIBLL departmentIBLL = new DepartmentBLL();
- #endregion
-
- #region 缓存定义
- private ICache cache = CacheFactory.CaChe();
- private string cacheKey = "learun_adms_user_"; // +公司主键
- private string cacheKeyAccount = "learun_adms_user_account_";// +用户账号(账号不允许改动)
- private string cacheKeyId = "learun_adms_user_Id_";// +用户账号(账号不允许改动)
- #endregion
-
- #region 获取数据
- /// <summary>
- /// 用户列表(根据公司主键)
- /// </summary>
- /// <param name="companyId">公司主键</param>
- /// <returns></returns>
- public List<UserEntity> GetList(string companyId)
- {
- try
- {
- if (string.IsNullOrEmpty(companyId))
- {
- return new List<UserEntity>();
- }
-
- List<UserEntity> list = cache.Read<List<UserEntity>>(cacheKey + companyId, CacheId.user);
- if (list == null)
- {
- list = (List<UserEntity>)userService.GetList(companyId);
- cache.Write<List<UserEntity>>(cacheKey + companyId, list, CacheId.user);
- }
- return list;
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- /// <summary>
- /// 用户列表(根据公司主键,部门主键)
- /// </summary>
- /// <param name="companyId">公司主键</param>
- /// <param name="departmentId">部门主键</param>
- /// <param name="keyword">查询关键词</param>
- /// <returns></returns>
- public List<UserEntity> GetList(string companyId, string departmentId, string keyword)
- {
- try
- {
-
-
- List<UserEntity> list = GetList(companyId);
- if (!string.IsNullOrEmpty(departmentId))
- {
- list = list.FindAll(t => t.F_DepartmentId.ContainsEx(departmentId));
- }
- if (!string.IsNullOrEmpty(keyword))
- {
- list = list.FindAll(t => t.F_RealName.ContainsEx(keyword) || t.F_Account.ContainsEx(keyword));
- }
- return list;
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
-
- public bool GetAny()
- {
- try
- {
-
- return userService.GetAny();
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
-
-
- public bool GetStuAny()
- {
- try
- {
-
- return userService.GetStuAny();
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- /// <summary>
- /// 用户列表(全部)
- /// </summary>
- /// <returns></returns>
- public List<UserEntity> GetAllList()
- {
- try
- {
- return (List<UserEntity>)userService.GetAllList();
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
-
- public void UpdateEntity(UserEntity entity)
- {
- try
- {
- userService.UpdateEntity(entity);
-
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
-
- /// <summary>
- /// 用户列表(根据部门主键)
- /// </summary>
- /// <param name="departmentId">部门主键</param>
- /// <returns></returns>
- public List<UserEntity> GetListByDepartmentId(string departmentId)
- {
- try
- {
- if (string.IsNullOrEmpty(departmentId))
- {
- return new List<UserEntity>();
- }
- DepartmentEntity departmentEntity = departmentIBLL.GetEntity(departmentId);
- if (departmentEntity == null)
- {
- return new List<UserEntity>();
- }
- return GetList(departmentEntity.F_CompanyId, departmentId, "");
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- public List<UserEntity> GetUserByDepartmentId(string departmentId)
- {
- try
- {
- return userService.GetUserByDepartmentId(departmentId);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
-
- /// <summary>
- /// 获取分页数据
- /// </summary>
- /// <param name="companyId">公司主键</param>
- /// <param name="departmentId">部门主键</param>
- /// <param name="pagination">分页参数</param>
- /// <param name="keyword">查询关键词</param>
- /// <param name="tp">0 教师 1学生</param>
- /// <returns></returns>
- public List<UserEntity> GetPageList(string companyId, string departmentId, Pagination pagination, string keyword, string tp)
- {
- try
- {
- return (List<UserEntity>)userService.GetPageList(companyId, departmentId, pagination, keyword, tp);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- /// <summary>
- /// 用户列表(导出Excel)
- /// </summary>
- /// <returns></returns>
- public void GetExportList()
- {
- try
- {
- //取出数据源
- DataTable exportTable = userService.GetExportList();
- //设置导出格式
- ExcelConfig excelconfig = new ExcelConfig();
- excelconfig.Title = "教师用户导出";
- excelconfig.TitleFont = "微软雅黑";
- excelconfig.TitlePoint = 25;
- excelconfig.FileName = "教师用户导出.xls";
- excelconfig.IsAllSizeColumn = true;
- //每一列的设置,没有设置的列信息,系统将按datatable中的列名导出
- excelconfig.ColumnEntity = new List<ColumnModel>();
- excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_account", ExcelColumn = "账户" });
- excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_realname", ExcelColumn = "姓名" });
- excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_gender", ExcelColumn = "性别" });
- excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_enabledmark", ExcelColumn = "状态" });
- excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_birthday", ExcelColumn = "生日" });
- excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_mobile", ExcelColumn = "手机" });
- excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_telephone", ExcelColumn = "电话" });
- excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_wechat", ExcelColumn = "微信" });
- excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_company", ExcelColumn = "学校" });
- excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_department", ExcelColumn = "部门" });
- excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_description", ExcelColumn = "说明" });
- excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_createdate", ExcelColumn = "创建日期" });
- excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_createusername", ExcelColumn = "创建人" });
- //调用导出方法
- ExcelHelper.ExcelDownload(exportTable, excelconfig);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- /// <summary>
- /// 用户列表(导出Excel)【学生】
- /// </summary>
- /// <returns></returns>
- public void GetExportListOfStudent()
- {
- try
- {
- //取出数据源
- DataTable exportTable = userService.GetExportListOfStudent();
- //设置导出格式
- ExcelConfig excelconfig = new ExcelConfig();
- excelconfig.Title = "学生用户导出";
- excelconfig.TitleFont = "微软雅黑";
- excelconfig.TitlePoint = 25;
- excelconfig.FileName = "学生用户导出.xls";
- excelconfig.IsAllSizeColumn = true;
- //每一列的设置,没有设置的列信息,系统将按datatable中的列名导出
- excelconfig.ColumnEntity = new List<ColumnModel>();
- excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_account", ExcelColumn = "账户" });
- excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_realname", ExcelColumn = "姓名" });
- excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_gender", ExcelColumn = "性别" });
- excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_birthday", ExcelColumn = "生日" });
- excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_mobile", ExcelColumn = "手机" });
- excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_telephone", ExcelColumn = "电话" });
- excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_wechat", ExcelColumn = "微信" });
- excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_company", ExcelColumn = "学校" });
- excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_department", ExcelColumn = "系部" });
- excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_description", ExcelColumn = "说明" });
- excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_createdate", ExcelColumn = "创建日期" });
- excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_createusername", ExcelColumn = "创建人" });
- //调用导出方法
- ExcelHelper.ExcelDownload(exportTable, excelconfig);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- /// <summary>
- /// 获取实体,通过用户账号
- /// </summary>
- /// <param name="account">用户账号</param>
- /// <returns></returns>
- public UserEntity GetEntityByAccount(string account)
- {
- try
- {
- UserEntity userEntity;
- userEntity = userService.GetEntityByAccount(account);
- return userEntity;
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
-
- public void UpdateIp(string ip, string id)
- {
- try
- {
- userService.UpdateIp(ip, id);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
-
- /// <summary>
- /// 获取用户数据
- /// </summary>
- /// <param name="userId">用户主键</param>
- /// <returns></returns>
- public UserEntity GetEntityByUserId(string userId)
- {
- try
- {
- UserEntity userEntity = cache.Read<UserEntity>(cacheKeyId + userId, CacheId.user);
- //if (userEntity == null)
- //{
- userEntity = userService.GetEntity(userId);
- if (userEntity != null)
- {
- cache.Write<string>(cacheKeyAccount + userEntity.F_Account, userId, CacheId.user);
- cache.Write<UserEntity>(cacheKeyId + userId, userEntity, CacheId.user);
- }
- //}
- return userEntity;
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
-
- public List<UserEntity> GetStudents()
- {
- try
- {
- return userService.GetStudents();
-
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
-
- public UserEntity GetEntityByWeixinOpenId(string openid)
- {
- try
- {
- UserEntity userEntity;
- userEntity = userService.GetEntityByWeixinOpenId(openid);
- return userEntity;
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
-
- public void UpdateWeixinOpenId(string keyValue, string openid)
- {
- try
- {
- userService.UpdateWeixinOpenId(keyValue, openid);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
-
- /// <summary>
- /// 获取超级管理员用户列表
- /// </summary>
- /// <returns></returns>
- public IEnumerable<UserEntity> GetAdminList()
- {
- try
- {
- return userService.GetAdminList();
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
-
-
- /// <summary>
- /// 获取用户列表数据
- /// </summary>
- /// <param name="userIds">用户主键串</param>
- /// <returns></returns>
- public List<UserEntity> GetListByUserIds(string userIds)
- {
- try
- {
- if (string.IsNullOrEmpty(userIds))
- {
- return null;
- }
- List<UserEntity> list = new List<UserEntity>();
- string[] userList = userIds.Split(',');
- foreach (string userId in userList)
- {
- UserEntity userEntity = GetEntityByUserId(userId);
- if (userEntity != null)
- {
- list.Add(userEntity);
- }
- }
-
-
- return list;
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
-
- public List<UserEntity> GetSaveClassMap()
- {
- try
- {
- var list = userService.GetAllList();
- return list.ToList();
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
-
- /// <summary>
- /// 获取映射数据
- /// </summary>
- /// <returns></returns>
- public Dictionary<string, UserModel> GetModelMap()
- {
- try
- {
- Dictionary<string, UserModel> dic = cache.Read<Dictionary<string, UserModel>>(cacheKey + "dic", CacheId.user);
- if (dic == null)
- {
- dic = new Dictionary<string, UserModel>();
- var list = userService.GetAllList();
- foreach (var item in list)
- {
- UserModel model = new UserModel()
- {
- companyId = item.F_CompanyId,
- departmentId = item.F_DepartmentId,
- name = item.F_RealName,
- };
- string img = "";
- if (!string.IsNullOrEmpty(item.F_HeadIcon))
- {
- string fileHeadImg = Config.GetValue("fileHeadImg");
- string fileImg = string.Format("{0}/{1}{2}", fileHeadImg, item.F_UserId, item.F_HeadIcon);
- if (DirFileHelper.IsExistFile(fileImg))
- {
- img = item.F_HeadIcon;
- }
- }
- if (string.IsNullOrEmpty(img))
- {
- if (item.F_Gender == 0)
- {
- img = "0";
- }
- else
- {
- img = "1";
- }
- }
- model.img = img;
- dic.Add(item.F_UserId, model);
- cache.Write(cacheKey + "dic", dic, CacheId.user);
- }
- }
- return dic;
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
-
- #endregion
-
- #region 提交数据
- /// <summary>
- /// 虚拟删除
- /// </summary>
- /// <param name="keyValue">主键</param>
- public void VirtualDelete(string keyValue)
- {
- try
- {
- UserEntity userEntity = GetEntityByUserId(keyValue);
- cache.Remove(cacheKey + userEntity.F_CompanyId, CacheId.user);
- cache.Remove(cacheKeyId + keyValue, CacheId.user);
- cache.Remove(cacheKeyAccount + userEntity.F_Account, CacheId.user);
-
- Dictionary<string, UserModel> dic = GetModelMap();
- dic.Remove(keyValue);
- cache.Write(cacheKey + "dic", dic, CacheId.department);
-
-
- userService.VirtualDelete(keyValue);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- /// <summary>
- /// 虚拟删除(批量)
- /// </summary>
- /// <param name="keyValue">主键</param>
- public void VirtualDeleteBatch(string keyValue)
- {
- try
- {
- foreach (var item in keyValue.Split(','))
- {
- UserEntity userEntity = GetEntityByUserId(item);
- cache.Remove(cacheKey + userEntity.F_CompanyId, CacheId.user);
- cache.Remove(cacheKeyId + item, CacheId.user);
- cache.Remove(cacheKeyAccount + userEntity.F_Account, CacheId.user);
-
- Dictionary<string, UserModel> dic = GetModelMap();
- dic.Remove(item);
- cache.Write(cacheKey + "dic", dic, CacheId.department);
- }
-
- userService.VirtualDeleteBatch(keyValue);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- /// <summary>
- /// 保存用户表单(新增、修改)
- /// </summary>
- /// <param name="keyValue">主键值</param>
- /// <param name="userEntity">用户实体</param>
- /// <returns></returns>
- public void SaveEntity(string keyValue, UserEntity userEntity)
- {
- try
- {
- cache.Remove(cacheKey + userEntity.F_CompanyId, CacheId.user);
- cache.Remove(cacheKeyId + keyValue, CacheId.user);
- cache.Remove(cacheKeyAccount + userEntity.F_Account, CacheId.user);
- cache.Remove(cacheKey + "dic", CacheId.user);
-
-
- if (!string.IsNullOrEmpty(keyValue))
- {
- userEntity.F_Account = null;// 账号不允许改动
- }
-
- userService.SaveEntity(keyValue, userEntity);
-
-
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- /// <summary>
- /// 修改用户登录密码
- /// </summary>
- /// <param name="newPassword">新密码(MD5 小写)</param>
- /// <param name="oldPassword">旧密码(MD5 小写)</param>
- public bool RevisePassword(string newPassword, string oldPassword)
- {
- try
- {
- UserInfo userInfo = LoginUserInfo.Get();
- cache.Remove(cacheKeyId + userInfo.userId, CacheId.user);
- cache.Remove(cacheKeyAccount + userInfo.account, CacheId.user);
-
- var entity = userService.GetEntity(userInfo.userId);
- string oldPasswordByEncrypt = Md5Helper.Encrypt(DESEncrypt.Encrypt(oldPassword, entity.F_Secretkey).ToLower(), 32).ToLower();
- if (oldPasswordByEncrypt == entity.F_Password)
- {
- userService.RevisePassword(userInfo.userId, newPassword);
- }
- else
- {
- return false;
- }
- return true;
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- /// <summary>
- /// 重置密码
- /// </summary>
- /// <param name="keyValue">账号主键</param>
- public void ResetPassword(string keyValue)
- {
- try
- {
- //单个
- //cache.Remove(cacheKeyId + keyValue, CacheId.user);
- //string password = Md5Helper.Encrypt("123456", 32).ToLower();
- //userService.RevisePassword(keyValue, password);
-
- //批量
- foreach (var item in keyValue.Split(','))
- {
- cache.Remove(cacheKeyId + item, CacheId.user);
- }
- string password = Md5Helper.Encrypt(ConfigurationManager.AppSettings["defaultpwd"], 32).ToLower();
- userService.RevisePasswordBatch(keyValue, password);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- public void setPassword(string userid,string pwd)
- {
- try
- {
- userService.RevisePassword(userid,pwd);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- /// <summary>
- /// 重置密码(八位)
- /// </summary>
- /// <param name="keyValue">账号主键</param>
- public void ResetPasswordEight(string keyValue)
- {
- try
- {
- foreach (var item in keyValue.Split(','))
- {
- cache.Remove(cacheKeyId + item, CacheId.user);
- }
- string password = Md5Helper.Encrypt(ConfigurationManager.AppSettings["defaultpwdeight"], 32).ToLower();
- userService.RevisePasswordBatch(keyValue, password);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- /// <summary>
- /// 修改用户状态
- /// </summary>
- /// <param name="keyValue">主键值</param>
- /// <param name="state">状态:1-启动;0-禁用</param>
- public void UpdateState(string keyValue, int state)
- {
- try
- {
- UserEntity userEntity = GetEntityByUserId(keyValue);
- cache.Remove(cacheKey + userEntity.F_CompanyId, CacheId.user);
- cache.Remove(cacheKeyId + keyValue, CacheId.user);
- cache.Remove(cacheKeyAccount + userEntity.F_Account, CacheId.user);
- cache.Remove(cacheKey + "dic", CacheId.user);
- userService.UpdateState(keyValue, state);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- /// <summary>
- /// 保存用户的设备号
- /// </summary>
- /// <param name="keyValue">主键</param>
- /// <param name="deviceId">设备号</param>
- public void UpdateDeviceId(string keyValue, string deviceId)
- {
- try
- {
- userService.UpdateDeviceId(keyValue, deviceId);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
-
- /// <summary>
- /// 解绑微信
- /// </summary>
- public void DoUnbundWeiXin(string keyValue)
- {
- try
- {
- userService.DoUnbundWeiXin(keyValue);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- #endregion
-
- #region 验证数据
- /// <summary>
- /// 账户不能重复
- /// </summary>
- /// <param name="account">账户值</param>
- /// <param name="keyValue">主键</param>
- /// <returns></returns>
- public bool ExistAccount(string account, string keyValue)
- {
- try
- {
- return userService.ExistAccount(account, keyValue);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- #endregion
-
- #region 扩展方法
- /// <summary>
- /// 验证登录
- /// </summary>
- /// <param name="account">账号</param>
- /// <param name="password">密码 MD5 32位 小写</param>
- /// <returns></returns>
- public UserEntity CheckLogin(string account, string password)
- {
- ////调用微信开放平台接口获得Token、OpenId
- //string appid = Config.GetValue("AppId");
- //string appsecret = Config.GetValue("AppSecret");
- //OpenTokenGet openTokenGet = new OpenTokenGet();
- //openTokenGet.appid = appid;
- //openTokenGet.secret = appsecret;
- //openTokenGet.code = "0815LTNN0EEei42rURNN0z5QNN05LTNS";
- //OpenTokenGetResult openInfo = openTokenGet.OpenSend();
- //string openid = openInfo.openid;
- //string token = openInfo.access_token;
- ////调用微信开放平台接口获得登录用户个人信息
- //OpenUserGet openuser = new OpenUserGet();
- //openuser.openid = openid;
- //openuser.access_token = token;
- //OpenUserGetResult userinfo = openuser.OpenSend();
- try
- {
- UserEntity userEntity = GetEntityByAccount(account);
- if (userEntity == null)
- {
- userEntity = new UserEntity()
- {
- LoginMsg = "账户不存在!",
- LoginOk = false
- };
- return userEntity;
- }
- userEntity.LoginOk = false;
- if (userEntity.F_EnabledMark == 1)
- {
- string dbPassword = Md5Helper.Encrypt(DESEncrypt.Encrypt(password.ToLower(), userEntity.F_Secretkey).ToLower(), 32).ToLower();
- if (dbPassword == userEntity.F_Password)
- {
- userEntity.LoginOk = true;
- }
- else
- {
- userEntity.LoginMsg = "密码和账户名不匹配!";
- }
- }
- else
- {
- userEntity.LoginMsg = "账户被系统锁定,请联系管理员!";
- }
- return userEntity;
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- /// <summary>
- /// 获取用户头像
- /// </summary>
- /// <param name="userId">用户ID</param>
- public void GetImg(string userId)
- {
- UserEntity entity = GetEntityByUserId(userId);
- string img = "";
- string fileHeadImg = Config.GetValue("fileHeadImg");
- string fileHeadImg2 = Config.GetValue("AnnexesFile");
- if (entity != null)
- {
- if (!string.IsNullOrEmpty(entity.F_HeadIcon))
- {
- string fileImg;
- //if (entity.F_Description == "管理员")
- //{
- // fileImg = string.Format("{0}/{1}{2}", fileHeadImg, entity.F_UserId, entity.F_HeadIcon);
- //}
- //else
- //{
-
- fileImg = $"{ Config.GetValue("AnnexesFile")}{entity.F_HeadIcon.Substring(9, entity.F_HeadIcon.Length - 9)}";
- //}
- if (DirFileHelper.IsExistFile(fileImg))
- {
- img = fileImg;
- }
- }
- }
- else
- {
- img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
- }
- if (string.IsNullOrEmpty(img))
- {
- if (entity.F_Gender == 0)
- {
- //img = string.Format("{0}/{1}", fileHeadImg, "on-girl.jpg");
- img = $"{fileHeadImg2.Substring(0, fileHeadImg2.Length - 9)}{entity.F_HeadIcon}";
-
- }
- else
- {
- //img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
- img = $"{fileHeadImg2.Substring(0, fileHeadImg2.Length - 9)}{entity.F_HeadIcon}";
- }
- }
- FileDownHelper.DownLoadnew(img);
- }
-
- public void GetImgForDC(string userId)
- {
- string filepath="";
- UserEntity entity = GetEntityByUserId(userId);
- if (entity!=null)
- {
-
- }
- }
-
-
- ///// <summary>
- ///// 获取用户头像
- ///// </summary>
- ///// <param name="userId">用户ID</param>
- //public void GetImg(string userId)
- //{
- // UserEntity entity = GetEntityByUserId(userId);
- // string img = "";
- // string fileHeadImg = Config.GetValue("fileHeadImg");
- // if (entity != null)
- // {
- // if (!string.IsNullOrEmpty(entity.F_HeadIcon))
- // {
- // string fileImg = string.Format("{0}/{1}{2}", fileHeadImg, entity.F_UserId, entity.F_HeadIcon);
- // if (DirFileHelper.IsExistFile(fileImg))
- // {
- // img = fileImg;
- // }
- // }
- // }
- // else
- // {
- // img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
- // }
- // if (string.IsNullOrEmpty(img))
- // {
- // if (entity.F_Gender == 0)
- // {
- // img = string.Format("{0}/{1}", fileHeadImg, "on-girl.jpg");
- // }
- // else
- // {
- // img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
- // }
- // }
- // FileDownHelper.DownLoadnew(img);
- //}
- #endregion
- }
- }
|