No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

1003 líneas
33 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 and F_EnabledMark =1 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. /// 用户列表,全部
  303. /// </summary>
  304. /// <returns></returns>
  305. public IEnumerable<UserEntity> GetAllListForMap(string description)
  306. {
  307. try
  308. {
  309. var fieldStr = @"t.F_CompanyId,t.F_DepartmentId,t.F_RealName,t.F_Mobile,t.F_HeadIcon,
  310. t.F_UserId,t.F_Gender ";
  311. var strSql = new StringBuilder();
  312. strSql.Append("SELECT ");
  313. strSql.Append(fieldStr.Replace("t.F_Password,", "").Replace("t.F_Secretkey,", ""));
  314. strSql.Append(" FROM LR_Base_User t WHERE t.F_DeleteMark = 0 ");
  315. if (!description.IsEmpty())
  316. {
  317. strSql.Append(" and F_Description !='学生'");
  318. }
  319. strSql.Append("ORDER BY t.F_CompanyId,t.F_DepartmentId,t.F_RealName ");
  320. return this.BaseRepository().FindList<UserEntity>(strSql.ToString());
  321. }
  322. catch (Exception ex)
  323. {
  324. if (ex is ExceptionEx)
  325. {
  326. throw;
  327. }
  328. else
  329. {
  330. throw ExceptionEx.ThrowServiceException(ex);
  331. }
  332. }
  333. }
  334. /// <summary>
  335. /// 用户列表(导出Excel)
  336. /// </summary>
  337. /// <returns></returns>
  338. public DataTable GetExportList()
  339. {
  340. try
  341. {
  342. var strSql = new StringBuilder();
  343. strSql.Append(@"SELECT u.F_Account
  344. ,u.F_RealName
  345. ,CASE WHEN u.F_Gender=1 THEN '男' ELSE '女' END AS F_Gender
  346. ,CASE WHEN u.F_EnabledMark=1 THEN '正常' ELSE '禁用' END AS F_EnabledMark
  347. ,u.F_Birthday
  348. ,u.F_Mobile
  349. ,u.F_Telephone
  350. ,u.F_WeChat
  351. ,o.F_FullName AS F_Company
  352. ,d.F_FullName AS F_Department
  353. ,u.F_Description
  354. ,u.F_CreateDate
  355. ,u.F_CreateUserName
  356. FROM LR_Base_User u
  357. INNER JOIN LR_Base_Department d ON u.F_DepartmentId=d.F_DepartmentId
  358. INNER JOIN LR_Base_Company o ON u.F_CompanyId=o.F_CompanyId
  359. WHERE u.F_DeleteMark = 0 and u.F_Description = '教师'");
  360. return this.BaseRepository().FindTable(strSql.ToString());
  361. }
  362. catch (Exception ex)
  363. {
  364. if (ex is ExceptionEx)
  365. {
  366. throw;
  367. }
  368. else
  369. {
  370. throw ExceptionEx.ThrowServiceException(ex);
  371. }
  372. }
  373. }
  374. /// <summary>
  375. /// 用户列表(导出Excel)【学生】
  376. /// </summary>
  377. /// <returns></returns>
  378. public DataTable GetExportListOfStudent()
  379. {
  380. try
  381. {
  382. var strSql = new StringBuilder();
  383. var name = this.BaseRepository("CollegeMIS").getDbConnection().Database;
  384. strSql.Append(@"SELECT u.F_Account
  385. ,u.F_RealName
  386. ,CASE WHEN u.F_Gender=1 THEN '男' ELSE '女' END AS F_Gender
  387. ,u.F_Birthday
  388. ,u.F_Mobile
  389. ,u.F_Telephone
  390. ,u.F_WeChat
  391. ,o.deptname AS F_Company
  392. ,u.F_DepartmentId AS F_Department
  393. ,u.F_Description
  394. ,u.F_CreateDate
  395. ,u.F_CreateUserName
  396. FROM LR_Base_User u
  397. INNER JOIN " + name + ".dbo.CDDEPT o ON u.F_DepartmentId=o.DeptNo WHERE u.F_DeleteMark = 0 and u.F_Description = '学生'");
  398. return this.BaseRepository().FindTable(strSql.ToString());
  399. }
  400. catch (Exception ex)
  401. {
  402. if (ex is ExceptionEx)
  403. {
  404. throw;
  405. }
  406. else
  407. {
  408. throw ExceptionEx.ThrowServiceException(ex);
  409. }
  410. }
  411. }
  412. /// <summary>
  413. /// 用户实体
  414. /// </summary>
  415. /// <param name="keyValue">主键值</param>
  416. /// <returns></returns>
  417. public UserEntity GetEntity(string keyValue)
  418. {
  419. try
  420. {
  421. return this.BaseRepository().FindEntity<UserEntity>(t => t.F_UserId == keyValue && t.F_DeleteMark == 0);
  422. }
  423. catch (Exception ex)
  424. {
  425. if (ex is ExceptionEx)
  426. {
  427. throw;
  428. }
  429. else
  430. {
  431. throw ExceptionEx.ThrowServiceException(ex);
  432. }
  433. }
  434. }
  435. #endregion
  436. #region 验证数据
  437. /// <summary>
  438. /// 账户不能重复
  439. /// </summary>
  440. /// <param name="account">账户值</param>
  441. /// <param name="keyValue">主键</param>
  442. /// <returns></returns>
  443. public bool ExistAccount(string account, string keyValue)
  444. {
  445. try
  446. {
  447. var expression = LinqExtensions.True<UserEntity>();
  448. expression = expression.And(t => t.F_Account == account);
  449. if (!string.IsNullOrEmpty(keyValue))
  450. {
  451. expression = expression.And(t => t.F_UserId != keyValue);
  452. }
  453. return this.BaseRepository().IQueryable(expression).Count() == 0 ? true : false;
  454. }
  455. catch (Exception ex)
  456. {
  457. if (ex is ExceptionEx)
  458. {
  459. throw;
  460. }
  461. else
  462. {
  463. throw ExceptionEx.ThrowServiceException(ex);
  464. }
  465. }
  466. }
  467. #endregion
  468. #region 提交数据
  469. /// <summary>
  470. /// 虚拟删除
  471. /// </summary>
  472. /// <param name="keyValue">主键</param>
  473. public void VirtualDelete(string keyValue)
  474. {
  475. try
  476. {
  477. UserEntity entity = new UserEntity()
  478. {
  479. F_UserId = keyValue,
  480. F_DeleteMark = 1
  481. };
  482. this.BaseRepository().Update(entity);
  483. }
  484. catch (Exception ex)
  485. {
  486. if (ex is ExceptionEx)
  487. {
  488. throw;
  489. }
  490. else
  491. {
  492. throw ExceptionEx.ThrowServiceException(ex);
  493. }
  494. }
  495. }
  496. /// <summary>
  497. /// 虚拟删除(批量)
  498. /// </summary>
  499. /// <param name="keyValue">主键</param>
  500. public void VirtualDeleteBatch(string keyValue)
  501. {
  502. var db = this.BaseRepository().BeginTrans();
  503. try
  504. {
  505. foreach (var item in keyValue.Split(','))
  506. {
  507. UserEntity entity = new UserEntity()
  508. {
  509. F_UserId = item,
  510. F_DeleteMark = 1
  511. };
  512. db.Update(entity);
  513. db.ExecuteBySql("delete from LR_Base_UserRelation where F_UserId='" + keyValue + "'");
  514. }
  515. db.Commit();
  516. }
  517. catch (Exception ex)
  518. {
  519. db.Rollback();
  520. }
  521. }
  522. internal List<UserEntity> GetStudents()
  523. {
  524. try
  525. {
  526. return this.BaseRepository().FindList<UserEntity>(a => a.F_Description == "学生").ToList();
  527. }
  528. catch (Exception ex)
  529. {
  530. if (ex is ExceptionEx)
  531. {
  532. throw;
  533. }
  534. else
  535. {
  536. throw ExceptionEx.ThrowServiceException(ex);
  537. }
  538. }
  539. }
  540. /// <summary>
  541. /// 保存用户表单(新增、修改)
  542. /// </summary>
  543. /// <param name="keyValue">主键值</param>
  544. /// <param name="userEntity">用户实体</param>
  545. /// <returns></returns>
  546. public void SaveEntity(string keyValue, UserEntity userEntity)
  547. {
  548. try
  549. {
  550. if (string.IsNullOrEmpty(keyValue))
  551. {
  552. userEntity.Create();
  553. userEntity.F_Secretkey = Md5Helper.Encrypt(CommonHelper.CreateNo(), 16).ToLower();
  554. userEntity.F_Password = Md5Helper.Encrypt(DESEncrypt.Encrypt(userEntity.F_Password, userEntity.F_Secretkey).ToLower(), 32).ToLower();
  555. this.BaseRepository().Insert(userEntity);
  556. }
  557. else
  558. {
  559. userEntity.Modify(keyValue);
  560. userEntity.F_Secretkey = null;
  561. userEntity.F_Password = null;
  562. this.BaseRepository().Update(userEntity);
  563. }
  564. }
  565. catch (Exception ex)
  566. {
  567. if (ex is ExceptionEx)
  568. {
  569. throw;
  570. }
  571. else
  572. {
  573. throw ExceptionEx.ThrowServiceException(ex);
  574. }
  575. }
  576. }
  577. /// <summary>
  578. /// 修改用户登录密码
  579. /// </summary>
  580. /// <param name="keyValue">主键值</param>
  581. /// <param name="password">新密码(MD5 小写)</param>
  582. public void RevisePassword(string keyValue, string password)
  583. {
  584. try
  585. {
  586. UserEntity userEntity = new UserEntity();
  587. userEntity.Modify(keyValue);
  588. userEntity.F_Secretkey = Md5Helper.Encrypt(CommonHelper.CreateNo(), 16).ToLower();
  589. userEntity.F_Password = Md5Helper.Encrypt(DESEncrypt.Encrypt(password, userEntity.F_Secretkey).ToLower(), 32).ToLower();
  590. this.BaseRepository().Update(userEntity);
  591. }
  592. catch (Exception ex)
  593. {
  594. if (ex is ExceptionEx)
  595. {
  596. throw;
  597. }
  598. else
  599. {
  600. throw ExceptionEx.ThrowServiceException(ex);
  601. }
  602. }
  603. }
  604. /// <summary>
  605. /// 修改用户登录密码(批量)
  606. /// </summary>
  607. /// <param name="keyValue">主键值</param>
  608. /// <param name="password">新密码(MD5 小写)</param>
  609. public void RevisePasswordBatch(string keyValue, string password)
  610. {
  611. var db = this.BaseRepository().BeginTrans();
  612. try
  613. {
  614. foreach (var item in keyValue.Split(','))
  615. {
  616. UserEntity userEntity = new UserEntity();
  617. userEntity.Modify(item);
  618. userEntity.F_Secretkey = Md5Helper.Encrypt(CommonHelper.CreateNo(), 16).ToLower();
  619. userEntity.F_Password = Md5Helper.Encrypt(DESEncrypt.Encrypt(password, userEntity.F_Secretkey).ToLower(), 32).ToLower();
  620. db.Update(userEntity);
  621. }
  622. db.Commit();
  623. }
  624. catch (Exception ex)
  625. {
  626. db.Rollback();
  627. }
  628. }
  629. /// <summary>
  630. /// 修改用户状态
  631. /// </summary>
  632. /// <param name="keyValue">主键值</param>
  633. /// <param name="state">状态:1-启动;0-禁用</param>
  634. public void UpdateState(string keyValue, int state)
  635. {
  636. try
  637. {
  638. UserEntity userEntity = new UserEntity();
  639. userEntity.Modify(keyValue);
  640. userEntity.F_EnabledMark = state;
  641. this.BaseRepository().Update(userEntity);
  642. }
  643. catch (Exception ex)
  644. {
  645. if (ex is ExceptionEx)
  646. {
  647. throw;
  648. }
  649. else
  650. {
  651. throw ExceptionEx.ThrowServiceException(ex);
  652. }
  653. }
  654. }
  655. /// <summary>
  656. /// 修改用户信息
  657. /// </summary>
  658. /// <param name="userEntity">实体对象</param>
  659. public void UpdateEntity(UserEntity userEntity)
  660. {
  661. try
  662. {
  663. this.BaseRepository().Update(userEntity);
  664. }
  665. catch (Exception ex)
  666. {
  667. if (ex is ExceptionEx)
  668. {
  669. throw;
  670. }
  671. else
  672. {
  673. throw ExceptionEx.ThrowServiceException(ex);
  674. }
  675. }
  676. }
  677. public List<UserEntity> GetUserByDepartmentId(string departmentId)
  678. {
  679. try
  680. {
  681. return this.BaseRepository().FindList<UserEntity>(a => a.F_DepartmentId == departmentId).ToList();
  682. }
  683. catch (Exception ex)
  684. {
  685. if (ex is ExceptionEx)
  686. {
  687. throw;
  688. }
  689. else
  690. {
  691. throw ExceptionEx.ThrowServiceException(ex);
  692. }
  693. }
  694. }
  695. public List<UserEntity> GetListByDepartmentIds(string departmentId)
  696. {
  697. try
  698. {
  699. var ids = departmentId.Split(',');
  700. return this.BaseRepository().FindList<UserEntity>(a => ids.Contains(a.F_DepartmentId)).ToList();
  701. }
  702. catch (Exception ex)
  703. {
  704. if (ex is ExceptionEx)
  705. {
  706. throw;
  707. }
  708. else
  709. {
  710. throw ExceptionEx.ThrowServiceException(ex);
  711. }
  712. }
  713. }
  714. /// <summary>
  715. /// 保存用户的设备号
  716. /// </summary>
  717. /// <param name="keyValue">主键</param>
  718. /// <param name="deviceId">设备号</param>
  719. public void UpdateDeviceId(string keyValue, string deviceId)
  720. {
  721. try
  722. {
  723. var userEntity = this.BaseRepository().FindEntity<UserEntity>(keyValue);
  724. if (userEntity != null)
  725. {
  726. userEntity.F_DeviceId = deviceId;
  727. userEntity.Modify(keyValue);
  728. this.BaseRepository().Update(userEntity);
  729. }
  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. #endregion
  744. public UserEntity GetEntityByWeixinOpenId(string openid)
  745. {
  746. try
  747. {
  748. var strSql = new StringBuilder();
  749. strSql.Append("SELECT ");
  750. strSql.Append(fieldSql);
  751. strSql.Append(" FROM LR_Base_User t ");
  752. strSql.Append(" WHERE t.OpenIdForWeixin = @openid AND t.F_DeleteMark = 0 ");
  753. return this.BaseRepository().FindEntity<UserEntity>(strSql.ToString(), new { openid = openid });
  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 UserEntity GetEntityByWeixinOpenIdPC(string openid)
  768. {
  769. try
  770. {
  771. var strSql = new StringBuilder();
  772. strSql.Append("SELECT ");
  773. strSql.Append(fieldSql);
  774. strSql.Append(" FROM LR_Base_User t ");
  775. strSql.Append(" WHERE t.OpenIdForWeixinPC = @openid AND t.F_DeleteMark = 0 ");
  776. return this.BaseRepository().FindEntity<UserEntity>(strSql.ToString(), new { openid = openid });
  777. }
  778. catch (Exception ex)
  779. {
  780. if (ex is ExceptionEx)
  781. {
  782. throw;
  783. }
  784. else
  785. {
  786. throw ExceptionEx.ThrowServiceException(ex);
  787. }
  788. }
  789. }
  790. public void UpdateWeixinOpenId(string keyValue, string openid)
  791. {
  792. try
  793. {
  794. var userEntity = this.BaseRepository().FindEntity<UserEntity>(keyValue);
  795. if (userEntity != null)
  796. {
  797. userEntity.OpenIdForWeixin = openid;
  798. userEntity.Modify(keyValue);
  799. this.BaseRepository().Update(userEntity);
  800. }
  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 UpdateWeixinOpenIdPC(string keyValue, string openid)
  815. {
  816. try
  817. {
  818. var userEntity = this.BaseRepository().FindEntity<UserEntity>(keyValue);
  819. if (userEntity != null)
  820. {
  821. userEntity.OpenIdForWeixinPC = 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. /// <summary>
  839. /// 获取超级管理员用户列表
  840. /// </summary>
  841. /// <returns></returns>
  842. public IEnumerable<UserEntity> GetAdminList()
  843. {
  844. try
  845. {
  846. return this.BaseRepository().FindList<UserEntity>(t => t.F_SecurityLevel == 1);
  847. }
  848. catch (Exception ex)
  849. {
  850. if (ex is ExceptionEx)
  851. {
  852. throw;
  853. }
  854. else
  855. {
  856. throw ExceptionEx.ThrowServiceException(ex);
  857. }
  858. }
  859. }
  860. /// <summary>
  861. /// 解绑微信
  862. /// </summary>
  863. public void DoUnbundWeiXin(string keyValue)
  864. {
  865. try
  866. {
  867. this.BaseRepository().ExecuteBySql("update LR_Base_User set OpenIdForWeixin=null where F_UserId='" + keyValue + "' ");
  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. public void UpdateIp(string ip, string id)
  882. {
  883. try
  884. {
  885. this.BaseRepository().ExecuteBySql("update LR_Base_User set LastIp='" + ip + "' where F_UserId='" + id + "' ");
  886. }
  887. catch (Exception ex)
  888. {
  889. if (ex is ExceptionEx)
  890. {
  891. throw;
  892. }
  893. else
  894. {
  895. throw ExceptionEx.ThrowServiceException(ex);
  896. }
  897. }
  898. }
  899. /// <summary>
  900. /// 获取用户头像,取empinfo照片
  901. /// </summary>
  902. /// <param name="userid"></param>
  903. /// <returns></returns>
  904. public string GetEmpPhotoPath(string userid)
  905. {
  906. string path = "";
  907. try
  908. {
  909. var userentity = BaseRepository().FindEntity<UserEntity>("select a.*,b.Photo from LR_Base_User a " +
  910. "left join " + BaseRepository("CollegeMIS").getDbConnection().Database +
  911. ".dbo.empinfo b on a.F_Account=b.empno where a.F_UserId='" + userid + "'", null);
  912. if (userentity != null && !string.IsNullOrEmpty(userentity.Photo))
  913. {
  914. //获取图片
  915. var LR_Base_AnnexesFile = BaseRepository().FindEntity<dynamic>("select * from LR_Base_AnnexesFile where F_FolderId='" + userentity.Photo + "'", null);
  916. if (LR_Base_AnnexesFile != null)
  917. {
  918. path = LR_Base_AnnexesFile.F_FilePath;
  919. }
  920. }
  921. return path;
  922. }
  923. catch (Exception ex)
  924. {
  925. if (ex is ExceptionEx)
  926. {
  927. throw;
  928. }
  929. else
  930. {
  931. throw ExceptionEx.ThrowServiceException(ex);
  932. }
  933. }
  934. }
  935. /// <summary>
  936. /// 修改用户的允许登录结束时间
  937. /// </summary>
  938. /// <param name="keyValue">主键值</param>
  939. /// <param name="state">状态:1-赋值;0-重置</param>
  940. public void UpdateAllowEndTime(string keyValue, int state)
  941. {
  942. try
  943. {
  944. if (state == 0)
  945. {
  946. this.BaseRepository().ExecuteBySql("update LR_Base_User set F_AllowEndTime=null where F_UserId='" + keyValue + "'");
  947. }
  948. else
  949. {
  950. this.BaseRepository().ExecuteBySql("update LR_Base_User set F_AllowEndTime='" + DateTime.Now + "' where F_UserId='" + keyValue + "'");
  951. }
  952. }
  953. catch (Exception ex)
  954. {
  955. if (ex is ExceptionEx)
  956. {
  957. throw;
  958. }
  959. else
  960. {
  961. throw ExceptionEx.ThrowServiceException(ex);
  962. }
  963. }
  964. }
  965. }
  966. }