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
using iWareCc.Cache.Entity;
using iWareCc.Conveyor.Entity;
using iWareCc.DecomposeTask.Entity;
using iWareCc.Properties;
using iWareCommon.Common.Entity;
using iWareCommon.Common.EnumType;
using iWareCommon.Utils;
using iWareDataCore.BASE.EnumType;
using iWareDataCore.ORM;
using iWareDataCore.TASK.Dao;
using iWareDataCore.TASK.EnumType;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace iWareCc.FinishConveyorTask.Chain
{
  public  class 查看物料是否到输送机末端: IHandler
    {
        /// <summary>
        /// 该节点的下一个节点
        /// </summary>
        private IHandler nextHandler = null;
        public IHandler NextHandler
        {
            set { nextHandler = value; }
        }
 
        private ConveyorEntity Conveyor;
 
        /// <summary>
        /// 任务容器
        /// </summary>
        private PartTaskContainer DecompositionTaskContainer;
 
 
        public 查看物料是否到输送机末端(ConveyorEntity conveyor, PartTaskContainer decompositionTaskContainer)
        {
            this.Conveyor = conveyor;
            this.DecompositionTaskContainer = decompositionTaskContainer;
        }
 
 
        public void Handle()
        {
            using (var dbModel = new DbModelCore())
            {
                try
                {
                    var task = DecompositionTaskContainer.PartTask;
                    var gate = Conveyor.Gates.FirstOrDefault(y => y.Place.Id == task.ToPlaceId);
                    var gatesource = Conveyor.Gates.FirstOrDefault(y => y.Place.Id == task.SourcePlaceId);
                    gatesource.TaskId = "";
 
                    if (gate.Place.PlaceTypeName!="gate12")
                    {
                        if (gate == null || !gate.ROccupied)
                        {
                            LogTextHelper.WriteLine(Resources.LogDir + @"/完成输送机任务/" + Conveyor.Equipment.EquipName, "查看托盘是否到输送机末端:{0}", "端口未到位");
                            return;
                        }
                    }
                    if (gate.RIsEmpty)
                    {
                        LogTextHelper.WriteLine(Resources.LogDir + @"/完成输送机任务/" + Conveyor.Equipment.EquipName, "查看托盘是否到输送机末端:{0}", "未检测到有钢材");
                        return;
                    }
                    task.IsFinished = (int)EYesOrNo.是;
                    task.Status = (int)EPartTaskStatus.已完成;
                    task.UpdateTime = DateTime.Now;
                    task.IsCurrent = (int)EYesOrNo.否;
 
                    LogTextHelper.WriteLine(Resources.LogDir + @"/完成输送机任务/" + Conveyor.Equipment.EquipName, "查看托盘是否到输送机末端:{0}", task.Id.ToString());
                    var placeMaterialViews = dbModel.BASEPlaceMaterialViews.FirstOrDefault(y => y.placeid == task.SourcePlaceId && y.materialcode == task.MaterialCode);
                    var sourcePlace = dbModel.BASEPlaces.FirstOrDefault(x => x.id == task.SourcePlaceId);
                    var toPlace = dbModel.BASEPlaces.FirstOrDefault(x => x.id == task.ToPlaceId);
                    sourcePlace.isexecute = (int)EYesOrNo.否;
                    sourcePlace.status = (int)EPlaceStatus.空库位;
                    sourcePlace.islock = (int)EYesOrNo.否;
                    toPlace.isexecute = (int)EYesOrNo.否;
                    toPlace.islock = (int)EYesOrNo.否;
                    toPlace.status = (int)EPlaceStatus.空库位;
                    BASEPlaceMaterial pm = new BASEPlaceMaterial();
                    if (task.MainTaskType == (int)EMainTaskType.出库任务)//出库任务
                    {
                         if (placeMaterialViews != null)
                         {
                            pm = dbModel.BASEPlaceMaterials.FirstOrDefault(x => x.placeid == placeMaterialViews.placeid && x.materialid == placeMaterialViews.materialid);
                         }
                         if (pm.id>0)
                        {
                               dbModel.BASEPlaceMaterials.Remove(pm);
                        }
                         if (gate.Place.PlaceTypeName == "gate22")//端口有货才发送退库任务
                         {
                             if (!gate.RIsEmpty && gate.ROccupied)//gate21已经发送了滚动任务并且已经到了gate22
                             {
                                 if (!gate.SendGateTask()) //如果发送失败,则发送失败
                                 {
                                     gate.SendGateTask();
                                 }
                             }
                         }
                    }
                    else//入库任务
                    {
                        if (placeMaterialViews != null)
                        {
                            pm = dbModel.BASEPlaceMaterials.FirstOrDefault(x => x.placeid == placeMaterialViews.placeid && x.materialid == placeMaterialViews.materialid);
                            pm.placeid = task.ToPlaceId;
                            pm.updatetime = DateTime.Now;
                      
                         }else
                        {
                          var material = dbModel.BASEMaterialViews.FirstOrDefault(y => y.code == task.MaterialCode);
                          pm = new BASEPlaceMaterial()
                            {
                                 placeid=task.ToPlaceId,
                                 materialid = material.id,
                                 createtime=DateTime.Now,
                                 updatetime = DateTime.Now,
                            };
                          dbModel.BASEPlaceMaterials.Add(pm);
                        }
                    }
          
                    PartTaskDao.GetInstance().Update(task, dbModel);
                    LogTextHelper.WriteLine(Resources.LogDir + @"/完成输送机任务/" + Conveyor.Equipment.EquipName, "查看托盘是否到输送机末端:{0}", "任务完成");
 
                    if (nextHandler != null)
                    {
                        nextHandler.Handle();
                    }
                }
                catch (Exception ex)
                {
                    LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "Handle", ex.Message);
                }
            }
        }
    }
}