222
schangxiang@126.com
2025-09-29 f782248da68c035aae12f902f29d828e9867abb0
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
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.ORM;
using iWareDataCore.TASK.Entity;
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 = dbModel.TASKPartTasks.OrderBy(x => x.finishtimes).FirstOrDefault(x => x.iscurrent == (int)EYesOrNo.是 && x.isreleased == (int)EYesOrNo.是 && x.isfinished == (int)EYesOrNo.否 && x.type == (int)EPartTaskType.输送机任务 && x.equipid == Conveyor.Equipment.Id && x.status == (int)EPartTaskStatus.执行中);
 
                    if (task == null)
                    {
                        LogTextHelper.WriteLine(Resources.LogDir + @"/完成输送机任务/" + Conveyor.Equipment.EquipName, "获取当前的任务:{0}", "没有找到待完成的任务");
                        return;
                    }
 
                    task.finishtimes += 1;
                    if (task.sourceplace == "100201")
                    {
                     var sc = CacheEntity.Conveyors.First(x => x.Equipment.EquipName == "conveyor1").Gates.FirstOrDefault(x => x.Place.PlaceTypeName == "sc");
                    var materila = dbModel.BASEMaterials.FirstOrDefault(x => x.code == task.materialcode);
                    if (!string.IsNullOrEmpty(materila.wide))
                    {
                        if (!sc.SendMaterialWindTask(materila.wide, materila.thick))
                        {
                            sc.SendMaterialWindTask(materila.wide, materila.thick);
                        }
                    }
                    }
                 
 
                    dbModel.SaveChanges();
 
                    DecompositionTaskContainer.PartTask = new PartTaskEntity(task);
 
 
                    LogTextHelper.WriteLine(Resources.LogDir + @"/完成输送机任务/" + Conveyor.Equipment.EquipName, "获取当前的任务:{0}", DecompositionTaskContainer.PartTask.Id);
 
                    if (nextHandler != null)
                    {
                        nextHandler.Handle();
                    }
 
                }
                catch (Exception ex)
                {
                    LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "Handle", ex.Message);
                }
            }
        }
    }
}