Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

928 строки
30 KiB

  1. using Learun.DataBase.Repository;
  2. using Learun.Util;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Runtime.CompilerServices;
  8. using System.Text;
  9. namespace Learun.Application.Organization
  10. {
  11. /// <summary>
  12. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  13. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  14. /// 创建人:陈彬彬
  15. /// 日 期:2017.03.04
  16. /// 描 述:用户模块数据操作服务类
  17. /// </summary>
  18. public class UserService : RepositoryFactory
  19. {
  20. #region 属性 构造函数
  21. private string fieldSql;
  22. public UserService()
  23. {
  24. fieldSql = "t.*";
  25. }
  26. #endregion
  27. #region 获取数据
  28. /// <summary>
  29. /// 获取实体,通过用户账号
  30. /// </summary>
  31. /// <param name="account">用户账号</param>
  32. /// <returns></returns>
  33. public UserEntity GetEntityByAccount(string account)
  34. {
  35. try
  36. {
  37. var strSql = new StringBuilder();
  38. strSql.Append("SELECT ");
  39. strSql.Append(fieldSql);
  40. strSql.Append(" FROM LR_Base_User t ");
  41. strSql.Append(" WHERE t.F_Account = @account AND t.F_DeleteMark = 0 ");
  42. return this.BaseRepository().FindEntity<UserEntity>(strSql.ToString(), new { account = account });
  43. }
  44. catch (Exception ex)
  45. {
  46. if (ex is ExceptionEx)
  47. {
  48. throw;
  49. }
  50. else
  51. {
  52. throw ExceptionEx.ThrowServiceException(ex);
  53. }
  54. }
  55. }
  56. /// <summary>
  57. /// 获取实体,通过用户账号
  58. /// </summary>
  59. /// <param name="account">用户账号</param>
  60. /// <returns></returns>
  61. public UserEntity GetEntityByName(string name)
  62. {
  63. try
  64. {
  65. return this.BaseRepository()
  66. .FindEntity<UserEntity>(a => a.F_RealName.Equals(name) && a.F_DeleteMark == 0);
  67. }
  68. catch (Exception ex)
  69. {
  70. if (ex is ExceptionEx)
  71. {
  72. throw;
  73. }
  74. else
  75. {
  76. throw ExceptionEx.ThrowServiceException(ex);
  77. }
  78. }
  79. }
  80. /// <summary>
  81. /// 用户列表(根据公司主键)
  82. /// </summary>
  83. /// <param name="companyId">公司主键</param>
  84. /// <returns></returns>
  85. public IEnumerable<UserEntity> GetList(string companyId)
  86. {
  87. try
  88. {
  89. var strSql = new StringBuilder();
  90. strSql.Append("SELECT ");
  91. strSql.Append(fieldSql.Replace("t.F_Password,", "").Replace("t.F_Secretkey,", ""));
  92. strSql.Append(" FROM LR_Base_User t WHERE t.F_DeleteMark = 0 AND t.F_CompanyId = @companyId ORDER BY t.F_DepartmentId,t.F_RealName ");
  93. return this.BaseRepository().FindList<UserEntity>(strSql.ToString(), new { companyId = companyId });
  94. }
  95. catch (Exception ex)
  96. {
  97. if (ex is ExceptionEx)
  98. {
  99. throw;
  100. }
  101. else
  102. {
  103. throw ExceptionEx.ThrowServiceException(ex);
  104. }
  105. }
  106. }
  107. internal bool GetStuAny()
  108. {
  109. try
  110. {
  111. return this.BaseRepository().FindList<UserEntity>(a => a.F_Description == "学生").ToList().Count() > 0 ? true : false;
  112. }
  113. catch (Exception ex)
  114. {
  115. if (ex is ExceptionEx)
  116. {
  117. throw;
  118. }
  119. else
  120. {
  121. throw ExceptionEx.ThrowServiceException(ex);
  122. }
  123. }
  124. }
  125. internal bool GetAny()
  126. {
  127. try
  128. {
  129. return this.BaseRepository().FindList<UserEntity>(a =>a.F_Description == "教师"&&a.F_DeleteMark==1&&a.F_EnabledMark==1).ToList().Count() > 0 ? true : false;
  130. }
  131. catch (Exception ex)
  132. {
  133. if (ex is ExceptionEx)
  134. {
  135. throw;
  136. }
  137. else
  138. {
  139. throw ExceptionEx.ThrowServiceException(ex);
  140. }
  141. }
  142. }
  143. /// <summary>
  144. /// 用户列表(根据公司主键)(分页)
  145. /// </summary>
  146. /// <param name="companyId"></param>
  147. /// <param name="departmentId"></param>
  148. /// <param name="pagination"></param>
  149. /// <param name="keyword"></param>
  150. /// <param name="tp">类型 0学生 1 教师</param>
  151. /// <returns></returns>
  152. public IEnumerable<UserEntity> GetPageList(string companyId, string departmentId, Pagination pagination, string keyword, string tp)
  153. {
  154. try
  155. {
  156. var strSql = new StringBuilder();
  157. strSql.Append("SELECT ");
  158. strSql.Append(fieldSql.Replace("t.F_Password,", "").Replace("t.F_Secretkey,", ""));
  159. strSql.Append(",F_UserId as F_UserId_Log FROM LR_Base_User t WHERE t.F_DeleteMark = 0 AND t.F_CompanyId = @companyId ");
  160. if (!string.IsNullOrEmpty(departmentId))
  161. {
  162. strSql.Append(" AND t.F_DepartmentId = @departmentId ");
  163. }
  164. if (!string.IsNullOrEmpty(tp))
  165. {
  166. switch (tp)
  167. {
  168. case "0":
  169. strSql.Append(" AND t.F_Description='教师' ");
  170. break;
  171. case "1":
  172. strSql.Append(" AND t.F_Description='学生' ");
  173. break;
  174. case "2":
  175. strSql.Append(" AND t.F_Description='家长' ");
  176. break;
  177. }
  178. }
  179. if (!string.IsNullOrEmpty(keyword))
  180. {
  181. keyword = "%" + keyword + "%";
  182. strSql.Append(" AND( t.F_Account like @keyword or t.F_RealName like @keyword or t.F_Mobile like @keyword ) ");
  183. }
  184. return this.BaseRepository().FindList<UserEntity>(strSql.ToString(), new { companyId, departmentId, keyword }, pagination);
  185. }
  186. catch (Exception ex)
  187. {
  188. if (ex is ExceptionEx)
  189. {
  190. throw;
  191. }
  192. else
  193. {
  194. throw ExceptionEx.ThrowServiceException(ex);
  195. }
  196. }
  197. }
  198. /// <summary>
  199. /// 用户列表,全部
  200. /// </summary>
  201. /// <returns></returns>
  202. public IEnumerable<UserEntity> GetAllList()
  203. {
  204. try
  205. {
  206. var strSql = new StringBuilder();
  207. strSql.Append("SELECT ");
  208. strSql.Append(fieldSql.Replace("t.F_Password,", "").Replace("t.F_Secretkey,", ""));
  209. strSql.Append(" FROM LR_Base_User t WHERE t.F_DeleteMark = 0 ORDER BY t.F_CompanyId,t.F_DepartmentId,t.F_RealName ");
  210. return this.BaseRepository().FindList<UserEntity>(strSql.ToString());
  211. }
  212. catch (Exception ex)
  213. {
  214. if (ex is ExceptionEx)
  215. {
  216. throw;
  217. }
  218. else
  219. {
  220. throw ExceptionEx.ThrowServiceException(ex);
  221. }
  222. }
  223. }
  224. /// <summary>
  225. /// 用户列表(导出Excel)
  226. /// </summary>
  227. /// <returns></returns>
  228. public DataTable GetExportList()
  229. {
  230. try
  231. {
  232. var strSql = new StringBuilder();
  233. strSql.Append(@"SELECT u.F_Account
  234. ,u.F_RealName
  235. ,CASE WHEN u.F_Gender=1 THEN '男' ELSE '女' END AS F_Gender
  236. ,CASE WHEN u.F_EnabledMark=1 THEN '正常' ELSE '禁用' END AS F_EnabledMark
  237. ,u.F_Birthday
  238. ,u.F_Mobile
  239. ,u.F_Telephone
  240. ,u.F_WeChat
  241. ,o.F_FullName AS F_Company
  242. ,d.F_FullName AS F_Department
  243. ,u.F_Description
  244. ,u.F_CreateDate
  245. ,u.F_CreateUserName
  246. FROM LR_Base_User u
  247. INNER JOIN LR_Base_Department d ON u.F_DepartmentId=d.F_DepartmentId
  248. INNER JOIN LR_Base_Company o ON u.F_CompanyId=o.F_CompanyId
  249. WHERE u.F_DeleteMark = 0 and u.F_Description = '教师'");
  250. return this.BaseRepository().FindTable(strSql.ToString());
  251. }
  252. catch (Exception ex)
  253. {
  254. if (ex is ExceptionEx)
  255. {
  256. throw;
  257. }
  258. else
  259. {
  260. throw ExceptionEx.ThrowServiceException(ex);
  261. }
  262. }
  263. }
  264. /// <summary>
  265. /// 用户列表(导出Excel)【学生】
  266. /// </summary>
  267. /// <returns></returns>
  268. public DataTable GetExportListOfStudent()
  269. {
  270. try
  271. {
  272. var strSql = new StringBuilder();
  273. strSql.Append(@"SELECT u.F_Account
  274. ,u.F_RealName
  275. ,CASE WHEN u.F_Gender=1 THEN '男' ELSE '女' END AS F_Gender
  276. ,u.F_Birthday
  277. ,u.F_Mobile
  278. ,u.F_Telephone
  279. ,u.F_WeChat
  280. ,o.F_FullName AS F_Company
  281. ,u.F_DepartmentId AS F_Department
  282. ,u.F_Description
  283. ,u.F_CreateDate
  284. ,u.F_CreateUserName
  285. FROM LR_Base_User u
  286. INNER JOIN LR_Base_Company o ON u.F_CompanyId=o.F_CompanyId
  287. WHERE u.F_DeleteMark = 0 and u.F_Description = '学生'");
  288. return this.BaseRepository().FindTable(strSql.ToString());
  289. }
  290. catch (Exception ex)
  291. {
  292. if (ex is ExceptionEx)
  293. {
  294. throw;
  295. }
  296. else
  297. {
  298. throw ExceptionEx.ThrowServiceException(ex);
  299. }
  300. }
  301. }
  302. /// <summary>
  303. /// 用户列表(导出Excel)【家长】
  304. /// </summary>
  305. /// <returns></returns>
  306. public DataTable GetExportListOfFamily()
  307. {
  308. try
  309. {
  310. var strSql = new StringBuilder();
  311. strSql.Append(@"SELECT u.F_Account
  312. ,u.F_RealName
  313. ,CASE WHEN u.F_Gender=1 THEN '男' ELSE '女' END AS F_Gender
  314. ,u.F_Birthday
  315. ,u.F_Mobile
  316. ,u.F_Telephone
  317. ,u.F_WeChat
  318. ,o.F_FullName AS F_Company
  319. ,u.F_DepartmentId AS F_Department
  320. ,u.F_Description
  321. ,u.F_CreateDate
  322. ,u.F_CreateUserName
  323. FROM LR_Base_User u
  324. INNER JOIN LR_Base_Company o ON u.F_CompanyId=o.F_CompanyId
  325. WHERE u.F_DeleteMark = 0 and u.F_Description = '家长'");
  326. return this.BaseRepository().FindTable(strSql.ToString());
  327. }
  328. catch (Exception ex)
  329. {
  330. if (ex is ExceptionEx)
  331. {
  332. throw;
  333. }
  334. else
  335. {
  336. throw ExceptionEx.ThrowServiceException(ex);
  337. }
  338. }
  339. }
  340. /// <summary>
  341. /// 用户实体
  342. /// </summary>
  343. /// <param name="keyValue">主键值</param>
  344. /// <returns></returns>
  345. public UserEntity GetEntity(string keyValue)
  346. {
  347. try
  348. {
  349. return this.BaseRepository().FindEntity<UserEntity>(t => t.F_UserId == keyValue && t.F_DeleteMark == 0);
  350. }
  351. catch (Exception ex)
  352. {
  353. if (ex is ExceptionEx)
  354. {
  355. throw;
  356. }
  357. else
  358. {
  359. throw ExceptionEx.ThrowServiceException(ex);
  360. }
  361. }
  362. }
  363. #endregion
  364. #region 验证数据
  365. /// <summary>
  366. /// 账户不能重复
  367. /// </summary>
  368. /// <param name="account">账户值</param>
  369. /// <param name="keyValue">主键</param>
  370. /// <returns></returns>
  371. public bool ExistAccount(string account, string keyValue)
  372. {
  373. try
  374. {
  375. var expression = LinqExtensions.True<UserEntity>();
  376. expression = expression.And(t => t.F_Account == account);
  377. if (!string.IsNullOrEmpty(keyValue))
  378. {
  379. expression = expression.And(t => t.F_UserId != keyValue);
  380. }
  381. return this.BaseRepository().IQueryable(expression).Count() == 0 ? true : false;
  382. }
  383. catch (Exception ex)
  384. {
  385. if (ex is ExceptionEx)
  386. {
  387. throw;
  388. }
  389. else
  390. {
  391. throw ExceptionEx.ThrowServiceException(ex);
  392. }
  393. }
  394. }
  395. #endregion
  396. #region 提交数据
  397. /// <summary>
  398. /// 虚拟删除
  399. /// </summary>
  400. /// <param name="keyValue">主键</param>
  401. public void VirtualDelete(string keyValue)
  402. {
  403. try
  404. {
  405. UserEntity entity = new UserEntity()
  406. {
  407. F_UserId = keyValue,
  408. F_DeleteMark = 1
  409. };
  410. this.BaseRepository().Update(entity);
  411. }
  412. catch (Exception ex)
  413. {
  414. if (ex is ExceptionEx)
  415. {
  416. throw;
  417. }
  418. else
  419. {
  420. throw ExceptionEx.ThrowServiceException(ex);
  421. }
  422. }
  423. }
  424. /// <summary>
  425. /// 虚拟删除(批量)
  426. /// </summary>
  427. /// <param name="keyValue">主键</param>
  428. public void VirtualDeleteBatch(string keyValue)
  429. {
  430. var db = this.BaseRepository().BeginTrans();
  431. try
  432. {
  433. foreach (var item in keyValue.Split(','))
  434. {
  435. UserEntity entity = new UserEntity()
  436. {
  437. F_UserId = item,
  438. F_DeleteMark = 1
  439. };
  440. db.Update(entity);
  441. db.ExecuteBySql("delete from LR_Base_UserRelation where F_UserId='" + keyValue + "'");
  442. }
  443. db.Commit();
  444. }
  445. catch (Exception ex)
  446. {
  447. db.Rollback();
  448. }
  449. }
  450. internal List<UserEntity> GetStudents()
  451. {
  452. try
  453. {
  454. return this.BaseRepository().FindList<UserEntity>(a => a.F_Description == "学生").ToList();
  455. }
  456. catch (Exception ex)
  457. {
  458. if (ex is ExceptionEx)
  459. {
  460. throw;
  461. }
  462. else
  463. {
  464. throw ExceptionEx.ThrowServiceException(ex);
  465. }
  466. }
  467. }
  468. /// <summary>
  469. /// 保存用户表单(新增、修改)
  470. /// </summary>
  471. /// <param name="keyValue">主键值</param>
  472. /// <param name="userEntity">用户实体</param>
  473. /// <returns></returns>
  474. public void SaveEntity(string keyValue, UserEntity userEntity)
  475. {
  476. try
  477. {
  478. if (string.IsNullOrEmpty(keyValue))
  479. {
  480. userEntity.Create();
  481. userEntity.F_Secretkey = Md5Helper.Encrypt(CommonHelper.CreateNo(), 16).ToLower();
  482. userEntity.F_Password = Md5Helper.Encrypt(DESEncrypt.Encrypt(userEntity.F_Password, userEntity.F_Secretkey).ToLower(), 32).ToLower();
  483. this.BaseRepository().Insert(userEntity);
  484. }
  485. else
  486. {
  487. userEntity.Modify(keyValue);
  488. userEntity.F_Secretkey = null;
  489. userEntity.F_Password = null;
  490. this.BaseRepository().Update(userEntity);
  491. }
  492. }
  493. catch (Exception ex)
  494. {
  495. if (ex is ExceptionEx)
  496. {
  497. throw;
  498. }
  499. else
  500. {
  501. throw ExceptionEx.ThrowServiceException(ex);
  502. }
  503. }
  504. }
  505. /// <summary>
  506. /// 修改用户登录密码
  507. /// </summary>
  508. /// <param name="keyValue">主键值</param>
  509. /// <param name="password">新密码(MD5 小写)</param>
  510. public void RevisePassword(string keyValue, string password)
  511. {
  512. try
  513. {
  514. UserEntity userEntity = new UserEntity();
  515. userEntity.Modify(keyValue);
  516. userEntity.F_Secretkey = Md5Helper.Encrypt(CommonHelper.CreateNo(), 16).ToLower();
  517. userEntity.F_Password = Md5Helper.Encrypt(DESEncrypt.Encrypt(password, userEntity.F_Secretkey).ToLower(), 32).ToLower();
  518. this.BaseRepository().Update(userEntity);
  519. }
  520. catch (Exception ex)
  521. {
  522. if (ex is ExceptionEx)
  523. {
  524. throw;
  525. }
  526. else
  527. {
  528. throw ExceptionEx.ThrowServiceException(ex);
  529. }
  530. }
  531. }
  532. /// <summary>
  533. /// 修改用户登录密码(批量)
  534. /// </summary>
  535. /// <param name="keyValue">主键值</param>
  536. /// <param name="password">新密码(MD5 小写)</param>
  537. public void RevisePasswordBatch(string keyValue, string password)
  538. {
  539. var db = this.BaseRepository().BeginTrans();
  540. try
  541. {
  542. foreach (var item in keyValue.Split(','))
  543. {
  544. UserEntity userEntity = new UserEntity();
  545. userEntity.Modify(item);
  546. userEntity.F_Secretkey = Md5Helper.Encrypt(CommonHelper.CreateNo(), 16).ToLower();
  547. userEntity.F_Password = Md5Helper.Encrypt(DESEncrypt.Encrypt(password, userEntity.F_Secretkey).ToLower(), 32).ToLower();
  548. db.Update(userEntity);
  549. }
  550. db.Commit();
  551. }
  552. catch (Exception ex)
  553. {
  554. db.Rollback();
  555. }
  556. }
  557. /// <summary>
  558. /// 修改用户状态
  559. /// </summary>
  560. /// <param name="keyValue">主键值</param>
  561. /// <param name="state">状态:1-启动;0-禁用</param>
  562. public void UpdateState(string keyValue, int state)
  563. {
  564. try
  565. {
  566. UserEntity userEntity = new UserEntity();
  567. userEntity.Modify(keyValue);
  568. userEntity.F_EnabledMark = state;
  569. this.BaseRepository().Update(userEntity);
  570. }
  571. catch (Exception ex)
  572. {
  573. if (ex is ExceptionEx)
  574. {
  575. throw;
  576. }
  577. else
  578. {
  579. throw ExceptionEx.ThrowServiceException(ex);
  580. }
  581. }
  582. }
  583. /// <summary>
  584. /// 修改用户信息
  585. /// </summary>
  586. /// <param name="userEntity">实体对象</param>
  587. public void UpdateEntity(UserEntity userEntity)
  588. {
  589. try
  590. {
  591. this.BaseRepository().Update(userEntity);
  592. }
  593. catch (Exception ex)
  594. {
  595. if (ex is ExceptionEx)
  596. {
  597. throw;
  598. }
  599. else
  600. {
  601. throw ExceptionEx.ThrowServiceException(ex);
  602. }
  603. }
  604. }
  605. public List<UserEntity> GetUserByDepartmentId(string departmentId)
  606. {
  607. try
  608. {
  609. return this.BaseRepository().FindList<UserEntity>(a => a.F_DepartmentId == departmentId).ToList();
  610. }
  611. catch (Exception ex)
  612. {
  613. if (ex is ExceptionEx)
  614. {
  615. throw;
  616. }
  617. else
  618. {
  619. throw ExceptionEx.ThrowServiceException(ex);
  620. }
  621. }
  622. }
  623. public List<UserEntity> GetListByDepartmentIds(string departmentId)
  624. {
  625. try
  626. {
  627. var ids = departmentId.Split(',');
  628. return this.BaseRepository().FindList<UserEntity>(a => ids.Contains(a.F_DepartmentId)).ToList();
  629. }
  630. catch (Exception ex)
  631. {
  632. if (ex is ExceptionEx)
  633. {
  634. throw;
  635. }
  636. else
  637. {
  638. throw ExceptionEx.ThrowServiceException(ex);
  639. }
  640. }
  641. }
  642. /// <summary>
  643. /// 保存用户的设备号
  644. /// </summary>
  645. /// <param name="keyValue">主键</param>
  646. /// <param name="deviceId">设备号</param>
  647. public void UpdateDeviceId(string keyValue, string deviceId)
  648. {
  649. try
  650. {
  651. var userEntity = this.BaseRepository().FindEntity<UserEntity>(keyValue);
  652. if (userEntity != null)
  653. {
  654. userEntity.F_DeviceId = deviceId;
  655. userEntity.Modify(keyValue);
  656. this.BaseRepository().Update(userEntity);
  657. }
  658. }
  659. catch (Exception ex)
  660. {
  661. if (ex is ExceptionEx)
  662. {
  663. throw;
  664. }
  665. else
  666. {
  667. throw ExceptionEx.ThrowServiceException(ex);
  668. }
  669. }
  670. }
  671. #endregion
  672. public UserEntity GetEntityByWeixinOpenId(string openid)
  673. {
  674. try
  675. {
  676. var strSql = new StringBuilder();
  677. strSql.Append("SELECT ");
  678. strSql.Append(fieldSql);
  679. strSql.Append(" FROM LR_Base_User t ");
  680. strSql.Append(" WHERE t.OpenIdForWeixin = @openid AND t.F_DeleteMark = 0 ");
  681. return this.BaseRepository().FindEntity<UserEntity>(strSql.ToString(), new { openid = openid });
  682. }
  683. catch (Exception ex)
  684. {
  685. if (ex is ExceptionEx)
  686. {
  687. throw;
  688. }
  689. else
  690. {
  691. throw ExceptionEx.ThrowServiceException(ex);
  692. }
  693. }
  694. }
  695. public UserEntity GetEntityByWeixinOpenIdPC(string openid)
  696. {
  697. try
  698. {
  699. var strSql = new StringBuilder();
  700. strSql.Append("SELECT ");
  701. strSql.Append(fieldSql);
  702. strSql.Append(" FROM LR_Base_User t ");
  703. strSql.Append(" WHERE t.OpenIdForWeixinPC = @openid AND t.F_DeleteMark = 0 ");
  704. return this.BaseRepository().FindEntity<UserEntity>(strSql.ToString(), new { openid = openid });
  705. }
  706. catch (Exception ex)
  707. {
  708. if (ex is ExceptionEx)
  709. {
  710. throw;
  711. }
  712. else
  713. {
  714. throw ExceptionEx.ThrowServiceException(ex);
  715. }
  716. }
  717. }
  718. public void UpdateWeixinOpenId(string keyValue, string openid)
  719. {
  720. try
  721. {
  722. var userEntity = this.BaseRepository().FindEntity<UserEntity>(keyValue);
  723. if (userEntity != null)
  724. {
  725. userEntity.OpenIdForWeixin = openid;
  726. userEntity.Modify(keyValue);
  727. this.BaseRepository().Update(userEntity);
  728. }
  729. }
  730. catch (Exception ex)
  731. {
  732. if (ex is ExceptionEx)
  733. {
  734. throw;
  735. }
  736. else
  737. {
  738. throw ExceptionEx.ThrowServiceException(ex);
  739. }
  740. }
  741. }
  742. public void UpdateWeixinOpenIdPC(string keyValue, string openid)
  743. {
  744. try
  745. {
  746. var userEntity = this.BaseRepository().FindEntity<UserEntity>(keyValue);
  747. if (userEntity != null)
  748. {
  749. userEntity.OpenIdForWeixinPC = openid;
  750. userEntity.Modify(keyValue);
  751. this.BaseRepository().Update(userEntity);
  752. }
  753. }
  754. catch (Exception ex)
  755. {
  756. if (ex is ExceptionEx)
  757. {
  758. throw;
  759. }
  760. else
  761. {
  762. throw ExceptionEx.ThrowServiceException(ex);
  763. }
  764. }
  765. }
  766. /// <summary>
  767. /// 获取超级管理员用户列表
  768. /// </summary>
  769. /// <returns></returns>
  770. public IEnumerable<UserEntity> GetAdminList()
  771. {
  772. try
  773. {
  774. return this.BaseRepository().FindList<UserEntity>(t => t.F_SecurityLevel == 1);
  775. }
  776. catch (Exception ex)
  777. {
  778. if (ex is ExceptionEx)
  779. {
  780. throw;
  781. }
  782. else
  783. {
  784. throw ExceptionEx.ThrowServiceException(ex);
  785. }
  786. }
  787. }
  788. /// <summary>
  789. /// 解绑微信
  790. /// </summary>
  791. public void DoUnbundWeiXin(string keyValue)
  792. {
  793. try
  794. {
  795. this.BaseRepository().ExecuteBySql("update LR_Base_User set OpenIdForWeixin=null where F_UserId='" + keyValue + "' ");
  796. }
  797. catch (Exception ex)
  798. {
  799. if (ex is ExceptionEx)
  800. {
  801. throw;
  802. }
  803. else
  804. {
  805. throw ExceptionEx.ThrowServiceException(ex);
  806. }
  807. }
  808. }
  809. public void UpdateIp(string ip, string id)
  810. {
  811. try
  812. {
  813. this.BaseRepository().ExecuteBySql("update LR_Base_User set LastIp='" + ip + "' where F_UserId='" + id + "' ");
  814. }
  815. catch (Exception ex)
  816. {
  817. if (ex is ExceptionEx)
  818. {
  819. throw;
  820. }
  821. else
  822. {
  823. throw ExceptionEx.ThrowServiceException(ex);
  824. }
  825. }
  826. }
  827. /// <summary>
  828. /// 获取用户头像,取empinfo照片
  829. /// </summary>
  830. /// <param name="userid"></param>
  831. /// <returns></returns>
  832. public string GetEmpPhotoPath(string userid)
  833. {
  834. string path = "";
  835. try
  836. {
  837. var userentity = BaseRepository().FindEntity<UserEntity>("select a.*,b.Photo from LR_Base_User a " +
  838. "left join " + BaseRepository("CollegeMIS").getDbConnection().Database +
  839. ".dbo.empinfo b on a.F_Account=b.empno where a.F_UserId='" + userid + "'", null);
  840. if (userentity != null && !string.IsNullOrEmpty(userentity.Photo))
  841. {
  842. //获取图片
  843. var LR_Base_AnnexesFile = BaseRepository().FindEntity<dynamic>("select * from LR_Base_AnnexesFile where F_FolderId='" + userentity.Photo + "'", null);
  844. if (LR_Base_AnnexesFile != null)
  845. {
  846. path = LR_Base_AnnexesFile.F_FilePath;
  847. }
  848. }
  849. return path;
  850. }
  851. catch (Exception ex)
  852. {
  853. if (ex is ExceptionEx)
  854. {
  855. throw;
  856. }
  857. else
  858. {
  859. throw ExceptionEx.ThrowServiceException(ex);
  860. }
  861. }
  862. }
  863. /// <summary>
  864. /// 修改用户的允许登录结束时间
  865. /// </summary>
  866. /// <param name="keyValue">主键值</param>
  867. /// <param name="state">状态:1-赋值;0-重置</param>
  868. public void UpdateAllowEndTime(string keyValue, int state)
  869. {
  870. try
  871. {
  872. if (state == 0)
  873. {
  874. this.BaseRepository().ExecuteBySql("update LR_Base_User set F_AllowEndTime=null where F_UserId='" + keyValue + "'");
  875. }
  876. else
  877. {
  878. this.BaseRepository().ExecuteBySql("update LR_Base_User set F_AllowEndTime='" + DateTime.Now + "' where F_UserId='" + keyValue + "'");
  879. }
  880. }
  881. catch (Exception ex)
  882. {
  883. if (ex is ExceptionEx)
  884. {
  885. throw;
  886. }
  887. else
  888. {
  889. throw ExceptionEx.ThrowServiceException(ex);
  890. }
  891. }
  892. }
  893. }
  894. }