333
schangxiang@126.com
2025-09-19 18966e02fb573c7e2bb0c6426ed792b38b910940
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
using IWareCC.CacheInfo.Container;
using IWareCC.ORM;
using IWareCC.Properties;
using IWareCC.SRM.Entity;
using IWareCommon.Enum.Common;
using IWareCommon.Help;
using IWareCommon.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace IWareCC.SRM.Handle.FinishStackerTaskAuto
{
  public   class 获取当前的堆垛机任务 : IHandler
    {
        /// <summary>
        /// 该节点的下一个节点
        /// </summary>
        private IHandler nextHandler = null;
        public IHandler NextHandler
        {
            set { nextHandler = value; }
        }
 
        private SrmEntity Stacker;
 
        /// <summary>
        /// 任务容器
        /// </summary>
        private PartTaskContainer DecompositionTaskContainer;
 
 
        public 获取当前的堆垛机任务(SrmEntity stacker, PartTaskContainer decompositionTaskContainer)
        {
            this.Stacker = stacker;
            this.DecompositionTaskContainer = decompositionTaskContainer;
        }
 
 
        public void Handle()
        {
            using (var dbModel = new DbModel())
            {
                try
                {
                    if (Stacker.RAck)
                    {
                        Stacker.WriteValue(Stacker.OpcWriteItems.Stb, 0);//复位stp
                        LogTextHelper.WriteLine(Resources.LogDir + @"/自动执行堆垛机任务流程/" + Stacker.SrmName, "选择一个未执行的堆垛机的任务:堆垛机{0}已执行任务中,不能再下发任务", Stacker.SrmName);
                        return;
                    }
 
                    if (!Stacker.RTaskFinish && Stacker.WTaskFinishConfirm)
                    {
                        Stacker.WriteValue(Stacker.OpcWriteItems.TaskFinishConfirm,0);
                        return;
                    }
                    var task = dbModel.PartTasks.OrderBy(x => x.finishtimes).FirstOrDefault(x => x.iscurrent == (int)EYesOrNo.是 && x.isreleased == (int)EYesOrNo.是 && x.isfinished == (int)EYesOrNo.否 && x.eqtype == (int)EPartTaskType.堆垛机任务 && x.eqid == Stacker.DeviceId);
 
                    if (task == null)
                    {
                       // LogTextHelper.WriteLine(Resources.LogDir + @"/完成堆垛机任务/" + Stacker.SrmName, "获取当前的堆垛机任务:{0}", "没有找到待完成的任务");
                        return;
                    }
 
 
                    task.finishtimes += 1;
 
                    dbModel.SaveChanges();
 
                    DecompositionTaskContainer.DecompositionTask = task;
                    LogTextHelper.WriteLine(Resources.LogDir + @"/完成堆垛机任务/" + Stacker.SrmName, "获取当前的堆垛机任务:{0}", DecompositionTaskContainer.DecompositionTask.id);
 
                    if (nextHandler != null)
                    {
                        nextHandler.Handle();
                    }
 
                }
                catch (Exception ex)
                {
                    LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "Handle", ex.Message);
                }
            }
        }
    }
}