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.

UserService.cs 30 KiB

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