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.

146 lines
6.2 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.SYS
  8. {
  9. public class ModuleMaintain_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 sModuleID = _fetchString(i_crm, @"ModuleID");
  35. var sModuleName = _fetchString(i_crm, @"ModuleName");
  36. var bExcel = _fetchBool(i_crm, @"Excel");
  37. pml.DataList = db.Queryable<OTB_SYS_ModuleList>()
  38. .Select(x => new View_SYS_ModuleList
  39. {
  40. ModuleID = SqlFunc.GetSelfAndAutoFill(x.ModuleID),
  41. ProCount = SqlFunc.ToInt32(SqlFunc.MappingColumn(x.ModuleID, "dbo.[OFN_SYS_GetProgramCountByModuleID](x.OrgID,x.ModuleID)")),
  42. OrderCount = SqlFunc.Subqueryable<OTB_SYS_ModuleList>().Where(p => p.OrgID == x.OrgID).Count()
  43. })
  44. .MergeTable()
  45. .Where(x => x.OrgID == i_crm.ORIGID && x.ModuleID.Contains(sModuleID) && x.ModuleName.Contains(sModuleName))
  46. .OrderBy(sSortField, sSortOrder)
  47. .ToPageList(pml.PageIndex, bExcel ? 100000 : pml.PageSize, ref iPageCount);
  48. pml.Total = iPageCount;
  49. rm = new SuccessResponseMessage(null, i_crm);
  50. if (bExcel)
  51. {
  52. }
  53. else
  54. {
  55. rm.DATA.Add(BLWording.REL, pml);
  56. }
  57. } while (false);
  58. }
  59. catch (Exception ex)
  60. {
  61. sMsg = Util.GetLastExceptionMsg(ex);
  62. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(ModuleMaintain_QryService), "", "QueryPage(模組管理(分頁查詢))", "", "", "");
  63. }
  64. finally
  65. {
  66. if (null != sMsg)
  67. {
  68. rm = new ErrorResponseMessage(sMsg, i_crm);
  69. }
  70. }
  71. return rm;
  72. }
  73. #endregion 模組管理(分頁查詢)
  74. #region 模組管理(更新排序)
  75. /// <summary>
  76. /// 模組管理(更新排序)
  77. /// </summary>
  78. /// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
  79. /// <returns></returns>
  80. public ResponseMessage UpdateOrderByValue(RequestMessage i_crm)
  81. {
  82. ResponseMessage rm = null;
  83. string sMsg = null;
  84. try
  85. {
  86. rm = SugarBase.ExecTran(db =>
  87. {
  88. do
  89. {
  90. var sId = _fetchString(i_crm, @"Id");
  91. var iOldOrderByValue = _fetchInt(i_crm, @"OldOrderByValue");
  92. var iNewOrderByValue = _fetchInt(i_crm, @"NewOrderByValue");
  93. var oOrderEntity = db.Queryable<OTB_SYS_ModuleList>().Single(x => x.OrgID == i_crm.ORIGID && x.ModuleID == sId);
  94. if (iNewOrderByValue > iOldOrderByValue)
  95. {
  96. var iRelUp = db.Updateable<OTB_SYS_ModuleList>()
  97. .UpdateColumns(x => new OTB_SYS_ModuleList { OrderByValue = x.OrderByValue - 1 })
  98. .Where(x => x.OrgID == oOrderEntity.OrgID && x.OrderByValue <= iNewOrderByValue && x.OrderByValue > iOldOrderByValue)
  99. .ExecuteCommand();
  100. }
  101. else
  102. {
  103. var iRelDown = db.Updateable<OTB_SYS_ModuleList>()
  104. .UpdateColumns(x => new OTB_SYS_ModuleList { OrderByValue = x.OrderByValue + 1 })
  105. .Where(x => x.OrgID == oOrderEntity.OrgID && x.OrderByValue >= iNewOrderByValue && x.OrderByValue < iOldOrderByValue)
  106. .ExecuteCommand();
  107. }
  108. var iRelSelf = db.Updateable(new OTB_SYS_ModuleList { OrderByValue = iNewOrderByValue })
  109. .UpdateColumns(x => x.OrderByValue)
  110. .Where(x => x.OrgID == i_crm.ORIGID && x.ModuleID == sId)
  111. .ExecuteCommand();
  112. rm = new SuccessResponseMessage(null, i_crm);
  113. rm.DATA.Add(BLWording.REL, iRelSelf);
  114. } while (false);
  115. return rm;
  116. });
  117. }
  118. catch (Exception ex)
  119. {
  120. sMsg = Util.GetLastExceptionMsg(ex);
  121. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(ModuleMaintain_QryService), @"模組管理", @"UpdateOrderByValue(模組管理(更新排序))", @"", @"", @"");
  122. }
  123. finally
  124. {
  125. if (null != sMsg)
  126. {
  127. rm = new ErrorResponseMessage(sMsg, i_crm);
  128. }
  129. }
  130. return rm;
  131. }
  132. #endregion 模組管理(更新排序)
  133. }
  134. }