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.

182 lines
8.7 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 ProgramMaintain_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 sProgramCode = _fetchString(i_crm, @"ProgramCode");
  36. var sProgramName = _fetchString(i_crm, @"ProgramName");
  37. var sEffective = _fetchString(i_crm, @"Effective");
  38. var bExcel = _fetchBool(i_crm, @"Excel");
  39. pml.DataList = db.Queryable<OTB_SYS_ProgramList, OTB_SYS_ModuleForProgram, OTB_SYS_ModuleList>
  40. ((t1, t2, t3) =>
  41. new object[] {
  42. JoinType.Left, t1.OrgID == t2.OrgID && t1.ProgramID == t2.ProgramID,
  43. JoinType.Left, t2.OrgID == t3.OrgID && t2.ModuleID == t3.ModuleID
  44. }
  45. )
  46. .Where((t1, t2, t3) => t1.OrgID == i_crm.ORIGID && t1.ProgramID.Contains(sProgramCode) && t1.ProgramName.Contains(sProgramName) && sEffective.Contains(t1.Effective))
  47. .WhereIF(!string.IsNullOrEmpty(sModuleID), (t1, t2, t3) => t2.ModuleID == sModuleID)
  48. .Select((t1, t2, t3) => new View_SYS_ProgramList
  49. {
  50. OrgID = t1.OrgID,
  51. ProgramID = t1.ProgramID,
  52. ModuleName = t3.ModuleName,
  53. ProgramName = t1.ProgramName,
  54. ModuleID = t2.ModuleID,
  55. FilePath = t1.FilePath,
  56. ImgPath = t1.ImgPath,
  57. AllowRight = SqlFunc.Trim(t1.AllowRight),
  58. ModOrderBy = t3.OrderByValue,
  59. OrderByValue = t2.OrderByValue,
  60. ProgramType = t1.ProgramType,
  61. BackgroundCSS = t1.BackgroundCSS,
  62. GroupTag = t1.GroupTag,
  63. Effective = t1.Effective,
  64. ShowInList = t1.ShowInList,
  65. ShowInHome = t1.ShowInHome,
  66. MainTableName = t1.MainTableName,
  67. ShowTop = t1.ShowTop,
  68. Memo = t1.Memo,
  69. CreateUser = t1.CreateUser,
  70. CreateDate = t1.CreateDate,
  71. ModifyUser = t1.ModifyUser,
  72. ModifyDate = t1.ModifyDate,
  73. AllModuleID = t1.ModuleID,
  74. ProgramTypeName = SqlFunc.IF(t1.ProgramType == "P").Return("程式").ElseIF(t1.ProgramType == "R").Return("報表").End("子程式"),
  75. EffectiveName = SqlFunc.IF(t1.Effective == "Y").Return("啟用").ElseIF(t1.Effective == "N").Return("停用").End("維修中"),
  76. ShowInListName = SqlFunc.IIF(t1.ShowInList == "Y", "顯示", "不顯示"),
  77. OrderCount = SqlFunc.Subqueryable<OTB_SYS_ModuleForProgram>().Where(p => p.ModuleID == t2.ModuleID && p.OrgID == t2.OrgID).Count()
  78. })
  79. .MergeTable()
  80. .OrderBy(sSortField, sSortOrder)
  81. .ToPageList(pml.PageIndex, bExcel ? 100000 : pml.PageSize, ref iPageCount);
  82. pml.Total = iPageCount;
  83. rm = new SuccessResponseMessage(null, i_crm);
  84. if (bExcel)
  85. {
  86. }
  87. else
  88. {
  89. rm.DATA.Add(BLWording.REL, pml);
  90. }
  91. } while (false);
  92. }
  93. catch (Exception ex)
  94. {
  95. sMsg = Util.GetLastExceptionMsg(ex);
  96. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.WEBAPP.SYS.ProgramMaintain_QryService", "", "QueryPage(程式管理(分頁查詢))", "", "", "");
  97. }
  98. finally
  99. {
  100. if (null != sMsg)
  101. {
  102. rm = new ErrorResponseMessage(sMsg, i_crm);
  103. }
  104. }
  105. return rm;
  106. }
  107. #endregion 程式管理(分頁查詢)
  108. #region 程式管理(更新排序)
  109. /// <summary>
  110. /// 程式管理(更新排序)
  111. /// </summary>
  112. /// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
  113. /// <returns></returns>
  114. public ResponseMessage UpdateOrderByValue(RequestMessage i_crm)
  115. {
  116. ResponseMessage rm = null;
  117. string sMsg = null;
  118. try
  119. {
  120. rm = SugarBase.ExecTran(db =>
  121. {
  122. do
  123. {
  124. var sParentId = _fetchString(i_crm, @"ParentId");
  125. var sId = _fetchString(i_crm, @"Id");
  126. var iOldOrderByValue = _fetchInt(i_crm, @"OldOrderByValue");
  127. var iNewOrderByValue = _fetchInt(i_crm, @"NewOrderByValue");
  128. var oOrderEntity = db.Queryable<OTB_SYS_ModuleForProgram>()
  129. .Single(x => x.OrgID == i_crm.ORIGID && x.ModuleID == sParentId && x.ProgramID == sId);
  130. if (iNewOrderByValue > iOldOrderByValue)
  131. {
  132. var iRelUp = db.Updateable<OTB_SYS_ModuleForProgram>()
  133. .UpdateColumns(x => new OTB_SYS_ModuleForProgram { OrderByValue = x.OrderByValue - 1 })
  134. .Where(x => x.OrgID == oOrderEntity.OrgID && x.ModuleID == sParentId && x.OrderByValue <= iNewOrderByValue && x.OrderByValue > iOldOrderByValue)
  135. .ExecuteCommand();
  136. }
  137. else
  138. {
  139. var iRelDown = db.Updateable<OTB_SYS_ModuleForProgram>()
  140. .UpdateColumns(x => new OTB_SYS_ModuleForProgram { OrderByValue = x.OrderByValue + 1 })
  141. .Where(x => x.OrgID == oOrderEntity.OrgID && x.ModuleID == sParentId && x.OrderByValue >= iNewOrderByValue && x.OrderByValue < iOldOrderByValue)
  142. .ExecuteCommand();
  143. }
  144. var iRelSelf = db.Updateable(new OTB_SYS_ModuleForProgram { OrderByValue = iNewOrderByValue })
  145. .UpdateColumns(x => x.OrderByValue)
  146. .Where(x => x.OrgID == i_crm.ORIGID && x.ModuleID == sParentId && x.ProgramID == sId)
  147. .ExecuteCommand();
  148. rm = new SuccessResponseMessage(null, i_crm);
  149. rm.DATA.Add(BLWording.REL, iRelSelf);
  150. } while (false);
  151. return rm;
  152. });
  153. }
  154. catch (Exception ex)
  155. {
  156. sMsg = Util.GetLastExceptionMsg(ex);
  157. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(ArgumentMaintain_QryService), @"程式管理管理", @"UpdateOrderByValue(程式管理管理(更新排序))", @"", @"", @"");
  158. }
  159. finally
  160. {
  161. if (null != sMsg)
  162. {
  163. rm = new ErrorResponseMessage(sMsg, i_crm);
  164. }
  165. }
  166. return rm;
  167. }
  168. #endregion 程式管理(更新排序)
  169. }
  170. }