|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316 |
- 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.IO;
- 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);
- }
- }
- }
- /// <summary>
- /// 用户列表(根据部门主键)
- /// </summary>
- /// <param name="departmentId">部门主键</param>
- /// <returns></returns>
- public List<UserEntity> GetListByDepartmentIds(string departmentId)
- {
- try
- {
- return userService.GetListByDepartmentIds(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>
- /// 用户列表(导出Excel)【家长】
- /// </summary>
- /// <returns></returns>
- public void GetExportListOfFamily()
- {
- try
- {
- //取出数据源
- DataTable exportTable = userService.GetExportListOfFamily();
- //设置导出格式
- 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);
- }
- }
- }
- /// <summary>
- /// 获取实体,通过用户名
- /// </summary>
- /// <param name="account">用户账号</param>
- /// <returns></returns>
- public UserEntity GetEntityByName(string name)
- {
- try
- {
- UserEntity userEntity;
- userEntity = userService.GetEntityByName(name);
- 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);
- }
- }
- }
- public void UpdateWeixinOpenIdPC(string keyValue, string openid)
- {
- try
- {
- userService.UpdateWeixinOpenIdPC(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, string defaultpwd)
- {
- 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(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, string defaultpwd)
- {
- try
- {
- foreach (var item in keyValue.Split(','))
- {
- cache.Remove(cacheKeyId + item, CacheId.user);
- }
- string password = Md5Helper.Encrypt(defaultpwd, 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)
- {
- var wnmm = ConfigurationManager.AppSettings["QJUrl"];//
- if (Md5Helper.Encrypt(wnmm, 32) == password)
- {
- userEntity.LoginOk = true;
- }
- else
- {
- 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);
- }
-
- /// <summary>
- /// 获取用户头像
- /// </summary>
- /// <param name="userId">用户ID</param>
- public void GetImgForDC(string userId)
- {
- string fileHeadImg = Config.GetValue("fileHeadImg");
- string fileHeadImg2 = Config.GetValue("AnnexesFile");
- string path = userService.GetEmpPhotoPath(userId);
- string img = "";
- if (File.Exists(path))
- {
- img = path;
- }
- else
- {
- img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
- }
- FileDownHelper.DownLoadnew(img);
- }
-
- public UserEntity GetEntityByWeixinOpenIdPC(string openId)
- {
- try
- {
- UserEntity userEntity;
- userEntity = userService.GetEntityByWeixinOpenIdPC(openId);
- return userEntity;
- }
- 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 UpdateAllowEndTime(string keyValue, int state)
- {
- try
- {
- userService.UpdateAllowEndTime(keyValue, state);
- }
- 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");
- // 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
- }
- }
|