2
schangxiang@126.com
2024-08-16 b47c50a2a514def7374b32d7194b2c599cba5625
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
using iWareCc.Cache.Entity;
using iWareCc.Conveyor.EnumType;
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 System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace iWareCc.DecomposeTask.Strategy.入库任务.Chain
{
   public class 寻找空库位 : IHandler
    {
 
        private ResultContainer ResultContainer;
        private MainTaskContainer LogisticalTaskContainer;
        private PlaceContainer PlaceContainer;
 
 
        /// <summary>
        /// 该节点的下一个节点
        /// </summary>
        private IHandler nextHandler = null;
        public IHandler NextHandler
        {
            set { nextHandler = value; }
        }
 
 
        public 寻找空库位(ResultContainer resultContainer, MainTaskContainer logisticalTaskContainer, PlaceContainer placeContainer)
        {
            this.ResultContainer = resultContainer;
            this.LogisticalTaskContainer = logisticalTaskContainer;
            this.PlaceContainer = placeContainer;
        }
 
        public void Handle()
        {
            using (var dbModel = new DbModelCore())
            {
                try
                {
                    if (LogisticalTaskContainer.MainTask == null)
                    {
                        ResultContainer.Msg = "未找到待分解任务";
                        LogTextHelper.WriteLine(Resources.LogDir + @"/分解任务流程", "寻找空库位:{0}", ResultContainer.Msg);
                        return;
                    }
                    //按照层列原则利用库位
 
                    var alerm = CacheEntity.Conveyors.Find(x => x.Equipment.EquipName == "conveyor1").Gates.Find(x => x.Place.PlaceTypeName == "alarm");
                    var emptyPlace = dbModel.BASEEmptyPlaceViews.Where(x => x.isexecute == (int)EYesOrNo.否 && x.islock == (int)EYesOrNo.否 && x.typeid == 4 && x.status == (int)EPlaceStatus.空库位).OrderBy(x => new { x.layer, x.col }).FirstOrDefault();
                    if (emptyPlace == null)
                    {
                        ResultContainer.Msg = "未找到空库位";
                        alerm.SendGateAlarmTask((int)ESendCode.入库库位不足);
                        LogTextHelper.WriteLine(Resources.LogDir + @"/分解任务流程", "寻找空库位:{0}", ResultContainer.Msg);
                        return;
                    }
 
                    PlaceContainer.Place = CacheEntity.Places.FirstOrDefault(x => x.Id == emptyPlace.id);
 
                    LogTextHelper.WriteLine(Resources.LogDir + @"/分解任务流程", "寻找空库位:{0}", PlaceContainer.Place.Code);
 
                    if (nextHandler != null)
                    {
                        nextHandler.Handle();
                    }
                }
                catch (Exception ex)
                {
 
                    ResultContainer.Msg = ex.Message;
                    LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "Handle", ex.Message);
                }
            }
        }
    }
}