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.
 
 
 
 
 
 

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