JuniorSpecialtyStudentCountServices.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.Common.Students.HighBaseTable;
  6. using EMIS.DataLogic.SystemSetting;
  7. using EMIS.DataLogic.Common.CalendarManage;
  8. using EMIS.ViewModel;
  9. using EMIS.Entities;
  10. using System.Transactions;
  11. namespace EMIS.CommonLogic.Students.HighBaseTable
  12. {
  13. public class JuniorSpecialtyStudentCountServices : BaseServices, IJuniorSpecialtyStudentCountServices
  14. {
  15. public DictionaryItemDAL DictionaryItemDAL { get; set; }
  16. public SchoolYearDAL SchoolYearDAL { get; set; }
  17. public JuniorSpecialtyStudentCountDAL JuniorSpecialtyStudentCountDAL { get; set; }
  18. public void Update()
  19. {
  20. try
  21. {
  22. var query = JuniorSpecialtyStudentCountDAL.GetStudent().OrderBy(x => x.LearningformID).ToList();
  23. //var specialty = query.Select(x => x.SpecialtyID).Distinct().ToList();
  24. //var learningform = query.Select(x => x.LearningformID).Distinct().ToList();
  25. var sex = DictionaryItemDAL.GetDictionaryItemViewQueryable(x => x.DictionaryCode == typeof(CF_Sex).Name).Select(x => x.Value).ToList();
  26. var schoolYear = SchoolYearDAL.GetSchoolYearQueryable(x => x.IsCurrent).FirstOrDefault().Years;
  27. //在校生数
  28. var queryInschool = JuniorSpecialtyStudentCountDAL.GetInschoolCount(schoolYear).ToList();
  29. //招生数
  30. var queryRecruit = JuniorSpecialtyStudentCountDAL.GetRecruitCount(schoolYear).ToList();
  31. //春季招生数,普教需要
  32. var querySpringRecruit = JuniorSpecialtyStudentCountDAL.SpringRecruitCount(schoolYear).ToList();
  33. //预计毕业生数
  34. var queryPlanGraduation = JuniorSpecialtyStudentCountDAL.PlanGraduationCount(schoolYear).ToList();
  35. //毕业生数
  36. var queryGraduated = JuniorSpecialtyStudentCountDAL.GetGraduationCount(schoolYear).ToList();
  37. //应届毕业生数
  38. var queryGraduating = JuniorSpecialtyStudentCountDAL.GetGraduatingCount(schoolYear).ToList();
  39. List<HB_JuniorSpecialtyStudentCount> SpecialtyStudentCountList = new List<HB_JuniorSpecialtyStudentCount>();
  40. List<HB_JuniorSpecialtyStudentCountDetail> SpecialtyStudentCountDetailList = new List<HB_JuniorSpecialtyStudentCountDetail>();
  41. foreach (var i in query)
  42. {
  43. foreach (var j in sex)
  44. {
  45. HB_JuniorSpecialtyStudentCount SpecialtyStudentCount = new HB_JuniorSpecialtyStudentCount();
  46. SpecialtyStudentCount.JuniorSpecialtyStudentCountID = Guid.NewGuid();
  47. SpecialtyStudentCount.Year = schoolYear;
  48. SpecialtyStudentCount.Sex = j;
  49. SpecialtyStudentCount.EducationTypeID = (int)EMIS.ViewModel.CF_EducationType.Special;
  50. SpecialtyStudentCount.LearningformID = i.LearningformID;
  51. SpecialtyStudentCount.StandardID = i.StandardID;
  52. SpecialtyStudentCount.LearnSystem = i.LearnSystem;
  53. SpecialtyStudentCount.IsTeacherIdentification = string.IsNullOrEmpty(i.IsTeacherIdentification) ? false : true;
  54. //毕业生数
  55. SpecialtyStudentCount.GraduationCount = queryGraduated.Where(x => x.LearningformID == i.LearningformID && x.Sex == j
  56. && x.StandardID == i.StandardID && x.LearnSystem == i.LearnSystem).Select(x => x.GraduationCount).FirstOrDefault();
  57. //招生数
  58. SpecialtyStudentCount.RecruitCount = queryRecruit.Where(x => x.LearningformID == i.LearningformID && x.Sex == j
  59. && x.StandardID == i.StandardID && x.LearnSystem == i.LearnSystem).Select(x => x.RecruitCount).FirstOrDefault();
  60. //预计毕业生数
  61. SpecialtyStudentCount.PlanGraduationCount = queryPlanGraduation.Where(x => x.LearningformID == i.LearningformID && x.Sex == j
  62. && x.StandardID == i.StandardID && x.LearnSystem == i.LearnSystem).Select(x => x.PlanGraduationCount).FirstOrDefault();
  63. //春季招生数
  64. SpecialtyStudentCount.SpringRecruitCount = querySpringRecruit.Where(x => x.LearningformID == i.LearningformID && x.Sex == j
  65. && x.StandardID == i.StandardID && x.LearnSystem == i.LearnSystem).Select(x => x.SpringRecruitCount).FirstOrDefault();
  66. //应届毕业生数
  67. SpecialtyStudentCount.GraduatingCount = queryGraduating.Where(x => x.LearningformID == i.LearningformID && x.Sex == j
  68. && x.StandardID == i.StandardID && x.LearnSystem == i.LearnSystem).Select(x => x.GraduatingCount).FirstOrDefault();
  69. SetNewStatus(SpecialtyStudentCount);
  70. SpecialtyStudentCountList.Add(SpecialtyStudentCount);
  71. var list = queryInschool.Where(x => x.LearningformID == i.LearningformID && x.Sex == j
  72. && x.StandardID == i.StandardID && x.LearnSystem == i.LearnSystem).OrderBy(x => x.StandardID).ThenBy(x => x.LearningformID).ThenBy(x => x.LearnSystem).ToList();
  73. foreach (var k in list)
  74. {
  75. HB_JuniorSpecialtyStudentCountDetail SpecialtyStudentCountDetail = new HB_JuniorSpecialtyStudentCountDetail();
  76. SpecialtyStudentCountDetail.JuniorSpecialtyStudentCountDetailID = Guid.NewGuid();
  77. SpecialtyStudentCountDetail.JuniorSpecialtyStudentCountID = SpecialtyStudentCount.JuniorSpecialtyStudentCountID;
  78. SpecialtyStudentCountDetail.SchoolyearNumID = k.SchoolyearNumID;
  79. SpecialtyStudentCountDetail.InschoolCount = k.InschoolCount;
  80. SetNewStatus(SpecialtyStudentCountDetail);
  81. SpecialtyStudentCountDetailList.Add(SpecialtyStudentCountDetail);
  82. }
  83. }
  84. }
  85. using (TransactionScope ts = new TransactionScope())
  86. {
  87. UnitOfWork.Delete<HB_JuniorSpecialtyStudentCountDetail>(x => x.HB_JuniorSpecialtyStudentCount.Year == schoolYear);
  88. UnitOfWork.Delete<HB_JuniorSpecialtyStudentCount>(x => x.Year == schoolYear);
  89. UnitOfWork.BulkInsert(SpecialtyStudentCountList);//统一写入
  90. UnitOfWork.BulkInsert(SpecialtyStudentCountDetailList);//统一写入
  91. ts.Complete();
  92. }
  93. }
  94. catch (Exception ex)
  95. {
  96. throw new Exception(ex.Message);
  97. }
  98. }
  99. //public List<string> SchoolYearDropDownList()
  100. //{
  101. // var item = RecruitStatusDAL.RecruitStatusRepository.Entities.Select(x => x.Year.ToString()).Distinct().ToList();
  102. // return item;
  103. //}
  104. }
  105. }