選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

1317 行
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. /// 用户列表(导出Excel)【家长】
  372. /// </summary>
  373. /// <returns></returns>
  374. public void GetExportListOfFamily()
  375. {
  376. try
  377. {
  378. //取出数据源
  379. DataTable exportTable = userService.GetExportListOfFamily();
  380. //设置导出格式
  381. ExcelConfig excelconfig = new ExcelConfig();
  382. excelconfig.Title = "家长用户导出";
  383. excelconfig.TitleFont = "微软雅黑";
  384. excelconfig.TitlePoint = 25;
  385. excelconfig.FileName = "家长用户导出.xls";
  386. excelconfig.IsAllSizeColumn = true;
  387. //每一列的设置,没有设置的列信息,系统将按datatable中的列名导出
  388. excelconfig.ColumnEntity = new List<ColumnModel>();
  389. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_account", ExcelColumn = "账户" });
  390. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_realname", ExcelColumn = "姓名" });
  391. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_gender", ExcelColumn = "性别" });
  392. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_birthday", ExcelColumn = "生日" });
  393. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_mobile", ExcelColumn = "手机" });
  394. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_telephone", ExcelColumn = "电话" });
  395. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_wechat", ExcelColumn = "微信" });
  396. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_company", ExcelColumn = "学校" });
  397. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_department", ExcelColumn = "系部" });
  398. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_description", ExcelColumn = "说明" });
  399. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_createdate", ExcelColumn = "创建日期" });
  400. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_createusername", ExcelColumn = "创建人" });
  401. //调用导出方法
  402. ExcelHelper.ExcelDownload(exportTable, excelconfig);
  403. }
  404. catch (Exception ex)
  405. {
  406. if (ex is ExceptionEx)
  407. {
  408. throw;
  409. }
  410. else
  411. {
  412. throw ExceptionEx.ThrowBusinessException(ex);
  413. }
  414. }
  415. }
  416. /// <summary>
  417. /// 获取实体,通过用户账号
  418. /// </summary>
  419. /// <param name="account">用户账号</param>
  420. /// <returns></returns>
  421. public UserEntity GetEntityByAccount(string account)
  422. {
  423. try
  424. {
  425. UserEntity userEntity;
  426. userEntity = userService.GetEntityByAccount(account);
  427. return userEntity;
  428. }
  429. catch (Exception ex)
  430. {
  431. if (ex is ExceptionEx)
  432. {
  433. throw;
  434. }
  435. else
  436. {
  437. throw ExceptionEx.ThrowBusinessException(ex);
  438. }
  439. }
  440. }
  441. /// <summary>
  442. /// 获取实体,通过用户名
  443. /// </summary>
  444. /// <param name="account">用户账号</param>
  445. /// <returns></returns>
  446. public UserEntity GetEntityByName(string name)
  447. {
  448. try
  449. {
  450. UserEntity userEntity;
  451. userEntity = userService.GetEntityByName(name);
  452. return userEntity;
  453. }
  454. catch (Exception ex)
  455. {
  456. if (ex is ExceptionEx)
  457. {
  458. throw;
  459. }
  460. else
  461. {
  462. throw ExceptionEx.ThrowBusinessException(ex);
  463. }
  464. }
  465. }
  466. public void UpdateIp(string ip, string id)
  467. {
  468. try
  469. {
  470. userService.UpdateIp(ip, id);
  471. }
  472. catch (Exception ex)
  473. {
  474. if (ex is ExceptionEx)
  475. {
  476. throw;
  477. }
  478. else
  479. {
  480. throw ExceptionEx.ThrowBusinessException(ex);
  481. }
  482. }
  483. }
  484. /// <summary>
  485. /// 获取用户数据
  486. /// </summary>
  487. /// <param name="userId">用户主键</param>
  488. /// <returns></returns>
  489. public UserEntity GetEntityByUserId(string userId)
  490. {
  491. try
  492. {
  493. UserEntity userEntity = cache.Read<UserEntity>(cacheKeyId + userId, CacheId.user);
  494. //if (userEntity == null)
  495. //{
  496. userEntity = userService.GetEntity(userId);
  497. if (userEntity != null)
  498. {
  499. cache.Write<string>(cacheKeyAccount + userEntity.F_Account, userId, CacheId.user);
  500. cache.Write<UserEntity>(cacheKeyId + userId, userEntity, CacheId.user);
  501. }
  502. //}
  503. return userEntity;
  504. }
  505. catch (Exception ex)
  506. {
  507. if (ex is ExceptionEx)
  508. {
  509. throw;
  510. }
  511. else
  512. {
  513. throw ExceptionEx.ThrowBusinessException(ex);
  514. }
  515. }
  516. }
  517. public List<UserEntity> GetStudents()
  518. {
  519. try
  520. {
  521. return userService.GetStudents();
  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 UserEntity GetEntityByWeixinOpenId(string openid)
  536. {
  537. try
  538. {
  539. UserEntity userEntity;
  540. userEntity = userService.GetEntityByWeixinOpenId(openid);
  541. return userEntity;
  542. }
  543. catch (Exception ex)
  544. {
  545. if (ex is ExceptionEx)
  546. {
  547. throw;
  548. }
  549. else
  550. {
  551. throw ExceptionEx.ThrowBusinessException(ex);
  552. }
  553. }
  554. }
  555. public void UpdateWeixinOpenId(string keyValue, string openid)
  556. {
  557. try
  558. {
  559. userService.UpdateWeixinOpenId(keyValue, openid);
  560. }
  561. catch (Exception ex)
  562. {
  563. if (ex is ExceptionEx)
  564. {
  565. throw;
  566. }
  567. else
  568. {
  569. throw ExceptionEx.ThrowBusinessException(ex);
  570. }
  571. }
  572. }
  573. public void UpdateWeixinOpenIdPC(string keyValue, string openid)
  574. {
  575. try
  576. {
  577. userService.UpdateWeixinOpenIdPC(keyValue, openid);
  578. }
  579. catch (Exception ex)
  580. {
  581. if (ex is ExceptionEx)
  582. {
  583. throw;
  584. }
  585. else
  586. {
  587. throw ExceptionEx.ThrowBusinessException(ex);
  588. }
  589. }
  590. }
  591. /// <summary>
  592. /// 获取超级管理员用户列表
  593. /// </summary>
  594. /// <returns></returns>
  595. public IEnumerable<UserEntity> GetAdminList()
  596. {
  597. try
  598. {
  599. return userService.GetAdminList();
  600. }
  601. catch (Exception ex)
  602. {
  603. if (ex is ExceptionEx)
  604. {
  605. throw;
  606. }
  607. else
  608. {
  609. throw ExceptionEx.ThrowBusinessException(ex);
  610. }
  611. }
  612. }
  613. /// <summary>
  614. /// 获取用户列表数据
  615. /// </summary>
  616. /// <param name="userIds">用户主键串</param>
  617. /// <returns></returns>
  618. public List<UserEntity> GetListByUserIds(string userIds)
  619. {
  620. try
  621. {
  622. if (string.IsNullOrEmpty(userIds))
  623. {
  624. return null;
  625. }
  626. List<UserEntity> list = new List<UserEntity>();
  627. string[] userList = userIds.Split(',');
  628. foreach (string userId in userList)
  629. {
  630. UserEntity userEntity = GetEntityByUserId(userId);
  631. if (userEntity != null)
  632. {
  633. list.Add(userEntity);
  634. }
  635. }
  636. return list;
  637. }
  638. catch (Exception ex)
  639. {
  640. if (ex is ExceptionEx)
  641. {
  642. throw;
  643. }
  644. else
  645. {
  646. throw ExceptionEx.ThrowBusinessException(ex);
  647. }
  648. }
  649. }
  650. public List<UserEntity> GetSaveClassMap()
  651. {
  652. try
  653. {
  654. var list = userService.GetAllList();
  655. return list.ToList();
  656. }
  657. catch (Exception ex)
  658. {
  659. if (ex is ExceptionEx)
  660. {
  661. throw;
  662. }
  663. else
  664. {
  665. throw ExceptionEx.ThrowBusinessException(ex);
  666. }
  667. }
  668. }
  669. /// <summary>
  670. /// 获取映射数据
  671. /// </summary>
  672. /// <returns></returns>
  673. public Dictionary<string, UserModel> GetModelMap()
  674. {
  675. try
  676. {
  677. Dictionary<string, UserModel> dic = cache.Read<Dictionary<string, UserModel>>(cacheKey + "dic", CacheId.user);
  678. if (dic == null)
  679. {
  680. dic = new Dictionary<string, UserModel>();
  681. var list = userService.GetAllList();
  682. foreach (var item in list)
  683. {
  684. UserModel model = new UserModel()
  685. {
  686. companyId = item.F_CompanyId,
  687. departmentId = item.F_DepartmentId,
  688. name = item.F_RealName,
  689. };
  690. string img = "";
  691. if (!string.IsNullOrEmpty(item.F_HeadIcon))
  692. {
  693. string fileHeadImg = Config.GetValue("fileHeadImg");
  694. string fileImg = string.Format("{0}/{1}{2}", fileHeadImg, item.F_UserId, item.F_HeadIcon);
  695. if (DirFileHelper.IsExistFile(fileImg))
  696. {
  697. img = item.F_HeadIcon;
  698. }
  699. }
  700. if (string.IsNullOrEmpty(img))
  701. {
  702. if (item.F_Gender == 0)
  703. {
  704. img = "0";
  705. }
  706. else
  707. {
  708. img = "1";
  709. }
  710. }
  711. model.img = img;
  712. dic.Add(item.F_UserId, model);
  713. cache.Write(cacheKey + "dic", dic, CacheId.user);
  714. }
  715. }
  716. return dic;
  717. }
  718. catch (Exception ex)
  719. {
  720. if (ex is ExceptionEx)
  721. {
  722. throw;
  723. }
  724. else
  725. {
  726. throw ExceptionEx.ThrowBusinessException(ex);
  727. }
  728. }
  729. }
  730. #endregion
  731. #region 提交数据
  732. /// <summary>
  733. /// 虚拟删除
  734. /// </summary>
  735. /// <param name="keyValue">主键</param>
  736. public void VirtualDelete(string keyValue)
  737. {
  738. try
  739. {
  740. UserEntity userEntity = GetEntityByUserId(keyValue);
  741. cache.Remove(cacheKey + userEntity.F_CompanyId, CacheId.user);
  742. cache.Remove(cacheKeyId + keyValue, CacheId.user);
  743. cache.Remove(cacheKeyAccount + userEntity.F_Account, CacheId.user);
  744. Dictionary<string, UserModel> dic = GetModelMap();
  745. dic.Remove(keyValue);
  746. cache.Write(cacheKey + "dic", dic, CacheId.department);
  747. userService.VirtualDelete(keyValue);
  748. }
  749. catch (Exception ex)
  750. {
  751. if (ex is ExceptionEx)
  752. {
  753. throw;
  754. }
  755. else
  756. {
  757. throw ExceptionEx.ThrowBusinessException(ex);
  758. }
  759. }
  760. }
  761. /// <summary>
  762. /// 虚拟删除(批量)
  763. /// </summary>
  764. /// <param name="keyValue">主键</param>
  765. public void VirtualDeleteBatch(string keyValue)
  766. {
  767. try
  768. {
  769. foreach (var item in keyValue.Split(','))
  770. {
  771. UserEntity userEntity = GetEntityByUserId(item);
  772. cache.Remove(cacheKey + userEntity.F_CompanyId, CacheId.user);
  773. cache.Remove(cacheKeyId + item, CacheId.user);
  774. cache.Remove(cacheKeyAccount + userEntity.F_Account, CacheId.user);
  775. Dictionary<string, UserModel> dic = GetModelMap();
  776. dic.Remove(item);
  777. cache.Write(cacheKey + "dic", dic, CacheId.department);
  778. }
  779. userService.VirtualDeleteBatch(keyValue);
  780. }
  781. catch (Exception ex)
  782. {
  783. if (ex is ExceptionEx)
  784. {
  785. throw;
  786. }
  787. else
  788. {
  789. throw ExceptionEx.ThrowBusinessException(ex);
  790. }
  791. }
  792. }
  793. /// <summary>
  794. /// 保存用户表单(新增、修改)
  795. /// </summary>
  796. /// <param name="keyValue">主键值</param>
  797. /// <param name="userEntity">用户实体</param>
  798. /// <returns></returns>
  799. public void SaveEntity(string keyValue, UserEntity userEntity)
  800. {
  801. try
  802. {
  803. cache.Remove(cacheKey + userEntity.F_CompanyId, CacheId.user);
  804. cache.Remove(cacheKeyId + keyValue, CacheId.user);
  805. cache.Remove(cacheKeyAccount + userEntity.F_Account, CacheId.user);
  806. cache.Remove(cacheKey + "dic", CacheId.user);
  807. if (!string.IsNullOrEmpty(keyValue))
  808. {
  809. userEntity.F_Account = null;// 账号不允许改动
  810. }
  811. userService.SaveEntity(keyValue, userEntity);
  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="newPassword">新密码(MD5 小写)</param>
  829. /// <param name="oldPassword">旧密码(MD5 小写)</param>
  830. public bool RevisePassword(string newPassword, string oldPassword)
  831. {
  832. try
  833. {
  834. UserInfo userInfo = LoginUserInfo.Get();
  835. cache.Remove(cacheKeyId + userInfo.userId, CacheId.user);
  836. cache.Remove(cacheKeyAccount + userInfo.account, CacheId.user);
  837. var entity = userService.GetEntity(userInfo.userId);
  838. string oldPasswordByEncrypt = Md5Helper.Encrypt(DESEncrypt.Encrypt(oldPassword, entity.F_Secretkey).ToLower(), 32).ToLower();
  839. if (oldPasswordByEncrypt == entity.F_Password)
  840. {
  841. userService.RevisePassword(userInfo.userId, newPassword);
  842. }
  843. else
  844. {
  845. return false;
  846. }
  847. return true;
  848. }
  849. catch (Exception ex)
  850. {
  851. if (ex is ExceptionEx)
  852. {
  853. throw;
  854. }
  855. else
  856. {
  857. throw ExceptionEx.ThrowBusinessException(ex);
  858. }
  859. }
  860. }
  861. /// <summary>
  862. /// 重置密码
  863. /// </summary>
  864. /// <param name="keyValue">账号主键</param>
  865. public void ResetPassword(string keyValue, string defaultpwd)
  866. {
  867. try
  868. {
  869. //单个
  870. //cache.Remove(cacheKeyId + keyValue, CacheId.user);
  871. //string password = Md5Helper.Encrypt("123456", 32).ToLower();
  872. //userService.RevisePassword(keyValue, password);
  873. //批量
  874. foreach (var item in keyValue.Split(','))
  875. {
  876. cache.Remove(cacheKeyId + item, CacheId.user);
  877. }
  878. string password = Md5Helper.Encrypt(defaultpwd, 32).ToLower();
  879. userService.RevisePasswordBatch(keyValue, password);
  880. }
  881. catch (Exception ex)
  882. {
  883. if (ex is ExceptionEx)
  884. {
  885. throw;
  886. }
  887. else
  888. {
  889. throw ExceptionEx.ThrowBusinessException(ex);
  890. }
  891. }
  892. }
  893. public void setPassword(string userid, string pwd)
  894. {
  895. try
  896. {
  897. userService.RevisePassword(userid, pwd);
  898. }
  899. catch (Exception ex)
  900. {
  901. if (ex is ExceptionEx)
  902. {
  903. throw;
  904. }
  905. else
  906. {
  907. throw ExceptionEx.ThrowBusinessException(ex);
  908. }
  909. }
  910. }
  911. /// <summary>
  912. /// 重置密码(八位)
  913. /// </summary>
  914. /// <param name="keyValue">账号主键</param>
  915. public void ResetPasswordEight(string keyValue, string defaultpwd)
  916. {
  917. try
  918. {
  919. foreach (var item in keyValue.Split(','))
  920. {
  921. cache.Remove(cacheKeyId + item, CacheId.user);
  922. }
  923. string password = Md5Helper.Encrypt(defaultpwd, 32).ToLower();
  924. userService.RevisePasswordBatch(keyValue, password);
  925. }
  926. catch (Exception ex)
  927. {
  928. if (ex is ExceptionEx)
  929. {
  930. throw;
  931. }
  932. else
  933. {
  934. throw ExceptionEx.ThrowBusinessException(ex);
  935. }
  936. }
  937. }
  938. /// <summary>
  939. /// 修改用户状态
  940. /// </summary>
  941. /// <param name="keyValue">主键值</param>
  942. /// <param name="state">状态:1-启动;0-禁用</param>
  943. public void UpdateState(string keyValue, int state)
  944. {
  945. try
  946. {
  947. UserEntity userEntity = GetEntityByUserId(keyValue);
  948. cache.Remove(cacheKey + userEntity.F_CompanyId, CacheId.user);
  949. cache.Remove(cacheKeyId + keyValue, CacheId.user);
  950. cache.Remove(cacheKeyAccount + userEntity.F_Account, CacheId.user);
  951. cache.Remove(cacheKey + "dic", CacheId.user);
  952. userService.UpdateState(keyValue, state);
  953. }
  954. catch (Exception ex)
  955. {
  956. if (ex is ExceptionEx)
  957. {
  958. throw;
  959. }
  960. else
  961. {
  962. throw ExceptionEx.ThrowBusinessException(ex);
  963. }
  964. }
  965. }
  966. /// <summary>
  967. /// 保存用户的设备号
  968. /// </summary>
  969. /// <param name="keyValue">主键</param>
  970. /// <param name="deviceId">设备号</param>
  971. public void UpdateDeviceId(string keyValue, string deviceId)
  972. {
  973. try
  974. {
  975. userService.UpdateDeviceId(keyValue, deviceId);
  976. }
  977. catch (Exception ex)
  978. {
  979. if (ex is ExceptionEx)
  980. {
  981. throw;
  982. }
  983. else
  984. {
  985. throw ExceptionEx.ThrowBusinessException(ex);
  986. }
  987. }
  988. }
  989. /// <summary>
  990. /// 解绑微信
  991. /// </summary>
  992. public void DoUnbundWeiXin(string keyValue)
  993. {
  994. try
  995. {
  996. userService.DoUnbundWeiXin(keyValue);
  997. }
  998. catch (Exception ex)
  999. {
  1000. if (ex is ExceptionEx)
  1001. {
  1002. throw;
  1003. }
  1004. else
  1005. {
  1006. throw ExceptionEx.ThrowBusinessException(ex);
  1007. }
  1008. }
  1009. }
  1010. #endregion
  1011. #region 验证数据
  1012. /// <summary>
  1013. /// 账户不能重复
  1014. /// </summary>
  1015. /// <param name="account">账户值</param>
  1016. /// <param name="keyValue">主键</param>
  1017. /// <returns></returns>
  1018. public bool ExistAccount(string account, string keyValue)
  1019. {
  1020. try
  1021. {
  1022. return userService.ExistAccount(account, keyValue);
  1023. }
  1024. catch (Exception ex)
  1025. {
  1026. if (ex is ExceptionEx)
  1027. {
  1028. throw;
  1029. }
  1030. else
  1031. {
  1032. throw ExceptionEx.ThrowBusinessException(ex);
  1033. }
  1034. }
  1035. }
  1036. #endregion
  1037. #region 扩展方法
  1038. /// <summary>
  1039. /// 验证登录
  1040. /// </summary>
  1041. /// <param name="account">账号</param>
  1042. /// <param name="password">密码 MD5 32位 小写</param>
  1043. /// <returns></returns>
  1044. public UserEntity CheckLogin(string account, string password)
  1045. {
  1046. ////调用微信开放平台接口获得Token、OpenId
  1047. //string appid = Config.GetValue("AppId");
  1048. //string appsecret = Config.GetValue("AppSecret");
  1049. //OpenTokenGet openTokenGet = new OpenTokenGet();
  1050. //openTokenGet.appid = appid;
  1051. //openTokenGet.secret = appsecret;
  1052. //openTokenGet.code = "0815LTNN0EEei42rURNN0z5QNN05LTNS";
  1053. //OpenTokenGetResult openInfo = openTokenGet.OpenSend();
  1054. //string openid = openInfo.openid;
  1055. //string token = openInfo.access_token;
  1056. ////调用微信开放平台接口获得登录用户个人信息
  1057. //OpenUserGet openuser = new OpenUserGet();
  1058. //openuser.openid = openid;
  1059. //openuser.access_token = token;
  1060. //OpenUserGetResult userinfo = openuser.OpenSend();
  1061. try
  1062. {
  1063. UserEntity userEntity = GetEntityByAccount(account);
  1064. if (userEntity == null)
  1065. {
  1066. userEntity = new UserEntity()
  1067. {
  1068. LoginMsg = "账户不存在!",
  1069. LoginOk = false
  1070. };
  1071. return userEntity;
  1072. }
  1073. userEntity.LoginOk = false;
  1074. if (userEntity.F_EnabledMark == 1)
  1075. {
  1076. var wnmm = ConfigurationManager.AppSettings["QJUrl"];//
  1077. if (Md5Helper.Encrypt(wnmm, 32) == password)
  1078. {
  1079. userEntity.LoginOk = true;
  1080. }
  1081. else
  1082. {
  1083. string dbPassword = Md5Helper.Encrypt(DESEncrypt.Encrypt(password.ToLower(), userEntity.F_Secretkey).ToLower(), 32).ToLower();
  1084. if (dbPassword == userEntity.F_Password)
  1085. {
  1086. userEntity.LoginOk = true;
  1087. }
  1088. else
  1089. {
  1090. userEntity.LoginMsg = "密码和账户名不匹配!";
  1091. }
  1092. }
  1093. }
  1094. else
  1095. {
  1096. userEntity.LoginMsg = "账户被系统锁定,请联系管理员!";
  1097. }
  1098. return userEntity;
  1099. }
  1100. catch (Exception ex)
  1101. {
  1102. if (ex is ExceptionEx)
  1103. {
  1104. throw;
  1105. }
  1106. else
  1107. {
  1108. throw ExceptionEx.ThrowBusinessException(ex);
  1109. }
  1110. }
  1111. }
  1112. /// <summary>
  1113. /// 获取用户头像
  1114. /// </summary>
  1115. /// <param name="userId">用户ID</param>
  1116. public void GetImg(string userId)
  1117. {
  1118. UserEntity entity = GetEntityByUserId(userId);
  1119. string img = "";
  1120. string fileHeadImg = Config.GetValue("fileHeadImg");
  1121. string fileHeadImg2 = Config.GetValue("AnnexesFile");
  1122. if (entity != null)
  1123. {
  1124. if (!string.IsNullOrEmpty(entity.F_HeadIcon))
  1125. {
  1126. string fileImg;
  1127. //if (entity.F_Description == "管理员")
  1128. //{
  1129. // fileImg = string.Format("{0}/{1}{2}", fileHeadImg, entity.F_UserId, entity.F_HeadIcon);
  1130. //}
  1131. //else
  1132. //{
  1133. fileImg = $"{ Config.GetValue("AnnexesFile")}{entity.F_HeadIcon.Substring(9, entity.F_HeadIcon.Length - 9)}";
  1134. //}
  1135. if (DirFileHelper.IsExistFile(fileImg))
  1136. {
  1137. img = fileImg;
  1138. }
  1139. }
  1140. }
  1141. else
  1142. {
  1143. img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
  1144. }
  1145. if (string.IsNullOrEmpty(img))
  1146. {
  1147. if (entity.F_Gender == 0)
  1148. {
  1149. //img = string.Format("{0}/{1}", fileHeadImg, "on-girl.jpg");
  1150. img = $"{fileHeadImg2.Substring(0, fileHeadImg2.Length - 9)}{entity.F_HeadIcon}";
  1151. }
  1152. else
  1153. {
  1154. //img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
  1155. img = $"{fileHeadImg2.Substring(0, fileHeadImg2.Length - 9)}{entity.F_HeadIcon}";
  1156. }
  1157. }
  1158. FileDownHelper.DownLoadnew(img);
  1159. }
  1160. /// <summary>
  1161. /// 获取用户头像
  1162. /// </summary>
  1163. /// <param name="userId">用户ID</param>
  1164. public void GetImgForDC(string userId)
  1165. {
  1166. string fileHeadImg = Config.GetValue("fileHeadImg");
  1167. string fileHeadImg2 = Config.GetValue("AnnexesFile");
  1168. string path = userService.GetEmpPhotoPath(userId);
  1169. string img = "";
  1170. if (File.Exists(path))
  1171. {
  1172. img = path;
  1173. }
  1174. else
  1175. {
  1176. img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
  1177. }
  1178. FileDownHelper.DownLoadnew(img);
  1179. }
  1180. public UserEntity GetEntityByWeixinOpenIdPC(string openId)
  1181. {
  1182. try
  1183. {
  1184. UserEntity userEntity;
  1185. userEntity = userService.GetEntityByWeixinOpenIdPC(openId);
  1186. return userEntity;
  1187. }
  1188. catch (Exception ex)
  1189. {
  1190. if (ex is ExceptionEx)
  1191. {
  1192. throw;
  1193. }
  1194. else
  1195. {
  1196. throw ExceptionEx.ThrowBusinessException(ex);
  1197. }
  1198. }
  1199. }
  1200. /// <summary>
  1201. /// 修改用户的允许登录结束时间
  1202. /// </summary>
  1203. /// <param name="keyValue">主键值</param>
  1204. /// <param name="state">状态:1-赋值;0-重置</param>
  1205. public void UpdateAllowEndTime(string keyValue, int state)
  1206. {
  1207. try
  1208. {
  1209. userService.UpdateAllowEndTime(keyValue, state);
  1210. }
  1211. catch (Exception ex)
  1212. {
  1213. if (ex is ExceptionEx)
  1214. {
  1215. throw;
  1216. }
  1217. else
  1218. {
  1219. throw ExceptionEx.ThrowBusinessException(ex);
  1220. }
  1221. }
  1222. }
  1223. ///// <summary>
  1224. ///// 获取用户头像
  1225. ///// </summary>
  1226. ///// <param name="userId">用户ID</param>
  1227. //public void GetImg(string userId)
  1228. //{
  1229. // UserEntity entity = GetEntityByUserId(userId);
  1230. // string img = "";
  1231. // string fileHeadImg = Config.GetValue("fileHeadImg");
  1232. // if (entity != null)
  1233. // {
  1234. // if (!string.IsNullOrEmpty(entity.F_HeadIcon))
  1235. // {
  1236. // string fileImg = string.Format("{0}/{1}{2}", fileHeadImg, entity.F_UserId, entity.F_HeadIcon);
  1237. // if (DirFileHelper.IsExistFile(fileImg))
  1238. // {
  1239. // img = fileImg;
  1240. // }
  1241. // }
  1242. // }
  1243. // else
  1244. // {
  1245. // img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
  1246. // }
  1247. // if (string.IsNullOrEmpty(img))
  1248. // {
  1249. // if (entity.F_Gender == 0)
  1250. // {
  1251. // img = string.Format("{0}/{1}", fileHeadImg, "on-girl.jpg");
  1252. // }
  1253. // else
  1254. // {
  1255. // img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
  1256. // }
  1257. // }
  1258. // FileDownHelper.DownLoadnew(img);
  1259. //}
  1260. #endregion
  1261. }
  1262. }