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
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
using IWareCC.CacheInfo.Container;
using IWareCC.Conveyor.Entity;
using IWareCC.ORM;
using IWareCC.Properties;
using IWareCC.wmsService;
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.Conveyor.Handle.FinishConveyorTaskAuto
{
  public  class 将输送线完成结果更新至数据库 : IHandler
    {
        /// <summary>
        /// 该节点的下一个节点
        /// </summary>
        private IHandler nextHandler = null;
        public IHandler NextHandler
        {
            set { nextHandler = value; }
        }
 
        private ConveyorEntity Conveyor;
 
        /// <summary>
        /// 任务容器
        /// </summary>
        private PartTaskContainer DecompositionTaskContainer;
 
 
        public 将输送线完成结果更新至数据库(PartTaskContainer decompositionTaskContainer)
        {
            this.DecompositionTaskContainer = decompositionTaskContainer;
        }
 
 
        public void Handle()
        {
            using (var dbModel = new DbModel())
            {
                try
                {
                    var task = DecompositionTaskContainer.DecompositionTask;
                    var parttask = dbModel.PartTasks.FirstOrDefault(x => x.isfinished == (int)EYesOrNo.否 && x.id == task.id);
                    parttask.isfinished = (int)EYesOrNo.是;
                    parttask.status = (int)EPartTaskStatus.已完成;
                    parttask.updatetime = DateTime.Now;
                    parttask.iscurrent = (int)EYesOrNo.否;
                    parttask.filereason = "";
                    var maintask = dbModel.MainTasks.OrderByDescending(x => x.id).FirstOrDefault(x => x.id == parttask.maintaskid);
                    if (maintask != null)
                    {
                        if (parttask.nexthandel == (int)ENextHandelTask.已全部完成)
                        {
                            maintask.finishstatus = 1;//任务已经全部完成
                        }
                        #region 入库高度检测处理
                        if ((parttask.sourceplace == "1021" && parttask.toplace == "1022") || (parttask.sourceplace == "1026" && parttask.toplace == "1027"))
                        {
                            if (task.heighttype != 0)//根据接收到的获取高度调取接口获取目标库位信息以及那个立库
                            {
                                IapitestClient iapservice = new IapitestClient();
                                string toplace = iapservice.getToPlace(int.Parse(maintask.taskno), task.containertype, task.heighttype);
                                LogTextHelper.WriteLine(Resources.LogDir + @"/完成输送线任务/" + "Line" + parttask.sourceplace, "高度是{0}Wcf返回位置{1}", task.heighttype, string.IsNullOrEmpty(toplace) ? "无目标位置" : toplace);
                                if (!string.IsNullOrEmpty(toplace))//获取到了目标库位任务号和目标库位
                                {
                                    maintask.heighttype = task.heighttype;
                                    maintask.toplace = toplace.Substring(2);
                                    maintask.storageno = int.Parse(toplace.Substring(0, 1));
                                    parttask.targetplace = toplace.Substring(2);
                                    parttask.storageno = int.Parse(toplace.Substring(0, 1));
                                    parttask.heighttype = task.heighttype;
                                }
                                else
                                {
                                    maintask.finishstatus = 3;
                                    parttask.nexthandel = (int)ENextHandelTask.已全部完成;
                                    parttask.ishandled = (int)EYesOrNo.是;
                                    PartTask otparttask = new PartTask
                                    {
                                        maintaskid = task.id,
                                        maintasktype = task.maintasktype,
                                        executionsequence = 1,
                                        sourceplace = task.toplace,
                                        status = (int)EPartTaskStatus.开始执行,
                                        createtime = DateTime.Now,
                                        updatetime = DateTime.Now,
                                        voidlabel = (int)EYesOrNo.否,
                                        priority = 100,
                                        ismovetask = (int)EYesOrNo.否,
                                        packageno = "0000",
                                        taskcode = NumberHelp.GenerateRandomCode(),
                                        targetplace = "0",
                                        containertype = task.containertype,
                                        toplace = task.sourceplace,
                                        heighttype = (int)task.heighttype,
                                        storageno = task.storageno,
                                        ishandled = (int)EYesOrNo.是,
                                        eqtype = (int)EPartTaskType.输送线任务,
                                        type = (int)ENextHandelTask.入库处库口出库输送线任务,
                                        nexthandel = (int)ENextHandelTask.已全部完成
                                    };
                                    if (task.toplace == "1027")
                                    {
                                        otparttask.toplace = "1026";
                                        otparttask.eqid = (int)EDeviceId.Line1027号输送线;
                                        otparttask.eqname = EDeviceId.Line1027号输送线.ToString();
                                    }
                                    else
                                    {
                                        otparttask.toplace = "1021";
                                        otparttask.eqid = (int)EDeviceId.Line1022号输送线;
                                        otparttask.eqname = EDeviceId.Line1022号输送线.ToString();
                                    }
                                    dbModel.PartTasks.Add(otparttask);
                                }
                            }
                            LogTextHelper.WriteLine(Resources.LogDir + @"/完成输送线任务/" + "Line" + parttask.sourceplace, "高度是{0}位置{1}", task.heighttype, parttask.toplace);
                        } 
                        #endregion
                    }
                    
                    dbModel.SaveChanges();
 
                    LogTextHelper.WriteLine(Resources.LogDir + @"/完成输送线任务/" + "Line"+parttask.sourceplace, "将完成结果更新至数据库:{0}", "保存成功");
 
                    if (nextHandler != null)
                    {
                        nextHandler.Handle();
                    }
                }
 
                catch (Exception ex)
                {
                    //LogTextHelper.WriteLine(Resources.LogDir + @"/完成输送线任务/" + Conveyor.ConveyorName, "将完成结果更新至数据库:{0}", ex.Message);
                    LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "Handle", ex.Message);
                }
            }
        }
    }
}