-
Notifications
You must be signed in to change notification settings - Fork 18
/
LUIS.cs
415 lines (390 loc) · 19.2 KB
/
LUIS.cs
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.IO;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Luis;
using Microsoft.Bot.Builder.Luis.Models;
using Microsoft.Bot.Connector;
using System.Text;
using Bot_Application2.Models;
using Newtonsoft.Json;
using System.Collections.Generic;
namespace VendingLuisDlg2
{
[LuisModel("da9e23fd-b4b5-496a-88b3-43484caef4f4", "e81aa411c89f4da88c7bda4022a846fc")]
[Serializable]
public class SimpleLUISDialog : LuisDialog<object>
{
public const string HELLO_ANSWERE = "您好,我是贩卖机管理小助手,请您先登录系统,输入验证码:";
public const string A_VERIFY = "验证成功,请问有什么可以帮您 ? ";
public const string A_MACHINE_PRODUCT_STATUS = "号贩卖机";
public const string A_MACHINE_PRODUCT_STATUS1 = "瓶可乐,";
public const string A_MACHINE_PRODUCT_STATUS2 = "瓶雪碧。";
public const string A_SUPPLY_PRODUCT = "已经安排了。请问还有什么可以帮您 ?";
public const string MACHINE_STATUS = "号贩卖机目前工作正常,但是,根据我们的预测,周六需要补充";
public const string MACHINE_STATUS2 = "瓶可乐。";
public const string A_MACHINE_LOCATION = "号贩卖机的具体位置请参考地图链接 http://j.map.baidu.com/TDG0F";
public const string A_MACHINE_POWERPI = "贩卖机整体状态PowerBi链接请参考 https://msit.powerbi.com/view?r=eyJrIjoiYWU2OTlkOGItYmNlMS00NmQ4LWJkMTUtMGE3YzRiOTU0MzM1IiwidCI6IjcyZjk4OGJmLTg2ZjEtNDFhZi05MWFiLTJkN2NkMDExZGI0NyIsImMiOjV9 ";
public const string ENTITY_MACHINENO = "";
public const string RE_CONFIRM = "不客气,请问还有什么可以帮您?";
public const string STATUS_QUERY_URL = "http://smartapi.chinacloudsites.cn/api/v1/querygoodsstatus?deviceid=98011609002D";
public const string TEMPER_QUERY_URL = "http://smartapi.chinacloudsites.cn/api/v1/querymachinestatus?deviceid=98011609002D";
private string machineNo = "1234";
//Hint: You can use google map link for showing the location info.
public string HttpGet(string Url, string postDataStr)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url + (postDataStr == "" ? "" : "?") + postDataStr);
request.Method = "GET";
request.ContentType = "text/html;charset=UTF-8";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream myResponseStream = response.GetResponseStream();
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
string retString = myStreamReader.ReadToEnd();
myStreamReader.Close();
myResponseStream.Close();
return retString;
}
[LuisIntent("")]
public async Task None(IDialogContext context, LuisResult result)
{
string message = $"对不起,目前我不支持这项服务,可以询问我:" + string.Join(", ", result.Intents.Select(i => i.Intent));
await context.PostAsync(message);
context.Wait(MessageReceived);
}
[LuisIntent("验证码")]
public async Task WeatherQuery(IDialogContext context, LuisResult result)
{
await context.PostAsync(A_VERIFY);
context.Wait(MessageReceived);
}
[LuisIntent("打招呼")]
public async Task SetTemp(IDialogContext context, LuisResult result)
{
await context.PostAsync(HELLO_ANSWERE);
context.Wait(MessageReceived);
}
[LuisIntent("贩卖机状态")]
public async Task DecreaseTemp(IDialogContext context, LuisResult result)
{
Random rd = new Random();
int number1 = rd.Next(1,50);
int number2 = rd.Next(1,15);
int numMachine = rd.Next(1000, 2000);
string num1 = Convert.ToString(number1);
string num2 = Convert.ToString(number2);
string machineNo = Convert.ToString(numMachine);
string machineStatus = HttpGet(STATUS_QUERY_URL,"");
QueryGoodsStatus goodsData = (QueryGoodsStatus)JsonConvert.DeserializeObject(machineStatus, typeof(QueryGoodsStatus));
if(true == goodsData.success)
{
StringBuilder MyStringBuilder = new StringBuilder();
string tempResult = "";
for (int i = 0; i< goodsData.goodsdata.Length; i++)
{
if(goodsData.goodsdata[i].goodsstatus == 1)
{
tempResult = goodsData.goodsdata[i].goodsno.ToString() + "货道" + "故障" +
"商品名称:"+ goodsData.goodsdata[i].goodsname;
MyStringBuilder.Append(tempResult);
MyStringBuilder.AppendLine("");
}
}
string finalStatusResult = MyStringBuilder.ToString();
if (finalStatusResult.Length > 1)
{
await context.PostAsync("0127" + A_MACHINE_PRODUCT_STATUS + finalStatusResult);
}
await context.PostAsync("0127" + A_MACHINE_PRODUCT_STATUS + "工作正常");
}
else
{
await context.PostAsync("无法查询到贩卖机状态,请稍后重试");
}
//await context.PostAsync(machineNo + A_MACHINE_PRODUCT_STATUS + num1 + A_MACHINE_PRODUCT_STATUS1 + num2 + A_MACHINE_PRODUCT_STATUS2);
//await context.PostAsync(machineStatus);
context.Wait(MessageReceived);
}
[LuisIntent("有无货物")]
public async Task goodsStatus(IDialogContext context, LuisResult result)
{
string machineStatus = HttpGet(STATUS_QUERY_URL, "");
QueryGoodsStatus goodsData = (QueryGoodsStatus)JsonConvert.DeserializeObject(machineStatus, typeof(QueryGoodsStatus));
if (true == goodsData.success)
{
List<Goodsdata> shortageGoods = new List<Goodsdata>();
List<string> resultGoods = new List<string>();
StringBuilder MyStringBuilder = new StringBuilder();
string tempResult = "";
int goodsStockNo;
for (int i = 0; i < goodsData.goodsdata.Length; i++)
{
if (goodsData.goodsdata[i].goodsstock == 1)
{
shortageGoods.Add(goodsData.goodsdata[i]);
goodsStockNo = goodsData.goodsdata[i].goodsno;
tempResult = goodsData.goodsdata[i].goodsno.ToString() + "货道" +
goodsData.goodsdata[i].goodsname + "缺货";
MyStringBuilder.Append(tempResult);
MyStringBuilder.AppendLine("");
}
}
string finalStatusResult = MyStringBuilder.ToString();
if(finalStatusResult.Length > 1)
{
await context.PostAsync("0127" + A_MACHINE_PRODUCT_STATUS + finalStatusResult);
}
else
{
await context.PostAsync("0127" + A_MACHINE_PRODUCT_STATUS + "货物充足");
}
}
else
{
await context.PostAsync("无法查询到贩卖机状态,请稍后重试");
}
//await context.PostAsync(machineNo + A_MACHINE_PRODUCT_STATUS + num1 + A_MACHINE_PRODUCT_STATUS1 + num2 + A_MACHINE_PRODUCT_STATUS2);
//await context.PostAsync(machineStatus);
context.Wait(MessageReceived);
}
[LuisIntent("货道状态")]
public async Task goodsLineStatus(IDialogContext context, LuisResult result)
{
string machineLineNo = result.Entities[0].Entity;
string machineStatus = HttpGet(STATUS_QUERY_URL, "");
QueryGoodsStatus goodsData = (QueryGoodsStatus)JsonConvert.DeserializeObject(machineStatus, typeof(QueryGoodsStatus));
if (true == goodsData.success)
{
StringBuilder MyStringBuilder = new StringBuilder();
string tempResult = "";
string goodsStockStatus ="";
string goodsStatus;
//int goodsStockNo;
for (int i = 0; i < goodsData.goodsdata.Length; i++)
{
if (goodsData.goodsdata[i].goodsno.ToString() == machineLineNo)
{
//shortageGoods.Add(goodsData.goodsdata[i]);
//goodsStockNo = goodsData.goodsdata[i].goodsno;
if(0 == goodsData.goodsdata[i].goodsstock)
{
goodsStockStatus = "有货";
}
else
{
goodsStockStatus = "缺货";
}
if(0 == goodsData.goodsdata[i].goodsstatus)
{
goodsStatus = "正常,";
}
else
{
goodsStatus = "故障,";
}
tempResult = goodsData.goodsdata[i].goodsno.ToString() + "号货道" + goodsStatus +
"商品名称:"+ goodsData.goodsdata[i].goodsname + goodsStockStatus;
MyStringBuilder.Append(tempResult);
MyStringBuilder.AppendLine("");
break;
}
}
if(goodsStockStatus.Length > 1)
{
string finalStatusResult = MyStringBuilder.ToString();
await context.PostAsync("0127" + A_MACHINE_PRODUCT_STATUS + finalStatusResult);
}
else
{
await context.PostAsync("0127" + A_MACHINE_PRODUCT_STATUS + "货道"+ machineLineNo
+ "不存在");
}
}
else
{
await context.PostAsync("无法查询到贩卖机状态,请稍后重试");
}
//await context.PostAsync(machineNo + A_MACHINE_PRODUCT_STATUS + num1 + A_MACHINE_PRODUCT_STATUS1 + num2 + A_MACHINE_PRODUCT_STATUS2);
//await context.PostAsync(machineStatus);
context.Wait(MessageReceived);
}
[LuisIntent("货道商品的名称")]
public async Task goodsLineName(IDialogContext context, LuisResult result)
{
string machineLineNo = result.Entities[0].Entity;
string machineStatus = HttpGet(STATUS_QUERY_URL, "");
QueryGoodsStatus goodsData = (QueryGoodsStatus)JsonConvert.DeserializeObject(machineStatus, typeof(QueryGoodsStatus));
if (true == goodsData.success)
{
StringBuilder MyStringBuilder = new StringBuilder();
string tempResult = "";
string goodsStockStatus ="";
//int goodsStockNo;
for (int i = 0; i < goodsData.goodsdata.Length; i++)
{
if (goodsData.goodsdata[i].goodsno.ToString() == machineLineNo)
{
//shortageGoods.Add(goodsData.goodsdata[i]);
//goodsStockNo = goodsData.goodsdata[i].goodsno;
if (0 == goodsData.goodsdata[i].goodsstock)
{
goodsStockStatus = "有货";
}
else
{
goodsStockStatus = "缺货";
}
tempResult = goodsData.goodsdata[i].goodsno.ToString() + "货道" +
"商品名称:" + goodsData.goodsdata[i].goodsname + goodsStockStatus;
MyStringBuilder.Append(tempResult);
MyStringBuilder.AppendLine("");
break;
}
}
if (goodsStockStatus.Length > 1)
{
string finalStatusResult = MyStringBuilder.ToString();
await context.PostAsync("0127" + A_MACHINE_PRODUCT_STATUS + finalStatusResult);
}
else
{
await context.PostAsync("0127" + A_MACHINE_PRODUCT_STATUS + "货道" + machineLineNo
+ "不存在");
}
}
else
{
await context.PostAsync("无法查询到贩卖机状态,请稍后重试");
}
//await context.PostAsync(machineNo + A_MACHINE_PRODUCT_STATUS + num1 + A_MACHINE_PRODUCT_STATUS1 + num2 + A_MACHINE_PRODUCT_STATUS2);
//await context.PostAsync(machineStatus);
context.Wait(MessageReceived);
}
[LuisIntent("补货请求")]
public async Task Reload_return(IDialogContext context, LuisResult result)
{
await context.PostAsync(A_SUPPLY_PRODUCT);
context.Wait(MessageReceived);
}
[LuisIntent("特定贩售机状态")]
public async Task IncreaseTemp(IDialogContext context, LuisResult result)
{
Random rd2 = new Random();
int number3 = rd2.Next(1,100);
string num3 = Convert.ToString(number3);
//string strRet = result.Entities[0].Entity;
machineNo = result.Entities[0].Entity;
await context.PostAsync(machineNo + MACHINE_STATUS + num3 + MACHINE_STATUS2);
context.Wait(MessageReceived);
machineNo = "1234";
}
[LuisIntent("贩售机位置")]
public async Task vendingMachineLoation(IDialogContext context, LuisResult result)
{
//machineNo = result.Entities[0].Entity;
await context.PostAsync("0127号" + A_MACHINE_LOCATION);
context.Wait(MessageReceived);
//machineNo = "1234";
}
[LuisIntent("整体状态")]
public async Task wholeStatusQuery(IDialogContext context, LuisResult result)
{
await context.PostAsync("0127号" + A_MACHINE_POWERPI);
context.Wait(MessageReceived);
}
[LuisIntent("感谢")]
public async Task Thanks_return(IDialogContext context, LuisResult result)
{
await context.PostAsync(RE_CONFIRM);
context.Wait(MessageReceived);
}
[LuisIntent("贩卖机的温度")]
public async Task tempuratureQuery(IDialogContext context, LuisResult result)
{
string machineTemperStatus = HttpGet(TEMPER_QUERY_URL, "");
MachineTemper machineTemper = (MachineTemper)JsonConvert.DeserializeObject(machineTemperStatus, typeof(MachineTemper));
if (true == machineTemper.success)
{
//List<Goodsdata> shortageGoods = new List<Goodsdata>();
List<string> resultMachineTmp = new List<string>();
StringBuilder MyStringBuilder = new StringBuilder();
string tempResult = "";
string temperMode = "关闭";
for (int i = 0; i < machineTemper.areadatas.Length; i++)
{
switch (machineTemper.areadatas[i].temperaturemode)
{
case 0:
temperMode = "关闭";
break;
case 1:
temperMode = "加热";
break;
case 2:
temperMode = "制冷";
break;
default:
break;
}
tempResult = machineTemper.areadatas[i].warmareaname + "温度:" + machineTemper.areadatas[i].temperature.ToString() +
" 温度模式:" + temperMode;
MyStringBuilder.Append(tempResult);
MyStringBuilder.AppendLine("");
}
string finalStatusResult = MyStringBuilder.ToString();
await context.PostAsync("0127" + A_MACHINE_PRODUCT_STATUS + "温度状态如下: \r\n"+ finalStatusResult);
}
else
{
await context.PostAsync("无法查询到贩卖机状态,请稍后重试");
}
//await context.PostAsync("贩卖机的温度状态如下:");
context.Wait(MessageReceived);
}
[LuisIntent("目前温度模式")]
public async Task tempuratureModeQuery(IDialogContext context, LuisResult result)
{
string machineTemperStatus = HttpGet(TEMPER_QUERY_URL, "");
MachineTemper machineTemper = (MachineTemper)JsonConvert.DeserializeObject(machineTemperStatus, typeof(MachineTemper));
if (true == machineTemper.success)
{
//List<Goodsdata> shortageGoods = new List<Goodsdata>();
List<string> resultMachineTmp = new List<string>();
StringBuilder MyStringBuilder = new StringBuilder();
string tempResult = "";
string temperMode = "关闭";
for (int i = 0; i < machineTemper.areadatas.Length; i++)
{
switch (machineTemper.areadatas[i].temperaturemode)
{
case 0:
temperMode = "关闭";
break;
case 1:
temperMode = "加热";
break;
case 2:
temperMode = "制冷";
break;
default:
break;
}
tempResult = machineTemper.areadatas[i].warmareaname + "模式:" + temperMode;
MyStringBuilder.Append(tempResult);
MyStringBuilder.AppendLine("");
}
string finalStatusResult = MyStringBuilder.ToString();
await context.PostAsync("0127" + A_MACHINE_PRODUCT_STATUS + "温度模式如下: \r\n" + finalStatusResult);
}
else
{
await context.PostAsync("无法查询到贩卖机状态,请稍后重试");
}
//await context.PostAsync("贩卖机的温度状态如下:");
context.Wait(MessageReceived);
}
}
}