CollegeSynchServices.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Transactions;
  6. using EMIS.CommonLogic.AdministrativeOrgan;
  7. using EMIS.CommonLogic.SystemServices;
  8. using EMIS.DataLogic.DataCenterSynch;
  9. using EMIS.Entities;
  10. using EMIS.ViewModel;
  11. namespace EMIS.CommonLogic.DataCenterSynch
  12. {
  13. public class CollegeSynchServices : DepartmentServices, ICollegeSynchServices
  14. {
  15. public Lazy<IParameterServices> ParameterServices { get; set; }
  16. public CollegeSynchDAL CollegeSynchrDAL { get; set; }
  17. public void Synchr()
  18. {
  19. var lastSynchTime = ParameterServices.Value.GetParameterValue<DateTime>(CF_ParameterType.SynchCollegeLastTime);
  20. var nowTime = DateTime.Now;
  21. var allCollegeList = CollegeSynchrDAL.XXBZ_JWXT_YXXX_VIEWRepository.GetList(x => x.TIMESTAMPS >= lastSynchTime || lastSynchTime == null).ToList();
  22. var allCollegeNoList = allCollegeList.Select(x => x.USER_DM.Trim()).Distinct().ToList();
  23. var dbCollegeList = this.DepartmentDAL.CollegeRepository.GetList(x => allCollegeNoList.Contains(x.No), (x => x.CF_CollegeProfile)).ToList();
  24. var dbDepartmentList = this.DepartmentDAL.DepartmentRepository.GetList(x => allCollegeNoList.Contains(x.No), (x => x.CF_DepartmentProfile)).ToList();
  25. var insertCollegeMainList = (from all in allCollegeList
  26. from db in dbCollegeList.Where(x => x.No == all.DM.Trim()).DefaultIfEmpty()
  27. where db == null
  28. select new { College = all, CollegeID = Guid.NewGuid() }).ToList();
  29. var insertCollegeList = insertCollegeMainList.Select(x => new CF_College
  30. {
  31. CollegeID = x.CollegeID,
  32. No = x.College.USER_DM.Trim(),
  33. Name = x.College.ZWMC,
  34. SimpleName = null,
  35. EnglishName = x.College.YWMC,
  36. RecordStatus = (int)SYS_STATUS.USABLE,
  37. CreateTime = nowTime,
  38. ModifyTime = nowTime
  39. }).ToList();
  40. var insertCollegeProfileList = insertCollegeMainList.Select(x => new CF_CollegeProfile
  41. {
  42. CollegeID = x.CollegeID,
  43. UnitCategoryID = (x.College.MENG_FLAG == "0") ? (int?)CF_UnitCategory.College : null,
  44. RecordStatus = (int)SYS_STATUS.USABLE,
  45. CreateTime = nowTime,
  46. ModifyTime = nowTime
  47. }).ToList();
  48. var insertDepartmentMainList = (from all in allCollegeList
  49. from college in dbCollegeList.Where(x => x.No == all.USER_DM.Trim()).DefaultIfEmpty()
  50. from insert in insertCollegeList.Where(x => x.No == all.USER_DM.Trim()).DefaultIfEmpty()
  51. from db in dbDepartmentList.Where(x => x.No == all.USER_DM.Trim()).DefaultIfEmpty()
  52. where db == null
  53. select new { College = all, CollegeID = college == null ? insert.CollegeID : college.CollegeID, DepartmentID = Guid.NewGuid() }).ToList();
  54. var insertDepartmentList = insertDepartmentMainList.Select(x => new CF_Department
  55. {
  56. DepartmentID = x.DepartmentID,
  57. CollegeID = x.CollegeID,
  58. No = x.College.USER_DM.Trim(),
  59. Name = x.College.ZWMC,
  60. SimpleName = null,
  61. EnglishName = x.College.YWMC,
  62. RecordStatus = (int)SYS_STATUS.USABLE,
  63. CreateTime = nowTime,
  64. ModifyTime = nowTime
  65. }).ToList();
  66. var insertDepartmentProfileList = insertDepartmentMainList.Select(x => new CF_DepartmentProfile
  67. {
  68. DepartmentID = x.DepartmentID,
  69. RecordStatus = (int)SYS_STATUS.USABLE,
  70. CreateTime = nowTime,
  71. ModifyTime = nowTime
  72. }).ToList();
  73. var updateMainList = (from all in allCollegeList
  74. from db in dbCollegeList.Where(x => x.No == all.USER_DM.Trim())
  75. select new { College = all, DbCollege = db, DbCollegeProfile = db.CF_CollegeProfile });
  76. var updateCollegeList = updateMainList.Select(x => new CF_College
  77. {
  78. CollegeID = x.DbCollege.CollegeID,
  79. CampusID = x.DbCollege.CampusID,
  80. No = x.DbCollege.No,
  81. Name = x.College.ZWMC,
  82. SimpleName = x.DbCollege.SimpleName,
  83. EnglishName = x.College.YWMC,
  84. Remark = x.DbCollege.Remark,
  85. RecordStatus = x.DbCollege.RecordStatus,
  86. CreateUserID = x.DbCollege.CreateUserID,
  87. CreateTime = x.DbCollege.CreateTime,
  88. ModifyUserID = x.DbCollege.ModifyUserID,
  89. ModifyTime = nowTime
  90. }).ToList();
  91. var updateCollegeProfileList = updateMainList.Select(x => new CF_CollegeProfile
  92. {
  93. CollegeID = x.DbCollegeProfile.CollegeID,
  94. PoliticalManager = x.DbCollegeProfile.PoliticalManager,
  95. AdministrativeManager = x.DbCollegeProfile.AdministrativeManager,
  96. UnitCategoryID = (x.College.MENG_FLAG == "0") ? (int?)CF_UnitCategory.College : null,
  97. CollegeTypeID = x.DbCollegeProfile.CollegeTypeID,
  98. CollegeCategoryID = x.DbCollegeProfile.CollegeCategoryID,
  99. RunByCategoryID = x.DbCollegeProfile.RunByCategoryID,
  100. FoundDate = x.DbCollegeProfile.FoundDate,
  101. Officephone = x.DbCollegeProfile.Officephone,
  102. RecordStatus = x.DbCollegeProfile.RecordStatus,
  103. CreateUserID = x.DbCollegeProfile.CreateUserID,
  104. CreateTime = x.DbCollegeProfile.CreateTime,
  105. ModifyUserID = x.DbCollegeProfile.ModifyUserID,
  106. ModifyTime = nowTime
  107. }).ToList();
  108. var updateDepartmentMainList = (from all in allCollegeList
  109. from college in dbCollegeList.Where(x => x.No == all.USER_DM.Trim()).DefaultIfEmpty()
  110. from insert in insertCollegeList.Where(x => x.No == all.USER_DM.Trim()).DefaultIfEmpty()
  111. from db in dbDepartmentList.Where(x => x.No == all.USER_DM.Trim())
  112. select new { College = all, CollegeID = college == null ? insert.CollegeID : college.CollegeID, DbDepartment = db, DbDepartmentProfile = db.CF_DepartmentProfile });
  113. var updateDepartmentList = updateDepartmentMainList.Select(x => new CF_Department
  114. {
  115. DepartmentID = x.DbDepartment.DepartmentID,
  116. CollegeID = x.CollegeID,
  117. No = x.DbDepartment.No,
  118. Name = x.College.ZWMC,
  119. SimpleName = x.DbDepartment.SimpleName,
  120. EnglishName = x.College.YWMC,
  121. HierarchyID = x.DbDepartment.HierarchyID,
  122. Remark = x.DbDepartment.Remark,
  123. RecordStatus = x.DbDepartment.RecordStatus,
  124. CreateUserID = x.DbDepartment.CreateUserID,
  125. CreateTime = x.DbDepartment.CreateTime,
  126. ModifyUserID = x.DbDepartment.ModifyUserID,
  127. ModifyTime = nowTime
  128. }).ToList();
  129. var updateDepartmentProfileList = updateDepartmentMainList.Select(x => new CF_DepartmentProfile
  130. {
  131. DepartmentID = x.DbDepartmentProfile.DepartmentID,
  132. DirectorID = x.DbDepartmentProfile.DirectorID,
  133. DeputyDirectorID = x.DbDepartmentProfile.DeputyDirectorID,
  134. FoundDate = x.DbDepartmentProfile.FoundDate,
  135. RecordStatus = x.DbDepartmentProfile.RecordStatus,
  136. CreateUserID = x.DbDepartmentProfile.CreateUserID,
  137. CreateTime = x.DbDepartmentProfile.CreateTime,
  138. ModifyUserID = x.DbDepartmentProfile.ModifyUserID,
  139. ModifyTime = nowTime
  140. }).ToList();
  141. using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions { IsolationLevel = IsolationLevel.Serializable }))
  142. {
  143. UnitOfWork.BulkInsert(insertCollegeList);
  144. UnitOfWork.BulkInsert(insertCollegeProfileList);
  145. UnitOfWork.BulkInsert(insertDepartmentList);
  146. UnitOfWork.BulkInsert(insertDepartmentProfileList);
  147. UnitOfWork.BatchUpdate(updateCollegeList);
  148. UnitOfWork.BatchUpdate(updateCollegeProfileList);
  149. UnitOfWork.BatchUpdate(updateDepartmentList);
  150. UnitOfWork.BatchUpdate(updateDepartmentProfileList);
  151. scope.Complete();
  152. }
  153. ParameterServices.Value.SaveTo(CF_ParameterType.SynchCollegeLastTime, nowTime);
  154. }
  155. }
  156. }