You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1149 line
38 KiB

  1. using Learun.Cache.Base;
  2. using Learun.Cache.Factory;
  3. using Learun.Util;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Drawing;
  8. using Learun.Application.WeChat;
  9. using System.Configuration;
  10. using System.IO;
  11. using System.Linq;
  12. namespace Learun.Application.Organization
  13. {
  14. /// <summary>
  15. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  16. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  17. /// 创建人:陈彬彬
  18. /// 日 期:2017.03.06
  19. /// 描 述:用户模块业务类
  20. /// </summary>
  21. public class UserBLL : UserIBLL
  22. {
  23. #region 属性
  24. private UserService userService = new UserService();
  25. private DepartmentIBLL departmentIBLL = new DepartmentBLL();
  26. #endregion
  27. #region 缓存定义
  28. private ICache cache = CacheFactory.CaChe();
  29. private string cacheKey = "learun_adms_user_"; // +公司主键
  30. private string cacheKeyAccount = "learun_adms_user_account_";// +用户账号(账号不允许改动)
  31. private string cacheKeyId = "learun_adms_user_Id_";// +用户账号(账号不允许改动)
  32. #endregion
  33. #region 获取数据
  34. /// <summary>
  35. /// 用户列表(根据公司主键)
  36. /// </summary>
  37. /// <param name="companyId">公司主键</param>
  38. /// <returns></returns>
  39. public List<UserEntity> GetList(string companyId)
  40. {
  41. try
  42. {
  43. if (string.IsNullOrEmpty(companyId))
  44. {
  45. return new List<UserEntity>();
  46. }
  47. List<UserEntity> list = cache.Read<List<UserEntity>>(cacheKey + companyId, CacheId.user);
  48. if (list == null)
  49. {
  50. list = (List<UserEntity>)userService.GetList(companyId);
  51. cache.Write<List<UserEntity>>(cacheKey + companyId, list, CacheId.user);
  52. }
  53. return list;
  54. }
  55. catch (Exception ex)
  56. {
  57. if (ex is ExceptionEx)
  58. {
  59. throw;
  60. }
  61. else
  62. {
  63. throw ExceptionEx.ThrowBusinessException(ex);
  64. }
  65. }
  66. }
  67. /// <summary>
  68. /// 用户列表(根据公司主键,部门主键)
  69. /// </summary>
  70. /// <param name="companyId">公司主键</param>
  71. /// <param name="departmentId">部门主键</param>
  72. /// <param name="keyword">查询关键词</param>
  73. /// <returns></returns>
  74. public List<UserEntity> GetList(string companyId, string departmentId, string keyword)
  75. {
  76. try
  77. {
  78. List<UserEntity> list = GetList(companyId);
  79. if (!string.IsNullOrEmpty(departmentId))
  80. {
  81. list = list.FindAll(t => t.F_DepartmentId.ContainsEx(departmentId));
  82. }
  83. if (!string.IsNullOrEmpty(keyword))
  84. {
  85. list = list.FindAll(t => t.F_RealName.ContainsEx(keyword) || t.F_Account.ContainsEx(keyword));
  86. }
  87. return list;
  88. }
  89. catch (Exception ex)
  90. {
  91. if (ex is ExceptionEx)
  92. {
  93. throw;
  94. }
  95. else
  96. {
  97. throw ExceptionEx.ThrowBusinessException(ex);
  98. }
  99. }
  100. }
  101. public bool GetAny()
  102. {
  103. try
  104. {
  105. return userService.GetAny();
  106. }
  107. catch (Exception ex)
  108. {
  109. if (ex is ExceptionEx)
  110. {
  111. throw;
  112. }
  113. else
  114. {
  115. throw ExceptionEx.ThrowBusinessException(ex);
  116. }
  117. }
  118. }
  119. public bool GetStuAny()
  120. {
  121. try
  122. {
  123. return userService.GetStuAny();
  124. }
  125. catch (Exception ex)
  126. {
  127. if (ex is ExceptionEx)
  128. {
  129. throw;
  130. }
  131. else
  132. {
  133. throw ExceptionEx.ThrowBusinessException(ex);
  134. }
  135. }
  136. }
  137. /// <summary>
  138. /// 用户列表(全部)
  139. /// </summary>
  140. /// <returns></returns>
  141. public List<UserEntity> GetAllList()
  142. {
  143. try
  144. {
  145. return (List<UserEntity>)userService.GetAllList();
  146. }
  147. catch (Exception ex)
  148. {
  149. if (ex is ExceptionEx)
  150. {
  151. throw;
  152. }
  153. else
  154. {
  155. throw ExceptionEx.ThrowBusinessException(ex);
  156. }
  157. }
  158. }
  159. public void UpdateEntity(UserEntity entity)
  160. {
  161. try
  162. {
  163. userService.UpdateEntity(entity);
  164. }
  165. catch (Exception ex)
  166. {
  167. if (ex is ExceptionEx)
  168. {
  169. throw;
  170. }
  171. else
  172. {
  173. throw ExceptionEx.ThrowBusinessException(ex);
  174. }
  175. }
  176. }
  177. /// <summary>
  178. /// 用户列表(根据部门主键)
  179. /// </summary>
  180. /// <param name="departmentId">部门主键</param>
  181. /// <returns></returns>
  182. public List<UserEntity> GetListByDepartmentId(string departmentId)
  183. {
  184. try
  185. {
  186. if (string.IsNullOrEmpty(departmentId))
  187. {
  188. return new List<UserEntity>();
  189. }
  190. DepartmentEntity departmentEntity = departmentIBLL.GetEntity(departmentId);
  191. if (departmentEntity == null)
  192. {
  193. return new List<UserEntity>();
  194. }
  195. return GetList(departmentEntity.F_CompanyId, departmentId, "");
  196. }
  197. catch (Exception ex)
  198. {
  199. if (ex is ExceptionEx)
  200. {
  201. throw;
  202. }
  203. else
  204. {
  205. throw ExceptionEx.ThrowBusinessException(ex);
  206. }
  207. }
  208. }
  209. public List<UserEntity> GetUserByDepartmentId(string departmentId)
  210. {
  211. try
  212. {
  213. return userService.GetUserByDepartmentId(departmentId);
  214. }
  215. catch (Exception ex)
  216. {
  217. if (ex is ExceptionEx)
  218. {
  219. throw;
  220. }
  221. else
  222. {
  223. throw ExceptionEx.ThrowBusinessException(ex);
  224. }
  225. }
  226. }
  227. /// <summary>
  228. /// 获取分页数据
  229. /// </summary>
  230. /// <param name="companyId">公司主键</param>
  231. /// <param name="departmentId">部门主键</param>
  232. /// <param name="pagination">分页参数</param>
  233. /// <param name="keyword">查询关键词</param>
  234. /// <param name="tp">0 教师 1学生</param>
  235. /// <returns></returns>
  236. public List<UserEntity> GetPageList(string companyId, string departmentId, Pagination pagination, string keyword, string tp)
  237. {
  238. try
  239. {
  240. return (List<UserEntity>)userService.GetPageList(companyId, departmentId, pagination, keyword, tp);
  241. }
  242. catch (Exception ex)
  243. {
  244. if (ex is ExceptionEx)
  245. {
  246. throw;
  247. }
  248. else
  249. {
  250. throw ExceptionEx.ThrowBusinessException(ex);
  251. }
  252. }
  253. }
  254. /// <summary>
  255. /// 用户列表(导出Excel)
  256. /// </summary>
  257. /// <returns></returns>
  258. public void GetExportList()
  259. {
  260. try
  261. {
  262. //取出数据源
  263. DataTable exportTable = userService.GetExportList();
  264. //设置导出格式
  265. ExcelConfig excelconfig = new ExcelConfig();
  266. excelconfig.Title = "教师用户导出";
  267. excelconfig.TitleFont = "微软雅黑";
  268. excelconfig.TitlePoint = 25;
  269. excelconfig.FileName = "教师用户导出.xls";
  270. excelconfig.IsAllSizeColumn = true;
  271. //每一列的设置,没有设置的列信息,系统将按datatable中的列名导出
  272. excelconfig.ColumnEntity = new List<ColumnModel>();
  273. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_account", ExcelColumn = "账户" });
  274. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_realname", ExcelColumn = "姓名" });
  275. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_gender", ExcelColumn = "性别" });
  276. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_enabledmark", ExcelColumn = "状态" });
  277. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_birthday", ExcelColumn = "生日" });
  278. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_mobile", ExcelColumn = "手机" });
  279. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_telephone", ExcelColumn = "电话" });
  280. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_wechat", ExcelColumn = "微信" });
  281. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_company", ExcelColumn = "学校" });
  282. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_department", ExcelColumn = "部门" });
  283. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_description", ExcelColumn = "说明" });
  284. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_createdate", ExcelColumn = "创建日期" });
  285. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_createusername", ExcelColumn = "创建人" });
  286. //调用导出方法
  287. ExcelHelper.ExcelDownload(exportTable, excelconfig);
  288. }
  289. catch (Exception ex)
  290. {
  291. if (ex is ExceptionEx)
  292. {
  293. throw;
  294. }
  295. else
  296. {
  297. throw ExceptionEx.ThrowBusinessException(ex);
  298. }
  299. }
  300. }
  301. /// <summary>
  302. /// 用户列表(导出Excel)【学生】
  303. /// </summary>
  304. /// <returns></returns>
  305. public void GetExportListOfStudent()
  306. {
  307. try
  308. {
  309. //取出数据源
  310. DataTable exportTable = userService.GetExportListOfStudent();
  311. //设置导出格式
  312. ExcelConfig excelconfig = new ExcelConfig();
  313. excelconfig.Title = "学生用户导出";
  314. excelconfig.TitleFont = "微软雅黑";
  315. excelconfig.TitlePoint = 25;
  316. excelconfig.FileName = "学生用户导出.xls";
  317. excelconfig.IsAllSizeColumn = true;
  318. //每一列的设置,没有设置的列信息,系统将按datatable中的列名导出
  319. excelconfig.ColumnEntity = new List<ColumnModel>();
  320. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_account", ExcelColumn = "账户" });
  321. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_realname", ExcelColumn = "姓名" });
  322. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_gender", ExcelColumn = "性别" });
  323. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_birthday", ExcelColumn = "生日" });
  324. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_mobile", ExcelColumn = "手机" });
  325. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_telephone", ExcelColumn = "电话" });
  326. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_wechat", ExcelColumn = "微信" });
  327. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_company", ExcelColumn = "学校" });
  328. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_department", ExcelColumn = "系部" });
  329. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_description", ExcelColumn = "说明" });
  330. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_createdate", ExcelColumn = "创建日期" });
  331. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_createusername", ExcelColumn = "创建人" });
  332. //调用导出方法
  333. ExcelHelper.ExcelDownload(exportTable, excelconfig);
  334. }
  335. catch (Exception ex)
  336. {
  337. if (ex is ExceptionEx)
  338. {
  339. throw;
  340. }
  341. else
  342. {
  343. throw ExceptionEx.ThrowBusinessException(ex);
  344. }
  345. }
  346. }
  347. /// <summary>
  348. /// 获取实体,通过用户账号
  349. /// </summary>
  350. /// <param name="account">用户账号</param>
  351. /// <returns></returns>
  352. public UserEntity GetEntityByAccount(string account)
  353. {
  354. try
  355. {
  356. UserEntity userEntity;
  357. userEntity = userService.GetEntityByAccount(account);
  358. return userEntity;
  359. }
  360. catch (Exception ex)
  361. {
  362. if (ex is ExceptionEx)
  363. {
  364. throw;
  365. }
  366. else
  367. {
  368. throw ExceptionEx.ThrowBusinessException(ex);
  369. }
  370. }
  371. }
  372. public void UpdateIp(string ip, string id)
  373. {
  374. try
  375. {
  376. userService.UpdateIp(ip, id);
  377. }
  378. catch (Exception ex)
  379. {
  380. if (ex is ExceptionEx)
  381. {
  382. throw;
  383. }
  384. else
  385. {
  386. throw ExceptionEx.ThrowBusinessException(ex);
  387. }
  388. }
  389. }
  390. /// <summary>
  391. /// 获取用户数据
  392. /// </summary>
  393. /// <param name="userId">用户主键</param>
  394. /// <returns></returns>
  395. public UserEntity GetEntityByUserId(string userId)
  396. {
  397. try
  398. {
  399. UserEntity userEntity = cache.Read<UserEntity>(cacheKeyId + userId, CacheId.user);
  400. //if (userEntity == null)
  401. //{
  402. userEntity = userService.GetEntity(userId);
  403. if (userEntity != null)
  404. {
  405. cache.Write<string>(cacheKeyAccount + userEntity.F_Account, userId, CacheId.user);
  406. cache.Write<UserEntity>(cacheKeyId + userId, userEntity, CacheId.user);
  407. }
  408. //}
  409. return userEntity;
  410. }
  411. catch (Exception ex)
  412. {
  413. if (ex is ExceptionEx)
  414. {
  415. throw;
  416. }
  417. else
  418. {
  419. throw ExceptionEx.ThrowBusinessException(ex);
  420. }
  421. }
  422. }
  423. public List<UserEntity> GetStudents()
  424. {
  425. try
  426. {
  427. return userService.GetStudents();
  428. }
  429. catch (Exception ex)
  430. {
  431. if (ex is ExceptionEx)
  432. {
  433. throw;
  434. }
  435. else
  436. {
  437. throw ExceptionEx.ThrowBusinessException(ex);
  438. }
  439. }
  440. }
  441. public UserEntity GetEntityByWeixinOpenId(string openid)
  442. {
  443. try
  444. {
  445. UserEntity userEntity;
  446. userEntity = userService.GetEntityByWeixinOpenId(openid);
  447. return userEntity;
  448. }
  449. catch (Exception ex)
  450. {
  451. if (ex is ExceptionEx)
  452. {
  453. throw;
  454. }
  455. else
  456. {
  457. throw ExceptionEx.ThrowBusinessException(ex);
  458. }
  459. }
  460. }
  461. public void UpdateWeixinOpenId(string keyValue, string openid)
  462. {
  463. try
  464. {
  465. userService.UpdateWeixinOpenId(keyValue, openid);
  466. }
  467. catch (Exception ex)
  468. {
  469. if (ex is ExceptionEx)
  470. {
  471. throw;
  472. }
  473. else
  474. {
  475. throw ExceptionEx.ThrowBusinessException(ex);
  476. }
  477. }
  478. }
  479. /// <summary>
  480. /// 获取超级管理员用户列表
  481. /// </summary>
  482. /// <returns></returns>
  483. public IEnumerable<UserEntity> GetAdminList()
  484. {
  485. try
  486. {
  487. return userService.GetAdminList();
  488. }
  489. catch (Exception ex)
  490. {
  491. if (ex is ExceptionEx)
  492. {
  493. throw;
  494. }
  495. else
  496. {
  497. throw ExceptionEx.ThrowBusinessException(ex);
  498. }
  499. }
  500. }
  501. /// <summary>
  502. /// 获取用户列表数据
  503. /// </summary>
  504. /// <param name="userIds">用户主键串</param>
  505. /// <returns></returns>
  506. public List<UserEntity> GetListByUserIds(string userIds)
  507. {
  508. try
  509. {
  510. if (string.IsNullOrEmpty(userIds))
  511. {
  512. return null;
  513. }
  514. List<UserEntity> list = new List<UserEntity>();
  515. string[] userList = userIds.Split(',');
  516. foreach (string userId in userList)
  517. {
  518. UserEntity userEntity = GetEntityByUserId(userId);
  519. if (userEntity != null)
  520. {
  521. list.Add(userEntity);
  522. }
  523. }
  524. return list;
  525. }
  526. catch (Exception ex)
  527. {
  528. if (ex is ExceptionEx)
  529. {
  530. throw;
  531. }
  532. else
  533. {
  534. throw ExceptionEx.ThrowBusinessException(ex);
  535. }
  536. }
  537. }
  538. public List<UserEntity> GetSaveClassMap()
  539. {
  540. try
  541. {
  542. var list = userService.GetAllList();
  543. return list.ToList();
  544. }
  545. catch (Exception ex)
  546. {
  547. if (ex is ExceptionEx)
  548. {
  549. throw;
  550. }
  551. else
  552. {
  553. throw ExceptionEx.ThrowBusinessException(ex);
  554. }
  555. }
  556. }
  557. /// <summary>
  558. /// 获取映射数据
  559. /// </summary>
  560. /// <returns></returns>
  561. public Dictionary<string, UserModel> GetModelMap()
  562. {
  563. try
  564. {
  565. Dictionary<string, UserModel> dic = cache.Read<Dictionary<string, UserModel>>(cacheKey + "dic", CacheId.user);
  566. if (dic == null)
  567. {
  568. dic = new Dictionary<string, UserModel>();
  569. var list = userService.GetAllList();
  570. foreach (var item in list)
  571. {
  572. UserModel model = new UserModel()
  573. {
  574. companyId = item.F_CompanyId,
  575. departmentId = item.F_DepartmentId,
  576. name = item.F_RealName,
  577. };
  578. string img = "";
  579. if (!string.IsNullOrEmpty(item.F_HeadIcon))
  580. {
  581. string fileHeadImg = Config.GetValue("fileHeadImg");
  582. string fileImg = string.Format("{0}/{1}{2}", fileHeadImg, item.F_UserId, item.F_HeadIcon);
  583. if (DirFileHelper.IsExistFile(fileImg))
  584. {
  585. img = item.F_HeadIcon;
  586. }
  587. }
  588. if (string.IsNullOrEmpty(img))
  589. {
  590. if (item.F_Gender == 0)
  591. {
  592. img = "0";
  593. }
  594. else
  595. {
  596. img = "1";
  597. }
  598. }
  599. model.img = img;
  600. dic.Add(item.F_UserId, model);
  601. cache.Write(cacheKey + "dic", dic, CacheId.user);
  602. }
  603. }
  604. return dic;
  605. }
  606. catch (Exception ex)
  607. {
  608. if (ex is ExceptionEx)
  609. {
  610. throw;
  611. }
  612. else
  613. {
  614. throw ExceptionEx.ThrowBusinessException(ex);
  615. }
  616. }
  617. }
  618. #endregion
  619. #region 提交数据
  620. /// <summary>
  621. /// 虚拟删除
  622. /// </summary>
  623. /// <param name="keyValue">主键</param>
  624. public void VirtualDelete(string keyValue)
  625. {
  626. try
  627. {
  628. UserEntity userEntity = GetEntityByUserId(keyValue);
  629. cache.Remove(cacheKey + userEntity.F_CompanyId, CacheId.user);
  630. cache.Remove(cacheKeyId + keyValue, CacheId.user);
  631. cache.Remove(cacheKeyAccount + userEntity.F_Account, CacheId.user);
  632. Dictionary<string, UserModel> dic = GetModelMap();
  633. dic.Remove(keyValue);
  634. cache.Write(cacheKey + "dic", dic, CacheId.department);
  635. userService.VirtualDelete(keyValue);
  636. }
  637. catch (Exception ex)
  638. {
  639. if (ex is ExceptionEx)
  640. {
  641. throw;
  642. }
  643. else
  644. {
  645. throw ExceptionEx.ThrowBusinessException(ex);
  646. }
  647. }
  648. }
  649. /// <summary>
  650. /// 虚拟删除(批量)
  651. /// </summary>
  652. /// <param name="keyValue">主键</param>
  653. public void VirtualDeleteBatch(string keyValue)
  654. {
  655. try
  656. {
  657. foreach (var item in keyValue.Split(','))
  658. {
  659. UserEntity userEntity = GetEntityByUserId(item);
  660. cache.Remove(cacheKey + userEntity.F_CompanyId, CacheId.user);
  661. cache.Remove(cacheKeyId + item, CacheId.user);
  662. cache.Remove(cacheKeyAccount + userEntity.F_Account, CacheId.user);
  663. Dictionary<string, UserModel> dic = GetModelMap();
  664. dic.Remove(item);
  665. cache.Write(cacheKey + "dic", dic, CacheId.department);
  666. }
  667. userService.VirtualDeleteBatch(keyValue);
  668. }
  669. catch (Exception ex)
  670. {
  671. if (ex is ExceptionEx)
  672. {
  673. throw;
  674. }
  675. else
  676. {
  677. throw ExceptionEx.ThrowBusinessException(ex);
  678. }
  679. }
  680. }
  681. /// <summary>
  682. /// 保存用户表单(新增、修改)
  683. /// </summary>
  684. /// <param name="keyValue">主键值</param>
  685. /// <param name="userEntity">用户实体</param>
  686. /// <returns></returns>
  687. public void SaveEntity(string keyValue, UserEntity userEntity)
  688. {
  689. try
  690. {
  691. cache.Remove(cacheKey + userEntity.F_CompanyId, CacheId.user);
  692. cache.Remove(cacheKeyId + keyValue, CacheId.user);
  693. cache.Remove(cacheKeyAccount + userEntity.F_Account, CacheId.user);
  694. cache.Remove(cacheKey + "dic", CacheId.user);
  695. if (!string.IsNullOrEmpty(keyValue))
  696. {
  697. userEntity.F_Account = null;// 账号不允许改动
  698. }
  699. userService.SaveEntity(keyValue, userEntity);
  700. }
  701. catch (Exception ex)
  702. {
  703. if (ex is ExceptionEx)
  704. {
  705. throw;
  706. }
  707. else
  708. {
  709. throw ExceptionEx.ThrowBusinessException(ex);
  710. }
  711. }
  712. }
  713. /// <summary>
  714. /// 修改用户登录密码
  715. /// </summary>
  716. /// <param name="newPassword">新密码(MD5 小写)</param>
  717. /// <param name="oldPassword">旧密码(MD5 小写)</param>
  718. public bool RevisePassword(string newPassword, string oldPassword)
  719. {
  720. try
  721. {
  722. UserInfo userInfo = LoginUserInfo.Get();
  723. cache.Remove(cacheKeyId + userInfo.userId, CacheId.user);
  724. cache.Remove(cacheKeyAccount + userInfo.account, CacheId.user);
  725. var entity = userService.GetEntity(userInfo.userId);
  726. string oldPasswordByEncrypt = Md5Helper.Encrypt(DESEncrypt.Encrypt(oldPassword, entity.F_Secretkey).ToLower(), 32).ToLower();
  727. if (oldPasswordByEncrypt == entity.F_Password)
  728. {
  729. userService.RevisePassword(userInfo.userId, newPassword);
  730. }
  731. else
  732. {
  733. return false;
  734. }
  735. return true;
  736. }
  737. catch (Exception ex)
  738. {
  739. if (ex is ExceptionEx)
  740. {
  741. throw;
  742. }
  743. else
  744. {
  745. throw ExceptionEx.ThrowBusinessException(ex);
  746. }
  747. }
  748. }
  749. /// <summary>
  750. /// 重置密码
  751. /// </summary>
  752. /// <param name="keyValue">账号主键</param>
  753. public void ResetPassword(string keyValue)
  754. {
  755. try
  756. {
  757. //单个
  758. //cache.Remove(cacheKeyId + keyValue, CacheId.user);
  759. //string password = Md5Helper.Encrypt("123456", 32).ToLower();
  760. //userService.RevisePassword(keyValue, password);
  761. //批量
  762. foreach (var item in keyValue.Split(','))
  763. {
  764. cache.Remove(cacheKeyId + item, CacheId.user);
  765. }
  766. string password = Md5Helper.Encrypt(ConfigurationManager.AppSettings["defaultpwd"], 32).ToLower();
  767. userService.RevisePasswordBatch(keyValue, password);
  768. }
  769. catch (Exception ex)
  770. {
  771. if (ex is ExceptionEx)
  772. {
  773. throw;
  774. }
  775. else
  776. {
  777. throw ExceptionEx.ThrowBusinessException(ex);
  778. }
  779. }
  780. }
  781. public void setPassword(string userid,string pwd)
  782. {
  783. try
  784. {
  785. userService.RevisePassword(userid,pwd);
  786. }
  787. catch (Exception ex)
  788. {
  789. if (ex is ExceptionEx)
  790. {
  791. throw;
  792. }
  793. else
  794. {
  795. throw ExceptionEx.ThrowBusinessException(ex);
  796. }
  797. }
  798. }
  799. /// <summary>
  800. /// 重置密码(八位)
  801. /// </summary>
  802. /// <param name="keyValue">账号主键</param>
  803. public void ResetPasswordEight(string keyValue)
  804. {
  805. try
  806. {
  807. foreach (var item in keyValue.Split(','))
  808. {
  809. cache.Remove(cacheKeyId + item, CacheId.user);
  810. }
  811. string password = Md5Helper.Encrypt(ConfigurationManager.AppSettings["defaultpwdeight"], 32).ToLower();
  812. userService.RevisePasswordBatch(keyValue, password);
  813. }
  814. catch (Exception ex)
  815. {
  816. if (ex is ExceptionEx)
  817. {
  818. throw;
  819. }
  820. else
  821. {
  822. throw ExceptionEx.ThrowBusinessException(ex);
  823. }
  824. }
  825. }
  826. /// <summary>
  827. /// 修改用户状态
  828. /// </summary>
  829. /// <param name="keyValue">主键值</param>
  830. /// <param name="state">状态:1-启动;0-禁用</param>
  831. public void UpdateState(string keyValue, int state)
  832. {
  833. try
  834. {
  835. UserEntity userEntity = GetEntityByUserId(keyValue);
  836. cache.Remove(cacheKey + userEntity.F_CompanyId, CacheId.user);
  837. cache.Remove(cacheKeyId + keyValue, CacheId.user);
  838. cache.Remove(cacheKeyAccount + userEntity.F_Account, CacheId.user);
  839. cache.Remove(cacheKey + "dic", CacheId.user);
  840. userService.UpdateState(keyValue, state);
  841. }
  842. catch (Exception ex)
  843. {
  844. if (ex is ExceptionEx)
  845. {
  846. throw;
  847. }
  848. else
  849. {
  850. throw ExceptionEx.ThrowBusinessException(ex);
  851. }
  852. }
  853. }
  854. /// <summary>
  855. /// 保存用户的设备号
  856. /// </summary>
  857. /// <param name="keyValue">主键</param>
  858. /// <param name="deviceId">设备号</param>
  859. public void UpdateDeviceId(string keyValue, string deviceId)
  860. {
  861. try
  862. {
  863. userService.UpdateDeviceId(keyValue, deviceId);
  864. }
  865. catch (Exception ex)
  866. {
  867. if (ex is ExceptionEx)
  868. {
  869. throw;
  870. }
  871. else
  872. {
  873. throw ExceptionEx.ThrowBusinessException(ex);
  874. }
  875. }
  876. }
  877. /// <summary>
  878. /// 解绑微信
  879. /// </summary>
  880. public void DoUnbundWeiXin(string keyValue)
  881. {
  882. try
  883. {
  884. userService.DoUnbundWeiXin(keyValue);
  885. }
  886. catch (Exception ex)
  887. {
  888. if (ex is ExceptionEx)
  889. {
  890. throw;
  891. }
  892. else
  893. {
  894. throw ExceptionEx.ThrowBusinessException(ex);
  895. }
  896. }
  897. }
  898. #endregion
  899. #region 验证数据
  900. /// <summary>
  901. /// 账户不能重复
  902. /// </summary>
  903. /// <param name="account">账户值</param>
  904. /// <param name="keyValue">主键</param>
  905. /// <returns></returns>
  906. public bool ExistAccount(string account, string keyValue)
  907. {
  908. try
  909. {
  910. return userService.ExistAccount(account, keyValue);
  911. }
  912. catch (Exception ex)
  913. {
  914. if (ex is ExceptionEx)
  915. {
  916. throw;
  917. }
  918. else
  919. {
  920. throw ExceptionEx.ThrowBusinessException(ex);
  921. }
  922. }
  923. }
  924. #endregion
  925. #region 扩展方法
  926. /// <summary>
  927. /// 验证登录
  928. /// </summary>
  929. /// <param name="account">账号</param>
  930. /// <param name="password">密码 MD5 32位 小写</param>
  931. /// <returns></returns>
  932. public UserEntity CheckLogin(string account, string password)
  933. {
  934. ////调用微信开放平台接口获得Token、OpenId
  935. //string appid = Config.GetValue("AppId");
  936. //string appsecret = Config.GetValue("AppSecret");
  937. //OpenTokenGet openTokenGet = new OpenTokenGet();
  938. //openTokenGet.appid = appid;
  939. //openTokenGet.secret = appsecret;
  940. //openTokenGet.code = "0815LTNN0EEei42rURNN0z5QNN05LTNS";
  941. //OpenTokenGetResult openInfo = openTokenGet.OpenSend();
  942. //string openid = openInfo.openid;
  943. //string token = openInfo.access_token;
  944. ////调用微信开放平台接口获得登录用户个人信息
  945. //OpenUserGet openuser = new OpenUserGet();
  946. //openuser.openid = openid;
  947. //openuser.access_token = token;
  948. //OpenUserGetResult userinfo = openuser.OpenSend();
  949. try
  950. {
  951. UserEntity userEntity = GetEntityByAccount(account);
  952. if (userEntity == null)
  953. {
  954. userEntity = new UserEntity()
  955. {
  956. LoginMsg = "账户不存在!",
  957. LoginOk = false
  958. };
  959. return userEntity;
  960. }
  961. userEntity.LoginOk = false;
  962. if (userEntity.F_EnabledMark == 1)
  963. {
  964. string dbPassword = Md5Helper.Encrypt(DESEncrypt.Encrypt(password.ToLower(), userEntity.F_Secretkey).ToLower(), 32).ToLower();
  965. if (dbPassword == userEntity.F_Password)
  966. {
  967. userEntity.LoginOk = true;
  968. }
  969. else
  970. {
  971. userEntity.LoginMsg = "密码和账户名不匹配!";
  972. }
  973. }
  974. else
  975. {
  976. userEntity.LoginMsg = "账户被系统锁定,请联系管理员!";
  977. }
  978. return userEntity;
  979. }
  980. catch (Exception ex)
  981. {
  982. if (ex is ExceptionEx)
  983. {
  984. throw;
  985. }
  986. else
  987. {
  988. throw ExceptionEx.ThrowBusinessException(ex);
  989. }
  990. }
  991. }
  992. /// <summary>
  993. /// 获取用户头像
  994. /// </summary>
  995. /// <param name="userId">用户ID</param>
  996. public void GetImg(string userId)
  997. {
  998. UserEntity entity = GetEntityByUserId(userId);
  999. string img = "";
  1000. string fileHeadImg = Config.GetValue("fileHeadImg");
  1001. string fileHeadImg2 = Config.GetValue("AnnexesFile");
  1002. if (entity != null)
  1003. {
  1004. if (!string.IsNullOrEmpty(entity.F_HeadIcon))
  1005. {
  1006. string fileImg;
  1007. //if (entity.F_Description == "管理员")
  1008. //{
  1009. // fileImg = string.Format("{0}/{1}{2}", fileHeadImg, entity.F_UserId, entity.F_HeadIcon);
  1010. //}
  1011. //else
  1012. //{
  1013. fileImg = $"{ Config.GetValue("AnnexesFile")}{entity.F_HeadIcon.Substring(9, entity.F_HeadIcon.Length - 9)}";
  1014. //}
  1015. if (DirFileHelper.IsExistFile(fileImg))
  1016. {
  1017. img = fileImg;
  1018. }
  1019. }
  1020. }
  1021. else
  1022. {
  1023. img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
  1024. }
  1025. if (string.IsNullOrEmpty(img))
  1026. {
  1027. if (entity.F_Gender == 0)
  1028. {
  1029. //img = string.Format("{0}/{1}", fileHeadImg, "on-girl.jpg");
  1030. img = $"{fileHeadImg2.Substring(0, fileHeadImg2.Length - 9)}{entity.F_HeadIcon}";
  1031. }
  1032. else
  1033. {
  1034. //img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
  1035. img = $"{fileHeadImg2.Substring(0, fileHeadImg2.Length - 9)}{entity.F_HeadIcon}";
  1036. }
  1037. }
  1038. FileDownHelper.DownLoadnew(img);
  1039. }
  1040. /// <summary>
  1041. /// 获取用户头像
  1042. /// </summary>
  1043. /// <param name="userId">用户ID</param>
  1044. public void GetImgForDC(string userId)
  1045. {
  1046. string fileHeadImg = Config.GetValue("fileHeadImg");
  1047. string fileHeadImg2 = Config.GetValue("AnnexesFile");
  1048. string path =userService.GetEmpPhotoPath(userId);
  1049. string img = "";
  1050. if (File.Exists(path))
  1051. {
  1052. img = path;
  1053. }
  1054. else
  1055. {
  1056. img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
  1057. }
  1058. FileDownHelper.DownLoadnew(img);
  1059. }
  1060. ///// <summary>
  1061. ///// 获取用户头像
  1062. ///// </summary>
  1063. ///// <param name="userId">用户ID</param>
  1064. //public void GetImg(string userId)
  1065. //{
  1066. // UserEntity entity = GetEntityByUserId(userId);
  1067. // string img = "";
  1068. // string fileHeadImg = Config.GetValue("fileHeadImg");
  1069. // if (entity != null)
  1070. // {
  1071. // if (!string.IsNullOrEmpty(entity.F_HeadIcon))
  1072. // {
  1073. // string fileImg = string.Format("{0}/{1}{2}", fileHeadImg, entity.F_UserId, entity.F_HeadIcon);
  1074. // if (DirFileHelper.IsExistFile(fileImg))
  1075. // {
  1076. // img = fileImg;
  1077. // }
  1078. // }
  1079. // }
  1080. // else
  1081. // {
  1082. // img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
  1083. // }
  1084. // if (string.IsNullOrEmpty(img))
  1085. // {
  1086. // if (entity.F_Gender == 0)
  1087. // {
  1088. // img = string.Format("{0}/{1}", fileHeadImg, "on-girl.jpg");
  1089. // }
  1090. // else
  1091. // {
  1092. // img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
  1093. // }
  1094. // }
  1095. // FileDownHelper.DownLoadnew(img);
  1096. //}
  1097. #endregion
  1098. }
  1099. }