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.
 
 
 
 
 
 

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