123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Bowin.Common.Linq.Entity;
- using Bowin.Common.Linq;
- using EMIS.ViewModel.TeachingMaterial;
- using EMIS.DataLogic.Common.TeachingMaterial;
- using EMIS.DataLogic.Repositories;
- using EMIS.Entities;
- using EMIS.ViewModel;
- using EMIS.DataLogic.Common.Students;
- using EMIS.ViewModel.Students;
- using EMIS.CommonLogic.UniversityManage.SpecialtyClassManage;
- using System.Linq.Expressions;
- using EMIS.CommonLogic.CalendarManage;
- namespace EMIS.CommonLogic.TeachingMaterial
- {
- public class StudentDistributeServices : BaseServices, IStudentDistributeServices
- {
- public StudentsOrderDAL StudentsOrderDAL { get; set; }
- public StudentDistributeDAL StudentDistributeDAL { get; set; }
- public StudentsDAL StudentsDAL { get; set; }
- public StudentDistributeRepository StudentDistributeRepository { get; set; }
- public TeachingMaterialPoolRepository TeachingMaterialPoolRepository { get; set; }
- public SchoolyearRepository SchoolyearRepository { get; set; }
- public UserRepository UserRepository { get; set; }
- public CoursematerialRepository CoursematerialRepository { get; set; }
- public SpecialtyPlanRepository SpecialtyPlanRepository { get; set; }
- public CollegeRepository CollegeRepository { get; set; }
- public DictionaryItemRepository DictionaryItemRepository { get; set; }
- public GrademajorRepository GrademajorRepository { get; set; }
- public FacultymajorRepository FacultymajorRepository { get; set; }
- public SpecialtyCourseRepository SpecialtyCourseRepository { get; set; }
- public ClassmajorRepository ClassmajorRepository { get; set; }
- public PublishRepository PublishRepository { get; set; }
- public IClassmajorServices classmajorServices { get; set; }
- public StudentRepository StudentRepository { get; set; }
- public TeachingMateriaInventoryRepository TeachingMateriaInventoryRepository { get; set; }
- public ISchoolYearServices schoolYearServices { get; set; }
- public IStockOutServices stockOutServices { get; set; }
- /// <summary>
- /// 查询学生发放记录
- /// </summary>
- public IGridResultSet<StudentDistributeView> GetStudentDistributeViewGrid(ViewModel.ConfiguretView configuretView, Guid? campusID,
- Guid? collegeID, int? years, Guid? grademajorID, Guid? coursematerialID, int? courseCategoryID, Guid? teachingMaterialPoolID, int? isDistribute,
- Guid? schoolyearID, int? standardID, int pageIndex, int pageSize)
- {
- Expression<Func<ET_StudentDistribute, bool>> exp = x => x.StockOutType == (int)CF_StockOutType.StudentPutOut;
- if (standardID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.StandardID == standardID);
- }
- if (teachingMaterialPoolID.HasValue)
- {
- exp = exp.And(x => x.CF_TeachingMaterialPool.TeachingMaterialPoolID == teachingMaterialPoolID);
- }
- if (schoolyearID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.SchoolyearID == schoolyearID);
- }
- if (campusID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.CF_College.CF_Campus.CampusID == campusID);
- }
- if (collegeID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.CF_College.CollegeID == collegeID);
- }
- if (years.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.GradeID == years);
- }
- if (grademajorID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.GrademajorID == grademajorID);
- }
- if (coursematerialID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.EM_Coursematerial.CoursematerialID == coursematerialID);
- }
- if (courseCategoryID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.CourseCategoryID == courseCategoryID);
- }
- if (isDistribute.HasValue && isDistribute>-1)
- {
- exp = exp.And(x => x.RecordStatus == isDistribute);
- }
- var query = StudentDistributeDAL.GetStudentDistributeGridView(exp);
- //var tmiquery = StudentDistributeDAL.GetInventoryNotOnlyOne();
- //if (tmiquery != null)
- //{
- // List<Guid> teachingMaterialPoolIDList = tmiquery.Select(x => x.TeachingMaterialPoolID).ToList();
- // List<StudentDistributeView> sdList = query.Where(x => teachingMaterialPoolIDList.Contains((Guid)x.TeachingMaterialPoolID)).ToList();
- //}
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderByDescending(x => x.SchoolyearCode).
- ThenBy(x => x.CollegeNo).ThenBy(x => x.GrademajorCode).ToGridResultSet<StudentDistributeView>(pageIndex, pageSize);
- return this.GetQueryByDataRangeByCollege(query).OrderByDescending(x => x.SchoolyearCode).
- ThenBy(x => x.CollegeNo).ThenBy(x => x.GrademajorCode).ToGridResultSet<StudentDistributeView>(pageIndex, pageSize);
- }
- #region 2.0 生成专业计划
- /// <summary>
- /// 生成征订计划
- /// </summary>
- /// <param name="schoolyearID"></param>
- public void CreateStudentDistribute(Guid schoolyearID, Guid userID)
- {
- try
- {
- #region 0.0 废弃
- //var planList = StudentDistributeDAL.GetStudentDistributeRepositoryBySpecialtyPlan(schoolyearID);
- //foreach (var planView in planList)
- //{
- // var studentDistributeList = (from a in StudentDistributeRepository.Entities.Where(x => x.SpecialtyPlanID == planView.SpecialtyPlanID && x.TeachingMaterialPoolID == planView.TeachingMaterialPoolID)
- // group a by new { a.TeachingMaterialPoolID, a.SpecialtyPlanID, a.RecordStatus } into g
- // select new { SpecialtyPlanID = g.Key.SpecialtyPlanID, TeachingMaterialPoolID = g.Key.TeachingMaterialPoolID, g.Key.RecordStatus }).ToList();
- // //如果该专业计划对应的课程信息 已提交、 那么可以再次生成、
- // bool IsCreate = true;
- // foreach (var studentDistribute in studentDistributeList)
- // {
- // if (studentDistribute.RecordStatus != 1)//已提交
- // {
- // IsCreate = false;
- // }
- // }
- // if (IsCreate)
- // {
- // var StudentDistributeEntity = StudentDistributeRepository.Entities.Where(x => x.SpecialtyPlanID == planView.SpecialtyPlanID && x.RecordStatus == 0).FirstOrDefault();
- // if (StudentDistributeEntity != null && planView.TeachingMaterialPoolID != null)
- // {
- // StudentDistributeEntity.TeachingMaterialPoolID = planView.TeachingMaterialPoolID;
- // StudentDistributeEntity.ModifyTime = DateTime.Now;
- // StudentDistributeRepository.UnitOfWork.Update(StudentDistributeEntity);
- // }
- // else
- // {
- // var studentDistribute = new ET_StudentDistribute
- // {
- // StudentDistributeID = Guid.NewGuid(),
- // RecordStatus = (int)CF_GeneralPurpose.IsNo,
- // StockOutType = (int)CF_StockOutType.StudentPutOut,
- // DistributeQty = (int)planView.OrderQty,//发放人数、
- // SpecialtyPlanID = planView.SpecialtyPlanID,
- // TeachingMaterialPoolID = planView.TeachingMaterialPoolID,
- // CreateTime = DateTime.Now,
- // CreateUserID = userID,
- // ModifyTime = DateTime.Now,
- // Remark = "学生发放"
- // };
- // StudentDistributeRepository.UnitOfWork.Add(studentDistribute);
- // }
- // }
- //}
- //StudentDistributeRepository.UnitOfWork.Commit();
- #endregion
- #region 1.0废弃
- //1.0 查询出该学年对应下的专业计划
- //var planIdsList = StudentDistributeDAL.GetStudentDistributeIDsBySpecialtyPlan(schoolyearID);
- //var specialtyIdsList = planIdsList.Select(x => x.SpecialtyPlanID).ToList();
- //if (specialtyIdsList.Count > 0)
- //{
- // UnitOfWork.Delete<ET_StudentDistribute>(x => specialtyIdsList.Contains((Guid)x.SpecialtyPlanID));//先删除、在生成、防止教材没有更新进去
- //}
- //var studentDistributeQuery = StudentDistributeDAL.GetStudentDistributeRepositoryBySpecialtyPlan(schoolyearID);
- //List<StudentDistributePrePlanView> planList = this.GetQueryByDataRangeByCollege(studentDistributeQuery).ToList();
- //List<ET_StudentDistribute> listStudentDistribute = new List<ET_StudentDistribute>();//学生发放集合
- //foreach (var planView in planList)
- //{
- // var studentDistribute = new ET_StudentDistribute
- // {
- // StudentDistributeID = Guid.NewGuid(),
- // RecordStatus = (int)CF_GeneralPurpose.IsNo,
- // StockOutType = (int)CF_StockOutType.StudentPutOut,
- // DistributeQty = (int)planView.OrderQty,//发放人数、
- // SpecialtyPlanID = planView.SpecialtyPlanID,
- // TeachingMaterialPoolID = planView.TeachingMaterialPoolID,
- // CreateTime = DateTime.Now,
- // CreateUserID = userID,
- // ModifyUserID = userID,
- // ModifyTime = DateTime.Now
- // };
- // listStudentDistribute.Add(studentDistribute);
- // // StudentDistributeRepository.UnitOfWork.Add(studentDistribute);
- //}
- //UnitOfWork.BulkInsert(listStudentDistribute);
- #endregion
- #region 2.0使用
- //生成的数据来源于学生用书里的征订生成中已提交的数据
- var distributeList = StudentDistributeDAL.GetStudentDistributeGenerateView(x => x.EM_SpecialtyPlan.SchoolyearID == schoolyearID && x.IsOrdered == true).ToList();
- var needDeleteDistributeIDList = distributeList.Where(x => x.OldStudentDistributeID != null).Select(x => x.OldStudentDistributeID).Distinct().ToList();
- #endregion
- if (needDeleteDistributeIDList.Count > 0)
- {
- UnitOfWork.Delete<ET_StudentDistribute>(x => needDeleteDistributeIDList.Contains(x.StudentDistributeID));
- }
- //var studentDistributeQuery = StudentDistributeDAL.GetStudentDistributeRepositoryBySpecialtyPlan(schoolyearID);
- List<ET_StudentDistribute> listStudentDistribute = new List<ET_StudentDistribute>();//学生发放集合
- foreach (var distribute in distributeList)
- {
- var studentDistribute = new ET_StudentDistribute
- {
- StudentDistributeID = Guid.NewGuid(),
- RecordStatus = (int)CF_GeneralPurpose.IsNo,
- StockOutType = (int)CF_StockOutType.StudentPutOut,
- DistributeQty = (int)distribute.StudentCount,//学生人数、
- SpecialtyPlanID = distribute.SpecialtyPlanID,
- TeachingMaterialPoolID = distribute.TeachingMaterialPoolID,
- CreateTime = DateTime.Now,
- CreateUserID = userID,
- ModifyUserID = userID,
- ModifyTime = DateTime.Now
- };
- listStudentDistribute.Add(studentDistribute);
- // StudentDistributeRepository.UnitOfWork.Add(studentDistribute);
- }
- UnitOfWork.BulkInsert(listStudentDistribute);
- //StudentDistributeRepository.UnitOfWork.Commit();
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- #endregion
- #region 3.0 确认发放
- /// <summary>
- /// 确认发放
- /// </summary>
- /// <param name="studentsOrderID"></param>
- /// <param name="teachingMaterialPoolID"></param>
- /// <param name="userID"></param>
- public void ComfirmStudentDistribute(List<Guid> studentDistributeID, Guid userID)
- {
- var studentDistributes = StudentDistributeDAL.GetStudentDistributeListByStudentDistributeIDs(studentDistributeID);
- if (studentDistributes.Any(x => x.TeachingMaterialPoolID == null))
- {
- throw new Exception("勾选的征订计划中,存在教材未指定。");
- }
- if (studentDistributes.Any(x => x.RecordStatus == 1))//存在已提交、不能重复提交
- {
- throw new Exception("勾选的征订计划中,存在已发放状态。");
- }
- foreach (var studentDistribute in studentDistributes)
- {
- //studentDistribute.RecordStatus = (int)CF_GeneralPurpose.IsYes;
- studentDistribute.ModifyTime = DateTime.Now;
- studentDistribute.ModifyUserID = userID;
- }
- foreach (var studentDistribute in studentDistributes.ToList())
- {
- StudentDistributeRepository.UnitOfWork.Update(studentDistribute);
- }
- StudentDistributeRepository.UnitOfWork.Commit();
- }
- #endregion
- #region 4.0 删除发放信息
- //删除发放信息
- public void DeleteStudentDistribute(List<Guid> studentDistributeIDs)
- {
- try
- {
- var studentDistributeList = StudentDistributeRepository.GetList(x => studentDistributeIDs.Contains(x.StudentDistributeID)).ToList();
- foreach (var studentDistribute in studentDistributeList)
- {
- if (studentDistribute.RecordStatus == (int)SYS_STATUS.USABLE)
- {
- throw new Exception("勾选信息包含已发放状态,不能删除!");
- }
- }
- TeachingMaterialPoolRepository.UnitOfWork.Delete<ET_StudentDistribute>(x => studentDistributeIDs.Contains(x.StudentDistributeID));
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- #endregion
- #region 5.0 查询学生信息
- public IGridResultSet<StudentsView> GetStudentViewGrid(ConfiguretView configuretView, int pageIndex, int pageSize)
- {
- var query = StudentsDAL.GetStudentQueryable(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.LoginID).ToGridResultSet<StudentsView>(pageIndex, pageSize);
- return query.OrderBy(x => x.LoginID).ToGridResultSet<StudentsView>(pageIndex, pageSize);
- }
- #endregion
- #region 6.0 保存未发学生信息
- public void SaveNotStudentDistribute(StudentDistributeView studentDistributeView, IList<StudentsView> studentsList, Guid? userId)
- {
- throw new NotImplementedException();
- }
- #endregion
- #region 7.0 保存发放清单
- public void SaveStudentReleaseInventory(StudentDistributeView studentDistributeView, IList<StudentsView> studentsList, Guid? userId)
- {
- throw new NotImplementedException();
- }
- #endregion
- #region 8.0 保存未发放清单
- public void SaveStudentUnpublishedInventory(StudentDistributeView studentDistributeView, IList<StudentsView> studentsList, Guid? userId)
- {
- try
- {
- #region 对用户先去的数进行重复排除
- //对数据进行分组、单价、教材ID一致、数量累加
- var studentsListGroupBy = (from sd in studentsList
- group new { sd } by new
- {
- sd.UserID,
- } into h
- select new
- {
- UserID = h.Key.UserID
- });
- List<Guid> userIdList = new List<Guid>();
- foreach (var item in studentsListGroupBy)
- {
- userIdList.Add(item.UserID);
- }
- #endregion
- var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
- ET_StudentDistribute studentDistributeEntity = StudentDistributeRepository
- .GetSingle(x => x.StudentDistributeID == studentDistributeView.StudentDistributeID, x => x.ET_StudentDistribute_CF_Student);//有多对多关系、一定要指定属性
- if (studentDistributeEntity != null)
- {
- studentDistributeEntity.ET_StudentDistribute_CF_Student = new HashSet<CF_Student>();//该学生发放ID、对应的所有数据
- var queryStudent = StudentRepository.Entities.Where(x => userIdList.Contains(x.UserID));
- foreach (var student in queryStudent)
- {
- studentDistributeEntity.ET_StudentDistribute_CF_Student.Add(student);
- }
- ////用学生人数和~~~减去未发人数~~
- //studentDistributeEntity.DistributeQty = studentDistributeView.StudentQty - queryStudent.Count();
- studentDistributeEntity.ModifyUserID = curUser.UserID;
- UnitOfWork.Update(studentDistributeEntity);//更新发放数量
- UnitOfWork.Commit();
- }
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- #endregion
- #region 9.0 根据发放ID、加载未发学生信息
- public IList<StudentDistribute_UserView> GetStudentDistributeByStudentViewList(Guid studentDistributeID)
- {
- return StudentDistributeDAL.GetStudentQueryable(x => x.StudentDistributeID == studentDistributeID).OrderBy(x=>x.LoginID.Length).ThenBy(x=>x.LoginID).ToList();
- }
- #endregion
- #region 10.0 查询学生发放Excel导出
- /// <summary>
- /// 查询学生发放记录
- /// </summary>
- public IList<StudentDistributeView> GetStudentDistributeViewList(ViewModel.ConfiguretView configuretView, Guid? campusID,
- Guid? collegeID, int? years, Guid? grademajorID, Guid? coursematerialID, int? courseCategoryID, Guid? teachingMaterialPoolID, int? isDistribute, Guid? schoolyearID, int? standardID)
- {
- Expression<Func<ET_StudentDistribute, bool>> exp = x => x.StockOutType == (int)CF_StockOutType.StudentPutOut;
- if (standardID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.StandardID == standardID);
- }
- if (teachingMaterialPoolID.HasValue)
- {
- exp = exp.And(x => x.CF_TeachingMaterialPool.TeachingMaterialPoolID == teachingMaterialPoolID);
- }
- if (schoolyearID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.SchoolyearID == schoolyearID);
- }
- if (campusID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.CF_College.CF_Campus.CampusID == campusID);
- }
- if (collegeID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.CF_College.CollegeID == collegeID);
- }
- if (years.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.GradeID == years);
- }
- if (grademajorID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.GrademajorID == grademajorID);
- }
- if (coursematerialID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.EM_Coursematerial.CoursematerialID == coursematerialID);
- }
- if (courseCategoryID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.CourseCategoryID == courseCategoryID);
- }
- if (isDistribute.HasValue && isDistribute > -1)
- {
- exp = exp.And(x => x.RecordStatus == isDistribute);
- }
- var query = StudentDistributeDAL.GetStudentDistributeGridView(exp);
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderByDescending(x => x.SchoolyearCode).
- ThenBy(x => x.CollegeNo).ThenBy(x => x.GrademajorCode).ToList();
- return this.GetQueryByDataRangeByCollege(query).OrderByDescending(x => x.SchoolyearCode).
- ThenBy(x => x.CollegeNo).ThenBy(x => x.GrademajorCode).ToList();
- }
- #endregion
- #region 11.0 获取编辑数据
- //获取编辑数据
- public StudentDistributeView GetSingleStudentDistribute(Guid studentDistributeID)
- {
- return StudentDistributeDAL.GetSingleStudentDistribute(x => x.StudentDistributeID == studentDistributeID);
- }
- #endregion
- #region 12.0 获取未发放学生列表
- //获取未发放学生列表
- 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)
- {
- ET_StudentDistribute studentDistributeEntity = StudentDistributeRepository
- .GetSingle(x => x.StudentDistributeID == studentDistributeID, (x => x.ET_StudentDistribute_CF_Student));//排除已经选取的学生
- var query = StudentDistributeDAL.GetStudentQueryable_User(x => x.StudentDistributeID == studentDistributeID);
- if (studentDistributeEntity.ET_StudentDistribute_CF_Student.Count > 0)
- {
- List<Guid> IdList = studentDistributeEntity.ET_StudentDistribute_CF_Student.Select(x => x.UserID).ToList();
- query = query.Where(x => !IdList.Contains(x.UserID));//排除已经选取的学生
- }
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.LoginID.Length).ThenBy(x=>x.LoginID).ToGridResultSet<StudentDistribute_UserView>(pageIndex, pageSize);
- return query.OrderBy(x => x.LoginID.Length).ThenBy(x => x.LoginID).ToGridResultSet<StudentDistribute_UserView>(pageIndex, pageSize);
- }
- #endregion
- #region 13.0保存并提交学生放发信息
- //保存并提交学生放发信息
- public void Save(List<Guid> studentDistributeID, StudentDistributeView studentDistributeView)
- {
- try
- {
- if (StudentDistributeRepository.Entities.Where(x => x.StudentDistributeNo == studentDistributeView.StudentDistributeNo).Count() > 0)
- {
- throw new Exception("出库单号已经存在,请重新输入!");
- }
- var studentDistributeEntityList = StudentDistributeRepository.Entities.Where(x => studentDistributeID.Contains(x.StudentDistributeID)).ToList();
- if (studentDistributeEntityList.Any(x => x.RecordStatus == (int)CF_GeneralPurpose.IsYes))
- {
- throw new Exception("该信息已经提交,请勿重复提交!");
- }
-
- foreach (var studentDistributeEntity in studentDistributeEntityList)
- {
- ET_StudentDistribute StuDisEntityLists = StudentDistributeRepository.GetSingle(x => x.StudentDistributeID == studentDistributeEntity.StudentDistributeID, (x => x.ET_StudentDistribute_CF_Student));
- var query = StudentDistributeDAL.GetInventory((Guid)studentDistributeEntity.TeachingMaterialPoolID);
- List<InventoryView> inList = query.OrderBy(x => x.CreateTime).ToList();
- int presentInventory = 0;
- int distributeQty = studentDistributeEntity.DistributeQty - studentDistributeEntity.ET_StudentDistribute_CF_Student.Count();//发放人数=用学生总人数-未发人数
- //学生征订提交时生成出库单
- ET_StockOut stockOut = new ET_StockOut();
- List<ET_StockOutDetail> stockOutDetailList = new List<ET_StockOutDetail>();
- Guid schoolyearID = schoolYearServices.GetSchoolYearIsCurrent(true).SchoolyearID;
- stockOut.StockOutID = Guid.NewGuid();
- stockOut.OutNumber = distributeQty;//发放人数
- stockOut.SchoolyearID = schoolyearID;
- stockOut.StockOutNo = studentDistributeView.StudentDistributeNo;//出库单据号暂时采用ID编号字符串
- stockOut.GetBookNo = studentDistributeView.RecipientUser;
- stockOut.StockOutType = (int)CF_StockOutType.StudentPutOut;
- stockOut.RecipientUserID = studentDistributeView.RecipientUserID;
- stockOut.StockOutTime = DateTime.Now;
- stockOut.Desc = studentDistributeView.Remark;
- SetNewStatus(stockOut);
-
- if (inList.Sum(x => x.PresentInventory) >= distributeQty)
- {
- //stockOutEntity.RecordStatus = (int)CF_GeneralPurpose.IsYes;
- //stockOutEntity.ModifyUserID = userId;
- //StockOutRepository.UnitOfWork.Update(stockOutEntity);
- // StockOutRepository.UnitOfWork.Commit();
- List<ET_StockOutDetail> stockOutDetailListsave = new List<ET_StockOutDetail>();
- //1.0 提取当前库存量、
- //foreach (var stockOutDetailEntity in stockOutDetailList)
- //{
- int? stockOutQuantity = distributeQty;
- List<ET_TeachingMateriaInventory> teachingMateriaInventorylist = stockOutServices.GetTeachingMateriaInventory(studentDistributeEntity.TeachingMaterialPoolID, 0).OrderBy(x => x.CreateTime).ToList();
- int count = 0;
- int Inventorysum = 0;
- int needQuantity = (int)stockOutQuantity;
- int oldInventory = 0;
- if (teachingMateriaInventorylist.Count > 0)
- {
- foreach (ET_TeachingMateriaInventory teachingMateriaInventory in teachingMateriaInventorylist)
- {
- Inventorysum = Inventorysum + (teachingMateriaInventory.PresentInventory ?? 0);
- count++;
- if (Inventorysum >= stockOutQuantity)
- {
- if (count == 1)
- {
- ET_StockOutDetail stockoutDetail = new ET_StockOutDetail();
- stockoutDetail.StockOutDetailID = Guid.NewGuid();
- stockoutDetail.StockOutID = stockOut.StockOutID;
- stockoutDetail.TeachingMaterialPoolID = teachingMateriaInventory.TeachingMaterialPoolID;
- stockoutDetail.StockOutQuantity = distributeQty;
- stockoutDetail.Discount = teachingMateriaInventory.DiscountPrice;//出库明细折合价
- stockoutDetail.DiscountPrice = teachingMateriaInventory.Discount;//出库明细折扣率
- SetModifyStatus(stockoutDetail);
- stockOut.ET_StockOutDetail.Add(stockoutDetail);
- teachingMateriaInventory.PresentInventory = teachingMateriaInventory.PresentInventory - stockOutQuantity;
- teachingMateriaInventory.ModifyTime = DateTime.Now;
- TeachingMateriaInventoryRepository.UnitOfWork.Update(teachingMateriaInventory);//更新库存数量
- break;
- }
- else
- {
- for (int i = 0; i < count; i++)
- {
-
- var view = teachingMateriaInventorylist[i];
- oldInventory = (int)view.PresentInventory;
- ET_StockOutDetail stockoutDetail = new ET_StockOutDetail();
- stockoutDetail.StockOutDetailID = Guid.NewGuid();
- stockoutDetail.StockOutID = stockOut.StockOutID;
- stockoutDetail.TeachingMaterialPoolID = teachingMateriaInventory.TeachingMaterialPoolID;
- stockoutDetail.StockOutQuantity = (view.PresentInventory - needQuantity) <= 0 ? view.PresentInventory : needQuantity;
- stockoutDetail.Discount = view.DiscountPrice;
- stockoutDetail.DiscountPrice = view.Discount;
- //Math.Round((decimal)(view.Discount / view.CF_TeachingMaterialPool.Price), 2);
- SetModifyStatus(stockoutDetail);
- stockOut.ET_StockOutDetail.Add(stockoutDetail);
- view.PresentInventory = (view.PresentInventory - needQuantity) <= 0 ? 0 : (view.PresentInventory - needQuantity);
- view.ModifyTime = DateTime.Now;
- TeachingMateriaInventoryRepository.UnitOfWork.Update(view);//更新库存数量
- if (oldInventory - needQuantity <= 0)
- {
- needQuantity = needQuantity - oldInventory;
- }
- }
- break;
- }
- }
-
- }
- }
- if (Inventorysum < stockOutQuantity)
- {
- throw new Exception("出库数量大于当前库存量!");
- }
- //for (int i = 0; i < inList.Count; i++)
- //{
- // InventoryView inventoryView = inList[i];
- // presentInventory = presentInventory + (int)inList[i].PresentInventory;
- // if (presentInventory >= distributeQty)
- // {
- // if (i == 0)
- // {
- // ET_TeachingMateriaInventory teachingMateriaInventoryEntity = TeachingMateriaInventoryRepository.GetSingle(x => x.TeachingMaterialPoolID == inventoryView.TeachingMaterialPoolID && x.CreateTime == inventoryView.CreateTime && x.PresentInventory > 0,(x => x.CF_TeachingMaterialPool));
- // //出库单详情
- // ET_StockOutDetail stockoutDetail = new ET_StockOutDetail();
- // stockoutDetail.StockOutDetailID = Guid.NewGuid();
- // stockoutDetail.StockOutID = stockOut.StockOutID;
- // stockoutDetail.TeachingMaterialPoolID = inventoryView.TeachingMaterialPoolID;
- // stockoutDetail.StockOutQuantity = distributeQty;
- // stockoutDetail.Discount = teachingMateriaInventoryEntity.Discount;
- // stockoutDetail.DiscountPrice = Math.Round((decimal)(teachingMateriaInventoryEntity.Discount/teachingMateriaInventoryEntity.CF_TeachingMaterialPool.Price),2);
- // SetModifyStatus(stockoutDetail);
- // stockOut.ET_StockOutDetail.Add(stockoutDetail);
- // teachingMateriaInventoryEntity.PresentInventory = teachingMateriaInventoryEntity.PresentInventory - distributeQty;
- // teachingMateriaInventoryEntity.ModifyTime = DateTime.Now;
- // break;
- // }
- // else
- // {
- // InventoryView inventoryViewold = inList[i - 1];
- // ET_TeachingMateriaInventory teachingMateriaInventoryEntity = TeachingMateriaInventoryRepository.GetSingle(x => x.TeachingMaterialPoolID == inventoryViewold.TeachingMaterialPoolID && x.CreateTime == inventoryViewold.CreateTime && x.PresentInventory > 0, (x => x.CF_TeachingMaterialPool));
- // int pre = (int)teachingMateriaInventoryEntity.PresentInventory;//已入库数量
- // //出库单详情
- // ET_StockOutDetail stockoutDetail = new ET_StockOutDetail();
- // stockoutDetail.StockOutDetailID = Guid.NewGuid();
- // stockoutDetail.StockOutID = stockOut.StockOutID;
- // stockoutDetail.TeachingMaterialPoolID = inventoryViewold.TeachingMaterialPoolID;
- // stockoutDetail.StockOutQuantity = pre;
- // stockoutDetail.Discount = teachingMateriaInventoryEntity.Discount;
- // stockoutDetail.DiscountPrice = Math.Round((decimal)(teachingMateriaInventoryEntity.Discount / teachingMateriaInventoryEntity.CF_TeachingMaterialPool.Price), 2);
- // SetNewStatus(stockoutDetail);
- // stockOut.ET_StockOutDetail.Add(stockoutDetail);
- // teachingMateriaInventoryEntity.PresentInventory = 0;
- // teachingMateriaInventoryEntity.ModifyTime = DateTime.Now;
- // ET_TeachingMateriaInventory teachingMateriaInventoryEntitytwo = TeachingMateriaInventoryRepository.GetSingle(x => x.TeachingMaterialPoolID == inventoryView.TeachingMaterialPoolID && x.CreateTime == inventoryView.CreateTime && x.PresentInventory > 0, (x => x.CF_TeachingMaterialPool));
- // //出库单详情
- // ET_StockOutDetail stockoutDetailtwo = new ET_StockOutDetail();
- // stockoutDetailtwo.StockOutDetailID = Guid.NewGuid();
- // stockoutDetailtwo.StockOutID = stockOut.StockOutID;
- // stockoutDetailtwo.TeachingMaterialPoolID = inventoryView.TeachingMaterialPoolID;
- // stockoutDetailtwo.StockOutQuantity = distributeQty - pre;
- // stockoutDetailtwo.Discount = teachingMateriaInventoryEntity.Discount;
- // stockoutDetail.DiscountPrice = Math.Round((decimal)(teachingMateriaInventoryEntity.Discount / teachingMateriaInventoryEntity.CF_TeachingMaterialPool.Price), 2);
- // SetNewStatus(stockoutDetailtwo);
- // stockOut.ET_StockOutDetail.Add(stockoutDetailtwo);
- // teachingMateriaInventoryEntitytwo.PresentInventory = teachingMateriaInventoryEntitytwo.PresentInventory - (distributeQty - pre);
- // teachingMateriaInventoryEntitytwo.ModifyTime = DateTime.Now;
- // break;
- // }
- // }
- // else
- // {
- // continue;
- // }
- //}
- }
- else {
- throw new Exception("征订数量大于当前库存量!");
- }
- //ET_TeachingMateriaInventory teachingMateriaInventoryEntity = TeachingMateriaInventoryRepository.GetSingle(x => x.TeachingMaterialPoolID == studentDistributeEntity.TeachingMaterialPoolID);
- //if (teachingMateriaInventoryEntity != null)
- //{
- // int distributeQty = studentDistributeEntity.DistributeQty - studentDistributeEntity.CF_Student.Count();//用学生总人数-未发人数
- // if (teachingMateriaInventoryEntity.PresentInventory <= 0)
- // {
- // throw new Exception("该教材库存量为0,不能进行出库!");
- // }
- // if (teachingMateriaInventoryEntity.PresentInventory < distributeQty)
- // {
- // throw new Exception("征订数量大于当前库存量!");
- // }
- // //2.0 当前库存量+入库数量 当前库存量-出库数量
- // teachingMateriaInventoryEntity.PresentInventory = teachingMateriaInventoryEntity.PresentInventory - distributeQty;
- // teachingMateriaInventoryEntity.ModifyTime = DateTime.Now;
- // UnitOfWork.Update(teachingMateriaInventoryEntity);//更新库存数量
- //}
- // BalanceInventory(studentDistributeEntity);
- if (studentDistributeEntity != null)
- {
- studentDistributeEntity.RecipientUser = studentDistributeView.RecipientUser;//领书人
- studentDistributeEntity.StudentDistributeNo = studentDistributeView.StudentDistributeNo;//出库单据号
- studentDistributeEntity.RecordStatus = (int)CF_GeneralPurpose.IsYes;//设置状态已提交!
- studentDistributeEntity.Remark = studentDistributeView.Remark;
- }
- UnitOfWork.Add(stockOut);
- }
- UnitOfWork.Commit();
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- #endregion
- #region 14.0 平衡教材库存数量(适用与出库、入库)
- public void BalanceInventory(ET_StudentDistribute studentDistribute)
- {
- ET_StudentDistribute studentDistributeEntity = StudentDistributeRepository.GetSingle(x => x.StudentDistributeID == studentDistribute.StudentDistributeID, (x => x.ET_StudentDistribute_CF_Student));
- ET_TeachingMateriaInventory teachingMateriaInventoryEntity = TeachingMateriaInventoryRepository.GetSingle(x => x.TeachingMaterialPoolID == studentDistribute.TeachingMaterialPoolID);
- if (teachingMateriaInventoryEntity != null)
- {
- int distributeQty = studentDistributeEntity.DistributeQty - studentDistributeEntity.ET_StudentDistribute_CF_Student.Count();//用学生总人数-未发人数
- if (teachingMateriaInventoryEntity.PresentInventory <= 0)
- {
- throw new Exception("该教材库存量为0,不能进行出库!");
- }
- if (teachingMateriaInventoryEntity.PresentInventory < distributeQty)
- {
- throw new Exception("征订数量大于当前库存量!");
- }
- //2.0 当前库存量+入库数量 当前库存量-出库数量
- teachingMateriaInventoryEntity.PresentInventory = teachingMateriaInventoryEntity.PresentInventory - distributeQty;
- teachingMateriaInventoryEntity.ModifyTime = DateTime.Now;
- UnitOfWork.Update(teachingMateriaInventoryEntity);//更新库存数量
- UnitOfWork.Commit();
- }
- }
- #endregion
- //发放清单列表
- public IGridResultSet<StudentDistributeView> GetStudentDistributeDetailViewList(Guid? studentDistributeID, int pageIndex, int pageSize)
- {
- var query = StudentDistributeDAL.GetStudentQueryableByStudentDistributeID(x => x.StudentDistributeID == studentDistributeID);
- query = query.Where(x => x.StudentNo != null);
- return query.OrderBy(x => x.StudentNo.Length).ThenBy(x => x.StudentNo).ToGridResultSet<StudentDistributeView>(pageIndex, pageSize);
- }
- public IList<StudentDistributeView> GetStudentDistributeDetailQuery(Guid? studentDistributeID)
- {
- var query = StudentDistributeDAL.GetStudentQueryableByStudentDistributeID(x => x.StudentDistributeID == studentDistributeID);
- query = query.Where(x => x.StudentNo != null);
- return query.OrderBy(x => x.StudentNo.Length).ThenBy(x => x.StudentNo).ToList();
- }
- }
- }
|