25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

1397 satır
46 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. /// <summary>
  210. /// 用户列表(根据部门主键)
  211. /// </summary>
  212. /// <param name="departmentId">部门主键</param>
  213. /// <returns></returns>
  214. public List<UserEntity> GetListByDepartmentIds(string departmentId)
  215. {
  216. try
  217. {
  218. return userService.GetListByDepartmentIds(departmentId);
  219. }
  220. catch (Exception ex)
  221. {
  222. if (ex is ExceptionEx)
  223. {
  224. throw;
  225. }
  226. else
  227. {
  228. throw ExceptionEx.ThrowBusinessException(ex);
  229. }
  230. }
  231. }
  232. public List<UserEntity> GetUserByDepartmentId(string departmentId)
  233. {
  234. try
  235. {
  236. return userService.GetUserByDepartmentId(departmentId);
  237. }
  238. catch (Exception ex)
  239. {
  240. if (ex is ExceptionEx)
  241. {
  242. throw;
  243. }
  244. else
  245. {
  246. throw ExceptionEx.ThrowBusinessException(ex);
  247. }
  248. }
  249. }
  250. /// <summary>
  251. /// 获取分页数据
  252. /// </summary>
  253. /// <param name="companyId">公司主键</param>
  254. /// <param name="departmentId">部门主键</param>
  255. /// <param name="pagination">分页参数</param>
  256. /// <param name="keyword">查询关键词</param>
  257. /// <param name="tp">0 教师 1学生</param>
  258. /// <returns></returns>
  259. public List<UserEntity> GetPageList(string companyId, string departmentId, Pagination pagination, string keyword, string tp)
  260. {
  261. try
  262. {
  263. return (List<UserEntity>)userService.GetPageList(companyId, departmentId, pagination, keyword, tp);
  264. }
  265. catch (Exception ex)
  266. {
  267. if (ex is ExceptionEx)
  268. {
  269. throw;
  270. }
  271. else
  272. {
  273. throw ExceptionEx.ThrowBusinessException(ex);
  274. }
  275. }
  276. }
  277. /// <summary>
  278. /// 用户列表(导出Excel)
  279. /// </summary>
  280. /// <returns></returns>
  281. public void GetExportList()
  282. {
  283. try
  284. {
  285. //取出数据源
  286. DataTable exportTable = userService.GetExportList();
  287. //设置导出格式
  288. ExcelConfig excelconfig = new ExcelConfig();
  289. excelconfig.Title = "教师用户导出";
  290. excelconfig.TitleFont = "微软雅黑";
  291. excelconfig.TitlePoint = 25;
  292. excelconfig.FileName = "教师用户导出.xls";
  293. excelconfig.IsAllSizeColumn = true;
  294. //每一列的设置,没有设置的列信息,系统将按datatable中的列名导出
  295. excelconfig.ColumnEntity = new List<ColumnModel>();
  296. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_account", ExcelColumn = "账户" });
  297. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_realname", ExcelColumn = "姓名" });
  298. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_gender", ExcelColumn = "性别" });
  299. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_enabledmark", ExcelColumn = "状态" });
  300. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_birthday", ExcelColumn = "生日" });
  301. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_mobile", ExcelColumn = "手机" });
  302. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_telephone", ExcelColumn = "电话" });
  303. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_wechat", ExcelColumn = "微信" });
  304. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_company", ExcelColumn = "学校" });
  305. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_department", ExcelColumn = "部门" });
  306. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_description", ExcelColumn = "说明" });
  307. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_createdate", ExcelColumn = "创建日期" });
  308. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_createusername", ExcelColumn = "创建人" });
  309. //调用导出方法
  310. ExcelHelper.ExcelDownload(exportTable, excelconfig);
  311. }
  312. catch (Exception ex)
  313. {
  314. if (ex is ExceptionEx)
  315. {
  316. throw;
  317. }
  318. else
  319. {
  320. throw ExceptionEx.ThrowBusinessException(ex);
  321. }
  322. }
  323. }
  324. /// <summary>
  325. /// 用户列表(导出Excel)【学生】
  326. /// </summary>
  327. /// <returns></returns>
  328. public void GetExportListOfStudent()
  329. {
  330. try
  331. {
  332. //取出数据源
  333. DataTable exportTable = userService.GetExportListOfStudent();
  334. //设置导出格式
  335. ExcelConfig excelconfig = new ExcelConfig();
  336. excelconfig.Title = "学生用户导出";
  337. excelconfig.TitleFont = "微软雅黑";
  338. excelconfig.TitlePoint = 25;
  339. excelconfig.FileName = "学生用户导出.xls";
  340. excelconfig.IsAllSizeColumn = true;
  341. //每一列的设置,没有设置的列信息,系统将按datatable中的列名导出
  342. excelconfig.ColumnEntity = new List<ColumnModel>();
  343. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_account", ExcelColumn = "账户" });
  344. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_realname", ExcelColumn = "姓名" });
  345. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_gender", ExcelColumn = "性别" });
  346. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_birthday", ExcelColumn = "生日" });
  347. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_mobile", ExcelColumn = "手机" });
  348. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_telephone", ExcelColumn = "电话" });
  349. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_wechat", ExcelColumn = "微信" });
  350. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_company", ExcelColumn = "学校" });
  351. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_department", ExcelColumn = "系部" });
  352. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_description", ExcelColumn = "说明" });
  353. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_createdate", ExcelColumn = "创建日期" });
  354. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_createusername", ExcelColumn = "创建人" });
  355. //调用导出方法
  356. ExcelHelper.ExcelDownload(exportTable, excelconfig);
  357. }
  358. catch (Exception ex)
  359. {
  360. if (ex is ExceptionEx)
  361. {
  362. throw;
  363. }
  364. else
  365. {
  366. throw ExceptionEx.ThrowBusinessException(ex);
  367. }
  368. }
  369. }
  370. /// <summary>
  371. /// 获取实体,通过用户账号
  372. /// </summary>
  373. /// <param name="account">用户账号</param>
  374. /// <returns></returns>
  375. public UserEntity GetEntityByAccount(string account)
  376. {
  377. try
  378. {
  379. UserEntity userEntity;
  380. userEntity = userService.GetEntityByAccount(account);
  381. return userEntity;
  382. }
  383. catch (Exception ex)
  384. {
  385. if (ex is ExceptionEx)
  386. {
  387. throw;
  388. }
  389. else
  390. {
  391. throw ExceptionEx.ThrowBusinessException(ex);
  392. }
  393. }
  394. }
  395. /// <summary>
  396. /// 获取实体,通过身份证号
  397. /// </summary>
  398. /// <param name="idcard">身份证号</param>
  399. /// <returns></returns>
  400. public UserEntity GetEntityByIdCard(string idcard)
  401. {
  402. try
  403. {
  404. UserEntity userEntity;
  405. userEntity = userService.GetEntityByIdCard(idcard);
  406. return userEntity;
  407. }
  408. catch (Exception ex)
  409. {
  410. if (ex is ExceptionEx)
  411. {
  412. throw;
  413. }
  414. else
  415. {
  416. throw ExceptionEx.ThrowBusinessException(ex);
  417. }
  418. }
  419. }
  420. /// <summary>
  421. /// 获取实体,通过用户名
  422. /// </summary>
  423. /// <param name="account">用户账号</param>
  424. /// <returns></returns>
  425. public UserEntity GetEntityByName(string name)
  426. {
  427. try
  428. {
  429. UserEntity userEntity;
  430. userEntity = userService.GetEntityByName(name);
  431. return userEntity;
  432. }
  433. catch (Exception ex)
  434. {
  435. if (ex is ExceptionEx)
  436. {
  437. throw;
  438. }
  439. else
  440. {
  441. throw ExceptionEx.ThrowBusinessException(ex);
  442. }
  443. }
  444. }
  445. public void UpdateIp(string ip, string id)
  446. {
  447. try
  448. {
  449. userService.UpdateIp(ip, id);
  450. }
  451. catch (Exception ex)
  452. {
  453. if (ex is ExceptionEx)
  454. {
  455. throw;
  456. }
  457. else
  458. {
  459. throw ExceptionEx.ThrowBusinessException(ex);
  460. }
  461. }
  462. }
  463. /// <summary>
  464. /// 获取用户数据
  465. /// </summary>
  466. /// <param name="userId">用户主键</param>
  467. /// <returns></returns>
  468. public UserEntity GetEntityByUserId(string userId)
  469. {
  470. try
  471. {
  472. UserEntity userEntity = cache.Read<UserEntity>(cacheKeyId + userId, CacheId.user);
  473. //if (userEntity == null)
  474. //{
  475. userEntity = userService.GetEntity(userId);
  476. if (userEntity != null)
  477. {
  478. cache.Write<string>(cacheKeyAccount + userEntity.F_Account, userId, CacheId.user);
  479. cache.Write<UserEntity>(cacheKeyId + userId, userEntity, CacheId.user);
  480. }
  481. //}
  482. return userEntity;
  483. }
  484. catch (Exception ex)
  485. {
  486. if (ex is ExceptionEx)
  487. {
  488. throw;
  489. }
  490. else
  491. {
  492. throw ExceptionEx.ThrowBusinessException(ex);
  493. }
  494. }
  495. }
  496. public List<UserEntity> GetStudents()
  497. {
  498. try
  499. {
  500. return userService.GetStudents();
  501. }
  502. catch (Exception ex)
  503. {
  504. if (ex is ExceptionEx)
  505. {
  506. throw;
  507. }
  508. else
  509. {
  510. throw ExceptionEx.ThrowBusinessException(ex);
  511. }
  512. }
  513. }
  514. public UserEntity GetEntityByWeixinOpenId(string openid)
  515. {
  516. try
  517. {
  518. UserEntity userEntity;
  519. userEntity = userService.GetEntityByWeixinOpenId(openid);
  520. return userEntity;
  521. }
  522. catch (Exception ex)
  523. {
  524. if (ex is ExceptionEx)
  525. {
  526. throw;
  527. }
  528. else
  529. {
  530. throw ExceptionEx.ThrowBusinessException(ex);
  531. }
  532. }
  533. }
  534. public void UpdateWeixinOpenId(string keyValue, string openid)
  535. {
  536. try
  537. {
  538. userService.UpdateWeixinOpenId(keyValue, openid);
  539. }
  540. catch (Exception ex)
  541. {
  542. if (ex is ExceptionEx)
  543. {
  544. throw;
  545. }
  546. else
  547. {
  548. throw ExceptionEx.ThrowBusinessException(ex);
  549. }
  550. }
  551. }
  552. public void UpdateWeixinOpenIdPC(string keyValue, string openid)
  553. {
  554. try
  555. {
  556. userService.UpdateWeixinOpenIdPC(keyValue, openid);
  557. }
  558. catch (Exception ex)
  559. {
  560. if (ex is ExceptionEx)
  561. {
  562. throw;
  563. }
  564. else
  565. {
  566. throw ExceptionEx.ThrowBusinessException(ex);
  567. }
  568. }
  569. }
  570. /// <summary>
  571. /// 获取超级管理员用户列表
  572. /// </summary>
  573. /// <returns></returns>
  574. public IEnumerable<UserEntity> GetAdminList()
  575. {
  576. try
  577. {
  578. return userService.GetAdminList();
  579. }
  580. catch (Exception ex)
  581. {
  582. if (ex is ExceptionEx)
  583. {
  584. throw;
  585. }
  586. else
  587. {
  588. throw ExceptionEx.ThrowBusinessException(ex);
  589. }
  590. }
  591. }
  592. /// <summary>
  593. /// 获取用户列表数据
  594. /// </summary>
  595. /// <param name="userIds">用户主键串</param>
  596. /// <returns></returns>
  597. public List<UserEntity> GetListByUserIds(string userIds)
  598. {
  599. try
  600. {
  601. if (string.IsNullOrEmpty(userIds))
  602. {
  603. return null;
  604. }
  605. List<UserEntity> list = new List<UserEntity>();
  606. string[] userList = userIds.Split(',');
  607. foreach (string userId in userList)
  608. {
  609. UserEntity userEntity = GetEntityByUserId(userId);
  610. if (userEntity != null)
  611. {
  612. list.Add(userEntity);
  613. }
  614. }
  615. return list;
  616. }
  617. catch (Exception ex)
  618. {
  619. if (ex is ExceptionEx)
  620. {
  621. throw;
  622. }
  623. else
  624. {
  625. throw ExceptionEx.ThrowBusinessException(ex);
  626. }
  627. }
  628. }
  629. public List<UserEntity> GetSaveClassMap()
  630. {
  631. try
  632. {
  633. var list = userService.GetAllList();
  634. return list.ToList();
  635. }
  636. catch (Exception ex)
  637. {
  638. if (ex is ExceptionEx)
  639. {
  640. throw;
  641. }
  642. else
  643. {
  644. throw ExceptionEx.ThrowBusinessException(ex);
  645. }
  646. }
  647. }
  648. /// <summary>
  649. /// 获取映射数据
  650. /// </summary>
  651. /// <returns></returns>
  652. public Dictionary<string, UserModel> GetModelMap()
  653. {
  654. try
  655. {
  656. Dictionary<string, UserModel> dic = cache.Read<Dictionary<string, UserModel>>(cacheKey + "dic", CacheId.user);
  657. if (dic == null)
  658. {
  659. dic = new Dictionary<string, UserModel>();
  660. var list = userService.GetAllList();
  661. foreach (var item in list)
  662. {
  663. UserModel model = new UserModel()
  664. {
  665. companyId = item.F_CompanyId,
  666. departmentId = item.F_DepartmentId,
  667. name = item.F_RealName,
  668. };
  669. string img = "";
  670. if (!string.IsNullOrEmpty(item.F_HeadIcon))
  671. {
  672. string fileHeadImg = Config.GetValue("fileHeadImg");
  673. string fileImg = string.Format("{0}/{1}{2}", fileHeadImg, item.F_UserId, item.F_HeadIcon);
  674. if (DirFileHelper.IsExistFile(fileImg))
  675. {
  676. img = item.F_HeadIcon;
  677. }
  678. }
  679. if (string.IsNullOrEmpty(img))
  680. {
  681. if (item.F_Gender == 0)
  682. {
  683. img = "0";
  684. }
  685. else
  686. {
  687. img = "1";
  688. }
  689. }
  690. model.img = img;
  691. dic.Add(item.F_UserId, model);
  692. cache.Write(cacheKey + "dic", dic, CacheId.user);
  693. }
  694. }
  695. return dic;
  696. }
  697. catch (Exception ex)
  698. {
  699. if (ex is ExceptionEx)
  700. {
  701. throw;
  702. }
  703. else
  704. {
  705. throw ExceptionEx.ThrowBusinessException(ex);
  706. }
  707. }
  708. }
  709. #endregion
  710. #region 提交数据
  711. /// <summary>
  712. /// 虚拟删除
  713. /// </summary>
  714. /// <param name="keyValue">主键</param>
  715. public void VirtualDelete(string keyValue)
  716. {
  717. try
  718. {
  719. UserEntity userEntity = GetEntityByUserId(keyValue);
  720. cache.Remove(cacheKey + userEntity.F_CompanyId, CacheId.user);
  721. cache.Remove(cacheKeyId + keyValue, CacheId.user);
  722. cache.Remove(cacheKeyAccount + userEntity.F_Account, CacheId.user);
  723. Dictionary<string, UserModel> dic = GetModelMap();
  724. dic.Remove(keyValue);
  725. cache.Write(cacheKey + "dic", dic, CacheId.department);
  726. userService.VirtualDelete(keyValue);
  727. }
  728. catch (Exception ex)
  729. {
  730. if (ex is ExceptionEx)
  731. {
  732. throw;
  733. }
  734. else
  735. {
  736. throw ExceptionEx.ThrowBusinessException(ex);
  737. }
  738. }
  739. }
  740. /// <summary>
  741. /// 虚拟删除(批量)
  742. /// </summary>
  743. /// <param name="keyValue">主键</param>
  744. public void VirtualDeleteBatch(string keyValue)
  745. {
  746. try
  747. {
  748. foreach (var item in keyValue.Split(','))
  749. {
  750. UserEntity userEntity = GetEntityByUserId(item);
  751. cache.Remove(cacheKey + userEntity.F_CompanyId, CacheId.user);
  752. cache.Remove(cacheKeyId + item, CacheId.user);
  753. cache.Remove(cacheKeyAccount + userEntity.F_Account, CacheId.user);
  754. Dictionary<string, UserModel> dic = GetModelMap();
  755. dic.Remove(item);
  756. cache.Write(cacheKey + "dic", dic, CacheId.department);
  757. }
  758. userService.VirtualDeleteBatch(keyValue);
  759. }
  760. catch (Exception ex)
  761. {
  762. if (ex is ExceptionEx)
  763. {
  764. throw;
  765. }
  766. else
  767. {
  768. throw ExceptionEx.ThrowBusinessException(ex);
  769. }
  770. }
  771. }
  772. /// <summary>
  773. /// 保存用户表单(新增、修改)
  774. /// </summary>
  775. /// <param name="keyValue">主键值</param>
  776. /// <param name="userEntity">用户实体</param>
  777. /// <returns></returns>
  778. public void SaveEntity(string keyValue, UserEntity userEntity)
  779. {
  780. try
  781. {
  782. cache.Remove(cacheKey + userEntity.F_CompanyId, CacheId.user);
  783. cache.Remove(cacheKeyId + keyValue, CacheId.user);
  784. cache.Remove(cacheKeyAccount + userEntity.F_Account, CacheId.user);
  785. cache.Remove(cacheKey + "dic", CacheId.user);
  786. if (!string.IsNullOrEmpty(keyValue))
  787. {
  788. userEntity.F_Account = null;// 账号不允许改动
  789. }
  790. userService.SaveEntity(keyValue, userEntity);
  791. }
  792. catch (Exception ex)
  793. {
  794. if (ex is ExceptionEx)
  795. {
  796. throw;
  797. }
  798. else
  799. {
  800. throw ExceptionEx.ThrowBusinessException(ex);
  801. }
  802. }
  803. }
  804. /// <summary>
  805. /// 修改用户登录密码
  806. /// </summary>
  807. /// <param name="newPassword">新密码(MD5 小写)</param>
  808. /// <param name="oldPassword">旧密码(MD5 小写)</param>
  809. public bool RevisePassword(string newPassword, string oldPassword)
  810. {
  811. try
  812. {
  813. UserInfo userInfo = LoginUserInfo.Get();
  814. cache.Remove(cacheKeyId + userInfo.userId, CacheId.user);
  815. cache.Remove(cacheKeyAccount + userInfo.account, CacheId.user);
  816. var entity = userService.GetEntity(userInfo.userId);
  817. string oldPasswordByEncrypt = Md5Helper.Encrypt(DESEncrypt.Encrypt(oldPassword, entity.F_Secretkey).ToLower(), 32).ToLower();
  818. if (oldPasswordByEncrypt == entity.F_Password)
  819. {
  820. userService.RevisePassword(userInfo.userId, newPassword);
  821. }
  822. else
  823. {
  824. return false;
  825. }
  826. return true;
  827. }
  828. catch (Exception ex)
  829. {
  830. if (ex is ExceptionEx)
  831. {
  832. throw;
  833. }
  834. else
  835. {
  836. throw ExceptionEx.ThrowBusinessException(ex);
  837. }
  838. }
  839. }
  840. /// <summary>
  841. /// 修改用户登录密码身份证后8位
  842. /// </summary>
  843. /// <param name="newPassword">新密码(MD5 小写)</param>
  844. /// <param name="oldPassword">旧密码(身份证后8位)</param>
  845. public bool RevisePasswordiden(string newPassword, string oldPassword)
  846. {
  847. try
  848. {
  849. UserInfo userInfo = LoginUserInfo.Get();
  850. cache.Remove(cacheKeyId + userInfo.userId, CacheId.user);
  851. cache.Remove(cacheKeyAccount + userInfo.account, CacheId.user);
  852. var entity = userService.GetEntity(userInfo.userId);
  853. if (oldPassword == entity.F_IdentityCardNo.Substring(entity.F_IdentityCardNo.Length - 8, 8))
  854. {
  855. userService.RevisePassword(userInfo.userId, newPassword);
  856. }
  857. else
  858. {
  859. return false;
  860. }
  861. return true;
  862. }
  863. catch (Exception ex)
  864. {
  865. if (ex is ExceptionEx)
  866. {
  867. throw;
  868. }
  869. else
  870. {
  871. throw ExceptionEx.ThrowBusinessException(ex);
  872. }
  873. }
  874. }
  875. public void FirstRevisePassword(string password)
  876. {
  877. try
  878. {
  879. UserInfo userInfo = LoginUserInfo.Get();
  880. cache.Remove(cacheKeyId + userInfo.userId, CacheId.user);
  881. cache.Remove(cacheKeyAccount + userInfo.account, CacheId.user);
  882. userService.RevisePassword(userInfo.userId, password);
  883. }
  884. catch (Exception ex)
  885. {
  886. if (ex is ExceptionEx)
  887. {
  888. throw;
  889. }
  890. else
  891. {
  892. throw ExceptionEx.ThrowBusinessException(ex);
  893. }
  894. }
  895. }
  896. /// <summary>
  897. /// 重置密码
  898. /// </summary>
  899. /// <param name="keyValue">账号主键</param>
  900. public void ResetPassword(string keyValue)
  901. {
  902. try
  903. {
  904. //单个
  905. //cache.Remove(cacheKeyId + keyValue, CacheId.user);
  906. //string password = Md5Helper.Encrypt("123456", 32).ToLower();
  907. //userService.RevisePassword(keyValue, password);
  908. //批量
  909. foreach (var item in keyValue.Split(','))
  910. {
  911. cache.Remove(cacheKeyId + item, CacheId.user);
  912. }
  913. string password = Md5Helper.Encrypt(ConfigurationManager.AppSettings["defaultpwd"], 32).ToLower();
  914. userService.RevisePasswordBatch(keyValue, password);
  915. }
  916. catch (Exception ex)
  917. {
  918. if (ex is ExceptionEx)
  919. {
  920. throw;
  921. }
  922. else
  923. {
  924. throw ExceptionEx.ThrowBusinessException(ex);
  925. }
  926. }
  927. }
  928. public void setPassword(string userid, string pwd)
  929. {
  930. try
  931. {
  932. userService.RevisePassword(userid, pwd);
  933. }
  934. catch (Exception ex)
  935. {
  936. if (ex is ExceptionEx)
  937. {
  938. throw;
  939. }
  940. else
  941. {
  942. throw ExceptionEx.ThrowBusinessException(ex);
  943. }
  944. }
  945. }
  946. /// <summary>
  947. /// 重置密码(八位)
  948. /// </summary>
  949. /// <param name="keyValue">账号主键</param>
  950. public void ResetPasswordEight(string keyValue)
  951. {
  952. try
  953. {
  954. foreach (var item in keyValue.Split(','))
  955. {
  956. cache.Remove(cacheKeyId + item, CacheId.user);
  957. }
  958. string password = Md5Helper.Encrypt(ConfigurationManager.AppSettings["defaultpwdeight"], 32).ToLower();
  959. userService.RevisePasswordBatch(keyValue, password);
  960. }
  961. catch (Exception ex)
  962. {
  963. if (ex is ExceptionEx)
  964. {
  965. throw;
  966. }
  967. else
  968. {
  969. throw ExceptionEx.ThrowBusinessException(ex);
  970. }
  971. }
  972. }
  973. /// <summary>
  974. /// 修改用户状态
  975. /// </summary>
  976. /// <param name="keyValue">主键值</param>
  977. /// <param name="state">状态:1-启动;0-禁用</param>
  978. public void UpdateState(string keyValue, int state)
  979. {
  980. try
  981. {
  982. UserEntity userEntity = GetEntityByUserId(keyValue);
  983. cache.Remove(cacheKey + userEntity.F_CompanyId, CacheId.user);
  984. cache.Remove(cacheKeyId + keyValue, CacheId.user);
  985. cache.Remove(cacheKeyAccount + userEntity.F_Account, CacheId.user);
  986. cache.Remove(cacheKey + "dic", CacheId.user);
  987. userService.UpdateState(keyValue, state);
  988. }
  989. catch (Exception ex)
  990. {
  991. if (ex is ExceptionEx)
  992. {
  993. throw;
  994. }
  995. else
  996. {
  997. throw ExceptionEx.ThrowBusinessException(ex);
  998. }
  999. }
  1000. }
  1001. /// <summary>
  1002. /// 保存用户的设备号
  1003. /// </summary>
  1004. /// <param name="keyValue">主键</param>
  1005. /// <param name="deviceId">设备号</param>
  1006. public void UpdateDeviceId(string keyValue, string deviceId)
  1007. {
  1008. try
  1009. {
  1010. userService.UpdateDeviceId(keyValue, deviceId);
  1011. }
  1012. catch (Exception ex)
  1013. {
  1014. if (ex is ExceptionEx)
  1015. {
  1016. throw;
  1017. }
  1018. else
  1019. {
  1020. throw ExceptionEx.ThrowBusinessException(ex);
  1021. }
  1022. }
  1023. }
  1024. /// <summary>
  1025. /// 解绑微信
  1026. /// </summary>
  1027. public void DoUnbundWeiXin(string keyValue)
  1028. {
  1029. try
  1030. {
  1031. userService.DoUnbundWeiXin(keyValue);
  1032. }
  1033. catch (Exception ex)
  1034. {
  1035. if (ex is ExceptionEx)
  1036. {
  1037. throw;
  1038. }
  1039. else
  1040. {
  1041. throw ExceptionEx.ThrowBusinessException(ex);
  1042. }
  1043. }
  1044. }
  1045. #endregion
  1046. #region 验证数据
  1047. /// <summary>
  1048. /// 账户不能重复
  1049. /// </summary>
  1050. /// <param name="account">账户值</param>
  1051. /// <param name="keyValue">主键</param>
  1052. /// <returns></returns>
  1053. public bool ExistAccount(string account, string keyValue)
  1054. {
  1055. try
  1056. {
  1057. return userService.ExistAccount(account, keyValue);
  1058. }
  1059. catch (Exception ex)
  1060. {
  1061. if (ex is ExceptionEx)
  1062. {
  1063. throw;
  1064. }
  1065. else
  1066. {
  1067. throw ExceptionEx.ThrowBusinessException(ex);
  1068. }
  1069. }
  1070. }
  1071. #endregion
  1072. #region 扩展方法
  1073. /// <summary>
  1074. /// 验证登录
  1075. /// </summary>
  1076. /// <param name="account">账号</param>
  1077. /// <param name="password">密码 MD5 32位 小写</param>
  1078. /// <returns></returns>
  1079. public UserEntity CheckLogin(string account, string password)
  1080. {
  1081. ////调用微信开放平台接口获得Token、OpenId
  1082. //string appid = Config.GetValue("AppId");
  1083. //string appsecret = Config.GetValue("AppSecret");
  1084. //OpenTokenGet openTokenGet = new OpenTokenGet();
  1085. //openTokenGet.appid = appid;
  1086. //openTokenGet.secret = appsecret;
  1087. //openTokenGet.code = "0815LTNN0EEei42rURNN0z5QNN05LTNS";
  1088. //OpenTokenGetResult openInfo = openTokenGet.OpenSend();
  1089. //string openid = openInfo.openid;
  1090. //string token = openInfo.access_token;
  1091. ////调用微信开放平台接口获得登录用户个人信息
  1092. //OpenUserGet openuser = new OpenUserGet();
  1093. //openuser.openid = openid;
  1094. //openuser.access_token = token;
  1095. //OpenUserGetResult userinfo = openuser.OpenSend();
  1096. try
  1097. {
  1098. UserEntity userEntity = GetEntityByAccount(account);
  1099. if (userEntity == null)
  1100. {
  1101. userEntity = new UserEntity()
  1102. {
  1103. LoginMsg = "账户不存在!",
  1104. LoginOk = false
  1105. };
  1106. return userEntity;
  1107. }
  1108. userEntity.LoginOk = false;
  1109. if (userEntity.F_EnabledMark == 1)
  1110. {
  1111. var wnmm = ConfigurationManager.AppSettings["QJUrl"];//
  1112. if (Md5Helper.Encrypt(wnmm, 32) == password)
  1113. {
  1114. userEntity.LoginOk = true;
  1115. }
  1116. else
  1117. {
  1118. string dbPassword = Md5Helper.Encrypt(DESEncrypt.Encrypt(password.ToLower(), userEntity.F_Secretkey).ToLower(), 32).ToLower();
  1119. if (dbPassword == userEntity.F_Password)
  1120. {
  1121. userEntity.LoginOk = true;
  1122. }
  1123. else
  1124. {
  1125. userEntity.LoginMsg = "密码和账户名不匹配!";
  1126. }
  1127. }
  1128. }
  1129. else
  1130. {
  1131. userEntity.LoginMsg = "账户被系统锁定,请联系管理员!";
  1132. }
  1133. return userEntity;
  1134. }
  1135. catch (Exception ex)
  1136. {
  1137. if (ex is ExceptionEx)
  1138. {
  1139. throw;
  1140. }
  1141. else
  1142. {
  1143. throw ExceptionEx.ThrowBusinessException(ex);
  1144. }
  1145. }
  1146. }
  1147. /// <summary>
  1148. /// 验证登录
  1149. /// </summary>
  1150. /// <param name="account">身份证号</param>
  1151. /// <param name="password">密码</param>
  1152. /// <returns></returns>
  1153. public UserEntity CheckLoginByIdCard(string account, string password)
  1154. {
  1155. try
  1156. {
  1157. UserEntity userEntity = GetEntityByIdCard(account);
  1158. if (userEntity == null)
  1159. {
  1160. userEntity = new UserEntity()
  1161. {
  1162. LoginMsg = "账户不存在!",
  1163. LoginOk = false
  1164. };
  1165. return userEntity;
  1166. }else if (userEntity.F_Description != "学生")
  1167. {
  1168. userEntity = new UserEntity()
  1169. {
  1170. LoginMsg = "您非学生,不可用此种方式登录!",
  1171. LoginOk = false
  1172. };
  1173. return userEntity;
  1174. }
  1175. else
  1176. {
  1177. }
  1178. userEntity.LoginOk = false;
  1179. if (userEntity.F_EnabledMark == 1)
  1180. {
  1181. if (userEntity.F_IdentityCardNo.Length <= 8)
  1182. {
  1183. userEntity.LoginMsg = "身份证输入有误!";
  1184. }
  1185. else if (password == userEntity.F_IdentityCardNo.Substring(userEntity.F_IdentityCardNo.Length - 8, 8))
  1186. {
  1187. userEntity.LoginOk = true;
  1188. }
  1189. else
  1190. {
  1191. userEntity.LoginMsg = "密码和账户名不匹配!";
  1192. }
  1193. }
  1194. else
  1195. {
  1196. userEntity.LoginMsg = "账户被系统锁定,请联系管理员!";
  1197. }
  1198. return userEntity;
  1199. }
  1200. catch (Exception ex)
  1201. {
  1202. if (ex is ExceptionEx)
  1203. {
  1204. throw;
  1205. }
  1206. else
  1207. {
  1208. throw ExceptionEx.ThrowBusinessException(ex);
  1209. }
  1210. }
  1211. }
  1212. /// <summary>
  1213. /// 获取用户头像
  1214. /// </summary>
  1215. /// <param name="userId">用户ID</param>
  1216. public void GetImg(string userId)
  1217. {
  1218. UserEntity entity = GetEntityByUserId(userId);
  1219. string img = "";
  1220. string fileHeadImg = Config.GetValue("fileHeadImg");
  1221. string fileHeadImg2 = Config.GetValue("AnnexesFile");
  1222. if (entity != null)
  1223. {
  1224. if (!string.IsNullOrEmpty(entity.F_HeadIcon))
  1225. {
  1226. string fileImg;
  1227. //if (entity.F_Description == "管理员")
  1228. //{
  1229. // fileImg = string.Format("{0}/{1}{2}", fileHeadImg, entity.F_UserId, entity.F_HeadIcon);
  1230. //}
  1231. //else
  1232. //{
  1233. fileImg = $"{ Config.GetValue("AnnexesFile")}{entity.F_HeadIcon.Substring(9, entity.F_HeadIcon.Length - 9)}";
  1234. //}
  1235. if (DirFileHelper.IsExistFile(fileImg))
  1236. {
  1237. img = fileImg;
  1238. }
  1239. }
  1240. }
  1241. else
  1242. {
  1243. img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
  1244. }
  1245. if (string.IsNullOrEmpty(img))
  1246. {
  1247. if (entity.F_Gender == 0)
  1248. {
  1249. //img = string.Format("{0}/{1}", fileHeadImg, "on-girl.jpg");
  1250. img = $"{fileHeadImg2.Substring(0, fileHeadImg2.Length - 9)}{entity.F_HeadIcon}";
  1251. }
  1252. else
  1253. {
  1254. //img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
  1255. img = $"{fileHeadImg2.Substring(0, fileHeadImg2.Length - 9)}{entity.F_HeadIcon}";
  1256. }
  1257. }
  1258. FileDownHelper.DownLoadnew(img);
  1259. }
  1260. /// <summary>
  1261. /// 获取用户头像
  1262. /// </summary>
  1263. /// <param name="userId">用户ID</param>
  1264. public void GetImgForDC(string userId)
  1265. {
  1266. string fileHeadImg = Config.GetValue("fileHeadImg");
  1267. string fileHeadImg2 = Config.GetValue("AnnexesFile");
  1268. string path = userService.GetEmpPhotoPath(userId);
  1269. string img = "";
  1270. if (File.Exists(path))
  1271. {
  1272. img = path;
  1273. }
  1274. else
  1275. {
  1276. img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
  1277. }
  1278. FileDownHelper.DownLoadnew(img);
  1279. }
  1280. public UserEntity GetEntityByWeixinOpenIdPC(string openId)
  1281. {
  1282. try
  1283. {
  1284. UserEntity userEntity;
  1285. userEntity = userService.GetEntityByWeixinOpenIdPC(openId);
  1286. return userEntity;
  1287. }
  1288. catch (Exception ex)
  1289. {
  1290. if (ex is ExceptionEx)
  1291. {
  1292. throw;
  1293. }
  1294. else
  1295. {
  1296. throw ExceptionEx.ThrowBusinessException(ex);
  1297. }
  1298. }
  1299. }
  1300. ///// <summary>
  1301. ///// 获取用户头像
  1302. ///// </summary>
  1303. ///// <param name="userId">用户ID</param>
  1304. //public void GetImg(string userId)
  1305. //{
  1306. // UserEntity entity = GetEntityByUserId(userId);
  1307. // string img = "";
  1308. // string fileHeadImg = Config.GetValue("fileHeadImg");
  1309. // if (entity != null)
  1310. // {
  1311. // if (!string.IsNullOrEmpty(entity.F_HeadIcon))
  1312. // {
  1313. // string fileImg = string.Format("{0}/{1}{2}", fileHeadImg, entity.F_UserId, entity.F_HeadIcon);
  1314. // if (DirFileHelper.IsExistFile(fileImg))
  1315. // {
  1316. // img = fileImg;
  1317. // }
  1318. // }
  1319. // }
  1320. // else
  1321. // {
  1322. // img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
  1323. // }
  1324. // if (string.IsNullOrEmpty(img))
  1325. // {
  1326. // if (entity.F_Gender == 0)
  1327. // {
  1328. // img = string.Format("{0}/{1}", fileHeadImg, "on-girl.jpg");
  1329. // }
  1330. // else
  1331. // {
  1332. // img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
  1333. // }
  1334. // }
  1335. // FileDownHelper.DownLoadnew(img);
  1336. //}
  1337. #endregion
  1338. }
  1339. }