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.

158 lines
6.0 KiB

2 years ago
  1. using EasyBL.WebApi.Message;
  2. using Entity.Sugar;
  3. using SqlSugar;
  4. using SqlSugar.Base;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. namespace EasyBL.WEBAPP.SYS
  9. {
  10. public class AnnouncementList_QryService : ServiceBase
  11. {
  12. #region 公告列表(分頁查詢)
  13. /// <summary>
  14. /// 公告列表(分頁查詢)
  15. /// </summary>
  16. /// <param name="i_crm"></param>
  17. /// <returns></returns>
  18. public ResponseMessage QueryPage(RequestMessage i_crm)
  19. {
  20. ResponseMessage rm = null;
  21. string sMsg = null;
  22. var db = SugarBase.GetIntance();
  23. try
  24. {
  25. do
  26. {
  27. var pml = new PageModel
  28. {
  29. PageIndex = _fetchInt(i_crm, @"pageIndex"),
  30. PageSize = _fetchInt(i_crm, @"pageSize")
  31. };
  32. var iPageCount = 0;
  33. var sSortField = _fetchString(i_crm, @"sortField");
  34. var sSortOrder = _fetchString(i_crm, @"sortOrder");
  35. var sTitle = _fetchString(i_crm, @"Title");
  36. var sAnn_Type = _fetchString(i_crm, @"Ann_Type");
  37. var sStartDateTime = _fetchString(i_crm, @"StartDateTime");
  38. var sEndDateTime = _fetchString(i_crm, @"EndDateTime");
  39. var bExcel = _fetchBool(i_crm, @"Excel");
  40. var rStartDateTime = new DateTime();
  41. var rEndDateTime = new DateTime();
  42. if (!string.IsNullOrEmpty(sStartDateTime))
  43. {
  44. rStartDateTime = SqlFunc.ToDate(sStartDateTime);
  45. }
  46. if (!string.IsNullOrEmpty(sEndDateTime))
  47. {
  48. rEndDateTime = SqlFunc.ToDate(sEndDateTime).AddDays(1);
  49. }
  50. pml.DataList = db.Queryable<OTB_SYS_Announcement>()
  51. .Where(x => x.OrgID == i_crm.ORIGID && x.Title.Contains(sTitle))
  52. .WhereIF(!string.IsNullOrEmpty(sAnn_Type), x => x.Ann_Type == sAnn_Type)
  53. .WhereIF(!string.IsNullOrEmpty(sStartDateTime), x => x.CreateDate >= rStartDateTime.Date)
  54. .WhereIF(!string.IsNullOrEmpty(sEndDateTime), x => x.CreateDate <= rEndDateTime.Date)
  55. .OrderBy(sSortField, sSortOrder)
  56. .ToPageList(pml.PageIndex, bExcel ? 100000 : pml.PageSize, ref iPageCount);
  57. pml.Total = iPageCount;
  58. rm = new SuccessResponseMessage(null, i_crm);
  59. if (bExcel)
  60. {
  61. }
  62. else
  63. {
  64. rm.DATA.Add(BLWording.REL, pml);
  65. }
  66. } while (false);
  67. }
  68. catch (Exception ex)
  69. {
  70. sMsg = Util.GetLastExceptionMsg(ex);
  71. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.WEBAPP.SYS.AnnouncementList_QryService", "", "QueryPage(公告列表(分頁查詢))", "", "", "");
  72. }
  73. finally
  74. {
  75. if (null != sMsg)
  76. {
  77. rm = new ErrorResponseMessage(sMsg, i_crm);
  78. }
  79. }
  80. return rm;
  81. }
  82. #endregion 公告列表(分頁查詢)
  83. #region 公告列表(置頂修改)
  84. /// <summary>
  85. /// 公告列表(置頂修改)
  86. /// </summary>
  87. /// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
  88. /// <returns></returns>
  89. public ResponseMessage UpdateGoTop(RequestMessage i_crm)
  90. {
  91. ResponseMessage rm = null;
  92. string sMsg = null;
  93. try
  94. {
  95. rm = SugarBase.ExecTran(db =>
  96. {
  97. do
  98. {
  99. var oNewEntity = _fetchEntity<OTB_SYS_Announcement>(i_crm);
  100. _setEntityBase(oNewEntity, i_crm);
  101. if (oNewEntity.GoTop == true)
  102. {
  103. oNewEntity.GoTop_Time = DateTime.Now;
  104. }
  105. var command = db.Updateable(oNewEntity);
  106. if (oNewEntity.GoTop == true)
  107. {
  108. command.UpdateColumns(x => new
  109. {
  110. x.GoTop,
  111. x.GoTop_Time,
  112. x.ModifyUser,
  113. x.ModifyDate
  114. });
  115. }
  116. else
  117. {
  118. command.UpdateColumns(x => new
  119. {
  120. x.GoTop,
  121. x.ModifyUser,
  122. x.ModifyDate
  123. });
  124. }
  125. var iRel = command.ExecuteCommand();
  126. rm = new SuccessResponseMessage(null, i_crm);
  127. rm.DATA.Add(BLWording.REL, iRel);
  128. } while (false);
  129. return rm;
  130. });
  131. }
  132. catch (Exception ex)
  133. {
  134. sMsg = Util.GetLastExceptionMsg(ex);
  135. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(AnnouncementList_QryService), @"公告管理編輯", @"Update(公告列表(置頂修改))", @"", @"", @"");
  136. }
  137. finally
  138. {
  139. if (null != sMsg)
  140. {
  141. rm = new ErrorResponseMessage(sMsg, i_crm);
  142. }
  143. }
  144. return rm;
  145. }
  146. #endregion 公告列表(置頂修改)
  147. }
  148. }