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.

206 lines
7.6 KiB

2 years ago
  1. using EasyBL.WebApi.Message;
  2. using Entity.Sugar;
  3. using SqlSugar;
  4. using SqlSugar.Base;
  5. using System;
  6. namespace EasyBL.WEBAPP.WSM
  7. {
  8. public class Announcement_UpdService : ServiceBase
  9. {
  10. #region 公告管理編輯(單筆查詢)
  11. /// <summary>
  12. /// 公告管理編輯(單筆查詢)
  13. /// </summary>
  14. /// <param name="i_crm"></param>
  15. /// <returns></returns>
  16. public ResponseMessage QueryOne(RequestMessage i_crm)
  17. {
  18. ResponseMessage rm = null;
  19. string sMsg = null;
  20. var db = SugarBase.GetIntance();
  21. try
  22. {
  23. do
  24. {
  25. var sAnnouncementID = _fetchString(i_crm, @"AnnouncementID");
  26. var oEntity = db.Queryable<OTB_SYS_Announcement, OTB_SYS_Members, OTB_SYS_Members>
  27. ((t1, t2, t3) =>
  28. new object[] {
  29. JoinType.Left, t1.OrgID == t2.OrgID && t1.CreateUser == t2.MemberID,
  30. JoinType.Left, t1.OrgID == t3.OrgID && t1.ModifyUser == t3.MemberID
  31. }
  32. )
  33. .Where((t1, t2, t3) => t1.OrgID == i_crm.ORIGID && t1.AnnouncementID == sAnnouncementID)
  34. .Select((t1, t2, t3) => new OTB_SYS_Announcement
  35. {
  36. AnnouncementID = SqlFunc.GetSelfAndAutoFill(t1.AnnouncementID),
  37. CreateUserName = t2.MemberName,
  38. ModifyUserName = t3.MemberName
  39. })
  40. .Single();
  41. rm = new SuccessResponseMessage(null, i_crm);
  42. rm.DATA.Add(BLWording.REL, oEntity);
  43. } while (false);
  44. }
  45. catch (Exception ex)
  46. {
  47. sMsg = Util.GetLastExceptionMsg(ex);
  48. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(Announcement_UpdService), "", "QueryOne(公告管理編輯(單筆查詢))", "", "", "");
  49. }
  50. finally
  51. {
  52. if (null != sMsg)
  53. {
  54. rm = new ErrorResponseMessage(sMsg, i_crm);
  55. }
  56. }
  57. return rm;
  58. }
  59. #endregion 公告管理編輯(單筆查詢)
  60. #region 公告管理編輯(新增)
  61. /// <summary>
  62. /// 公告管理編輯(新增)
  63. /// </summary>
  64. /// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
  65. /// <returns></returns>
  66. public ResponseMessage Insert(RequestMessage i_crm)
  67. {
  68. ResponseMessage rm = null;
  69. string sMsg = null;
  70. try
  71. {
  72. rm = SugarBase.ExecTran(db =>
  73. {
  74. do
  75. {
  76. var oEntity = _fetchEntity<OTB_SYS_Announcement>(i_crm);
  77. _setEntityBase(oEntity, i_crm);
  78. oEntity.AnnouncementID = Guid.NewGuid().ToString();
  79. oEntity.GoTop = false;
  80. oEntity.GoTop_Time = DateTime.Now;
  81. var oRes = db.Insertable(oEntity).ExecuteReturnEntity();
  82. rm = new SuccessResponseMessage(null, i_crm);
  83. rm.DATA.Add(BLWording.REL, oRes);
  84. } while (false);
  85. return rm;
  86. });
  87. }
  88. catch (Exception ex)
  89. {
  90. sMsg = Util.GetLastExceptionMsg(ex);
  91. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(Announcement_UpdService), @"公告管理編輯", @"Add(公告管理編輯(新增))", @"", @"", @"");
  92. }
  93. finally
  94. {
  95. if (null != sMsg)
  96. {
  97. rm = new ErrorResponseMessage(sMsg, i_crm);
  98. }
  99. }
  100. return rm;
  101. }
  102. #endregion 公告管理編輯(新增)
  103. #region 公告管理編輯(修改)
  104. /// <summary>
  105. /// 公告管理編輯(修改)
  106. /// </summary>
  107. /// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
  108. /// <returns></returns>
  109. public ResponseMessage Update(RequestMessage i_crm)
  110. {
  111. ResponseMessage rm = null;
  112. string sMsg = null;
  113. try
  114. {
  115. rm = SugarBase.ExecTran(db =>
  116. {
  117. do
  118. {
  119. var oNewEntity = _fetchEntity<OTB_SYS_Announcement>(i_crm);
  120. _setEntityBase(oNewEntity, i_crm);
  121. var iRel = db.Updateable(oNewEntity)
  122. .IgnoreColumns(x => new
  123. {
  124. x.CreateUser,
  125. x.CreateDate,
  126. x.GoTop,
  127. x.GoTop_Time
  128. }).ExecuteCommand();
  129. rm = new SuccessResponseMessage(null, i_crm);
  130. rm.DATA.Add(BLWording.REL, iRel);
  131. } while (false);
  132. return rm;
  133. });
  134. }
  135. catch (Exception ex)
  136. {
  137. sMsg = Util.GetLastExceptionMsg(ex);
  138. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(Announcement_UpdService), @"公告管理編輯", @"Update(公告管理編輯(修改))", @"", @"", @"");
  139. }
  140. finally
  141. {
  142. if (null != sMsg)
  143. {
  144. rm = new ErrorResponseMessage(sMsg, i_crm);
  145. }
  146. }
  147. return rm;
  148. }
  149. #endregion 公告管理編輯(修改)
  150. #region 公告管理編輯(刪除)
  151. /// <summary>
  152. /// 公告管理編輯(刪除)
  153. /// </summary>
  154. /// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
  155. /// <returns></returns>
  156. public ResponseMessage Delete(RequestMessage i_crm)
  157. {
  158. ResponseMessage rm = null;
  159. string sMsg = null;
  160. try
  161. {
  162. rm = SugarBase.ExecTran(db =>
  163. {
  164. do
  165. {
  166. var sAnnouncementID = _fetchString(i_crm, @"AnnouncementID");
  167. var iRel = db.Deleteable<OTB_SYS_Announcement>()
  168. .Where(x => x.OrgID == i_crm.ORIGID && x.AnnouncementID == sAnnouncementID).ExecuteCommand();
  169. rm = new SuccessResponseMessage(null, i_crm);
  170. rm.DATA.Add(BLWording.REL, iRel);
  171. } while (false);
  172. return rm;
  173. });
  174. }
  175. catch (Exception ex)
  176. {
  177. sMsg = Util.GetLastExceptionMsg(ex);
  178. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(Announcement_UpdService), @"公告管理編輯", @"Delete(公告管理編輯(刪除))", @"", @"", @"");
  179. }
  180. finally
  181. {
  182. if (null != sMsg)
  183. {
  184. rm = new ErrorResponseMessage(sMsg, i_crm);
  185. }
  186. }
  187. return rm;
  188. }
  189. #endregion 公告管理編輯(刪除)
  190. }
  191. }