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.
 
 
 
 
 
 

1370 lines
44 KiB

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