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.
 
 
 
 
 
 

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