25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1396 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. var user = userService.GetListById(userList).ToList();
  607. return user;
  608. //foreach (string userId in userList)
  609. //{
  610. // UserEntity userEntity = GetEntityByUserId(userId);
  611. // if (userEntity != null)
  612. // {
  613. // list.Add(userEntity);
  614. // }
  615. //}
  616. //return list;
  617. }
  618. catch (Exception ex)
  619. {
  620. if (ex is ExceptionEx)
  621. {
  622. throw;
  623. }
  624. else
  625. {
  626. throw ExceptionEx.ThrowBusinessException(ex);
  627. }
  628. }
  629. }
  630. public List<UserEntity> GetSaveClassMap()
  631. {
  632. try
  633. {
  634. var list = userService.GetAllList();
  635. return list.ToList();
  636. }
  637. catch (Exception ex)
  638. {
  639. if (ex is ExceptionEx)
  640. {
  641. throw;
  642. }
  643. else
  644. {
  645. throw ExceptionEx.ThrowBusinessException(ex);
  646. }
  647. }
  648. }
  649. /// <summary>
  650. /// 获取映射数据
  651. /// </summary>
  652. /// <returns></returns>
  653. public Dictionary<string, UserModel> GetModelMap()
  654. {
  655. try
  656. {
  657. Dictionary<string, UserModel> dic = cache.Read<Dictionary<string, UserModel>>(cacheKey + "dic", CacheId.user);
  658. if (dic == null)
  659. {
  660. dic = new Dictionary<string, UserModel>();
  661. var list = userService.GetAllListForMap();
  662. string fileHeadImg = Config.GetValue("fileHeadImg");
  663. foreach (var item in list)
  664. {
  665. UserModel model = new UserModel()
  666. {
  667. companyId = item.F_CompanyId,
  668. departmentId = item.F_DepartmentId,
  669. name = item.F_RealName,
  670. mobile = item.F_Mobile ?? ""
  671. };
  672. string img = "";
  673. if (!string.IsNullOrEmpty(item.F_HeadIcon))
  674. {
  675. string fileImg = string.Format("{0}/{1}{2}", fileHeadImg, item.F_UserId, item.F_HeadIcon);
  676. if (DirFileHelper.IsExistFile(fileImg))
  677. {
  678. img = item.F_HeadIcon;
  679. }
  680. }
  681. if (string.IsNullOrEmpty(img))
  682. {
  683. if (item.F_Gender == 0)
  684. {
  685. img = "0";
  686. }
  687. else
  688. {
  689. img = "1";
  690. }
  691. }
  692. model.img = img;
  693. dic.Add(item.F_UserId, model);
  694. cache.Write(cacheKey + "dic", dic, CacheId.user);
  695. }
  696. }
  697. return dic;
  698. }
  699. catch (Exception ex)
  700. {
  701. if (ex is ExceptionEx)
  702. {
  703. throw;
  704. }
  705. else
  706. {
  707. throw ExceptionEx.ThrowBusinessException(ex);
  708. }
  709. }
  710. }
  711. /// <summary>
  712. /// 获取映射数据
  713. /// </summary>
  714. /// <returns></returns>
  715. public Dictionary<string, UserModel> GetModelMap(string description)
  716. {
  717. try
  718. {
  719. Dictionary<string, UserModel> dic = cache.Read<Dictionary<string, UserModel>>(cacheKeynos + "dic", CacheId.usernostu);
  720. if (dic == null)
  721. {
  722. dic = new Dictionary<string, UserModel>();
  723. var list = userService.GetAllListForMap(description);
  724. string fileHeadImg = Config.GetValue("fileHeadImg");
  725. foreach (var item in list)
  726. {
  727. UserModel model = new UserModel()
  728. {
  729. companyId = item.F_CompanyId,
  730. departmentId = item.F_DepartmentId,
  731. name = item.F_RealName,
  732. mobile = item.F_Mobile ?? ""
  733. };
  734. string img = "";
  735. if (!string.IsNullOrEmpty(item.F_HeadIcon))
  736. {
  737. string fileImg = string.Format("{0}/{1}{2}", fileHeadImg, item.F_UserId, item.F_HeadIcon);
  738. if (DirFileHelper.IsExistFile(fileImg))
  739. {
  740. img = item.F_HeadIcon;
  741. }
  742. }
  743. if (string.IsNullOrEmpty(img))
  744. {
  745. if (item.F_Gender == 0)
  746. {
  747. img = "0";
  748. }
  749. else
  750. {
  751. img = "1";
  752. }
  753. }
  754. model.img = img;
  755. dic.Add(item.F_UserId, model);
  756. cache.Write(cacheKeynos + "dic", dic, CacheId.usernostu);
  757. }
  758. }
  759. return dic;
  760. }
  761. catch (Exception ex)
  762. {
  763. if (ex is ExceptionEx)
  764. {
  765. throw;
  766. }
  767. else
  768. {
  769. throw ExceptionEx.ThrowBusinessException(ex);
  770. }
  771. }
  772. }
  773. #endregion
  774. #region 提交数据
  775. /// <summary>
  776. /// 虚拟删除
  777. /// </summary>
  778. /// <param name="keyValue">主键</param>
  779. public void VirtualDelete(string keyValue)
  780. {
  781. try
  782. {
  783. UserEntity userEntity = GetEntityByUserId(keyValue);
  784. cache.Remove(cacheKey + userEntity.F_CompanyId, CacheId.user);
  785. cache.Remove(cacheKeyId + keyValue, CacheId.user);
  786. cache.Remove(cacheKeyAccount + userEntity.F_Account, CacheId.user);
  787. Dictionary<string, UserModel> dic = GetModelMap();
  788. dic.Remove(keyValue);
  789. cache.Write(cacheKey + "dic", dic, CacheId.department);
  790. userService.VirtualDelete(keyValue);
  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="keyValue">主键</param>
  808. public void VirtualDeleteBatch(string keyValue)
  809. {
  810. try
  811. {
  812. foreach (var item in keyValue.Split(','))
  813. {
  814. UserEntity userEntity = GetEntityByUserId(item);
  815. cache.Remove(cacheKey + userEntity.F_CompanyId, CacheId.user);
  816. cache.Remove(cacheKeyId + item, CacheId.user);
  817. cache.Remove(cacheKeyAccount + userEntity.F_Account, CacheId.user);
  818. Dictionary<string, UserModel> dic = GetModelMap();
  819. dic.Remove(item);
  820. cache.Write(cacheKey + "dic", dic, CacheId.department);
  821. }
  822. userService.VirtualDeleteBatch(keyValue);
  823. }
  824. catch (Exception ex)
  825. {
  826. if (ex is ExceptionEx)
  827. {
  828. throw;
  829. }
  830. else
  831. {
  832. throw ExceptionEx.ThrowBusinessException(ex);
  833. }
  834. }
  835. }
  836. /// <summary>
  837. /// 保存用户表单(新增、修改)
  838. /// </summary>
  839. /// <param name="keyValue">主键值</param>
  840. /// <param name="userEntity">用户实体</param>
  841. /// <returns></returns>
  842. public void SaveEntity(string keyValue, UserEntity userEntity)
  843. {
  844. try
  845. {
  846. cache.Remove(cacheKey + userEntity.F_CompanyId, CacheId.user);
  847. cache.Remove(cacheKeyId + keyValue, CacheId.user);
  848. cache.Remove(cacheKeyAccount + userEntity.F_Account, CacheId.user);
  849. cache.Remove(cacheKey + "dic", CacheId.user);
  850. if (!string.IsNullOrEmpty(keyValue))
  851. {
  852. userEntity.F_Account = null;// 账号不允许改动
  853. }
  854. userService.SaveEntity(keyValue, userEntity);
  855. }
  856. catch (Exception ex)
  857. {
  858. if (ex is ExceptionEx)
  859. {
  860. throw;
  861. }
  862. else
  863. {
  864. throw ExceptionEx.ThrowBusinessException(ex);
  865. }
  866. }
  867. }
  868. /// <summary>
  869. /// 修改用户登录密码
  870. /// </summary>
  871. /// <param name="newPassword">新密码(MD5 小写)</param>
  872. /// <param name="oldPassword">旧密码(MD5 小写)</param>
  873. public bool RevisePassword(string newPassword, string oldPassword)
  874. {
  875. try
  876. {
  877. UserInfo userInfo = LoginUserInfo.Get();
  878. cache.Remove(cacheKeyId + userInfo.userId, CacheId.user);
  879. cache.Remove(cacheKeyAccount + userInfo.account, CacheId.user);
  880. var entity = userService.GetEntity(userInfo.userId);
  881. string oldPasswordByEncrypt = Md5Helper.Encrypt(DESEncrypt.Encrypt(oldPassword, entity.F_Secretkey).ToLower(), 32).ToLower();
  882. if (oldPasswordByEncrypt == entity.F_Password)
  883. {
  884. userService.RevisePassword(userInfo.userId, newPassword);
  885. }
  886. else
  887. {
  888. return false;
  889. }
  890. return true;
  891. }
  892. catch (Exception ex)
  893. {
  894. if (ex is ExceptionEx)
  895. {
  896. throw;
  897. }
  898. else
  899. {
  900. throw ExceptionEx.ThrowBusinessException(ex);
  901. }
  902. }
  903. }
  904. /// <summary>
  905. /// 重置密码
  906. /// </summary>
  907. /// <param name="keyValue">账号主键</param>
  908. public void ResetPassword(string keyValue, string defaultpwd)
  909. {
  910. try
  911. {
  912. //单个
  913. //cache.Remove(cacheKeyId + keyValue, CacheId.user);
  914. //string password = Md5Helper.Encrypt("123456", 32).ToLower();
  915. //userService.RevisePassword(keyValue, password);
  916. //批量
  917. foreach (var item in keyValue.Split(','))
  918. {
  919. cache.Remove(cacheKeyId + item, CacheId.user);
  920. }
  921. string password = Md5Helper.Encrypt(defaultpwd, 32).ToLower();
  922. userService.RevisePasswordBatch(keyValue, password);
  923. }
  924. catch (Exception ex)
  925. {
  926. if (ex is ExceptionEx)
  927. {
  928. throw;
  929. }
  930. else
  931. {
  932. throw ExceptionEx.ThrowBusinessException(ex);
  933. }
  934. }
  935. }
  936. public void setPassword(string userid, string pwd)
  937. {
  938. try
  939. {
  940. userService.RevisePassword(userid, pwd);
  941. }
  942. catch (Exception ex)
  943. {
  944. if (ex is ExceptionEx)
  945. {
  946. throw;
  947. }
  948. else
  949. {
  950. throw ExceptionEx.ThrowBusinessException(ex);
  951. }
  952. }
  953. }
  954. /// <summary>
  955. /// 重置密码(八位)
  956. /// </summary>
  957. /// <param name="keyValue">账号主键</param>
  958. public void ResetPasswordEight(string keyValue, string defaultpwd)
  959. {
  960. try
  961. {
  962. foreach (var item in keyValue.Split(','))
  963. {
  964. cache.Remove(cacheKeyId + item, CacheId.user);
  965. }
  966. string password = Md5Helper.Encrypt(defaultpwd, 32).ToLower();
  967. userService.RevisePasswordBatch(keyValue, password);
  968. }
  969. catch (Exception ex)
  970. {
  971. if (ex is ExceptionEx)
  972. {
  973. throw;
  974. }
  975. else
  976. {
  977. throw ExceptionEx.ThrowBusinessException(ex);
  978. }
  979. }
  980. }
  981. /// <summary>
  982. /// 修改用户状态
  983. /// </summary>
  984. /// <param name="keyValue">主键值</param>
  985. /// <param name="state">状态:1-启动;0-禁用</param>
  986. public void UpdateState(string keyValue, int state)
  987. {
  988. try
  989. {
  990. UserEntity userEntity = GetEntityByUserId(keyValue);
  991. cache.Remove(cacheKey + userEntity.F_CompanyId, CacheId.user);
  992. cache.Remove(cacheKeyId + keyValue, CacheId.user);
  993. cache.Remove(cacheKeyAccount + userEntity.F_Account, CacheId.user);
  994. cache.Remove(cacheKey + "dic", CacheId.user);
  995. userService.UpdateState(keyValue, state);
  996. }
  997. catch (Exception ex)
  998. {
  999. if (ex is ExceptionEx)
  1000. {
  1001. throw;
  1002. }
  1003. else
  1004. {
  1005. throw ExceptionEx.ThrowBusinessException(ex);
  1006. }
  1007. }
  1008. }
  1009. /// <summary>
  1010. /// 保存用户的设备号
  1011. /// </summary>
  1012. /// <param name="keyValue">主键</param>
  1013. /// <param name="deviceId">设备号</param>
  1014. public void UpdateDeviceId(string keyValue, string deviceId)
  1015. {
  1016. try
  1017. {
  1018. userService.UpdateDeviceId(keyValue, deviceId);
  1019. }
  1020. catch (Exception ex)
  1021. {
  1022. if (ex is ExceptionEx)
  1023. {
  1024. throw;
  1025. }
  1026. else
  1027. {
  1028. throw ExceptionEx.ThrowBusinessException(ex);
  1029. }
  1030. }
  1031. }
  1032. /// <summary>
  1033. /// 解绑微信
  1034. /// </summary>
  1035. public void DoUnbundWeiXin(string keyValue)
  1036. {
  1037. try
  1038. {
  1039. userService.DoUnbundWeiXin(keyValue);
  1040. }
  1041. catch (Exception ex)
  1042. {
  1043. if (ex is ExceptionEx)
  1044. {
  1045. throw;
  1046. }
  1047. else
  1048. {
  1049. throw ExceptionEx.ThrowBusinessException(ex);
  1050. }
  1051. }
  1052. }
  1053. #endregion
  1054. #region 验证数据
  1055. /// <summary>
  1056. /// 账户不能重复
  1057. /// </summary>
  1058. /// <param name="account">账户值</param>
  1059. /// <param name="keyValue">主键</param>
  1060. /// <returns></returns>
  1061. public bool ExistAccount(string account, string keyValue)
  1062. {
  1063. try
  1064. {
  1065. return userService.ExistAccount(account, keyValue);
  1066. }
  1067. catch (Exception ex)
  1068. {
  1069. if (ex is ExceptionEx)
  1070. {
  1071. throw;
  1072. }
  1073. else
  1074. {
  1075. throw ExceptionEx.ThrowBusinessException(ex);
  1076. }
  1077. }
  1078. }
  1079. #endregion
  1080. #region 扩展方法
  1081. /// <summary>
  1082. /// 验证登录
  1083. /// </summary>
  1084. /// <param name="account">账号</param>
  1085. /// <param name="password">密码 MD5 32位 小写</param>
  1086. /// <returns></returns>
  1087. public UserEntity CheckLogin(string account, string password)
  1088. {
  1089. ////调用微信开放平台接口获得Token、OpenId
  1090. //string appid = Config.GetValue("AppId");
  1091. //string appsecret = Config.GetValue("AppSecret");
  1092. //OpenTokenGet openTokenGet = new OpenTokenGet();
  1093. //openTokenGet.appid = appid;
  1094. //openTokenGet.secret = appsecret;
  1095. //openTokenGet.code = "0815LTNN0EEei42rURNN0z5QNN05LTNS";
  1096. //OpenTokenGetResult openInfo = openTokenGet.OpenSend();
  1097. //string openid = openInfo.openid;
  1098. //string token = openInfo.access_token;
  1099. ////调用微信开放平台接口获得登录用户个人信息
  1100. //OpenUserGet openuser = new OpenUserGet();
  1101. //openuser.openid = openid;
  1102. //openuser.access_token = token;
  1103. //OpenUserGetResult userinfo = openuser.OpenSend();
  1104. try
  1105. {
  1106. //UserEntity userEntity = userService.GetEntityByIdCard(account);
  1107. //if (userEntity == null)
  1108. //{
  1109. UserEntity userEntity = userService.GetEntityByAccount(account);
  1110. //}
  1111. if (userEntity == null)
  1112. {
  1113. userEntity = new UserEntity()
  1114. {
  1115. LoginMsg = "账户不存在!",
  1116. LoginOk = false
  1117. };
  1118. return userEntity;
  1119. }
  1120. userEntity.LoginOk = false;
  1121. if (userEntity.F_EnabledMark == 1)
  1122. {
  1123. //var wnmm = ConfigurationManager.AppSettings["QJUrl"];//
  1124. //if (Md5Helper.Encrypt(wnmm, 32) == password)
  1125. //{
  1126. userEntity.LoginOk = true;
  1127. //}
  1128. //else
  1129. //{
  1130. // string dbPassword = Md5Helper.Encrypt(DESEncrypt.Encrypt(password.ToLower(), userEntity.F_Secretkey).ToLower(), 32).ToLower();
  1131. // //string phone = Md5Helper.Encrypt(userEntity.F_Mobile, 32).ToLower();
  1132. // if (dbPassword == userEntity.F_Password)
  1133. // {
  1134. // userEntity.LoginOk = true;
  1135. // }
  1136. // //else if (phone == password)
  1137. // //{
  1138. // // userEntity.LoginOk = true;
  1139. // //}
  1140. // else
  1141. // {
  1142. // userEntity.LoginMsg = "密码和账户名不匹配!";
  1143. // }
  1144. //}
  1145. }
  1146. else
  1147. {
  1148. userEntity.LoginMsg = "账户被系统锁定,请联系管理员!";
  1149. }
  1150. return userEntity;
  1151. }
  1152. catch (Exception ex)
  1153. {
  1154. if (ex is ExceptionEx)
  1155. {
  1156. throw;
  1157. }
  1158. else
  1159. {
  1160. throw ExceptionEx.ThrowBusinessException(ex);
  1161. }
  1162. }
  1163. }
  1164. /// <summary>
  1165. /// 获取用户头像
  1166. /// </summary>
  1167. /// <param name="userId">用户ID</param>
  1168. public void GetImg(string userId)
  1169. {
  1170. UserEntity entity = GetEntityByUserId(userId);
  1171. string img = "";
  1172. string fileHeadImg = Config.GetValue("fileHeadImg");
  1173. string fileHeadImg2 = Config.GetValue("AnnexesFile");
  1174. if (entity != null)
  1175. {
  1176. if (!string.IsNullOrEmpty(entity.F_HeadIcon))
  1177. {
  1178. string fileImg;
  1179. //if (entity.F_Description == "管理员")
  1180. //{
  1181. // fileImg = string.Format("{0}/{1}{2}", fileHeadImg, entity.F_UserId, entity.F_HeadIcon);
  1182. //}
  1183. //else
  1184. //{
  1185. fileImg = $"{Config.GetValue("AnnexesFile")}{entity.F_HeadIcon.Substring(9, entity.F_HeadIcon.Length - 9)}";
  1186. //}
  1187. if (DirFileHelper.IsExistFile(fileImg))
  1188. {
  1189. img = fileImg;
  1190. }
  1191. }
  1192. }
  1193. else
  1194. {
  1195. img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
  1196. }
  1197. if (string.IsNullOrEmpty(img))
  1198. {
  1199. if (entity.F_Gender == 0)
  1200. {
  1201. //img = string.Format("{0}/{1}", fileHeadImg, "on-girl.jpg");
  1202. img = $"{fileHeadImg2.Substring(0, fileHeadImg2.Length - 9)}{entity.F_HeadIcon}";
  1203. }
  1204. else
  1205. {
  1206. //img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
  1207. img = $"{fileHeadImg2.Substring(0, fileHeadImg2.Length - 9)}{entity.F_HeadIcon}";
  1208. }
  1209. }
  1210. FileDownHelper.DownLoadnew(img);
  1211. }
  1212. /// <summary>
  1213. /// 获取用户头像
  1214. /// </summary>
  1215. /// <param name="userId">用户ID</param>
  1216. public void GetImgForDC(string userId)
  1217. {
  1218. string fileHeadImg = Config.GetValue("fileHeadImg");
  1219. string fileHeadImg2 = Config.GetValue("AnnexesFile");
  1220. string path = userService.GetEmpPhotoPath(userId);
  1221. string img = "";
  1222. if (File.Exists(path))
  1223. {
  1224. img = path;
  1225. }
  1226. else
  1227. {
  1228. img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
  1229. }
  1230. FileDownHelper.DownLoadnew(img);
  1231. }
  1232. public UserEntity GetEntityByWeixinOpenIdPC(string openId)
  1233. {
  1234. try
  1235. {
  1236. UserEntity userEntity;
  1237. userEntity = userService.GetEntityByWeixinOpenIdPC(openId);
  1238. return userEntity;
  1239. }
  1240. catch (Exception ex)
  1241. {
  1242. if (ex is ExceptionEx)
  1243. {
  1244. throw;
  1245. }
  1246. else
  1247. {
  1248. throw ExceptionEx.ThrowBusinessException(ex);
  1249. }
  1250. }
  1251. }
  1252. /// <summary>
  1253. /// 修改用户的允许登录结束时间
  1254. /// </summary>
  1255. /// <param name="keyValue">主键值</param>
  1256. /// <param name="state">状态:1-赋值;0-重置</param>
  1257. public void UpdateAllowEndTime(string keyValue, int state)
  1258. {
  1259. try
  1260. {
  1261. userService.UpdateAllowEndTime(keyValue, state);
  1262. }
  1263. catch (Exception ex)
  1264. {
  1265. if (ex is ExceptionEx)
  1266. {
  1267. throw;
  1268. }
  1269. else
  1270. {
  1271. throw ExceptionEx.ThrowBusinessException(ex);
  1272. }
  1273. }
  1274. }
  1275. ///// <summary>
  1276. ///// 获取用户头像
  1277. ///// </summary>
  1278. ///// <param name="userId">用户ID</param>
  1279. //public void GetImg(string userId)
  1280. //{
  1281. // UserEntity entity = GetEntityByUserId(userId);
  1282. // string img = "";
  1283. // string fileHeadImg = Config.GetValue("fileHeadImg");
  1284. // if (entity != null)
  1285. // {
  1286. // if (!string.IsNullOrEmpty(entity.F_HeadIcon))
  1287. // {
  1288. // string fileImg = string.Format("{0}/{1}{2}", fileHeadImg, entity.F_UserId, entity.F_HeadIcon);
  1289. // if (DirFileHelper.IsExistFile(fileImg))
  1290. // {
  1291. // img = fileImg;
  1292. // }
  1293. // }
  1294. // }
  1295. // else
  1296. // {
  1297. // img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
  1298. // }
  1299. // if (string.IsNullOrEmpty(img))
  1300. // {
  1301. // if (entity.F_Gender == 0)
  1302. // {
  1303. // img = string.Format("{0}/{1}", fileHeadImg, "on-girl.jpg");
  1304. // }
  1305. // else
  1306. // {
  1307. // img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
  1308. // }
  1309. // }
  1310. // FileDownHelper.DownLoadnew(img);
  1311. //}
  1312. /// <summary>
  1313. /// 获取实体,账号身份证
  1314. /// </summary>
  1315. /// <param name="account">账号身份证</param>
  1316. /// <returns></returns>
  1317. public UserEntity GetEntityByIdCard(string account)
  1318. {
  1319. try
  1320. {
  1321. UserEntity userEntity;
  1322. userEntity = userService.GetEntityByIdCard(account);
  1323. return userEntity;
  1324. }
  1325. catch (Exception ex)
  1326. {
  1327. if (ex is ExceptionEx)
  1328. {
  1329. throw;
  1330. }
  1331. else
  1332. {
  1333. throw ExceptionEx.ThrowBusinessException(ex);
  1334. }
  1335. }
  1336. }
  1337. #endregion
  1338. }
  1339. }