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.
 
 
 
 
 
 

966 lines
34 KiB

  1. using Dapper;
  2. using Learun.DataBase.Repository;
  3. using Learun.Util;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Linq;
  8. using System.Text;
  9. using Learun.Application.Base.AuthorizeModule;
  10. using Learun.Application.Organization;
  11. using System.Reflection;
  12. using Learun.Application.Base.SystemModule;
  13. using Learun.Application.TwoDevelopment.LogisticsManagement;
  14. namespace Learun.Application.TwoDevelopment.EducationalAdministration
  15. {
  16. /// <summary>
  17. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  18. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  19. /// 创 建:超级管理员
  20. /// 日 期:2019-02-21 16:53
  21. /// 描 述:学生学籍
  22. /// </summary>
  23. public class StuInfoBasicService : RepositoryFactory
  24. {
  25. #region 获取数据
  26. /// <summary>
  27. /// 获取页面显示列表数据
  28. /// <summary>
  29. /// <param name="queryJson">查询参数</param>
  30. /// <returns></returns>
  31. public IEnumerable<StuInfoBasicEntity> GetPageList(Pagination pagination, string queryJson)
  32. {
  33. try
  34. {
  35. var strSql = new StringBuilder();
  36. strSql.Append("SELECT t.* ");
  37. strSql.Append(" FROM StuInfoBasic t ");
  38. strSql.Append(" WHERE 1=1 ");
  39. var queryParam = queryJson.ToJObject();
  40. // 虚拟参数
  41. var dp = new DynamicParameters(new { });
  42. if (!queryParam["StuNo"].IsEmpty())
  43. {
  44. dp.Add("StuNo", queryParam["StuNo"].ToString(), DbType.String);
  45. strSql.Append(" AND t.StuNo = @StuNo ");
  46. }
  47. if (!queryParam["StuName"].IsEmpty())
  48. {
  49. dp.Add("StuName", "%" + queryParam["StuName"].ToString() + "%", DbType.String);
  50. strSql.Append(" AND t.StuName Like @StuName ");
  51. }
  52. if (!queryParam["DeptNo"].IsEmpty())
  53. {
  54. dp.Add("DeptNo", "" + queryParam["DeptNo"].ToString() + "", DbType.String);
  55. strSql.Append(" AND t.DeptNo=@DeptNo ");
  56. }
  57. if (!queryParam["MajorNo"].IsEmpty())
  58. {
  59. dp.Add("MajorNo", "" + queryParam["MajorNo"].ToString() + "", DbType.String);
  60. strSql.Append(" AND t.MajorNo=@MajorNo ");
  61. }
  62. if (!queryParam["ClassNo"].IsEmpty())
  63. {
  64. dp.Add("ClassNo", "" + queryParam["ClassNo"].ToString() + "", DbType.String);
  65. strSql.Append(" AND t.ClassNo=@ClassNo ");
  66. }
  67. if (!queryParam["Grade"].IsEmpty())
  68. {
  69. dp.Add("Grade", "" + queryParam["Grade"].ToString() + "", DbType.String);
  70. strSql.Append(" AND t.Grade=@Grade ");
  71. }
  72. if (!queryParam["FinishSchoolMark"].IsEmpty())
  73. {
  74. dp.Add("FinishSchoolMark", "" + queryParam["FinishSchoolMark"].ToString() + "", DbType.String);
  75. if (queryParam["FinishSchoolMark"].ToString() == "0")
  76. {
  77. strSql.Append(" AND (t.FinishSchoolMark is null or t.FinishSchoolMark='0') ");
  78. }
  79. else
  80. {
  81. strSql.Append(" AND t.FinishSchoolMark=@FinishSchoolMark ");
  82. }
  83. }
  84. if (!queryParam["Remark"].IsEmpty())
  85. {
  86. dp.Add("Remark", "%" + queryParam["Remark"].ToString() + "%", DbType.String);
  87. strSql.Append(" AND t.Remark Like @Remark ");
  88. }
  89. return this.BaseRepository("CollegeMIS").FindList<StuInfoBasicEntity>(strSql.ToString(), dp, pagination);
  90. }
  91. catch (Exception ex)
  92. {
  93. if (ex is ExceptionEx)
  94. {
  95. throw;
  96. }
  97. else
  98. {
  99. throw ExceptionEx.ThrowServiceException(ex);
  100. }
  101. }
  102. }
  103. internal List<string> GetSaveClassStudents(string account)
  104. {
  105. try
  106. {
  107. var classNO = this.BaseRepository("CollegeMIS").FindEntity<StuInfoBasicEntity>(a => a.StuNo == account).ClassNo;
  108. return this.BaseRepository("CollegeMIS").FindList<StuInfoBasicEntity>(a => a.ClassNo == classNO).Select(a => a.StuNo).ToList();
  109. }
  110. catch (Exception ex)
  111. {
  112. if (ex is ExceptionEx)
  113. {
  114. throw;
  115. }
  116. else
  117. {
  118. throw ExceptionEx.ThrowServiceException(ex);
  119. }
  120. }
  121. }
  122. internal bool GetAny()
  123. {
  124. try
  125. {
  126. return this.BaseRepository("CollegeMIS").FindList<StuInfoBasicEntity>().ToList().Count > 0 ? true : false;
  127. }
  128. catch (Exception ex)
  129. {
  130. if (ex is ExceptionEx)
  131. {
  132. throw;
  133. }
  134. else
  135. {
  136. throw ExceptionEx.ThrowServiceException(ex);
  137. }
  138. }
  139. }
  140. internal StuInfoBasicEntity GetStuInfoBasicEntityByStuNo(string enCode)
  141. {
  142. try
  143. {
  144. var data = this.BaseRepository("CollegeMIS").FindEntity<StuInfoBasicEntity>(a => a.StuNo == enCode);
  145. if (data != null && (data.Photo != null && data.Photo != ""))
  146. {
  147. var url = this.BaseRepository().FindEntity<AnnexesFileEntity>(a => a.F_FolderId == data.Photo)?.F_FilePath;
  148. if (!string.IsNullOrEmpty(url))
  149. {
  150. url = "/" + url.Substring(url.IndexOf("Resource"));
  151. data.Photo = url;
  152. }
  153. }
  154. return data;
  155. }
  156. catch (Exception ex)
  157. {
  158. if (ex is ExceptionEx)
  159. {
  160. throw;
  161. }
  162. else
  163. {
  164. throw ExceptionEx.ThrowServiceException(ex);
  165. }
  166. }
  167. }
  168. public string GetPhotoByStuNo(string enCode)
  169. {
  170. try
  171. {
  172. var data = this.BaseRepository("CollegeMIS").FindEntity<StuInfoBasicEntity>(a => a.StuNo == enCode);
  173. if (data != null)
  174. {
  175. return data.Photo;
  176. }
  177. return "";
  178. }
  179. catch (Exception ex)
  180. {
  181. if (ex is ExceptionEx)
  182. {
  183. throw;
  184. }
  185. else
  186. {
  187. throw ExceptionEx.ThrowServiceException(ex);
  188. }
  189. }
  190. }
  191. public StuInfoBasicEntity GetStuInfoBasicEntityByStuName(string name)
  192. {
  193. try
  194. {
  195. return this.BaseRepository("CollegeMIS").FindEntity<StuInfoBasicEntity>(a => a.StuName == name);
  196. }
  197. catch (Exception ex)
  198. {
  199. if (ex is ExceptionEx)
  200. {
  201. throw;
  202. }
  203. else
  204. {
  205. throw ExceptionEx.ThrowServiceException(ex);
  206. }
  207. }
  208. }
  209. /// <summary>
  210. /// 获取StuInfoBasic表实体数据
  211. /// <param name="keyValue">主键</param>
  212. /// <summary>
  213. /// <returns></returns>
  214. public StuInfoBasicEntity GetStuInfoBasicEntity(string keyValue)
  215. {
  216. try
  217. {
  218. return this.BaseRepository("CollegeMIS").FindEntity<StuInfoBasicEntity>(keyValue);
  219. }
  220. catch (Exception ex)
  221. {
  222. if (ex is ExceptionEx)
  223. {
  224. throw;
  225. }
  226. else
  227. {
  228. throw ExceptionEx.ThrowServiceException(ex);
  229. }
  230. }
  231. }
  232. /// <summary>
  233. /// 获取准许毕业的学生的专业
  234. /// <summary>
  235. /// <returns></returns>
  236. public List<CdMajorEntity> GetMajorInfoWithGraduation()
  237. {
  238. try
  239. {
  240. var stuInfo = this.BaseRepository("CollegeMIS")
  241. .FindList<StuInfoBasicEntity>(a => a.FinishSchoolMark == "1").ToList();
  242. var majorNoList = stuInfo.GroupBy(a => a.MajorNo).Select(a => a.Key).ToList();
  243. var majorList = this.BaseRepository("CollegeMIS")
  244. .FindList<CdMajorEntity>(a => majorNoList.Contains(a.MajorNo)).ToList();
  245. return majorList;
  246. }
  247. catch (Exception ex)
  248. {
  249. if (ex is ExceptionEx)
  250. {
  251. throw;
  252. }
  253. else
  254. {
  255. throw ExceptionEx.ThrowServiceException(ex);
  256. }
  257. }
  258. }
  259. /// <summary>
  260. /// 获取StuInfoBasic表实体数据
  261. /// <param name="keyValue">主键</param>
  262. /// <summary>
  263. /// <returns></returns>
  264. public void CreateGraduateNoByMajor(string CityCode, string SchoolCode, string MajorList)
  265. {
  266. try
  267. {
  268. var year = DateTime.Now.Year.ToString().Substring(2, 2);
  269. var firstStr = year + CityCode + SchoolCode;
  270. //获取最大的序号
  271. var DiplomaNoList = this.BaseRepository("CollegeMIS")
  272. .FindList<StuInfoBasicEntity>(a => a.DiplomaNo.Contains(firstStr)).Select(a => a.DiplomaNo.Substring(a.DiplomaNo.Length - 4, 4).ToInt()).ToList();
  273. var orderNo = 1;
  274. if (DiplomaNoList.Count() > 0)
  275. {
  276. var MaxDiplomaNo = DiplomaNoList.Max(a => a);
  277. orderNo = MaxDiplomaNo + 1;
  278. }
  279. var ListMajorNo = MajorList.Split(',').ToList();
  280. foreach (var MajorNo in ListMajorNo)
  281. {
  282. var stuList = this.BaseRepository("CollegeMIS")
  283. .FindList<StuInfoBasicEntity>(a => a.MajorNo == MajorNo)
  284. .Where(a => a.DiplomaNo == null || a.DiplomaNo == "");
  285. if (stuList.Count() > 0)
  286. {
  287. foreach (var stuInfo in stuList)
  288. {
  289. stuInfo.DiplomaNo = firstStr + orderNo.ToString().PadLeft(4, '0');
  290. this.BaseRepository("CollegeMIS").Update(stuInfo);
  291. orderNo++;
  292. }
  293. }
  294. }
  295. }
  296. catch (Exception ex)
  297. {
  298. if (ex is ExceptionEx)
  299. {
  300. throw;
  301. }
  302. else
  303. {
  304. throw ExceptionEx.ThrowServiceException(ex);
  305. }
  306. }
  307. }
  308. /// <summary>
  309. /// 获取StuInfoBasic表实体数据
  310. /// <param name="keyValue">主键</param>
  311. /// <summary>
  312. /// <returns></returns>
  313. public StuInfoBasicEntity GetStuNoByAccount(string keyValue)
  314. {
  315. try
  316. {
  317. return this.BaseRepository("CollegeMIS").FindEntity<StuInfoBasicEntity>(a => a.StuNo == keyValue);
  318. }
  319. catch (Exception ex)
  320. {
  321. if (ex is ExceptionEx)
  322. {
  323. throw;
  324. }
  325. else
  326. {
  327. throw ExceptionEx.ThrowServiceException(ex);
  328. }
  329. }
  330. }
  331. /// <summary>
  332. /// 获取树形数据
  333. /// </summary>
  334. /// <returns></returns>
  335. public DataTable GetSqlTree()
  336. {
  337. try
  338. {
  339. var ClassDiredctorNo = LoginUserInfo.Get().account;
  340. return this.BaseRepository("CollegeMIS").FindTable($" SELECT * FROM dbo.ClassInfo where ClassDiredctorNo='{ClassDiredctorNo}' or ClassTutorNo='{ClassDiredctorNo}'");
  341. }
  342. catch (Exception ex)
  343. {
  344. if (ex is ExceptionEx)
  345. {
  346. throw;
  347. }
  348. else
  349. {
  350. throw ExceptionEx.ThrowServiceException(ex);
  351. }
  352. }
  353. }
  354. #endregion
  355. #region 提交数据
  356. /// <summary>
  357. /// 审核全部
  358. /// </summary>
  359. public void CheckAll()
  360. {
  361. try
  362. {
  363. this.BaseRepository("CollegeMIS").ExecuteBySql("update StuInfoBasic set CheckMark=1");
  364. }
  365. catch (Exception ex)
  366. {
  367. if (ex is ExceptionEx)
  368. {
  369. throw;
  370. }
  371. else
  372. {
  373. throw ExceptionEx.ThrowServiceException(ex);
  374. }
  375. }
  376. }
  377. /// <summary>
  378. /// 准许毕业操作
  379. /// </summary>
  380. public void AllowGraduate(string stuNo, string status)
  381. {
  382. try
  383. {
  384. var list = stuNo.Split(',').ToList().Select(a => "'" + a + "'");
  385. var stulist = string.Join(",", list);
  386. this.BaseRepository("CollegeMIS").ExecuteBySql($"UPDATE dbo.StuInfoBasic SET FinishSchoolMark ='{status}' WHERE StuNo in({stulist})");
  387. }
  388. catch (Exception ex)
  389. {
  390. if (ex is ExceptionEx)
  391. {
  392. throw;
  393. }
  394. else
  395. {
  396. throw ExceptionEx.ThrowServiceException(ex);
  397. }
  398. }
  399. }
  400. public void SynPhoto()
  401. {
  402. //var logpath = @"D:\新版数字化校园\Publish\log\0913.txt";
  403. try
  404. {
  405. var stuList = this.BaseRepository("CollegeMIS").FindList<StuInfoBasicEntity>(x => x.Grade == "21")
  406. .ToList();
  407. var url = AppDomain.CurrentDomain.BaseDirectory;
  408. //System.IO.File.AppendAllText(logpath, "同步照片\r\n");
  409. var num = 0;
  410. foreach (var stuInfo in stuList)
  411. {
  412. var F_FileName = stuInfo.ksh + ".jpg";
  413. var F_FilePath = $"{url}/Resource/UserPhoto/KSZP/{F_FileName}";
  414. //判断文件是否存在
  415. if (System.IO.File.Exists(F_FilePath))
  416. {
  417. //照片不为空
  418. if (!string.IsNullOrEmpty(stuInfo.Photo))
  419. {
  420. var annex = this.BaseRepository()
  421. .FindEntity<AnnexesFileEntity>(a => a.F_FolderId == stuInfo.Photo);
  422. if (annex == null)
  423. {
  424. var annexEntity = new AnnexesFileEntity()
  425. {
  426. F_Id = Guid.NewGuid().ToString(),
  427. F_FileName = F_FileName,
  428. F_FilePath = F_FilePath,
  429. F_FolderId = stuInfo.Photo
  430. };
  431. this.BaseRepository().Insert(annexEntity);
  432. }
  433. else
  434. {
  435. annex.F_FileName = F_FileName;
  436. annex.F_FilePath = F_FilePath;
  437. this.BaseRepository().Update(annex);
  438. }
  439. }
  440. else
  441. {
  442. stuInfo.Photo = Guid.NewGuid().ToString();
  443. var annexEntity = new AnnexesFileEntity()
  444. {
  445. F_Id = Guid.NewGuid().ToString(),
  446. F_FileName = F_FileName,
  447. F_FilePath = F_FilePath,
  448. F_FolderId = stuInfo.Photo
  449. };
  450. annexEntity.Create();
  451. this.BaseRepository("CollegeMIS").Update(stuInfo);
  452. this.BaseRepository().Insert(annexEntity);
  453. }
  454. //num++;
  455. }
  456. else
  457. {
  458. //System.IO.File.AppendAllText(logpath, F_FilePath + "学生:" + stuInfo.StuName + "文件不存在" + "\r\n");
  459. }
  460. }
  461. //System.IO.File.AppendAllText(logpath, "同步照片:" + num + "个学生\r\n");
  462. }
  463. catch (Exception ex)
  464. {
  465. if (ex is ExceptionEx)
  466. {
  467. throw;
  468. }
  469. else
  470. {
  471. throw ExceptionEx.ThrowServiceException(ex);
  472. }
  473. }
  474. }
  475. /// <summary>
  476. /// 删除实体数据
  477. /// <param name="keyValue">主键</param>
  478. /// <summary>
  479. /// <returns></returns>
  480. public void DeleteEntity(string keyValue)
  481. {
  482. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  483. try
  484. {
  485. //单个删除
  486. //this.BaseRepository("CollegeMIS").Delete<StuInfoBasicEntity>(t => t.StuId == keyValue);
  487. //多个删除
  488. var keyValueArr = keyValue.Split(',');
  489. foreach (var item in keyValueArr)
  490. {
  491. db.Delete<StuInfoBasicEntity>(t => t.StuId == item);
  492. }
  493. db.Commit();
  494. }
  495. catch (Exception ex)
  496. {
  497. db.Rollback();
  498. if (ex is ExceptionEx)
  499. {
  500. throw;
  501. }
  502. else
  503. {
  504. throw ExceptionEx.ThrowServiceException(ex);
  505. }
  506. }
  507. }
  508. /// <summary>
  509. /// 领取毕业证
  510. /// <param name="keyValue">主键</param>
  511. /// <summary>
  512. /// <returns></returns>
  513. public void GetCard(string keyValue)
  514. {
  515. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  516. try
  517. {
  518. var keyValueArr = keyValue.Split(',');
  519. foreach (var item in keyValueArr)
  520. {
  521. var sql = $"UPDATE dbo.StuInfoBasic SET FinishSchoolMark='2',FinishSchoolDate=GETDATE() WHERE StuId='{item}'";
  522. db.ExecuteBySql(sql);
  523. }
  524. db.Commit();
  525. }
  526. catch (Exception ex)
  527. {
  528. db.Rollback();
  529. if (ex is ExceptionEx)
  530. {
  531. throw;
  532. }
  533. else
  534. {
  535. throw ExceptionEx.ThrowServiceException(ex);
  536. }
  537. }
  538. }
  539. /// <summary>
  540. /// 毕业生归档
  541. /// <summary>
  542. /// <returns></returns>
  543. public void StuStore()
  544. {
  545. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  546. var adb = this.BaseRepository().BeginTrans();
  547. try
  548. {
  549. //归档前提为已经领取毕业证的学生
  550. var stuInfos = db
  551. .FindList<StuInfoBasicEntity>(a => a.FinishSchoolMark == "2");
  552. foreach (var item in stuInfos)
  553. {
  554. var StuInfoType = typeof(StuInfoBasicEntity);
  555. var PropertyInfoStuInfo = StuInfoType.GetProperties();
  556. var GraduateEntity = new StuInfoGraduateEntity();
  557. var typegraduate = typeof(StuInfoGraduateEntity);
  558. var PropertyInfoGraduate = typegraduate.GetProperties();
  559. foreach (var itemStuInfo in PropertyInfoStuInfo)
  560. {
  561. var objStuInfoType = itemStuInfo.GetValue(StuInfoType);
  562. foreach (var itemGraduate in PropertyInfoGraduate)
  563. {
  564. if (itemGraduate.Name == itemStuInfo.Name)
  565. {
  566. itemGraduate.SetValue(GraduateEntity, objStuInfoType, null);
  567. }
  568. }
  569. }
  570. var accountInfo = adb.FindEntity<UserEntity>(a => a.F_Account == item.StuNo);
  571. if (accountInfo != null)
  572. {
  573. //删除账户
  574. adb.Delete(accountInfo);
  575. }
  576. //清空宿舍信息
  577. var dormitory = db
  578. .FindEntity<Acc_DormitoryBuildEntity>(a => a.StudentID == item.StuId);
  579. if (dormitory != null)
  580. {
  581. dormitory.StudentID = "";
  582. dormitory.StuName = "";
  583. db.Update(dormitory);
  584. }
  585. db.Delete(item);
  586. db.Insert(GraduateEntity);
  587. }
  588. }
  589. catch (Exception ex)
  590. {
  591. db.Rollback();
  592. adb.Rollback();
  593. if (ex is ExceptionEx)
  594. {
  595. throw;
  596. }
  597. else
  598. {
  599. throw ExceptionEx.ThrowServiceException(ex);
  600. }
  601. }
  602. }
  603. /// <summary>
  604. /// 保存实体数据(新增、修改)
  605. /// <param name="keyValue">主键</param>
  606. /// <summary>
  607. /// <returns></returns>
  608. public void SaveEntity(string keyValue, StuInfoBasicEntity entity)
  609. {
  610. try
  611. {
  612. UserIBLL userIBLL = new UserBLL();
  613. if (!string.IsNullOrEmpty(keyValue))
  614. {
  615. entity.Modify(keyValue);
  616. var oldEntity = this.BaseRepository("CollegeMIS").FindEntity<StuInfoBasicEntity>(keyValue);
  617. List<StuInfoBasic_ChangeLogEntity> list = new List<StuInfoBasic_ChangeLogEntity>();
  618. var loginUser = LoginUserInfo.Get();
  619. var tableInfos = this.BaseRepository("CollegeMIS").FindTable(@"SELECT t.[name] AS 表名,c.[name] AS 字段名,cast(ep.[value]
  620. as varchar(100)) AS [字段说明]
  621. FROM sys.tables AS t
  622. INNER JOIN sys.columns
  623. AS c ON t.object_id = c.object_id
  624. LEFT JOIN sys.extended_properties AS ep
  625. ON ep.major_id = c.object_id AND ep.minor_id = c.column_id WHERE ep.class =1
  626. AND t.name='StuInfoBasic'");
  627. PropertyInfo[] properties = oldEntity.GetType().GetProperties();
  628. foreach (System.Reflection.PropertyInfo item in properties)
  629. {
  630. string name = item.Name;
  631. object oldValue = item.GetValue(oldEntity);
  632. object newValue = item.GetValue(entity);
  633. if (oldValue == null || newValue == null)
  634. {
  635. continue;
  636. }
  637. if (!oldValue.Equals(newValue))
  638. {
  639. var columnName = "";
  640. foreach (DataRow rows in tableInfos.Rows)
  641. {
  642. if (rows["字段名"].ToString() == item.Name)
  643. {
  644. columnName = rows["字段说明"].ToString();
  645. }
  646. }
  647. var changeEntity = new StuInfoBasic_ChangeLogEntity
  648. {
  649. StuID = keyValue,
  650. BeforeChange = oldValue.ToString(),
  651. AfterChange = newValue.ToString(),
  652. FieldName = columnName,
  653. UpdateBy = loginUser.userId,
  654. UpdateTime = DateTime.Now
  655. };
  656. changeEntity.Create();
  657. list.Add(changeEntity);
  658. }
  659. }
  660. if (list.Count > 0)
  661. {
  662. this.BaseRepository("CollegeMIS").Insert(list);
  663. }
  664. var annexesFileEntity = this.BaseRepository().FindEntity<AnnexesFileEntity>(a => a.F_FolderId == entity.Photo);
  665. var url = "";
  666. if (annexesFileEntity != null)
  667. {
  668. url = annexesFileEntity.F_FilePath;
  669. url = "/" + url.Substring(url.IndexOf("Resource"), url.Length - url.IndexOf("Resource"));
  670. }
  671. var baseUser = userIBLL.GetEntityByAccount(entity.StuNo);
  672. if (baseUser != null)
  673. {
  674. baseUser.F_HeadIcon = url;
  675. userIBLL.SaveEntity(baseUser.F_UserId, baseUser);
  676. }
  677. this.BaseRepository("CollegeMIS").Update(entity);
  678. }
  679. else
  680. {
  681. entity.Create();
  682. this.BaseRepository("CollegeMIS").Insert(entity);
  683. }
  684. }
  685. catch (Exception ex)
  686. {
  687. if (ex is ExceptionEx)
  688. {
  689. throw;
  690. }
  691. else
  692. {
  693. throw ExceptionEx.ThrowServiceException(ex);
  694. }
  695. }
  696. }
  697. #endregion
  698. public class TableInfo
  699. {
  700. public string TableName { get; set; }
  701. public string ColumnName { get; set; }
  702. public string ColumnDescription { get; set; }
  703. }
  704. public void GenerateAccout()
  705. {
  706. UserRelationIBLL userRelationIBLL = new UserRelationBLL();
  707. UserIBLL userIBLL = new UserBLL();
  708. try
  709. {
  710. var stuInfoBasicEntities = BaseRepository("CollegeMIS").FindList<StuInfoBasicEntity>(m => m.CheckMark != "0");
  711. var alluserlist = userIBLL.GetAllList().Where(m => m.F_Description == "学生");
  712. var roleId = Config.GetValue("GenerateStudentsRoleId");
  713. var studentList = new List<UserEntity>();
  714. foreach (var tEntity in stuInfoBasicEntities)
  715. {
  716. if (alluserlist.Count(m => m.F_Account == tEntity.StuNo) > 0)
  717. {
  718. continue;
  719. }
  720. var annexesFileEntity = this.BaseRepository().FindEntity<AnnexesFileEntity>(a => a.F_FolderId == tEntity.Photo);
  721. var url = "";
  722. if (annexesFileEntity != null)
  723. {
  724. url = annexesFileEntity.F_FilePath;
  725. url = "/" + url.Substring(url.IndexOf("Resource"));
  726. }
  727. UserEntity userbase = new UserEntity();
  728. userbase.F_Account = tEntity.StuNo;
  729. userbase.F_RealName = tEntity.StuName;
  730. userbase.F_EnCode = tEntity.StuNo;
  731. userbase.F_Password = Md5Helper.Encrypt(Config.GetValue("defaultpwd"), 32).ToLower();
  732. userbase.F_HeadIcon = string.IsNullOrEmpty(url) ? Config.GetValue("defaultheadimg") : url;
  733. userbase.F_Gender = tEntity.GenderNo.HasValue ? Convert.ToInt32(tEntity.GenderNo.Value) : 1;
  734. userbase.F_DeleteMark = 0;
  735. userbase.F_EnabledMark = 1;
  736. userbase.F_Mobile = tEntity.mobile;
  737. userbase.F_Description = "学生";
  738. userbase.F_CompanyId = tEntity.F_SchoolId;
  739. userbase.F_DepartmentId = tEntity.DeptNo;
  740. userbase.F_IdentityCardNo = tEntity.IdentityCardNo;
  741. userIBLL.SaveEntity(null, userbase);
  742. studentList.Add(userbase);
  743. }
  744. if (studentList.Any())
  745. {
  746. string s = studentList.Select(m => m.F_UserId).Aggregate((current, userEntity) => current + "," + userEntity);
  747. userRelationIBLL.SaveEntityList2(roleId, 1, s);
  748. }
  749. }
  750. catch (Exception ex)
  751. {
  752. if (ex is ExceptionEx)
  753. {
  754. throw;
  755. }
  756. else
  757. {
  758. throw ExceptionEx.ThrowServiceException(ex);
  759. }
  760. }
  761. }
  762. public void UpdateAccount()
  763. {
  764. try
  765. {
  766. UserIBLL userIBLL = new UserBLL();
  767. var teacherList = this.BaseRepository("CollegeMIS").FindList<StuInfoBasicEntity>();
  768. var baseTeacherList = userIBLL.GetAllList().Where(m => m.F_Description == "学生");
  769. foreach (var baseTeacher in baseTeacherList)
  770. {
  771. var num = 0;
  772. var teacher = teacherList.FirstOrDefault(a => a.StuNo == baseTeacher.F_Account);
  773. if (teacher != null)
  774. {
  775. if (baseTeacher.F_RealName != teacher.StuName)
  776. {
  777. baseTeacher.F_RealName = teacher.StuName;
  778. num++;
  779. }
  780. if (baseTeacher.F_Gender != Convert.ToInt32(teacher.GenderNo))
  781. {
  782. baseTeacher.F_Gender = Convert.ToInt32(teacher.GenderNo);
  783. num++;
  784. }
  785. if (baseTeacher.F_Mobile != teacher.mobile)
  786. {
  787. baseTeacher.F_Mobile = teacher.mobile;
  788. num++;
  789. }
  790. if (baseTeacher.F_CompanyId != teacher.F_SchoolId)
  791. {
  792. baseTeacher.F_CompanyId = teacher.F_SchoolId;
  793. num++;
  794. }
  795. if (baseTeacher.F_DepartmentId != teacher.DeptNo)
  796. {
  797. baseTeacher.F_DepartmentId = teacher.DeptNo;
  798. num++;
  799. }
  800. if (baseTeacher.F_IdentityCardNo != teacher.IdentityCardNo)
  801. {
  802. baseTeacher.F_IdentityCardNo = teacher.IdentityCardNo;
  803. num++;
  804. }
  805. if (num > 0)
  806. {
  807. userIBLL.UpdateEntity(baseTeacher);
  808. }
  809. }
  810. }
  811. }
  812. catch (Exception ex)
  813. {
  814. if (ex is ExceptionEx)
  815. {
  816. throw;
  817. }
  818. else
  819. {
  820. throw ExceptionEx.ThrowServiceException(ex);
  821. }
  822. }
  823. }
  824. public IEnumerable<StuInfoBasicEntity> GetAllList()
  825. {
  826. try
  827. {
  828. return this.BaseRepository("CollegeMIS").FindList<StuInfoBasicEntity>(m => m.CheckMark == "1");
  829. }
  830. catch (Exception ex)
  831. {
  832. if (ex is ExceptionEx)
  833. {
  834. throw;
  835. }
  836. else
  837. {
  838. throw ExceptionEx.ThrowServiceException(ex);
  839. }
  840. }
  841. }
  842. public IEnumerable<StuInfoBasicEntity> GetStuInfoByClassNo(string classNo)
  843. {
  844. try
  845. {
  846. return this.BaseRepository("CollegeMIS").FindList<StuInfoBasicEntity>(m => m.CheckMark == "1" && m.ClassNo == classNo);
  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. public void SyncDept()
  861. {
  862. try
  863. {
  864. var data = this.BaseRepository("CollegeMIS").FindList<StuInfoBasicEntity>().ToList();
  865. var majorList = this.BaseRepository("CollegeMIS").FindList<CdMajorEntity>().ToList();
  866. foreach (var item in data)
  867. {
  868. var deptNo = majorList.FirstOrDefault(a => a.MajorNo == item.MajorNo)?.DeptNo;
  869. item.DeptNo = deptNo;
  870. this.BaseRepository("CollegeMIS").Update(item);
  871. }
  872. }
  873. catch (Exception ex)
  874. {
  875. if (ex is ExceptionEx)
  876. {
  877. throw;
  878. }
  879. else
  880. {
  881. throw ExceptionEx.ThrowServiceException(ex);
  882. }
  883. }
  884. }
  885. public void SyncMajor()
  886. {
  887. try
  888. {
  889. var data = this.BaseRepository("CollegeMIS").FindList<StuInfoBasicEntity>().ToList();
  890. var classList = this.BaseRepository("CollegeMIS").FindList<ClassInfoEntity>().ToList();
  891. foreach (var item in data)
  892. {
  893. var majorNo = classList.FirstOrDefault(a => a.ClassNo == item.ClassNo)?.MajorNo;
  894. item.MajorNo = majorNo;
  895. this.BaseRepository("CollegeMIS").Update(item);
  896. }
  897. }
  898. catch (Exception ex)
  899. {
  900. if (ex is ExceptionEx)
  901. {
  902. throw;
  903. }
  904. else
  905. {
  906. throw ExceptionEx.ThrowServiceException(ex);
  907. }
  908. }
  909. }
  910. }
  911. }