UserBLL.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. using LeaRun.Application.Entity.BaseManage;
  2. using LeaRun.Application.Entity.MessageManage;
  3. using LeaRun.Application.IService.BaseManage;
  4. using LeaRun.Application.Service.BaseManage;
  5. using LeaRun.Cache.Factory;
  6. using LeaRun.Util;
  7. using LeaRun.Util.Extension;
  8. using LeaRun.Util.Offices;
  9. using LeaRun.Util.SignalR;
  10. using LeaRun.Util.WebControl;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Data;
  14. using System.Drawing;
  15. using LeaRun.Application.Code;
  16. namespace LeaRun.Application.Busines.BaseManage
  17. {
  18. /// <summary>
  19. /// 版 本
  20. /// Copyright (c) 2013-2016 上海力软信息技术有限公司
  21. /// 创建人:佘赐雄
  22. /// 日 期:2015.11.03 10:58
  23. /// 描 述:用户管理
  24. /// </summary>
  25. public class UserBLL
  26. {
  27. private IUserService service = new UserService();
  28. /// <summary>
  29. /// 缓存key
  30. /// </summary>
  31. public string cacheKey = "userCache";
  32. #region 获取数据
  33. /// <summary>
  34. /// 用户列表
  35. /// </summary>
  36. /// <returns></returns>
  37. public DataTable GetTable()
  38. {
  39. return service.GetTable();
  40. }
  41. /// <summary>
  42. /// 用户列表
  43. /// </summary>
  44. /// <returns></returns>
  45. public IEnumerable<UserEntity> GetList()
  46. {
  47. return service.GetList();
  48. }
  49. /// <summary>
  50. /// 用户列表
  51. /// </summary>
  52. /// <param name="pagination">分页</param>
  53. /// <param name="queryJson">查询参数</param>
  54. /// <returns></returns>
  55. public IEnumerable<UserEntity> GetPageList(Pagination pagination, string queryJson)
  56. {
  57. return service.GetPageList(pagination, queryJson);
  58. }
  59. /// <summary>
  60. /// 用户列表(ALL)
  61. /// </summary>
  62. /// <returns></returns>
  63. public DataTable GetAllTable()
  64. {
  65. return service.GetAllTable();
  66. }
  67. /// <summary>
  68. /// 用户实体
  69. /// </summary>
  70. /// <param name="keyValue">主键值</param>
  71. /// <returns></returns>
  72. public UserEntity GetEntity(string keyValue)
  73. {
  74. return service.GetEntity(keyValue);
  75. }
  76. #endregion
  77. #region 验证数据
  78. /// <summary>
  79. /// 账户不能重复
  80. /// </summary>
  81. /// <param name="account">账户值</param>
  82. /// <param name="keyValue">主键</param>
  83. /// <returns></returns>
  84. public bool ExistAccount(string account, string keyValue = "")
  85. {
  86. return service.ExistAccount(account, keyValue);
  87. }
  88. #endregion
  89. #region 提交数据
  90. /// <summary>
  91. /// 删除用户
  92. /// </summary>
  93. /// <param name="keyValue">主键</param>
  94. public void RemoveForm(string keyValue)
  95. {
  96. try
  97. {
  98. service.RemoveForm(keyValue);
  99. CacheFactory.Cache().RemoveCache(cacheKey);
  100. UpdateIMUserList(keyValue,false,null);
  101. }
  102. catch (Exception)
  103. {
  104. throw;
  105. }
  106. }
  107. /// <summary>
  108. /// 保存用户表单(新增、修改)
  109. /// </summary>
  110. /// <param name="keyValue">主键值</param>
  111. /// <param name="userEntity">用户实体</param>
  112. /// <returns></returns>
  113. public string SaveForm(string keyValue, UserEntity userEntity)
  114. {
  115. try
  116. {
  117. keyValue = service.SaveForm(keyValue, userEntity);
  118. CacheFactory.Cache().RemoveCache(cacheKey);
  119. UpdateIMUserList(keyValue, true, userEntity);
  120. return keyValue;
  121. }
  122. catch (Exception)
  123. {
  124. throw;
  125. }
  126. }
  127. /// <summary>
  128. /// 修改用户登录密码
  129. /// </summary>
  130. /// <param name="keyValue">主键值</param>
  131. /// <param name="Password">新密码(MD5 小写)</param>
  132. public void RevisePassword(string keyValue, string Password)
  133. {
  134. try
  135. {
  136. service.RevisePassword(keyValue, Password);
  137. CacheFactory.Cache().RemoveCache(cacheKey);
  138. }
  139. catch (Exception)
  140. {
  141. throw;
  142. }
  143. }
  144. /// <summary>
  145. /// 修改用户状态
  146. /// </summary>
  147. /// <param name="keyValue">主键值</param>
  148. /// <param name="State">状态:1-启动;0-禁用</param>
  149. public void UpdateState(string keyValue, int State)
  150. {
  151. try
  152. {
  153. service.UpdateState(keyValue, State);
  154. CacheFactory.Cache().RemoveCache(cacheKey);
  155. if (State == 0)
  156. {
  157. UpdateIMUserList(keyValue, false, null);
  158. }
  159. else
  160. {
  161. UserEntity entity = service.GetEntity(keyValue);
  162. UpdateIMUserList(keyValue, true, entity);
  163. }
  164. }
  165. catch (Exception)
  166. {
  167. throw;
  168. }
  169. }
  170. /// <summary>
  171. /// 登录验证
  172. /// </summary>
  173. /// <param name="username">用户名</param>
  174. /// <param name="password">密码</param>
  175. /// <returns></returns>
  176. public UserEntity CheckLogin(string username, string password)
  177. {
  178. UserEntity userEntity = service.CheckLogin(username);
  179. if (userEntity != null)
  180. {
  181. if (userEntity.EnabledMark == 1)
  182. {
  183. string dbPassword = Md5Helper.MD5(DESEncrypt.Encrypt(password.ToLower(), userEntity.Secretkey).ToLower(), 32).ToLower();
  184. if (dbPassword == userEntity.Password)
  185. {
  186. DateTime LastVisit = DateTime.Now;
  187. int LogOnCount = (userEntity.LogOnCount).ToInt() + 1;
  188. if (userEntity.LastVisit != null)
  189. {
  190. userEntity.PreviousVisit = userEntity.LastVisit.ToDate();
  191. }
  192. userEntity.LastVisit = LastVisit;
  193. userEntity.LogOnCount = LogOnCount;
  194. userEntity.UserOnLine = 1;
  195. service.UpdateEntity(userEntity);
  196. return userEntity;
  197. }
  198. else
  199. {
  200. throw new Exception("密码和账户名不匹配");
  201. }
  202. }
  203. else
  204. {
  205. throw new Exception("账户名被系统锁定,请联系管理员");
  206. }
  207. }
  208. else
  209. {
  210. throw new Exception("账户不存在,请重新输入");
  211. }
  212. }
  213. /// <summary>
  214. /// 更新实时通信用户列表
  215. /// </summary>
  216. private void UpdateIMUserList(string keyValue, bool isAdd, UserEntity userEntity)
  217. {
  218. try
  219. {
  220. IMUserModel entity = new IMUserModel();
  221. OrganizeBLL bll = new OrganizeBLL();
  222. DepartmentBLL dbll = new DepartmentBLL();
  223. entity.UserId = keyValue;
  224. if (userEntity != null)
  225. {
  226. entity.RealName = userEntity.RealName;
  227. entity.DepartmentId = dbll.GetEntity(userEntity.DepartmentId).FullName;
  228. entity.Gender = (int)userEntity.Gender;
  229. entity.HeadIcon = userEntity.HeadIcon;
  230. entity.OrganizeId = bll.GetEntity(userEntity.OrganizeId).FullName; ;
  231. }
  232. SendHubs.callMethod("upDateUserList", entity, isAdd);
  233. }
  234. catch
  235. {
  236. }
  237. }
  238. #endregion
  239. #region 处理数据
  240. /// <summary>
  241. /// 导出用户列表
  242. /// </summary>
  243. /// <returns></returns>
  244. public void GetExportList()
  245. {
  246. //取出数据源
  247. DataTable exportTable = service.GetExportList();
  248. //设置导出格式
  249. ExcelConfig excelconfig = new ExcelConfig();
  250. excelconfig.Title = "测试用户导出";
  251. excelconfig.TitleFont = "微软雅黑";
  252. excelconfig.TitlePoint = 25;
  253. excelconfig.FileName = "用户导出.xls";
  254. excelconfig.IsAllSizeColumn = true;
  255. //每一列的设置,没有设置的列信息,系统将按datatable中的列名导出
  256. List<ColumnEntity> listColumnEntity = new List<ColumnEntity>();
  257. excelconfig.ColumnEntity = listColumnEntity;
  258. ColumnEntity columnentity = new ColumnEntity();
  259. excelconfig.ColumnEntity.Add(new ColumnEntity() { Column = "account", ExcelColumn = "账户" });
  260. excelconfig.ColumnEntity.Add(new ColumnEntity() { Column = "realname", ExcelColumn = "姓名" });
  261. excelconfig.ColumnEntity.Add(new ColumnEntity() { Column = "gender", ExcelColumn = "性别" });
  262. excelconfig.ColumnEntity.Add(new ColumnEntity() { Column = "birthday", ExcelColumn = "生日" });
  263. excelconfig.ColumnEntity.Add(new ColumnEntity() { Column = "mobile", ExcelColumn = "手机", Background = Color.Red });
  264. excelconfig.ColumnEntity.Add(new ColumnEntity() { Column = "telephone", ExcelColumn = "电话", Background = Color.Red });
  265. excelconfig.ColumnEntity.Add(new ColumnEntity() { Column = "wechat", ExcelColumn = "微信" });
  266. excelconfig.ColumnEntity.Add(new ColumnEntity() { Column = "manager", ExcelColumn = "主管" });
  267. excelconfig.ColumnEntity.Add(new ColumnEntity() { Column = "organize", ExcelColumn = "公司" });
  268. excelconfig.ColumnEntity.Add(new ColumnEntity() { Column = "department", ExcelColumn = "部门" });
  269. excelconfig.ColumnEntity.Add(new ColumnEntity() { Column = "description", ExcelColumn = "说明" });
  270. excelconfig.ColumnEntity.Add(new ColumnEntity() { Column = "createdate", ExcelColumn = "创建日期" });
  271. excelconfig.ColumnEntity.Add(new ColumnEntity() { Column = "createusername", ExcelColumn = "创建人" });
  272. //调用导出方法
  273. ExcelHelper.ExcelDownload(exportTable, excelconfig);
  274. //从泛型Lis导出
  275. //TExcelHelper<DepartmentEntity>.ExcelDownload(department.GetList().ToList(), excelconfig);
  276. }
  277. #endregion
  278. }
  279. }