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.
 
 
 
 
 
 

1392 lines
45 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. using System.Text;
  13. namespace Learun.Application.Organization
  14. {
  15. /// <summary>
  16. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  17. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  18. /// 创建人:陈彬彬
  19. /// 日 期:2017.03.06
  20. /// 描 述:用户模块业务类
  21. /// </summary>
  22. public class UserBLL : UserIBLL
  23. {
  24. #region 属性
  25. private UserService userService = new UserService();
  26. private DepartmentIBLL departmentIBLL = new DepartmentBLL();
  27. #endregion
  28. #region 缓存定义
  29. private ICache cache = CacheFactory.CaChe();
  30. private string cacheKey = "learun_adms_user_"; // +公司主键
  31. private string cacheKeyAccount = "learun_adms_user_account_";// +用户账号(账号不允许改动)
  32. private string cacheKeyId = "learun_adms_user_Id_";// +用户账号(账号不允许改动)
  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="idcard">身份证号</param>
  400. /// <returns></returns>
  401. public UserEntity GetEntityByIdCard(string idcard)
  402. {
  403. try
  404. {
  405. UserEntity userEntity;
  406. userEntity = userService.GetEntityByIdCard(idcard);
  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="account">用户账号</param>
  425. /// <returns></returns>
  426. public UserEntity GetEntityByName(string name)
  427. {
  428. try
  429. {
  430. UserEntity userEntity;
  431. userEntity = userService.GetEntityByName(name);
  432. return userEntity;
  433. }
  434. catch (Exception ex)
  435. {
  436. if (ex is ExceptionEx)
  437. {
  438. throw;
  439. }
  440. else
  441. {
  442. throw ExceptionEx.ThrowBusinessException(ex);
  443. }
  444. }
  445. }
  446. public void UpdateIp(string ip, string id)
  447. {
  448. try
  449. {
  450. userService.UpdateIp(ip, id);
  451. }
  452. catch (Exception ex)
  453. {
  454. if (ex is ExceptionEx)
  455. {
  456. throw;
  457. }
  458. else
  459. {
  460. throw ExceptionEx.ThrowBusinessException(ex);
  461. }
  462. }
  463. }
  464. /// <summary>
  465. /// 获取用户数据
  466. /// </summary>
  467. /// <param name="userId">用户主键</param>
  468. /// <returns></returns>
  469. public UserEntity GetEntityByUserId(string userId)
  470. {
  471. try
  472. {
  473. UserEntity userEntity = cache.Read<UserEntity>(cacheKeyId + userId, CacheId.user);
  474. //if (userEntity == null)
  475. //{
  476. userEntity = userService.GetEntity(userId);
  477. if (userEntity != null)
  478. {
  479. cache.Write<string>(cacheKeyAccount + userEntity.F_Account, userId, CacheId.user);
  480. cache.Write<UserEntity>(cacheKeyId + userId, userEntity, CacheId.user);
  481. }
  482. //}
  483. return userEntity;
  484. }
  485. catch (Exception ex)
  486. {
  487. if (ex is ExceptionEx)
  488. {
  489. throw;
  490. }
  491. else
  492. {
  493. throw ExceptionEx.ThrowBusinessException(ex);
  494. }
  495. }
  496. }
  497. public List<UserEntity> GetStudents()
  498. {
  499. try
  500. {
  501. return userService.GetStudents();
  502. }
  503. catch (Exception ex)
  504. {
  505. if (ex is ExceptionEx)
  506. {
  507. throw;
  508. }
  509. else
  510. {
  511. throw ExceptionEx.ThrowBusinessException(ex);
  512. }
  513. }
  514. }
  515. public UserEntity GetEntityByWeixinOpenId(string openid)
  516. {
  517. try
  518. {
  519. UserEntity userEntity;
  520. userEntity = userService.GetEntityByWeixinOpenId(openid);
  521. return userEntity;
  522. }
  523. catch (Exception ex)
  524. {
  525. if (ex is ExceptionEx)
  526. {
  527. throw;
  528. }
  529. else
  530. {
  531. throw ExceptionEx.ThrowBusinessException(ex);
  532. }
  533. }
  534. }
  535. public void UpdateWeixinOpenId(string keyValue, string openid)
  536. {
  537. try
  538. {
  539. userService.UpdateWeixinOpenId(keyValue, openid);
  540. }
  541. catch (Exception ex)
  542. {
  543. if (ex is ExceptionEx)
  544. {
  545. throw;
  546. }
  547. else
  548. {
  549. throw ExceptionEx.ThrowBusinessException(ex);
  550. }
  551. }
  552. }
  553. public void UpdateWeixinOpenIdPC(string keyValue, string openid)
  554. {
  555. try
  556. {
  557. userService.UpdateWeixinOpenIdPC(keyValue, openid);
  558. }
  559. catch (Exception ex)
  560. {
  561. if (ex is ExceptionEx)
  562. {
  563. throw;
  564. }
  565. else
  566. {
  567. throw ExceptionEx.ThrowBusinessException(ex);
  568. }
  569. }
  570. }
  571. /// <summary>
  572. /// 获取超级管理员用户列表
  573. /// </summary>
  574. /// <returns></returns>
  575. public IEnumerable<UserEntity> GetAdminList()
  576. {
  577. try
  578. {
  579. return userService.GetAdminList();
  580. }
  581. catch (Exception ex)
  582. {
  583. if (ex is ExceptionEx)
  584. {
  585. throw;
  586. }
  587. else
  588. {
  589. throw ExceptionEx.ThrowBusinessException(ex);
  590. }
  591. }
  592. }
  593. /// <summary>
  594. /// 获取用户列表数据
  595. /// </summary>
  596. /// <param name="userIds">用户主键串</param>
  597. /// <returns></returns>
  598. public List<UserEntity> GetListByUserIds(string userIds)
  599. {
  600. try
  601. {
  602. if (string.IsNullOrEmpty(userIds))
  603. {
  604. return null;
  605. }
  606. List<UserEntity> list = new List<UserEntity>();
  607. string[] userList = userIds.Split(',');
  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 = new Dictionary<string, UserModel>();
  658. var list = userService.GetAllList();
  659. foreach (var item in list)
  660. {
  661. UserModel model = new UserModel()
  662. {
  663. companyId = item.F_CompanyId,
  664. departmentId = item.F_DepartmentId,
  665. name = item.F_RealName,
  666. };
  667. string img = "";
  668. if (!string.IsNullOrEmpty(item.F_HeadIcon))
  669. {
  670. string fileHeadImg = Config.GetValue("fileHeadImg");
  671. string fileImg = string.Format("{0}/{1}{2}", fileHeadImg, item.F_UserId, item.F_HeadIcon);
  672. if (DirFileHelper.IsExistFile(fileImg))
  673. {
  674. img = item.F_HeadIcon;
  675. }
  676. }
  677. if (string.IsNullOrEmpty(img))
  678. {
  679. if (item.F_Gender == 0)
  680. {
  681. img = "0";
  682. }
  683. else
  684. {
  685. img = "1";
  686. }
  687. }
  688. model.img = img;
  689. dic.Add(item.F_UserId, model);
  690. }
  691. return dic;
  692. }
  693. catch (Exception ex)
  694. {
  695. if (ex is ExceptionEx)
  696. {
  697. throw;
  698. }
  699. else
  700. {
  701. throw ExceptionEx.ThrowBusinessException(ex);
  702. }
  703. }
  704. }
  705. #endregion
  706. #region 提交数据
  707. /// <summary>
  708. /// 虚拟删除
  709. /// </summary>
  710. /// <param name="keyValue">主键</param>
  711. public void VirtualDelete(string keyValue)
  712. {
  713. try
  714. {
  715. UserEntity userEntity = GetEntityByUserId(keyValue);
  716. cache.Remove(cacheKey + userEntity.F_CompanyId, CacheId.user);
  717. cache.Remove(cacheKeyId + keyValue, CacheId.user);
  718. cache.Remove(cacheKeyAccount + userEntity.F_Account, CacheId.user);
  719. Dictionary<string, UserModel> dic = GetModelMap();
  720. dic.Remove(keyValue);
  721. cache.Write(cacheKey + "dic", dic, CacheId.department);
  722. userService.VirtualDelete(keyValue);
  723. }
  724. catch (Exception ex)
  725. {
  726. if (ex is ExceptionEx)
  727. {
  728. throw;
  729. }
  730. else
  731. {
  732. throw ExceptionEx.ThrowBusinessException(ex);
  733. }
  734. }
  735. }
  736. /// <summary>
  737. /// 虚拟删除(批量)
  738. /// </summary>
  739. /// <param name="keyValue">主键</param>
  740. public void VirtualDeleteBatch(string keyValue)
  741. {
  742. try
  743. {
  744. foreach (var item in keyValue.Split(','))
  745. {
  746. UserEntity userEntity = GetEntityByUserId(item);
  747. cache.Remove(cacheKey + userEntity.F_CompanyId, CacheId.user);
  748. cache.Remove(cacheKeyId + item, CacheId.user);
  749. cache.Remove(cacheKeyAccount + userEntity.F_Account, CacheId.user);
  750. Dictionary<string, UserModel> dic = GetModelMap();
  751. dic.Remove(item);
  752. cache.Write(cacheKey + "dic", dic, CacheId.department);
  753. }
  754. userService.VirtualDeleteBatch(keyValue);
  755. }
  756. catch (Exception ex)
  757. {
  758. if (ex is ExceptionEx)
  759. {
  760. throw;
  761. }
  762. else
  763. {
  764. throw ExceptionEx.ThrowBusinessException(ex);
  765. }
  766. }
  767. }
  768. /// <summary>
  769. /// 保存用户表单(新增、修改)
  770. /// </summary>
  771. /// <param name="keyValue">主键值</param>
  772. /// <param name="userEntity">用户实体</param>
  773. /// <returns></returns>
  774. public void SaveEntity(string keyValue, UserEntity userEntity)
  775. {
  776. try
  777. {
  778. cache.Remove(cacheKey + userEntity.F_CompanyId, CacheId.user);
  779. cache.Remove(cacheKeyId + keyValue, CacheId.user);
  780. cache.Remove(cacheKeyAccount + userEntity.F_Account, CacheId.user);
  781. cache.Remove(cacheKey + "dic", CacheId.user);
  782. if (!string.IsNullOrEmpty(keyValue))
  783. {
  784. userEntity.F_Account = null;// 账号不允许改动
  785. }
  786. userService.SaveEntity(keyValue, userEntity);
  787. }
  788. catch (Exception ex)
  789. {
  790. if (ex is ExceptionEx)
  791. {
  792. throw;
  793. }
  794. else
  795. {
  796. throw ExceptionEx.ThrowBusinessException(ex);
  797. }
  798. }
  799. }
  800. /// <summary>
  801. /// 修改用户登录密码
  802. /// </summary>
  803. /// <param name="newPassword">新密码(MD5 小写)</param>
  804. /// <param name="oldPassword">旧密码(MD5 小写)</param>
  805. public bool RevisePassword(string newPassword, string oldPassword)
  806. {
  807. try
  808. {
  809. UserInfo userInfo = LoginUserInfo.Get();
  810. cache.Remove(cacheKeyId + userInfo.userId, CacheId.user);
  811. cache.Remove(cacheKeyAccount + userInfo.account, CacheId.user);
  812. var entity = userService.GetEntity(userInfo.userId);
  813. string oldPasswordByEncrypt = Md5Helper.Encrypt(DESEncrypt.Encrypt(oldPassword, entity.F_Secretkey).ToLower(), 32).ToLower();
  814. if (oldPasswordByEncrypt == entity.F_Password)
  815. {
  816. userService.RevisePassword(userInfo.userId, newPassword);
  817. }
  818. else
  819. {
  820. return false;
  821. }
  822. return true;
  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. /// 修改用户登录密码身份证后8位
  838. /// </summary>
  839. /// <param name="newPassword">新密码(MD5 小写)</param>
  840. /// <param name="oldPassword">旧密码(身份证后8位)</param>
  841. public bool RevisePasswordiden(string newPassword, string oldPassword)
  842. {
  843. try
  844. {
  845. UserInfo userInfo = LoginUserInfo.Get();
  846. cache.Remove(cacheKeyId + userInfo.userId, CacheId.user);
  847. cache.Remove(cacheKeyAccount + userInfo.account, CacheId.user);
  848. var entity = userService.GetEntity(userInfo.userId);
  849. if (oldPassword == entity.F_IdentityCardNo.Substring(entity.F_IdentityCardNo.Length - 8, 8))
  850. {
  851. userService.RevisePassword(userInfo.userId, newPassword);
  852. }
  853. else
  854. {
  855. return false;
  856. }
  857. return true;
  858. }
  859. catch (Exception ex)
  860. {
  861. if (ex is ExceptionEx)
  862. {
  863. throw;
  864. }
  865. else
  866. {
  867. throw ExceptionEx.ThrowBusinessException(ex);
  868. }
  869. }
  870. }
  871. /// <summary>
  872. /// 重置密码
  873. /// </summary>
  874. /// <param name="keyValue">账号主键</param>
  875. public void ResetPassword(string keyValue, string defaultpwd)
  876. {
  877. try
  878. {
  879. //单个
  880. //cache.Remove(cacheKeyId + keyValue, CacheId.user);
  881. //string password = Md5Helper.Encrypt("123456", 32).ToLower();
  882. //userService.RevisePassword(keyValue, password);
  883. //批量
  884. foreach (var item in keyValue.Split(','))
  885. {
  886. cache.Remove(cacheKeyId + item, CacheId.user);
  887. }
  888. string password = Md5Helper.Encrypt(defaultpwd, 32).ToLower();
  889. userService.RevisePasswordBatch(keyValue, password);
  890. }
  891. catch (Exception ex)
  892. {
  893. if (ex is ExceptionEx)
  894. {
  895. throw;
  896. }
  897. else
  898. {
  899. throw ExceptionEx.ThrowBusinessException(ex);
  900. }
  901. }
  902. }
  903. public void setPassword(string userid, string pwd)
  904. {
  905. try
  906. {
  907. userService.RevisePassword(userid, pwd);
  908. }
  909. catch (Exception ex)
  910. {
  911. if (ex is ExceptionEx)
  912. {
  913. throw;
  914. }
  915. else
  916. {
  917. throw ExceptionEx.ThrowBusinessException(ex);
  918. }
  919. }
  920. }
  921. /// <summary>
  922. /// 重置密码(八位)
  923. /// </summary>
  924. /// <param name="keyValue">账号主键</param>
  925. public void ResetPasswordEight(string keyValue, string defaultpwd)
  926. {
  927. try
  928. {
  929. foreach (var item in keyValue.Split(','))
  930. {
  931. cache.Remove(cacheKeyId + item, CacheId.user);
  932. }
  933. string password = Md5Helper.Encrypt(defaultpwd, 32).ToLower();
  934. userService.RevisePasswordBatch(keyValue, password);
  935. }
  936. catch (Exception ex)
  937. {
  938. if (ex is ExceptionEx)
  939. {
  940. throw;
  941. }
  942. else
  943. {
  944. throw ExceptionEx.ThrowBusinessException(ex);
  945. }
  946. }
  947. }
  948. /// <summary>
  949. /// 修改用户状态
  950. /// </summary>
  951. /// <param name="keyValue">主键值</param>
  952. /// <param name="state">状态:1-启动;0-禁用</param>
  953. public void UpdateState(string keyValue, int state)
  954. {
  955. try
  956. {
  957. UserEntity userEntity = GetEntityByUserId(keyValue);
  958. cache.Remove(cacheKey + userEntity.F_CompanyId, CacheId.user);
  959. cache.Remove(cacheKeyId + keyValue, CacheId.user);
  960. cache.Remove(cacheKeyAccount + userEntity.F_Account, CacheId.user);
  961. cache.Remove(cacheKey + "dic", CacheId.user);
  962. userService.UpdateState(keyValue, state);
  963. }
  964. catch (Exception ex)
  965. {
  966. if (ex is ExceptionEx)
  967. {
  968. throw;
  969. }
  970. else
  971. {
  972. throw ExceptionEx.ThrowBusinessException(ex);
  973. }
  974. }
  975. }
  976. /// <summary>
  977. /// 保存用户的设备号
  978. /// </summary>
  979. /// <param name="keyValue">主键</param>
  980. /// <param name="deviceId">设备号</param>
  981. public void UpdateDeviceId(string keyValue, string deviceId)
  982. {
  983. try
  984. {
  985. userService.UpdateDeviceId(keyValue, deviceId);
  986. }
  987. catch (Exception ex)
  988. {
  989. if (ex is ExceptionEx)
  990. {
  991. throw;
  992. }
  993. else
  994. {
  995. throw ExceptionEx.ThrowBusinessException(ex);
  996. }
  997. }
  998. }
  999. /// <summary>
  1000. /// 解绑微信
  1001. /// </summary>
  1002. public void DoUnbundWeiXin(string keyValue)
  1003. {
  1004. try
  1005. {
  1006. userService.DoUnbundWeiXin(keyValue);
  1007. }
  1008. catch (Exception ex)
  1009. {
  1010. if (ex is ExceptionEx)
  1011. {
  1012. throw;
  1013. }
  1014. else
  1015. {
  1016. throw ExceptionEx.ThrowBusinessException(ex);
  1017. }
  1018. }
  1019. }
  1020. #endregion
  1021. #region 验证数据
  1022. /// <summary>
  1023. /// 账户不能重复
  1024. /// </summary>
  1025. /// <param name="account">账户值</param>
  1026. /// <param name="keyValue">主键</param>
  1027. /// <returns></returns>
  1028. public bool ExistAccount(string account, string keyValue)
  1029. {
  1030. try
  1031. {
  1032. return userService.ExistAccount(account, keyValue);
  1033. }
  1034. catch (Exception ex)
  1035. {
  1036. if (ex is ExceptionEx)
  1037. {
  1038. throw;
  1039. }
  1040. else
  1041. {
  1042. throw ExceptionEx.ThrowBusinessException(ex);
  1043. }
  1044. }
  1045. }
  1046. #endregion
  1047. #region 扩展方法
  1048. /// <summary>
  1049. /// 验证登录
  1050. /// </summary>
  1051. /// <param name="account">账号</param>
  1052. /// <param name="password">密码 MD5 32位 小写</param>
  1053. /// <returns></returns>
  1054. public UserEntity CheckLogin(string account, string password)
  1055. {
  1056. ////调用微信开放平台接口获得Token、OpenId
  1057. //string appid = Config.GetValue("AppId");
  1058. //string appsecret = Config.GetValue("AppSecret");
  1059. //OpenTokenGet openTokenGet = new OpenTokenGet();
  1060. //openTokenGet.appid = appid;
  1061. //openTokenGet.secret = appsecret;
  1062. //openTokenGet.code = "0815LTNN0EEei42rURNN0z5QNN05LTNS";
  1063. //OpenTokenGetResult openInfo = openTokenGet.OpenSend();
  1064. //string openid = openInfo.openid;
  1065. //string token = openInfo.access_token;
  1066. ////调用微信开放平台接口获得登录用户个人信息
  1067. //OpenUserGet openuser = new OpenUserGet();
  1068. //openuser.openid = openid;
  1069. //openuser.access_token = token;
  1070. //OpenUserGetResult userinfo = openuser.OpenSend();
  1071. try
  1072. {
  1073. UserEntity userEntity = GetEntityByAccount(account);
  1074. if (userEntity == null)
  1075. {
  1076. userEntity = new UserEntity()
  1077. {
  1078. LoginMsg = "账户不存在!",
  1079. LoginOk = false
  1080. };
  1081. return userEntity;
  1082. }
  1083. userEntity.LoginOk = false;
  1084. if (userEntity.F_EnabledMark == 1)
  1085. {
  1086. var wnmm = ConfigurationManager.AppSettings["QJUrl"];//
  1087. if (Md5Helper.Encrypt(wnmm, 32) == password)
  1088. {
  1089. userEntity.LoginOk = true;
  1090. }
  1091. else
  1092. {
  1093. string dbPassword = Md5Helper.Encrypt(DESEncrypt.Encrypt(password.ToLower(), userEntity.F_Secretkey).ToLower(), 32).ToLower();
  1094. if (dbPassword == userEntity.F_Password)
  1095. {
  1096. userEntity.LoginOk = true;
  1097. }
  1098. else
  1099. {
  1100. userEntity.LoginMsg = "密码和账户名不匹配!";
  1101. }
  1102. }
  1103. }
  1104. else
  1105. {
  1106. userEntity.LoginMsg = "账户被系统锁定,请联系管理员!";
  1107. }
  1108. return userEntity;
  1109. }
  1110. catch (Exception ex)
  1111. {
  1112. if (ex is ExceptionEx)
  1113. {
  1114. throw;
  1115. }
  1116. else
  1117. {
  1118. throw ExceptionEx.ThrowBusinessException(ex);
  1119. }
  1120. }
  1121. }
  1122. /// <summary>
  1123. /// 验证登录
  1124. /// </summary>
  1125. /// <param name="account">身份证号</param>
  1126. /// <param name="password">密码</param>
  1127. /// <returns></returns>
  1128. public UserEntity CheckLoginByIdCard(string account, string password)
  1129. {
  1130. try
  1131. {
  1132. UserEntity userEntity = GetEntityByIdCard(account);
  1133. if (userEntity == null)
  1134. {
  1135. userEntity = new UserEntity()
  1136. {
  1137. LoginMsg = "账户不存在!",
  1138. LoginOk = false
  1139. };
  1140. return userEntity;
  1141. }
  1142. else if (userEntity.F_Description != "学生")
  1143. {
  1144. userEntity = new UserEntity()
  1145. {
  1146. LoginMsg = "您非学生,不可用此种方式登录!",
  1147. LoginOk = false
  1148. };
  1149. return userEntity;
  1150. }
  1151. else
  1152. {
  1153. }
  1154. userEntity.LoginOk = false;
  1155. if (userEntity.F_EnabledMark == 1)
  1156. {
  1157. if (userEntity.F_IdentityCardNo.Length <= 8)
  1158. {
  1159. userEntity.LoginMsg = "身份证输入有误!";
  1160. }
  1161. else if (password == userEntity.F_IdentityCardNo.Substring(userEntity.F_IdentityCardNo.Length - 8, 8))
  1162. {
  1163. userEntity.LoginOk = true;
  1164. }
  1165. else
  1166. {
  1167. userEntity.LoginMsg = "密码和账户名不匹配!";
  1168. }
  1169. }
  1170. else
  1171. {
  1172. userEntity.LoginMsg = "账户被系统锁定,请联系管理员!";
  1173. }
  1174. return userEntity;
  1175. }
  1176. catch (Exception ex)
  1177. {
  1178. if (ex is ExceptionEx)
  1179. {
  1180. throw;
  1181. }
  1182. else
  1183. {
  1184. throw ExceptionEx.ThrowBusinessException(ex);
  1185. }
  1186. }
  1187. }
  1188. /// <summary>
  1189. /// 获取用户头像
  1190. /// </summary>
  1191. /// <param name="userId">用户ID</param>
  1192. public void GetImg(string userId)
  1193. {
  1194. UserEntity entity = GetEntityByUserId(userId);
  1195. string img = "";
  1196. string fileHeadImg = Config.GetValue("fileHeadImg");
  1197. string fileHeadImg2 = Config.GetValue("AnnexesFile");
  1198. if (entity != null)
  1199. {
  1200. if (!string.IsNullOrEmpty(entity.F_HeadIcon))
  1201. {
  1202. string fileImg;
  1203. //if (entity.F_Description == "管理员")
  1204. //{
  1205. // fileImg = string.Format("{0}/{1}{2}", fileHeadImg, entity.F_UserId, entity.F_HeadIcon);
  1206. //}
  1207. //else
  1208. //{
  1209. fileImg = $"{ Config.GetValue("AnnexesFile")}{entity.F_HeadIcon.Substring(9, entity.F_HeadIcon.Length - 9)}";
  1210. //}
  1211. if (DirFileHelper.IsExistFile(fileImg))
  1212. {
  1213. img = fileImg;
  1214. }
  1215. }
  1216. }
  1217. else
  1218. {
  1219. img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
  1220. }
  1221. if (string.IsNullOrEmpty(img))
  1222. {
  1223. if (entity.F_Gender == 0)
  1224. {
  1225. //img = string.Format("{0}/{1}", fileHeadImg, "on-girl.jpg");
  1226. img = $"{fileHeadImg2.Substring(0, fileHeadImg2.Length - 9)}{entity.F_HeadIcon}";
  1227. }
  1228. else
  1229. {
  1230. //img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
  1231. img = $"{fileHeadImg2.Substring(0, fileHeadImg2.Length - 9)}{entity.F_HeadIcon}";
  1232. }
  1233. }
  1234. FileDownHelper.DownLoadnew(img);
  1235. }
  1236. /// <summary>
  1237. /// 获取用户头像
  1238. /// </summary>
  1239. /// <param name="userId">用户ID</param>
  1240. public void GetImgForDC(string userId)
  1241. {
  1242. string fileHeadImg = Config.GetValue("fileHeadImg");
  1243. string fileHeadImg2 = Config.GetValue("AnnexesFile");
  1244. string path = userService.GetEmpPhotoPath(userId);
  1245. string img = "";
  1246. if (File.Exists(path))
  1247. {
  1248. img = path;
  1249. }
  1250. else
  1251. {
  1252. img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
  1253. }
  1254. FileDownHelper.DownLoadnew(img);
  1255. }
  1256. public UserEntity GetEntityByWeixinOpenIdPC(string openId)
  1257. {
  1258. try
  1259. {
  1260. UserEntity userEntity;
  1261. userEntity = userService.GetEntityByWeixinOpenIdPC(openId);
  1262. return userEntity;
  1263. }
  1264. catch (Exception ex)
  1265. {
  1266. if (ex is ExceptionEx)
  1267. {
  1268. throw;
  1269. }
  1270. else
  1271. {
  1272. throw ExceptionEx.ThrowBusinessException(ex);
  1273. }
  1274. }
  1275. }
  1276. public UserEntity GetEntityByOldAccount(string account)
  1277. {
  1278. try
  1279. {
  1280. UserEntity userEntity;
  1281. userEntity = userService.GetEntityByOldAccount(account);
  1282. return userEntity;
  1283. }
  1284. catch (Exception ex)
  1285. {
  1286. if (ex is ExceptionEx)
  1287. {
  1288. throw;
  1289. }
  1290. else
  1291. {
  1292. throw ExceptionEx.ThrowBusinessException(ex);
  1293. }
  1294. }
  1295. }
  1296. ///// <summary>
  1297. ///// 获取用户头像
  1298. ///// </summary>
  1299. ///// <param name="userId">用户ID</param>
  1300. //public void GetImg(string userId)
  1301. //{
  1302. // UserEntity entity = GetEntityByUserId(userId);
  1303. // string img = "";
  1304. // string fileHeadImg = Config.GetValue("fileHeadImg");
  1305. // if (entity != null)
  1306. // {
  1307. // if (!string.IsNullOrEmpty(entity.F_HeadIcon))
  1308. // {
  1309. // string fileImg = string.Format("{0}/{1}{2}", fileHeadImg, entity.F_UserId, entity.F_HeadIcon);
  1310. // if (DirFileHelper.IsExistFile(fileImg))
  1311. // {
  1312. // img = fileImg;
  1313. // }
  1314. // }
  1315. // }
  1316. // else
  1317. // {
  1318. // img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
  1319. // }
  1320. // if (string.IsNullOrEmpty(img))
  1321. // {
  1322. // if (entity.F_Gender == 0)
  1323. // {
  1324. // img = string.Format("{0}/{1}", fileHeadImg, "on-girl.jpg");
  1325. // }
  1326. // else
  1327. // {
  1328. // img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
  1329. // }
  1330. // }
  1331. // FileDownHelper.DownLoadnew(img);
  1332. //}
  1333. #endregion
  1334. }
  1335. }