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.

218 lines
8.0 KiB

2 years ago
  1. using EasyBL.WebApi.Message;
  2. using EasyNet;
  3. using Entity;
  4. using Entity.Sugar;
  5. using JumpKick.HttpLib;
  6. using SqlSugar;
  7. using SqlSugar.Base;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text.RegularExpressions;
  12. namespace EasyBL.WEBAPP.EIP
  13. {
  14. public class LeaveRequest_UpdService : ServiceBase
  15. {
  16. #region 請假區間編輯(單筆查詢)
  17. /// <summary>
  18. /// 請假區間編輯(單筆查詢)
  19. /// </summary>
  20. /// <param name="i_crm"></param>
  21. /// <returns></returns>
  22. public ResponseMessage QueryOne(RequestMessage i_crm)
  23. {
  24. ResponseMessage rm = null;
  25. string sMsg = null;
  26. var db = SugarBase.GetIntance();
  27. try
  28. {
  29. do
  30. {
  31. var sId = _fetchString(i_crm, @"Guid");
  32. var oEntity = db.Queryable<OTB_EIP_LeaveRequest>().Single(x => x.OrgID == i_crm.ORIGID && x.guid == sId);
  33. rm = new SuccessResponseMessage(null, i_crm);
  34. rm.DATA.Add(BLWording.REL, oEntity);
  35. } while (false);
  36. }
  37. catch (Exception ex)
  38. {
  39. sMsg = Util.GetLastExceptionMsg(ex);
  40. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(LeaveRequest_UpdService), "", "QueryOne(請假區間設定(單筆查詢))", "", "", "");
  41. }
  42. finally
  43. {
  44. if (null != sMsg)
  45. {
  46. rm = new ErrorResponseMessage(sMsg, i_crm);
  47. }
  48. }
  49. return rm;
  50. }
  51. #endregion 請假區間編輯(單筆查詢)
  52. #region 請假區間編輯(新增)
  53. /// <summary>
  54. /// 請假區間編輯(新增)
  55. /// </summary>
  56. /// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
  57. /// <returns></returns>
  58. public ResponseMessage Insert(RequestMessage i_crm)
  59. {
  60. ResponseMessage rm = null;
  61. string sMsg = null;
  62. try
  63. {
  64. rm = SugarBase.ExecTran(db =>
  65. {
  66. do
  67. {
  68. string sGUID = Guid.NewGuid().ToString();
  69. //客戶資料表身
  70. var oEntity = _fetchEntity<OTB_EIP_LeaveRequest>(i_crm);
  71. _setEntityBase(oEntity, i_crm);
  72. oEntity.guid = sGUID;
  73. oEntity.UsedHours = 0;
  74. oEntity.RemainHours = oEntity.PaymentHours;
  75. oEntity.DelFlag = false;
  76. var iRel = db.Insertable(oEntity).ExecuteReturnEntity();
  77. rm = new SuccessResponseMessage(null, i_crm);
  78. rm.DATA.Add(BLWording.REL, iRel);
  79. } while (false);
  80. return rm;
  81. });
  82. }
  83. catch (Exception ex)
  84. {
  85. sMsg = Util.GetLastExceptionMsg(ex);
  86. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(LeaveRequest_UpdService), @"請假區間編輯", @"Add(請假區間編輯(新增))", @"", @"", @"");
  87. }
  88. finally
  89. {
  90. if (null != sMsg)
  91. {
  92. rm = new ErrorResponseMessage(sMsg, i_crm);
  93. }
  94. }
  95. return rm;
  96. }
  97. #endregion 請假區間編輯(新增)
  98. #region 請假區間編輯(修改)
  99. /// <summary>
  100. /// 請假區間編輯(修改)
  101. /// </summary>
  102. /// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
  103. /// <returns></returns>
  104. public ResponseMessage Update(RequestMessage i_crm)
  105. {
  106. ResponseMessage rm = null;
  107. string sMsg = null;
  108. try
  109. {
  110. rm = SugarBase.ExecTran(db =>
  111. {
  112. do
  113. {
  114. var sId = _fetchString(i_crm, @"guid");
  115. var sUpdayOur = _fetchString(i_crm, @"UpdLeaveHours");
  116. decimal.TryParse(sUpdayOur, out var dUpdLeaveHours);
  117. var oNewEntity = _fetchEntity<OTB_EIP_LeaveRequest>(i_crm);
  118. _setEntityBase(oNewEntity, i_crm);
  119. if (oNewEntity.PaymentHours == null)
  120. oNewEntity.PaymentHours = 0;
  121. if (oNewEntity.RemainHours == null)
  122. oNewEntity.RemainHours = 0;
  123. if (oNewEntity.UsedHours == null)
  124. oNewEntity.UsedHours = 0;
  125. string sOrgId = oNewEntity.OrgID;
  126. oNewEntity.PaymentHours += dUpdLeaveHours;
  127. oNewEntity.RemainHours += dUpdLeaveHours;
  128. var iRel = db.Updateable(oNewEntity)
  129. .IgnoreColumns(x => new
  130. {
  131. x.CreateUser,
  132. x.CreateDate
  133. }).ExecuteCommand();
  134. var NewResult = db.Queryable<OTB_EIP_LeaveRequest>()
  135. .Where(p => p.OrgID == sOrgId && p.guid == oNewEntity.guid)
  136. .Single();
  137. rm = new SuccessResponseMessage(null, i_crm);
  138. rm.DATA.Add(BLWording.REL, NewResult);
  139. } while (false);
  140. return rm;
  141. });
  142. }
  143. catch (Exception ex)
  144. {
  145. sMsg = Util.GetLastExceptionMsg(ex);
  146. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(LeaveRequest_UpdService), @"請假區間編輯", @"Update(請假區間編輯(修改))", @"", @"", @"");
  147. }
  148. finally
  149. {
  150. if (null != sMsg)
  151. {
  152. rm = new ErrorResponseMessage(sMsg, i_crm);
  153. }
  154. }
  155. return rm;
  156. }
  157. #endregion 請假區間編輯(修改)
  158. #region 請假區間編輯(刪除)
  159. /// <summary>
  160. /// 請假區間編輯(刪除)
  161. /// </summary>
  162. /// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
  163. /// <returns></returns>
  164. public ResponseMessage Delete(RequestMessage i_crm)
  165. {
  166. ResponseMessage rm = null;
  167. string sMsg = null;
  168. try
  169. {
  170. rm = SugarBase.ExecTran(db =>
  171. {
  172. do
  173. {
  174. var sId = _fetchString(i_crm, @"Guid");
  175. var iRel = db.Deleteable<OTB_EIP_LeaveRequest>().Where(x => x.guid == sId).ExecuteCommand();
  176. var iMstRel = db.Deleteable<OTB_EIP_LeaveRequest>().Where(x => x.guid == sId).ExecuteCommand();
  177. rm = new SuccessResponseMessage(null, i_crm);
  178. rm.DATA.Add(BLWording.REL, iRel);
  179. } while (false);
  180. return rm;
  181. });
  182. }
  183. catch (Exception ex)
  184. {
  185. sMsg = Util.GetLastExceptionMsg(ex);
  186. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(LeaveRequest_UpdService), @"請假區間編輯", @"Delete(請假區間編輯(刪除))", @"", @"", @"");
  187. }
  188. finally
  189. {
  190. if (null != sMsg)
  191. {
  192. rm = new ErrorResponseMessage(sMsg, i_crm);
  193. }
  194. }
  195. return rm;
  196. }
  197. #endregion 請假區間編輯(刪除)
  198. }
  199. }