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

865 строки
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. if (string.IsNullOrEmpty(departmentId))
  587. {
  588. return new List<UserEntity>();
  589. }
  590. if (departmentId.IndexOf(',') == -1)
  591. {
  592. return this.BaseRepository().FindList<UserEntity>(a => a.F_DepartmentId == departmentId && a.F_DeleteMark == 0).ToList();
  593. }
  594. else
  595. {
  596. var ids = departmentId.Split(',');
  597. return this.BaseRepository().FindList<UserEntity>(a => ids.Contains(a.F_DepartmentId) && a.F_DeleteMark == 0).ToList();
  598. }
  599. }
  600. catch (Exception ex)
  601. {
  602. if (ex is ExceptionEx)
  603. {
  604. throw;
  605. }
  606. else
  607. {
  608. throw ExceptionEx.ThrowServiceException(ex);
  609. }
  610. }
  611. }
  612. /// <summary>
  613. /// 保存用户的设备号
  614. /// </summary>
  615. /// <param name="keyValue">主键</param>
  616. /// <param name="deviceId">设备号</param>
  617. public void UpdateDeviceId(string keyValue, string deviceId)
  618. {
  619. try
  620. {
  621. var userEntity = this.BaseRepository().FindEntity<UserEntity>(keyValue);
  622. if (userEntity != null)
  623. {
  624. userEntity.F_DeviceId = deviceId;
  625. userEntity.Modify(keyValue);
  626. this.BaseRepository().Update(userEntity);
  627. }
  628. }
  629. catch (Exception ex)
  630. {
  631. if (ex is ExceptionEx)
  632. {
  633. throw;
  634. }
  635. else
  636. {
  637. throw ExceptionEx.ThrowServiceException(ex);
  638. }
  639. }
  640. }
  641. #endregion
  642. public UserEntity GetEntityByWeixinOpenId(string openid)
  643. {
  644. try
  645. {
  646. var strSql = new StringBuilder();
  647. strSql.Append("SELECT ");
  648. strSql.Append(fieldSql);
  649. strSql.Append(" FROM LR_Base_User t ");
  650. strSql.Append(" WHERE t.OpenIdForWeixin = @openid AND t.F_DeleteMark = 0 ");
  651. return this.BaseRepository().FindEntity<UserEntity>(strSql.ToString(), new { openid = openid });
  652. }
  653. catch (Exception ex)
  654. {
  655. if (ex is ExceptionEx)
  656. {
  657. throw;
  658. }
  659. else
  660. {
  661. throw ExceptionEx.ThrowServiceException(ex);
  662. }
  663. }
  664. }
  665. public UserEntity GetEntityByWeixinOpenIdPC(string openid)
  666. {
  667. try
  668. {
  669. var strSql = new StringBuilder();
  670. strSql.Append("SELECT ");
  671. strSql.Append(fieldSql);
  672. strSql.Append(" FROM LR_Base_User t ");
  673. strSql.Append(" WHERE t.OpenIdForWeixinPC = @openid AND t.F_DeleteMark = 0 ");
  674. return this.BaseRepository().FindEntity<UserEntity>(strSql.ToString(), new { openid = openid });
  675. }
  676. catch (Exception ex)
  677. {
  678. if (ex is ExceptionEx)
  679. {
  680. throw;
  681. }
  682. else
  683. {
  684. throw ExceptionEx.ThrowServiceException(ex);
  685. }
  686. }
  687. }
  688. public void UpdateWeixinOpenId(string keyValue, string openid)
  689. {
  690. try
  691. {
  692. var userEntity = this.BaseRepository().FindEntity<UserEntity>(keyValue);
  693. if (userEntity != null)
  694. {
  695. userEntity.OpenIdForWeixin = openid;
  696. userEntity.Modify(keyValue);
  697. this.BaseRepository().Update(userEntity);
  698. }
  699. }
  700. catch (Exception ex)
  701. {
  702. if (ex is ExceptionEx)
  703. {
  704. throw;
  705. }
  706. else
  707. {
  708. throw ExceptionEx.ThrowServiceException(ex);
  709. }
  710. }
  711. }
  712. public void UpdateWeixinOpenIdPC(string keyValue, string openid)
  713. {
  714. try
  715. {
  716. var userEntity = this.BaseRepository().FindEntity<UserEntity>(keyValue);
  717. if (userEntity != null)
  718. {
  719. userEntity.OpenIdForWeixinPC = openid;
  720. userEntity.Modify(keyValue);
  721. this.BaseRepository().Update(userEntity);
  722. }
  723. }
  724. catch (Exception ex)
  725. {
  726. if (ex is ExceptionEx)
  727. {
  728. throw;
  729. }
  730. else
  731. {
  732. throw ExceptionEx.ThrowServiceException(ex);
  733. }
  734. }
  735. }
  736. /// <summary>
  737. /// 获取超级管理员用户列表
  738. /// </summary>
  739. /// <returns></returns>
  740. public IEnumerable<UserEntity> GetAdminList()
  741. {
  742. try
  743. {
  744. return this.BaseRepository().FindList<UserEntity>(t => t.F_SecurityLevel == 1);
  745. }
  746. catch (Exception ex)
  747. {
  748. if (ex is ExceptionEx)
  749. {
  750. throw;
  751. }
  752. else
  753. {
  754. throw ExceptionEx.ThrowServiceException(ex);
  755. }
  756. }
  757. }
  758. /// <summary>
  759. /// 解绑微信
  760. /// </summary>
  761. public void DoUnbundWeiXin(string keyValue)
  762. {
  763. try
  764. {
  765. this.BaseRepository().ExecuteBySql("update LR_Base_User set OpenIdForWeixin=null where F_UserId='" + keyValue + "' ");
  766. }
  767. catch (Exception ex)
  768. {
  769. if (ex is ExceptionEx)
  770. {
  771. throw;
  772. }
  773. else
  774. {
  775. throw ExceptionEx.ThrowServiceException(ex);
  776. }
  777. }
  778. }
  779. public void UpdateIp(string ip, string id)
  780. {
  781. try
  782. {
  783. this.BaseRepository().ExecuteBySql("update LR_Base_User set LastIp='" + ip + "' where F_UserId='" + id + "' ");
  784. }
  785. catch (Exception ex)
  786. {
  787. if (ex is ExceptionEx)
  788. {
  789. throw;
  790. }
  791. else
  792. {
  793. throw ExceptionEx.ThrowServiceException(ex);
  794. }
  795. }
  796. }
  797. /// <summary>
  798. /// 获取用户头像,取empinfo照片
  799. /// </summary>
  800. /// <param name="userid"></param>
  801. /// <returns></returns>
  802. public string GetEmpPhotoPath(string userid)
  803. {
  804. string path = "";
  805. try
  806. {
  807. var userentity = BaseRepository().FindEntity<UserEntity>("select a.*,b.Photo from LR_Base_User a " +
  808. "left join " + BaseRepository("CollegeMIS").getDbConnection().Database +
  809. ".dbo.empinfo b on a.F_Account=b.empno where a.F_UserId='" + userid + "'", null);
  810. if (userentity != null && !string.IsNullOrEmpty(userentity.Photo))
  811. {
  812. //获取图片
  813. var LR_Base_AnnexesFile = BaseRepository().FindEntity<dynamic>("select * from LR_Base_AnnexesFile where F_FolderId='" + userentity.Photo + "'", null);
  814. if (LR_Base_AnnexesFile != null)
  815. {
  816. path = LR_Base_AnnexesFile.F_FilePath;
  817. }
  818. }
  819. return path;
  820. }
  821. catch (Exception ex)
  822. {
  823. if (ex is ExceptionEx)
  824. {
  825. throw;
  826. }
  827. else
  828. {
  829. throw ExceptionEx.ThrowServiceException(ex);
  830. }
  831. }
  832. }
  833. }
  834. }