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.

93 lines
4.0 KiB

2 years ago
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.SYS
  8. {
  9. public class MembersMaintain_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 sMemberID = _fetchString(i_crm, @"MemberID");
  35. var sMemberName = _fetchString(i_crm, @"MemberName");
  36. var sEffective = _fetchString(i_crm, @"Effective");
  37. var sDepartmentID = _fetchString(i_crm, @"DepartmentID");
  38. var sJobTitle = _fetchString(i_crm, @"JobTitle");
  39. var bExcel = _fetchBool(i_crm, @"Excel");
  40. pml.DataList = db.Queryable<OTB_SYS_Members, OTB_SYS_Departments, OTB_SYS_Jobtitle, OTB_SYS_Members>
  41. ((t1, t2, t3, t4) =>
  42. new object[] {
  43. JoinType.Left, t1.OrgID == t2.OrgID && t1.DepartmentID == t2.DepartmentID,
  44. JoinType.Left, t1.OrgID == t3.OrgID && t1.JobTitle == t3.JobtitleID,
  45. JoinType.Left, t1.OrgID == t4.OrgID && t1.ImmediateSupervisor == t4.MemberID
  46. }
  47. )
  48. .Where((t1, t2, t3, t4) => t1.OrgID == i_crm.ORIGID && t1.MemberID.Contains(sMemberID) && t1.MemberName.Contains(sMemberName) && sEffective.Contains(t1.Effective))
  49. .WhereIF(!string.IsNullOrEmpty(sDepartmentID), (t1, t2, t3, t4) => t1.DepartmentID == sDepartmentID)
  50. .WhereIF(!string.IsNullOrEmpty(sJobTitle), (t1, t2, t3, t4) => t1.JobTitle == sJobTitle)
  51. .Select((t1, t2, t3, t4) => new View_SYS_Members
  52. {
  53. MemberID = SqlFunc.GetSelfAndAutoFill(t1.MemberID),
  54. DepartmentName = t2.DepartmentName,
  55. JobtitleName = t3.JobtitleName,
  56. ImmediateSupervisorName = t4.MemberName
  57. })
  58. .MergeTable()
  59. .OrderBy(sSortField, sSortOrder)
  60. .ToPageList(pml.PageIndex, bExcel ? 100000 : pml.PageSize, ref iPageCount);
  61. pml.Total = iPageCount;
  62. rm = new SuccessResponseMessage(null, i_crm);
  63. if (bExcel)
  64. {
  65. }
  66. else
  67. {
  68. rm.DATA.Add(BLWording.REL, pml);
  69. }
  70. } while (false);
  71. }
  72. catch (Exception ex)
  73. {
  74. sMsg = Util.GetLastExceptionMsg(ex);
  75. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(MembersMaintain_QryService), "", "QueryPage(帳號管理(分頁查詢))", "", "", "");
  76. }
  77. finally
  78. {
  79. if (null != sMsg)
  80. {
  81. rm = new ErrorResponseMessage(sMsg, i_crm);
  82. }
  83. }
  84. return rm;
  85. }
  86. #endregion 帳號管理(分頁查詢)
  87. }
  88. }