StudentDistributeDAL.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.Repositories;
  6. using EMIS.ViewModel.TeachingMaterial;
  7. using System.Linq.Expressions;
  8. using EMIS.Entities;
  9. using EMIS.ViewModel;
  10. using EMIS.ViewModel.Students;
  11. using Bowin.Common.Linq;
  12. using EMIS.DataLogic.Common.Studentsetting;
  13. using EMIS.DataLogic.Common.Students;
  14. namespace EMIS.DataLogic.Common.TeachingMaterial
  15. {
  16. public class StudentDistributeDAL
  17. {
  18. #region --0.0 定义--
  19. public StudentDistributeRepository StudentDistributeRepository { get; set; }
  20. public TeachingMaterialPoolRepository TeachingMaterialPoolRepository { get; set; }
  21. public SchoolyearRepository SchoolyearRepository { get; set; }
  22. public UserRepository UserRepository { get; set; }
  23. public CoursematerialRepository CoursematerialRepository { get; set; }
  24. public SpecialtyPlanRepository SpecialtyPlanRepository { get; set; }
  25. public CollegeRepository CollegeRepository { get; set; }
  26. public DictionaryItemRepository DictionaryItemRepository { get; set; }
  27. public GrademajorRepository GrademajorRepository { get; set; }
  28. public FacultymajorRepository FacultymajorRepository { get; set; }
  29. public SpecialtyCourseRepository SpecialtyCourseRepository { get; set; }
  30. public ClassmajorRepository ClassmajorRepository { get; set; }
  31. public PublishRepository PublishRepository { get; set; }
  32. public TeachingMateriaInventoryRepository TeachingMateriaInventoryRepository { get; set; }
  33. public StudentRepository StudentRepository { get; set; }
  34. public RecruitstudentsRepository RecruitstudentsRepository { get; set; }
  35. public StudentProfileRepository StudentProfileRepository { get; set; }
  36. public StudentsOrderRepository StudentsOrderRepository { get; set; }
  37. public StaffRepository StaffRepository { get; set; }
  38. public InSchoolSettingRepository inSchoolSettingRepository { get; set; }
  39. #endregion
  40. /// <summary>
  41. /// 获取学生发放信息列表
  42. /// </summary>
  43. /// <param name="exp"></param>
  44. /// <returns></returns>
  45. public IQueryable<StudentDistributeView> GetStudentDistributeGridView(Expression<Func<ET_StudentDistribute, bool>> exporder)
  46. {
  47. var teaquery = from tmi in TeachingMateriaInventoryRepository.Entities
  48. group tmi by tmi.TeachingMaterialPoolID
  49. into t
  50. select new InventoryView
  51. {
  52. TeachingMaterialPoolID = t.Key,
  53. PresentInventory = t.Sum(x => x.PresentInventory),
  54. };
  55. var inSchoolStatusIDList = inSchoolSettingRepository.GetList(x => x.IsSelected == true).Select(w => w.InSchoolStatusID).ToList();//获取选中的在校设定状态、
  56. var view = (from so in StudentDistributeRepository.GetList(exporder)
  57. join u in UserRepository.Entities on so.CreateUserID equals u.UserID
  58. join tmp in TeachingMaterialPoolRepository.Entities on so.TeachingMaterialPoolID equals tmp.TeachingMaterialPoolID into ttmp
  59. from ctmp in ttmp.DefaultIfEmpty()
  60. join kc in teaquery on so.TeachingMaterialPoolID equals kc.TeachingMaterialPoolID into kctmp
  61. from kcmp in kctmp.DefaultIfEmpty()
  62. join fdi in DictionaryItemRepository.Entities on new { so.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.StandardID, DictionaryCode = typeof(CF_Standard).Name }
  63. equals new { StandardID = fdi.Value, fdi.DictionaryCode } into tfdi
  64. from cfdi in tfdi.DefaultIfEmpty()
  65. join sct in DictionaryItemRepository.Entities on new { so.EM_SpecialtyPlan.CourseCategoryID, DictionaryCode =typeof(CF_CourseCategory).Name }
  66. equals new { CourseCategoryID = sct.Value, sct.DictionaryCode } into tsct
  67. from csct in tsct.DefaultIfEmpty()
  68. join sctt in DictionaryItemRepository.Entities on new { so.EM_SpecialtyPlan.CourseTypeID, DictionaryCode = typeof(CF_CourseType).Name }
  69. equals new { CourseTypeID = sctt.Value, sctt.DictionaryCode } into tsctt
  70. from csctt in tsctt.DefaultIfEmpty()
  71. join scq in DictionaryItemRepository.Entities on new { so.EM_SpecialtyPlan.CourseQualityID, DictionaryCode = typeof(CF_CourseQuality).Name }
  72. equals new { CourseQualityID = scq.Value, scq.DictionaryCode } into tscq
  73. from cscq in tscq.DefaultIfEmpty()
  74. join sdord in StudentsOrderRepository.Entities on new { SpecialtyPlanID = (Guid)so.SpecialtyPlanID, so.TeachingMaterialPoolID }
  75. equals new { SpecialtyPlanID = sdord.SpecialtyPlanID, sdord.TeachingMaterialPoolID }
  76. into tsdord
  77. from ctsdord in tsdord.DefaultIfEmpty()
  78. select new StudentDistributeView
  79. {
  80. GrademajorID = so.EM_SpecialtyPlan.CF_Grademajor.GrademajorID,
  81. StudentDistributeID = so.StudentDistributeID,
  82. SchoolyearID = so.EM_SpecialtyPlan.SchoolyearID,
  83. SchoolyearCode = so.EM_SpecialtyPlan.CF_Schoolyear.Code,
  84. TeachingMaterialPoolID = ctmp.TeachingMaterialPoolID,
  85. CollegeID = so.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.CF_College.CollegeID,
  86. CollegeName = so.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.CF_College.Name,
  87. CollegeNo = so.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.CF_College.No,
  88. GradeSpecialtyCode = so.EM_SpecialtyPlan.CF_Grademajor.Code,
  89. GradeSpecialtyName = so.EM_SpecialtyPlan.CF_Grademajor.Name,
  90. GrademajorCode = so.EM_SpecialtyPlan.CF_Grademajor.Code,
  91. GrademajorName = so.EM_SpecialtyPlan.CF_Grademajor.Name,
  92. Years = so.EM_SpecialtyPlan.CF_Grademajor.GradeID,
  93. GradeID = so.EM_SpecialtyPlan.CF_Grademajor.GradeID,
  94. StandardName = cfdi.Name,
  95. StudentQty = so.EM_SpecialtyPlan.CF_Grademajor.CF_Classmajor.Sum(w => w.CF_Student.Where(q => inSchoolStatusIDList.Contains(q.InSchoolStatusID)).Count()),
  96. OrderQty = ctsdord.OrderQty,
  97. CourseCode = so.EM_SpecialtyPlan.EM_Coursematerial.CourseCode,
  98. CourseName = so.EM_SpecialtyPlan.EM_Coursematerial.CourseName,
  99. CourseCategoryID = so.EM_SpecialtyPlan.CourseCategoryID,
  100. CourseCategoryName = csct.Name,
  101. // Years = sy.Years,
  102. CourseTypeID = so.EM_SpecialtyPlan.CourseTypeID,
  103. CourseTypeName = csctt.Name,
  104. CourseQualityID = so.EM_SpecialtyPlan.CourseQualityID,
  105. CourseQualityName = cscq.Name,
  106. CampusID = so.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.CF_College.CF_Campus.CampusID,
  107. StandardID = so.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.StandardID,
  108. SpecialtyValue = so.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.StandardID,
  109. CoursematerialID = so.EM_SpecialtyPlan.EM_Coursematerial.CoursematerialID,
  110. IsDistribute = (int)so.RecordStatus,
  111. IsDistributeName = so.RecordStatus == (int)CF_YesOrNoStatus.Yes ? "是" : "否",
  112. TeachingMaterialCode = ctmp.TeachingMaterialCode,
  113. TeachingMaterialName = ctmp.TeachingMaterialName,
  114. CreateTime = so.CreateTime,
  115. CreateUserName = u.Name,
  116. //Discount = kcmp.Discount == null ? 0 : (kcmp.Discount ?? 1) / (ctmp.Price ?? 1),
  117. //DiscountPrice = kcmp.Discount ?? 0,
  118. PresentInventory = kcmp.PresentInventory ?? 0,
  119. Price = ctmp.Price??0,
  120. RemainingQty = so.ET_StudentDistribute_CF_Student.Where(x => inSchoolStatusIDList.Contains(x.InSchoolStatusID)).Count(),//获取未发放表学生数
  121. DistributeQty = so.DistributeQty - so.ET_StudentDistribute_CF_Student.Where(x => inSchoolStatusIDList.Contains(x.InSchoolStatusID)).Count(),
  122. //DistributeQty = so.EM_SpecialtyPlan.CF_Grademajor.CF_Classmajor.Sum(w => w.CF_Student.Where(q => inSchoolStatusIDList.Contains(q.InSchoolStatusID)).Count()) - so.CF_Student.Where(x => inSchoolStatusIDList.Contains(x.InSchoolStatusID)).Count(),
  123. ISBN = ctmp.ISBN,
  124. PublishTime = ctmp.PublishTime,//版本时间
  125. Author = ctmp.Author,
  126. PublishName = ctmp.CF_Publish.UnitName,
  127. TeachingMaterialTypeID = ctmp.TeachingMaterialTypeID ?? -1
  128. });
  129. return view;
  130. }
  131. public IQueryable<StudentDistributeView> GetAllUsableStudentDistribute()
  132. {
  133. var query = from sd in StudentDistributeRepository.GetList(x => x.RecordStatus == (int)SYS_STATUS.USABLE)
  134. select new StudentDistributeView
  135. {
  136. StudentDistributeID = sd.StudentDistributeID,
  137. SpecialtyPlanID = (Guid)sd.SpecialtyPlanID,
  138. };
  139. return query;
  140. }
  141. public IList<StudentOrderPrePlanView> GetStudentDistributeIDsBySpecialtyPlan(Guid schoolyearID)
  142. {
  143. var planList = (from sd in StudentDistributeRepository.Entities.Where(x => x.RecordStatus == (int)CF_YesOrNoStatus.No && x.TeachingMaterialPoolID == null)
  144. join sy in SchoolyearRepository.Entities.Where(x => x.SchoolyearID == schoolyearID) on sd.EM_SpecialtyPlan.SchoolyearID equals sy.SchoolyearID
  145. select new StudentOrderPrePlanView
  146. {
  147. SpecialtyPlanID = (Guid)sd.SpecialtyPlanID
  148. }).ToList();
  149. //var planList = (from sp in SpecialtyPlanRepository.Entities.Where(x => x.IsNeedMaterial == true)
  150. // join sy in SchoolyearRepository.Entities.Where(x => x.SchoolyearID == schoolyearID) on sp.SchoolyearID equals sy.SchoolyearID
  151. // join so in StudentDistributeRepository.Entities.Where(x => x.RecordStatus == (int)CF_YesOrNoStatus.No) on sp.SpecialtyPlanID equals so.SpecialtyPlanID into tso
  152. // from cso in tso.DefaultIfEmpty()
  153. // select new StudentOrderPrePlanView
  154. // {
  155. // SpecialtyPlanID = sp.SpecialtyPlanID
  156. // }).ToList();
  157. return planList;
  158. }
  159. /// <summary>
  160. /// 获取专业计划对应的需要征订的信息
  161. /// </summary>
  162. /// <param name="exp"></param>
  163. /// <returns></returns>
  164. public IQueryable<StudentDistributePrePlanView> GetStudentDistributeRepositoryBySpecialtyPlan(Guid schoolyearID)
  165. {
  166. var inSchoolStatusIDList = inSchoolSettingRepository.GetList(x => x.IsSelected == true).Select(w => w.InSchoolStatusID).ToList();//获取选中的在校设定状态、
  167. //TODO:增加生成学生发放数据时、以院系所为限制条件生成对应院系数据。
  168. //var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  169. Expression<Func<EM_SpecialtyPlan, bool>> exp = x => x.IsNeedMaterial == true;
  170. var planList = (from sp in SpecialtyPlanRepository.GetList(exp)
  171. join sy in SchoolyearRepository.Entities.Where(x => x.SchoolyearID == schoolyearID) on sp.SchoolyearID equals sy.SchoolyearID
  172. join gj in GrademajorRepository.Entities on sp.GrademajorID equals gj.GrademajorID
  173. join cj in ClassmajorRepository.Entities on gj.GrademajorID equals cj.GrademajorID into tcj
  174. from ccj in tcj.DefaultIfEmpty()
  175. from ctlpv in sp.EM_Coursematerial.CF_TeachingMaterialPool.DefaultIfEmpty()
  176. join so in StudentDistributeRepository.Entities on sp.SpecialtyPlanID equals so.SpecialtyPlanID into tso
  177. from cso in tso.DefaultIfEmpty()
  178. where cso == null
  179. group new { sp, ccj, ctlpv }
  180. // group new { sp, sd = ccj.CF_Student, ctlpv }
  181. by new { sp.SpecialtyPlanID, ctlpv.TeachingMaterialPoolID, sp.CF_Grademajor.CF_Facultymajor.CollegeID } into g
  182. select new StudentDistributePrePlanView
  183. {
  184. SpecialtyPlanID = g.Key.SpecialtyPlanID,
  185. OrderQty = g.Sum(x => x.ccj.CF_Student.Where(e => inSchoolStatusIDList.Contains(e.InSchoolStatusID)).Count()),//只获取在校学生
  186. CollegeID = g.Key.CollegeID,
  187. TeachingMaterialPoolID = g.Key.TeachingMaterialPoolID
  188. });
  189. var ss = planList;
  190. //以学生征订提交数据为基准 (废弃)
  191. //var planList = (from sp in SpecialtyPlanRepository.Entities.Where(x => x.IsNeedMaterial == true)
  192. // join sy in SchoolyearRepository.Entities.Where(x => x.SchoolyearID == schoolyearID) on sp.SchoolyearID equals sy.SchoolyearID
  193. // join sd in StudentsOrderRepository.Entities.Where(x => x.IsOrdered == true) on sp.SpecialtyPlanID equals sd.SpecialtyPlanID
  194. // join gj in GrademajorRepository.Entities on sp.GrademajorID equals gj.GrademajorID
  195. // join sc in SpecialtyCourseRepository.Entities on sp.SpecialtyCourseID equals sc.SpecialtyCourseID
  196. // join cj in ClassmajorRepository.Entities on gj.GrademajorID equals cj.GrademajorID into tcj
  197. // from ccj in tcj.DefaultIfEmpty()
  198. // group new { sd, ccj }
  199. // by new { sd.SpecialtyPlanID, sd.TeachingMaterialPoolID } into g
  200. // select new StudentDistributePrePlanView
  201. // {
  202. // SpecialtyPlanID = g.Key.SpecialtyPlanID,
  203. // OrderQty = g.Sum(x => x.ccj.ClassNum ?? 0),
  204. // TeachingMaterialPoolID = (Guid)g.Key.TeachingMaterialPoolID
  205. // });
  206. return planList;
  207. }
  208. /// <summary>
  209. /// 根据征订ID获取发放数据
  210. /// </summary>
  211. /// <param name="studentsOrderIDs"></param>
  212. /// <returns></returns>
  213. public IList<ET_StudentDistribute> GetStudentDistributeListByStudentDistributeIDs(List<Guid> studentDistributeIDs)
  214. {
  215. return StudentDistributeRepository.GetList(x => studentDistributeIDs.Contains(x.StudentDistributeID)).ToList();
  216. }
  217. /// <summary>
  218. /// 获取当前学年学期所有未发学生信息
  219. /// </summary>
  220. /// <param name="filter"></param>
  221. /// <returns></returns>
  222. public IList<StudentDistribute_UserView> GetStudentQueryable(Expression<Func<ET_StudentDistribute, bool>> filter)
  223. {
  224. var query = from a in StudentDistributeRepository.GetList(filter)
  225. from c in a.ET_StudentDistribute_CF_Student.Where(x => x.InSchoolStatusID == 1)
  226. join sp in SpecialtyPlanRepository.Entities on a.SpecialtyPlanID equals sp.SpecialtyPlanID
  227. join cos in CoursematerialRepository.Entities on sp.CoursematerialID equals cos.CoursematerialID
  228. join recruitStudent in RecruitstudentsRepository.Entities on c.UserID equals recruitStudent.UserID
  229. join u in UserRepository.Entities on a.CreateUserID equals u.UserID
  230. from b in c.EM_StudentReport.AsQueryable().Where(w => w.CF_Schoolyear.IsCurrent == true).DefaultIfEmpty() //当前学年学期的报到情况
  231. select new StudentDistribute_UserView
  232. {
  233. UserID = c.UserID,
  234. LoginID = c.Sys_User.LoginID,
  235. Name = c.Sys_User.Name,
  236. TeachingMaterialCode = a.CF_TeachingMaterialPool.TeachingMaterialCode,
  237. TeachingMaterialName = a.CF_TeachingMaterialPool.TeachingMaterialName,
  238. Remark = a.Remark,
  239. CreateTime = (DateTime)a.CreateTime,
  240. CreateUserName = u.Name,
  241. CourseName = cos.CourseName,
  242. CourseCode = cos.CourseCode
  243. };
  244. return query.ToList();
  245. }
  246. public StudentDistributeView GetSingleStudentDistribute(Expression<Func<ET_StudentDistribute, bool>> filter)
  247. {
  248. var view = from a in StudentDistributeRepository.GetList(filter)
  249. select new StudentDistributeView
  250. {
  251. IsDistribute = (int)a.RecordStatus,
  252. StudentDistributeID = a.StudentDistributeID
  253. };
  254. return view.FirstOrDefault();
  255. }
  256. /// <summary>
  257. /// 获取当前学年学期所有学生信息
  258. /// </summary>
  259. /// <param name="filter"></param>
  260. /// <returns></returns>
  261. public IQueryable<StudentDistribute_UserView> GetStudentQueryable_User(Expression<Func<ET_StudentDistribute, bool>> filter)
  262. {
  263. var query = from so in StudentDistributeRepository.Entities.Where(filter)
  264. join sp in SpecialtyPlanRepository.Entities on so.SpecialtyPlanID equals sp.SpecialtyPlanID
  265. join sy in SchoolyearRepository.Entities on sp.SchoolyearID equals sy.SchoolyearID
  266. join gj in GrademajorRepository.Entities on sp.GrademajorID equals gj.GrademajorID
  267. join fj in FacultymajorRepository.Entities on gj.FacultymajorID equals fj.FacultymajorID
  268. join co in CollegeRepository.Entities on fj.CollegeID equals co.CollegeID
  269. join cos in CoursematerialRepository.Entities on sp.CoursematerialID equals cos.CoursematerialID
  270. join u in UserRepository.Entities on so.CreateUserID equals u.UserID
  271. join tmp in TeachingMaterialPoolRepository.Entities on so.TeachingMaterialPoolID equals tmp.TeachingMaterialPoolID into ttmp
  272. from ctmp in ttmp.DefaultIfEmpty()
  273. from bj in gj.CF_Classmajor
  274. from sd in bj.CF_Student.Where(x => x.InSchoolStatusID == 1)
  275. select new StudentDistribute_UserView
  276. {
  277. UserID = sd.UserID,
  278. LoginID = sd.Sys_User.LoginID,
  279. Name = sd.Sys_User.Name,
  280. Sex = sd.SexID,
  281. ClassMajorName = sd.CF_Classmajor.Name,
  282. InSchoolStatusID = sd.InSchoolStatusID,
  283. StudentStatus = sd.StudentStatus,
  284. TeachingMaterialCode = ctmp.TeachingMaterialCode,
  285. TeachingMaterialName = ctmp.TeachingMaterialName,
  286. Remark = so.Remark,
  287. CreateTime = (DateTime)so.CreateTime,
  288. CreateUserName = u.Name,
  289. CourseName = cos.CourseName,
  290. CourseCode = cos.CourseCode
  291. };
  292. return query;
  293. }
  294. /// <summary>
  295. /// 获取已发放学生
  296. /// </summary>
  297. /// <param name="filter"></param>
  298. /// <returns></returns>
  299. public IQueryable<StudentDistributeView> GetStudentQueryableByStudentDistributeID(Expression<Func<ET_StudentDistribute, bool>> filter)
  300. {
  301. var inSchoolStatusIDList = inSchoolSettingRepository.GetList(x => x.IsSelected == true).Select(w => w.InSchoolStatusID).ToList();//获取选中的在校设定状态、
  302. //1.0 获取未发学生
  303. var userIdlist = (from a in StudentDistributeRepository.Entities.Where(filter)
  304. from sd in a.ET_StudentDistribute_CF_Student
  305. //.Where(x => inSchoolStatusIDList.Contains(x.InSchoolStatusID))
  306. select new StudentDistributeView
  307. {
  308. RecipientUserID = sd.UserID
  309. }).ToList();
  310. List<Guid> userList = new List<Guid>();
  311. if (userIdlist.Count > 0)
  312. {
  313. foreach (var Id in userIdlist)
  314. {
  315. userList.Add(Id.RecipientUserID);
  316. }
  317. }
  318. //2.0 获取发放学生
  319. var query = from a in StudentDistributeRepository.Entities.Where(filter)
  320. join tmp in TeachingMaterialPoolRepository.Entities on a.TeachingMaterialPoolID equals tmp.TeachingMaterialPoolID into ttmp
  321. from ctmp in ttmp.DefaultIfEmpty()
  322. // from sdnt in a.CF_Student //未发学生
  323. join u in UserRepository.Entities on a.ModifyUserID equals u.UserID into tu
  324. from ctu in tu.DefaultIfEmpty()
  325. from spl in a.EM_SpecialtyPlan.CF_Grademajor.CF_Classmajor
  326. from cls in spl.CF_Student
  327. //.Where(x => inSchoolStatusIDList.Contains(x.InSchoolStatusID)) //班级对应的学生
  328. where cls != null
  329. join tp in TeachingMateriaInventoryRepository.Entities on ctmp.TeachingMaterialPoolID equals tp.TeachingMaterialPoolID into ttp
  330. from cttp in ttp.DefaultIfEmpty()
  331. select new StudentDistributeView
  332. {
  333. TeachingMaterialCode = ctmp.TeachingMaterialCode,
  334. TeachingMaterialName = ctmp.TeachingMaterialName,
  335. StudentDistributeNo = a.StudentDistributeNo,
  336. DistributeQty = 1,//a.DistributeQty == null ? 1 : a.DistributeQty,
  337. Price = ctmp.Price,
  338. Discount = cttp.Discount,
  339. DiscountPrice = cttp.DiscountPrice,
  340. TotalPrice = ctmp.Price, //ctmp.Price * a.DistributeQty,
  341. TotalDollar = cttp.DiscountPrice,
  342. StockOutUserName = ctu.Name,
  343. CreateTime = (DateTime)a.CreateTime,
  344. ModifyTime = (DateTime)a.ModifyTime,
  345. StudentNo = cls.Sys_User.LoginID,
  346. StudentName = cls.Sys_User.Name,
  347. RecipientUser = a.RecipientUser,
  348. RecipientUserID = cls.UserID,
  349. Remark = a.Remark
  350. };
  351. return query.Where(x => !userList.Contains(x.RecipientUserID)).Distinct();
  352. }
  353. public IQueryable<StudentDistributeGenerateView> GetStudentDistributeGenerateView(Expression<Func<ET_StudentsOrder, bool>> exp)
  354. {
  355. var query = from order in StudentsOrderRepository.GetList(exp)
  356. join plan in SpecialtyPlanRepository.Entities on order.SpecialtyPlanID equals plan.SpecialtyPlanID
  357. join grade in
  358. (
  359. from grade in GrademajorRepository.Entities
  360. join classmajor in ClassmajorRepository.Entities on grade.GrademajorID equals classmajor.GrademajorID
  361. join student in StudentRepository.Entities on classmajor.ClassmajorID equals student.ClassmajorID
  362. join inschool in inSchoolSettingRepository.Entities on student.InSchoolStatusID equals inschool.InSchoolStatusID
  363. where inschool.IsSelected == true
  364. group student by grade.GrademajorID into g
  365. select new { GrademajorID = g.Key, StudentCount = (int?)g.Count() }
  366. ) on plan.GrademajorID equals grade.GrademajorID
  367. join distribute in StudentDistributeRepository.Entities.Where(x => x.RecordStatus == (int)SYS_STATUS.UNUSABLE)
  368. on new { SpecialtyPlanID = order.SpecialtyPlanID, order.TeachingMaterialPoolID } equals new { SpecialtyPlanID = (Guid)distribute.SpecialtyPlanID, distribute.TeachingMaterialPoolID } into ddistribute
  369. from distribute in ddistribute.DefaultIfEmpty()
  370. join submited in StudentDistributeRepository.Entities.Where(x => x.RecordStatus == (int)SYS_STATUS.USABLE)
  371. on new { order.SpecialtyPlanID, order.TeachingMaterialPoolID } equals new { SpecialtyPlanID = (Guid)submited.SpecialtyPlanID, submited.TeachingMaterialPoolID } into dsubmited
  372. from submited in dsubmited.DefaultIfEmpty()
  373. where (grade.StudentCount ?? 0) > 0 && submited.StudentDistributeID == null
  374. select new StudentDistributeGenerateView
  375. {
  376. SpecialtyPlanID = order.SpecialtyPlanID,
  377. TeachingMaterialPoolID = order.TeachingMaterialPoolID,
  378. StudentCount = grade.StudentCount ?? 0,
  379. OldStudentDistributeID = distribute.StudentDistributeID
  380. };
  381. return query;
  382. }
  383. public IQueryable<InventoryView> GetInventory(Guid poolID)
  384. {
  385. var query = from tmi in TeachingMateriaInventoryRepository.GetList(x => x.TeachingMaterialPoolID == poolID && x.PresentInventory > 0)
  386. select new InventoryView
  387. {
  388. TeachingMaterialPoolID = tmi.TeachingMaterialPoolID,
  389. PresentInventory = tmi.PresentInventory,
  390. CreateTime = tmi.CreateTime,
  391. };
  392. return query;
  393. }
  394. }
  395. }