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.

178 lines
7.5 KiB

2 years ago
  1. using EasyBL.WebApi.Message;
  2. using Entity.Sugar;
  3. using SqlSugar.Base;
  4. using System;
  5. namespace EasyBL.WEBAPP.WSM
  6. {
  7. public class News_UpdService : ServiceBase
  8. {
  9. #region 最新消息(新增)
  10. /// <summary>
  11. /// 最新消息(新增)
  12. /// </summary>
  13. /// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
  14. /// <returns></returns>
  15. public ResponseMessage Add(RequestMessage i_crm)
  16. {
  17. ResponseMessage rm = null;
  18. string sMsg = null;
  19. try
  20. {
  21. rm = SugarBase.ExecTran(db =>
  22. {
  23. do
  24. {
  25. var oEntity = _fetchEntity<OTB_WSM_News>(i_crm);
  26. _setEntityBase(oEntity, i_crm);
  27. var iOldCout = db.Queryable<OTB_WSM_News>()
  28. .Count(x => x.OrgID == i_crm.ORIGID && x.News_LanguageType == oEntity.News_LanguageType && x.News_Type == oEntity.News_Type);
  29. if (oEntity.OrderByValue <= iOldCout)
  30. {
  31. var iRelUp = db.Updateable<OTB_WSM_News>()
  32. .UpdateColumns(x => new OTB_WSM_News { OrderByValue = x.OrderByValue + 1 })
  33. .Where(x => x.OrgID == i_crm.ORIGID && x.News_LanguageType == oEntity.News_LanguageType && x.News_Type == oEntity.News_Type && x.OrderByValue >= oEntity.OrderByValue)
  34. .ExecuteCommand();
  35. }
  36. var iRel = db.Insertable(oEntity).ExecuteCommand();
  37. rm = new SuccessResponseMessage(null, i_crm);
  38. rm.DATA.Add(BLWording.REL, iRel);
  39. } while (false);
  40. return rm;
  41. });
  42. }
  43. catch (Exception ex)
  44. {
  45. sMsg = Util.GetLastExceptionMsg(ex);
  46. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(News_UpdService), @"最新消息", @"Add(最新消息(新增))", @"", @"", @"");
  47. }
  48. finally
  49. {
  50. if (null != sMsg)
  51. {
  52. rm = new ErrorResponseMessage(sMsg, i_crm);
  53. }
  54. }
  55. return rm;
  56. }
  57. #endregion 最新消息(新增)
  58. #region 最新消息(修改)
  59. /// <summary>
  60. /// 最新消息(修改)
  61. /// </summary>
  62. /// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
  63. /// <returns></returns>
  64. public ResponseMessage Update(RequestMessage i_crm)
  65. {
  66. ResponseMessage rm = null;
  67. string sMsg = null;
  68. try
  69. {
  70. rm = SugarBase.ExecTran(db =>
  71. {
  72. do
  73. {
  74. var oNewEntity = _fetchEntity<OTB_WSM_News>(i_crm);
  75. _setEntityBase(oNewEntity, i_crm);
  76. var iOldEntity = db.Queryable<OTB_WSM_News>().Single(x => x.OrgID == i_crm.ORIGID && x.SN == oNewEntity.SN);
  77. if (oNewEntity.OrderByValue > iOldEntity.OrderByValue)
  78. {
  79. var iRelUp = db.Updateable<OTB_WSM_News>()
  80. .UpdateColumns(x => new OTB_WSM_News { OrderByValue = x.OrderByValue - 1 })
  81. .Where(x => x.OrgID == oNewEntity.OrgID && x.News_LanguageType == oNewEntity.News_LanguageType && x.News_Type == oNewEntity.News_Type && x.OrderByValue <= oNewEntity.OrderByValue && x.OrderByValue > iOldEntity.OrderByValue).ExecuteCommand();
  82. }
  83. else
  84. {
  85. var iRelDown = db.Updateable<OTB_WSM_News>()
  86. .UpdateColumns(x => new OTB_WSM_News { OrderByValue = x.OrderByValue + 1 })
  87. .Where(x => x.OrgID == oNewEntity.OrgID && x.News_LanguageType == oNewEntity.News_LanguageType && x.News_Type == oNewEntity.News_Type && x.OrderByValue >= oNewEntity.OrderByValue && x.OrderByValue < iOldEntity.OrderByValue).ExecuteCommand();
  88. }
  89. var iRel = db.Updateable(oNewEntity)
  90. .IgnoreColumns(x => new
  91. {
  92. x.OrgID,
  93. x.CreateUser,
  94. x.CreateDate
  95. }).ExecuteCommand();
  96. rm = new SuccessResponseMessage(null, i_crm);
  97. rm.DATA.Add(BLWording.REL, iRel);
  98. } while (false);
  99. return rm;
  100. });
  101. }
  102. catch (Exception ex)
  103. {
  104. sMsg = Util.GetLastExceptionMsg(ex);
  105. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(News_UpdService), @"最新消息", @"Update(最新消息(修改))", @"", @"", @"");
  106. }
  107. finally
  108. {
  109. if (null != sMsg)
  110. {
  111. rm = new ErrorResponseMessage(sMsg, i_crm);
  112. }
  113. }
  114. return rm;
  115. }
  116. #endregion 最新消息(修改)
  117. #region 最新消息(刪除)
  118. /// <summary>
  119. /// 最新消息(刪除)
  120. /// </summary>
  121. /// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
  122. /// <returns></returns>
  123. public ResponseMessage Delete(RequestMessage i_crm)
  124. {
  125. ResponseMessage rm = null;
  126. string sMsg = null;
  127. try
  128. {
  129. rm = SugarBase.ExecTran(db =>
  130. {
  131. do
  132. {
  133. var iId = _fetchInt(i_crm, @"Id");
  134. var oEntity = db.Queryable<OTB_WSM_News>().Single(x => x.SN == iId);
  135. var iRel = db.Deleteable<OTB_WSM_News>().Where(x => x.SN == iId).ExecuteCommand();
  136. var iRelUp = db.Updateable<OTB_WSM_News>()
  137. .UpdateColumns(x => new OTB_WSM_News { OrderByValue = x.OrderByValue - 1 })
  138. .Where(x => x.OrgID == oEntity.OrgID && x.News_LanguageType == oEntity.News_LanguageType && x.News_Type == oEntity.News_Type && x.OrderByValue > oEntity.OrderByValue)
  139. .ExecuteCommand();
  140. rm = new SuccessResponseMessage(null, i_crm);
  141. rm.DATA.Add(BLWording.REL, iRel);
  142. } while (false);
  143. return rm;
  144. });
  145. }
  146. catch (Exception ex)
  147. {
  148. sMsg = Util.GetLastExceptionMsg(ex);
  149. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(News_UpdService), @"最新消息", @"Delete(最新消息(刪除))", @"", @"", @"");
  150. }
  151. finally
  152. {
  153. if (null != sMsg)
  154. {
  155. rm = new ErrorResponseMessage(sMsg, i_crm);
  156. }
  157. }
  158. return rm;
  159. }
  160. #endregion 最新消息(刪除)
  161. }
  162. }