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.

201 lines
7.1 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 MailSet_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 sEmailID = _fetchString(i_crm, @"EmailID");
  26. var oEntity = db.Queryable<OTB_SYS_Email, 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.EmailID == sEmailID)
  34. .Select((t1, t2, t3) => new OTB_SYS_Email
  35. {
  36. EmailID = SqlFunc.GetSelfAndAutoFill(t1.EmailID),
  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(MailSet_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_Email>(i_crm);
  77. _setEntityBase(oEntity, i_crm);
  78. var iRel = db.Insertable(oEntity).ExecuteCommand();
  79. rm = new SuccessResponseMessage(null, i_crm);
  80. rm.DATA.Add(BLWording.REL, iRel);
  81. } while (false);
  82. return rm;
  83. });
  84. }
  85. catch (Exception ex)
  86. {
  87. sMsg = Util.GetLastExceptionMsg(ex);
  88. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(MailSet_UpdService), @"郵件管理", @"Add(郵件管理(新增))", @"", @"", @"");
  89. }
  90. finally
  91. {
  92. if (null != sMsg)
  93. {
  94. rm = new ErrorResponseMessage(sMsg, i_crm);
  95. }
  96. }
  97. return rm;
  98. }
  99. #endregion 郵件管理(新增)
  100. #region 郵件管理(修改)
  101. /// <summary>
  102. /// 郵件管理(修改)
  103. /// </summary>
  104. /// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
  105. /// <returns></returns>
  106. public ResponseMessage Update(RequestMessage i_crm)
  107. {
  108. ResponseMessage rm = null;
  109. string sMsg = null;
  110. try
  111. {
  112. rm = SugarBase.ExecTran(db =>
  113. {
  114. do
  115. {
  116. var oNewEntity = _fetchEntity<OTB_SYS_Email>(i_crm);
  117. _setEntityBase(oNewEntity, i_crm);
  118. var iRel = db.Updateable(oNewEntity)
  119. .IgnoreColumns(x => new
  120. {
  121. x.CreateUser,
  122. x.CreateDate
  123. }).ExecuteCommand();
  124. rm = new SuccessResponseMessage(null, i_crm);
  125. rm.DATA.Add(BLWording.REL, iRel);
  126. } while (false);
  127. return rm;
  128. });
  129. }
  130. catch (Exception ex)
  131. {
  132. sMsg = Util.GetLastExceptionMsg(ex);
  133. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(MailSet_UpdService), @"郵件管理", @"Update(郵件管理(修改))", @"", @"", @"");
  134. }
  135. finally
  136. {
  137. if (null != sMsg)
  138. {
  139. rm = new ErrorResponseMessage(sMsg, i_crm);
  140. }
  141. }
  142. return rm;
  143. }
  144. #endregion 郵件管理(修改)
  145. #region 郵件管理(刪除)
  146. /// <summary>
  147. /// 郵件管理(刪除)
  148. /// </summary>
  149. /// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
  150. /// <returns></returns>
  151. public ResponseMessage Delete(RequestMessage i_crm)
  152. {
  153. ResponseMessage rm = null;
  154. string sMsg = null;
  155. try
  156. {
  157. rm = SugarBase.ExecTran(db =>
  158. {
  159. do
  160. {
  161. var sEmailID = _fetchString(i_crm, @"EmailID");
  162. var iRel = db.Deleteable<OTB_SYS_Email>().Where(x => x.OrgID == i_crm.ORIGID && x.EmailID == sEmailID).ExecuteCommand();
  163. rm = new SuccessResponseMessage(null, i_crm);
  164. rm.DATA.Add(BLWording.REL, iRel);
  165. } while (false);
  166. return rm;
  167. });
  168. }
  169. catch (Exception ex)
  170. {
  171. sMsg = Util.GetLastExceptionMsg(ex);
  172. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(MailSet_UpdService), @"郵件管理", @"Delete(郵件管理(刪除))", @"", @"", @"");
  173. }
  174. finally
  175. {
  176. if (null != sMsg)
  177. {
  178. rm = new ErrorResponseMessage(sMsg, i_crm);
  179. }
  180. }
  181. return rm;
  182. }
  183. #endregion 郵件管理(刪除)
  184. }
  185. }