Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

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