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.

248 lines
9.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 OfficeTemplate_UpdService : ServiceBase
  9. {
  10. #region Office模版管理(單筆查詢)
  11. /// <summary>
  12. /// Office模版管理(單筆查詢)
  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 sTemplID = _fetchString(i_crm, @"TemplID");
  26. var oEntity = db.Queryable<OTB_SYS_OfficeTemplate, 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.TemplID == sTemplID)
  34. .Select((t1, t2, t3) => new OTB_SYS_OfficeTemplate
  35. {
  36. TemplID = SqlFunc.GetSelfAndAutoFill(t1.TemplID),
  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(OfficeTemplate_UpdService), "", "QueryOne(Office模版管理(單筆查詢))", "", "", "");
  49. }
  50. finally
  51. {
  52. if (null != sMsg)
  53. {
  54. rm = new ErrorResponseMessage(sMsg, i_crm);
  55. }
  56. }
  57. return rm;
  58. }
  59. #endregion Office模版管理(單筆查詢)
  60. #region Office模版管理(新增)
  61. /// <summary>
  62. /// Office模版管理(新增)
  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_OfficeTemplate>(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(OfficeTemplate_UpdService), @"Office模版管理", @"Add(Office模版管理(新增))", @"", @"", @"");
  89. }
  90. finally
  91. {
  92. if (null != sMsg)
  93. {
  94. rm = new ErrorResponseMessage(sMsg, i_crm);
  95. }
  96. }
  97. return rm;
  98. }
  99. #endregion Office模版管理(新增)
  100. #region Office模版管理(修改)
  101. /// <summary>
  102. /// Office模版管理(修改)
  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_OfficeTemplate>(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(OfficeTemplate_UpdService), @"Office模版管理", @"Update(Office模版管理(修改))", @"", @"", @"");
  134. }
  135. finally
  136. {
  137. if (null != sMsg)
  138. {
  139. rm = new ErrorResponseMessage(sMsg, i_crm);
  140. }
  141. }
  142. return rm;
  143. }
  144. #endregion Office模版管理(修改)
  145. #region Office模版管理(刪除)
  146. /// <summary>
  147. /// Office模版管理(刪除)
  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 sTemplID = _fetchString(i_crm, @"TemplID");
  162. var oOfficeTemplate = db.Queryable<OTB_SYS_OfficeTemplate>().Single(x => x.TemplID == sTemplID);
  163. var iRel = db.Deleteable<OTB_SYS_OfficeTemplate>().Where(x => x.OrgID == i_crm.ORIGID && x.TemplID == sTemplID).ExecuteCommand();
  164. i_crm.DATA.Add("FileID", oOfficeTemplate.FileID);
  165. i_crm.DATA.Add("IDType", "parent");
  166. new CommonService().DelFile(i_crm);
  167. rm = new SuccessResponseMessage(null, i_crm);
  168. rm.DATA.Add(BLWording.REL, iRel);
  169. } while (false);
  170. return rm;
  171. });
  172. }
  173. catch (Exception ex)
  174. {
  175. sMsg = Util.GetLastExceptionMsg(ex);
  176. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(OfficeTemplate_UpdService), @"Office模版管理", @"Delete(Office模版管理(刪除))", @"", @"", @"");
  177. }
  178. finally
  179. {
  180. if (null != sMsg)
  181. {
  182. rm = new ErrorResponseMessage(sMsg, i_crm);
  183. }
  184. }
  185. return rm;
  186. }
  187. #endregion Office模版管理(刪除)
  188. #region Office模版管理(查詢筆數)
  189. /// <summary>
  190. /// Office模版管理(查詢筆數)
  191. /// </summary>
  192. /// <param name="i_crm"></param>
  193. /// <returns></returns>
  194. public ResponseMessage QueryCout(RequestMessage i_crm)
  195. {
  196. ResponseMessage rm = null;
  197. string sMsg = null;
  198. var db = SugarBase.GetIntance();
  199. try
  200. {
  201. do
  202. {
  203. var sTemplID = _fetchString(i_crm, @"TemplID");
  204. var iCout = db.Queryable<OTB_SYS_OfficeTemplate>()
  205. .Where(x => x.OrgID == i_crm.ORIGID)
  206. .WhereIF(!string.IsNullOrEmpty(sTemplID), x => x.TemplID == sTemplID)
  207. .Count();
  208. rm = new SuccessResponseMessage(null, i_crm);
  209. rm.DATA.Add(BLWording.REL, iCout);
  210. } while (false);
  211. }
  212. catch (Exception ex)
  213. {
  214. sMsg = Util.GetLastExceptionMsg(ex);
  215. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(OfficeTemplate_UpdService), "", "QueryCout(Office模版管理(查詢筆數))", "", "", "");
  216. }
  217. finally
  218. {
  219. if (null != sMsg)
  220. {
  221. rm = new ErrorResponseMessage(sMsg, i_crm);
  222. }
  223. }
  224. return rm;
  225. }
  226. #endregion Office模版管理(查詢筆數)
  227. }
  228. }