移动系统liao
2024-12-11 c573732636815e569d24aacff11a82f93602585a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
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);
 
 
                // 发送请求并获取响应
                try
                {
                    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 }));
                        }
 
                    }
                }
                catch (Exception e)
                {
 
                    NLogUtil.WriteAll(NLog.LogLevel.Error, LogType.PcWeb, "调用CYOA后台链接错误", JsonConvert.SerializeObject(new { url, e.Message, e.StackTrace }));
                }
                
            }
        }
    }
}