You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

159 lines
7.0 KiB

2 years ago
  1. using EasyBL.WebApi.Message;
  2. using Entity.Sugar;
  3. using Entity.ViewModels;
  4. using SqlSugar;
  5. using SqlSugar.Base;
  6. using System;
  7. namespace EasyBL.WEBAPP.EIP
  8. {
  9. public class TravelExpenseReport_QryService : ServiceBase
  10. {
  11. #region 國外差旅費報告書分頁查詢
  12. /// <summary>
  13. /// 國外差旅費報告書分頁查詢
  14. /// </summary>
  15. /// <param name="i_crm"></param>
  16. /// <returns></returns>
  17. public ResponseMessage QueryPage(RequestMessage i_crm)
  18. {
  19. ResponseMessage rm = null;
  20. string sMsg = null;
  21. var db = SugarBase.GetIntance();
  22. try
  23. {
  24. do
  25. {
  26. var pml = new PageModel
  27. {
  28. PageIndex = _fetchInt(i_crm, @"pageIndex"),
  29. PageSize = _fetchInt(i_crm, @"pageSize")
  30. };
  31. var iPageCount = 0;
  32. var sSortField = _fetchString(i_crm, @"sortField");
  33. var sSortOrder = _fetchString(i_crm, @"sortOrder");
  34. var sKeyNote = _fetchString(i_crm, @"KeyNote");
  35. var sApplicant = _fetchString(i_crm, @"Applicant");
  36. var sImportant = _fetchString(i_crm, @"Important");
  37. var sStatus = _fetchString(i_crm, @"Status");
  38. var sRoles = _fetchString(i_crm, @"Roles");
  39. var bExcel = _fetchBool(i_crm, @"Excel");
  40. pml.DataList = db.Queryable<OTB_EIP_TravelExpense, OTB_SYS_Members, OTB_SYS_Departments, OTB_SYS_Members>
  41. ((t1, t2, t3, t4) =>
  42. new object[] {
  43. JoinType.Inner, t1.OrgID == t2.OrgID && t1.Applicant == t2.MemberID,
  44. JoinType.Inner, t2.OrgID == t3.OrgID && t2.DepartmentID == t3.DepartmentID,
  45. JoinType.Inner, t1.OrgID == t4.OrgID && t1.Handle_Person == t4.MemberID
  46. }
  47. )
  48. .Where((t1, t2, t3, t4) => t1.OrgID == i_crm.ORIGID && t1.KeyNote.Contains(sKeyNote) && sImportant.Contains(t1.Important))
  49. //.Where((t1, t2, t3, t4) => t1.OrgID == i_crm.ORIGID )
  50. .WhereIF(!string.IsNullOrEmpty(sApplicant), (t1, t2, t3, t4) => t1.Applicant == sApplicant)
  51. .WhereIF(!string.IsNullOrEmpty(sStatus), (t1, t2, t3, t4) => sStatus.Contains(t1.Status))
  52. .WhereIF(!(sRoles.Contains("Admin") || sRoles.Contains("EipManager") || sRoles.Contains("EipView")), (t1, t2, t3, t4) => (t1.Applicant == i_crm.USERID || t1.Handle_Person == i_crm.USERID || t1.CheckFlows.Contains(i_crm.USERID)))
  53. .Select((t1, t2, t3, t4) => new View_EIP_TravelExpense
  54. {
  55. Guid = SqlFunc.GetSelfAndAutoFill(t1.Guid),
  56. ApplicantName = t2.MemberName,
  57. DeptName = t3.DepartmentName,
  58. Handle_PersonName = t4.MemberName
  59. })
  60. .MergeTable()
  61. .OrderBy(sSortField, sSortOrder)
  62. .ToPageList(pml.PageIndex, bExcel ? 100000 : pml.PageSize, ref iPageCount);
  63. pml.Total = iPageCount;
  64. rm = new SuccessResponseMessage(null, i_crm);
  65. if (bExcel)
  66. {
  67. }
  68. else
  69. {
  70. rm.DATA.Add(BLWording.REL, pml);
  71. }
  72. } while (false);
  73. }
  74. catch (Exception ex)
  75. {
  76. sMsg = Util.GetLastExceptionMsg(ex);
  77. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.WEBAPP.EIP.TravelExpenseReport_QryService", "", "QueryPage(國外差旅費報告書分頁查詢)", "", "", "");
  78. }
  79. finally
  80. {
  81. if (null != sMsg)
  82. {
  83. rm = new ErrorResponseMessage(sMsg, i_crm);
  84. }
  85. }
  86. return rm;
  87. }
  88. #endregion 國外差旅費報告書分頁查詢
  89. #region 國外差旅費報告書單筆查詢
  90. /// <summary>
  91. /// 國外差旅費報告書單筆查詢
  92. /// </summary>
  93. /// <param name="i_crm"></param>
  94. /// <returns></returns>
  95. public ResponseMessage QueryOne(RequestMessage i_crm)
  96. {
  97. ResponseMessage rm = null;
  98. string sMsg = null;
  99. var db = SugarBase.GetIntance();
  100. try
  101. {
  102. do
  103. {
  104. var sId = _fetchString(i_crm, @"Guid");
  105. var oEntity = db.Queryable<OTB_EIP_TravelExpense, OTB_SYS_Members, OTB_SYS_Departments, OTB_SYS_Members>
  106. ((t1, t2, t3, t4) =>
  107. new object[] {
  108. JoinType.Inner, t1.OrgID == t2.OrgID && t1.Applicant == t2.MemberID,
  109. JoinType.Inner, t2.OrgID == t3.OrgID && t2.DepartmentID == t3.DepartmentID,
  110. JoinType.Inner, t1.OrgID == t4.OrgID && t1.Handle_Person == t4.MemberID
  111. }
  112. )
  113. .Where((t1, t2, t3, t4) => t1.OrgID == i_crm.ORIGID && t1.Guid == sId)
  114. .Select((t1, t2, t3, t4) => new View_EIP_TravelExpense
  115. {
  116. Guid = SqlFunc.GetSelfAndAutoFill(t1.Guid),
  117. ApplicantName = t2.MemberName,
  118. DeptName = t3.DepartmentName,
  119. Handle_PersonName = t4.MemberName
  120. }).Single();
  121. if (!string.IsNullOrEmpty(oEntity.RelationId))
  122. {
  123. var oRelation = db.Queryable<OTB_EIP_TravelExpense>().Single(x => x.OrgID == i_crm.ORIGID && x.Guid == oEntity.RelationId);
  124. if (oRelation != null)
  125. {
  126. oEntity.ExFeild1 = oRelation.KeyNote;
  127. }
  128. }
  129. rm = new SuccessResponseMessage(null, i_crm);
  130. rm.DATA.Add(BLWording.REL, oEntity);
  131. } while (false);
  132. }
  133. catch (Exception ex)
  134. {
  135. sMsg = Util.GetLastExceptionMsg(ex);
  136. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.WEBAPP.EIP.TravelExpenseReport_QryService", "", "QueryOne(國外差旅費報告書單筆查詢)", "", "", "");
  137. }
  138. finally
  139. {
  140. if (null != sMsg)
  141. {
  142. rm = new ErrorResponseMessage(sMsg, i_crm);
  143. }
  144. }
  145. return rm;
  146. }
  147. #endregion 國外差旅費報告書單筆查詢
  148. }
  149. }