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.
 
 
 
 
 
 

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