EpsTrxCleanupManager.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. static NLog.Logger logger = NLog.LogManager.LoadConfiguration("nlog.config").GetLogger("SinochemEpsApp");
  14. private Eps eps;
  15. public EpsTrxCleanupManager(Eps eps) : base(0, "EpsTrxCleanup")
  16. {
  17. //debugLogger.Add("EpsTrxCleanupManager is constructed");
  18. logger.Info("EpsTrxCleanupManager is constructed");
  19. this.eps = eps;
  20. }
  21. public override string EntityType => "EpsTrxCleanup";
  22. public override string EntitySubType => "";
  23. protected override void ConfigStates()
  24. {
  25. States.CONFIGURATION.Config(stateMachine.StateTransitionLookup);
  26. }
  27. internal List<EpsTransaction> GetNeedRefundEpsTrxes()
  28. {
  29. DateTime dummyTime = DateTime.Now;
  30. return EpsTransactionQuery.GetEpsTrxesByTrxStatusAndCreatedTime
  31. (EpsTrxStatus.PaymentOkButNeedRefund, dummyTime, true);
  32. }
  33. internal List<EpsTransaction> GetNeedConfirmEpsTrxes()
  34. {
  35. DateTime expirationDatetime = DateTime.Now.AddMinutes(-1 * ConfigurationValues.NeedConfirmEpsTrxExpirationInMinutes);
  36. //debugLogger.Add("NeedConfirmEpsTrxes expiration datetime: " + expirationDatetime);
  37. logger.Info("NeedConfirmEpsTrxes expiration datetime: " + expirationDatetime);
  38. List<EpsTransaction> needConfirmEpsTrxes = EpsTransactionQuery.GetEpsTrxesByTrxStatusAndCreatedTime
  39. (EpsTrxStatus.PaymentNeedConfirm, expirationDatetime, false);
  40. debugLogger.Add(needConfirmEpsTrxes.Count() + " eps trxes need confirmation");
  41. return needConfirmEpsTrxes;
  42. }
  43. internal List<EpsTransaction> GetNeedResendPosNotifyEpsTrxes()
  44. {
  45. DateTime expirationDatetime = DateTime.Now.AddMinutes(-1 * ConfigurationValues.ResendPosNotifyExpirationInMinutes);
  46. //debugLogger.Add("NeedResendPosNotifyEpsTrxes expiration datetime: " + expirationDatetime);
  47. logger.Info("NeedResendPosNotifyEpsTrxes expiration datetime: " + expirationDatetime);
  48. List<EpsTransaction> needResendPosNotifyEpsTrxes = EpsTransactionQuery.GetEpsTrxesByNotifyPosFlagAndCreatedTime
  49. (NotifyPosFlag.NotifyFailed, expirationDatetime);
  50. //debugLogger.Add(needResendPosNotifyEpsTrxes.Count() + " eps trxes need resending pos notify");
  51. logger.Info(needResendPosNotifyEpsTrxes.Count() + " eps trxes need resending pos notify");
  52. return needResendPosNotifyEpsTrxes;
  53. }
  54. internal RefundResponse RefundEpsTrxInCloud(EpsTransactionModel trxModel)
  55. {
  56. return eps.SendRefundToCloud(trxModel, debugLogger);
  57. }
  58. internal TrxStatusInquiryResponse InquiryCloudTrxStatus(EpsTransactionModel trxModel)
  59. {
  60. return eps.SendTrxQueryToCloud(trxModel, debugLogger);
  61. }
  62. internal TrxNotificationResponse NotifySuccessfulTrxToPos(EpsTransactionModel trxModel)
  63. {
  64. return eps.NotifySuccessfulTrxToPos(trxModel, debugLogger);
  65. }
  66. internal void RemoveEpsTrxHistoryBeforeCertainDate()
  67. {
  68. DateTime oldEnoughDatetime = DateTime.Now.AddDays(-1 * ConfigurationValues.EpsTrxHistoryArchiveInDays);
  69. //debugLogger.Add("RemoveEpsTrxHistory before datetime: " + oldEnoughDatetime);
  70. logger.Info("RemoveEpsTrxHistory before datetime: " + oldEnoughDatetime);
  71. EpsTransactionQuery.DeleteEpsTrxesBefore(oldEnoughDatetime);
  72. }
  73. }
  74. }