SupDocumentServices.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Bowin.Common.Linq.Entity;
  6. using EMIS.ViewModel.SupervisionManage;
  7. using EMIS.ViewModel;
  8. using System.Linq.Expressions;
  9. using EMIS.Entities;
  10. using Bowin.Common.Linq;
  11. using EMIS.DataLogic.SupervisionManage;
  12. using EMIS.CommonLogic.SystemServices;
  13. namespace EMIS.CommonLogic.SupervisionManage
  14. {
  15. public class SupDocumentServices : BaseServices, ISupDocumentServices, IFileUploadServices
  16. {
  17. public SupDocumentDAL supDocumentDAL { get; set; }
  18. public IGridResultSet<SupDocumentView> GetSupDocumentViewGrid(ConfiguretView conditionView, int? documentType, Guid? collegeID, int? pageIndex, int? pageSize)
  19. {
  20. Expression<Func<Sys_User, bool>> userExp = (x => true);
  21. Expression<Func<SUP_SupDocument, bool>> supdocumentExp = (x => true);
  22. if (collegeID.HasValue)
  23. {
  24. userExp = userExp.And(x => x.CF_Staff.CollegeID == collegeID);
  25. }
  26. if (documentType.HasValue)
  27. {
  28. supdocumentExp = supdocumentExp.And(x => x.DocumentType == documentType);
  29. }
  30. var query = supDocumentDAL.GetSupDocumentView(supdocumentExp);
  31. if (!string.IsNullOrEmpty(conditionView.ConditionValue))
  32. {
  33. query = query.DynamicWhere(conditionView.Attribute, conditionView.Condition, conditionView.ConditionValue);
  34. }
  35. query = query.OrderBy(x => x.DocumentTypeID).ThenBy(x => x.Title);
  36. return query.ToGridResultSet(pageIndex, pageSize);
  37. }
  38. public SupDocumentView GetSupDocumentView(Guid? documentID)
  39. {
  40. return supDocumentDAL.GetSupDocumentView(x => x.DocumentID == documentID).FirstOrDefault();
  41. }
  42. public List<FileUploadView> GetFileList(Guid? formID)
  43. {
  44. return supDocumentDAL.GetDocumentAttachmentQueryable(x => x.DocumentID == formID).ToList();
  45. }
  46. public void Save(SupDocumentView supDocumentView, List<FileUploadView> fileList)
  47. {
  48. try
  49. {
  50. if (fileList.Count > 1)
  51. {
  52. throw new Exception("单条记录只能上传一个文件");
  53. }
  54. if (fileList.Count() <= 0)
  55. {
  56. throw new Exception("必须上传文件");
  57. }
  58. var supDocument = new SUP_SupDocument();
  59. var dbSupDocument = supDocumentDAL.supDocumentRepository.GetSingle(x => x.DocumentID == supDocumentView.DocumentID);
  60. if (dbSupDocument != null)
  61. {
  62. supDocument = this.supDocumentDAL.supDocumentRepository
  63. .GetSingle(x => x.DocumentID == supDocumentView.DocumentID, (x => x.SUP_DocumentAttachment));
  64. UnitOfWork.Remove<SUP_DocumentAttachment>(x => x.DocumentID == supDocument.DocumentID);
  65. if (supDocument == null)
  66. {
  67. throw new Exception("当前编辑的记录可能已被其他人删除。");
  68. }
  69. SetModifyStatus(supDocument);
  70. }
  71. else
  72. {
  73. var checksupDocument = this.supDocumentDAL.supDocumentRepository.GetSingle(x => x.Title == supDocumentView.Title);
  74. if (checksupDocument != null)
  75. {
  76. throw new Exception("已存在相同标题的督导文件记录。");
  77. }
  78. supDocument.DocumentID = Guid.NewGuid();
  79. this.SetNewStatus(supDocument);
  80. UnitOfWork.Add(supDocument);
  81. }
  82. supDocument.Title = supDocumentView.Title;
  83. supDocument.DocumentType = supDocumentView.DocumentTypeID;
  84. supDocument.SUP_DocumentAttachment = new HashSet<SUP_DocumentAttachment>();
  85. fileList.ToList().ForEach(x =>
  86. {
  87. var attachment = new SUP_DocumentAttachment();
  88. attachment.DocumeAttachmentID = Guid.NewGuid();
  89. attachment.DocumentID = supDocument.DocumentID;
  90. attachment.Name = x.FileName;
  91. attachment.Url = x.FileUrl;
  92. this.SetNewStatus(attachment);
  93. UnitOfWork.Add(attachment);
  94. });
  95. UnitOfWork.Commit();
  96. }
  97. catch (Exception)
  98. {
  99. throw;
  100. }
  101. }
  102. public void Delete(IList<Guid?> documentIDList)
  103. {
  104. UnitOfWork.Delete<SUP_DocumentAttachment>(x => documentIDList.Contains(x.DocumentID));
  105. UnitOfWork.Delete<SUP_SupDocument>(x => documentIDList.Contains(x.DocumentID));
  106. }
  107. public FileUploadView GetFileUploadViewByDocumentID(Guid? documentID)
  108. {
  109. FileUploadView fileUploadView = new FileUploadView();
  110. var fileUploadViewList = supDocumentDAL.documentAttachmentRepository.GetList(x => x.DocumentID == documentID);
  111. if (fileUploadViewList != null)
  112. {
  113. fileUploadView.FileID = fileUploadViewList.FirstOrDefault().DocumeAttachmentID;
  114. fileUploadView.FileName = fileUploadViewList.FirstOrDefault().Name;
  115. fileUploadView.FileUrl = fileUploadViewList.FirstOrDefault().Url;
  116. fileUploadView.FormID = fileUploadViewList.FirstOrDefault().DocumentID;
  117. }
  118. return fileUploadView;
  119. }
  120. }
  121. }