StudentDistributeServices.cs 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Bowin.Common.Linq.Entity;
  6. using Bowin.Common.Linq;
  7. using EMIS.ViewModel.TeachingMaterial;
  8. using EMIS.DataLogic.Common.TeachingMaterial;
  9. using EMIS.DataLogic.Repositories;
  10. using EMIS.Entities;
  11. using EMIS.ViewModel;
  12. using EMIS.DataLogic.Common.Students;
  13. using EMIS.ViewModel.Students;
  14. using EMIS.CommonLogic.UniversityManage.SpecialtyClassManage;
  15. using System.Linq.Expressions;
  16. using EMIS.CommonLogic.CalendarManage;
  17. namespace EMIS.CommonLogic.TeachingMaterial
  18. {
  19. public class StudentDistributeServices : BaseServices, IStudentDistributeServices
  20. {
  21. public StudentsOrderDAL StudentsOrderDAL { get; set; }
  22. public StudentDistributeDAL StudentDistributeDAL { get; set; }
  23. public StudentsDAL StudentsDAL { get; set; }
  24. public StudentDistributeRepository StudentDistributeRepository { get; set; }
  25. public TeachingMaterialPoolRepository TeachingMaterialPoolRepository { get; set; }
  26. public SchoolyearRepository SchoolyearRepository { get; set; }
  27. public UserRepository UserRepository { get; set; }
  28. public CoursematerialRepository CoursematerialRepository { get; set; }
  29. public SpecialtyPlanRepository SpecialtyPlanRepository { get; set; }
  30. public CollegeRepository CollegeRepository { get; set; }
  31. public DictionaryItemRepository DictionaryItemRepository { get; set; }
  32. public GrademajorRepository GrademajorRepository { get; set; }
  33. public FacultymajorRepository FacultymajorRepository { get; set; }
  34. public SpecialtyCourseRepository SpecialtyCourseRepository { get; set; }
  35. public ClassmajorRepository ClassmajorRepository { get; set; }
  36. public PublishRepository PublishRepository { get; set; }
  37. public IClassmajorServices classmajorServices { get; set; }
  38. public StudentRepository StudentRepository { get; set; }
  39. public TeachingMateriaInventoryRepository TeachingMateriaInventoryRepository { get; set; }
  40. public ISchoolYearServices schoolYearServices { get; set; }
  41. public IStockOutServices stockOutServices { get; set; }
  42. /// <summary>
  43. /// 查询学生发放记录
  44. /// </summary>
  45. public IGridResultSet<StudentDistributeView> GetStudentDistributeViewGrid(ViewModel.ConfiguretView configuretView, Guid? campusID,
  46. Guid? collegeID, int? years, Guid? grademajorID, Guid? coursematerialID, int? courseCategoryID, Guid? teachingMaterialPoolID, int? isDistribute,
  47. Guid? schoolyearID, int? standardID, int pageIndex, int pageSize)
  48. {
  49. Expression<Func<ET_StudentDistribute, bool>> exp = x => x.StockOutType == (int)CF_StockOutType.StudentPutOut;
  50. if (standardID.HasValue)
  51. {
  52. exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.StandardID == standardID);
  53. }
  54. if (teachingMaterialPoolID.HasValue)
  55. {
  56. exp = exp.And(x => x.CF_TeachingMaterialPool.TeachingMaterialPoolID == teachingMaterialPoolID);
  57. }
  58. if (schoolyearID.HasValue)
  59. {
  60. exp = exp.And(x => x.EM_SpecialtyPlan.SchoolyearID == schoolyearID);
  61. }
  62. if (campusID.HasValue)
  63. {
  64. exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.CF_College.CF_Campus.CampusID == campusID);
  65. }
  66. if (collegeID.HasValue)
  67. {
  68. exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.CF_College.CollegeID == collegeID);
  69. }
  70. if (years.HasValue)
  71. {
  72. exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.GradeID == years);
  73. }
  74. if (grademajorID.HasValue)
  75. {
  76. exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.GrademajorID == grademajorID);
  77. }
  78. if (coursematerialID.HasValue)
  79. {
  80. exp = exp.And(x => x.EM_SpecialtyPlan.EM_Coursematerial.CoursematerialID == coursematerialID);
  81. }
  82. if (courseCategoryID.HasValue)
  83. {
  84. exp = exp.And(x => x.EM_SpecialtyPlan.CourseCategoryID == courseCategoryID);
  85. }
  86. if (isDistribute.HasValue && isDistribute>-1)
  87. {
  88. exp = exp.And(x => x.RecordStatus == isDistribute);
  89. }
  90. var query = StudentDistributeDAL.GetStudentDistributeGridView(exp);
  91. //var tmiquery = StudentDistributeDAL.GetInventoryNotOnlyOne();
  92. //if (tmiquery != null)
  93. //{
  94. // List<Guid> teachingMaterialPoolIDList = tmiquery.Select(x => x.TeachingMaterialPoolID).ToList();
  95. // List<StudentDistributeView> sdList = query.Where(x => teachingMaterialPoolIDList.Contains((Guid)x.TeachingMaterialPoolID)).ToList();
  96. //}
  97. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  98. return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderByDescending(x => x.SchoolyearCode).
  99. ThenBy(x => x.CollegeNo).ThenBy(x => x.GrademajorCode).ToGridResultSet<StudentDistributeView>(pageIndex, pageSize);
  100. return this.GetQueryByDataRangeByCollege(query).OrderByDescending(x => x.SchoolyearCode).
  101. ThenBy(x => x.CollegeNo).ThenBy(x => x.GrademajorCode).ToGridResultSet<StudentDistributeView>(pageIndex, pageSize);
  102. }
  103. #region 2.0 生成专业计划
  104. /// <summary>
  105. /// 生成征订计划
  106. /// </summary>
  107. /// <param name="schoolyearID"></param>
  108. public void CreateStudentDistribute(Guid schoolyearID, Guid userID)
  109. {
  110. try
  111. {
  112. #region 0.0 废弃
  113. //var planList = StudentDistributeDAL.GetStudentDistributeRepositoryBySpecialtyPlan(schoolyearID);
  114. //foreach (var planView in planList)
  115. //{
  116. // var studentDistributeList = (from a in StudentDistributeRepository.Entities.Where(x => x.SpecialtyPlanID == planView.SpecialtyPlanID && x.TeachingMaterialPoolID == planView.TeachingMaterialPoolID)
  117. // group a by new { a.TeachingMaterialPoolID, a.SpecialtyPlanID, a.RecordStatus } into g
  118. // select new { SpecialtyPlanID = g.Key.SpecialtyPlanID, TeachingMaterialPoolID = g.Key.TeachingMaterialPoolID, g.Key.RecordStatus }).ToList();
  119. // //如果该专业计划对应的课程信息 已提交、 那么可以再次生成、
  120. // bool IsCreate = true;
  121. // foreach (var studentDistribute in studentDistributeList)
  122. // {
  123. // if (studentDistribute.RecordStatus != 1)//已提交
  124. // {
  125. // IsCreate = false;
  126. // }
  127. // }
  128. // if (IsCreate)
  129. // {
  130. // var StudentDistributeEntity = StudentDistributeRepository.Entities.Where(x => x.SpecialtyPlanID == planView.SpecialtyPlanID && x.RecordStatus == 0).FirstOrDefault();
  131. // if (StudentDistributeEntity != null && planView.TeachingMaterialPoolID != null)
  132. // {
  133. // StudentDistributeEntity.TeachingMaterialPoolID = planView.TeachingMaterialPoolID;
  134. // StudentDistributeEntity.ModifyTime = DateTime.Now;
  135. // StudentDistributeRepository.UnitOfWork.Update(StudentDistributeEntity);
  136. // }
  137. // else
  138. // {
  139. // var studentDistribute = new ET_StudentDistribute
  140. // {
  141. // StudentDistributeID = Guid.NewGuid(),
  142. // RecordStatus = (int)CF_GeneralPurpose.IsNo,
  143. // StockOutType = (int)CF_StockOutType.StudentPutOut,
  144. // DistributeQty = (int)planView.OrderQty,//发放人数、
  145. // SpecialtyPlanID = planView.SpecialtyPlanID,
  146. // TeachingMaterialPoolID = planView.TeachingMaterialPoolID,
  147. // CreateTime = DateTime.Now,
  148. // CreateUserID = userID,
  149. // ModifyTime = DateTime.Now,
  150. // Remark = "学生发放"
  151. // };
  152. // StudentDistributeRepository.UnitOfWork.Add(studentDistribute);
  153. // }
  154. // }
  155. //}
  156. //StudentDistributeRepository.UnitOfWork.Commit();
  157. #endregion
  158. #region 1.0废弃
  159. //1.0 查询出该学年对应下的专业计划
  160. //var planIdsList = StudentDistributeDAL.GetStudentDistributeIDsBySpecialtyPlan(schoolyearID);
  161. //var specialtyIdsList = planIdsList.Select(x => x.SpecialtyPlanID).ToList();
  162. //if (specialtyIdsList.Count > 0)
  163. //{
  164. // UnitOfWork.Delete<ET_StudentDistribute>(x => specialtyIdsList.Contains((Guid)x.SpecialtyPlanID));//先删除、在生成、防止教材没有更新进去
  165. //}
  166. //var studentDistributeQuery = StudentDistributeDAL.GetStudentDistributeRepositoryBySpecialtyPlan(schoolyearID);
  167. //List<StudentDistributePrePlanView> planList = this.GetQueryByDataRangeByCollege(studentDistributeQuery).ToList();
  168. //List<ET_StudentDistribute> listStudentDistribute = new List<ET_StudentDistribute>();//学生发放集合
  169. //foreach (var planView in planList)
  170. //{
  171. // var studentDistribute = new ET_StudentDistribute
  172. // {
  173. // StudentDistributeID = Guid.NewGuid(),
  174. // RecordStatus = (int)CF_GeneralPurpose.IsNo,
  175. // StockOutType = (int)CF_StockOutType.StudentPutOut,
  176. // DistributeQty = (int)planView.OrderQty,//发放人数、
  177. // SpecialtyPlanID = planView.SpecialtyPlanID,
  178. // TeachingMaterialPoolID = planView.TeachingMaterialPoolID,
  179. // CreateTime = DateTime.Now,
  180. // CreateUserID = userID,
  181. // ModifyUserID = userID,
  182. // ModifyTime = DateTime.Now
  183. // };
  184. // listStudentDistribute.Add(studentDistribute);
  185. // // StudentDistributeRepository.UnitOfWork.Add(studentDistribute);
  186. //}
  187. //UnitOfWork.BulkInsert(listStudentDistribute);
  188. #endregion
  189. #region 2.0使用
  190. //生成的数据来源于学生用书里的征订生成中已提交的数据
  191. var distributeList = StudentDistributeDAL.GetStudentDistributeGenerateView(x => x.EM_SpecialtyPlan.SchoolyearID == schoolyearID && x.IsOrdered == true).ToList();
  192. var needDeleteDistributeIDList = distributeList.Where(x => x.OldStudentDistributeID != null).Select(x => x.OldStudentDistributeID).Distinct().ToList();
  193. #endregion
  194. if (needDeleteDistributeIDList.Count > 0)
  195. {
  196. UnitOfWork.Delete<ET_StudentDistribute>(x => needDeleteDistributeIDList.Contains(x.StudentDistributeID));
  197. }
  198. //var studentDistributeQuery = StudentDistributeDAL.GetStudentDistributeRepositoryBySpecialtyPlan(schoolyearID);
  199. List<ET_StudentDistribute> listStudentDistribute = new List<ET_StudentDistribute>();//学生发放集合
  200. foreach (var distribute in distributeList)
  201. {
  202. var studentDistribute = new ET_StudentDistribute
  203. {
  204. StudentDistributeID = Guid.NewGuid(),
  205. RecordStatus = (int)CF_GeneralPurpose.IsNo,
  206. StockOutType = (int)CF_StockOutType.StudentPutOut,
  207. DistributeQty = (int)distribute.StudentCount,//学生人数、
  208. SpecialtyPlanID = distribute.SpecialtyPlanID,
  209. TeachingMaterialPoolID = distribute.TeachingMaterialPoolID,
  210. CreateTime = DateTime.Now,
  211. CreateUserID = userID,
  212. ModifyUserID = userID,
  213. ModifyTime = DateTime.Now
  214. };
  215. listStudentDistribute.Add(studentDistribute);
  216. // StudentDistributeRepository.UnitOfWork.Add(studentDistribute);
  217. }
  218. UnitOfWork.BulkInsert(listStudentDistribute);
  219. //StudentDistributeRepository.UnitOfWork.Commit();
  220. }
  221. catch (Exception ex)
  222. {
  223. throw ex;
  224. }
  225. }
  226. #endregion
  227. #region 3.0 确认发放
  228. /// <summary>
  229. /// 确认发放
  230. /// </summary>
  231. /// <param name="studentsOrderID"></param>
  232. /// <param name="teachingMaterialPoolID"></param>
  233. /// <param name="userID"></param>
  234. public void ComfirmStudentDistribute(List<Guid> studentDistributeID, Guid userID)
  235. {
  236. var studentDistributes = StudentDistributeDAL.GetStudentDistributeListByStudentDistributeIDs(studentDistributeID);
  237. if (studentDistributes.Any(x => x.TeachingMaterialPoolID == null))
  238. {
  239. throw new Exception("勾选的征订计划中,存在教材未指定。");
  240. }
  241. if (studentDistributes.Any(x => x.RecordStatus == 1))//存在已提交、不能重复提交
  242. {
  243. throw new Exception("勾选的征订计划中,存在已发放状态。");
  244. }
  245. foreach (var studentDistribute in studentDistributes)
  246. {
  247. //studentDistribute.RecordStatus = (int)CF_GeneralPurpose.IsYes;
  248. studentDistribute.ModifyTime = DateTime.Now;
  249. studentDistribute.ModifyUserID = userID;
  250. }
  251. foreach (var studentDistribute in studentDistributes.ToList())
  252. {
  253. StudentDistributeRepository.UnitOfWork.Update(studentDistribute);
  254. }
  255. StudentDistributeRepository.UnitOfWork.Commit();
  256. }
  257. #endregion
  258. #region 4.0 删除发放信息
  259. //删除发放信息
  260. public void DeleteStudentDistribute(List<Guid> studentDistributeIDs)
  261. {
  262. try
  263. {
  264. var studentDistributeList = StudentDistributeRepository.GetList(x => studentDistributeIDs.Contains(x.StudentDistributeID)).ToList();
  265. foreach (var studentDistribute in studentDistributeList)
  266. {
  267. if (studentDistribute.RecordStatus == (int)SYS_STATUS.USABLE)
  268. {
  269. throw new Exception("勾选信息包含已发放状态,不能删除!");
  270. }
  271. }
  272. TeachingMaterialPoolRepository.UnitOfWork.Delete<ET_StudentDistribute>(x => studentDistributeIDs.Contains(x.StudentDistributeID));
  273. }
  274. catch (Exception ex)
  275. {
  276. throw ex;
  277. }
  278. }
  279. #endregion
  280. #region 5.0 查询学生信息
  281. public IGridResultSet<StudentsView> GetStudentViewGrid(ConfiguretView configuretView, int pageIndex, int pageSize)
  282. {
  283. var query = StudentsDAL.GetStudentQueryable(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  284. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  285. return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.LoginID).ToGridResultSet<StudentsView>(pageIndex, pageSize);
  286. return query.OrderBy(x => x.LoginID).ToGridResultSet<StudentsView>(pageIndex, pageSize);
  287. }
  288. #endregion
  289. #region 6.0 保存未发学生信息
  290. public void SaveNotStudentDistribute(StudentDistributeView studentDistributeView, IList<StudentsView> studentsList, Guid? userId)
  291. {
  292. throw new NotImplementedException();
  293. }
  294. #endregion
  295. #region 7.0 保存发放清单
  296. public void SaveStudentReleaseInventory(StudentDistributeView studentDistributeView, IList<StudentsView> studentsList, Guid? userId)
  297. {
  298. throw new NotImplementedException();
  299. }
  300. #endregion
  301. #region 8.0 保存未发放清单
  302. public void SaveStudentUnpublishedInventory(StudentDistributeView studentDistributeView, IList<StudentsView> studentsList, Guid? userId)
  303. {
  304. try
  305. {
  306. #region 对用户先去的数进行重复排除
  307. //对数据进行分组、单价、教材ID一致、数量累加
  308. var studentsListGroupBy = (from sd in studentsList
  309. group new { sd } by new
  310. {
  311. sd.UserID,
  312. } into h
  313. select new
  314. {
  315. UserID = h.Key.UserID
  316. });
  317. List<Guid> userIdList = new List<Guid>();
  318. foreach (var item in studentsListGroupBy)
  319. {
  320. userIdList.Add(item.UserID);
  321. }
  322. #endregion
  323. var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  324. ET_StudentDistribute studentDistributeEntity = StudentDistributeRepository
  325. .GetSingle(x => x.StudentDistributeID == studentDistributeView.StudentDistributeID, x => x.ET_StudentDistribute_CF_Student);//有多对多关系、一定要指定属性
  326. if (studentDistributeEntity != null)
  327. {
  328. studentDistributeEntity.ET_StudentDistribute_CF_Student = new HashSet<CF_Student>();//该学生发放ID、对应的所有数据
  329. var queryStudent = StudentRepository.Entities.Where(x => userIdList.Contains(x.UserID));
  330. foreach (var student in queryStudent)
  331. {
  332. studentDistributeEntity.ET_StudentDistribute_CF_Student.Add(student);
  333. }
  334. ////用学生人数和~~~减去未发人数~~
  335. //studentDistributeEntity.DistributeQty = studentDistributeView.StudentQty - queryStudent.Count();
  336. studentDistributeEntity.ModifyUserID = curUser.UserID;
  337. UnitOfWork.Update(studentDistributeEntity);//更新发放数量
  338. UnitOfWork.Commit();
  339. }
  340. }
  341. catch (Exception ex)
  342. {
  343. throw new Exception(ex.Message);
  344. }
  345. }
  346. #endregion
  347. #region 9.0 根据发放ID、加载未发学生信息
  348. public IList<StudentDistribute_UserView> GetStudentDistributeByStudentViewList(Guid studentDistributeID)
  349. {
  350. return StudentDistributeDAL.GetStudentQueryable(x => x.StudentDistributeID == studentDistributeID).OrderBy(x=>x.LoginID.Length).ThenBy(x=>x.LoginID).ToList();
  351. }
  352. #endregion
  353. #region 10.0 查询学生发放Excel导出
  354. /// <summary>
  355. /// 查询学生发放记录
  356. /// </summary>
  357. public IList<StudentDistributeView> GetStudentDistributeViewList(ViewModel.ConfiguretView configuretView, Guid? campusID,
  358. Guid? collegeID, int? years, Guid? grademajorID, Guid? coursematerialID, int? courseCategoryID, Guid? teachingMaterialPoolID, int? isDistribute, Guid? schoolyearID, int? standardID)
  359. {
  360. Expression<Func<ET_StudentDistribute, bool>> exp = x => x.StockOutType == (int)CF_StockOutType.StudentPutOut;
  361. if (standardID.HasValue)
  362. {
  363. exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.StandardID == standardID);
  364. }
  365. if (teachingMaterialPoolID.HasValue)
  366. {
  367. exp = exp.And(x => x.CF_TeachingMaterialPool.TeachingMaterialPoolID == teachingMaterialPoolID);
  368. }
  369. if (schoolyearID.HasValue)
  370. {
  371. exp = exp.And(x => x.EM_SpecialtyPlan.SchoolyearID == schoolyearID);
  372. }
  373. if (campusID.HasValue)
  374. {
  375. exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.CF_College.CF_Campus.CampusID == campusID);
  376. }
  377. if (collegeID.HasValue)
  378. {
  379. exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.CF_College.CollegeID == collegeID);
  380. }
  381. if (years.HasValue)
  382. {
  383. exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.GradeID == years);
  384. }
  385. if (grademajorID.HasValue)
  386. {
  387. exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.GrademajorID == grademajorID);
  388. }
  389. if (coursematerialID.HasValue)
  390. {
  391. exp = exp.And(x => x.EM_SpecialtyPlan.EM_Coursematerial.CoursematerialID == coursematerialID);
  392. }
  393. if (courseCategoryID.HasValue)
  394. {
  395. exp = exp.And(x => x.EM_SpecialtyPlan.CourseCategoryID == courseCategoryID);
  396. }
  397. if (isDistribute.HasValue && isDistribute > -1)
  398. {
  399. exp = exp.And(x => x.RecordStatus == isDistribute);
  400. }
  401. var query = StudentDistributeDAL.GetStudentDistributeGridView(exp);
  402. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  403. return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderByDescending(x => x.SchoolyearCode).
  404. ThenBy(x => x.CollegeNo).ThenBy(x => x.GrademajorCode).ToList();
  405. return this.GetQueryByDataRangeByCollege(query).OrderByDescending(x => x.SchoolyearCode).
  406. ThenBy(x => x.CollegeNo).ThenBy(x => x.GrademajorCode).ToList();
  407. }
  408. #endregion
  409. #region 11.0 获取编辑数据
  410. //获取编辑数据
  411. public StudentDistributeView GetSingleStudentDistribute(Guid studentDistributeID)
  412. {
  413. return StudentDistributeDAL.GetSingleStudentDistribute(x => x.StudentDistributeID == studentDistributeID);
  414. }
  415. #endregion
  416. #region 12.0 获取未发放学生列表
  417. //获取未发放学生列表
  418. public IGridResultSet<StudentDistribute_UserView> GetStudentDistributeByUserViewList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? yearID, int? standardID, int? learningformID, Guid? studentDistributeID, int? IsGraduation, int? inSchoolStatusID, Guid? grademajorID, int pageIndex, int pageSize)
  419. {
  420. ET_StudentDistribute studentDistributeEntity = StudentDistributeRepository
  421. .GetSingle(x => x.StudentDistributeID == studentDistributeID, (x => x.ET_StudentDistribute_CF_Student));//排除已经选取的学生
  422. var query = StudentDistributeDAL.GetStudentQueryable_User(x => x.StudentDistributeID == studentDistributeID);
  423. if (studentDistributeEntity.ET_StudentDistribute_CF_Student.Count > 0)
  424. {
  425. List<Guid> IdList = studentDistributeEntity.ET_StudentDistribute_CF_Student.Select(x => x.UserID).ToList();
  426. query = query.Where(x => !IdList.Contains(x.UserID));//排除已经选取的学生
  427. }
  428. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  429. return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.LoginID.Length).ThenBy(x=>x.LoginID).ToGridResultSet<StudentDistribute_UserView>(pageIndex, pageSize);
  430. return query.OrderBy(x => x.LoginID.Length).ThenBy(x => x.LoginID).ToGridResultSet<StudentDistribute_UserView>(pageIndex, pageSize);
  431. }
  432. #endregion
  433. #region 13.0保存并提交学生放发信息
  434. //保存并提交学生放发信息
  435. public void Save(List<Guid> studentDistributeID, StudentDistributeView studentDistributeView)
  436. {
  437. try
  438. {
  439. if (StudentDistributeRepository.Entities.Where(x => x.StudentDistributeNo == studentDistributeView.StudentDistributeNo).Count() > 0)
  440. {
  441. throw new Exception("出库单号已经存在,请重新输入!");
  442. }
  443. var studentDistributeEntityList = StudentDistributeRepository.Entities.Where(x => studentDistributeID.Contains(x.StudentDistributeID)).ToList();
  444. if (studentDistributeEntityList.Any(x => x.RecordStatus == (int)CF_GeneralPurpose.IsYes))
  445. {
  446. throw new Exception("该信息已经提交,请勿重复提交!");
  447. }
  448. foreach (var studentDistributeEntity in studentDistributeEntityList)
  449. {
  450. ET_StudentDistribute StuDisEntityLists = StudentDistributeRepository.GetSingle(x => x.StudentDistributeID == studentDistributeEntity.StudentDistributeID, (x => x.ET_StudentDistribute_CF_Student));
  451. var query = StudentDistributeDAL.GetInventory((Guid)studentDistributeEntity.TeachingMaterialPoolID);
  452. List<InventoryView> inList = query.OrderBy(x => x.CreateTime).ToList();
  453. int presentInventory = 0;
  454. int distributeQty = studentDistributeEntity.DistributeQty - studentDistributeEntity.ET_StudentDistribute_CF_Student.Count();//发放人数=用学生总人数-未发人数
  455. //学生征订提交时生成出库单
  456. ET_StockOut stockOut = new ET_StockOut();
  457. List<ET_StockOutDetail> stockOutDetailList = new List<ET_StockOutDetail>();
  458. Guid schoolyearID = schoolYearServices.GetSchoolYearIsCurrent(true).SchoolyearID;
  459. stockOut.StockOutID = Guid.NewGuid();
  460. stockOut.OutNumber = distributeQty;//发放人数
  461. stockOut.SchoolyearID = schoolyearID;
  462. stockOut.StockOutNo = studentDistributeView.StudentDistributeNo;//出库单据号暂时采用ID编号字符串
  463. stockOut.GetBookNo = studentDistributeView.RecipientUser;
  464. stockOut.StockOutType = (int)CF_StockOutType.StudentPutOut;
  465. stockOut.RecipientUserID = studentDistributeView.RecipientUserID;
  466. stockOut.StockOutTime = DateTime.Now;
  467. stockOut.Desc = studentDistributeView.Remark;
  468. SetNewStatus(stockOut);
  469. if (inList.Sum(x => x.PresentInventory) >= distributeQty)
  470. {
  471. //stockOutEntity.RecordStatus = (int)CF_GeneralPurpose.IsYes;
  472. //stockOutEntity.ModifyUserID = userId;
  473. //StockOutRepository.UnitOfWork.Update(stockOutEntity);
  474. // StockOutRepository.UnitOfWork.Commit();
  475. List<ET_StockOutDetail> stockOutDetailListsave = new List<ET_StockOutDetail>();
  476. //1.0 提取当前库存量、
  477. //foreach (var stockOutDetailEntity in stockOutDetailList)
  478. //{
  479. int? stockOutQuantity = distributeQty;
  480. List<ET_TeachingMateriaInventory> teachingMateriaInventorylist = stockOutServices.GetTeachingMateriaInventory(studentDistributeEntity.TeachingMaterialPoolID, 0).OrderBy(x => x.CreateTime).ToList();
  481. int count = 0;
  482. int Inventorysum = 0;
  483. int needQuantity = (int)stockOutQuantity;
  484. int oldInventory = 0;
  485. if (teachingMateriaInventorylist.Count > 0)
  486. {
  487. foreach (ET_TeachingMateriaInventory teachingMateriaInventory in teachingMateriaInventorylist)
  488. {
  489. Inventorysum = Inventorysum + (teachingMateriaInventory.PresentInventory ?? 0);
  490. count++;
  491. if (Inventorysum >= stockOutQuantity)
  492. {
  493. if (count == 1)
  494. {
  495. ET_StockOutDetail stockoutDetail = new ET_StockOutDetail();
  496. stockoutDetail.StockOutDetailID = Guid.NewGuid();
  497. stockoutDetail.StockOutID = stockOut.StockOutID;
  498. stockoutDetail.TeachingMaterialPoolID = teachingMateriaInventory.TeachingMaterialPoolID;
  499. stockoutDetail.StockOutQuantity = distributeQty;
  500. stockoutDetail.Discount = teachingMateriaInventory.DiscountPrice;//出库明细折合价
  501. stockoutDetail.DiscountPrice = teachingMateriaInventory.Discount;//出库明细折扣率
  502. SetModifyStatus(stockoutDetail);
  503. stockOut.ET_StockOutDetail.Add(stockoutDetail);
  504. teachingMateriaInventory.PresentInventory = teachingMateriaInventory.PresentInventory - stockOutQuantity;
  505. teachingMateriaInventory.ModifyTime = DateTime.Now;
  506. TeachingMateriaInventoryRepository.UnitOfWork.Update(teachingMateriaInventory);//更新库存数量
  507. break;
  508. }
  509. else
  510. {
  511. for (int i = 0; i < count; i++)
  512. {
  513. var view = teachingMateriaInventorylist[i];
  514. oldInventory = (int)view.PresentInventory;
  515. ET_StockOutDetail stockoutDetail = new ET_StockOutDetail();
  516. stockoutDetail.StockOutDetailID = Guid.NewGuid();
  517. stockoutDetail.StockOutID = stockOut.StockOutID;
  518. stockoutDetail.TeachingMaterialPoolID = teachingMateriaInventory.TeachingMaterialPoolID;
  519. stockoutDetail.StockOutQuantity = (view.PresentInventory - needQuantity) <= 0 ? view.PresentInventory : needQuantity;
  520. stockoutDetail.Discount = view.DiscountPrice;
  521. stockoutDetail.DiscountPrice = view.Discount;
  522. //Math.Round((decimal)(view.Discount / view.CF_TeachingMaterialPool.Price), 2);
  523. SetModifyStatus(stockoutDetail);
  524. stockOut.ET_StockOutDetail.Add(stockoutDetail);
  525. view.PresentInventory = (view.PresentInventory - needQuantity) <= 0 ? 0 : (view.PresentInventory - needQuantity);
  526. view.ModifyTime = DateTime.Now;
  527. TeachingMateriaInventoryRepository.UnitOfWork.Update(view);//更新库存数量
  528. if (oldInventory - needQuantity <= 0)
  529. {
  530. needQuantity = needQuantity - oldInventory;
  531. }
  532. }
  533. break;
  534. }
  535. }
  536. }
  537. }
  538. if (Inventorysum < stockOutQuantity)
  539. {
  540. throw new Exception("出库数量大于当前库存量!");
  541. }
  542. //for (int i = 0; i < inList.Count; i++)
  543. //{
  544. // InventoryView inventoryView = inList[i];
  545. // presentInventory = presentInventory + (int)inList[i].PresentInventory;
  546. // if (presentInventory >= distributeQty)
  547. // {
  548. // if (i == 0)
  549. // {
  550. // ET_TeachingMateriaInventory teachingMateriaInventoryEntity = TeachingMateriaInventoryRepository.GetSingle(x => x.TeachingMaterialPoolID == inventoryView.TeachingMaterialPoolID && x.CreateTime == inventoryView.CreateTime && x.PresentInventory > 0,(x => x.CF_TeachingMaterialPool));
  551. // //出库单详情
  552. // ET_StockOutDetail stockoutDetail = new ET_StockOutDetail();
  553. // stockoutDetail.StockOutDetailID = Guid.NewGuid();
  554. // stockoutDetail.StockOutID = stockOut.StockOutID;
  555. // stockoutDetail.TeachingMaterialPoolID = inventoryView.TeachingMaterialPoolID;
  556. // stockoutDetail.StockOutQuantity = distributeQty;
  557. // stockoutDetail.Discount = teachingMateriaInventoryEntity.Discount;
  558. // stockoutDetail.DiscountPrice = Math.Round((decimal)(teachingMateriaInventoryEntity.Discount/teachingMateriaInventoryEntity.CF_TeachingMaterialPool.Price),2);
  559. // SetModifyStatus(stockoutDetail);
  560. // stockOut.ET_StockOutDetail.Add(stockoutDetail);
  561. // teachingMateriaInventoryEntity.PresentInventory = teachingMateriaInventoryEntity.PresentInventory - distributeQty;
  562. // teachingMateriaInventoryEntity.ModifyTime = DateTime.Now;
  563. // break;
  564. // }
  565. // else
  566. // {
  567. // InventoryView inventoryViewold = inList[i - 1];
  568. // ET_TeachingMateriaInventory teachingMateriaInventoryEntity = TeachingMateriaInventoryRepository.GetSingle(x => x.TeachingMaterialPoolID == inventoryViewold.TeachingMaterialPoolID && x.CreateTime == inventoryViewold.CreateTime && x.PresentInventory > 0, (x => x.CF_TeachingMaterialPool));
  569. // int pre = (int)teachingMateriaInventoryEntity.PresentInventory;//已入库数量
  570. // //出库单详情
  571. // ET_StockOutDetail stockoutDetail = new ET_StockOutDetail();
  572. // stockoutDetail.StockOutDetailID = Guid.NewGuid();
  573. // stockoutDetail.StockOutID = stockOut.StockOutID;
  574. // stockoutDetail.TeachingMaterialPoolID = inventoryViewold.TeachingMaterialPoolID;
  575. // stockoutDetail.StockOutQuantity = pre;
  576. // stockoutDetail.Discount = teachingMateriaInventoryEntity.Discount;
  577. // stockoutDetail.DiscountPrice = Math.Round((decimal)(teachingMateriaInventoryEntity.Discount / teachingMateriaInventoryEntity.CF_TeachingMaterialPool.Price), 2);
  578. // SetNewStatus(stockoutDetail);
  579. // stockOut.ET_StockOutDetail.Add(stockoutDetail);
  580. // teachingMateriaInventoryEntity.PresentInventory = 0;
  581. // teachingMateriaInventoryEntity.ModifyTime = DateTime.Now;
  582. // ET_TeachingMateriaInventory teachingMateriaInventoryEntitytwo = TeachingMateriaInventoryRepository.GetSingle(x => x.TeachingMaterialPoolID == inventoryView.TeachingMaterialPoolID && x.CreateTime == inventoryView.CreateTime && x.PresentInventory > 0, (x => x.CF_TeachingMaterialPool));
  583. // //出库单详情
  584. // ET_StockOutDetail stockoutDetailtwo = new ET_StockOutDetail();
  585. // stockoutDetailtwo.StockOutDetailID = Guid.NewGuid();
  586. // stockoutDetailtwo.StockOutID = stockOut.StockOutID;
  587. // stockoutDetailtwo.TeachingMaterialPoolID = inventoryView.TeachingMaterialPoolID;
  588. // stockoutDetailtwo.StockOutQuantity = distributeQty - pre;
  589. // stockoutDetailtwo.Discount = teachingMateriaInventoryEntity.Discount;
  590. // stockoutDetail.DiscountPrice = Math.Round((decimal)(teachingMateriaInventoryEntity.Discount / teachingMateriaInventoryEntity.CF_TeachingMaterialPool.Price), 2);
  591. // SetNewStatus(stockoutDetailtwo);
  592. // stockOut.ET_StockOutDetail.Add(stockoutDetailtwo);
  593. // teachingMateriaInventoryEntitytwo.PresentInventory = teachingMateriaInventoryEntitytwo.PresentInventory - (distributeQty - pre);
  594. // teachingMateriaInventoryEntitytwo.ModifyTime = DateTime.Now;
  595. // break;
  596. // }
  597. // }
  598. // else
  599. // {
  600. // continue;
  601. // }
  602. //}
  603. }
  604. else {
  605. throw new Exception("征订数量大于当前库存量!");
  606. }
  607. //ET_TeachingMateriaInventory teachingMateriaInventoryEntity = TeachingMateriaInventoryRepository.GetSingle(x => x.TeachingMaterialPoolID == studentDistributeEntity.TeachingMaterialPoolID);
  608. //if (teachingMateriaInventoryEntity != null)
  609. //{
  610. // int distributeQty = studentDistributeEntity.DistributeQty - studentDistributeEntity.CF_Student.Count();//用学生总人数-未发人数
  611. // if (teachingMateriaInventoryEntity.PresentInventory <= 0)
  612. // {
  613. // throw new Exception("该教材库存量为0,不能进行出库!");
  614. // }
  615. // if (teachingMateriaInventoryEntity.PresentInventory < distributeQty)
  616. // {
  617. // throw new Exception("征订数量大于当前库存量!");
  618. // }
  619. // //2.0 当前库存量+入库数量 当前库存量-出库数量
  620. // teachingMateriaInventoryEntity.PresentInventory = teachingMateriaInventoryEntity.PresentInventory - distributeQty;
  621. // teachingMateriaInventoryEntity.ModifyTime = DateTime.Now;
  622. // UnitOfWork.Update(teachingMateriaInventoryEntity);//更新库存数量
  623. //}
  624. // BalanceInventory(studentDistributeEntity);
  625. if (studentDistributeEntity != null)
  626. {
  627. studentDistributeEntity.RecipientUser = studentDistributeView.RecipientUser;//领书人
  628. studentDistributeEntity.StudentDistributeNo = studentDistributeView.StudentDistributeNo;//出库单据号
  629. studentDistributeEntity.RecordStatus = (int)CF_GeneralPurpose.IsYes;//设置状态已提交!
  630. studentDistributeEntity.Remark = studentDistributeView.Remark;
  631. }
  632. UnitOfWork.Add(stockOut);
  633. }
  634. UnitOfWork.Commit();
  635. }
  636. catch (Exception ex)
  637. {
  638. throw new Exception(ex.Message);
  639. }
  640. }
  641. #endregion
  642. #region 14.0 平衡教材库存数量(适用与出库、入库)
  643. public void BalanceInventory(ET_StudentDistribute studentDistribute)
  644. {
  645. ET_StudentDistribute studentDistributeEntity = StudentDistributeRepository.GetSingle(x => x.StudentDistributeID == studentDistribute.StudentDistributeID, (x => x.ET_StudentDistribute_CF_Student));
  646. ET_TeachingMateriaInventory teachingMateriaInventoryEntity = TeachingMateriaInventoryRepository.GetSingle(x => x.TeachingMaterialPoolID == studentDistribute.TeachingMaterialPoolID);
  647. if (teachingMateriaInventoryEntity != null)
  648. {
  649. int distributeQty = studentDistributeEntity.DistributeQty - studentDistributeEntity.ET_StudentDistribute_CF_Student.Count();//用学生总人数-未发人数
  650. if (teachingMateriaInventoryEntity.PresentInventory <= 0)
  651. {
  652. throw new Exception("该教材库存量为0,不能进行出库!");
  653. }
  654. if (teachingMateriaInventoryEntity.PresentInventory < distributeQty)
  655. {
  656. throw new Exception("征订数量大于当前库存量!");
  657. }
  658. //2.0 当前库存量+入库数量 当前库存量-出库数量
  659. teachingMateriaInventoryEntity.PresentInventory = teachingMateriaInventoryEntity.PresentInventory - distributeQty;
  660. teachingMateriaInventoryEntity.ModifyTime = DateTime.Now;
  661. UnitOfWork.Update(teachingMateriaInventoryEntity);//更新库存数量
  662. UnitOfWork.Commit();
  663. }
  664. }
  665. #endregion
  666. //发放清单列表
  667. public IGridResultSet<StudentDistributeView> GetStudentDistributeDetailViewList(Guid? studentDistributeID, int pageIndex, int pageSize)
  668. {
  669. var query = StudentDistributeDAL.GetStudentQueryableByStudentDistributeID(x => x.StudentDistributeID == studentDistributeID);
  670. query = query.Where(x => x.StudentNo != null);
  671. return query.OrderBy(x => x.StudentNo.Length).ThenBy(x => x.StudentNo).ToGridResultSet<StudentDistributeView>(pageIndex, pageSize);
  672. }
  673. public IList<StudentDistributeView> GetStudentDistributeDetailQuery(Guid? studentDistributeID)
  674. {
  675. var query = StudentDistributeDAL.GetStudentQueryableByStudentDistributeID(x => x.StudentDistributeID == studentDistributeID);
  676. query = query.Where(x => x.StudentNo != null);
  677. return query.OrderBy(x => x.StudentNo.Length).ThenBy(x => x.StudentNo).ToList();
  678. }
  679. }
  680. }