EpsTrxCleanupManager.cs 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using SinochemCloudClient.Models;
  8. using SinochemPosClient.Models;
  9. namespace SinochemInternetPlusApp.EpsTrxCleanup
  10. {
  11. public class EpsTrxCleanupManager : StateManager
  12. {
  13. private Eps eps;
  14. public EpsTrxCleanupManager(Eps eps) : base(0, "EpsTrxCleanup")
  15. {
  16. debugLogger.Add("EpsTrxCleanupManager is constructed");
  17. this.eps = eps;
  18. }
  19. public override string EntityType => "EpsTrxCleanup";
  20. public override string EntitySubType => "";
  21. protected override void ConfigStates()
  22. {
  23. States.CONFIGURATION.Config(stateMachine.StateTransitionLookup);
  24. }
  25. internal List<EpsTransaction> GetNeedRefundEpsTrxes()
  26. {
  27. DateTime dummyTime = DateTime.Now;
  28. return EpsTransactionQuery.GetEpsTrxesByTrxStatusAndCreatedTime
  29. (EpsTrxStatus.PaymentOkButNeedRefund, dummyTime, true);
  30. }
  31. internal List<EpsTransaction> GetNeedConfirmEpsTrxes()
  32. {
  33. DateTime expirationDatetime = DateTime.Now.AddMinutes(-1 * ConfigurationValues.NeedConfirmEpsTrxExpirationInMinutes);
  34. debugLogger.Add("NeedConfirmEpsTrxes expiration datetime: " + expirationDatetime);
  35. List<EpsTransaction> needConfirmEpsTrxes = EpsTransactionQuery.GetEpsTrxesByTrxStatusAndCreatedTime
  36. (EpsTrxStatus.PaymentNeedConfirm, expirationDatetime, false);
  37. debugLogger.Add(needConfirmEpsTrxes.Count() + " eps trxes need confirmation");
  38. return needConfirmEpsTrxes;
  39. }
  40. internal List<EpsTransaction> GetNeedResendPosNotifyEpsTrxes()
  41. {
  42. DateTime expirationDatetime = DateTime.Now.AddMinutes(-1 * ConfigurationValues.ResendPosNotifyExpirationInMinutes);
  43. debugLogger.Add("NeedResendPosNotifyEpsTrxes expiration datetime: " + expirationDatetime);
  44. List<EpsTransaction> needResendPosNotifyEpsTrxes = EpsTransactionQuery.GetEpsTrxesByNotifyPosFlagAndCreatedTime
  45. (NotifyPosFlag.NotifyFailed, expirationDatetime);
  46. debugLogger.Add(needResendPosNotifyEpsTrxes.Count() + " eps trxes need resending pos notify");
  47. return needResendPosNotifyEpsTrxes;
  48. }
  49. internal RefundResponse RefundEpsTrxInCloud(EpsTransactionModel trxModel)
  50. {
  51. return eps.SendRefundToCloud(trxModel, debugLogger);
  52. }
  53. internal TrxStatusInquiryResponse InquiryCloudTrxStatus(EpsTransactionModel trxModel)
  54. {
  55. return eps.SendTrxQueryToCloud(trxModel, debugLogger);
  56. }
  57. internal TrxNotificationResponse NotifySuccessfulTrxToPos(EpsTransactionModel trxModel)
  58. {
  59. return eps.NotifySuccessfulTrxToPos(trxModel, debugLogger);
  60. }
  61. internal void RemoveEpsTrxHistoryBeforeCertainDate()
  62. {
  63. //Remove the old trxes
  64. DateTime oldEnoughDatetime = DateTime.Now.AddDays(-1 * ConfigurationValues.EpsTrxHistoryArchiveInDays);
  65. debugLogger.Add("RemoveEpsTrxHistory before datetime: " + oldEnoughDatetime);
  66. EpsTransactionQuery.DeleteEpsTrxesBefore(oldEnoughDatetime);
  67. //Remove the eps trxes that the status is "before fueling"
  68. DateTime epsPendingTrxExpiredHours = DateTime.Now.AddHours(-1 * ConfigurationValues.EpsPendingTrxExpiredInHours);
  69. debugLogger.Add("Remove Eps Pending Trx before datetime: " + epsPendingTrxExpiredHours);
  70. EpsTransactionQuery.DeleteEpsTrxPendingBefore(epsPendingTrxExpiredHours);
  71. }
  72. }
  73. }