using System; using System.Collections.Generic; using System.Linq; using System.Text; using EMIS.DataLogic.Common.Specialtymanage; using EMIS.Entities; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; using EMIS.ViewModel.Specialtymanage; using EMIS.ViewModel; using System.Text.RegularExpressions; using Bowin.Common.Utility; using EMIS.ViewModel.Cache; using EMIS.Utility; using System.Linq.Expressions; using EMIS.DataLogic.ExamManage; using EMIS.DataLogic.CerificateManage; using EMIS.CommonLogic.SystemServices; using EMIS.ViewModel.CerificateManage; using EMIS.DataLogic.Repositories; namespace EMIS.CommonLogic.CerificateManage { public class CertisfierDistributeServices : BaseServices, ICertisfierDistributeServices { public ProjectScoreRepository ProjectScoreRepository { get; set; } public CertisfierDistributeDAL Logic { get; set; } public ISerialNumberServices SerialNumberService { get; set; } public IGridResultSet GetExamProjectListViewGrid(int pageIndex, int pageSize, params EMIS.ViewModel.ConfiguretView[] configuretViews) { System.Linq.Expressions.Expression> expCampus = (x => true); var query = Logic.GetCerificateViewListOnlyGenerated(expCampus, x => true, x => true, x => true, x => true); //查询条件 foreach (var configuretView in configuretViews) { if (!string.IsNullOrEmpty(configuretView.ConditionValue)) query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } var result = query.OrderBy(x => x.ExaminationProjectID).GroupBy(x => new { x.ExaminationProjectID, x.ProjectName, }).Select(x => new ExamBatchProjectView() { ExaminationProjectID = x.Key.ExaminationProjectID.Value, Name = x.Key.ProjectName, }); return result .OrderBy(x => x.ExaminationProjectID) .ToGridResultSet(pageIndex, pageSize); } public object GetCertisfierListViewGrid(ConfiguretView examinationSubjectView, Guid? schoolyearID, Guid? examinationProjectID, Guid? collegeID, int? schoolAreaID, int? year, Guid? classmajorID, int? standardID, int? distributeTypeID, int? recordStatus, Guid? userid,int pageIndex, int pageSize) { Expression> expCertisfier = (x => true); Expression> expcol = (x => true); Expression> expgra = (x => true); Expression> expcla = (x => true); Expression> expfac = (x => true); if (schoolyearID.HasValue) { expCertisfier = expCertisfier.And(x => x.SchoolyearID == schoolyearID); } if (examinationProjectID.HasValue) { expCertisfier = expCertisfier.And(x => x.ExaminationProjectID == examinationProjectID); } if (collegeID.HasValue) { expcol = expcol.And(x => x.CollegeID == collegeID); } if (schoolAreaID.HasValue) { expgra = expgra.And(x => x.SchoolAreaID == schoolAreaID); } if (year.HasValue) { expgra = expgra.And(x => x.SchoolyearID == year); } if (classmajorID.HasValue) { expcla = expcla.And(x => x.ClassmajorID == classmajorID); } if (standardID.HasValue) { expfac = expfac.And(x => x.StandardID == standardID); } if (distributeTypeID.HasValue) { expCertisfier = expCertisfier.And(x => x.DistributeTypeID == distributeTypeID); } if (recordStatus.HasValue) { expCertisfier = expCertisfier.And(x => x.RecordStatus == recordStatus); } if (userid.HasValue) { expCertisfier = expCertisfier.And(x => x.UserID == userid); } var query = Logic.GetCerificateViewListOnlyGenerated(expCertisfier, expcol, expgra, expcla, expfac); if (!string.IsNullOrEmpty(examinationSubjectView.ConditionValue) && !string.IsNullOrEmpty(examinationSubjectView.Attribute)) query = query.DynamicWhere(examinationSubjectView.Attribute, examinationSubjectView.Condition, examinationSubjectView.ConditionValue); query = this.GetQueryByAssistant(query, (x => x.ClassmajorID), this.GetQueryByDataRangeByCollege(query)); int Count = query.Count(); int Already = query.Where(x => x.RecordStatus == (int)ER_CertisfierDistributeStatus.Complete).Count(); int NotReceived = query.Where(x => x.RecordStatus == (int)ER_CertisfierDistributeStatus.Waiting).Count(); var pages = query.OrderBy(x => x.RecordStatus).ThenByDescending(x => x.SchoolYearCode).ThenBy(x => x.ProjectName).ThenBy(x => x.SaveNo.Length).ThenBy(x => x.SaveNo).ThenBy(x => x.ClassmajorName).ThenBy(x => x.IDNumber) .ToGridResultSet(pageIndex, pageSize); return new { Count = Count, Already = Already, NotReceived = NotReceived, rows = pages.rows, pages.total }; //return query.OrderBy(x => x.Schoolyear).ThenByDescending(x => x.Years).ThenBy(x => x.IDNumber).ToGridResultSet(pageIndex, pageSize); } public ViewModel.CerificateView GetView(Guid? ViewID) { Expression> expCertisfier = (x => true); if (ViewID.HasValue) { expCertisfier = expCertisfier.And(x => x.CertisfierDistributeID == ViewID); } var query = Logic.GetCerificateViewListOnlyGenerated(expCertisfier, x => true, x => true, x => true, x => true).FirstOrDefault(); return query; } public void Edit(ViewModel.CerificateView view) { UnitOfWork.Delete(q => q.CertisfierDistributeID == view.CertisfierDistributeID); Logic.DistributeRepository.UnitOfWork.Commit(); } public void UpdateCertisfierDistributeType(ViewModel.CerificateView view) { Logic.DistributeRepository.UnitOfWork.Update(x => new ER_CertisfierDistribute() { DistributeTypeID = view.DistributeTypeID, ContactPerson = view.DistributeTypeID == (int)ER_CertisfierDistributeType.Self ? null : (view.DistributeTypeID == (int)ER_CertisfierDistributeType.Entrust ? view.EntrustDistributer : view.ContactPerson), ContactNo = view.DistributeTypeID == (int)ER_CertisfierDistributeType.Self ? null : (view.DistributeTypeID == (int)ER_CertisfierDistributeType.Entrust ? view.ContactNo : view.MailContactNo), ContactIDNo = view.ContactIDNo, Address = view.Address, ModifyTime = DateTime.Now, }, x => view.CertisfierDistributeID == x.CertisfierDistributeID); UnitOfWork.Commit(); } public ViewModel.CerificateView GetView(System.Linq.Expressions.Expression> expCampus) { var query = Logic.GetCerificateViewListOnlyGenerated(expCampus, x => true, x => true, x => true, x => true).SingleOrDefault(); return query; } public List GetList(ConfiguretView examinationSubjectView, Guid? schoolyearID, Guid? examinationProjectID, Guid? collegeID, int? schoolAreaID, int? year, Guid? classmajorID, int? standardID, int? distributeTypeID, int? recordStatus, List ids) { Expression> expCertisfier = (x => true); Expression> expcol = (x => true); Expression> expgra = (x => true); Expression> expcla = (x => true); Expression> expfac = (x => true); if (schoolyearID.HasValue) { expCertisfier = expCertisfier.And(x => x.SchoolyearID == schoolyearID); } if (examinationProjectID.HasValue) { expCertisfier = expCertisfier.And(x => x.ExaminationProjectID == examinationProjectID); } if (collegeID.HasValue) { expcol = expcol.And(x => x.CollegeID == collegeID); } if (schoolAreaID.HasValue) { expgra = expgra.And(x => x.SchoolAreaID == schoolAreaID); } if (year.HasValue) { expgra = expgra.And(x => x.SchoolyearID == year); } if (classmajorID.HasValue) { expcla = expcla.And(x => x.ClassmajorID == classmajorID); } if (standardID.HasValue) { expfac = expfac.And(x => x.StandardID == standardID); } if (distributeTypeID.HasValue) { expCertisfier = expCertisfier.And(x => x.DistributeTypeID == distributeTypeID); } if (recordStatus.HasValue) { expCertisfier = expCertisfier.And(x => x.RecordStatus == recordStatus); } if (ids.Count() > 0) { expCertisfier = expCertisfier.And(x => ids.Contains(x.CertisfierDistributeID)); } //if (userid.HasValue) //{ // expCertisfier = expCertisfier.And(x => x.UserID == userid); //} var query = Logic.GetCerificateViewListOnlyGenerated(expCertisfier, expcol, expgra, expcla, expfac); if (!string.IsNullOrEmpty(examinationSubjectView.ConditionValue) && !string.IsNullOrEmpty(examinationSubjectView.Attribute)) query = query.DynamicWhere(examinationSubjectView.Attribute, examinationSubjectView.Condition, examinationSubjectView.ConditionValue); return query.OrderBy(x => x.RecordStatus).ThenByDescending(x => x.SchoolYearCode).ThenBy(x => x.ProjectName).ThenBy(x => x.SaveNo.Length).ThenBy(x => x.SaveNo).ThenBy(x => x.ClassmajorName).ThenBy(x => x.IDNumber).ToList(); } public bool Delete(List IDs) { UnitOfWork.Delete(x => IDs.Contains(x.CertisfierDistributeID)); UnitOfWork.Commit(); return true; } public bool OpenDistribute(List IDs) { //var list = ProjectScoreRepository.GetList(x => IDs.Contains(x.ProjectScoreID)).ToList(); //var distributeList = Logic.GetCertisfierDistributByProjectScore(x => IDs.Contains(x.ProjectScoreID)).ToList(); //if (distributeList.Any(x => x.RecordStatus != (int)ER_CertisfierDistributeStatus.Making)) //{ // throw new Exception("证书已经开放领取,不能重复开放。"); //} ////判断是否已经有证书领取表的记录,没有则新增,有则更改状态 //foreach (var item in list) //{ // var distribute = distributeList.SingleOrDefault(x => x.ExaminationProjectID == item.ExaminationProjectID && x.UserID == item.UserID); // if (distribute == null) // { // distribute = new ER_CertisfierDistribute() // { // UserID = item.UserID, // CertisfierDistributeID = Guid.NewGuid(), // ExaminationProjectID = item.ExaminationProjectID, // DistributeTypeID = (int)ER_CertisfierDistributeType.Self // }; // SetNewStatus(distribute); // distribute.RecordStatus = (int)ER_CertisfierDistributeStatus.Waiting; // UnitOfWork.Add(distribute); // } // else if (distribute.RecordStatus == (int)ER_CertisfierDistributeStatus.Making) // { // distribute.RecordStatus = (int)ER_CertisfierDistributeStatus.Waiting; // } //} try { var list = Logic.DistributeRepository.Entities.Where(x => IDs.Contains(x.CertisfierDistributeID)).ToList(); list.ForEach(x => { x.RecordStatus = (int)ER_CertisfierDistributeStatus.Waiting; x.DistributeTypeID = (int)ER_CertisfierDistributeType.Self; }); UnitOfWork.Commit(); return true; } catch (Exception) { throw; } } public bool CancelOpenDistribute(List IDs) { var hasCantCancel = Logic.DistributeRepository.Entities.Any(x => IDs.Contains(x.CertisfierDistributeID) && x.RecordStatus != (int)ER_CertisfierDistributeStatus.Waiting); if (hasCantCancel) { throw new Exception("只能撤销待领证状态的信息。"); } Logic.DistributeRepository.UnitOfWork.Update(x => new ER_CertisfierDistribute() { RecordStatus = (int)ER_CertisfierDistributeStatus.Making, DistributeTypeID = null, Distributer = null, DistributeTime = null, No = null }, x => IDs.Contains(x.CertisfierDistributeID)); UnitOfWork.Commit(); return true; } public bool CancelDistribute(List IDs) { var hasCantCancel = Logic.DistributeRepository.Entities.Any(x => IDs.Contains(x.CertisfierDistributeID) && x.RecordStatus != (int)ER_CertisfierDistributeStatus.Complete); if (hasCantCancel) { throw new Exception("只能撤销已领证状态的信息。"); } Logic.DistributeRepository.UnitOfWork.Update(x => new ER_CertisfierDistribute() { RecordStatus = (int)ER_CertisfierDistributeStatus.Waiting, Distributer = null, DistributeTime = null, No = null }, x => IDs.Contains(x.CertisfierDistributeID)); UnitOfWork.Commit(); return true; } public bool ConfirmDistribute(List IDs, string Distributer) { var list = Logic.DistributeRepository.Entities.Where(x => IDs.Contains(x.CertisfierDistributeID)).ToList(); var nowTime = DateTime.Now; var distributeNo = SerialNumberService.SetDialySN(Const.EX_CERTISFIERDISTRIBUTE_NO_PREFIX, 3) .Replace(Const.EX_CERTISFIERDISTRIBUTE_NO_PREFIX, Const.EX_CERTISFIERDISTRIBUTE_NO_PREFIX + DateTime.Today.ToString("yyMMdd")); //更新状态为待领取的 foreach (var distribute in list) { if (distribute.RecordStatus == (int)ER_CertisfierDistributeStatus.Complete) { throw new Exception("待领证状态下的数据才能确认领取,如果需要重新确认领取,请先进行撤销领取操作"); } if (distribute.RecordStatus == (int)ER_CertisfierDistributeStatus.Making) { throw new Exception("只有待领证状态下的数据才能确认领取"); } if (distribute != null && distribute.RecordStatus == (int)ER_CertisfierDistributeStatus.Waiting) { distribute.RecordStatus = (int)ER_CertisfierDistributeStatus.Complete; distribute.Distributer = Distributer; distribute.DistributeTime = nowTime; distribute.No = distributeNo; //SerialNumberService.GetSN("LQ", 3, DateTime.Now.ToString("yyMMdd")); } } UnitOfWork.Commit(); return true; } /// /// Excel导入 /// /// /// /// /// /// /// public void Import(Dictionary cellheader, out int? inCount, out int? upCount, out List errdataList, out int? errCount, string sourcePhysicalPath) { try { StringBuilder errorMsg = new StringBuilder(); // 错误信息 List errList = new List(); // 1.1解析文件,存放到一个List集合里 cellheader.Remove("ErrorMessage");//移除“未导入原因”列(ErrorMessage) List enlist = NpoiExcelHelper.ExcelToEntityList(cellheader, sourcePhysicalPath, out errorMsg, out errList); cellheader.Add("ErrorMessage", "未导入原因"); //对List集合进行有效性校验 if (enlist.Count() <= 0) { throw new Exception("Excel文件数据为空,请检查。"); } Regex reg = new Regex(@"^[0-9]+([.]{1}[0-9]+){0,1}$"); //学制字段正则表达式() inCount = 0; //导入个数 upCount = 0; //更新个数 errCount = 0; //失败个数 string errorMsgStr = ""; //错误信息 List upList = new List(); //专业信息update实体List //循环检测数据列,对各数据列进行验证(必填、字典项验证、数据格式等) for (int i = 0; i < enlist.Count; i++) { CerificateView en = enlist[i]; //Excel表数据视图 CF_Specialty specialty = new CF_Specialty(); //专业信息实体 //证件号码 if (string.IsNullOrEmpty(en.IDNumber)) { errCount++; errorMsgStr = "证件号码不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } //考试项目 if (string.IsNullOrEmpty(en.ProjectName)) { errCount++; errorMsgStr = "考试项目不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } //邮寄单号 if (string.IsNullOrEmpty(en.DeliveryNoteNo)) { errCount++; errorMsgStr = "邮寄单号不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } var entity = Logic.GetCerificateViewListOnlyGenerated(x => true, x => true, x => true, x => true, x => true).Where(x => x.ProjectName == en.ProjectName && x.IDNumber == en.IDNumber).FirstOrDefault(); if (entity == null) { errCount++; errorMsgStr = "找不到考试项目和对应的学生"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } if (entity.RecordStatus == (int)ER_CertisfierDistributeStatus.Making) { errCount++; errorMsgStr = "制证中不允许导入"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } UnitOfWork.Update(x => new ER_CertisfierDistribute() { DeliveryNoteNo = en.DeliveryNoteNo, ContactPerson = en.ContactPerson, ContactNo = en.ContactNo, Address = en.Address, RecordStatus = (int)ER_CertisfierDistributeStatus.Complete }, x => x.CertisfierDistributeID == entity.CertisfierDistributeID); upCount++; } UnitOfWork.Commit(); errdataList = errList.Distinct().ToList(); //错误列表List } catch (Exception ex) { //目前会出现,由于错误信息字符太长,无法抛出弹出框的问题 throw new Exception(ex.Message); } } public IGridResultSet GetCertificateMobileViewGrid(int? pageIndex, int? pageSize, Guid userID) { Expression> exp = (x => x.UserID == userID); Expression> detailExp = (x => true); var certificateViewList = this.Logic.GetCertificateMobileViewQueryable(exp) .OrderBy(x => x.DistributeStatusID).ToGridResultSet(pageIndex, pageSize); if (pageSize.HasValue && pageIndex.HasValue) { var projectScoreIDList = certificateViewList.rows.Select(x => x.ProjectScoreID).ToList(); //detailExp = (x => projectScoreIDList.Contains(x.ProjectScoreID)); } else { detailExp = exp; } //var scoreList = this.Logic.GetCertificateMobileScoreViewQueryable(exp).ToList(); //certificateViewList.rows.ForEach(x => //{ // var curScoreList = scoreList.Where(w => w.ExaminationProjectID == x.ExaminationProjectID).ToList(); // x.ScoreViewList = curScoreList; //}); return certificateViewList; } /// /// 存放编号导入 /// /// /// /// /// /// /// public void NumberImport(Dictionary cellheader, out int? inCount, out int? upCount, out List errdataList, out int? errCount, string sourcePhysicalPath) { try { StringBuilder errorMsg = new StringBuilder(); // 错误信息 List errList = new List(); var CerificateList = Logic.DistributeRepository.Entities.ToList(); var CerificateViewList = Logic.GetCerificateViewListOnlyGenerated(x => true, x => true, x => true, x => true, x => true).ToList(); var ProjectList = Logic.ExaminationProjectRepository.Entities.ToList(); var studentList = Logic.StudentRepository.Entities.ToList(); var userList = Logic.UserRepository.Entities.ToList(); // 1.1解析文件,存放到一个List集合里 cellheader.Remove("ErrorMessage");//移除“未导入原因”列(ErrorMessage) List enlist = NpoiExcelHelper.ExcelToEntityList(cellheader, sourcePhysicalPath, out errorMsg, out errList); cellheader.Add("ErrorMessage", "未导入原因"); //对List集合进行有效性校验 if (enlist.Count() <= 0) { throw new Exception("Excel文件数据为空,请检查。"); } Regex reg = new Regex(@"^[0-9]+([.]{1}[0-9]+){0,1}$"); //学制字段正则表达式() inCount = 0; //导入个数 upCount = 0; //更新个数 errCount = 0; //失败个数 string errorMsgStr = ""; //错误信息 List upList = new List(); //专业信息update实体List //循环检测数据列,对各数据列进行验证(必填、字典项验证、数据格式等) for (int i = 0; i < enlist.Count; i++) { CerificateView en = enlist[i]; //Excel表数据视图 //证件号码 if (string.IsNullOrEmpty(en.IDNumber)) { errCount++; errorMsgStr = "证件号码不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else if (!studentList.Any(x => x.IDNumber.Trim() == en.IDNumber.Trim())) { errCount++; errorMsgStr = "学生不存在,请检查证件号码"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } //考试项目 if (string.IsNullOrEmpty(en.ProjectName)) { errCount++; errorMsgStr = "考试项目不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else if (!ProjectList.Any(x => x.Name.Trim() == en.ProjectName.Trim())) { errCount++; errorMsgStr = "考试项目不存在,请检查考试项目名称"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } var entity = CerificateViewList.Where(x => x.ProjectName.Trim() == en.ProjectName.Trim() && x.IDNumber.Trim() == en.IDNumber.Trim()).FirstOrDefault(); if (entity == null) { errCount++; errorMsgStr = "找不到考试项目和对应的学生,请检查该学生是否有该项目的证书"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } if (entity.RecordStatus == (int)ER_CertisfierDistributeStatus.Making || entity.RecordStatus == null) { errCount++; errorMsgStr = "制证中的证书无法导入存放编号"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } //if (entity.RecordStatus == (int)ER_CertisfierDistributeStatus.Making) //{ // errCount++; // errorMsgStr = "制证中不允许导入"; // en.ErrorMessage = errorMsgStr; // errList.Add(en); // errorMsg.AppendLine(errorMsgStr); // continue; //} //UnitOfWork.Update(x => new ER_CertisfierDistribute() { DeliveryNoteNo = en.DeliveryNoteNo, ContactPerson = en.ContactPerson, ContactNo = en.ContactNo, Address = en.Address, RecordStatus = (int)ER_CertisfierDistributeStatus.Complete }, x => x.CertisfierDistributeID == entity.CertisfierDistributeID); //CerificateList.FirstOrDefault(x => x.) var Cerificate = CerificateList.FirstOrDefault(x => x.ExaminationProjectID == entity.ExaminationProjectID && x.UserID == entity.UserID); Cerificate.SaveNo = en.SaveNo; upList.Add(Cerificate); upCount++; } UnitOfWork.BatchUpdate(upList); errdataList = errList.Distinct().ToList(); //错误列表List } catch (Exception ex) { //目前会出现,由于错误信息字符太长,无法抛出弹出框的问题 throw new Exception(ex.Message); } } } }