using CoreCms.Net.Configuration;
|
using CoreCms.Net.IRepository.UnitOfWork;
|
using CoreCms.Net.IServices;
|
using CoreCms.Net.IServices.CYOAServices;
|
using CoreCms.Net.Loging;
|
using EC_SeckillInfo;
|
using Essensoft.Paylink.Alipay.Notify;
|
using InitQ.Abstractions;
|
using InitQ.Attributes;
|
using Newtonsoft.Json;
|
using Newtonsoft.Json.Linq;
|
using NPOI.HSSF.Record;
|
using SqlSugar;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Net.Http;
|
using System.Text;
|
using System.Text.Json;
|
using System.Threading.Tasks;
|
|
namespace CoreCms.Net.RedisMQ
|
{
|
public class CyPlanOderMq: IRedisSubscribe
|
{
|
private readonly ISqlSugarClient _CyDbClient;
|
private readonly IUnitOfWork _UnitOfWork;
|
private readonly IApiService _ApiService;
|
|
public CyPlanOderMq(IUnitOfWork UnitOfWork,IApiService apiService)
|
{
|
_UnitOfWork = UnitOfWork;
|
_CyDbClient = UnitOfWork.GetDbClient().GetConnection(AppSettingsConstVars.CYDbDbID);
|
_ApiService = apiService;
|
|
}
|
/// <summary>
|
/// 处理队列
|
/// </summary>
|
/// <param name="DeliverOrderTarcks"></param>
|
/// <returns></returns>
|
[Subscribe(RedisMessageQueueKey.CyDeliverOrderTarcks)]
|
private async Task Set(string DeliverOrderTarcks)
|
{
|
var notify = JsonConvert.DeserializeObject<TracksDto>(DeliverOrderTarcks);
|
if(notify != null)
|
{
|
var lisrId= await _CyDbClient.Queryable<CoreDeliverOrder>().Where(x => x.OrderState == CoreDeliverOrderType.Start&&x.DeliveryMoble== notify.Moble).Select(x=>x.id).ToListAsync();
|
|
if(lisrId != null&&lisrId.Count>0)
|
{
|
var tarklist = new List< CoreDeliveryOrderTracks>();
|
//需要写入
|
foreach(var item in lisrId)
|
{
|
tarklist.Add(new CoreDeliveryOrderTracks
|
{
|
CreateBy = notify.Moble,
|
CreateTime = notify.CreateTime,
|
Latitude = notify.Latitude,
|
Longitude = notify.Longitude,
|
id= Guid.NewGuid(),
|
OrderID=item,
|
});
|
|
}
|
await _CyDbClient.Insertable(tarklist).ExecuteCommandAsync();
|
}
|
|
}
|
}
|
|
/// <summary>
|
/// 调用计算结余接口
|
/// </summary>
|
/// <param name="msgID"></param>
|
/// <returns></returns>
|
[Subscribe(RedisMessageQueueKey.CyDeliverOAjisuanjine)]
|
private async Task CyDeliverOAjisuanjine(string msgID)
|
{
|
// 创建 HttpClient 实例
|
using (var client = new HttpClient())
|
{
|
// 设置请求 URL
|
string url = $"{AppSettingsConstVars.CYOAHttps}/Pages/business/jisuanjine.aspx?tmp={new Random().Next()}&Target=jisuanorderJine&OrderId={msgID}";
|
|
// 设置请求头
|
client.DefaultRequestHeaders.Add("Cookie", "ASP.NET_SessionId=d2u3uyhydzml21wnlcir1dh0");
|
|
// 创建 HTTP POST 请求
|
var request = new HttpRequestMessage(HttpMethod.Post, url);
|
|
// 发送请求并获取响应
|
using (var response = await client.SendAsync(request))
|
{
|
// 确保请求成功
|
response.EnsureSuccessStatusCode();
|
|
try
|
{
|
// 读取响应内容
|
string responseBody = await response.Content.ReadAsStringAsync();
|
|
try
|
{
|
JObject jsonObject = JObject.Parse(responseBody.ToLower());
|
|
if ("True" == (string)jsonObject["status"])
|
{
|
return;
|
}
|
else
|
{
|
NLogUtil.WriteAll(NLog.LogLevel.Error, LogType.PcWeb, "调用CYOA后台返回错误", JsonConvert.SerializeObject(new { url, responseBody }));
|
}
|
}
|
catch (Exception e)
|
{
|
|
NLogUtil.WriteAll(NLog.LogLevel.Error, LogType.PcWeb, "调用CYOA后台返回错误", JsonConvert.SerializeObject(new { url, responseBody }));
|
}
|
|
}
|
catch (Exception e)
|
{
|
|
NLogUtil.WriteAll(NLog.LogLevel.Error, LogType.PcWeb, "调用CYOA后台链接错误", JsonConvert.SerializeObject(new { url, e.Message, e.StackTrace }));
|
}
|
|
}
|
}
|
}
|
}
|
}
|