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.
 
 
 
 
 
 

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