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.
 
 
 
 
 
 

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