diff --git a/Api/OnlineSalesAutoCrop.CoreAPI.Models/Enums.cs b/Api/OnlineSalesAutoCrop.CoreAPI.Models/Enums.cs
index a1732c0..3924448 100644
--- a/Api/OnlineSalesAutoCrop.CoreAPI.Models/Enums.cs
+++ b/Api/OnlineSalesAutoCrop.CoreAPI.Models/Enums.cs
@@ -754,4 +754,11 @@ namespace OnlineSalesAutoCrop.CoreAPI.Models
[Description("Sent To SAP")]
SentToSAP = 7
}
+
+ public enum SAPOrderStatusEnum : short
+ {
+ Pending = 0,
+ Sent = 1,
+ Error = 2
+ }
}
\ No newline at end of file
diff --git a/Api/OnlineSalesAutoCrop.CoreAPI.Models/Global/AppSettings.cs b/Api/OnlineSalesAutoCrop.CoreAPI.Models/Global/AppSettings.cs
index 9d50f91..e945499 100644
--- a/Api/OnlineSalesAutoCrop.CoreAPI.Models/Global/AppSettings.cs
+++ b/Api/OnlineSalesAutoCrop.CoreAPI.Models/Global/AppSettings.cs
@@ -127,22 +127,23 @@ namespace OnlineSalesAutoCrop.CoreAPI.Models.Global
public string LoggerPath { get; set; }
public int LoggerMinLevel { get; set; }
- ///
- /// Database connection Hangfire
- ///
- private string _hangfireDb;
- public string HangfireDb
- {
- get
- {
- if (string.IsNullOrEmpty(_hangfireDb) || string.IsNullOrEmpty(PwdSecretKey))
- return string.Empty;
+ ///
+ /// Database connection Hangfire
+ ///
+ public string HangfireDb { get; set; }
+ //private string _hangfireDb;
+ //public string HangfireDb
+ //{
+ // get
+ // {
+ // if (string.IsNullOrEmpty(_hangfireDb) || string.IsNullOrEmpty(PwdSecretKey))
+ // return string.Empty;
- string secretKey = GlobalFunctions.ConvertFromBase64String(PwdSecretKey);
- return Ease.NetCore.Utility.Global.CipherFunctions.DecryptByAES(privateKey: secretKey, publicKey: secretKey, data: _hangfireDb, input: 2);
- }
- set { _hangfireDb = value; }
- }
+ // string secretKey = GlobalFunctions.ConvertFromBase64String(PwdSecretKey);
+ // return Ease.NetCore.Utility.Global.CipherFunctions.DecryptByAES(privateKey: secretKey, publicKey: secretKey, data: _hangfireDb, input: 2);
+ // }
+ // set { _hangfireDb = value; }
+ //}
diff --git a/Api/OnlineSalesAutoCrop.CoreAPI.Models/Requests/MobileApp/OrderRequest.cs b/Api/OnlineSalesAutoCrop.CoreAPI.Models/Requests/MobileApp/OrderRequest.cs
index 1e5652f..3677c21 100644
--- a/Api/OnlineSalesAutoCrop.CoreAPI.Models/Requests/MobileApp/OrderRequest.cs
+++ b/Api/OnlineSalesAutoCrop.CoreAPI.Models/Requests/MobileApp/OrderRequest.cs
@@ -77,4 +77,14 @@ public class GetOrderSummaryRequest : PagedRequest
public DateTime? StartDate { get; set; }
public DateTime? EndDate { get; set; }
public OrderStatusEnum? OrderStatus { get; set; }
+}
+
+public class UpdateSapDetailsRequest
+{
+ public int OrderId { get; set; }
+ public SAPOrderStatusEnum Status { get; set; }
+ public DateTime SentAt { get; set; }
+ public int RetryCount { get; set; }
+ public string LastError { get; set; }
+ public string ReturnMessage { get; set; }
}
\ No newline at end of file
diff --git a/Api/OnlineSalesAutoCrop.CoreAPI.Models/Responses/MobileApp/OrderResponse.cs b/Api/OnlineSalesAutoCrop.CoreAPI.Models/Responses/MobileApp/OrderResponse.cs
index d1eb5a5..91c7677 100644
--- a/Api/OnlineSalesAutoCrop.CoreAPI.Models/Responses/MobileApp/OrderResponse.cs
+++ b/Api/OnlineSalesAutoCrop.CoreAPI.Models/Responses/MobileApp/OrderResponse.cs
@@ -119,4 +119,31 @@ public sealed class FreeGoodsRuleDto
public decimal FreeQuantity { get; set; }
public string UnitOfMeasure { get; set; } = string.Empty;
public string FocUnitOfMeasure { get; set; } = string.Empty;
+}
+
+public class GetOrderForSAPResponse
+{
+ public GetOrderForSAPResponse()
+ {
+ to_Item = new List();
+ }
+
+ public string SalesOrderType { get; set; }
+ public string SalesOrganization { get; set; }
+ public string DistributionChannel { get; set; }
+ public string OrganizationDivision { get; set; }
+ public string SoldToParty { get; set; }
+ public string PurchaseOrderByCustomer { get; set; }
+ public string CustomerPurchaseOrderDate { get; set; }
+ public string PurchaseOrderByShipToParty { get; set; }
+ public string CustomerPaymentTerms { get; set; }
+ public string? CustomerGroup { get; set; }
+ public string? CustomerPriceGroup { get; set; }
+ public IList to_Item { get; set; }
+}
+
+public class GetOrderItemForSAPResponse
+{
+ public string Material { get; set; }
+ public string RequestedQuantity { get; set; }
}
\ No newline at end of file
diff --git a/Api/OnlineSalesAutoCrop.CoreAPI.Services/Contracts/BackgroupJobs/IBackgroundJobService.cs b/Api/OnlineSalesAutoCrop.CoreAPI.Services/Contracts/BackgroupJobs/IBackgroundJobService.cs
new file mode 100644
index 0000000..05d0844
--- /dev/null
+++ b/Api/OnlineSalesAutoCrop.CoreAPI.Services/Contracts/BackgroupJobs/IBackgroundJobService.cs
@@ -0,0 +1,13 @@
+
+using Hangfire;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace OnlineSalesAutoCrop.CoreAPI.Services.Contracts.BackgroupJobs;
+
+public interface IBackgroundJobService
+{
+ [Queue("sap_order_send")]
+ [DisableConcurrentExecution(timeoutInSeconds: 40 * 60)]
+ Task ExecuteSendingOrderAsync(CancellationToken cancellationToken);
+}
diff --git a/Api/OnlineSalesAutoCrop.CoreAPI.Services/Contracts/Integrations/IIntegrationHttpService.cs b/Api/OnlineSalesAutoCrop.CoreAPI.Services/Contracts/Integrations/IIntegrationHttpService.cs
index db7a12a..c620fcb 100644
--- a/Api/OnlineSalesAutoCrop.CoreAPI.Services/Contracts/Integrations/IIntegrationHttpService.cs
+++ b/Api/OnlineSalesAutoCrop.CoreAPI.Services/Contracts/Integrations/IIntegrationHttpService.cs
@@ -1,5 +1,6 @@
using OnlineSalesAutoCrop.CoreAPI.Models.Responses.Integrations;
+using OnlineSalesAutoCrop.CoreAPI.Models.Responses.MobileApp;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
@@ -14,5 +15,7 @@ public interface IIntegrationHttpService
Task> GetMaterialStockAsync(string plantCode,
CancellationToken cancellationToken = default);
+ Task SendSAPOrdersAsync(GetOrderForSAPResponse request,
+ CancellationToken cancellationToken = default);
}
diff --git a/Api/OnlineSalesAutoCrop.CoreAPI.Services/Contracts/MobileApp/IOrderService.cs b/Api/OnlineSalesAutoCrop.CoreAPI.Services/Contracts/MobileApp/IOrderService.cs
index a2601f5..9eca33d 100644
--- a/Api/OnlineSalesAutoCrop.CoreAPI.Services/Contracts/MobileApp/IOrderService.cs
+++ b/Api/OnlineSalesAutoCrop.CoreAPI.Services/Contracts/MobileApp/IOrderService.cs
@@ -1,8 +1,9 @@
-
-using OnlineSalesAutoCrop.CoreAPI.Models.Requests;
+using OnlineSalesAutoCrop.CoreAPI.Models;
using OnlineSalesAutoCrop.CoreAPI.Models.Requests.MobileApp;
using OnlineSalesAutoCrop.CoreAPI.Models.Responses;
using OnlineSalesAutoCrop.CoreAPI.Models.Responses.MobileApp;
+using System.Collections.Generic;
+using System.Threading;
using System.Threading.Tasks;
namespace OnlineSalesAutoCrop.CoreAPI.Services.Contracts.MobileApp;
@@ -11,4 +12,8 @@ public interface IOrderService
{
Task SaveOrderAsync(SaveOrderRequest request, int userId);
Task> GetSalesOrdersSummary(GetOrderSummaryRequest request, int userId);
+ Task> GetAvailableOrderIdsForSAPAsync(SAPOrderStatusEnum orderStaus, CancellationToken cancellationToken = default);
+ Task GetOrderDetailsForSapByIdAsync(int orderId, CancellationToken cancellationToken = default);
+ Task UpdateSendingSapDetailsAsync(UpdateSapDetailsRequest request, CancellationToken cancellationToken = default);
+
}
diff --git a/Api/OnlineSalesAutoCrop.CoreAPI.Services/OnlineSalesAutoCrop.CoreAPI.Services.csproj b/Api/OnlineSalesAutoCrop.CoreAPI.Services/OnlineSalesAutoCrop.CoreAPI.Services.csproj
index 7b160a0..4d7e330 100644
--- a/Api/OnlineSalesAutoCrop.CoreAPI.Services/OnlineSalesAutoCrop.CoreAPI.Services.csproj
+++ b/Api/OnlineSalesAutoCrop.CoreAPI.Services/OnlineSalesAutoCrop.CoreAPI.Services.csproj
@@ -96,6 +96,7 @@
+
diff --git a/Api/OnlineSalesAutoCrop.CoreAPI.Services/Services/BackgroupJobs/BackgroundJobService.cs b/Api/OnlineSalesAutoCrop.CoreAPI.Services/Services/BackgroupJobs/BackgroundJobService.cs
new file mode 100644
index 0000000..80a5b74
--- /dev/null
+++ b/Api/OnlineSalesAutoCrop.CoreAPI.Services/Services/BackgroupJobs/BackgroundJobService.cs
@@ -0,0 +1,55 @@
+
+using Microsoft.Extensions.Logging;
+using OnlineSalesAutoCrop.CoreAPI.Models;
+using OnlineSalesAutoCrop.CoreAPI.Models.Requests.MobileApp;
+using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.BackgroupJobs;
+using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.Integrations;
+using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.MobileApp;
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace OnlineSalesAutoCrop.CoreAPI.Services.Services.BackgroupJobs;
+
+public class BackgroundJobService : IBackgroundJobService
+{
+ private readonly IIntegrationHttpService _httpService;
+ private readonly IOrderService _orderService;
+ private readonly ILogger _logger;
+
+ public BackgroundJobService(IIntegrationHttpService httpService, IOrderService orderService, ILogger logger)
+ {
+ _httpService = httpService;
+ _orderService = orderService;
+ _logger = logger;
+ }
+
+ public async Task ExecuteSendingOrderAsync(CancellationToken cancellationToken)
+ {
+ _logger.LogInformation("SendingOrder Job successfully run at: " + DateTime.Now.ToString());
+ try
+ {
+ var pendingOrderIds = await _orderService.GetAvailableOrderIdsForSAPAsync(SAPOrderStatusEnum.Pending);
+ foreach (var item in pendingOrderIds)
+ {
+ var orderDetails = await _orderService.GetOrderDetailsForSapByIdAsync(item);
+
+ string httpResponse = await _httpService.SendSAPOrdersAsync(orderDetails);
+ await _orderService.UpdateSendingSapDetailsAsync(new UpdateSapDetailsRequest
+ {
+ OrderId = item,
+ SentAt = DateTime.Now,
+ RetryCount =1,
+ ReturnMessage = httpResponse
+ });
+ }
+ }
+ catch(Exception ex)
+ {
+ _logger.LogError("Exception Occur in ExecuteSendingOrder "+ ex.Message);
+ throw;
+ }
+
+ _logger.LogInformation("SendingOrder Job successfully finished at: " + DateTime.Now.ToString());
+ }
+}
diff --git a/Api/OnlineSalesAutoCrop.CoreAPI.Services/Services/Integrations/IntegrationHttpService.cs b/Api/OnlineSalesAutoCrop.CoreAPI.Services/Services/Integrations/IntegrationHttpService.cs
index 12c35f7..317f182 100644
--- a/Api/OnlineSalesAutoCrop.CoreAPI.Services/Services/Integrations/IntegrationHttpService.cs
+++ b/Api/OnlineSalesAutoCrop.CoreAPI.Services/Services/Integrations/IntegrationHttpService.cs
@@ -1,6 +1,7 @@
using Microsoft.Extensions.Logging;
using OnlineSalesAutoCrop.CoreAPI.Models.Responses.Integrations;
+using OnlineSalesAutoCrop.CoreAPI.Models.Responses.MobileApp;
using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.Integrations;
using System;
using System.Collections.Generic;
@@ -71,4 +72,30 @@ public class IntegrationHttpService : IIntegrationHttpService
throw;
}
}
+
+ public async Task SendSAPOrdersAsync(GetOrderForSAPResponse request, CancellationToken cancellationToken = default)
+ {
+ try
+ {
+ var requestUri = "http/sales_order";
+
+ var response = await _httpClient.PostAsJsonAsync(requestUri,request,cancellationToken);
+
+ if (!response.IsSuccessStatusCode)
+ {
+ var body = await response.Content.ReadAsStringAsync(cancellationToken);
+ _logger.LogError("Save Orders call failed: {StatusCode} — {Body}", response.StatusCode, body);
+ response.EnsureSuccessStatusCode();
+ return body;
+ }
+
+ var payload = await response.Content.ReadFromJsonAsync>(cancellationToken: cancellationToken);
+
+ return string.Empty ;
+ }
+ catch (Exception)
+ {
+ throw;
+ }
+ }
}
diff --git a/Api/OnlineSalesAutoCrop.CoreAPI.Services/Services/MobileApp/OrderService.cs b/Api/OnlineSalesAutoCrop.CoreAPI.Services/Services/MobileApp/OrderService.cs
index 4d10fc9..004b25d 100644
--- a/Api/OnlineSalesAutoCrop.CoreAPI.Services/Services/MobileApp/OrderService.cs
+++ b/Api/OnlineSalesAutoCrop.CoreAPI.Services/Services/MobileApp/OrderService.cs
@@ -1,6 +1,5 @@
using Ease.NetCore.DataAccess;
using Ease.NetCore.DataAccess.SQL;
-using Microsoft.AspNetCore.Http;
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Options;
using OnlineSalesAutoCrop.CoreAPI.Models;
@@ -14,7 +13,7 @@ using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
-using System.Security.Claims;
+using System.Threading;
using System.Threading.Tasks;
namespace OnlineSalesAutoCrop.CoreAPI.Services.Services.MobileApp;
@@ -808,4 +807,156 @@ public class OrderService : IOrderService
return response;
}
+
+ public async Task> GetAvailableOrderIdsForSAPAsync(SAPOrderStatusEnum orderStaus, CancellationToken cancellationToken = default)
+ {
+ List response = new List();
+
+ try
+ {
+ using TransactionContext tc = await TransactionContext.BeginAsync(_settings.DefaultConnection.ConnectionNode);
+ try
+ {
+ SqlParameter[] p =
+ [
+ SqlHelperExtension.CreateInParam(pName: "@OrderStatus", pType: SqlDbType.Int, pValue: (int?)orderStaus ),
+ ];
+
+ using (IDataReader dr = await tc.ExecuteReaderSpAsync("dbo.GetAvailableOrderIdsByStatus", parameterValues: p))
+ {
+ while (dr.Read())
+ {
+ response.Add(dr.GetInt32(0));
+ }
+
+ dr.Close();
+ }
+ tc.End();
+ }
+ catch (Exception ie)
+ {
+ tc?.HandleError();
+
+ throw DBCustomError.GenerateCustomError(ie);
+ }
+ }
+ catch (Exception ex)
+ {
+ throw;
+ }
+
+ return response;
+ }
+
+ public async Task GetOrderDetailsForSapByIdAsync(int orderId, CancellationToken cancellationToken = default)
+ {
+ GetOrderForSAPResponse response = null;
+
+ try
+ {
+ using TransactionContext tc = await TransactionContext.BeginAsync(_settings.DefaultConnection.ConnectionNode);
+ try
+ {
+ SqlParameter[] p =
+ [
+ SqlHelperExtension.CreateInParam(pName: "@OrderId", pType: SqlDbType.Int, pValue: orderId ),
+ ];
+
+ using (IDataReader dr = await tc.ExecuteReaderSpAsync("dbo.GetOrderDetailsById", parameterValues: p))
+ {
+ while (dr.Read())
+ {
+ response = new GetOrderForSAPResponse()
+ {
+ SalesOrderType = dr.GetString(0),
+ SalesOrganization = dr.GetString(1),
+ DistributionChannel = dr.GetString(2),
+ OrganizationDivision = dr.GetString(3),
+ SoldToParty = dr.GetString(4),
+ PurchaseOrderByCustomer = dr.GetString(5),
+ CustomerPurchaseOrderDate = ConvertOrderDateIntoMilisec( dr.GetDateTime(6)),
+ PurchaseOrderByShipToParty =dr.IsDBNull(7) ? null : dr.GetString(7),
+ CustomerPaymentTerms = dr.IsDBNull(8) ? null : dr.GetString(8),
+ CustomerGroup = dr.GetString(9),
+ CustomerPriceGroup = dr.GetString(10)
+ };
+ }
+
+ if (response is not null && dr.NextResult())
+ {
+ while (dr.Read())
+ {
+ response.to_Item.Add(new GetOrderItemForSAPResponse
+ {
+ Material = dr.GetString(0),
+ RequestedQuantity =Convert.ToString( dr.IsDBNull(1)? 0 : dr.GetDecimal(1))
+ });
+ }
+ }
+
+ dr.Close();
+ }
+
+ tc.End();
+ }
+ catch (Exception ie)
+ {
+ tc?.HandleError();
+
+ throw DBCustomError.GenerateCustomError(ie);
+ }
+ }
+ catch (Exception ex)
+ {
+ throw;
+ }
+
+ return response;
+ }
+
+ private string ConvertOrderDateIntoMilisec(DateTime orderDate)
+ {
+ long milliseconds = new DateTimeOffset(orderDate).ToUnixTimeMilliseconds();
+ string sapDate = $"/Date({milliseconds})/";
+ return sapDate;
+ }
+
+ public async Task UpdateSendingSapDetailsAsync(UpdateSapDetailsRequest request, CancellationToken cancellationToken = default)
+ {
+ bool response = false;
+
+ try
+ {
+ using TransactionContext tc = await TransactionContext.BeginAsync(_settings.DefaultConnection.ConnectionNode, true);
+ try
+ {
+ SqlParameter[] p =
+ [
+ SqlHelperExtension.CreateInParam(pName: "@OrderId", pType: SqlDbType.Int, pValue: request.OrderId ),
+ SqlHelperExtension.CreateInParam(pName: "@Status", pType: SqlDbType.Int, pValue: request.Status ),
+ SqlHelperExtension.CreateInParam(pName: "@SentAt", pType: SqlDbType.DateTime, pValue: DateTime.Now ),
+ SqlHelperExtension.CreateInParam(pName: "@RetryCount", pType: SqlDbType.Int, pValue: request.RetryCount ),
+ SqlHelperExtension.CreateInParam(pName: "@LastError", pType: SqlDbType.Int, pValue: request.LastError ),
+ SqlHelperExtension.CreateInParam(pName: "@ReturnMessage", pType: SqlDbType.Int, pValue: request.ReturnMessage ),
+ ];
+
+ await tc.ExecuteNonQuerySpAsync("dbo.UpdateSendingSapDetails", parameterValues: p);
+
+ tc.End();
+ }
+ catch (Exception ie)
+ {
+ tc?.HandleError();
+
+ throw DBCustomError.GenerateCustomError(ie);
+ }
+ }
+ catch (Exception ex)
+ {
+ throw;
+ }
+
+ return response;
+ }
+
}
diff --git a/Api/OnlineSalesAutoCrop.CoreAPI/Configurations/DI/ServiceCollectionExtensions.cs b/Api/OnlineSalesAutoCrop.CoreAPI/Configurations/DI/ServiceCollectionExtensions.cs
index 977360b..947e317 100644
--- a/Api/OnlineSalesAutoCrop.CoreAPI/Configurations/DI/ServiceCollectionExtensions.cs
+++ b/Api/OnlineSalesAutoCrop.CoreAPI/Configurations/DI/ServiceCollectionExtensions.cs
@@ -1,10 +1,13 @@
-using Microsoft.Extensions.DependencyInjection;
+using Hangfire;
+using Microsoft.Extensions.DependencyInjection;
using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.Auth;
+using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.BackgroupJobs;
using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.Integrations;
using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.MobileApp;
using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.Setups;
using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.Systems;
using OnlineSalesAutoCrop.CoreAPI.Services.Services.Auth;
+using OnlineSalesAutoCrop.CoreAPI.Services.Services.BackgroupJobs;
using OnlineSalesAutoCrop.CoreAPI.Services.Services.Integrations;
using OnlineSalesAutoCrop.CoreAPI.Services.Services.MobileApp;
using OnlineSalesAutoCrop.CoreAPI.Services.Services.Setups;
@@ -32,8 +35,9 @@ namespace OnlineSalesAutoCrop.CoreAPI.Configuration.DI
services.AddTransient();
services.AddTransient();
services.AddScoped();
- services.AddScoped();
- services.AddScoped();
+ services.AddScoped();
+ services.AddScoped();
+ services.AddScoped();
}
}
}
diff --git a/Api/OnlineSalesAutoCrop.CoreAPI/OnlineSalesAutoCrop.CoreAPI.csproj b/Api/OnlineSalesAutoCrop.CoreAPI/OnlineSalesAutoCrop.CoreAPI.csproj
index 47984ff..c522316 100644
--- a/Api/OnlineSalesAutoCrop.CoreAPI/OnlineSalesAutoCrop.CoreAPI.csproj
+++ b/Api/OnlineSalesAutoCrop.CoreAPI/OnlineSalesAutoCrop.CoreAPI.csproj
@@ -167,7 +167,8 @@
-
+
+
diff --git a/Api/OnlineSalesAutoCrop.CoreAPI/Startup.cs b/Api/OnlineSalesAutoCrop.CoreAPI/Startup.cs
index 2a650a6..92216bb 100644
--- a/Api/OnlineSalesAutoCrop.CoreAPI/Startup.cs
+++ b/Api/OnlineSalesAutoCrop.CoreAPI/Startup.cs
@@ -8,6 +8,7 @@ using Microsoft.AspNetCore.CookiePolicy;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
@@ -22,6 +23,7 @@ using OnlineSalesAutoCrop.CoreAPI.Configurations;
using OnlineSalesAutoCrop.CoreAPI.Models;
using OnlineSalesAutoCrop.CoreAPI.Models.Global;
using OnlineSalesAutoCrop.CoreAPI.Models.Responses;
+using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.BackgroupJobs;
using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.Integrations;
using OnlineSalesAutoCrop.CoreAPI.Services.Services.Integrations;
using OnlineSalesAutoCrop.CoreAPI.SignalRHub;
@@ -30,14 +32,14 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
+using System.Net;
+using System.Net.Http;
+using System.Net.Http.Headers;
using System.Reflection;
using System.Text;
+using System.Threading;
using System.Threading.RateLimiting;
using System.Threading.Tasks;
-using Microsoft.AspNetCore.HttpOverrides;
-using System.Net.Http.Headers;
-using System.Net.Http;
-using System.Net;
namespace OnlineSalesAutoCrop.CoreAPI
{
@@ -312,7 +314,11 @@ namespace OnlineSalesAutoCrop.CoreAPI
services.AddHangfire(config =>
{
config.UseFilter(new TimeRestrictionServerFilter(startHour: 1, endHour: 7));
- config.UseSqlServerStorage(_appSettings.HangfireDb, new SqlServerStorageOptions
+ config.SetDataCompatibilityLevel(CompatibilityLevel.Version_180);
+ config.UseSimpleAssemblyNameTypeSerializer();
+ config.UseRecommendedSerializerSettings();
+
+ config.UseSqlServerStorage(_appSettings.HangfireDb, new SqlServerStorageOptions
{
DisableGlobalLocks = true,
QueuePollInterval = TimeSpan.Zero,
@@ -321,14 +327,18 @@ namespace OnlineSalesAutoCrop.CoreAPI
SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5)
});
});
- services.AddHangfireServer();
+ services.AddHangfireServer(options =>
+ {
+ options.Queues = new[] { "sap_order_send", "default" }; // merge with any queues you already have
+ }); ;
}
- #endregion
- #region SWAGGER
+ #endregion
- if (_appSettings.Swagger.Enabled)
+ #region SWAGGER
+
+ if (_appSettings.Swagger.Enabled)
{
services.AddTransient, ConfigureSwaggerOptions>();
services.AddSwaggerGen(options =>
@@ -353,8 +363,8 @@ namespace OnlineSalesAutoCrop.CoreAPI
{
var opt = _appSettings.AutoCropSAPApi;
- client.BaseAddress = new Uri(opt.BaseUrl);
-
+ client.BaseAddress = new Uri(opt.BaseUrl);
+
var basicAuth = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{opt.UserName}:{opt.Password}"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", basicAuth);
@@ -529,7 +539,12 @@ namespace OnlineSalesAutoCrop.CoreAPI
app.UseHangfireDashboard();
RecurringJobOptions options = new() { TimeZone = TimeZoneInfo.Local, MisfireHandling = MisfireHandlingMode.Relaxed };
- }
+
+ RecurringJob.AddOrUpdate(
+ "send-sap-orders",
+ service => service.ExecuteSendingOrderAsync(CancellationToken.None),
+ "*/1 * * * *");
+ }
#endregion
diff --git a/Api/OnlineSalesAutoCrop.CoreAPI/appsettings.json b/Api/OnlineSalesAutoCrop.CoreAPI/appsettings.json
index cf9d690..e1e89c5 100644
--- a/Api/OnlineSalesAutoCrop.CoreAPI/appsettings.json
+++ b/Api/OnlineSalesAutoCrop.CoreAPI/appsettings.json
@@ -51,7 +51,7 @@
"EmailUseDefaultCredentials": false,
"EPMaxLevel": 2,
"FileProcessFolder": "D:\\Local\\EaseBilling\\Api\\OnlineSalesAutoCrop.CoreAPI\\FileProcessFolder",
- "HangfireDb": "9oXGnVl0H8yqF5I2MjHeXGNp5367ljjQjnsatcKsW/KFPlA8iwEVdaY7ZMBnU+AtKZIaKjwWoHZvDLmNn0K8Ke96pS3Sj4tD+mJejgSfJLhaB+UERm6M+xqVC30kk25TsVBQezB7AsmS8PXLfgWAboe4YmyQ3pXMrDx7WCfiuJA=",
+ "HangfireDb": "Data Source=210.4.65.222,3341;Initial Catalog=AutoCropDB;User ID=dmsuser;Password=dMsu@er;Encrypt=false",
"JwtAudience": "www.celdevbd.com",
"JwtCryptoKey": "Computer ease limited, dhaka, bangladesh BDComputer ease limited",
"JwtIssuer": "https://www.celdevbd.com",