Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

890 Zeilen
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. this.BaseRepository().Update(userEntity);
  502. }
  503. catch (Exception ex)
  504. {
  505. if (ex is ExceptionEx)
  506. {
  507. throw;
  508. }
  509. else
  510. {
  511. throw ExceptionEx.ThrowServiceException(ex);
  512. }
  513. }
  514. }
  515. /// <summary>
  516. /// 修改用户登录密码(批量)
  517. /// </summary>
  518. /// <param name="keyValue">主键值</param>
  519. /// <param name="password">新密码(MD5 小写)</param>
  520. public void RevisePasswordBatch(string keyValue, string password)
  521. {
  522. var db = this.BaseRepository().BeginTrans();
  523. try
  524. {
  525. foreach (var item in keyValue.Split(','))
  526. {
  527. UserEntity userEntity = new UserEntity();
  528. userEntity.Modify(item);
  529. userEntity.F_Secretkey = Md5Helper.Encrypt(CommonHelper.CreateNo(), 16).ToLower();
  530. userEntity.F_Password = Md5Helper.Encrypt(DESEncrypt.Encrypt(password, userEntity.F_Secretkey).ToLower(), 32).ToLower();
  531. db.Update(userEntity);
  532. }
  533. db.Commit();
  534. }
  535. catch (Exception ex)
  536. {
  537. db.Rollback();
  538. }
  539. }
  540. /// <summary>
  541. /// 修改用户状态
  542. /// </summary>
  543. /// <param name="keyValue">主键值</param>
  544. /// <param name="state">状态:1-启动;0-禁用</param>
  545. public void UpdateState(string keyValue, int state)
  546. {
  547. try
  548. {
  549. UserEntity userEntity = new UserEntity();
  550. userEntity.Modify(keyValue);
  551. userEntity.F_EnabledMark = state;
  552. this.BaseRepository().Update(userEntity);
  553. }
  554. catch (Exception ex)
  555. {
  556. if (ex is ExceptionEx)
  557. {
  558. throw;
  559. }
  560. else
  561. {
  562. throw ExceptionEx.ThrowServiceException(ex);
  563. }
  564. }
  565. }
  566. /// <summary>
  567. /// 修改用户信息
  568. /// </summary>
  569. /// <param name="userEntity">实体对象</param>
  570. public void UpdateEntity(UserEntity userEntity)
  571. {
  572. try
  573. {
  574. this.BaseRepository().Update(userEntity);
  575. }
  576. catch (Exception ex)
  577. {
  578. if (ex is ExceptionEx)
  579. {
  580. throw;
  581. }
  582. else
  583. {
  584. throw ExceptionEx.ThrowServiceException(ex);
  585. }
  586. }
  587. }
  588. public List<UserEntity> GetUserByDepartmentId(string departmentId)
  589. {
  590. try
  591. {
  592. return this.BaseRepository().FindList<UserEntity>(a => a.F_DepartmentId == departmentId).ToList();
  593. }
  594. catch (Exception ex)
  595. {
  596. if (ex is ExceptionEx)
  597. {
  598. throw;
  599. }
  600. else
  601. {
  602. throw ExceptionEx.ThrowServiceException(ex);
  603. }
  604. }
  605. }
  606. public List<UserEntity> GetListByDepartmentIds(string departmentId)
  607. {
  608. try
  609. {
  610. if (string.IsNullOrEmpty(departmentId))
  611. {
  612. return new List<UserEntity>();
  613. }
  614. if (departmentId.IndexOf(',') == -1)
  615. {
  616. return this.BaseRepository().FindList<UserEntity>(a => a.F_DepartmentId == departmentId && a.F_DeleteMark == 0).ToList();
  617. }
  618. else
  619. {
  620. var ids = departmentId.Split(',');
  621. return this.BaseRepository().FindList<UserEntity>(a => ids.Contains(a.F_DepartmentId) && a.F_DeleteMark == 0).ToList();
  622. }
  623. }
  624. catch (Exception ex)
  625. {
  626. if (ex is ExceptionEx)
  627. {
  628. throw;
  629. }
  630. else
  631. {
  632. throw ExceptionEx.ThrowServiceException(ex);
  633. }
  634. }
  635. }
  636. /// <summary>
  637. /// 保存用户的设备号
  638. /// </summary>
  639. /// <param name="keyValue">主键</param>
  640. /// <param name="deviceId">设备号</param>
  641. public void UpdateDeviceId(string keyValue, string deviceId)
  642. {
  643. try
  644. {
  645. var userEntity = this.BaseRepository().FindEntity<UserEntity>(keyValue);
  646. if (userEntity != null)
  647. {
  648. userEntity.F_DeviceId = deviceId;
  649. userEntity.Modify(keyValue);
  650. this.BaseRepository().Update(userEntity);
  651. }
  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. #endregion
  666. public UserEntity GetEntityByWeixinOpenId(string openid)
  667. {
  668. try
  669. {
  670. var strSql = new StringBuilder();
  671. strSql.Append("SELECT ");
  672. strSql.Append(fieldSql);
  673. strSql.Append(" FROM LR_Base_User t ");
  674. strSql.Append(" WHERE t.OpenIdForWeixin = @openid AND t.F_DeleteMark = 0 ");
  675. return this.BaseRepository().FindEntity<UserEntity>(strSql.ToString(), new { openid = openid });
  676. }
  677. catch (Exception ex)
  678. {
  679. if (ex is ExceptionEx)
  680. {
  681. throw;
  682. }
  683. else
  684. {
  685. throw ExceptionEx.ThrowServiceException(ex);
  686. }
  687. }
  688. }
  689. public UserEntity GetEntityByWeixinOpenIdPC(string openid)
  690. {
  691. try
  692. {
  693. var strSql = new StringBuilder();
  694. strSql.Append("SELECT ");
  695. strSql.Append(fieldSql);
  696. strSql.Append(" FROM LR_Base_User t ");
  697. strSql.Append(" WHERE t.OpenIdForWeixinPC = @openid AND t.F_DeleteMark = 0 ");
  698. return this.BaseRepository().FindEntity<UserEntity>(strSql.ToString(), new { openid = openid });
  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 UpdateWeixinOpenId(string keyValue, string openid)
  713. {
  714. try
  715. {
  716. var userEntity = this.BaseRepository().FindEntity<UserEntity>(keyValue);
  717. if (userEntity != null)
  718. {
  719. userEntity.OpenIdForWeixin = 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. public void UpdateWeixinOpenIdPC(string keyValue, string openid)
  737. {
  738. try
  739. {
  740. var userEntity = this.BaseRepository().FindEntity<UserEntity>(keyValue);
  741. if (userEntity != null)
  742. {
  743. userEntity.OpenIdForWeixinPC = openid;
  744. userEntity.Modify(keyValue);
  745. this.BaseRepository().Update(userEntity);
  746. }
  747. }
  748. catch (Exception ex)
  749. {
  750. if (ex is ExceptionEx)
  751. {
  752. throw;
  753. }
  754. else
  755. {
  756. throw ExceptionEx.ThrowServiceException(ex);
  757. }
  758. }
  759. }
  760. /// <summary>
  761. /// 获取超级管理员用户列表
  762. /// </summary>
  763. /// <returns></returns>
  764. public IEnumerable<UserEntity> GetAdminList()
  765. {
  766. try
  767. {
  768. return this.BaseRepository().FindList<UserEntity>(t => t.F_SecurityLevel == 1);
  769. }
  770. catch (Exception ex)
  771. {
  772. if (ex is ExceptionEx)
  773. {
  774. throw;
  775. }
  776. else
  777. {
  778. throw ExceptionEx.ThrowServiceException(ex);
  779. }
  780. }
  781. }
  782. /// <summary>
  783. /// 解绑微信
  784. /// </summary>
  785. public void DoUnbundWeiXin(string keyValue)
  786. {
  787. try
  788. {
  789. this.BaseRepository().ExecuteBySql("update LR_Base_User set OpenIdForWeixin=null where F_UserId='" + keyValue + "' ");
  790. }
  791. catch (Exception ex)
  792. {
  793. if (ex is ExceptionEx)
  794. {
  795. throw;
  796. }
  797. else
  798. {
  799. throw ExceptionEx.ThrowServiceException(ex);
  800. }
  801. }
  802. }
  803. public void UpdateIp(string ip, string id)
  804. {
  805. try
  806. {
  807. this.BaseRepository().ExecuteBySql("update LR_Base_User set LastIp='" + ip + "' where F_UserId='" + id + "' ");
  808. }
  809. catch (Exception ex)
  810. {
  811. if (ex is ExceptionEx)
  812. {
  813. throw;
  814. }
  815. else
  816. {
  817. throw ExceptionEx.ThrowServiceException(ex);
  818. }
  819. }
  820. }
  821. /// <summary>
  822. /// 获取用户头像,取empinfo照片
  823. /// </summary>
  824. /// <param name="userid"></param>
  825. /// <returns></returns>
  826. public string GetEmpPhotoPath(string userid)
  827. {
  828. string path = "";
  829. try
  830. {
  831. var userentity = BaseRepository().FindEntity<UserEntity>("select a.*,b.Photo from LR_Base_User a " +
  832. "left join " + BaseRepository("CollegeMIS").getDbConnection().Database +
  833. ".dbo.empinfo b on a.F_Account=b.empno where a.F_UserId='" + userid + "'", null);
  834. if (userentity != null && !string.IsNullOrEmpty(userentity.Photo))
  835. {
  836. //获取图片
  837. var LR_Base_AnnexesFile = BaseRepository().FindEntity<dynamic>("select * from LR_Base_AnnexesFile where F_FolderId='" + userentity.Photo + "'", null);
  838. if (LR_Base_AnnexesFile != null)
  839. {
  840. path = LR_Base_AnnexesFile.F_FilePath;
  841. }
  842. }
  843. return path;
  844. }
  845. catch (Exception ex)
  846. {
  847. if (ex is ExceptionEx)
  848. {
  849. throw;
  850. }
  851. else
  852. {
  853. throw ExceptionEx.ThrowServiceException(ex);
  854. }
  855. }
  856. }
  857. }
  858. }