選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

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