You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UserBLL.cs 45 KiB

4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
3 jaren geleden
3 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373
  1. using Learun.Cache.Base;
  2. using Learun.Cache.Factory;
  3. using Learun.Util;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Drawing;
  8. using Learun.Application.WeChat;
  9. using System.Configuration;
  10. using System.IO;
  11. using System.Linq;
  12. namespace Learun.Application.Organization
  13. {
  14. /// <summary>
  15. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  16. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  17. /// 创建人:陈彬彬
  18. /// 日 期:2017.03.06
  19. /// 描 述:用户模块业务类
  20. /// </summary>
  21. public class UserBLL : UserIBLL
  22. {
  23. #region 属性
  24. private UserService userService = new UserService();
  25. private DepartmentIBLL departmentIBLL = new DepartmentBLL();
  26. #endregion
  27. #region 缓存定义
  28. private ICache cache = CacheFactory.CaChe();
  29. private string cacheKey = "learun_adms_user_"; // +公司主键
  30. private string cacheKeyAccount = "learun_adms_user_account_";// +用户账号(账号不允许改动)
  31. private string cacheKeyId = "learun_adms_user_Id_";// +用户账号(账号不允许改动)
  32. #endregion
  33. #region 获取数据
  34. /// <summary>
  35. /// 用户列表(根据公司主键)
  36. /// </summary>
  37. /// <param name="companyId">公司主键</param>
  38. /// <returns></returns>
  39. public List<UserEntity> GetList(string companyId)
  40. {
  41. try
  42. {
  43. if (string.IsNullOrEmpty(companyId))
  44. {
  45. return new List<UserEntity>();
  46. }
  47. List<UserEntity> list = cache.Read<List<UserEntity>>(cacheKey + companyId, CacheId.user);
  48. if (list == null)
  49. {
  50. list = (List<UserEntity>)userService.GetList(companyId);
  51. cache.Write<List<UserEntity>>(cacheKey + companyId, list, CacheId.user);
  52. }
  53. return list;
  54. }
  55. catch (Exception ex)
  56. {
  57. if (ex is ExceptionEx)
  58. {
  59. throw;
  60. }
  61. else
  62. {
  63. throw ExceptionEx.ThrowBusinessException(ex);
  64. }
  65. }
  66. }
  67. /// <summary>
  68. /// 用户列表(根据公司主键,部门主键)
  69. /// </summary>
  70. /// <param name="companyId">公司主键</param>
  71. /// <param name="departmentId">部门主键</param>
  72. /// <param name="keyword">查询关键词</param>
  73. /// <returns></returns>
  74. public List<UserEntity> GetList(string companyId, string departmentId, string keyword)
  75. {
  76. try
  77. {
  78. List<UserEntity> list = GetList(companyId);
  79. if (!string.IsNullOrEmpty(departmentId))
  80. {
  81. list = list.FindAll(t => t.F_DepartmentId.ContainsEx(departmentId));
  82. }
  83. if (!string.IsNullOrEmpty(keyword))
  84. {
  85. list = list.FindAll(t => t.F_RealName.ContainsEx(keyword) || t.F_Account.ContainsEx(keyword));
  86. }
  87. return list;
  88. }
  89. catch (Exception ex)
  90. {
  91. if (ex is ExceptionEx)
  92. {
  93. throw;
  94. }
  95. else
  96. {
  97. throw ExceptionEx.ThrowBusinessException(ex);
  98. }
  99. }
  100. }
  101. public bool GetAny()
  102. {
  103. try
  104. {
  105. return userService.GetAny();
  106. }
  107. catch (Exception ex)
  108. {
  109. if (ex is ExceptionEx)
  110. {
  111. throw;
  112. }
  113. else
  114. {
  115. throw ExceptionEx.ThrowBusinessException(ex);
  116. }
  117. }
  118. }
  119. public bool GetStuAny()
  120. {
  121. try
  122. {
  123. return userService.GetStuAny();
  124. }
  125. catch (Exception ex)
  126. {
  127. if (ex is ExceptionEx)
  128. {
  129. throw;
  130. }
  131. else
  132. {
  133. throw ExceptionEx.ThrowBusinessException(ex);
  134. }
  135. }
  136. }
  137. /// <summary>
  138. /// 用户列表(全部)
  139. /// </summary>
  140. /// <returns></returns>
  141. public List<UserEntity> GetAllList()
  142. {
  143. try
  144. {
  145. return (List<UserEntity>)userService.GetAllList();
  146. }
  147. catch (Exception ex)
  148. {
  149. if (ex is ExceptionEx)
  150. {
  151. throw;
  152. }
  153. else
  154. {
  155. throw ExceptionEx.ThrowBusinessException(ex);
  156. }
  157. }
  158. }
  159. public void UpdateEntity(UserEntity entity)
  160. {
  161. try
  162. {
  163. userService.UpdateEntity(entity);
  164. }
  165. catch (Exception ex)
  166. {
  167. if (ex is ExceptionEx)
  168. {
  169. throw;
  170. }
  171. else
  172. {
  173. throw ExceptionEx.ThrowBusinessException(ex);
  174. }
  175. }
  176. }
  177. /// <summary>
  178. /// 用户列表(根据部门主键)
  179. /// </summary>
  180. /// <param name="departmentId">部门主键</param>
  181. /// <returns></returns>
  182. public List<UserEntity> GetListByDepartmentId(string departmentId)
  183. {
  184. try
  185. {
  186. if (string.IsNullOrEmpty(departmentId))
  187. {
  188. return new List<UserEntity>();
  189. }
  190. DepartmentEntity departmentEntity = departmentIBLL.GetEntity(departmentId);
  191. if (departmentEntity == null)
  192. {
  193. return new List<UserEntity>();
  194. }
  195. return GetList(departmentEntity.F_CompanyId, departmentId, "");
  196. }
  197. catch (Exception ex)
  198. {
  199. if (ex is ExceptionEx)
  200. {
  201. throw;
  202. }
  203. else
  204. {
  205. throw ExceptionEx.ThrowBusinessException(ex);
  206. }
  207. }
  208. }
  209. /// <summary>
  210. /// 用户列表(根据部门主键)
  211. /// </summary>
  212. /// <param name="departmentId">部门主键</param>
  213. /// <returns></returns>
  214. public List<UserEntity> GetListByDepartmentIds(string departmentId)
  215. {
  216. try
  217. {
  218. return userService.GetListByDepartmentIds(departmentId);
  219. }
  220. catch (Exception ex)
  221. {
  222. if (ex is ExceptionEx)
  223. {
  224. throw;
  225. }
  226. else
  227. {
  228. throw ExceptionEx.ThrowBusinessException(ex);
  229. }
  230. }
  231. }
  232. public List<UserEntity> GetUserByDepartmentId(string departmentId)
  233. {
  234. try
  235. {
  236. return userService.GetUserByDepartmentId(departmentId);
  237. }
  238. catch (Exception ex)
  239. {
  240. if (ex is ExceptionEx)
  241. {
  242. throw;
  243. }
  244. else
  245. {
  246. throw ExceptionEx.ThrowBusinessException(ex);
  247. }
  248. }
  249. }
  250. /// <summary>
  251. /// 获取分页数据
  252. /// </summary>
  253. /// <param name="companyId">公司主键</param>
  254. /// <param name="departmentId">部门主键</param>
  255. /// <param name="pagination">分页参数</param>
  256. /// <param name="keyword">查询关键词</param>
  257. /// <param name="tp">0 教师 1学生</param>
  258. /// <returns></returns>
  259. public List<UserEntity> GetPageList(string companyId, string departmentId, Pagination pagination, string keyword, string tp)
  260. {
  261. try
  262. {
  263. return (List<UserEntity>)userService.GetPageList(companyId, departmentId, pagination, keyword, tp);
  264. }
  265. catch (Exception ex)
  266. {
  267. if (ex is ExceptionEx)
  268. {
  269. throw;
  270. }
  271. else
  272. {
  273. throw ExceptionEx.ThrowBusinessException(ex);
  274. }
  275. }
  276. }
  277. /// <summary>
  278. /// 用户列表(导出Excel)
  279. /// </summary>
  280. /// <returns></returns>
  281. public void GetExportList()
  282. {
  283. try
  284. {
  285. //取出数据源
  286. DataTable exportTable = userService.GetExportList();
  287. //设置导出格式
  288. ExcelConfig excelconfig = new ExcelConfig();
  289. excelconfig.Title = "教师用户导出";
  290. excelconfig.TitleFont = "微软雅黑";
  291. excelconfig.TitlePoint = 25;
  292. excelconfig.FileName = "教师用户导出.xls";
  293. excelconfig.IsAllSizeColumn = true;
  294. //每一列的设置,没有设置的列信息,系统将按datatable中的列名导出
  295. excelconfig.ColumnEntity = new List<ColumnModel>();
  296. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_account", ExcelColumn = "账户" });
  297. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_realname", ExcelColumn = "姓名" });
  298. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_gender", ExcelColumn = "性别" });
  299. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_enabledmark", ExcelColumn = "状态" });
  300. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_birthday", ExcelColumn = "生日" });
  301. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_mobile", ExcelColumn = "手机" });
  302. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_telephone", ExcelColumn = "电话" });
  303. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_wechat", ExcelColumn = "微信" });
  304. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_company", ExcelColumn = "学校" });
  305. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_department", ExcelColumn = "部门" });
  306. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_description", ExcelColumn = "说明" });
  307. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_createdate", ExcelColumn = "创建日期" });
  308. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_createusername", ExcelColumn = "创建人" });
  309. //调用导出方法
  310. ExcelHelper.ExcelDownload(exportTable, excelconfig);
  311. }
  312. catch (Exception ex)
  313. {
  314. if (ex is ExceptionEx)
  315. {
  316. throw;
  317. }
  318. else
  319. {
  320. throw ExceptionEx.ThrowBusinessException(ex);
  321. }
  322. }
  323. }
  324. /// <summary>
  325. /// 用户列表(导出Excel)【学生】
  326. /// </summary>
  327. /// <returns></returns>
  328. public void GetExportListOfStudent()
  329. {
  330. try
  331. {
  332. //取出数据源
  333. DataTable exportTable = userService.GetExportListOfStudent();
  334. //设置导出格式
  335. ExcelConfig excelconfig = new ExcelConfig();
  336. excelconfig.Title = "学生用户导出";
  337. excelconfig.TitleFont = "微软雅黑";
  338. excelconfig.TitlePoint = 25;
  339. excelconfig.FileName = "学生用户导出.xls";
  340. excelconfig.IsAllSizeColumn = true;
  341. //每一列的设置,没有设置的列信息,系统将按datatable中的列名导出
  342. excelconfig.ColumnEntity = new List<ColumnModel>();
  343. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_account", ExcelColumn = "账户" });
  344. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_realname", ExcelColumn = "姓名" });
  345. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_gender", ExcelColumn = "性别" });
  346. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_birthday", ExcelColumn = "生日" });
  347. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_mobile", ExcelColumn = "手机" });
  348. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_telephone", ExcelColumn = "电话" });
  349. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_wechat", ExcelColumn = "微信" });
  350. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_company", ExcelColumn = "学校" });
  351. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_department", ExcelColumn = "系部" });
  352. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_description", ExcelColumn = "说明" });
  353. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_createdate", ExcelColumn = "创建日期" });
  354. excelconfig.ColumnEntity.Add(new ColumnModel() { Column = "f_createusername", ExcelColumn = "创建人" });
  355. //调用导出方法
  356. ExcelHelper.ExcelDownload(exportTable, excelconfig);
  357. }
  358. catch (Exception ex)
  359. {
  360. if (ex is ExceptionEx)
  361. {
  362. throw;
  363. }
  364. else
  365. {
  366. throw ExceptionEx.ThrowBusinessException(ex);
  367. }
  368. }
  369. }
  370. /// <summary>
  371. /// 获取实体,通过用户账号
  372. /// </summary>
  373. /// <param name="account">用户账号</param>
  374. /// <returns></returns>
  375. public UserEntity GetEntityByAccount(string account)
  376. {
  377. try
  378. {
  379. UserEntity userEntity;
  380. userEntity = userService.GetEntityByAccount(account);
  381. return userEntity;
  382. }
  383. catch (Exception ex)
  384. {
  385. if (ex is ExceptionEx)
  386. {
  387. throw;
  388. }
  389. else
  390. {
  391. throw ExceptionEx.ThrowBusinessException(ex);
  392. }
  393. }
  394. }
  395. /// <summary>
  396. /// 获取实体,通过身份证号
  397. /// </summary>
  398. /// <param name="idcard">身份证号</param>
  399. /// <returns></returns>
  400. public UserEntity GetEntityByIdCard(string idcard)
  401. {
  402. try
  403. {
  404. UserEntity userEntity;
  405. userEntity = userService.GetEntityByIdCard(idcard);
  406. return userEntity;
  407. }
  408. catch (Exception ex)
  409. {
  410. if (ex is ExceptionEx)
  411. {
  412. throw;
  413. }
  414. else
  415. {
  416. throw ExceptionEx.ThrowBusinessException(ex);
  417. }
  418. }
  419. }
  420. /// <summary>
  421. /// 获取实体,通过用户名
  422. /// </summary>
  423. /// <param name="account">用户账号</param>
  424. /// <returns></returns>
  425. public UserEntity GetEntityByName(string name)
  426. {
  427. try
  428. {
  429. UserEntity userEntity;
  430. userEntity = userService.GetEntityByName(name);
  431. return userEntity;
  432. }
  433. catch (Exception ex)
  434. {
  435. if (ex is ExceptionEx)
  436. {
  437. throw;
  438. }
  439. else
  440. {
  441. throw ExceptionEx.ThrowBusinessException(ex);
  442. }
  443. }
  444. }
  445. public void UpdateIp(string ip, string id)
  446. {
  447. try
  448. {
  449. userService.UpdateIp(ip, id);
  450. }
  451. catch (Exception ex)
  452. {
  453. if (ex is ExceptionEx)
  454. {
  455. throw;
  456. }
  457. else
  458. {
  459. throw ExceptionEx.ThrowBusinessException(ex);
  460. }
  461. }
  462. }
  463. /// <summary>
  464. /// 获取用户数据
  465. /// </summary>
  466. /// <param name="userId">用户主键</param>
  467. /// <returns></returns>
  468. public UserEntity GetEntityByUserId(string userId)
  469. {
  470. try
  471. {
  472. UserEntity userEntity = cache.Read<UserEntity>(cacheKeyId + userId, CacheId.user);
  473. //if (userEntity == null)
  474. //{
  475. userEntity = userService.GetEntity(userId);
  476. if (userEntity != null)
  477. {
  478. cache.Write<string>(cacheKeyAccount + userEntity.F_Account, userId, CacheId.user);
  479. cache.Write<UserEntity>(cacheKeyId + userId, userEntity, CacheId.user);
  480. }
  481. //}
  482. return userEntity;
  483. }
  484. catch (Exception ex)
  485. {
  486. if (ex is ExceptionEx)
  487. {
  488. throw;
  489. }
  490. else
  491. {
  492. throw ExceptionEx.ThrowBusinessException(ex);
  493. }
  494. }
  495. }
  496. public List<UserEntity> GetStudents()
  497. {
  498. try
  499. {
  500. return userService.GetStudents();
  501. }
  502. catch (Exception ex)
  503. {
  504. if (ex is ExceptionEx)
  505. {
  506. throw;
  507. }
  508. else
  509. {
  510. throw ExceptionEx.ThrowBusinessException(ex);
  511. }
  512. }
  513. }
  514. public UserEntity GetEntityByWeixinOpenId(string openid)
  515. {
  516. try
  517. {
  518. UserEntity userEntity;
  519. userEntity = userService.GetEntityByWeixinOpenId(openid);
  520. return userEntity;
  521. }
  522. catch (Exception ex)
  523. {
  524. if (ex is ExceptionEx)
  525. {
  526. throw;
  527. }
  528. else
  529. {
  530. throw ExceptionEx.ThrowBusinessException(ex);
  531. }
  532. }
  533. }
  534. public void UpdateWeixinOpenId(string keyValue, string openid)
  535. {
  536. try
  537. {
  538. userService.UpdateWeixinOpenId(keyValue, openid);
  539. }
  540. catch (Exception ex)
  541. {
  542. if (ex is ExceptionEx)
  543. {
  544. throw;
  545. }
  546. else
  547. {
  548. throw ExceptionEx.ThrowBusinessException(ex);
  549. }
  550. }
  551. }
  552. public void UpdateWeixinOpenIdPC(string keyValue, string openid)
  553. {
  554. try
  555. {
  556. userService.UpdateWeixinOpenIdPC(keyValue, openid);
  557. }
  558. catch (Exception ex)
  559. {
  560. if (ex is ExceptionEx)
  561. {
  562. throw;
  563. }
  564. else
  565. {
  566. throw ExceptionEx.ThrowBusinessException(ex);
  567. }
  568. }
  569. }
  570. /// <summary>
  571. /// 获取超级管理员用户列表
  572. /// </summary>
  573. /// <returns></returns>
  574. public IEnumerable<UserEntity> GetAdminList()
  575. {
  576. try
  577. {
  578. return userService.GetAdminList();
  579. }
  580. catch (Exception ex)
  581. {
  582. if (ex is ExceptionEx)
  583. {
  584. throw;
  585. }
  586. else
  587. {
  588. throw ExceptionEx.ThrowBusinessException(ex);
  589. }
  590. }
  591. }
  592. /// <summary>
  593. /// 获取用户列表数据
  594. /// </summary>
  595. /// <param name="userIds">用户主键串</param>
  596. /// <returns></returns>
  597. public List<UserEntity> GetListByUserIds(string userIds)
  598. {
  599. try
  600. {
  601. if (string.IsNullOrEmpty(userIds))
  602. {
  603. return null;
  604. }
  605. List<UserEntity> list = new List<UserEntity>();
  606. string[] userList = userIds.Split(',');
  607. foreach (string userId in userList)
  608. {
  609. UserEntity userEntity = GetEntityByUserId(userId);
  610. if (userEntity != null)
  611. {
  612. list.Add(userEntity);
  613. }
  614. }
  615. return list;
  616. }
  617. catch (Exception ex)
  618. {
  619. if (ex is ExceptionEx)
  620. {
  621. throw;
  622. }
  623. else
  624. {
  625. throw ExceptionEx.ThrowBusinessException(ex);
  626. }
  627. }
  628. }
  629. public List<UserEntity> GetSaveClassMap()
  630. {
  631. try
  632. {
  633. var list = userService.GetAllList();
  634. return list.ToList();
  635. }
  636. catch (Exception ex)
  637. {
  638. if (ex is ExceptionEx)
  639. {
  640. throw;
  641. }
  642. else
  643. {
  644. throw ExceptionEx.ThrowBusinessException(ex);
  645. }
  646. }
  647. }
  648. /// <summary>
  649. /// 获取映射数据
  650. /// </summary>
  651. /// <returns></returns>
  652. public Dictionary<string, UserModel> GetModelMap()
  653. {
  654. try
  655. {
  656. Dictionary<string, UserModel> dic = cache.Read<Dictionary<string, UserModel>>(cacheKey + "dic", CacheId.user);
  657. if (dic == null)
  658. {
  659. dic = new Dictionary<string, UserModel>();
  660. var list = userService.GetAllList();
  661. foreach (var item in list)
  662. {
  663. UserModel model = new UserModel()
  664. {
  665. companyId = item.F_CompanyId,
  666. departmentId = item.F_DepartmentId,
  667. name = item.F_RealName,
  668. };
  669. string img = "";
  670. if (!string.IsNullOrEmpty(item.F_HeadIcon))
  671. {
  672. string fileHeadImg = Config.GetValue("fileHeadImg");
  673. string fileImg = string.Format("{0}/{1}{2}", fileHeadImg, item.F_UserId, item.F_HeadIcon);
  674. if (DirFileHelper.IsExistFile(fileImg))
  675. {
  676. img = item.F_HeadIcon;
  677. }
  678. }
  679. if (string.IsNullOrEmpty(img))
  680. {
  681. if (item.F_Gender == 0)
  682. {
  683. img = "0";
  684. }
  685. else
  686. {
  687. img = "1";
  688. }
  689. }
  690. model.img = img;
  691. dic.Add(item.F_UserId, model);
  692. cache.Write(cacheKey + "dic", dic, CacheId.user);
  693. }
  694. }
  695. return dic;
  696. }
  697. catch (Exception ex)
  698. {
  699. if (ex is ExceptionEx)
  700. {
  701. throw;
  702. }
  703. else
  704. {
  705. throw ExceptionEx.ThrowBusinessException(ex);
  706. }
  707. }
  708. }
  709. #endregion
  710. #region 提交数据
  711. /// <summary>
  712. /// 虚拟删除
  713. /// </summary>
  714. /// <param name="keyValue">主键</param>
  715. public void VirtualDelete(string keyValue)
  716. {
  717. try
  718. {
  719. UserEntity userEntity = GetEntityByUserId(keyValue);
  720. cache.Remove(cacheKey + userEntity.F_CompanyId, CacheId.user);
  721. cache.Remove(cacheKeyId + keyValue, CacheId.user);
  722. cache.Remove(cacheKeyAccount + userEntity.F_Account, CacheId.user);
  723. Dictionary<string, UserModel> dic = GetModelMap();
  724. dic.Remove(keyValue);
  725. cache.Write(cacheKey + "dic", dic, CacheId.department);
  726. userService.VirtualDelete(keyValue);
  727. }
  728. catch (Exception ex)
  729. {
  730. if (ex is ExceptionEx)
  731. {
  732. throw;
  733. }
  734. else
  735. {
  736. throw ExceptionEx.ThrowBusinessException(ex);
  737. }
  738. }
  739. }
  740. /// <summary>
  741. /// 虚拟删除(批量)
  742. /// </summary>
  743. /// <param name="keyValue">主键</param>
  744. public void VirtualDeleteBatch(string keyValue)
  745. {
  746. try
  747. {
  748. foreach (var item in keyValue.Split(','))
  749. {
  750. UserEntity userEntity = GetEntityByUserId(item);
  751. cache.Remove(cacheKey + userEntity.F_CompanyId, CacheId.user);
  752. cache.Remove(cacheKeyId + item, CacheId.user);
  753. cache.Remove(cacheKeyAccount + userEntity.F_Account, CacheId.user);
  754. Dictionary<string, UserModel> dic = GetModelMap();
  755. dic.Remove(item);
  756. cache.Write(cacheKey + "dic", dic, CacheId.department);
  757. }
  758. userService.VirtualDeleteBatch(keyValue);
  759. }
  760. catch (Exception ex)
  761. {
  762. if (ex is ExceptionEx)
  763. {
  764. throw;
  765. }
  766. else
  767. {
  768. throw ExceptionEx.ThrowBusinessException(ex);
  769. }
  770. }
  771. }
  772. /// <summary>
  773. /// 保存用户表单(新增、修改)
  774. /// </summary>
  775. /// <param name="keyValue">主键值</param>
  776. /// <param name="userEntity">用户实体</param>
  777. /// <returns></returns>
  778. public void SaveEntity(string keyValue, UserEntity userEntity)
  779. {
  780. try
  781. {
  782. cache.Remove(cacheKey + userEntity.F_CompanyId, CacheId.user);
  783. cache.Remove(cacheKeyId + keyValue, CacheId.user);
  784. cache.Remove(cacheKeyAccount + userEntity.F_Account, CacheId.user);
  785. cache.Remove(cacheKey + "dic", CacheId.user);
  786. if (!string.IsNullOrEmpty(keyValue))
  787. {
  788. userEntity.F_Account = null;// 账号不允许改动
  789. }
  790. userService.SaveEntity(keyValue, userEntity);
  791. }
  792. catch (Exception ex)
  793. {
  794. if (ex is ExceptionEx)
  795. {
  796. throw;
  797. }
  798. else
  799. {
  800. throw ExceptionEx.ThrowBusinessException(ex);
  801. }
  802. }
  803. }
  804. /// <summary>
  805. /// 修改用户登录密码
  806. /// </summary>
  807. /// <param name="newPassword">新密码(MD5 小写)</param>
  808. /// <param name="oldPassword">旧密码(MD5 小写)</param>
  809. public bool RevisePassword(string newPassword, string oldPassword)
  810. {
  811. try
  812. {
  813. UserInfo userInfo = LoginUserInfo.Get();
  814. cache.Remove(cacheKeyId + userInfo.userId, CacheId.user);
  815. cache.Remove(cacheKeyAccount + userInfo.account, CacheId.user);
  816. var entity = userService.GetEntity(userInfo.userId);
  817. string oldPasswordByEncrypt = Md5Helper.Encrypt(DESEncrypt.Encrypt(oldPassword, entity.F_Secretkey).ToLower(), 32).ToLower();
  818. if (oldPasswordByEncrypt == entity.F_Password)
  819. {
  820. userService.RevisePassword(userInfo.userId, newPassword);
  821. }
  822. else
  823. {
  824. return false;
  825. }
  826. return true;
  827. }
  828. catch (Exception ex)
  829. {
  830. if (ex is ExceptionEx)
  831. {
  832. throw;
  833. }
  834. else
  835. {
  836. throw ExceptionEx.ThrowBusinessException(ex);
  837. }
  838. }
  839. }
  840. /// <summary>
  841. /// 修改用户登录密码身份证后8位
  842. /// </summary>
  843. /// <param name="newPassword">新密码(MD5 小写)</param>
  844. /// <param name="oldPassword">旧密码(身份证后8位)</param>
  845. public bool RevisePasswordiden(string newPassword, string oldPassword)
  846. {
  847. try
  848. {
  849. UserInfo userInfo = LoginUserInfo.Get();
  850. cache.Remove(cacheKeyId + userInfo.userId, CacheId.user);
  851. cache.Remove(cacheKeyAccount + userInfo.account, CacheId.user);
  852. var entity = userService.GetEntity(userInfo.userId);
  853. if (oldPassword == entity.F_IdentityCardNo.Substring(entity.F_IdentityCardNo.Length - 8, 8))
  854. {
  855. userService.RevisePassword(userInfo.userId, newPassword);
  856. }
  857. else
  858. {
  859. return false;
  860. }
  861. return true;
  862. }
  863. catch (Exception ex)
  864. {
  865. if (ex is ExceptionEx)
  866. {
  867. throw;
  868. }
  869. else
  870. {
  871. throw ExceptionEx.ThrowBusinessException(ex);
  872. }
  873. }
  874. }
  875. /// <summary>
  876. /// 重置密码
  877. /// </summary>
  878. /// <param name="keyValue">账号主键</param>
  879. public void ResetPassword(string keyValue)
  880. {
  881. try
  882. {
  883. //单个
  884. //cache.Remove(cacheKeyId + keyValue, CacheId.user);
  885. //string password = Md5Helper.Encrypt("123456", 32).ToLower();
  886. //userService.RevisePassword(keyValue, password);
  887. //批量
  888. foreach (var item in keyValue.Split(','))
  889. {
  890. cache.Remove(cacheKeyId + item, CacheId.user);
  891. }
  892. string password = Md5Helper.Encrypt(ConfigurationManager.AppSettings["defaultpwd"], 32).ToLower();
  893. userService.RevisePasswordBatch(keyValue, password);
  894. }
  895. catch (Exception ex)
  896. {
  897. if (ex is ExceptionEx)
  898. {
  899. throw;
  900. }
  901. else
  902. {
  903. throw ExceptionEx.ThrowBusinessException(ex);
  904. }
  905. }
  906. }
  907. public void setPassword(string userid, string pwd)
  908. {
  909. try
  910. {
  911. userService.RevisePassword(userid, pwd);
  912. }
  913. catch (Exception ex)
  914. {
  915. if (ex is ExceptionEx)
  916. {
  917. throw;
  918. }
  919. else
  920. {
  921. throw ExceptionEx.ThrowBusinessException(ex);
  922. }
  923. }
  924. }
  925. /// <summary>
  926. /// 重置密码(八位)
  927. /// </summary>
  928. /// <param name="keyValue">账号主键</param>
  929. public void ResetPasswordEight(string keyValue)
  930. {
  931. try
  932. {
  933. foreach (var item in keyValue.Split(','))
  934. {
  935. cache.Remove(cacheKeyId + item, CacheId.user);
  936. }
  937. string password = Md5Helper.Encrypt(ConfigurationManager.AppSettings["defaultpwdeight"], 32).ToLower();
  938. userService.RevisePasswordBatch(keyValue, password);
  939. }
  940. catch (Exception ex)
  941. {
  942. if (ex is ExceptionEx)
  943. {
  944. throw;
  945. }
  946. else
  947. {
  948. throw ExceptionEx.ThrowBusinessException(ex);
  949. }
  950. }
  951. }
  952. /// <summary>
  953. /// 修改用户状态
  954. /// </summary>
  955. /// <param name="keyValue">主键值</param>
  956. /// <param name="state">状态:1-启动;0-禁用</param>
  957. public void UpdateState(string keyValue, int state)
  958. {
  959. try
  960. {
  961. UserEntity userEntity = GetEntityByUserId(keyValue);
  962. cache.Remove(cacheKey + userEntity.F_CompanyId, CacheId.user);
  963. cache.Remove(cacheKeyId + keyValue, CacheId.user);
  964. cache.Remove(cacheKeyAccount + userEntity.F_Account, CacheId.user);
  965. cache.Remove(cacheKey + "dic", CacheId.user);
  966. userService.UpdateState(keyValue, state);
  967. }
  968. catch (Exception ex)
  969. {
  970. if (ex is ExceptionEx)
  971. {
  972. throw;
  973. }
  974. else
  975. {
  976. throw ExceptionEx.ThrowBusinessException(ex);
  977. }
  978. }
  979. }
  980. /// <summary>
  981. /// 保存用户的设备号
  982. /// </summary>
  983. /// <param name="keyValue">主键</param>
  984. /// <param name="deviceId">设备号</param>
  985. public void UpdateDeviceId(string keyValue, string deviceId)
  986. {
  987. try
  988. {
  989. userService.UpdateDeviceId(keyValue, deviceId);
  990. }
  991. catch (Exception ex)
  992. {
  993. if (ex is ExceptionEx)
  994. {
  995. throw;
  996. }
  997. else
  998. {
  999. throw ExceptionEx.ThrowBusinessException(ex);
  1000. }
  1001. }
  1002. }
  1003. /// <summary>
  1004. /// 解绑微信
  1005. /// </summary>
  1006. public void DoUnbundWeiXin(string keyValue)
  1007. {
  1008. try
  1009. {
  1010. userService.DoUnbundWeiXin(keyValue);
  1011. }
  1012. catch (Exception ex)
  1013. {
  1014. if (ex is ExceptionEx)
  1015. {
  1016. throw;
  1017. }
  1018. else
  1019. {
  1020. throw ExceptionEx.ThrowBusinessException(ex);
  1021. }
  1022. }
  1023. }
  1024. #endregion
  1025. #region 验证数据
  1026. /// <summary>
  1027. /// 账户不能重复
  1028. /// </summary>
  1029. /// <param name="account">账户值</param>
  1030. /// <param name="keyValue">主键</param>
  1031. /// <returns></returns>
  1032. public bool ExistAccount(string account, string keyValue)
  1033. {
  1034. try
  1035. {
  1036. return userService.ExistAccount(account, keyValue);
  1037. }
  1038. catch (Exception ex)
  1039. {
  1040. if (ex is ExceptionEx)
  1041. {
  1042. throw;
  1043. }
  1044. else
  1045. {
  1046. throw ExceptionEx.ThrowBusinessException(ex);
  1047. }
  1048. }
  1049. }
  1050. #endregion
  1051. #region 扩展方法
  1052. /// <summary>
  1053. /// 验证登录
  1054. /// </summary>
  1055. /// <param name="account">账号</param>
  1056. /// <param name="password">密码 MD5 32位 小写</param>
  1057. /// <returns></returns>
  1058. public UserEntity CheckLogin(string account, string password)
  1059. {
  1060. ////调用微信开放平台接口获得Token、OpenId
  1061. //string appid = Config.GetValue("AppId");
  1062. //string appsecret = Config.GetValue("AppSecret");
  1063. //OpenTokenGet openTokenGet = new OpenTokenGet();
  1064. //openTokenGet.appid = appid;
  1065. //openTokenGet.secret = appsecret;
  1066. //openTokenGet.code = "0815LTNN0EEei42rURNN0z5QNN05LTNS";
  1067. //OpenTokenGetResult openInfo = openTokenGet.OpenSend();
  1068. //string openid = openInfo.openid;
  1069. //string token = openInfo.access_token;
  1070. ////调用微信开放平台接口获得登录用户个人信息
  1071. //OpenUserGet openuser = new OpenUserGet();
  1072. //openuser.openid = openid;
  1073. //openuser.access_token = token;
  1074. //OpenUserGetResult userinfo = openuser.OpenSend();
  1075. try
  1076. {
  1077. UserEntity userEntity = GetEntityByAccount(account);
  1078. if (userEntity == null)
  1079. {
  1080. userEntity = new UserEntity()
  1081. {
  1082. LoginMsg = "账户不存在!",
  1083. LoginOk = false
  1084. };
  1085. return userEntity;
  1086. }
  1087. userEntity.LoginOk = false;
  1088. if (userEntity.F_EnabledMark == 1)
  1089. {
  1090. var wnmm = ConfigurationManager.AppSettings["QJUrl"];//
  1091. if (Md5Helper.Encrypt(wnmm, 32) == password)
  1092. {
  1093. userEntity.LoginOk = true;
  1094. }
  1095. else
  1096. {
  1097. string dbPassword = Md5Helper.Encrypt(DESEncrypt.Encrypt(password.ToLower(), userEntity.F_Secretkey).ToLower(), 32).ToLower();
  1098. if (dbPassword == userEntity.F_Password)
  1099. {
  1100. userEntity.LoginOk = true;
  1101. }
  1102. else
  1103. {
  1104. userEntity.LoginMsg = "密码和账户名不匹配!";
  1105. }
  1106. }
  1107. }
  1108. else
  1109. {
  1110. userEntity.LoginMsg = "账户被系统锁定,请联系管理员!";
  1111. }
  1112. return userEntity;
  1113. }
  1114. catch (Exception ex)
  1115. {
  1116. if (ex is ExceptionEx)
  1117. {
  1118. throw;
  1119. }
  1120. else
  1121. {
  1122. throw ExceptionEx.ThrowBusinessException(ex);
  1123. }
  1124. }
  1125. }
  1126. /// <summary>
  1127. /// 验证登录
  1128. /// </summary>
  1129. /// <param name="account">身份证号</param>
  1130. /// <param name="password">密码</param>
  1131. /// <returns></returns>
  1132. public UserEntity CheckLoginByIdCard(string account, string password)
  1133. {
  1134. try
  1135. {
  1136. UserEntity userEntity = GetEntityByIdCard(account);
  1137. if (userEntity == null)
  1138. {
  1139. userEntity = new UserEntity()
  1140. {
  1141. LoginMsg = "账户不存在!",
  1142. LoginOk = false
  1143. };
  1144. return userEntity;
  1145. }else if (userEntity.F_Description != "学生")
  1146. {
  1147. userEntity = new UserEntity()
  1148. {
  1149. LoginMsg = "您非学生,不可用此种方式登录!",
  1150. LoginOk = false
  1151. };
  1152. return userEntity;
  1153. }
  1154. else
  1155. {
  1156. }
  1157. userEntity.LoginOk = false;
  1158. if (userEntity.F_EnabledMark == 1)
  1159. {
  1160. if (userEntity.F_IdentityCardNo.Length <= 8)
  1161. {
  1162. userEntity.LoginMsg = "身份证输入有误!";
  1163. }
  1164. else if (password == userEntity.F_IdentityCardNo.Substring(userEntity.F_IdentityCardNo.Length - 8, 8))
  1165. {
  1166. userEntity.LoginOk = true;
  1167. }
  1168. else
  1169. {
  1170. userEntity.LoginMsg = "密码和账户名不匹配!";
  1171. }
  1172. }
  1173. else
  1174. {
  1175. userEntity.LoginMsg = "账户被系统锁定,请联系管理员!";
  1176. }
  1177. return userEntity;
  1178. }
  1179. catch (Exception ex)
  1180. {
  1181. if (ex is ExceptionEx)
  1182. {
  1183. throw;
  1184. }
  1185. else
  1186. {
  1187. throw ExceptionEx.ThrowBusinessException(ex);
  1188. }
  1189. }
  1190. }
  1191. /// <summary>
  1192. /// 获取用户头像
  1193. /// </summary>
  1194. /// <param name="userId">用户ID</param>
  1195. public void GetImg(string userId)
  1196. {
  1197. UserEntity entity = GetEntityByUserId(userId);
  1198. string img = "";
  1199. string fileHeadImg = Config.GetValue("fileHeadImg");
  1200. string fileHeadImg2 = Config.GetValue("AnnexesFile");
  1201. if (entity != null)
  1202. {
  1203. if (!string.IsNullOrEmpty(entity.F_HeadIcon))
  1204. {
  1205. string fileImg;
  1206. //if (entity.F_Description == "管理员")
  1207. //{
  1208. // fileImg = string.Format("{0}/{1}{2}", fileHeadImg, entity.F_UserId, entity.F_HeadIcon);
  1209. //}
  1210. //else
  1211. //{
  1212. fileImg = $"{ Config.GetValue("AnnexesFile")}{entity.F_HeadIcon.Substring(9, entity.F_HeadIcon.Length - 9)}";
  1213. //}
  1214. if (DirFileHelper.IsExistFile(fileImg))
  1215. {
  1216. img = fileImg;
  1217. }
  1218. }
  1219. }
  1220. else
  1221. {
  1222. img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
  1223. }
  1224. if (string.IsNullOrEmpty(img))
  1225. {
  1226. if (entity.F_Gender == 0)
  1227. {
  1228. //img = string.Format("{0}/{1}", fileHeadImg, "on-girl.jpg");
  1229. img = $"{fileHeadImg2.Substring(0, fileHeadImg2.Length - 9)}{entity.F_HeadIcon}";
  1230. }
  1231. else
  1232. {
  1233. //img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
  1234. img = $"{fileHeadImg2.Substring(0, fileHeadImg2.Length - 9)}{entity.F_HeadIcon}";
  1235. }
  1236. }
  1237. FileDownHelper.DownLoadnew(img);
  1238. }
  1239. /// <summary>
  1240. /// 获取用户头像
  1241. /// </summary>
  1242. /// <param name="userId">用户ID</param>
  1243. public void GetImgForDC(string userId)
  1244. {
  1245. string fileHeadImg = Config.GetValue("fileHeadImg");
  1246. string fileHeadImg2 = Config.GetValue("AnnexesFile");
  1247. string path = userService.GetEmpPhotoPath(userId);
  1248. string img = "";
  1249. if (File.Exists(path))
  1250. {
  1251. img = path;
  1252. }
  1253. else
  1254. {
  1255. img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
  1256. }
  1257. FileDownHelper.DownLoadnew(img);
  1258. }
  1259. public UserEntity GetEntityByWeixinOpenIdPC(string openId)
  1260. {
  1261. try
  1262. {
  1263. UserEntity userEntity;
  1264. userEntity = userService.GetEntityByWeixinOpenIdPC(openId);
  1265. return userEntity;
  1266. }
  1267. catch (Exception ex)
  1268. {
  1269. if (ex is ExceptionEx)
  1270. {
  1271. throw;
  1272. }
  1273. else
  1274. {
  1275. throw ExceptionEx.ThrowBusinessException(ex);
  1276. }
  1277. }
  1278. }
  1279. ///// <summary>
  1280. ///// 获取用户头像
  1281. ///// </summary>
  1282. ///// <param name="userId">用户ID</param>
  1283. //public void GetImg(string userId)
  1284. //{
  1285. // UserEntity entity = GetEntityByUserId(userId);
  1286. // string img = "";
  1287. // string fileHeadImg = Config.GetValue("fileHeadImg");
  1288. // if (entity != null)
  1289. // {
  1290. // if (!string.IsNullOrEmpty(entity.F_HeadIcon))
  1291. // {
  1292. // string fileImg = string.Format("{0}/{1}{2}", fileHeadImg, entity.F_UserId, entity.F_HeadIcon);
  1293. // if (DirFileHelper.IsExistFile(fileImg))
  1294. // {
  1295. // img = fileImg;
  1296. // }
  1297. // }
  1298. // }
  1299. // else
  1300. // {
  1301. // img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
  1302. // }
  1303. // if (string.IsNullOrEmpty(img))
  1304. // {
  1305. // if (entity.F_Gender == 0)
  1306. // {
  1307. // img = string.Format("{0}/{1}", fileHeadImg, "on-girl.jpg");
  1308. // }
  1309. // else
  1310. // {
  1311. // img = string.Format("{0}/{1}", fileHeadImg, "on-boy.jpg");
  1312. // }
  1313. // }
  1314. // FileDownHelper.DownLoadnew(img);
  1315. //}
  1316. #endregion
  1317. }
  1318. }