FacultySynchServices.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Transactions;
  6. using EMIS.CommonLogic.Specialtyclass;
  7. using EMIS.CommonLogic.SystemServices;
  8. using EMIS.CommonLogic.SystemSetting;
  9. using EMIS.DataLogic.DataCenterSynch;
  10. using EMIS.DataLogic.SystemSetting;
  11. using EMIS.Entities;
  12. using EMIS.ViewModel;
  13. namespace EMIS.CommonLogic.DataCenterSynch
  14. {
  15. public class FacultySynchServices : FacultymajorServices, IFacultySynchServices
  16. {
  17. public Lazy<IParameterServices> ParameterServices { get; set; }
  18. public DictionaryItemDAL DictionaryItemDAL { get; set; }
  19. public FacultySynchDAL FacultySynchDAL { get; set; }
  20. public void Synchr()
  21. {
  22. var lastSynchTime = ParameterServices.Value.GetParameterValue<DateTime>(CF_ParameterType.SynchFacultyLastTime);
  23. var nowTime = DateTime.Now;
  24. var allFacultyList = FacultySynchDAL.XXBZ_JWXT_ZYXX_VIEWRepository.GetList(x => x.TIMESTAMPS >= lastSynchTime || lastSynchTime == null).ToList();
  25. var allFacultyCodeList = allFacultyList.Select(x => x.USER_DM.Trim()).Distinct().ToList();
  26. var allCollegeNoList = allFacultyList.Select(x => x.SSYXB_USERDM.Trim()).Distinct().ToList();
  27. var dbFacultyList = this.FacultymajorDAL.FacultymajorRepository.GetList(x => allFacultyCodeList.Contains(x.Code)).ToList();
  28. var dbCollegeList = this.FacultymajorDAL.CollegeRepository.GetList(x => allCollegeNoList.Contains(x.No)).ToList();
  29. var standardDictionaryCode = typeof(CF_Standard).Name;
  30. var dbDictionaryList = this.DictionaryItemDAL.DictionaryItemRepository.GetList(x => x.DictionaryCode == standardDictionaryCode && allFacultyCodeList.Contains(x.Code)).ToList();
  31. var insertDictionaryList = (
  32. from all in allFacultyList
  33. from db in dbDictionaryList.Where(x => x.Code == all.USER_DM.Trim()).DefaultIfEmpty()
  34. where db == null
  35. select new Sys_DictionaryItem
  36. {
  37. DictionaryItemID = Guid.NewGuid(),
  38. DictionaryCode = standardDictionaryCode,
  39. Code = all.USER_DM.Trim(),
  40. Name = all.ZWMC.Trim(),
  41. Value = Convert.ToInt32(all.USER_DM.Trim()),
  42. RecordStatus = (int)SYS_STATUS.USABLE,
  43. OrderNo = Convert.ToInt16(all.USER_DM.Trim()),
  44. IsEditable = true
  45. }
  46. ).ToList();
  47. var updateDictionaryList = (
  48. from all in allFacultyList
  49. from db in dbDictionaryList.Where(x => x.Code == all.USER_DM.Trim())
  50. select new Sys_DictionaryItem
  51. {
  52. DictionaryItemID = db.DictionaryItemID,
  53. DictionaryCode = db.DictionaryCode,
  54. Code = all.USER_DM.Trim(),
  55. Name = all.ZWMC.Trim(),
  56. Value = Convert.ToInt32(all.USER_DM.Trim()),
  57. RecordStatus = db.RecordStatus,
  58. OrderNo = Convert.ToInt16(all.USER_DM.Trim()),
  59. IsEditable = db.IsEditable
  60. }
  61. ).ToList();
  62. var allDictionaryList = insertDictionaryList.Concat(updateDictionaryList).ToList();
  63. var insertList = (from all in allFacultyList
  64. from college in dbCollegeList.Where(x => x.No == all.SSYXB_USERDM.Trim())
  65. from dic in allDictionaryList.Where(x => x.Code == all.USER_DM.Trim())
  66. from db in dbFacultyList.Where(x => x.Code == all.USER_DM.Trim()).DefaultIfEmpty()
  67. where db == null
  68. select new CF_Facultymajor
  69. {
  70. FacultymajorID = Guid.NewGuid(),
  71. CollegeID = college.CollegeID,
  72. Code = all.USER_DM.Trim(),
  73. Name = all.ZWMC.Trim(),
  74. Abbreviation = null,
  75. EnglishName = all.YWMC?.Trim(),
  76. StandardID = dic.Value,
  77. RecordStatus = (int)SYS_STATUS.USABLE,
  78. CreateTime = nowTime,
  79. ModifyTime = nowTime
  80. }).ToList();
  81. var updateList = (from all in allFacultyList
  82. from college in dbCollegeList.Where(x => x.No == all.SSYXB_USERDM.Trim())
  83. from dic in allDictionaryList.Where(x => x.Code == all.USER_DM.Trim())
  84. from db in dbFacultyList.Where(x => x.Code == all.USER_DM.Trim())
  85. select new CF_Facultymajor
  86. {
  87. FacultymajorID = db.FacultymajorID,
  88. CollegeID = college.CollegeID,
  89. Code = all.USER_DM.Trim(),
  90. Name = all.ZWMC.Trim(),
  91. Abbreviation = db.Abbreviation,
  92. EnglishName = all.YWMC?.Trim(),
  93. StandardID = dic.Value,
  94. EducationID = db.EducationID,
  95. LearningformID = db.LearningformID,
  96. LearnSystem = db.LearnSystem,
  97. ScienceclassID = db.ScienceclassID,
  98. LearningstyleID = db.LearningstyleID,
  99. LearnPositionID = db.LearnPositionID,
  100. TeacherIdentification = db.TeacherIdentification,
  101. SetTime = db.SetTime,
  102. Remark = db.Remark,
  103. RecordStatus = (int)SYS_STATUS.USABLE,
  104. CreateUserID = db.CreateUserID,
  105. CreateTime = db.CreateTime,
  106. ModifyUserID = db.ModifyUserID,
  107. ModifyTime = nowTime
  108. }).ToList();
  109. using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions { IsolationLevel = IsolationLevel.Serializable }))
  110. {
  111. UnitOfWork.BulkInsert(insertDictionaryList);
  112. UnitOfWork.BatchUpdate(updateDictionaryList);
  113. UnitOfWork.BulkInsert(insertList);
  114. UnitOfWork.BatchUpdate(updateList);
  115. scope.Complete();
  116. }
  117. ParameterServices.Value.SaveTo(CF_ParameterType.SynchFacultyLastTime, nowTime);
  118. }
  119. }
  120. }