您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

854 行
28 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 == "教师").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. }
  175. }
  176. if (!string.IsNullOrEmpty(keyword))
  177. {
  178. keyword = "%" + keyword + "%";
  179. strSql.Append(" AND( t.F_Account like @keyword or t.F_RealName like @keyword or t.F_Mobile like @keyword ) ");
  180. }
  181. return this.BaseRepository().FindList<UserEntity>(strSql.ToString(), new { companyId, departmentId, keyword }, pagination);
  182. }
  183. catch (Exception ex)
  184. {
  185. if (ex is ExceptionEx)
  186. {
  187. throw;
  188. }
  189. else
  190. {
  191. throw ExceptionEx.ThrowServiceException(ex);
  192. }
  193. }
  194. }
  195. /// <summary>
  196. /// 用户列表,全部
  197. /// </summary>
  198. /// <returns></returns>
  199. public IEnumerable<UserEntity> GetAllList()
  200. {
  201. try
  202. {
  203. var strSql = new StringBuilder();
  204. strSql.Append("SELECT ");
  205. strSql.Append(fieldSql.Replace("t.F_Password,", "").Replace("t.F_Secretkey,", ""));
  206. strSql.Append(" FROM LR_Base_User t WHERE t.F_DeleteMark = 0 ORDER BY t.F_CompanyId,t.F_DepartmentId,t.F_RealName ");
  207. return this.BaseRepository().FindList<UserEntity>(strSql.ToString());
  208. }
  209. catch (Exception ex)
  210. {
  211. if (ex is ExceptionEx)
  212. {
  213. throw;
  214. }
  215. else
  216. {
  217. throw ExceptionEx.ThrowServiceException(ex);
  218. }
  219. }
  220. }
  221. /// <summary>
  222. /// 用户列表(导出Excel)
  223. /// </summary>
  224. /// <returns></returns>
  225. public DataTable GetExportList()
  226. {
  227. try
  228. {
  229. var strSql = new StringBuilder();
  230. strSql.Append(@"SELECT u.F_Account
  231. ,u.F_RealName
  232. ,CASE WHEN u.F_Gender=1 THEN '男' ELSE '女' END AS F_Gender
  233. ,CASE WHEN u.F_EnabledMark=1 THEN '正常' ELSE '禁用' END AS F_EnabledMark
  234. ,u.F_Birthday
  235. ,u.F_Mobile
  236. ,u.F_Telephone
  237. ,u.F_WeChat
  238. ,o.F_FullName AS F_Company
  239. ,d.F_FullName AS F_Department
  240. ,u.F_Description
  241. ,u.F_CreateDate
  242. ,u.F_CreateUserName
  243. FROM LR_Base_User u
  244. INNER JOIN LR_Base_Department d ON u.F_DepartmentId=d.F_DepartmentId
  245. INNER JOIN LR_Base_Company o ON u.F_CompanyId=o.F_CompanyId
  246. WHERE u.F_DeleteMark = 0 and u.F_Description = '教师'");
  247. return this.BaseRepository().FindTable(strSql.ToString());
  248. }
  249. catch (Exception ex)
  250. {
  251. if (ex is ExceptionEx)
  252. {
  253. throw;
  254. }
  255. else
  256. {
  257. throw ExceptionEx.ThrowServiceException(ex);
  258. }
  259. }
  260. }
  261. /// <summary>
  262. /// 用户列表(导出Excel)【学生】
  263. /// </summary>
  264. /// <returns></returns>
  265. public DataTable GetExportListOfStudent()
  266. {
  267. try
  268. {
  269. var strSql = new StringBuilder();
  270. strSql.Append(@"SELECT u.F_Account
  271. ,u.F_RealName
  272. ,CASE WHEN u.F_Gender=1 THEN '男' ELSE '女' END AS F_Gender
  273. ,u.F_Birthday
  274. ,u.F_Mobile
  275. ,u.F_Telephone
  276. ,u.F_WeChat
  277. ,o.F_FullName AS F_Company
  278. ,u.F_DepartmentId AS F_Department
  279. ,u.F_Description
  280. ,u.F_CreateDate
  281. ,u.F_CreateUserName
  282. FROM LR_Base_User u
  283. INNER JOIN LR_Base_Company o ON u.F_CompanyId=o.F_CompanyId
  284. WHERE u.F_DeleteMark = 0 and u.F_Description = '学生'");
  285. return this.BaseRepository().FindTable(strSql.ToString());
  286. }
  287. catch (Exception ex)
  288. {
  289. if (ex is ExceptionEx)
  290. {
  291. throw;
  292. }
  293. else
  294. {
  295. throw ExceptionEx.ThrowServiceException(ex);
  296. }
  297. }
  298. }
  299. /// <summary>
  300. /// 用户实体
  301. /// </summary>
  302. /// <param name="keyValue">主键值</param>
  303. /// <returns></returns>
  304. public UserEntity GetEntity(string keyValue)
  305. {
  306. try
  307. {
  308. return this.BaseRepository().FindEntity<UserEntity>(t => t.F_UserId == keyValue && t.F_DeleteMark == 0);
  309. }
  310. catch (Exception ex)
  311. {
  312. if (ex is ExceptionEx)
  313. {
  314. throw;
  315. }
  316. else
  317. {
  318. throw ExceptionEx.ThrowServiceException(ex);
  319. }
  320. }
  321. }
  322. #endregion
  323. #region 验证数据
  324. /// <summary>
  325. /// 账户不能重复
  326. /// </summary>
  327. /// <param name="account">账户值</param>
  328. /// <param name="keyValue">主键</param>
  329. /// <returns></returns>
  330. public bool ExistAccount(string account, string keyValue)
  331. {
  332. try
  333. {
  334. var expression = LinqExtensions.True<UserEntity>();
  335. expression = expression.And(t => t.F_Account == account);
  336. if (!string.IsNullOrEmpty(keyValue))
  337. {
  338. expression = expression.And(t => t.F_UserId != keyValue);
  339. }
  340. return this.BaseRepository().IQueryable(expression).Count() == 0 ? true : false;
  341. }
  342. catch (Exception ex)
  343. {
  344. if (ex is ExceptionEx)
  345. {
  346. throw;
  347. }
  348. else
  349. {
  350. throw ExceptionEx.ThrowServiceException(ex);
  351. }
  352. }
  353. }
  354. #endregion
  355. #region 提交数据
  356. /// <summary>
  357. /// 虚拟删除
  358. /// </summary>
  359. /// <param name="keyValue">主键</param>
  360. public void VirtualDelete(string keyValue)
  361. {
  362. try
  363. {
  364. UserEntity entity = new UserEntity()
  365. {
  366. F_UserId = keyValue,
  367. F_DeleteMark = 1
  368. };
  369. this.BaseRepository().Update(entity);
  370. }
  371. catch (Exception ex)
  372. {
  373. if (ex is ExceptionEx)
  374. {
  375. throw;
  376. }
  377. else
  378. {
  379. throw ExceptionEx.ThrowServiceException(ex);
  380. }
  381. }
  382. }
  383. /// <summary>
  384. /// 虚拟删除(批量)
  385. /// </summary>
  386. /// <param name="keyValue">主键</param>
  387. public void VirtualDeleteBatch(string keyValue)
  388. {
  389. var db = this.BaseRepository().BeginTrans();
  390. try
  391. {
  392. foreach (var item in keyValue.Split(','))
  393. {
  394. UserEntity entity = new UserEntity()
  395. {
  396. F_UserId = item,
  397. F_DeleteMark = 1
  398. };
  399. db.Update(entity);
  400. db.ExecuteBySql("delete from LR_Base_UserRelation where F_UserId='" + keyValue + "'");
  401. }
  402. db.Commit();
  403. }
  404. catch (Exception ex)
  405. {
  406. db.Rollback();
  407. }
  408. }
  409. internal List<UserEntity> GetStudents()
  410. {
  411. try
  412. {
  413. return this.BaseRepository().FindList<UserEntity>(a => a.F_Description == "学生").ToList();
  414. }
  415. catch (Exception ex)
  416. {
  417. if (ex is ExceptionEx)
  418. {
  419. throw;
  420. }
  421. else
  422. {
  423. throw ExceptionEx.ThrowServiceException(ex);
  424. }
  425. }
  426. }
  427. /// <summary>
  428. /// 保存用户表单(新增、修改)
  429. /// </summary>
  430. /// <param name="keyValue">主键值</param>
  431. /// <param name="userEntity">用户实体</param>
  432. /// <returns></returns>
  433. public void SaveEntity(string keyValue, UserEntity userEntity)
  434. {
  435. try
  436. {
  437. if (string.IsNullOrEmpty(keyValue))
  438. {
  439. userEntity.Create();
  440. userEntity.F_Secretkey = Md5Helper.Encrypt(CommonHelper.CreateNo(), 16).ToLower();
  441. userEntity.F_Password = Md5Helper.Encrypt(DESEncrypt.Encrypt(userEntity.F_Password, userEntity.F_Secretkey).ToLower(), 32).ToLower();
  442. this.BaseRepository().Insert(userEntity);
  443. }
  444. else
  445. {
  446. userEntity.Modify(keyValue);
  447. userEntity.F_Secretkey = null;
  448. userEntity.F_Password = null;
  449. this.BaseRepository().Update(userEntity);
  450. }
  451. }
  452. catch (Exception ex)
  453. {
  454. if (ex is ExceptionEx)
  455. {
  456. throw;
  457. }
  458. else
  459. {
  460. throw ExceptionEx.ThrowServiceException(ex);
  461. }
  462. }
  463. }
  464. /// <summary>
  465. /// 修改用户登录密码
  466. /// </summary>
  467. /// <param name="keyValue">主键值</param>
  468. /// <param name="password">新密码(MD5 小写)</param>
  469. public void RevisePassword(string keyValue, string password)
  470. {
  471. try
  472. {
  473. UserEntity userEntity = new UserEntity();
  474. userEntity.Modify(keyValue);
  475. userEntity.F_Secretkey = Md5Helper.Encrypt(CommonHelper.CreateNo(), 16).ToLower();
  476. userEntity.F_Password = Md5Helper.Encrypt(DESEncrypt.Encrypt(password, userEntity.F_Secretkey).ToLower(), 32).ToLower();
  477. this.BaseRepository().Update(userEntity);
  478. }
  479. catch (Exception ex)
  480. {
  481. if (ex is ExceptionEx)
  482. {
  483. throw;
  484. }
  485. else
  486. {
  487. throw ExceptionEx.ThrowServiceException(ex);
  488. }
  489. }
  490. }
  491. /// <summary>
  492. /// 修改用户登录密码(批量)
  493. /// </summary>
  494. /// <param name="keyValue">主键值</param>
  495. /// <param name="password">新密码(MD5 小写)</param>
  496. public void RevisePasswordBatch(string keyValue, string password)
  497. {
  498. var db = this.BaseRepository().BeginTrans();
  499. try
  500. {
  501. foreach (var item in keyValue.Split(','))
  502. {
  503. UserEntity userEntity = new UserEntity();
  504. userEntity.Modify(item);
  505. userEntity.F_Secretkey = Md5Helper.Encrypt(CommonHelper.CreateNo(), 16).ToLower();
  506. userEntity.F_Password = Md5Helper.Encrypt(DESEncrypt.Encrypt(password, userEntity.F_Secretkey).ToLower(), 32).ToLower();
  507. db.Update(userEntity);
  508. }
  509. db.Commit();
  510. }
  511. catch (Exception ex)
  512. {
  513. db.Rollback();
  514. }
  515. }
  516. /// <summary>
  517. /// 修改用户状态
  518. /// </summary>
  519. /// <param name="keyValue">主键值</param>
  520. /// <param name="state">状态:1-启动;0-禁用</param>
  521. public void UpdateState(string keyValue, int state)
  522. {
  523. try
  524. {
  525. UserEntity userEntity = new UserEntity();
  526. userEntity.Modify(keyValue);
  527. userEntity.F_EnabledMark = state;
  528. this.BaseRepository().Update(userEntity);
  529. }
  530. catch (Exception ex)
  531. {
  532. if (ex is ExceptionEx)
  533. {
  534. throw;
  535. }
  536. else
  537. {
  538. throw ExceptionEx.ThrowServiceException(ex);
  539. }
  540. }
  541. }
  542. /// <summary>
  543. /// 修改用户信息
  544. /// </summary>
  545. /// <param name="userEntity">实体对象</param>
  546. public void UpdateEntity(UserEntity userEntity)
  547. {
  548. try
  549. {
  550. this.BaseRepository().Update(userEntity);
  551. }
  552. catch (Exception ex)
  553. {
  554. if (ex is ExceptionEx)
  555. {
  556. throw;
  557. }
  558. else
  559. {
  560. throw ExceptionEx.ThrowServiceException(ex);
  561. }
  562. }
  563. }
  564. public List<UserEntity> GetUserByDepartmentId(string departmentId)
  565. {
  566. try
  567. {
  568. return this.BaseRepository().FindList<UserEntity>(a => a.F_DepartmentId == departmentId).ToList();
  569. }
  570. catch (Exception ex)
  571. {
  572. if (ex is ExceptionEx)
  573. {
  574. throw;
  575. }
  576. else
  577. {
  578. throw ExceptionEx.ThrowServiceException(ex);
  579. }
  580. }
  581. }
  582. public List<UserEntity> GetListByDepartmentIds(string departmentId)
  583. {
  584. try
  585. {
  586. var ids = departmentId.Split(',');
  587. return this.BaseRepository().FindList<UserEntity>(a => ids.Contains(a.F_DepartmentId)).ToList();
  588. }
  589. catch (Exception ex)
  590. {
  591. if (ex is ExceptionEx)
  592. {
  593. throw;
  594. }
  595. else
  596. {
  597. throw ExceptionEx.ThrowServiceException(ex);
  598. }
  599. }
  600. }
  601. /// <summary>
  602. /// 保存用户的设备号
  603. /// </summary>
  604. /// <param name="keyValue">主键</param>
  605. /// <param name="deviceId">设备号</param>
  606. public void UpdateDeviceId(string keyValue, string deviceId)
  607. {
  608. try
  609. {
  610. var userEntity = this.BaseRepository().FindEntity<UserEntity>(keyValue);
  611. if (userEntity != null)
  612. {
  613. userEntity.F_DeviceId = deviceId;
  614. userEntity.Modify(keyValue);
  615. this.BaseRepository().Update(userEntity);
  616. }
  617. }
  618. catch (Exception ex)
  619. {
  620. if (ex is ExceptionEx)
  621. {
  622. throw;
  623. }
  624. else
  625. {
  626. throw ExceptionEx.ThrowServiceException(ex);
  627. }
  628. }
  629. }
  630. #endregion
  631. public UserEntity GetEntityByWeixinOpenId(string openid)
  632. {
  633. try
  634. {
  635. var strSql = new StringBuilder();
  636. strSql.Append("SELECT ");
  637. strSql.Append(fieldSql);
  638. strSql.Append(" FROM LR_Base_User t ");
  639. strSql.Append(" WHERE t.OpenIdForWeixin = @openid AND t.F_DeleteMark = 0 ");
  640. return this.BaseRepository().FindEntity<UserEntity>(strSql.ToString(), new { openid = openid });
  641. }
  642. catch (Exception ex)
  643. {
  644. if (ex is ExceptionEx)
  645. {
  646. throw;
  647. }
  648. else
  649. {
  650. throw ExceptionEx.ThrowServiceException(ex);
  651. }
  652. }
  653. }
  654. public UserEntity GetEntityByWeixinOpenIdPC(string openid)
  655. {
  656. try
  657. {
  658. var strSql = new StringBuilder();
  659. strSql.Append("SELECT ");
  660. strSql.Append(fieldSql);
  661. strSql.Append(" FROM LR_Base_User t ");
  662. strSql.Append(" WHERE t.OpenIdForWeixinPC = @openid AND t.F_DeleteMark = 0 ");
  663. return this.BaseRepository().FindEntity<UserEntity>(strSql.ToString(), new { openid = openid });
  664. }
  665. catch (Exception ex)
  666. {
  667. if (ex is ExceptionEx)
  668. {
  669. throw;
  670. }
  671. else
  672. {
  673. throw ExceptionEx.ThrowServiceException(ex);
  674. }
  675. }
  676. }
  677. public void UpdateWeixinOpenId(string keyValue, string openid)
  678. {
  679. try
  680. {
  681. var userEntity = this.BaseRepository().FindEntity<UserEntity>(keyValue);
  682. if (userEntity != null)
  683. {
  684. userEntity.OpenIdForWeixin = openid;
  685. userEntity.Modify(keyValue);
  686. this.BaseRepository().Update(userEntity);
  687. }
  688. }
  689. catch (Exception ex)
  690. {
  691. if (ex is ExceptionEx)
  692. {
  693. throw;
  694. }
  695. else
  696. {
  697. throw ExceptionEx.ThrowServiceException(ex);
  698. }
  699. }
  700. }
  701. public void UpdateWeixinOpenIdPC(string keyValue, string openid)
  702. {
  703. try
  704. {
  705. var userEntity = this.BaseRepository().FindEntity<UserEntity>(keyValue);
  706. if (userEntity != null)
  707. {
  708. userEntity.OpenIdForWeixinPC = openid;
  709. userEntity.Modify(keyValue);
  710. this.BaseRepository().Update(userEntity);
  711. }
  712. }
  713. catch (Exception ex)
  714. {
  715. if (ex is ExceptionEx)
  716. {
  717. throw;
  718. }
  719. else
  720. {
  721. throw ExceptionEx.ThrowServiceException(ex);
  722. }
  723. }
  724. }
  725. /// <summary>
  726. /// 获取超级管理员用户列表
  727. /// </summary>
  728. /// <returns></returns>
  729. public IEnumerable<UserEntity> GetAdminList()
  730. {
  731. try
  732. {
  733. return this.BaseRepository().FindList<UserEntity>(t => t.F_SecurityLevel == 1);
  734. }
  735. catch (Exception ex)
  736. {
  737. if (ex is ExceptionEx)
  738. {
  739. throw;
  740. }
  741. else
  742. {
  743. throw ExceptionEx.ThrowServiceException(ex);
  744. }
  745. }
  746. }
  747. /// <summary>
  748. /// 解绑微信
  749. /// </summary>
  750. public void DoUnbundWeiXin(string keyValue)
  751. {
  752. try
  753. {
  754. this.BaseRepository().ExecuteBySql("update LR_Base_User set OpenIdForWeixin=null where F_UserId='" + keyValue + "' ");
  755. }
  756. catch (Exception ex)
  757. {
  758. if (ex is ExceptionEx)
  759. {
  760. throw;
  761. }
  762. else
  763. {
  764. throw ExceptionEx.ThrowServiceException(ex);
  765. }
  766. }
  767. }
  768. public void UpdateIp(string ip, string id)
  769. {
  770. try
  771. {
  772. this.BaseRepository().ExecuteBySql("update LR_Base_User set LastIp='" + ip + "' where F_UserId='" + id + "' ");
  773. }
  774. catch (Exception ex)
  775. {
  776. if (ex is ExceptionEx)
  777. {
  778. throw;
  779. }
  780. else
  781. {
  782. throw ExceptionEx.ThrowServiceException(ex);
  783. }
  784. }
  785. }
  786. /// <summary>
  787. /// 获取用户头像,取empinfo照片
  788. /// </summary>
  789. /// <param name="userid"></param>
  790. /// <returns></returns>
  791. public string GetEmpPhotoPath(string userid)
  792. {
  793. string path = "";
  794. try
  795. {
  796. var userentity = BaseRepository().FindEntity<UserEntity>("select a.*,b.Photo from LR_Base_User a " +
  797. "left join " + BaseRepository("CollegeMIS").getDbConnection().Database +
  798. ".dbo.empinfo b on a.F_Account=b.empno where a.F_UserId='" + userid + "'", null);
  799. if (userentity != null && !string.IsNullOrEmpty(userentity.Photo))
  800. {
  801. //获取图片
  802. var LR_Base_AnnexesFile = BaseRepository().FindEntity<dynamic>("select * from LR_Base_AnnexesFile where F_FolderId='" + userentity.Photo + "'", null);
  803. if (LR_Base_AnnexesFile != null)
  804. {
  805. path = LR_Base_AnnexesFile.F_FilePath;
  806. }
  807. }
  808. return path;
  809. }
  810. catch (Exception ex)
  811. {
  812. if (ex is ExceptionEx)
  813. {
  814. throw;
  815. }
  816. else
  817. {
  818. throw ExceptionEx.ThrowServiceException(ex);
  819. }
  820. }
  821. }
  822. }
  823. }