You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

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