BaseBll.cs
34.5 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
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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
using DMSkin.Core;
using System;
using System.Collections.Generic;
using System.Linq;
namespace HH_WCS_Standard
{
public class BaseBll
{
#region Task
/// <summary>
/// 创建任务
/// </summary>
/// <param name="WmsTno"></param>
/// <param name="e_TaskType"></param>
/// <param name="Entrance"></param>
/// <param name="Exit"></param>
/// <returns></returns>
public BllResult<I_Task> CreateTask(string WmsTno, string preTaskNo, string TaskType, string Pallet, string Entrance, string Exit, string PlatForm)
{
var taskcount = App.taskList.Count(a => a.PalletOrBoxNo == Pallet);
if (taskcount > 0)
{
return BllResult<I_Task>.Error($"该托盘号{Pallet}已有任务");
}
if (TaskType == E_TaskType.托盘出库.GetIndexString())
{
Exit = "ExitStationA01";
}
if (TaskType == E_TaskType.托盘入库.GetIndexString())
{
Entrance = "EntranceStationA01";
}
I_Task i_Task = new I_Task()
{
tNo_WMS = WmsTno,
preTaskNo = preTaskNo,
Type = TaskType,
NowState = E_TaskState.任务创建.GetIndexInt(),
PalletOrBoxNo = Pallet,
Priority = 0,
FromPlace = Entrance,
EntrancePlace = Entrance,
ExitPlace = Exit,
Task_CreateTime = DateTime.Now,
Task_CreateWho = PlatForm,
Task_StartTime = null,
Task_FinishTime = null,
SendAgainFlag = 0,
DeleteFlag = 0,
EmptyOutFlag = 0,
FullInFlag = 0,
Height = "0",
TaskSetp = 0
};
var taskflow = TaskMenu(i_Task);
if (!taskflow.Success)
{
return BllResult<I_Task>.Error($"创建任务时获取任务流程失败,{taskflow.Msg}");
}
i_Task.TaskFlow = taskflow.Data;
var nextchangeresult = NextStateChange(i_Task);
if (!nextchangeresult.Success)
{
return BllResult<I_Task>.Error("获取下一个任务状态失败");
}
var TaskNo = GetTaskNo();
if (!TaskNo.Success)
{
return BllResult<I_Task>.Error("创建任务时获取任务号失败");
}
i_Task.tNo = TaskNo.Data;
BaseDal<I_Task> _taskDb = new BaseDal<I_Task>();
var insetresult = _taskDb.Insert(i_Task);
if (insetresult.Success)
{
UIExecute.Run(() =>
{
App.taskList.Add(i_Task);
});
return BllResult<I_Task>.Sucess(i_Task, "成功");
}
else
{
return BllResult<I_Task>.Error("创建任务时插入数据库失败");
}
}
/// <summary>
/// 强制删除任务
/// </summary>
/// <param name="task"></param>
/// <returns></returns>
public BllResult TaskDelete(I_Task task)
{
//更新删除信息
Dictionary<string, object> lstColumnValues = new Dictionary<string, object>();
lstColumnValues.Add("ErrorMsg", "强制删除");
BaseDal<I_Task> _taskDb = new BaseDal<I_Task>();
_taskDb.BeginTran();
var updateresult = _taskDb.Update(lstColumnValues, a => a.tNo == task.tNo);
var deleteresult = _taskDb.Delete(a => a.tNo_WMS == task.tNo_WMS);
if (!deleteresult.Success)
{
_taskDb.RollbackTran();
LogExecute.logNet.WriteError($"该任务删除失败,删除WCS任务表信息失败");
return BllResult.Error($"该任务删除失败,删除WCS任务表信息失败");
}
else
{
_taskDb.CommitTran();
UIExecute.Run(() =>
{
App.taskList.Remove(task);
});
if (task.NowState == E_TaskState.下发堆垛机取货任务.GetIndexInt() || task.NowState == E_TaskState.下发堆垛机放货任务.GetIndexInt())
{
LogExecute.logNet.WriteDebug($"该任务删除成功,请至WCS手动界面删除堆垛机任务");
return BllResult.Sucess($"该任务删除成功,请至WCS手动界面删除堆垛机任务");
}
else
{
LogExecute.logNet.WriteDebug($"该任务{task.tNo}删除成功");
return BllResult.Sucess($"该任务{task.tNo}删除成功");
}
}
}
/// <summary>
/// 完成任务
/// </summary>
public void FinishTask()
{
var finishtasks = App.taskList.ToList().FindAll(a => a.NextState == E_TaskState.任务完成.GetIndexInt());
if (finishtasks.Count != 0)
{
int i = -1;
for (i = finishtasks.Count - 1; i >= 0; i--)
{
var task = finishtasks[i];
ReqTaskFinish reqTaskFinish = new ReqTaskFinish() { };
reqTaskFinish.taskNo = task.tNo_WMS;
reqTaskFinish.weight = "0";
if (task.Type == E_TaskType.托盘入库.GetIndexString() || task.Type == E_TaskType.分拣出库.GetIndexString())
{
reqTaskFinish.weight = task.Weight;
}
reqTaskFinish.isEmptyOut = 0;
reqTaskFinish.IsForkError = 0;
if (!string.IsNullOrWhiteSpace(task.FullInPlace))
{
reqTaskFinish.isDoubleIn = 1;
reqTaskFinish.redirectionLocationCode = task.ExitPlace;
}
if (!string.IsNullOrWhiteSpace(task.tNo_WMS) && task.tNo_WMS != "999999999")
{
var interfaceresult = WcsWebApiClient.FinishTask(reqTaskFinish);
if (!interfaceresult.Success)
{
LogExecute.logNet.WriteError($"完成任务时调用WMS接口失败,任务号{task.tNo},错误原因{interfaceresult.Msg}");
continue;
}
LogExecute.logNet.WriteDebug($"完成任务时调用WMS接口成功,任务号{task.tNo}");
}
task.Task_FinishTime = DateTime.Now;
I_Task_His i_Task_His = new I_Task_His();
i_Task_His.CopyTask(task);
//更新任务信息,删除任务信息,插入任务历史表
Dictionary<string, object> lstColumnValues = new Dictionary<string, object>();
lstColumnValues.Add("ErrorMsg", "自动完成");
lstColumnValues.Add("Task_FinishTime", DateTime.Now);
BaseDal<I_Task> _taskDb = new BaseDal<I_Task>();
_taskDb.BeginTran();
var updateresult = _taskDb.Update(lstColumnValues, a => a.tNo == task.tNo);
var deleteresult = _taskDb.Delete(a => a.tNo == task.tNo);
if (deleteresult.Success && updateresult.Success)
{
_taskDb.CommitTran();
UIExecute.Run(() =>
{
App.taskList.Remove(task);
});
LogExecute.logNet.WriteDebug($"任务{task.tNo},WMS任务号{task.tNo_WMS},托盘号{task.PalletOrBoxNo}已完成");
}
else
{
_taskDb.RollbackTran();
LogExecute.logNet.WriteError($"完成任务失败,任务号{task.tNo},WMS任务号{task.tNo_WMS},错误原因:更新或者删除任务表数据失败");
}
}
}
}
/// <summary>
/// 取消任务
/// </summary>
/// <param name="reqTaskCancel"></param>
/// <returns></returns>
public BllResult TaskCancel(string wmstno)
{
var task = App.taskList.FirstOrDefault(a => a.tNo_WMS == wmstno);
if (task == null)
{
return BllResult.Error($"该任务取消失败,找不到对应的任务");
}
else
{
if (task.NowState != E_TaskState.任务创建.GetIndexInt())
{
return BllResult.Error($"该任务取消失败,任务已经执行无法取消");
}
else
{
//更新删除信息
Dictionary<string, object> lstColumnValues = new Dictionary<string, object>();
lstColumnValues.Add("ErrorMsg", "取消任务");
BaseDal<I_Task> _taskDb = new BaseDal<I_Task>();
_taskDb.BeginTran();
var updateresult = _taskDb.Update(lstColumnValues, a => a.tNo == task.tNo);
var deleteresult = _taskDb.Delete(task);
if (deleteresult.Success)
{
_taskDb.CommitTran();
UIExecute.Run(() =>
{
App.taskList.Remove(task);
});
LogExecute.logNet.WriteDebug($"该任务{wmstno}取消成功");
return BllResult.Sucess($"该任务取消成功");
}
else
{
_taskDb.RollbackTran();
LogExecute.logNet.WriteError($"该任务{wmstno}取消失败,删除WCS任务表信息失败");
return BllResult.Error($"该任务取消失败,删除WCS任务表信息失败");
}
}
}
}
/// <summary>
/// 查询任务当前状态
/// </summary>
/// <param name="reqTaskInfo"></param>
/// <returns></returns>
public BllResult<I_Task> GetTaskInfo(ReqTaskInfo reqTaskInfo)
{
var task = App.taskList.FirstOrDefault(a => a.tNo_WMS == reqTaskInfo.taskNo);
if (task == null)
{
return BllResult<I_Task>.Error("查询该任务号对应的任务失败");
}
return BllResult<I_Task>.Sucess(task, "查询成功");
}
/// <summary>
/// 满入处理
/// </summary>
/// <param name="wcstaskno"></param>
/// <returns></returns>
public BllResult<I_Pose> FullInExcute(string taskno)
{
var task = App.taskList.FirstOrDefault(a => a.tNo_WMS == taskno);
LogExecute.ApilogNet.WriteDebug($"请求WMS满入处理(任务{taskno}),获取新的仓位");
ReqOverrideHandle reqOverrideHandle = new ReqOverrideHandle()
{
taskNo = taskno,
toLocationCode = task.ExitPlace,
redirectionLocationCode = "0"
};
var apiResult = WcsWebApiClient.OverrideHandle(reqOverrideHandle);
if (apiResult.Success)
{
var pose = apiResult.Data.redirectionLocationCode;
I_Pose _pose = App.poseList.FirstOrDefault(a => a.wcName == pose);
if (_pose != null)
{
BaseDal<I_Task> taskDb = new BaseDal<I_Task>();
taskDb.BeginTran();
Dictionary<string, object> dict = new Dictionary<string, object>();
dict.Add("FullInPlace", task.ExitPlace);
dict.Add("ExitPlace", pose);
dict.Add("ToPlace", pose);
dict.Add("FullInFlag", 1);
var updateResult = taskDb.Update(dict, a => a.tNo == task.tNo);
if (updateResult.Success)
{
taskDb.CommitTran();
task.FullInPlace = task.ExitPlace;
task.ExitPlace = pose;
task.ToPlace = pose;
task.FullInFlag = 1;
LogExecute.logNet.WriteDebug($"请求WMS满入处理成功,新库位{_pose}已获取");
return BllResult<I_Pose>.Sucess(_pose);
}
else
{
taskDb.RollbackTran();
LogExecute.logNet.WriteError($"请求WMS满入处理成功,更新原目标库位至满入库位失败");
return BllResult<I_Pose>.Error($"请求WMS满入处理成功,更新原目标库位至满入库位失败");
}
}
else
{
LogExecute.logNet.WriteError($"请求WMS满入处理重新分配的库位在不在库位表中,请重试:{apiResult.Data.redirectionLocationCode}");
return BllResult<I_Pose>.Error($"请求WMS满入处理重新分配的库位在不在库位表中,请重试:{apiResult.Data.redirectionLocationCode}");
}
}
else
LogExecute.logNet.WriteError($"请求WMS满入接口失败,错误原因是:{apiResult.Msg}");
return BllResult<I_Pose>.Error($"请求WMS满入接口失败,错误原因是:{apiResult.Msg}");
}
/// <summary>
/// 空出处理
/// </summary>
/// <param name="wcstaskno"></param>
/// <returns></returns>
public BllResult EmptyOutExcute(string taskno)
{
ReqEmptyOut reqEmptyOut = new ReqEmptyOut() { taskNo = taskno };
var apiResult = WcsWebApiClient.EmptyOutHandle(reqEmptyOut);
if (apiResult.Success)
{
var task = App.taskList.FirstOrDefault(a => a.tNo_WMS == taskno);
var delResult = TaskDelete(task);
if (delResult.Success)
{
App.taskList.Remove(task);
LogExecute.logNet.WriteDebug($"空出处理成功,任务信息{taskno}已删除");
return BllResult.Sucess($"空出处理成功,任务信息{taskno}已删除");
}
else
LogExecute.logNet.WriteError($"空出处理失败,WCS任务删除失败,错误原因是{delResult.Msg}");
return BllResult.Error($"空出处理失败,WCS任务删除失败,错误原因是{delResult.Msg}");
}
else
LogExecute.logNet.WriteError($"请求WMS接口空出失败,任务号是{taskno},错误原因是{apiResult.Msg}");
return BllResult.Error($"请求WMS接口空出失败,任务号是{taskno},错误原因是{apiResult.Msg}");
}
/// <summary>
/// 取货错处理
/// </summary>
/// <param name="wcstaskno"></param>
/// <returns></returns>
public BllResult TakeErrExcute(string taskno)
{
ReqTakeError reqTakeError = new ReqTakeError() { taskNo = taskno };
LogExecute.logNet.WriteDebug($"取货错处理请求WMS接口,任务号{taskno}");
var result = WcsWebApiClient.TakeErrHandle(reqTakeError);
if (result.Success)
{
var task = App.taskList.FirstOrDefault(a => a.tNo_WMS == taskno);
var delResult = TaskDelete(task);
if (delResult.Success)
{
App.taskList.Remove(task);
LogExecute.logNet.WriteDebug($"取货错处理,WMS接口响应成功,{delResult.Msg}");
return BllResult.Sucess($"取货错处理,WMS接口处理成功,{delResult.Msg}");
}
else
{
LogExecute.logNet.WriteError($"取货错处理,WMS接口响应成功,任务删除失败,错误信息为{delResult.Msg}");
return BllResult.Error($"取货错处理,WMS接口响应成功,任务删除失败,错误信息为{delResult.Msg}");
}
}
else
{
LogExecute.logNet.WriteError($"取货错处理:WMS接口处理响应失败,错误原因是{result.Msg}");
return BllResult.Error($"取货错处理:WMS接口处理响应失败,错误原因是{result.Msg}");
}
}
/// <summary>
/// 堆垛机取到货(接口处理)
/// </summary>
/// <param name="wmstno"></param>
/// <returns></returns>
public BllResult SrmLoad(string wmstno)
{
return BllResult.Error($"请求WMS堆垛机已取货失败");
}
/// <summary>
/// 获取仓位
/// </summary>
/// <param name="task"></param>
/// <returns></returns>
public BllResult GetWareCell(I_Task task)
{
ReqWarecellAllocation reqWarecellAllocation = new ReqWarecellAllocation()
{
//后续根据实际需要填写 (接口定义的是float,但这里定义的是string)
taskNo = task.tNo_WMS,
weight = task.Weight,
height = task.Height,
platform = "0"
};
LogExecute.logNet.WriteDebug($"向WMS申请仓位:任务号:{task.tNo_WMS},条码:{task.PalletOrBoxNo},重量:{task.Weight},高度:{task.Height}");
var apiResult = WcsWebApiClient.GetWareCellHandle(reqWarecellAllocation);
if (apiResult.Success)
{
LogExecute.logNet.WriteDebug($"接口请求仓位获取成功,仓位为{apiResult.Data.toLocationCode},任务号:{task.tNo},条码:{task.PalletOrBoxNo}");
return BllResult.Sucess(apiResult.Data.toLocationCode, "接口请求仓位获取成功");
}
else
{
LogExecute.logNet.WriteError($"接口请求仓位获取失败,任务号是{task.tNo},原因:{apiResult.Msg}");
return BllResult.Error($"接口请求仓位获取失败,任务号是{task.tNo}");
}
}
/// <summary>
/// 到达操作任务回传处理
/// </summary>
/// <returns></returns>
//public BllResult TaskStatusFeedBackExcute(I_Task task)
//{
// ReqTaskStatusFeedBack reqTaskPostBack = new ReqTaskStatusFeedBack()
// {
// taskNo = task.tNo_WMS,
// state = E_TaskState.响应出入口地址到达.GetIndexInt(),
// currentEquipmentName = "出库口(P1007)"
// };
// var apiResult = WcsWebApiClient.TaskStatusFeedBack(reqTaskPostBack);
// if (apiResult.Success)
// {
// LogExecute.logNet.WriteDebug($"托盘号{task.PalletOrBoxNo},任务号{task.tNo},到达操作口任务回传成功");
// return BllResult.Sucess($"托盘号{task.PalletOrBoxNo},任务号{task.tNo},到达操作口任务回传成功");
// }
// else
// {
// LogExecute.logNet.WriteError($"托盘号{task.PalletOrBoxNo}到达操作口任务回传失败");
// return BllResult.Error($"托盘号{task.PalletOrBoxNo}到达操作口任务回传失败");
// }
//}
#endregion Task
#region ChangeTaskValue
public BllResult<int> TaskMenu(I_Task task)
{
var entrancepose = App.poseList.FirstOrDefault(a => a.wcName == task.EntrancePlace);
//var exitpose = App.poseList.FirstOrDefault(a => a.wcName == task.ExitPlace);
if (entrancepose == null )//|| exitpose == null)
{
return BllResult<int>.Error($"找不到起点或终点对应的站点类型,{task.Type},{ task.EntrancePlace},{task.ExitPlace}");
}
var result = App.taskflowList.FindAll(a => a.TaskType == task.Type && a.EntranceType == entrancepose.wcType);//&& a.ExitType == exitpose.wcType);
if (result.Count == 0)
{
return BllResult<int>.Error($"找不到起点或终点对应的任务流程,{task.Type},{entrancepose.wcName}");//,{exitpose.wcName}");
}
var group = result.GroupBy(a => a.Menu);
if (group.Count() != 1)
{
string _menus = "";
foreach (var a in group)
{
_menus += a.Key.ToString() + ",";
}
return BllResult<int>.Error($"找到{group.Count()}条起点或终点对应的任务流程,Menu值为{_menus}");
}
return BllResult<int>.Sucess(group.First().Key, "");
}
public BllResult NextStateChange(I_Task task)
{
BaseDal<I_Task> baseDal = new BaseDal<I_Task>();
var taskflow = App.taskflowList.FirstOrDefault(a => a.Menu == task.TaskFlow && a.Setp == task.TaskSetp + 1);
if (taskflow != null)
{
string from = taskflow.FromPlace;
if (taskflow.FromPlace == "Entrance")
{
from = task.EntrancePlace;
}
else if (taskflow.FromPlace == "Exit")
{
from = task.ExitPlace;
}
string to = taskflow.ToPlace;
if (taskflow.ToPlace == "Entrance")
{
to = task.EntrancePlace;
}
else if (taskflow.ToPlace == "Exit")
{
to = task.ExitPlace;
}
task.NowState = taskflow.NowState;
task.NextState = taskflow.NextState;
task.FromPlace = from;
task.ToPlace = to;
task.TaskSetp += 1;
return BllResult.Sucess();
}
else
{
return BllResult.Error($"找不到当前任务的下一个流程,任务号{task.tNo},当前任务状态{task.NowState},当前位置{task.FromPlace}");
}
}
public BllResult NextStateChange(I_Task task, BaseDal<I_Task> baseDal)
{
var taskflow = App.taskflowList.FirstOrDefault(a => a.Menu == task.TaskFlow && a.Setp == task.TaskSetp + 1);
if (taskflow != null)
{
string from = taskflow.FromPlace;
if (taskflow.FromPlace == "Entrance")
{
from = task.EntrancePlace;
}
else if (taskflow.FromPlace == "Exit")
{
from = task.ExitPlace;
}
string to = taskflow.ToPlace;
if (taskflow.ToPlace == "Entrance")
{
to = task.EntrancePlace;
}
else if (taskflow.ToPlace == "Exit")
{
to = task.ExitPlace;
}
Dictionary<string, object> lstColumnValues = new Dictionary<string, object>();
lstColumnValues.Add("NowState", taskflow.NowState);
lstColumnValues.Add("NextState", taskflow.NextState);
lstColumnValues.Add("FromPlace", from);
lstColumnValues.Add("ToPlace", to);
lstColumnValues.Add("TaskSetp", task.TaskSetp + 1);
var updateresult = baseDal.Update(lstColumnValues, a => a.tNo == task.tNo);
if (updateresult.Success)
{
return BllResult.Sucess();
}
else
{
return BllResult.Error($"更新下一个流程失败,任务号{task.tNo},当前任务状态{task.NowState},当前位置{task.FromPlace}");
}
}
else
{
return BllResult.Error($"找不到当前任务的下一个流程,任务号{task.tNo},当前任务状态{task.NowState},当前位置{task.FromPlace}");
}
}
/// <summary>
/// 更新任务状态缓存
/// </summary>
/// <param name="task"></param>
/// <param name="baseDal"></param>
/// <returns></returns>
public BllResult NextStateChangeCache(I_Task task)
{
var taskflow = App.taskflowList.FirstOrDefault(a => a.Menu == task.TaskFlow && a.Setp == task.TaskSetp + 1);
if (taskflow != null)
{
string from = taskflow.FromPlace;
if (taskflow.FromPlace == "Entrance")
{
from = task.EntrancePlace;
}
else if (taskflow.FromPlace == "Exit")
{
from = task.ExitPlace;
}
string to = taskflow.ToPlace;
if (taskflow.ToPlace == "Entrance")
{
to = task.EntrancePlace;
}
else if (taskflow.ToPlace == "Exit")
{
to = task.ExitPlace;
}
task.NowState = taskflow.NowState;
task.NextState = taskflow.NextState;
task.FromPlace = from;
task.ToPlace = to;
task.TaskSetp += 1;
return BllResult.Sucess();
}
else
{
return BllResult.Error($"找不到当前任务的下一个流程,任务号{task.tNo},当前任务状态{task.NowState},当前位置{task.FromPlace}");
}
}
public BllResult LastStateChange(I_Task task)
{
BaseDal<I_Task> baseDal = new BaseDal<I_Task>();
var taskflow = App.taskflowList.FirstOrDefault(a => a.Menu == task.TaskFlow && a.Setp == task.TaskSetp - 1);
if (taskflow != null)
{
string from = taskflow.FromPlace;
if (taskflow.FromPlace == "Entrance")
{
from = task.EntrancePlace;
}
else if (taskflow.FromPlace == "Exit")
{
from = task.ExitPlace;
}
string to = taskflow.ToPlace;
if (taskflow.ToPlace == "Entrance")
{
to = task.EntrancePlace;
}
else if (taskflow.ToPlace == "Exit")
{
to = task.ExitPlace;
}
task.NowState = taskflow.NowState;
task.NextState = taskflow.NextState;
task.FromPlace = from;
task.ToPlace = to;
task.TaskSetp -= 1;
return BllResult.Sucess();
}
else
{
return BllResult.Error($"找不到当前任务的上一个流程,任务号{task.tNo},当前任务状态{task.NowState},当前位置{task.FromPlace}");
}
}
public BllResult LastStateChange(I_Task task, BaseDal<I_Task> baseDal)
{
var taskflow = App.taskflowList.FirstOrDefault(a => a.Menu == task.TaskFlow && a.Setp == task.TaskSetp - 1);
if (taskflow != null)
{
string from = taskflow.FromPlace;
if (taskflow.FromPlace == "Entrance")
{
from = task.EntrancePlace;
}
else if (taskflow.FromPlace == "Exit")
{
from = task.ExitPlace;
}
string to = taskflow.ToPlace;
if (taskflow.ToPlace == "Entrance")
{
to = task.EntrancePlace;
}
else if (taskflow.ToPlace == "Exit")
{
to = task.ExitPlace;
}
Dictionary<string, object> lstColumnValues = new Dictionary<string, object>();
lstColumnValues.Add("NowState", taskflow.NowState);
lstColumnValues.Add("NextState", taskflow.NextState);
lstColumnValues.Add("FromPlace", from);
lstColumnValues.Add("ToPlace", to);
lstColumnValues.Add("TaskSetp", task.TaskSetp - 1);
var updateresult = baseDal.Update(lstColumnValues, a => a.tNo == task.tNo);
if (updateresult.Success)
{
task.NowState = taskflow.NowState;
task.NextState = taskflow.NextState;
task.FromPlace = from;
task.ToPlace = to;
task.TaskSetp -= 1;
return BllResult.Sucess();
}
else
{
return BllResult.Error($"回滚上一个流程失败,任务号{task.tNo},当前任务状态{task.NowState},当前位置{task.FromPlace}");
}
}
else
{
return BllResult.Error($"找不到当前任务的上一个流程,任务号{task.tNo},当前任务状态{task.NowState},当前位置{task.FromPlace}");
}
}
public BllResult ChangeState(I_Task task, int setp)
{
var taskflow = App.taskflowList.FirstOrDefault(a => a.Menu == task.TaskFlow && a.Setp == setp);
if (taskflow != null)
{
string from = taskflow.FromPlace;
if (taskflow.FromPlace == "Entrance")
{
from = task.EntrancePlace;
}
else if (taskflow.FromPlace == "Exit")
{
from = task.ExitPlace;
}
string to = taskflow.ToPlace;
if (taskflow.ToPlace == "Entrance")
{
to = task.EntrancePlace;
}
else if (taskflow.ToPlace == "Exit")
{
to = task.ExitPlace;
}
BaseDal<I_Task> baseDal = new BaseDal<I_Task>();
Dictionary<string, object> lstColumnValues = new Dictionary<string, object>();
lstColumnValues.Add("NowState", taskflow.NowState);
lstColumnValues.Add("NextState", taskflow.NextState);
lstColumnValues.Add("FromPlace", from);
lstColumnValues.Add("ToPlace", to);
lstColumnValues.Add("TaskSetp", setp);
var updateresult = baseDal.Update(lstColumnValues, a => a.tNo == task.tNo);
if (updateresult.Success)
{
task.NowState = taskflow.NowState;
task.NextState = taskflow.NextState;
task.FromPlace = from;
task.ToPlace = to;
task.TaskSetp = setp;
return BllResult.Sucess();
}
else
{
return BllResult.Error($"回滚上一个流程失败,任务号{task.tNo},当前任务状态{task.NowState},当前位置{task.FromPlace}");
}
}
else
{
return BllResult.Error($"找不到当前任务的上一个流程,任务号{task.tNo},当前任务状态{task.NowState},当前位置{task.FromPlace}");
}
}
#endregion ChangeTaskValue
#region Default
public BllResult<string> GetTaskNo()
{
BaseDal<T_BaseNumber> _numDb = new BaseDal<T_BaseNumber>();
var result = _numDb.Query(a => a.Value == "Tno");
if (result.Success)
{
string tno = result.Data[0].VKey;
int nowyear = DateTime.Now.Year;
int nowmin = DateTime.Now.Month;
int nowday = DateTime.Now.Day;
int year = int.Parse(tno.Substring(0, 4));
int min = int.Parse(tno.Substring(4, 2));
int day = int.Parse(tno.Substring(6, 2));
int index = int.Parse(tno.Substring(8, 6));
if (nowyear == year && nowmin == min && nowday == day)
{
index += 1;
}
else
{
index = 1;
}
string renewtno = nowyear.ToString() + nowmin.ToString().PadLeft(2, '0') + nowday.ToString().PadLeft(2, '0') + index.ToString().PadLeft(6, '0');
Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
keyValuePairs.Add("VKey", renewtno);
result.Data[0].VKey = renewtno;
//var update = _numDb.Update(result.Data[0]);
var update = _numDb.Update(keyValuePairs, a => a.Value == result.Data[0].Value);
if (update.Success)
{
return BllResult<string>.Sucess(renewtno, "");
}
}
return BllResult<string>.Error();
}
public string GetTime(int millisecond)
{
try
{
//LogExecute.logNet.WriteDebug($"读取到的PLC时间是{millisecond}");
string result = "";
int hour = 0;
int minute = 0;
int second = 0;
second = Convert.ToInt32(millisecond / 1000);
if (second > 60)
{
if (second > 3600)
{
hour = second / 3600;
minute = second % 3600 / 60;
second = second % 3600 % 60 % 60;
}
else
{
minute = second / 60;
second = second % 60;
}
}
result = hour.ToString().PadLeft(2, '0') + ":" + minute.ToString().PadLeft(2, '0') + ":" + second.ToString().PadLeft(2, '0');
//LogExecute.logNet.WriteDebug($"转换后的时间是{result}");
return result;
}
catch (Exception ex)
{
LogExecute.logNet.WriteDebug("time时间转换报错" + ex.Message);
throw new Exception("time时间转换报错" + ex.Message);
}
}
#endregion Default
}
}