schangxiang@126.com
2025-08-25 aa383c30e4f1053e97c6a33ccf9a899fca26dd20
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
using iWareLog.ORM;
using iWareLog.LOG.Entity;
using iWareLog.LOG.Dao;
using iWareCommon.Common.Service;
using iWareCommon.Utils;
using System;
using iWareCommon.Common.EnumType;
using Newtonsoft.Json;
using iWareLog.Properties;
using iWareCommon.Common.Entity;
using System.Linq;
 
namespace iWareLog.LOG.Service
{
    public class FailSentMessageService : CommonService<FailSentMessageEntity, LOGERRORFailSentMessage, DbModelLog>
    {
           private static object Lock = new object();
 
           private FailSentMessageService() : base(FailSentMessageDao.GetInstance()) { }
 
           private static FailSentMessageService Instance = null;
 
        /// <summary>
        /// 获取单例的方法
        /// </summary>
        /// <returns>log服务的单例实体</returns>
           public static FailSentMessageService GetInstance()
        {
 
            if (Instance == null)
            {
                lock (Lock)
                {
                    if (Instance == null)
                    {
                        Instance = new FailSentMessageService();
                    }
                }
            }
            return Instance;
        }
           /// <summary>
           /// 重新发送
           /// </summary>
           /// <param name="message"></param>
           /// <param name="msg"></param>
           /// <returns></returns>
           public bool ReSend(int id, out string msg)
           {
               using (var dbModel = new DbModelLog())
               {
                   try
                   {
                       msg = "";
                       var url = "";
 
                       var message = dbModel.LOGERRORFailSentMessages.FirstOrDefault(x => x.id == id);
 
                       if (message == null)
                       {
                           msg = string.Format("没有找到id为{0}的记录", id);
                           return false;
                       }
 
                       switch (message.url)
                       {
                           case "pushstatusforpreheating":
                           case "pushstatusforheatstorage":
                           case "pushstatusforbufferfeed":
                           case "preheatstoragefinish":
                           case "pushstatusforft":
                           case "pushstatusforecmfeedbyrcs":
                           case "pushstatusforecmblankingbyrcs":
                           case "pushstatusforheattrans":
                           case "pushstatusforartificialqualityinspection":
                           case "heatstoroutbindrfid":
                           case "heatstoroutbindfinish":
                           case "pushstatusforbuffertrans":
                               url = Resources.WipUrl + @"/";
                               break;
                           case "syncmaterialinfo":
                           case "materialstatemodify":
                           case "getloadingtablestatus":
                           case "getecmtablestatus":
                           case "businessexception":
                           case "equipwarn":
                           case "equipstatus":
                           case "agvrealtimelocation":
                           case "outstoragecompleted":
                           case "movestoragecompleted":
                           case "bufferlayingoffcompleted":
                           case "artificialwarehousing":
                           case "processcardforwcs":
                           case "resetprocesscardprintqueue":
                               url = Resources.WipUrl2 + @"/";
                               break;
                           case "reparsetask":
                               break;
 
 
                       }
 
                       var responseStr = HttpHelper.GetHttpResponse(url + message.url, JsonConvert.DeserializeObject(message.requeststr), 5000);
                       var resFormat = JsonConvert.DeserializeObject<ResEntity>(responseStr);
 
                       message.isok = resFormat.resCode == "00000" ? (int)EYesOrNo.是 : (int)EYesOrNo.否;
 
                       message.updatetime = DateTime.Now;
 
                       message.retrytimes += 1;
 
                       dbModel.SaveChanges();
 
                       if (message.isok == (int)EYesOrNo.否)
                       {
                           msg = resFormat.resMsg;
                       }
 
                       return message.isok == (int)EYesOrNo.是;
 
                   }
                   catch (Exception ex)
                   {
                       msg = ex.Message;
                       var message = dbModel.LOGERRORFailSentMessages.FirstOrDefault(x => x.id == id);
                       message.isok = (int)EYesOrNo.否;
 
                       message.updatetime = DateTime.Now;
 
                       message.retrytimes += 1;
 
                       dbModel.SaveChanges();
                       LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "ReSend", msg);
                       return false;
                   }
               }
           }
 
           public bool PushBusinessException(int id, out string msg)
           {
               using (var dbModel2 = new DbModelLog())
               {
                   try
                   {
                       msg = "";
 
                       var message = dbModel2.LOGERRORFailSentMessages.FirstOrDefault(x => x.id == id);
 
                       if (message == null)
                       {
                           msg = string.Format("没有找到id为{0}的记录", id);
                           return false;
                       }
 
                       var requestBody = new
                       {
                           sysCode = "WCS",
                           taskNo = StringHelper.GetValue(message.requeststr, "taskNo"),
                           processCardNumber = StringHelper.GetValue(message.requeststr, "processCardNumber"),
                           exceptionCode = "001",
                           exceptionMsg = message.resmsg,
                           timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
                       };
 
                       var responseStr = HttpHelper.GetHttpResponse(Resources.WipUrl2 + @"/businessexception", requestBody, 5000);
 
                       LogTextHelper.WriteLine(Resources.LogDir, "PushBusinessException:responseStr = {0}", responseStr);
 
                       return true;
                   }
                   catch (Exception ex)
                   {
                       msg = ex.Message;
 
                       LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "PushBusinessException", msg);
                       return false;
                   }
 
               }
 
           }
 
         
    }
}