HttpManager.cs
8.7 KB
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
using Common;
using Common.Communication;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
namespace DeviceLib.BLL
{
public class HttpManager
{
//http://localhost:8001/smf-core/service/store/innerBox/boxTakeAway?rfid=CN0020B
static string baseUrl = AppConfigSetting.GetStrVal(Setting_Str.HttpServer, "http://localhost:8001/smf-core");
static HttpClient httpClient = new HttpClient(baseUrl);
/// <summary>
/// 清除料箱与工单的绑定
/// </summary>
/// <param name="rfid"></param>
/// <returns></returns>
//public static bool ClearBoxBind(string rfid="")
//{
// try
// {
// //if (string.IsNullOrEmpty(rfid)) return false;
// //HttpClient httpClient = new HttpClient(baseUrl);
// Dictionary<string, string> queryStr = new Dictionary<string, string>();
// queryStr.Add("rfid", rfid);
// string json = httpClient.Get("/service/store/innerBox/boxTakeAway", queryStr);
// RtnData rtnData = JsonHelper.DeserializeJsonToObject<RtnData>(json);
// LogUtil.Info($"清除料箱绑定:【{rfid}】【{json}】");
// if (rtnData != null)
// {
// return rtnData.code == 0;
// }
// }
// catch(Exception ex)
// {
// LogUtil.Error($"清除料箱绑定异常:【{rfid}】",ex);
// }
// return false;
//}
public static bool ClearBoxBind(string rfid,string source)
{
try
{
//if (string.IsNullOrEmpty(rfid)) return false;
//HttpClient httpClient = new HttpClient(baseUrl);
Dictionary<string, string> queryStr = new Dictionary<string, string>();
queryStr.Add("rfid", rfid);
queryStr.Add("source", source);
string json = httpClient.Get("/service/store/innerBox/clearRfidInfo", queryStr);
RtnData rtnData = JsonHelper.DeserializeJsonToObject<RtnData>(json);
LogUtil.Info($"清理料箱信息:【{rfid}】【{json}】");
if (rtnData != null)
{
return rtnData.code == 0;
}
}
catch (Exception ex)
{
LogUtil.Error($"清理料箱信息:【{rfid}】", ex);
}
return false;
}
/// <summary>
/// 料箱送入agv
/// </summary>
/// <param name="rfid"></param>
/// <param name="boxTaskInfo"></param>
/// <returns></returns>
public static bool BoxToAgv(string rfid,string agvName)
{
try
{
if (string.IsNullOrEmpty(rfid)) return false;
//HttpClient httpClient = new HttpClient(baseUrl);
Dictionary<string, string> queryStr = new Dictionary<string, string>();
queryStr.Add("rfid", rfid);
string json = httpClient.Get("/service/store/innerBox/boxToAgv", queryStr);
RtnData rtnData = JsonHelper.DeserializeJsonToObject<RtnData>(json);
LogUtil.Info($"料箱送入agv:【{rfid}】【{agvName}】【{json}】");
if (rtnData != null)
{
return rtnData.code == 0;
}
}
catch (Exception ex)
{
LogUtil.Error($"料箱送入agv:【{rfid}】【{agvName}】", ex);
}
return false;
}
//public static bool GetBoxTarget(string rfid,out BoxTaskInfo boxTaskInfo)
//{
// boxTaskInfo = null;
// try
// {
// if (string.IsNullOrEmpty(rfid)) return false;
// //HttpClient httpClient = new HttpClient(baseUrl);
// Dictionary<string, string> queryStr = new Dictionary<string, string>();
// queryStr.Add("rfid", rfid);
// string json = httpClient.Get("/service/store/innerBox/getBoxStatusInfo", queryStr);
// ServerData1 rtnData = JsonHelper.DeserializeJsonToObject<ServerData1>(json);
// LogUtil.Info($"获取料箱信息:【{rfid}】【{json}】");
// if (rtnData != null)
// {
// boxTaskInfo = rtnData.data;
// return rtnData.code == 0;
// }
// }
// catch (Exception ex)
// {
// LogUtil.Error($"获取料箱信息:【{rfid}】", ex);
// }
// return false;
//}
public static bool GetBoxTarget(string rfid, out BoxTaskInfo boxTaskInfo)
{
boxTaskInfo = null;
try
{
if (string.IsNullOrEmpty(rfid)) return false;
//HttpClient httpClient = new HttpClient(baseUrl);
Dictionary<string, string> queryStr = new Dictionary<string, string>();
queryStr.Add("rfid", rfid);
string json = httpClient.Get("/service/store/innerBox/getAgvLineInfo", queryStr);
ServerData1 rtnData = JsonHelper.DeserializeJsonToObject<ServerData1>(json);
LogUtil.Info($"获取料箱信息:【{rfid}】【{json}】");
if (rtnData != null)
{
boxTaskInfo = rtnData.data;
return rtnData.code == 0;
}
}
catch (Exception ex)
{
LogUtil.Error($"获取料箱信息:【{rfid}】", ex);
}
return false;
}
static string Addr_GetNIOutInfo = "/service/store/innerBox/getNlOutInfo";
public static bool getNIOutInfo(out string line)
{
line = "";
try
{
//Dictionary<string, string> queryStr = new Dictionary<string, string>();
//queryStr.Add("rfid", rfid);
string json = httpClient.Get(Addr_GetNIOutInfo);
ServerData4 rtnData = JsonHelper.DeserializeJsonToObject<ServerData4>(json);
if (rtnData != null && rtnData.code==0)
{
LogUtil.Debug($"获取料架单独出库信息:【{json}】");
line=rtnData.data.line;
return true;
}
}
catch (Exception ex)
{
LogUtil.Error($"获取料架单独出库信息", ex);
}
return false;
}
}
public class ServerData4
{
//{"code":0,"msg":"ok","data":"7"}
public int code { get; set; }
public string msg { get; set; }
public NIOutInfo data { get; set; }
}
public class NIOutInfo
{
public string line { get; set; }
}
public class ServerData1
{
public int code { get; set; }
public string msg { get; set; }
public BoxTaskInfo data { get; set; }
}
/// <summary>
/// 箱子剩余数量
/// </summary>
public class BoxTaskInfo
{
public string outlet { get; set; }
public string cid { get; set; }
public string rfid { get; set; }
/// <summary>
/// 所属需求单剩余当前料仓未完成任务数
/// </summary>
public int remainTaskCount { get; set; } = -1;
/// <summary>
/// 所属需求单剩余料架任务数
/// </summary>
public int rackTaskCount { get; set; } = -1;
/// <summary>
/// 需求单号
/// </summary>
public string hSerial { get; set; } = "";
/// <summary>
/// 目的地
/// </summary>
public string line { get; set; } = "";
/// <summary>
/// 当前料箱隔口内侧已放入
/// </summary>
public int boxTCount { get; set; } = -1;
public int boxBCount { get; set; } = -1;
public string ToStr()
{
return $"内侧格口已有数量:{boxTCount},外侧格口已有数量;{boxBCount}; 需求单:{hSerial},剩余任务数={remainTaskCount}," +
$"剩余料架数:{rackTaskCount},目的地:{line}";
}
}
public class RtnData
{
//{
//"code": 0,
//"data": "",
//"msg": "ok",
//"msgKey": "smfcore.ok",
//"okResult": true,
//"params": []
//}
public int code { get; set; }
public string data { get; set; }
public string msg { get; set; }
}
}