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.

171 lines
7.9 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.WSM
  8. {
  9. public class News_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 sNews_Type = _fetchString(i_crm, @"News_Type");
  35. var sNews_LanguageType = _fetchString(i_crm, @"News_LanguageType");
  36. var sNews_Title = _fetchString(i_crm, @"News_Title");
  37. var sNews_Show = _fetchString(i_crm, @"News_Show");
  38. var sNews_StartDate = _fetchString(i_crm, @"News_StartDate");
  39. var sNews_EndDate = _fetchString(i_crm, @"News_EndDate");
  40. var bExcel = _fetchBool(i_crm, @"Excel");
  41. var rNews_StartDate = new DateTime();
  42. var rNews_EndDate = new DateTime();
  43. if (!string.IsNullOrEmpty(sNews_StartDate))
  44. {
  45. rNews_StartDate = SqlFunc.ToDate(sNews_StartDate);
  46. }
  47. if (!string.IsNullOrEmpty(sNews_EndDate))
  48. {
  49. rNews_EndDate = SqlFunc.ToDate(sNews_EndDate).AddDays(1);
  50. }
  51. pml.DataList = db.Queryable<OTB_WSM_News, OTB_SYS_Arguments, OTB_SYS_Arguments>
  52. ((t1, t2, t3) =>
  53. new object[] {
  54. JoinType.Left, t1.OrgID == t2.OrgID && t1.News_Type == t2.ArgumentID && t2.ArgumentClassID == "News_Class",
  55. JoinType.Left, t1.OrgID == t3.OrgID && t1.News_LanguageType == t3.ArgumentID && t3.ArgumentClassID == "LanCountry"
  56. }
  57. )
  58. .Where((t1, t2, t3) => t1.OrgID == i_crm.ORIGID && t1.News_Title.Contains(sNews_Title) && sNews_Show.Contains(t1.News_Show))
  59. .WhereIF(!string.IsNullOrEmpty(sNews_Type), (t1, t2, t3) => t1.News_Type == sNews_Type)
  60. .WhereIF(!string.IsNullOrEmpty(sNews_LanguageType), (t1, t2, t3) => t1.News_LanguageType == sNews_LanguageType)
  61. .WhereIF(!string.IsNullOrEmpty(sNews_StartDate), (t1, t2, t3) => t1.News_EndDete >= rNews_StartDate.Date)
  62. .WhereIF(!string.IsNullOrEmpty(sNews_EndDate), (t1, t2, t3) => t1.News_StartDete <= rNews_EndDate.Date)
  63. .Select((t1, t2, t3) => new View_WSM_News
  64. {
  65. SN = SqlFunc.GetSelfAndAutoFill(t1.SN),
  66. News_TypeName = t2.ArgumentValue,
  67. News_LanguageTypeName = t3.ArgumentValue,
  68. OrderCount = SqlFunc.Subqueryable<OTB_WSM_News>().Where(p => p.News_LanguageType == t1.News_LanguageType && p.OrgID == t1.OrgID).Count()
  69. })
  70. .MergeTable()
  71. .OrderBy(sSortField, sSortOrder)
  72. .ToPageList(pml.PageIndex, pml.PageSize, ref iPageCount);
  73. pml.Total = iPageCount;
  74. rm = new SuccessResponseMessage(null, i_crm);
  75. if (bExcel)
  76. {
  77. }
  78. else
  79. {
  80. rm.DATA.Add(BLWording.REL, pml);
  81. }
  82. } while (false);
  83. }
  84. catch (Exception ex)
  85. {
  86. sMsg = Util.GetLastExceptionMsg(ex);
  87. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.WEBAPP.WSM.News_QryService", "", "QueryPage(最新消息(分頁查詢))", "", "", "");
  88. }
  89. finally
  90. {
  91. if (null != sMsg)
  92. {
  93. rm = new ErrorResponseMessage(sMsg, i_crm);
  94. }
  95. }
  96. return rm;
  97. }
  98. #endregion 最新消息(分頁查詢)
  99. #region 最新消息(更新排序)
  100. /// <summary>
  101. /// 最新消息(更新排序)
  102. /// </summary>
  103. /// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
  104. /// <returns></returns>
  105. public ResponseMessage UpdateOrderByValue(RequestMessage i_crm)
  106. {
  107. ResponseMessage rm = null;
  108. string sMsg = null;
  109. try
  110. {
  111. rm = SugarBase.ExecTran(db =>
  112. {
  113. do
  114. {
  115. var iId = _fetchInt(i_crm, @"Id");
  116. var iOldOrderByValue = _fetchInt(i_crm, @"OldOrderByValue");
  117. var iNewOrderByValue = _fetchInt(i_crm, @"NewOrderByValue");
  118. var oOrderEntity = db.Queryable<OTB_WSM_News>().Single(x => x.SN == iId);
  119. if (iNewOrderByValue > iOldOrderByValue)
  120. {
  121. var iRelUp = db.Updateable<OTB_WSM_News>()
  122. .UpdateColumns(x => new OTB_WSM_News { OrderByValue = x.OrderByValue - 1 })
  123. .Where(x => x.OrgID == oOrderEntity.OrgID && x.News_Type == oOrderEntity.News_Type && x.News_LanguageType == oOrderEntity.News_LanguageType && x.OrderByValue <= iNewOrderByValue && x.OrderByValue > iOldOrderByValue)
  124. .ExecuteCommand();
  125. }
  126. else
  127. {
  128. var iRelDown = db.Updateable<OTB_WSM_News>()
  129. .UpdateColumns(x => new OTB_WSM_News { OrderByValue = x.OrderByValue + 1 })
  130. .Where(x => x.OrgID == oOrderEntity.OrgID && x.News_Type == oOrderEntity.News_Type && x.News_LanguageType == oOrderEntity.News_LanguageType && x.OrderByValue >= iNewOrderByValue && x.OrderByValue < iOldOrderByValue)
  131. .ExecuteCommand();
  132. }
  133. var iRelSelf = db.Updateable(new OTB_WSM_News { OrderByValue = iNewOrderByValue })
  134. .UpdateColumns(x => x.OrderByValue)
  135. .Where(x => x.SN == iId).ExecuteCommand();
  136. rm = new SuccessResponseMessage(null, i_crm);
  137. rm.DATA.Add(BLWording.REL, iRelSelf);
  138. } while (false);
  139. return rm;
  140. });
  141. }
  142. catch (Exception ex)
  143. {
  144. sMsg = Util.GetLastExceptionMsg(ex);
  145. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(WebSiteSetupService), @"最新消息", @"UpdateOrderByValue(最新消息(更新排序))", @"", @"", @"");
  146. }
  147. finally
  148. {
  149. if (null != sMsg)
  150. {
  151. rm = new ErrorResponseMessage(sMsg, i_crm);
  152. }
  153. }
  154. return rm;
  155. }
  156. #endregion 最新消息(更新排序)
  157. }
  158. }