Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

1463 linhas
47 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. public UserEntity GetEntityByMobile(string mobile)
  371. {
  372. try
  373. {
  374. UserEntity userEntity;
  375. userEntity = userService.GetEntityByMobile(mobile);
  376. return userEntity;
  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="account">用户账号</param>
  394. /// <returns></returns>
  395. public UserEntity GetEntityByAccount(string account)
  396. {
  397. try
  398. {
  399. UserEntity userEntity;
  400. userEntity = userService.GetEntityByAccount(account);
  401. return userEntity;
  402. }
  403. catch (Exception ex)
  404. {
  405. if (ex is ExceptionEx)
  406. {
  407. throw;
  408. }
  409. else
  410. {
  411. throw ExceptionEx.ThrowBusinessException(ex);
  412. }
  413. }
  414. }
  415. /// <summary>
  416. /// 获取实体,通过身份证号
  417. /// </summary>
  418. /// <param name="idcard">身份证号</param>
  419. /// <returns></returns>
  420. public UserEntity GetEntityByIdCard(string idcard)
  421. {
  422. try
  423. {
  424. UserEntity userEntity;
  425. userEntity = userService.GetEntityByIdCard(idcard);
  426. return userEntity;
  427. }
  428. catch (Exception ex)
  429. {
  430. if (ex is ExceptionEx)
  431. {
  432. throw;
  433. }
  434. else
  435. {
  436. throw ExceptionEx.ThrowBusinessException(ex);
  437. }
  438. }
  439. }
  440. /// <summary>
  441. /// 获取实体,通过用户名
  442. /// </summary>
  443. /// <param name="account">用户账号</param>
  444. /// <returns></returns>
  445. public UserEntity GetEntityByName(string name)
  446. {
  447. try
  448. {
  449. UserEntity userEntity;
  450. userEntity = userService.GetEntityByName(name);
  451. return userEntity;
  452. }
  453. catch (Exception ex)
  454. {
  455. if (ex is ExceptionEx)
  456. {
  457. throw;
  458. }
  459. else
  460. {
  461. throw ExceptionEx.ThrowBusinessException(ex);
  462. }
  463. }
  464. }
  465. public void UpdateIp(string ip, string id)
  466. {
  467. try
  468. {
  469. userService.UpdateIp(ip, id);
  470. }
  471. catch (Exception ex)
  472. {
  473. if (ex is ExceptionEx)
  474. {
  475. throw;
  476. }
  477. else
  478. {
  479. throw ExceptionEx.ThrowBusinessException(ex);
  480. }
  481. }
  482. }
  483. /// <summary>
  484. /// 记录已登录标记
  485. /// </summary>
  486. /// <param name="id"></param>
  487. public void UpdateHaveLogMark(string id)
  488. {
  489. try
  490. {
  491. userService.UpdateHaveLogMark(id);
  492. }
  493. catch (Exception ex)
  494. {
  495. if (ex is ExceptionEx)
  496. {
  497. throw;
  498. }
  499. else
  500. {
  501. throw ExceptionEx.ThrowBusinessException(ex);
  502. }
  503. }
  504. }
  505. /// <summary>
  506. /// 获取用户数据
  507. /// </summary>
  508. /// <param name="userId">用户主键</param>
  509. /// <returns></returns>
  510. public UserEntity GetEntityByUserId(string userId)
  511. {
  512. try
  513. {
  514. UserEntity userEntity = cache.Read<UserEntity>(cacheKeyId + userId, CacheId.user);
  515. //if (userEntity == null)
  516. //{
  517. userEntity = userService.GetEntity(userId);
  518. if (userEntity != null)
  519. {
  520. cache.Write<string>(cacheKeyAccount + userEntity.F_Account, userId, CacheId.user);
  521. cache.Write<UserEntity>(cacheKeyId + userId, userEntity, CacheId.user);
  522. }
  523. //}
  524. return userEntity;
  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> GetStudents()
  539. {
  540. try
  541. {
  542. return userService.GetStudents();
  543. }
  544. catch (Exception ex)
  545. {
  546. if (ex is ExceptionEx)
  547. {
  548. throw;
  549. }
  550. else
  551. {
  552. throw ExceptionEx.ThrowBusinessException(ex);
  553. }
  554. }
  555. }
  556. public UserEntity GetEntityByWeixinOpenId(string openid)
  557. {
  558. try
  559. {
  560. UserEntity userEntity;
  561. userEntity = userService.GetEntityByWeixinOpenId(openid);
  562. return userEntity;
  563. }
  564. catch (Exception ex)
  565. {
  566. if (ex is ExceptionEx)
  567. {
  568. throw;
  569. }
  570. else
  571. {
  572. throw ExceptionEx.ThrowBusinessException(ex);
  573. }
  574. }
  575. }
  576. public void UpdateWeixinOpenId(string keyValue, string openid)
  577. {
  578. try
  579. {
  580. userService.UpdateWeixinOpenId(keyValue, openid);
  581. }
  582. catch (Exception ex)
  583. {
  584. if (ex is ExceptionEx)
  585. {
  586. throw;
  587. }
  588. else
  589. {
  590. throw ExceptionEx.ThrowBusinessException(ex);
  591. }
  592. }
  593. }
  594. public void UpdateWeixinOpenIdPC(string keyValue, string openid)
  595. {
  596. try
  597. {
  598. userService.UpdateWeixinOpenIdPC(keyValue, openid);
  599. }
  600. catch (Exception ex)
  601. {
  602. if (ex is ExceptionEx)
  603. {
  604. throw;
  605. }
  606. else
  607. {
  608. throw ExceptionEx.ThrowBusinessException(ex);
  609. }
  610. }
  611. }
  612. /// <summary>
  613. /// 获取超级管理员用户列表
  614. /// </summary>
  615. /// <returns></returns>
  616. public IEnumerable<UserEntity> GetAdminList()
  617. {
  618. try
  619. {
  620. return userService.GetAdminList();
  621. }
  622. catch (Exception ex)
  623. {
  624. if (ex is ExceptionEx)
  625. {
  626. throw;
  627. }
  628. else
  629. {
  630. throw ExceptionEx.ThrowBusinessException(ex);
  631. }
  632. }
  633. }
  634. /// <summary>
  635. /// 获取用户列表数据
  636. /// </summary>
  637. /// <param name="userIds">用户主键串</param>
  638. /// <returns></returns>
  639. public List<UserEntity> GetListByUserIds(string userIds)
  640. {
  641. try
  642. {
  643. if (string.IsNullOrEmpty(userIds))
  644. {
  645. return null;
  646. }
  647. List<UserEntity> list = new List<UserEntity>();
  648. string[] userList = userIds.Split(',');
  649. foreach (string userId in userList)
  650. {
  651. UserEntity userEntity = GetEntityByUserId(userId);
  652. if (userEntity != null)
  653. {
  654. list.Add(userEntity);
  655. }
  656. }
  657. return list;
  658. }
  659. catch (Exception ex)
  660. {
  661. if (ex is ExceptionEx)
  662. {
  663. throw;
  664. }
  665. else
  666. {
  667. throw ExceptionEx.ThrowBusinessException(ex);
  668. }
  669. }
  670. }
  671. public List<UserEntity> GetSaveClassMap()
  672. {
  673. try
  674. {
  675. var list = userService.GetAllList();
  676. return list.ToList();
  677. }
  678. catch (Exception ex)
  679. {
  680. if (ex is ExceptionEx)
  681. {
  682. throw;
  683. }
  684. else
  685. {
  686. throw ExceptionEx.ThrowBusinessException(ex);
  687. }
  688. }
  689. }
  690. /// <summary>
  691. /// 获取映射数据
  692. /// </summary>
  693. /// <returns></returns>
  694. public Dictionary<string, UserModel> GetModelMap()
  695. {
  696. try
  697. {
  698. Dictionary<string, UserModel> dic = cache.Read<Dictionary<string, UserModel>>(cacheKey + "dic", CacheId.user);
  699. if (dic == null)
  700. {
  701. dic = new Dictionary<string, UserModel>();
  702. var list = userService.GetAllList();
  703. foreach (var item in list)
  704. {
  705. UserModel model = new UserModel()
  706. {
  707. companyId = item.F_CompanyId,
  708. departmentId = item.F_DepartmentId,
  709. name = item.F_RealName,
  710. };
  711. string img = "";
  712. if (!string.IsNullOrEmpty(item.F_HeadIcon))
  713. {
  714. string fileHeadImg = Config.GetValue("fileHeadImg");
  715. string fileImg = string.Format("{0}/{1}{2}", fileHeadImg, item.F_UserId, item.F_HeadIcon);
  716. if (DirFileHelper.IsExistFile(fileImg))
  717. {
  718. img = item.F_HeadIcon;
  719. }
  720. }
  721. if (string.IsNullOrEmpty(img))
  722. {
  723. if (item.F_Gender == 0)
  724. {
  725. img = "0";
  726. }
  727. else
  728. {
  729. img = "1";
  730. }
  731. }
  732. model.img = img;
  733. dic.Add(item.F_UserId, model);
  734. cache.Write(cacheKey + "dic", dic, CacheId.user);
  735. }
  736. }
  737. return dic;
  738. }
  739. catch (Exception ex)
  740. {
  741. if (ex is ExceptionEx)
  742. {
  743. throw;
  744. }
  745. else
  746. {
  747. throw ExceptionEx.ThrowBusinessException(ex);
  748. }
  749. }
  750. }
  751. #endregion
  752. #region 提交数据
  753. /// <summary>
  754. /// 虚拟删除
  755. /// </summary>
  756. /// <param name="keyValue">主键</param>
  757. public void VirtualDelete(string keyValue)
  758. {
  759. try
  760. {
  761. UserEntity userEntity = GetEntityByUserId(keyValue);
  762. cache.Remove(cacheKey + userEntity.F_CompanyId, CacheId.user);
  763. cache.Remove(cacheKeyId + keyValue, CacheId.user);
  764. cache.Remove(cacheKeyAccount + userEntity.F_Account, CacheId.user);
  765. Dictionary<string, UserModel> dic = GetModelMap();
  766. dic.Remove(keyValue);
  767. cache.Write(cacheKey + "dic", dic, CacheId.department);
  768. userService.VirtualDelete(keyValue);
  769. }
  770. catch (Exception ex)
  771. {
  772. if (ex is ExceptionEx)
  773. {
  774. throw;
  775. }
  776. else
  777. {
  778. throw ExceptionEx.ThrowBusinessException(ex);
  779. }
  780. }
  781. }
  782. /// <summary>
  783. /// 虚拟删除(批量)
  784. /// </summary>
  785. /// <param name="keyValue">主键</param>
  786. public void VirtualDeleteBatch(string keyValue)
  787. {
  788. try
  789. {
  790. foreach (var item in keyValue.Split(','))
  791. {
  792. UserEntity userEntity = GetEntityByUserId(item);
  793. cache.Remove(cacheKey + userEntity.F_CompanyId, CacheId.user);
  794. cache.Remove(cacheKeyId + item, CacheId.user);
  795. cache.Remove(cacheKeyAccount + userEntity.F_Account, CacheId.user);
  796. Dictionary<string, UserModel> dic = GetModelMap();
  797. dic.Remove(item);
  798. cache.Write(cacheKey + "dic", dic, CacheId.department);
  799. }
  800. userService.VirtualDeleteBatch(keyValue);
  801. }
  802. catch (Exception ex)
  803. {
  804. if (ex is ExceptionEx)
  805. {
  806. throw;
  807. }
  808. else
  809. {
  810. throw ExceptionEx.ThrowBusinessException(ex);
  811. }
  812. }
  813. }
  814. /// <summary>
  815. /// 保存用户表单(新增、修改)
  816. /// </summary>
  817. /// <param name="keyValue">主键值</param>
  818. /// <param name="userEntity">用户实体</param>
  819. /// <returns></returns>
  820. public void SaveEntity(string keyValue, UserEntity userEntity)
  821. {
  822. try
  823. {
  824. cache.Remove(cacheKey + userEntity.F_CompanyId, CacheId.user);
  825. cache.Remove(cacheKeyId + keyValue, CacheId.user);
  826. cache.Remove(cacheKeyAccount + userEntity.F_Account, CacheId.user);
  827. cache.Remove(cacheKey + "dic", CacheId.user);
  828. if (!string.IsNullOrEmpty(keyValue))
  829. {
  830. userEntity.F_Account = null;// 账号不允许改动
  831. }
  832. userService.SaveEntity(keyValue, userEntity);
  833. }
  834. catch (Exception ex)
  835. {
  836. if (ex is ExceptionEx)
  837. {
  838. throw;
  839. }
  840. else
  841. {
  842. throw ExceptionEx.ThrowBusinessException(ex);
  843. }
  844. }
  845. }
  846. /// <summary>
  847. /// 修改用户登录密码
  848. /// </summary>
  849. /// <param name="newPassword">新密码(MD5 小写)</param>
  850. /// <param name="oldPassword">旧密码(MD5 小写)</param>
  851. public bool RevisePassword(string newPassword, string oldPassword)
  852. {
  853. try
  854. {
  855. UserInfo userInfo = LoginUserInfo.Get();
  856. cache.Remove(cacheKeyId + userInfo.userId, CacheId.user);
  857. cache.Remove(cacheKeyAccount + userInfo.account, CacheId.user);
  858. var entity = userService.GetEntity(userInfo.userId);
  859. string oldPasswordByEncrypt = Md5Helper.Encrypt(DESEncrypt.Encrypt(oldPassword, entity.F_Secretkey).ToLower(), 32).ToLower();
  860. if (oldPasswordByEncrypt == entity.F_Password)
  861. {
  862. userService.RevisePassword(userInfo.userId, newPassword);
  863. }
  864. else
  865. {
  866. return false;
  867. }
  868. return true;
  869. }
  870. catch (Exception ex)
  871. {
  872. if (ex is ExceptionEx)
  873. {
  874. throw;
  875. }
  876. else
  877. {
  878. throw ExceptionEx.ThrowBusinessException(ex);
  879. }
  880. }
  881. }
  882. /// <summary>
  883. /// 修改用户登录密码身份证后8位
  884. /// </summary>
  885. /// <param name="newPassword">新密码(MD5 小写)</param>
  886. /// <param name="oldPassword">旧密码(身份证后8位)</param>
  887. public bool RevisePasswordiden(string newPassword, string oldPassword)
  888. {
  889. try
  890. {
  891. UserInfo userInfo = LoginUserInfo.Get();
  892. cache.Remove(cacheKeyId + userInfo.userId, CacheId.user);
  893. cache.Remove(cacheKeyAccount + userInfo.account, CacheId.user);
  894. var entity = userService.GetEntity(userInfo.userId);
  895. if (oldPassword == entity.F_IdentityCardNo.Substring(entity.F_IdentityCardNo.Length - 8, 8))
  896. {
  897. userService.RevisePassword(userInfo.userId, newPassword);
  898. }
  899. else
  900. {
  901. return false;
  902. }
  903. return true;
  904. }
  905. catch (Exception ex)
  906. {
  907. if (ex is ExceptionEx)
  908. {
  909. throw;
  910. }
  911. else
  912. {
  913. throw ExceptionEx.ThrowBusinessException(ex);
  914. }
  915. }
  916. }
  917. public void FirstRevisePassword(string password)
  918. {
  919. try
  920. {
  921. UserInfo userInfo = LoginUserInfo.Get();
  922. cache.Remove(cacheKeyId + userInfo.userId, CacheId.user);
  923. cache.Remove(cacheKeyAccount + userInfo.account, CacheId.user);
  924. userService.RevisePassword(userInfo.userId, password);
  925. }
  926. catch (Exception ex)
  927. {
  928. if (ex is ExceptionEx)
  929. {
  930. throw;
  931. }
  932. else
  933. {
  934. throw ExceptionEx.ThrowBusinessException(ex);
  935. }
  936. }
  937. }
  938. /// <summary>
  939. /// 重置密码
  940. /// </summary>
  941. /// <param name="keyValue">账号主键</param>
  942. public void ResetPassword(string keyValue)
  943. {
  944. try
  945. {
  946. //单个
  947. //cache.Remove(cacheKeyId + keyValue, CacheId.user);
  948. //string password = Md5Helper.Encrypt("123456", 32).ToLower();
  949. //userService.RevisePassword(keyValue, password);
  950. //批量
  951. foreach (var item in keyValue.Split(','))
  952. {
  953. cache.Remove(cacheKeyId + item, CacheId.user);
  954. }
  955. string password = Md5Helper.Encrypt(ConfigurationManager.AppSettings["pwdprex"] + ConfigurationManager.AppSettings["pwdsuff"], 32).ToLower();
  956. userService.RevisePasswordBatch(keyValue, password);
  957. }
  958. catch (Exception ex)
  959. {
  960. if (ex is ExceptionEx)
  961. {
  962. throw;
  963. }
  964. else
  965. {
  966. throw ExceptionEx.ThrowBusinessException(ex);
  967. }
  968. }
  969. }
  970. public void setPassword(string userid, string pwd)
  971. {
  972. try
  973. {
  974. userService.RevisePassword(userid, pwd);
  975. }
  976. catch (Exception ex)
  977. {
  978. if (ex is ExceptionEx)
  979. {
  980. throw;
  981. }
  982. else
  983. {
  984. throw ExceptionEx.ThrowBusinessException(ex);
  985. }
  986. }
  987. }
  988. /// <summary>
  989. /// 重置密码(八位)
  990. /// </summary>
  991. /// <param name="keyValue">账号主键</param>
  992. public void ResetPasswordEight(string keyValue)
  993. {
  994. try
  995. {
  996. foreach (var item in keyValue.Split(','))
  997. {
  998. cache.Remove(cacheKeyId + item, CacheId.user);
  999. }
  1000. string password = Md5Helper.Encrypt(ConfigurationManager.AppSettings["defaultpwdeight"], 32).ToLower();
  1001. userService.RevisePasswordBatch(keyValue, password);
  1002. }
  1003. catch (Exception ex)
  1004. {
  1005. if (ex is ExceptionEx)
  1006. {
  1007. throw;
  1008. }
  1009. else
  1010. {
  1011. throw ExceptionEx.ThrowBusinessException(ex);
  1012. }
  1013. }
  1014. }
  1015. /// <summary>
  1016. /// 修改用户状态
  1017. /// </summary>
  1018. /// <param name="keyValue">主键值</param>
  1019. /// <param name="state">状态:1-启动;0-禁用</param>
  1020. public void UpdateState(string keyValue, int state)
  1021. {
  1022. try
  1023. {
  1024. UserEntity userEntity = GetEntityByUserId(keyValue);
  1025. cache.Remove(cacheKey + userEntity.F_CompanyId, CacheId.user);
  1026. cache.Remove(cacheKeyId + keyValue, CacheId.user);
  1027. cache.Remove(cacheKeyAccount + userEntity.F_Account, CacheId.user);
  1028. cache.Remove(cacheKey + "dic", CacheId.user);
  1029. userService.UpdateState(keyValue, state);
  1030. }
  1031. catch (Exception ex)
  1032. {
  1033. if (ex is ExceptionEx)
  1034. {
  1035. throw;
  1036. }
  1037. else
  1038. {
  1039. throw ExceptionEx.ThrowBusinessException(ex);
  1040. }
  1041. }
  1042. }
  1043. /// <summary>
  1044. /// 保存用户的设备号
  1045. /// </summary>
  1046. /// <param name="keyValue">主键</param>
  1047. /// <param name="deviceId">设备号</param>
  1048. public void UpdateDeviceId(string keyValue, string deviceId)
  1049. {
  1050. try
  1051. {
  1052. userService.UpdateDeviceId(keyValue, deviceId);
  1053. }
  1054. catch (Exception ex)
  1055. {
  1056. if (ex is ExceptionEx)
  1057. {
  1058. throw;
  1059. }
  1060. else
  1061. {
  1062. throw ExceptionEx.ThrowBusinessException(ex);
  1063. }
  1064. }
  1065. }
  1066. /// <summary>
  1067. /// 解绑微信
  1068. /// </summary>
  1069. public void DoUnbundWeiXin(string keyValue)
  1070. {
  1071. try
  1072. {
  1073. userService.DoUnbundWeiXin(keyValue);
  1074. }
  1075. catch (Exception ex)
  1076. {
  1077. if (ex is ExceptionEx)
  1078. {
  1079. throw;
  1080. }
  1081. else
  1082. {
  1083. throw ExceptionEx.ThrowBusinessException(ex);
  1084. }
  1085. }
  1086. }
  1087. /// <summary>
  1088. /// 修改手机号
  1089. /// </summary>
  1090. /// <param name="keyValue"></param>
  1091. /// <param name="mobile"></param>
  1092. public void UpdateMobile(string keyValue, string mobile)
  1093. {
  1094. try
  1095. {
  1096. userService.UpdateMobile(keyValue, mobile);
  1097. }
  1098. catch (Exception ex)
  1099. {
  1100. if (ex is ExceptionEx)
  1101. {
  1102. throw;
  1103. }
  1104. else
  1105. {
  1106. throw ExceptionEx.ThrowBusinessException(ex);
  1107. }
  1108. }
  1109. }
  1110. #endregion
  1111. #region 验证数据
  1112. /// <summary>
  1113. /// 账户不能重复
  1114. /// </summary>
  1115. /// <param name="account">账户值</param>
  1116. /// <param name="keyValue">主键</param>
  1117. /// <returns></returns>
  1118. public bool ExistAccount(string account, string keyValue)
  1119. {
  1120. try
  1121. {
  1122. return userService.ExistAccount(account, keyValue);
  1123. }
  1124. catch (Exception ex)
  1125. {
  1126. if (ex is ExceptionEx)
  1127. {
  1128. throw;
  1129. }
  1130. else
  1131. {
  1132. throw ExceptionEx.ThrowBusinessException(ex);
  1133. }
  1134. }
  1135. }
  1136. #endregion
  1137. #region 扩展方法
  1138. /// <summary>
  1139. /// 验证登录
  1140. /// </summary>
  1141. /// <param name="account">账号</param>
  1142. /// <param name="password">密码 MD5 32位 小写</param>
  1143. /// <returns></returns>
  1144. public UserEntity CheckLogin(string account, string password)
  1145. {
  1146. ////调用微信开放平台接口获得Token、OpenId
  1147. //string appid = Config.GetValue("AppId");
  1148. //string appsecret = Config.GetValue("AppSecret");
  1149. //OpenTokenGet openTokenGet = new OpenTokenGet();
  1150. //openTokenGet.appid = appid;
  1151. //openTokenGet.secret = appsecret;
  1152. //openTokenGet.code = "0815LTNN0EEei42rURNN0z5QNN05LTNS";
  1153. //OpenTokenGetResult openInfo = openTokenGet.OpenSend();
  1154. //string openid = openInfo.openid;
  1155. //string token = openInfo.access_token;
  1156. ////调用微信开放平台接口获得登录用户个人信息
  1157. //OpenUserGet openuser = new OpenUserGet();
  1158. //openuser.openid = openid;
  1159. //openuser.access_token = token;
  1160. //OpenUserGetResult userinfo = openuser.OpenSend();
  1161. try
  1162. {
  1163. UserEntity userEntity = GetEntityByAccount(account);
  1164. if (userEntity == null)
  1165. {
  1166. userEntity = new UserEntity()
  1167. {
  1168. LoginMsg = "账户或密码错误!",
  1169. LoginOk = false
  1170. };
  1171. return userEntity;
  1172. }
  1173. userEntity.LoginOk = false;
  1174. if (userEntity.F_EnabledMark == 1)
  1175. {
  1176. var wnmm = ConfigurationManager.AppSettings["QJUrl"];//
  1177. if (Md5Helper.Encrypt(wnmm, 32) == password)
  1178. {
  1179. userEntity.LoginOk = true;
  1180. }
  1181. else
  1182. {
  1183. string dbPassword = Md5Helper.Encrypt(DESEncrypt.Encrypt(password.ToLower(), userEntity.F_Secretkey).ToLower(), 32).ToLower();
  1184. if (dbPassword == userEntity.F_Password)
  1185. {
  1186. userEntity.LoginOk = true;
  1187. }
  1188. else
  1189. {
  1190. userEntity.LoginMsg = "账户或密码错误!";
  1191. }
  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="account">身份证号</param>
  1216. /// <param name="password">密码</param>
  1217. /// <returns></returns>
  1218. public UserEntity CheckLoginByIdCard(string account, string password)
  1219. {
  1220. try
  1221. {
  1222. UserEntity userEntity = GetEntityByIdCard(account);
  1223. if (userEntity == null)
  1224. {
  1225. userEntity = new UserEntity()
  1226. {
  1227. LoginMsg = "账户不存在!",
  1228. LoginOk = false
  1229. };
  1230. return userEntity;
  1231. }
  1232. else if (userEntity.F_Description != "学生")
  1233. {
  1234. userEntity = new UserEntity()
  1235. {
  1236. LoginMsg = "您非学生,不可用此种方式登录!",
  1237. LoginOk = false
  1238. };
  1239. return userEntity;
  1240. }
  1241. else
  1242. {
  1243. }
  1244. userEntity.LoginOk = false;
  1245. if (userEntity.F_EnabledMark == 1)
  1246. {
  1247. if (userEntity.F_IdentityCardNo.Length <= 8)
  1248. {
  1249. userEntity.LoginMsg = "身份证输入有误!";
  1250. }
  1251. else if (password == userEntity.F_IdentityCardNo.Substring(userEntity.F_IdentityCardNo.Length - 8, 8))
  1252. {
  1253. userEntity.LoginOk = true;
  1254. }
  1255. else
  1256. {
  1257. userEntity.LoginMsg = "密码和账户名不匹配!";
  1258. }
  1259. }
  1260. else
  1261. {
  1262. userEntity.LoginMsg = "账户被系统锁定,请联系管理员!";
  1263. }
  1264. return userEntity;
  1265. }
  1266. catch (Exception ex)
  1267. {
  1268. if (ex is ExceptionEx)
  1269. {
  1270. throw;
  1271. }
  1272. else
  1273. {
  1274. throw ExceptionEx.ThrowBusinessException(ex);
  1275. }
  1276. }
  1277. }
  1278. /// <summary>
  1279. /// 获取用户头像
  1280. /// </summary>
  1281. /// <param name="userId">用户ID</param>
  1282. public void GetImg(string userId)
  1283. {
  1284. UserEntity entity = GetEntityByUserId(userId);
  1285. string img = "";
  1286. string fileHeadImg = Config.GetValue("fileHeadImg");
  1287. string fileHeadImg2 = Config.GetValue("AnnexesFile");
  1288. if (entity != null)
  1289. {
  1290. if (!string.IsNullOrEmpty(entity.F_HeadIcon))
  1291. {
  1292. string fileImg;
  1293. //if (entity.F_Description == "管理员")
  1294. //{
  1295. // fileImg = string.Format("{0}/{1}{2}", fileHeadImg, entity.F_UserId, entity.F_HeadIcon);
  1296. //}
  1297. //else
  1298. //{
  1299. fileImg = $"{ Config.GetValue("AnnexesFile")}{entity.F_HeadIcon.Substring(9, entity.F_HeadIcon.Length - 9)}";
  1300. //}
  1301. if (DirFileHelper.IsExistFile(fileImg))
  1302. {
  1303. img = fileImg;
  1304. }
  1305. }
  1306. }
  1307. else
  1308. {
  1309. img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
  1310. }
  1311. if (string.IsNullOrEmpty(img))
  1312. {
  1313. if (entity.F_Gender == 0)
  1314. {
  1315. //img = string.Format("{0}/{1}", fileHeadImg, "on-girl.jpg");
  1316. img = $"{fileHeadImg2.Substring(0, fileHeadImg2.Length - 9)}{entity.F_HeadIcon}";
  1317. }
  1318. else
  1319. {
  1320. //img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
  1321. img = $"{fileHeadImg2.Substring(0, fileHeadImg2.Length - 9)}{entity.F_HeadIcon}";
  1322. }
  1323. }
  1324. FileDownHelper.DownLoadnew(img);
  1325. }
  1326. /// <summary>
  1327. /// 获取用户头像
  1328. /// </summary>
  1329. /// <param name="userId">用户ID</param>
  1330. public void GetImgForDC(string userId)
  1331. {
  1332. string fileHeadImg = Config.GetValue("fileHeadImg");
  1333. string fileHeadImg2 = Config.GetValue("AnnexesFile");
  1334. string path = userService.GetEmpPhotoPath(userId);
  1335. string img = "";
  1336. if (File.Exists(path))
  1337. {
  1338. img = path;
  1339. }
  1340. else
  1341. {
  1342. img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
  1343. }
  1344. FileDownHelper.DownLoadnew(img);
  1345. }
  1346. public UserEntity GetEntityByWeixinOpenIdPC(string openId)
  1347. {
  1348. try
  1349. {
  1350. UserEntity userEntity;
  1351. userEntity = userService.GetEntityByWeixinOpenIdPC(openId);
  1352. return userEntity;
  1353. }
  1354. catch (Exception ex)
  1355. {
  1356. if (ex is ExceptionEx)
  1357. {
  1358. throw;
  1359. }
  1360. else
  1361. {
  1362. throw ExceptionEx.ThrowBusinessException(ex);
  1363. }
  1364. }
  1365. }
  1366. ///// <summary>
  1367. ///// 获取用户头像
  1368. ///// </summary>
  1369. ///// <param name="userId">用户ID</param>
  1370. //public void GetImg(string userId)
  1371. //{
  1372. // UserEntity entity = GetEntityByUserId(userId);
  1373. // string img = "";
  1374. // string fileHeadImg = Config.GetValue("fileHeadImg");
  1375. // if (entity != null)
  1376. // {
  1377. // if (!string.IsNullOrEmpty(entity.F_HeadIcon))
  1378. // {
  1379. // string fileImg = string.Format("{0}/{1}{2}", fileHeadImg, entity.F_UserId, entity.F_HeadIcon);
  1380. // if (DirFileHelper.IsExistFile(fileImg))
  1381. // {
  1382. // img = fileImg;
  1383. // }
  1384. // }
  1385. // }
  1386. // else
  1387. // {
  1388. // img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
  1389. // }
  1390. // if (string.IsNullOrEmpty(img))
  1391. // {
  1392. // if (entity.F_Gender == 0)
  1393. // {
  1394. // img = string.Format("{0}/{1}", fileHeadImg, "on-girl.jpg");
  1395. // }
  1396. // else
  1397. // {
  1398. // img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
  1399. // }
  1400. // }
  1401. // FileDownHelper.DownLoadnew(img);
  1402. //}
  1403. #endregion
  1404. }
  1405. }